Support a gcm revision-specific game ini for cheats + partially fix gecko codes in default ini.

The local ini is not revision-specific because it would require renaming
everything.  Meh.
This commit is contained in:
comex 2013-09-23 02:39:14 -04:00
parent 1ed06f1dc4
commit f57ff0a569
25 changed files with 134 additions and 93 deletions

View File

@ -28,8 +28,8 @@ struct ARCode
void RunAllActive();
bool RunCode(const ARCode &arcode);
void LoadCodes(IniFile &globalIni, IniFile &localIni, bool forceLoad);
void LoadCodes(std::vector<ARCode> &_arCodes, IniFile &globalIni, IniFile &localIni);
void LoadCodes(IniFile &globalini, IniFile &localIni, bool forceLoad);
void LoadCodes(std::vector<ARCode> &_arCodes, IniFile &globalini, IniFile &localIni);
size_t GetCodeListSize();
ARCode GetARCode(size_t index);
void SetARCode_IsActive(bool active, size_t index);

View File

@ -149,8 +149,7 @@ bool CBoot::EmulatedBS2_GC()
PC = PowerPC::ppcState.gpr[3];
// Load patches
std::string gameID = VolumeHandler::GetVolume()->GetUniqueID();
PatchEngine::LoadPatches(gameID.c_str());
PatchEngine::LoadPatches();
PowerPC::ppcState.DebugCount = 0;
@ -422,7 +421,7 @@ bool CBoot::EmulatedBS2_Wii()
// Load patches and run startup patches
std::string gameID = VolumeHandler::GetVolume()->GetUniqueID();
PatchEngine::LoadPatches(gameID.c_str());
PatchEngine::LoadPatches();
// return
PC = PowerPC::ppcState.gpr[3];

View File

@ -118,7 +118,7 @@ bool CBoot::Boot_WiiWAD(const char* _pFilename)
// Load patches and run startup patches
const DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(_pFilename);
if (pVolume != NULL)
PatchEngine::LoadPatches(pVolume->GetUniqueID().c_str());
PatchEngine::LoadPatches();
return true;
}

View File

@ -75,14 +75,17 @@ bool BootCore(const std::string& _rFilename)
// Load game specific settings
std::string unique_id = StartUp.GetUniqueID();
std::string revision_specific = StartUp.m_strRevisionSpecificUniqueID;
StartUp.m_strGameIniDefault = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + unique_id + ".ini";
if (revision_specific != "")
StartUp.m_strGameIniDefaultRevisionSpecific = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + revision_specific + ".ini";
else
StartUp.m_strGameIniDefaultRevisionSpecific = "";
StartUp.m_strGameIniLocal = File::GetUserPath(D_GAMESETTINGS_IDX) + unique_id + ".ini";
if (unique_id.size() == 6)
{
IniFile game_ini;
game_ini.Load(StartUp.m_strGameIniDefault);
game_ini.Load(StartUp.m_strGameIniLocal, true);
IniFile game_ini = StartUp.LoadGameIni();
config_cache.valid = true;
config_cache.bCPUThread = StartUp.bCPUThread;

View File

@ -204,9 +204,7 @@ bool Init()
g_aspect_wide = _CoreParameter.bWii;
if (g_aspect_wide)
{
IniFile gameIni;
gameIni.Load(_CoreParameter.m_strGameIniDefault.c_str());
gameIni.Load(_CoreParameter.m_strGameIniLocal.c_str(), true);
IniFile gameIni = _CoreParameter.LoadGameIni();
gameIni.Get("Wii", "Widescreen", &g_aspect_wide,
!!SConfig::GetInstance().m_SYSCONF->
GetData<u8>("IPL.AR"));

View File

@ -147,6 +147,7 @@ bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2)
}
m_strName = pVolume->GetName();
m_strUniqueID = pVolume->GetUniqueID();
m_strRevisionSpecificUniqueID = pVolume->GetRevisionSpecificUniqueID();
// Check if we have a Wii disc
bWii = DiscIO::IsVolumeWiiDisc(pVolume);
@ -390,3 +391,29 @@ void SCoreStartupParameter::CheckMemcardPath(std::string& memcardPath, std::stri
}
}
}
IniFile SCoreStartupParameter::LoadGameIni() const
{
IniFile game_ini;
game_ini.Load(m_strGameIniDefault);
if (m_strGameIniDefaultRevisionSpecific != "")
game_ini.Load(m_strGameIniDefaultRevisionSpecific, true);
game_ini.Load(m_strGameIniLocal, true);
return game_ini;
}
IniFile SCoreStartupParameter::LoadDefaultGameIni() const
{
IniFile game_ini;
game_ini.Load(m_strGameIniDefault);
if (m_strGameIniDefaultRevisionSpecific != "")
game_ini.Load(m_strGameIniDefaultRevisionSpecific, true);
return game_ini;
}
IniFile SCoreStartupParameter::LoadLocalGameIni() const
{
IniFile game_ini;
game_ini.Load(m_strGameIniLocal);
return game_ini;
}

