mirror of https://github.com/PCSX2/pcsx2.git
PCSX2: Remove the arbitrary limit on patches by converting the patch list to a vector. (#2797)
Pnach had a limit that, while increased at some point to 2048, is still not enough for everyone. This uses a vector to avoid that limit, as there is no reason to keep it and people loading pnach with over 2048 patches most likely know what they are doing. Inipatch group member was also unused in the whole codebase so I did some cleanup and removed it.
This commit is contained in:
parent
2aadf0be89
commit
628f5abaac
|
@ -22,6 +22,7 @@
|
|||
#include "GameDatabase.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <wx/textfile.h>
|
||||
#include <wx/dir.h>
|
||||
#include <wx/txtstrm.h>
|
||||
|
@ -33,9 +34,7 @@
|
|||
extern void _ApplyPatch(IniPatch *p);
|
||||
|
||||
|
||||
IniPatch Patch[ MAX_PATCH ];
|
||||
|
||||
int patchnumber = 0;
|
||||
std::vector<IniPatch> Patch;
|
||||
|
||||
wxString strgametitle;
|
||||
|
||||
|
@ -115,7 +114,7 @@ static void inifile_command(const wxString& cmd)
|
|||
|
||||
// Is this really what we want to be doing here? Seems like just leaving it empty/blank
|
||||
// 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);
|
||||
}
|
||||
|
@ -126,7 +125,7 @@ void TrimPatches(wxString& s)
|
|||
{
|
||||
wxStringTokenizer tkn( s, L"\n" );
|
||||
|
||||
while(tkn.HasMoreTokens()) {
|
||||
while(tkn.HasMoreTokens()) {
|
||||
inifile_command(tkn.GetNextToken());
|
||||
}
|
||||
}
|
||||
|
@ -152,29 +151,29 @@ int LoadPatchesFromGamesDB(const wxString& crc, const Game_Data& game)
|
|||
|
||||
if (patchFound) TrimPatches(patch);
|
||||
|
||||
return patchnumber;
|
||||
return Patch.size();
|
||||
}
|
||||
|
||||
void inifile_processString(const wxString& inStr)
|
||||
{
|
||||
wxString str(inStr);
|
||||
inifile_trim(str);
|
||||
if (!str.IsEmpty()) inifile_command(str);
|
||||
wxString str(inStr);
|
||||
inifile_trim(str);
|
||||
if (!str.IsEmpty()) inifile_command(str);
|
||||
}
|
||||
|
||||
// This routine receives a file from inifile_read, trims it,
|
||||
// Then sends the command to be parsed.
|
||||
void inifile_process(wxTextFile &f1 )
|
||||
{
|
||||
for (uint i = 0; i < f1.GetLineCount(); i++)
|
||||
{
|
||||
inifile_processString(f1[i]);
|
||||
}
|
||||
for (uint i = 0; i < f1.GetLineCount(); i++)
|
||||
{
|
||||
inifile_processString(f1[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void ForgetLoadedPatches()
|
||||
{
|
||||
patchnumber = 0;
|
||||
Patch.clear();
|
||||
}
|
||||
|
||||
static int _LoadPatchFiles(const wxDirName& folderName, wxString& fileSpec, const wxString& friendlyName, int& numberFoundPatchFiles)
|
||||
|
@ -187,26 +186,26 @@ static int _LoadPatchFiles(const wxDirName& folderName, wxString& fileSpec, cons
|
|||
}
|
||||
wxDir dir(folderName.ToString());
|
||||
|
||||
int before = patchnumber;
|
||||
int before = Patch.size();
|
||||
wxString buffer;
|
||||
wxTextFile f;
|
||||
bool found = dir.GetFirst(&buffer, L"*", wxDIR_FILES);
|
||||
while (found) {
|
||||
if (buffer.Upper().Matches(fileSpec.Upper())) {
|
||||
PatchesCon->WriteLn(Color_Green, L"Found %s file: '%s'", WX_STR(friendlyName), WX_STR(buffer));
|
||||
int before = patchnumber;
|
||||
int before = Patch.size();
|
||||
f.Open(Path::Combine(dir.GetName(), buffer));
|
||||
inifile_process(f);
|
||||
f.Close();
|
||||
int loaded = patchnumber - before;
|
||||
int loaded = Patch.size() - before;
|
||||
PatchesCon->WriteLn((loaded ? Color_Green : Color_Gray), L"Loaded %d %s from '%s' at '%s'",
|
||||
loaded, WX_STR(friendlyName), WX_STR(buffer), WX_STR(folderName.ToString()));
|
||||
loaded, WX_STR(friendlyName), WX_STR(buffer), WX_STR(folderName.ToString()));
|
||||
numberFoundPatchFiles++;
|
||||
}
|
||||
found = dir.GetNext(&buffer);
|
||||
}
|
||||
|
||||
return patchnumber - before;
|
||||
return Patch.size() - before;
|
||||
}
|
||||
|
||||
// This routine loads patches from a zip file
|
||||
|
@ -216,7 +215,7 @@ static int _LoadPatchFiles(const wxDirName& folderName, wxString& fileSpec, cons
|
|||
int LoadPatchesFromZip(wxString gameCRC, const wxString& patchesArchiveFilename) {
|
||||
gameCRC.MakeUpper();
|
||||
|
||||
int before = patchnumber;
|
||||
int before = Patch.size();
|
||||
|
||||
std::unique_ptr<wxZipEntry> entry;
|
||||
wxFFileInputStream in(patchesArchiveFilename);
|
||||
|
@ -227,14 +226,14 @@ int LoadPatchesFromZip(wxString gameCRC, const wxString& patchesArchiveFilename)
|
|||
name.MakeUpper();
|
||||
if (name.Find(gameCRC) == 0 && name.Find(L".PNACH")+6u == name.Length()) {
|
||||
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);
|
||||
while (!zip.Eof()) {
|
||||
inifile_processString(pnach.ReadLine());
|
||||
}
|
||||
}
|
||||
}
|
||||
return patchnumber - before;
|
||||
return Patch.size() - before;
|
||||
}
|
||||
|
||||
|
||||
|
@ -263,28 +262,28 @@ int LoadPatchesFromDir(wxString name, const wxDirName& folderName, const wxStrin
|
|||
|
||||
static u32 StrToU32(const wxString& str, int base = 10)
|
||||
{
|
||||
unsigned long l;
|
||||
str.ToULong(&l, base);
|
||||
return l;
|
||||
unsigned long l;
|
||||
str.ToULong(&l, base);
|
||||
return l;
|
||||
}
|
||||
|
||||
static u64 StrToU64(const wxString& str, int base = 10)
|
||||
{
|
||||
wxULongLong_t l;
|
||||
str.ToULongLong(&l, base);
|
||||
return l;
|
||||
wxULongLong_t l;
|
||||
str.ToULongLong(&l, base);
|
||||
return l;
|
||||
}
|
||||
|
||||
// PatchFunc Functions.
|
||||
namespace PatchFunc
|
||||
{
|
||||
void comment( const wxString& text1, const wxString& text2 )
|
||||
{
|
||||
void comment( const wxString& text1, const wxString& text2 )
|
||||
{
|
||||
PatchesCon->WriteLn(L"comment: " + text2);
|
||||
}
|
||||
}
|
||||
|
||||
struct PatchPieces
|
||||
{
|
||||
struct PatchPieces
|
||||
{
|
||||
wxArrayString m_pieces;
|
||||
|
||||
PatchPieces( const wxString& param )
|
||||
|
@ -299,7 +298,7 @@ namespace PatchFunc
|
|||
const wxString& MemAddr() const { return m_pieces[2]; }
|
||||
const wxString& OperandSize() const { return m_pieces[3]; }
|
||||
const wxString& WriteValue() const { return m_pieces[4]; }
|
||||
};
|
||||
};
|
||||
|
||||
void patchHelper(const wxString& cmd, const wxString& param) {
|
||||
// Error Handling Note: I just throw simple wxStrings here, and then catch them below and
|
||||
|
@ -313,17 +312,15 @@ namespace PatchFunc
|
|||
|
||||
try
|
||||
{
|
||||
if(patchnumber >= MAX_PATCH)
|
||||
throw wxString( L"Maximum number of patches reached" );
|
||||
|
||||
IniPatch& iPatch = Patch[patchnumber];
|
||||
PatchPieces pieces(param);
|
||||
|
||||
IniPatch iPatch = { 0 };
|
||||
iPatch.enabled = 0;
|
||||
|
||||
iPatch.placetopatch = StrToU32(pieces.PlaceToPatch(), 10);
|
||||
|
||||
if (iPatch.placetopatch >= _PPT_END_MARKER)
|
||||
throw wxsFormat(L"Invalid 'place' value '%s' (0 - once on startup, 1: continuously)", WX_STR(pieces.PlaceToPatch()));
|
||||
|
||||
iPatch.cpu = (patch_cpu_type)PatchTableExecute(pieces.CpuType(), cpuCore);
|
||||
iPatch.addr = StrToU32(pieces.MemAddr(), 16);
|
||||
iPatch.type = (patch_data_type)PatchTableExecute(pieces.OperandSize(), dataType);
|
||||
|
@ -336,8 +333,8 @@ namespace PatchFunc
|
|||
throw wxsFormat(L"Unrecognized Operand Size: '%s'", WX_STR(pieces.OperandSize()));
|
||||
|
||||
iPatch.enabled = 1; // omg success!!
|
||||
Patch.push_back(iPatch);
|
||||
|
||||
patchnumber++;
|
||||
}
|
||||
catch( wxString& exmsg )
|
||||
{
|
||||
|
@ -351,9 +348,9 @@ namespace PatchFunc
|
|||
// This is for applying patches directly to memory
|
||||
void ApplyLoadedPatches(patch_place_type place)
|
||||
{
|
||||
for (int i = 0; i < patchnumber; i++)
|
||||
for (auto& i : Patch)
|
||||
{
|
||||
if (Patch[i].placetopatch == place)
|
||||
_ApplyPatch(&Patch[i]);
|
||||
if (i.placetopatch == place)
|
||||
_ApplyPatch(&i);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,8 +38,6 @@
|
|||
#include "Pcsx2Defs.h"
|
||||
#include "SysForwardDefs.h"
|
||||
|
||||
#define MAX_PATCH 2048
|
||||
|
||||
enum patch_cpu_type {
|
||||
NO_CPU,
|
||||
CPU_EE,
|
||||
|
@ -85,7 +83,6 @@ typedef void PATCHTABLEFUNC( const wxString& text1, const wxString& text2 );
|
|||
struct IniPatch
|
||||
{
|
||||
int enabled;
|
||||
int group;
|
||||
patch_data_type type;
|
||||
patch_cpu_type cpu;
|
||||
int placetopatch;
|
||||
|
|
|
@ -75,7 +75,7 @@ void RefreshListBox(HWND hWnd)
|
|||
char cpucore[2][10]={"EE", "IOP"};
|
||||
|
||||
// Adding items
|
||||
for (int i = patchnumber-1; i >= 0; i--)
|
||||
for (int i = Patch.size()-1; i >= 0; i--)
|
||||
{
|
||||
sprintf(Address, "0x%.8x", patch[i].addr);
|
||||
sprintf(CPU, "%s", cpucore[patch[i].cpu-1]);
|
||||
|
@ -697,8 +697,7 @@ BOOL CALLBACK AddPatchProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
|
|||
break;
|
||||
|
||||
// Add new patch, refresh and exit
|
||||
memcpy((void *)&patch[patchnumber], (void *)&temp, sizeof(IniPatch));
|
||||
patchnumber++;
|
||||
Patch.push_back(temp);
|
||||
RefreshListBox(hParent);
|
||||
EndDialog(hWnd,1);
|
||||
break;
|
||||
|
@ -952,10 +951,10 @@ BOOL CALLBACK pnachWriterProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
|
|||
}
|
||||
|
||||
// write patches
|
||||
for(int i=0;i<patchnumber;i++)
|
||||
for (const auto& i : Patch)
|
||||
{
|
||||
char cpucore[10], type[10];
|
||||
switch(patch[i].cpu)
|
||||
switch(i.cpu)
|
||||
{
|
||||
case 1:
|
||||
strcpy(cpucore, "EE");
|
||||
|
@ -965,7 +964,7 @@ BOOL CALLBACK pnachWriterProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
|
|||
break;
|
||||
}
|
||||
|
||||
switch(patch[i].type)
|
||||
switch(i.type)
|
||||
{
|
||||
case 1:
|
||||
strcpy(type, "byte");
|
||||
|
@ -981,7 +980,7 @@ BOOL CALLBACK pnachWriterProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
|
|||
break;
|
||||
}
|
||||
//patch=placetopatch,cpucore,address,type,data
|
||||
fprintf(fp, "patch=%d,%s,%.8x,%s,%.8x\n", patch[i].placetopatch, cpucore, patch[i].addr, type, patch[i].data);
|
||||
fprintf(fp, "patch=%d,%s,%.8x,%s,%.8x\n", i.placetopatch, cpucore, i.addr, type, i.data);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
|
Loading…
Reference in New Issue