From 2ee86d1281886d080b7c93516be4e715e085dfe7 Mon Sep 17 00:00:00 2001 From: wiidev Date: Sun, 1 Jan 2023 17:00:24 +0000 Subject: [PATCH] Add basic CISO support for Nintendont --- source/GameCube/GCGames.cpp | 45 +++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/source/GameCube/GCGames.cpp b/source/GameCube/GCGames.cpp index 7289a77c..fa6e0fd2 100644 --- a/source/GameCube/GCGames.cpp +++ b/source/GameCube/GCGames.cpp @@ -136,19 +136,30 @@ void GCGames::LoadGameList(const std::string &path, std::vector for (int i = 0; i < 4; i++) { - char name[50]; + char name[12]; snprintf(name, sizeof(name), "%.6s.%s", (i % 2) == 0 ? "game" : (char *)id, i >= 2 ? "gcm" : "iso"); snprintf(fpath, sizeof(fpath), "%s%s/%s", path.c_str(), dirname, name); if ((found = (stat(fpath, &st) == 0)) == true) break; } + if (!found) + { + for (int i = 0; i < 2; i++) + { + char name[12]; + snprintf(name, sizeof(name), "%.6s.ciso", (i % 2) == 0 ? "game" : (char *)id); + snprintf(fpath, sizeof(fpath), "%s%s/%s", path.c_str(), dirname, name); + if ((found = (stat(fpath, &st) == 0)) == true) + break; + } + } // Check if only disc2.iso is present if (!found) { for (int i = 0; i < 2; i++) { - char name[50]; + char name[12]; snprintf(name, sizeof(name), "disc2.%s", (i % 2) == 0 ? "gcm" : "iso"); // allow gcm, though DM(L) require "disc2.iso" filename snprintf(fpath, sizeof(fpath), "%s%s/%s", path.c_str(), dirname, name); if ((found = (stat(fpath, &st) == 0)) == true) @@ -159,6 +170,18 @@ void GCGames::LoadGameList(const std::string &path, std::vector } } + if (!found) + { + char name[12]; + snprintf(name, sizeof(name), "disc2.ciso"); + snprintf(fpath, sizeof(fpath), "%s%s/%s", path.c_str(), dirname, name); + if ((found = (stat(fpath, &st) == 0)) == true) + { + disc_number = 1; + break; + } + } + if (!found) { snprintf(fpath, sizeof(fpath), "%s%s/sys/boot.bin", path.c_str(), dirname); @@ -176,7 +199,16 @@ void GCGames::LoadGameList(const std::string &path, std::vector FILE *fp = fopen(fpath, "rb"); if (fp != NULL) { + u32 cios_magic; memset(&tmpHdr, 0, sizeof(tmpHdr)); + fread(&cios_magic, sizeof(u32), 1, fp); + if (cios_magic == 0x4349534F) + { + tmpHdr.is_ciso = 1; + fseek(fp, 0x8000, SEEK_SET); + } + else + fseek(fp, 0, SEEK_SET); fread(&tmpHdr, sizeof(struct discHdr), 1, fp); fclose(fp); @@ -216,7 +248,16 @@ void GCGames::LoadGameList(const std::string &path, std::vector FILE *fp = fopen(fpath, "rb"); if (fp != NULL) { + u32 cios_magic; memset(&tmpHdr, 0, sizeof(tmpHdr)); + fread(&cios_magic, sizeof(u32), 1, fp); + if (cios_magic == 0x4349534F) + { + tmpHdr.is_ciso = 1; + fseek(fp, 0x8000, SEEK_SET); + } + else + fseek(fp, 0, SEEK_SET); fread(&tmpHdr, sizeof(struct discHdr), 1, fp); fclose(fp);