From d83497c0cb71c658b20a4f40791c20f0a27371b0 Mon Sep 17 00:00:00 2001
From: BotoX <github@botox.bz>
Date: Wed, 18 Dec 2019 12:02:38 +0100
Subject: [PATCH] move some features from CSSFixes to PhysHooks

---
 AntiLagSwitch/scripting/AntiLagSwitch.sp     |  2 +-
 LagCompensation/scripting/LagCompensation.sp | 44 +++++++++---------
 SelectiveBhop/scripting/SelectiveBhop.sp     |  2 +-
 includes/CSSFixes.inc                        | 17 -------
 includes/PhysHooks.inc                       | 47 ++++++++++++++++++++
 5 files changed, 71 insertions(+), 41 deletions(-)
 create mode 100644 includes/PhysHooks.inc

diff --git a/AntiLagSwitch/scripting/AntiLagSwitch.sp b/AntiLagSwitch/scripting/AntiLagSwitch.sp
index a8185a12..04431a28 100644
--- a/AntiLagSwitch/scripting/AntiLagSwitch.sp
+++ b/AntiLagSwitch/scripting/AntiLagSwitch.sp
@@ -1,6 +1,6 @@
 #include <sourcemod>
 #include <sdktools>
-#include <CSSFixes>
+#include <PhysHooks>
 #include <dhooks>
 
 #pragma semicolon 1
diff --git a/LagCompensation/scripting/LagCompensation.sp b/LagCompensation/scripting/LagCompensation.sp
index f20d648e..0b1b87f8 100644
--- a/LagCompensation/scripting/LagCompensation.sp
+++ b/LagCompensation/scripting/LagCompensation.sp
@@ -1,7 +1,7 @@
 #include <sourcemod>
 #include <sdkhooks>
 #include <sdktools>
-#include <CSSFixes>
+#include <PhysHooks>
 #include <dhooks>
 
 #define SetBit(%1,%2)		((%1)[(%2) >> 5] |= (1 << ((%2) & 31)))
@@ -21,7 +21,7 @@ public Plugin myinfo =
 };
 
 bool g_bLateLoad = false;
-bool g_bHasCSSFixes = true;
+bool g_bHasPhysHooks = true;
 
 // Don't change this.
 #define MAX_EDICTS 2048
@@ -134,8 +134,8 @@ int g_iSimulationTime;
 int g_iCoordinateFrame;
 
 int g_aLagCompensated[MAX_EDICTS] = {-1, ...};
-int g_aFilterTriggerTouch[MAX_EDICTS / 32];
-int g_aaFilterClientEntity[((MAXPLAYERS + 1) * MAX_EDICTS) / 32];
+int g_aBlockTriggerTouchPlayers[MAX_EDICTS / 32];
+int g_aaFilterClientSolidTouch[((MAXPLAYERS + 1) * MAX_EDICTS) / 32];
 int g_aBlockTriggerMoved[MAX_EDICTS / 32];
 int g_aBlacklisted[MAX_EDICTS / 32];
 
@@ -271,7 +271,7 @@ public void OnPluginStart()
 	RegAdminCmd("sm_unlag", Command_AddLagCompensation, ADMFLAG_RCON, "sm_unlag <entidx>");
 	RegAdminCmd("sm_lagged", Command_CheckLagCompensated, ADMFLAG_GENERIC, "sm_lagged");
 
-	FilterClientEntityMap(g_aaFilterClientEntity, true);
+	FilterClientSolidTouch(g_aaFilterClientSolidTouch, true);
 	BlockTriggerMoved(g_aBlockTriggerMoved, true);
 }
 
