From 9e804b4515520f7251866a07ade9c544d4ebb2d1 Mon Sep 17 00:00:00 2001 From: qwertymodo Date: Thu, 17 Aug 2017 11:30:44 -0700 Subject: [PATCH] Add support for loading .msu1 packs as ROM files, if they actually contain a ROM file --- loadzip.cpp | 13 +++++++++++-- memmap.cpp | 45 ++++++++++++++++++++++++--------------------- win32/wsnes9x.cpp | 11 +++++++++-- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/loadzip.cpp b/loadzip.cpp index d3168939..840da42e 100644 --- a/loadzip.cpp +++ b/loadzip.cpp @@ -209,7 +209,7 @@ bool8 LoadZip (const char *zipname, uint32 *TotalFileSize, uint8 *buffer) if (file == NULL) return (FALSE); - // find largest file in zip file (under MAX_ROM_SIZE) or a file with extension .1 + // find largest file in zip file (under MAX_ROM_SIZE) or a file with extension .1, or a file named program.rom char filename[132]; uint32 filesize = 0; int port = unzGoToFirstFile(file); @@ -241,10 +241,19 @@ bool8 LoadZip (const char *zipname, uint32 *TotalFileSize, uint8 *buffer) break; } + if (strncasecmp(name, "program.rom", 11) == 0) + { + strcpy(filename, name); + filesize = info.uncompressed_size; + break; + } + port = unzGoToNextFile(file); } - if (!(port == UNZ_END_OF_LIST_OF_FILE || port == UNZ_OK) || filesize == 0) + int len = strlen(zipname); + if (!(port == UNZ_END_OF_LIST_OF_FILE || port == UNZ_OK) || filesize == 0 || + (len > 5 && strcasecmp(zipname + len - 5, ".msu1") == 0 && strcasecmp(filename, "program.rom") != 0)) { assert(unzClose(file) == UNZ_OK); return (FALSE); diff --git a/memmap.cpp b/memmap.cpp index 230ea285..6e2534ee 100644 --- a/memmap.cpp +++ b/memmap.cpp @@ -1439,7 +1439,7 @@ uint32 CMemory::FileLoader (uint8 *buffer, const char *filename, uint32 maxsize) _makepath(fname, drive, dir, name, exts); int nFormat = FILE_DEFAULT; - if (strcasecmp(ext, "zip") == 0) + if (strcasecmp(ext, "zip") == 0 || strcasecmp(ext, "msu1") == 0) nFormat = FILE_ZIP; else if (strcasecmp(ext, "jma") == 0) @@ -4258,31 +4258,34 @@ void CMemory::CheckForAnyPatch (const char *rom_filename, bool8 header, int32 &r #ifdef UNZIP_SUPPORT // Mercurial Magic (MSU-1 distribution pack) - _makepath(fname, drive, dir, name, "msu1"); - unzFile msu1file = unzOpen(fname); - - if (!msu1file) + if (strcasecmp(ext, "msu1") && strcasecmp(ext, ".msu1")) { - _snprintf(fname, sizeof(fname), "%s" SLASH_STR "%s%s", - S9xGetDirectory(IPS_DIR), name, ".msu1"); - msu1file = unzOpen(fname); - } + _makepath(fname, drive, dir, name, "msu1"); + unzFile msu1file = unzOpen(fname); - if (msu1file) - { - int port = unzFindExtension(msu1file, "bps"); - if (port == UNZ_OK) + if (!msu1file) { - printf(" in %s", fname); + _snprintf(fname, sizeof(fname), "%s" SLASH_STR "%s%s", + S9xGetDirectory(IPS_DIR), name, ".msu1"); + msu1file = unzOpen(fname); + } - Stream *s = new unzStream(msu1file); - ret = ReadBPSPatch(s, offset, rom_size); - s->closeStream(); + if (msu1file) + { + int port = unzFindExtension(msu1file, "bps"); + if (port == UNZ_OK) + { + printf(" in %s", fname); - if (ret) - printf("!\n"); - else - printf(" failed!\n"); + Stream *s = new unzStream(msu1file); + ret = ReadBPSPatch(s, offset, rom_size); + s->closeStream(); + + if (ret) + printf("!\n"); + else + printf(" failed!\n"); + } } } diff --git a/win32/wsnes9x.cpp b/win32/wsnes9x.cpp index 2758f4c1..015a1498 100644 --- a/win32/wsnes9x.cpp +++ b/win32/wsnes9x.cpp @@ -7020,10 +7020,17 @@ void MakeExtFile(void) ofstream out; out.open("Valid.Ext"); - out<<"smcN"<