From: notaz Date: Fri, 28 Jun 2024 22:02:05 +0000 (+0300) Subject: standalone: some ppf loading X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fde7a317052fd7e7111b0e003e65d0d1b8159cac;p=pcsx_rearmed.git standalone: some ppf loading mostly for testing, like game.chd.ppf would load game.chd and apply game.chd.ppf patch --- diff --git a/frontend/menu.c b/frontend/menu.c index 39f0a697..eb3237e3 100644 --- a/frontend/menu.c +++ b/frontend/menu.c @@ -40,6 +40,7 @@ #include "../libpcsxcore/cdrom.h" #include "../libpcsxcore/cdriso.h" #include "../libpcsxcore/cheat.h" +#include "../libpcsxcore/ppf.h" #include "../libpcsxcore/new_dynarec/new_dynarec.h" #include "../plugins/dfsound/spu_config.h" #include "psemu_plugin_defs.h" @@ -740,7 +741,7 @@ static const char *filter_exts[] = { #ifdef HAVE_CHD "chd", #endif - "bz", "znx", "pbp", "cbn", NULL + "bz", "znx", "pbp", "cbn", "ppf", NULL }; // rrrr rggg gggb bbbb @@ -2157,6 +2158,18 @@ static int run_exe(void) static int run_cd_image(const char *fname) { int autoload_state = g_autostateld_opt; + size_t fname_len = strlen(fname); + const char *ppfname = NULL; + char fname2[256]; + + // simle ppf handling, like game.chd.ppf + if (4 < fname_len && fname_len < sizeof(fname2) + && strcasecmp(fname + fname_len - 4, ".ppf") == 0) { + memcpy(fname2, fname, fname_len - 4); + fname2[fname_len - 4] = 0; + ppfname = fname; + fname = fname2; + } ready_to_go = 0; reload_plugins(fname); @@ -2170,6 +2183,8 @@ static int run_cd_image(const char *fname) menu_update_msg("unsupported/invalid CD image"); return -1; } + if (ppfname) + BuildPPFCache(ppfname); SysReset(); @@ -2185,7 +2200,7 @@ static int run_cd_image(const char *fname) if (autoload_state) { unsigned int newest = 0; - int time, slot, newest_slot = -1; + int time = 0, slot, newest_slot = -1; for (slot = 0; slot < 10; slot++) { if (emu_check_save_file(slot, &time)) { diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index 47a32cce..aafe5221 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -466,7 +466,7 @@ int CheckCdrom() { Apply_Hacks_Cdrom(); - BuildPPFCache(); + BuildPPFCache(NULL); return 0; } diff --git a/libpcsxcore/ppf.c b/libpcsxcore/ppf.c index f37687cc..6a88e053 100644 --- a/libpcsxcore/ppf.c +++ b/libpcsxcore/ppf.c @@ -181,7 +181,7 @@ static void AddToPPF(s32 ladr, s32 pos, s32 anz, unsigned char *ppfmem) { } } -void BuildPPFCache() { +void BuildPPFCache(const char *fname) { FILE *ppffile; char buffer[12]; char method, undo = 0, blockcheck = 0; @@ -196,23 +196,25 @@ void BuildPPFCache() { if (CdromId[0] == '\0') return; - // Generate filename in the format of SLUS_123.45 - buffer[0] = toupper(CdromId[0]); - buffer[1] = toupper(CdromId[1]); - buffer[2] = toupper(CdromId[2]); - buffer[3] = toupper(CdromId[3]); - buffer[4] = '_'; - buffer[5] = CdromId[4]; - buffer[6] = CdromId[5]; - buffer[7] = CdromId[6]; - buffer[8] = '.'; - buffer[9] = CdromId[7]; - buffer[10] = CdromId[8]; - buffer[11] = '\0'; - - sprintf(szPPF, "%s%s", Config.PatchesDir, buffer); - - ppffile = fopen(szPPF, "rb"); + if (!fname) { + // Generate filename in the format of SLUS_123.45 + buffer[0] = toupper(CdromId[0]); + buffer[1] = toupper(CdromId[1]); + buffer[2] = toupper(CdromId[2]); + buffer[3] = toupper(CdromId[3]); + buffer[4] = '_'; + buffer[5] = CdromId[4]; + buffer[6] = CdromId[5]; + buffer[7] = CdromId[6]; + buffer[8] = '.'; + buffer[9] = CdromId[7]; + buffer[10] = CdromId[8]; + buffer[11] = '\0'; + + sprintf(szPPF, "%s%s", Config.PatchesDir, buffer); + fname = szPPF; + } + ppffile = fopen(fname, "rb"); if (ppffile == NULL) return; memset(buffer, 0, 5); @@ -220,7 +222,7 @@ void BuildPPFCache() { goto fail_io; if (strcmp(buffer, "PPF") != 0) { - SysPrintf(_("Invalid PPF patch: %s.\n"), szPPF); + SysPrintf(_("Invalid PPF patch: %s.\n"), fname); fclose(ppffile); return; } @@ -346,7 +348,8 @@ void BuildPPFCache() { FillPPFCache(); // build address array - SysPrintf(_("Loaded PPF %d.0 patch: %s.\n"), method + 1, szPPF); + SysPrintf(_("Loaded PPF %d.0 patch: %s.\n"), method + 1, fname); + return; fail_io: #ifndef NDEBUG diff --git a/libpcsxcore/ppf.h b/libpcsxcore/ppf.h index a1b14751..e646e554 100644 --- a/libpcsxcore/ppf.h +++ b/libpcsxcore/ppf.h @@ -23,7 +23,7 @@ extern "C" { #endif -void BuildPPFCache(); +void BuildPPFCache(const char *fname); void FreePPFCache(); void CheckPPFCache(unsigned char *pB, unsigned char m, unsigned char s, unsigned char f);