@@ -283,18 +283,18 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
 
 public void OnLibraryRemoved(const char[] name)
 {
-	if(StrEqual(name, "CSSFixes"))
-		g_bHasCSSFixes = false;
+	if(StrEqual(name, "PhysHooks"))
+		g_bHasPhysHooks = false;
 }
 
 public void OnPluginEnd()
 {
 	g_bCleaningUp = true;
-	if(g_bHasCSSFixes)
+	if(g_bHasPhysHooks)
 	{
-		FilterClientEntityMap(g_aaFilterClientEntity, false);
+		FilterClientSolidTouch(g_aaFilterClientSolidTouch, false);
 		BlockTriggerMoved(g_aBlockTriggerMoved, false);
-		FilterTriggerTouchPlayers(g_aFilterTriggerTouch, false);
+		BlockTriggerTouchPlayers(g_aBlockTriggerTouchPlayers, false);
 	}
 
 	DHookDisableDetour(g_hUTIL_Remove, false, Detour_OnUTIL_Remove);
@@ -613,12 +613,12 @@ public MRESReturn Detour_OnRestartRound()
 		int iEntity = g_aEntityLagData[i].iEntity;
 
 		g_aLagCompensated[iEntity] = -1;
-		ClearBit(g_aFilterTriggerTouch, iEntity);
+		ClearBit(g_aBlockTriggerTouchPlayers, iEntity);
 		ClearBit(g_aBlockTriggerMoved, iEntity);
 
 		for(int client = 1; client <= MaxClients; client++)
 		{
-			ClearBit(g_aaFilterClientEntity, client * MAX_EDICTS + iEntity);
+			ClearBit(g_aaFilterClientSolidTouch, client * MAX_EDICTS + iEntity);
 		}
 
 		if(g_aEntityLagData[i].iDeleted)
@@ -693,7 +693,7 @@ public MRESReturn Detour_OnFrameUpdatePostEntityThink()
 
 public void OnRunThinkFunctions(bool simulating)
 {
-	FilterTriggerTouchPlayers(g_aFilterTriggerTouch, false);
+	BlockTriggerTouchPlayers(g_aBlockTriggerTouchPlayers, false);
 
 	for(int i = 0; i < g_iNumEntities; i++)
 	{
@@ -766,19 +766,19 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
 		// Entity too new, the client couldn't even see it yet.
 		if(g_aEntityLagData[i].iSpawned > iPlayerSimTick)
 		{
-			SetBit(g_aaFilterClientEntity, client * MAX_EDICTS + iEntity);
+			SetBit(g_aaFilterClientSolidTouch, client * MAX_EDICTS + iEntity);
 			continue;
 		}
 		else if(g_aEntityLagData[i].iSpawned == iPlayerSimTick)
 		{
-			ClearBit(g_aaFilterClientEntity, client * MAX_EDICTS + iEntity);
+			ClearBit(g_aaFilterClientSolidTouch, client * MAX_EDICTS + iEntity);
 		}
 
 		if(g_aEntityLagData[i].iDeleted)
 		{
 			if(g_aEntityLagData[i].iDeleted <= iPlayerSimTick)
 			{
-				SetBit(g_aaFilterClientEntity, client * MAX_EDICTS + iEntity);
+				SetBit(g_aaFilterClientSolidTouch, client * MAX_EDICTS + iEntity);
 				continue;
 			}
 		}
@@ -815,7 +815,7 @@ public void OnPostPlayerThinkFunctions()
 		g_aEntityLagData[i].bRestore = false;
 	}
 
-	FilterTriggerTouchPlayers(g_aFilterTriggerTouch, true);
+	BlockTriggerTouchPlayers(g_aBlockTriggerTouchPlayers, true);
 }
 
 public void OnRunThinkFunctionsPost(bool simulating)
@@ -999,7 +999,7 @@ bool AddEntityForLagCompensation(int iEntity, bool bLateKill)
 
 	if(bLateKill)
 	{
-		SetBit(g_aFilterTriggerTouch, iEntity);
+		SetBit(g_aBlockTriggerTouchPlayers, iEntity);
 	}
 
 	RecordDataIntoRecord(iEntity, g_aaLagRecords[i][0]);
@@ -1050,12 +1050,12 @@ void RemoveRecord(int index)
 	}
 
 	g_aLagCompensated[iEntity] = -1;
-	ClearBit(g_aFilterTriggerTouch, iEntity);
+	ClearBit(g_aBlockTriggerTouchPlayers, iEntity);
 	ClearBit(g_aBlockTriggerMoved, iEntity);
 
 	for(int client = 1; client <= MaxClients; client++)
 	{
-		ClearBit(g_aaFilterClientEntity, client * MAX_EDICTS + iEntity);
+		ClearBit(g_aaFilterClientSolidTouch, client * MAX_EDICTS + iEntity);
 	}
 
 	g_aEntityLagData[index].iEntity = INVALID_ENT_REFERENCE;
@@ -1168,14 +1168,14 @@ public Action Command_CheckLagCompensated(int client, int argc)
 		bool bDeleted = false;
 		for(int j = 1; j <= MaxClients; j++)
 		{
-			if(CheckBit(g_aaFilterClientEntity, j * MAX_EDICTS + iEntity))
+			if(CheckBit(g_aaFilterClientSolidTouch, j * MAX_EDICTS + iEntity))
 			{
 				bDeleted = true;
 				break;
 			}
 		}
 
