Reformat all the things. Have fun with merge conflicts.

This commit is contained in:
Pierre Bourdon
2016-06-24 10:43:46 +02:00
parent 2115e8a4a6
commit 3570c7f03a
1116 changed files with 187405 additions and 180344 deletions

View File

@ -2,7 +2,6 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
// PatchEngine
// Supports simple memory patches, and has a partial Action Replay implementation
// in ActionReplay.cpp/h.
@ -37,196 +36,194 @@ using namespace Common;
namespace PatchEngine
{
const char *PatchTypeStrings[] =
{
"byte",
"word",
"dword",
const char* PatchTypeStrings[] = {
"byte", "word", "dword",
};
static std::vector<Patch> onFrame;
static std::map<u32, int> speedHacks;
void LoadPatchSection(const std::string& section, std::vector<Patch>& patches, IniFile& globalIni, IniFile& localIni)
void LoadPatchSection(const std::string& section, std::vector<Patch>& patches, IniFile& globalIni,
IniFile& localIni)
{
// Load the name of all enabled patches
std::string enabledSectionName = section + "_Enabled";
std::vector<std::string> enabledLines;
std::set<std::string> enabledNames;
localIni.GetLines(enabledSectionName, &enabledLines);
for (const std::string& line : enabledLines)
{
if (line.size() != 0 && line[0] == '$')
{
std::string name = line.substr(1, line.size() - 1);
enabledNames.insert(name);
}
}
// Load the name of all enabled patches
std::string enabledSectionName = section + "_Enabled";
std::vector<std::string> enabledLines;
std::set<std::string> enabledNames;
localIni.GetLines(enabledSectionName, &enabledLines);
for (const std::string& line : enabledLines)
{
if (line.size() != 0 && line[0] == '$')
{
std::string name = line.substr(1, line.size() - 1);
enabledNames.insert(name);
}
}
const IniFile* inis[2] = {&globalIni, &localIni};
const IniFile* inis[2] = {&globalIni, &localIni};
for (const IniFile* ini : inis)
{
std::vector<std::string> lines;
Patch currentPatch;
ini->GetLines(section, &lines);
for (const IniFile* ini : inis)
{
std::vector<std::string> lines;
Patch currentPatch;
ini->GetLines(section, &lines);
for (std::string& line : lines)
{
if (line.size() == 0)
continue;
for (std::string& line : lines)
{
if (line.size() == 0)
continue;
if (line[0] == '$')
{
// Take care of the previous code
if (currentPatch.name.size())
{
patches.push_back(currentPatch);
}
currentPatch.entries.clear();
if (line[0] == '$')
{
// Take care of the previous code
if (currentPatch.name.size())
{
patches.push_back(currentPatch);
}
currentPatch.entries.clear();
// Set active and name
currentPatch.name = line.substr(1, line.size() - 1);
currentPatch.active = enabledNames.find(currentPatch.name) != enabledNames.end();
currentPatch.user_defined = (ini == &localIni);
}
else
{
std::string::size_type loc = line.find('=');
// Set active and name
currentPatch.name = line.substr(1, line.size() - 1);
currentPatch.active = enabledNames.find(currentPatch.name) != enabledNames.end();
currentPatch.user_defined = (ini == &localIni);
}
else
{
std::string::size_type loc = line.find('=');
if (loc != std::string::npos)
{
line[loc] = ':';
}
if (loc != std::string::npos)
{
line[loc] = ':';
}
std::vector<std::string> items;
SplitString(line, ':', items);
std::vector<std::string> items;
SplitString(line, ':', items);
if (items.size() >= 3)
{
PatchEntry pE;
bool success = true;
success &= TryParse(items[0], &pE.address);
success &= TryParse(items[2], &pE.value);
if (items.size() >= 3)
{
PatchEntry pE;
bool success = true;
success &= TryParse(items[0], &pE.address);
success &= TryParse(items[2], &pE.value);
pE.type = PatchType(std::find(PatchTypeStrings, PatchTypeStrings + 3, items[1]) - PatchTypeStrings);
success &= (pE.type != (PatchType)3);
if (success)
{
currentPatch.entries.push_back(pE);
}
}
}
}
pE.type = PatchType(std::find(PatchTypeStrings, PatchTypeStrings + 3, items[1]) -
PatchTypeStrings);
success &= (pE.type != (PatchType)3);
if (success)
{
currentPatch.entries.push_back(pE);
}
}
}
}
if (currentPatch.name.size() && currentPatch.entries.size())
{
patches.push_back(currentPatch);
}
}
if (currentPatch.name.size() && currentPatch.entries.size())
{
patches.push_back(currentPatch);
}
}
}
static void LoadSpeedhacks(const std::string& section, IniFile& ini)
{
std::vector<std::string> keys;
ini.GetKeys(section, &keys);
for (const std::string& key : keys)
{
std::string value;
ini.GetOrCreateSection(section)->Get(key, &value, "BOGUS");
if (value != "BOGUS")
{
u32 address;
u32 cycles;
bool success = true;
success &= TryParse(key, &address);
success &= TryParse(value, &cycles);
if (success)
{
speedHacks[address] = (int)cycles;
}
}
}
std::vector<std::string> keys;
ini.GetKeys(section, &keys);
for (const std::string& key : keys)
{
std::string value;
ini.GetOrCreateSection(section)->Get(key, &value, "BOGUS");
if (value != "BOGUS")
{
u32 address;
u32 cycles;
bool success = true;
success &= TryParse(key, &address);
success &= TryParse(value, &cycles);
if (success)
{
speedHacks[address] = (int)cycles;
}
}
}
}
int GetSpeedhackCycles(const u32 addr)
{
std::map<u32, int>::const_iterator iter = speedHacks.find(addr);
if (iter == speedHacks.end())
return 0;
else
return iter->second;
std::map<u32, int>::const_iterator iter = speedHacks.find(addr);
if (iter == speedHacks.end())
return 0;
else
return iter->second;
}
void LoadPatches()
{
IniFile merged = SConfig::GetInstance().LoadGameIni();
IniFile globalIni = SConfig::GetInstance().LoadDefaultGameIni();
IniFile localIni = SConfig::GetInstance().LoadLocalGameIni();
IniFile merged = SConfig::GetInstance().LoadGameIni();
IniFile globalIni = SConfig::GetInstance().LoadDefaultGameIni();
IniFile localIni = SConfig::GetInstance().LoadLocalGameIni();
LoadPatchSection("OnFrame", onFrame, globalIni, localIni);
ActionReplay::LoadAndApplyCodes(globalIni, localIni);
LoadPatchSection("OnFrame", onFrame, globalIni, localIni);
ActionReplay::LoadAndApplyCodes(globalIni, localIni);
// lil silly
std::vector<Gecko::GeckoCode> gcodes;
Gecko::LoadCodes(globalIni, localIni, gcodes);
Gecko::SetActiveCodes(gcodes);
// lil silly
std::vector<Gecko::GeckoCode> gcodes;
Gecko::LoadCodes(globalIni, localIni, gcodes);
Gecko::SetActiveCodes(gcodes);
LoadSpeedhacks("Speedhacks", merged);
LoadSpeedhacks("Speedhacks", merged);
}
static void ApplyPatches(const std::vector<Patch> &patches)
static void ApplyPatches(const std::vector<Patch>& patches)
{
for (const Patch& patch : patches)
{
if (patch.active)
{
for (const PatchEntry& entry : patch.entries)
{
u32 addr = entry.address;
u32 value = entry.value;
switch (entry.type)
{
case PATCH_8BIT:
PowerPC::HostWrite_U8((u8)value, addr);
break;
case PATCH_16BIT:
PowerPC::HostWrite_U16((u16)value, addr);
break;
case PATCH_32BIT:
PowerPC::HostWrite_U32(value, addr);
break;
default:
//unknown patchtype
break;
}
}
}
}
for (const Patch& patch : patches)
{
if (patch.active)
{
for (const PatchEntry& entry : patch.entries)
{
u32 addr = entry.address;
u32 value = entry.value;
switch (entry.type)
{
case PATCH_8BIT:
PowerPC::HostWrite_U8((u8)value, addr);
break;
case PATCH_16BIT:
PowerPC::HostWrite_U16((u16)value, addr);
break;
case PATCH_32BIT:
PowerPC::HostWrite_U32(value, addr);
break;
default:
// unknown patchtype
break;
}
}
}
}
}
void ApplyFramePatches()
{
// TODO: Messing with MSR this way is really, really, evil; we should
// probably be using some sort of Gecko OS-style hooking mechanism
// so the emulated CPU is in a predictable state when we process cheats.
u32 oldMSR = MSR;
UReg_MSR newMSR = oldMSR;
newMSR.IR = 1;
newMSR.DR = 1;
MSR = newMSR.Hex;
ApplyPatches(onFrame);
// TODO: Messing with MSR this way is really, really, evil; we should
// probably be using some sort of Gecko OS-style hooking mechanism
// so the emulated CPU is in a predictable state when we process cheats.
u32 oldMSR = MSR;
UReg_MSR newMSR = oldMSR;
newMSR.IR = 1;
newMSR.DR = 1;
MSR = newMSR.Hex;
ApplyPatches(onFrame);
// Run the Gecko code handler
Gecko::RunCodeHandler();
ActionReplay::RunAllActive();
MSR = oldMSR;
// Run the Gecko code handler
Gecko::RunCodeHandler();
ActionReplay::RunAllActive();
MSR = oldMSR;
}
void Shutdown()
{
onFrame.clear();
onFrame.clear();
}
} // namespace