diff --git a/amx-deps/src/syscalls.cpp b/amx-deps/src/syscalls.cpp index 25f9250..a95301b 100644 --- a/amx-deps/src/syscalls.cpp +++ b/amx-deps/src/syscalls.cpp @@ -70,27 +70,33 @@ AMX_NATIVE boundNatives[MAX_SAMP_NATIVES]; template struct NativeGenerator { - static const char* BoundNativeName; - - static cell AMX_NATIVE_CALL DoNative(AMX* amx, const cell* params) { - return n_samp(amx, params, BoundNativeName); - } - - static void Generate() { - boundNativeNames[index] = &BoundNativeName; - boundNatives[index] = reinterpret_cast(&DoNative); - - if constexpr (index + 1 < MAX_SAMP_NATIVES) { - NativeGenerator::Generate(); - } - } + static const char* BoundNativeName; + static cell AMX_NATIVE_CALL DoNative(AMX* amx, const cell* params) { + return n_samp(amx, params, BoundNativeName); + } + + static void Register() { + boundNativeNames[index] = &BoundNativeName; + boundNatives[index] = reinterpret_cast(&DoNative); + } }; -template<> struct NativeGenerator {}; - template const char* NativeGenerator::BoundNativeName = nullptr; +template +struct RecursiveRegister { + static void Run() { + if constexpr (Start == End) { + NativeGenerator::Register(); + } else { + constexpr size_t Mid = Start + (End - Start) / 2; + RecursiveRegister::Run(); + RecursiveRegister::Run(); + } + } +}; + int callLuaMTRead(lua_State *luaVM) { luaL_checktype(luaVM, 1, LUA_TTABLE); lua_getfield(luaVM, 1, "amx"); @@ -463,7 +469,7 @@ void initSAMPSyscalls() { if(!mainVM || sampNatives) return; - NativeGenerator<0>::Generate(); + RecursiveRegister<0, MAX_SAMP_NATIVES - 1>::Run(); lua_getglobal(mainVM, "g_SAMPSyscallPrototypes"); int numNatives = 0;