View File

@ -197,8 +197,10 @@ struct SCoreStartupParameter
std::string m_strDVDRoot;
std::string m_strApploader;
std::string m_strUniqueID;
std::string m_strRevisionSpecificUniqueID;
std::string m_strName;
std::string m_strGameIniDefault;
std::string m_strGameIniDefaultRevisionSpecific;
std::string m_strGameIniLocal;
// Constructor just calls LoadDefaults
@ -208,6 +210,9 @@ struct SCoreStartupParameter
bool AutoSetup(EBootBS2 _BootBS2);
const std::string &GetUniqueID() const { return m_strUniqueID; }
void CheckMemcardPath(std::string& memcardPath, std::string Region, bool isSlotA);
IniFile LoadDefaultGameIni() const;
IniFile LoadLocalGameIni() const;
IniFile LoadGameIni() const;
};
#endif

View File

@ -65,7 +65,8 @@ namespace Gecko
std::string name, creator;
std::vector<std::string> notes;
bool enabled;
bool enabled;
bool user_defined;
bool Compare(GeckoCode compare) const;
bool Exist(u32 address, u32 data);

View File

@ -15,70 +15,74 @@
namespace Gecko
{
// TODO: Support loading codes from default game inis.
void LoadCodes(const IniFile& inifile, std::vector<GeckoCode>& gcodes)
void LoadCodes(const IniFile& globalIni, const IniFile& localIni, std::vector<GeckoCode>& gcodes)
{
std::vector<std::string> lines;
inifile.GetLines(GECKO_CODE_INI_SECTION, lines, false);
GeckoCode gcode;
std::vector<std::string>::const_iterator
lines_iter = lines.begin(),
lines_end = lines.end();
for (; lines_iter!=lines_end; ++lines_iter)
const IniFile* inis[] = {&globalIni, &localIni};
for (size_t i = 0; i < ArraySize(inis); ++i)
{
if (lines_iter->empty())
continue;
std::vector<std::string> lines;
inis[i]->GetLines(GECKO_CODE_INI_SECTION, lines, false);
std::istringstream ss(*lines_iter);
GeckoCode gcode;
switch ((*lines_iter)[0])
for (auto lines_iter = lines.begin(); lines_iter!=lines.end(); ++lines_iter)
{
if (lines_iter->empty())
continue;
// enabled or disabled code
case '+' :
ss.seekg(1);
case '$' :
if (gcode.name.size())
gcodes.push_back(gcode);
gcode = GeckoCode();
gcode.enabled = (1 == ss.tellg()); // silly
ss.seekg(1, std::ios_base::cur);
// read the code name
std::getline(ss, gcode.name, '['); // stop at [ character (beginning of contributor name)
gcode.name = StripSpaces(gcode.name);
// read the code creator name
std::getline(ss, gcode.creator, ']');
break;
std::istringstream ss(*lines_iter);
// notes
case '*':
gcode.notes.push_back(std::string(++lines_iter->begin(), lines_iter->end()));
break;
switch ((*lines_iter)[0])
{
// enabled or disabled code
case '+' :
ss.seekg(1);
case '$' :
if (gcode.name.size())
gcodes.push_back(gcode);
gcode = GeckoCode();
gcode.enabled = (1 == ss.tellg()); // silly
gcode.user_defined = i == 1;
ss.seekg(1, std::ios_base::cur);
// read the code name
std::getline(ss, gcode.name, '['); // stop at [ character (beginning of contributor name)
gcode.name = StripSpaces(gcode.name);
// read the code creator name
std::getline(ss, gcode.creator, ']');
break;
// notes
case '*':
gcode.notes.push_back(std::string(++lines_iter->begin(), lines_iter->end()));
break;
// either part of the code, or an option choice
default :
{
GeckoCode::Code new_code;
// TODO: support options
new_code.original_line = *lines_iter;
ss >> std::hex >> new_code.address >> new_code.data;
gcode.codes.push_back(new_code);
}
break;
}
// either part of the code, or an option choice
default :
{
GeckoCode::Code new_code;
// TODO: support options
new_code.original_line = *lines_iter;
ss >> std::hex >> new_code.address >> new_code.data;
gcode.codes.push_back(new_code);
}
break;
}
// add the last code
if (gcode.name.size())
gcodes.push_back(gcode);
}
// add the last code
if (gcode.name.size())
gcodes.push_back(gcode);
}
// used by the SaveGeckoCodes function
void SaveGeckoCode(std::vector<std::string>& lines, const GeckoCode& gcode)
{
if (!gcode.user_defined)
return;
std::string name;
if (gcode.enabled)

View File

@ -12,7 +12,7 @@
namespace Gecko
{
void LoadCodes(const IniFile& inifile, std::vector<GeckoCode>& gcodes);
void LoadCodes(const IniFile& globalIni, const IniFile& localIni, std::vector<GeckoCode>& gcodes);
void SaveCodes(IniFile& inifile, const std::vector<GeckoCode>& gcodes);
};

View File

@ -28,6 +28,7 @@
#include "GeckoCode.h"
#include "GeckoCodeConfig.h"
#include "FileUtil.h"
#include "ConfigManager.h"
using namespace Common;
@ -166,22 +167,18 @@ int GetSpeedhackCycles(const u32 addr)
return iter->second;
}
void LoadPatches(const char *gameID)
void LoadPatches()
{
IniFile globalIni, localIni;
globalIni.Load(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + gameID + ".ini");
localIni.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + gameID + ".ini", true);
IniFile merged;
merged.Load(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + gameID + ".ini");
merged.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + gameID + ".ini", true);
IniFile merged = SConfig::GetInstance().m_LocalCoreStartupParameter.LoadGameIni();
IniFile globalIni = SConfig::GetInstance().m_LocalCoreStartupParameter.LoadDefaultGameIni();
IniFile localIni = SConfig::GetInstance().m_LocalCoreStartupParameter.LoadLocalGameIni();
LoadPatchSection("OnFrame", onFrame, globalIni, localIni);
ActionReplay::LoadCodes(globalIni, localIni, false);
// lil silly
std::vector<Gecko::GeckoCode> gcodes;
Gecko::LoadCodes(localIni, gcodes);
Gecko::LoadCodes(globalIni, localIni, gcodes);
Gecko::SetActiveCodes(gcodes);
LoadSpeedhacks("Speedhacks", speedHacks, merged);

