Skip to content

Commit 5414b2f

Browse files
Fix creating new class function breaking existing custom bindings
1 parent bc9aaa0 commit 5414b2f

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SourceMod plugin that exposes many VScript features to make use of it. Currently supports L4D2 and TF2.
44

55
## Builds
6-
All builds can be found in [releases](https://github.com/FortyTwoFortyTwo/VScript/releases) page, auto-built on every commits done in master branch.
6+
All builds can be found in [releases](https://github.com/FortyTwoFortyTwo/VScript/releases) page, auto-built on every commits done in main branch.
77

88
## Requirements
99
- At least SourceMod version 1.12.0.6924

scripting/vscript.sp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "include/vscript.inc"
44

5-
#define PLUGIN_VERSION "1.9.1"
5+
#define PLUGIN_VERSION "1.9.2"
66
#define PLUGIN_VERSION_REVISION "manual"
77

88
char g_sOperatingSystem[16];

scripting/vscript/binding.sp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,17 @@ void Binding_SetCustom(VScriptFunction pFunction)
6262
Function_SetBinding(pFunction, g_pCustomBinding);
6363
}
6464

65-
void Binding_Delete(VScriptFunction pFunction)
65+
bool Binding_Delete(VScriptFunction pFunction)
6666
{
6767
int iIndex = g_aBindingInfos.FindValue(pFunction, BindingInfo::pFunction);
6868
if (iIndex == -1)
69-
return;
69+
return false;
7070

7171
BindingInfo info;
7272
g_aBindingInfos.GetArray(iIndex, info);
7373
delete info.hSDKCall;
7474
g_aBindingInfos.Erase(iIndex);
75+
return true;
7576
}
7677

7778
public MRESReturn Binding_Detour(DHookReturn hReturn, DHookParam hParam)

scripting/vscript/class.sp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,24 @@ VScriptFunction Class_GetFunctionFromName(VScriptClass pClass, const char[] sNam
138138

139139
VScriptFunction Class_CreateFunction(VScriptClass pClass)
140140
{
141-
Address pFunctionBindings = pClass + view_as<Address>(g_iClassDesc_FunctionBindings);
142-
int iFunctionCount = LoadFromAddress(pClass + view_as<Address>(g_iClassDesc_FunctionBindings) + view_as<Address>(0x0C), NumberType_Int32);
141+
int iFunctionCount = Class_GetFunctionCount(pClass);
142+
143+
// Clear any binding detours we have first before moving over to new memory
144+
ArrayList aList = new ArrayList();
145+
for (int i = 0; i < iFunctionCount; i++)
146+
if (Binding_Delete(Class_GetFunctionFromIndex(pClass, i)))
147+
aList.Push(i);
143148

149+
Address pFunctionBindings = pClass + view_as<Address>(g_iClassDesc_FunctionBindings);
144150
Memory_UtlVectorSetSize(pFunctionBindings, g_iFunctionBinding_sizeof, iFunctionCount + 1);
145151

146-
Address pData = LoadFromAddress(pClass + view_as<Address>(g_iClassDesc_FunctionBindings), NumberType_Int32);
147-
VScriptFunction pFunction = view_as<VScriptFunction>(pData + view_as<Address>(g_iFunctionBinding_sizeof * iFunctionCount));
152+
// Re-detour any bindings
153+
for (int i = 0; i < aList.Length; i++)
154+
Binding_SetCustom(Class_GetFunctionFromIndex(pClass, aList.Get(i)));
155+
156+
delete aList;
157+
158+
VScriptFunction pFunction = Class_GetFunctionFromIndex(pClass, iFunctionCount);
148159
Function_Init(pFunction, true);
149160
return pFunction;
150161
}

0 commit comments

Comments
 (0)