Skip to content

Commit ba9d8ea

Browse files
Update to use virtual address
1 parent 44fff7e commit ba9d8ea

17 files changed

Lines changed: 489 additions & 521 deletions

File tree

gamedata/vscript.txt

Lines changed: 155 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010
"windows" "windows"
1111
}
1212

13-
"IGameSystem" "CVScriptGameSystem"
14-
"IScriptVM" "CSquirrelVM"
15-
1613
// Extra virtual functions that exists for each games
17-
"IGameSystem::ExtraOffsets" ""
1814
"IScriptVM::ExtraOffsets" ""
1915

2016
"AllowResetScriptVM" "1"
@@ -32,10 +28,60 @@
3228
"FIELD_QANGLE" "39"
3329
}
3430

31+
"Signatures"
32+
{
33+
"g_pScriptVM"
34+
{
35+
"linux" "@g_pScriptVM"
36+
}
37+
}
38+
39+
"Addresses"
40+
{
41+
"g_pScriptVM"
42+
{
43+
"signature" "g_pScriptVM"
44+
}
45+
}
46+
3547
"Offsets"
3648
{
3749
// All offsets are based on any game with smallest offset numbers, of which a large amount of it is based from sdk2013
3850

51+
// CUtlVector
52+
53+
"CUtlVector::m_pMemory"
54+
{
55+
"linux" "0"
56+
"windows" "0"
57+
}
58+
59+
"CUtlVector::m_nAllocationCount"
60+
{
61+
"linux" "4"
62+
"windows" "4"
63+
}
64+
65+
"CUtlVector::m_nGrowSize"
66+
{
67+
"linux" "8"
68+
"windows" "8"
69+
}
70+
71+
"CUtlVector::m_Size"
72+
{
73+
"linux" "12"
74+
"windows" "12"
75+
}
76+
77+
"CUtlVector::m_pElements"
78+
{
79+
"linux" "16"
80+
"windows" "16"
81+
}
82+
83+
// ScriptClassDesc_t
84+
3985
"ScriptClassDesc_t::m_pszScriptName"
4086
{
4187
"linux" "0"
@@ -78,6 +124,8 @@
78124
"windows" "52"
79125
}
80126

127+
// ScriptFunctionBinding_t
128+
81129
"ScriptFunctionBinding_t::m_pszScriptName"
82130
{
83131
"linux" "0"
@@ -132,6 +180,8 @@
132180
"windows" "48"
133181
}
134182

183+
// ScriptVariant_t
184+
135185
"ScriptVariant_t::union"
136186
{
137187
"linux" "0"
@@ -156,41 +206,23 @@
156206
"windows" "4"
157207
}
158208

209+
// CBaseEntity
210+
159211
"CBaseEntity::GetScriptDesc"
160212
{
161213
"linux" "13"
162214
"windows" "12"
163215
}
164216

165-
"IGameSystem::LevelInitPreEntity"
166-
{
167-
"linux" "4"
168-
"windows" "4"
169-
}
170-
171-
"IGameSystem::LevelShutdownPostEntity"
172-
{
173-
"linux" "7"
174-
"windows" "7"
175-
}
217+
// CVScriptGameSystem
176218

177-
"IGameSystem::FrameUpdatePostEntityThink"
219+
"sizeof(CVScriptGameSystem)"
178220
{
179-
"linux" "15"
180-
"windows" "14"
181-
}
182-
183-
"CVScriptGameSystem::m_bAllowEntityCreationInScripts"
184-
{
185-
"linux" "12"
186-
"windows" "12"
221+
"linux" "16"
222+
"windows" "16"
187223
}
188224

189-
"IScriptVM::Init"
190-
{
191-
"linux" "0"
192-
"windows" "0"
193-
}
225+
// IScriptVM
194226

195227
"IScriptVM::CompileScript" // vtable dumper got it wrong
196228
{
@@ -294,6 +326,25 @@
294326
"windows" "34"
295327
}
296328
}
329+
330+
"Functions"
331+
{
332+
"IScriptVM::Init"
333+
{
334+
"signature" "IScriptVM::Init"
335+
"callconv" "cdecl"
336+
"return" "void"
337+
"this" "address"
338+
}
339+
340+
"CVScriptGameSystem::LevelInitPreEntity"
341+
{
342+
"signature" "CVScriptGameSystem::LevelInitPreEntity"
343+
"callconv" "cdecl"
344+
"return" "void"
345+
"this" "address"
346+
}
347+
}
297348
}
298349

