From d5296828995ce5f5ff7269114ed3ca5c8c956b44 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 23 Jan 2021 03:42:23 +0800 Subject: [PATCH] Fix server crash if sdkhook dropped first --- extension.cpp | 36 +++++++++++++++++++------- extension.h | 14 +++++----- msvc15/TransmitManager.sln | 7 +++-- msvc15/TransmitManager.vcxproj | 22 ++++++++++++---- msvc15/TransmitManager.vcxproj.filters | 4 +-- smsdk_config.h | 2 +- 6 files changed, 57 insertions(+), 28 deletions(-) diff --git a/extension.cpp b/extension.cpp index a47e3e5..97d269a 100644 --- a/extension.cpp +++ b/extension.cpp @@ -1,4 +1,5 @@ #include "extension.h" +#include "ISDKHooks.h" #ifdef _WINDOWS #pragma comment(lib, "legacy_stdio_definitions.lib") @@ -138,25 +139,21 @@ void TransmitManager::Hook_SetTransmit(CCheckTransmitInfo* pInfo, bool bAlways) RETURN_META(MRES_IGNORED); } -bool TransmitManager::SDK_OnLoad(char *error, size_t maxlen, bool late) +bool TransmitManager::SDK_OnLoad(char *error, size_t maxlength, bool late) { sharesys->AddDependency(myself, "sdkhooks.ext", true, true); - if (!sharesys->RequestInterface(SMINTERFACE_SDKHOOKS_NAME, SMINTERFACE_SDKHOOKS_VERSION, myself, reinterpret_cast(&g_pSDKHooks))) - { - smutils->Format(error, maxlen, "Cannot get SDKHooks Interface"); - return false; - } + SM_GET_IFACE(SDKHOOKS, g_pSDKHooks) - if (!gameconfs->LoadGameConfigFile("sdkhooks.games", &g_pGameConf, error, maxlen)) + if (!gameconfs->LoadGameConfigFile("sdkhooks.games", &g_pGameConf, error, maxlength)) { - smutils->Format(error, maxlen, "Failed to load SDKHooks gamedata."); + smutils->Format(error, maxlength, "Failed to load SDKHooks gamedata."); return false; } auto offset = -1; if (!g_pGameConf->GetOffset("SetTransmit", &offset)) { - smutils->Format(error, maxlen, "Failed to load 'SetTransmit' offset."); + smutils->Format(error, maxlength, "Failed to load 'SetTransmit' offset."); return false; } SH_MANUALHOOK_RECONFIGURE(SetTransmit, offset, 0, 0); @@ -173,10 +170,29 @@ bool TransmitManager::SDK_OnLoad(char *error, size_t maxlen, bool late) return true; } +void TransmitManager::NotifyInterfaceDrop(SMInterface* pInterface) +{ + if (strcmp(pInterface->GetInterfaceName(), SMINTERFACE_SDKHOOKS_NAME) == 0) + { + g_pSDKHooks = nullptr; + } +} + +bool TransmitManager::QueryRunning(char* error, size_t maxlength) +{ + SM_CHECK_IFACE(SDKHOOKS, g_pSDKHooks) + return true; +} + void TransmitManager::SDK_OnUnload() { playerhelpers->RemoveClientListener(this); - g_pSDKHooks->RemoveEntityListener(this); + + // I don't know why SDKHooks dropped first. + if (g_pSDKHooks != nullptr) + { + g_pSDKHooks->RemoveEntityListener(this); + } for (auto i = 0; i < MAX_EDICTS; i++) { diff --git a/extension.h b/extension.h index fe072ed..4ce371f 100644 --- a/extension.h +++ b/extension.h @@ -11,24 +11,22 @@ class TransmitManager : public SDKExtension, public ISMEntityListener, public IC public: virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late); virtual void SDK_OnUnload(); + virtual bool QueryRunning(char* error, size_t maxlength); + virtual void NotifyInterfaceDrop(SMInterface* pInterface); -public: virtual void OnEntityDestroyed(CBaseEntity* pEntity); -public: virtual void OnClientPutInServer(int client); virtual void OnClientDisconnecting(int client); -public: void Hook_SetTransmit(CCheckTransmitInfo* pInfo, bool bAlways); -private: - inline bool IsEntityIndexInRange(int i) { return i >= 1 && i < 2048; } - -public: void HookEntity(CBaseEntity* pEntity); - void UnhookEntity(int index); +private: + void UnhookEntity(int index); }; +inline bool IsEntityIndexInRange(int i) { return i >= 1 && i < 2048; } + #endif diff --git a/msvc15/TransmitManager.sln b/msvc15/TransmitManager.sln index 2af2d9f..3fcf2e9 100644 --- a/msvc15/TransmitManager.sln +++ b/msvc15/TransmitManager.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26403.7 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30907.101 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TransmitManager", "TransmitManager.vcxproj", "{B3E797CF-4E77-4C9D-B8A8-7589B6902206}" EndProject @@ -16,4 +16,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3FB0701A-9C7D-4565-9CA7-AF56D21B7D4F} + EndGlobalSection EndGlobal diff --git a/msvc15/TransmitManager.vcxproj b/msvc15/TransmitManager.vcxproj index fc6283a..852487d 100644 --- a/msvc15/TransmitManager.vcxproj +++ b/msvc15/TransmitManager.vcxproj @@ -1,6 +1,10 @@  + + Debug + Win32 + Release Win32 @@ -10,7 +14,7 @@ {B3E797CF-4E77-4C9D-B8A8-7589B6902206} TransmitManager Win32Proj - 7.0 + 10.0.18362.0 TransmitManager @@ -18,7 +22,10 @@ DynamicLibrary MultiByte true - v141_xp + v141 + + + v142 @@ -52,7 +59,7 @@ - false + DebugFull Windows true true @@ -64,14 +71,19 @@ $(HL2SDK-CSGO)\lib\public + + + DebugFull + + - + - + diff --git a/msvc15/TransmitManager.vcxproj.filters b/msvc15/TransmitManager.vcxproj.filters index 014bd71..3060f7b 100644 --- a/msvc15/TransmitManager.vcxproj.filters +++ b/msvc15/TransmitManager.vcxproj.filters @@ -21,7 +21,7 @@ Source Files - + SourceMod SDK @@ -32,7 +32,7 @@ SourceMod SDK - + SourceMod SDK diff --git a/smsdk_config.h b/smsdk_config.h index b91bc18..c59949e 100644 --- a/smsdk_config.h +++ b/smsdk_config.h @@ -3,7 +3,7 @@ #define SMEXT_CONF_NAME "Transmit Manager" #define SMEXT_CONF_DESCRIPTION "" -#define SMEXT_CONF_VERSION "1.0.0" +#define SMEXT_CONF_VERSION "1.0.1" #define SMEXT_CONF_AUTHOR "Kyle \"Kxnrl\" Frankiss" #define SMEXT_CONF_URL "https://www.kxnrl.com" #define SMEXT_CONF_LOGTAG "TransmitManager"