From 4679873c3aa6c49358a1ee84ecd9492aa5865292 Mon Sep 17 00:00:00 2001 From: Silent Date: Wed, 25 Dec 2019 17:40:59 +0100 Subject: [PATCH] VC: Make drive-by one shot sounds owned by the driver instead of the car --- SilentPatchVC/SilentPatchVC.cpp | 13 +++++++++++++ SilentPatchVC/SilentPatchVC.vcxproj | 1 + SilentPatchVC/SilentPatchVC.vcxproj.filters | 3 +++ SilentPatchVC/VehicleVC.cpp | 15 +++++++++++++++ SilentPatchVC/VehicleVC.h | 8 +++++++- 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 SilentPatchVC/VehicleVC.cpp diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index ef74c7d..06df663 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -1130,6 +1130,19 @@ void Patch_VC_Common() static const float MULT_6 = 6.0f; Patch( extraMult6, &MULT_6 ); } + + + // Make drive-by one shot sounds owned by the driver instead of the car + // Fixes incorrect weapon sound being used for drive-by + { + auto getDriverOneShot = pattern( "FF 35 ? ? ? ? 6A 37 50 E8 ? ? ? ? 83 7E 08 00" ).get_one(); + + // nop + // mov ecx, ebx + // call CVehicle::GetOneShotOwnerID + Patch( getDriverOneShot.get( -8 ), { 0x90, 0x89, 0xD9 } ); + InjectHook( getDriverOneShot.get( -5 ), &CVehicle::GetOneShotOwnerID_SilentPatch, PATCH_CALL ); + } } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) diff --git a/SilentPatchVC/SilentPatchVC.vcxproj b/SilentPatchVC/SilentPatchVC.vcxproj index 72b1ba6..f15d9c3 100644 --- a/SilentPatchVC/SilentPatchVC.vcxproj +++ b/SilentPatchVC/SilentPatchVC.vcxproj @@ -220,6 +220,7 @@ Create Create + diff --git a/SilentPatchVC/SilentPatchVC.vcxproj.filters b/SilentPatchVC/SilentPatchVC.vcxproj.filters index e116df4..e61b197 100644 --- a/SilentPatchVC/SilentPatchVC.vcxproj.filters +++ b/SilentPatchVC/SilentPatchVC.vcxproj.filters @@ -92,6 +92,9 @@ Source Files + + Source Files + diff --git a/SilentPatchVC/VehicleVC.cpp b/SilentPatchVC/VehicleVC.cpp new file mode 100644 index 0000000..1d6e230 --- /dev/null +++ b/SilentPatchVC/VehicleVC.cpp @@ -0,0 +1,15 @@ +#include "StdAfx.h" +#include "VehicleVC.h" + +int32_t CVehicle::GetOneShotOwnerID_SilentPatch() const +{ + if ( m_pDriver != nullptr ) + { + // TODO: Define this as a proper CPhysical + uintptr_t ptr = reinterpret_cast(m_pDriver); + return *reinterpret_cast( ptr + 0x64 ); + } + + // Fallback + return m_audioEntityId; +} diff --git a/SilentPatchVC/VehicleVC.h b/SilentPatchVC/VehicleVC.h index 0cf5fab..ffa00c0 100644 --- a/SilentPatchVC/VehicleVC.h +++ b/SilentPatchVC/VehicleVC.h @@ -21,8 +21,12 @@ protected: CMatrix m_matrix; uint8_t __pad4[16]; uint16_t m_modelIndex; // TODO: THE FLA + void* m_pFirstReference; + int32_t m_audioEntityId; // TODO: This should really be CPhysical + uint8_t __pad5[320]; + void* m_pDriver; - uint8_t __pad1[414]; + uint8_t __pad1[80]; uint8_t m_BombOnBoard : 3; uint8_t __pad2[17]; class CEntity* m_pBombOwner; @@ -44,6 +48,8 @@ public: { m_BombOnBoard = bombOnBoard; } void SetBombOwner( class CEntity* owner ) { m_pBombOwner = owner; } + + int32_t GetOneShotOwnerID_SilentPatch() const; }; class CAutomobile : public CVehicle