forked from gunslingermod/gunslinger_wpnpatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLensDoubleRender.pas
773 lines (639 loc) · 20.2 KB
/
LensDoubleRender.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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
unit LensDoubleRender;
{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
interface
uses CRT;
function Init():boolean; stdcall;
function IsLensFrameNow():boolean; stdcall;
function NeedLensFrameNow():boolean; stdcall;
function LensConditions(ignore_forcing_override:boolean):boolean; stdcall;
function GetLensFOV(default:single):single;stdcall;
function GetCurrentFrameGpuID():cardinal; stdcall;
procedure CopyRenderTargetData(src:pCRT_rec; dest:pCRT_rec); stdcall;
implementation
uses BaseGameData, Windows, SysUtils, Misc, gunsl_config, ActorUtils, HudItemUtils, dynamic_caster, WeaponAdditionalBuffer, MatVectors, math, ConsoleUtils, ActorDOF, UIUtils, KeyUtils, collimator;
type
render_f=function():pCRT_rec;
var
//data from engine
pD3DXLoadSurfaceFromSurface:pointer;
_copyresource_vftable_index:cardinal;
pHW_Device:cardinal;
pSwapchain:cardinal;
pIID_ID3DTexture2D:cardinal;
_p_iGPUNum:pCardinal;
_is_lens_frame:boolean; //flag
_scoped_frames:cardinal;
_non_scoped_frames:cardinal;
_buffer_index:cardinal;
_restore_fov_after_lens_frame:single;
_last_fov_changed_frame:cardinal; //êàäð, â êîòîðîì ïîñëåäíèé ðàç ìåíÿëè ôîâ
_scopeframe_renderspecific_end:procedure(f:render_f); stdcall;
_dof_context:DofContext;
_last_cursor_frame:cardinal;
_last_cursor_pos:FVector2;
_last_prev_cursor_pos:FVector2;
_last_pda_frame:cardinal;
const
D3DBACKBUFFER_TYPE_MONO:cardinal = 0;
LENS_DOF_NEAR:single = -9151;
LENS_DOF_FOCUS:single = 0;
LENS_DOF_FAR:single = 9151;
LENS_DOF_SPEED:single = 2.16723;
//Exports////////////////////////////////////
function IsLensFrameNow():boolean; stdcall;
begin
result:=_is_lens_frame;
end;
function LensConditions(ignore_forcing_override:boolean):boolean; stdcall;
var
wpn:pointer;
buf:WpnBuf;
begin
result:=false;
wpn:=GetActorActiveItem();
if (wpn=nil) or not IsLensEnabled() then begin
exit;
end;
buf:=GetBuffer(wpn);
if (not ignore_forcing_override) and (buf<>nil) and buf.NeedPermanentLensRendering() then begin
result:=true;
exit;
end;
//ðàáîòàòü ïîêà íàäî òîëüêî ñ CWeapon
wpn:=dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CWeapon, false);
if (wpn=nil) then begin
exit;
end;
if (IsAimNow(wpn) or IsHolderInAimState(wpn) or (GetAimFactor(wpn)>0.001)) and (not IsGrenadeMode(wpn) or game_ini_r_bool_def(GetHUDSection(wpn), 'doublerendered_gl_zoom', false)) then begin
if IsLensedScopeInstalled(wpn) then begin
result:= (GetAlterZoomDirectSwitchMixupFactor(wpn) > 0) or (not IsAlterZoom(wpn) and not IsLastZoomAlter(wpn));
end else begin
result:=game_ini_r_bool_def(GetHUDSection(wpn), 'need_lens_frame', false) or game_ini_r_bool_def(GetSection(wpn), 'need_lens_frame', false);
end;
end;
end;
function NeedLensFrameNow():boolean; stdcall;
begin
//â ðåæèìå ôîðñèðîâàíèÿ êàäðà ëèíçû îäèí "ãïó" (íóëåâîé) ïîñòîÿííî çàãðóæåí ðåíäåðîì ëèíçîâûõ êàäðîâ
if IsForcedLens() then begin
result:= (GetCurrentFrameGpuID()=0);
exit;
end;
//èíà÷å ðåíäåð ëèíçû àêòèâåí íå âñåãäà
result:=(GetDevicedwFrame() mod ( (_p_iGPUNum^)*GetLensRenderFactor()))=0;
if result then begin
//åñëè â ìåíþ - íå ðåíäåðèì
if IsMainMenuActive() or IsDemoRecord() then begin
result:=false;
exit;
end;
result:=LensConditions(false);
end;
end;
function GetLensFOV(default:single):single; stdcall;
var
wpn:pointer;
fov, factor:single;
buf:WpnBuf;
lens_params:lens_zoom_params;
scope_sect:PChar;
scope_status:cardinal;
const
EPS:single = 0.00001;
begin
result:=default;
wpn:=GetActorActiveItem();
if wpn=nil then exit;
buf:=GetBuffer(wpn);
if buf=nil then exit;
lens_params:=buf.GetLensParams();
scope_status:=GetScopeStatus(wpn);
if (scope_status=2) and IsScopeAttached(wpn) then begin
scope_sect:=game_ini_read_string(GetCurrentScopeSection(wpn), 'scope_name');
lens_params.factor_min:=game_ini_r_single_def(scope_sect, 'min_lens_factor', 1.0);
lens_params.factor_max:=game_ini_r_single_def(scope_sect, 'max_lens_factor', 1.0);
end;
factor:=lens_params.factor_min+(lens_params.factor_max-lens_params.factor_min)*lens_params.real_position;
fov:=(GetBaseFOV()/2)*pi/180;
result:=2*arctan(tan(fov)/factor)*180/pi;
end;
function GetCurrentFrameGpuID():cardinal; stdcall;
begin
result:=(GetDevicedwFrame() mod _p_iGPUNum^);
end;
/////////////////////////////////////////////
procedure ForcedRenderUI(); stdcall;
asm
pushad
mov ecx, xrgame_addr
mov ecx, [ecx+$512D30]
mov ecx, [ecx]
mov edx, [ecx]
mov eax, [edx+$2c]
call eax
popad
end;
function GetBackBuffer(iSwapChain: LongWord; iBackBuffer: LongWord; _Type: cardinal; ppBackBuffer:pointer):cardinal; stdcall;
asm
pushad
mov ebx, pHW_Device
mov ebx, [ebx]
mov eax, [ebx]
mov eax, [eax+$48]
push ppBackBuffer
push _Type
push iBackBuffer
push iSwapChain
push ebx
call eax
mov @result, eax
popad
end;
function LoadSurfaceFromSurface(this, dest:pointer):cardinal; stdcall;
asm
pushad
push 0
push $FFFFFFFF
push 0
push 0
push this
push 0
push 0
push dest
mov eax, pD3DXLoadSurfaceFromSurface
call eax
mov @result, eax
popad
end;
procedure RenderSpecific_End_R1_R2(f:render_f); stdcall;
var
backbuffer: {IDirect3DSurface9} pointer;
begin
GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, @backbuffer);
if backbuffer = nil then exit;
LoadSurfaceFromSurface(backbuffer, f().pRT);
IUnknown(backbuffer)._Release();
end;
function CopyResource(this, dest:pointer):cardinal; stdcall;
asm
pushad
push this
push dest
mov eax, pHW_Device
mov eax, [eax]
push eax
mov ecx, [eax]
mov eax, ecx
add eax, _copyresource_vftable_index
call [eax]
mov @result, eax
popad
end;
procedure RenderSpecific_End_R3_R4(f:render_f); stdcall;
asm
pushad
mov eax, pSwapchain
mov eax, [eax]
mov ecx, [eax]
push eax //buffer address will be written here
lea edx, [esp]
mov ebx, pIID_ID3DTexture2D //__uuidof( ID3D10Texture2D )
push edx //pBuffer
push ebx //guid
push 0
push eax //HW.m_pSwapChain
mov eax, [ecx+$24]
call eax //HW.m_pSwapChain->GetBuffer
call f
push [eax+CRT_rec.pSurface]
mov edx, [esp+4]
push edx //Buffer
call CopyResource
mov ecx, [esp]
mov eax, [ecx]
mov eax, [eax+$8]
call eax //release
popad
end;
procedure CopyRenderTargetData(src:pCRT_rec; dest:pCRT_rec); stdcall;
begin
if (xrRender_R1_addr<>0) or (xrRender_R2_addr<>0) then begin
LoadSurfaceFromSurface(src.pRT, dest.pRT);
end else if (xrRender_R3_addr<>0) or (xrRender_R4_addr<>0) then begin
CopyResource(src.pSurface, dest.pSurface);
end;
end;
procedure dof_lens_on(); stdcall;
var
local_dof:DofContext;
begin
_dof_context.valid:=false;
GetContext(@_dof_context);
if _dof_context.valid then begin
local_dof.values.dest.x:=LENS_DOF_NEAR;
local_dof.values.dest.y:=LENS_DOF_FOCUS;
local_dof.values.dest.z:=LENS_DOF_FAR;
local_dof.values.current:=local_dof.values.dest;
local_dof.values.from:=local_dof.values.dest;
local_dof.values.original:=_dof_context.values.original;
local_dof.change_speed_koef:=LENS_DOF_SPEED;
local_dof.change_speed_recalc:=LENS_DOF_SPEED;
local_dof.valid:=true;
SetContext(@local_dof);
// log('save dof');
end;
end;
procedure dof_lens_off(); stdcall;
var
local_dof:DofContext;
begin
GetContext(@local_dof);
if (_dof_context.valid) and (local_dof.valid) then begin
//ìû ÷òî-òî ñîõðàíèëè, íàäî âîññòàíîâèòü
if
(local_dof.values.dest.x=LENS_DOF_NEAR)
and
(local_dof.values.dest.y=LENS_DOF_FOCUS)
and
(local_dof.values.dest.z=LENS_DOF_FAR)
and
(local_dof.change_speed_koef=LENS_DOF_SPEED)
and
(local_dof.change_speed_recalc=LENS_DOF_SPEED)
then begin
//èçìåíåíèé íå áûëî, âîññòàíàâëèâàåì ñòàðûé
_dof_context.values.original:=local_dof.values.original; //íà âñÿêèé, âäðóã èçìåíèëñÿ...
SetContext(@_dof_context);
// log('restore dof');
end else begin
// íå ïîâåçëî - íà ýòîì êàäðå êòî-òî ñìåíèë öåëåâîé äîô
// log('dof changed! restoring known');
local_dof.values.current:=_dof_context.values.current;
local_dof.values.from:=_dof_context.values.from;
SetContext(@local_dof);
end;
end;
_dof_context.valid :=false
end;
/////////////////////////////////////////////
// Äî ðåíäåðà
procedure BeginSecondVP( ); stdcall;
var
pda:pCUIPdaWnd;
cursor:pCUICursor;
pause_status:boolean;
begin
pda:=GetPDA();
if (pda<>nil) and IsPDAWindowVisible() then begin
pause_status:=bShowPauseString^;
bShowPauseString^:=false;
ForcedRenderUI();
cursor:=GetUICursor();
if cursor<>nil then virtual_CUICursor__OnRender(cursor);
_scopeframe_renderspecific_end(@GetUirender);
bShowPauseString^:=pause_status;
end;
if _is_lens_frame then begin
_scoped_frames:=_scoped_frames+1;
dof_lens_on();
end else begin
_non_scoped_frames:=_non_scoped_frames+1;
end;
if IsForcedLens() then begin
_buffer_index:=GetDevicedwFrame();
end else begin
_buffer_index:=_non_scoped_frames;
end;
end;
// Ïîñëå ðåíäåðà ìèðà è äî UI
procedure EndSecondVP( ); stdcall;
begin
if _is_lens_frame then begin
_scopeframe_renderspecific_end(@GetScoperender);
dof_lens_off();
end;
end;
//ïîñëå ðåíäåðà ìèðà ðåíäåðèì UI
procedure EndSecondVP_OnUIRender( ); stdcall;
begin
ForcedRenderUI();
if _is_lens_frame then begin
_scopeframe_renderspecific_end(@GetScoperenderWithUI);
end;
end;
procedure CLevel__OnRender_Before_Patch(); stdcall;
asm
pushad
call BeginSecondVP
popad
mov eax, xrgame_addr
call [eax+$512f30]
end;
procedure CLevel__OnRender_After_Patch(); stdcall;
asm
pushad
call EndSecondVP
popad
mov ecx, xrgame_addr
mov ecx, [ecx+$512D30]
end;
procedure CLevel__OnUIRender_Patch(); stdcall;
asm
pushad
call EndSecondVP_OnUIRender
popad
end;
procedure CCameraManager__Update_Lens_FOV_manipulation(value:pSingle); stdcall;
var
need_lens_frame_now:boolean;
wpn:pointer;
buf:WpnBuf;
begin
need_lens_frame_now:=NeedLensFrameNow();
if not IsLensEnabled() then begin
// Ëèíçà îòêëþ÷åíà â íàñòðîéêàõ. Åñëè ìû â ðåæèìå ïðèöåëèâàíèÿ - âñå êàäðû ðåíäåðèì ñ óêàçàííûì ôîâ
wpn:=GetActorActiveItem();
wpn:=dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CWeapon, false);
if (wpn<>nil) and (GetAimFactor(wpn) > 0.999) and not (((GetGLStatus(wpn)=1) or IsGLAttached(wpn)) and IsGLEnabled(wpn)) and IsLensedScopeInstalled(wpn) then begin
buf:=GetBuffer(wpn);
if (buf=nil) or not buf.IsAlterZoomMode() then begin
value^:=GetLensFOV(value^);
end;
end;
exit;
end;
if GetDevicedwFrame()=_last_fov_changed_frame then begin
value^:=GetLensFOV(value^);
exit;
end;
if _restore_fov_after_lens_frame = 0 then begin
//ìû íå ìåíÿëè ÔÎÂ ðàíåå. Åñëè ðèñóåòñÿ êàäð ëèíçû - ñîõðàíèì è âûñòàâèì ôîâ ëèíçû
if need_lens_frame_now then begin
_restore_fov_after_lens_frame:=value^;
_last_fov_changed_frame:=GetDevicedwFrame();
value^:=GetLensFOV(value^);
_is_lens_frame:=true;
end;
end else begin
//Ìû ðàíåå óæå èçìåíèëè ôîâ. Åñëè äî ñèõ ïîð íóæíî äåëàòü êàäð ëèíçû - ïðîñòî âûñòàâèì åãî ôîâ, èíà÷å - âîññòàíîâèì òî, ÷òî èçìåíèëè
if need_lens_frame_now then begin
value^:=GetLensFOV(value^);
_last_fov_changed_frame:=GetDevicedwFrame();
_is_lens_frame:=true;
end else begin
value^:= _restore_fov_after_lens_frame;
_restore_fov_after_lens_frame:=0;
end;
end;
end;
procedure CCameraManager__Update_Lens_FOV_manipulation_Patch(); stdcall;
asm
movss [esi+$3c], xmm1
mov byte ptr [esi+$40], 0
pushad
add esi, $34
push esi
call CCameraManager__Update_Lens_FOV_manipulation
popad
end;
procedure need_render_hud_patch(); stdcall;
asm
mov al, 1
cmp _is_lens_frame, 0
je @finish
xor al, al
@finish:
pop edi
pop esi
ret
end;
//Ôóíêöèè îðãàíèçàöèè íåâûâîäà êàäðà ëèíçû íà ýêðàí äëÿ êàæäîãî èç ðåíäåðîâ////////////////////////////////////
// R2 -> Ýòà ôóíêöèÿ îòâå÷àåò çà âûçîâ ->Present(), êîòîðûé îáíîâëÿåò êàðòèíêó íà ýêðàíå
// Îíà åñòü â êàæäîì ðåíäåðå.
procedure dxRenderDeviceRender__End__R1_R2(); stdcall;
label original;
asm
// Ïðîâåðÿåì, èä¸ò ëè ñåé÷àñ ðåíäåð âòîðîãî êàäðà
cmp _is_lens_frame, 0
je original
// Åñëè äà, òî íå îáíîâëÿåì êàðòèíêó íà ýêðàíå
mov _is_lens_frame, 0
ret
// Åñëè íåò, òî îòðèñîâûâàåì íà ýêðàí (âûçûâàåì Present())
original:
push 00
push 00
push 00
push 00
push eax
call edx
end;
procedure dxRenderDeviceRender__End__R3_R4(); stdcall;
label original;
asm
// Ïðîâåðÿåì, èä¸ò ëè ñåé÷àñ ðåíäåð âòîðîãî êàäðà
cmp _is_lens_frame, 0
je original
// Åñëè äà, òî íå îáíîâëÿåì êàðòèíêó íà ýêðàíå
mov _is_lens_frame, 0
ret
// Åñëè íåò, òî îòðèñîâûâàåì íà ýêðàí (âûçûâàåì Present())
original:
push 00
push 00
push eax
//[bug] áàã ñ VSync
//äëÿ DX9 - ñìîòðåòü Misc
pushad
call IsVSyncEnabled
cmp al, 0
popad
je @calling
mov [esp+4], 1
@calling:
call edx
end;
procedure CActor__UpdateCL_Crosshair_Patch(); stdcall;
//çàïðåùàåì îáíîâëÿòü äèñïåðñèþ, êîãäà ðåíäåðèòñÿ êàäð ïðèöåëà
asm
cmp _is_lens_frame, 0
jne @restore_fpu
sub esp, 8
fstp dword ptr [esp+$4]
fstp dword ptr [esp]
mov eax, xrGame_addr
add eax, $4b01e0
call eax //CHudManager::SetCrosshairDisp
jmp @finish
@restore_fpu: //Âîññòàíàâëèâàåì ñîñòîÿíèå FPU, åñëè âûçîâà íå ïðîèçâîäèëîñü - îíî òóò âàæíî!
sub esp, 8
fstp dword ptr [esp+$4]
fstp dword ptr [esp]
add esp, 8
@finish:
end;
function CUICursor__OnRender_DisableMultiRender_Check():boolean; stdcall;
var
curframe:cardinal;
begin
//îòêëþ÷àåì îòðèñîâêó êóðñîðà, åñëè â ýòîì êàäðå îí óæå ðèñîâàëñÿ - íàäî äëÿ êîððåêòíîé ðàáîòû ÏÄÀ
curframe:=GetCurrentFrame();
result:= not (_last_cursor_frame=curframe);
_last_cursor_frame:=curframe;
end;
procedure CUICursor__OnRender_DisableMultiRender_Patch(); stdcall;
asm
pushad
call CUICursor__OnRender_DisableMultiRender_Check
cmp al, 0
popad
je @exit
pop eax
push esi
mov esi, ecx
mov ecx, xrgame_addr
mov ecx, [ecx+$651e0c]
jmp eax
@exit:
//ðåíäåðèòü íå íàäî, óõîäèì
add esp, 4
ret // return address from CUICursor::OnRender
end;
function CUIPdaWnd__Draw_DisableMultiRender_Check():boolean; stdcall;
var
curframe:cardinal;
begin
//îòêëþ÷àåì îòðèñîâêó ÏÄÀ, åñëè â ýòîì êàäðå îí óæå ðèñîâàëñÿ
curframe:=GetCurrentFrame();
result:= not (_last_pda_frame=curframe);
_last_pda_frame:=curframe;
end;
procedure CUIPdaWnd__Draw_DisableMultiRender_Patch(); stdcall;
asm
pushad
call CUIPdaWnd__Draw_DisableMultiRender_Check
cmp al, 0
popad
je @exit
//äåëàåì âûðåçàííîå
pop eax
push esi
push eax
mov esi, ecx
mov eax, xrgame_addr
add eax, $484F80 //CUIWindow::Draw
call eax
ret
@exit:
//ðåíäåðèòü íå íàäî, óõîäèì
add esp, 4
ret // return address from CUIPdaWnd::Draw
end;
//////////////////////////////////////////////////////////////////////
function Init():boolean; stdcall;
var
jmp_addr:cardinal;
dHandle:cardinal;
buf:pCardinal;
begin
result:=false;
_is_lens_frame:=false;
_restore_fov_after_lens_frame:=0;
_last_fov_changed_frame:=0;
_scoped_frames:=0;
_non_scoped_frames:=0;
_dof_context.valid:=false;
_last_cursor_pos.x:=-1;
_last_cursor_pos.y:=-1;
_last_prev_cursor_pos.x:=-1;
_last_prev_cursor_pos.y:=-1;
_last_pda_frame:=0;
_last_cursor_frame:=0;
if xrRender_R1_addr<>0 then begin
dHandle := LoadLibrary('d3dx9_42.dll');
pD3DXLoadSurfaceFromSurface:=GetProcAddress(dHandle, 'D3DXLoadSurfaceFromSurface');
FreeLibrary(dHandle);
log('pD3DXLoadSurfaceFromSurface = '+inttohex(cardinal(pD3DXLoadSurfaceFromSurface),8));
pHW_Device:=xrRender_R1_addr+$A4900;
_p_iGPUNum:=pointer(xrRender_R1_addr+$A491C);
_scopeframe_renderspecific_end:=@RenderSpecific_End_R1_R2;
jmp_addr:=xrRender_R1_addr+$4774F;
if not WriteJump(jmp_addr, cardinal(@dxRenderDeviceRender__End__R1_R2), 11, false) then exit;
end else if xrRender_R2_addr<>0 then begin
dHandle := LoadLibrary('d3dx9_42.dll');
pD3DXLoadSurfaceFromSurface:=GetProcAddress(dHandle, 'D3DXLoadSurfaceFromSurface');
FreeLibrary(dHandle);
log('pD3DXLoadSurfaceFromSurface = '+inttohex(cardinal(pD3DXLoadSurfaceFromSurface),8));
pHW_Device:=xrRender_R2_addr+$CBB88;
_p_iGPUNum:=pointer(xrRender_R2_addr+$CBBA4);
_scopeframe_renderspecific_end:=@RenderSpecific_End_R1_R2;
jmp_addr:=xrRender_R2_addr+$AF06C;
if not WriteJump(jmp_addr, cardinal(@dxRenderDeviceRender__End__R1_R2), 11, false) then exit;
buf:=@_buffer_index;
//CRenderTarget::phase_combine
nop_code(xrRender_R2_addr+$6CBEC, 9);
nop_code(xrRender_R2_addr+$6CBEC, 1, CHR($A1)); //opcode 'mov eax, [xxxxxxxx]'
if not WriteBufAtAdr(xrRender_R2_addr+$6CBED, @buf, sizeof(buf)) then exit;
//CRenderTarget::phase_luminance
nop_code(xrRender_R2_addr+$70575, 9);
nop_code(xrRender_R2_addr+$70575, 1, CHR($A1)); //opcode 'mov eax, [xxxxxxxx]'
if not WriteBufAtAdr(xrRender_R2_addr+$70576, @buf, sizeof(buf)) then exit;
end else if xrRender_R3_addr<>0 then begin
pHW_Device:=xrRender_R3_addr+$E7E38;
pSwapchain:=xrRender_R3_addr+$E7E44;
_p_iGPUNum:=pointer(xrRender_R3_addr+$E7E60);
pIID_ID3DTexture2D:=xrRender_R3_addr+$D7104;
_copyresource_vftable_index:=$84;
_scopeframe_renderspecific_end:=@RenderSpecific_End_R3_R4;
jmp_addr:=xrRender_R3_addr+$BB920;
if not WriteJump(jmp_addr, cardinal(@dxRenderDeviceRender__End__R3_R4), 7, false) then exit;
buf:=@_buffer_index;
nop_code(xrRender_R3_addr+$7676F, 9);
nop_code(xrRender_R3_addr+$7676F, 1, CHR($A1)); //opcode 'mov eax, [xxxxxxxx]'
if not WriteBufAtAdr(xrRender_R3_addr+$76770, @buf, sizeof(buf)) then exit;
nop_code(xrRender_R3_addr+$79BFD, 9);
nop_code(xrRender_R3_addr+$79BFD, 1, CHR($A1)); //opcode 'mov eax, [xxxxxxxx]'
if not WriteBufAtAdr(xrRender_R3_addr+$79BFE, @buf, sizeof(buf)) then exit;
end else if xrRender_R4_addr<>0 then begin
pHW_Device:=xrrender_R4_addr+$106C10;
pSwapchain:=xrRender_R4_addr+$106C14;
_p_iGPUNum:=pointer(xrRender_R4_addr+$106C30);
pIID_ID3DTexture2D:=xrRender_R4_addr+$E3950;
_copyresource_vftable_index:=$BC;
_scopeframe_renderspecific_end:=@RenderSpecific_End_R3_R4;
jmp_addr:=xrRender_R4_addr+$C63B0;
if not WriteJump(jmp_addr, cardinal(@dxRenderDeviceRender__End__R3_R4), 7, false) then exit;
buf:=@_buffer_index;
//CRenderTarget::phase_combine
nop_code(xrRender_R4_addr+$7AF1F, 9);
nop_code(xrRender_R4_addr+$7AF1F, 1, CHR($A1)); //opcode 'mov eax, [xxxxxxxx]'
if not WriteBufAtAdr(xrRender_R4_addr+$7AF20, @buf, sizeof(buf)) then exit;
//CRenderTarget::phase_luminance
nop_code(xrRender_R4_addr+$7ED43, 9);
nop_code(xrRender_R4_addr+$7ED43, 1, CHR($A1)); //opcode 'mov eax, [xxxxxxxx]'
if not WriteBufAtAdr(xrRender_R4_addr+$7ED44, @buf, sizeof(buf)) then exit;
end else begin
dHandle:=0;
pD3DXLoadSurfaceFromSurface:=nil;
log('LensDoubleRender.Init: No Render DLL!');
exit;
end;
jmp_addr:=xrGame_addr+$232C03;
if not WriteJump(jmp_addr, cardinal(@CLevel__OnRender_Before_Patch), 6, true) then exit;
jmp_addr:=xrGame_addr+$232C34;
if not WriteJump(jmp_addr, cardinal(@CLevel__OnRender_After_Patch), 6, true) then exit;
jmp_addr:=xrGame_addr+$232C3A;
if not WriteJump(jmp_addr, cardinal(@CLevel__OnUIRender_Patch), 10, true) then exit;
jmp_addr:=xrEngine_addr+$2CAB9;
if not WriteJump(jmp_addr, cardinal(@CCameraManager__Update_Lens_FOV_manipulation_Patch), 9, true) then exit;
jmp_addr:=xrGame_addr+$4B061D;
if not WriteJump(jmp_addr, cardinal(@need_render_hud_patch), 5, false) then exit;
jmp_addr:=xrGame_addr+$26211C;
if not WriteJump(jmp_addr, cardinal(@CActor__UpdateCL_Crosshair_Patch), 15, true) then exit;
jmp_addr:=xrGame_addr+$4D9690;
if not WriteJump(jmp_addr, cardinal(@CUICursor__OnRender_DisableMultiRender_Patch), 9, true) then exit;
jmp_addr:=xrGame_addr+$442770;
if not WriteJump(jmp_addr, cardinal(@CUIPdaWnd__Draw_DisableMultiRender_Patch), 8, true) then exit;
result:=true;
end;
end.