-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathr_constants.pas
618 lines (518 loc) · 14.8 KB
/
r_constants.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
unit r_constants;
{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
//äîáàâëÿåò ýêñïîðò íîâûõ ïàðàìåòðîâ â øåéäåðû
//ñìîòðåòü CBlender_Compile__SetMapping, îñòàëüíîå íå òðîãàòü
interface
function Init():boolean;
implementation
uses BaseGameData, sysutils, ActorUtils, HudItemUtils, dynamic_caster, WeaponAdditionalBuffer, gunsl_config, MatVectors, math, Misc, LensDoubleRender, collimator;
//////////////////////////////////////////////////////////////////
type R_constant = record
//todo:äîïèñàòü
end;
type pR_constant = ^R_constant;
/////////////////// R_constant_setup//////////////////////////////
type R_constant_setup_vftable = record
setup_proc:pointer;
virtual_destructor:pointer;
end;
type pR_constant_setup_vftable = ^R_constant_setup_vftable;
type R_constant_setup = record
vftable:pR_constant_setup_vftable;
setup_proc_addr:procedure(C:pR_constant); stdcall; //äëÿ àäðåñà ïðîöåäóðû setup, â îðèãèíàëå íåò! Íóæíî äëÿ óäîáñòâà ðàáîòû
end;
type pR_constant_setup = ^R_constant_setup;
//////////////////////////////////////////////////////////////////////////
const
eye_direction:PChar = 'eye_direction';
var
CBlender_Compile__r_Constant_proc_addr:cardinal;
RCache__set: procedure(C:pR_constant; x,y,z,w:single); stdcall;
r_constant_vftable:R_constant_setup_vftable;
binder_cur_zoom_factor:R_constant_setup;
binder_actor_states:R_constant_setup;
binder_zoom_deviation:R_constant_setup;
binder_affects:R_constant_setup;
binder_timearrow:R_constant_setup;
binder_timearrow2:R_constant_setup;
binder_digiclock:R_constant_setup;
//Âûçîâ äâèæêîì áëåíäåðà////////////////////////////////////////
// "ïðîêëàäêà" äëÿ óäîáñòâà ðàáîòû ñ ÷ëåíîì-óêàçàòåëåì
procedure R_constant_setup__setup_internal_caller(this:pR_constant_setup; C:pR_constant); stdcall;
begin
this.setup_proc_addr(C);
end;
//ýòà ïðîöåäóðà âûçûâàåòñÿ äâèæêîì
procedure R_constant_setup__setup(); stdcall;
asm
push ebp
mov ebp, esp
pushad
push [ebp+$8]
push ecx
call R_constant_setup__setup_internal_caller
popad
pop ebp
ret 4
end;
////////////////////////////////////////////////////////////////
//ïðîöåäóðà ðåãèñòðàöèè íîâîé êîíñòàíòû
procedure CBlender_Compile__r_Constant(this:pointer; name:PChar; addr:pR_constant_setup); stdcall;
asm
pushad
push name
push this
mov esi, addr
call CBlender_Compile__r_Constant_proc_addr
popad
end;
////////////////////////////////////////////////////////////////////////
//ñîáñòâåííî ôóíêöèè çàïîëíåíèÿ äàííûìè íàøèõ êîíñòàíò
procedure binder_cur_zoom_factor_setup(C:pR_constant); stdcall;
var
wpn:pointer;
val:single;
abberation:single;
x,y:cardinal;
sect:PChar;
lens_factor:single;
begin
val:=0;
wpn:=GetActorActiveItem();
abberation:=0;
lens_factor:=0;
if (wpn<>nil) and (dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CWeapon, false)<>nil) then begin
val:=GetAimFactor(wpn);
abberation:=ModifyFloatUpgradedValue(wpn, 'scope_abberation', game_ini_r_single_def(GetSection(wpn), 'scope_abberation', 0));
if IsScopeAttached(wpn) then begin
sect:=game_ini_read_string(GetCurrentScopeSection(wpn), 'scope_name');
abberation:=game_ini_r_single_def(sect, 'scope_abberation', abberation);
end;
lens_factor:=GetZoomLensVisibilityFactor(wpn);
end;
GetScreenParams(@x, @y);
RCache__set(C, y/x,val,abberation,lens_factor);
end;
procedure binder_affects_setup(C:pR_constant); stdcall;
var
decr:single;
begin
if IsElectronicsProblemsDecreasing() then decr:=1 else decr := 0;
RCache__set(C, CurrentElectronicsProblemsCnt()/10, random, TargetElectronicsProblemsCnt()/10, decr);
end;
procedure binder_actor_states_setup(C:pR_constant); stdcall;
var
act, outfit, wpn:pointer;
actor_health, actor_weapon_cond, actor_outfit_cond, actor_wpn_loading:single;
buf:WpnBuf;
reload_time, now_time:cardinal;
begin
act:=GetActor();
if act=nil then begin
RCache__set(C, -1,-1,-1,-1);
end;
outfit:=ItemInSlot(act, OUTFIT_SLOT);
if (outfit<>nil) then outfit:=dynamic_cast(outfit, 0, RTTI_CInventoryItem, RTTI_CCustomOutfit, false);
if (outfit<>nil) then begin
actor_outfit_cond:=GetCurrentCondition(outfit);
end else begin
actor_outfit_cond:=-1;
end;
wpn:=GetActorActiveItem();
if wpn<>nil then begin
actor_weapon_cond:=GetCurrentCondition(wpn);
buf:=GetBuffer(wpn);
if buf<>nil then begin
reload_time:=floor(buf.GetLastRechargeTime() * 1000);
now_time:= buf.GetLastShotTimeDelta();
actor_wpn_loading := now_time / reload_time;
if actor_wpn_loading>1 then actor_wpn_loading:=1;
end else begin
actor_wpn_loading :=1;
end;
end else begin
actor_weapon_cond:=-1;
actor_wpn_loading:=1;
end;
actor_health:=GetActorHealth(act);
RCache__set(C, actor_health, actor_outfit_cond, actor_weapon_cond, actor_wpn_loading);
end;
procedure binder_zoom_deviation_setup(C:pR_constant); stdcall;
var
wpn:pointer;
buf:WpnBuf;
offset_params:lens_offset_params;
ang, len, x,y, cond:single;
scope_sect:PChar;
begin
wpn:=GetActorActiveItem();
if (wpn<>nil) and WpnCanShoot(wpn) then buf:=GetBuffer(wpn) else buf:=nil;
if buf<>nil then begin
buf.GetLensOffsetParams(@offset_params);
ang:=offset_params.dir*2*pi;
cond:=GetCurrentCondition(wpn);
if cond>offset_params.start_condition then
len:=0
else if cond<offset_params.end_condition then
len:=offset_params.max_value
else
len:=offset_params.max_value*(offset_params.start_condition-cond)/(offset_params.start_condition-offset_params.end_condition);
if IsScopeAttached(wpn) and (GetScopeStatus(wpn)=2) then begin
scope_sect:=game_ini_read_string(GetCurrentScopeSection(wpn), 'scope_name');
len:=len*game_ini_r_single_def(scope_sect, 'lens_offset_factor', 1.0);
end;
x:=len*cos(ang);
y:=len*sin(ang);
x:=x+buf.GetCurLensRecoil.x;
y:=y+buf.GetCurLensRecoil.y;
// log('deviation len='+floattostr(len)+', x='+floattostr(x)+', y='+floattostr(y));
RCache__set(C, x,y,buf.GetCurBrightness.cur_value,buf.GetCurBrightness.jitter);
end;
end;
procedure binder_timearrow_setup(C:pR_constant); stdcall;
var
y, mo, d, h, m, s, ms:integer;
h_f, m_f, s_f:single;
h_angle, m_angle, s_angle:single;
begin
y:=0;
mo:=0;
d:=0;
h:=0;
m:=0;
s:=0;
ms:=0;
get_split_time(@y, @mo, @d, @h, @m, @s, @ms);
R_ASSERT((h>=0) and (h<24), 'Invalid hours value', 'binder_timearrow_setup');
R_ASSERT((m>=0) and (m<60), 'Invalid minutes value', 'binder_timearrow_setup');
R_ASSERT((s>=0) and (s<60), 'Invalid seconds value', 'binder_timearrow_setup');
s_f := s/60;
s_angle := 2*pi*s_f;
m_f:= (s_f+m) / 60;
m_angle := 2*pi*m_f;
h_f:= (m_f+h) / 12;
h_angle:=2*pi*h_f;
RCache__set(C, sin(h_angle), cos(h_angle), sin(m_angle), cos(m_angle));
end;
procedure binder_timearrow2_setup(C:pR_constant); stdcall;
var
y, mo, d, h, m, s, ms:integer;
camdir:FVector3;
sec_f, temp:single;
sec_angle, compass_angle:single;
begin
y:=0;
mo:=0;
d:=0;
h:=0;
m:=0;
s:=0;
ms:=0;
get_split_time(@y, @mo, @d, @h, @m, @s, @ms);
R_ASSERT((s>=0) and (s<60), 'Invalid seconds value', 'binder_timearrow2_setup');
sec_f:= s / 60;
sec_angle := 2*pi*sec_f;
camdir:=FVector3_copyfromengine(CRenderDevice__GetCamDir());
getHP(@camdir, compass_angle, temp);
RCache__set(C, sin(sec_angle), cos(sec_angle), sin(compass_angle), cos(compass_angle));
end;
procedure binder_digiclock_setup(C:pR_constant); stdcall;
var
y, mo, d, h, m, s, ms:integer;
hh, hl, mh, ml:single;
begin
y:=0;
mo:=0;
d:=0;
h:=0;
m:=0;
s:=0;
ms:=0;
get_split_time(@y, @mo, @d, @h, @m, @s, @ms);
hh:= (h div 10) / 10; //ñòàðøèé ðàçðÿä ÷àñîâ
hl:= (h mod 10) / 10; //ìëàäøèé ðàçðÿä ÷àñîâ
mh:= (m div 10) / 10; //ñòàðøèé ðàçðÿä ìèíóò
ml:= (m mod 10) / 10; //ìëàäøèé ðàçðÿä ìèíóò
RCache__set(C, hh, hl, mh, ml);
end;
////////////////////////////////////////////////////////////////////////
procedure CBlender_Compile__SetMapping(this:pointer); stdcall;
begin
//Íîâûå êîíñòàíòû äîïèñûâàòü ÇÄÅÑÜ!
//log(inttohex(cardinal(@binder_cur_zoom_factor), 8));
binder_cur_zoom_factor.vftable:=@r_constant_vftable;
binder_cur_zoom_factor.setup_proc_addr:=@binder_cur_zoom_factor_setup;
CBlender_Compile__r_Constant(this, 'm_hud_params', @binder_cur_zoom_factor);
binder_actor_states.vftable:=@r_constant_vftable;
binder_actor_states.setup_proc_addr:=@binder_actor_states_setup;
CBlender_Compile__r_Constant(this, 'm_actor_params', @binder_actor_states);
binder_zoom_deviation.vftable:=@r_constant_vftable;
binder_zoom_deviation.setup_proc_addr:=@binder_zoom_deviation_setup;
CBlender_Compile__r_Constant(this, 'm_zoom_deviation', @binder_zoom_deviation);
binder_affects.vftable:=@r_constant_vftable;
binder_affects.setup_proc_addr:=@binder_affects_setup;
CBlender_Compile__r_Constant(this, 'm_affects', @binder_affects);
binder_timearrow.vftable:=@r_constant_vftable;
binder_timearrow.setup_proc_addr:=@binder_timearrow_setup;
CBlender_Compile__r_Constant(this, 'm_timearrow', @binder_timearrow);
binder_timearrow2.vftable:=@r_constant_vftable;
binder_timearrow2.setup_proc_addr:=@binder_timearrow2_setup;
CBlender_Compile__r_Constant(this, 'm_timearrow2', @binder_timearrow2);
binder_digiclock.vftable:=@r_constant_vftable;
binder_digiclock.setup_proc_addr:=@binder_digiclock_setup;
CBlender_Compile__r_Constant(this, 'm_digiclock', @binder_digiclock);
end;
//Ïàò÷ äëÿ äîáàâëåíèÿ êîíñòàíò
procedure CBlender_Compile__SetMapping_Patch(); stdcall;
asm
pushad
push edi
call CBlender_Compile__SetMapping
popad
push [esp]
push eax
mov eax, eye_direction
mov [esp+8], eax
pop eax
end;
//////////////Ñåìåéñòâî RCache::Set äëÿ êàæäîãî èç ðåíäåðîâ/////////////
procedure RCache__Set_R1 (C:pR_constant; x,y,z,w:single); stdcall;
asm
pushad
mov ecx, C
test ecx, ecx
je @finish
test byte ptr [ecx+$0C],01
movss xmm0, x
movss xmm1, y
movss xmm2, z
movss xmm3, w
je @vertex
//if pixel
movzx eax,word ptr [ecx+$10]
shl eax,04
add eax, xrRender_R1_addr
add eax, $B5B60
movss [eax],xmm0
movss [eax+$04],xmm1
movss [eax+$08],xmm2
movss [eax+$0C],xmm3
movzx eax,word ptr [ecx+$10]
mov ebx, xrRender_R1_addr
add ebx, $B6B64
cmp eax, [ebx]
lea edx,[eax+$01]
jae @p1
mov [ebx], eax
@p1:
add ebx, $4
cmp edx, [ebx]
jna @p2
mov [ebx], edx
@p2:
mov [ebx+$8], 1
@vertex:
test byte ptr [ecx+$0C],02
je @finish
movzx eax,word ptr [ecx+$14]
shl eax,04
add eax, xrRender_R1_addr
add eax, $B6B80
movss [eax],xmm0
movss [eax+$04],xmm1
movss [eax+$08],xmm2
movss [eax+$0C],xmm3
movzx eax,word ptr [ecx+$14]
mov ebx, xrRender_R1_addr
add ebx, $B7B84
cmp eax, [ebx]
lea ecx,[eax+$01]
jae @v1
mov [ebx], eax
@v1:
add ebx, $4
cmp ecx, [ebx]
jna @v2
mov [ebx], ecx
@v2:
mov [ebx+$8], 1
@finish:
popad
end;
procedure RCache__Set_R2 (C:pR_constant; x,y,z,w:single); stdcall;
asm
pushad
mov ecx, C
test ecx, ecx
je @finish
test byte ptr [ecx+$0C],01
movss xmm0, x
movss xmm1, y
movss xmm2, z
movss xmm3, w
je @vertex
//if pixel
movzx eax,word ptr [ecx+$10]
shl eax,04
add eax, xrRender_R2_addr
add eax, $DD090
movss [eax],xmm0
movss [eax+$04],xmm1
movss [eax+$08],xmm2
movss [eax+$0C],xmm3
movzx eax,word ptr [ecx+$10]
mov ebx, xrRender_R2_addr
add ebx, $DE094
cmp eax, [ebx]
lea edx,[eax+$01]
jae @p1
mov [ebx], eax
@p1:
add ebx, $4
cmp edx, [ebx]
jna @p2
mov [ebx], edx
@p2:
mov [ebx+$8], 1
@vertex:
test byte ptr [ecx+$0C],02
je @finish
movzx eax,word ptr [ecx+$14]
shl eax,04
add eax, xrRender_R2_addr
add eax, $DE0B0
movss [eax],xmm0
movss [eax+$04],xmm1
movss [eax+$08],xmm2
movss [eax+$0C],xmm3
movzx eax,word ptr [ecx+$14]
mov ebx, xrRender_R2_addr
add ebx, $DF0B4
cmp eax, [ebx]
lea ecx,[eax+$01]
jae @v1
mov [ebx], eax
@v1:
add ebx, $4
cmp ecx, [ebx]
jna @v2
mov [ebx], ecx
@v2:
mov [ebx+$8], 1
@finish:
popad
end;
procedure RCache__Set_R3_internal(); stdcall;
//fake arguments present!!!
//íàø äåâèç: ÷òî ðàáîòàåò - òî íå áåçîáðàçíî!!!
asm
mov ecx, esp
sub esp, $10
push esi
mov esi, [ecx+$04]
mov eax, [ecx+$08]
mov [esp+$04], eax
mov eax, [ecx+$0C]
mov [esp+$08], eax
mov eax, [ecx+$10]
mov [esp+$0C], eax
mov eax, [ecx+$14]
mov [esp+$10], eax
mov ecx, xrrender_r3_addr
add ecx, $96F64
mov eax, [esi+$0C]
test al, 01
jmp ecx //[hack] èñïîëüçóåì êóñîê äâèæêîâîé ôóíêöèè
end;
procedure RCache__Set_R3 (C:pR_constant; x,y,z,w:single); stdcall;
asm
pushad
cmp C, 0
je @finish
push w
push z
push y
push x
push c
call RCache__Set_R3_internal
add esp, $10
@finish:
popad
end;
procedure RCache__Set_R4_internal(); stdcall;
//fake arguments present!!!
//íàø äåâèç: ÷òî ðàáîòàåò - òî íå áåçîáðàçíî!!!
asm
mov ecx, esp
sub esp, $10
push esi
mov esi, [ecx+$04]
mov eax, [ecx+$08]
mov [esp+$04], eax
mov eax, [ecx+$0C]
mov [esp+$08], eax
mov eax, [ecx+$10]
mov [esp+$0C], eax
mov eax, [ecx+$14]
mov [esp+$10], eax
mov ecx, xrrender_r4_addr
add ecx, $9F15A
mov eax, [esi+$0C]
push ebx
mov ebx, 1
test bl, al
jmp ecx //[hack] èñïîëüçóåì êóñîê äâèæêîâîé ôóíêöèè
end;
procedure RCache__Set_R4 (C:pR_constant; x,y,z,w:single); stdcall;
asm
pushad
cmp C, 0
je @finish
push w
push z
push y
push x
push c
call RCache__Set_R4_internal
add esp, $10
@finish:
popad
end;
////////////////////////////////////////////////////////////////////////
function Init():boolean;
var
jmp_addr:cardinal;
begin
result:=false;
if xrRender_R1_addr<>0 then begin
CBlender_Compile__r_Constant_proc_addr:=xrRender_R1_addr+$610A0;
RCache__set:=RCache__Set_R1;
jmp_addr:=xrRender_R1_addr+$6304B;
r_constant_vftable.virtual_destructor:= pointer(xrRender_R1_addr+$616C0);
end else if xrRender_R2_addr<>0 then begin
CBlender_Compile__r_Constant_proc_addr:=xrRender_R2_addr+$89600;
RCache__set:=RCache__Set_R2;
jmp_addr:=xrRender_R2_addr+$8B5EB;
r_constant_vftable.virtual_destructor:=pointer(xrRender_R2_addr+$89c60);
end else if xrRender_R3_addr<>0 then begin
CBlender_Compile__r_Constant_proc_addr:=xrRender_R3_addr+$95490;
RCache__set:=RCache__Set_R3;
jmp_addr:=xrRender_R3_addr+$9762B;
r_constant_vftable.virtual_destructor:=pointer(xrRender_R3_addr+$15950);
end else if xrRender_R4_addr<>0 then begin
CBlender_Compile__r_Constant_proc_addr:=xrRender_R4_addr+$9D160;
RCache__set:=RCache__Set_R4;
jmp_addr:=xrRender_R4_addr+$9FF3B;
r_constant_vftable.virtual_destructor:=pointer(xrRender_R4_addr+$9E1C0);
end else begin
CBlender_Compile__r_Constant_proc_addr :=0;
RCache__set:=nil;
r_constant_vftable.virtual_destructor:=nil;
jmp_addr:=0;
end;
if jmp_addr>0 then
if not WriteJump(jmp_addr, cardinal(@CBlender_Compile__SetMapping_Patch), 5, true) then exit;
r_constant_vftable.setup_proc:=@R_constant_setup__setup;
result:=true;
end;
end.