From fcc799645fdf3cb31ae0734866a916ee07ae694f Mon Sep 17 00:00:00 2001 From: Silent Date: Tue, 27 Mar 2018 22:28:45 +0200 Subject: [PATCH] Extras working correctly on bikes - VC --- SilentPatch/General.h | 2 ++ SilentPatchVC/ModelInfoVC.cpp | 24 +++++++++++++++++++++ SilentPatchVC/ModelInfoVC.h | 18 ++++++++++++++++ SilentPatchVC/SilentPatchVC.cpp | 19 ++++++++++++++++ SilentPatchVC/SilentPatchVC.vcxproj | 2 ++ SilentPatchVC/SilentPatchVC.vcxproj.filters | 6 ++++++ 6 files changed, 71 insertions(+) create mode 100644 SilentPatchVC/ModelInfoVC.cpp create mode 100644 SilentPatchVC/ModelInfoVC.h diff --git a/SilentPatch/General.h b/SilentPatch/General.h index 8ddaa74..7896791 100644 --- a/SilentPatch/General.h +++ b/SilentPatch/General.h @@ -1,6 +1,8 @@ #ifndef __GENERAL #define __GENERAL +#include + class CRGBA { public: diff --git a/SilentPatchVC/ModelInfoVC.cpp b/SilentPatchVC/ModelInfoVC.cpp new file mode 100644 index 0000000..1be50aa --- /dev/null +++ b/SilentPatchVC/ModelInfoVC.cpp @@ -0,0 +1,24 @@ +#include "StdAfx.h" +#include "ModelInfoVC.h" + +#include "VehicleVC.h" + +auto GetFrameFromId = hook::get_pattern( "8B 4C 24 0C 89 04 24", -7 ); + +RwFrame* CVehicleModelInfo::GetExtrasFrame( RpClump* clump ) +{ + RwFrame* frame; + if ( m_dwType == VEHICLE_AUTOMOBILE || m_dwType == VEHICLE_BIKE ) + { + frame = GetFrameFromId( clump, 1 ); + if ( frame == nullptr ) + { + frame = RpClumpGetFrame( clump ); + } + } + else + { + frame = RpClumpGetFrame( clump ); + } + return frame; +} \ No newline at end of file diff --git a/SilentPatchVC/ModelInfoVC.h b/SilentPatchVC/ModelInfoVC.h new file mode 100644 index 0000000..ff87aa6 --- /dev/null +++ b/SilentPatchVC/ModelInfoVC.h @@ -0,0 +1,18 @@ +#pragma once + +#include "General.h" +#include +#include + +class CVehicleModelInfo +{ +private: + uint8_t __pad1[60]; + unsigned int m_dwType; + uint8_t __pad2[308]; + +public: + RwFrame* GetExtrasFrame( RpClump* clump ); +}; + +static_assert(sizeof(CVehicleModelInfo) == 0x174, "Wrong size: CvehicleModelInfo"); \ No newline at end of file diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index f0b9815..2dc54a7 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -5,6 +5,7 @@ #include "Common.h" #include "Common_ddraw.h" #include "General.h" +#include "ModelInfoVC.h" #include @@ -146,6 +147,17 @@ void __declspec(naked) SubtitlesShadowFix() } } +void __declspec(naked) CreateInstance_BikeFix() +{ + _asm + { + push eax + mov ecx, ebp + call CVehicleModelInfo::GetExtrasFrame + retn + } +} + extern char** ppUserFilesDir = AddressByVersion(0x6022AA, 0x60228A, 0x601ECA); static LARGE_INTEGER FrameTime; @@ -666,6 +678,13 @@ void Patch_VC_Common() InjectHook( give_weapon, GiveWeapon_SP ); } + + // Extras working correctly on bikes + { + auto createInstance = get_pattern( "89 C1 8B 41 04" ); + InjectHook( createInstance, CreateInstance_BikeFix, PATCH_CALL ); + } + } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) diff --git a/SilentPatchVC/SilentPatchVC.vcxproj b/SilentPatchVC/SilentPatchVC.vcxproj index bb05501..cc922e9 100644 --- a/SilentPatchVC/SilentPatchVC.vcxproj +++ b/SilentPatchVC/SilentPatchVC.vcxproj @@ -181,6 +181,7 @@ + @@ -201,6 +202,7 @@ + Create diff --git a/SilentPatchVC/SilentPatchVC.vcxproj.filters b/SilentPatchVC/SilentPatchVC.vcxproj.filters index c0ca74b..5d2ed8e 100644 --- a/SilentPatchVC/SilentPatchVC.vcxproj.filters +++ b/SilentPatchVC/SilentPatchVC.vcxproj.filters @@ -39,6 +39,9 @@ Header Files + + Header Files + @@ -62,6 +65,9 @@ Source Files + + Source Files +