299350
"#default"
@@ -306,10 +357,43 @@
306357
"game" "tf" // Team Fortress 2
307358
}
308359

309-
"Keys"
360+
"Signatures"
361+
{
362+
"g_pScriptVM"
363+
{
364+
// CVScriptGameSystem::FrameUpdatePostEntityThink
365+
"windows" "\x8B\x0D\x2A\x2A\x2A\x2A\x85\xC9\x74\x2A\xA1\x2A\x2A\x2A\x2A\x8B\x11\x51"
366+
}
367+
368+
"CVScriptGameSystem::LevelInitPreEntity"
369+
{
370+
"linux" "@_ZN18CVScriptGameSystem18LevelInitPreEntityEv"
371+
"windows" "\x80\x3D\x2A\x2A\x2A\x2A\x00\x56\x8B\xF1\x74\x2A\x8B\x0D\x2A\x2A\x2A\x2A\x85\xC9"
372+
}
373+
374+
"CVScriptGameSystem::LevelShutdownPostEntity"
375+
{
376+
"linux" "@_ZN18CVScriptGameSystem23LevelShutdownPostEntityEv"
377+
"windows" "\x80\x3D\x2A\x2A\x2A\x2A\x00\x74\x2A\x8B\x0D\x2A\x2A\x2A\x2A\x85\xC9"
378+
}
379+
380+
"IScriptVM::Init"
381+
{
382+
"library" "vscript"
383+
"linux" "@_ZN11CSquirrelVM4InitEv"
384+
"windows" "\x55\x8B\xEC\x83\xEC\x08\x2A\x68\x00\x04\x00\x00"
385+
}
386+
}
387+
388+
"Addresses"
310389
{
311-
// 6 - IGameSystem::LevelShutdownPreClearSteamAPIContext
312-
"IGameSystem::ExtraOffsets" "6"
390+
"g_pScriptVM"
391+
{
392+
"windows"
393+
{
394+
"read" "2"
395+
}
396+
}
313397
}
314398

315399
"Offsets"
@@ -370,5 +454,44 @@
370454
"FIELD_UINT32" "38" // +1
371455
"FIELD_QANGLE" "40" // +1
372456
}
457+
458+
"Signatures"
459+
{
460+
"g_pScriptVM"
461+
{
462+
// CVScriptGameSystem::FrameUpdatePostEntityThink
463+
"windows" "\x55\x8B\xEC\x8B\x0D\x2A\x2A\x2A\x2A\x83\xEC\x0C"
464+
}
465+
466+
"CVScriptGameSystem::LevelInitPreEntity"
467+
{
468+
"linux" "@_ZN18CVScriptGameSystem18LevelInitPreEntityEv"
469+
"windows" "\xB9\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\x80\x3D\x2A\x2A\x2A\x2A\x00"
470+
}
471+
472+
"CVScriptGameSystem::LevelShutdownPostEntity"
473+
{
474+
"linux" "@_ZN18CVScriptGameSystem23LevelShutdownPostEntityEv"
475+
"windows" "\x80\x3D\x2A\x2A\x2A\x2A\x00\x74\x2A\xE8\x2A\x2A\x2A\x2A\xC6\x05\x2A\x2A\x2A\x2A\x01"
476+
}
477+
478+
"IScriptVM::Init"
479+
{
480+
"library" "vscript"
481+
"linux" "@_ZN11CSquirrelVM4InitEv"
482+
"windows" "\x55\x8B\xEC\x83\xE4\xF8\x83\xEC\x0C\x53\x56\x57\x8B\xF9"
483+
}
484+
}
485+
486+
"Addresses"
487+
{
488+
"g_pScriptVM"
489+
{
490+
"windows"
491+
{
492+
"read" "5"
493+
}
494+
}
495+
}
373496
}
374497
}

scripting/include/vscript.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ methodmap VScriptFunction < Address
177177
public native get();
178178
}
179179

