forked from gunslingermod/gunslinger_wpnpatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxr_keybinding.pas
419 lines (339 loc) · 12.4 KB
/
xr_keybinding.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
unit xr_keybinding;
{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
{//$define DISABLE_UNUSED_COMMANDS}
interface
function Init():boolean; stdcall;
//íîâûå äåéñòâèÿ äîáàâëÿòü â procedure fill_actions_list(), îñòàëüíîå àâòîìàòîì
type _action = packed record
action_name:PChar;
id:cardinal;
key_group:cardinal;
end;
type paction = ^_action;
type _binding = packed record
action:paction;
key1:cardinal;
key2:cardinal;
end;
const
_keygroup_both:cardinal=1;
_keygroup_sp:cardinal=3;
_keygroup_mp:cardinal=5;
implementation
uses BaseGameData, KeyUtils, sysutils, windows, gunsl_config;
const
_max_actions_size:cardinal=100;
_max_keybinding_size:cardinal=100;
var
_arr:array [0..99] of _action;
_keybindings:array[0..99] of _binding;
_actions_count:integer;
_max_id:integer;
function _add_action(name:PChar; id:cardinal; key_group:cardinal):boolean; stdcall;
begin
result:=false;
if _actions_count>=_max_actions_size then begin
log ('keybinding._add_action: Cannot add action - overflow; increase bind_size value and size of _arr!', true);
exit;
end else if id>=_max_keybinding_size then begin
log ('keybinding._add_action: Cannot add action with id='+inttostr(id)+', increase _max_keybinding_size value and size of _keybindings!', true);
exit;
end;
if id>_max_id then _max_id:=id;
_arr[_actions_count].action_name:=name;
_arr[_actions_count].id:=id;
_arr[_actions_count].key_group:=key_group;
_actions_count:=_actions_count+1;
result:=true;
end;
procedure _finalize_keybindings();
begin
// log ('finalizing... (max id='+inttostr(_max_id)+')');
_add_action(nil, _max_id+1, _keygroup_both);
end;
procedure fill_actions_list();
begin
_add_action('left', kLEFT, _keygroup_both);
_add_action('right', kRIGHT, _keygroup_both);
_add_action('up', kUP, _keygroup_both);
_add_action('down', kDOWN, _keygroup_both);
_add_action('jump', kJUMP, _keygroup_both);
_add_action('crouch', kCROUCH, _keygroup_both);
_add_action('accel', kACCEL, _keygroup_both);
_add_action('sprint_toggle', kSPRINT_TOGGLE, _keygroup_both);
_add_action('forward', kFWD, _keygroup_both);
_add_action('back', kBACK, _keygroup_both);
_add_action('lstrafe', kL_STRAFE, _keygroup_both);
_add_action('rstrafe', kR_STRAFE, _keygroup_both);
_add_action('llookout', kL_LOOKOUT, _keygroup_both);
_add_action('rlookout', kR_LOOKOUT, _keygroup_both);
{$ifndef DISABLE_UNUSED_COMMANDS}
_add_action('cam_1', kCAM_1, _keygroup_both);
_add_action('cam_2', kCAM_2, _keygroup_both);
_add_action('cam_3', kCAM_3, _keygroup_both);
{$endif}
_add_action('cam_zoom_in', kCAM_ZOOM_IN, _keygroup_both);
_add_action('cam_zoom_out', kCAM_ZOOM_OUT, _keygroup_both);
_add_action('torch', kTORCH, _keygroup_both);
_add_action('night_vision', kNIGHT_VISION, _keygroup_both);
_add_action('show_detector', kDETECTOR, _keygroup_sp);
_add_action('wpn_1', kWPN_1, _keygroup_both);
_add_action('wpn_2', kWPN_2, _keygroup_both);
_add_action('wpn_3', kWPN_3, _keygroup_both);
_add_action('wpn_4', kWPN_4, _keygroup_both);
_add_action('wpn_5', kWPN_5, _keygroup_both);
_add_action('wpn_6', kWPN_6, _keygroup_both);
{$ifndef DISABLE_UNUSED_COMMANDS}
_add_action('artefact', kARTEFACT, _keygroup_both);
{$endif}
_add_action('wpn_next', kWPN_NEXT, _keygroup_both);
_add_action('wpn_fire', kWPN_FIRE, _keygroup_both);
_add_action('wpn_zoom', kWPN_ZOOM, _keygroup_both);
_add_action('wpn_zoom_inc', kWPN_ZOOM_INC, _keygroup_both);
_add_action('wpn_zoom_dec', kWPN_ZOOM_DEC, _keygroup_both);
_add_action('wpn_reload', kWPN_RELOAD, _keygroup_both);
_add_action('wpn_func', kWPN_FUNC, _keygroup_both);
_add_action('wpn_firemode_prev', kWPN_FIREMODE_PREV, _keygroup_both);
_add_action('wpn_firemode_next', kWPN_FIREMODE_NEXT, _keygroup_both);
_add_action('pause', kPAUSE, _keygroup_both);
_add_action('drop', kDROP, _keygroup_both);
_add_action('use', kUSE, _keygroup_both);
_add_action('scores', kSCORES, _keygroup_both);
{$ifndef DISABLE_UNUSED_COMMANDS}
_add_action('chat', kCHAT, _keygroup_mp);
_add_action('chat_team', kCHAT_TEAM, _keygroup_mp);
{$endif}
_add_action('screenshot', kSCREENSHOT, _keygroup_both);
_add_action('quit', kQUIT, _keygroup_both);
_add_action('console', kCONSOLE, _keygroup_both);
_add_action('inventory', kINVENTORY, _keygroup_both);
{$ifndef DISABLE_UNUSED_COMMANDS}
_add_action('buy_menu', kBUY, _keygroup_mp);
_add_action('skin_menu', kSKIN, _keygroup_mp);
_add_action('team_menu', kTEAM, _keygroup_mp);
{$endif}
_add_action('active_jobs', kACTIVE_JOBS, _keygroup_sp); //PDA
{$ifndef DISABLE_UNUSED_COMMANDS}
_add_action('vote_begin', kVOTE_BEGIN, _keygroup_mp);
_add_action('show_admin_menu', kADMIN, _keygroup_mp);
_add_action('vote', kVOTE, _keygroup_mp);
_add_action('vote_yes', kVOTEYES, _keygroup_mp);
_add_action('vote_no', kVOTENO, _keygroup_mp);
{$endif}
_add_action('next_slot', kNEXT_SLOT, _keygroup_both);
_add_action('prev_slot', kPREV_SLOT, _keygroup_both);
{$ifndef DISABLE_UNUSED_COMMANDS}
_add_action('speech_menu_0', kSPEECH_MENU_0, _keygroup_mp);
_add_action('speech_menu_1', kSPEECH_MENU_1, _keygroup_mp);
{$endif}
_add_action('quick_use_1', kQUICK_USE_1, _keygroup_both);
_add_action('quick_use_2', kQUICK_USE_2, _keygroup_both);
_add_action('quick_use_3', kQUICK_USE_3, _keygroup_both);
_add_action('quick_use_4', kQUICK_USE_4, _keygroup_both);
_add_action('quick_save', kQUICK_SAVE, _keygroup_sp);
_add_action('quick_load', kQUICK_LOAD, _keygroup_sp);
_add_action('wpn_laser', kLASER, _keygroup_both);
_add_action('wpn_torch', kTACTICALTORCH, _keygroup_both);
_add_action('quick_grenade', kQUICK_GRENADE, _keygroup_both);
_add_action('wpn_zoom_alter', kWPN_ZOOM_ALTER, _keygroup_both);
_add_action('quick_kick', kQUICK_KICK, _keygroup_both);
_add_action('scope_brightness_plus', kBRIGHTNESS_PLUS, _keygroup_both);
_add_action('scope_brightness_minus', kBRIGHTNESS_MINUS, _keygroup_both);
// _add_action('alife_command', kALIFE_CMD, _keygroup_sp); //âîññòàíàâëèâàåì ×Íîâñêîå
// _add_action('not_binded', $45, _keygroup_sp);
end;
function find_action_by_id(id:cardinal):paction; stdcall;
var
i:integer;
begin
for i:=0 to _actions_count-1 do begin
if _arr[i].id=id then begin
result:=@_arr[i];
exit;
end;
end;
result:=@_arr[_max_id-1];
end;
procedure initialize_bindings_fixed(); stdcall;
var
i:integer;
res:paction;
begin
for i:=0 to _max_id-1 do begin
res:=find_action_by_id(i);
// log ('for id='+inttostr(i)+' found index '+inttohex(cardinal(res),8));
_keybindings[i].action:=res;
end;
end;
procedure initialize_bindings_bugfix_Patch(); stdcall;
asm
pushad
call initialize_bindings_fixed
popad
ret
end;
function Init():boolean; stdcall;
var
c_addr, rb:cardinal;
a_addr:pointer;
tmp:cardinal;
begin
result:=false;
_actions_count:=0;
_max_id:=-1;
//äëÿ ãàðàíòèè
for tmp:=0 to _max_keybinding_size-1 do begin
_keybindings[tmp].action:=nil;
_keybindings[tmp].key1:=0;
_keybindings[tmp].key2:=0;
end;
fill_actions_list();
_finalize_keybindings();
// _add_action('test1', $43, _keygroup_sp);
// _add_action(nil, kLASTACTION, _keygroup_both);
// log(inttohex(cardinal(@_arr[0]),8));
// xrgame.dll+6345f8 - çäåñü íà÷èíàåòñÿ îðèãèíàëüíûé ìàññèâ äåéñòâèé
//ìåíÿåì åãî âî âñåì êîäå íà íàø
a_addr:=@_arr[0];
// log(inttohex(cardinal(a_addr),8));
c_addr:=xrgame_addr+$25ba3a;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
c_addr:=xrgame_addr+$25ba48;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
c_addr:=xrgame_addr+$25ba66;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
c_addr:=xrgame_addr+$25ba6E;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
c_addr:=xrgame_addr+$25ba91;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
// òóò (initialize_bindings) áàã â îðèãèíàëå - ïðàâèì íèæå
// c_addr:=xrgame_addr+$25bdc2;
// writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
// if rb<>4 then exit;
//ïåðåíàïðàâèì áèíäû
//ïàò÷èì bool is_binded(EGameActions _action_id, int _dik);
a_addr:=@_keybindings[0];
c_addr:=xrgame_addr+$25bba7;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
a_addr:=@_keybindings[0];
a_addr:=PChar(a_addr)+4;
c_addr:=xrgame_addr+$25bb9e;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
//ïàò÷èì int get_action_dik(EGameActions _action_id, int idx)
a_addr:=@_keybindings[0];
c_addr:=xrgame_addr+$25bbe1;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
//ïàò÷èì CCC_Bind::Save
a_addr:=@_keybindings[0];
c_addr:=xrgame_addr+$25bc92;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
a_addr:=@_keybindings[0];
a_addr:=PChar(a_addr)+(_max_id)*12;
c_addr:=xrgame_addr+$25bccc;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
//ïàò÷èì CCC_ListActions::Execute
a_addr:=@_keybindings[0];
c_addr:=xrgame_addr+$25bcfa;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
a_addr:=@_keybindings[0];
a_addr:=PChar(a_addr)+(_max_id)*12;
c_addr:=xrgame_addr+$25bd14;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
//ïàò÷èì (inline) initialize_bindings â void CCC_RegisterInput
//ñòðîêà g_key_bindings[idx].m_action = &actions[idx] áàãîîïàñíà - åñëè id action'a íå ñîâïàäàåò ñ åãî èíäåêñîì â actions (à òàê îíî â îðèãèíàëå è åñòü - òàì "îêíî" èç-çà âûðåçàííîé êîìàíäû kALIFE_CMD) - áóäåò ïëîõî.
//ïåðåïèøåì âñþ ôóíêöèþ.
c_addr:=xrgame_addr+$25bdc0;
if not WriteJump(c_addr, cardinal(@initialize_bindings_bugfix_Patch), 22, true) then exit;
// a_addr:=@_keybindings[0];
// c_addr:=xrgame_addr+$25bdc8;
// writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
// if rb<>4 then exit;
// tmp:=(_max_id)*12;
// c_addr:=xrgame_addr+$25bdd0;
// writeprocessmemory(hndl, PChar(c_addr), @tmp, 4, rb);
// if rb<>4 then exit;
//ïàò÷èì GetActionAllBinding
a_addr:=@_keybindings[0];
c_addr:=xrgame_addr+$25c141;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
a_addr:=@_keybindings[0];
a_addr:=PChar(a_addr)+4;
c_addr:=xrgame_addr+$25c138;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
//ïàò÷èì CCC_Bind::Execute
a_addr:=@_keybindings[0];
c_addr:=xrgame_addr+$25c957;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
a_addr:=@_keybindings[0];
a_addr:=PChar(a_addr)+8;
c_addr:=xrgame_addr+$25c960;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
a_addr:=@_keybindings[0];
a_addr:=PChar(a_addr)+(_max_id)*12+8;
c_addr:=xrgame_addr+$25c9a0;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
//ïàò÷èì EGameActions get_binded_action (int _dik);
a_addr:=@_keybindings[0];
a_addr:=PChar(a_addr)+8;
c_addr:=xrgame_addr+$25bc1c;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
a_addr:=@_keybindings[0];
a_addr:=PChar(a_addr)+(_max_id)*12+8;
c_addr:=xrgame_addr+$25bc4f;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
//ïàò÷èì CCC_BindList::Execute
a_addr:=@_keybindings[0];
a_addr:=PChar(a_addr)+4;
c_addr:=xrgame_addr+$25c2c9;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
a_addr:=@_keybindings[0];
a_addr:=PChar(a_addr)+(_max_id)*12+4;
c_addr:=xrgame_addr+$25c32f;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
//ïàò÷èì ???
a_addr:=@_keybindings[0];
a_addr:=PChar(a_addr)+8;
c_addr:=xrgame_addr+$25ca82;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
a_addr:=@_keybindings[0];
a_addr:=PChar(a_addr)+(_max_id)*12+8;
c_addr:=xrgame_addr+$25ca91;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
//ïàò÷èì CCC_Unbind::Execute
a_addr:=@_keybindings[0];
a_addr:=PChar(a_addr)+4;
c_addr:=xrgame_addr+$25bd97;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
//ïàò÷èì ???
a_addr:=@_keybindings[0];
a_addr:=PChar(a_addr)+4;
c_addr:=xrgame_addr+$463cf0;
writeprocessmemory(hndl, PChar(c_addr), @a_addr, 4, rb);
if rb<>4 then exit;
result:=true;
end;
end.