Skip to content

Commit 7faa918

Browse files
committed
sirens: Improve hkUsesSiren Hook
1 parent 22257b9 commit 7faa918

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/features/sirens.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bool IsValidSirenVehicle(RwFrame *pFrame)
4242

4343
std::map<CVehicle *, bool> sirenExtraUsedFlag;
4444

45-
char __fastcall Sirens::hkUsesSiren(CVehicle *ptr)
45+
bool Sirens::hkUsesSiren(std::function<hkUsesSirenFunc> originalCall, CVehicle* ptr)
4646
{
4747
if (Util::IsEngineOff(ptr))
4848
{
@@ -55,12 +55,13 @@ char __fastcall Sirens::hkUsesSiren(CVehicle *ptr)
5555
sirenExtraUsedFlag[ptr] = IsValidSirenVehicle((RwFrame *)ptr->m_pRwClump->object.parent);
5656
}
5757

58-
if (Sirens::modelData.contains(ptr->m_nModelIndex) && sirenExtraUsedFlag[ptr])
58+
if (modelData.contains(ptr->m_nModelIndex) && sirenExtraUsedFlag[ptr])
5959
{
6060
ptr->m_vehicleAudio.m_bModelWithSiren = true;
6161
return true;
6262
}
63-
return ptr->IsLawEnforcementVehicle();
63+
64+
return originalCall(ptr);
6465
}
6566

6667
static ThiscallEvent<AddressList<0x6AAB71, H_CALL>, PRIORITY_BEFORE, ArgPickN<CVehicle*, 0>, void(CVehicle*)> Automobile__PreRenderEvent;
@@ -924,7 +925,8 @@ void Sirens::Init()
924925
ModelInfoMgr::EnableSirenMaterial(vehicle, mat.first);
925926
} });
926927

927-
patch::ReplaceFunctionCall(0x6D8492, (void *)hkUsesSiren);
928+
using hkUsesSirenHook = injector::function_hooker_thiscall<injector::scoped_call, 0x6D8492, hkUsesSirenFunc>;
929+
injector::make_static_hook<hkUsesSirenHook>(hkUsesSiren);
928930

929931
Automobile__PreRenderEvent += [](CVehicle* pVeh) {
930932
pCurrentVeh = pVeh; // Captured for hkAddPointLights()

src/features/sirens.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,11 @@ class Sirens : public CBaseFeature
207207
static inline std::map<int, VehicleSirenData *> modelData;
208208
static inline std::map<int, std::vector<VehicleDummy *>> modelRotators;
209209

210+
using hkUsesSirenFunc = bool(CVehicle*);
210211
using hkRegisterCoronaFunc = void(unsigned int&, CEntity *&, unsigned char&, unsigned char&, unsigned char&, unsigned char&, const CVector&, float&, float&, eCoronaType&, eCoronaFlareType&, bool&, bool&, int&, float&, bool&, float&, unsigned char&, float&, bool&, bool&);
211212
using hkAddPointLightsFunc = void(unsigned char&, CVector&, CVector&, float&, float&, float&, float&, unsigned char&, bool&, CEntity*&);
212213

213-
static char __fastcall hkUsesSiren(CVehicle *ptr);
214+
static bool hkUsesSiren(std::function<hkUsesSirenFunc> originalCall, CVehicle* ptr);
214215
static void hkRegisterCorona(std::function<hkRegisterCoronaFunc> originalCall, unsigned int& id, CEntity*& attachTo, unsigned char& red, unsigned char& green, unsigned char& blue, unsigned char& alpha, const CVector& posn, float& radius, float& farClip, eCoronaType& coronaType, eCoronaFlareType& flaretype, bool& enableReflection, bool& checkObstacles, int& _param_not_used, float& angle, bool& longDistance, float& nearClip, unsigned char& fadeState, float& fadeSpeed, bool& onlyFromBelow, bool& reflectionDelay);
215216
static void hkAddPointLights(std::function<hkAddPointLightsFunc> originalCall, uint8_t& type, CVector& position, CVector& direction, float& range, float& red, float& green, float& blue, uint8_t& fogEffect, bool& bCastsShadowFromPlayerCarAndPed, CEntity*& castingEntity);
216217

0 commit comments

Comments
 (0)