180-
// Gets/Sets the address of the function
180+
// Gets/Sets the address of the function, null if function is a virtual
181181
property Address Function
182182
{
183183
public native get();

scripting/vscript.sp

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <virtual_address>
12
#include <sourcescramble>
23

34
#include "include/vscript.inc"
@@ -8,6 +9,7 @@
89
char g_sOperatingSystem[16];
910
bool g_bWindows;
1011
bool g_bAllowResetScriptVM;
12+
int g_iInitializing;
1113

1214
Address g_pToScriptVM;
1315

@@ -39,14 +41,14 @@ const VScriptFunction VScriptFunction_Invalid = view_as<VScriptFunction>(Address
3941
#include "vscript/hscript.sp"
4042
#include "vscript/list.sp"
4143
#include "vscript/memory.sp"
44+
#include "vscript/scriptvm.sp"
4245
#include "vscript/util.sp"
4346
#include "vscript/variant.sp"
44-
#include "vscript/vtable.sp"
4547

4648
public Plugin myinfo =
4749
{
4850
name = "VScript",
49-
author = "42",
51+
author = "FortyTwoFortyTwo",
5052
description = "Exposes VScript features into SourceMod",
5153
version = PLUGIN_VERSION ... "." ... PLUGIN_VERSION_REVISION,
5254
url = "https://github.com/FortyTwoFortyTwo/VScript",
@@ -161,7 +163,8 @@ public void OnPluginStart()
161163
g_iScriptVariant_union = hGameData.GetOffset("ScriptVariant_t::union");
162164
g_iScriptVariant_type = hGameData.GetOffset("ScriptVariant_t::m_type");
163165

164-
VTable_LoadGamedata(hGameData);
166+
Memory_Init();
167+
ScriptVM_Init();
165168

166169
Class_LoadGamedata(hGameData);
167170
Entity_LoadGamedata(hGameData);
@@ -171,16 +174,17 @@ public void OnPluginStart()
171174
GameSystem_LoadGamedata(hGameData);
172175
HScript_LoadGamedata(hGameData);
173176
List_LoadGamedata(hGameData);
177+
Memory_LoadGamedata(hGameData);
178+
ScriptVM_LoadGamedata(hGameData);
174179

175-
g_hSDKCallCompileScript = CreateSDKCall(hGameData, "IScriptVM", "CompileScript", SDKType_PlainOldData, SDKType_String, SDKType_String);
176-
g_hSDKCallRegisterInstance = CreateSDKCall(hGameData, "IScriptVM", "RegisterInstance", SDKType_PlainOldData, SDKType_PlainOldData, SDKType_String);
177-
g_hSDKCallGetInstanceEntity = CreateSDKCall(hGameData, "IScriptVM", "GetInstanceValue", SDKType_CBaseEntity, SDKType_PlainOldData, SDKType_PlainOldData);
180+
g_hSDKCallCompileScript = ScriptVM_CreateSDKCall(hGameData, "CompileScript", SDKType_PlainOldData, SDKType_String, SDKType_String);
181+
g_hSDKCallRegisterInstance = ScriptVM_CreateSDKCall(hGameData, "RegisterInstance", SDKType_PlainOldData, SDKType_PlainOldData, SDKType_String);
182+
g_hSDKCallGetInstanceEntity = ScriptVM_CreateSDKCall(hGameData, "GetInstanceValue", SDKType_CBaseEntity, SDKType_PlainOldData, SDKType_PlainOldData);
178183

179184
delete hGameData;
180185

181186
List_LoadDefaults();
182187
Binding_Init();
183-
Memory_Init();
184188
}
185189

186190
public void OnPluginEnd()
@@ -219,10 +223,29 @@ public any Native_HScript_GetValueField(Handle hPlugin, int iNumParams)
219223

220224
public any Native_HScript_GetValue(Handle hPlugin, int iNumParams)
221225
{
222-
ScriptVariant_t pValue = HScript_NativeGetValue(SMField_Cell);
223-
any nValue = pValue.nValue;
224-
delete pValue;
225-
return nValue;
226+
ScriptVariant_t pValue = HScript_NativeGetValue(SMField_Cell|SMField_Address);
227+
fieldtype_t nField = pValue.nType;
228+
229+
switch (Field_GetSMField(nField))
230+
{
231+
case SMField_Cell:
232+
{
233+
any nValue = pValue.nValue;
234+
delete pValue;
235+
return nValue;
236+
}
237+
case SMField_Address:
238+
{
239+
Address pAddress = pValue.pAddress;
240+
delete pValue;
241+
return pAddress;
242+
}
243+
default:
244+
{
245+
ThrowError("Unexpected condition, file a bug report.");
246+
return 0;
247+
}
248+
}
226249
}
227250

228251
public any Native_HScript_GetValueString(Handle hPlugin, int iNumParams)
@@ -261,7 +284,7 @@ public any Native_HScript_IsValueNull(Handle hPlugin, int iNumParams)
261284

262285
public any Native_HScript_SetValue(Handle hPlugin, int iNumParams)
263286
{
264-
HScript_NativeSetValue(SMField_Cell);
287+
HScript_NativeSetValue(SMField_Cell|SMField_Address);
265288
return 0;
266289
}
267290

0 commit comments

Comments
 (0)