Add plugin limiting to enhancements

This commit is contained in:
zilmar 2021-02-17 10:24:17 +10:30
parent 3e02ff31d7
commit 6127878f8f
10 changed files with 125 additions and 86 deletions

View File

@ -14,6 +14,11 @@
#include <Project64-core\N64System\Mips\MemoryVirtualMem.h>
#include <Project64-core\N64System\Recompiler\RecompilerClass.h>
#include <Project64-core\N64System\SystemGlobals.h>
#include <Project64-core\Plugins\PluginClass.h>
#include <Project64-core\Plugins\GFXPlugin.h>
#include <Project64-core\Plugins\AudioPlugin.h>
#include <Project64-core\Plugins\RSPPlugin.h>
#include <Project64-core\Plugins\ControllerPlugin.h>
#include <Common\path.h>
#include <Common\Util.h>
@ -24,23 +29,21 @@ CEnhancements::CEnhancements() :
m_UpdateCheats(false)
{
m_ScanFileThread.Start(this);
g_Settings->RegisterChangeCB(Game_IniKey, this, stGameChanged);
}
CEnhancements::~CEnhancements()
{
g_Settings->UnregisterChangeCB(Game_IniKey, this, stGameChanged);
m_Scan = false;
WaitScanDone();
}
void CEnhancements::ApplyActive(CMipsMemoryVM & MMU, bool UpdateChanges)
void CEnhancements::ApplyActive(CMipsMemoryVM & MMU, CPlugins * Plugins, bool UpdateChanges)
{
CGuard Guard(m_CS);
if (m_UpdateCheats && UpdateChanges)
{
m_UpdateCheats = false;
LoadCheats(&MMU);
Load(&MMU, Plugins);
}
for (size_t i = 0, n = m_ActiveCodes.size(); i < n; i++)
{
@ -83,6 +86,7 @@ void CEnhancements::ApplyGSButton(CMipsMemoryVM & MMU, bool /*UpdateChanges*/)
void CEnhancements::UpdateCheats(const CEnhancementList & Cheats)
{
std::string GameName = g_Settings->LoadStringVal(Rdb_GoodName);
std::string SectionIdent = g_Settings->LoadStringVal(Game_IniKey);
CPath OutFile(g_Settings->LoadStringVal(SupportFile_UserCheatDir), stdstr_f("%s.cht", GameName.c_str()).c_str());
#ifdef _WIN32
OutFile.NormalizePath(CPath(CPath::MODULE_DIRECTORY));
@ -95,17 +99,17 @@ void CEnhancements::UpdateCheats(const CEnhancementList & Cheats)
{
OutFile.DirectoryCreate();
}
SectionFiles::const_iterator CheatFileItr = m_CheatFiles.find(m_SectionIdent);
SectionFiles::const_iterator CheatFileItr = m_CheatFiles.find(SectionIdent);
if (m_CheatFiles.end() != CheatFileItr)
{
m_CheatFiles.erase(CheatFileItr);
}
m_CheatFile = std::make_unique<CEnhancmentFile>(OutFile, "Cheat");
m_CheatFiles.insert(SectionFiles::value_type(m_SectionIdent, OutFile));
m_CheatFiles.insert(SectionFiles::value_type(SectionIdent, OutFile));
}
m_CheatFile->SetName(m_SectionIdent.c_str(), GameName.c_str());
m_CheatFile->RemoveEnhancements(m_SectionIdent.c_str());
m_CheatFile->SetName(SectionIdent.c_str(), GameName.c_str());
m_CheatFile->RemoveEnhancements(SectionIdent.c_str());
for (CEnhancementList::const_iterator itr = Cheats.begin(); itr != Cheats.end(); itr++)
{
const CEnhancement & Enhancement = itr->second;
@ -114,7 +118,7 @@ void CEnhancements::UpdateCheats(const CEnhancementList & Cheats)
g_Notify->BreakPoint(__FILE__, __LINE__);
continue;
}
m_CheatFile->AddEnhancement(m_SectionIdent.c_str(), Enhancement);
m_CheatFile->AddEnhancement(SectionIdent.c_str(), Enhancement);
}
m_CheatFile->SaveCurrentSection();
m_UpdateCheats = true;
@ -128,6 +132,7 @@ void CEnhancements::UpdateCheats(void)
void CEnhancements::UpdateEnhancements(const CEnhancementList & Enhancements)
{
std::string GameName = g_Settings->LoadStringVal(Rdb_GoodName);
std::string SectionIdent = g_Settings->LoadStringVal(Game_IniKey);
CPath OutFile(g_Settings->LoadStringVal(SupportFile_UserEnhancementDir), stdstr_f("%s.enh", GameName.c_str()).c_str());
#ifdef _WIN32
OutFile.NormalizePath(CPath(CPath::MODULE_DIRECTORY));
@ -140,17 +145,17 @@ void CEnhancements::UpdateEnhancements(const CEnhancementList & Enhancements)
{
OutFile.DirectoryCreate();
}
SectionFiles::const_iterator EnhancementFileItr = m_EnhancementFiles.find(m_SectionIdent);
SectionFiles::const_iterator EnhancementFileItr = m_EnhancementFiles.find(SectionIdent);
if (m_EnhancementFiles.end() != EnhancementFileItr)
{
m_EnhancementFiles.erase(EnhancementFileItr);
}
m_EnhancementFile = std::make_unique<CEnhancmentFile>(OutFile, "Enhancement");
m_EnhancementFiles.insert(SectionFiles::value_type(m_SectionIdent, OutFile));
m_EnhancementFiles.insert(SectionFiles::value_type(SectionIdent, OutFile));
}
m_EnhancementFile->SetName(m_SectionIdent.c_str(), GameName.c_str());
m_EnhancementFile->RemoveEnhancements(m_SectionIdent.c_str());
m_EnhancementFile->SetName(SectionIdent.c_str(), GameName.c_str());
m_EnhancementFile->RemoveEnhancements(SectionIdent.c_str());
for (CEnhancementList::const_iterator itr = Enhancements.begin(); itr != Enhancements.end(); itr++)
{
const CEnhancement & Enhancement = itr->second;
@ -159,12 +164,38 @@ void CEnhancements::UpdateEnhancements(const CEnhancementList & Enhancements)
g_Notify->BreakPoint(__FILE__, __LINE__);
continue;
}
m_EnhancementFile->AddEnhancement(m_SectionIdent.c_str(), Enhancement);
m_EnhancementFile->AddEnhancement(SectionIdent.c_str(), Enhancement);
}
m_EnhancementFile->SaveCurrentSection();
m_UpdateCheats = true;
}
void CEnhancements::ResetActive(CPlugins * Plugins)
{
bool inBasicMode = g_Settings->LoadBool(UserInterface_BasicMode);
bool CheatsRemembered = !inBasicMode && g_Settings->LoadBool(Setting_RememberCheats);
if (CheatsRemembered || m_ActiveCodes.empty())
{
return;
}
bool reset = false;
for (CEnhancementList::iterator itr = m_Cheats.begin(); itr != m_Cheats.end(); itr++)
{
if (!itr->second.Active())
{
continue;
}
itr->second.SetActive(false);
reset = true;
}
if (reset)
{
m_ActiveCodes.clear();
LoadActive(m_Enhancements, Plugins);
}
}
void CEnhancements::ResetCodes(CMipsMemoryVM * MMU)
{
m_ActiveCodes.clear();
@ -197,7 +228,8 @@ void CEnhancements::ResetCodes(CMipsMemoryVM * MMU)
void CEnhancements::LoadEnhancements(const char * Ident, SectionFiles & Files, std::unique_ptr<CEnhancmentFile> & File, CEnhancementList & EnhancementList)
{
SectionFiles::const_iterator CheatFileItr = Files.find(m_SectionIdent);
std::string SectionIdent = g_Settings->LoadStringVal(Game_IniKey);
SectionFiles::const_iterator CheatFileItr = Files.find(SectionIdent);
bool FoundFile = false;
if (CheatFileItr != Files.end())
{
@ -205,7 +237,7 @@ void CEnhancements::LoadEnhancements(const char * Ident, SectionFiles & Files, s
if (CheatFile.Exists())
{
File = std::make_unique<CEnhancmentFile>(CheatFile, Ident);
File->GetEnhancementList(m_SectionIdent.c_str(), EnhancementList);
File->GetEnhancementList(SectionIdent.c_str(), EnhancementList);
FoundFile = true;
}
}
@ -217,7 +249,7 @@ void CEnhancements::LoadEnhancements(const char * Ident, SectionFiles & Files, s
}
}
void CEnhancements::LoadCheats(CMipsMemoryVM * MMU)
void CEnhancements::Load(CMipsMemoryVM * MMU, CPlugins * Plugins)
{
WaitScanDone();
CGuard Guard(m_CS);
@ -226,11 +258,11 @@ void CEnhancements::LoadCheats(CMipsMemoryVM * MMU)
LoadEnhancements("Enhancement", m_EnhancementFiles, m_EnhancementFile, m_Enhancements);
ResetCodes(MMU);
LoadActive(m_Cheats);
LoadActive(m_Enhancements);
LoadActive(m_Cheats, nullptr);
LoadActive(m_Enhancements, Plugins);
}
void CEnhancements::LoadActive(CEnhancementList & List)
void CEnhancements::LoadActive(CEnhancementList & List, CPlugins * Plugins)
{
for (CEnhancementList::const_iterator itr = List.begin(); itr != List.end(); itr++)
{
@ -240,6 +272,40 @@ void CEnhancements::LoadActive(CEnhancementList & List)
continue;
}
if (Plugins != nullptr && !Enhancement.GetPluginList().empty())
{
bool LoadEntry = false;
const CEnhancement::PluginList & PluginList = Enhancement.GetPluginList();
for (size_t i = 0, n = PluginList.size(); i < n; i++)
{
std::string PluginName = stdstr(PluginList[i]).Trim();
if (Plugins->Gfx() != NULL && strstr(Plugins->Gfx()->PluginName(), PluginName.c_str()) != nullptr)
{
LoadEntry = true;
break;
}
if (Plugins->Audio() != NULL && strstr(Plugins->Audio()->PluginName(), PluginName.c_str()) != nullptr)
{
LoadEntry = true;
break;
}
if (Plugins->RSP() != NULL && strstr(Plugins->RSP()->PluginName(), PluginName.c_str()) != nullptr)
{
LoadEntry = true;
break;
}
if (Plugins->Control() != NULL && strstr(Plugins->Control()->PluginName(), PluginName.c_str()) != nullptr)
{
LoadEntry = true;
break;
}
}
if (!LoadEntry)
{
continue;
}
}
const CEnhancement::CodeEntries Entries = Enhancement.GetEntries();
CODES Code;
for (size_t i = 0, n = Entries.size(); i < n; i++)
@ -592,33 +658,6 @@ void CEnhancements::WaitScanDone()
}
}
void CEnhancements::GameChanged(void)
{
bool inBasicMode = g_Settings->LoadBool(UserInterface_BasicMode);
bool CheatsRemembered = !inBasicMode && g_Settings->LoadBool(Setting_RememberCheats);
m_SectionIdent = g_Settings->LoadStringVal(Game_IniKey);
LoadCheats(nullptr);
if (!CheatsRemembered && !m_ActiveCodes.empty())
{
bool reset = false;
for (CEnhancementList::iterator itr = m_Cheats.begin(); itr != m_Cheats.end(); itr++)
{
if (!itr->second.Active())
{
continue;
}
itr->second.SetActive(false);
reset = true;
}
if (reset)
{
m_ActiveCodes.clear();
LoadActive(m_Enhancements);
}
}
}
uint32_t CEnhancements::ConvertXP64Address(uint32_t Address)
{
uint32_t tmpAddress = (Address ^ 0x68000000) & 0xFF000000;

View File

@ -17,6 +17,7 @@
#include <string>
class CMipsMemoryVM;
class CPlugins;
class CEnhancements
{
@ -29,12 +30,14 @@ public:
CEnhancements();
~CEnhancements();
void ApplyActive(CMipsMemoryVM & MMU, bool UpdateChanges);
void ApplyActive(CMipsMemoryVM & MMU, CPlugins * Plugins, bool UpdateChanges);
void ApplyGSButton(CMipsMemoryVM & MMU, bool UpdateChanges);
void UpdateCheats(const CEnhancementList & Cheats);
void UpdateCheats(void);
void UpdateEnhancements(const CEnhancementList & Enhancements);
void ResetActive(CPlugins * Plugins);
void Load(CMipsMemoryVM * MMU, CPlugins * Plugins);
inline const CEnhancementList & Cheats(void) const { return m_Cheats; }
inline const CEnhancementList & Enhancements(void) const { return m_Enhancements; }
@ -64,8 +67,7 @@ private:
typedef std::map<uint32_t, MEM_VALUE8> ORIGINAL_VALUES8;
void ResetCodes(CMipsMemoryVM * MMU);
void LoadCheats(CMipsMemoryVM * MMU);
void LoadActive(CEnhancementList & List);
void LoadActive(CEnhancementList & List, CPlugins * Plugins);
void LoadEnhancements(const char * Ident, SectionFiles & Files, std::unique_ptr<CEnhancmentFile> & File, CEnhancementList & EnhancementList);
void ApplyGameSharkCodes(CMipsMemoryVM & MMU, CODES & CodeEntry, uint32_t CurrentEntry);
uint32_t EntrySize(const CODES & CodeEntry, uint32_t CurrentEntry);
@ -79,10 +81,8 @@ private:
static uint16_t ConvertXP64Value(uint16_t Value);
static uint32_t stScanFileThread(void * lpThreadParameter) { ((CEnhancements *)lpThreadParameter)->ScanFileThread(); return 0; }
static void stGameChanged(void * lpData) { ((CEnhancements *)lpData)->GameChanged(); }
CriticalSection m_CS;
std::string m_SectionIdent;
SectionFiles m_CheatFiles, m_EnhancementFiles;
std::unique_ptr<CEnhancmentFile> m_CheatFile, m_EnhancementFile;
CEnhancementList m_Cheats;

View File

@ -128,6 +128,8 @@ CN64System::CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesR
g_Settings->SaveBool(Game_LoadSaveAtStart, false);
}
}
g_Enhancements->ResetActive(Plugins);
g_Enhancements->UpdateCheats();
WriteTrace(TraceN64System, TraceDebug, "Done");
}
@ -359,7 +361,6 @@ bool CN64System::LoadFileImage(const char * FileLoc)
g_Settings->SaveString(Game_File, FileLoc);
}
g_Settings->SaveBool(GameRunning_LoadingInProgress, false);
WriteTrace(TraceN64System, TraceDebug, "Finished Loading (GoodName: %s)", g_Settings->LoadStringVal(Rdb_GoodName).c_str());
}
else
@ -2443,7 +2444,7 @@ void CN64System::RefreshScreen()
}
if ((m_Reg.STATUS_REGISTER & STATUS_IE) != 0)
{
g_Enhancements->ApplyActive(m_MMU_VM, !m_SyncSystem);
g_Enhancements->ApplyActive(m_MMU_VM, g_BaseSystem->m_Plugins, !m_SyncSystem);
}
// if (bProfiling) { m_Profile.StartTimer(ProfilingAddr != Timer_None ? ProfilingAddr : Timer_R4300); }
}

