Skip to content

Commit

Permalink
Merge pull request #17 from GAMMACASE/improve_wait_handling_on_triggers
Browse files Browse the repository at this point in the history
Replace OnTrigger hook with ActivateMultiTrigger
  • Loading branch information
hermansimensen authored Mar 31, 2022
2 parents 01eff5c + 009b2da commit ff6b07a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 42 deletions.
19 changes: 14 additions & 5 deletions gamedata/eventfix.games.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"windows" "\x55\x8B\xEC\x53\x8B\x5D\x0C\x85\xDB\x74\x2A"
"linux" "\x55\x89\xE5\x57\x56\x53\x83\xEC\x2C\x8B\x4D\x14"
}
"ActivateMultiTrigger"
{
"windows" "\x55\x8B\xEC\x83\xEC\x14\x53\x56\x8B\xF1\x8B\x0D\x2A\x2A\x2A\x2A\x8B\x86\x2A\x2A\x2A\x2A\x57\x8D\xBE\x2A\x2A\x2A\x2A\x83\xF8\xFF"
"linux" "\x55\x89\xE5\x56\x53\x83\xEC\x50\x8B\x5D\x08\xC7\x44\x24\x2A\x2A\x2A\x2A\x2A\x8B\x75\x0C\x89\x1C\x24\xE8"
}
}

"Offsets"
Expand All @@ -55,16 +60,20 @@
"Signatures"
{
"AddEventThree"
{
"windows" "\x55\x8B\xEC\x56\x57\x8B\xF9\xB9\x2A\x2A\x2A\x2A\x6A\x38\xE8\x2A\x2A\x2A\x2A\x8B\xF0\x85\xF6\x74\x2A\xC7\x46\x0C\xFF\xFF\xFF\xFF\xC7\x46\x10\xFF\xFF\xFF\xFF\xC7\x46\x18\xFF\xFF\xFF\xFF\xC7\x46\x1C\x00\x00\x00\x00\xC7\x46\x28\xFF\xFF\xFF\xFF\xC7\x46\x2C\x00\x00\x00\x00\xEB\x2A\x33\xF6\xA1\x2A\x2A\x2A\x2A\xF3\x0F\x10\x40\x0C"
"linux" "@_ZN11CEventQueue8AddEventEPKcS1_9variant_tfP11CBaseEntityS4_i"
}

{
"windows" "\x55\x8B\xEC\x56\x57\x8B\xF9\xB9\x2A\x2A\x2A\x2A\x6A\x38\xE8\x2A\x2A\x2A\x2A\x8B\xF0\x85\xF6\x74\x2A\xC7\x46\x0C\xFF\xFF\xFF\xFF\xC7\x46\x10\xFF\xFF\xFF\xFF\xC7\x46\x18\xFF\xFF\xFF\xFF\xC7\x46\x1C\x00\x00\x00\x00\xC7\x46\x28\xFF\xFF\xFF\xFF\xC7\x46\x2C\x00\x00\x00\x00\xEB\x2A\x33\xF6\xA1\x2A\x2A\x2A\x2A\xF3\x0F\x10\x40\x0C"
"linux" "@_ZN11CEventQueue8AddEventEPKcS1_9variant_tfP11CBaseEntityS4_i"
}
"FindEntityByName"
{
"windows" "\x55\x8B\xEC\x53\x8B\x5D\x0C\x56\x8B\xF1\x85\xDB\x74\x2A"
"linux" "@_ZN17CGlobalEntityList16FindEntityByNameEP11CBaseEntityPKcS1_S1_S1_P17IEntityFindFilter"
}
"ActivateMultiTrigger"
{
"windows" "\x55\x8B\xEC\x56\x6A\x00\x8B\xF1\xE8\x2A\x2A\x2A\x2A\xA1\x2A\x2A\x2A\x2A\xD9\x40\x0C\xD9\xC9"
"linux" "@_ZN16CTriggerMultiple20ActivateMultiTriggerEP11CBaseEntity"
}
}

"Offsets"
Expand Down
81 changes: 44 additions & 37 deletions scripting/eventqueuefix.sp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define PLUGIN_NAME "EventQueue fix"
#define PLUGIN_AUTHOR "carnifex"
#define PLUGIN_DESCRIPTION ""
#define PLUGIN_VERSION "1.2.1"
#define PLUGIN_VERSION "1.3.0"
#define PLUGIN_URL ""

#include <sourcemod>
Expand Down Expand Up @@ -48,7 +48,6 @@ public Plugin myinfo =
public void OnPluginStart()
{
LoadDHooks();
HookEntityOutput("trigger_multiple", "OnTrigger", OnTrigger);
}

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
Expand All @@ -62,7 +61,6 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max

g_bLateLoad = late;


RegPluginLibrary("eventqueuefix");

return APLRes_Success;
Expand Down Expand Up @@ -122,7 +120,7 @@ public void OnEntityCreated(int entity, const char[] classname)

void LoadDHooks()
{
GameData gamedataConf = LoadGameConfigFile("eventfix.games");
GameData gamedataConf = new GameData("eventfix.games");

if(gamedataConf == null)
{
Expand All @@ -138,7 +136,8 @@ void LoadDHooks()
else
StartPrepSDKCall(SDKCall_EntityList);

PrepSDKCall_SetFromConf(gamedataConf, SDKConf_Signature, "FindEntityByName");
if(!PrepSDKCall_SetFromConf(gamedataConf, SDKConf_Signature, "FindEntityByName"))
SetFailState("Faild to find FindEntityByName signature.");
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_ByValue);
PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer, VDECODE_FLAG_ALLOWNULL | VDECODE_FLAG_ALLOWWORLD);
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
Expand All @@ -149,7 +148,8 @@ void LoadDHooks()
g_hFindEntityByName = EndPrepSDKCall();

