forked from CSSZombieEscape/sm-ext-CSSFixes
		
	Use bitfields instead of char arrays, make natives more useful for blocking TriggerMoved and SolidMoved.
This commit is contained in:
		@@ -38,6 +38,10 @@
 | 
				
			|||||||
#include <server_class.h>
 | 
					#include <server_class.h>
 | 
				
			||||||
#include <ispatialpartition.h>
 | 
					#include <ispatialpartition.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define SetBit(A,I)		((A)[(I) >> 5] |= (1 << ((I) & 31)))
 | 
				
			||||||
 | 
					#define ClearBit(A,I)	((A)[(I) >> 5] &= ~(1 << ((I) & 31)))
 | 
				
			||||||
 | 
					#define CheckBit(A,I)	!!((A)[(I) >> 5] & (1 << ((I) & 31)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool UTIL_ContainsDataTable(SendTable *pTable, const char *name)
 | 
					bool UTIL_ContainsDataTable(SendTable *pTable, const char *name)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const char *pname = pTable->GetName();
 | 
						const char *pname = pTable->GetName();
 | 
				
			||||||
@@ -520,21 +524,16 @@ void Physics_SimulateEntity_CustomLoop(CBaseEntity **ppList, int Count, float St
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int g_TriggerEntityMoved;
 | 
					int g_TriggerEntityMoved;
 | 
				
			||||||
char *g_pFilterTriggerTouchPlayers = NULL;
 | 
					int *g_pFilterTriggerTouchPlayers = NULL;
 | 
				
			||||||
int g_FilterTriggerMoved = -1;
 | 
					int *g_pBlockTriggerMoved = NULL;
 | 
				
			||||||
// void IVEngineServer::TriggerMoved( edict_t *pTriggerEnt, bool testSurroundingBoundsOnly ) = 0;
 | 
					// void IVEngineServer::TriggerMoved( edict_t *pTriggerEnt, bool testSurroundingBoundsOnly ) = 0;
 | 
				
			||||||
SH_DECL_HOOK2_void(IVEngineServer, TriggerMoved, SH_NOATTRIB, 0, edict_t *, bool);
 | 
					SH_DECL_HOOK2_void(IVEngineServer, TriggerMoved, SH_NOATTRIB, 0, edict_t *, bool);
 | 
				
			||||||
void TriggerMoved(edict_t *pTriggerEnt, bool testSurroundingBoundsOnly)
 | 
					void TriggerMoved(edict_t *pTriggerEnt, bool testSurroundingBoundsOnly)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	g_TriggerEntityMoved = gamehelpers->IndexOfEdict(pTriggerEnt);
 | 
						g_TriggerEntityMoved = gamehelpers->IndexOfEdict(pTriggerEnt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Allow all
 | 
						// Block if bit is set
 | 
				
			||||||
	if(g_FilterTriggerMoved == -1)
 | 
						if(g_pBlockTriggerMoved && CheckBit(g_pBlockTriggerMoved, g_TriggerEntityMoved))
 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		RETURN_META(MRES_IGNORED);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// Block All
 | 
					 | 
				
			||||||
	else if(g_FilterTriggerMoved == 0)
 | 
					 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		RETURN_META(MRES_SUPERCEDE);
 | 
							RETURN_META(MRES_SUPERCEDE);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -547,7 +546,7 @@ void TriggerMoved(edict_t *pTriggerEnt, bool testSurroundingBoundsOnly)
 | 
				
			|||||||
SH_DECL_HOOK1(CTriggerMoved, EnumElement, SH_NOATTRIB, 0, IterationRetval_t, IHandleEntity *);
 | 
					SH_DECL_HOOK1(CTriggerMoved, EnumElement, SH_NOATTRIB, 0, IterationRetval_t, IHandleEntity *);
 | 
				
			||||||
IterationRetval_t TriggerMoved_EnumElement(IHandleEntity *pHandleEntity)
 | 
					IterationRetval_t TriggerMoved_EnumElement(IHandleEntity *pHandleEntity)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if(g_FilterTriggerMoved <= 0 && !g_pFilterTriggerTouchPlayers)
 | 
						if(!g_pFilterTriggerTouchPlayers)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		RETURN_META_VALUE(MRES_IGNORED, ITERATION_CONTINUE);
 | 
							RETURN_META_VALUE(MRES_IGNORED, ITERATION_CONTINUE);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -562,14 +561,8 @@ IterationRetval_t TriggerMoved_EnumElement(IHandleEntity *pHandleEntity)
 | 
				
			|||||||
		RETURN_META_VALUE(MRES_IGNORED, ITERATION_CONTINUE);
 | 
							RETURN_META_VALUE(MRES_IGNORED, ITERATION_CONTINUE);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// block touching any clients here if map exists and evaluates to true
 | 
						// block touching any clients here if bit is set
 | 
				
			||||||
	if(g_pFilterTriggerTouchPlayers && g_pFilterTriggerTouchPlayers[g_TriggerEntityMoved])
 | 
						if(CheckBit(g_pFilterTriggerTouchPlayers, g_TriggerEntityMoved))
 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		RETURN_META_VALUE(MRES_SUPERCEDE, ITERATION_CONTINUE);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// if filter is active block touch from all other players
 | 
					 | 
				
			||||||
	if(g_FilterTriggerMoved > 0 && index != g_FilterTriggerMoved)
 | 
					 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		RETURN_META_VALUE(MRES_SUPERCEDE, ITERATION_CONTINUE);
 | 
							RETURN_META_VALUE(MRES_SUPERCEDE, ITERATION_CONTINUE);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -578,16 +571,20 @@ IterationRetval_t TriggerMoved_EnumElement(IHandleEntity *pHandleEntity)
 | 
				
			|||||||
	RETURN_META_VALUE(MRES_IGNORED, ITERATION_CONTINUE);
 | 
						RETURN_META_VALUE(MRES_IGNORED, ITERATION_CONTINUE);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cell_t FilterTriggerMoved(IPluginContext *pContext, const cell_t *params)
 | 
					cell_t BlockTriggerMoved(IPluginContext *pContext, const cell_t *params)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	g_FilterTriggerMoved = params[1];
 | 
						if(params[2])
 | 
				
			||||||
 | 
							pContext->LocalToPhysAddr(params[1], &g_pBlockTriggerMoved);
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							g_pBlockTriggerMoved = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cell_t FilterTriggerTouchPlayers(IPluginContext *pContext, const cell_t *params)
 | 
					cell_t FilterTriggerTouchPlayers(IPluginContext *pContext, const cell_t *params)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if(params[2])
 | 
						if(params[2])
 | 
				
			||||||
		pContext->LocalToPhysAddr(params[1], (cell_t **)&g_pFilterTriggerTouchPlayers);
 | 
							pContext->LocalToPhysAddr(params[1], &g_pFilterTriggerTouchPlayers);
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		g_pFilterTriggerTouchPlayers = NULL;
 | 
							g_pFilterTriggerTouchPlayers = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -595,32 +592,21 @@ cell_t FilterTriggerTouchPlayers(IPluginContext *pContext, const cell_t *params)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int g_SolidEntityMoved;
 | 
					int g_SolidEntityMoved;
 | 
				
			||||||
int g_BlockSolidMoved = -1;
 | 
					int *g_pBlockSolidMoved = NULL;
 | 
				
			||||||
char *g_pFilterClientEntityMap = NULL;
 | 
					int *g_pFilterClientEntityMap = NULL;
 | 
				
			||||||
// void IVEngineServer::SolidMoved( edict_t *pSolidEnt, ICollideable *pSolidCollide, const Vector* pPrevAbsOrigin, bool testSurroundingBoundsOnly ) = 0;
 | 
					// void IVEngineServer::SolidMoved( edict_t *pSolidEnt, ICollideable *pSolidCollide, const Vector* pPrevAbsOrigin, bool testSurroundingBoundsOnly ) = 0;
 | 
				
			||||||
SH_DECL_HOOK4_void(IVEngineServer, SolidMoved, SH_NOATTRIB, 0, edict_t *, ICollideable *, const Vector *, bool);
 | 
					SH_DECL_HOOK4_void(IVEngineServer, SolidMoved, SH_NOATTRIB, 0, edict_t *, ICollideable *, const Vector *, bool);
 | 
				
			||||||
void SolidMoved(edict_t *pSolidEnt, ICollideable *pSolidCollide, const Vector *pPrevAbsOrigin, bool testSurroundingBoundsOnly)
 | 
					void SolidMoved(edict_t *pSolidEnt, ICollideable *pSolidCollide, const Vector *pPrevAbsOrigin, bool testSurroundingBoundsOnly)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	g_SolidEntityMoved = gamehelpers->IndexOfEdict(pSolidEnt);
 | 
						g_SolidEntityMoved = gamehelpers->IndexOfEdict(pSolidEnt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Allow all
 | 
						// Block if bit is set
 | 
				
			||||||
	if(g_BlockSolidMoved == -1)
 | 
						if(g_pBlockSolidMoved && CheckBit(g_pBlockSolidMoved, g_TriggerEntityMoved))
 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		RETURN_META(MRES_IGNORED);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// Block all
 | 
					 | 
				
			||||||
	else if(g_BlockSolidMoved == 0)
 | 
					 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		RETURN_META(MRES_SUPERCEDE);
 | 
							RETURN_META(MRES_SUPERCEDE);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Block filtered entity
 | 
						// Decide per entity in TouchLinks_EnumElement
 | 
				
			||||||
	if(g_SolidEntityMoved == g_BlockSolidMoved)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		RETURN_META(MRES_SUPERCEDE);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Allow all others
 | 
					 | 
				
			||||||
	RETURN_META(MRES_IGNORED);
 | 
						RETURN_META(MRES_IGNORED);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -650,12 +636,8 @@ IterationRetval_t TouchLinks_EnumElement(IHandleEntity *pHandleEntity)
 | 
				
			|||||||
		RETURN_META_VALUE(MRES_IGNORED, ITERATION_CONTINUE);
 | 
							RETURN_META_VALUE(MRES_IGNORED, ITERATION_CONTINUE);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// SourcePawn char map[MAXPLAYERS + 1][2048]
 | 
					 | 
				
			||||||
	// Contiguous memory, shift array by client idx * 2048
 | 
					 | 
				
			||||||
	int arrayIdx = g_SolidEntityMoved * 2048 + index;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Block player from touching this entity if it's filtered
 | 
						// Block player from touching this entity if it's filtered
 | 
				
			||||||
	if(g_pFilterClientEntityMap[arrayIdx])
 | 
						if(CheckBit(g_pFilterClientEntityMap, g_SolidEntityMoved * 2048 + index))
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		RETURN_META_VALUE(MRES_SUPERCEDE, ITERATION_CONTINUE);
 | 
							RETURN_META_VALUE(MRES_SUPERCEDE, ITERATION_CONTINUE);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -666,14 +648,18 @@ IterationRetval_t TouchLinks_EnumElement(IHandleEntity *pHandleEntity)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
cell_t BlockSolidMoved(IPluginContext *pContext, const cell_t *params)
 | 
					cell_t BlockSolidMoved(IPluginContext *pContext, const cell_t *params)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	g_BlockSolidMoved = params[1];
 | 
						if(params[2])
 | 
				
			||||||
 | 
							pContext->LocalToPhysAddr(params[1], &g_pBlockSolidMoved);
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							g_pBlockSolidMoved = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cell_t FilterClientEntityMap(IPluginContext *pContext, const cell_t *params)
 | 
					cell_t FilterClientEntityMap(IPluginContext *pContext, const cell_t *params)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if(params[2])
 | 
						if(params[2])
 | 
				
			||||||
		pContext->LocalToPhysAddr(params[1], (cell_t **)&g_pFilterClientEntityMap);
 | 
							pContext->LocalToPhysAddr(params[1], &g_pFilterClientEntityMap);
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		g_pFilterClientEntityMap = NULL;
 | 
							g_pFilterClientEntityMap = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -945,7 +931,7 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const sp_nativeinfo_t MyNatives[] =
 | 
					const sp_nativeinfo_t MyNatives[] =
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	{ "FilterTriggerMoved", FilterTriggerMoved },
 | 
						{ "BlockTriggerMoved", BlockTriggerMoved },
 | 
				
			||||||
	{ "BlockSolidMoved", BlockSolidMoved },
 | 
						{ "BlockSolidMoved", BlockSolidMoved },
 | 
				
			||||||
	{ "FilterClientEntityMap", FilterClientEntityMap },
 | 
						{ "FilterClientEntityMap", FilterClientEntityMap },
 | 
				
			||||||
	{ "FilterTriggerTouchPlayers", FilterTriggerTouchPlayers },
 | 
						{ "FilterTriggerTouchPlayers", FilterTriggerTouchPlayers },
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,23 +8,17 @@ forward void OnPrePlayerThinkFunctions();
 | 
				
			|||||||
forward void OnPostPlayerThinkFunctions();
 | 
					forward void OnPostPlayerThinkFunctions();
 | 
				
			||||||
forward void OnRunThinkFunctionsPost(bool simulating);
 | 
					forward void OnRunThinkFunctionsPost(bool simulating);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// -1 = Ignore, normal operation.
 | 
					// Block TriggerMoved from being called at all for an entity by setting the bit to 1.
 | 
				
			||||||
// 0 = Block ALL SV_TriggerMoved.
 | 
					native void BlockTriggerMoved(int map[2048 / 32], bool set);
 | 
				
			||||||
// >0 = Entity index for which to allow EnumElement to be called.
 | 
					 | 
				
			||||||
// REMEMBER TO CALL THIS AGAIN WITH -1 AFTER USING IT !!!
 | 
					 | 
				
			||||||
native void FilterTriggerMoved(int entity);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// -1 = Ignore, normal operation.
 | 
					// Block SolidMoved from being called at all for an entity by setting the bit to 1.
 | 
				
			||||||
// 0 = Block ALL SV_SolidMoved.
 | 
					native void BlockSolidMoved(int map[2048 / 32], bool set);
 | 
				
			||||||
// >0 = Entity index for which to allow SV_SolidMoved to be called.
 | 
					 | 
				
			||||||
// REMEMBER TO CALL THIS AGAIN WITH -1 AFTER USING IT !!!
 | 
					 | 
				
			||||||
native void BlockSolidMoved(int entity);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Block clients SolidMoved from touching an entity by setting it to 1 in the clients map.
 | 
					// Block clients SolidMoved from touching an entity by setting the bit to 1 in the clients map.
 | 
				
			||||||
native void FilterClientEntityMap(char map[MAXPLAYERS + 1][2048], bool set);
 | 
					native void FilterClientEntityMap(int map[((MAXPLAYERS + 1) * 2048) / 32], bool set);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Block triggers TriggerMoved from touching any client by setting it to 1 for the entity index.
 | 
					// Block triggers TriggerMoved from touching any client by setting the bit to 1 for the entity index.
 | 
				
			||||||
native void FilterTriggerTouchPlayers(char map[2048], bool set);
 | 
					native void FilterTriggerTouchPlayers(int map[2048 / 32], bool set);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Map entities to client entity in FireBullets/SwingOrStab ShouldHitEntity.
 | 
					// Map entities to client entity in FireBullets/SwingOrStab ShouldHitEntity.
 | 
				
			||||||
// Aka. shoot and knife through physboxes that are parented to teammates (white knight, gandalf, horse, etc.)
 | 
					// Aka. shoot and knife through physboxes that are parented to teammates (white knight, gandalf, horse, etc.)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,7 +40,7 @@
 | 
				
			|||||||
/* Basic information exposed publicly */
 | 
					/* Basic information exposed publicly */
 | 
				
			||||||
#define SMEXT_CONF_NAME			"CSSFixes"
 | 
					#define SMEXT_CONF_NAME			"CSSFixes"
 | 
				
			||||||
#define SMEXT_CONF_DESCRIPTION	"Patches bugs in the CSS server binary and more..."
 | 
					#define SMEXT_CONF_DESCRIPTION	"Patches bugs in the CSS server binary and more..."
 | 
				
			||||||
#define SMEXT_CONF_VERSION		"1.14"
 | 
					#define SMEXT_CONF_VERSION		"1.15"
 | 
				
			||||||
#define SMEXT_CONF_AUTHOR		"BotoX"
 | 
					#define SMEXT_CONF_AUTHOR		"BotoX"
 | 
				
			||||||
#define SMEXT_CONF_URL			""
 | 
					#define SMEXT_CONF_URL			""
 | 
				
			||||||
#define SMEXT_CONF_LOGTAG		"CSSFIXES"
 | 
					#define SMEXT_CONF_LOGTAG		"CSSFIXES"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user