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:
GovanifY 2019-01-23 02:01:30 +01:00 committed by lightningterror
parent 2aadf0be89
commit 628f5abaac
3 changed files with 46 additions and 53 deletions

View File

@ -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;
@ -152,7 +151,7 @@ int LoadPatchesFromGamesDB(const wxString& crc, const Game_Data& game)
if (patchFound) TrimPatches(patch);
return patchnumber;
return Patch.size();
}
void inifile_processString(const wxString& inStr)
@ -174,7 +173,7 @@ void inifile_process(wxTextFile &f1 )
void ForgetLoadedPatches()
{
patchnumber = 0;
Patch.clear();
}
static int _LoadPatchFiles(const wxDirName& folderName, wxString& fileSpec, const wxString& friendlyName, int& numberFoundPatchFiles)
@ -187,18 +186,18 @@ 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()));
numberFoundPatchFiles++;
@ -206,7 +205,7 @@ static int _LoadPatchFiles(const wxDirName& folderName, wxString& fileSpec, cons
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);
@ -234,7 +233,7 @@ int LoadPatchesFromZip(wxString gameCRC, const wxString& patchesArchiveFilename)
}
}
}
return patchnumber - before;
return Patch.size() - before;
}
@ -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);
}
}

View File

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

View File

@ -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);