View File

@ -39,7 +39,7 @@ struct Patch
int GetSpeedhackCycles(const u32 addr);
void LoadPatchSection(const char *section, std::vector<Patch> &patches,
IniFile &globalIni, IniFile &localIni);
void LoadPatches(const char *gameID);
void LoadPatches();
void ApplyFramePatches();
void ApplyARPatches();
void Shutdown();

View File

@ -25,6 +25,7 @@ public:
virtual bool GetTitleID(u8*) const { return false; }
virtual void GetTMD(u8*, u32 *_sz) const { *_sz=0; }
virtual std::string GetUniqueID() const = 0;
virtual std::string GetRevisionSpecificUniqueID() const { return ""; }
virtual std::string GetMakerID() const = 0;
virtual int GetRevision() const { return 0; }
// TODO: eliminate?

View File

@ -54,6 +54,13 @@ std::string CVolumeGC::GetUniqueID() const
return ID;
}
std::string CVolumeGC::GetRevisionSpecificUniqueID() const
{
char rev[16];
sprintf(rev, "r%d", GetRevision());
return GetUniqueID() + rev;
}
IVolume::ECountry CVolumeGC::GetCountry() const
{
if (!m_pReader)

View File

@ -20,6 +20,7 @@ public:
bool Read(u64 _Offset, u64 _Length, u8* _pBuffer) const;
bool RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const;
std::string GetUniqueID() const;
std::string GetRevisionSpecificUniqueID() const;
std::string GetMakerID() const;
int GetRevision() const;
std::vector<std::string> GetNames() const;

View File

@ -242,10 +242,9 @@ void wxCheatsWindow::OnEvent_Close(wxCloseEvent& ev)
void wxCheatsWindow::UpdateGUI()
{
// load code
m_gameini_default_path = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + Core::g_CoreStartupParameter.GetUniqueID() + ".ini";
m_gameini_default.Load(m_gameini_default_path);
m_gameini_local_path = File::GetUserPath(D_GAMESETTINGS_IDX) + Core::g_CoreStartupParameter.GetUniqueID() + ".ini";
m_gameini_local.Load(m_gameini_local_path, true);
m_gameini_default = Core::g_CoreStartupParameter.LoadDefaultGameIni();
m_gameini_local = Core::g_CoreStartupParameter.LoadLocalGameIni();
m_gameini_local_path = Core::g_CoreStartupParameter.m_strGameIniLocal;
Load_ARCodes();
Load_GeckoCodes();
@ -286,7 +285,7 @@ void wxCheatsWindow::Load_ARCodes()
void wxCheatsWindow::Load_GeckoCodes()
{
m_geckocode_panel->LoadCodes(m_gameini_local, Core::g_CoreStartupParameter.GetUniqueID(), true);
m_geckocode_panel->LoadCodes(m_gameini_default, m_gameini_local, Core::g_CoreStartupParameter.GetUniqueID(), true);
}
void wxCheatsWindow::OnEvent_CheatsList_ItemSelected(wxCommandEvent& WXUNUSED (event))

View File

@ -132,7 +132,6 @@ class wxCheatsWindow : public wxDialog
Gecko::CodeConfigPanel *m_geckocode_panel;
IniFile m_gameini_default;
IniFile m_gameini_local;
std::string m_gameini_default_path;
std::string m_gameini_local_path;
void Init_ChildControls();

View File

@ -81,13 +81,13 @@ void CodeConfigPanel::UpdateCodeList(bool checkRunning)
UpdateInfoBox(evt);
}
void CodeConfigPanel::LoadCodes(const IniFile& inifile, const std::string& gameid, bool checkRunning)
void CodeConfigPanel::LoadCodes(const IniFile& globalIni, const IniFile& localIni, const std::string& gameid, bool checkRunning)
{
m_gameid = gameid;
m_gcodes.clear();
if (!checkRunning || Core::IsRunning())
Gecko::LoadCodes(inifile, m_gcodes);
Gecko::LoadCodes(globalIni, localIni, m_gcodes);
UpdateCodeList(checkRunning);
}

View File

@ -20,7 +20,7 @@ public:
CodeConfigPanel(wxWindow* const parent);
void LoadCodes(const IniFile& inifile, const std::string& gameid = "", bool checkRunning = false);
void LoadCodes(const IniFile& globalIni, const IniFile& localIni, const std::string& gameid = "", bool checkRunning = false);
const std::vector<GeckoCode>& GetCodes() const { return m_gcodes; }
protected:

View File

@ -110,6 +110,7 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW
// Load game ini
std::string _iniFilename = OpenISO->GetUniqueID();
std::string _iniFilenameRevisionSpecific = OpenISO->GetRevisionSpecificUniqueID();
if (!_iniFilename.length())
{
@ -123,9 +124,12 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW
}
GameIniFileDefault = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + _iniFilename + ".ini";
std::string GameIniFileDefaultRevisionSpecific = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + _iniFilenameRevisionSpecific + ".ini";
GameIniFileLocal = File::GetUserPath(D_GAMESETTINGS_IDX) + _iniFilename + ".ini";
GameIniDefault.Load(GameIniFileDefault);
if (_iniFilenameRevisionSpecific != "")
GameIniDefault.Load(GameIniFileDefaultRevisionSpecific);
GameIniLocal.Load(GameIniFileLocal);
// Setup GUI
@ -1047,7 +1051,7 @@ void CISOProperties::LoadGameConfig()
PatchList_Load();
ActionReplayList_Load();
m_geckocode_panel->LoadCodes(GameIniLocal, OpenISO->GetUniqueID());
m_geckocode_panel->LoadCodes(GameIniDefault, GameIniLocal, OpenISO->GetUniqueID());
}
void CISOProperties::SaveGameIniValueFrom3StateCheckbox(const char* section, const char* key, wxCheckBox* checkbox)

