From 0458b67ac7f7c7c5ef6a57c848e2f4d12a1a84fd Mon Sep 17 00:00:00 2001 From: rtldg Date: Thu, 24 Apr 2025 00:07:01 +0000 Subject: [PATCH] Fetch callbacks for each call --- .../sourcemod/scripting/shavit-checkpoints.sp | 46 ++++++++----------- addons/sourcemod/scripting/shavit-core.sp | 34 ++++++-------- 2 files changed, 31 insertions(+), 49 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-checkpoints.sp b/addons/sourcemod/scripting/shavit-checkpoints.sp index 13fe3d0c..618b8c8d 100644 --- a/addons/sourcemod/scripting/shavit-checkpoints.sp +++ b/addons/sourcemod/scripting/shavit-checkpoints.sp @@ -117,9 +117,6 @@ int gI_Offset_m_afButtonDisabled = 0; int gI_Offset_m_afButtonForced = 0; // vscript!!! you're going to break all my checkpoints!!! -VScriptExecute gH_VScript_Timer_OnCheckpointSave; -VScriptExecute gH_VScript_Timer_OnCheckpointLoadPre; -VScriptExecute gH_VScript_Timer_OnCheckpointLoadPost; VScriptFunction gH_VScript_Timer_SetCheckpointCustomData; VScriptFunction gH_VScript_Timer_GetCheckpointCustomData; enum VScript_Checkpoint_State @@ -1791,10 +1788,13 @@ void SaveCheckpointCache(int saver, int target, cp_cache_t cpcache, int index, H gI_VScript_Checkpointing[target] = VCS_Saving; gH_VScript_Checkpoint_CustomData[target] = cpcache.customdata; - if (gH_VScript_Timer_OnCheckpointSave) + if (HSCRIPT_RootTable.ValueExists("Timer_OnCheckpointSave")) { - gH_VScript_Timer_OnCheckpointSave.SetParam(1, FIELD_HSCRIPT, VScript_EntityToHScript(target)); - gH_VScript_Timer_OnCheckpointSave.Execute(); + // ::Timer_OnCheckpointSave <- function(player) + VScriptExecute Timer_OnCheckpointSave = new VScriptExecute(HSCRIPT_RootTable.GetValue("Timer_OnCheckpointSave")); + Timer_OnCheckpointSave.SetParam(1, FIELD_HSCRIPT, VScript_EntityToHScript(target)); + Timer_OnCheckpointSave.Execute(); + delete Timer_OnCheckpointSave; } gI_VScript_Checkpointing[target] = VCS_NO_TOUCH; @@ -1902,10 +1902,13 @@ bool LoadCheckpointCache(int client, cp_cache_t cpcache, int index, bool force = gI_VScript_Checkpointing[client] = VCS_Loading; gH_VScript_Checkpoint_CustomData[client] = cpcache.customdata; - if (gH_VScript_Timer_OnCheckpointLoadPre) + if (HSCRIPT_RootTable.ValueExists("Timer_OnCheckpointLoadPre")) { - gH_VScript_Timer_OnCheckpointLoadPre.SetParam(1, FIELD_HSCRIPT, VScript_EntityToHScript(client)); - gH_VScript_Timer_OnCheckpointLoadPre.Execute(); + // ::Timer_OnCheckpointLoadPre <- function(player) + VScriptExecute Timer_OnCheckpointLoadPre = new VScriptExecute(HSCRIPT_RootTable.GetValue("Timer_OnCheckpointLoadPre")); + Timer_OnCheckpointLoadPre.SetParam(1, FIELD_HSCRIPT, VScript_EntityToHScript(client)); + Timer_OnCheckpointLoadPre.Execute(); + delete Timer_OnCheckpointLoadPre; } gI_VScript_Checkpointing[client] = VCS_NO_TOUCH; @@ -2290,22 +2293,6 @@ public any Native_SaveCheckpointCache(Handle plugin, int numParams) // This is called after mapspawn.nut for reference. (Which is before OnMapStart() too) public void VScript_OnScriptVMInitialized() { - delete gH_VScript_Timer_OnCheckpointSave; - delete gH_VScript_Timer_OnCheckpointLoadPre; - delete gH_VScript_Timer_OnCheckpointLoadPost; - - // ::Timer_OnCheckpointSave <- function(player) - if (HSCRIPT_RootTable.ValueExists("Timer_OnCheckpointSave")) - gH_VScript_Timer_OnCheckpointSave = new VScriptExecute(HSCRIPT_RootTable.GetValue("Timer_OnCheckpointSave")); - - // ::Timer_OnCheckpointLoadPre <- function(player) - if (HSCRIPT_RootTable.ValueExists("Timer_OnCheckpointLoadPre")) - gH_VScript_Timer_OnCheckpointLoadPre = new VScriptExecute(HSCRIPT_RootTable.GetValue("Timer_OnCheckpointLoadPre")); - - // ::Timer_OnCheckpointLoadPost <- function(player) - if (HSCRIPT_RootTable.ValueExists("Timer_OnCheckpointLoadPost")) - gH_VScript_Timer_OnCheckpointLoadPost = new VScriptExecute(HSCRIPT_RootTable.GetValue("Timer_OnCheckpointLoadPost")); - // function Timer_SetCheckpointCustomData(player, key, value) if (!gH_VScript_Timer_SetCheckpointCustomData) { @@ -2410,10 +2397,13 @@ void Do_Timer_OnCheckpointLoadPost(int client, StringMap customdata) gI_VScript_Checkpointing[client] = VCS_Loading; gH_VScript_Checkpoint_CustomData[client] = customdata; - if (gH_VScript_Timer_OnCheckpointLoadPost) + if (HSCRIPT_RootTable.ValueExists("Timer_OnCheckpointLoadPost")) { - gH_VScript_Timer_OnCheckpointLoadPost.SetParam(1, FIELD_HSCRIPT, VScript_EntityToHScript(client)); - gH_VScript_Timer_OnCheckpointLoadPost.Execute(); + // ::Timer_OnCheckpointLoadPost <- function(player) + VScriptExecute Timer_OnCheckpointLoadPost = new VScriptExecute(HSCRIPT_RootTable.GetValue("Timer_OnCheckpointLoadPost")); + Timer_OnCheckpointLoadPost.SetParam(1, FIELD_HSCRIPT, VScript_EntityToHScript(client)); + Timer_OnCheckpointLoadPost.Execute(); + delete Timer_OnCheckpointLoadPost; } gI_VScript_Checkpointing[client] = VCS_NO_TOUCH; diff --git a/addons/sourcemod/scripting/shavit-core.sp b/addons/sourcemod/scripting/shavit-core.sp index 7ed07134..e052af97 100644 --- a/addons/sourcemod/scripting/shavit-core.sp +++ b/addons/sourcemod/scripting/shavit-core.sp @@ -62,8 +62,6 @@ DynamicHook gH_TeleportDhook = null; Address gI_TF2PreventBunnyJumpingAddr = Address_Null; // vscript (non-checkpoint natives) -VScriptExecute gH_VScript_OnStart; -VScriptExecute gH_VScript_OnFinish; VScriptFunction gH_VScript_Timer_GetTime; VScriptFunction gH_VScript_Timer_GetStatus; VScriptFunction gH_VScript_Timer_GetTrack; @@ -2051,11 +2049,14 @@ public int Native_FinishMap(Handle handler, int numParams) if (gB_VScript) { - if (gH_VScript_OnFinish) + if (HSCRIPT_RootTable.ValueExists("Timer_OnFinish")) { - gH_VScript_OnFinish.SetParam(1, FIELD_HSCRIPT, VScript_EntityToHScript(client)); - gH_VScript_OnFinish.SetParam(2, FIELD_INTEGER, snapshot.iTimerTrack); - gH_VScript_OnFinish.Execute(); + // ::Timer_OnFinish <- function(player) + VScriptExecute Timer_OnFinish = new VScriptExecute(HSCRIPT_RootTable.GetValue("Timer_OnFinish")); + Timer_OnFinish.SetParam(1, FIELD_HSCRIPT, VScript_EntityToHScript(client)); + Timer_OnFinish.SetParam(2, FIELD_INTEGER, snapshot.iTimerTrack); + Timer_OnFinish.Execute(); + delete Timer_OnFinish; } } @@ -2656,11 +2657,13 @@ void StartTimer(int client, int track, bool skipGroundCheck) if (gB_VScript) { - if (gH_VScript_OnStart) + if (HSCRIPT_RootTable.ValueExists("Timer_OnStart")) { - gH_VScript_OnStart.SetParam(1, FIELD_HSCRIPT, VScript_EntityToHScript(client)); - gH_VScript_OnStart.SetParam(2, FIELD_INTEGER, track); - gH_VScript_OnStart.Execute(); + VScriptExecute Timer_OnStart = new VScriptExecute(HSCRIPT_RootTable.GetValue("Timer_OnStart")); + Timer_OnStart.SetParam(1, FIELD_HSCRIPT, VScript_EntityToHScript(client)); + Timer_OnStart.SetParam(2, FIELD_INTEGER, track); + Timer_OnStart.Execute(); + delete Timer_OnStart; } } } @@ -3953,17 +3956,6 @@ void UpdateStyleSettings(int client) // This is called after mapspawn.nut for reference. (Which is before OnMapStart() too) public void VScript_OnScriptVMInitialized() { - delete gH_VScript_OnStart; - delete gH_VScript_OnFinish; - - // ::Timer_OnStart <- function(player) - if (HSCRIPT_RootTable.ValueExists("Timer_OnStart")) - gH_VScript_OnStart = new VScriptExecute(HSCRIPT_RootTable.GetValue("Timer_OnStart")); - - // ::Timer_OnFinish <- function(player) - if (HSCRIPT_RootTable.ValueExists("Timer_OnFinish")) - gH_VScript_OnFinish = new VScriptExecute(HSCRIPT_RootTable.GetValue("Timer_OnFinish")); - // function Timer_GetTime(player) // returns a float if (!gH_VScript_Timer_GetTime) {