Handle addEventThree = DHookCreateDetour(Address_Null, CallConv_THISCALL, ReturnType_Void, ThisPointer_Ignore);
DHookSetFromConf(addEventThree, gamedataConf, SDKConf_Signature, "AddEventThree");
if(!DHookSetFromConf(addEventThree, gamedataConf, SDKConf_Signature, "AddEventThree"))
SetFailState("Faild to find AddEventThree signature.");
DHookAddParam(addEventThree, HookParamType_CharPtr);
DHookAddParam(addEventThree, HookParamType_CharPtr);
DHookAddParam(addEventThree, HookParamType_Object, 20, DHookPass_ByVal|DHookPass_ODTOR|DHookPass_OCTOR|DHookPass_OASSIGNOP);
Expand All @@ -159,7 +159,14 @@ void LoadDHooks()
DHookAddParam(addEventThree, HookParamType_Int);
if(!DHookEnableDetour(addEventThree, false, DHook_AddEventThree))
SetFailState("Couldn't enable AddEventThree detour.");


Handle activateMultiTrigger = DHookCreateDetour(Address_Null, CallConv_THISCALL, ReturnType_Void, ThisPointer_CBaseEntity);
if(!DHookSetFromConf(activateMultiTrigger, gamedataConf, SDKConf_Signature, "ActivateMultiTrigger"))
SetFailState("Faild to find ActivateMultiTrigger signature.");
DHookAddParam(activateMultiTrigger, HookParamType_CBaseEntity);
if(!DHookEnableDetour(activateMultiTrigger, false, DHook_ActivateMultiTrigger))
SetFailState("Couldn't enable ActivateMultiTrigger detour.");

delete gamedataConf;
}

Expand Down Expand Up @@ -204,7 +211,7 @@ public MRESReturn DHook_AddEventThree(Handle hParams)
event.outputID = DHookGetParam(hParams, 7);

#if defined DEBUG
PrintToChatAll("AddEventThree: %s, %s, %s, %f, %i, %i, %i, time: %f", event.target, event.targetInput, event.variantValue, event.delay, entIndex, EntRefToEntIndex(event.caller), event.outputID, GetGameTime());
PrintToServer("[%i] AddEventThree: %s, %s, %s, %f, %i, %i, %i, time: %f", GetGameTickCount(), event.target, event.targetInput, event.variantValue, event.delay, entIndex, EntRefToEntIndex(event.caller), event.outputID, GetGameTime());
#endif

g_aPlayerEvents[entIndex].PushArray(event);
Expand Down Expand Up @@ -246,39 +253,39 @@ public void ResolveVariantValue(Handle &params, event_t event)
}
}

public Action OnTrigger(const char[] output, int caller, int activator, float delay)
public MRESReturn DHook_ActivateMultiTrigger(int pThis, DHookParam hParams)
{
if(activator <= MAXPLAYERS && activator > 0)
int client = hParams.Get(1);

if(!(0 < client <= MaxClients) || !IsClientInGame(client) || IsFakeClient(client))
return MRES_Ignored;

float m_flWait = GetEntPropFloat(pThis, Prop_Data, "m_flWait");

bool bFound;
entity_t ent;
for(int i = 0; i < g_aOutputWait[client].Length; i++)
{
float m_flWait = GetEntPropFloat(caller, Prop_Data, "m_flWait");

bool bFound;
entity_t ent;
for(int i = 0; i < g_aOutputWait[activator].Length; i++)
{
g_aOutputWait[activator].GetArray(i, ent);

if(caller == EntRefToEntIndex(ent.caller))
{
bFound = true;
break;
}
}
g_aOutputWait[client].GetArray(i, ent);

if(!bFound)
if(pThis == EntRefToEntIndex(ent.caller))
{
ent.caller = EntIndexToEntRef(caller);
int ticks = RoundToCeil((m_flWait - FLT_EPSILON) / GetTickInterval());
ent.waitTime = float(ticks);
g_aOutputWait[activator].PushArray(ent);
return Plugin_Continue;
bFound = true;
break;
}
else
{
return Plugin_Handled;
}
}
return Plugin_Continue;
}

if(!bFound)
{
ent.caller = EntIndexToEntRef(pThis);
int ticks = RoundToCeil((m_flWait - FLT_EPSILON) / GetTickInterval());
ent.waitTime = float(ticks);
g_aOutputWait[client].PushArray(ent);
SetEntProp(pThis, Prop_Data, "m_nNextThinkTick", 0);
return MRES_Ignored;
}

return MRES_Supercede;
}

int FindEntityByName(int startEntity, char[] targetname, int searchingEnt, int activator, int caller)
Expand Down Expand Up @@ -308,7 +315,7 @@ public void ServiceEvent(event_t event)
AcceptEntityInput(targetEntity, event.targetInput, activator, caller, event.outputID);

#if defined DEBUG
PrintToChat(activator, "Performing output: %s, %i, %i, %s %s, %i, %f", event.target, targetEntity, caller, event.targetInput, event.variantValue, event.outputID, GetGameTime());
PrintToServer("[%i] Performing output: %s, %i, %i, %s %s, %i, %f", GetGameTickCount(), event.target, targetEntity, caller, event.targetInput, event.variantValue, event.outputID, GetGameTime());
#endif
}
}
Expand Down

0 comments on commit ff6b07a

Please sign in to comment.