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 "GameDatabase.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
#include <wx/textfile.h>
|
#include <wx/textfile.h>
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
#include <wx/txtstrm.h>
|
#include <wx/txtstrm.h>
|
||||||
|
@ -33,9 +34,7 @@
|
||||||
extern void _ApplyPatch(IniPatch *p);
|
extern void _ApplyPatch(IniPatch *p);
|
||||||
|
|
||||||
|
|
||||||
IniPatch Patch[ MAX_PATCH ];
|
std::vector<IniPatch> Patch;
|
||||||
|
|
||||||
int patchnumber = 0;
|
|
||||||
|
|
||||||
wxString strgametitle;
|
wxString strgametitle;
|
||||||
|
|
||||||
|
@ -152,7 +151,7 @@ int LoadPatchesFromGamesDB(const wxString& crc, const Game_Data& game)
|
||||||
|
|
||||||
if (patchFound) TrimPatches(patch);
|
if (patchFound) TrimPatches(patch);
|
||||||
|
|
||||||
return patchnumber;
|
return Patch.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void inifile_processString(const wxString& inStr)
|
void inifile_processString(const wxString& inStr)
|
||||||
|
@ -174,7 +173,7 @@ void inifile_process(wxTextFile &f1 )
|
||||||
|
|
||||||
void ForgetLoadedPatches()
|
void ForgetLoadedPatches()
|
||||||
{
|
{
|
||||||
patchnumber = 0;
|
Patch.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _LoadPatchFiles(const wxDirName& folderName, wxString& fileSpec, const wxString& friendlyName, int& numberFoundPatchFiles)
|
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());
|
wxDir dir(folderName.ToString());
|
||||||
|
|
||||||
int before = patchnumber;
|
int before = Patch.size();
|
||||||
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 = patchnumber;
|
int before = Patch.size();
|
||||||
f.Open(Path::Combine(dir.GetName(), buffer));
|
f.Open(Path::Combine(dir.GetName(), buffer));
|
||||||
inifile_process(f);
|
inifile_process(f);
|
||||||
f.Close();
|
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'",
|
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++;
|
numberFoundPatchFiles++;
|
||||||
|
@ -206,7 +205,7 @@ static int _LoadPatchFiles(const wxDirName& folderName, wxString& fileSpec, cons
|
||||||
found = dir.GetNext(&buffer);
|
found = dir.GetNext(&buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return patchnumber - before;
|
return Patch.size() - before;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This routine loads patches from a zip file
|
// 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) {
|
int LoadPatchesFromZip(wxString gameCRC, const wxString& patchesArchiveFilename) {
|
||||||
gameCRC.MakeUpper();
|
gameCRC.MakeUpper();
|
||||||
|
|
||||||
int before = patchnumber;
|
int before = Patch.size();
|
||||||
|
|
||||||
std::unique_ptr<wxZipEntry> entry;
|
std::unique_ptr<wxZipEntry> entry;
|
||||||
wxFFileInputStream in(patchesArchiveFilename);
|
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
|
try
|
||||||
{
|
{
|
||||||
if(patchnumber >= MAX_PATCH)
|
|
||||||
throw wxString( L"Maximum number of patches reached" );
|
|
||||||
|
|
||||||
IniPatch& iPatch = Patch[patchnumber];
|
|
||||||
PatchPieces pieces(param);
|
PatchPieces pieces(param);
|
||||||
|
|
||||||
|
IniPatch iPatch = { 0 };
|
||||||
iPatch.enabled = 0;
|
iPatch.enabled = 0;
|
||||||
|
|
||||||
iPatch.placetopatch = StrToU32(pieces.PlaceToPatch(), 10);
|
iPatch.placetopatch = StrToU32(pieces.PlaceToPatch(), 10);
|
||||||
|
|
||||||
if (iPatch.placetopatch >= _PPT_END_MARKER)
|
if (iPatch.placetopatch >= _PPT_END_MARKER)
|
||||||
throw wxsFormat(L"Invalid 'place' value '%s' (0 - once on startup, 1: continuously)", WX_STR(pieces.PlaceToPatch()));
|
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.cpu = (patch_cpu_type)PatchTableExecute(pieces.CpuType(), cpuCore);
|
||||||
iPatch.addr = StrToU32(pieces.MemAddr(), 16);
|
iPatch.addr = StrToU32(pieces.MemAddr(), 16);
|
||||||
iPatch.type = (patch_data_type)PatchTableExecute(pieces.OperandSize(), dataType);
|
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()));
|
throw wxsFormat(L"Unrecognized Operand Size: '%s'", WX_STR(pieces.OperandSize()));
|
||||||
|
|
||||||
iPatch.enabled = 1; // omg success!!
|
iPatch.enabled = 1; // omg success!!
|
||||||
|
Patch.push_back(iPatch);
|
||||||
|
|
||||||
patchnumber++;
|
|
||||||
}
|
}
|
||||||
catch( wxString& exmsg )
|
catch( wxString& exmsg )
|
||||||
{
|
{
|
||||||
|
@ -351,9 +348,9 @@ 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)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < patchnumber; i++)
|
for (auto& i : Patch)
|
||||||
{
|
{
|
||||||
if (Patch[i].placetopatch == place)
|
if (i.placetopatch == place)
|
||||||
_ApplyPatch(&Patch[i]);
|
_ApplyPatch(&i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,6 @@
|
||||||
#include "Pcsx2Defs.h"
|
#include "Pcsx2Defs.h"
|
||||||
#include "SysForwardDefs.h"
|
#include "SysForwardDefs.h"
|
||||||
|
|
||||||
#define MAX_PATCH 2048
|
|
||||||
|
|
||||||
enum patch_cpu_type {
|
enum patch_cpu_type {
|
||||||
NO_CPU,
|
NO_CPU,
|
||||||
CPU_EE,
|
CPU_EE,
|
||||||
|
@ -85,7 +83,6 @@ typedef void PATCHTABLEFUNC( const wxString& text1, const wxString& text2 );
|
||||||
struct IniPatch
|
struct IniPatch
|
||||||
{
|
{
|
||||||
int enabled;
|
int enabled;
|
||||||
int group;
|
|
||||||
patch_data_type type;
|
patch_data_type type;
|
||||||
patch_cpu_type cpu;
|
patch_cpu_type cpu;
|
||||||
int placetopatch;
|
int placetopatch;
|
||||||
|
|
|
@ -75,7 +75,7 @@ void RefreshListBox(HWND hWnd)
|
||||||
char cpucore[2][10]={"EE", "IOP"};
|
char cpucore[2][10]={"EE", "IOP"};
|
||||||
|
|
||||||
// Adding items
|
// 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(Address, "0x%.8x", patch[i].addr);
|
||||||
sprintf(CPU, "%s", cpucore[patch[i].cpu-1]);
|
sprintf(CPU, "%s", cpucore[patch[i].cpu-1]);
|
||||||
|
@ -697,8 +697,7 @@ BOOL CALLBACK AddPatchProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Add new patch, refresh and exit
|
// Add new patch, refresh and exit
|
||||||
memcpy((void *)&patch[patchnumber], (void *)&temp, sizeof(IniPatch));
|
Patch.push_back(temp);
|
||||||
patchnumber++;
|
|
||||||
RefreshListBox(hParent);
|
RefreshListBox(hParent);
|
||||||
EndDialog(hWnd,1);
|
EndDialog(hWnd,1);
|
||||||
break;
|
break;
|
||||||
|
@ -952,10 +951,10 @@ BOOL CALLBACK pnachWriterProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
// write patches
|
// write patches
|
||||||
for(int i=0;i<patchnumber;i++)
|
for (const auto& i : Patch)
|
||||||
{
|
{
|
||||||
char cpucore[10], type[10];
|
char cpucore[10], type[10];
|
||||||
switch(patch[i].cpu)
|
switch(i.cpu)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
strcpy(cpucore, "EE");
|
strcpy(cpucore, "EE");
|
||||||
|
@ -965,7 +964,7 @@ BOOL CALLBACK pnachWriterProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(patch[i].type)
|
switch(i.type)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
strcpy(type, "byte");
|
strcpy(type, "byte");
|
||||||
|
@ -981,7 +980,7 @@ BOOL CALLBACK pnachWriterProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//patch=placetopatch,cpucore,address,type,data
|
//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);
|
fclose(fp);
|
||||||
|
|
Loading…
Reference in New Issue