From 075c4a39ed67fb185be08d48951ba9a55259b576 Mon Sep 17 00:00:00 2001 From: oddMLan Date: Thu, 29 May 2025 01:53:36 -0700 Subject: [PATCH] [Enhancements] Implement ini settings for key Rom settings --- .../N64System/Enhancement/Enhancement.cpp | 64 ++++++++++++ .../N64System/Enhancement/Enhancement.h | 66 +++++++++++++ .../N64System/Enhancement/Enhancements.cpp | 61 ++++++++++++ .../Project64-core/Settings/GameSettings.cpp | 98 +++++++++++++++++++ Source/Project64-core/Settings/GameSettings.h | 6 ++ 5 files changed, 295 insertions(+) diff --git a/Source/Project64-core/N64System/Enhancement/Enhancement.cpp b/Source/Project64-core/N64System/Enhancement/Enhancement.cpp index 2c95294de..8299eb8a9 100644 --- a/Source/Project64-core/N64System/Enhancement/Enhancement.cpp +++ b/Source/Project64-core/N64System/Enhancement/Enhancement.cpp @@ -188,14 +188,42 @@ CEnhancement::CEnhancement(const char * Ident, const char * Entry) : { m_Note = &Pos[1]; } + else if (stricmp(Key.c_str(), "WIP") == 0) + { + // TODO + } else if (stricmp(Key.c_str(), "OnByDefault") == 0 || stricmp(Key.c_str(), "On By Default") == 0) { m_OnByDefault = Pos[1] == '1'; } + else if (stricmp(Key.c_str(), "Counter Factor") == 0) + { + SetCounterFactor(true, atoi(&Pos[1])); + } else if (stricmp(Key.c_str(), "Overclock") == 0) { SetOverClock(true, atoi(&Pos[1])); } + else if (stricmp(Key.c_str(), "VI Refresh") == 0) + { + SetViRefresh(true, atoi(&Pos[1])); + } + else if (stricmp(Key.c_str(), "RDRAM Size") == 0) + { + SetRdramSize(true, atoi(&Pos[1])); + } + else if (stricmp(Key.c_str(), "SMM-Protect") == 0) + { + SetSmmProtect(true, Pos[1] == '1'); + } + else if (stricmp(Key.c_str(), "Fixed Audio") == 0) + { + SetFixedAudio(true, Pos[1] == '1'); + } + else if (stricmp(Key.c_str(), "Sync Audio") == 0) + { + SetSyncAudio(true, Pos[1] == '1'); + } else { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -369,6 +397,42 @@ void CEnhancement::SetOverClock(bool OverClock, uint32_t OverClockModifier) } } +void CEnhancement::SetCounterFactor(bool hasValue, uint32_t value) +{ + m_HasCounterFactor = hasValue; + m_CounterFactor = value; +} + +void CEnhancement::SetViRefresh(bool hasValue, uint32_t value) +{ + m_HasViRefresh = hasValue; + m_ViRefresh = value; +} + +void CEnhancement::SetRdramSize(bool hasValue, uint32_t value) +{ + m_HasRdramSize = hasValue; + m_RdramSize = value; +} + +void CEnhancement::SetSmmProtect(bool hasValue, bool value) +{ + m_HasSmmProtect = hasValue; + m_SmmProtect = value; +} + +void CEnhancement::SetFixedAudio(bool hasValue, bool value) +{ + m_HasFixedAudio = hasValue; + m_FixedAudio = value; +} + +void CEnhancement::SetSyncAudio(bool hasValue, bool value) +{ + m_HasSyncAudio = hasValue; + m_SyncAudio = value; +} + void CEnhancement::CheckValid(void) { m_Valid = false; diff --git a/Source/Project64-core/N64System/Enhancement/Enhancement.h b/Source/Project64-core/N64System/Enhancement/Enhancement.h index ffd10b8ee..724954abd 100644 --- a/Source/Project64-core/N64System/Enhancement/Enhancement.h +++ b/Source/Project64-core/N64System/Enhancement/Enhancement.h @@ -35,6 +35,12 @@ public: void SetActive(bool Active); void SetOnByDefault(bool OnByDefault); void SetOverClock(bool OverClock, uint32_t OverClockModifier); + void SetCounterFactor(bool hasValue, uint32_t value); + void SetViRefresh(bool hasValue, uint32_t value); + void SetRdramSize(bool hasValue, uint32_t value); + void SetSmmProtect(bool hasValue, bool value); + void SetFixedAudio(bool hasValue, bool value); + void SetSyncAudio(bool hasValue, bool value); inline const std::string & GetName(void) const { @@ -88,6 +94,54 @@ public: { return m_OverClockModifier; } + inline bool HasCounterFactor() const + { + return m_HasCounterFactor; + } + inline uint32_t CounterFactor() const + { + return m_CounterFactor; + } + inline bool HasViRefresh() const + { + return m_HasViRefresh; + } + inline uint32_t ViRefresh() const + { + return m_ViRefresh; + } + inline bool HasRdramSize() const + { + return m_HasRdramSize; + } + inline uint32_t RdramSize() const + { + return m_RdramSize; + } + inline bool HasSmmProtect() const + { + return m_HasSmmProtect; + } + inline bool SmmProtect() const + { + return m_SmmProtect; + } + inline bool HasFixedAudio() const + { + return m_HasFixedAudio; + } + inline bool FixedAudio() const + { + return m_FixedAudio; + } + inline bool HasSyncAudio() const + { + return m_HasSyncAudio; + } + inline bool SyncAudio() const + { + return m_SyncAudio; + } bool OptionSelected() const { return (m_SelectedOption & 0xFFFF0000) == 0; @@ -118,4 +172,16 @@ private: uint32_t m_OverClockModifier; bool m_Active; bool m_Valid; + bool m_HasCounterFactor = false; + uint32_t m_CounterFactor = 0; + bool m_HasViRefresh = false; + uint32_t m_ViRefresh = 0; + bool m_HasRdramSize = false; + uint32_t m_RdramSize = 0; + bool m_HasSmmProtect = false; + bool m_SmmProtect = false; + bool m_HasFixedAudio = false; + bool m_FixedAudio = false; + bool m_HasSyncAudio = false; + bool m_SyncAudio = false; }; diff --git a/Source/Project64-core/N64System/Enhancement/Enhancements.cpp b/Source/Project64-core/N64System/Enhancement/Enhancements.cpp index ad015b839..daade1e7e 100644 --- a/Source/Project64-core/N64System/Enhancement/Enhancements.cpp +++ b/Source/Project64-core/N64System/Enhancement/Enhancements.cpp @@ -280,11 +280,72 @@ void CEnhancements::LoadActive(CMipsMemoryVM * MMU, CPlugins * Plugins) m_OverClock = false; m_OverClockModifier = 1; + // Track enhancement overrides for each setting + bool hasCounterFactor = false; + uint32_t counterFactor = 2; + bool hasViRefresh = false; + uint32_t viRefresh = 1500; + bool hasRdramSize = false; + uint32_t rdramSize = 0; + bool hasSmmProtect = false; + bool smmProtect = false; + bool hasFixedAudio = false; + bool fixedAudio = true; + bool hasSyncAudio = false; + bool syncAudio = true; + ResetCodes(MMU); LoadActive(m_Cheats, nullptr); LoadActive(m_Enhancements, Plugins); + // Scan all active enhancements for overrides + for (const auto & list : {m_Cheats, m_Enhancements}) + { + for (const auto & pair : list) + { + const CEnhancement & enh = pair.second; + if (!enh.Valid() || !enh.Active()) continue; + if (enh.HasCounterFactor()) + { + hasCounterFactor = true; + counterFactor = enh.CounterFactor(); + } + if (enh.HasViRefresh()) + { + hasViRefresh = true; + viRefresh = enh.ViRefresh(); + } + if (enh.HasRdramSize()) + { + hasRdramSize = true; + rdramSize = enh.RdramSize(); + } + if (enh.HasSmmProtect()) + { + hasSmmProtect = true; + smmProtect = enh.SmmProtect(); + } + if (enh.HasFixedAudio()) + { + hasFixedAudio = true; + fixedAudio = enh.FixedAudio(); + } + if (enh.HasSyncAudio()) + { + hasSyncAudio = true; + syncAudio = enh.SyncAudio(); + } + } + } + + // Apply enhancement overrides CGameSettings::SetOverClockModifier(m_OverClock, m_OverClockModifier); + CGameSettings::SetCountPerOp(hasCounterFactor, counterFactor); + CGameSettings::SetViRefreshRate(hasViRefresh, viRefresh); + CGameSettings::SetRdramSize(hasRdramSize, rdramSize); + CGameSettings::SetSmmProtect(hasSmmProtect, smmProtect); + CGameSettings::SetFixedAudio(hasFixedAudio, fixedAudio); + CGameSettings::SetSyncAudio(hasSyncAudio, syncAudio); } CEnhancementList CEnhancements::Cheats(void) diff --git a/Source/Project64-core/Settings/GameSettings.cpp b/Source/Project64-core/Settings/GameSettings.cpp index ae401816d..3695304a7 100644 --- a/Source/Project64-core/Settings/GameSettings.cpp +++ b/Source/Project64-core/Settings/GameSettings.cpp @@ -147,3 +147,101 @@ void CGameSettings::EnableDiskChanged(void *) { m_EnableDisk = g_Settings->LoadBool(Setting_EnableDisk); } + +void CGameSettings::SetCountPerOp(bool enhancementActive, uint32_t value) +{ + static bool s_EnhancementActive = false; + static uint32_t s_EnhancementValue = 2; + s_EnhancementActive = enhancementActive; + s_EnhancementValue = value; + if (s_EnhancementActive) + { + m_CountPerOp = s_EnhancementValue; + } + else + { + m_CountPerOp = g_Settings->LoadDword(Game_CounterFactor); + if (m_CountPerOp == 0) m_CountPerOp = 2; + } +} + +void CGameSettings::SetViRefreshRate(bool enhancementActive, uint32_t value) +{ + static bool s_EnhancementActive = false; + static uint32_t s_EnhancementValue = 1500; + s_EnhancementActive = enhancementActive; + s_EnhancementValue = value; + if (s_EnhancementActive) + { + m_ViRefreshRate = s_EnhancementValue; + } + else + { + m_ViRefreshRate = g_Settings->LoadDword(Game_ViRefreshRate); + if (m_ViRefreshRate == 0) m_ViRefreshRate = 1500; + } +} + +void CGameSettings::SetRdramSize(bool enhancementActive, uint32_t value) +{ + static bool s_EnhancementActive = false; + static uint32_t s_EnhancementValue = 0; + s_EnhancementActive = enhancementActive; + s_EnhancementValue = value; + if (s_EnhancementActive) + { + m_RdramSize = s_EnhancementValue; + } + else + { + m_RdramSize = g_Settings->LoadDword(Game_RDRamSize); + } +} + +void CGameSettings::SetFixedAudio(bool enhancementActive, bool value) +{ + static bool s_EnhancementActive = false; + static bool s_EnhancementValue = true; + s_EnhancementActive = enhancementActive; + s_EnhancementValue = value; + if (s_EnhancementActive) + { + m_bFixedAudio = s_EnhancementValue; + } + else + { + m_bFixedAudio = g_Settings->LoadBool(Game_FixedAudio); + } +} + +void CGameSettings::SetSyncAudio(bool enhancementActive, bool value) +{ + static bool s_EnhancementActive = false; + static bool s_EnhancementValue = true; + s_EnhancementActive = enhancementActive; + s_EnhancementValue = value; + if (s_EnhancementActive) + { + m_bSyncToAudio = s_EnhancementValue; + } + else + { + m_bSyncToAudio = g_Settings->LoadBool(Game_SyncViaAudio) && g_Settings->LoadBool(Setting_SyncViaAudioEnabled) && g_Settings->LoadBool(Plugin_EnableAudio); + } +} + +void CGameSettings::SetSmmProtect(bool enhancementActive, bool value) +{ + static bool s_EnhancementActive = false; + static bool s_EnhancementValue = false; + s_EnhancementActive = enhancementActive; + s_EnhancementValue = value; + if (s_EnhancementActive) + { + m_bSMM_StoreInstruc = s_EnhancementValue; + } + else + { + m_bSMM_StoreInstruc = g_Settings->LoadBool(Game_SMM_StoreInstruc); + } +} diff --git a/Source/Project64-core/Settings/GameSettings.h b/Source/Project64-core/Settings/GameSettings.h index 2501057ef..d17fad91f 100644 --- a/Source/Project64-core/Settings/GameSettings.h +++ b/Source/Project64-core/Settings/GameSettings.h @@ -134,6 +134,12 @@ public: void RefreshSyncToAudio(void); static void SetOverClockModifier(bool EnhancmentOverClock, uint32_t EnhancmentOverClockModifier); + static void SetCountPerOp(bool enhancementActive, uint32_t value); + static void SetViRefreshRate(bool enhancementActive, uint32_t value); + static void SetRdramSize(bool enhancementActive, uint32_t value); + static void SetFixedAudio(bool enhancementActive, bool value); + static void SetSyncAudio(bool enhancementActive, bool value); + static void SetSmmProtect(bool enhancementActive, bool value); protected: static void SpeedChanged(int32_t SpeedLimit);