diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index 65ba8570..c088e0e5 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -69,8 +69,16 @@ GameEngine::GameEngine() { if (std::filesystem::exists(main_path)) { archiveFiles.push_back(main_path); } else { - GenAssetFile(); - archiveFiles.push_back(main_path); + if (ShowYesNoBox("No O2R Files", "No O2R files found. Generate one now?") == IDYES) { + if(!GenAssetFile()){ + ShowMessage("Error", "An error occured, no O2R file was generated.\n\nExiting..."); + exit(1); + } else { + archiveFiles.push_back(main_path); + } + } else { + exit(1); + } } if (std::filesystem::exists(assets_path)) { @@ -197,21 +205,23 @@ GameEngine::GameEngine() { context->GetResourceManager()->SetAltAssetsEnabled(prevAltAssets); } -void GameEngine::GenAssetFile() { +bool GameEngine::GenAssetFile() { auto extractor = new GameExtractor(); if (!extractor->SelectGameFromUI()) { - ShowMessage("Extractor", "No game selected."); - return; - } - if (!extractor->ValidateChecksum()) { - ShowMessage("Extractor", "Invalid checksum."); - return; + ShowMessage("Error", "No ROM selected.\n\nExiting..."); + exit(1); } - if (!extractor->GenerateOTR()) { - ShowMessage("Extractor", "Failed to generate OTR."); + auto game = extractor->ValidateChecksum(); + if (!game.has_value()) { + ShowMessage("Unsupported ROM", "The provided ROM is not supported.\n\nCheck the readme for a list of supported versions."); + exit(1); } + + ShowMessage(("Found " + game.value()).c_str(), "The extraction process will now begin.\n\nThis may take a few minutes."); + + return extractor->GenerateOTR(); } void GameEngine::Create() { @@ -457,6 +467,30 @@ void GameEngine::ShowMessage(const char* title, const char* message) { #endif } +int GameEngine::ShowYesNoBox(const char* title, const char* box) { + int ret; +#ifdef _WIN32 + ret = MessageBoxA(nullptr, box, title, MB_YESNO | MB_ICONQUESTION); +#else + SDL_MessageBoxData boxData = { 0 }; + SDL_MessageBoxButtonData buttons[2] = { { 0 } }; + + buttons[0].buttonid = IDYES; + buttons[0].text = "Yes"; + buttons[0].flags = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT; + buttons[1].buttonid = IDNO; + buttons[1].text = "No"; + buttons[1].flags = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT; + boxData.numbuttons = 2; + boxData.flags = SDL_MESSAGEBOX_INFORMATION; + boxData.message = box; + boxData.title = title; + boxData.buttons = buttons; + SDL_ShowMessageBox(&boxData, &ret); +#endif + return ret; +} + extern "C" uint32_t GameEngine_GetSampleRate() { auto player = Ship::Context::GetInstance()->GetAudio()->GetAudioPlayer(); if (player == nullptr) { diff --git a/src/port/Engine.h b/src/port/Engine.h index 5b09f1e5..4b5e6243 100644 --- a/src/port/Engine.h +++ b/src/port/Engine.h @@ -15,7 +15,12 @@ struct GamePool { #include #include "libultraship/src/Context.h" - +#ifndef IDYES +#define IDYES 6 +#endif +#ifndef IDNO +#define IDNO 7 +#endif class GameEngine { public: @@ -24,7 +29,7 @@ class GameEngine { std::shared_ptr context; GameEngine(); - static void GenAssetFile(); + static bool GenAssetFile(); static void Create(); void StartFrame() const; static void HandleAudioThread(); @@ -38,6 +43,8 @@ class GameEngine { static void Destroy(); static void ProcessGfxCommands(Gfx* commands); static uint32_t GetInterpolationFPS(); + + static int ShowYesNoBox(const char* title, const char* box); static void ShowMessage(const char* title, const char* message); }; diff --git a/src/port/extractor/GameExtractor.cpp b/src/port/extractor/GameExtractor.cpp index 9cfd7ea4..29d222d2 100644 --- a/src/port/extractor/GameExtractor.cpp +++ b/src/port/extractor/GameExtractor.cpp @@ -8,8 +8,10 @@ #include std::unordered_map mGameList = { - { "f7475fb11e7e6830f82883412638e8390791ab87", "Star Fox 64 (U) (V1.1) (Uncompressed)" }, - { "09f0d105f476b00efa5303a3ebc42e60a7753b7a", "Star Fox 64 (U) (V1.1)" } + { "d8b1088520f7c5f81433292a9258c1184afa1457", "Star Fox 64 (U) (V1.1)" }, + { "63b69f0ef36306257481afc250f9bc304c7162b2", "Star Fox 64 (U) (V1.0) (Uncompressed)" }, + { "09f0d105f476b00efa5303a3ebc42e60a7753b7a", "Star Fox 64 (U) (V1.1)" }, + { "f7475fb11e7e6830f82883412638e8390791ab87", "Star Fox 64 (U) (V1.0) (Uncompressed)" }, }; bool GameExtractor::SelectGameFromUI() { @@ -34,7 +36,13 @@ bool GameExtractor::SelectGameFromUI() { std::optional GameExtractor::ValidateChecksum() const { const auto rom = new N64::Cartridge(this->mGameData); rom->Initialize(); - return mGameList[rom->GetHash()]; + auto hash = rom->GetHash(); + + if (mGameList.find(hash) == mGameList.end()) { + return std::nullopt; + } + + return mGameList[hash]; } bool GameExtractor::GenerateOTR() const { @@ -43,8 +51,7 @@ bool GameExtractor::GenerateOTR() const { try { Companion::Instance->Init(ExportType::Binary); } catch (const std::exception& e) { - GameEngine::ShowMessage("Failed to generate OTR", e.what()); - exit(1); + return false; } return true; diff --git a/src/port/extractor/GameExtractor.h b/src/port/extractor/GameExtractor.h index da5de754..a6423495 100644 --- a/src/port/extractor/GameExtractor.h +++ b/src/port/extractor/GameExtractor.h @@ -7,7 +7,7 @@ class GameExtractor { public: - static void GenAssetFile(); + static bool GenAssetFile(); std::optional ValidateChecksum() const; bool SelectGameFromUI(); bool GenerateOTR() const; diff --git a/tools/Torch b/tools/Torch index c6b1cdfa..7da8ae8e 160000 --- a/tools/Torch +++ b/tools/Torch @@ -1 +1 @@ -Subproject commit c6b1cdfa850597165bba15b36447ab2d91e4abff +Subproject commit 7da8ae8e25d6c1267792941bf9ac56c1acc384ae