From fe712ee06b8845a9241b6d514bc7dfdb2a5689d0 Mon Sep 17 00:00:00 2001 From: AmeerDotEXE Date: Sun, 29 Mar 2026 16:05:24 +0300 Subject: [PATCH 1/3] sirens: Improve `hkRegisterCorona` Hook --- src/features/sirens.cpp | 23 +++++++++-------------- src/features/sirens.h | 4 +++- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/features/sirens.cpp b/src/features/sirens.cpp index 8662ddd7..954bea94 100755 --- a/src/features/sirens.cpp +++ b/src/features/sirens.cpp @@ -932,30 +932,25 @@ void Sirens::Init() Events::initGameEvent += [] { - injector::MakeCALL((void *)0x6ABA60, hkRegisterCorona, true); - injector::MakeCALL((void *)0x6ABB35, hkRegisterCorona, true); - injector::MakeCALL((void *)0x6ABC69, hkRegisterCorona, true); - injector::MakeCALL((void *)0x6BD4DD, hkRegisterCorona, true); - injector::MakeCALL((void *)0x6BD531, hkRegisterCorona, true); + using hkRegisterCoronaHook = injector::function_hooker; + injector::make_static_hook_dyn(hkRegisterCorona, 0x6ABA60); + injector::make_static_hook_dyn(hkRegisterCorona, 0x6ABB35); + injector::make_static_hook_dyn(hkRegisterCorona, 0x6ABC69); + injector::make_static_hook_dyn(hkRegisterCorona, 0x6BD4DD); + injector::make_static_hook_dyn(hkRegisterCorona, 0x6BD531); }; }; -void Sirens::hkRegisterCorona(unsigned int id, CEntity *attachTo, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha, CVector const &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) +void Sirens::hkRegisterCorona(std::function 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) { - CVehicle *vehicle = NULL; - - _asm { - pushad - mov vehicle, esi - popad - } + CVehicle *vehicle = (CVehicle*)attachTo; if (vehicle && modelData.contains(vehicle->m_nModelIndex)) { return; } - CCoronas::RegisterCorona(id, attachTo, red, green, blue, alpha, posn, radius, farClip, coronaType, flaretype, enableReflection, checkObstacles, _param_not_used, angle, longDistance, nearClip, fadeState, fadeSpeed, onlyFromBelow, reflectionDelay); + originalCall(id, attachTo, red, green, blue, alpha, posn, radius, farClip, coronaType, flaretype, enableReflection, checkObstacles, _param_not_used, angle, longDistance, nearClip, fadeState, fadeSpeed, onlyFromBelow, reflectionDelay); } void Sirens::EnableDummy(int id, VehicleDummy *dummy, CVehicle *vehicle, VehicleSirenMaterial *material, eCoronaFlareType type, uint64_t time) diff --git a/src/features/sirens.h b/src/features/sirens.h index 5c6ed26e..6ac048b2 100755 --- a/src/features/sirens.h +++ b/src/features/sirens.h @@ -207,8 +207,10 @@ class Sirens : public CBaseFeature static inline std::map modelData; static inline std::map> modelRotators; + 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&); + static char __fastcall hkUsesSiren(CVehicle *ptr); - static void hkRegisterCorona(unsigned int id, CEntity *attachTo, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha, CVector const &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); + static void hkRegisterCorona(std::function 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); static void __cdecl hkAddPointLights(uint8_t type, float px, float py, float pz, float dx, float dy, float dz, float range, float red, float green, float blue, uint8_t fogEffect, bool bCastsShadowFromPlayerCarAndPed, CEntity* castingEntity); static void RegisterMaterial(CVehicle *vehicle, RpMaterial *material); From 22257b99706735fc93dd6b013c967c65e5582397 Mon Sep 17 00:00:00 2001 From: AmeerDotEXE Date: Sun, 29 Mar 2026 22:08:55 +0300 Subject: [PATCH 2/3] sirens: Improve `hkAddPointLights` Hook --- src/features/sirens.cpp | 39 +++++++++++++++++++++------------------ src/features/sirens.h | 5 +++-- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/features/sirens.cpp b/src/features/sirens.cpp index 954bea94..e393fcf0 100755 --- a/src/features/sirens.cpp +++ b/src/features/sirens.cpp @@ -63,12 +63,8 @@ char __fastcall Sirens::hkUsesSiren(CVehicle *ptr) return ptr->IsLawEnforcementVehicle(); } +static ThiscallEvent, PRIORITY_BEFORE, ArgPickN, void(CVehicle*)> Automobile__PreRenderEvent; static CVehicle *pCurrentVeh = nullptr; -void __fastcall hkVehiclePreRender(CVehicle *ptr) -{ - pCurrentVeh = ptr; - CallMethod<0x6D6480>(ptr); -} void Sirens::Reload(CVehicle *pVeh) { @@ -81,20 +77,22 @@ void Sirens::Reload(CVehicle *pVeh) } void Sirens::hkAddPointLights( - uint8_t type, - float px, float py, float pz, - float dx, float dy, float dz, - float range, - float red, float green, float blue, - uint8_t fogEffect, - bool bCastsShadowFromPlayerCarAndPed, - CEntity* castingEntity + std::function originalCall, + uint8_t& type, + CVector& position, + CVector& direction, + float& range, + float& red, float& green, float& blue, + uint8_t& fogEffect, + bool& bCastsShadowFromPlayerCarAndPed, + CEntity*& castingEntity ) { - if (pCurrentVeh == nullptr) return; - if (Sirens::modelData.contains(pCurrentVeh->m_nModelIndex)) return; + if (pCurrentVeh && modelData.contains(pCurrentVeh->m_nModelIndex)) { + return; + } - CPointLights::AddLight(type, {px, py, pz}, {dx, dy, dz}, range, red, green, blue, fogEffect, bCastsShadowFromPlayerCarAndPed, castingEntity); + originalCall(type, position, direction, range, red, green, blue, fogEffect, bCastsShadowFromPlayerCarAndPed, castingEntity); } VehicleSirenMaterial::VehicleSirenMaterial(std::string state, int material, nlohmann::json json) @@ -927,8 +925,13 @@ void Sirens::Init() } }); patch::ReplaceFunctionCall(0x6D8492, (void *)hkUsesSiren); - patch::ReplaceFunctionCall(0x6AB80F, (void *)hkAddPointLights); - patch::ReplaceFunctionCall(0x6AAB71, (void *)hkVehiclePreRender); + + Automobile__PreRenderEvent += [](CVehicle* pVeh) { + pCurrentVeh = pVeh; // Captured for hkAddPointLights() + }; + + using hkAddPointLightsHook = injector::function_hooker; + injector::make_static_hook(hkAddPointLights); Events::initGameEvent += [] { diff --git a/src/features/sirens.h b/src/features/sirens.h index 6ac048b2..9751acc7 100755 --- a/src/features/sirens.h +++ b/src/features/sirens.h @@ -208,10 +208,11 @@ class Sirens : public CBaseFeature static inline std::map> modelRotators; 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&); - + using hkAddPointLightsFunc = void(unsigned char&, CVector&, CVector&, float&, float&, float&, float&, unsigned char&, bool&, CEntity*&); + static char __fastcall hkUsesSiren(CVehicle *ptr); static void hkRegisterCorona(std::function 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); - static void __cdecl hkAddPointLights(uint8_t type, float px, float py, float pz, float dx, float dy, float dz, float range, float red, float green, float blue, uint8_t fogEffect, bool bCastsShadowFromPlayerCarAndPed, CEntity* castingEntity); + static void hkAddPointLights(std::function originalCall, uint8_t& type, CVector& position, CVector& direction, float& range, float& red, float& green, float& blue, uint8_t& fogEffect, bool& bCastsShadowFromPlayerCarAndPed, CEntity*& castingEntity); static void RegisterMaterial(CVehicle *vehicle, RpMaterial *material); static void EnableDummy(int id, VehicleDummy *dummy, CVehicle *vehicle, VehicleSirenMaterial *material, eCoronaFlareType type, uint64_t time); From 7faa91803e5153ff1ae632d564d32d7b2bb2a04e Mon Sep 17 00:00:00 2001 From: AmeerDotEXE Date: Sun, 29 Mar 2026 22:27:25 +0300 Subject: [PATCH 3/3] sirens: Improve `hkUsesSiren` Hook --- src/features/sirens.cpp | 10 ++++++---- src/features/sirens.h | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/features/sirens.cpp b/src/features/sirens.cpp index e393fcf0..0fcfe462 100755 --- a/src/features/sirens.cpp +++ b/src/features/sirens.cpp @@ -42,7 +42,7 @@ bool IsValidSirenVehicle(RwFrame *pFrame) std::map sirenExtraUsedFlag; -char __fastcall Sirens::hkUsesSiren(CVehicle *ptr) +bool Sirens::hkUsesSiren(std::function originalCall, CVehicle* ptr) { if (Util::IsEngineOff(ptr)) { @@ -55,12 +55,13 @@ char __fastcall Sirens::hkUsesSiren(CVehicle *ptr) sirenExtraUsedFlag[ptr] = IsValidSirenVehicle((RwFrame *)ptr->m_pRwClump->object.parent); } - if (Sirens::modelData.contains(ptr->m_nModelIndex) && sirenExtraUsedFlag[ptr]) + if (modelData.contains(ptr->m_nModelIndex) && sirenExtraUsedFlag[ptr]) { ptr->m_vehicleAudio.m_bModelWithSiren = true; return true; } - return ptr->IsLawEnforcementVehicle(); + + return originalCall(ptr); } static ThiscallEvent, PRIORITY_BEFORE, ArgPickN, void(CVehicle*)> Automobile__PreRenderEvent; @@ -924,7 +925,8 @@ void Sirens::Init() ModelInfoMgr::EnableSirenMaterial(vehicle, mat.first); } }); - patch::ReplaceFunctionCall(0x6D8492, (void *)hkUsesSiren); + using hkUsesSirenHook = injector::function_hooker_thiscall; + injector::make_static_hook(hkUsesSiren); Automobile__PreRenderEvent += [](CVehicle* pVeh) { pCurrentVeh = pVeh; // Captured for hkAddPointLights() diff --git a/src/features/sirens.h b/src/features/sirens.h index 9751acc7..4e925e49 100755 --- a/src/features/sirens.h +++ b/src/features/sirens.h @@ -207,10 +207,11 @@ class Sirens : public CBaseFeature static inline std::map modelData; static inline std::map> modelRotators; + using hkUsesSirenFunc = bool(CVehicle*); 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&); using hkAddPointLightsFunc = void(unsigned char&, CVector&, CVector&, float&, float&, float&, float&, unsigned char&, bool&, CEntity*&); - static char __fastcall hkUsesSiren(CVehicle *ptr); + static bool hkUsesSiren(std::function originalCall, CVehicle* ptr); static void hkRegisterCorona(std::function 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); static void hkAddPointLights(std::function originalCall, uint8_t& type, CVector& position, CVector& direction, float& range, float& red, float& green, float& blue, uint8_t& fogEffect, bool& bCastsShadowFromPlayerCarAndPed, CEntity*& castingEntity);