From 30c10a9a2590538ad6125666aab6b912c76241e7 Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 3 Feb 2019 14:09:29 +0100 Subject: [PATCH] Added more options to debug menu (rotor fix, small steam texts, minimal HUD) --- SilentPatchSA/SilentPatchSA.cpp | 97 +++++++++++++++++++++++++++++---- SilentPatchSA/VehicleSA.cpp | 20 ++++--- SilentPatchSA/VehicleSA.h | 3 +- 3 files changed, 99 insertions(+), 21 deletions(-) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index c59a109..ba9bc61 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -2331,6 +2331,48 @@ static const float fSteamRadioNamePosY = 33.0f; static const float fSteamRadioNameSizeX = 0.4f; static const float fSteamRadioNameSizeY = 0.6f; +static float* orgSubtitleSizeX; +static float* orgSubtitleSizeY; +static float* orgRadioNamePosY; +static float* orgRadioNameSizeX; +static float* orgRadioNameSizeY; + +static void ToggleSteamTexts( bool enable ) +{ + using namespace Memory::VP; + + if ( enable ) + { + Patch(0x58C387, &fSteamSubtitleSizeY); + Patch(0x58C40F, &fSteamSubtitleSizeY); + Patch(0x58C4CE, &fSteamSubtitleSizeY); + + Patch(0x58C39D, &fSteamSubtitleSizeX); + Patch(0x58C425, &fSteamSubtitleSizeX); + Patch(0x58C4E4, &fSteamSubtitleSizeX); + + Patch(0x4E9FD8, &fSteamRadioNamePosY); + Patch(0x4E9F22, &fSteamRadioNameSizeY); + Patch(0x4E9F38, &fSteamRadioNameSizeX); + } + else + { + assert( orgSubtitleSizeY != nullptr && orgSubtitleSizeX != nullptr && orgRadioNamePosY != nullptr && orgRadioNameSizeY != nullptr && orgRadioNameSizeX != nullptr ); + + Patch(0x58C387, orgSubtitleSizeY); + Patch(0x58C40F, orgSubtitleSizeY); + Patch(0x58C4CE, orgSubtitleSizeY); + + Patch(0x58C39D, orgSubtitleSizeX); + Patch(0x58C425, orgSubtitleSizeX); + Patch(0x58C4E4, orgSubtitleSizeX); + + Patch(0x4E9FD8, orgRadioNamePosY); + Patch(0x4E9F22, orgRadioNameSizeY); + Patch(0x4E9F38, orgRadioNameSizeX); + } +} + static const double dRetailSubtitleSizeX = 0.58; static const double dRetailSubtitleSizeY = 1.2; static const double dRetailSubtitleSizeY2 = 1.22; @@ -2425,20 +2467,29 @@ BOOL InjectDelayedPatches_10() Patch(AddressByRegion_10(0x748AA8), 0x3DEB); } - if ( GetPrivateProfileIntW(L"SilentPatch", L"SmallSteamTexts", -1, wcModulePath) == 1 ) { - // We're on 1.0 - make texts smaller - Patch(0x58C387, &fSteamSubtitleSizeY); - Patch(0x58C40F, &fSteamSubtitleSizeY); - Patch(0x58C4CE, &fSteamSubtitleSizeY); + static bool bSmallSteamTexts = false; + if ( bHasDebugMenu ) + { + orgSubtitleSizeX = *(float**)0x58C39D; + orgSubtitleSizeY = *(float**)0x58C387; + orgRadioNamePosY = *(float**)0x4E9FD8; + orgRadioNameSizeY = *(float**)0x4E9F22; + orgRadioNameSizeX = *(float**)0x4E9F38; - Patch(0x58C39D, &fSteamSubtitleSizeX); - Patch(0x58C425, &fSteamSubtitleSizeX); - Patch(0x58C4E4, &fSteamSubtitleSizeX); + DebugMenuAddVar( "SilentPatch", "Small Steam texts", &bSmallSteamTexts, []() { + ToggleSteamTexts( bSmallSteamTexts ); + } ); + + } - Patch(0x4E9FD8, &fSteamRadioNamePosY); - Patch(0x4E9F22, &fSteamRadioNameSizeY); - Patch(0x4E9F38, &fSteamRadioNameSizeX); + if ( GetPrivateProfileIntW(L"SilentPatch", L"SmallSteamTexts", -1, wcModulePath) == 1 ) + { + // We're on 1.0 - make texts smaller + ToggleSteamTexts( true ); + + bSmallSteamTexts = true; + } } if ( const int INIoption = GetPrivateProfileIntW(L"SilentPatch", L"ColouredZoneNames", -1, wcModulePath); INIoption != -1 ) @@ -2602,6 +2653,24 @@ BOOL InjectDelayedPatches_10() Patch( 0x588905 + 1, 0 ); } + if ( bHasDebugMenu ) + { + static bool bMinimalHUDEnabled = INIoption == 1; + DebugMenuAddVar( "SilentPatch", "Minimal HUD", &bMinimalHUDEnabled, []() { + if ( bMinimalHUDEnabled ) + { + Memory::VP::Patch( 0x588905 + 1, 0 ); + } + else + { + Memory::VP::Patch( 0x588905 + 1, 5 ); + } + + // Call CHud::ReInitialise + auto ReInitialise = (void(*)())0x588880; + ReInitialise(); + } ); + } } // Moonphases @@ -2690,7 +2759,11 @@ BOOL InjectDelayedPatches_10() if ( bHasDebugMenu ) { static const char * const str[] = { "Off", "Default", "On" }; - DebugMenuEntry *e = DebugMenuAddVar( "SilentPatch", "Lightbeam fix", &CVehicle::ms_lightbeamFixOverride, nullptr, 1, -1, 1, str); + + DebugMenuEntry *e = DebugMenuAddVar( "SilentPatch", "Rotors fix", &CVehicle::ms_rotorFixOverride, nullptr, 1, -1, 1, str); + DebugMenuEntrySetWrap(e, true); + + e = DebugMenuAddVar( "SilentPatch", "Lightbeam fix", &CVehicle::ms_lightbeamFixOverride, nullptr, 1, -1, 1, str); DebugMenuEntrySetWrap(e, true); } diff --git a/SilentPatchSA/VehicleSA.cpp b/SilentPatchSA/VehicleSA.cpp index f06a837..c79a9ee 100644 --- a/SilentPatchSA/VehicleSA.cpp +++ b/SilentPatchSA/VehicleSA.cpp @@ -233,9 +233,13 @@ bool __stdcall CheckDoubleRWheelsList( void* modelInfo, uint8_t* handlingData ) // Now left only for "backwards compatibility" -static bool ShouldIgnoreRotor( int32_t id ) +bool CVehicle::IgnoresRotorFix() const { - return SVF::ModelHasFeature( id, SVF::Feature::NO_ROTOR_FADE ); + if ( ms_rotorFixOverride != 0 ) + { + return ms_rotorFixOverride < 0; + } + return SVF::ModelHasFeature( m_nModelIndex.Get(), SVF::Feature::NO_ROTOR_FADE ); } static void* varVehicleRender = AddressByVersion(0x6D0E60, 0x6D1680, 0x70C0B0); @@ -482,9 +486,9 @@ CPed* CVehicle::PickRandomPassenger() void CHeli::Render() { double dRotorsSpeed, dMovingRotorSpeed; - bool bDisplayRotors = !ShouldIgnoreRotor( m_nModelIndex.Get() ); - bool bHasMovingRotor = m_pCarNode[13] != nullptr && bDisplayRotors; - bool bHasMovingRotor2 = m_pCarNode[15] != nullptr && bDisplayRotors; + const bool bDisplayRotors = !IgnoresRotorFix(); + const bool bHasMovingRotor = m_pCarNode[13] != nullptr && bDisplayRotors; + const bool bHasMovingRotor2 = m_pCarNode[15] != nullptr && bDisplayRotors; m_nTimeTillWeNeedThisCar = CTimer::m_snTimeInMilliseconds + 3000; @@ -534,9 +538,9 @@ void CHeli::Render() void CPlane::Render() { double dRotorsSpeed, dMovingRotorSpeed; - bool bDisplayRotors = !ShouldIgnoreRotor( m_nModelIndex.Get() ); - bool bHasMovingProp = m_pCarNode[13] != nullptr && bDisplayRotors; - bool bHasMovingProp2 = m_pCarNode[15] != nullptr && bDisplayRotors; + const bool bDisplayRotors = !IgnoresRotorFix(); + const bool bHasMovingProp = m_pCarNode[13] != nullptr && bDisplayRotors; + const bool bHasMovingProp2 = m_pCarNode[15] != nullptr && bDisplayRotors; m_nTimeTillWeNeedThisCar = CTimer::m_snTimeInMilliseconds + 3000; diff --git a/SilentPatchSA/VehicleSA.h b/SilentPatchSA/VehicleSA.h index d38fa04..7e4ade2 100644 --- a/SilentPatchSA/VehicleSA.h +++ b/SilentPatchSA/VehicleSA.h @@ -271,8 +271,9 @@ public: static inline void (CVehicle::*orgDoHeadLightBeam)( int type, CMatrix& m, bool right ); - static inline int8_t ms_lightbeamFixOverride = 0; // 0 - normal, 1 - always on, -1 - always off + static inline int8_t ms_lightbeamFixOverride = 0, ms_rotorFixOverride = 0; // 0 - normal, 1 - always on, -1 - always off bool IgnoresLightbeamFix() const; + bool IgnoresRotorFix() const; void DoHeadLightBeam( int type, CMatrix& m, bool right ) {