Add support for loading .msu1 packs as ROM files, if they actually contain a ROM file

This commit is contained in:
qwertymodo 2017-08-17 11:30:44 -07:00
parent 96fd5c4121
commit 9e804b4515
3 changed files with 44 additions and 25 deletions

View File

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

View File

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

View File

@ -7020,10 +7020,17 @@ void MakeExtFile(void)
ofstream out;
out.open("Valid.Ext");
out<<"smcN"<<endl<<"zipY"<<endl<<"gzY" <<endl<<"swcN"<<endl<<"figN"<<endl;
out<<"smcN"<<endl;
#ifdef UNZIP_SUPPORT
out<<"zipY"<<endl;
out<<"msu1Y"<<endl;
#endif
out<<"gzY"<<endl;
out<<"swcN"<<endl;
out<<"figN"<<endl;
out<<"sfcN"<<endl;
out<<"bsN"<<endl;
out<<"jmaY";
out<<"jmaY"<<endl;
out.close();
SetFileAttributes(TEXT("Valid.Ext"), FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY);
};