-		bool bBlockPhysics = CheckBit(g_aFilterTriggerTouch, iEntity);
+		bool bBlockPhysics = CheckBit(g_aBlockTriggerTouchPlayers, iEntity);
 		bool bBlockTriggerMoved = CheckBit(g_aBlockTriggerMoved, iEntity);
 		bool bBlacklisted = CheckBit(g_aBlacklisted, iEntity);
 
diff --git a/SelectiveBhop/scripting/SelectiveBhop.sp b/SelectiveBhop/scripting/SelectiveBhop.sp
index 9a48c93b..d2f5f8bf 100644
--- a/SelectiveBhop/scripting/SelectiveBhop.sp
+++ b/SelectiveBhop/scripting/SelectiveBhop.sp
@@ -3,7 +3,7 @@
 
 #include <sourcemod>
 #include <sdkhooks>
-#include <CSSFixes>
+#include <PhysHooks>
 #undef REQUIRE_PLUGIN
 #include <zombiereloaded>
 #define REQUIRE_PLUGIN
diff --git a/includes/CSSFixes.inc b/includes/CSSFixes.inc
index de9998e3..a75d2934 100644
--- a/includes/CSSFixes.inc
+++ b/includes/CSSFixes.inc
@@ -3,23 +3,6 @@
 #endif
 #define _cssfixes_included
 
-forward void OnRunThinkFunctions(bool simulating);
-forward void OnPrePlayerThinkFunctions();
-forward void OnPostPlayerThinkFunctions();
-forward void OnRunThinkFunctionsPost(bool simulating);
-
-// Block TriggerMoved from being called at all for an entity by setting the bit to 1.
-native void BlockTriggerMoved(int map[2048 / 32], bool set);
-
-// Block SolidMoved from being called at all for an entity by setting the bit to 1.
-native void BlockSolidMoved(int map[2048 / 32], bool set);
-
-// Block clients SolidMoved from touching an entity by setting the bit to 1 in the clients map.
-native void FilterClientEntityMap(int map[((MAXPLAYERS + 1) * 2048) / 32], bool set);
-
-// Block triggers TriggerMoved from touching any client by setting the bit to 1 for the entity index.
-native void FilterTriggerTouchPlayers(int map[2048 / 32], bool set);
-
 // 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.)
 native void PhysboxToClientMap(char map[2048], bool set);
diff --git a/includes/PhysHooks.inc b/includes/PhysHooks.inc
new file mode 100644
index 00000000..8b27a777
--- /dev/null
+++ b/includes/PhysHooks.inc
@@ -0,0 +1,47 @@
+#if defined _physhooks_included
+ #endinput
+#endif
+#define _physhooks_included
+
+forward void OnRunThinkFunctions(bool simulating);
+forward void OnPrePlayerThinkFunctions();
+forward void OnPostPlayerThinkFunctions();
+forward void OnRunThinkFunctionsPost(bool simulating);
+
+// Block TriggerMoved from being called at all for an entity by setting the bit to 1.
+native void BlockTriggerMoved(int map[2048 / 32], bool set);
+
+// Block triggers TriggerMoved from touching any client by setting the bit to 1 for the entity index.
+native void BlockTriggerTouchPlayers(int map[2048 / 32], bool set);
+
+// Block SolidMoved from being called at all for an entity by setting the bit to 1.
+native void BlockSolidMoved(int map[2048 / 32], bool set);
+
+// Block solids SolidMoved from touching any client by setting the bit to 1 for the entity index.
+native void BlockSolidTouchPlayers(int map[2048 / 32], bool set);
+
+// Block clients SolidMoved from touching an entity by setting the bit to 1 in the clients map.
+native void FilterClientSolidTouch(int map[((MAXPLAYERS + 1) * 2048) / 32], bool set);
+
+
+public Extension __ext_PhysHooks =
+{
+	name = "PhysHooks",
+	file = "PhysHooks.ext",
+#if defined AUTOLOAD_EXTENSIONS
+	autoload = 1,
+#else
+	autoload = 0,
+#endif
+#if defined REQUIRE_EXTENSIONS
+	required = 1,
+#else
+	required = 0,
+#endif
+};
+
+#if !defined REQUIRE_EXTENSIONS
+public __ext_PhysHooks_SetNTVOptional()
+{
+}
+#endif