forked from gunslingermod/gunslinger_wpnpatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActorDOF.pas
448 lines (368 loc) · 11.5 KB
/
ActorDOF.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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
unit ActorDOF;
{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
interface
uses MatVectors;
type
DofValues = packed record
dest:FVector3;
current:FVector3;
from:FVector3;
original:FVector3;
end;
pDofValues = ^DofValues;
DofContext = record
values:DofValues;
change_speed_koef:single;
change_speed_recalc:single;
changed:boolean;
valid:boolean;
end;
pDofContext = ^DofContext;
function Init():boolean; stdcall;
function GetGamePersistent():pointer; stdcall;
procedure SetDOF(dof_near:single; dof_focus:single; dof_far:single; speed:single); stdcall; overload;
procedure SetDOF(v:FVector3; speed:single); stdcall; overload;
function RefreshZoomDOF(wpn:pointer):boolean; stdcall;
procedure ResetDOF(speed:single); stdcall;
function ReadActionDOFVector(wpn:pointer; var v:FVector3; param:string; def:boolean=true):boolean; stdcall;
function ReadZoomDOFVector(wpn:pointer):FVector3; stdcall;
function ReadAlterZoomDOFVector(wpn:pointer):FVector3; stdcall;
function ReadGLDOFVector(wpn:pointer):FVector3; stdcall;
function ReadLensDOFVector(wpn:pointer):FVector3; stdcall;
function ReadActionDOFSpeed_In(wpn:pointer; param:string):single;
function ReadActionDOFSpeed_Out(wpn:pointer; param:string):single;
function ReadActionDOFTimeOffset(wpn:pointer; param:string):integer;
procedure SetDofSpeedfactor(speed:single); stdcall;
procedure GetCurrentDOF(v:pFVector3); stdcall;
function DOFChanged():boolean; stdcall;
procedure GetContext(context:pDofContext); stdcall;
procedure SetContext(context:pDofContext); stdcall;
function GetDOFState():pDofValues; stdcall;
procedure SetDOFState(values:pDofValues); stdcall;
implementation
uses BaseGameData, collimator, gunsl_config, HudItemUtils, ActorUtils, math, sysutils, LensDoubleRender;
var
_dof_change_speed_koef:single;
_dof_change_speed_recalc:single;
_dof_changed:boolean;
//-----------------------------------------------------------------------------------------------------------
function DOFChanged():boolean; stdcall;
begin
result:=_dof_changed;
end;
procedure SetPickableDofEffectorStatus(status:boolean); stdcall;
asm
pushad
call GetGamePersistent
mov ecx, eax
mov eax, xrgame_addr
add eax, $230960
movzx edx, status
push edx
call eax //CGamePersistent::SetPickableEffecorDOF
popad
end;
function IsPickableDofEffectorActive():boolean;
begin
asm
pushad
call GetGamePersistent
mov al, byte ptr [eax+$4e1] //m_bPickableDOF
mov result, al
popad
end;
end;
function RefreshZoomDOF(wpn:pointer):boolean; stdcall;
begin
if not IsDofEnabled() then begin
result:=false;
end else if LensConditions(true) and not IsAlterZoom(wpn) then begin
//â ðåæèìå ïðèöåëèâàíèÿ ñ ïîìîùüþ ëèíçû
result:=false;
if IsPickableDofEffectorActive() then begin
//Åñëè áûëà àêòèâíà "ðîäíàÿ" ñõåìà äîôà - ñáðîñèì åå, îíà ìåøàåò
SetPickableDofEffectorStatus(false);
end;
SetDOF(ReadLensDOFVector(wpn), game_ini_r_single_def(GetHUDSection(wpn),'zoom_in_dof_speed', GetDefaultDOFSpeed_In()));
end else if IsConstZoomDOF() then begin
result:=false; //â ðîäíîì äîôå íå íóæäàåìñÿ
if IsPickableDofEffectorActive() then begin
//Åñëè áûëà àêòèâíà "ðîäíàÿ" ñõåìà äîôà - ñáðîñèì åå, îíà ìåøàåò
SetPickableDofEffectorStatus(false);
end;
if IsGrenadeMode(wpn) and CHudItem__GetHUDMode(wpn) then begin
SetDOF(ReadGLDOFVector(wpn), game_ini_r_single_def(GetHUDSection(wpn),'gl_in_dof_speed', GetDefaultDOFSpeed_In()));
end else if IsAlterZoom(wpn) then begin
SetDOF(ReadAlterZoomDOFVector(wpn), game_ini_r_single_def(GetHUDSection(wpn),'alter_zoom_in_dof_speed', GetDefaultDOFSpeed_In()));
end else if (not IsScopeAttached(wpn)) and (GetScopeStatus(wpn)<>1) and CHudItem__GetHUDMode(wpn) then begin
SetDOF(ReadZoomDOFVector(wpn), game_ini_r_single_def(GetHUDSection(wpn),'zoom_in_dof_speed', GetDefaultDOFSpeed_In()));
end;
end else begin
if game_ini_r_bool_def(GetSection(wpn), 'disable_zoom_dof', false) then begin
result:=false;
end else if IsAlterZoom(wpn) then begin
result:=true;
end else begin
// Ñ êîëëèìàòîðîì èñïîëüçîâàòü íåëüçÿ - âûãëÿäèò ñòðàííî
result:= (not IsCollimatorInstalled(wpn) and not IsLensedScopeInstalled(wpn));
end;
if result then SetDofSpeedfactor(GetDefaultDOFSpeed());
end;
//Óïðàâëÿåì íåîáõîäèìîñòüþ "îðèãèíàëüíîãî" ýôôåêòà ÄÎÔà, ïàðàìåòðû êîòîðîãî çàâèñÿò îò òî÷êè, â êîòîðóþ ñìîòðèò èãðîê
if result then begin
SetPickableDofEffectorStatus(true);
end;
end;
procedure CWeapon__OnZoomIn_needDOF_Patch(); stdcall;
asm
pushad
push esi
call RefreshZoomDOF
popad
end;
function GetGamePersistent():pointer; stdcall;
begin
asm
mov eax, xrgame_addr
mov eax, [eax+$512c28]
mov eax, [eax]
mov @result, eax
end;
end;
procedure SetDofSpeedfactor(speed:single); stdcall; //default=5
begin
_dof_change_speed_koef:=speed;
end;
procedure RecalcDofSpeed(); stdcall;
begin
if GetActor<>nil then begin
_dof_change_speed_recalc:=_dof_change_speed_koef;
end else
_dof_change_speed_recalc:=1000;
end;
procedure DOFLoadSpeed_Patch(); stdcall;
asm
sub esp, $C
movss [esp], xmm0
movss [esp+4], xmm1
movss [esp+8], xmm2
pushad
call RecalcDofSpeed
popad
movss xmm0, [esp]
movss xmm1, [esp+4]
movss xmm2, [esp+8]
add esp, $c
mulss xmm2, _dof_change_speed_recalc
end;
procedure SetDOF(dof_near:single; dof_focus:single; dof_far:single; speed:single); stdcall; overload;
asm
pushad
push speed
call SetDofSpeedfactor
call GetGamePersistent
//ñîõðàíèì òåêóùåå â ïðåäûäóùåå
mov ebx, [eax+$4f8]
mov [eax+$504], ebx
mov ebx, [eax+$4fc]
mov [eax+$508], ebx
mov ebx, [eax+$500]
mov [eax+$50c], ebx
//çàïèøåì íîâîå â öåëåâîå
mov ebx, dof_near
mov [eax+$4EC], ebx
mov ebx, dof_focus
mov [eax+$4F0], ebx
mov ebx, dof_far
mov [eax+$4F4], ebx
mov _dof_changed, 1
popad
end;
procedure SetDOF(v:FVector3; speed:single); stdcall; overload;
begin
SetDOF(v.x, v.y, v.z, speed);
end;
procedure ResetDOF(speed:single); stdcall;
asm
cmp _dof_changed, 0
je @finish
pushad
push speed
call SetDofSpeedfactor
call GetGamePersistent
//ñîõðàíèì òåêóùåå â ïðåäûäóùåå
mov ebx, [eax+$4f8]
mov [eax+$504], ebx
mov ebx, [eax+$4fc]
mov [eax+$508], ebx
mov ebx, [eax+$500]
mov [eax+$50c], ebx
//çàïèøåì äåôàóëòîâîå â öåëåâîå
mov ebx, [eax+$510]
mov [eax+$4ec], ebx
mov ebx, [eax+$514]
mov [eax+$4f0], ebx
mov ebx, [eax+$518]
mov [eax+$4f4], ebx
mov _dof_changed, 0
popad
@finish:
end;
procedure GetCurrentDOF(v:pFVector3); stdcall;
asm
pushad
call GetGamePersistent
mov ecx, eax
push v
mov eax, xrgame_addr
add eax, $2306f0
call eax
popad
end;
function ReadActionDOFVector(wpn:pointer; var v:FVector3; param:string; def:boolean=true):boolean; stdcall;
var
sect:PChar;
begin
sect:=GetHUDSection(wpn);
result:=IsDynamicDOF() and CHudItem__GetHUDMode(wpn) and game_ini_r_bool_def(sect, PChar('use_dof_'+param), def);
if result then begin
v:=GetDefaultActionDOF();
param:='dof_'+param;
v.x:=game_ini_r_single_def(sect, PChar(param+'_near'), v.x);
v.y:=game_ini_r_single_def(sect, PChar(param+'_focus'), v.y);
v.z:=game_ini_r_single_def(sect, PChar(param+'_far'), v.z);
end;
end;
function ReadActionDOFSpeed_In(wpn:pointer; param:string):single;
var
sect:PChar;
begin
sect:=GetHUDSection(wpn);
result:=game_ini_r_single_def(sect, PChar('dof_speed_in_'+param), GetDefaultDOFSpeed_In());
end;
function ReadActionDOFSpeed_Out(wpn:pointer; param:string):single;
var
sect:PChar;
begin
sect:=GetHUDSection(wpn);
result:=game_ini_r_single_def(sect, PChar('dof_speed_out_'+param), GetDefaultDOFSpeed_Out());
end;
function ReadActionDOFTimeOffset(wpn:pointer; param:string):integer;
var
sect:PChar;
begin
sect:=GetHUDSection(wpn);
result:=floor(game_ini_r_single_def(sect, PChar('dof_time_offset_'+param), GetDefaultDOFTimeOffset())*1000);
end;
function ReadZoomDOFVector(wpn:pointer):FVector3; stdcall;
var
sect:PChar;
begin
sect:=GetHUDSection(wpn);
result:=GetDefaultZoomDOF();
result.x:=game_ini_r_single_def(sect, PChar('zoom_dof_near'), result.x);
result.y:=game_ini_r_single_def(sect, PChar('zoom_dof_focus'), result.y);
result.z:=game_ini_r_single_def(sect, PChar('zoom_dof_far'), result.z);
end;
function ReadAlterZoomDOFVector(wpn:pointer):FVector3; stdcall;
var
sect:PChar;
begin
sect:=GetHUDSection(wpn);
result:=ReadZoomDOFVector(wpn);
result.x:=game_ini_r_single_def(sect, PChar('alter_zoom_dof_near'), result.x);
result.y:=game_ini_r_single_def(sect, PChar('alter_zoom_dof_focus'), result.y);
result.z:=game_ini_r_single_def(sect, PChar('alter_zoom_dof_far'), result.z);
end;
function ReadGLDOFVector(wpn:pointer):FVector3; stdcall;
var
sect:PChar;
begin
sect:=GetHUDSection(wpn);
result:=GetDefaultZoomDOF();
result.x:=game_ini_r_single_def(sect, PChar('gl_dof_near'), result.x);
result.y:=game_ini_r_single_def(sect, PChar('gl_dof_focus'), result.y);
result.z:=game_ini_r_single_def(sect, PChar('gl_dof_far'), result.z);
end;
function ReadLensDOFVector(wpn:pointer):FVector3; stdcall;
var
sect:PChar;
begin
sect:=GetHUDSection(wpn);
result:=GetDefaultZoomDOF();
result.x:=game_ini_r_single_def(sect, PChar('lens_dof_near'), result.x);
result.y:=game_ini_r_single_def(sect, PChar('lens_dof_focus'), result.y);
result.z:=game_ini_r_single_def(sect, PChar('lens_dof_far'), result.z);
if IsScopeAttached(wpn) then begin
sect:=GetCurrentScopeSection(wpn);
result.x:=game_ini_r_single_def(sect, PChar('lens_dof_near'), result.x);
result.y:=game_ini_r_single_def(sect, PChar('lens_dof_focus'), result.y);
result.z:=game_ini_r_single_def(sect, PChar('lens_dof_far'), result.z);
end;
end;
function Init():boolean; stdcall;
var jmp_addr:cardinal;
begin
result:=false;
_dof_change_speed_koef:=GetDefaultDOFSpeed();
_dof_changed:=false;
jmp_addr:= xrgame_addr+$2C07FB;
if not WriteJump(jmp_addr, cardinal(@CWeapon__OnZoomIn_needDOF_Patch), 7, true) then exit;
jmp_addr:= xrgame_addr+$230ADE;
if not WriteJump(jmp_addr, cardinal(@DOFLoadSpeed_Patch), 8, true) then exit;
result:=true;
end;
procedure GetContext(context:pDofContext); stdcall;
var
m_dof:pDofValues;
begin
m_dof:=GetDOFState();
if m_dof<>nil then begin
context^.values:=m_dof^;
context^.change_speed_koef:=_dof_change_speed_koef;
context^.change_speed_recalc:=_dof_change_speed_recalc;
context^.changed:=_dof_changed;
context^.valid:=true;
end else begin
context^.valid:=false;
end;
end;
procedure SetContext(context:pDofContext); stdcall;
var
m_dof:pDofValues;
begin
m_dof:=GetDOFState();
if context^.valid and (m_dof<>nil) then begin
m_dof^:=context^.values;
_dof_change_speed_koef:=context^.change_speed_koef;
_dof_change_speed_recalc:=context^.change_speed_recalc;
_dof_changed:=context^.changed;
end;
end;
function GetDOFState():pDofValues; stdcall;
var
game_persistent:cardinal;
begin
game_persistent:= cardinal(GetGamePersistent());
if game_persistent<>0 then begin
result:= pDofValues((cardinal(game_persistent)+$4EC))
end else begin
result:=nil;
end;
end;
procedure SetDOFState(values:pDofValues); stdcall;
var
m_dof:pDofValues;
begin
m_dof:=GetDOFState();
if m_dof<>nil then begin
m_dof^:=values^;
end;
end;
end.
//xrGame.dll+230790 - CGamePersistent::RestoreEffectorDOF
//xrGame.dll+230960 - CGamePersistent::SetPickableEffectorDOF
//xrGame.dll+30bd10 - CCustomZone::feel_touch_delete
//xrGame.dll+30bef0 - CCustomZone::feel_touch_new
//xrGame.dll+313300 - CNoGravityZone::switchGravity
//xrGame.dll+30aeb0 CCustomZone::PlayEntranceParticles