X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=libpcsxcore%2Fppf.c;h=f37687cc007a7dae10f5aa47ad73738495078a3e;hb=refs%2Fheads%2Fmaster;hp=454290d0d204ba462b0409b4e94e6e72789b0499;hpb=4904809d2ed121844ea23cf0ea580785d3da1f0b;p=pcsx_rearmed.git diff --git a/libpcsxcore/ppf.c b/libpcsxcore/ppf.c index 454290d0..6a88e053 100644 --- a/libpcsxcore/ppf.c +++ b/libpcsxcore/ppf.c @@ -21,6 +21,7 @@ #include "psxcommon.h" #include "ppf.h" +#include "misc.h" #include "cdrom.h" typedef struct tagPPF_DATA { @@ -58,6 +59,7 @@ static void FillPPFCache() { if (iPPFNum <= 0) return; pc = ppfCache = (PPF_CACHE *)malloc(iPPFNum * sizeof(PPF_CACHE)); + if (pc == NULL) return; iPPFNum--; p = ppfHead; @@ -133,6 +135,7 @@ void CheckPPFCache(unsigned char *pB, unsigned char m, unsigned char s, unsigned static void AddToPPF(s32 ladr, s32 pos, s32 anz, unsigned char *ppfmem) { if (ppfHead == NULL) { ppfHead = (PPF_DATA *)malloc(sizeof(PPF_DATA) + anz); + if (ppfHead == NULL) return; ppfHead->addr = ladr; ppfHead->pNext = NULL; ppfHead->pos = pos; @@ -164,6 +167,7 @@ static void AddToPPF(s32 ladr, s32 pos, s32 anz, unsigned char *ppfmem) { } padd = (PPF_DATA *)malloc(sizeof(PPF_DATA) + anz); + if (padd == NULL) return; padd->addr = ladr; padd->pNext = p; padd->pos = pos; @@ -177,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; @@ -192,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); @@ -216,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; } @@ -342,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 @@ -353,6 +360,7 @@ fail_io: // redump.org SBI files, slightly different handling from PCSX-Reloaded unsigned char *sbi_sectors; +int sbi_len; int LoadSBI(const char *fname, int sector_count) { int good_sectors = 0; @@ -366,7 +374,8 @@ int LoadSBI(const char *fname, int sector_count) { if (sbihandle == NULL) return -1; - sbi_sectors = calloc(1, sector_count / 8); + sbi_len = (sector_count + 7) / 8; + sbi_sectors = calloc(1, sbi_len); if (sbi_sectors == NULL) goto end; @@ -410,15 +419,13 @@ int LoadSBI(const char *fname, int sector_count) { break; } - fclose(sbihandle); - return 0; - end: if (!clean_eof) SysPrintf(_("SBI: parse failure at 0x%lx\n"), ftell(sbihandle)); if (!good_sectors) { free(sbi_sectors); sbi_sectors = NULL; + sbi_len = 0; } fclose(sbihandle); return sbi_sectors ? 0 : -1; @@ -428,5 +435,6 @@ void UnloadSBI(void) { if (sbi_sectors) { free(sbi_sectors); sbi_sectors = NULL; + sbi_len = 0; } }