Merge pull request #108 from condret/master
fix gameboy header-detection in libretro interface
This commit is contained in:
commit
48f7437612
|
@ -2079,6 +2079,8 @@ bool cheatsImportGSACodeFile(const char* name, int game, bool v3)
|
|||
fread(&codes, 1, 4, f);
|
||||
while (codes > 0) {
|
||||
fread(&len, 1, 4, f);
|
||||
if (len > 255)
|
||||
goto evil_gsa_code_file; //XXX: this functione needs a rewrite in general, so for the short this is better than nothing
|
||||
fread(desc, 1, len, f);
|
||||
desc[len] = 0;
|
||||
desc[31] = 0;
|
||||
|
@ -2098,6 +2100,7 @@ bool cheatsImportGSACodeFile(const char* name, int game, bool v3)
|
|||
codes--;
|
||||
}
|
||||
}
|
||||
evil_gsa_code_file:
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -99,16 +99,19 @@ bool utilIsGBAImage(const char* file)
|
|||
|
||||
bool utilIsGBImage(const char* file)
|
||||
{
|
||||
if (strlen(file) > 4) {
|
||||
const char* p = strrchr(file, '.');
|
||||
|
||||
if (p != NULL) {
|
||||
if ((_stricmp(p, ".dmg") == 0) || (_stricmp(p, ".gb") == 0) || (_stricmp(p, ".gbc") == 0) || (_stricmp(p, ".cgb") == 0) || (_stricmp(p, ".sgb") == 0))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
FILE *fp;
|
||||
bool ret = false;
|
||||
char buffer[47];
|
||||
if (!file || !(fd = fopen (file, "r"))) //TODO more checks here (does file exist, is it a file, a symlink or a blockdevice)
|
||||
return ret;
|
||||
fseek (fp, 0, SEEK_END);
|
||||
if (ftell (fp) >= 0x8000) { //afaik there can be no gb-rom smaller than this
|
||||
fseek (fp, 0x104, SEEK_SET);
|
||||
fread (buffer, sizeof (char), 47, fp);
|
||||
ret = !memcmp (buffer, gb_image_header, 47);
|
||||
}
|
||||
fclose (fp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// strip .gz or .z off end
|
||||
|
|
|
@ -16,3 +16,10 @@ extern const char *saveDotCodeFile;
|
|||
extern bool skipSaveGameBattery;
|
||||
extern bool skipSaveGameCheats;
|
||||
#define MAX_CHEATS 100
|
||||
|
||||
const char gb_image_header[]={
|
||||
0xce, 0xed, 0x66, 0x66, 0xcc, 0x0d, 0x00, 0x0b, 0x03, 0x73, 0x00,
|
||||
0x83, 0x00, 0x0c, 0x00, 0x0d, 0x00, 0x08, 0x11, 0x1f, 0x88, 0x89,
|
||||
0x00, 0x0e, 0xdc, 0xcc, 0x6e, 0xe6, 0xdd, 0xdd, 0xd9, 0x99, 0xbb,
|
||||
0xbb, 0x67, 0x63, 0x6e, 0x0e, 0xec, 0xcc, 0xdd, 0xdc, 0x99, 0x9f,
|
||||
0xbb, 0xb9, 0x33, 0x3e};
|
||||
|
|
Loading…
Reference in New Issue