From 4bf700621b95a9284756ef44a643a8172ef42161 Mon Sep 17 00:00:00 2001 From: Peter Marton Date: Mon, 21 Oct 2024 12:14:47 +0200 Subject: [PATCH] fix(game): sync for custom radio stations --- .../src/PatchVehicleRadioSync.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 code/components/gta-core-five/src/PatchVehicleRadioSync.cpp diff --git a/code/components/gta-core-five/src/PatchVehicleRadioSync.cpp b/code/components/gta-core-five/src/PatchVehicleRadioSync.cpp new file mode 100644 index 0000000000..bd658b9436 --- /dev/null +++ b/code/components/gta-core-five/src/PatchVehicleRadioSync.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + +static hook::cdecl_stub GetRadioStationByArrayIndex([]() +{ + return hook::get_pattern("3B 0D ? ? ? ? 73 ? 48 8B 05 ? ? ? ? 8B C9"); +}); + +static hook::cdecl_stub GetRadioStationArrayIndex([]() +{ + return hook::get_pattern("44 8B 05 ? ? ? ? 33 C0 45 85 C0 74 ? 48 8B 15"); +}); + +void* GetRadioStationByMetaIndex(int idx, int unk) +{ + return GetRadioStationByArrayIndex(idx); +} + +int GetRadioStationMetaIndex(void* station, int unk) +{ + return GetRadioStationArrayIndex(station); +} + +static HookFunction hookFunction([]() +{ + if(xbr::IsGameBuildOrGreater<2944>()) + { + auto location = hook::get_pattern("E8 ? ? ? ? 48 83 BB ? ? ? ? ? 48 8B F0 48 89 83"); + hook::call(location, GetRadioStationByMetaIndex); + + location = hook::get_pattern("E8 ? ? ? ? 83 C0 ? 89 83"); + hook::call(location, GetRadioStationMetaIndex); + } +});