-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarRandomizer.cpp
More file actions
955 lines (738 loc) · 25 KB
/
CarRandomizer.cpp
File metadata and controls
955 lines (738 loc) · 25 KB
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
#include "framework.h"
#include "CarRandomizer.hpp"
#include "DebugVehicleSelection.hpp"
#include "UserProfile.hpp"
#include "FEPlayerCarDB.hpp"
#include "EAXSound.hpp"
#include "NIS.hpp"
#include "injector/injector.hpp"
#include <iostream>
#include <unordered_map>
#include <string>
#include <vector>
#include <fstream>
#include <filesystem>
#include <chrono>
#include <random>
#include <shlobj_core.h>
//
// ISSUES:
// - car sounds cause crashes -- probably fixed? EAXSound::ReStartRace fixed it maybe...
// - in final boss race, after the first race, because of the car switch another phantom player appears and causes a crash at the finish (GCareer::IsPlayerCrewWinner crashes because it can't find a vehicle for player checks) -- fixed by nuking the player
// - sometimes car sounds don't appear
// - just car sounds in general cause crashes - NIS_RevManager crashes if EAXSound::ReStartRace is called before a NIS... many edge cases exist...
// - (not a big issue) maybe add presetride into the mix
//
namespace CarRandomizer
{
uintptr_t pGetTicker;
uintptr_t pGame_RaceDone;
uintptr_t pGame_DoPostBossFlow;
uintptr_t pGame_JumpToSafeHouse;
uintptr_t pDALPauseStates_IsPaused;
uintptr_t pDALPauseStates_RequestUnPause;
uintptr_t pGameFlowManager_UnloadTrack;
uintptr_t pAttribGenPVehicle;
//uintptr_t pAttribGenPresetRide;
//uintptr_t p_bRandom;
//uintptr_t p_SHGetFolderPathA;
uintptr_t pDALCareer_SetCar;
uintptr_t pGRaceStatus_GetRacerCount;
uintptr_t pGRaceParameters_GetEventID;
uintptr_t pGRaceParameters_GetRaceType;
uintptr_t pGRaceParameters_GetIsBossRace;
uintptr_t pGRaceParameters_GetIsChallengeSeriesRace;
uintptr_t pGRaceParameters_GetPlayerCarType;
uintptr_t pGRaceParameters_GetUsePresetRide;
uintptr_t pGRaceParameters_GetPlayerCarTypeHash;
std::chrono::steady_clock::time_point nextSpeechExecution;
uintptr_t pSpeech_Manager_Update;
uintptr_t pGameFlowManager;
uintptr_t pGameFlowManagerState;
//std::unordered_map<uint32_t, std::string> sCarLibraryMap;
std::unordered_map<uint32_t, uint32_t> sCarLibraryHandles;
//std::vector<uintptr_t> sCarRecords;
std::vector<uint32_t> sCarLibraryKeys;
const uint32_t sTrafficCarLibraryKeys[] =
{
STRINGHASH32("cs_semi"), // this one is safe to use...
STRINGHASH32("traf4dseda"),
STRINGHASH32("traf4dsedb"),
STRINGHASH32("traf4dsedc"),
STRINGHASH32("trafcourt"),
STRINGHASH32("trafficcoup"),
STRINGHASH32("trafha"),
STRINGHASH32("trafstwag"),
STRINGHASH32("traftaxi"),
STRINGHASH32("trafamb"),
STRINGHASH32("trafcemtr"),
STRINGHASH32("trafdmptr"),
STRINGHASH32("traffire"),
STRINGHASH32("trafgarb"),
STRINGHASH32("trafcamper"),
STRINGHASH32("trafminivan"),
STRINGHASH32("trafnews"),
STRINGHASH32("trafpickupa"),
STRINGHASH32("trafsuva"),
STRINGHASH32("trafvanb"),
};
const uint32_t sTrafficSemiLibraryKeys[] =
{
STRINGHASH32("semia"),
STRINGHASH32("semib"),
STRINGHASH32("semibox"),
STRINGHASH32("semicmt"),
STRINGHASH32("semicon"),
STRINGHASH32("semicrate"),
STRINGHASH32("semilog"),
};
const uint32_t sCopCarLibraryKeys[] =
{
STRINGHASH32("copgto"),
STRINGHASH32("copgtoghost"),
STRINGHASH32("copmidsize"),
STRINGHASH32("copghost"),
STRINGHASH32("copsport"),
STRINGHASH32("copcross"),
STRINGHASH32("copsportghost"),
STRINGHASH32("copsporthench"),
STRINGHASH32("copsuv"),
STRINGHASH32("copsuvpatrol"),
STRINGHASH32("copsuvl"),
};
uint32_t CurrentVehicle;
uint32_t CurrentVehicleCS;
//bool bCSVehicleIsPreset;
//char sCurrentVehicleTypeCS[128];
bool bWasInPostRace;
bool bWasBossCanyonRace;
bool bChallengeRace;
bool bInPostBossFlow;
bool bQueueEAXRefreshFromNIS;
bool bExcludeTrafficCars;
bool bIncludeTrafficSemis;
bool bExcludeCopCars;
bool bExcludeRegularCars;
void SetExcludeTrafficCars(bool state)
{
bExcludeTrafficCars = state;
}
bool GetExcludeTrafficCars()
{
return bExcludeTrafficCars;
}
void SetIncludeTrafficSemis(bool state)
{
bIncludeTrafficSemis = state;
}
bool GetIncludeTrafficSemis()
{
return bIncludeTrafficSemis;
}
void SetExcludeCopCars(bool state)
{
bExcludeCopCars = state;
}
bool GetExcludeCopCars()
{
return bExcludeCopCars;
}
void SetExcludeRegularCars(bool state)
{
bExcludeRegularCars = state;
}
bool GetExcludeRegularCars()
{
return bExcludeRegularCars;
}
static int GetGameFlowManagerState()
{
if (!pGameFlowManagerState)
return -1;
return *reinterpret_cast<int*>(pGameFlowManagerState);
}
static unsigned int bRandom(unsigned int max) {
// Create a random device and seed the random number generator
std::random_device rd;
std::mt19937 gen(rd());
// Create a uniform distribution in the specified range
std::uniform_int_distribution<unsigned int> dis(0, max);
// Generate and return the random number
return dis(gen);
}
//static unsigned int bRandom(int range)
//{
// if (!p_bRandom)
// return 1;
//
// return reinterpret_cast<unsigned int(*)(int)>(p_bRandom)(range);
//}
static const char* GetPVehicleNameByKey(uint32_t k)
{
Attrib_Instance instance = { 0 };
reinterpret_cast<void(__thiscall*)(Attrib_Instance*, unsigned int, unsigned int)>(pAttribGenPVehicle)(&instance, k, 0);
uintptr_t layout = reinterpret_cast<uintptr_t>(instance.mLayoutPtr);
return *reinterpret_cast<char**>(layout + 0x24);
}
//static const char* GetPresetRideNameByKey(uint32_t k)
//{
// Attrib_Instance instance = { 0 };
// reinterpret_cast<void(__thiscall*)(Attrib_Instance*, unsigned int, unsigned int)>(pAttribGenPresetRide)(&instance, k, 0);
//
// uintptr_t layout = reinterpret_cast<uintptr_t>(instance.mLayoutPtr);
// return *reinterpret_cast<char**>(layout + 0xC);
//}
//static uint32_t TryGetPresetKey(uintptr_t carRecord)
//{
// if (!*reinterpret_cast<bool*>(carRecord + 0x16))
// return 0;
//
// return *reinterpret_cast<uint32_t*>(carRecord + 0xC);
//}
//
//static uint32_t TryGetVehicleKey(uintptr_t carRecord)
//{
// return *reinterpret_cast<uint32_t*>(carRecord + 0x8);
//}
//static HRESULT WINAPI SHGetFolderPathA_Game(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPSTR pszPath)
//{
// if (!p_SHGetFolderPathA)
// return SHGetFolderPathA(hwnd, csidl, hToken, dwFlags, pszPath);
//
// return reinterpret_cast<HRESULT(WINAPI*)(HWND, int, HANDLE, DWORD, LPSTR)>(p_SHGetFolderPathA)(hwnd, csidl, hToken, dwFlags, pszPath);
//}
static bool DALCareer_SetCar(int handle)
{
if (!pDALCareer_SetCar)
return false;
return reinterpret_cast<bool(__stdcall*)(int)>(pDALCareer_SetCar)(handle);
}
static int InjectDebugVehicle(uint32_t key)
{
uintptr_t profile = UserProfile::Get(0);
if (!profile)
return 0x12345678;
uintptr_t mCarStable = UserProfile::GetCarStable(profile);
uintptr_t carRecord = FEPlayerCarDB::GetCarByIndex(mCarStable, 0);
int handle = *reinterpret_cast<int*>(carRecord);
*reinterpret_cast<uint32_t*>(carRecord + 4) = STRINGHASH32("uncustomizable");
*reinterpret_cast<uint32_t*>(carRecord + 8) = key;
*reinterpret_cast<uint8_t*>(carRecord + 0x10) = 0xFF;
return handle;
}
static void SetVehicle(const char* vehicleName)
{
if (GetGameFlowManagerState() != 6)
return;
uintptr_t pDebugVehicleSelection = DebugVehicleSelection::Get();
if (!pDebugVehicleSelection)
return;
DebugVehicleSelection::SwitchPlayerVehicle(pDebugVehicleSelection, vehicleName);
if (!bInPostBossFlow)
{
if (NIS::bIsInNIS())
bQueueEAXRefreshFromNIS = true;
else
EAXSound::Refresh();
// delay speech updates by 15 seconds because it may make the game unstable...
nextSpeechExecution = std::chrono::steady_clock::now() + std::chrono::seconds(15);
}
}
static void SetVehicle(uint32_t key)
{
SetVehicle(GetPVehicleNameByKey(key));
if (sCarLibraryHandles.find(key) != sCarLibraryHandles.end())
DALCareer_SetCar(sCarLibraryHandles[key]);
else
{
DALCareer_SetCar(InjectDebugVehicle(key));
}
}
#ifdef _DEBUG
//bool bDoSecondCar;
const uint32_t DebugCars[] =
{
//STRINGHASH32("player_cop_gto"),
//STRINGHASH32("darius"),
//STRINGHASH32("zonda"),
//STRINGHASH32("murcielago640"),
//STRINGHASH32("player_cop_corvette"),
STRINGHASH32("copcross"),
STRINGHASH32("copgto"),
};
int DebugCarCounter = 0;
#endif
static void SetRandomVehicle()
{
if (bChallengeRace)
{
bChallengeRace = false;
return;
}
#ifdef _DEBUG
SetVehicle(DebugCars[DebugCarCounter]);
DebugCarCounter++;
DebugCarCounter %= _countof(DebugCars);
#else
unsigned int index = bRandom(sCarLibraryKeys.size());
if (CurrentVehicle == sCarLibraryKeys[index])
{
bWasInPostRace = false;
return;
}
CurrentVehicle = sCarLibraryKeys[index];
SetVehicle(sCarLibraryKeys[index]);
#endif
bWasInPostRace = false;
bWasBossCanyonRace = false;
bInPostBossFlow = false;
}
static void HandleEmergencyReset()
{
if (((GetAsyncKeyState(VK_RCONTROL) & 0x8000) || (GetAsyncKeyState(VK_LCONTROL) & 0x8000)) && (GetAsyncKeyState(VK_F9) & 0x8000))
{
if (*reinterpret_cast<int*>(pGameFlowManagerState) == 6)
{
bWasInPostRace = false;
bChallengeRace = false;
bool bPaused = reinterpret_cast<bool(*)()>(pDALPauseStates_IsPaused)();
if (bPaused)
reinterpret_cast<void(*)()>(pDALPauseStates_RequestUnPause)();
reinterpret_cast<void(*)()>(pGame_JumpToSafeHouse)();
}
}
}
static void HandleMainLoop()
{
if (bQueueEAXRefreshFromNIS)
{
if (!NIS::bIsInNIS())
{
bQueueEAXRefreshFromNIS = false;
if (!bInPostBossFlow)
EAXSound::Refresh();
}
}
HandleEmergencyReset();
}
static void GetCarList()
{
// obtain car keys from the car stable
uintptr_t profile = UserProfile::Get(0);
if (!profile)
return;
// failsafe
if (bExcludeRegularCars && bExcludeTrafficCars && bExcludeCopCars)
bExcludeRegularCars = false;
uintptr_t mCarStable = UserProfile::GetCarStable(profile);
size_t maxCarRecords = FEPlayerCarDB::GetNumCarRecords();
std::vector<uint32_t> CarKeys;
std::vector<uintptr_t> CarRecords;
//sCarRecords.clear();
//sCarLibrary.clear();
for (int i = 0; i < maxCarRecords; i++)
{
uintptr_t carRecord = FEPlayerCarDB::GetCarByIndex(mCarStable, i);
int handle = *reinterpret_cast<int*>(carRecord);
uint32_t VehicleKey = *reinterpret_cast<uint32_t*>(carRecord + 8);
if (handle == -1)
continue;
CarKeys.push_back(VehicleKey);
CarRecords.push_back(carRecord);
}
//sCarLibraryMap.clear();
sCarLibraryKeys.clear();
sCarLibraryHandles.clear();
if (!bExcludeRegularCars)
{
for (int i = 0; i < CarKeys.size(); i++)
{
uint32_t k = CarKeys[i];
uintptr_t carRecord = CarRecords[i];
int handle = *reinterpret_cast<int*>(carRecord);
sCarLibraryKeys.push_back(k);
//sCarLibraryMap[k] = GetPVehicleNameByKey(k);
sCarLibraryHandles[k] = handle;
}
}
if (!bExcludeTrafficCars)
{
for (const uint32_t& k : sTrafficCarLibraryKeys)
sCarLibraryKeys.push_back(k);
if (bIncludeTrafficSemis)
for (const uint32_t& k : sTrafficSemiLibraryKeys)
sCarLibraryKeys.push_back(k);
}
if (!bExcludeCopCars)
{
for (const uint32_t& k : sCopCarLibraryKeys)
sCarLibraryKeys.push_back(k);
}
}
namespace FEPostRaceStateManager
{
constexpr size_t vtidx_Start = 7;
constexpr size_t vtidx_ExitPostRace = 71;
uintptr_t pStart;
uintptr_t pExitPostRace;
#pragma runtime_checks("", off)
//static void __stdcall ExitPostRace_Hook(int exitReason)
//{
// uintptr_t that;
// _asm mov that, ecx
//
// //SetVehicle(testVehicleName);
// //SetRandomVehicle();
//
// return reinterpret_cast<void(__thiscall*)(uintptr_t, int)>(pExitPostRace)(that, exitReason);
//}
static void __stdcall Start_Hook()
{
uintptr_t that;
_asm mov that, ecx
//SetVehicle(testVehicleName);
//SetRandomVehicle();
bWasInPostRace = true;
return reinterpret_cast<void(__thiscall*)(uintptr_t)>(pStart)(that);
}
#pragma runtime_checks("", restore)
static void Init()
{
uintptr_t loc_59B7C7 = 0x59B7C7;
uintptr_t* vt = *reinterpret_cast<uintptr_t**>(loc_59B7C7 + 2);
pStart = vt[vtidx_Start];
injector::WriteMemory(&vt[vtidx_Start], Start_Hook, true);
//pExitPostRace = vt[vtidx_ExitPostRace];
//injector::WriteMemory(&vt[vtidx_ExitPostRace], ExitPostRace_Hook, true);
}
}
namespace MemcardManager
{
//constexpr size_t vtidx_SaveDone = 4;
constexpr size_t vtidx_LoadDone = 7;
uintptr_t pOnLoadDone;
//uintptr_t pOnSaveDone;
#pragma runtime_checks("", off)
static void __stdcall LoadDone_Hook(const char* name)
{
uintptr_t that;
_asm mov that, ecx
reinterpret_cast<void(__thiscall*)(uintptr_t, const char*)>(pOnLoadDone)(that, name);
GetCarList();
//LoadActiveVehicle(name);
}
//static void __stdcall SaveDone_Hook(const char* name)
//{
// uintptr_t that;
// _asm mov that, ecx
//
// reinterpret_cast<void(__thiscall*)(uintptr_t, const char*)>(pOnSaveDone)(that, name);
//
// //SaveActiveVehicle(name);
//}
#pragma runtime_checks("", restore)
static void Init()
{
uintptr_t loc_5ABF5C = 0x5ABF5C;
uintptr_t* vt = *reinterpret_cast<uintptr_t**>(loc_5ABF5C + 2);
pOnLoadDone = vt[vtidx_LoadDone];
injector::WriteMemory(&vt[vtidx_LoadDone], LoadDone_Hook, true);
//pOnSaveDone = vt[vtidx_SaveDone];
//injector::WriteMemory(&vt[vtidx_SaveDone], SaveDone_Hook, true);
}
}
namespace FECarClassSelectStateManager
{
constexpr size_t vtidx_HandlePadAccept = 30;
constexpr size_t vtidx_HandlePadStart = 58;
//uintptr_t pHandlePadAccept;
uintptr_t pHandlePadStart;
uintptr_t pShowDialog;
#pragma runtime_checks("", off)
static void __stdcall HandlePadAccept_Hook()
{
uintptr_t that;
_asm mov that, ecx
// redirect HandlePadAccept to HandlePadStart to disable the test drive (via buttons at least, probably doesn't disable the mouse button interaction)
return reinterpret_cast<void(__thiscall*)(uintptr_t)>(pHandlePadStart)(that);
}
static void __stdcall ShowDialog(int nextState)
{
uintptr_t that;
_asm mov that, ecx
// redirect test drive to car selection (via buttons at least, probably doesn't disable the mouse button interaction)
return reinterpret_cast<void(__thiscall*)(uintptr_t, int)>(pShowDialog)(that, 4);
}
#pragma runtime_checks("", restore)
static void Init()
{
uintptr_t loc_847644 = 0x847644;
uintptr_t loc_847742 = 0x847742;
uintptr_t* vt = *reinterpret_cast<uintptr_t**>(loc_847644 + 2);
pHandlePadStart = vt[vtidx_HandlePadStart];
//pHandlePadAccept = vt[vtidx_HandlePadAccept];
injector::WriteMemory(&vt[vtidx_HandlePadAccept], HandlePadAccept_Hook, true);
pShowDialog = static_cast<uintptr_t>(injector::GetBranchDestination(loc_847742));
injector::MakeCALL(loc_847742, ShowDialog);
}
}
static void Game_RaceDone_Hook()
{
//SetVehicle(testVehicleName);
if (bWasInPostRace && !bWasBossCanyonRace)
SetRandomVehicle();
if (pGame_RaceDone)
return reinterpret_cast<void(*)()>(pGame_RaceDone)();
}
static void Game_DoPostBossFlow_Hook(uintptr_t instance)
{
if (pGame_DoPostBossFlow)
reinterpret_cast<void(*)(uintptr_t)>(pGame_DoPostBossFlow)(instance);
bInPostBossFlow = true;
// the vehicle switch must be delayed for bosses because you don't get the post boss flow otherwise...
if (bWasInPostRace && bWasBossCanyonRace)
SetRandomVehicle();
}
static uint32_t GetTicker_Hook()
{
uint32_t retVal = reinterpret_cast<uint32_t(*)()>(pGetTicker)();
HandleMainLoop();
return retVal;
}
static bool __stdcall ValidateRacerInfo(uintptr_t GRacerInfo)
{
// actually idk what this value is -- index? position? I only have ProStreet GRacerInfo to go off of...
uint32_t index = *reinterpret_cast<uint32_t*>(GRacerInfo);
if (!index)
return false;
// usually a pretty good indicator - if the name is empty, something went really, really bad
char* name = reinterpret_cast<char*>(GRacerInfo + 8);
if (name[0] == '\0')
return false;
// #TODO add more here...
return true;
}
static bool __stdcall IsCanyonBossDuel(uintptr_t GRaceParameters)
{
constexpr int raceTypeCanyon = 0xD;
int raceType = reinterpret_cast<int(__thiscall*)(uintptr_t)>(pGRaceParameters_GetRaceType)(GRaceParameters);
if (raceType != raceTypeCanyon)
return false;
return reinterpret_cast<bool(__thiscall*)(uintptr_t)>(pGRaceParameters_GetIsBossRace)(GRaceParameters);
}
static void __declspec(naked) hkGetWinningPlayerInfo()
{
_asm
{
pushad
push esi
call ValidateRacerInfo
test al, al
jnz epNormalExitGWPI
popad
mov cl, 1
ret
epNormalExitGWPI:
popad
mov cl, [esi+0x1C8]
ret
}
}
uintptr_t loc_452C0C;
uintptr_t loc_452B9B;
static void __declspec(naked) hkNISListenerActivitySomething()
{
_asm
{
test eax, eax
jz epMissingVehicleNLAS
mov edx, [eax]
mov ecx, eax
call dword ptr [edx + 0xC0]
jmp [loc_452B9B]
epMissingVehicleNLAS:
jmp [loc_452C0C]
}
}
static bool ShouldDelaySpeechUpdate()
{
auto currentTime = std::chrono::steady_clock::now();
if (currentTime >= nextSpeechExecution)
return false;
return true;
}
static void Speech_Manager_Update_Hook(float dT)
{
if (ShouldDelaySpeechUpdate())
return;
return reinterpret_cast<void(*)(int)>(pSpeech_Manager_Update)(dT);
}
#pragma runtime_checks("", off)
static int __stdcall GRaceStatus_GetRacerCount_Hook()
{
uintptr_t that;
_asm mov that, ecx
constexpr size_t offRacerCount = 0x6A08;
//constexpr size_t offRaceParms = 0x6A1C;
constexpr size_t offRacerInfos = 0x18;
constexpr size_t sizeGRacerInfo = 0x384;
struct GRacerInfo
{
uint8_t data[sizeGRacerInfo];
};
int mRacerCount = *reinterpret_cast<int*>(that + offRacerCount);
GRacerInfo* mRacerInfo = reinterpret_cast<GRacerInfo*>(that + offRacerInfos);
// no need to check any further if it's the only one...
if (mRacerCount == 1)
return reinterpret_cast<int(__thiscall*)(uintptr_t)>(pGRaceStatus_GetRacerCount)(that);
// racer validation must be put in place in order to avoid crashes
// the game creates a new player when the car switches, this ensures that it never happens
// sadly, the tutorial is still broken...
std::vector<GRacerInfo> validRacers;
for (int i = 0; i < mRacerCount; i++)
{
if (ValidateRacerInfo(reinterpret_cast<uintptr_t>(&mRacerInfo[i])))
{
validRacers.push_back(mRacerInfo[i]);
}
}
for (int i = 0; i < validRacers.size(); i++)
{
memset(&mRacerInfo[i], 0, sizeof(GRacerInfo));
memcpy(&mRacerInfo[i], &validRacers[i], sizeof(GRacerInfo));
}
*reinterpret_cast<int*>(that + offRacerCount) = validRacers.size();
// set the index to the first one if this is the ONLY car...
//if (validRacers.size() == 1)
//{
// *reinterpret_cast<uint32_t*>(&mRacerInfo[0]) = 1;
//}
return reinterpret_cast<int(__thiscall*)(uintptr_t)>(pGRaceStatus_GetRacerCount)(that);
}
static const char* __stdcall GRaceParameters_GetEventID_Hook()
{
uintptr_t that;
_asm mov that, ecx
// check if this was a boss canyon duel
bWasBossCanyonRace = IsCanyonBossDuel(that);
bChallengeRace = reinterpret_cast<bool(__thiscall*)(uintptr_t)>(pGRaceParameters_GetIsChallengeSeriesRace)(that);
bWasInPostRace = false;
return reinterpret_cast<const char*(__thiscall*)(uintptr_t)>(pGRaceParameters_GetEventID)(that);
}
static const char* __stdcall GRaceParameters_GetPlayerCarType_Hook()
{
uintptr_t that;
_asm mov that, ecx
bChallengeRace = reinterpret_cast<bool(__thiscall*)(uintptr_t)>(pGRaceParameters_GetIsChallengeSeriesRace)(that);
if (!bChallengeRace)
return reinterpret_cast<const char* (__thiscall*)(uintptr_t)>(pGRaceParameters_GetPlayerCarType)(that);
//unsigned int index = bRandom(sCarLibraryKeys.size());
//CurrentVehicleCS = sCarLibraryKeys[index];
return GetPVehicleNameByKey(CurrentVehicleCS);
}
static uint32_t __stdcall GRaceParameters_GetPlayerCarTypeHash_Hook()
{
uintptr_t that;
_asm mov that, ecx
bChallengeRace = reinterpret_cast<bool(__thiscall*)(uintptr_t)>(pGRaceParameters_GetIsChallengeSeriesRace)(that);
if (!bChallengeRace)
return reinterpret_cast<uint32_t(__thiscall*)(uintptr_t)>(pGRaceParameters_GetPlayerCarTypeHash)(that);
unsigned int index = bRandom(sCarLibraryKeys.size());
CurrentVehicleCS = sCarLibraryKeys[index];
return CurrentVehicleCS;
}
static bool __stdcall GRaceParameters_GetUsePresetRide_Hook()
{
uintptr_t that;
_asm mov that, ecx
bChallengeRace = reinterpret_cast<bool(__thiscall*)(uintptr_t)>(pGRaceParameters_GetIsChallengeSeriesRace)(that);
if (!bChallengeRace)
return reinterpret_cast<bool(__thiscall*)(uintptr_t)>(pGRaceParameters_GetUsePresetRide)(that);
return false;
}
static void __stdcall GameFlowManager_UnloadTrack_Hook()
{
uintptr_t that;
_asm mov that, ecx
bWasInPostRace = false;
bChallengeRace = false;
return reinterpret_cast<void(__thiscall*)(uintptr_t)>(pGameFlowManager_UnloadTrack)(that);
}
#pragma runtime_checks("", restore)
void Init()
{
uintptr_t loc_6B7957 = 0x6B7957;
uintptr_t loc_423031 = 0x423031;
//uintptr_t loc_4D180F = 0x4D180F;
//uintptr_t loc_555A0A = 0x555A0A;
uintptr_t loc_5CD04D = 0x5CD04D;
uintptr_t loc_66A55E = 0x66A55E;
uintptr_t loc_66A9E8 = 0x66A9E8;
//uintptr_t loc_7166AA = 0x7166AA;
uintptr_t loc_4D98D0 = 0x4D98D0;
uintptr_t loc_641168 = 0x641168;
uintptr_t loc_668F1E = 0x668F1E;
uintptr_t loc_65610B = 0x65610B;
uintptr_t loc_4CB390 = 0x4CB390;
uintptr_t loc_64145F = 0x64145F;
uintptr_t loc_5A0F9B = 0x5A0F9B;
uintptr_t loc_6459AD = 0x6459AD;
uintptr_t loc_52228D = 0x52228D;
uintptr_t loc_66A4CB = 0x66A4CB;
uintptr_t loc_5A0FB6 = 0x5A0FB6;
uintptr_t loc_5A0FBF = 0x5A0FBF;
uintptr_t loc_765780 = 0x765780;
uintptr_t loc_7657A1 = 0x7657A1;
uintptr_t loc_64577D = 0x64577D;
loc_452C0C = 0x452C0C;
loc_452B9B = 0x452B9B;
uintptr_t loc_452B91 = 0x452B91;
pGetTicker = static_cast<uintptr_t>(injector::GetBranchDestination(loc_6B7957));
injector::MakeCALL(loc_6B7957, GetTicker_Hook);
pAttribGenPVehicle = static_cast<uintptr_t>(injector::GetBranchDestination(loc_423031));
//pAttribGenPresetRide = static_cast<uintptr_t>(injector::GetBranchDestination(loc_4D180F));
//p_bRandom = static_cast<uintptr_t>(injector::GetBranchDestination(loc_555A0A));
pGameFlowManagerState = *reinterpret_cast<uintptr_t*>(loc_5CD04D + 2);
pGameFlowManager = pGameFlowManagerState - 8;
//pEventSysAllocate = static_cast<uintptr_t>(injector::GetBranchDestination(loc_66997A));
//pECommitAudioAssets = static_cast<uintptr_t>(injector::GetBranchDestination(loc_669994));
pGame_RaceDone = *reinterpret_cast<uintptr_t*>(loc_66A55E + 1);
injector::WriteMemory(loc_66A55E + 1, &Game_RaceDone_Hook, true);
pGame_DoPostBossFlow = *reinterpret_cast<uintptr_t*>(loc_66A9E8 + 1);
injector::WriteMemory(loc_66A9E8 + 1, &Game_DoPostBossFlow_Hook, true);
pGame_JumpToSafeHouse = *reinterpret_cast<uintptr_t*>(loc_66A4CB + 1);
injector::MakeNOP(loc_641168 + 5);
injector::MakeCALL(loc_641168, hkGetWinningPlayerInfo);
injector::MakeJMP(loc_452B91, hkNISListenerActivitySomething);
pGRaceStatus_GetRacerCount = static_cast<uintptr_t>(injector::GetBranchDestination(loc_668F1E));
injector::MakeCALL(loc_668F1E, GRaceStatus_GetRacerCount_Hook);
pGRaceParameters_GetPlayerCarType = static_cast<uintptr_t>(injector::GetBranchDestination(loc_765780));
injector::MakeCALL(loc_765780, GRaceParameters_GetPlayerCarType_Hook);
pGRaceParameters_GetPlayerCarTypeHash = static_cast<uintptr_t>(injector::GetBranchDestination(loc_64577D));
injector::MakeCALL(loc_64577D, GRaceParameters_GetPlayerCarTypeHash_Hook);
pGRaceParameters_GetUsePresetRide = static_cast<uintptr_t>(injector::GetBranchDestination(loc_7657A1));
injector::MakeCALL(loc_7657A1, GRaceParameters_GetUsePresetRide_Hook);
pGRaceParameters_GetEventID = static_cast<uintptr_t>(injector::GetBranchDestination(loc_65610B));
injector::MakeCALL(loc_65610B, GRaceParameters_GetEventID_Hook);
pGameFlowManager_UnloadTrack = static_cast<uintptr_t>(injector::GetBranchDestination(loc_5A0F9B));
injector::MakeCALL(loc_5A0F9B, GameFlowManager_UnloadTrack_Hook);
pSpeech_Manager_Update = static_cast<uintptr_t>(injector::GetBranchDestination(loc_52228D));
injector::MakeCALL(loc_52228D, Speech_Manager_Update_Hook);
pGRaceParameters_GetRaceType = static_cast<uintptr_t>(injector::GetBranchDestination(loc_4CB390));
pGRaceParameters_GetIsBossRace = static_cast<uintptr_t>(injector::GetBranchDestination(loc_64145F));
pGRaceParameters_GetIsChallengeSeriesRace = static_cast<uintptr_t>(injector::GetBranchDestination(loc_6459AD));
//uintptr_t ppGetFolder = *reinterpret_cast<uintptr_t*>(loc_7166AA + 2);
//p_SHGetFolderPathA = *reinterpret_cast<uintptr_t*>(ppGetFolder);
pDALCareer_SetCar = static_cast<uintptr_t>(injector::GetBranchDestination(loc_4D98D0));
pDALPauseStates_IsPaused = static_cast<uintptr_t>(injector::GetBranchDestination(loc_5A0FB6));
pDALPauseStates_RequestUnPause = static_cast<uintptr_t>(injector::GetBranchDestination(loc_5A0FBF));
FEPostRaceStateManager::Init();
FECarClassSelectStateManager::Init();
MemcardManager::Init();
GetCarList();
nextSpeechExecution = std::chrono::steady_clock::now();
//strcpy_s(testVehicleName, "viper");
//printf("bTestTrigger = 0x%X\n", &bTestTrigger);
//printf("testVehicleName = 0x%X\n", testVehicleName);
}
}