diff --git a/Makefile b/Makefile index 50a7360..843ecb4 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,7 @@ INCLUDE = -I. -I$(CSSDK)/common -I$(CSSDK)/dlls -I$(CSSDK)/engine \ BIN_DIR = Release CFLAGS = $(OPT_FLAGS) -Wno-unused-result -CFLAGS += -m32 -fvisibility=hidden -std=c++17 -D_GLIBCXX_USE_CXX11_ABI=0 +CFLAGS += -m32 -fvisibility=hidden -std=c++17 -D_GLIBCXX_USE_CXX11_ABI=0 -DWITHOUT_SQL #-Wl,--as-needed #-D_GLIBCXX_USE_CXX11_ABI=0 #-Wl,--as-needed diff --git a/Release/refsapi_amxx_i386.so b/Release/refsapi_amxx_i386.so index 67901e9..a1a9c49 100644 Binary files a/Release/refsapi_amxx_i386.so and b/Release/refsapi_amxx_i386.so differ diff --git a/amxxmodule.cpp b/amxxmodule.cpp index f34c20a..91444fb 100644 --- a/amxxmodule.cpp +++ b/amxxmodule.cpp @@ -16,105 +16,104 @@ // Module info static amxx_module_info_s g_ModuleInfo = -{ - Plugin_info.name, - Plugin_info.author, - Plugin_info.version, - FALSE, - Plugin_info.logtag, - "refsapi", - "refsapi" -}; + { + Plugin_info.name, + Plugin_info.author, + Plugin_info.version, + FALSE, + Plugin_info.logtag, + "refsapi", + "refsapi"}; // Storage for the requested functions amxxapi_t g_amxxapi; static struct funcreq_t { - const char * name; + const char *name; size_t offset; } g_funcrequests[] = -{ - DECLARE_REQ(AddNatives), - //DECLARE_REQ(AddNewNatives), - //DECLARE_REQ(BuildPathname), - //DECLARE_REQ(BuildPathnameR), - DECLARE_REQ(GetAmxAddr), - //DECLARE_REQ(GetAmxVectorNull), // AMXX 1.8.3-dev - //DECLARE_REQ(PrintSrvConsole), - DECLARE_REQ(GetModname), - DECLARE_REQ(GetAmxScriptName), - //DECLARE_REQ(GetAmxScript), - DECLARE_REQ(FindAmxScriptByAmx), - //DECLARE_REQ(FindAmxScriptByName), - DECLARE_REQ(SetAmxString), - DECLARE_REQ(SetAmxStringUTF8Char), // AMXX 1.8.3-dev - DECLARE_REQ(SetAmxStringUTF8Cell), // AMXX 1.8.3-dev - DECLARE_REQ(GetAmxString), - //DECLARE_REQ(GetAmxStringNull), // AMXX 1.8.3-dev - //DECLARE_REQ(GetAmxStringLen), - DECLARE_REQ(FormatAmxString), - //DECLARE_REQ(CopyAmxMemory), - DECLARE_REQ(Log), - DECLARE_REQ(LogError), - //DECLARE_REQ(RaiseAmxError), - DECLARE_REQ(RegisterForward), - DECLARE_REQ(ExecuteForward), - DECLARE_REQ(PrepareCellArray), - DECLARE_REQ(PrepareCharArray), - DECLARE_REQ(PrepareCellArrayA), - DECLARE_REQ(PrepareCharArrayA), - //DECLARE_REQ(IsPlayerValid), - //DECLARE_REQ(GetPlayerName), - //DECLARE_REQ(GetPlayerIP), - //DECLARE_REQ(IsPlayerInGame), - //DECLARE_REQ(IsPlayerBot), - //DECLARE_REQ(IsPlayerAuthorized), - //DECLARE_REQ(GetPlayerTime), - //DECLARE_REQ(GetPlayerPlayTime), - //DECLARE_REQ(GetPlayerCurweapon), - //DECLARE_REQ(GetPlayerTeam), - //DECLARE_REQ(GetPlayerTeamID), - //DECLARE_REQ(GetPlayerDeaths), - //DECLARE_REQ(GetPlayerMenu), - //DECLARE_REQ(GetPlayerKeys), - //DECLARE_REQ(IsPlayerAlive), - //DECLARE_REQ(GetPlayerFrags), - //DECLARE_REQ(IsPlayerConnecting), - //DECLARE_REQ(IsPlayerHLTV), - //DECLARE_REQ(GetPlayerArmor), - //DECLARE_REQ(GetPlayerHealth), - //DECLARE_REQ(amx_Exec), - //DECLARE_REQ(amx_Execv), - //DECLARE_REQ(amx_Allot), - DECLARE_REQ(amx_FindPublic), - //DECLARE_REQ(LoadAmxScript), - //DECLARE_REQ(UnloadAmxScript), - //DECLARE_REQ(RealToCell), - //DECLARE_REQ(CellToReal), - DECLARE_REQ(RegisterSPForward), - DECLARE_REQ(RegisterSPForwardByName), - DECLARE_REQ(UnregisterSPForward), - //DECLARE_REQ(MergeDefinitionFile), - //DECLARE_REQ(amx_FindNative), - //DECLARE_REQ(GetPlayerFlags), - //DECLARE_REQ(GetPlayerEdict), - //DECLARE_REQ(Format), - //DECLARE_REQ(RegisterFunction), - //DECLARE_REQ(RequestFunction), - //DECLARE_REQ(amx_Push), - DECLARE_REQ(SetPlayerTeamInfo), - //DECLARE_REQ(PlayerPropAddr), - //DECLARE_REQ(RegAuthFunc), - //DECLARE_REQ(UnregAuthFunc), - //DECLARE_REQ(FindLibrary), - //DECLARE_REQ(AddLibraries), - //DECLARE_REQ(RemoveLibraries), - //DECLARE_REQ(OverrideNatives), - //DECLARE_REQ(GetLocalInfo), - //DECLARE_REQ(AmxReregister), - //DECLARE_REQ(RegisterFunctionEx), - //DECLARE_REQ(MessageBlock), + { + DECLARE_REQ(AddNatives), + // DECLARE_REQ(AddNewNatives), + // DECLARE_REQ(BuildPathname), + // DECLARE_REQ(BuildPathnameR), + DECLARE_REQ(GetAmxAddr), + // DECLARE_REQ(GetAmxVectorNull), // AMXX 1.8.3-dev + // DECLARE_REQ(PrintSrvConsole), + DECLARE_REQ(GetModname), + DECLARE_REQ(GetAmxScriptName), + // DECLARE_REQ(GetAmxScript), + DECLARE_REQ(FindAmxScriptByAmx), + // DECLARE_REQ(FindAmxScriptByName), + DECLARE_REQ(SetAmxString), + DECLARE_REQ(SetAmxStringUTF8Char), // AMXX 1.8.3-dev + DECLARE_REQ(SetAmxStringUTF8Cell), // AMXX 1.8.3-dev + DECLARE_REQ(GetAmxString), + // DECLARE_REQ(GetAmxStringNull), // AMXX 1.8.3-dev + // DECLARE_REQ(GetAmxStringLen), + DECLARE_REQ(FormatAmxString), + // DECLARE_REQ(CopyAmxMemory), + DECLARE_REQ(Log), + DECLARE_REQ(LogError), + // DECLARE_REQ(RaiseAmxError), + DECLARE_REQ(RegisterForward), + DECLARE_REQ(ExecuteForward), + DECLARE_REQ(PrepareCellArray), + DECLARE_REQ(PrepareCharArray), + DECLARE_REQ(PrepareCellArrayA), + DECLARE_REQ(PrepareCharArrayA), + // DECLARE_REQ(IsPlayerValid), + // DECLARE_REQ(GetPlayerName), + // DECLARE_REQ(GetPlayerIP), + // DECLARE_REQ(IsPlayerInGame), + // DECLARE_REQ(IsPlayerBot), + // DECLARE_REQ(IsPlayerAuthorized), + // DECLARE_REQ(GetPlayerTime), + // DECLARE_REQ(GetPlayerPlayTime), + // DECLARE_REQ(GetPlayerCurweapon), + // DECLARE_REQ(GetPlayerTeam), + // DECLARE_REQ(GetPlayerTeamID), + // DECLARE_REQ(GetPlayerDeaths), + // DECLARE_REQ(GetPlayerMenu), + // DECLARE_REQ(GetPlayerKeys), + // DECLARE_REQ(IsPlayerAlive), + // DECLARE_REQ(GetPlayerFrags), + // DECLARE_REQ(IsPlayerConnecting), + // DECLARE_REQ(IsPlayerHLTV), + // DECLARE_REQ(GetPlayerArmor), + // DECLARE_REQ(GetPlayerHealth), + // DECLARE_REQ(amx_Exec), + // DECLARE_REQ(amx_Execv), + // DECLARE_REQ(amx_Allot), + DECLARE_REQ(amx_FindPublic), + // DECLARE_REQ(LoadAmxScript), + // DECLARE_REQ(UnloadAmxScript), + // DECLARE_REQ(RealToCell), + // DECLARE_REQ(CellToReal), + DECLARE_REQ(RegisterSPForward), + DECLARE_REQ(RegisterSPForwardByName), + DECLARE_REQ(UnregisterSPForward), + // DECLARE_REQ(MergeDefinitionFile), + // DECLARE_REQ(amx_FindNative), + // DECLARE_REQ(GetPlayerFlags), + // DECLARE_REQ(GetPlayerEdict), + // DECLARE_REQ(Format), + // DECLARE_REQ(RegisterFunction), + // DECLARE_REQ(RequestFunction), + // DECLARE_REQ(amx_Push), + DECLARE_REQ(SetPlayerTeamInfo), + // DECLARE_REQ(PlayerPropAddr), + // DECLARE_REQ(RegAuthFunc), + // DECLARE_REQ(UnregAuthFunc), + // DECLARE_REQ(FindLibrary), + // DECLARE_REQ(AddLibraries), + // DECLARE_REQ(RemoveLibraries), + // DECLARE_REQ(OverrideNatives), + // DECLARE_REQ(GetLocalInfo), + // DECLARE_REQ(AmxReregister), + // DECLARE_REQ(RegisterFunctionEx), + // DECLARE_REQ(MessageBlock), }; C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo) @@ -122,7 +121,6 @@ C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo // check parameters if (!interfaceVersion || !moduleInfo) return AMXX_PARAM; - // check interface version if (*interfaceVersion != AMXX_INTERFACE_VERSION) { @@ -130,7 +128,6 @@ C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo *interfaceVersion = AMXX_INTERFACE_VERSION; return AMXX_IFVERS; } - // copy module info memcpy(moduleInfo, &g_ModuleInfo, sizeof(amxx_module_info_s)); return AMXX_OK; @@ -146,26 +143,17 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) // Check pointer if (!reqFnptrFunc) return AMXX_PARAM; - for (size_t i = 0; i < ARRAYSIZE(g_funcrequests); i++) { - void* fptr = reqFnptrFunc(g_funcrequests[i].name); + void *fptr = reqFnptrFunc(g_funcrequests[i].name); if (fptr == NULL) { return AMXX_FUNC_NOT_PRESENT; } *(void **)((unsigned long)&g_amxxapi + g_funcrequests[i].offset) = fptr; } - OnAmxxAttach(); - RegisterNatives_Misc(); - - //RegisterNatives_HookChains(); - //RegisterNatives_Members(); - //RegisterNatives_Misc(); - //RegisterNatives_Common(); - return AMXX_OK; } @@ -176,11 +164,6 @@ C_DLLEXPORT int AMXX_Detach() C_DLLEXPORT int AMXX_PluginsLoaded() { - //int iFwd = g_amxxapi.RegisterForward("__reapi_version_check", ET_IGNORE, FP_CELL, FP_CELL, FP_DONE); - //g_amxxapi.ExecuteForward(iFwd, REAPI_VERSION_MAJOR, REAPI_VERSION_MINOR); - - //g_amxxapi.OverrideNatives(); - return AMXX_OK; } @@ -199,7 +182,6 @@ NOINLINE void AMXX_Log(const char *fmt, ...) va_start(arglst, fmt); vsnprintf(msg, sizeof msg, fmt, arglst); va_end(arglst); - g_amxxapi.Log("[%s] %s", g_ModuleInfo.logtag, msg); } @@ -210,28 +192,23 @@ NOINLINE void AMXX_LogError(AMX *amx, int err, const char *fmt, ...) va_start(arglst, fmt); vsnprintf(msg, sizeof msg, fmt, arglst); va_end(arglst); - g_amxxapi.LogError(amx, err, "[%s] %s", g_ModuleInfo.logtag, msg); } -char* getAmxString(cell* src, char* dest, size_t max, size_t* len) +char *getAmxString(cell *src, char *dest, size_t max, size_t *len) { - char* start = dest; - + char *start = dest; while (*src && --max) *dest++ = (char)*src++; *dest = '\0'; - if (len) *len = dest - start; - return start; } -void setAmxString(cell* dest, const char* string, size_t max) +void setAmxString(cell *dest, const char *string, size_t max) { while (*string && max--) *dest++ = (cell)*string++; - *dest = 0; } diff --git a/api_config.cpp b/api_config.cpp index d789deb..c5f732e 100644 --- a/api_config.cpp +++ b/api_config.cpp @@ -2,26 +2,32 @@ CAPI_Config api_cfg; -CAPI_Config::CAPI_Config() : m_api_rehlds(false), m_api_regame(false) { +CAPI_Config::CAPI_Config() : m_api_rehlds(false), m_api_regame(false) +{ } -void CAPI_Config::FailedReGameDllAPI() { +void CAPI_Config::FailedReGameDllAPI() +{ m_api_regame = false; } -void CAPI_Config::Init() { +void CAPI_Config::Init() +{ m_api_rehlds = RehldsApi_Init(); m_api_regame = RegamedllApi_Init(); - if (m_api_rehlds) { + if (m_api_rehlds) + { g_engfuncs.pfnServerPrint("[REFSAPI] ReHLDS API successfully initialized.\n"); g_RehldsHookchains->Cvar_DirectSet()->registerHook(Cvar_DirectSet_RH); - } - if (m_api_regame) { + } + if (m_api_regame) + { g_engfuncs.pfnServerPrint("[REFSAPI] ReGAME API successfully initialized.\n"); g_ReGameHookchains->InstallGameRules()->registerHook(&InstallGameRules); } - cvar_t* pCvar = CVAR_GET_POINTER(REFSAPI_CVAR); - if (pCvar == nullptr) { + cvar_t *pCvar = CVAR_GET_POINTER(REFSAPI_CVAR); + if (pCvar == nullptr) + { cvar_t cvar; cvar.name = REFSAPI_CVAR; cvar.flags = (FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED); @@ -33,7 +39,8 @@ void CAPI_Config::Init() { } } -void CAPI_Config::ServerDeactivate() const { +void CAPI_Config::ServerDeactivate() const +{ if (m_api_regame) g_pGameRules = nullptr; } diff --git a/dllapi.cpp b/dllapi.cpp index e864675..7a8973c 100644 --- a/dllapi.cpp +++ b/dllapi.cpp @@ -2,138 +2,140 @@ DLL_FUNCTIONS *g_pFunctionTable, *g_pFunctionTable_Post; DLL_FUNCTIONS g_FunctionTable = -{ - NULL, // pfnGameInit - &DispatchSpawn, // pfnSpawn - NULL, // pfnThink - NULL, // pfnUse - NULL, // pfnTouch - NULL, // pfnBlocked - &KeyValue, // pfnKeyValue - NULL, // pfnSave - NULL, // pfnRestore - NULL, // pfnSetAbsBox - NULL, // pfnSaveWriteFields - NULL, // pfnSaveReadFields - NULL, // pfnSaveGlobalState - NULL, // pfnRestoreGlobalState - &ResetGlobalState, // pfnResetGlobalState - NULL, // pfnClientConnect - &R_ClientDisconnect, // pfnClientDisconnect - NULL, // pfnClientKill - NULL, // pfnClientPutInServer - NULL, // pfnClientCommand - NULL, // pfnClientUserInfoChanged - NULL, // pfnServerActivate - NULL, // pfnServerDeactivate - NULL, // pfnPlayerPreThink - NULL, // pfnPlayerPostThink - NULL, // pfnStartFrame - NULL, // pfnParmsNewLevel - NULL, // pfnParmsChangeLevel - NULL, // pfnGetGameDescription - NULL, // pfnPlayerCustomization - NULL, // pfnSpectatorConnect - NULL, // pfnSpectatorDisconnect - NULL, // pfnSpectatorThink - NULL, // pfnSys_Error - NULL, // pfnPM_Move - NULL, // pfnPM_Init - NULL, // pfnPM_FindTextureType - NULL, // pfnSetupVisibility - NULL, // pfnUpdateClientData - NULL, // pfnAddToFullPack - NULL, // pfnCreateBaseline - NULL, // pfnRegisterEncoders - NULL, // pfnGetWeaponData - NULL, // pfnCmdStart - NULL, // pfnCmdEnd - NULL, // pfnConnectionlessPacket - NULL, // pfnGetHullBounds - NULL, // pfnCreateInstancedBaselines - NULL, // pfnInconsistentFile - NULL, // pfnAllowLagCompensation + { + NULL, // pfnGameInit + &DispatchSpawn, // pfnSpawn + NULL, // pfnThink + NULL, // pfnUse + NULL, // pfnTouch + NULL, // pfnBlocked + &KeyValue, // pfnKeyValue + NULL, // pfnSave + NULL, // pfnRestore + NULL, // pfnSetAbsBox + NULL, // pfnSaveWriteFields + NULL, // pfnSaveReadFields + NULL, // pfnSaveGlobalState + NULL, // pfnRestoreGlobalState + &ResetGlobalState, // pfnResetGlobalState + NULL, // pfnClientConnect + &R_ClientDisconnect, // pfnClientDisconnect + NULL, // pfnClientKill + NULL, // pfnClientPutInServer + NULL, // pfnClientCommand + NULL, // pfnClientUserInfoChanged + NULL, // pfnServerActivate + NULL, // pfnServerDeactivate + NULL, // pfnPlayerPreThink + NULL, // pfnPlayerPostThink + NULL, // pfnStartFrame + NULL, // pfnParmsNewLevel + NULL, // pfnParmsChangeLevel + NULL, // pfnGetGameDescription + NULL, // pfnPlayerCustomization + NULL, // pfnSpectatorConnect + NULL, // pfnSpectatorDisconnect + NULL, // pfnSpectatorThink + NULL, // pfnSys_Error + NULL, // pfnPM_Move + NULL, // pfnPM_Init + NULL, // pfnPM_FindTextureType + NULL, // pfnSetupVisibility + NULL, // pfnUpdateClientData + NULL, // pfnAddToFullPack + NULL, // pfnCreateBaseline + NULL, // pfnRegisterEncoders + NULL, // pfnGetWeaponData + NULL, // pfnCmdStart + NULL, // pfnCmdEnd + NULL, // pfnConnectionlessPacket + NULL, // pfnGetHullBounds + NULL, // pfnCreateInstancedBaselines + NULL, // pfnInconsistentFile + NULL, // pfnAllowLagCompensation }; DLL_FUNCTIONS g_FunctionTable_Post = -{ - NULL, // pfnGameInit - NULL, // pfnSpawn - NULL, // pfnThink - NULL, // pfnUse - NULL, // pfnTouch - NULL, // pfnBlocked - NULL, // pfnKeyValue - NULL, // pfnSave - NULL, // pfnRestore - NULL, // pfnSetAbsBox - NULL, // pfnSaveWriteFields - NULL, // pfnSaveReadFields - NULL, // pfnSaveGlobalState - NULL, // pfnRestoreGlobalState - NULL, // pfnResetGlobalState - NULL, // pfnClientConnect - NULL, // pfnClientDisconnect - NULL, // pfnClientKill - &R_ClientPutInServer_Post, // pfnClientPutInServer - NULL, // pfnClientCommand - NULL, // pfnClientUserInfoChanged - &ServerActivate_Post, // pfnServerActivate - &ServerDeactivate_Post, // pfnServerDeactivate - NULL, // pfnPlayerPreThink - NULL, // pfnPlayerPostThink - NULL, // pfnStartFrame - NULL, // pfnParmsNewLevel - NULL, // pfnParmsChangeLevel - NULL, // pfnGetGameDescription - NULL, // pfnPlayerCustomization - NULL, // pfnSpectatorConnect - NULL, // pfnSpectatorDisconnect - NULL, // pfnSpectatorThink - NULL, // pfnSys_Error - NULL, // pfnPM_Move - NULL, // pfnPM_Init - NULL, // pfnPM_FindTextureType - NULL, // pfnSetupVisibility - NULL, // pfnUpdateClientData - NULL, // pfnAddToFullPack - NULL, // pfnCreateBaseline - NULL, // pfnRegisterEncoders - NULL, // pfnGetWeaponData - NULL, // pfnCmdStart - CmdEnd_Post, // pfnCmdEnd - NULL, // pfnConnectionlessPacket - NULL, // pfnGetHullBounds - NULL, // pfnCreateInstancedBaselines - NULL, // pfnInconsistentFile - NULL, // pfnAllowLagCompensation + { + NULL, // pfnGameInit + NULL, // pfnSpawn + NULL, // pfnThink + NULL, // pfnUse + NULL, // pfnTouch + NULL, // pfnBlocked + NULL, // pfnKeyValue + NULL, // pfnSave + NULL, // pfnRestore + NULL, // pfnSetAbsBox + NULL, // pfnSaveWriteFields + NULL, // pfnSaveReadFields + NULL, // pfnSaveGlobalState + NULL, // pfnRestoreGlobalState + NULL, // pfnResetGlobalState + NULL, // pfnClientConnect + NULL, // pfnClientDisconnect + NULL, // pfnClientKill + &R_ClientPutInServer_Post, // pfnClientPutInServer + NULL, // pfnClientCommand + NULL, // pfnClientUserInfoChanged + &ServerActivate_Post, // pfnServerActivate + &ServerDeactivate_Post, // pfnServerDeactivate + NULL, // pfnPlayerPreThink + NULL, // pfnPlayerPostThink + NULL, // pfnStartFrame + NULL, // pfnParmsNewLevel + NULL, // pfnParmsChangeLevel + NULL, // pfnGetGameDescription + NULL, // pfnPlayerCustomization + NULL, // pfnSpectatorConnect + NULL, // pfnSpectatorDisconnect + NULL, // pfnSpectatorThink + NULL, // pfnSys_Error + NULL, // pfnPM_Move + NULL, // pfnPM_Init + NULL, // pfnPM_FindTextureType + NULL, // pfnSetupVisibility + NULL, // pfnUpdateClientData + NULL, // pfnAddToFullPack + NULL, // pfnCreateBaseline + NULL, // pfnRegisterEncoders + NULL, // pfnGetWeaponData + NULL, // pfnCmdStart + CmdEnd_Post, // pfnCmdEnd + NULL, // pfnConnectionlessPacket + NULL, // pfnGetHullBounds + NULL, // pfnCreateInstancedBaselines + NULL, // pfnInconsistentFile + NULL, // pfnAllowLagCompensation }; NEW_DLL_FUNCTIONS g_NewDllFunctionTable = -{ - &OnFreeEntPrivateData, //! pfnOnFreeEntPrivateData() Called right before the object's memory is freed. Calls its destructor. - NULL, //! pfnGameShutdown() - NULL, //! pfnShouldCollide() - NULL, //! pfnCvarValue() - NULL, //! pfnCvarValue2() + { + &OnFreeEntPrivateData, //! pfnOnFreeEntPrivateData() Called right before the object's memory is freed. Calls its destructor. + NULL, //! pfnGameShutdown() + NULL, //! pfnShouldCollide() + NULL, //! pfnCvarValue() + NULL, //! pfnCvarValue2() }; NEW_DLL_FUNCTIONS g_NewDllFunctionTable_Post = -{ - NULL, //! pfnOnFreeEntPrivateData() Called right before the object's memory is freed. Calls its destructor. - NULL, //! pfnGameShutdown() - NULL, //! pfnShouldCollide() - NULL, //! pfnCvarValue() - NULL, //! pfnCvarValue2() + { + NULL, //! pfnOnFreeEntPrivateData() Called right before the object's memory is freed. Calls its destructor. + NULL, //! pfnGameShutdown() + NULL, //! pfnShouldCollide() + NULL, //! pfnCvarValue() + NULL, //! pfnCvarValue2() }; C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion) { - if (!pFunctionTable) { + if (!pFunctionTable) + { ALERT(at_logged, "%s called with null pFunctionTable", __FUNCTION__); return false; } - if (*interfaceVersion != INTERFACE_VERSION) { + if (*interfaceVersion != INTERFACE_VERSION) + { ALERT(at_logged, "%s version mismatch; requested=%d ours=%d", __FUNCTION__, *interfaceVersion, INTERFACE_VERSION); *interfaceVersion = INTERFACE_VERSION; return false; @@ -147,11 +149,13 @@ C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersi C_DLLEXPORT int GetEntityAPI2_Post(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion) { - if (!pFunctionTable) { + if (!pFunctionTable) + { ALERT(at_logged, "%s called with null pFunctionTable", __FUNCTION__); return false; } - if (*interfaceVersion != INTERFACE_VERSION) { + if (*interfaceVersion != INTERFACE_VERSION) + { ALERT(at_logged, "%s version mismatch; requested=%d ours=%d", __FUNCTION__, *interfaceVersion, INTERFACE_VERSION); *interfaceVersion = INTERFACE_VERSION; return false; @@ -165,11 +169,13 @@ C_DLLEXPORT int GetEntityAPI2_Post(DLL_FUNCTIONS *pFunctionTable, int *interface C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion) { - if (!pNewFunctionTable) { + if (!pNewFunctionTable) + { ALERT(at_logged, "%s called with null pNewFunctionTable", __FUNCTION__); return false; } - if (*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) { + if (*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) + { ALERT(at_logged, "%s version mismatch; requested=%d ours=%d", __FUNCTION__, *interfaceVersion, NEW_DLL_FUNCTIONS_VERSION); *interfaceVersion = NEW_DLL_FUNCTIONS_VERSION; return false; @@ -181,11 +187,13 @@ C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *in C_DLLEXPORT int GetNewDLLFunctions_Post(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion) { - if (!pNewFunctionTable) { + if (!pNewFunctionTable) + { ALERT(at_logged, "%s called with null pNewFunctionTable", __FUNCTION__); return false; } - if (*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) { + if (*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) + { ALERT(at_logged, "%s version mismatch; requested=%d ours=%d", __FUNCTION__, *interfaceVersion, NEW_DLL_FUNCTIONS_VERSION); *interfaceVersion = NEW_DLL_FUNCTIONS_VERSION; return false; diff --git a/engine_api.cpp b/engine_api.cpp index ba9b08f..f383a92 100644 --- a/engine_api.cpp +++ b/engine_api.cpp @@ -1,356 +1,358 @@ #include "precompiled.h" enginefuncs_t g_EngineFunctionsTable = -{ - NULL, // pfnPrecacheModel() - NULL, // pfnPrecacheSound() - NULL, // pfnSetModel() - NULL, // pfnModelIndex() - NULL, // pfnModelFrames() - NULL, // pfnSetSize() - NULL, // pfnChangeLevel() - NULL, // pfnGetSpawnParms() - NULL, // pfnSaveSpawnParms() - NULL, // pfnVecToYaw() - NULL, // pfnVecToAngles() - NULL, // pfnMoveToOrigin() - NULL, // pfnChangeYaw() - NULL, // pfnChangePitch() - NULL, // pfnFindEntityByString() - NULL, // pfnGetEntityIllum() - NULL, // pfnFindEntityInSphere() - NULL, // pfnFindClientInPVS() - NULL, // pfnEntitiesInPVS() - NULL, // pfnMakeVectors() - NULL, // pfnAngleVectors() - NULL, // pfnCreateEntity() - NULL, // pfnRemoveEntity() - NULL, // pfnCreateNamedEntity() - NULL, // pfnMakeStatic() - NULL, // pfnEntIsOnFloor() - NULL, // pfnDropToFloor() - NULL, // pfnWalkMove() - NULL, // pfnSetOrigin() - NULL, // pfnEmitSound() - NULL, // pfnEmitAmbientSound() - NULL, // pfnTraceLine() - NULL, // pfnTraceToss() - NULL, // pfnTraceMonsterHull() - NULL, // pfnTraceHull() - NULL, // pfnTraceModel() - NULL, // pfnTraceTexture() - NULL, // pfnTraceSphere() - NULL, // pfnGetAimVector() - NULL, // pfnServerCommand() - NULL, // pfnServerExecute() - NULL, // pfnClientCommand() - NULL, // pfnParticleEffect() - NULL, // pfnLightStyle() - NULL, // pfnDecalIndex() - NULL, // pfnPointContents() - NULL, // pfnMessageBegin() - NULL, // pfnMessageEnd() - NULL, // pfnWriteByte() - NULL, // pfnWriteChar() - NULL, // pfnWriteShort() - NULL, // pfnWriteLong() - NULL, // pfnWriteAngle() - NULL, // pfnWriteCoord() - NULL, // pfnWriteString() - NULL, // pfnWriteEntity() - NULL, // pfnCVarRegister() - NULL, // pfnCVarGetFloat() - NULL, // pfnCVarGetString() - NULL, // pfnCVarSetFloat() - NULL, // pfnCVarSetString() - NULL, // pfnAlertMessage() - NULL, // pfnEngineFprintf() - &R_PvAllocEntPrivateData, // pfnPvAllocEntPrivateData() - NULL, // pfnPvEntPrivateData() - NULL, // pfnFreeEntPrivateData() - NULL, // pfnSzFromIndex() - NULL, // pfnAllocString() - NULL, // pfnGetVarsOfEnt() - NULL, // pfnPEntityOfEntOffset() - NULL, // pfnEntOffsetOfPEntity() - NULL, // pfnIndexOfEdict() - NULL, // pfnPEntityOfEntIndex() - NULL, // pfnFindEntityByVars() - NULL, // pfnGetModelPtr() - NULL, // pfnRegUserMsg() - NULL, // pfnAnimationAutomove() - NULL, // pfnGetBonePosition() - NULL, // pfnFunctionFromName() - NULL, // pfnNameForFunction() - NULL, // pfnClientPrintf() - NULL, // pfnServerPrint() - NULL, // pfnCmd_Args() - NULL, // pfnCmd_Argv() - NULL, // pfnCmd_Argc() - NULL, // pfnGetAttachment() - NULL, // pfnCRC32_Init() - NULL, // pfnCRC32_ProcessBuffer() - NULL, // pfnCRC32_ProcessByte() - NULL, // pfnCRC32_Final() - NULL, // pfnRandomLong() - NULL, // pfnRandomFloat() - NULL, // pfnSetView() - NULL, // pfnTime() - NULL, // pfnCrosshairAngle() - NULL, // pfnLoadFileForMe() - NULL, // pfnFreeFile() - NULL, // pfnEndSection() - NULL, // pfnCompareFileTime() - NULL, // pfnGetGameDir() - NULL, // pfnCvar_RegisterVariable() - NULL, // pfnFadeClientVolume() - NULL, // pfnSetClientMaxspeed() - NULL, // pfnCreateFakeClient() - NULL, // pfnRunPlayerMove() - NULL, // pfnNumberOfEntities() - NULL, // pfnGetInfoKeyBuffer() - NULL, // pfnInfoKeyValue() - NULL, // pfnSetKeyValue() - NULL, // pfnSetClientKeyValue() - NULL, // pfnIsMapValid() - NULL, // pfnStaticDecal() - NULL, // pfnPrecacheGeneric() - NULL, // pfnGetPlayerUserId() - NULL, // pfnBuildSoundMsg() - NULL, // pfnIsDedicatedServer() - NULL, // pfnCVarGetPointer() - NULL, // pfnGetPlayerWONId() - NULL, // pfnInfo_RemoveKey() - NULL, // pfnGetPhysicsKeyValue() - NULL, // pfnSetPhysicsKeyValue() - NULL, // pfnGetPhysicsInfoString() - NULL, // pfnPrecacheEvent() - NULL, // pfnPlaybackEvent() - NULL, // pfnSetFatPVS() - NULL, // pfnSetFatPAS() - NULL, // pfnCheckVisibility() - NULL, // pfnDeltaSetField() - NULL, // pfnDeltaUnsetField() - NULL, // pfnDeltaAddEncoder() - NULL, // pfnGetCurrentPlayer() - NULL, // pfnCanSkipPlayer() - NULL, // pfnDeltaFindField() - NULL, // pfnDeltaSetFieldByIndex() - NULL, // pfnDeltaUnsetFieldByIndex() - NULL, // pfnSetGroupMask() - NULL, // pfnCreateInstancedBaseline() - NULL, // pfnCvar_DirectSet() - NULL, // pfnForceUnmodified() - NULL, // pfnGetPlayerStats() - NULL, // pfnAddServerCommand() + { + NULL, // pfnPrecacheModel() + NULL, // pfnPrecacheSound() + NULL, // pfnSetModel() + NULL, // pfnModelIndex() + NULL, // pfnModelFrames() + NULL, // pfnSetSize() + NULL, // pfnChangeLevel() + NULL, // pfnGetSpawnParms() + NULL, // pfnSaveSpawnParms() + NULL, // pfnVecToYaw() + NULL, // pfnVecToAngles() + NULL, // pfnMoveToOrigin() + NULL, // pfnChangeYaw() + NULL, // pfnChangePitch() + NULL, // pfnFindEntityByString() + NULL, // pfnGetEntityIllum() + NULL, // pfnFindEntityInSphere() + NULL, // pfnFindClientInPVS() + NULL, // pfnEntitiesInPVS() + NULL, // pfnMakeVectors() + NULL, // pfnAngleVectors() + NULL, // pfnCreateEntity() + NULL, // pfnRemoveEntity() + NULL, // pfnCreateNamedEntity() + NULL, // pfnMakeStatic() + NULL, // pfnEntIsOnFloor() + NULL, // pfnDropToFloor() + NULL, // pfnWalkMove() + NULL, // pfnSetOrigin() + NULL, // pfnEmitSound() + NULL, // pfnEmitAmbientSound() + NULL, // pfnTraceLine() + NULL, // pfnTraceToss() + NULL, // pfnTraceMonsterHull() + NULL, // pfnTraceHull() + NULL, // pfnTraceModel() + NULL, // pfnTraceTexture() + NULL, // pfnTraceSphere() + NULL, // pfnGetAimVector() + NULL, // pfnServerCommand() + NULL, // pfnServerExecute() + NULL, // pfnClientCommand() + NULL, // pfnParticleEffect() + NULL, // pfnLightStyle() + NULL, // pfnDecalIndex() + NULL, // pfnPointContents() + NULL, // pfnMessageBegin() + NULL, // pfnMessageEnd() + NULL, // pfnWriteByte() + NULL, // pfnWriteChar() + NULL, // pfnWriteShort() + NULL, // pfnWriteLong() + NULL, // pfnWriteAngle() + NULL, // pfnWriteCoord() + NULL, // pfnWriteString() + NULL, // pfnWriteEntity() + NULL, // pfnCVarRegister() + NULL, // pfnCVarGetFloat() + NULL, // pfnCVarGetString() + NULL, // pfnCVarSetFloat() + NULL, // pfnCVarSetString() + NULL, // pfnAlertMessage() + NULL, // pfnEngineFprintf() + &R_PvAllocEntPrivateData, // pfnPvAllocEntPrivateData() + NULL, // pfnPvEntPrivateData() + NULL, // pfnFreeEntPrivateData() + NULL, // pfnSzFromIndex() + NULL, // pfnAllocString() + NULL, // pfnGetVarsOfEnt() + NULL, // pfnPEntityOfEntOffset() + NULL, // pfnEntOffsetOfPEntity() + NULL, // pfnIndexOfEdict() + NULL, // pfnPEntityOfEntIndex() + NULL, // pfnFindEntityByVars() + NULL, // pfnGetModelPtr() + NULL, // pfnRegUserMsg() + NULL, // pfnAnimationAutomove() + NULL, // pfnGetBonePosition() + NULL, // pfnFunctionFromName() + NULL, // pfnNameForFunction() + NULL, // pfnClientPrintf() + NULL, // pfnServerPrint() + NULL, // pfnCmd_Args() + NULL, // pfnCmd_Argv() + NULL, // pfnCmd_Argc() + NULL, // pfnGetAttachment() + NULL, // pfnCRC32_Init() + NULL, // pfnCRC32_ProcessBuffer() + NULL, // pfnCRC32_ProcessByte() + NULL, // pfnCRC32_Final() + NULL, // pfnRandomLong() + NULL, // pfnRandomFloat() + NULL, // pfnSetView() + NULL, // pfnTime() + NULL, // pfnCrosshairAngle() + NULL, // pfnLoadFileForMe() + NULL, // pfnFreeFile() + NULL, // pfnEndSection() + NULL, // pfnCompareFileTime() + NULL, // pfnGetGameDir() + NULL, // pfnCvar_RegisterVariable() + NULL, // pfnFadeClientVolume() + NULL, // pfnSetClientMaxspeed() + NULL, // pfnCreateFakeClient() + NULL, // pfnRunPlayerMove() + NULL, // pfnNumberOfEntities() + NULL, // pfnGetInfoKeyBuffer() + NULL, // pfnInfoKeyValue() + NULL, // pfnSetKeyValue() + NULL, // pfnSetClientKeyValue() + NULL, // pfnIsMapValid() + NULL, // pfnStaticDecal() + NULL, // pfnPrecacheGeneric() + NULL, // pfnGetPlayerUserId() + NULL, // pfnBuildSoundMsg() + NULL, // pfnIsDedicatedServer() + NULL, // pfnCVarGetPointer() + NULL, // pfnGetPlayerWONId() + NULL, // pfnInfo_RemoveKey() + NULL, // pfnGetPhysicsKeyValue() + NULL, // pfnSetPhysicsKeyValue() + NULL, // pfnGetPhysicsInfoString() + NULL, // pfnPrecacheEvent() + NULL, // pfnPlaybackEvent() + NULL, // pfnSetFatPVS() + NULL, // pfnSetFatPAS() + NULL, // pfnCheckVisibility() + NULL, // pfnDeltaSetField() + NULL, // pfnDeltaUnsetField() + NULL, // pfnDeltaAddEncoder() + NULL, // pfnGetCurrentPlayer() + NULL, // pfnCanSkipPlayer() + NULL, // pfnDeltaFindField() + NULL, // pfnDeltaSetFieldByIndex() + NULL, // pfnDeltaUnsetFieldByIndex() + NULL, // pfnSetGroupMask() + NULL, // pfnCreateInstancedBaseline() + NULL, // pfnCvar_DirectSet() + NULL, // pfnForceUnmodified() + NULL, // pfnGetPlayerStats() + NULL, // pfnAddServerCommand() - // Added in SDK 2.2: - NULL, // pfnVoice_GetClientListening() - NULL, // pfnVoice_SetClientListening() + // Added in SDK 2.2: + NULL, // pfnVoice_GetClientListening() + NULL, // pfnVoice_SetClientListening() - // Added for HL 1109 (no SDK update): - NULL, // pfnGetPlayerAuthId() + // Added for HL 1109 (no SDK update): + NULL, // pfnGetPlayerAuthId() - // Added 2003/11/10 (no SDK update): - NULL, // pfnSequenceGet() - NULL, // pfnSequencePickSentence() - NULL, // pfnGetFileSize() - NULL, // pfnGetApproxWavePlayLen() - NULL, // pfnIsCareerMatch() - NULL, // pfnGetLocalizedStringLength() - NULL, // pfnRegisterTutorMessageShown() - NULL, // pfnGetTimesTutorMessageShown() - NULL, // pfnProcessTutorMessageDecayBuffer() - NULL, // pfnConstructTutorMessageDecayBuffer() - NULL, // pfnResetTutorMessageDecayData() + // Added 2003/11/10 (no SDK update): + NULL, // pfnSequenceGet() + NULL, // pfnSequencePickSentence() + NULL, // pfnGetFileSize() + NULL, // pfnGetApproxWavePlayLen() + NULL, // pfnIsCareerMatch() + NULL, // pfnGetLocalizedStringLength() + NULL, // pfnRegisterTutorMessageShown() + NULL, // pfnGetTimesTutorMessageShown() + NULL, // pfnProcessTutorMessageDecayBuffer() + NULL, // pfnConstructTutorMessageDecayBuffer() + NULL, // pfnResetTutorMessageDecayData() - // Added Added 2005-08-11 (no SDK update) - NULL, // pfnQueryClientCvarValue() - // Added Added 2005-11-22 (no SDK update) - NULL, // pfnQueryClientCvarValue2() - // Added 2009-06-17 (no SDK update) - // NULL, // pfnEngCheckParm() // s1lent: comment out this, for compatibility with older versions metamod + // Added Added 2005-08-11 (no SDK update) + NULL, // pfnQueryClientCvarValue() + // Added Added 2005-11-22 (no SDK update) + NULL, // pfnQueryClientCvarValue2() + // Added 2009-06-17 (no SDK update) + // NULL, // pfnEngCheckParm() // s1lent: comment out this, for compatibility with older versions metamod }; enginefuncs_t g_EngineFunctionsTable_Post = -{ - NULL, // pfnPrecacheModel() - NULL, // pfnPrecacheSound() - NULL, // pfnSetModel() - NULL, // pfnModelIndex() - NULL, // pfnModelFrames() - NULL, // pfnSetSize() - NULL, // pfnChangeLevel() - NULL, // pfnGetSpawnParms() - NULL, // pfnSaveSpawnParms() - NULL, // pfnVecToYaw() - NULL, // pfnVecToAngles() - NULL, // pfnMoveToOrigin() - NULL, // pfnChangeYaw() - NULL, // pfnChangePitch() - NULL, // pfnFindEntityByString() - NULL, // pfnGetEntityIllum() - NULL, // pfnFindEntityInSphere() - NULL, // pfnFindClientInPVS() - NULL, // pfnEntitiesInPVS() - NULL, // pfnMakeVectors() - NULL, // pfnAngleVectors() - NULL, // pfnCreateEntity() - NULL, // pfnRemoveEntity() - NULL, // pfnCreateNamedEntity() - NULL, // pfnMakeStatic() - NULL, // pfnEntIsOnFloor() - NULL, // pfnDropToFloor() - NULL, // pfnWalkMove() - NULL, // pfnSetOrigin() - NULL, // pfnEmitSound() - NULL, // pfnEmitAmbientSound() - NULL, // pfnTraceLine() - NULL, // pfnTraceToss() - NULL, // pfnTraceMonsterHull() - NULL, // pfnTraceHull() - NULL, // pfnTraceModel() - NULL, // pfnTraceTexture() - NULL, // pfnTraceSphere() - NULL, // pfnGetAimVector() - NULL, // pfnServerCommand() - NULL, // pfnServerExecute() - NULL, // pfnClientCommand() - NULL, // pfnParticleEffect() - NULL, // pfnLightStyle() - NULL, // pfnDecalIndex() - NULL, // pfnPointContents() - &R_MessageBegin_Post, // pfnMessageBegin() - &R_MessageEnd_Post, // pfnMessageEnd() - &R_WriteByte_Post, // pfnWriteByte() - &R_WriteChar_Post, // pfnWriteChar() - &R_WriteShort_Post, // pfnWriteShort() - &R_WriteLong_Post, // pfnWriteLong() - &R_WriteAngle_Post, // pfnWriteAngle() - &R_WriteCoord_Post, // pfnWriteCoord() - &R_WriteString_Post, // pfnWriteString() - &R_WriteEntity_Post, // pfnWriteEntity() - NULL, // pfnCVarRegister() //CVarRegister_Post - NULL, // pfnCVarGetFloat() - NULL, // pfnCVarGetString() - NULL, // pfnCVarSetFloat() - NULL, // pfnCVarSetString() - NULL, // pfnAlertMessage() - NULL, // pfnEngineFprintf() - NULL, // pfnPvAllocEntPrivateData() - NULL, // pfnPvEntPrivateData() - NULL, // pfnFreeEntPrivateData() - NULL, // pfnSzFromIndex() - NULL, // pfnAllocString() - NULL, // pfnGetVarsOfEnt() - NULL, // pfnPEntityOfEntOffset() - NULL, // pfnEntOffsetOfPEntity() - NULL, // pfnIndexOfEdict() - NULL, // pfnPEntityOfEntIndex() - NULL, // pfnFindEntityByVars() - NULL, // pfnGetModelPtr() - &R_RegUserMsg_Post, // pfnRegUserMsg() - NULL, // pfnAnimationAutomove() - NULL, // pfnGetBonePosition() - NULL, // pfnFunctionFromName() - NULL, // pfnNameForFunction() - NULL, // pfnClientPrintf() - NULL, // pfnServerPrint() - NULL, // pfnCmd_Args() - NULL, // pfnCmd_Argv() - NULL, // pfnCmd_Argc() - NULL, // pfnGetAttachment() - NULL, // pfnCRC32_Init() - NULL, // pfnCRC32_ProcessBuffer() - NULL, // pfnCRC32_ProcessByte() - NULL, // pfnCRC32_Final() - NULL, // pfnRandomLong() - NULL, // pfnRandomFloat() - NULL, // pfnSetView() - NULL, // pfnTime() - NULL, // pfnCrosshairAngle() - NULL, // pfnLoadFileForMe() - NULL, // pfnFreeFile() - NULL, // pfnEndSection() - NULL, // pfnCompareFileTime() - NULL, // pfnGetGameDir() - NULL, // pfnCvar_RegisterVariable() // - NULL, // pfnFadeClientVolume() - NULL, // pfnSetClientMaxspeed() - NULL, // pfnCreateFakeClient() - NULL, // pfnRunPlayerMove() - NULL, // pfnNumberOfEntities() - NULL, // pfnGetInfoKeyBuffer() - NULL, // pfnInfoKeyValue() - NULL, // pfnSetKeyValue() - NULL, // pfnSetClientKeyValue() - NULL, // pfnIsMapValid() - NULL, // pfnStaticDecal() - NULL, // pfnPrecacheGeneric() - NULL, // pfnGetPlayerUserId() - NULL, // pfnBuildSoundMsg() - NULL, // pfnIsDedicatedServer() - NULL, // pfnCVarGetPointer() - NULL, // pfnGetPlayerWONId() - NULL, // pfnInfo_RemoveKey() - NULL, // pfnGetPhysicsKeyValue() - NULL, // pfnSetPhysicsKeyValue() - NULL, // pfnGetPhysicsInfoString() - NULL, // pfnPrecacheEvent() - NULL, // pfnPlaybackEvent() - NULL, // pfnSetFatPVS() - NULL, // pfnSetFatPAS() - NULL, // pfnCheckVisibility() - NULL, // pfnDeltaSetField() - NULL, // pfnDeltaUnsetField() - NULL, // pfnDeltaAddEncoder() - NULL, // pfnGetCurrentPlayer() - NULL, // pfnCanSkipPlayer() - NULL, // pfnDeltaFindField() - NULL, // pfnDeltaSetFieldByIndex() - NULL, // pfnDeltaUnsetFieldByIndex() - NULL, // pfnSetGroupMask() - NULL, // pfnCreateInstancedBaseline() - NULL, // pfnCvar_DirectSet() - NULL, // pfnForceUnmodified() - NULL, // pfnGetPlayerStats() - NULL, // pfnAddServerCommand() + { + NULL, // pfnPrecacheModel() + NULL, // pfnPrecacheSound() + NULL, // pfnSetModel() + NULL, // pfnModelIndex() + NULL, // pfnModelFrames() + NULL, // pfnSetSize() + NULL, // pfnChangeLevel() + NULL, // pfnGetSpawnParms() + NULL, // pfnSaveSpawnParms() + NULL, // pfnVecToYaw() + NULL, // pfnVecToAngles() + NULL, // pfnMoveToOrigin() + NULL, // pfnChangeYaw() + NULL, // pfnChangePitch() + NULL, // pfnFindEntityByString() + NULL, // pfnGetEntityIllum() + NULL, // pfnFindEntityInSphere() + NULL, // pfnFindClientInPVS() + NULL, // pfnEntitiesInPVS() + NULL, // pfnMakeVectors() + NULL, // pfnAngleVectors() + NULL, // pfnCreateEntity() + NULL, // pfnRemoveEntity() + NULL, // pfnCreateNamedEntity() + NULL, // pfnMakeStatic() + NULL, // pfnEntIsOnFloor() + NULL, // pfnDropToFloor() + NULL, // pfnWalkMove() + NULL, // pfnSetOrigin() + NULL, // pfnEmitSound() + NULL, // pfnEmitAmbientSound() + NULL, // pfnTraceLine() + NULL, // pfnTraceToss() + NULL, // pfnTraceMonsterHull() + NULL, // pfnTraceHull() + NULL, // pfnTraceModel() + NULL, // pfnTraceTexture() + NULL, // pfnTraceSphere() + NULL, // pfnGetAimVector() + NULL, // pfnServerCommand() + NULL, // pfnServerExecute() + NULL, // pfnClientCommand() + NULL, // pfnParticleEffect() + NULL, // pfnLightStyle() + NULL, // pfnDecalIndex() + NULL, // pfnPointContents() + &R_MessageBegin_Post, // pfnMessageBegin() + &R_MessageEnd_Post, // pfnMessageEnd() + &R_WriteByte_Post, // pfnWriteByte() + &R_WriteChar_Post, // pfnWriteChar() + &R_WriteShort_Post, // pfnWriteShort() + &R_WriteLong_Post, // pfnWriteLong() + &R_WriteAngle_Post, // pfnWriteAngle() + &R_WriteCoord_Post, // pfnWriteCoord() + &R_WriteString_Post, // pfnWriteString() + &R_WriteEntity_Post, // pfnWriteEntity() + NULL, // pfnCVarRegister() //CVarRegister_Post + NULL, // pfnCVarGetFloat() + NULL, // pfnCVarGetString() + NULL, // pfnCVarSetFloat() + NULL, // pfnCVarSetString() + NULL, // pfnAlertMessage() + NULL, // pfnEngineFprintf() + NULL, // pfnPvAllocEntPrivateData() + NULL, // pfnPvEntPrivateData() + NULL, // pfnFreeEntPrivateData() + NULL, // pfnSzFromIndex() + NULL, // pfnAllocString() + NULL, // pfnGetVarsOfEnt() + NULL, // pfnPEntityOfEntOffset() + NULL, // pfnEntOffsetOfPEntity() + NULL, // pfnIndexOfEdict() + NULL, // pfnPEntityOfEntIndex() + NULL, // pfnFindEntityByVars() + NULL, // pfnGetModelPtr() + &R_RegUserMsg_Post, // pfnRegUserMsg() + NULL, // pfnAnimationAutomove() + NULL, // pfnGetBonePosition() + NULL, // pfnFunctionFromName() + NULL, // pfnNameForFunction() + NULL, // pfnClientPrintf() + NULL, // pfnServerPrint() + NULL, // pfnCmd_Args() + NULL, // pfnCmd_Argv() + NULL, // pfnCmd_Argc() + NULL, // pfnGetAttachment() + NULL, // pfnCRC32_Init() + NULL, // pfnCRC32_ProcessBuffer() + NULL, // pfnCRC32_ProcessByte() + NULL, // pfnCRC32_Final() + NULL, // pfnRandomLong() + NULL, // pfnRandomFloat() + NULL, // pfnSetView() + NULL, // pfnTime() + NULL, // pfnCrosshairAngle() + NULL, // pfnLoadFileForMe() + NULL, // pfnFreeFile() + NULL, // pfnEndSection() + NULL, // pfnCompareFileTime() + NULL, // pfnGetGameDir() + NULL, // pfnCvar_RegisterVariable() // + NULL, // pfnFadeClientVolume() + NULL, // pfnSetClientMaxspeed() + NULL, // pfnCreateFakeClient() + NULL, // pfnRunPlayerMove() + NULL, // pfnNumberOfEntities() + NULL, // pfnGetInfoKeyBuffer() + NULL, // pfnInfoKeyValue() + NULL, // pfnSetKeyValue() + NULL, // pfnSetClientKeyValue() + NULL, // pfnIsMapValid() + NULL, // pfnStaticDecal() + NULL, // pfnPrecacheGeneric() + NULL, // pfnGetPlayerUserId() + NULL, // pfnBuildSoundMsg() + NULL, // pfnIsDedicatedServer() + NULL, // pfnCVarGetPointer() + NULL, // pfnGetPlayerWONId() + NULL, // pfnInfo_RemoveKey() + NULL, // pfnGetPhysicsKeyValue() + NULL, // pfnSetPhysicsKeyValue() + NULL, // pfnGetPhysicsInfoString() + NULL, // pfnPrecacheEvent() + NULL, // pfnPlaybackEvent() + NULL, // pfnSetFatPVS() + NULL, // pfnSetFatPAS() + NULL, // pfnCheckVisibility() + NULL, // pfnDeltaSetField() + NULL, // pfnDeltaUnsetField() + NULL, // pfnDeltaAddEncoder() + NULL, // pfnGetCurrentPlayer() + NULL, // pfnCanSkipPlayer() + NULL, // pfnDeltaFindField() + NULL, // pfnDeltaSetFieldByIndex() + NULL, // pfnDeltaUnsetFieldByIndex() + NULL, // pfnSetGroupMask() + NULL, // pfnCreateInstancedBaseline() + NULL, // pfnCvar_DirectSet() + NULL, // pfnForceUnmodified() + NULL, // pfnGetPlayerStats() + NULL, // pfnAddServerCommand() - // Added in SDK 2.2: - NULL, // pfnVoice_GetClientListening() - NULL, // pfnVoice_SetClientListening() + // Added in SDK 2.2: + NULL, // pfnVoice_GetClientListening() + NULL, // pfnVoice_SetClientListening() - // Added for HL 1109 (no SDK update): - NULL, // pfnGetPlayerAuthId() + // Added for HL 1109 (no SDK update): + NULL, // pfnGetPlayerAuthId() - // Added 2003/11/10 (no SDK update): - NULL, // pfnSequenceGet() - NULL, // pfnSequencePickSentence() - NULL, // pfnGetFileSize() - NULL, // pfnGetApproxWavePlayLen() - NULL, // pfnIsCareerMatch() - NULL, // pfnGetLocalizedStringLength() - NULL, // pfnRegisterTutorMessageShown() - NULL, // pfnGetTimesTutorMessageShown() - NULL, // pfnProcessTutorMessageDecayBuffer() - NULL, // pfnConstructTutorMessageDecayBuffer() - NULL, // pfnResetTutorMessageDecayData() + // Added 2003/11/10 (no SDK update): + NULL, // pfnSequenceGet() + NULL, // pfnSequencePickSentence() + NULL, // pfnGetFileSize() + NULL, // pfnGetApproxWavePlayLen() + NULL, // pfnIsCareerMatch() + NULL, // pfnGetLocalizedStringLength() + NULL, // pfnRegisterTutorMessageShown() + NULL, // pfnGetTimesTutorMessageShown() + NULL, // pfnProcessTutorMessageDecayBuffer() + NULL, // pfnConstructTutorMessageDecayBuffer() + NULL, // pfnResetTutorMessageDecayData() - // Added Added 2005-08-11 (no SDK update) - NULL, // pfnQueryClientCvarValue() - // Added Added 2005-11-22 (no SDK update) - NULL, // pfnQueryClientCvarValue2() - // Added 2009-06-17 (no SDK update) - // NULL, // pfnEngCheckParm() // s1lent: comment out this, for compatibility with older versions metamod + // Added Added 2005-08-11 (no SDK update) + NULL, // pfnQueryClientCvarValue() + // Added Added 2005-11-22 (no SDK update) + NULL, // pfnQueryClientCvarValue2() + // Added 2009-06-17 (no SDK update) + // NULL, // pfnEngCheckParm() // s1lent: comment out this, for compatibility with older versions metamod }; C_DLLEXPORT int GetEngineFunctions(enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion) { - if (!pengfuncsFromEngine) { + if (!pengfuncsFromEngine) + { ALERT(at_logged, "%s called with null pengfuncsFromEngine", __FUNCTION__); return false; } - if (*interfaceVersion != ENGINE_INTERFACE_VERSION) { + if (*interfaceVersion != ENGINE_INTERFACE_VERSION) + { ALERT(at_logged, "%s version mismatch; requested=%d ours=%d", __FUNCTION__, *interfaceVersion, ENGINE_INTERFACE_VERSION); *interfaceVersion = ENGINE_INTERFACE_VERSION; return false; @@ -362,11 +364,13 @@ C_DLLEXPORT int GetEngineFunctions(enginefuncs_t *pengfuncsFromEngine, int *inte C_DLLEXPORT int GetEngineFunctions_Post(enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion) { - if (!pengfuncsFromEngine) { + if (!pengfuncsFromEngine) + { ALERT(at_logged, "%s called with null pengfuncsFromEngine", __FUNCTION__); return false; } - if (*interfaceVersion != ENGINE_INTERFACE_VERSION) { + if (*interfaceVersion != ENGINE_INTERFACE_VERSION) + { ALERT(at_logged, "%s version mismatch; requested=%d ours=%d", __FUNCTION__, *interfaceVersion, ENGINE_INTERFACE_VERSION); *interfaceVersion = ENGINE_INTERFACE_VERSION; return false; diff --git a/h_export.cpp b/h_export.cpp index 21c62e9..777a84c 100644 --- a/h_export.cpp +++ b/h_export.cpp @@ -3,7 +3,7 @@ #include "precompiled.h" enginefuncs_t g_engfuncs; -globalvars_t *gpGlobals; +globalvars_t *gpGlobals; // Receive engine function table from engine. // This appears to be the _first_ DLL routine called by the engine, so we diff --git a/main.cpp b/main.cpp index 0b84f6b..6a2b2d8 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,7 @@ #include "precompiled.h" -edict_t* g_pEdicts; -playermove_t* g_pMove; +edict_t *g_pEdicts; +playermove_t *g_pMove; char g_szMapName[32] = ""; void OnAmxxAttach() @@ -30,9 +30,10 @@ bool OnMetaAttach() void OnMetaDetach() { // clear all hooks? - //g_hookManager.Clear(); + // g_hookManager.Clear(); - if (api_cfg.hasReGameDLL()) { + if (api_cfg.hasReGameDLL()) + { g_ReGameHookchains->InstallGameRules()->unregisterHook(&InstallGameRules); } } @@ -46,14 +47,12 @@ void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax) r_bMapHasBuyZone = g_Tries.entities.find("func_buyzone") != g_Tries.entities.end(); g_RehldsHookchains->SV_DropClient()->registerHook(SV_DropClient_RH); g_RehldsHookchains->CreateFakeClient()->registerHook(CreateFakeClient_RH); - //g_RehldsHookchains->ED_Alloc()->registerHook(ED_Alloc_RH); - //g_RehldsHookchains->ED_Free()->registerHook(ED_Free_RH); g_ReGameHookchains->CBasePlayer_Killed()->registerHook(CBasePlayer_Killed_RG); g_ReGameHookchains->CSGameRules_CheckMapConditions()->registerHook(CSGameRules_CheckMapConditions_RG); g_ReGameHookchains->CBasePlayer_AddPlayerItem()->registerHook(CBasePlayer_AddPlayerItem_RG); g_ReGameHookchains->CBasePlayer_RemovePlayerItem()->registerHook(CBasePlayer_RemovePlayerItem_RG); g_ReGameHookchains->CBasePlayer_Spawn()->registerHook(CBasePlayer_Spawn_RG); - //g_ReGameHookchains->CreateWeaponBox()->registerHook(CreateWeaponBox_RG); + // g_ReGameHookchains->CreateWeaponBox()->registerHook(CreateWeaponBox_RG); SET_META_RESULT(MRES_IGNORED); } @@ -63,25 +62,23 @@ void ServerDeactivate_Post() SERVER_PRINT("[DEBUG] SERVER_DEACTIVATED\n"); #ifndef WITHOUT_SQL g_mysql_mngr.stop(); - g_cvar_mngr.clear(); g_mysql_mngr.close_all(); #endif + g_cvar_mngr.clear(); g_pEdicts = nullptr; api_cfg.ServerDeactivate(); - //g_hookManager.Clear(); + // g_hookManager.Clear(); g_pFunctionTable->pfnSpawn = DispatchSpawn; g_pFunctionTable->pfnKeyValue = KeyValue; g_RehldsHookchains->SV_DropClient()->unregisterHook(SV_DropClient_RH); g_RehldsHookchains->CreateFakeClient()->unregisterHook(CreateFakeClient_RH); - //g_RehldsHookchains->ED_Alloc()->unregisterHook(ED_Alloc_RH); - //g_RehldsHookchains->ED_Free()->unregisterHook(ED_Free_RH); g_ReGameHookchains->CBasePlayer_Killed()->unregisterHook(CBasePlayer_Killed_RG); g_ReGameHookchains->CSGameRules_CheckMapConditions()->unregisterHook(CSGameRules_CheckMapConditions_RG); g_ReGameHookchains->CBasePlayer_AddPlayerItem()->unregisterHook(CBasePlayer_AddPlayerItem_RG); g_ReGameHookchains->CBasePlayer_RemovePlayerItem()->unregisterHook(CBasePlayer_RemovePlayerItem_RG); g_ReGameHookchains->CBasePlayer_Spawn()->unregisterHook(CBasePlayer_Spawn_RG); - //g_ReGameHookchains->CreateWeaponBox()->unregisterHook(CreateWeaponBox_RG); - // CLEAR TRIES + // g_ReGameHookchains->CreateWeaponBox()->unregisterHook(CreateWeaponBox_RG); + // CLEAR TRIES r_bMapHasBuyZone = false; memset(g_Clients, 0, sizeof(g_Clients)); memset(g_PlayersNum, 0, sizeof(g_PlayersNum)); @@ -134,7 +131,8 @@ int DispatchSpawn(edict_t *pEntity) void ResetGlobalState() { // restore mapname - if (strcmp(g_RehldsData->GetName(), g_szMapName) != 0) { + if (strcmp(g_RehldsData->GetName(), g_szMapName) != 0) + { g_RehldsData->SetName(g_szMapName); g_pFunctionTable->pfnResetGlobalState = nullptr; } @@ -145,7 +143,7 @@ void OnFreeEntPrivateData(edict_t *pEdict) { CBaseEntity *pEntity = getPrivate(pEdict); if (pEntity) - Free_EntPrivateData(pEdict); //RefsAPI + Free_EntPrivateData(pEdict); // RefsAPI SET_META_RESULT(MRES_IGNORED); } @@ -154,10 +152,10 @@ CTempStrings::CTempStrings() m_current = 0; } - -char* CTempStrings::push(AMX* amx) +char *CTempStrings::push(AMX *amx) { - if (m_current == STRINGS_MAX) { + if (m_current == STRINGS_MAX) + { AMXX_LogError(amx, AMX_ERR_NATIVE, "Temp strings limit exceeded, contact reapi authors"); return nullptr; } diff --git a/meta_api.cpp b/meta_api.cpp index b862336..c9df95d 100644 --- a/meta_api.cpp +++ b/meta_api.cpp @@ -6,16 +6,16 @@ mutil_funcs_t *gpMetaUtilFuncs; enginefuncs_t *g_pengfuncsTable; plugin_info_t Plugin_info = -{ - META_INTERFACE_VERSION, // ifvers - "RefsAPI", // name - "1.0.2.2", // version - __DATE__, // date - "Refresh", // author - "https://github.com/jobmail/refsapi", // url - "REFSAPI", // logtag - PT_ANYTIME, // (when) loadable - PT_NEVER, // (when) unloadable + { + META_INTERFACE_VERSION, // ifvers + "RefsAPI", // name + "1.0.3", // version + __DATE__, // date + "Refresh", // author + "https://github.com/jobmail/refsapi", // url + "REFSAPI", // logtag + PT_ANYTIME, // (when) loadable + PT_NEVER, // (when) unloadable }; C_DLLEXPORT int Meta_Query(char *interfaceVersion, plugin_info_t **plinfo, mutil_funcs_t *pMetaUtilFuncs) @@ -26,15 +26,15 @@ C_DLLEXPORT int Meta_Query(char *interfaceVersion, plugin_info_t **plinfo, mutil } META_FUNCTIONS gMetaFunctionTable = -{ - NULL, // pfnGetEntityAPI HL SDK; called before game DLL - NULL, // pfnGetEntityAPI_Post META; called after game DLL - GetEntityAPI2, // pfnGetEntityAPI2 HL SDK2; called before game DLL - GetEntityAPI2_Post, // pfnGetEntityAPI2_Post META; called after game DLL - GetNewDLLFunctions, // pfnGetNewDLLFunctions HL SDK2; called before game DLL - GetNewDLLFunctions_Post, // pfnGetNewDLLFunctions_Post META; called after game DLL - GetEngineFunctions, // pfnGetEngineFunctions META; called before HL engine - GetEngineFunctions_Post, // pfnGetEngineFunctions_Post META; called after HL engine + { + NULL, // pfnGetEntityAPI HL SDK; called before game DLL + NULL, // pfnGetEntityAPI_Post META; called after game DLL + GetEntityAPI2, // pfnGetEntityAPI2 HL SDK2; called before game DLL + GetEntityAPI2_Post, // pfnGetEntityAPI2_Post META; called after game DLL + GetNewDLLFunctions, // pfnGetNewDLLFunctions HL SDK2; called before game DLL + GetNewDLLFunctions_Post, // pfnGetNewDLLFunctions_Post META; called after game DLL + GetEngineFunctions, // pfnGetEngineFunctions META; called before HL engine + GetEngineFunctions_Post, // pfnGetEngineFunctions_Post META; called after HL engine }; C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs) @@ -46,7 +46,7 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m return false; UTIL_ServerPrint("\n################\n# Hello World! #\n################\n\n"); - + GET_HOOK_TABLES(PLID, &g_pengfuncsTable, nullptr, nullptr); memcpy(pFunctionTable, &gMetaFunctionTable, sizeof(META_FUNCTIONS)); diff --git a/natives_helper.h b/natives_helper.h index dbeabb2..a704af0 100644 --- a/natives_helper.h +++ b/natives_helper.h @@ -1,27 +1,62 @@ #pragma once -#define PARAMS_COUNT (params[0] / sizeof(cell)) +#define PARAMS_COUNT (params[0] / sizeof(cell)) -#define CHECK_ISPLAYER(x) if (unlikely(params[x] <= 0 || params[x] > gpGlobals->maxClients)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid player index %i [%s]", __FUNCTION__, params[x], #x); return FALSE; } -#define CHECK_ISENTITY(x) if (unlikely(params[x] < 0 || params[x] > gpGlobals->maxEntities)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid entity index %i [%s]", __FUNCTION__, params[x], #x); return FALSE; } -#define CHECK_GAMERULES() if (unlikely(!g_pGameRules)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: gamerules not initialized", __FUNCTION__); return FALSE; } -#define CHECK_CONNECTED(x, y) if (unlikely(x == nullptr || x->has_disconnected)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[y]); return FALSE; } -#define CHECK_INSTANCE_OF(x, y) if (unlikely(dynamic_cast((x::BaseClass *)y) == nullptr)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid entity %d ('%s'), is not an instance of the base class '%s'", __FUNCTION__, indexOfEdict(y->pev), STRING(y->pev->classname), #x); return FALSE; } -#define CHECK_REQUIREMENTS(x) if (unlikely(!api_cfg.has##x())) { AMXX_LogError(amx, AMX_ERR_NATIVE, "Native '%s' is not available, %s required.", __FUNCTION__, #x); return FALSE; } if (!g_RehldsMessageManager) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: %s message manager not initialized.", __FUNCTION__, #x); return FALSE; } +#define CHECK_ISPLAYER(x) \ + if (unlikely(params[x] <= 0 || params[x] > gpGlobals->maxClients)) \ + { \ + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid player index %i [%s]", __FUNCTION__, params[x], #x); \ + return FALSE; \ + } +#define CHECK_ISENTITY(x) \ + if (unlikely(params[x] < 0 || params[x] > gpGlobals->maxEntities)) \ + { \ + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid entity index %i [%s]", __FUNCTION__, params[x], #x); \ + return FALSE; \ + } +#define CHECK_GAMERULES() \ + if (unlikely(!g_pGameRules)) \ + { \ + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: gamerules not initialized", __FUNCTION__); \ + return FALSE; \ + } +#define CHECK_CONNECTED(x, y) \ + if (unlikely(x == nullptr || x->has_disconnected)) \ + { \ + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[y]); \ + return FALSE; \ + } +#define CHECK_INSTANCE_OF(x, y) \ + if (unlikely(dynamic_cast((x::BaseClass *)y) == nullptr)) \ + { \ + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid entity %d ('%s'), is not an instance of the base class '%s'", __FUNCTION__, indexOfEdict(y->pev), STRING(y->pev->classname), #x); \ + return FALSE; \ + } +#define CHECK_REQUIREMENTS(x) \ + if (unlikely(!api_cfg.has##x())) \ + { \ + AMXX_LogError(amx, AMX_ERR_NATIVE, "Native '%s' is not available, %s required.", __FUNCTION__, #x); \ + return FALSE; \ + } \ + if (!g_RehldsMessageManager) \ + { \ + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: %s message manager not initialized.", __FUNCTION__, #x); \ + return FALSE; \ + } class CAmxArg { public: - CAmxArg(AMX* amx, cell value) : m_amx(amx), m_value(value) {} + CAmxArg(AMX *amx, cell value) : m_amx(amx), m_value(value) {} operator float() const { return *(float *)&m_value; } - operator Vector&() const + operator Vector &() const { return *(Vector *)getAmxAddr(m_amx, m_value); } - operator entvars_s*() const + operator entvars_s *() const { auto pev = PEV(m_value); // faster return m_value < 0 ? nullptr : pev; @@ -46,13 +81,13 @@ class CAmxArg { return (unsigned short)m_value; } - operator CBaseEntity*() const + operator CBaseEntity *() const { if (m_value < 0) return nullptr; return getPrivate(m_value); } - operator CBasePlayer*() const + operator CBasePlayer *() const { if (m_value < 0) return nullptr; @@ -92,50 +127,50 @@ class CAmxArg { return reinterpret_cast(m_value); } - Vector& vector() const + Vector &vector() const { - return operator Vector&(); + return operator Vector &(); } private: - AMX* m_amx; - cell m_value; + AMX *m_amx; + cell m_value; }; class CAmxArgs { public: - CAmxArgs(AMX* amx, cell* params) : m_amx(amx), m_params(params) {} + CAmxArgs(AMX *amx, cell *params) : m_amx(amx), m_params(params) {} CAmxArg operator[](size_t index) const { return CAmxArg(m_amx, m_params[index]); } private: - AMX* m_amx; - cell* m_params; + AMX *m_amx; + cell *m_params; }; -template -const char* getAmxString(cell* src, char (&dest)[N], size_t* len = nullptr) +template +const char *getAmxString(cell *src, char (&dest)[N], size_t *len = nullptr) { return getAmxString(src, dest, N - 1, len); } -template -const char* getAmxString(AMX* amx, cell addr, char (&dest)[N], size_t* len = nullptr) +template +const char *getAmxString(AMX *amx, cell addr, char (&dest)[N], size_t *len = nullptr) { return getAmxString(getAmxAddr(amx, addr), dest, N - 1, len); } -template -string_t getAmxStringAlloc(AMX* amx, cell addr, char (&dest)[N], size_t* len = nullptr) +template +string_t getAmxStringAlloc(AMX *amx, cell addr, char (&dest)[N], size_t *len = nullptr) { - const char* pszDest = getAmxString(getAmxAddr(amx, addr), dest, N - 1, len); + const char *pszDest = getAmxString(getAmxAddr(amx, addr), dest, N - 1, len); return (pszDest && pszDest[0] != '\0') ? ALLOC_STRING(pszDest) : iStringNull; } -inline void fillNatives(AMX_NATIVE_INFO* table, cell (with)(AMX *, cell *)) +inline void fillNatives(AMX_NATIVE_INFO *table, cell(with)(AMX *, cell *)) { for (size_t i = 0; table[i].name; i++) table[i].func = with; diff --git a/natives_refsapi.cpp b/natives_refsapi.cpp index b271fcf..f59afca 100644 --- a/natives_refsapi.cpp +++ b/natives_refsapi.cpp @@ -158,45 +158,43 @@ cell AMX_NATIVE_CALL rf_config(AMX *amx, cell *params) arg_folder }; int result = FALSE; - //UTIL_ServerPrint("[DEBUG] rf_config(): START\n"); + // UTIL_ServerPrint("[DEBUG] rf_config(): START\n"); CPluginMngr::CPlugin *plugin = findPluginFast(amx); auto plugin_cvars = g_cvar_mngr.get(plugin->getId()); if (check_it_empty(plugin_cvars)) return FALSE; // Sort list plugin_cvars->second.sort([](cvar_list_it p1, cvar_list_it p2) - { - return p1->first < p2->first; - }); - //g_cvar_mngr.sort(plugin_cvars); + { return p1->first < p2->first; }); + // g_cvar_mngr.sort(plugin_cvars); std::wstring name = stows(getAmxString(amx, params[arg_name], g_buff)); std::wstring path = stows(getAmxString(amx, params[arg_folder], g_buff)); - //UTIL_ServerPrint("[DEBUG] rf_config(): path = %s\n", wstos(path).c_str()); + // UTIL_ServerPrint("[DEBUG] rf_config(): path = %s\n", wstos(path).c_str()); if (name.empty()) name = stows(plugin->getName()); size_t pos = name.find(L".amxx"); - //UTIL_ServerPrint("[DEBUG] rf_config(): find pos = %d\n", pos); + // UTIL_ServerPrint("[DEBUG] rf_config(): find pos = %d\n", pos); if (pos != -1) name.replace(pos, sizeof(L".amxx") - 1, L""); getcwd(g_buff, sizeof(g_buff)); std::wstring root = stows(g_buff); path = wfmt(L"%s/%s/%s/plugins/%s", wstos(root).c_str(), g_amxxapi.GetModname(), LOCALINFO("amxx_configsdir"), path.empty() ? "" : wstos(path).c_str()).c_str(); - //UTIL_ServerPrint("[DEBUG] rf_config(): root = %s, dirs = %s\n", wstos(root).c_str(), wstos(path).c_str()); + // UTIL_ServerPrint("[DEBUG] rf_config(): root = %s, dirs = %s\n", wstos(root).c_str(), wstos(path).c_str()); if (path.back() != L'/') { - //UTIL_ServerPrint("[DEBUG] rf_config(): create dirs = %s\n", wstos(path).c_str()); + // UTIL_ServerPrint("[DEBUG] rf_config(): create dirs = %s\n", wstos(path).c_str()); std::filesystem::create_directories(wstos(path).c_str()); path += L'/'; } path += name + L".cfg"; - //UTIL_ServerPrint("[DEBUG] rf_config(): auto_create = %d, path = %s\n", params[arg_auto_create], wstos(path).c_str()); + // UTIL_ServerPrint("[DEBUG] rf_config(): auto_create = %d, path = %s\n", params[arg_auto_create], wstos(path).c_str()); bool is_exist; if ((is_exist = file_exists(path)) || params[arg_auto_create]) { std::wfstream file; file.open(wstos(path).c_str(), is_exist ? std::ios::in | std::ios::out | std::ios::binary : std::ios::in | std::ios::out | std::ios::binary | std::ios::trunc); - //UTIL_ServerPrint("[DEBUG] rf_config(): is_exist = %d, is_open = %d\n", is_exist, file.is_open()); + // UTIL_ServerPrint("[DEBUG] rf_config(): is_exist = %d, is_open = %d\n", is_exist, file.is_open()); if (file.is_open()) { file.imbue(_LOCALE); @@ -209,7 +207,7 @@ cell AMX_NATIVE_CALL rf_config(AMX *amx, cell *params) std::wstring var_value; while (std::getline(file, line, L'\n')) { - //UTIL_ServerPrint("[DEBUG] rf_config(): line = <%s>\n", wstos(line).c_str()); + // UTIL_ServerPrint("[DEBUG] rf_config(): line = <%s>\n", wstos(line).c_str()); trim(line); // Is comments? if (line.find(L";") == 0 || line.find(L"#") == 0 || line.find(L"//") == 0 || (pos = line.find(L" ")) == std::string::npos) @@ -219,19 +217,19 @@ cell AMX_NATIVE_CALL rf_config(AMX *amx, cell *params) var_value = trim_c(line.substr(pos, line.size() - pos)); if (rm_quote(var_value) == -1) AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: the parameter <%s> has a value <%s> with a wrong quotation mark", __FUNCTION__, wstos(var_name).c_str(), wstos(var_value).c_str()); - //UTIL_ServerPrint("[DEBUG] rf_config(): name = <%s>, value = <%s>\n", wstos(var_name).c_str(), wstos(var_value).c_str()); - load_cvars.insert({ var_name, var_value }); + // UTIL_ServerPrint("[DEBUG] rf_config(): name = <%s>, value = <%s>\n", wstos(var_name).c_str(), wstos(var_value).c_str()); + load_cvars.insert({var_name, var_value}); } } - //UTIL_ServerPrint("[DEBUG] rf_config(): cvars read %d\n", load_cvars.size()); + // UTIL_ServerPrint("[DEBUG] rf_config(): cvars read %d\n", load_cvars.size()); bool need_update = g_cvar_mngr.need_update(load_cvars, plugin_cvars); load_cvars_t::iterator load_cvars_it; bool need_replace; - m_cvar_t* m_cvar; + m_cvar_t *m_cvar; if (need_update) { - //UTIL_ServerPrint("[DEBUG] rf_config(): the config needs to be updated\n"); - // Need truncate? + // UTIL_ServerPrint("[DEBUG] rf_config(): the config needs to be updated\n"); + // Need truncate? if (is_exist) { // Reopen @@ -242,13 +240,13 @@ cell AMX_NATIVE_CALL rf_config(AMX *amx, cell *params) file << L"// This file was auto-generated by REFSAPI\n"; file << L"// Cvars for plugin \"" << plugin->getTitle() << L"\" by \"" << plugin->getAuthor() << L"\" (" << plugin->getName() << L", v" << plugin->getVersion() << L")\n"; } - for (auto& cvar_it : plugin_cvars->second) + for (auto &cvar_it : plugin_cvars->second) { m_cvar = &cvar_it->second; if (need_update) { file << L"\n// "; - for (auto& ch : m_cvar->desc) + for (auto &ch : m_cvar->desc) { file << ch; if (ch == L'\n') @@ -273,12 +271,12 @@ cell AMX_NATIVE_CALL rf_config(AMX *amx, cell *params) load_cvars.erase(load_cvars_it); } } - //UTIL_ServerPrint("[DEBUG] rf_config(): cvars left %d\n", load_cvars.size()); - // Unknown cvars left? + // UTIL_ServerPrint("[DEBUG] rf_config(): cvars left %d\n", load_cvars.size()); + // Unknown cvars left? if (need_update && load_cvars.size() > 0) { file << L"\n// - DISABLED\n"; - for (auto& cvar : load_cvars) + for (auto &cvar : load_cvars) file << L"// " << cvar.first << L" = \"" << cvar.second << "\"\n"; } result = (plugin_cvars->second.size() & 0xFF) | ((load_cvars.size() & 0xFF) << 8) | ((is_exist | ((!is_exist && (bool)params[arg_auto_create]) << 1) | (need_update << 2)) << 16); @@ -310,8 +308,8 @@ cell AMX_NATIVE_CALL rf_create_cvar(AMX *amx, cell *params) std::wstring value = stows(getAmxString(amx, params[arg_value], g_buff)); std::wstring desc = stows(getAmxString(amx, params[arg_desc], g_buff)); auto result = g_cvar_mngr.add(plugin->getId(), name, value, params[arg_flags], desc, params[arg_has_min], amx_ctof(params[arg_min_val]), params[arg_has_max], amx_ctof(params[arg_max_val])); - //UTIL_ServerPrint("[DEBUG] rf_create_cvar(): RESULT = %d\n", result->second.cvar); - return check_it_empty(result) ? FALSE : (cell)((void*)(result->second.cvar)); + // UTIL_ServerPrint("[DEBUG] rf_create_cvar(): RESULT = %d\n", result->second.cvar); + return check_it_empty(result) ? FALSE : (cell)((void *)(result->second.cvar)); } // native rf_bind_pcvar(type, pcvar, any:var[], varlen = 0); @@ -329,7 +327,7 @@ cell AMX_NATIVE_CALL rf_bind_pcvar(AMX *amx, cell *params) // Variable address is not inside global area? check_global_r(params[arg_var]); check_type_r(params[arg_type]); - cvar_t* cvar = (cvar_t*)((void*)params[arg_pcvar]); + cvar_t *cvar = (cvar_t *)((void *)params[arg_pcvar]); g_cvar_mngr.bind(plugin, (CVAR_TYPES_t)params[arg_type], g_cvar_mngr.get(cvar), getAmxAddr(amx, params[arg_var]), params[arg_var_size]); return TRUE; } @@ -348,8 +346,8 @@ cell AMX_NATIVE_CALL rf_hook_cvar_change(AMX *amx, cell *params) std::wstring name = stows(getAmxString(amx, params[arg_callback], g_buff)); int fwd = g_amxxapi.RegisterSPForwardByName(amx, wstos(name).c_str(), FP_CELL, FP_STRING, FP_STRING, FP_DONE); check_fwd_r(fwd, wstos(name).c_str()); - cvar_t* cvar = (cvar_t*)((void*)params[arg_pcvar]); - //UTIL_ServerPrint("[DEBUG] rf_hook_cvar_change(): fwd = %d, name = <%s>, cvar = %d\n", fwd, wstos(name).c_str(), cvar); + cvar_t *cvar = (cvar_t *)((void *)params[arg_pcvar]); + // UTIL_ServerPrint("[DEBUG] rf_hook_cvar_change(): fwd = %d, name = <%s>, cvar = %d\n", fwd, wstos(name).c_str(), cvar); auto result = g_cvar_mngr.create_hook(fwd, g_cvar_mngr.get(cvar), params[arg_state]); return check_it_empty(result) || fwd != result->first ? FALSE : (cell)result->first; } @@ -377,7 +375,7 @@ cell AMX_NATIVE_CALL rf_get_pcvar(AMX *amx, cell *params) arg_var, arg_var_size, }; - cvar_t* cvar = (cvar_t*)((void*)params[arg_pcvar]); + cvar_t *cvar = (cvar_t *)((void *)params[arg_pcvar]); return g_cvar_mngr.get((CVAR_TYPES_t)params[arg_type], cvar, getAmxAddr(amx, params[arg_var]), params[arg_var_size]); } @@ -406,17 +404,17 @@ cell AMX_NATIVE_CALL rf_set_pcvar(AMX *amx, cell *params) arg_pcvar, arg_var, }; - cvar_t* cvar = (cvar_t*)((void*)params[arg_pcvar]); - cell* ptr; + cvar_t *cvar = (cvar_t *)((void *)params[arg_pcvar]); + cell *ptr; switch (params[arg_type]) { - case CVAR_TYPE_NUM: - case CVAR_TYPE_FLT: - ptr = getAmxAddr(amx, params[arg_var]); - //UTIL_ServerPrint("[DEBUG] rf_set_pcvar(): value_int = %d, value_float = %f\n", *ptr, *ptr); - break; - case CVAR_TYPE_STR: - ptr = (cell*)getAmxString(amx, params[arg_var], g_buff); + case CVAR_TYPE_NUM: + case CVAR_TYPE_FLT: + ptr = getAmxAddr(amx, params[arg_var]); + // UTIL_ServerPrint("[DEBUG] rf_set_pcvar(): value_int = %d, value_float = %f\n", *ptr, *ptr); + break; + case CVAR_TYPE_STR: + ptr = (cell *)getAmxString(amx, params[arg_var], g_buff); } g_cvar_mngr.set((CVAR_TYPES_t)params[arg_type], cvar, ptr); return TRUE; @@ -433,16 +431,16 @@ cell AMX_NATIVE_CALL rf_set_cvar(AMX *amx, cell *params) arg_var, }; std::wstring name = stows(getAmxString(amx, params[arg_cvar], g_buff)); - cell* ptr; + cell *ptr; switch (params[arg_type]) { - case CVAR_TYPE_NUM: - case CVAR_TYPE_FLT: - ptr = getAmxAddr(amx, params[arg_var]); - //UTIL_ServerPrint("[DEBUG] rf_set_pcvar(): value_int = %d, value_float = %f\n", *ptr, *ptr); - break; - case CVAR_TYPE_STR: - ptr = (cell*)getAmxString(amx, params[arg_var], g_buff); + case CVAR_TYPE_NUM: + case CVAR_TYPE_FLT: + ptr = getAmxAddr(amx, params[arg_var]); + // UTIL_ServerPrint("[DEBUG] rf_set_pcvar(): value_int = %d, value_float = %f\n", *ptr, *ptr); + break; + case CVAR_TYPE_STR: + ptr = (cell *)getAmxString(amx, params[arg_var], g_buff); } g_cvar_mngr.set((CVAR_TYPES_t)params[arg_type], name, ptr); return TRUE; @@ -456,10 +454,10 @@ cell AMX_NATIVE_CALL rf_get_cvar_ptr(AMX *amx, cell *params) arg_count, arg_cvar, }; - //UTIL_ServerPrint("[DEBUG] rf_get_cvar_ptr(): start\n"); + // UTIL_ServerPrint("[DEBUG] rf_get_cvar_ptr(): start\n"); std::wstring name = stows(getAmxString(amx, params[arg_cvar], g_buff)); auto result = g_cvar_mngr.get(name); - return check_it_empty(result) ? FALSE : (cell)((void*)(result->second.cvar)); + return check_it_empty(result) ? FALSE : (cell)((void *)(result->second.cvar)); } // native rf_recoil_enable(custom_impulse_offset); @@ -471,14 +469,14 @@ cell AMX_NATIVE_CALL rf_recoil_enable(AMX *amx, cell *params) arg_custom_impulse_offset, }; g_recoil_mngr.enable(params[arg_custom_impulse_offset]); - return TRUE; + return TRUE; } // native rf_recoil_disable(); cell AMX_NATIVE_CALL rf_recoil_disable(AMX *amx, cell *params) { g_recoil_mngr.disable(); - return TRUE; + return TRUE; } #ifndef WITHOUT_SQL @@ -489,9 +487,9 @@ cell AMX_NATIVE_CALL rf_sql_tuple(AMX *amx, cell *params) { arg_count, arg_callback, - arg_db_host, - arg_db_user, - arg_db_pass, + arg_db_host, + arg_db_user, + arg_db_pass, arg_db_name, arg_timeout, arg_db_chrs, @@ -502,7 +500,7 @@ cell AMX_NATIVE_CALL rf_sql_tuple(AMX *amx, cell *params) callback = getAmxString(amx, params[arg_callback], g_buff); if (!callback.empty()) { - //public QueryHandler(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime); + // public QueryHandler(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime); fwd = g_amxxapi.RegisterSPForwardByName(amx, callback.c_str(), FP_CELL, FP_CELL, FP_ARRAY, FP_CELL, FP_ARRAY, FP_CELL, FP_CELL, FP_DONE); check_fwd_r(fwd, callback); } @@ -536,7 +534,7 @@ cell AMX_NATIVE_CALL rf_sql_close(AMX *amx, cell *params) arg_count, arg_conn, }; - return g_mysql_mngr.close((MYSQL*)params[arg_conn]); + return g_mysql_mngr.close((MYSQL *)params[arg_conn]); } // native bool:rf_sql_async_query(Handle:tuple, query[], data[] = "", data_size = 0, pri = 3, timeout = 60); @@ -552,7 +550,7 @@ cell AMX_NATIVE_CALL rf_sql_async_query(AMX *amx, cell *params) arg_pri, arg_timeout, }; - //std::string query = getAmxString(amx, params[arg_query], g_buff); + // std::string query = getAmxString(amx, params[arg_query], g_buff); return g_mysql_mngr.push_query(params[arg_tuple], getAmxString(amx, params[arg_query], g_buff), getAmxAddr(amx, params[arg_data]), params[arg_data_size], params[arg_pri], params[arg_timeout]); } @@ -565,7 +563,7 @@ cell AMX_NATIVE_CALL rf_sql_get_result(AMX *amx, cell *params) arg_query, arg_buffered, }; - return g_mysql_mngr.get_result((m_query_t*)params[arg_query], params[arg_buffered]); + return g_mysql_mngr.get_result((m_query_t *)params[arg_query], params[arg_buffered]); } // native rf_sql_num_rows(Handle:query); @@ -576,7 +574,7 @@ cell AMX_NATIVE_CALL rf_sql_num_rows(AMX *amx, cell *params) arg_count, arg_query, }; - return g_mysql_mngr.num_rows((m_query_t*)params[arg_query]); + return g_mysql_mngr.num_rows((m_query_t *)params[arg_query]); } // native bool:rf_sql_fetch_row(Handle:query); @@ -587,7 +585,7 @@ cell AMX_NATIVE_CALL rf_sql_fetch_row(AMX *amx, cell *params) arg_count, arg_query, }; - return g_mysql_mngr.fetch_row((m_query_t*)params[arg_query]); + return g_mysql_mngr.fetch_row((m_query_t *)params[arg_query]); } // native rf_sql_field_count(Handle:query); @@ -598,7 +596,7 @@ cell AMX_NATIVE_CALL rf_sql_field_count(AMX *amx, cell *params) arg_count, arg_query, }; - return g_mysql_mngr.field_count((m_query_t*)params[arg_query]); + return g_mysql_mngr.field_count((m_query_t *)params[arg_query]); } // native [RF_MAX_FIELD_SIZE] rf_sql_fetch_field(Handle:query, offset, mode = FT_AUTO, buff[] = "", buff_size = 0); @@ -614,7 +612,7 @@ cell AMX_NATIVE_CALL rf_sql_fetch_field(AMX *amx, cell *params) arg_buff_size, arg_ret, }; - return g_mysql_mngr.fetch_field((m_query_t*)params[arg_query], params[arg_offset], params[arg_type], getAmxAddr(amx, params[arg_ret]), getAmxAddr(amx, params[arg_buff]), params[arg_buff_size]); + return g_mysql_mngr.fetch_field((m_query_t *)params[arg_query], params[arg_offset], params[arg_type], getAmxAddr(amx, params[arg_ret]), getAmxAddr(amx, params[arg_buff]), params[arg_buff_size]); } // native [RF_MAX_FIELD_SIZE] rf_sql_fetch_nm_field(Handle:query, name[], mode = FT_AUTO, buff[] = "", buff_size = 0); @@ -631,7 +629,7 @@ cell AMX_NATIVE_CALL rf_sql_fetch_nm_field(AMX *amx, cell *params) arg_ret, }; char buff[2 * RF_MAX_FIELD_NAME]; - return g_mysql_mngr.fetch_field((m_query_t*)params[arg_query], getAmxString(amx, params[arg_name], buff), params[arg_type], getAmxAddr(amx, params[arg_ret]), getAmxAddr(amx, params[arg_buff]), params[arg_buff_size]); + return g_mysql_mngr.fetch_field((m_query_t *)params[arg_query], getAmxString(amx, params[arg_name], buff), params[arg_type], getAmxAddr(amx, params[arg_ret]), getAmxAddr(amx, params[arg_buff]), params[arg_buff_size]); } // native [RF_MAX_FIELD_NAME] rf_sql_field_name(Handle:query, offset, buff[] = 0, buff_size = 0); @@ -646,7 +644,7 @@ cell AMX_NATIVE_CALL rf_sql_field_name(AMX *amx, cell *params) arg_buff_size, arg_ret, }; - return g_mysql_mngr.field_name((m_query_t*)params[arg_query], params[arg_offset], getAmxAddr(amx, params[arg_ret]), getAmxAddr(amx, params[arg_buff]) , params[arg_buff_size]); + return g_mysql_mngr.field_name((m_query_t *)params[arg_query], params[arg_offset], getAmxAddr(amx, params[arg_ret]), getAmxAddr(amx, params[arg_buff]), params[arg_buff_size]); } // native rf_sql_insert_id(Handle:query); @@ -657,7 +655,7 @@ cell AMX_NATIVE_CALL rf_sql_insert_id(AMX *amx, cell *params) arg_count, arg_query, }; - return g_mysql_mngr.insert_id((m_query_t*)params[arg_query]); + return g_mysql_mngr.insert_id((m_query_t *)params[arg_query]); } // native rf_sql_affected_rows(Handle:query); @@ -668,7 +666,7 @@ cell AMX_NATIVE_CALL rf_sql_affected_rows(AMX *amx, cell *params) arg_count, arg_query, }; - return g_mysql_mngr.affected_rows((m_query_t*)params[arg_query]); + return g_mysql_mngr.affected_rows((m_query_t *)params[arg_query]); } // native [RF_MAX_FIELD_SIZE] rf_sql_query_str(Handle:query, buff[] = "", buff_size = 0); @@ -682,7 +680,7 @@ cell AMX_NATIVE_CALL rf_sql_query_str(AMX *amx, cell *params) arg_buff_size, arg_ret, }; - return g_mysql_mngr.query_str((m_query_t*)params[arg_query], getAmxAddr(amx, params[arg_ret]), getAmxAddr(amx, params[arg_buff]) , params[arg_buff_size]); + return g_mysql_mngr.query_str((m_query_t *)params[arg_query], getAmxAddr(amx, params[arg_ret]), getAmxAddr(amx, params[arg_buff]), params[arg_buff_size]); } // native Handle:rf_sql_query(Handle:conn, const fmt[], any:...); @@ -696,7 +694,7 @@ cell AMX_NATIVE_CALL rf_sql_query(AMX *amx, cell *params) }; int len; auto fmt = g_amxxapi.FormatAmxString(amx, params, arg_fmt, &len); - return (cell)g_mysql_mngr.prepare_query((MYSQL*)params[arg_conn], fmt); + return (cell)g_mysql_mngr.prepare_query((MYSQL *)params[arg_conn], fmt); } // native bool:rf_sql_exec(Handle:query); @@ -707,7 +705,7 @@ cell AMX_NATIVE_CALL rf_sql_exec(AMX *amx, cell *params) arg_count, arg_query, }; - return g_mysql_mngr.exec_query((m_query_t*)params[arg_query]); + return g_mysql_mngr.exec_query((m_query_t *)params[arg_query]); } // native rf_sql_free(Handle:query); @@ -718,7 +716,7 @@ cell AMX_NATIVE_CALL rf_sql_free(AMX *amx, cell *params) arg_count, arg_query, }; - g_mysql_mngr.free_query((m_query_t*)params[arg_query]); + g_mysql_mngr.free_query((m_query_t *)params[arg_query]); return TRUE; } #endif @@ -745,7 +743,7 @@ AMX_NATIVE_INFO Misc_Natives[] = { #ifndef WITHOUT_SQL {"rf_sql_tuple", rf_sql_tuple}, {"rf_sql_connect", rf_sql_connect}, - {"rf_sql_close", rf_sql_close}, + {"rf_sql_close", rf_sql_close}, {"rf_sql_get_result", rf_sql_get_result}, {"rf_sql_async_query", rf_sql_async_query}, {"rf_sql_num_rows", rf_sql_num_rows}, @@ -761,11 +759,10 @@ AMX_NATIVE_INFO Misc_Natives[] = { {"rf_sql_exec", rf_sql_exec}, {"rf_sql_free", rf_sql_free}, #endif - {nullptr, nullptr} -}; + {nullptr, nullptr}}; void RegisterNatives_Misc() { g_amxxapi.AddNatives(Misc_Natives); - //g_amxxapi.OverrideNatives() + // g_amxxapi.OverrideNatives() } diff --git a/natives_refsapi.h b/natives_refsapi.h index d41c487..9265031 100644 --- a/natives_refsapi.h +++ b/natives_refsapi.h @@ -1,5 +1,20 @@ -#define check_global_r(x) if ((x) > plugin->getAMX()->hlw) { AMXX_LogError(plugin->getAMX(), AMX_ERR_NATIVE, "%s: Cvars can only be bound to global variables", __FUNCTION__); return FALSE; } -#define check_type_r(x) if (!((x) > CVAR_TYPE_NONE && x < CVAR_TYPES_SIZE)) { AMXX_LogError(plugin->getAMX(), AMX_ERR_NATIVE, "%s: Cvars type error", __FUNCTION__); return FALSE; } -#define check_fwd_r(x, name) if ((x) == -1) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: register callback <%s> failed", __FUNCTION__, name); return FALSE; } +#define check_global_r(x) \ + if ((x) > plugin->getAMX()->hlw) \ + { \ + AMXX_LogError(plugin->getAMX(), AMX_ERR_NATIVE, "%s: Cvars can only be bound to global variables", __FUNCTION__); \ + return FALSE; \ + } +#define check_type_r(x) \ + if (!((x) > CVAR_TYPE_NONE && x < CVAR_TYPES_SIZE)) \ + { \ + AMXX_LogError(plugin->getAMX(), AMX_ERR_NATIVE, "%s: Cvars type error", __FUNCTION__); \ + return FALSE; \ + } +#define check_fwd_r(x, name) \ + if ((x) == -1) \ + { \ + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: register callback <%s> failed", __FUNCTION__, name); \ + return FALSE; \ + } void RegisterNatives_Misc(); \ No newline at end of file diff --git a/refsapi.cpp b/refsapi.cpp index 2323491..2228bde 100644 --- a/refsapi.cpp +++ b/refsapi.cpp @@ -15,15 +15,16 @@ sTries g_Tries; std::wstring_convert g_converter; funEventCall modMsgsEnd[MAX_REG_MSGS]; funEventCall modMsgs[MAX_REG_MSGS]; -void (*function)(void*); -void (*endfunction)(void*); +void (*function)(void *); +void (*endfunction)(void *); g_RegUserMsg g_user_msg[] = -{ - { "TeamInfo", &gmsgTeamInfo, Client_TeamInfo, false }, + { + {"TeamInfo", &gmsgTeamInfo, Client_TeamInfo, false}, }; -void* R_PvAllocEntPrivateData(edict_t *pEdict, int32 cb) { +void *R_PvAllocEntPrivateData(edict_t *pEdict, int32 cb) +{ Alloc_EntPrivateData(pEdict); RETURN_META_VALUE(MRES_IGNORED, 0); } @@ -37,40 +38,46 @@ void ED_Free_RH(IRehldsHook_ED_Free *chain, edict_t *pEdict) { edict_t* ED_Alloc_RH(IRehldsHook_ED_Alloc* chain) { auto origin = chain->callNext(); Alloc_EntPrivateData(origin); - return origin; + return origin; } */ -void Alloc_EntPrivateData(edict_t *pEdict) { - if (FStringNull(pEdict->v.classname)) return; - //UTIL_ServerPrint"[DEBUG] Alloc_EntPrivateData(): id = %d, classname = <%s>, owner = %d\n", ENTINDEX(pEdict), STRING(pEdict->v.classname), ENTINDEX(pEdict->v.owner)); +void Alloc_EntPrivateData(edict_t *pEdict) +{ + if (FStringNull(pEdict->v.classname)) + return; + // UTIL_ServerPrint"[DEBUG] Alloc_EntPrivateData(): id = %d, classname = <%s>, owner = %d\n", ENTINDEX(pEdict), STRING(pEdict->v.classname), ENTINDEX(pEdict->v.owner)); int entity_index = ENTINDEX(pEdict); std::string key = STRING(pEdict->v.classname); // ADD ENTITIES int result = trie_add(&g_Tries.entities, key, entity_index); - //UTIL_ServerPrint"[DEBUG] Alloc_EntPrivateData(): classname = <%s>, new_count = %d\n", key.c_str(), result); - // ADD CLASSNAMES + // UTIL_ServerPrint"[DEBUG] Alloc_EntPrivateData(): classname = <%s>, new_count = %d\n", key.c_str(), result); + // ADD CLASSNAMES g_Tries.classnames[entity_index] = key; // ADD WP_ENTITIES - if (key.find(WP_CLASS_PREFIX) == 0 && key.length() > WP_CLASS_PREFIX_LEN) { + if (key.find(WP_CLASS_PREFIX) == 0 && key.length() > WP_CLASS_PREFIX_LEN) + { vector_add(&g_Tries.wp_entities, entity_index); - //UTIL_ServerPrint"[DEBUG] Alloc_EntPrivateData(): WEAPONS, new_count = %d\n", result); + // UTIL_ServerPrint"[DEBUG] Alloc_EntPrivateData(): WEAPONS, new_count = %d\n", result); } } -void Free_EntPrivateData(edict_t *pEdict) { +void Free_EntPrivateData(edict_t *pEdict) +{ std::string key; int entity_index, owner_index; entity_index = ENTINDEX(pEdict); owner_index = ENTINDEX(pEdict->v.owner); - //UTIL_ServerPrint"[DEBUG] Free_EntPrivateData(): pEdict = %p, privdata = %p, free = %d, kill = %d, entity = %d, classname = <%s>, owner = %d\n", pEdict, pEdict->pvPrivateData, pEdict->free, pEdict->v.flags & FL_KILLME, entity_index, STRING(pEdict->v.classname), owner_index); - // CHECK CREATION CLASSNAME - if (pEdict == nullptr || pEdict->pvPrivateData == nullptr || pEdict->free || FStringNull(pEdict->v.classname)) { + // UTIL_ServerPrint"[DEBUG] Free_EntPrivateData(): pEdict = %p, privdata = %p, free = %d, kill = %d, entity = %d, classname = <%s>, owner = %d\n", pEdict, pEdict->pvPrivateData, pEdict->free, pEdict->v.flags & FL_KILLME, entity_index, STRING(pEdict->v.classname), owner_index); + // CHECK CREATION CLASSNAME + if (pEdict == nullptr || pEdict->pvPrivateData == nullptr || pEdict->free || FStringNull(pEdict->v.classname)) + { // WAS REGISTERED? - if (g_Tries.classnames.find(entity_index) != g_Tries.classnames.end()) { + if (g_Tries.classnames.find(entity_index) != g_Tries.classnames.end()) + { key = g_Tries.classnames[entity_index]; - //UTIL_ServerPrint"[DEBUG] Free_EntPrivateData(): found deleted entity = %d with creation_classname = <%s> << WARNING !!!\n", entity_index, key); - // REMOVE FROM ENTITIES + // UTIL_ServerPrint"[DEBUG] Free_EntPrivateData(): found deleted entity = %d with creation_classname = <%s> << WARNING !!!\n", entity_index, key); + // REMOVE FROM ENTITIES vector_remove(&g_Tries.entities[key], entity_index); // REMOVE PLAYER_ENTITIES if (is_valid_index(owner_index)) @@ -85,22 +92,24 @@ void Free_EntPrivateData(edict_t *pEdict) { } key = STRING(pEdict->v.classname); // CHECK ENTITY CREATION CLASS - if (key != g_Tries.classnames[entity_index]) { - //UTIL_ServerPrint"[DEBUG] Free_EntPrivateData(): entity = %d, classname = <%s> was changed from <%s> << WARNING !!!\n", entity_index, key.c_str(), g_Tries.classnames[entity_index].c_str()); + if (key != g_Tries.classnames[entity_index]) + { + // UTIL_ServerPrint"[DEBUG] Free_EntPrivateData(): entity = %d, classname = <%s> was changed from <%s> << WARNING !!!\n", entity_index, key.c_str(), g_Tries.classnames[entity_index].c_str()); key = g_Tries.classnames[entity_index]; } // REMOVE ENTITIES int result = trie_remove(&g_Tries.entities, key, entity_index); - //UTIL_ServerPrint"[DEBUG] Free_EntPrivateData(): remove entity = %d from classname = <%s>, new_count = %d\n", entity_index, key.c_str(), result); - // REMOVE PLAYER_ENTITIES + // UTIL_ServerPrint"[DEBUG] Free_EntPrivateData(): remove entity = %d from classname = <%s>, new_count = %d\n", entity_index, key.c_str(), result); + // REMOVE PLAYER_ENTITIES if (is_valid_index(owner_index)) vector_remove(&g_Tries.player_entities[owner_index], entity_index); // REMOVE CLASSNAME g_Tries.classnames.erase(entity_index); // REMOVE WP_ENTITIES - if (key.find(WP_CLASS_PREFIX) == 0 && key.length() > WP_CLASS_PREFIX_LEN) { + if (key.find(WP_CLASS_PREFIX) == 0 && key.length() > WP_CLASS_PREFIX_LEN) + { vector_remove(&g_Tries.wp_entities, entity_index); - //UTIL_ServerPrint"[DEBUG] Free_EntPrivateData(): WEAPONS, new_count = %d\n", result); + // UTIL_ServerPrint"[DEBUG] Free_EntPrivateData(): WEAPONS, new_count = %d\n", result); } } @@ -138,7 +147,7 @@ qboolean CBasePlayer_RemovePlayerItem_RG(IReGameHook_CBasePlayer_RemovePlayerIte if (is_valid_index(owner_index)) { vector_remove(&g_Tries.player_entities[owner_index], entity_index); - //UTIL_ServerPrint"[DEBUG] CBasePlayer_RemovePlayerItem_RG(): remove entity = %d from owner = %d\n", entity_index, owner_index); + // UTIL_ServerPrint"[DEBUG] CBasePlayer_RemovePlayerItem_RG(): remove entity = %d from owner = %d\n", entity_index, owner_index); } } return origin; @@ -153,21 +162,21 @@ qboolean CBasePlayer_AddPlayerItem_RG(IReGameHook_CBasePlayer_AddPlayerItem *cha int entity_index = pItem->entindex(); int owner_index = ENTINDEX(pItem->pev->owner); vector_add(&g_Tries.player_entities[id], entity_index); - //UTIL_ServerPrint"[DEBUG] AddPlayerItem_RG(): id = %d, entity = %d prev_owner = %d\n", id, entity_index, owner_index); - // FIX OWNER + // UTIL_ServerPrint"[DEBUG] AddPlayerItem_RG(): id = %d, entity = %d prev_owner = %d\n", id, entity_index, owner_index); + // FIX OWNER pItem->pev->owner = pPlayer->edict(); - //UTIL_ServerPrint("[DEBUG] AddPlayerItem_RG(): id = %d, entity = %d, item_classname = <%s>, item_owner = %d\n", pPlayer->entindex(), pItem->entindex(), STRING(pItem->pev->classname), owner_index); + // UTIL_ServerPrint("[DEBUG] AddPlayerItem_RG(): id = %d, entity = %d, item_classname = <%s>, item_owner = %d\n", pPlayer->entindex(), pItem->entindex(), STRING(pItem->pev->classname), owner_index); } return origin; } void R_ClientPutInServer_Post(edict_t *pEntity) { - //UTIL_ServerPrint("[DEBUG] ClientPutInServer_Post() ===>\n"); + // UTIL_ServerPrint("[DEBUG] ClientPutInServer_Post() ===>\n"); CBasePlayer *pPlayer = UTIL_PlayerByIndexSafe(ENTINDEX(pEntity)); if (pPlayer != nullptr && !pPlayer->IsBot()) Client_PutInServer(pEntity, STRING(pEntity->v.netname), false); - //Client_PutInServer(pEntity, STRING(pEntity->v.netname), false); + // Client_PutInServer(pEntity, STRING(pEntity->v.netname), false); RETURN_META(MRES_IGNORED); } @@ -182,33 +191,33 @@ void CBasePlayer_Killed_RG(IReGameHook_CBasePlayer_Killed *chain, CBasePlayer *p { if (g_Clients[pPlayer->entindex()].is_connected && is_valid_team(pPlayer->m_iTeam)) g_PlayersNum[TEAM_DEAD_TT + pPlayer->m_iTeam - 1]++; - //UTIL_ServerPrint("[DEBUG] KILL: num_unassigned = %d, num_tt = %d, num_ct = %d, num_spec = %d, num_dead_tt = %d, num_dead_ct = %d\n", - // g_PlayersNum[TEAM_UNASSIGNED], g_PlayersNum[TEAM_TERRORIST], g_PlayersNum[TEAM_CT], g_PlayersNum[TEAM_SPECTRATOR], g_PlayersNum[TEAM_DEAD_TT], g_PlayersNum[TEAM_DEAD_CT] + // UTIL_ServerPrint("[DEBUG] KILL: num_unassigned = %d, num_tt = %d, num_ct = %d, num_spec = %d, num_dead_tt = %d, num_dead_ct = %d\n", + // g_PlayersNum[TEAM_UNASSIGNED], g_PlayersNum[TEAM_TERRORIST], g_PlayersNum[TEAM_CT], g_PlayersNum[TEAM_SPECTRATOR], g_PlayersNum[TEAM_DEAD_TT], g_PlayersNum[TEAM_DEAD_CT] //); chain->callNext(pPlayer, pevAttacker, iGib); } -edict_t* CreateFakeClient_RH(IRehldsHook_CreateFakeClient *chain, const char *netname) +edict_t *CreateFakeClient_RH(IRehldsHook_CreateFakeClient *chain, const char *netname) { edict_t *pEntity = chain->callNext(netname); - //UTIL_ServerPrint("[DEBUG] CreateFakeClient(): id = %d, name = %s\n", ENTINDEX(pEntity), netname); + // UTIL_ServerPrint("[DEBUG] CreateFakeClient(): id = %d, name = %s\n", ENTINDEX(pEntity), netname); Client_PutInServer(pEntity, netname, true); return pEntity; } void R_ClientDisconnect(edict_t *pEntity) { - //UTIL_ServerPrint("[DEBUG] R_ClientDisconnect() ===>\n"); + // UTIL_ServerPrint("[DEBUG] R_ClientDisconnect() ===>\n"); Client_Disconnected(pEntity, false, 0); - RETURN_META(MRES_IGNORED); + RETURN_META(MRES_IGNORED); } void SV_DropClient_RH(IRehldsHook_SV_DropClient *chain, IGameClient *cl, bool crash, const char *format) { - + char buffer[1024]; - //UTIL_ServerPrint("[DEBUG] SV_DropClient_RH() ===>\n"); - Q_strcpy_s(buffer, (char*)format); + // UTIL_ServerPrint("[DEBUG] SV_DropClient_RH() ===>\n"); + Q_strcpy_s(buffer, (char *)format); Client_Disconnected(cl->GetEdict(), crash, buffer); chain->callNext(cl, crash, format); } @@ -216,22 +225,25 @@ void SV_DropClient_RH(IRehldsHook_SV_DropClient *chain, IGameClient *cl, bool cr void Client_PutInServer(edict_t *pEntity, const char *netname, const bool is_bot) { int id = ENTINDEX(pEntity); - if (is_valid_index(id)) { + if (is_valid_index(id)) + { g_Clients[id].is_bot = is_bot; g_Clients[id].is_connected = true; g_Clients[id].team = TEAM_UNASSIGNED; g_PlayersNum[TEAM_UNASSIGNED]++; - //UTIL_ServerPrint("[DEBUG] PutInServer_Post(): id = %d, name = %s, authid = %s, team = %d, is_connected = %d\n", id, netname, GETPLAYERAUTHID(pEntity), g_Clients[id].team, g_Clients[id].is_connected); - //UTIL_ServerPrint("[DEBUG] num_unassigned = %d, num_tt = %d, num_ct = %d, num_spec = %d\n", g_PlayersNum[TEAM_UNASSIGNED], g_PlayersNum[TEAM_TERRORIST], g_PlayersNum[TEAM_CT], g_PlayersNum[TEAM_SPECTRATOR]); + // UTIL_ServerPrint("[DEBUG] PutInServer_Post(): id = %d, name = %s, authid = %s, team = %d, is_connected = %d\n", id, netname, GETPLAYERAUTHID(pEntity), g_Clients[id].team, g_Clients[id].is_connected); + // UTIL_ServerPrint("[DEBUG] num_unassigned = %d, num_tt = %d, num_ct = %d, num_spec = %d\n", g_PlayersNum[TEAM_UNASSIGNED], g_PlayersNum[TEAM_TERRORIST], g_PlayersNum[TEAM_CT], g_PlayersNum[TEAM_SPECTRATOR]); } } void Client_Disconnected(edict_t *pEdict, bool crash, char *format) { int id = ENTINDEX(pEdict); - if (is_valid_index(id)) { - //UTIL_ServerPrint("[DEBUG] Client_Disconnected(): id = %d, is_connected = %d\n", id, g_Clients[id].is_connected); - if (g_Clients[id].is_connected) { + if (is_valid_index(id)) + { + // UTIL_ServerPrint("[DEBUG] Client_Disconnected(): id = %d, is_connected = %d\n", id, g_Clients[id].is_connected); + if (g_Clients[id].is_connected) + { g_Clients[id].is_connected = false; g_Clients[id].is_bot = false; ////UTIL_ServerPrint("[DEBUG] Client_Disconnected(): id = %d, name = %s\n", id, STRING(pPlayer->edict()->v.netname)); @@ -239,201 +251,247 @@ void Client_Disconnected(edict_t *pEdict, bool crash, char *format) // FIX TEAMS DEAD COUNT if (is_valid_entity(pEdict) && pEdict->v.deadflag != DEAD_NO && is_valid_team(g_Clients[id].team) && g_PlayersNum[TEAM_DEAD_TT + g_Clients[id].team - 1] > 0) g_PlayersNum[TEAM_DEAD_TT + g_Clients[id].team - 1]--; - //UTIL_ServerPrint("[DEBUG] DISCONNECT: num_unassigned = %d, num_tt = %d, num_ct = %d, num_spec = %d, num_dead_tt = %d, num_dead_ct = %d\n", - // g_PlayersNum[TEAM_UNASSIGNED], g_PlayersNum[TEAM_TERRORIST], g_PlayersNum[TEAM_CT], g_PlayersNum[TEAM_SPECTRATOR], g_PlayersNum[TEAM_DEAD_TT], g_PlayersNum[TEAM_DEAD_CT] + // UTIL_ServerPrint("[DEBUG] DISCONNECT: num_unassigned = %d, num_tt = %d, num_ct = %d, num_spec = %d, num_dead_tt = %d, num_dead_ct = %d\n", + // g_PlayersNum[TEAM_UNASSIGNED], g_PlayersNum[TEAM_TERRORIST], g_PlayersNum[TEAM_CT], g_PlayersNum[TEAM_SPECTRATOR], g_PlayersNum[TEAM_DEAD_TT], g_PlayersNum[TEAM_DEAD_CT] //); } } } -void Client_TeamInfo(void* m_value) +void Client_TeamInfo(void *m_value) { static int id; char *msg; TEAMS_t new_team; - switch (m_state++) { - case 0: - id = *(int*)m_value; - break; - case 1: - if (!is_valid_index(id)) break; - msg = (char*)m_value; - if (!msg) break; - switch (msg[0]) { - case 'T': - new_team = TEAM_TERRORIST; - break; - case 'C': - new_team = TEAM_CT; - break; - case 'S': - new_team = TEAM_SPECTRATOR; - break; - default: new_team = TEAM_UNASSIGNED; - } - //UTIL_ServerPrint("[DEBUG] id = %d, old_team = %d, new_team = %d\n", id, g_Clients[id].team, new_team); - if (!g_Clients[id].is_connected) { - g_Clients[id].team = new_team; - } else if (new_team != TEAM_UNASSIGNED && g_Clients[id].team != new_team) { - edict_t* pEdict = INDEXENT(id); - // FIX TEAMS DEAD COUNT - if (is_valid_entity(pEdict) && pEdict->v.deadflag != DEAD_NO) { - if (is_valid_team(g_Clients[id].team) && g_PlayersNum[TEAM_DEAD_TT + g_Clients[id].team - 1] > 0) - g_PlayersNum[TEAM_DEAD_TT + g_Clients[id].team - 1]--; - if (is_valid_team(new_team) && g_PlayersNum[TEAM_DEAD_TT + new_team - 1] > 0) - g_PlayersNum[TEAM_DEAD_TT + new_team - 1]++; - } - //UTIL_ServerPrint("[DEBUG] Team changed!!!\n"); - g_PlayersNum[g_Clients[id].team]--; - g_PlayersNum[new_team]++; - g_Clients[id].team = new_team; - //UTIL_ServerPrint("[DEBUG] num_unassigned = %d, num_tt = %d, num_ct = %d, num_spec = %d, num_dead_tt = %d, num_dead_ct = %d\n", - // g_PlayersNum[TEAM_UNASSIGNED], g_PlayersNum[TEAM_TERRORIST], g_PlayersNum[TEAM_CT], g_PlayersNum[TEAM_SPECTRATOR], g_PlayersNum[TEAM_DEAD_TT], g_PlayersNum[TEAM_DEAD_CT] - //); + switch (m_state++) + { + case 0: + id = *(int *)m_value; + break; + case 1: + if (!is_valid_index(id)) + break; + msg = (char *)m_value; + if (!msg) + break; + switch (msg[0]) + { + case 'T': + new_team = TEAM_TERRORIST; + break; + case 'C': + new_team = TEAM_CT; + break; + case 'S': + new_team = TEAM_SPECTRATOR; + break; + default: + new_team = TEAM_UNASSIGNED; + } + // UTIL_ServerPrint("[DEBUG] id = %d, old_team = %d, new_team = %d\n", id, g_Clients[id].team, new_team); + if (!g_Clients[id].is_connected) + { + g_Clients[id].team = new_team; + } + else if (new_team != TEAM_UNASSIGNED && g_Clients[id].team != new_team) + { + edict_t *pEdict = INDEXENT(id); + // FIX TEAMS DEAD COUNT + if (is_valid_entity(pEdict) && pEdict->v.deadflag != DEAD_NO) + { + if (is_valid_team(g_Clients[id].team) && g_PlayersNum[TEAM_DEAD_TT + g_Clients[id].team - 1] > 0) + g_PlayersNum[TEAM_DEAD_TT + g_Clients[id].team - 1]--; + if (is_valid_team(new_team) && g_PlayersNum[TEAM_DEAD_TT + new_team - 1] > 0) + g_PlayersNum[TEAM_DEAD_TT + new_team - 1]++; } - // FIX TEAM - edict_t* pEdict = INDEXENT(id); - if (is_valid_entity(pEdict)) - pEdict->v.team = new_team; + // UTIL_ServerPrint("[DEBUG] Team changed!!!\n"); + g_PlayersNum[g_Clients[id].team]--; + g_PlayersNum[new_team]++; + g_Clients[id].team = new_team; + // UTIL_ServerPrint("[DEBUG] num_unassigned = %d, num_tt = %d, num_ct = %d, num_spec = %d, num_dead_tt = %d, num_dead_ct = %d\n", + // g_PlayersNum[TEAM_UNASSIGNED], g_PlayersNum[TEAM_TERRORIST], g_PlayersNum[TEAM_CT], g_PlayersNum[TEAM_SPECTRATOR], g_PlayersNum[TEAM_DEAD_TT], g_PlayersNum[TEAM_DEAD_CT] + //); + } + // FIX TEAM + edict_t *pEdict = INDEXENT(id); + if (is_valid_entity(pEdict)) + pEdict->v.team = new_team; } } -int R_RegUserMsg_Post(const char *pszName, int iSize) +int R_RegUserMsg_Post(const char *pszName, int iSize) { - for (auto& msg : g_user_msg) { - if (strcmp(msg.name, pszName) == 0) { - int id = META_RESULT_ORIG_RET(int); - //UTIL_ServerPrint("[DEBUG] RegUserMsg: id = %d, %s\n", id, pszName); + for (auto &msg : g_user_msg) + { + if (strcmp(msg.name, pszName) == 0) + { + int id = META_RESULT_ORIG_RET(int); + // UTIL_ServerPrint("[DEBUG] RegUserMsg: id = %d, %s\n", id, pszName); *msg.id = id; if (msg.endmsg) - modMsgsEnd[id] = msg.func; + modMsgsEnd[id] = msg.func; else - modMsgs[id] = msg.func; - break; + modMsgs[id] = msg.func; + break; } - } - RETURN_META_VALUE(MRES_IGNORED, 0); + } + RETURN_META_VALUE(MRES_IGNORED, 0); } -void R_MessageBegin_Post(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed) { +void R_MessageBegin_Post(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed) +{ m_state = 0; - function = modMsgs[msg_type]; + function = modMsgs[msg_type]; endfunction = modMsgsEnd[msg_type]; - RETURN_META(MRES_IGNORED); + RETURN_META(MRES_IGNORED); } -void R_WriteByte_Post(int iValue) { - if (function) (*function)((void *)&iValue); - RETURN_META(MRES_IGNORED); +void R_WriteByte_Post(int iValue) +{ + if (function) + (*function)((void *)&iValue); + RETURN_META(MRES_IGNORED); } -void R_WriteChar_Post(int iValue) { - if (function) (*function)((void *)&iValue); - RETURN_META(MRES_IGNORED); +void R_WriteChar_Post(int iValue) +{ + if (function) + (*function)((void *)&iValue); + RETURN_META(MRES_IGNORED); } -void R_WriteShort_Post(int iValue) { - if (function) (*function)((void *)&iValue); - RETURN_META(MRES_IGNORED); +void R_WriteShort_Post(int iValue) +{ + if (function) + (*function)((void *)&iValue); + RETURN_META(MRES_IGNORED); } -void R_WriteLong_Post(int iValue) { - if (function) (*function)((void *)&iValue); - RETURN_META(MRES_IGNORED); +void R_WriteLong_Post(int iValue) +{ + if (function) + (*function)((void *)&iValue); + RETURN_META(MRES_IGNORED); } -void R_WriteAngle_Post(float flValue) { - if (function) (*function)((void *)&flValue); - RETURN_META(MRES_IGNORED); +void R_WriteAngle_Post(float flValue) +{ + if (function) + (*function)((void *)&flValue); + RETURN_META(MRES_IGNORED); } -void R_WriteCoord_Post(float flValue) { - if (function) (*function)((void *)&flValue); - RETURN_META(MRES_IGNORED); +void R_WriteCoord_Post(float flValue) +{ + if (function) + (*function)((void *)&flValue); + RETURN_META(MRES_IGNORED); } -void R_WriteString_Post(const char *sz) { - if (function) (*function)((void *)sz); - RETURN_META(MRES_IGNORED); +void R_WriteString_Post(const char *sz) +{ + if (function) + (*function)((void *)sz); + RETURN_META(MRES_IGNORED); } -void R_WriteEntity_Post(int iValue) { - if (function) (*function)((void *)&iValue); - RETURN_META(MRES_IGNORED); +void R_WriteEntity_Post(int iValue) +{ + if (function) + (*function)((void *)&iValue); + RETURN_META(MRES_IGNORED); } -void R_MessageEnd_Post(void) { - if (endfunction) (*endfunction)(NULL); - RETURN_META(MRES_IGNORED); +void R_MessageEnd_Post(void) +{ + if (endfunction) + (*endfunction)(NULL); + RETURN_META(MRES_IGNORED); } -int trie_add(std::map>* trie, std::string key, int value) { +int trie_add(std::map> *trie, std::string key, int value) +{ std::vector v; if (trie->find(key) != trie->end()) v = (*trie)[key]; - - if (v.size() < v.max_size()) { + + if (v.size() < v.max_size()) + { v.push_back(value); (*trie)[key] = v; } return v.size(); } -int trie_remove(std::map>* trie, std::string key, int value) { +int trie_remove(std::map> *trie, std::string key, int value) +{ std::vector v; std::vector::iterator it_value; - if (trie->find(key) != trie->end()) { + if (trie->find(key) != trie->end()) + { v = (*trie)[key]; - if ((it_value = std::find(v.begin(), v.end(), value)) != v.end()) { + if ((it_value = std::find(v.begin(), v.end(), value)) != v.end()) + { v.erase(it_value); if (v.size() > 0) - (*trie)[key] = v; + (*trie)[key] = v; else - trie->erase(key); + trie->erase(key); } } return v.size(); } -void trie_transfer(std::map>* trie, std::string key_from, std::string key_to, int value) { +void trie_transfer(std::map> *trie, std::string key_from, std::string key_to, int value) +{ trie_remove(trie, key_from, value); - + g_Tries.classnames[value] = key_to; trie_add(trie, key_to, value); } -int vector_add(std::vector *v, int value) { +int vector_add(std::vector *v, int value) +{ v->push_back(value); return v->size(); } -int vector_remove(std::vector *v, int value) { +int vector_remove(std::vector *v, int value) +{ std::vector::iterator it_value; if ((it_value = std::find(v->begin(), v->end(), value)) != v->end()) v->erase(it_value); return v->size(); } -bool get_user_buyzone(const edict_t *pEdict) { +bool get_user_buyzone(const edict_t *pEdict) +{ bool result = false; - //UTIL_ServerPrint("[DEBUG] get_user_buyzone(): id = %d, team = %d, classname = %s\n", ENTINDEX(pEdict), pEdict->v.team, STRING(pEdict->v.classname)); - if (is_valid_entity(pEdict) && is_valid_team(pEdict->v.team) && pEdict->v.deadflag == DEAD_NO) { - if (r_bMapHasBuyZone) { - //UTIL_ServerPrint("[DEBUG] get_user_buyzone(): zone_count = %d\n", g_Tries.entities["func_buyzone"].size()); - for (auto& buyzone : g_Tries.entities["func_buyzone"]) { - edict_t* pBuyZone = INDEXENT(buyzone); - //UTIL_ServerPrint("[DEBUG] get_user_buyzone(): entity = %d, team = %d\n", buyzone, pBuyZone->v.team); - if (is_valid_entity(pBuyZone) && pEdict->v.team == pBuyZone->v.team && is_entity_intersects(pEdict, pBuyZone)) { + // UTIL_ServerPrint("[DEBUG] get_user_buyzone(): id = %d, team = %d, classname = %s\n", ENTINDEX(pEdict), pEdict->v.team, STRING(pEdict->v.classname)); + if (is_valid_entity(pEdict) && is_valid_team(pEdict->v.team) && pEdict->v.deadflag == DEAD_NO) + { + if (r_bMapHasBuyZone) + { + // UTIL_ServerPrint("[DEBUG] get_user_buyzone(): zone_count = %d\n", g_Tries.entities["func_buyzone"].size()); + for (auto &buyzone : g_Tries.entities["func_buyzone"]) + { + edict_t *pBuyZone = INDEXENT(buyzone); + // UTIL_ServerPrint("[DEBUG] get_user_buyzone(): entity = %d, team = %d\n", buyzone, pBuyZone->v.team); + if (is_valid_entity(pBuyZone) && pEdict->v.team == pBuyZone->v.team && is_entity_intersects(pEdict, pBuyZone)) + { result = true; break; } } - - } else { - for (auto& spawn : g_Tries.entities[pEdict->v.team == TEAM_TERRORIST ? "info_player_deathmatch" : "info_player_start"]) { - edict_t* pSpawn = INDEXENT(spawn); - //UTIL_ServerPrint("[DEBUG] get_user_buyzone(): spawn = %d, classname = %s, kill = %d\n", spawn, STRING(pSpawn->v.classname), (pSpawn->v.flags & FL_KILLME)); - if (is_valid_entity(pSpawn) && (pSpawn->v.origin - pEdict->v.origin).Length() < 200.0f) { + } + else + { + for (auto &spawn : g_Tries.entities[pEdict->v.team == TEAM_TERRORIST ? "info_player_deathmatch" : "info_player_start"]) + { + edict_t *pSpawn = INDEXENT(spawn); + // UTIL_ServerPrint("[DEBUG] get_user_buyzone(): spawn = %d, classname = %s, kill = %d\n", spawn, STRING(pSpawn->v.classname), (pSpawn->v.flags & FL_KILLME)); + if (is_valid_entity(pSpawn) && (pSpawn->v.origin - pEdict->v.origin).Length() < 200.0f) + { result = true; break; } diff --git a/refsapi.h b/refsapi.h index ce0dcc6..80e882f 100644 --- a/refsapi.h +++ b/refsapi.h @@ -4,25 +4,28 @@ // gets rid of annoying "deprecated conversion from string constant blah blah" warning #pragma GCC diagnostic ignored "-Wwrite-strings" -#define MAX_PLAYERS 32 -#define DECIMAL_POINT '.' -#define WP_CLASS_PREFIX "weapon_" -#define WP_CLASS_PREFIX_LEN (sizeof(WP_CLASS_PREFIX) - 1) -#define REFSAPI_CVAR "acs_refsapi_loaded" -#define check_it_empty(x) ((x)._M_node == nullptr) -#define check_it_empty_r(x) if (check_it_empty(x)) return +#define MAX_PLAYERS 32 +#define DECIMAL_POINT '.' +#define WP_CLASS_PREFIX "weapon_" +#define WP_CLASS_PREFIX_LEN (sizeof(WP_CLASS_PREFIX) - 1) +#define REFSAPI_CVAR "acs_refsapi_loaded" +#define check_it_empty(x) ((x)._M_node == nullptr) +#define check_it_empty_r(x) \ + if (check_it_empty(x)) \ + return -#define _QQ "\"'`" -#define _TRIM_CHARS " \r\t\n" -#define _LOCALE std::locale("ru_RU.UTF-8") -#define _COUNT(x) (size_t)(sizeof(x)/sizeof(cell)) +#define _QQ "\"'`" +#define _TRIM_CHARS " \r\t\n" +#define _LOCALE std::locale("ru_RU.UTF-8") +#define _COUNT(x) (size_t)(sizeof(x) / sizeof(cell)) -#define amx_ftoc(f) ( * ((cell*)&f) ) /* float to cell */ -#define amx_ctof(c) ( * ((float*)&c) ) /* cell to float */ +#define amx_ftoc(f) (*((cell *)&f)) /* float to cell */ +#define amx_ctof(c) (*((float *)&c)) /* cell to float */ -typedef void (*funEventCall)(void*); +typedef void (*funEventCall)(void *); -typedef enum TEAMS_e{ +typedef enum TEAMS_e +{ TEAM_UNASSIGNED, TEAM_TERRORIST, @@ -33,28 +36,30 @@ typedef enum TEAMS_e{ } TEAMS_t; -struct g_RegUserMsg { +struct g_RegUserMsg +{ - const char* name; - int* id; - funEventCall func; + const char *name; + int *id; + funEventCall func; bool endmsg; - }; -struct sTries { +struct sTries +{ std::map names; std::map authids; - std::map> entities; // all entities - std::vector wp_entities; // has classname weapon_* + std::map> entities; // all entities + std::vector wp_entities; // has classname weapon_* std::map classnames; std::vector player_entities[MAX_PLAYERS + 1]; - //std::map> ips; - //std::map> ips_int; + // std::map> ips; + // std::map> ips_int; }; -struct sClients { +struct sClients +{ bool is_connected; bool is_bot; TEAMS_t team; @@ -74,27 +79,27 @@ extern std::wstring_convert g_converter; extern funEventCall modMsgsEnd[MAX_REG_MSGS]; extern funEventCall modMsgs[MAX_REG_MSGS]; -extern void (*function)(void*); -extern void (*endfunction)(void*); +extern void (*function)(void *); +extern void (*endfunction)(void *); -edict_t* CreateFakeClient_RH(IRehldsHook_CreateFakeClient *chain, const char *netname); +edict_t *CreateFakeClient_RH(IRehldsHook_CreateFakeClient *chain, const char *netname); void SV_DropClient_RH(IRehldsHook_SV_DropClient *chain, IGameClient *cl, bool crash, const char *format); -//edict_t* ED_Alloc_RH(IRehldsHook_ED_Alloc* chain); -//void ED_Free_RH(IRehldsHook_ED_Free *chain, edict_t *pEdict); +// edict_t* ED_Alloc_RH(IRehldsHook_ED_Alloc* chain); +// void ED_Free_RH(IRehldsHook_ED_Free *chain, edict_t *pEdict); void CBasePlayer_Killed_RG(IReGameHook_CBasePlayer_Killed *chain, CBasePlayer *pPlayer, entvars_t *pevAttacker, int iGib); void CSGameRules_CheckMapConditions_RG(IReGameHook_CSGameRules_CheckMapConditions *chain); qboolean CBasePlayer_AddPlayerItem_RG(IReGameHook_CBasePlayer_AddPlayerItem *chain, CBasePlayer *pPlayer, class CBasePlayerItem *pItem); qboolean CBasePlayer_RemovePlayerItem_RG(IReGameHook_CBasePlayer_RemovePlayerItem *chain, CBasePlayer *pthis, CBasePlayerItem *pItem); -CBaseEntity* CBasePlayer_GiveNamedItem_RG(IReGameHook_CBasePlayer_GiveNamedItem *chain, CBasePlayer *pPlayer, const char *classname); +CBaseEntity *CBasePlayer_GiveNamedItem_RG(IReGameHook_CBasePlayer_GiveNamedItem *chain, CBasePlayer *pPlayer, const char *classname); qboolean CSGameRules_CanHavePlayerItem_RG(IReGameHook_CSGameRules_CanHavePlayerItem *chain, CBasePlayer *pPlayer, CBasePlayerItem *pItem); -CWeaponBox* CreateWeaponBox_RG(IReGameHook_CreateWeaponBox *chain, CBasePlayerItem *pItem, CBasePlayer *pPlayer, const char *model, Vector &v_origin, Vector &v_angels, Vector &v_velocity, float life_time, bool pack_ammo); +CWeaponBox *CreateWeaponBox_RG(IReGameHook_CreateWeaponBox *chain, CBasePlayerItem *pItem, CBasePlayer *pPlayer, const char *model, Vector &v_origin, Vector &v_angels, Vector &v_velocity, float life_time, bool pack_ammo); void CBasePlayer_Spawn_RG(IReGameHook_CBasePlayer_Spawn *chain, CBasePlayer *pPlayer); void R_ClientPutInServer_Post(edict_t *pEntity); void R_ClientDisconnect(edict_t *pEntity); -void* R_PvAllocEntPrivateData(edict_t *pEdict, int32 cb); -int R_RegUserMsg_Post(const char *pszName, int iSize); +void *R_PvAllocEntPrivateData(edict_t *pEdict, int32 cb); +int R_RegUserMsg_Post(const char *pszName, int iSize); void R_MessageBegin_Post(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed); void R_WriteByte_Post(int iValue); void R_WriteChar_Post(int iValue); @@ -106,15 +111,15 @@ void R_WriteString_Post(const char *sz); void R_WriteEntity_Post(int iValue); void R_MessageEnd_Post(void); -void Client_TeamInfo(void*); +void Client_TeamInfo(void *); void Client_PutInServer(edict_t *pEntity, const char *netname, const bool is_bot); void Client_Disconnected(edict_t *pEdict, bool crash, char *format); void Alloc_EntPrivateData(edict_t *pEdict); void Free_EntPrivateData(edict_t *pEdict); -int trie_add(std::map>* trie, std::string key, int value); -int trie_remove(std::map>* trie, std::string key, int value); -void trie_transfer(std::map>* trie, std::string key_from, std::string key_to, int value); +int trie_add(std::map> *trie, std::string key, int value); +int trie_remove(std::map> *trie, std::string key, int value); +void trie_transfer(std::map> *trie, std::string key_from, std::string key_to, int value); int vector_add(std::vector *v, int value); int vector_remove(std::vector *v, int value); bool get_user_buyzone(const edict_t *pEdict); \ No newline at end of file diff --git a/refsapi_cvar_mngr.cpp b/refsapi_cvar_mngr.cpp index 6eaa6ff..5483a07 100644 --- a/refsapi_cvar_mngr.cpp +++ b/refsapi_cvar_mngr.cpp @@ -8,12 +8,12 @@ void Cvar_RegisterVariable_Post(cvar_t *cvar) void Cvar_DirectSet_RH(IRehldsHook_Cvar_DirectSet *chain, cvar_t *cvar, const char *value) { chain->callNext(cvar, value); - //UTIL_ServerPrint("[DEBUG] Cvar_DirectSet_RH(): cvar = <%s>, string = <%s>, value = %f\n", cvar->name, cvar->string, cvar->value); + // UTIL_ServerPrint("[DEBUG] Cvar_DirectSet_RH(): cvar = <%s>, string = <%s>, value = %f\n", cvar->name, cvar->string, cvar->value); g_cvar_mngr.on_direct_set(cvar, stows(value)); } void CVarRegister_Post(cvar_t *cvar) { - //UTIL_ServerPrint("[DEBUG] CVarRegister_Post(): cvar = <%s>, string = <%s>, value = %f\n", cvar->name, cvar->string, cvar->value); + // UTIL_ServerPrint("[DEBUG] CVarRegister_Post(): cvar = <%s>, string = <%s>, value = %f\n", cvar->name, cvar->string, cvar->value); g_cvar_mngr.on_register(cvar); } diff --git a/refsapi_cvar_mngr.h b/refsapi_cvar_mngr.h index 0428c19..4de32c9 100644 --- a/refsapi_cvar_mngr.h +++ b/refsapi_cvar_mngr.h @@ -34,7 +34,7 @@ typedef struct m_cvar_s typedef struct ptr_bind_s { - cell* ptr; + cell *ptr; uint8_t type; size_t size; } ptr_bind_t; @@ -53,22 +53,22 @@ typedef cvar_list_t::iterator cvar_list_it; typedef std::map> plugin_cvar_t; typedef plugin_cvar_t::iterator plugin_cvar_it; -typedef std::map p_cvar_t; +typedef std::map p_cvar_t; typedef p_cvar_t::iterator p_cvar_it; -typedef std::map> cvar_bind_t; +typedef std::map> cvar_bind_t; typedef cvar_bind_t::iterator cvar_bind_it; typedef std::map cvar_hook_state_t; typedef cvar_hook_state_t::iterator cvar_hook_state_it; -typedef std::map> cvar_hook_list_t; +typedef std::map> cvar_hook_list_t; typedef cvar_hook_list_t::iterator cvar_hook_list_it; typedef struct cvar_mngr_s { cvar_list_t cvar_list; - plugin_cvar_t plugin; + plugin_cvar_t plugin; p_cvar_t p_cvar; cvar_bind_t bind_list; cvar_hook_state_t hook_state; @@ -82,7 +82,7 @@ class cvar_mngr private: bool check_range(m_cvar_t *m_cvar) { - //UTIL_ServerPrint("[DEBUG] check_range(): type = %d, name = <%s>, value = <%s>\n", m_cvar->type, m_cvar->cvar->name, m_cvar->cvar->string); + // UTIL_ServerPrint("[DEBUG] check_range(): type = %d, name = <%s>, value = <%s>\n", m_cvar->type, m_cvar->cvar->name, m_cvar->cvar->string); if (m_cvar->type == CVAR_TYPE_NONE || m_cvar->type == CVAR_TYPE_STR) return true; // Is number? @@ -90,7 +90,7 @@ class cvar_mngr if (!is_number(s)) { // Fix wrong value for bind - //UTIL_ServerPrint("[DEBUG] check_range(): wrong non-number value <%s>\n", s.c_str()); + // UTIL_ServerPrint("[DEBUG] check_range(): wrong non-number value <%s>\n", s.c_str()); CVAR_SET_STRING(m_cvar->cvar->name, "0"); return false; } @@ -99,9 +99,9 @@ class cvar_mngr // Check bind type and conver if (m_cvar->type == CVAR_TYPE_NUM) result = result >= 0.0 ? (int)result : -(int)(-result); - //UTIL_ServerPrint("[DEBUG] check_range(): in = %s, out = %f\n", s.c_str(), result); - //UTIL_ServerPrint("[DEBUG] check_range(): has_min = %d, min_val = %f, has_max = %d, max_val = %f\n", m_cvar->has_min, m_cvar->min_val, m_cvar->has_max, m_cvar->max_val); - // Check override + // UTIL_ServerPrint("[DEBUG] check_range(): in = %s, out = %f\n", s.c_str(), result); + // UTIL_ServerPrint("[DEBUG] check_range(): has_min = %d, min_val = %f, has_max = %d, max_val = %f\n", m_cvar->has_min, m_cvar->min_val, m_cvar->has_max, m_cvar->max_val); + // Check override if ((is_override |= (m_cvar->has_min && result < m_cvar->min_val))) result = m_cvar->min_val; else if ((is_override |= (m_cvar->has_max && result > m_cvar->max_val))) @@ -109,7 +109,7 @@ class cvar_mngr // Fix overriden if (is_override) { - //UTIL_ServerPrint("[DEBUG] check_range(): override = %s, new_string = %f\n", s.c_str(), result); + // UTIL_ServerPrint("[DEBUG] check_range(): override = %s, new_string = %f\n", s.c_str(), result); CVAR_SET_FLOAT(wstos(m_cvar->name).c_str(), result); } return !is_override; @@ -118,20 +118,25 @@ class cvar_mngr { switch (bind->type) { - case CVAR_TYPE_NUM: - *bind->ptr = (int)std::stof(cvar->string); - break; - case CVAR_TYPE_FLT: - *bind->ptr = amx_ftoc(cvar->value); - break; - case CVAR_TYPE_STR: - //UTIL_ServerPrint("[DEBUG] copy_bind(): from = %s, size = %d\n", cvar->string, bind->size); - setAmxString(bind->ptr, cvar->string, bind->size); + case CVAR_TYPE_NUM: + *bind->ptr = (int)std::stof(cvar->string); + break; + case CVAR_TYPE_FLT: + *bind->ptr = amx_ftoc(cvar->value); + break; + case CVAR_TYPE_STR: + // UTIL_ServerPrint("[DEBUG] copy_bind(): from = %s, size = %d\n", cvar->string, bind->size); + setAmxString(bind->ptr, cvar->string, bind->size); } } - cvar_t* create_cvar(std::wstring name, std::wstring value, int flags = 0) - { - enum { _name, _value, _count }; + cvar_t *create_cvar(std::wstring name, std::wstring value, int flags = 0) + { + enum + { + _name, + _value, + _count + }; // Copy params std::string p[_count] = {wstos(name), wstos(value)}; auto p_name = p[_name].data(); @@ -147,10 +152,10 @@ class cvar_mngr cvar.value = 0.0f; cvar.flags = flags; cvar.next = nullptr; - //UTIL_ServerPrint("[DEBUG] create_cvar(): name = <%s>, value = <%s>\n", cvar.name, cvar.string); + // UTIL_ServerPrint("[DEBUG] create_cvar(): name = <%s>, value = <%s>\n", cvar.name, cvar.string); CVAR_REGISTER(&cvar); p_cvar = CVAR_GET_POINTER(p_name); - //UTIL_ServerPrint("[DEBUG] create_cvar(): is_created = %d\n", p_cvar != nullptr); + // UTIL_ServerPrint("[DEBUG] create_cvar(): is_created = %d\n", p_cvar != nullptr); } return p_cvar; } @@ -158,7 +163,7 @@ class cvar_mngr public: bool need_update(load_cvars_t &load_cvars, plugin_cvar_it plugin_cvars) { - for (auto& cvar_it : plugin_cvars->second) + for (auto &cvar_it : plugin_cvars->second) { if (load_cvars.find(cvar_it->first) == load_cvars.end()) return true; @@ -182,24 +187,24 @@ class cvar_mngr cvar_list_it cvar_list = get(cvar); check_it_empty_r(cvar_list); // Get m_cvar - m_cvar_t* m_cvar = &cvar_list->second; + m_cvar_t *m_cvar = &cvar_list->second; // Value not changed? if (m_cvar->value.compare(value) == 0) return; // Bind non-exists? if (m_cvar->type == CVAR_TYPE_NONE) { - //if (strcmp(cvar->name, "mp_timeleft") != 0) - // UTIL_ServerPrint("[DEBUG] on_direct_set(): NOT BIND => type = %d, name = <%s>, string = <%s>, value = %f\n", m_cvar->type, cvar->name, cvar->string, cvar->value); - // Save new value + // if (strcmp(cvar->name, "mp_timeleft") != 0) + // UTIL_ServerPrint("[DEBUG] on_direct_set(): NOT BIND => type = %d, name = <%s>, string = <%s>, value = %f\n", m_cvar->type, cvar->name, cvar->string, cvar->value); + // Save new value m_cvar->value = value; return; } // Check range if (!check_range(m_cvar)) return; - //UTIL_ServerPrint("[DEBUG] on_direct_set(): cvar_t = %d, cvar_list = %d <===\n", cvar, cvar_list->second.cvar); - // Do event + // UTIL_ServerPrint("[DEBUG] on_direct_set(): cvar_t = %d, cvar_list = %d <===\n", cvar, cvar_list->second.cvar); + // Do event on_change(cvar_list, value); // Save new value m_cvar->value = value; @@ -207,7 +212,7 @@ class cvar_mngr void bind(CPluginMngr::CPlugin *plugin, CVAR_TYPES_t type, cvar_list_it cvar_list, cell *ptr, size_t size = 0) { check_it_empty_r(cvar_list); - m_cvar_t* m_cvar = &cvar_list->second; + m_cvar_t *m_cvar = &cvar_list->second; // Check previos type of m_cvar if (m_cvar->type != CVAR_TYPE_NONE && m_cvar->type != type) { @@ -226,10 +231,11 @@ class cvar_mngr { // Finding exists record with same (ptr & size) auto result = std::find_if(bind_list.begin(), bind_list.end(), [&](ptr_bind_t b) + { + return (b.ptr == ptr); // && (b.size = size); + }); + if (result != bind_list.end()) { - return (b.ptr == ptr); // && (b.size = size); - }); - if (result != bind_list.end()) { AMXX_LogError(plugin->getAMX(), AMX_ERR_NATIVE, "%s: cvar <%s> is already binded on this global variable\n", __FUNCTION__, wstos(cvar_list->first).c_str()); return; } @@ -246,8 +252,8 @@ class cvar_mngr bind_it->second = bind_list; else cvars.bind_list[m_cvar->cvar] = bind_list; - //UTIL_ServerPrint("[DEBUG] bind(): type = %d, name = %s, value = <%s>, cvar = %d, size = %d\n", m_cvar->type, m_cvar->cvar->name, m_cvar->cvar->string, m_cvar->cvar, size); - // Set m_cvar type + // UTIL_ServerPrint("[DEBUG] bind(): type = %d, name = %s, value = <%s>, cvar = %d, size = %d\n", m_cvar->type, m_cvar->cvar->name, m_cvar->cvar->string, m_cvar->cvar, size); + // Set m_cvar type m_cvar->type = type; // Check range check_range(m_cvar); @@ -255,27 +261,27 @@ class cvar_mngr void on_change(cvar_list_it cvar_list, std::wstring &new_value) { check_it_empty_r(cvar_list); - m_cvar_t* m_cvar = &cvar_list->second; + m_cvar_t *m_cvar = &cvar_list->second; cvar_bind_it bind_it; // Bind exists? if ((bind_it = cvars.bind_list.find(m_cvar->cvar)) != cvars.bind_list.end()) { - //UTIL_ServerPrint("[DEBUG] on_change(): name = <%s>, old_value = <%s>, new_value = <%s>\n", wstos(m_cvar->name).c_str(), wstos(m_cvar->value).c_str(), wstos(new_value).c_str()); - for (auto& bind : bind_it->second) + // UTIL_ServerPrint("[DEBUG] on_change(): name = <%s>, old_value = <%s>, new_value = <%s>\n", wstos(m_cvar->name).c_str(), wstos(m_cvar->value).c_str(), wstos(new_value).c_str()); + for (auto &bind : bind_it->second) copy_bind(&bind, m_cvar->cvar); } // Hook exists? cvar_hook_list_it hook_it; if ((hook_it = cvars.cvar_hook_list.find(m_cvar->cvar)) != cvars.cvar_hook_list.end()) { - for (auto& h : hook_it->second) + for (auto &h : hook_it->second) { - //UTIL_ServerPrint("[DEBUG] on_change(): exec hook = %d, enabled = %d\n", h->first, h->second); + // UTIL_ServerPrint("[DEBUG] on_change(): exec hook = %d, enabled = %d\n", h->first, h->second); if (h->second) - g_amxxapi.ExecuteForward(h->first, (cell)((void*)(m_cvar->cvar)), wstos(m_cvar->value).c_str(), wstos(new_value).c_str()); + g_amxxapi.ExecuteForward(h->first, (cell)((void *)(m_cvar->cvar)), wstos(m_cvar->value).c_str(), wstos(new_value).c_str()); } - }// else - //UTIL_ServerPrint("[DEBUG] on_change(): hook for cvar <%d> not found !!!\n", m_cvar->cvar); + } // else + // UTIL_ServerPrint("[DEBUG] on_change(): hook for cvar <%d> not found !!!\n", m_cvar->cvar); } cvar_list_it add_exists(cvar_t *cvar, std::wstring desc = L"", bool has_min = false, float min_val = 0.0f, bool has_max = false, float max_val = 0.0f) { @@ -299,11 +305,11 @@ class cvar_mngr m_cvar.has_max = has_max; m_cvar.max_val = max_val; // Save cvars list - auto result = cvars.cvar_list.insert({ m_cvar.name, m_cvar }); + auto result = cvars.cvar_list.insert({m_cvar.name, m_cvar}); if (result.second) { - //UTIL_ServerPrint("[DEBUG] add_exists(): cvar = %d, name = <%s>, value = <%s>\n", m_cvar.cvar, wstos(m_cvar.name).c_str(), wstos(m_cvar.value).c_str()); - cvars.p_cvar.insert({ m_cvar.cvar, result.first }); + // UTIL_ServerPrint("[DEBUG] add_exists(): cvar = %d, name = <%s>, value = <%s>\n", m_cvar.cvar, wstos(m_cvar.name).c_str(), wstos(m_cvar.value).c_str()); + cvars.p_cvar.insert({m_cvar.cvar, result.first}); return result.first; } } @@ -314,13 +320,13 @@ class cvar_mngr if (!name.empty()) { cvar_t *cvar = create_cvar(name, value, flags); - //UTIL_ServerPrint("[DEBUG] add(): cvar = %d\n", cvar); + // UTIL_ServerPrint("[DEBUG] add(): cvar = %d\n", cvar); cvar_list_it cvar_list = add_exists(cvar, desc, has_min, min_val, has_max, max_val); if (!check_it_empty(cvar_list)) { // Set m_cvar - m_cvar_t* m_cvar = &cvar_list->second; - //UTIL_ServerPrint("[DEBUG] add(): has_min = %d, min_val = %f, has_max = %d, max_val = %f\n", m_cvar->has_min, m_cvar->min_val, m_cvar->has_max, m_cvar->max_val); + m_cvar_t *m_cvar = &cvar_list->second; + // UTIL_ServerPrint("[DEBUG] add(): has_min = %d, min_val = %f, has_max = %d, max_val = %f\n", m_cvar->has_min, m_cvar->min_val, m_cvar->has_max, m_cvar->max_val); plugin_cvar_it plugin_cvar; // Plugin cvars exist? if ((plugin_cvar = cvars.plugin.find(plugin_id)) != cvars.plugin.end()) @@ -361,36 +367,37 @@ class cvar_mngr { p_cvar_it p_cvar; // Cvar exists? - return cvar == nullptr ? cvar_list_it{} : (p_cvar = cvars.p_cvar.find(cvar)) != cvars.p_cvar.end() ? p_cvar->second : get(stows(cvar->name)); + return cvar == nullptr ? cvar_list_it{} : (p_cvar = cvars.p_cvar.find(cvar)) != cvars.p_cvar.end() ? p_cvar->second + : get(stows(cvar->name)); } - cell get(CVAR_TYPES_t type, cvar_list_it cvar_list, cell* ptr, size_t ptr_size) + cell get(CVAR_TYPES_t type, cvar_list_it cvar_list, cell *ptr, size_t ptr_size) { cell result = FALSE; // Cvar exists? if (!check_it_empty(cvar_list)) - { - m_cvar_t* m_cvar = &cvar_list->second; + { + m_cvar_t *m_cvar = &cvar_list->second; switch (type) { - case CVAR_TYPE_NUM: - result = (int)m_cvar->cvar->value; - break; - case CVAR_TYPE_FLT: - result = amx_ftoc(m_cvar->cvar->value); - break; - case CVAR_TYPE_STR: - std::string s = wstos(m_cvar->value); - result = std::min(ptr_size, s.size()); - setAmxString(ptr, s.c_str(), result << 2); + case CVAR_TYPE_NUM: + result = (int)m_cvar->cvar->value; + break; + case CVAR_TYPE_FLT: + result = amx_ftoc(m_cvar->cvar->value); + break; + case CVAR_TYPE_STR: + std::string s = wstos(m_cvar->value); + result = std::min(ptr_size, s.size()); + setAmxString(ptr, s.c_str(), result << 2); } } return result; } - cell get(CVAR_TYPES_t type, cvar_t* cvar, cell* ptr, size_t ptr_size) + cell get(CVAR_TYPES_t type, cvar_t *cvar, cell *ptr, size_t ptr_size) { return get(type, get(cvar), ptr, ptr_size); } - cell get(CVAR_TYPES_t type, std::wstring name, cell* ptr, size_t ptr_size) + cell get(CVAR_TYPES_t type, std::wstring name, cell *ptr, size_t ptr_size) { return get(type, get(name), ptr, ptr_size); } @@ -407,23 +414,23 @@ class cvar_mngr auto cvar = cvar_list->second.cvar; direct_set(cvar, wstos(value).c_str()); } - void set(CVAR_TYPES_t type, cvar_t* cvar, cell* ptr) + void set(CVAR_TYPES_t type, cvar_t *cvar, cell *ptr) { if (cvar == nullptr) return; switch (type) { - case CVAR_TYPE_NUM: - direct_set(cvar, std::to_string((int)*ptr).c_str()); - break; - case CVAR_TYPE_FLT: - CVAR_SET_FLOAT(cvar->name, *(float*)ptr); - break; - case CVAR_TYPE_STR: - CVAR_SET_STRING(cvar->name, (char*)ptr); + case CVAR_TYPE_NUM: + direct_set(cvar, std::to_string((int)*ptr).c_str()); + break; + case CVAR_TYPE_FLT: + CVAR_SET_FLOAT(cvar->name, *(float *)ptr); + break; + case CVAR_TYPE_STR: + CVAR_SET_STRING(cvar->name, (char *)ptr); } } - void set(CVAR_TYPES_t type, std::wstring name, cell* ptr) + void set(CVAR_TYPES_t type, std::wstring name, cell *ptr) { cvar_list_it cvar_list = get(name); check_it_empty_r(cvar_list); @@ -433,17 +440,17 @@ class cvar_mngr { if (!check_it_empty(cvar_list)) { - //UTIL_ServerPrint("[DEBUG] create_hook(): fwd = %d, cvar = %d\n", fwd, cvar_list->second.cvar); - auto result = cvars.hook_state.insert({ fwd, is_enable }); + // UTIL_ServerPrint("[DEBUG] create_hook(): fwd = %d, cvar = %d\n", fwd, cvar_list->second.cvar); + auto result = cvars.hook_state.insert({fwd, is_enable}); if (result.second) { cvar_hook_list_it hook_it; - m_cvar_t* m_cvar = &cvar_list->second; + m_cvar_t *m_cvar = &cvar_list->second; if ((hook_it = cvars.cvar_hook_list.find(m_cvar->cvar)) != cvars.cvar_hook_list.end()) hook_it->second.push_back(result.first); else cvars.cvar_hook_list[m_cvar->cvar].push_back(result.first); - //UTIL_ServerPrint("\n[DEBUG] create_hook(): fwd = %d, hook = %d, cvar = %d, name = <%s>, value = <%s>, enabled = %d\n\n", fwd, result.first, cvar_list->second.cvar, cvar_list->second.cvar->name, cvar_list->second.cvar->string, is_enable); + // UTIL_ServerPrint("\n[DEBUG] create_hook(): fwd = %d, hook = %d, cvar = %d, name = <%s>, value = <%s>, enabled = %d\n\n", fwd, result.first, cvar_list->second.cvar, cvar_list->second.cvar->name, cvar_list->second.cvar->string, is_enable); return result.first; } } @@ -462,9 +469,7 @@ class cvar_mngr { auto list = plugin_cvars->second; list.sort([](cvar_list_it p1, cvar_list_it p2) - { - return p1->first.compare(p2->first); - }); + { return p1->first.compare(p2->first); }); } void clear_plugin(CPluginMngr::CPlugin *plugin) { diff --git a/refsapi_misc.cpp b/refsapi_misc.cpp index 28af88e..aca7599 100644 --- a/refsapi_misc.cpp +++ b/refsapi_misc.cpp @@ -1,6 +1,7 @@ #include "precompiled.h" -bool is_number(std::string &s) { +bool is_number(std::string &s) +{ trim(s); if (s.empty()) return false; @@ -22,11 +23,11 @@ bool is_number(std::string &s) { } it++; } - //UTIL_ServerPrint("[DEBUG] is_number(): s = <%s>, result = %d\n", s.c_str(), it == s.end()); + // UTIL_ServerPrint("[DEBUG] is_number(): s = <%s>, result = %d\n", s.c_str(), it == s.end()); return it == s.end(); } -size_t set_amx_string(cell* dest, const char* str, size_t max_len) +size_t set_amx_string(cell *dest, const char *str, size_t max_len) { size_t count = 0; if (max_len) diff --git a/refsapi_misc.h b/refsapi_misc.h index cf5a0e0..e0e9f38 100644 --- a/refsapi_misc.h +++ b/refsapi_misc.h @@ -3,7 +3,7 @@ #include "refsapi.h" bool is_number(std::string &s); -size_t set_amx_string(cell* dest, const char* str, size_t max_len); +size_t set_amx_string(cell *dest, const char *str, size_t max_len); class fmt { @@ -103,7 +103,7 @@ inline std::wstring stows(const std::string &s) { std::wstring result; size_t length = s.length(); - //UTIL_ServerPrint("[DEBUG] stows(): catch !!! length = %d\n", length); + // UTIL_ServerPrint("[DEBUG] stows(): catch !!! length = %d\n", length); result.reserve(length); for (size_t i = 0; i < length; i++) result.push_back(s[i] & 0xFF); @@ -113,8 +113,8 @@ inline std::wstring stows(const std::string &s) inline double stod(std::string s, bool has_min = false, float min_val = 0.0f, bool has_max = false, float max_val = 0.0f) { - auto result = std::stod(s);//std::strtof(s.c_str(), 0); //(float)std::stod(s); - //UTIL_ServerPrint("[DEBUG] stod(): in = %s, out = %f\n", s.c_str(), result); + auto result = std::stod(s); // std::strtof(s.c_str(), 0); //(float)std::stod(s); + // UTIL_ServerPrint("[DEBUG] stod(): in = %s, out = %f\n", s.c_str(), result); if (has_min && result < min_val) result = min_val; if (has_min && result > max_val) @@ -124,7 +124,7 @@ inline double stod(std::string s, bool has_min = false, float min_val = 0.0f, bo inline double roundd(double value, int precision = -6) { - //UTIL_ServerPrint("[DEBUG] acs_roundfloat(): value = %f, precision = %d", value, precision); + // UTIL_ServerPrint("[DEBUG] acs_roundfloat(): value = %f, precision = %d", value, precision); auto power = pow(10.0f, -precision); return floor(value * power + 0.5) / power; } @@ -138,56 +138,56 @@ inline bool file_exists(const std::wstring &name) inline void remove_chars(std::string &s, std::string chars = _TRIM_CHARS) { s.erase(std::remove_if(s.begin(), s.end(), [&](unsigned char ch) - { + { for (auto& sub : chars) if (ch == sub) return true; - return false; - }), s.end()); + return false; }), + s.end()); } inline void ltrim(std::string &s, std::string chars = _TRIM_CHARS) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [&](unsigned char ch) - { + { for (auto& sub : chars) if (ch == sub) return false; - return true; - })); + return true; })); } inline void ltrim(std::wstring &s, std::string chars = _TRIM_CHARS) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [&](unsigned char ch) - { + { for (auto& sub : chars) if (ch == sub) return false; - return true; - })); + return true; })); } inline void rtrim(std::string &s, std::string chars = _TRIM_CHARS) { s.erase(std::find_if(s.rbegin(), s.rend(), [&](unsigned char ch) - { + { for (auto& sub : chars) if (ch == sub) return false; - return true; - }).base(), s.end()); + return true; }) + .base(), + s.end()); } inline void rtrim(std::wstring &s, std::string chars = _TRIM_CHARS) { s.erase(std::find_if(s.rbegin(), s.rend(), [&](unsigned char ch) - { + { for (auto& sub : chars) if (ch == sub) return false; - return true; - }).base(), s.end()); + return true; }) + .base(), + s.end()); } inline void rtrim_zero(std::string &s) @@ -196,9 +196,9 @@ inline void rtrim_zero(std::string &s) if (it == s.rend()) return; s.erase(std::find_if(s.rbegin(), it, [&](unsigned char ch) - { - return ch != '0'; - }).base(), s.end()); + { return ch != '0'; }) + .base(), + s.end()); } inline std::string rtrim_zero_c(std::string s) @@ -264,7 +264,7 @@ inline int rm_quote(std::string &s) { int result = 0; bool f[2]; - for (auto& ch : _QQ) + for (auto &ch : _QQ) { f[0] = f[1] = 0; if ((f[0] = s.front() == ch) && (f[1] = s.back() == ch)) @@ -288,7 +288,7 @@ inline int rm_quote(std::wstring &s) { int result = 0; bool f[2]; - for (auto& ch : _QQ) + for (auto &ch : _QQ) { f[0] = f[1] = 0; if ((f[0] = s.front() == ch) && (f[1] = s.back() == ch)) @@ -309,7 +309,7 @@ inline int rm_quote(std::wstring &s) inline std::string rm_quote_c(std::string &s) { - for (auto& ch : _QQ) + for (auto &ch : _QQ) { if (s.front() == ch && s.back() == ch) { @@ -323,7 +323,7 @@ inline std::string rm_quote_c(std::string &s) inline std::wstring rm_quote_c(std::wstring &s) { - for (auto& ch : _QQ) + for (auto &ch : _QQ) { if (s.front() == ch && s.back() == ch) { diff --git a/refsapi_mysql_mngr.h b/refsapi_mysql_mngr.h index b9c306f..905f4e5 100644 --- a/refsapi_mysql_mngr.h +++ b/refsapi_mysql_mngr.h @@ -1,17 +1,17 @@ #include "precompiled.h" #ifndef WITHOUT_SQL -#define _DEBUG 1 -#define MAX_QUERY_PRIORITY 3 // PRI->THREADS: 0 -> 8, 1 -> 4, 2 -> 2, 3 -> 1 -#define QUERY_POOLING_INTERVAL 5 -#define QUERY_RETRY_COUNT 3 -#define SQL_FLAGS CLIENT_COMPRESS | CLIENT_MULTI_STATEMENTS -#define RF_MAX_FIELD_SIZE 256 -#define RF_MAX_FIELD_NAME 64 -#define gettid() std::this_thread::get_id() -#define TQUERY_CONNECT_FAILED -2 -#define TQUERY_QUERY_FAILED -1 -#define TQUERY_SUCCESS 0 +#define _DEBUG 1 +#define MAX_QUERY_PRIORITY 3 // PRI->THREADS: 0 -> 8, 1 -> 4, 2 -> 2, 3 -> 1 +#define QUERY_POOLING_INTERVAL 5 +#define QUERY_RETRY_COUNT 3 +#define SQL_FLAGS CLIENT_COMPRESS | CLIENT_MULTI_STATEMENTS +#define RF_MAX_FIELD_SIZE 256 +#define RF_MAX_FIELD_NAME 64 +#define gettid() std::this_thread::get_id() +#define TQUERY_CONNECT_FAILED -2 +#define TQUERY_QUERY_FAILED -1 +#define TQUERY_SUCCESS 0 typedef enum field_types_e { @@ -30,9 +30,9 @@ typedef struct prm_s std::string db_user; std::string db_pass; std::string db_name; - std::string db_chrs; // charterset - size_t db_port; // 3306 - size_t timeout; // ms + std::string db_chrs; // charterset + size_t db_port; // 3306 + size_t timeout; // ms } prm_t; typedef std::list prm_list_t; @@ -47,20 +47,20 @@ typedef struct m_query_s uint8 pri; size_t conn_id; std::string query; - cell* data; + cell *data; size_t data_size; size_t timeout; uint8 retry_count; bool async; std::atomic started; - std::atomic aborted; + std::atomic aborted; std::atomic finished; std::atomic successful; double time_create; double time_start; double time_end; MYSQL *conn; - MYSQL_RES* result; + MYSQL_RES *result; bool is_buffered; MYSQL_ROW row; prm_list_it prms; @@ -69,10 +69,11 @@ typedef struct m_query_s size_t f_count; } m_query_t; -typedef std::map m_query_list_t; +typedef std::map m_query_list_t; typedef m_query_list_t::iterator m_query_list_it; -class mysql_mngr { +class mysql_mngr +{ size_t max_threads; prm_list_t m_conn_prms; m_query_list_t m_queries[MAX_QUERY_PRIORITY + 1]; @@ -84,35 +85,37 @@ class mysql_mngr { std::atomic stop_threads; std::mutex threads_mutex, fwd_mutex, std_mutex; std::atomic m_query_nums; - std::vector conns; + std::vector conns; time_point_t _time_0; + private: int wait_for_mysql(MYSQL *conn, int status, int timeout_ms = 0) { int timeout, res; struct pollfd pfd; - //DEBUG("wait_for_mysql(): conn = %d", conn); + // DEBUG("wait_for_mysql(): conn = %d", conn); pfd.fd = mysql_get_socket(conn); - //DEBUG("wait_for_mysql(): socket = %d", pfd.fd); + // DEBUG("wait_for_mysql(): socket = %d", pfd.fd); pfd.events = (status & MYSQL_WAIT_READ ? POLLIN : 0) | (status & MYSQL_WAIT_WRITE ? POLLOUT : 0) | (status & MYSQL_WAIT_EXCEPT ? POLLPRI : 0); - //DEBUG("wait_for_mysql(): socket = %d, events = %d", pfd.fd, pfd.events); + // DEBUG("wait_for_mysql(): socket = %d, events = %d", pfd.fd, pfd.events); if (status & MYSQL_WAIT_TIMEOUT) timeout = timeout_ms ? timeout_ms : mysql_get_timeout_value_ms(conn); else timeout = -1; - //DEBUG("wait_for_mysql(): timeout = %d", timeout); + // DEBUG("wait_for_mysql(): timeout = %d", timeout); do res = poll(&pfd, 1, timeout); while (!stop_threads && res == -1 && errno == EINTR); - //DEBUG("wait_for_mysql(): res = %d", res); + // DEBUG("wait_for_mysql(): res = %d", res); if (res == 0) return MYSQL_WAIT_TIMEOUT; else if (res < 0) - return MYSQL_WAIT_TIMEOUT; //MYSQL_WAIT_EXCEPT; - else { + return MYSQL_WAIT_TIMEOUT; // MYSQL_WAIT_EXCEPT; + else + { int status = 0; if (pfd.revents & POLLIN) status |= MYSQL_WAIT_READ; @@ -148,7 +151,7 @@ class mysql_mngr { { int pri; std::thread::id key; - m_query_t* q; + m_query_t *q; std::vector finished; for (pri = 0; pri < MAX_QUERY_PRIORITY + 1; pri++) { @@ -190,8 +193,8 @@ class mysql_mngr { q->started = true; q->time_start = get_time(); std::thread t(&mysql_mngr::exec_async_query, this, pri, q); - //m_threads.emplace(key = t.get_id(), t); - m_threads.insert({ key = t.get_id(), std::move(t) }); + // m_threads.emplace(key = t.get_id(), t); + m_threads.insert({key = t.get_id(), std::move(t)}); q->tid = key; num_threads++; DEBUG("run_query(): thread starting pid = %p, q = %p, threads_num = %d", key, q, m_threads.size()); @@ -232,11 +235,13 @@ class mysql_mngr { float queuetime = q->time_end - q->time_start; if (!stop_threads && q->prms->fwd != -1) { - //public QueryHandler(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime); + // public QueryHandler(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime); DEBUG("exec_async_query: EXEC AMXX FORWARD = %d, is_debug = %d, failstate = %d, err = %d, query = %p, time = %f (%f / %f / %f), error = %s", q->prms->fwd, q->prms->is_debug, failstate, err, q, queuetime, q->time_create, q->time_start, q->time_end, q->error.c_str()); - if (q->prms->is_debug) fwd_mutex.lock(); - g_amxxapi.ExecuteForward(q->prms->fwd, failstate, q, g_amxxapi.PrepareCharArray((char*)q->error.c_str(), q->error.size() + 1), err, g_amxxapi.PrepareCellArray(q->data, q->data_size), q->data_size, amx_ftoc(queuetime)); - if (q->prms->is_debug) fwd_mutex.unlock(); + if (q->prms->is_debug) + fwd_mutex.lock(); + g_amxxapi.ExecuteForward(q->prms->fwd, failstate, q, g_amxxapi.PrepareCharArray((char *)q->error.c_str(), q->error.size() + 1), err, g_amxxapi.PrepareCellArray(q->data, q->data_size), q->data_size, amx_ftoc(queuetime)); + if (q->prms->is_debug) + fwd_mutex.unlock(); DEBUG("exec_async_query: AFTER FORWARD"); } free_query(q); @@ -244,7 +249,7 @@ class mysql_mngr { q->finished = true; DEBUG("exec_async_query(): pid = %p, END, num_finished = %d", pid, num_finished.load()); } - m_query_t* prepare_query(MYSQL* conn, const char *query, bool async = false) + m_query_t *prepare_query(MYSQL *conn, const char *query, bool async = false) { auto q = new m_query_t; q->conn = conn; @@ -274,7 +279,7 @@ class mysql_mngr { q->data = data_size ? new cell[data_size] : nullptr; Q_memcpy(q->data, data, data_size << 2); std::lock_guard lock(threads_mutex); - m_queries[pri].insert({ q->id, q }); + m_queries[pri].insert({q->id, q}); DEBUG("push_query(): q = %p, query = %s, pri = %d, count = %d", q, query, pri, m_queries[pri].size()); return true; } @@ -325,7 +330,7 @@ class mysql_mngr { if (q->data != nullptr && (q->successful || stop_threads)) { DEBUG("free_query: FREE DATA, q = %p", q); - delete [] q->data; + delete[] q->data; q->data = nullptr; } } @@ -362,47 +367,47 @@ class mysql_mngr { { if (q->result == nullptr || !q->row) return 0; - //DEBUG("fetch_field(): field = %s, type = %d, q = %p, offset = %d, mode = %d, ret = %p, buff = %p, len = %d", q->row[offset], q->result->fields[offset].type, q, offset, mode, ret, buff, buff_len); + // DEBUG("fetch_field(): field = %s, type = %d, q = %p, offset = %d, mode = %d, ret = %p, buff = %p, len = %d", q->row[offset], q->result->fields[offset].type, q, offset, mode, ret, buff, buff_len); switch (mode) { - case FT_AUTO: - switch (q->result->fields[offset].type) - { - case MYSQL_TYPE_TINY: - case MYSQL_TYPE_SHORT: - case MYSQL_TYPE_INT24: - case MYSQL_TYPE_LONG: - case MYSQL_TYPE_BIT: - *ret = q->row[offset] == NULL ? 0 : atoi(q->row[offset]); - break; - case MYSQL_TYPE_FLOAT: - case MYSQL_TYPE_DOUBLE: - case MYSQL_TYPE_DECIMAL: - *ret = q->row[offset] == NULL ? 0.0f : (float)atof(q->row[offset]); - break; - default: - set_amx_string(ret, q->row[offset], RF_MAX_FIELD_SIZE - 1); - break; - } - break; - case FT_INT: - *ret = atoi(q->row[offset]); + case FT_AUTO: + switch (q->result->fields[offset].type) + { + case MYSQL_TYPE_TINY: + case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_INT24: + case MYSQL_TYPE_LONG: + case MYSQL_TYPE_BIT: + *ret = q->row[offset] == NULL ? 0 : atoi(q->row[offset]); break; - case FT_FLT: - *ret = (float)atof(q->row[offset]); + case MYSQL_TYPE_FLOAT: + case MYSQL_TYPE_DOUBLE: + case MYSQL_TYPE_DECIMAL: + *ret = q->row[offset] == NULL ? 0.0f : (float)atof(q->row[offset]); break; default: - if (mode == FT_STR) - set_amx_string(ret, q->row[offset], RF_MAX_FIELD_SIZE - 1); - else if (buff_len) - *ret = set_amx_string(buff, q->row[offset], buff_len); + set_amx_string(ret, q->row[offset], RF_MAX_FIELD_SIZE - 1); + break; + } + break; + case FT_INT: + *ret = atoi(q->row[offset]); + break; + case FT_FLT: + *ret = (float)atof(q->row[offset]); + break; + default: + if (mode == FT_STR) + set_amx_string(ret, q->row[offset], RF_MAX_FIELD_SIZE - 1); + else if (buff_len) + *ret = set_amx_string(buff, q->row[offset], buff_len); } - //DEBUG("fetch_field(): ret = %d", *ret); + // DEBUG("fetch_field(): ret = %d", *ret); return 1; } bool fetch_row(m_query_t *q) { - //DEBUG("fetch_row(): query = %p, is_buffered = %d", q, q->is_buffered); + // DEBUG("fetch_row(): query = %p, is_buffered = %d", q, q->is_buffered); if (q->result == nullptr || !q->f_count) return false; if (!q->is_buffered) @@ -416,8 +421,8 @@ class mysql_mngr { } else q->row = mysql_fetch_row(q->result); - //if (q->time_start == q->time_end) - //DEBUG("fetch_row(): status = %d, %s", status, q->row != NULL ? "done" : "end +++"); + // if (q->time_start == q->time_end) + // DEBUG("fetch_row(): status = %d, %s", status, q->row != NULL ? "done" : "end +++"); return q->row != NULL; } cell field_count(m_query_t *q) @@ -433,7 +438,7 @@ class mysql_mngr { DEBUG("get_result(): result = %p, query = %p, conn = %p, is_buffered = %d, state = %s", q->result, q, q->conn, is_buffered, q->conn->net.sqlstate); if ((q->f_count = mysql_field_count(q->conn)) && q->result) for (int i = 0; i < q->f_count; i++) - q->f_names.insert({ q->result->fields[i].name, i }); + q->f_names.insert({q->result->fields[i].name, i}); DEBUG("get_result(): done, field count = %d", q->f_count); return true; } @@ -443,7 +448,7 @@ class mysql_mngr { { return q->result == nullptr ? -1 : mysql_num_rows(q->result); } - MYSQL* connect(size_t conn_id, cell *err_num, cell *err_str, size_t err_str_size) + MYSQL *connect(size_t conn_id, cell *err_num, cell *err_str, size_t err_str_size) { MYSQL *ret, *conn = mysql_init(NULL); auto prms = get_connect(conn_id); @@ -496,12 +501,11 @@ class mysql_mngr { for (auto it : conns) mysql_close(it); conns.clear(); - } size_t add_connect(int fwd, bool is_debug, std::string &db_host, std::string &db_user, std::string &db_pass, std::string &db_name, std::string &db_chrs, size_t timeout) { - //DEBUG("add_connect(): pid = %d, fwd = %d, host = <%s>, user = <%s>, pass = <%s>, name = <%s>, timeout = %d", - // gettid(), fwd, db_host.c_str(), db_user.c_str(), db_pass.c_str(), db_name.c_str(), timeout_ms + // DEBUG("add_connect(): pid = %d, fwd = %d, host = <%s>, user = <%s>, pass = <%s>, name = <%s>, timeout = %d", + // gettid(), fwd, db_host.c_str(), db_user.c_str(), db_pass.c_str(), db_name.c_str(), timeout_ms //); prm_t prms; prms.fwd = fwd; @@ -526,7 +530,7 @@ class mysql_mngr { } void start_main() { - //DEBUG("start(): pid = %d, START", gettid()); + // DEBUG("start(): pid = %d, START", gettid()); stop_main = false; main_thread = std::thread(&mysql_mngr::main, this); } @@ -562,9 +566,9 @@ class mysql_mngr { stop_main = false; stop_threads = true; m_query_nums = 1; - num_threads = 0; + num_threads = 0; num_finished = 0; - max_threads = clamp(std::thread::hardware_concurrency() >> 1, 1U, 4U); + max_threads = clamp(std::thread::hardware_concurrency() >> 1, 1U, 4U); } ~mysql_mngr() { diff --git a/refsapi_recoil_mngr.cpp b/refsapi_recoil_mngr.cpp index 1cf553a..b870551 100644 --- a/refsapi_recoil_mngr.cpp +++ b/refsapi_recoil_mngr.cpp @@ -1,11 +1,11 @@ #include "precompiled.h" -void CmdEnd_Post(const edict_t* pEdict) +void CmdEnd_Post(const edict_t *pEdict) { - g_recoil_mngr.cmd_end(pEdict); + g_recoil_mngr.cmd_end(pEdict); } -void RG_CBasePlayer_PostThink(IReGameHook_CBasePlayer_PostThink* chain, CBasePlayer* player) +void RG_CBasePlayer_PostThink(IReGameHook_CBasePlayer_PostThink *chain, CBasePlayer *player) { chain->callNext(player); g_recoil_mngr.think_post(player); diff --git a/refsapi_recoil_mngr.h b/refsapi_recoil_mngr.h index dcb4191..c6d5d7e 100644 --- a/refsapi_recoil_mngr.h +++ b/refsapi_recoil_mngr.h @@ -1,19 +1,19 @@ #include "precompiled.h" -#define RECOIL_ALL 0 +#define RECOIL_ALL 0 -void CmdEnd_Post(const edict_t* pEdict); -void RG_CBasePlayer_PostThink(IReGameHook_CBasePlayer_PostThink* chain, CBasePlayer* player); +void CmdEnd_Post(const edict_t *pEdict); +void RG_CBasePlayer_PostThink(IReGameHook_CBasePlayer_PostThink *chain, CBasePlayer *player); class recoil_mngr { int IMPULSE_OFFSET; - std::array weapon_recoil; + std::array weapon_recoil; std::array last_fired; bool is_enabled; private: - void add(size_t weapon_id, const char* weapon_name) + void add(size_t weapon_id, const char *weapon_name) { auto cvar_list = g_cvar_mngr.get(wfmt(L"wcs_recoil_%s", weapon_name).c_str()); weapon_recoil[weapon_id] = check_it_empty(cvar_list) ? nullptr : cvar_list->second.cvar; @@ -35,7 +35,7 @@ class recoil_mngr weapon_recoil[weapon_id]->value = recoil; } void enable(int _offset = 0) - { + { disable(); init(); is_enabled = true; @@ -47,43 +47,43 @@ class recoil_mngr if (!is_enabled) return; is_enabled = false; - g_ReGameHookchains->CBasePlayer_PostThink()->unregisterHook(RG_CBasePlayer_PostThink); + g_ReGameHookchains->CBasePlayer_PostThink()->unregisterHook(RG_CBasePlayer_PostThink); } void clear() { for (auto rc : weapon_recoil) CVAR_SET_FLOAT(rc->name, 0.0f); } - void cmd_end(const edict_t* pEdict) + void cmd_end(const edict_t *pEdict) { if (!is_enabled) return; - auto player = UTIL_PlayerByIndexSafe(ENTINDEX(pEdict)); + auto player = UTIL_PlayerByIndexSafe(ENTINDEX(pEdict)); if (player != nullptr && player->IsAlive()) last_fired[player->entindex()] = player->m_flLastFired; } - void think_post(CBasePlayer* player) + void think_post(CBasePlayer *player) { if (!is_enabled || !player->IsAlive() || player->IsBot()) return; auto ped = player->edict(); auto index = player->entindex(); - if (is_valid_entity(ped) && (ped->v.button & IN_ATTACK) && player->m_flLastFired != last_fired[index] - && player->m_pActiveItem && player->m_pActiveItem->IsWeapon()/* <--Fix crash ReGAME*/) + if (is_valid_entity(ped) && (ped->v.button & IN_ATTACK) && player->m_flLastFired != last_fired[index] && player->m_pActiveItem && player->m_pActiveItem->IsWeapon() /* <--Fix crash ReGAME*/) { last_fired[index] = player->m_flLastFired; - CBasePlayerWeapon* weapon = static_cast(player->m_pActiveItem); + CBasePlayerWeapon *weapon = static_cast(player->m_pActiveItem); if (!((BIT(WEAPON_NONE) | BIT(WEAPON_HEGRENADE) | BIT(WEAPON_C4) | BIT(WEAPON_SMOKEGRENADE) | BIT(WEAPON_FLASHBANG) | BIT(WEAPON_KNIFE)) & BIT(player->m_pActiveItem->m_iId))) { auto wed = weapon->edict(); auto pcvar = weapon_recoil[player->m_pActiveItem->m_iId]; auto pcvar_all = weapon_recoil[RECOIL_ALL]; - auto recoil = IMPULSE_OFFSET > 0 && (wed->v.iuser4 - IMPULSE_OFFSET) >= 0 && wed->v.impulse == wed->v.iuser4 ? wed->v.fuser1 : pcvar != nullptr ? pcvar->value : 0.0f; - //UTIL_ServerPrint("[DEBUG] think_post(): offset = %d, pcvar = %d, pcvar_recoil = %f, weapon_id = %d, recoil = %f\n", IMPULSE_OFFSET, pcvar, pcvar->value, player->m_pActiveItem->m_iId, recoil); + auto recoil = IMPULSE_OFFSET > 0 && (wed->v.iuser4 - IMPULSE_OFFSET) >= 0 && wed->v.impulse == wed->v.iuser4 ? wed->v.fuser1 : pcvar != nullptr ? pcvar->value + : 0.0f; + // UTIL_ServerPrint("[DEBUG] think_post(): offset = %d, pcvar = %d, pcvar_recoil = %f, weapon_id = %d, recoil = %f\n", IMPULSE_OFFSET, pcvar, pcvar->value, player->m_pActiveItem->m_iId, recoil); bool is_recoil_set = recoil > 0.0f && recoil < 1.0f; if (!is_recoil_set && pcvar_all != nullptr && (is_recoil_set = pcvar_all->value > 0.0f && pcvar_all->value < 1.0f)) recoil = weapon_recoil[RECOIL_ALL]->value; - //UTIL_ServerPrint("[DEBUG] think_post(): is_recoil_set = %d, pcvar = %d, recoil = %f\n", is_recoil_set, pcvar_all, recoil); + // UTIL_ServerPrint("[DEBUG] think_post(): is_recoil_set = %d, pcvar = %d, recoil = %f\n", is_recoil_set, pcvar_all, recoil); if (is_recoil_set) { ped->v.punchangle = ped->v.punchangle * recoil; diff --git a/sdk_util.cpp b/sdk_util.cpp index 39f893c..7221ec0 100644 --- a/sdk_util.cpp +++ b/sdk_util.cpp @@ -4,15 +4,11 @@ void NORETURN UTIL_SysError(const char *fmt, ...) { va_list argptr; char string[8192]; - va_start(argptr, fmt); vsnprintf(string, sizeof(string), fmt, argptr); va_end(argptr); - printf("%s\n", string); - - //TerminateProcess(GetCurrentProcess(), 1); - + // TerminateProcess(GetCurrentProcess(), 1); volatile int *null = 0; *null = 0; exit(-1); @@ -22,11 +18,9 @@ char *UTIL_VarArgs(char *format, ...) { va_list argptr; static char string[1024]; - va_start(argptr, format); vsprintf(string, format, argptr); va_end(argptr); - return string; } @@ -34,11 +28,9 @@ void UTIL_LogPrintf(const char *fmt, ...) { va_list argptr; char string[1024]; - va_start(argptr, fmt); vsprintf(string, fmt, argptr); va_end(argptr); - ALERT(at_logged, "%s", string); } @@ -46,10 +38,8 @@ void UTIL_ServerPrint(const char *fmt, ...) { va_list argptr; char string[1024]; - va_start(argptr, fmt); vsprintf(string, fmt, argptr); va_end(argptr); - SERVER_PRINT(string); } \ No newline at end of file