View File

@ -142,9 +142,9 @@ public:
bool ResetInUiThread(CN64System * System);
void GameReset(void);
inline CGfxPlugin * Gfx(void) const { return m_Gfx; }
inline CAudioPlugin * Audio(void) const { return m_Audio; }
inline CRSP_Plugin * RSP(void) const { return m_RSP; }
inline CGfxPlugin * Gfx(void) const { return m_Gfx; }
inline CAudioPlugin * Audio(void) const { return m_Audio; }
inline CRSP_Plugin * RSP(void) const { return m_RSP; }
inline CControl_Plugin * Control(void) const { return m_Control; }
inline RenderWindow * MainWindow(void) const { return m_MainWindow; }

View File

@ -86,8 +86,8 @@ class CEditPluginList :
public:
BEGIN_MSG_MAP_EX(CEditPluginList)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER(ID_ADD, OnAddBtn)
COMMAND_ID_HANDLER(ID_REMOVE, OnRemoveBtn)
COMMAND_ID_HANDLER(IDC_ADD, OnAddBtn)
COMMAND_ID_HANDLER(IDC_REMOVE, OnRemoveBtn)
COMMAND_ID_HANDLER(IDOK, OnOkCmd)
COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd)
END_MSG_MAP()

View File

@ -14,6 +14,7 @@
#include <commctrl.h>
#include <Project64-core/Settings/SettingType/SettingsType-Application.h>
#include <Project64-core/N64System/Enhancement/Enhancements.h>
#include <Project64-core/N64System/N64DiskClass.h>
#include "DiscordRPC.h"
@ -949,10 +950,13 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO
}
else if (LOWORD(wParam) == ID_POPUPMENU_EDITCHEATS)
{
g_Enhancements->ResetActive(nullptr);
g_Enhancements->Load(nullptr, nullptr);
_this->m_CheatsUI.Display(hWnd, true);
}
else if (LOWORD(wParam) == ID_POPUPMENU_CHOOSEENHANCEMENT)
{
g_Enhancements->Load(nullptr, nullptr);
_this->m_EnhancementUI.Display(hWnd, true);
}

