forked from gunslingermod/gunslinger_wpnpatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScriptFunctors.pas
270 lines (222 loc) · 4.68 KB
/
ScriptFunctors.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
unit ScriptFunctors;
{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
interface
procedure script_call(name:PChar; arg1:PChar; arg2:single); stdcall;
function script_bool_call(name:PChar; arg1:pchar; arg2:single; arg3:pchar):boolean; stdcall;
function script_pchar_call(name:PChar; arg1:pchar; arg2:single; arg3:boolean; arg4:pchar):pchar; stdcall;
type bind_data = packed record
ptr1:cardinal;
ptr2:cardinal;
id:cardinal;
end;
type pbinddata = ^bind_data;
type script_functor_pchar_single = packed record
bind:pbinddata;
str:^PChar;
number:psingle;
status:byte;
unused1:byte;
unused2:word;
end;
type script_bool_functor_pchar_single_pchar = packed record
bind:pbinddata;
str1:^PChar;
number:psingle;
str2:^PChar;
status:byte;
unused1:byte;
unused2:word;
end;
type script_pchar_functor_pchar_single_bool_pchar = packed record
bind:pbinddata;
str1:^PChar;
number:psingle;
bool:pboolean;
str2:^PChar;
status:byte;
unused1:byte;
unused2:word;
end;
type pscript_functor_pchar_single = ^script_functor_pchar_single;
implementation
uses BaseGameData, Misc;
const
CAISPACE_SZ:cardinal=$2C;
function CAISpace_new():pointer; stdcall;
begin
result:=xrMemory__allocate(CAISPACE_SZ);
if result = nil then exit;
FillChar(PChar(result)^, CAISPACE_SZ, 0);
PCardinal(result)^:=xrgame_addr+$547064;
end;
function Get_script_engine():pointer; stdcall;
begin
asm
pushad
mov eax, xrgame_addr
mov ebx, [eax+$64DA98]
cmp ebx, 0
jne @get
call CAISpace_new
mov [eax+$64DA98], eax
@get:
mov eax, xrgame_addr
mov eax, [eax+$64DA98]
cmp eax, 0
je @finish
mov eax, [eax+$1c]
mov @result, eax
@finish:
popad
end;
end;
procedure luabind_detail_unref(p:cardinal; id:cardinal); stdcall;
asm
pushad
push id
push p
mov eax, xrgame_addr
call [eax+$512490]
add esp, 8
popad
end;
procedure clear_functor(f:pscript_functor_pchar_single); stdcall;
begin
if ((f.bind.ptr2) = 0) or ((f.bind.id) = $FFFFFFFE) then exit;
luabind_detail_unref(f.bind.ptr2, f.bind.id);
end;
function bind_functor(name:PChar; b:pbinddata):boolean; stdcall;
asm
pushad
mov @result, 0
call Get_script_engine
cmp eax, 0
je @finish
push b
push name
mov ecx, eax
mov eax, xrgame_addr
add eax, $96740
call eax
mov @result,al
@finish:
popad
end;
function bind_bool_functor(name:PChar; b:pbinddata):boolean; stdcall;
asm
pushad
mov @result, 0
call Get_script_engine
cmp eax, 0
je @finish
push b
push name
mov ecx, eax
mov eax, xrgame_addr
add eax, $85c10
call eax
mov @result,al
@finish:
popad
end;
function bind_pchar_functor(name:PChar; b:pbinddata):boolean; stdcall;
asm
pushad
mov @result, 0
call Get_script_engine
cmp eax, 0
je @finish
push b
push name
mov ecx, eax
mov eax, xrgame_addr
add eax, $b0e80
call eax
mov @result,al
@finish:
popad
end;
procedure script_call(name:PChar; arg1:PChar; arg2:single); stdcall;
var
b:bind_data;
f:script_functor_pchar_single;
p:pointer;
begin
f.bind:=@b;
f.bind.ptr1:=0;
f.bind.ptr2:=0;
f.bind.id:=$FFFFFFFE;
if not bind_functor(name, f.bind) then exit;
f.str:=@arg1;
f.number:=@arg2;
f.status:=0;
p:=@f;
asm
pushad
mov ecx, p
mov eax, xrgame_addr
add eax, $468d10
call eax
popad
end;
R_ASSERT(f.status <> 0, PChar('Failed '+name), 'script_call');
clear_functor(@f);
end;
function script_bool_call(name:PChar; arg1:pchar; arg2:single; arg3:pchar):boolean; stdcall;
var
b:bind_data;
f:script_bool_functor_pchar_single_pchar;
p:pointer;
begin
f.bind:=@b;
f.bind.ptr1:=0;
f.bind.ptr2:=0;
f.bind.id:=$FFFFFFFE;
if not bind_bool_functor(name, f.bind) then exit;
f.str1:=@arg1;
f.number:=@arg2;
f.str2:=@arg3;
f.status:=0;
p:=@f;
asm
pushad
mov ecx, p
mov eax, xrgame_addr
add eax, $468c70
call eax
mov @result, al
popad
end;
R_ASSERT(f.status <> 0, PChar('Failed '+name), 'script_bool_call');
clear_functor(@f);
end;
function script_pchar_call(name:PChar; arg1:pchar; arg2:single; arg3:boolean; arg4:pchar):pchar; stdcall;
var
b:bind_data;
f:script_pchar_functor_pchar_single_bool_pchar;
p:pointer;
begin
f.bind:=@b;
f.bind.ptr1:=0;
f.bind.ptr2:=0;
f.bind.id:=$FFFFFFFE;
if not bind_pchar_functor(name, f.bind) then exit;
f.str1:=@arg1;
f.number:=@arg2;
f.bool:=@arg3;
f.str2:=@arg4;
f.status:=0;
p:=@f;
asm
pushad
mov ecx, p
mov eax, xrgame_addr
add eax, $468e30
call eax
mov @result, eax
popad
end;
R_ASSERT(f.status <> 0, PChar('Failed '+name), 'script_pchar_call');
clear_functor(@f);
end;
end.