Don't call sourcepawn detour callbacks from threads other than the main thread

The SourcePawn VM isn't threadsafe.
This commit is contained in:
Peace-Maker 2018-05-02 13:37:41 +02:00
parent 30fc311738
commit 9d43111829
3 changed files with 9 additions and 0 deletions

View File

@ -252,6 +252,10 @@ bool UpdateRegisterArgumentSizes(CHook* pDetour, HookSetup *setup)
// Central handler for all detours. Heart of the detour support.
ReturnAction_t HandleDetour(HookType_t hookType, CHook* pDetour)
{
// Can't call into SourcePawn offthread.
if (g_MainThreadId != ke::GetCurrentThreadId())
return ReturnAction_Ignored;
DetourMap *map;
if (hookType == HOOKTYPE_PRE)
map = &g_pPreDetours;

View File

@ -15,6 +15,8 @@ HandleType_t g_HookSetupHandle = 0;
HandleType_t g_HookParamsHandle = 0;
HandleType_t g_HookReturnHandle = 0;
ke::ThreadId g_MainThreadId;
bool DHooks::SDK_OnLoad(char *error, size_t maxlength, bool late)
{
HandleError err;
@ -59,6 +61,7 @@ bool DHooks::SDK_OnLoad(char *error, size_t maxlength, bool late)
g_pEntityListener = new DHooksEntityListener();
g_pSignatures = new SignatureGameConfig();
g_MainThreadId = ke::GetCurrentThreadId();
return true;
}

View File

@ -43,6 +43,7 @@
#include <IBinTools.h>
#include <ISDKTools.h>
#include "sdk-hacks.h"
#include <amtl/am-thread-utils.h>
/**
* @brief Sample implementation of the SDK Extension.
@ -129,4 +130,5 @@ public:
};
extern SourceHook::IHookManagerAutoGen *g_pHookManager;
extern sp_nativeinfo_t g_Natives[];
extern ke::ThreadId g_MainThreadId;
#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_