View File

@ -95,9 +95,9 @@ LRESULT CSettingConfig::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*
//Set the text for all gui Items
SetDlgItemText(IDC_RESET_PAGE, wGS(BOTTOM_RESET_PAGE).c_str());
SetDlgItemText(IDC_RESET_ALL, wGS(BOTTOM_RESET_ALL).c_str());
SetDlgItemText(IDOK, wGS(CHEAT_OK).c_str());
SetDlgItemText(IDCANCEL, wGS(CHEAT_CANCEL).c_str());
SetDlgItemText(IDAPPLY, wGS(BOTTOM_APPLY).c_str());
SetDlgItemText(IDC_OK, wGS(CHEAT_OK).c_str());
SetDlgItemText(IDC_CANCEL, wGS(CHEAT_CANCEL).c_str());
SetDlgItemText(IDC_APPLY, wGS(BOTTOM_APPLY).c_str());
if (m_GameConfig)
{
@ -216,14 +216,14 @@ LRESULT CSettingConfig::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL& /*
{
switch (wID)
{
case IDAPPLY:
case IDC_APPLY:
ApplySettings(true);
break;
case IDOK:
case IDC_OK:
ApplySettings(false);
EndDialog(1);
break;
case IDCANCEL:
case IDC_CANCEL:
EndDialog(0);
break;
case IDC_RESET_PAGE:
@ -278,7 +278,7 @@ void CSettingConfig::ApplySettings(bool UpdateScreen)
if (UpdateScreen)
{
::EnableWindow(GetDlgItem(IDAPPLY), false);
::EnableWindow(GetDlgItem(IDC_APPLY), false);
::EnableWindow(GetDlgItem(IDC_RESET_PAGE), m_CurrentPage->EnableReset());
}
@ -354,7 +354,7 @@ LRESULT CSettingConfig::OnPageListClicked(NMHDR*)
LRESULT CSettingConfig::OnSettingPageChanged(UINT /*uMsg*/, WPARAM /*wPage*/, LPARAM /*lParam*/)
{
::EnableWindow(GetDlgItem(IDAPPLY), true);
::EnableWindow(GetDlgItem(IDC_APPLY), true);
::EnableWindow(GetDlgItem(IDC_RESET_PAGE), m_CurrentPage->EnableReset());
BoldChangedPages(m_PagesTreeList.GetRootItem());
return 0;

View File

@ -40,9 +40,9 @@ private:
typedef std::list<CConfigSettingSection *> SETTING_SECTIONS;
CTreeViewCtrl m_PagesTreeList;
CTreeViewCtrl m_PagesTreeList;
SETTING_SECTIONS m_Sections;
CSettingsPage * m_CurrentPage, *m_GeneralOptionsPage, *m_AdvancedPage, *m_DefaultsPage, *m_DiskDrivePage;
bool m_GameConfig;
bool m_bTVNSelChangedSupported;
CSettingsPage * m_CurrentPage, *m_GeneralOptionsPage, *m_AdvancedPage, *m_DefaultsPage, *m_DiskDrivePage;
bool m_GameConfig;
bool m_bTVNSelChangedSupported;
};

