Skip to content

Commit ab60282

Browse files
committed
Added features (1 JAN 22)
Added ini option EnableSpecialFeatures
1 parent a557f22 commit ab60282

3 files changed

Lines changed: 273 additions & 5 deletions

File tree

ModelVariations/ModelVariations.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ int enableAllSideMissions = 0;
7777
int enableVehicles = 0;
7878
int loadAllVehicles = 0;
7979

80+
void(*PreRenderOriginal)(CAutomobile*) = NULL;
81+
void(*ProcessSuspensionOriginal)(CAutomobile*) = NULL;
82+
void(*SetupSuspensionLinesOriginal)(CAutomobile*) = NULL;
83+
void(*DoBurstAndSoftGroundRatiosOriginal)(CAutomobile*) = NULL;
84+
void(*CAutomobileRenderOriginal)(CAutomobile*) = NULL;
85+
void(__fastcall *VehicleDamageOriginal)(CAutomobile*, void*, float, __int16, int, RwV3d*, RwV3d*, signed int) = NULL;
86+
char(__fastcall* BurstTyreOriginal)(CAutomobile*, void*, char, char) = NULL;
87+
int(__fastcall* ProcessEntityCollisionOriginal)(CAutomobile*, void*, CVehicle*, CColPoint*) = NULL;
88+
89+
8090
bool isGameModelPolice(int model)
8191
{
8292
switch (model)

ModelVariations/Vehicles.cpp

Lines changed: 254 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ int roadblockModel = -1;
2626
int passengerModelIndex = -1;
2727
const unsigned int jmp613B7E = 0x613B7E;
2828

29-
3029
int hasModelSideMission(int model)
3130
{
3231
switch (model)
@@ -54,7 +53,7 @@ bool isModelAmbulance(int model)
5453
bool isModelFiretruck(int model)
5554
{
5655
auto it = vehOriginalModels.find(model);
57-
if (it != vehOriginalModels.end() && (it->second == 407 || it->second == 544))
56+
if (it != vehOriginalModels.end() && it->second == 407)
5857
return true;
5958

6059
return false;
@@ -295,6 +294,20 @@ void __cdecl AddPoliceCarOccupantsHooked(CVehicle* a2, char a3)
295294
CAutomobile* __fastcall CAutomobileHooked(CAutomobile* automobile, void*, int modelIndex, char usageType, char bSetupSuspensionLines)
296295
{
297296
return CallMethodAndReturn<CAutomobile*, 0x6B0A90>(automobile, getRandomVariation(modelIndex), usageType, bSetupSuspensionLines);
297+
/*
298+
if (modelIndex != 432)
299+
return CallMethodAndReturn<CAutomobile*, 0x6B0A90>(automobile, getRandomVariation(modelIndex), usageType, bSetupSuspensionLines);
300+
else
301+
{
302+
int randomVariation = getRandomVariation(modelIndex);
303+
*((short*)0x6B0CF4) = randomVariation;
304+
*((short*)0x6B12D8) = randomVariation;
305+
CAutomobile* retVal = CallMethodAndReturn<CAutomobile*, 0x6B0A90>(automobile, randomVariation, usageType, bSetupSuspensionLines);
306+
*((short*)0x6B0CF4) = 0x1B0;
307+
*((short*)0x6B12D8) = 0x1B0;
308+
return retVal;
309+
}
310+
*/
298311
}
299312

300313
signed int __fastcall PickRandomCarHooked(CLoadedCarGroup* cargrp, void*, char a2, char a3) //for random parked cars
@@ -512,6 +525,204 @@ void __fastcall ProcessControlHooked(CVehicle* veh)
512525
}
513526
*/
514527

528+
void __fastcall ProcessControlHooked(CVehicle* veh)
529+
{
530+
if (veh && getVariationOriginalModel(veh->m_nModelIndex) == 407 || getVariationOriginalModel(veh->m_nModelIndex) == 601)
531+
{
532+
//EB 0A
533+
*((BYTE*)0x6B1F4F) = 0xEB;
534+
*((BYTE*)0x6B1F50) = 0x0A;
535+
plugin::CallMethod<0x6B1880>(veh);
536+
*((BYTE*)0x6B1F4F) = 0x66;
537+
*((BYTE*)0x6B1F50) = 0x3D;
538+
}/*
539+
else if (getVariationOriginalModel(veh->m_nModelIndex) == 432)
540+
{
541+
injector::MakeJMP(0x6B1F7B, 0x6B2026);
542+
injector::MakeNOP(0x6B36DA, 6);
543+
plugin::CallMethod<0x6B1880>(veh);
544+
((BYTE*)0x6B1F7B)[0] = 0x66;
545+
((BYTE*)0x6B1F7B)[1] = 0x3D;
546+
((BYTE*)0x6B1F7B)[2] = 0xB0;
547+
((BYTE*)0x6B1F7B)[3] = 0x01;
548+
((BYTE*)0x6B1F7B)[4] = 0x0F;
549+
550+
((BYTE*)0x6B36DA)[0] = 0x0F;
551+
((BYTE*)0x6B36DA)[1] = 0x85;
552+
((BYTE*)0x6B36DA)[2] = 0x95;
553+
((BYTE*)0x6B36DA)[3] = 0x00;
554+
((BYTE*)0x6B36DA)[4] = 0x00;
555+
((BYTE*)0x6B36DA)[5] = 0x00;
556+
}*/
557+
else
558+
plugin::CallMethod<0x6B1880>(veh);
559+
560+
}
561+
562+
void __fastcall PreRenderHooked(CAutomobile* veh)
563+
{
564+
if (veh && getVariationOriginalModel(veh->m_nModelIndex) == 407)
565+
{
566+
*((BYTE*)0x6ACA57) = 0xEB;
567+
*((BYTE*)0x6ACA58) = 0x04;
568+
PreRenderOriginal(veh);
569+
*((BYTE*)0x6ACA57) = 0x66;
570+
*((BYTE*)0x6ACA58) = 0x3D;
571+
}
572+
/*else if (getVariationOriginalModel(veh->m_nModelIndex) == 432)
573+
{
574+
*((short*)0x6ABC83) = veh->m_nModelIndex;
575+
*((short*)0x6ABD11) = veh->m_nModelIndex;
576+
*((short*)0x6ABFCC) = veh->m_nModelIndex;
577+
*((short*)0x6AC029) = veh->m_nModelIndex;
578+
*((short*)0x6ACA4D) = veh->m_nModelIndex;
579+
PreRenderOriginal(veh);
580+
*((short*)0x6ABC83) = 0x1B0;
581+
*((short*)0x6ABD11) = 0x1B0;
582+
*((short*)0x6ABFCC) = 0x1B0;
583+
*((short*)0x6AC029) = 0x1B0;
584+
*((short*)0x6ACA4D) = 0x1B0;
585+
}*/
586+
else if (getVariationOriginalModel(veh->m_nModelIndex) == 601)
587+
{
588+
*((short*)0x6ACA53) = veh->m_nModelIndex;
589+
PreRenderOriginal(veh);
590+
*((short*)0x6ACA53) = 0x259;
591+
}
592+
else
593+
PreRenderOriginal(veh);
594+
}
595+
596+
void __fastcall ProcessSuspensionHooked(CAutomobile* veh)
597+
{
598+
if (getVariationOriginalModel(veh->m_nModelIndex) == 432)
599+
{
600+
injector::MakeNOP(0x6B02A2, 6);
601+
*((short*)0x6AFB48) = veh->m_nModelIndex;
602+
603+
ProcessSuspensionOriginal(veh);
604+
((BYTE*)0x6B02A2)[0] = 0x0F;
605+
((BYTE*)0x6B02A2)[1] = 0x85;
606+
((BYTE*)0x6B02A2)[2] = 0x7B;
607+
((BYTE*)0x6B02A2)[3] = 0x01;
608+
((BYTE*)0x6B02A2)[4] = 0x00;
609+
((BYTE*)0x6B02A2)[5] = 0x00;
610+
*((short*)0x6AFB48) = 0x1B0;
611+
}
612+
else
613+
ProcessSuspensionOriginal(veh);
614+
}
615+
616+
void __fastcall SetupSuspensionLinesHooked(CAutomobile* veh)
617+
{
618+
if (getVariationOriginalModel(veh->m_nModelIndex) == 432)
619+
{
620+
*((short*)0x6A6606) = veh->m_nModelIndex;
621+
*((short*)0x6A6999) = veh->m_nModelIndex;
622+
SetupSuspensionLinesOriginal(veh);
623+
*((short*)0x6A6606) = 0x1B0;
624+
*((short*)0x6A6999) = 0x1B0;
625+
}
626+
else
627+
SetupSuspensionLinesOriginal(veh);
628+
}
629+
630+
void __fastcall TankControlHooked(CAutomobile* veh)
631+
{
632+
if (getVariationOriginalModel(veh->m_nModelIndex) == 432)
633+
{
634+
*((short*)0x6AE9CB) = veh->m_nModelIndex;
635+
veh->TankControl();
636+
*((short*)0x6AE9CB) = 0x1B0;
637+
}
638+
else
639+
veh->TankControl();
640+
}
641+
642+
void __fastcall VehicleDamageHooked(CAutomobile* veh, void* edx, float fDamageIntensity, __int16 tCollisionComponent, int Damager, RwV3d* vecCollisionCoors, RwV3d* vecCollisionDirection, signed int a7)
643+
{
644+
if (getVariationOriginalModel(veh->m_nModelIndex) == 432)
645+
{
646+
*((short*)0x6A80C0) = veh->m_nModelIndex;
647+
*((short*)0x6A8384) = veh->m_nModelIndex;
648+
VehicleDamageOriginal(veh, edx, fDamageIntensity, tCollisionComponent, Damager, vecCollisionCoors, vecCollisionDirection, a7);
649+
*((short*)0x6A80C0) = 0x1B0;
650+
*((short*)0x6A8384) = 0x1B0;
651+
}
652+
else
653+
VehicleDamageOriginal(veh, edx, fDamageIntensity, tCollisionComponent, Damager, vecCollisionCoors, vecCollisionDirection, a7);
654+
}
655+
656+
void __fastcall DoSoftGroundResistanceHooked(CAutomobile *veh, void*, unsigned int &a3)
657+
{
658+
if (getVariationOriginalModel(veh->m_nModelIndex) == 432)
659+
{
660+
*((short*)0x6A4BBA) = veh->m_nModelIndex;
661+
*((short*)0x6A4E0E) = veh->m_nModelIndex;
662+
veh->DoSoftGroundResistance(a3);
663+
*((short*)0x6A4BBA) = 0x1B0;
664+
*((short*)0x6A4E0E) = 0x1B0;
665+
}
666+
else
667+
veh->DoSoftGroundResistance(a3);
668+
}
669+
670+
void __fastcall DoBurstAndSoftGroundRatiosHooked(CAutomobile* a1)
671+
{
672+
if (getVariationOriginalModel(a1->m_nModelIndex) == 432)
673+
{
674+
*((short*)0x6A4917) = a1->m_nModelIndex;
675+
DoBurstAndSoftGroundRatiosOriginal(a1);
676+
*((short*)0x6A4917) = 0x1B0;
677+
}
678+
else
679+
DoBurstAndSoftGroundRatiosOriginal(a1);
680+
}
681+
682+
char __fastcall BurstTyreHooked(CAutomobile* veh, void *edx, char componentId, char a3)
683+
{
684+
char retVal = 0;
685+
if (getVariationOriginalModel(veh->m_nModelIndex) == 432)
686+
{
687+
*((short*)0x6A32BB) = veh->m_nModelIndex;
688+
retVal = BurstTyreOriginal(veh, edx, componentId, a3);
689+
*((short*)0x6A32BB) = 0x1B0;
690+
}
691+
else
692+
retVal = BurstTyreOriginal(veh, edx, componentId, a3);
693+
694+
return retVal;
695+
}
696+
697+
void __fastcall CAutomobileRenderHooked(CAutomobile* veh)
698+
{
699+
if (getVariationOriginalModel(veh->m_nModelIndex) == 432)
700+
{
701+
*((short*)0x6A2C2D) = veh->m_nModelIndex;
702+
*((short*)0x6A2EAD) = veh->m_nModelIndex;
703+
CAutomobileRenderOriginal(veh);
704+
*((short*)0x6A2C2D) = 0x1B0;
705+
*((short*)0x6A2EAD) = 0x1B0;
706+
}
707+
else
708+
CAutomobileRenderOriginal(veh);
709+
}
710+
/*
711+
int __fastcall ProcessEntityCollisionHooked(CAutomobile* veh, void* edx, CVehicle* collEntity, CColPoint* colPoint)
712+
{
713+
if (getVariationOriginalModel(veh->m_nModelIndex) == 432)
714+
{
715+
*((short*)0x6ACEE9) = veh->m_nModelIndex;
716+
*((short*)0x6AD242) = veh->m_nModelIndex;
717+
int retVal = ProcessEntityCollisionOriginal(veh, edx, collEntity, colPoint);
718+
*((short*)0x6ACEE9) = 0x1B0;
719+
*((short*)0x6AD242) = 0x1B0;
720+
return retVal;
721+
}
722+
723+
return ProcessEntityCollisionOriginal(veh, edx, collEntity, colPoint);
724+
}
725+
*/
515726
CColModel* __fastcall GetColModelHooked(CVehicle* entity)
516727
{
517728
if (roadblockModel >= 400)
@@ -679,9 +890,47 @@ void installVehicleHooks()
679890
patch::RedirectCall(0x431DF9, SetUpDriverAndPassengersForVehicleHooked); //CCarCtrl::GenerateOneRandomCar
680891
patch::RedirectCall(0x431ED1, SetUpDriverAndPassengersForVehicleHooked); //CCarCtrl::GenerateOneRandomCar
681892

682-
//DWORD** p;
683-
//p = reinterpret_cast<DWORD**>(0x871148);
684-
//*p = (DWORD*)ProcessControlHooked;
893+
if (iniVeh.ReadInteger("Settings", "EnableSpecialFeatures", 0))
894+
{
895+
DWORD** p = reinterpret_cast<DWORD**>(0x871148);
896+
*p = (DWORD*)ProcessControlHooked;
897+
898+
p = reinterpret_cast<DWORD**>(0x871164);
899+
PreRenderOriginal = *((void(**)(CAutomobile*))0x871164);
900+
*p = (DWORD*)PreRenderHooked;
901+
902+
//p = reinterpret_cast<DWORD**>(0x871238);
903+
//ProcessSuspensionOriginal = *((void(**)(CAutomobile*))0x871238);
904+
//*p = (DWORD*)ProcessSuspensionHooked;
905+
906+
//p = reinterpret_cast<DWORD**>(0x871200);
907+
//VehicleDamageOriginal = *((void(__fastcall**)(CAutomobile*, void*, float, __int16, int, RwV3d*, RwV3d*, signed int))0x871200);
908+
//*p = (DWORD*)VehicleDamageHooked;
909+
910+
//p = reinterpret_cast<DWORD**>(0x8711E0);
911+
//SetupSuspensionLinesOriginal = *((void(**)(CAutomobile*))0x8711E0);
912+
//*p = (DWORD*)SetupSuspensionLinesHooked;
913+
914+
//p = reinterpret_cast<DWORD**>(0x8711F0);
915+
//DoBurstAndSoftGroundRatiosOriginal = *((void(**)(CAutomobile*))0x8711F0);
916+
//*p = (DWORD*)DoBurstAndSoftGroundRatiosHooked;
917+
918+
//p = reinterpret_cast<DWORD**>(0x8711D0);
919+
//BurstTyreOriginal = *((char(__fastcall**)(CAutomobile*, void*, char, char))0x8711D0);
920+
//*p = (DWORD*)BurstTyreHooked;
921+
922+
//p = reinterpret_cast<DWORD**>(0x871168);
923+
//CAutomobileRenderOriginal = *((void(**)(CAutomobile*))0x871168);
924+
//*p = (DWORD*)CAutomobileRenderHooked;
925+
926+
////p = reinterpret_cast<DWORD**>(0x871178);
927+
////ProcessEntityCollisionOriginal = *((int(__fastcall**)(CAutomobile*, void*, CVehicle*, CColPoint*))0x871178);
928+
////*p = (DWORD*)ProcessEntityCollisionHooked;
929+
930+
//patch::RedirectCall(0x6B2028, TankControlHooked); //CAutomobile::ProcessControl
931+
//patch::RedirectCall(0x6B51B8, DoSoftGroundResistanceHooked); //CAutomobile::ProcessAI
932+
933+
}
685934

686935
if (iniVeh.ReadInteger("Settings", "EnableSiren", 0))
687936
patch::RedirectCall(0x6D8492, HasCarSiren); //CVehicle::UsesSiren

ModelVariations/Vehicles.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "IniReader/IniReader.h"
44

55
#include "CPed.h"
6+
#include "CAutomobile.h"
67

78
#include <vector>
89
#include <unordered_set>
@@ -24,6 +25,14 @@ extern int changeCarGenerators;
2425
extern bool isPlayerInTaxi;
2526
extern bool enableSideMissions;
2627
extern int enableAllSideMissions;
28+
extern void(*PreRenderOriginal)(CAutomobile*);
29+
extern void(*ProcessSuspensionOriginal)(CAutomobile*);
30+
extern void(*SetupSuspensionLinesOriginal)(CAutomobile*);
31+
extern void(*DoBurstAndSoftGroundRatiosOriginal)(CAutomobile*);
32+
extern void(*CAutomobileRenderOriginal)(CAutomobile*);
33+
extern void(__fastcall *VehicleDamageOriginal)(CAutomobile*, void*, float, __int16, int, RwV3d*, RwV3d*, signed int);
34+
extern char(__fastcall *BurstTyreOriginal)(CAutomobile*, void*, char, char);
35+
extern int(__fastcall *ProcessEntityCollisionOriginal)(CAutomobile*, void*, CVehicle*, CColPoint*);
2736

2837
extern std::vector<short> iniLineParser(eVariationType type, int section, const char key[12], CIniReader* ini);
2938
extern void vectorUnion(std::vector<short>& vec1, std::vector<short>& vec2, std::vector<short>& dest);

0 commit comments

Comments
 (0)