Fix server crash if sdkhook dropped first

This commit is contained in:
Kyle
2021-01-23 03:42:23 +08:00
parent 98e524b5eb
commit d529682899
6 changed files with 57 additions and 28 deletions
+25 -9
View File
@@ -1,4 +1,5 @@
#include "extension.h" #include "extension.h"
#include "ISDKHooks.h"
#ifdef _WINDOWS #ifdef _WINDOWS
#pragma comment(lib, "legacy_stdio_definitions.lib") #pragma comment(lib, "legacy_stdio_definitions.lib")
@@ -138,25 +139,21 @@ void TransmitManager::Hook_SetTransmit(CCheckTransmitInfo* pInfo, bool bAlways)
RETURN_META(MRES_IGNORED); 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); sharesys->AddDependency(myself, "sdkhooks.ext", true, true);
if (!sharesys->RequestInterface(SMINTERFACE_SDKHOOKS_NAME, SMINTERFACE_SDKHOOKS_VERSION, myself, reinterpret_cast<SMInterface**>(&g_pSDKHooks))) SM_GET_IFACE(SDKHOOKS, g_pSDKHooks)
{
smutils->Format(error, maxlen, "Cannot get SDKHooks Interface");
return false;
}
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; return false;
} }
auto offset = -1; auto offset = -1;
if (!g_pGameConf->GetOffset("SetTransmit", &offset)) 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; return false;
} }
SH_MANUALHOOK_RECONFIGURE(SetTransmit, offset, 0, 0); SH_MANUALHOOK_RECONFIGURE(SetTransmit, offset, 0, 0);
@@ -173,10 +170,29 @@ bool TransmitManager::SDK_OnLoad(char *error, size_t maxlen, bool late)
return true; 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() void TransmitManager::SDK_OnUnload()
{ {
playerhelpers->RemoveClientListener(this); playerhelpers->RemoveClientListener(this);
// I don't know why SDKHooks dropped first.
if (g_pSDKHooks != nullptr)
{
g_pSDKHooks->RemoveEntityListener(this); g_pSDKHooks->RemoveEntityListener(this);
}
for (auto i = 0; i < MAX_EDICTS; i++) for (auto i = 0; i < MAX_EDICTS; i++)
{ {
+6 -8
View File
@@ -11,24 +11,22 @@ class TransmitManager : public SDKExtension, public ISMEntityListener, public IC
public: public:
virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late); virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
virtual void SDK_OnUnload(); virtual void SDK_OnUnload();
virtual bool QueryRunning(char* error, size_t maxlength);
virtual void NotifyInterfaceDrop(SMInterface* pInterface);
public:
virtual void OnEntityDestroyed(CBaseEntity* pEntity); virtual void OnEntityDestroyed(CBaseEntity* pEntity);
public:
virtual void OnClientPutInServer(int client); virtual void OnClientPutInServer(int client);
virtual void OnClientDisconnecting(int client); virtual void OnClientDisconnecting(int client);
public:
void Hook_SetTransmit(CCheckTransmitInfo* pInfo, bool bAlways); void Hook_SetTransmit(CCheckTransmitInfo* pInfo, bool bAlways);
private:
inline bool IsEntityIndexInRange(int i) { return i >= 1 && i < 2048; }
public:
void HookEntity(CBaseEntity* pEntity); void HookEntity(CBaseEntity* pEntity);
void UnhookEntity(int index);
private:
void UnhookEntity(int index);
}; };
inline bool IsEntityIndexInRange(int i) { return i >= 1 && i < 2048; }
#endif #endif
+5 -2
View File
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio Version 16
VisualStudioVersion = 15.0.26403.7 VisualStudioVersion = 16.0.30907.101
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TransmitManager", "TransmitManager.vcxproj", "{B3E797CF-4E77-4C9D-B8A8-7589B6902206}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TransmitManager", "TransmitManager.vcxproj", "{B3E797CF-4E77-4C9D-B8A8-7589B6902206}"
EndProject EndProject
@@ -16,4 +16,7 @@ Global
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3FB0701A-9C7D-4565-9CA7-AF56D21B7D4F}
EndGlobalSection
EndGlobal EndGlobal
+17 -5
View File
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32"> <ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
@@ -10,7 +14,7 @@
<ProjectGuid>{B3E797CF-4E77-4C9D-B8A8-7589B6902206}</ProjectGuid> <ProjectGuid>{B3E797CF-4E77-4C9D-B8A8-7589B6902206}</ProjectGuid>
<RootNamespace>TransmitManager</RootNamespace> <RootNamespace>TransmitManager</RootNamespace>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>7.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
<ProjectName>TransmitManager</ProjectName> <ProjectName>TransmitManager</ProjectName>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
@@ -18,7 +22,10 @@
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v141_xp</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
@@ -52,7 +59,7 @@
<Link> <Link>
<IgnoreSpecificDefaultLibraries> <IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries> </IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>false</GenerateDebugInformation> <GenerateDebugInformation>DebugFull</GenerateDebugInformation>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
@@ -64,14 +71,19 @@
<AdditionalLibraryDirectories>$(HL2SDK-CSGO)\lib\public</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(HL2SDK-CSGO)\lib\public</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Link>
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\extension.cpp" /> <ClCompile Include="..\extension.cpp" />
<ClCompile Include="..\..\..\Extension\sourcemod\public\smsdk_ext.cpp" /> <ClCompile Include="..\..\..\Extension\sourcemod\sourcemod-1.10\public\smsdk_ext.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\extension.h" /> <ClInclude Include="..\extension.h" />
<ClInclude Include="..\smsdk_config.h" /> <ClInclude Include="..\smsdk_config.h" />
<ClInclude Include="..\..\..\Extension\sourcemod\public\smsdk_ext.h" /> <ClInclude Include="..\..\..\Extension\sourcemod\sourcemod-1.10\public\smsdk_ext.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
+2 -2
View File
@@ -21,7 +21,7 @@
<ClCompile Include="..\extension.cpp"> <ClCompile Include="..\extension.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\Extension\sourcemod\public\smsdk_ext.cpp"> <ClCompile Include="..\..\..\Extension\sourcemod\sourcemod-1.10\public\smsdk_ext.cpp">
<Filter>SourceMod SDK</Filter> <Filter>SourceMod SDK</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
@@ -32,7 +32,7 @@
<ClInclude Include="..\smsdk_config.h"> <ClInclude Include="..\smsdk_config.h">
<Filter>SourceMod SDK</Filter> <Filter>SourceMod SDK</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\..\Extension\sourcemod\public\smsdk_ext.h"> <ClInclude Include="..\..\..\Extension\sourcemod\sourcemod-1.10\public\smsdk_ext.h">
<Filter>SourceMod SDK</Filter> <Filter>SourceMod SDK</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
+1 -1
View File
@@ -3,7 +3,7 @@
#define SMEXT_CONF_NAME "Transmit Manager" #define SMEXT_CONF_NAME "Transmit Manager"
#define SMEXT_CONF_DESCRIPTION "" #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_AUTHOR "Kyle \"Kxnrl\" Frankiss"
#define SMEXT_CONF_URL "https://www.kxnrl.com" #define SMEXT_CONF_URL "https://www.kxnrl.com"
#define SMEXT_CONF_LOGTAG "TransmitManager" #define SMEXT_CONF_LOGTAG "TransmitManager"