View File

@ -538,13 +538,13 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTI
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
DEFPUSHBUTTON "OK",IDOK,194,196,50,14
PUSHBUTTON "Cancel",IDCANCEL,248,196,50,14
DEFPUSHBUTTON "OK",IDC_OK,194,196,50,14
PUSHBUTTON "Cancel",IDC_CANCEL,248,196,50,14
CONTROL "Tree1",IDC_PAGELIST,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS | WS_BORDER | WS_HSCROLL | WS_TABSTOP,8,7,116,180
CONTROL "",IDC_STATIC,"Static",SS_BLACKFRAME | SS_SUNKEN,7,192,343,1
PUSHBUTTON "Reset Page",IDC_RESET_PAGE,7,196,58,14,WS_DISABLED
CONTROL "",IDC_SETTING_INFO,"Static",SS_ETCHEDFRAME,131,7,219,181
PUSHBUTTON "Apply",IDAPPLY,301,196,50,14,WS_DISABLED
PUSHBUTTON "Apply",IDC_APPLY,301,196,50,14,WS_DISABLED
PUSHBUTTON "Reset All",IDC_RESET_ALL,68,196,52,14,WS_DISABLED
END
@ -1411,8 +1411,8 @@ BEGIN
DEFPUSHBUTTON "OK",IDOK,7,165,50,14
PUSHBUTTON "Cancel",IDCANCEL,65,165,50,14
LISTBOX IDC_PLUGIN_LIST,7,43,109,97,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
DEFPUSHBUTTON "Add",ID_ADD,66,23,50,14
DEFPUSHBUTTON "Remove",ID_REMOVE,66,143,50,14
DEFPUSHBUTTON "Add",IDC_ADD,66,23,50,14
DEFPUSHBUTTON "Remove",IDC_REMOVE,66,143,50,14
EDITTEXT IDC_ADD_EDIT,7,7,109,12,ES_AUTOHSCROLL
END

