diff --git a/extensions/sdktools/vglobals.cpp b/extensions/sdktools/vglobals.cpp index 09337a70..0925dbec 100644 --- a/extensions/sdktools/vglobals.cpp +++ b/extensions/sdktools/vglobals.cpp @@ -83,18 +83,28 @@ void InitializeValveGlobals() } #endif +bool vcmp(const void *_addr1, const void *_addr2, size_t len) +{ + unsigned char *addr1 = (unsigned char *)_addr1; + unsigned char *addr2 = (unsigned char *)_addr2; + + for (size_t i=0; iFindPattern(engine, ISERVER_WIN_SIG, ISERVER_WIN_SIG_LEN)) - { - return; - } - int offset; void *vfunc = NULL; @@ -110,6 +120,12 @@ void GetIServer() return; } + /* Check if we're on the expected function */ + if (!vcmp(vfunc, ISERVER_WIN_SIG, ISERVER_WIN_SIG_LEN)) + { + return; + } + /* Finally we have the interface we were looking for */ iserver = *reinterpret_cast(reinterpret_cast(vfunc) + offset); #else @@ -123,6 +139,11 @@ void GetIServer() void **vtable = *reinterpret_cast(enginePatch->GetThisPtr() + info.thisptroffs + info.vtbloffs); vfunc = vtable[info.vtblindex]; } + /* Check if we're on the expected function */ + if (!vcmp(vfunc, ISERVER_WIN_SIG, ISERVER_WIN_SIG_LEN)) + { + return; + } iserver = *reinterpret_cast(reinterpret_cast(vfunc) + offset); #endif @@ -136,6 +157,6 @@ void GetIServer() return; } - iserver = *reinterpret_cast(addr); + iserver = reinterpret_cast(addr); } #endif diff --git a/extensions/sdktools/vhelpers.cpp b/extensions/sdktools/vhelpers.cpp index 44a577a1..571abdd0 100644 --- a/extensions/sdktools/vhelpers.cpp +++ b/extensions/sdktools/vhelpers.cpp @@ -272,7 +272,7 @@ bool GetPlayerInfo(int client, player_info_t *info) #if defined ORANGEBOX_BUILD return engine->GetPlayerInfo(client, info); #else - return iserver->GetPlayerInfo(client, info); + return (iserver) ? iserver->GetPlayerInfo(client-1, info) : false; #endif } diff --git a/extensions/sdktools/vnatives.cpp b/extensions/sdktools/vnatives.cpp index ce54958d..6416caea 100644 --- a/extensions/sdktools/vnatives.cpp +++ b/extensions/sdktools/vnatives.cpp @@ -853,6 +853,11 @@ static cell_t GetPlayerDecalFile(IPluginContext *pContext, const cell_t *params) static cell_t GetServerNetStats(IPluginContext *pContext, const cell_t *params) { + if (iserver == NULL) + { + return pContext->ThrowNativeError("IServer interface not supported, file a bug report."); + } + float in, out; cell_t *pIn, *pOut;