Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Support a gcm revision-specific game ini for cheats + partially fix g…
…ecko codes in default ini.

The local ini is not revision-specific because it would require renaming
everything.  Meh.
  • Loading branch information
comex committed Sep 29, 2013
1 parent 1ed06f1 commit f57ff0a
Show file tree
Hide file tree
Showing 25 changed files with 136 additions and 95 deletions.
4 changes: 2 additions & 2 deletions Source/Core/Core/Src/ActionReplay.h
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions Source/Core/Core/Src/Boot/Boot_BS2Emu.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/Src/Boot/Boot_WiiWAD.cpp
Expand Up @@ -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;
}
Expand Down
9 changes: 6 additions & 3 deletions Source/Core/Core/Src/BootManager.cpp
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions Source/Core/Core/Src/Core.cpp
Expand Up @@ -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"));
Expand Down
27 changes: 27 additions & 0 deletions Source/Core/Core/Src/CoreParameter.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
5 changes: 5 additions & 0 deletions Source/Core/Core/Src/CoreParameter.h
Expand Up @@ -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
Expand All @@ -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
3 changes: 2 additions & 1 deletion Source/Core/Core/Src/GeckoCode.h
Expand Up @@ -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);
Expand Down
104 changes: 54 additions & 50 deletions Source/Core/Core/Src/GeckoCodeConfig.cpp
Expand Up @@ -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;

std::istringstream ss(*lines_iter);

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;
}

// 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;

// 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;
}

// 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)
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/Src/GeckoCodeConfig.h
Expand Up @@ -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);

};
Expand Down
15 changes: 6 additions & 9 deletions Source/Core/Core/Src/PatchEngine.cpp
Expand Up @@ -28,6 +28,7 @@
#include "GeckoCode.h"
#include "GeckoCodeConfig.h"
#include "FileUtil.h"
#include "ConfigManager.h"

using namespace Common;

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/Src/PatchEngine.h
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DiscIO/Src/Volume.h
Expand Up @@ -25,6 +25,7 @@ class IVolume
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?
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/DiscIO/Src/VolumeGC.cpp
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DiscIO/Src/VolumeGC.h
Expand Up @@ -20,6 +20,7 @@ class CVolumeGC : public IVolume
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;
Expand Down
9 changes: 4 additions & 5 deletions Source/Core/DolphinWX/Src/CheatsWindow.cpp
Expand Up @@ -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();

Expand Down Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion Source/Core/DolphinWX/Src/CheatsWindow.h
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinWX/Src/GeckoCodeDiag.cpp
Expand Up @@ -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);
}
Expand Down

0 comments on commit f57ff0a

Please sign in to comment.