View File

@ -2,13 +2,6 @@
// Microsoft Visual C++ generated include file.
// Used by UIResources.rc
//
#define VERSION_REVISION 0
#define VER_VER_DEBUG 0
#define VERSION_MAJOR 2
#define IDAPPLY 3
#define VERSION_MINOR 4
#define ID_ADD 4
#define ID_REMOVE 5
#define IDI_PJ64_Icon 101
#define IDD_Rom_Information 104
#define IDD_Key_Prompt 108
@ -612,7 +605,6 @@
#define IDC_CHK_CPU 1473
#define IDC_CHK_OV 1474
#define IDC_CHK_TRAP 1475
#define VERSION_BUILD 1475
#define IDC_CHK_VCEI 1476
#define IDC_CHK_FPE 1477
#define IDC_CHK_WATCH 1478
@ -869,6 +861,9 @@
#define IDC_DD44_LBL 1720
#define IDC_DD48_LBL 1721
#define IDC_COPYALLREGISTERS_BTN 1722
#define IDC_OK 1723
#define IDC_CANCEL 1724
#define IDC_APPLY 1725
#define ID_POPUPMENU_PLAYGAMEWITHDISK 40008
#define ID_POPUPMENU_ADDSYMBOL 40013
#define ID_POPUPMENU_VIEWDISASM 40017
@ -942,7 +937,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 225
#define _APS_NEXT_COMMAND_VALUE 40121
#define _APS_NEXT_CONTROL_VALUE 1586
#define _APS_NEXT_CONTROL_VALUE 1726
#define _APS_NEXT_SYMED_VALUE 102
#endif
#endif