View File

@ -12,6 +12,7 @@
#include "Core.h"
#include "Movie.h"
#include "OnScreenDisplay.h"
#include "ConfigManager.h"
VideoConfig g_Config;
VideoConfig g_ActiveConfig;
@ -120,7 +121,7 @@ void VideoConfig::Load(const char *ini_file)
OSD::AddMessage("Warning: Shader Debugging is enabled, performance will suffer heavily", 15000);
}
void VideoConfig::GameIniLoad(const char* default_ini_file, const char* local_ini_file)
void VideoConfig::GameIniLoad()
{
bool gfx_override_exists = false;
@ -136,9 +137,7 @@ void VideoConfig::GameIniLoad(const char* default_ini_file, const char* local_in
} \
} while (0)
IniFile iniFile;
iniFile.Load(default_ini_file);
iniFile.Load(local_ini_file, true);
IniFile iniFile = SConfig::GetInstance().m_LocalCoreStartupParameter.LoadGameIni();
CHECK_SETTING("Video_Hardware", "VSync", bVSync);

View File

@ -50,10 +50,9 @@ struct VideoConfig
{
VideoConfig();
void Load(const char *ini_file);
void GameIniLoad(const char* default_ini, const char* game_ini);
void GameIniLoad();
void VerifyValidity();
void Save(const char *ini_file);
void GameIniSave(const char* default_ini, const char* game_ini);
void UpdateProjectionHack();
bool IsVSync();

View File

@ -157,7 +157,7 @@ bool VideoBackend::Initialize(void *&window_handle)
const SCoreStartupParameter& core_params = SConfig::GetInstance().m_LocalCoreStartupParameter;
g_Config.Load((File::GetUserPath(D_CONFIG_IDX) + "gfx_dx11.ini").c_str());
g_Config.GameIniLoad(core_params.m_strGameIniDefault.c_str(), core_params.m_strGameIniLocal.c_str());
g_Config.GameIniLoad();
g_Config.UpdateProjectionHack();
g_Config.VerifyValidity();
UpdateActiveConfig();

View File

@ -150,8 +150,7 @@ bool VideoBackend::Initialize(void *&window_handle)
frameCount = 0;
g_Config.Load((File::GetUserPath(D_CONFIG_IDX) + "gfx_dx9.ini").c_str());
g_Config.GameIniLoad(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strGameIniDefault.c_str(),
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strGameIniLocal.c_str());
g_Config.GameIniLoad();
g_Config.UpdateProjectionHack();
g_Config.VerifyValidity();
// as only some driver/hardware configurations support dual source blending only enable it if is

View File

@ -172,8 +172,7 @@ bool VideoBackend::Initialize(void *&window_handle)
frameCount = 0;
g_Config.Load((File::GetUserPath(D_CONFIG_IDX) + "gfx_opengl.ini").c_str());
g_Config.GameIniLoad(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strGameIniDefault.c_str(),
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strGameIniLocal.c_str());
g_Config.GameIniLoad();
g_Config.UpdateProjectionHack();
g_Config.VerifyValidity();
UpdateActiveConfig();