fixed amb1252, GetPlayerInfo wouldnt work for the last player index
authorBorja Ferrer <faluco@alliedmods.net>
Fri Dec 07 00:17:24 2007 +0000 (2007-12-07)
changeset 1773d00a853ec547
parent 1772 e27ea26b2685
child 1774 b94704497073
fixed amb1252, GetPlayerInfo wouldnt work for the last player index
fixed iserver crashing on linux
extensions/sdktools/vglobals.cpp
extensions/sdktools/vhelpers.cpp
extensions/sdktools/vnatives.cpp
     1.1 --- a/extensions/sdktools/vglobals.cpp	Thu Dec 06 14:08:22 2007 +0000
     1.2 +++ b/extensions/sdktools/vglobals.cpp	Fri Dec 07 00:17:24 2007 +0000
     1.3 @@ -83,18 +83,28 @@
     1.4  }
     1.5  #endif
     1.6  
     1.7 +bool vcmp(const void *_addr1, const void *_addr2, size_t len)
     1.8 +{
     1.9 +	unsigned char *addr1 = (unsigned char *)_addr1;
    1.10 +	unsigned char *addr2 = (unsigned char *)_addr2;
    1.11 +
    1.12 +	for (size_t i=0; i<len; i++)
    1.13 +	{
    1.14 +		if (addr2[i] == '*')
    1.15 +			continue;
    1.16 +		if (addr1[i] != addr2[i])
    1.17 +			return false;
    1.18 +	}
    1.19 +
    1.20 +	return true;
    1.21 +}
    1.22 +
    1.23  #if defined PLATFORM_WINDOWS
    1.24  	/* Thanks to DS for the sigs */
    1.25  	#define ISERVER_WIN_SIG				"\x8B\x44\x24\x2A\x50\xB9\x2A\x2A\x2A\x2A\xE8"
    1.26  	#define ISERVER_WIN_SIG_LEN			11
    1.27  void GetIServer()
    1.28  {
    1.29 -	/* First check that the IVEngineServer::CreateFakeClient exists */
    1.30 -	if (!memutils->FindPattern(engine, ISERVER_WIN_SIG, ISERVER_WIN_SIG_LEN))
    1.31 -	{
    1.32 -		return;
    1.33 -	}
    1.34 -
    1.35  	int offset;
    1.36  	void *vfunc = NULL;
    1.37  
    1.38 @@ -110,6 +120,12 @@
    1.39  		return;
    1.40  	}
    1.41  
    1.42 +	/* Check if we're on the expected function */
    1.43 +	if (!vcmp(vfunc, ISERVER_WIN_SIG, ISERVER_WIN_SIG_LEN))
    1.44 +	{
    1.45 +		return;
    1.46 +	}
    1.47 +
    1.48  	/* Finally we have the interface we were looking for */
    1.49  	iserver = *reinterpret_cast<IServer **>(reinterpret_cast<unsigned char *>(vfunc) + offset);
    1.50  #else
    1.51 @@ -123,6 +139,11 @@
    1.52  		void **vtable = *reinterpret_cast<void ***>(enginePatch->GetThisPtr() + info.thisptroffs + info.vtbloffs);
    1.53  		vfunc = vtable[info.vtblindex];
    1.54  	}
    1.55 +	/* Check if we're on the expected function */
    1.56 +	if (!vcmp(vfunc, ISERVER_WIN_SIG, ISERVER_WIN_SIG_LEN))
    1.57 +	{
    1.58 +		return;
    1.59 +	}
    1.60  
    1.61  	iserver = *reinterpret_cast<IServer **>(reinterpret_cast<unsigned char *>(vfunc) + offset);
    1.62  #endif
    1.63 @@ -136,6 +157,6 @@
    1.64  		return;
    1.65  	}
    1.66  
    1.67 -	iserver = *reinterpret_cast<IServer **>(addr);
    1.68 +	iserver = reinterpret_cast<IServer *>(addr);
    1.69  }
    1.70  #endif
     2.1 --- a/extensions/sdktools/vhelpers.cpp	Thu Dec 06 14:08:22 2007 +0000
     2.2 +++ b/extensions/sdktools/vhelpers.cpp	Fri Dec 07 00:17:24 2007 +0000
     2.3 @@ -272,7 +272,7 @@
     2.4  #if defined ORANGEBOX_BUILD
     2.5  	return engine->GetPlayerInfo(client, info);
     2.6  #else
     2.7 -	return iserver->GetPlayerInfo(client, info);
     2.8 +	return (iserver) ? iserver->GetPlayerInfo(client-1, info) : false;
     2.9  #endif
    2.10  }
    2.11  
     3.1 --- a/extensions/sdktools/vnatives.cpp	Thu Dec 06 14:08:22 2007 +0000
     3.2 +++ b/extensions/sdktools/vnatives.cpp	Fri Dec 07 00:17:24 2007 +0000
     3.3 @@ -853,6 +853,11 @@
     3.4  
     3.5  static cell_t GetServerNetStats(IPluginContext *pContext, const cell_t *params)
     3.6  {
     3.7 +	if (iserver == NULL)
     3.8 +	{
     3.9 +		return pContext->ThrowNativeError("IServer interface not supported, file a bug report.");
    3.10 +	}
    3.11 +
    3.12  	float in, out;
    3.13  	cell_t *pIn, *pOut;
    3.14