-
-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathdllmain.cpp
1465 lines (1248 loc) · 61.6 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>
struct Screen
{
int32_t Width;
int32_t Height;
int32_t Width43;
float fWidth;
float fHeight;
float fAspectRatio;
float fHudScaleX;
float fHudPosX;
} Screen;
struct bVector3
{
float x;
float y;
float z;
float pad;
};
struct bVector4
{
float x;
float y;
float z;
float w;
};
struct bMatrix4
{
bVector4 v0;
bVector4 v1;
bVector4 v2;
bVector4 v3;
};
bool bIsResizing = false;
bool bHUDWidescreenMode = true;
bool bFixHUD = true;
bool bFixFOV = true;
int nScaling = 1;
static float hor3DScale = 4.0f / 3.0f;
static float fRainScaleX = ((0.75f) * (4.0f / 3.0f));
float* HudScaleX_8AF9A4 = (float*)0x8AF9A4;
float* FE_Xpos_894B40 = (float*)0x894B40;
float* AutosculptScale_8AE8F8 = (float*)0x8AE8F8;
float* ArrestBlurScale_8AFA08 = (float*)0x8AFA08;
bool* DrawHUD_57CAA8 = (bool*)0x57CAA8;
namespace ShadowRes
{
constexpr uint32_t ShadowDepthCheckRes = 3072;
// 0 = D24S8 (Shadow Map)
// 1 = INTZ (Depth Buffer as Texture)
// 2 = DF16 (Depth Buffer as Texture, Radeon Only)
// 3 = DF24 (Depth Buffer as Texture, Radeon Only)
uint32_t ShadowMapTexFormats[] = {75, 0x5A544E49, 0x36314644, 0x34324644};
int CurrentTexFormat = 0;
bool bForceSharpShadows = false;
uint32_t Resolution = 2048;
bool bAutoScaleShadowsRes = true;
// X resolution ptrs
uintptr_t dword_6C86B1;
uint32_t dword_6C878B;
uint32_t dword_6C87BD;
uintptr_t dword_6C87F4;
// Y resolution ptrs
uintptr_t dword_6C86C1;
uint32_t* dword_6C8786;
uint32_t* dword_6C87B8;
uintptr_t dword_6C87EF;
uintptr_t DepthBiasAddr_901AC0 = 0x901AC0;
uintptr_t DepthBiasSlopeAddr_901ABC = 0x901ABC;
float DepthBias = 4.0f;
float DepthBiasSlope = 4.0f;
void update(uint32_t res)
{
uint32_t resval = res;
if (resval > 16384)
resval = 16384;
uint32_t resX = resval;
if (bAutoScaleShadowsRes)
{
float newShadowX = resval * (Screen.fAspectRatio / (4.0f / 3.0f));
resX = static_cast<uint32_t>(newShadowX);
}
uint32_t resY = resval;
if (resX > 16384)
resX = 16384;
*(uint32_t*)dword_6C86B1 = resX;
*(uint32_t*)dword_6C878B = resX;
*(uint32_t*)dword_6C87BD = resX;
*(uint32_t*)dword_6C87F4 = resX;
*(uint32_t*)dword_6C86C1 = resY;
*(uint32_t*)dword_6C8786 = resY;
*(uint32_t*)dword_6C87B8 = resY;
*(uint32_t*)dword_6C87EF = resY;
if (resX > resval)
resval = resX;
if ((CurrentTexFormat > 0) && !bForceSharpShadows)
{
DepthBias = *(int32_t*)DepthBiasAddr_901AC0 * (static_cast<float>(resval) / 1024.0f);
DepthBiasSlope = *(float*)DepthBiasSlopeAddr_901ABC * (static_cast<float>(resval) / 1024.0f);
}
else if (resval > ShadowDepthCheckRes)
{
DepthBias = *(int32_t*)DepthBiasAddr_901AC0 * (static_cast<float>(resval) / static_cast<float>(ShadowDepthCheckRes));
DepthBiasSlope = *(float*)DepthBiasSlopeAddr_901ABC * (static_cast<float>(resval) / static_cast<float>(ShadowDepthCheckRes));
}
}
}
namespace XtendedInput
{
HMODULE mhXtendedInput;
float(__cdecl* SetFEScale)(float val);
bool(__cdecl* GetUseWin32Cursor)();
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"));
bFoundXInput = (SetFEScale != nullptr) && (GetUseWin32Cursor != nullptr);
}
}
}
}
namespace FEScale
{
float fFEScale = 1.0f;
float fCalcFEScale = 1.0f;
float fFMVScale = 1.0f;
float fCalcFMVScale = 1.0f;
bool bEnabled = false;
bool bAutoFitFE = true;
bool bAutoFitFMV = true;
uintptr_t SetTransformAddr = 0x6C8000;
uintptr_t gMoviePlayerAddr = 0x91CB10;
void __cdecl SetTransformHook(D3DMATRIX* mat, uint32_t EVIEW_ID)
{
D3DMATRIX cMat;
memcpy(&cMat, mat, sizeof(D3DMATRIX));
if (*(uintptr_t*)gMoviePlayerAddr)
{
cMat._11 *= fCalcFMVScale;
cMat._22 *= fCalcFMVScale;
}
else
{
cMat._11 *= fCalcFEScale;
cMat._22 *= fCalcFEScale;
}
return reinterpret_cast<void(__cdecl*)(D3DMATRIX*, uint32_t)>(SetTransformAddr)(&cMat, EVIEW_ID);
}
void Update()
{
fCalcFEScale = fFEScale;
fCalcFMVScale = fFMVScale;
if (bHUDWidescreenMode)
{
if (bAutoFitFE)
fCalcFEScale *= Screen.fAspectRatio / (16.0f / 9.0f);
if (bAutoFitFMV)
fCalcFMVScale *= Screen.fAspectRatio / (16.0f / 9.0f);
}
else
{
if (bAutoFitFE)
fCalcFEScale *= Screen.fAspectRatio / (4.0f / 3.0f);
if (bAutoFitFMV)
fCalcFMVScale *= Screen.fAspectRatio / (4.0f / 3.0f);
}
if (fCalcFEScale > fFEScale)
fCalcFEScale = fFEScale;
if (fCalcFMVScale > fFMVScale)
fCalcFMVScale = fFMVScale;
if (!XtendedInput::bLookedForXInput)
XtendedInput::LookForXtendedInput();
if (!XtendedInput::bFoundXInput) return;
if (!XtendedInput::GetUseWin32Cursor()) return;
XtendedInput::SetFEScale(fCalcFEScale);
}
}
void updateValues(const float& newWidth, const float& newHeight)
{
//Screen resolution
Screen.Width = newWidth;
Screen.Height = newHeight;
// clamp the size because below 32x32 the game crashes!
if (Screen.Width < 32)
Screen.Width = 32;
if (Screen.Height < 32)
Screen.Height = 32;
Screen.fWidth = static_cast<float>(Screen.Width);
Screen.fHeight = static_cast<float>(Screen.Height);
Screen.fAspectRatio = (Screen.fWidth / Screen.fHeight);
Screen.Width43 = static_cast<int32_t>(Screen.fHeight * (4.0f / 3.0f));
Screen.fHudScaleX = (1.0f / Screen.fWidth * (Screen.fHeight / 480.0f)) * 2.0f;
Screen.fHudPosX = 640.0f / (640.0f * Screen.fHudScaleX);
//Autosculpt scaling
*AutosculptScale_8AE8F8 = 480.0f * Screen.fAspectRatio;
//Arrest blur
*ArrestBlurScale_8AFA08 = (1.0f / 640.0f) * ((4.0f / 3.0f) / Screen.fAspectRatio);
//Rain droplets
fRainScaleX = ((0.75f / Screen.fAspectRatio) * (4.0f / 3.0f));
if (bFixFOV)
{
hor3DScale = 1.0f / (Screen.fAspectRatio / (4.0f / 3.0f));
if (nScaling)
hor3DScale /= 1.047485948f;
}
if (bFixHUD)
{
*HudScaleX_8AF9A4 = Screen.fHudScaleX;
*FE_Xpos_894B40 = Screen.fHudPosX;
}
if (ShadowRes::Resolution)
ShadowRes::update(ShadowRes::Resolution);
if (FEScale::bEnabled)
FEScale::Update();
}
void __stdcall RacingResolution_Hook(int *width, int *height)
{
*width = Screen.Width;
*height = Screen.Height;
}
// cave at 0x6E726B - in eDisplayFrame
// for skipping shader recompilation
uint32_t FastWndReset_Exit_True = 0x6E728D;
uint32_t FastWndReset_Exit_False = 0x6E7272;
uint32_t* ResetWnd_982C39 = (uint32_t*)0x00982C39;
void __declspec(naked) FastWndReset_Cave()
{
if (bIsResizing)
_asm jmp FastWndReset_Exit_True
_asm
{
mov eax, ResetWnd_982C39
mov al, byte ptr [eax]
test al, al
jmp FastWndReset_Exit_False
}
}
// cave at 0x6E72C6 - in eDisplayFrame
// at the end of the reset procedure
uint32_t FastWndReset_Finish_Exit = 0x006E72CD;
void __declspec(naked) FastWndReset_Finish_Cave()
{
bIsResizing = false;
*DrawHUD_57CAA8 = true;
_asm
{
mov eax, ResetWnd_982C39
mov [eax], 0
jmp FastWndReset_Finish_Exit
}
}
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_SIZE:
{
bIsResizing = true;
*DrawHUD_57CAA8 = false;
updateValues((float)LOWORD(lParam), (float)HIWORD(lParam));
}
return TRUE;
}
return GameWndProc(hWnd, msg, wParam, lParam);
}
#pragma runtime_checks( "", off )
namespace NOSTrailFix
{
float NOSTrailScalar = 2.0f;
float NOSTrailPositionScalar = 0.3f;
bMatrix4 carbody_nos;
uintptr_t CarRenderInfo_RenderFlaresOnCar_Addr = 0x00742950;
void __stdcall CarRenderInfo_RenderFlaresOnCar_Hook(void* eView, bVector3* position, bMatrix4* body_matrix, int unk1, int unk2, int unk3)
{
void* thethis = 0;
_asm mov thethis, ecx
memcpy(&carbody_nos, body_matrix, sizeof(bMatrix4));
float pos_scale = (NOSTrailScalar * NOSTrailPositionScalar);
if (pos_scale < 1.0f)
pos_scale = 1.0f;
carbody_nos.v0.x *= pos_scale;
carbody_nos.v0.y *= pos_scale;
carbody_nos.v0.z *= pos_scale;
carbody_nos.v2.x *= pos_scale;
carbody_nos.v2.y *= pos_scale;
return reinterpret_cast<void(__thiscall*)(void*, void*, bVector3*, bMatrix4*, int, int, int)>(CarRenderInfo_RenderFlaresOnCar_Addr)(thethis, eView, position, &carbody_nos, unk1, unk2, unk3);
}
bVector3* WorldPos1;
bVector3* WorldPos2;
bVector3* NOSFlarePos;
uintptr_t NOSTrailCave2Exit = 0x745040;
void __declspec(naked) NOSTrailCave2()
{
_asm
{
mov WorldPos1, edx
mov WorldPos2, esi
lea edx, [esp + 0x30]
mov NOSFlarePos, edx
}
(*NOSFlarePos).x = ((*WorldPos1).x - (*WorldPos2).x) * NOSTrailScalar;
(*NOSFlarePos).y = ((*WorldPos1).y - (*WorldPos2).y) * NOSTrailScalar;
(*NOSFlarePos).z = ((*WorldPos1).z - (*WorldPos2).z) * NOSTrailScalar;
_asm
{
xor eax, eax
jmp NOSTrailCave2Exit
}
}
}
#pragma runtime_checks( "", restore )
uintptr_t PostStartFunc = 0x739600;
void InitPostStart()
{
if (FEScale::bEnabled)
FEScale::Update();
return reinterpret_cast<void(*)()>(PostStartFunc)();
}
void Init()
{
CIniReader iniReader("");
Screen.Width = iniReader.ReadInteger("MAIN", "ResX", 0);
Screen.Height = iniReader.ReadInteger("MAIN", "ResY", 0);
bFixHUD = iniReader.ReadInteger("MAIN", "FixHUD", 1) != 0;
bFixFOV = iniReader.ReadInteger("MAIN", "FixFOV", 1) != 0;
bHUDWidescreenMode = iniReader.ReadInteger("MAIN", "HUDWidescreenMode", 1) == 1;
int nFMVWidescreenMode = iniReader.ReadInteger("MAIN", "FMVWidescreenMode", 1);
FEScale::fFEScale = iniReader.ReadFloat("MAIN", "FEScale", 1.0f);
FEScale::fCalcFEScale = FEScale::fFEScale;
FEScale::fFMVScale = iniReader.ReadFloat("MAIN", "FMVScale", 1.0f);
FEScale::fCalcFMVScale = FEScale::fFMVScale;
FEScale::bAutoFitFE = iniReader.ReadInteger("MAIN", "AutoFitFE", 1) != 0;
FEScale::bAutoFitFMV = iniReader.ReadInteger("MAIN", "AutoFitFMV", 1) != 0;
nScaling = iniReader.ReadInteger("MAIN", "Scaling", 1);
bool bSkipIntro = iniReader.ReadInteger("MISC", "SkipIntro", 0) != 0;
bool bFixResolutionText = iniReader.ReadInteger("MISC", "FixResolutionText", 1) != 0;
static auto szCustomUserFilesDirectoryInGameDir = iniReader.ReadString("MISC", "CustomUserFilesDirectoryInGameDir", "");
static std::filesystem::path CustomUserDir;
if (szCustomUserFilesDirectoryInGameDir.empty() || szCustomUserFilesDirectoryInGameDir == "0")
szCustomUserFilesDirectoryInGameDir.clear();
bool bWriteSettingsToFile = iniReader.ReadInteger("MISC", "WriteSettingsToFile", 1) != 0;
static int nImproveGamepadSupport = iniReader.ReadInteger("MISC", "ImproveGamepadSupport", 0);
bool bForceHighSpecAudio = iniReader.ReadInteger("MISC", "ForceHighSpecAudio", 1) != 0;
static float fLeftStickDeadzone = iniReader.ReadFloat("MISC", "LeftStickDeadzone", 10.0f);
static int SimRate = iniReader.ReadInteger("MISC", "SimRate", -1);
int nWindowedMode = iniReader.ReadInteger("MISC", "WindowedMode", 0);
ShadowRes::Resolution = iniReader.ReadInteger("GRAPHICS", "ShadowsRes", 2048);
ShadowRes::bAutoScaleShadowsRes = iniReader.ReadInteger("GRAPHICS", "AutoScaleShadowsRes", 1) != 0;
ShadowRes::CurrentTexFormat = iniReader.ReadInteger("GRAPHICS", "ShadowMapTextureFormat", 0);
ShadowRes::bForceSharpShadows = iniReader.ReadInteger("GRAPHICS", "ForceSharpShadows", 0) != 0;
static float fRainDropletsScale = iniReader.ReadFloat("GRAPHICS", "RainDropletsScale", 0.5f);
bool bShadowsFix = iniReader.ReadInteger("GRAPHICS", "ShadowsFix", 1) != 0;
bool bImproveShadowLOD = iniReader.ReadInteger("GRAPHICS", "ImproveShadowLOD", 1) != 0;
bool bDisableMotionBlur = iniReader.ReadInteger("GRAPHICS", "DisableMotionBlur", 0) != 0;
bool bLightStreaksEnable = iniReader.ReadInteger("GRAPHICS", "LightStreaksEnable", 0) != 0;
bool bBleachByPassEnable = iniReader.ReadInteger("GRAPHICS", "BleachByPassEnable", 0) != 0;
static uint32_t ForcedGPUVendor = static_cast<uint32_t>(iniReader.ReadInteger("GRAPHICS", "ForcedGPUVendor", 0x10DE));
bool bFixNOSTrailLength = iniReader.ReadInteger("NOSTrail", "FixNOSTrailLength", 1) == 1;
bool bFixNOSTrailPosition = iniReader.ReadInteger("NOSTrail", "FixNOSTrailPosition", 0) != 0;
static float fCustomNOSTrailLength = iniReader.ReadFloat("NOSTrail", "CustomNOSTrailLength", 1.0f);
NOSTrailFix::NOSTrailPositionScalar = iniReader.ReadFloat("NOSTrail", "NOSTrailPositionScalar", 0.3f);
if (!Screen.Width || !Screen.Height)
std::tie(Screen.Width, Screen.Height) = GetDesktopRes();
// clamp the size because below 32x32 the game crashes!
if (Screen.Width < 32)
Screen.Width = 32;
if (Screen.Height < 32)
Screen.Height = 32;
Screen.fWidth = static_cast<float>(Screen.Width);
Screen.fHeight = static_cast<float>(Screen.Height);
Screen.fAspectRatio = (Screen.fWidth / Screen.fHeight);
Screen.Width43 = static_cast<int32_t>(Screen.fHeight * (4.0f / 3.0f));
Screen.fHudScaleX = (1.0f / Screen.fWidth * (Screen.fHeight / 480.0f)) * 2.0f;
Screen.fHudPosX = 640.0f / (640.0f * Screen.fHudScaleX);
// 08/2022. - keep memory areas unprotected to allow updating of values without constantly calling VirtualProtect ~ Xan
DWORD oldprotect = 0;
// Post-start init function hook
uintptr_t loc_66616E = reinterpret_cast<uintptr_t>(hook::pattern("68 89 88 88 3C E8 ? ? ? ? E8 ? ? ? ? 6A 00").get_first(0)) + 0x6F;
PostStartFunc = static_cast<uintptr_t>(injector::GetBranchDestination(loc_66616E));
injector::MakeCALL(loc_66616E, InitPostStart);
//Screen resolution
for (size_t i = 0; i < 2; i++)
{
uint32_t* sub_6C27D0 = hook::pattern("A1 ? ? ? ? 83 F8 05 0F ? ? 00 00 00 FF 24 85 ? ? ? ? 8B 44 24 04").count(1).get(0).get<uint32_t>(0);
injector::MakeJMP(sub_6C27D0, RacingResolution_Hook, true);
}
//Autosculpt scaling
AutosculptScale_8AE8F8 = *hook::pattern("D8 0D ? ? ? ? DA 74 24 18 E8 ? ? ? ? 89 46 04 EB 03").count(1).get(0).get<float*>(2);
injector::UnprotectMemory(AutosculptScale_8AE8F8, sizeof(float), oldprotect);
*AutosculptScale_8AE8F8 = 480.0f * Screen.fAspectRatio;
//Arrest blur
ArrestBlurScale_8AFA08 = *hook::pattern("D8 0D ? ? ? ? 8B 4C 24 18 8B 54 24 1C").count(1).get(0).get<float*>(2);
injector::UnprotectMemory(ArrestBlurScale_8AFA08, sizeof(float), oldprotect);
*ArrestBlurScale_8AFA08 = (1.0f / 640.0f) * ((4.0f / 3.0f) / Screen.fAspectRatio);
//Rain droplets
fRainScaleX = ((0.75f / Screen.fAspectRatio) * (4.0f / 3.0f));
auto pattern = hook::pattern("D9 44 24 0C D8 44 24 10 8B 4C 24 08 8B 44 24 10 8B D1");
struct RainDropletsHook
{
void operator()(injector::reg_pack& regs)
{
float esp0C = *(float*)(regs.esp + 0x0C);
float esp10 = *(float*)(regs.esp + 0x10);
_asm fld dword ptr[esp0C]
_asm fmul dword ptr[fRainScaleX]
_asm fmul dword ptr[fRainDropletsScale]
_asm fadd dword ptr[esp10]
}
}; injector::MakeInline<RainDropletsHook>(pattern.get_first(0), pattern.get_first(8)); //6D480D
struct RainDropletsYScaleHook
{
void operator()(injector::reg_pack& regs)
{
float esp08 = *(float*)(regs.esp + 0x08);
_asm fmul dword ptr[fRainDropletsScale]
_asm fadd dword ptr[esp08]
* (uintptr_t*)(regs.esp + 0x38) = regs.ecx;
}
}; injector::MakeInline<RainDropletsYScaleHook>(pattern.get_first(30), pattern.get_first(30 + 8)); //6D482B
if (ShadowRes::Resolution)
{
uintptr_t loc_6E5507 = reinterpret_cast<uintptr_t>(hook::pattern("52 68 C3 00 00 00 50 FF 91 E4 00 00 00").get_first(0)) + 0xD;
uintptr_t loc_6E54E1 = loc_6E5507 - 0x26;
ShadowRes::DepthBiasAddr_901AC0 = *(uintptr_t*)(loc_6E54E1 + 2);
ShadowRes::DepthBiasSlopeAddr_901ABC = *(uintptr_t*)(loc_6E5507 + 2);
struct ShadowDepthBiasHook
{
void operator()(injector::reg_pack& regs)
{
_asm fld ShadowRes::DepthBias
}
}; injector::MakeInline<ShadowDepthBiasHook>(loc_6E54E1, loc_6E54E1 + 6);
struct ShadowDepthBiasSlopeHook
{
void operator()(injector::reg_pack& regs)
{
regs.edx = *(uint32_t*)(&ShadowRes::DepthBiasSlope);
}
}; injector::MakeInline<ShadowDepthBiasSlopeHook>(loc_6E5507, loc_6E5507 + 6);
uintptr_t loc_6BD32B = reinterpret_cast<uintptr_t>(hook::pattern("89 56 08 89 46 0C C7 46 04 0F 00 00 00 89 7E 10 E8").get_first(0)) + 0x10;
uintptr_t loc_6BD333 = loc_6BD32B + 8;
ShadowRes::dword_6C86B1 = static_cast<uintptr_t>(injector::GetBranchDestination(loc_6BD32B)) + 1;
ShadowRes::dword_6C86C1 = static_cast<uintptr_t>(injector::GetBranchDestination(loc_6BD333)) + 1;
ShadowRes::dword_6C8786 = hook::pattern("68 00 04 00 00 68 00 04 00 00 50 FF 51 5C 85 C0 7C 32").count(1).get(0).get<uint32_t>(1);
ShadowRes::dword_6C878B = (uint32_t)ShadowRes::dword_6C8786 + 5;
ShadowRes::dword_6C87B8 = hook::pattern("68 00 04 00 00 68 00 04 00 00 50 FF 52 5C 85 C0 7D 36").count(1).get(0).get<uint32_t>(1);
ShadowRes::dword_6C87BD = (uint32_t)ShadowRes::dword_6C87B8 + 5;
uintptr_t loc_6C87E5 = reinterpret_cast<uintptr_t>(hook::pattern("68 44 46 31 36 6A 02 6A 01 68").get_first(0));
ShadowRes::dword_6C87EF = loc_6C87E5 + 0xA;
ShadowRes::dword_6C87F4 = ShadowRes::dword_6C87EF + 5;
injector::UnprotectMemory(ShadowRes::dword_6C86B1, sizeof(uint32_t), oldprotect);
injector::UnprotectMemory(ShadowRes::dword_6C86C1, sizeof(uint32_t), oldprotect);
injector::UnprotectMemory(ShadowRes::dword_6C8786, sizeof(uint32_t), oldprotect);
injector::UnprotectMemory(ShadowRes::dword_6C878B, sizeof(uint32_t), oldprotect);
injector::UnprotectMemory(ShadowRes::dword_6C87B8, sizeof(uint32_t), oldprotect);
injector::UnprotectMemory(ShadowRes::dword_6C87BD, sizeof(uint32_t), oldprotect);
injector::UnprotectMemory(ShadowRes::dword_6C87F4, sizeof(uint32_t), oldprotect);
injector::UnprotectMemory(ShadowRes::dword_6C87EF, sizeof(uint32_t), oldprotect);
ShadowRes::update(ShadowRes::Resolution);
}
if (ShadowRes::CurrentTexFormat >= 0)
{
uintptr_t loc_6C87E5 = reinterpret_cast<uintptr_t>(hook::pattern("68 44 46 31 36 6A 02 6A 01 68").get_first(0));
uintptr_t loc_6C8798 = loc_6C87E5 - 0x4D;
uintptr_t loc_6C87D5 = loc_6C87E5 - 0x10;
uintptr_t loc_6C87A2 = loc_6C87E5 - 0x43;
uintptr_t loc_6C87B2 = loc_6C87E5 - 0x33;
uintptr_t loc_6C174E = reinterpret_cast<uintptr_t>(hook::pattern("68 44 46 31 36 6A 03 6A 02 6A 16 6A 01 52 50 FF").get_first(0));
uintptr_t loc_6C1703 = loc_6C174E - 0x4B;
uintptr_t loc_6C170A = loc_6C174E - 0x44;
uintptr_t loc_6C1719 = loc_6C174E - 0x35;
uintptr_t loc_6C172C = loc_6C174E - 0x22;
uintptr_t loc_6C1741 = loc_6C174E - 0xD;
uintptr_t loc_6C1764 = loc_6C174E + 0x16;
uintptr_t dword_982C08 = *reinterpret_cast<uintptr_t*>(loc_6C172C + 2);
if (ShadowRes::CurrentTexFormat > (_countof(ShadowRes::ShadowMapTexFormats) - 1))
ShadowRes::CurrentTexFormat = (_countof(ShadowRes::ShadowMapTexFormats) - 1);
// disable writes to the shadow map texture type variable
injector::MakeNOP(loc_6C1703, 6);
injector::MakeNOP(loc_6C172C, 10);
injector::MakeNOP(loc_6C1764, 10);
if (ShadowRes::ShadowMapTexFormats[ShadowRes::CurrentTexFormat] < 0x7F)
{
injector::MakeJMP(loc_6C8798, loc_6C87A2);
injector::WriteMemory<uint8_t>(loc_6C87B2 + 1, ShadowRes::ShadowMapTexFormats[ShadowRes::CurrentTexFormat] & 0xFF, true);
injector::MakeNOP(loc_6C170A, 2);
injector::WriteMemory<uint8_t>(loc_6C1719 + 1, ShadowRes::ShadowMapTexFormats[ShadowRes::CurrentTexFormat] & 0xFF, true);
}
else
{
injector::MakeJMP(loc_6C8798, loc_6C87D5);
injector::WriteMemory<uint32_t>(loc_6C87E5 + 1, ShadowRes::ShadowMapTexFormats[ShadowRes::CurrentTexFormat], true);
injector::MakeJMP(loc_6C170A, loc_6C1741);
injector::WriteMemory<uint32_t>(loc_6C174E + 1, ShadowRes::ShadowMapTexFormats[ShadowRes::CurrentTexFormat], true);
}
// Var at 0x00982C08
// 1 = Sample Shadow Map Directly, 2 = Depth Buffer as Texture
if (ShadowRes::CurrentTexFormat == 0)
*(uint32_t*)dword_982C08 = 1;
else
*(uint32_t*)dword_982C08 = 2;
}
if (ForcedGPUVendor)
{
uint32_t* dword_93D898 = *hook::pattern("A1 ? ? ? ? 49 3D 02 10 00 00 89 0D").count(1).get(0).get<uint32_t*>(1);
for (size_t i = 0; i < 20; i++)
{
uint32_t* dword__93D898 = hook::pattern(pattern_str(to_bytes(dword_93D898))).count(1).get(0).get<uint32_t>(0);
injector::WriteMemory(dword__93D898, &ForcedGPUVendor, true);
}
}
if (ShadowRes::bForceSharpShadows)
{
uintptr_t loc_6D5F3A = reinterpret_cast<uintptr_t>(hook::pattern("83 E8 03 89 44 24 14 EB 04 3B C3 7F 44").get_first(0));
injector::WriteMemory<uint8_t>(loc_6D5F3A + 2, 2, true);
}
if (bImproveShadowLOD)
{
uint32_t* dword_6E5174 = hook::pattern("68 ? ? ? ? EB ? A1 ? ? ? ? 0D").count(1).get(0).get<uint32_t>(1);
injector::WriteMemory(dword_6E5174, 0x00000000, true);
uint32_t* dword_6BFFA2 = hook::pattern("68 ? ? ? ? 50 41 68").count(2).get(1).get<uint32_t>(1);
injector::WriteMemory(dword_6BFFA2, 0x00006102, true);
}
if (bFixHUD)
{
HudScaleX_8AF9A4 = *hook::pattern("D8 0D ? ? ? ? D8 25 ? ? ? ? D9 5C 24 20 D9 46 04").count(1).get(0).get<float*>(2);
injector::UnprotectMemory(HudScaleX_8AF9A4, sizeof(float), oldprotect);
*HudScaleX_8AF9A4 = Screen.fHudScaleX;
//fHudScaleY = *(float*)0x8AF9A0;
//injector::WriteMemory<float>(0x8AF9A0, fHudScaleY, true);
FE_Xpos_894B40 = *hook::pattern("D8 25 ? ? ? ? D9 5C 24 14 DB 05 ? ? ? ? D8 25 ? ? ? ? D9 5C 24 1C 74 20").count(1).get(0).get<float*>(2);
injector::UnprotectMemory(FE_Xpos_894B40, sizeof(float), oldprotect);
*FE_Xpos_894B40 = Screen.fHudPosX;
// make code read the FE X position from the variable
pattern = hook::pattern("C7 ? ? ? ? 00 00 00 00 A0 43 C7 ? ? ? ? 00 00 00 00 70 43"); // 0x56FED4
struct HudPosXHook1
{
void operator()(injector::reg_pack& regs)
{
*(float*)(regs.esp + 0x19C) = *(float*)(FE_Xpos_894B40);
}
}; injector::MakeInline<HudPosXHook1>(pattern.get_first(0), pattern.get_first(11));
pattern = hook::pattern("C7 ? ? ? ? 00 00 00 00 A0 43 C7 ? ? ? ? 00 00 00 00 70 43"); // 0x584EEF
struct HudPosXHook2
{
void operator()(injector::reg_pack& regs)
{
*(float*)(regs.esp + 0x90) = *(float*)(FE_Xpos_894B40);
}
}; injector::MakeInline<HudPosXHook2>(pattern.get_first(0), pattern.get_first(11));
pattern = hook::pattern("C7 ? ? ? ? 00 00 00 00 A0 43 C7 ? ? ? ? 00 00 00 00 70 43"); // 0x599E79
struct HudPosXHook3
{
void operator()(injector::reg_pack& regs)
{
*(float*)(regs.esp + 0x84) = *(float*)(FE_Xpos_894B40);
}
}; injector::MakeInline<HudPosXHook3>(pattern.get_first(0), pattern.get_first(11));
pattern = hook::pattern("C7 ? ? ? ? 00 00 00 00 A0 43 C7 ? ? ? ? 00 00 00 00 70 43"); // 0x0059A120
struct HudPosXHook4
{
void operator()(injector::reg_pack& regs)
{
*(float*)(regs.esp + 0xC4) = *(float*)(FE_Xpos_894B40);
}
}; injector::MakeInline<HudPosXHook4>(pattern.get_first(0), pattern.get_first(11));
pattern = hook::pattern("C7 ? ? ? ? 00 00 00 00 A0 43 C7 ? ? ? ? 00 00 00 00 70 43"); // 0x0059A5AB
struct HudPosXHook5
{
void operator()(injector::reg_pack& regs)
{
*(float*)(regs.esp + 0x94) = *(float*)(FE_Xpos_894B40);
}
}; injector::MakeInline<HudPosXHook5>(pattern.get_first(0), pattern.get_first(11));
pattern = hook::pattern("C7 ? ? ? ? 00 00 00 00 A0 43 C7 ? ? ? ? 00 00 00 00 70 43"); // 0x0059A83E
injector::MakeInline<HudPosXHook5>(pattern.get_first(0), pattern.get_first(11));
pattern = hook::pattern("C7 ? ? ? 00 00 A0 43 C7 ? ? ? 00 00 70 43"); // 0x005A44C8
struct HudPosXHook6
{
void operator()(injector::reg_pack& regs)
{
*(float*)(regs.esp + 0x64) = *(float*)(FE_Xpos_894B40);
}
}; injector::MakeInline<HudPosXHook6>(pattern.get_first(0), pattern.get_first(8));
//mirror position fix
pattern = hook::pattern("C7 44 24 70 00 00 E1 43 C7 44 24 74 00 00 98 41 C7 84 24 80 00 00 00 00 00 3E 43"); // 0x6E70C0
struct MirrorPosXHook
{
void operator()(injector::reg_pack& regs)
{
*(float*)(regs.esp + 0x70) = (*(float*)(FE_Xpos_894B40) - 320.0f) + 450.0f;
*(float*)(regs.esp + 0xA0) = (*(float*)(FE_Xpos_894B40) - 320.0f) + 450.0f;
*(float*)(regs.esp + 0x80) = (*(float*)(FE_Xpos_894B40) - 320.0f) + 190.0f;
*(float*)(regs.esp + 0x90) = (*(float*)(FE_Xpos_894B40) - 320.0f) + 190.0f;
// others
*(float*)(regs.esp + 0x74) = 19.0;
*(float*)(regs.esp + 0x84) = 19.0;
*(float*)(regs.esp + 0x94) = 89.0;
*(float*)(regs.esp + 0xA4) = 89.0;
}
}; injector::MakeInline<MirrorPosXHook>(pattern.get_first(0), pattern.get_first(82));
}
if (bFixFOV)
{
hor3DScale = 1.0f / (Screen.fAspectRatio / (4.0f / 3.0f));
static float ver3DScale = 1.0f; // don't touch this
static float mirrorScale = 0.4f;
static float f1215 = 1.215f;
static float f043434 = 0.43434f;
static float f1 = 1.0f; // horizontal for vehicle reflection
static float flt1 = 0.0f;
static float flt2 = 0.0f;
static float flt3 = 0.0f;
if (nScaling)
{
hor3DScale /= 1.047485948f;
f1215 = 1.21f;
if (nScaling == 2)
{
f1215 = 1.27f;
}
}
// Xan's note: please, write direct addresses in names whereever possible. Obfuscating it behind math or pattern detector is stupid and just makes maintainence harder.
uint32_t* dword_6CF4F0 = hook::pattern("DB 40 18 DA 70 14").count(1).get(0).get<uint32_t>(0);
uintptr_t loc_6CF4EA = (uintptr_t)dword_6CF4F0 - 6;
uintptr_t loc_6CF4F6 = (uintptr_t)dword_6CF4F0 + 6;
struct FOVHook
{
void operator()(injector::reg_pack& regs)
{
regs.eax = *(uint32_t*)(regs.edi + 0x60);
if (regs.ecx == 1 || regs.ecx == 4) //Headlights stretching, reflections etc
{
flt1 = hor3DScale;
flt2 = f043434;
flt3 = f1215;
}
else
{
if (regs.ecx > 10)
{
flt1 = f1;
flt2 = 0.5f;
flt3 = 1.0f;
_asm fld ds : f1
return;
}
else
{
flt1 = 1.0f;
flt2 = 0.5f;
flt3 = 1.0f;
}
}
if (regs.ecx == 3) //if rearview mirror
_asm fld ds : mirrorScale
else
_asm fld ds : ver3DScale
}
}; injector::MakeInline<FOVHook>(loc_6CF4EA, loc_6CF4F6);
injector::WriteMemory(dword_6CF4F0, 0x9001F983, true); //cmp ecx, 1
uint32_t* dword_6CF566 = hook::pattern("D8 3D ? ? ? ? D9 5C 24 20 DB 44 24 30 D8 4C 24 2C").count(1).get(0).get<uint32_t>(2);
injector::WriteMemory(dword_6CF566, &flt1, true);
// FOV being different in menus and in-game fix
uint32_t* dword_6CF578 = hook::pattern("D8 0D ? ? ? ? E8 ? ? ? ? 8B F8 57 E8").count(2).get(1).get<uint32_t>(2);
injector::WriteMemory(dword_6CF578, &flt2, true);
uint32_t* dword_6CF5DC = hook::pattern("D8 3D ? ? ? ? D9 44 24 20 D8 64 24 24").count(1).get(0).get<uint32_t>(2);
injector::WriteMemory(dword_6CF5DC, &flt3, true);
//Shadow pop-in fix
uint32_t* dword_6C9653 = hook::pattern("D8 0D ? ? ? ? D9 5C 24 ? E8 ? ? ? ? 8A").count(1).get(0).get<uint32_t>(2);
static float fShadowDistanceMultiplier = 10.0f;
injector::WriteMemory((uint32_t)dword_6C9653, &fShadowDistanceMultiplier, true);
// Shadow camera FOV fix
uintptr_t loc_6E4652 = reinterpret_cast<uintptr_t>(hook::pattern("8B 46 60 8B 48 18 8B 50 14 89 4C 24 14 DB 44 24 14").get_first(0)) + 9;
uintptr_t loc_6E4668 = loc_6E4652 + 0x16;
uintptr_t loc_6E47E4 = reinterpret_cast<uintptr_t>(hook::pattern("8B 40 60 8B 50 18 8B 40 14 89 54 24 14 89 44 24 18 0F B7 8B C4 00 00 00").get_first(0)) + 0x18;
uintptr_t loc_6E47EC = loc_6E47E4 + 8;
uintptr_t loc_6E46B0 = reinterpret_cast<uintptr_t>(hook::pattern("D8 7C 24 1C 0F B7 8B C4 00 00 00 89 4C 24 1C").get_first(0)) + 0xF;
uintptr_t loc_6E4830 = reinterpret_cast<uintptr_t>(hook::pattern("D8 7C 24 1C 0F B7 93 C4 00 00 00 89 54 24 1C").get_first(0)) + 0xF;
struct ShadowCameraFix1
{
void operator()(injector::reg_pack& regs)
{
_asm fld ver3DScale
}
}; injector::MakeInline<ShadowCameraFix1>(loc_6E4652, loc_6E4652 + 8);
injector::MakeNOP(loc_6E4668, 4);
struct ShadowCameraFix2
{
void operator()(injector::reg_pack& regs)
{
*(uint32_t*)(regs.esp + 0x14) = regs.ecx;
_asm fld ver3DScale
}
}; injector::MakeInline<ShadowCameraFix2>(loc_6E47E4, loc_6E47E4 + 8);
injector::MakeNOP(loc_6E47EC, 4);
injector::WriteMemory<uintptr_t>(loc_6E46B0 + 2, (uintptr_t)&hor3DScale, true);
injector::WriteMemory<uintptr_t>(loc_6E4830 + 2, (uintptr_t)&hor3DScale, true);
}
uint32_t* dword_57CB82 = hook::pattern("3A 55 34 0F 85 0B 02 00 00 A1").count(1).get(0).get<uint32_t>(0); // HUD
uint32_t* dword_5696CB = hook::pattern("8A 41 34 38 86 30 03 00 00 74 52 84 C0").count(1).get(0).get<uint32_t>(0); // HUD
uint32_t* dword_58D883 = hook::pattern("8A 40 34 5F 5E 5D 3B CB 5B 75 12").count(1).get(0).get<uint32_t>(0); // EA Trax
uint32_t* dword_56885A = hook::pattern("38 48 34 74 31 8B 4E 38 68 7E 78 8E 90").count(1).get(0).get<uint32_t>(0); // Wrong Way Sign
if (bHUDWidescreenMode)
{
injector::WriteMemory<uint32_t>(dword_57CB82, 0x0F01FA80, true);
injector::WriteMemory<uint32_t>(dword_5696CB, 0x389001B0, true);
injector::WriteMemory<uint32_t>(dword_58D883, 0x5F9001B0, true);
injector::WriteMemory<uint32_t>(dword_56885A, 0x7401F980, true);
//Widescreen Splash
pattern = hook::pattern("8B 46 10 8B 3D ? ? ? ? 53 50");
injector::MakeNOP(pattern.get_first(-2), 2, true);
pattern = hook::pattern("E8 ? ? ? ? 84 C0 B8 ? ? ? ? 75 ? B8 ? ? ? ? C3");
auto aWs_mw_ls_splas = *pattern.count(2).get(1).get<char*>(8);
auto aMw_ls_splash_0 = *pattern.count(2).get(1).get<char*>(15);
injector::WriteMemoryRaw(aMw_ls_splash_0, aWs_mw_ls_splas, strlen(aWs_mw_ls_splas), true);
uint32_t* dword_5A3142 = hook::pattern("68 ? ? ? ? 68 ? ? ? ? 51 E8 ? ? ? ? 83 C4 ? 3B FB").count(1).get(0).get<uint32_t>(6);
injector::WriteMemory(dword_5A3142, 0xC4DF3FF2, true); //"CLICK to continue" (PC)
//issue #343 HD Compatible For Optimal Gaming Logo
pattern = hook::pattern("E8 ? ? ? ? 83 C4 0C E8 ? ? ? ? 85 C0 75 ? 8B 46");
injector::MakeCALL(pattern.get_first(0), injector::GetBranchDestination(hook::get_pattern("E8 ? ? ? ? 8B 46 10 68 6D 44 CF 13"), true), true);
}
else
{
injector::WriteMemory<uint32_t>(dword_57CB82, 0x0F00FA80, true);
injector::WriteMemory<uint32_t>(dword_5696CB, 0x389000B0, true);
injector::WriteMemory<uint32_t>(dword_58D883, 0x5F9000B0, true);
injector::WriteMemory<uint32_t>(dword_56885A, 0x7400F980, true);
}
if (nFMVWidescreenMode)
{
uint32_t* dword_59A02A = hook::pattern("68 00 00 80 3F 68 00 00 00 3F 68 00 00 00 3F 68 00 00 00 BF 68 00 00 00 BF 8B CB E8 ? ? ? ? 8B 4C 24 18").count(1).get(0).get<uint32_t>(6);
injector::WriteMemory<float>(dword_59A02A + 0, (0.5f / ((4.0f / 3.0f) / (16.0f / 9.0f))), true); // Height (Bottom)
injector::WriteMemory<float>((uint32_t)dword_59A02A + 5, (0.5f / ((4.0f / 3.0f) / (16.0f / 9.0f))), true); // Width (Right)
injector::WriteMemory<float>((uint32_t)dword_59A02A + 10, -(0.5f / ((4.0f / 3.0f) / (16.0f / 9.0f))), true); // Height (Top)
injector::WriteMemory<float>((uint32_t)dword_59A02A + 15, -(0.5f / ((4.0f / 3.0f) / (16.0f / 9.0f))), true); // Width (Left)
if (nFMVWidescreenMode > 1)
{
injector::WriteMemory<float>(dword_59A02A + 0, (0.5f / ((4.0f / 3.0f) / (4.0f / 3.0f))), true); // Height (Bottom)
injector::WriteMemory<float>((uint32_t)dword_59A02A + 5, (0.5f / ((4.0f / 3.0f) / (16.0f / 9.0f))), true); // Width (Right)
injector::WriteMemory<float>((uint32_t)dword_59A02A + 10, -(0.5f / ((4.0f / 3.0f) / (4.0f / 3.0f))), true); // Height (Top)
injector::WriteMemory<float>((uint32_t)dword_59A02A + 15, -(0.5f / ((4.0f / 3.0f) / (16.0f / 9.0f))), true); // Width (Left)
}
}
if (bShadowsFix)
{
//dynamic shadow fix that stops them from disappearing when going into tunnels, under bridges, etc.
uint32_t* dword_6DE377 = hook::pattern("75 3B C7 05 ? ? ? ? 00 00 80 3F").count(1).get(0).get<uint32_t>(0);
injector::MakeNOP(dword_6DE377, 2, true);
injector::WriteMemory((uint32_t)dword_6DE377 + 8, 0, true);
//car shadow opacity
uint32_t* dword_8A0E50 = *hook::pattern("D9 05 ? ? ? ? 8B 54 24 70 D9 1A E9 D1").count(1).get(0).get<uint32_t*>(2);
injector::WriteMemory(dword_8A0E50, 60.0f, true);
}
if (bForceHighSpecAudio)
{
uint32_t* dword_4C41F5 = hook::pattern("C7 05 ? ? ? ? ? ? 00 00 A1 ? ? ? ? 85 C0 ? ? A3 ? ? ? ? 8D 44 24 08").count(1).get(0).get<uint32_t>(6);
injector::WriteMemory<int>(dword_4C41F5, 44100, true);
}
if (!szCustomUserFilesDirectoryInGameDir.empty())
{
CustomUserDir = GetExeModulePath<std::filesystem::path>();
CustomUserDir.append(szCustomUserFilesDirectoryInGameDir);
auto SHGetFolderPathAHook = [](HWND /*hwnd*/, int /*csidl*/, HANDLE /*hToken*/, DWORD /*dwFlags*/, LPSTR pszPath) -> HRESULT
{
CreateDirectoryW((LPCWSTR)(CustomUserDir.u16string().c_str()), NULL);
memcpy(pszPath, CustomUserDir.u8string().data(), CustomUserDir.u8string().size() + 1);
return S_OK;
};
auto pattern = hook::pattern("50 6A 00 6A 00 68 ? 80 00 00 6A 00");
for (size_t i = 0; i < pattern.size(); i++)
{
uint32_t* dword_6CBF17 = pattern.get(i).get<uint32_t>(12);
if (*(BYTE*)dword_6CBF17 != 0xFF)
dword_6CBF17 = pattern.get(i).get<uint32_t>(14);
injector::MakeCALL((uint32_t)dword_6CBF17, static_cast<HRESULT(WINAPI*)(HWND, int, HANDLE, DWORD, LPSTR)>(SHGetFolderPathAHook), true);
injector::MakeNOP((uint32_t)dword_6CBF17 + 5, 1, true);
}
}
if (bSkipIntro)
{
static auto counter = 0;
static auto og_value = 0;
pattern = hook::pattern("A1 ? ? ? ? 85 C0 74 1C 8B 45 04");
static uint32_t* dword_926144 = *pattern.get_first<uint32_t*>(1);
struct SkipIntroHook
{
void operator()(injector::reg_pack& regs)
{
if (counter < 3)
{
if (counter == 0)
og_value = *dword_926144;
*dword_926144 = 1;
counter++;
}
else
{
*dword_926144 = og_value;
}
regs.eax = *(uint32_t*)dword_926144;
}
}; injector::MakeInline<SkipIntroHook>(pattern.get_first(0));
}
if (nImproveGamepadSupport)
{
pattern = hook::pattern("6A FF 68 ? ? ? ? 64 A1 ? ? ? ? 50 64 89 25 ? ? ? ? 51 A1 ? ? ? ? 50 E8 ? ? ? ? 83 C4 04 89 04 24 85 C0 C7 44 24 ? ? ? ? ? 74 22 8B 4C 24 24 8B 54 24 20 51");
static auto CreateResourceFile = (void*(*)(const char* ResourceFileName, int32_t ResourceFileType, int, int, int)) pattern.get_first(0); //0x0065FD30
pattern = hook::pattern("8B 44 24 04 56 8B F1 8B 4C 24 0C 89 46 34 89 4E 38 FF 05 ? ? ? ? 8B 46 3C 85 C0 75 14 8B 56 10 C1 EA 03 81 E2 ? ? ? ? 52 8B CE");
static auto ResourceFileBeginLoading = (void(__thiscall *)(void* rsc, int a1, int a2)) pattern.get_first(0); //0x006616F0;
static auto LoadResourceFile = [](const char* ResourceFileName, int32_t ResourceFileType, int32_t nUnk1 = 0, int32_t nUnk2 = 0, int32_t nUnk3 = 0, int32_t nUnk4 = 0, int32_t nUnk5 = 0)
{
auto r = CreateResourceFile(ResourceFileName, ResourceFileType, nUnk1, nUnk2, nUnk3);
ResourceFileBeginLoading(r, nUnk4, nUnk5);
};
if (nImproveGamepadSupport < 3)
{
static auto TPKPath = GetThisModulePath<std::string>().substr(GetExeModulePath<std::string>().length());
if (nImproveGamepadSupport == 1)
TPKPath += "buttons-xbox.tpk";
else if (nImproveGamepadSupport == 2)
TPKPath += "buttons-playstation.tpk";
static injector::hook_back<void(__cdecl*)()> hb_662B30;
auto LoadTPK = []()
{
if (std::filesystem::exists(TPKPath))
{
LoadResourceFile(TPKPath.c_str(), 1);
}
return hb_662B30.fun();
};
pattern = hook::pattern("E8 ? ? ? ? E8 ? ? ? ? E8 ? ? ? ? E8 ? ? ? ? 56 57 B9 ? ? ? ? E8"); //0x6660B6
hb_662B30.fun = injector::MakeCALL(pattern.get_first(0), static_cast<void(__cdecl*)()>(LoadTPK), true).get();
/*
cursor
constexpr float cursorScale = 1.0f * (128.0f / 16.0f);
pattern = hook::pattern("C7 84 24 34 02 00 00 00 00 80 3F D9"); //5704F8
injector::WriteMemory<float>(pattern.get_first(7), cursorScale, true);