From 2733e538007fcfe7d5874b12747df7aab2fd6fba Mon Sep 17 00:00:00 2001 From: BotoX Date: Mon, 5 Dec 2016 23:05:51 +0100 Subject: [PATCH] New plugin: RandomTriggerTouch randomizes OnTrigger !activator by randomizing calls to trigger_multiple Touch --- AntiFlood/scripting/AntiFlood.sp | 2 +- .../scripting/RandomTriggerTouch.sp | 136 ++++++++++++++++++ .../scripting/include/CSSFixes.inc | 1 + ReservedSlot/scripting/ReservedSlot.sp | 2 +- includes/CSSFixes.inc | 29 ++++ includes/pscd.inc | 4 +- 6 files changed, 170 insertions(+), 4 deletions(-) create mode 100644 RandomTriggerTouch/scripting/RandomTriggerTouch.sp create mode 120000 RandomTriggerTouch/scripting/include/CSSFixes.inc create mode 100644 includes/CSSFixes.inc diff --git a/AntiFlood/scripting/AntiFlood.sp b/AntiFlood/scripting/AntiFlood.sp index c2754266..8fa66f84 100644 --- a/AntiFlood/scripting/AntiFlood.sp +++ b/AntiFlood/scripting/AntiFlood.sp @@ -14,7 +14,7 @@ public Plugin myinfo = name = "AntiFlood", author = "BotoX", description = "", - version = "0.1", + version = "1.0", url = "" }; diff --git a/RandomTriggerTouch/scripting/RandomTriggerTouch.sp b/RandomTriggerTouch/scripting/RandomTriggerTouch.sp new file mode 100644 index 00000000..334d5ab3 --- /dev/null +++ b/RandomTriggerTouch/scripting/RandomTriggerTouch.sp @@ -0,0 +1,136 @@ +#include +#include +#include +#include + +#pragma semicolon 1 +#pragma newdecls required + +Handle g_hCBaseEntity_Touch; +bool g_bIgnoreHook = false; + +#define TOUCHED_MAX (MAXPLAYERS + 1) +int g_aTouched[TOUCHED_MAX]; +int g_aaTouchedList[TOUCHED_MAX][MAXPLAYERS + 1]; +int g_aTouchedListSize[TOUCHED_MAX]; + +public Plugin myinfo = +{ + name = "Randomize Trigger Touch", + author = "BotoX", + description = "Randomize Touches on trigger_multiple", + version = "1.0" +} + +public void OnPluginStart() +{ + Handle hGameConf = LoadGameConfigFile("sdkhooks.games"); + if(hGameConf == INVALID_HANDLE) + { + SetFailState("Couldn't load sdkhooks.games game config!"); + return; + } + + if(GameConfGetOffset(hGameConf, "Touch") == -1) + { + CloseHandle(hGameConf); + SetFailState("Couldn't get Touch offset from game config!"); + return; + } + + // void CBaseEntity::Touch( CBaseEntity *pOther ) + StartPrepSDKCall(SDKCall_Entity); + if(!PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "Touch")) + { + CloseHandle(hGameConf); + SetFailState("PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, \"Touch\" failed!"); + return; + } + PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer); + g_hCBaseEntity_Touch = EndPrepSDKCall(); + + // Late load + int entity = INVALID_ENT_REFERENCE; + while((entity = FindEntityByClassname(entity, "trigger_multiple")) != INVALID_ENT_REFERENCE) + { + SDKHook(entity, SDKHook_Touch, OnTouch); + } +} + +public void OnRunThinkFunctionsPost(bool simulating) +{ + g_bIgnoreHook = true; + for(int i = 0; i < sizeof(g_aTouched); i++) + { + if(!g_aTouched[i]) + break; + + if(!IsValidEntity(g_aTouched[i])) + continue; + + // Fisher-Yates Shuffle + for(int j = g_aTouchedListSize[i] - 1; j >= 1; j--) + { + int k = GetRandomInt(0, j); + int t = g_aaTouchedList[i][j]; + g_aaTouchedList[i][j] = g_aaTouchedList[i][k]; + g_aaTouchedList[i][k] = t; + } + + for(int j = 0; j < g_aTouchedListSize[i]; j++) + { + if(IsValidEntity(g_aaTouchedList[i][j])) + SDKCall(g_hCBaseEntity_Touch, g_aTouched[i], g_aaTouchedList[i][j]); + } + + g_aTouched[i] = 0; + g_aTouchedListSize[i] = 0; + } + g_bIgnoreHook = false; +} + +public void OnEntityCreated(int entity, const char[] classname) +{ + if(StrEqual(classname, "trigger_multiple")) + { + SDKHook(entity, SDKHook_Touch, OnTouch); + } +} + +public Action OnTouch(int touched, int toucher) +{ + if(toucher > MAXPLAYERS || g_bIgnoreHook) + return Plugin_Continue; + + int i; + for(i = 0; i < sizeof(g_aTouched); i++) + { + if(!g_aTouched[i] || g_aTouched[i] == touched) + break; + } + + if(i == sizeof(g_aTouched)) + return Plugin_Continue; + + g_aTouched[i] = touched; + + for(int j = 0; j < g_aTouchedListSize[i]; j++) + { + if(g_aaTouchedList[i][j] == toucher) + return Plugin_Handled; + } + + g_aaTouchedList[i][g_aTouchedListSize[i]++] = toucher; + + return Plugin_Handled; +} + +stock int GetHighestClientIndex() +{ + for(int i = MaxClients; i >= 1; i--) + { + if(IsValidEntity(i)) + return i; + } + return 0; +} diff --git a/RandomTriggerTouch/scripting/include/CSSFixes.inc b/RandomTriggerTouch/scripting/include/CSSFixes.inc new file mode 120000 index 00000000..aa0b4998 --- /dev/null +++ b/RandomTriggerTouch/scripting/include/CSSFixes.inc @@ -0,0 +1 @@ +../../../includes/CSSFixes.inc \ No newline at end of file diff --git a/ReservedSlot/scripting/ReservedSlot.sp b/ReservedSlot/scripting/ReservedSlot.sp index 8d4788af..73b30c57 100644 --- a/ReservedSlot/scripting/ReservedSlot.sp +++ b/ReservedSlot/scripting/ReservedSlot.sp @@ -22,7 +22,7 @@ public Plugin myinfo = name = "Reserved Slot", author = "BotoX", description = "Kicks someone to make space for a connecting donator.", - version = "0.1", + version = "1.0", url = "" }; diff --git a/includes/CSSFixes.inc b/includes/CSSFixes.inc new file mode 100644 index 00000000..84751b47 --- /dev/null +++ b/includes/CSSFixes.inc @@ -0,0 +1,29 @@ +#if defined _cssfixes_included + #endinput +#endif +#define _cssfixes_included + +forward void OnRunThinkFunctions(bool simulating); +forward void OnRunThinkFunctionsPost(bool simulating); + +public Extension:__ext_CSSFixes = +{ + name = "CSSFixes", + file = "CSSFixes.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_CSSFixes_SetNTVOptional() +{ +} +#endif diff --git a/includes/pscd.inc b/includes/pscd.inc index 4acd0124..70046fc9 100644 --- a/includes/pscd.inc +++ b/includes/pscd.inc @@ -61,7 +61,7 @@ public Extension:__ext_PointDetour = }; #if !defined REQUIRE_EXTENSIONS -public __ext_dhooks_SetNTVOptional() +public __ext_PointDetour_SetNTVOptional() { } -#endif \ No newline at end of file +#endif