mirror of https://github.com/PCSX2/pcsx2.git
lint: Clang Format files
This commit is contained in:
parent
5ef141187a
commit
279dfd741a
103
pcsx2/Patch.cpp
103
pcsx2/Patch.cpp
|
@ -32,7 +32,7 @@
|
||||||
// This is a declaration for PatchMemory.cpp::_ApplyPatch where we're (patch.cpp)
|
// This is a declaration for PatchMemory.cpp::_ApplyPatch where we're (patch.cpp)
|
||||||
// the only consumer, so it's not made public via Patch.h
|
// the only consumer, so it's not made public via Patch.h
|
||||||
// Applies a single patch line to emulation memory regardless of its "place" value.
|
// Applies a single patch line to emulation memory regardless of its "place" value.
|
||||||
extern void _ApplyPatch(IniPatch *p);
|
extern void _ApplyPatch(IniPatch* p);
|
||||||
|
|
||||||
|
|
||||||
std::vector<IniPatch> Patch;
|
std::vector<IniPatch> Patch;
|
||||||
|
@ -47,43 +47,41 @@ struct PatchTextTable
|
||||||
};
|
};
|
||||||
|
|
||||||
static const PatchTextTable commands_patch[] =
|
static const PatchTextTable commands_patch[] =
|
||||||
{
|
{
|
||||||
{ 1, L"author", PatchFunc::author},
|
{1, L"author", PatchFunc::author},
|
||||||
{ 2, L"comment", PatchFunc::comment },
|
{2, L"comment", PatchFunc::comment},
|
||||||
{ 3, L"patch", PatchFunc::patch },
|
{3, L"patch", PatchFunc::patch},
|
||||||
{ 0, wxEmptyString, NULL } // Array Terminator
|
{0, wxEmptyString, NULL} // Array Terminator
|
||||||
};
|
};
|
||||||
|
|
||||||
static const PatchTextTable dataType[] =
|
static const PatchTextTable dataType[] =
|
||||||
{
|
{
|
||||||
{ 1, L"byte", NULL },
|
{1, L"byte", NULL},
|
||||||
{ 2, L"short", NULL },
|
{2, L"short", NULL},
|
||||||
{ 3, L"word", NULL },
|
{3, L"word", NULL},
|
||||||
{ 4, L"double", NULL },
|
{4, L"double", NULL},
|
||||||
{ 5, L"extended", NULL },
|
{5, L"extended", NULL},
|
||||||
{ 0, wxEmptyString, NULL }
|
{0, wxEmptyString, NULL}};
|
||||||
};
|
|
||||||
|
|
||||||
static const PatchTextTable cpuCore[] =
|
static const PatchTextTable cpuCore[] =
|
||||||
{
|
{
|
||||||
{ 1, L"EE", NULL },
|
{1, L"EE", NULL},
|
||||||
{ 2, L"IOP", NULL },
|
{2, L"IOP", NULL},
|
||||||
{ 0, wxEmptyString, NULL }
|
{0, wxEmptyString, NULL}};
|
||||||
};
|
|
||||||
|
|
||||||
// IniFile Functions.
|
// IniFile Functions.
|
||||||
|
|
||||||
static void inifile_trim( wxString& buffer )
|
static void inifile_trim(wxString& buffer)
|
||||||
{
|
{
|
||||||
buffer.Trim(false); // trims left side.
|
buffer.Trim(false); // trims left side.
|
||||||
|
|
||||||
if( buffer.Length() <= 1 ) // this I'm not sure about... - air
|
if (buffer.Length() <= 1) // this I'm not sure about... - air
|
||||||
{
|
{
|
||||||
buffer.Empty();
|
buffer.Empty();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( buffer.Left( 2 ) == L"//" )
|
if (buffer.Left(2) == L"//")
|
||||||
{
|
{
|
||||||
buffer.Empty();
|
buffer.Empty();
|
||||||
return;
|
return;
|
||||||
|
@ -92,7 +90,7 @@ static void inifile_trim( wxString& buffer )
|
||||||
buffer.Trim(true); // trims right side.
|
buffer.Trim(true); // trims right side.
|
||||||
}
|
}
|
||||||
|
|
||||||
static int PatchTableExecute( const ParsedAssignmentString& set, const PatchTextTable * Table )
|
static int PatchTableExecute(const ParsedAssignmentString& set, const PatchTextTable* Table)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
@ -100,7 +98,8 @@ static int PatchTableExecute( const ParsedAssignmentString& set, const PatchText
|
||||||
{
|
{
|
||||||
if (!set.lvalue.Cmp(Table[i].text))
|
if (!set.lvalue.Cmp(Table[i].text))
|
||||||
{
|
{
|
||||||
if (Table[i].func) Table[i].func(set.lvalue, set.rvalue);
|
if (Table[i].func)
|
||||||
|
Table[i].func(set.lvalue, set.rvalue);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
|
@ -112,13 +111,14 @@ static int PatchTableExecute( const ParsedAssignmentString& set, const PatchText
|
||||||
// This routine is for executing the commands of the ini file.
|
// This routine is for executing the commands of the ini file.
|
||||||
static void inifile_command(const wxString& cmd)
|
static void inifile_command(const wxString& cmd)
|
||||||
{
|
{
|
||||||
ParsedAssignmentString set( cmd );
|
ParsedAssignmentString set(cmd);
|
||||||
|
|
||||||
// Is this really what we want to be doing here? Seems like just leaving it empty/blank
|
// Is this really what we want to be doing here? Seems like just leaving it empty/blank
|
||||||
// would make more sense... --air
|
// would make more sense... --air
|
||||||
if (set.rvalue.IsEmpty()) set.rvalue = set.lvalue;
|
if (set.rvalue.IsEmpty())
|
||||||
|
set.rvalue = set.lvalue;
|
||||||
|
|
||||||
/*int code = */PatchTableExecute(set, commands_patch);
|
/*int code = */ PatchTableExecute(set, commands_patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This routine loads patches from the game database (but not the config/game fixes/hacks)
|
// This routine loads patches from the game database (but not the config/game fixes/hacks)
|
||||||
|
@ -143,7 +143,6 @@ int LoadPatchesFromGamesDB(const wxString& crc, const GameDatabaseSchema::GameEn
|
||||||
{
|
{
|
||||||
inifile_command(line);
|
inifile_command(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,12 +153,13 @@ void inifile_processString(const wxString& inStr)
|
||||||
{
|
{
|
||||||
wxString str(inStr);
|
wxString str(inStr);
|
||||||
inifile_trim(str);
|
inifile_trim(str);
|
||||||
if (!str.IsEmpty()) inifile_command(str);
|
if (!str.IsEmpty())
|
||||||
|
inifile_command(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This routine receives a file from inifile_read, trims it,
|
// This routine receives a file from inifile_read, trims it,
|
||||||
// Then sends the command to be parsed.
|
// Then sends the command to be parsed.
|
||||||
void inifile_process(wxTextFile &f1 )
|
void inifile_process(wxTextFile& f1)
|
||||||
{
|
{
|
||||||
for (uint i = 0; i < f1.GetLineCount(); i++)
|
for (uint i = 0; i < f1.GetLineCount(); i++)
|
||||||
{
|
{
|
||||||
|
@ -176,7 +176,8 @@ static int _LoadPatchFiles(const wxDirName& folderName, wxString& fileSpec, cons
|
||||||
{
|
{
|
||||||
numberFoundPatchFiles = 0;
|
numberFoundPatchFiles = 0;
|
||||||
|
|
||||||
if (!folderName.Exists()) {
|
if (!folderName.Exists())
|
||||||
|
{
|
||||||
Console.WriteLn(Color_Red, L"The %s folder ('%s') is inaccessible. Skipping...", WX_STR(friendlyName), WX_STR(folderName.ToString()));
|
Console.WriteLn(Color_Red, L"The %s folder ('%s') is inaccessible. Skipping...", WX_STR(friendlyName), WX_STR(folderName.ToString()));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -186,8 +187,10 @@ static int _LoadPatchFiles(const wxDirName& folderName, wxString& fileSpec, cons
|
||||||
wxString buffer;
|
wxString buffer;
|
||||||
wxTextFile f;
|
wxTextFile f;
|
||||||
bool found = dir.GetFirst(&buffer, L"*", wxDIR_FILES);
|
bool found = dir.GetFirst(&buffer, L"*", wxDIR_FILES);
|
||||||
while (found) {
|
while (found)
|
||||||
if (buffer.Upper().Matches(fileSpec.Upper())) {
|
{
|
||||||
|
if (buffer.Upper().Matches(fileSpec.Upper()))
|
||||||
|
{
|
||||||
PatchesCon->WriteLn(Color_Green, L"Found %s file: '%s'", WX_STR(friendlyName), WX_STR(buffer));
|
PatchesCon->WriteLn(Color_Green, L"Found %s file: '%s'", WX_STR(friendlyName), WX_STR(buffer));
|
||||||
int before = Patch.size();
|
int before = Patch.size();
|
||||||
f.Open(Path::Combine(dir.GetName(), buffer));
|
f.Open(Path::Combine(dir.GetName(), buffer));
|
||||||
|
@ -208,7 +211,8 @@ static int _LoadPatchFiles(const wxDirName& folderName, wxString& fileSpec, cons
|
||||||
// Returns number of patches loaded
|
// Returns number of patches loaded
|
||||||
// Note: does not reset previously loaded patches (use ForgetLoadedPatches() for that)
|
// Note: does not reset previously loaded patches (use ForgetLoadedPatches() for that)
|
||||||
// Note: only load patches from the root folder of the zip
|
// Note: only load patches from the root folder of the zip
|
||||||
int LoadPatchesFromZip(wxString gameCRC, const wxString& patchesArchiveFilename) {
|
int LoadPatchesFromZip(wxString gameCRC, const wxString& patchesArchiveFilename)
|
||||||
|
{
|
||||||
gameCRC.MakeUpper();
|
gameCRC.MakeUpper();
|
||||||
|
|
||||||
int before = Patch.size();
|
int before = Patch.size();
|
||||||
|
@ -220,11 +224,13 @@ int LoadPatchesFromZip(wxString gameCRC, const wxString& patchesArchiveFilename)
|
||||||
{
|
{
|
||||||
wxString name = entry->GetName();
|
wxString name = entry->GetName();
|
||||||
name.MakeUpper();
|
name.MakeUpper();
|
||||||
if (name.Find(gameCRC) == 0 && name.Find(L".PNACH")+6u == name.Length()) {
|
if (name.Find(gameCRC) == 0 && name.Find(L".PNACH") + 6u == name.Length())
|
||||||
|
{
|
||||||
PatchesCon->WriteLn(Color_Green, L"Loading patch '%s' from archive '%s'",
|
PatchesCon->WriteLn(Color_Green, L"Loading patch '%s' from archive '%s'",
|
||||||
WX_STR(entry->GetName()), WX_STR(patchesArchiveFilename));
|
WX_STR(entry->GetName()), WX_STR(patchesArchiveFilename));
|
||||||
wxTextInputStream pnach(zip);
|
wxTextInputStream pnach(zip);
|
||||||
while (!zip.Eof()) {
|
while (!zip.Eof())
|
||||||
|
{
|
||||||
inifile_processString(pnach.ReadLine());
|
inifile_processString(pnach.ReadLine());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,7 +253,8 @@ int LoadPatchesFromDir(wxString name, const wxDirName& folderName, const wxStrin
|
||||||
// This comment _might_ be buggy. This function (LoadPatchesFromDir) loads from an explicit folder.
|
// This comment _might_ be buggy. This function (LoadPatchesFromDir) loads from an explicit folder.
|
||||||
// This folder can be cheats or cheats_ws at either the default location or a custom one.
|
// This folder can be cheats or cheats_ws at either the default location or a custom one.
|
||||||
// This check only tests the default cheats folder, so the message it produces is possibly misleading.
|
// This check only tests the default cheats folder, so the message it produces is possibly misleading.
|
||||||
if (folderName.ToString().IsSameAs(PathDefs::GetCheats().ToString()) && numberFoundPatchFiles == 0) {
|
if (folderName.ToString().IsSameAs(PathDefs::GetCheats().ToString()) && numberFoundPatchFiles == 0)
|
||||||
|
{
|
||||||
wxString pathName = Path::Combine(folderName, name.MakeUpper() + L".pnach");
|
wxString pathName = Path::Combine(folderName, name.MakeUpper() + L".pnach");
|
||||||
PatchesCon->WriteLn(Color_Gray, L"Not found %s file: %s", WX_STR(friendlyName), WX_STR(pathName));
|
PatchesCon->WriteLn(Color_Gray, L"Not found %s file: %s", WX_STR(friendlyName), WX_STR(pathName));
|
||||||
}
|
}
|
||||||
|
@ -273,7 +280,7 @@ static u64 StrToU64(const wxString& str, int base = 10)
|
||||||
// PatchFunc Functions.
|
// PatchFunc Functions.
|
||||||
namespace PatchFunc
|
namespace PatchFunc
|
||||||
{
|
{
|
||||||
void comment( const wxString& text1, const wxString& text2 )
|
void comment(const wxString& text1, const wxString& text2)
|
||||||
{
|
{
|
||||||
PatchesCon->WriteLn(L"comment: " + text2);
|
PatchesCon->WriteLn(L"comment: " + text2);
|
||||||
}
|
}
|
||||||
|
@ -287,11 +294,11 @@ namespace PatchFunc
|
||||||
{
|
{
|
||||||
wxArrayString m_pieces;
|
wxArrayString m_pieces;
|
||||||
|
|
||||||
PatchPieces( const wxString& param )
|
PatchPieces(const wxString& param)
|
||||||
{
|
{
|
||||||
SplitString( m_pieces, param, L"," );
|
SplitString(m_pieces, param, L",");
|
||||||
if( m_pieces.Count() < 5 )
|
if (m_pieces.Count() < 5)
|
||||||
throw wxsFormat( L"Expected 5 data parameters; only found %d", m_pieces.Count() );
|
throw wxsFormat(L"Expected 5 data parameters; only found %d", m_pieces.Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
const wxString& PlaceToPatch() const { return m_pieces[0]; }
|
const wxString& PlaceToPatch() const { return m_pieces[0]; }
|
||||||
|
@ -301,7 +308,8 @@ namespace PatchFunc
|
||||||
const wxString& WriteValue() const { return m_pieces[4]; }
|
const wxString& WriteValue() const { return m_pieces[4]; }
|
||||||
};
|
};
|
||||||
|
|
||||||
void patchHelper(const wxString& cmd, const wxString& param) {
|
void patchHelper(const wxString& cmd, const wxString& param)
|
||||||
|
{
|
||||||
// Error Handling Note: I just throw simple wxStrings here, and then catch them below and
|
// Error Handling Note: I just throw simple wxStrings here, and then catch them below and
|
||||||
// format them into more detailed cmd+data+error printouts. If we want to add user-friendly
|
// format them into more detailed cmd+data+error printouts. If we want to add user-friendly
|
||||||
// (translated) messages for display in a popup window then we'll have to upgrade the
|
// (translated) messages for display in a popup window then we'll have to upgrade the
|
||||||
|
@ -315,7 +323,7 @@ namespace PatchFunc
|
||||||
{
|
{
|
||||||
PatchPieces pieces(param);
|
PatchPieces pieces(param);
|
||||||
|
|
||||||
IniPatch iPatch = { 0 };
|
IniPatch iPatch = {0};
|
||||||
iPatch.enabled = 0;
|
iPatch.enabled = 0;
|
||||||
iPatch.placetopatch = StrToU32(pieces.PlaceToPatch(), 10);
|
iPatch.placetopatch = StrToU32(pieces.PlaceToPatch(), 10);
|
||||||
|
|
||||||
|
@ -335,16 +343,15 @@ namespace PatchFunc
|
||||||
|
|
||||||
iPatch.enabled = 1; // omg success!!
|
iPatch.enabled = 1; // omg success!!
|
||||||
Patch.push_back(iPatch);
|
Patch.push_back(iPatch);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch( wxString& exmsg )
|
catch (wxString& exmsg)
|
||||||
{
|
{
|
||||||
Console.Error(L"(Patch) Error Parsing: %s=%s", WX_STR(cmd), WX_STR(param));
|
Console.Error(L"(Patch) Error Parsing: %s=%s", WX_STR(cmd), WX_STR(param));
|
||||||
Console.Indent().Error( exmsg );
|
Console.Indent().Error(exmsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void patch(const wxString& cmd, const wxString& param) { patchHelper(cmd, param); }
|
void patch(const wxString& cmd, const wxString& param) { patchHelper(cmd, param); }
|
||||||
}
|
} // namespace PatchFunc
|
||||||
|
|
||||||
// This is for applying patches directly to memory
|
// This is for applying patches directly to memory
|
||||||
void ApplyLoadedPatches(patch_place_type place)
|
void ApplyLoadedPatches(patch_place_type place)
|
||||||
|
|
Loading…
Reference in New Issue