-
-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathdllmain.cpp
1442 lines (1247 loc) · 64.3 KB
/
dllmain.cpp
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
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "stdafx.h"
#include <d3d9.h>
namespace DamageFix
{
inline uintptr_t ptrGameFlowManagerStatus = 0x00ABB510;
inline uintptr_t ptrbFree = 0x00436130;
inline intptr_t ptrMemoryPoolClose = 0x00435D20;
inline uintptr_t ptr_g_AttachmentVBMemoryPool = 0x00BFBCE0;
inline uintptr_t ptr_g_AttachmentMemoryPool = 0x00BFBCE4;
void* ptrDamageVBPool = 0;
void* ptrDamagePool = 0;
inline const char* aDamagevbpool = "OptimizedDamageVBPool";
inline const char* aDamagepool = "OptimizedDamagePool";
inline intptr_t bGetFreeMemoryPoolNum = 0x00435C70;
inline intptr_t bWareMalloc = 0x00435EB0;
inline uintptr_t MemoryPoolInfoTable = 0x00B4D9F0;
inline uintptr_t MemoryPoolMem = 0x00B4DD10;
inline uintptr_t MemoryPools = 0x00B4DBF0;
inline uintptr_t MemoryPool_Init = 0x00435140;
#define g_AttachmentVBMemoryPool_Val *reinterpret_cast<uint32_t*>(ptr_g_AttachmentVBMemoryPool)
#define g_AttachmentMemoryPool_Val *reinterpret_cast<uint32_t*>(ptr_g_AttachmentMemoryPool)
void __declspec(naked) DamagePublic_Init()
{
// clang-format off
_asm
{
push ebx
push esi
call bGetFreeMemoryPoolNum; bGetFreeMemoryPoolNum(void)
xor ebx, ebx
push ebx; allocation_params
push 1000000h; size
mov ebx, ptr_g_AttachmentVBMemoryPool
mov dword ptr [ebx], eax; int g_AttachmentVBMemoryPool
call bWareMalloc; bWareMalloc(int, char const*, int, int)
mov ptrDamageVBPool, eax
mov edx, ptr_g_AttachmentVBMemoryPool
mov edx, dword ptr [edx]; memory
mov ecx, edx
shl ecx, 4
add ecx, MemoryPoolInfoTable; MemoryPoolInfo* MemoryPoolInfoTable
mov[ecx + 1], bl
mov dword ptr[ecx + 4], 0FFFFFFFFh
mov dword ptr[ecx + 8], 10h
mov ecx, edx
imul ecx, 7Ch; '|'; mempool
add esp, 8
push aDamagevbpool; "DamageVBPool"
push 1000000h; memory_size
mov esi, MemoryPoolMem
lea esi, dword ptr[esi + ecx]
push eax; memory
mov eax, MemoryPools
mov dword ptr[eax + edx * 4], esi; MemoryPool** MemoryPools
call MemoryPool_Init; MemoryPool::Init(void*, int, char const*)
mov eax, ptr_g_AttachmentVBMemoryPool
mov eax, dword ptr [eax]
mov esi, eax
and eax, 1Fh
or eax, 40h
push eax; allocation_params
push 10h; size
call bWareMalloc; bWareMalloc(int, char const*, int, int)
mov edx, MemoryPools
mov edx, dword ptr[edx + esi * 4]; MemoryPool** MemoryPools
push eax
mov[edx + 45h], bl
call ptrbFree; bFree(void*)
call bGetFreeMemoryPoolNum; bGetFreeMemoryPoolNum(void)
push ebx; allocation_params
push 700000h; size
mov ebx, ptr_g_AttachmentMemoryPool
mov dword ptr [ebx], eax
call bWareMalloc; bWareMalloc(int, char const*, int, int)
mov ptrDamagePool, eax
mov edx, ptr_g_AttachmentMemoryPool
mov edx, dword ptr [edx]
mov ecx, edx
shl ecx, 4
add ecx, MemoryPoolInfoTable; MemoryPoolInfo* MemoryPoolInfoTable
mov[ecx + 1], bl
mov dword ptr[ecx + 4], 0FFFFFFFFh
mov dword ptr[ecx + 8], 10h
mov ecx, edx
imul ecx, 7Ch; '|'; mempool
add esp, 14h
push aDamagepool; "DamagePool"
push 700000h; memory_size
mov esi, MemoryPoolMem
lea esi, dword ptr[esi + ecx]
push eax; memory
mov eax, MemoryPools
mov dword ptr[eax + edx * 4], esi; MemoryPool** MemoryPools
call MemoryPool_Init; MemoryPool::Init(void*, int, char const*)
mov eax, ptr_g_AttachmentMemoryPool
mov eax, dword ptr [eax]
mov esi, eax
and eax, 1Fh
or eax, 40h
push eax; allocation_params
push 10h; size
call bWareMalloc; bWareMalloc(int, char const*, int, int)
mov edx, MemoryPools
mov edx, dword ptr[edx + esi * 4]; MemoryPool** MemoryPools
push eax
mov[edx + 45h], bl
call ptrbFree; bFree(void*)
add esp, 0Ch
pop esi
pop ebx
retn
}
// clang-format on
}
bool bReInitFlag = false;
void __stdcall QuitToFEHook()
{
bReInitFlag = true;
}
void GameLoopExecutor()
{
if (!bReInitFlag) return;
if (*reinterpret_cast<uint32_t*>(ptrGameFlowManagerStatus) == 3)
{
//*(bool*)0x00A9D6A7 = false; // g_AttachmentInPhysics
//printf("Re-initing damage memory pools\n");
// close the memory pools first
reinterpret_cast<void(*)(uint32_t)>(ptrMemoryPoolClose)(g_AttachmentMemoryPool_Val); // MemoryPool::Close
reinterpret_cast<void(*)(uint32_t)>(ptrMemoryPoolClose)(g_AttachmentVBMemoryPool_Val); // MemoryPool::Close
g_AttachmentVBMemoryPool_Val = -1;
g_AttachmentMemoryPool_Val = -1;
reinterpret_cast<void(*)(void*)>(ptrbFree)(ptrDamageVBPool); // bFree
reinterpret_cast<void(*)(void*)>(ptrbFree)(ptrDamagePool); // bFree
DamagePublic_Init();
bReInitFlag = false;
//*(bool*)0x00A9D6A7 = true; // g_AttachmentInPhysics
}
}
int Init()
{
uintptr_t loc_6DAB0E = reinterpret_cast<uintptr_t>(hook::pattern("68 00 60 00 00 E8 ? ? ? ? D9 05 ? ? ? ?").get_first(0)) + 0x5A;
uintptr_t loc_6A7976 = reinterpret_cast<uintptr_t>(hook::pattern("8B 11 8B 43 08 8B 92 54 01 00 00 50 FF D2").get_first(0)) - 0xB;
uintptr_t loc_4351CC = reinterpret_cast<uintptr_t>(hook::pattern("7E 18 68 FF FF FF 7F").get_first(0));
uintptr_t loc_4351E6 = loc_4351CC + 0x1A;
uintptr_t loc_4482FC = reinterpret_cast<uintptr_t>(hook::pattern("66 F7 46 0E 00 20 0F").get_first(0)) + 6;
uintptr_t loc_6DB10F = reinterpret_cast<uintptr_t>(hook::pattern("E8 ? ? ? ? E8 ? ? ? ? 8B 4C 24 10 64 89 0D 00 00 00 00 59 5E 83 C4 14 C3 CC").get_first(0)) - 0xA;
uintptr_t loc_4AD80F = reinterpret_cast<uintptr_t>(hook::pattern("E8 ? ? ? ? 83 3D ? ? ? ? 06 0F").get_first(0)) + 7;
ptrGameFlowManagerStatus = *reinterpret_cast<uintptr_t*>(loc_4AD80F);
ptrbFree = reinterpret_cast<uintptr_t>(hook::pattern("80 7E F5 22").get_first(0)) - 0x74;
uintptr_t loc_7907EA = reinterpret_cast<uintptr_t>(hook::pattern("E8 ? ? ? ? 8B 4E 60 51").get_first(0));
ptrMemoryPoolClose = loc_7907EA + 5 + *reinterpret_cast<intptr_t*>(loc_7907EA + 1);
uintptr_t loc_65F770 = reinterpret_cast<uintptr_t>(hook::pattern("6A 47 68 00 40 16 00").get_first(0)) + 0x12;
bGetFreeMemoryPoolNum = loc_65F770 + 5 + *reinterpret_cast<intptr_t*>(loc_65F770 + 1);
uintptr_t loc_436538 = reinterpret_cast<uintptr_t>(hook::pattern("C1 E8 02 25 FF 07 00 00").get_first(0)) + 0x40;
bWareMalloc = loc_436538 + 5 + *reinterpret_cast<intptr_t*>(loc_436538 + 1);
uintptr_t loc_1C45036 = reinterpret_cast<uintptr_t>(hook::pattern("8B C8 C1 E1 04 81 C1 ? ? ? ?").get_first(0)); // securom section, in drm-free demo: 0x00436188
MemoryPoolInfoTable = *reinterpret_cast<uintptr_t*>(loc_1C45036 + 7);
MemoryPoolMem = *reinterpret_cast<uintptr_t*>(loc_1C45036 + 0x2A);
MemoryPools = *reinterpret_cast<uintptr_t*>(loc_1C45036 + 0x37);
uintptr_t loc_435F84 = reinterpret_cast<uintptr_t>(hook::pattern("C6 05 ? ? ? ? 00 C7 05 ? ? ? ? FF FF FF FF C7 05 ? ? ? ? 10 00 00 00 89 35 ? ? ? ? E8").get_first(0)) + 0x21; // 2 hits in DRM-free, which is OK
MemoryPool_Init = loc_435F84 + 5 + *reinterpret_cast<intptr_t*>(loc_435F84 + 1);
uintptr_t sub_438AE0 = reinterpret_cast<uintptr_t>(hook::pattern("A1 ? ? ? ? 83 E0 1F 0D 00 04 00 00 89 44 24 08 E9 ? ? ? ?").get_first(0));
ptr_g_AttachmentVBMemoryPool = *reinterpret_cast<uintptr_t*>(sub_438AE0 + 1);
uintptr_t loc_438962 = reinterpret_cast<uintptr_t>(hook::pattern("A1 ? ? ? ? 83 E0 1F 0D 00 04 00 00 50 68 C4 0A 00 00").get_first(0));
ptr_g_AttachmentMemoryPool = *reinterpret_cast<uintptr_t*>(loc_438962 + 1);
// DamagePublic init DRM-free code
injector::MakeCALL(loc_6DAB0E, DamagePublic_Init, true);
// Hook for EQuitToFE to tell the game it's ready to free memory
injector::MakeCALL(loc_6A7976, QuitToFEHook, true);
// remove free assert
injector::MakeJMP(loc_4351CC, loc_4351E6, true);
// force damage skin recreation!
//injector::MakeNOP(0x00448D85, 6, true);
//injector::MakeNOP(0x00448D7B, 6, true);
injector::MakeNOP(loc_4482FC, 6, true);
// game loop
injector::MakeCALL(loc_6DB10F, GameLoopExecutor, true);
return 0;
}
}
static bool bAccessedPostRace;
uint32_t StuffToCompare = 0;
bool __stdcall memory_readable(void *ptr, size_t byteCount)
{
MEMORY_BASIC_INFORMATION mbi;
if (VirtualQuery(ptr, &mbi, sizeof(MEMORY_BASIC_INFORMATION)) == 0)
return false;
if (mbi.State != MEM_COMMIT)
return false;
if (mbi.Protect == PAGE_NOACCESS || mbi.Protect == PAGE_EXECUTE)
return false;
// This checks that the start of memory block is in the same "region" as the
// end. If it isn't you "simplify" the problem into checking that the rest of
// the memory is readable.
size_t blockOffset = (size_t)((char *)ptr - (char *)mbi.AllocationBase);
size_t blockBytesPostPtr = mbi.RegionSize - blockOffset;
if (blockBytesPostPtr < byteCount)
return memory_readable((char *)ptr + blockBytesPostPtr,
byteCount - blockBytesPostPtr);
return true;
}
uint32_t FEScriptFixExit;
void __declspec(naked) FEScriptMemoryCheck()
{
_asm
{
push edi
mov edi, [esp + 8]
mov StuffToCompare, edi
}
if (memory_readable((void*)StuffToCompare, 8))
_asm jmp FEScriptFixExit
_asm
{
pop edi
retn
}
}
uint32_t* dword_AC6ED4 = (uint32_t*)0x00AC6ED4;
static bool bInSparkRender = false;
void(__thiscall* sub_706550)(void* that, void* texture) = (void(__thiscall*)(void*, void*))0x706550;
void(__thiscall* XSpriteManager_DrawBatch)(void* that, void* view) = (void(__thiscall*)(void*, void*))0x004B61C0;
#pragma runtime_checks( "", off )
void __stdcall XSpriteManager_DrawBatch_Hook(void* view)
{
void* that;
_asm mov that, ecx
bInSparkRender = true;
XSpriteManager_DrawBatch(that, view);
bInSparkRender = false;
}
void __stdcall sub_706550_hook(void* texture)
{
void* that;
_asm mov that, ecx
sub_706550(that, texture);
if (bInSparkRender)
{
LPDIRECT3DDEVICE9 gDevice = **(LPDIRECT3DDEVICE9**)dword_AC6ED4;
gDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
}
}
uintptr_t SinglePlayerPostRaceStateManager_HandleScreenConstructed = 0x5A7750;
void __stdcall SinglePlayerPostRaceStateManager_HandleScreenConstructed_Hook()
{
uintptr_t that;
_asm mov that, ecx
reinterpret_cast<void(__thiscall*)(uintptr_t)>(SinglePlayerPostRaceStateManager_HandleScreenConstructed)(that);
// set mbScreenConstructed to true because the game has anxiety setting it
*(bool*)(that + 0xC6) = true;
}
uintptr_t OnlinePostRaceStateManager_HandleScreenConstructed = 0x5FA460;
void __stdcall OnlinePostRaceStateManager_HandleScreenConstructed_Hook()
{
uintptr_t that;
_asm mov that, ecx
reinterpret_cast<void(__thiscall*)(uintptr_t)>(OnlinePostRaceStateManager_HandleScreenConstructed)(that);
// set mbScreenConstructed to true because the game has anxiety setting it
*(bool*)(that + 0xC6) = true;
}
int32_t RetZero()
{
return 0;
}
void __declspec(naked) UpdateAchievements_Hook()
{
_asm
{
pop eax
pop eax
ret
}
}
namespace XtendedInput
{
HMODULE mhXtendedInput;
float(__cdecl* SetFEScale)(float val);
bool(__cdecl* GetUseWin32Cursor)();
bool(__cdecl* SetPollingState)(bool state);
bool bLookedForXInput = false;
bool bFoundXInput = false;
void LookForXtendedInput()
{
if (!mhXtendedInput)
{
mhXtendedInput = GetModuleHandleA("NFS_XtendedInput.asi");
if (mhXtendedInput)
{
SetFEScale = reinterpret_cast<float(__cdecl*)(float)>(GetProcAddress(mhXtendedInput, "SetFEScale"));
GetUseWin32Cursor = reinterpret_cast<bool(__cdecl*)()>(GetProcAddress(mhXtendedInput, "GetUseWin32Cursor"));
SetPollingState = reinterpret_cast<bool(__cdecl*)(bool)>(GetProcAddress(mhXtendedInput, "SetPollingState"));
bFoundXInput = (SetFEScale != nullptr) && (GetUseWin32Cursor != nullptr) && (SetPollingState != nullptr);
}
}
}
}
namespace LANFix
{
uintptr_t ptrDataConnection = 0x827190;
uint32_t AddrFamily = 2; // 2 = AF_INET, 23 = AF_INET6 (to add v6, the string needs to be extended, as the input box is limited to 15 chars!)
uint32_t CheckAddressFamily(std::string addr)
{
// default to AF_INET because it doesn't work otherwise...
return 2;
}
bool __stdcall DataConnectionHook(char* addr, void* unk)
{
uintptr_t that;
_asm mov that, ecx
// attempt to detect address family
AddrFamily = CheckAddressFamily(addr);
return reinterpret_cast<bool(__thiscall*)(uintptr_t, char*, void*)>(ptrDataConnection)(that, addr, unk);
}
}
namespace FEScale
{
float fFEScale = 1.0f;
float fCalcFEScale = 1.0f;
float fFMVScale = 1.0f;
float fCalcFMVScale = 1.0f;
bool bAutoFitFE = true;
bool bAutoFitFMV = true;
void UpdateXtendedInput()
{
if (!XtendedInput::bLookedForXInput)
XtendedInput::LookForXtendedInput();
if (!XtendedInput::bFoundXInput) return;
if (!XtendedInput::GetUseWin32Cursor()) return;
XtendedInput::SetFEScale(fCalcFEScale);
}
}
namespace OnlineInputBlocker
{
bool bPollingEnabledOnline = true;
uintptr_t ptrGameDevicePoll = 0x006C0D10;
void __stdcall GameDevice_PollDevice_Hook()
{
uintptr_t that;
_asm mov that, ecx
if (!bPollingEnabledOnline)
return;
return reinterpret_cast<void(__thiscall*)(uintptr_t)>(ptrGameDevicePoll)(that);
}
uintptr_t ptrSteeringWheelDevicePoll = 0x006A6180;
uint32_t __stdcall SteeringWheelDevice_PollDevice_Hook()
{
uintptr_t that;
_asm mov that, ecx
if (!bPollingEnabledOnline)
return 0;
return reinterpret_cast<uint32_t(__thiscall*)(uintptr_t)>(ptrSteeringWheelDevicePoll)(that);
}
}
uintptr_t OnlineActiveGameManager_msInstance = 0x00B3082C;
unsigned int GameWndProcAddr = 0;
LRESULT(WINAPI* GameWndProc)(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT WINAPI WSFixWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_ACTIVATEAPP:
case WM_ACTIVATE:
if (LOWORD(wParam) == WA_INACTIVE || wParam == FALSE)
{
if (*(uint32_t*)OnlineActiveGameManager_msInstance)
{
if (!XtendedInput::bLookedForXInput)
{
XtendedInput::LookForXtendedInput();
XtendedInput::bLookedForXInput = true;
}
if (XtendedInput::bFoundXInput)
XtendedInput::SetPollingState(false);
else
OnlineInputBlocker::bPollingEnabledOnline = false;
return TRUE;
}
}
else
{
if (!XtendedInput::bLookedForXInput)
{
XtendedInput::LookForXtendedInput();
XtendedInput::bLookedForXInput = true;
}
if (XtendedInput::bFoundXInput)
XtendedInput::SetPollingState(true);
else
OnlineInputBlocker::bPollingEnabledOnline = true;
}
}
return GameWndProc(hWnd, msg, wParam, lParam);
}
#pragma runtime_checks( "", restore )
bool bCheckDemoVersion()
{
// demo version check
uintptr_t sub_6DBA80 = reinterpret_cast<uintptr_t>(hook::pattern("83 EC 08 6A 01 68 ? ? ? ? C7 44 24 0C 00 00 00 00").get_first(0));
char* nfsc_demo_str = *reinterpret_cast<char**>(sub_6DBA80 + 6); // yes, we're checking for nfsc_demo.exe, this is correct for Pro Street
if ((strstr(nfsc_demo_str, "demo.exe") == nullptr) && (nfsc_demo_str != nullptr))
return false;
return true;
}
void Init()
{
//Stop settings reset after crash
auto pattern = hook::pattern("C7 44 24 ? ? ? ? ? FF 15 ? ? ? ? 8D 54 24 0C 52");
injector::WriteMemory(pattern.get_first(4), 0, true);
//Enables HD_GROUP texture on start screen
uint32_t* dword_7E2C02 = hook::pattern("68 ? ? ? ? E8 ? ? ? ? 8B F8 8B 46 0C 57").count(1).get(0).get<uint32_t>(1);
injector::WriteMemory(dword_7E2C02, &"ENABLEHD", true);
CIniReader iniReader("");
auto bShowConsole = iniReader.ReadInteger("MultiFix", "ShowConsole", 0) != 0;
auto bResDetect = iniReader.ReadInteger("MultiFix", "ResDetect", 1) != 0;
auto bPostRaceFix = iniReader.ReadInteger("MultiFix", "PostRaceFix", 1) != 0;
auto bFramerateUncap = iniReader.ReadInteger("MultiFix", "FramerateUncap", 1) != 0;
auto bAntiTrackStreamerCrash = iniReader.ReadInteger("MultiFix", "AntiTrackStreamerCrash", 1) != 0;
auto bAntiFEScriptCrash = (iniReader.ReadInteger("MultiFix", "AntiFEScriptCrash", 1) != 0);
auto bDisableAchievements = iniReader.ReadInteger("MultiFix", "DisableAchievements", 1) != 0;
//auto bDisableMassiveAds = iniReader.ReadInteger("MultiFix", "DisableMassiveAds", 1) != 0;
auto bDisableBoosterPackThanks = iniReader.ReadInteger("MultiFix", "DisableBoosterPackThanks", 1) != 0;
auto bDisablePunkBuster = iniReader.ReadInteger("MultiFix", "DisablePunkBuster", 1) != 0;
auto bDamageMemoryLeakFix = iniReader.ReadInteger("MultiFix", "DamageMemoryLeakFix", 1) != 0;
bool bWin11LANFix = iniReader.ReadInteger("MultiFix", "Win11LANFix", 1) != 0;
if (!bShowConsole)
FreeConsole();
if (bResDetect)
{
struct ScreenRes
{
uint32_t ResX;
uint32_t ResY;
};
std::vector<std::string> list;
GetResolutionsList(list);
static std::vector<ScreenRes> list2;
for (auto s : list)
{
ScreenRes r;
sscanf_s(s.c_str(), "%dx%d", &r.ResX, &r.ResY);
list2.emplace_back(r);
}
auto pattern = hook::pattern("83 C0 08 83 F8 58 72 E8 E9 ? ? ? ? 8B 53 3C 8B 43 10"); //0x70B3F0
injector::WriteMemory(pattern.get_first(-0x6), &list2[0].ResX, true); //0x70B3EA
injector::WriteMemory(pattern.get_first(-0xE), &list2[0].ResY, true); //0x70B3E2
injector::WriteMemory<uint8_t>(pattern.get_first(0x5), 0xFFi8, true); //0x70B3F5
}
if (bAntiTrackStreamerCrash)
{
auto pattern = hook::pattern("80 7C 24 ? ? 74 10 68 ? ? ? ? 55");
injector::MakeJMP(pattern.get_first(0), pattern.get_first(23), true); //0x00748A09, 0x748A20
pattern = hook::pattern("75 11 01 6C 24 1C 83 43 28 01");
injector::MakeNOP(pattern.get_first(0), 2, true); //0x007489FD
}
if (bAntiFEScriptCrash)
{
auto pattern = hook::pattern("57 8B 7C 24 08 85 FF 74 2C 8B 44 24 0C 56");
injector::MakeJMP(pattern.get_first(0), FEScriptMemoryCheck, true); //0x58DC10
FEScriptFixExit = (uint32_t)hook::get_pattern("85 FF 74 2C 8B 44 24 0C 56 50 8B CF", 0); //0x0058DC15
}
if (bDisablePunkBuster)
{
uintptr_t loc_704667 = reinterpret_cast<uintptr_t>(hook::pattern("83 B9 80 03 00 00 00").get_first(0)) - 0x36;
injector::MakeRET(loc_704667, 0, true);
}
if (bDamageMemoryLeakFix)
DamageFix::Init();
// this "multifix" portion is only for v1.1 (and newer?)! checking version number here (addresses: v1.0 = 0x6B95E6, v1.1 = 0x6CC3A6)
uintptr_t VersionLoc = reinterpret_cast<uintptr_t>(hook::pattern("6A ? 6A ? 8D 4C 24 18 68 ? ? ? ? 51").get_first(0));
uint8_t MinorVer = *(uint8_t*)(VersionLoc + 1);
uint8_t MajorVer = *(uint8_t*)(VersionLoc + 3);
if ((MajorVer >= 1) && (MinorVer >= 1))
{
if (bDisableAchievements)
{
uintptr_t loc_7B3A90 = reinterpret_cast<uintptr_t>(hook::pattern("A1 ? ? ? ? C3 CC CC CC CC CC CC CC CC CC CC 53 56 57 8B D9").get_first(0));
uintptr_t loc_7C2607 = reinterpret_cast<uintptr_t>(hook::pattern("8B F1 80 7E 20 00 75 05").get_first(0)) - 0x1B;
uintptr_t loc_691F20 = reinterpret_cast<uintptr_t>(hook::pattern("8B F9 33 ED 80 3D ? ? ? ? 00 74 30").get_first(0)) - 0x27;
injector::MakeJMP(loc_7B3A90, RetZero, true); // AchievementManager::Get
injector::MakeJMP(loc_7C2607, UpdateAchievements_Hook, true); // AchievementManager::UpdateAchievements
injector::MakeRET(loc_691F20, 4, true); // GProStreetAchievments::Check
}
// PostRaceStateManagerFix
if (bPostRaceFix)
{
uintptr_t loc_5A783C = reinterpret_cast<uintptr_t>(hook::pattern("75 07 C6 86 C5 00 00 00 01").get_first(0));
uintptr_t loc_5A7845 = loc_5A783C + 9;
uintptr_t loc_5A788A = loc_5A783C + 0x4E;
uintptr_t vTable = reinterpret_cast<uintptr_t>(hook::pattern("6A 2C C6 44 24 1C 01 C7 06 ? ? ? ?").get_first(0)) + 9;
uintptr_t vTableLoc = *reinterpret_cast<uintptr_t*>(vTable) + 0x128;
uintptr_t vTableOnline = reinterpret_cast<uintptr_t>(hook::pattern("C7 86 CC 00 00 00 ? ? ? ? C7 06 ? ? ? ? C7 86 CC 00 00 00 ? ? ? ? C7 86 D0 00 00").get_first(0)) + 0xC;
uintptr_t vTableOnlineLoc = *reinterpret_cast<uintptr_t*>(vTableOnline) + 0x128;
SinglePlayerPostRaceStateManager_HandleScreenConstructed = *reinterpret_cast<uintptr_t*>(vTableLoc);
OnlinePostRaceStateManager_HandleScreenConstructed = *reinterpret_cast<uintptr_t*>(vTableOnlineLoc);
// skip shadow & stat uploading to avoid memory leaks
injector::MakeNOP(loc_5A783C, 2, true);
injector::MakeJMP(loc_5A7845, loc_5A788A, true);
// fix FEPostRaceStateManager::mbScreenConstructed from not being set after the screen's constructed
injector::WriteMemory<uintptr_t>(vTableLoc, reinterpret_cast<uintptr_t>(&SinglePlayerPostRaceStateManager_HandleScreenConstructed_Hook), true);
injector::WriteMemory<uintptr_t>(vTableOnlineLoc, reinterpret_cast<uintptr_t>(&OnlinePostRaceStateManager_HandleScreenConstructed_Hook), true);
}
if (bFramerateUncap) // Framerate unlock
{
auto pattern = hook::pattern("83 3D ? ? ? ? ? 75 05 E8 ? ? ? ? 8B 0D ? ? ? ? 85 C9 74 0F 6A 09");
if (!pattern.empty())
injector::MakeJMP(pattern.get_first(0), pattern.get_first(14), true); //0x004B42FA, 0x4B4308
}
// causes the game randomly not to launch so not a good idea to disable
//if (bDisableMassiveAds)
//{
// injector::MakeRET(0x007BE4F0, 0, true); // DynamicAds
// injector::MakeJMP(0x70E515, 0x70E541, true); // MassiveAds
// injector::MakeJMP(0x004B03B5, 0x4B03D3, true);
// injector::MakeJMP(0x698D28, 0x698D50, true);
// injector::MakeJMP(0x006FA940, 0x6D8A30, true);
// injector::MakeRET(0x007B6510, 0, true);
//}
if (bDisableBoosterPackThanks)
{
uintptr_t loc_7E2380 = reinterpret_cast<uintptr_t>(hook::pattern("50 8B F1 68 E6 2E 00 00").get_first(0)) - 0xC;
uintptr_t loc_7E2382 = loc_7E2380 + 2;
uintptr_t loc_7E23A3 = loc_7E2380 + 0x23;
uintptr_t loc_7E23A5 = loc_7E2380 + 0x25;
injector::MakeJMP(loc_7E2382, loc_7E23A3, true);
injector::MakeNOP(loc_7E23A5, 4, true);
}
if (bWin11LANFix)
{
LANFix::ptrDataConnection = reinterpret_cast<uintptr_t>(hook::pattern("83 EC 20 33 C0 56 6A 11 6A 02 89 44 24 10").get_first(0));
uintptr_t loc_82719A = LANFix::ptrDataConnection + 0xA;
uintptr_t loc_8271A6 = LANFix::ptrDataConnection + 0x16;
uintptr_t loc_8271A9 = LANFix::ptrDataConnection + 0x19;
uintptr_t loc_8271D1 = LANFix::ptrDataConnection + 0x41;
uintptr_t loc_823C54 = reinterpret_cast<uintptr_t>(hook::pattern("C7 44 24 1C FF FF FF FF 89 46 04 E8 ? ? ? ? 84 C0 0F 84").get_first(0)) + 0xB;
struct LANFixHook1
{
void operator()(injector::reg_pack& regs)
{
*(uint32_t*)(regs.esp + 0x10) = LANFix::AddrFamily;
regs.eax = LANFix::AddrFamily;
}
}; injector::MakeInline<LANFixHook1>(loc_82719A, loc_8271A6);
struct LANFixHook2
{
void operator()(injector::reg_pack& regs)
{
*(uint32_t*)(regs.esp + 0x10) = 0;
*(uint32_t*)(regs.esp + 0x20) = 0;
*(uint32_t*)(regs.esp + 0x24) = 0;
*(uint32_t*)(regs.esp + 0x28) = 0;
*(uint32_t*)(regs.esp + 0x2C) = 0;
*(uint32_t*)(regs.esp + 0x18) = 2;
*(uint32_t*)(regs.esp + 0x1C) = 17;
}
}; injector::MakeInline<LANFixHook2>(loc_8271A9, loc_8271D1);
injector::MakeCALL(loc_823C54, LANFix::DataConnectionHook);
}
}
bool bFixAspectRatio = iniReader.ReadInteger("MAIN", "FixAspectRatio", 1) != 0;
static int32_t nScaling = iniReader.ReadInteger("MAIN", "Scaling", 1);
bool bFMVWidescreenMode = iniReader.ReadInteger("MAIN", "FMVWidescreenMode", 1) != 0;
FEScale::fFEScale = iniReader.ReadFloat("MAIN", "FEScale", 1.0f);
FEScale::fCalcFEScale = FEScale::fFEScale;
FEScale::fFMVScale = iniReader.ReadFloat("MAIN", "FMVScale", 1.0f);
FEScale::fCalcFMVScale = FEScale::fFMVScale;
static bool bAutoFitFE = iniReader.ReadInteger("MAIN", "AutoFitFE", 1) != 0;
static bool bAutoFitFMV = iniReader.ReadInteger("MAIN", "AutoFitFMV", 1) != 0;
static int ForceFEMode = iniReader.ReadInteger("MAIN", "ForceFEMode", 0);
bool bGammaFix = iniReader.ReadInteger("MISC", "GammaFix", 1) != 0;
bool bSkipIntro = iniReader.ReadInteger("MISC", "SkipIntro", 0) != 0;
bool bSkipFEBootflow = iniReader.ReadInteger("MISC", "SkipFEBootflow", 0) != 0;
static int32_t nWindowedMode = iniReader.ReadInteger("MISC", "WindowedMode", 0);
//static int32_t nImproveGamepadSupport = iniReader.ReadInteger("MISC", "ImproveGamepadSupport", 0);
static float fLeftStickDeadzone = iniReader.ReadFloat("MISC", "LeftStickDeadzone", 10.0f);
bool bWriteSettingsToFile = iniReader.ReadInteger("MISC", "WriteSettingsToFile", 0) != 0;
bool bDisableMotionBlur = iniReader.ReadInteger("MISC", "DisableMotionBlur", 0) != 0;
bool bFixXenonEffects = iniReader.ReadInteger("MISC", "FixXenonEffects", 1) != 0;
bool bBrakeLightFix = iniReader.ReadInteger("MISC", "BrakeLightFix", 1) != 0;
static int32_t nShadowRes = iniReader.ReadInteger("MISC", "ShadowRes", 2048);
static auto szCustomUserFilesDirectoryInGameDir = iniReader.ReadString("MISC", "CustomUserFilesDirectoryInGameDir", "0");
static std::filesystem::path CustomUserDir;
if (szCustomUserFilesDirectoryInGameDir.empty() || szCustomUserFilesDirectoryInGameDir == "0")
szCustomUserFilesDirectoryInGameDir.clear();
static int SimRate = iniReader.ReadInteger("MISC", "SimRate", -1);
if (bFixAspectRatio)
{
// Real-Time Aspect Ratio Calculation
static uint32_t* dword_BBADB4 = *hook::pattern("C7 05 ? ? ? ? 03 00 00 00 89 3D ? ? ? ? 89 3D").get(0).get<uint32_t*>(35); // ResX
static uint32_t* dword_BBADB8 = *hook::pattern("C7 05 ? ? ? ? 03 00 00 00 89 3D ? ? ? ? 89 3D").get(0).get<uint32_t*>(41); // ResY
static float fScreenAspectRatio;
auto pattern = hook::pattern("F3 0F 10 05 ? ? ? ? F3 0F 11 04 24 D9 04 24 83 C4 0C");
struct AspectRatioHook
{
void operator()(injector::reg_pack& regs)
{
auto ResX = *(float*)(dword_BBADB4);
auto ResY = *(float*)(dword_BBADB8);
fScreenAspectRatio = (ResX / ResY) * 0.5625f;
auto f = regs.xmm0.f32[0];
_asm { fld dword ptr ds : [f] }
}
}; injector::MakeInline<AspectRatioHook>(pattern.get_first(8), pattern.get_first(16)); // 4BCB35
// Force 16:9 FOV, HUD & FMV Scaling
{
static float fRatio = 1.777777777f;
auto pattern = hook::pattern("A1 ? ? ? ? 83 EC 0C 80 B8 ? ? ? ? 00 ? ? B9 ? ? ? ? E8");
uint32_t* dword_4BCAEF = pattern.count(1).get(0).get<uint32_t>(15);
injector::WriteMemory<uint8_t>(dword_4BCAEF, 0xEB, true); // jmp
uint32_t* dword_4BCB39 = pattern.count(1).get(0).get<uint32_t>(89);
injector::WriteMemory(dword_4BCB39, &fRatio, true);
uint32_t* dword_6FF9E3 = hook::pattern("D9 C9 DF F1 DD D8 ? ? 0F B7 C3").count(1).get(0).get<uint32_t>(6);
injector::MakeNOP(dword_6FF9E3, 2, true); // 2 nops
uint32_t* dword_4B51EB = hook::pattern("74 ? 8B 16 8B 42 ? FF D0 5E 5B").count(1).get(0).get<uint32_t>(0);
injector::WriteMemory<uint8_t>(dword_4B51EB, 0xEB, true); // jmp
}
// FOV Width & Height
{
static float dword_9FA868, temp_xmm0;
auto pattern = hook::pattern("0F 57 C0 F3 0F 10 ? ? ? ? ? F3 0F 10 ? ? ? F3 0F 10 ? ? ? ? ? 8D 7E");
struct FOVHook
{
void operator()(injector::reg_pack& regs)
{
int ebp08 = *(int*)(regs.ebp + 0x08);
float esp48 = *(float*)(regs.esp + 0x48);
if (ebp08 <= 0x19) // jump if greater than
*(float*)(regs.esp + 0x48) = (esp48 / fScreenAspectRatio);
regs.xmm0.f64[0] = 0.0f;
regs.xmm0.f64[1] = 0.0f;
regs.xmm1.f32[0] = dword_9FA868;
}
}; injector::MakeInline<FOVHook>(pattern.get_first(0), pattern.get_first(11)); // 6FFB1A
if (nScaling)
{
static double XB360_Hor;
static double XB360_Ver;
if (nScaling == 1)
{
XB360_Hor = 1.26;
XB360_Ver = 1.50;
}
if (nScaling >= 2)
{
XB360_Hor = 1.30;
XB360_Ver = 1.48;
}
auto pattern = hook::pattern("DC 0D ? ? ? ? D9 5C 24 ? D9 44 24 ? DC 0D ? ? ? ? ? ? D9 44 24 ? DC 0D");
uint32_t* dword_6FFA12 = pattern.count(2).get(0).get<uint32_t>(2);
injector::WriteMemory(dword_6FFA12, &XB360_Hor, true);
uint32_t* dword_6FFA20 = pattern.count(2).get(0).get<uint32_t>(16);
injector::WriteMemory(dword_6FFA20, &XB360_Ver, true);
}
}
// HUD Width
{
static double dbl_HUDWidth = (4.0 / 3.0f);
auto pattern = hook::pattern("DC 3D ? ? ? ? D9 5C 24 0C F3 0F 10");
struct HUDWidthHook
{
void operator()(injector::reg_pack& regs)
{
_asm
{
fdivr qword ptr ds : [dbl_HUDWidth]
fdiv dword ptr ds : [fScreenAspectRatio]
}
}
}; injector::MakeInline<HUDWidthHook>(pattern.get_first(0), pattern.get_first(6)); // 4B44F6
}
// FMV Width & Height
{
static float Width1 = -0.75f;
static float Width2 = 0.75f;
static float Height1 = 0.75f;
static float Height2 = -0.75f;
static float FMVWidthLeft, FMVWidthRight;
if (bFMVWidescreenMode)
{
Width1 = -1.00f;
Width2 = 1.00f;
Height1 = 1.00f;
Height2 = -1.00f;
}
static float CalcWidth1 = Width1;
static float CalcWidth2 = Width2;
static float CalcHeight1 = Height1;
static float CalcHeight2 = Height2;
// Real-Time FMV Aspect Ratio Calculation
auto pattern = hook::pattern("80 BC 24 ? ? ? ? 00 DE F9 D9");
struct FMVHook
{
void operator()(injector::reg_pack& regs)
{
int espB0 = *(int*)(regs.esp + 0xB0);
CalcWidth1 = Width1 * FEScale::fCalcFMVScale;
CalcWidth2 = Width2 * FEScale::fCalcFMVScale;
CalcHeight1 = Height1 * FEScale::fCalcFMVScale;
CalcHeight2 = Height2 * FEScale::fCalcFMVScale;
FMVWidthLeft = CalcWidth1 / fScreenAspectRatio;
FMVWidthRight = CalcWidth2 / fScreenAspectRatio;
_asm cmp byte ptr ds : [espB0] , 0x00;
}
}; injector::MakeInline<FMVHook>(pattern.get_first(0), pattern.get_first(8)); // 70235A
{
auto pattern = hook::pattern("F3 0F 10 ? ? ? ? ? F3 0F 10 ? ? ? ? ? 0F 57 C0 F3 0F 10");
uint32_t* dword_702224 = pattern.count(1).get(0).get<uint32_t>(4);
injector::WriteMemory(dword_702224, &CalcHeight1, true);
uint32_t* dword_70222C = pattern.count(1).get(0).get<uint32_t>(12);
injector::WriteMemory(dword_70222C, &FMVWidthLeft, true);
uint32_t* dword_702237 = pattern.count(1).get(0).get<uint32_t>(23);
injector::WriteMemory(dword_702237, &FMVWidthRight, true);
uint32_t* dword_702261 = pattern.count(1).get(0).get<uint32_t>(65);
injector::WriteMemory(dword_702261, &CalcHeight2, true);
}
}
// Crowd Culling Fix
{
static float CrowdCullDist;
auto pattern = hook::pattern("F3 0F 10 05 ? ? ? ? F3 0F 11 44 24 7C ? ? ? ? ? ? 2B C3 83 E8 01");
struct CrowdCullHook
{
void operator()(injector::reg_pack& regs)
{
CrowdCullDist = (0.6f / fScreenAspectRatio);
*(float*)(regs.esp + 0x7C) = CrowdCullDist;
}
}; injector::MakeInline<CrowdCullHook>(pattern.get_first(0), pattern.get_first(8)); // 76CECB
}
}
// Real-Time Aspect Ratio Calculation
static uint32_t* dword_BBADB4 = *hook::pattern("C7 05 ? ? ? ? 03 00 00 00 89 3D ? ? ? ? 89 3D").get(0).get<uint32_t*>(35); // ResX
static uint32_t* dword_BBADB8 = *hook::pattern("C7 05 ? ? ? ? 03 00 00 00 89 3D ? ? ? ? 89 3D").get(0).get<uint32_t*>(41); // ResY
// the game normally checks against 1.34, but this breaks 16:10 aspect ratios
// 1.5555555 is halfway between 4:3 and 16:9
static float WidescreenCheckThreshold = 1.5555555f;
if (ForceFEMode >= 2)
WidescreenCheckThreshold = +INFINITY;
if (ForceFEMode == 1)
WidescreenCheckThreshold = -INFINITY;
pattern = hook::pattern("0F B6 C0 89 01 B0 01");
struct HUDWidescreenModeHook
{
void operator()(injector::reg_pack& regs)
{
auto ResX = *(float*)(dword_BBADB4);
auto ResY = *(float*)(dword_BBADB8);
float fScreenAspectRatio = (ResX / ResY);
FEScale::fCalcFEScale = FEScale::fFEScale;
FEScale::fCalcFMVScale = FEScale::fFMVScale;
if ((fScreenAspectRatio >= WidescreenCheckThreshold))
{
if (bAutoFitFE)
FEScale::fCalcFEScale *= fScreenAspectRatio / (16.0f / 9.0f);
if (bAutoFitFMV)
FEScale::fCalcFMVScale *= fScreenAspectRatio / (16.0f / 9.0f);
regs.eax = (int)1;
*(int*)(regs.ecx) = regs.eax;
}
else
{
if (bAutoFitFE)
FEScale::fCalcFEScale *= fScreenAspectRatio / (4.0f / 3.0f);
if (bAutoFitFMV)
FEScale::fCalcFMVScale *= fScreenAspectRatio / (4.0f / 3.0f);
regs.eax = (int)0;
*(int*)(regs.ecx) = regs.eax;
}
if (FEScale::fCalcFEScale > FEScale::fFEScale)
FEScale::fCalcFEScale = FEScale::fFEScale;
if (FEScale::fCalcFMVScale > FEScale::fFMVScale)
FEScale::fCalcFMVScale = FEScale::fFMVScale;
FEScale::UpdateXtendedInput();
}
}; injector::MakeInline<HUDWidescreenModeHook>(pattern.count(7).get(0).get<uint32_t>(0)); // 44C332
// this sets the actual value used to check the aspect ratio, but will cause stuff to stretch if forced in one way or the other
//uintptr_t loc_6F9545 = reinterpret_cast<uintptr_t>(hook::pattern("D9 05 ? ? ? ? D9 C9 DF F1 DD D8 76 ? B8 01 00 00 00").get_first(0));
//injector::WriteMemory<float*>(loc_6F9545 + 2, &WidescreenCheckThreshold, true);
static bool bMovieFlag = false;
uintptr_t loc_4B4518 = reinterpret_cast<uintptr_t>(hook::pattern("F3 0F 11 44 24 14 F3 0F 10 05 ? ? ? ? 6A 00").get_first(0)) + 6;
struct FEScaleHook
{
void operator()(injector::reg_pack& regs)
{
float Xscale = FEScale::fCalcFEScale;
float Yscale = FEScale::fCalcFEScale;
if (bMovieFlag)
{
Xscale = FEScale::fCalcFMVScale;
Yscale = FEScale::fCalcFMVScale;
}
*(float*)(regs.esp + 0x14) *= Xscale;
regs.xmm0.f32[0] = Yscale;
}
}; injector::MakeInline<FEScaleHook>(loc_4B4518, loc_4B4518 + 8);
uintptr_t loc_5CE7DA = reinterpret_cast<uintptr_t>(hook::pattern("8D 94 24 7C 01 00 00 55").get_first(0));
static uintptr_t sub_4B4430 = reinterpret_cast<uintptr_t>(hook::pattern("8D 4C 24 18 51 68 89 13 00 00").get_first(0)) - 0x9E;
struct FEMovieStarterCallbackHook
{
void operator()(injector::reg_pack& regs)
{
// ignore FE_BG (splash screen) movie
std::string filename = (char*)(regs.esp + 0x13C);
if ((filename.find("FE_BG") == std::string::npos) && !bMovieFlag)
{
bMovieFlag = true;
// trigger the FE transform before the movie player locks it!
// this calls render functions inside the main thread, so if things become unstable when movies play, this could be the reason!
// calling render stuff in non-render threads is unsafe
// it's only math stuff though, so it shouldn't be unstable
reinterpret_cast<void(*)()>(sub_4B4430)();
}
regs.edx = regs.esp + 0x17C;
}
}; injector::MakeInline<FEMovieStarterCallbackHook>(loc_5CE7DA, loc_5CE7DA + 0x7);
uintptr_t loc_59AD04 = reinterpret_cast<uintptr_t>(hook::pattern("C7 05 ? ? ? ? 01 00 00 00 A1 ? ? ? ? 85 C0 0F 84 ? ? ? ? 8B 35").get_first(0));
static uintptr_t ptr_movieshuttingdown = *reinterpret_cast<uintptr_t*>(loc_59AD04 + 2);
struct MoviePlayerShutdownHook
{
void operator()(injector::reg_pack& regs)
{
bMovieFlag = false;
*(uint32_t*)ptr_movieshuttingdown = 1;
}
}; injector::MakeInline<MoviePlayerShutdownHook>(loc_59AD04, loc_59AD04 + 0xA);
if (bGammaFix)
{
static uint32_t* dword_AC6F0C; // Gamma Integer
if (bCheckDemoVersion())
dword_AC6F0C = *hook::pattern("A1 ? ? ? ? 8B 4C 24 04 8B D0 83 C2 04 B8 CD CC CC CC").get(0).get<uint32_t*>(1);
else
dword_AC6F0C = *hook::pattern("A1 ? ? ? ? 8B 4C 24 04 8B D0 B8 67 66 66 66").get(0).get<uint32_t*>(1);
static uint32_t* dword_AA9630 = *hook::pattern("F3 0F 11 44 24 04 D8 64 24 04 C6 ? 01 D9 5C").get(0).get<uint32_t*>(29); // Gamma Float
injector::WriteMemory(dword_AA9630, 1.0f, true); // sets default brightness to 50%
static float NewBrightness;
auto pattern = hook::pattern("55 8B EC 83 E4 F8 83 EC 10 ? ? ? ? ? ? ? ? 56 57 33 FF");
struct GammaHook
{
void operator()(injector::reg_pack& regs)
{
auto GammaInteger = *(int*)(dword_AC6F0C);
auto GammaFloat = *(float*)(dword_AA9630);
NewBrightness = 100.0f / (GammaInteger * 2.0f);
GammaFloat = NewBrightness;
regs.xmm0.f32[0] = GammaFloat;
}
}; injector::MakeInline<GammaHook>(pattern.count(1).get(0).get<uint32_t>(9), pattern.count(1).get(0).get<uint32_t>(17)); // 4B3E89
}
if (bSkipIntro)
{
// EA Bumper
uint32_t* dword_6FC24A = hook::pattern("68 ? ? ? ? 6A ? FF D2 D9 EE").count(1).get(0).get<uint32_t>(1);