From 5414b2f390d9b82935445fdb5fcf14f6679f2237 Mon Sep 17 00:00:00 2001 From: FortyTwoFortyTwo Date: Mon, 13 Jan 2025 21:40:00 +0000 Subject: [PATCH] Fix creating new class function breaking existing custom bindings --- README.md | 2 +- scripting/vscript.sp | 2 +- scripting/vscript/binding.sp | 5 +++-- scripting/vscript/class.sp | 19 +++++++++++++++---- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1a6e043..77061d1 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ SourceMod plugin that exposes many VScript features to make use of it. Currently supports L4D2 and TF2. ## Builds -All builds can be found in [releases](https://github.com/FortyTwoFortyTwo/VScript/releases) page, auto-built on every commits done in master branch. +All builds can be found in [releases](https://github.com/FortyTwoFortyTwo/VScript/releases) page, auto-built on every commits done in main branch. ## Requirements - At least SourceMod version 1.12.0.6924 diff --git a/scripting/vscript.sp b/scripting/vscript.sp index 845b46c..e6b5cc2 100644 --- a/scripting/vscript.sp +++ b/scripting/vscript.sp @@ -2,7 +2,7 @@ #include "include/vscript.inc" -#define PLUGIN_VERSION "1.9.1" +#define PLUGIN_VERSION "1.9.2" #define PLUGIN_VERSION_REVISION "manual" char g_sOperatingSystem[16]; diff --git a/scripting/vscript/binding.sp b/scripting/vscript/binding.sp index 285685d..3366a04 100644 --- a/scripting/vscript/binding.sp +++ b/scripting/vscript/binding.sp @@ -62,16 +62,17 @@ void Binding_SetCustom(VScriptFunction pFunction) Function_SetBinding(pFunction, g_pCustomBinding); } -void Binding_Delete(VScriptFunction pFunction) +bool Binding_Delete(VScriptFunction pFunction) { int iIndex = g_aBindingInfos.FindValue(pFunction, BindingInfo::pFunction); if (iIndex == -1) - return; + return false; BindingInfo info; g_aBindingInfos.GetArray(iIndex, info); delete info.hSDKCall; g_aBindingInfos.Erase(iIndex); + return true; } public MRESReturn Binding_Detour(DHookReturn hReturn, DHookParam hParam) diff --git a/scripting/vscript/class.sp b/scripting/vscript/class.sp index ee24c61..1f1be02 100644 --- a/scripting/vscript/class.sp +++ b/scripting/vscript/class.sp @@ -138,13 +138,24 @@ VScriptFunction Class_GetFunctionFromName(VScriptClass pClass, const char[] sNam VScriptFunction Class_CreateFunction(VScriptClass pClass) { - Address pFunctionBindings = pClass + view_as
(g_iClassDesc_FunctionBindings); - int iFunctionCount = LoadFromAddress(pClass + view_as
(g_iClassDesc_FunctionBindings) + view_as
(0x0C), NumberType_Int32); + int iFunctionCount = Class_GetFunctionCount(pClass); + + // Clear any binding detours we have first before moving over to new memory + ArrayList aList = new ArrayList(); + for (int i = 0; i < iFunctionCount; i++) + if (Binding_Delete(Class_GetFunctionFromIndex(pClass, i))) + aList.Push(i); + Address pFunctionBindings = pClass + view_as
(g_iClassDesc_FunctionBindings); Memory_UtlVectorSetSize(pFunctionBindings, g_iFunctionBinding_sizeof, iFunctionCount + 1); - Address pData = LoadFromAddress(pClass + view_as
(g_iClassDesc_FunctionBindings), NumberType_Int32); - VScriptFunction pFunction = view_as(pData + view_as
(g_iFunctionBinding_sizeof * iFunctionCount)); + // Re-detour any bindings + for (int i = 0; i < aList.Length; i++) + Binding_SetCustom(Class_GetFunctionFromIndex(pClass, aList.Get(i))); + + delete aList; + + VScriptFunction pFunction = Class_GetFunctionFromIndex(pClass, iFunctionCount); Function_Init(pFunction, true); return pFunction; }