From 93b35cdf2868092463233959cd12b39b0dbe8611 Mon Sep 17 00:00:00 2001 From: zilmar Date: Wed, 10 Mar 2021 18:09:01 +1030 Subject: [PATCH] Add Overclock to enhancment --- Config/Enhancement/GoldenEye 007 (U).enh | 7 ++ .../N64System/Enhancement/Enhancement.cpp | 22 +++++ .../N64System/Enhancement/Enhancement.h | 5 ++ .../N64System/Enhancement/EnhancementFile.cpp | 4 + .../N64System/Enhancement/Enhancements.cpp | 86 +++++++++++-------- .../N64System/Enhancement/Enhancements.h | 2 + .../Project64-core/Settings/GameSettings.cpp | 19 ++++ Source/Project64-core/Settings/GameSettings.h | 3 + .../Project64/UserInterface/EnhancementUI.cpp | 41 +++++---- 9 files changed, 137 insertions(+), 52 deletions(-) create mode 100644 Config/Enhancement/GoldenEye 007 (U).enh diff --git a/Config/Enhancement/GoldenEye 007 (U).enh b/Config/Enhancement/GoldenEye 007 (U).enh new file mode 100644 index 000000000..dbf8b841b --- /dev/null +++ b/Config/Enhancement/GoldenEye 007 (U).enh @@ -0,0 +1,7 @@ +[DCBC50D1-09FD1AA3-C:45] +Name=GoldenEye 007 (U) + +$Over Clock +OnByDefault=1 +OverClock=8 + diff --git a/Source/Project64-core/N64System/Enhancement/Enhancement.cpp b/Source/Project64-core/N64System/Enhancement/Enhancement.cpp index 5c10a895b..2232f3311 100644 --- a/Source/Project64-core/N64System/Enhancement/Enhancement.cpp +++ b/Source/Project64-core/N64System/Enhancement/Enhancement.cpp @@ -118,6 +118,8 @@ CEnhancement::CEnhancement(const char * Ident) : m_SelectedOption(0xFFFF0000), m_OnByDefault(false), m_Active(false), + m_OverClock(false), + m_OverClockModifier(1), m_Valid(false) { } @@ -128,6 +130,8 @@ CEnhancement::CEnhancement(const char * Ident, const char * Entry) : m_SelectedOption(0xFFFF0000), m_OnByDefault(false), m_Active(false), + m_OverClock(false), + m_OverClockModifier(1), m_Valid(false) { stdstr EntryLine(Entry); @@ -175,6 +179,10 @@ CEnhancement::CEnhancement(const char * Ident, const char * Entry) : { m_OnByDefault = Pos[1] == '1'; } + else if (stricmp(Key.c_str(), "OverClock") == 0) + { + SetOverClock(true, atoi(&Pos[1])); + } else { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -322,6 +330,20 @@ void CEnhancement::SetOnByDefault(bool OnByDefault) m_Active = CSettingEnhancementActive(m_Name.c_str(), m_Ident.c_str(), m_OnByDefault).Active(); } +void CEnhancement::SetOverClock(bool OverClock, uint32_t OverClockModifier) +{ + m_OverClock = OverClock; + m_OverClockModifier = OverClockModifier; + if (m_OverClockModifier < 1) + { + m_OverClockModifier = 1; + } + if (m_OverClockModifier > 20) + { + m_OverClockModifier = 20; + } +} + 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 628b08829..a31bc61de 100644 --- a/Source/Project64-core/N64System/Enhancement/Enhancement.h +++ b/Source/Project64-core/N64System/Enhancement/Enhancement.h @@ -33,6 +33,7 @@ public: void SetSelectedOption(uint16_t Value); void SetActive(bool Active); void SetOnByDefault(bool OnByDefault); + void SetOverClock(bool OverClock, uint32_t OverClockModifier); inline const std::string & GetName(void) const { return m_Name; } inline const std::string & GetNameAndExtension(void) const { return m_NameAndExtension; } @@ -44,6 +45,8 @@ public: inline bool Valid(void) const { return m_Valid; } inline bool Active(void) const { return m_Active; } inline bool GetOnByDefault(void) const { return m_OnByDefault; } + inline bool OverClock(void) const { return m_OverClock; } + inline uint32_t OverClockModifier(void) const { return m_OverClockModifier; } bool OptionSelected() const { return (m_SelectedOption & 0xFFFF0000) == 0; } uint16_t SelectedOption() const { return (uint16_t)(m_SelectedOption & 0xFFFF); } @@ -63,6 +66,8 @@ private: uint32_t m_CodeOptionSize; uint32_t m_SelectedOption; bool m_OnByDefault; + bool m_OverClock; + uint32_t m_OverClockModifier; bool m_Active; bool m_Valid; }; diff --git a/Source/Project64-core/N64System/Enhancement/EnhancementFile.cpp b/Source/Project64-core/N64System/Enhancement/EnhancementFile.cpp index 671b94d7f..3407b30c6 100644 --- a/Source/Project64-core/N64System/Enhancement/EnhancementFile.cpp +++ b/Source/Project64-core/N64System/Enhancement/EnhancementFile.cpp @@ -329,6 +329,10 @@ void CEnhancmentFile::SaveCurrentSection(void) { Section += stdstr_f("OnByDefault=1%s", m_LineFeed); } + if (Enhancement.OverClock()) + { + Section += stdstr_f("OverClock=%d%s", Enhancement.OverClockModifier(), m_LineFeed); + } if (!Enhancement.GetNote().empty()) { Section += stdstr_f("Note=%s%s", Enhancement.GetNote().c_str(), m_LineFeed); diff --git a/Source/Project64-core/N64System/Enhancement/Enhancements.cpp b/Source/Project64-core/N64System/Enhancement/Enhancements.cpp index a8ea7cb4e..25420940c 100644 --- a/Source/Project64-core/N64System/Enhancement/Enhancements.cpp +++ b/Source/Project64-core/N64System/Enhancement/Enhancements.cpp @@ -32,7 +32,9 @@ CEnhancements::CEnhancements() : m_ScanFileThread(stScanFileThread), m_Scan(true), m_Scanned(false), - m_UpdateCheats(false) + m_UpdateCheats(false), + m_OverClock(false), + m_OverClockModifier(1) { m_ScanFileThread.Start(this); } @@ -267,9 +269,14 @@ void CEnhancements::Load(CMipsMemoryVM * MMU, CPlugins * Plugins) LoadEnhancements(CEnhancement::CheatIdent, m_CheatFiles, m_CheatFile, m_Cheats); LoadEnhancements(CEnhancement::EnhancementIdent, m_EnhancementFiles, m_EnhancementFile, m_Enhancements); + m_OverClock = false; + m_OverClockModifier = 1; + ResetCodes(MMU); LoadActive(m_Cheats, nullptr); LoadActive(m_Enhancements, Plugins); + + CGameSettings::SetOverClockModifier(m_OverClock, m_OverClockModifier); } CEnhancementList CEnhancements::Cheats(void) @@ -336,41 +343,52 @@ void CEnhancements::LoadActive(CEnhancementList & List, CPlugins * Plugins) } } - const CEnhancement::CodeEntries Entries = Enhancement.GetEntries(); - CODES Code; - Code.reserve(Entries.size()); - for (size_t i = 0, n = Entries.size(); i < n; i++) + if (Enhancement.OverClock()) { - uint32_t Command = Entries[i].Command; - uint16_t Value = 0, DisableValue = 0; - bool HasDisableValue = false; - - if (strncmp(Entries[i].Value.c_str(), "????", 4) == 0) - { - Value = Enhancement.SelectedOption(); - } - else if (strncmp(Entries[i].Value.c_str(), "??", 2) == 0) - { - Value = (uint8_t)(strtoul(&(Entries[i].Value.c_str()[2]), 0, 16), 0, 16); - Value |= Enhancement.SelectedOption() << 16; - } - else if (strncmp(&Entries[i].Value[2], "??", 2) == 0) - { - Value = (uint16_t)(strtoul(Entries[i].Value.c_str(), 0, 16) << 16); - Value |= Enhancement.SelectedOption(); - } - else - { - Value = (uint16_t)strtoul(Entries[i].Value.c_str(), 0, 16); - } - if (Entries[i].Value.size() > 8 && Entries[i].Value[4] == ':') - { - HasDisableValue = true; - DisableValue = (uint16_t)strtoul(&Entries[i].Value[5], 0, 16); - } - Code.emplace_back(GAMESHARK_CODE(Command, Value, HasDisableValue, DisableValue)); + m_OverClock = true; + m_OverClockModifier = Enhancement.OverClockModifier(); + } + const CEnhancement::CodeEntries Entries = Enhancement.GetEntries(); + if (Entries.size() > 0) + { + CODES Code; + Code.reserve(Entries.size()); + for (size_t i = 0, n = Entries.size(); i < n; i++) + { + uint32_t Command = Entries[i].Command; + uint16_t Value = 0, DisableValue = 0; + bool HasDisableValue = false; + + if (strncmp(Entries[i].Value.c_str(), "????", 4) == 0) + { + Value = Enhancement.SelectedOption(); + } + else if (strncmp(Entries[i].Value.c_str(), "??", 2) == 0) + { + Value = (uint8_t)(strtoul(&(Entries[i].Value.c_str()[2]), 0, 16), 0, 16); + Value |= Enhancement.SelectedOption() << 16; + } + else if (strncmp(&Entries[i].Value[2], "??", 2) == 0) + { + Value = (uint16_t)(strtoul(Entries[i].Value.c_str(), 0, 16) << 16); + Value |= Enhancement.SelectedOption(); + } + else + { + Value = (uint16_t)strtoul(Entries[i].Value.c_str(), 0, 16); + } + if (Entries[i].Value.size() > 8 && Entries[i].Value[4] == ':') + { + HasDisableValue = true; + DisableValue = (uint16_t)strtoul(&Entries[i].Value[5], 0, 16); + } + Code.emplace_back(GAMESHARK_CODE(Command, Value, HasDisableValue, DisableValue)); + } + if (Code.size() > 0) + { + m_ActiveCodes.push_back(std::move(Code)); + } } - m_ActiveCodes.push_back(Code); } } diff --git a/Source/Project64-core/N64System/Enhancement/Enhancements.h b/Source/Project64-core/N64System/Enhancement/Enhancements.h index 76f0a5472..ba3cb466b 100644 --- a/Source/Project64-core/N64System/Enhancement/Enhancements.h +++ b/Source/Project64-core/N64System/Enhancement/Enhancements.h @@ -100,4 +100,6 @@ private: bool m_Scan; bool m_Scanned; bool m_UpdateCheats; + bool m_OverClock; + uint32_t m_OverClockModifier; }; \ No newline at end of file diff --git a/Source/Project64-core/Settings/GameSettings.cpp b/Source/Project64-core/Settings/GameSettings.cpp index 1e8b864bf..ea4872a8f 100644 --- a/Source/Project64-core/Settings/GameSettings.cpp +++ b/Source/Project64-core/Settings/GameSettings.cpp @@ -31,6 +31,8 @@ SYSTEM_TYPE CGameSettings::m_SystemType = SYSTEM_NTSC; CPU_TYPE CGameSettings::m_CpuType = CPU_Recompiler; uint32_t CGameSettings::m_OverClockModifier = 1; DISK_SEEK_TYPE CGameSettings::m_DiskSeekTimingType = DiskSeek_Turbo; +bool CGameSettings::m_EnhancmentOverClock = false; +uint32_t CGameSettings::m_EnhancmentOverClockModifier = 1; void CGameSettings::RefreshGameSettings() { @@ -86,3 +88,20 @@ void CGameSettings::RefreshSyncToAudio(void) { m_bSyncToAudio = g_Settings->LoadBool(Game_SyncViaAudio) && g_Settings->LoadBool(Setting_SyncViaAudioEnabled) && g_Settings->LoadBool(Plugin_EnableAudio); } + +void CGameSettings::SetOverClockModifier(bool EnhancmentOverClock, uint32_t EnhancmentOverClockModifier) +{ + m_EnhancmentOverClock = EnhancmentOverClock; + m_EnhancmentOverClockModifier = EnhancmentOverClockModifier; + + if (m_EnhancmentOverClock) + { + m_OverClockModifier = m_EnhancmentOverClockModifier; + } + else + { + m_OverClockModifier = g_Settings->LoadDword(Game_OverClockModifier); + } + if (m_OverClockModifier < 1) { m_OverClockModifier = 1; } + if (m_OverClockModifier > 20) { m_OverClockModifier = 20; } +} \ No newline at end of file diff --git a/Source/Project64-core/Settings/GameSettings.h b/Source/Project64-core/Settings/GameSettings.h index 7548dce7b..a4e6548a9 100644 --- a/Source/Project64-core/Settings/GameSettings.h +++ b/Source/Project64-core/Settings/GameSettings.h @@ -38,6 +38,7 @@ public: inline static DISK_SEEK_TYPE DiskSeekTimingType(void) { return m_DiskSeekTimingType; }; void RefreshSyncToAudio(void); + static void SetOverClockModifier(bool EnhancmentOverClock, uint32_t EnhancmentOverClockModifier); protected: static void SpeedChanged(int32_t SpeedLimit); @@ -72,4 +73,6 @@ private: static CPU_TYPE m_CpuType; static uint32_t m_OverClockModifier; static DISK_SEEK_TYPE m_DiskSeekTimingType; + static bool m_EnhancmentOverClock; + static uint32_t m_EnhancmentOverClockModifier; }; diff --git a/Source/Project64/UserInterface/EnhancementUI.cpp b/Source/Project64/UserInterface/EnhancementUI.cpp index 879002698..490e07178 100644 --- a/Source/Project64/UserInterface/EnhancementUI.cpp +++ b/Source/Project64/UserInterface/EnhancementUI.cpp @@ -9,6 +9,7 @@ public: BEGIN_MSG_MAP_EX(CEditEnhancement) MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) COMMAND_HANDLER_EX(IDC_GAMESHARK, BN_CLICKED, OnGamesharkBtn) + COMMAND_HANDLER_EX(IDC_OVERCLOCK, BN_CLICKED, OnOverClockBtn) COMMAND_ID_HANDLER(IDC_BTN_GAMESHARK, OnEditGameshark) COMMAND_ID_HANDLER(IDOK, OnOkCmd) COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd) @@ -25,6 +26,7 @@ private: LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnGamesharkBtn(UINT Code, int id, HWND ctl); + LRESULT OnOverClockBtn(UINT Code, int id, HWND ctl); LRESULT OnEditGameshark(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnOkCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); @@ -498,12 +500,14 @@ LRESULT CEditEnhancement::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM { m_Entries = m_EditEnhancement != nullptr ? m_EditEnhancement->GetEntries() : CEnhancement::CodeEntries(); m_PluginList = m_EditEnhancement != nullptr ? m_EditEnhancement->GetPluginList() : CEnhancement::PluginList(); - GetDlgItem(IDC_OVERCLOCK).EnableWindow(false); - GetDlgItem(IDC_OVER_CLOCK_MODIFIER).EnableWindow(false); GetDlgItem(IDC_CODE_NAME).SetWindowText(m_EditEnhancement != nullptr ? stdstr(m_EditEnhancement->GetName()).ToUTF16().c_str() : L""); GetDlgItem(IDC_NOTES).SetWindowText(m_EditEnhancement != nullptr ? stdstr(m_EditEnhancement->GetNote()).ToUTF16().c_str() : L""); CButton(GetDlgItem(IDC_AUTOON)).SetCheck(m_EditEnhancement != nullptr ? (m_EditEnhancement->GetOnByDefault() ? BST_CHECKED : BST_UNCHECKED) : BST_UNCHECKED); CButton(GetDlgItem(IDC_GAMESHARK)).SetCheck(m_Entries.size() > 0 ? BST_CHECKED : BST_UNCHECKED); + CButton(GetDlgItem(IDC_OVERCLOCK)).SetCheck(m_EditEnhancement != nullptr ? (m_EditEnhancement->OverClock() ? BST_CHECKED : BST_UNCHECKED) : BST_UNCHECKED); + GetDlgItem(IDC_OVER_CLOCK_MODIFIER).SetWindowText(m_EditEnhancement != nullptr ? stdstr_f("%d",m_EditEnhancement->OverClockModifier()).ToUTF16().c_str() : L"1"); + GetDlgItem(IDC_OVER_CLOCK_MODIFIER).EnableWindow(m_EditEnhancement != nullptr ? m_EditEnhancement->OverClock() : false); + return TRUE; } @@ -515,6 +519,12 @@ LRESULT CEditEnhancement::OnGamesharkBtn(UINT /*Code*/, int /*id*/, HWND /*ctl*/ return 0; } +LRESULT CEditEnhancement::OnOverClockBtn(UINT /*Code*/, int /*id*/, HWND /*ctl*/) +{ + GetDlgItem(IDC_OVER_CLOCK_MODIFIER).EnableWindow(CButton(GetDlgItem(IDC_OVERCLOCK)).GetCheck() == BST_CHECKED); + return 0; +} + LRESULT CEditEnhancement::OnEditGameshark(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { OnGamesharkBtn(0, 0, 0); @@ -529,24 +539,19 @@ LRESULT CEditEnhancement::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWnd LRESULT CEditEnhancement::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { + CEnhancement TempEnhancement(CEnhancement::EnhancementIdent); + CEnhancement & Enhancement = m_EditEnhancement != nullptr ? *m_EditEnhancement : TempEnhancement; + Enhancement.SetName(GetCWindowText(GetDlgItem(IDC_CODE_NAME)).c_str()); + Enhancement.SetOnByDefault(CButton(GetDlgItem(IDC_AUTOON)).GetCheck() == BST_CHECKED); + Enhancement.SetOverClock(CButton(GetDlgItem(IDC_OVERCLOCK)).GetCheck() == BST_CHECKED, atoi(GetCWindowText(GetDlgItem(IDC_OVER_CLOCK_MODIFIER)).c_str())); + Enhancement.SetEntries(m_Entries); + Enhancement.SetPluginList(m_PluginList); + Enhancement.SetNote(GetCWindowText(GetDlgItem(IDC_NOTES)).c_str()); + CEnhancementList & Enhancements = m_EnhancementUI.m_Enhancements; - if (m_EditEnhancement != nullptr) + if (m_EditEnhancement == nullptr) { - m_EditEnhancement->SetName(GetCWindowText(GetDlgItem(IDC_CODE_NAME)).c_str()); - m_EditEnhancement->SetOnByDefault(CButton(GetDlgItem(IDC_AUTOON)).GetCheck() == BST_CHECKED); - m_EditEnhancement->SetEntries(m_Entries); - m_EditEnhancement->SetPluginList(m_PluginList); - m_EditEnhancement->SetNote(GetCWindowText(GetDlgItem(IDC_NOTES)).c_str()); - } - else - { - CEnhancement Enhancement(CEnhancement::EnhancementIdent); - Enhancement.SetName(GetCWindowText(GetDlgItem(IDC_CODE_NAME)).c_str()); - Enhancement.SetOnByDefault(CButton(GetDlgItem(IDC_AUTOON)).GetCheck() == BST_CHECKED); - Enhancement.SetEntries(m_Entries); - Enhancement.SetPluginList(m_PluginList); - Enhancement.SetNote(GetCWindowText(GetDlgItem(IDC_NOTES)).c_str()); - Enhancements.AddItem(Enhancement); + Enhancements.AddItem(TempEnhancement); } g_Enhancements->UpdateEnhancements(Enhancements); m_EnhancementUI.RefreshList();