diff options
| author | KiritoDv <kiritodev01@gmail.com> | 2025-01-15 15:50:57 -0600 |
|---|---|---|
| committer | KiritoDv <kiritodev01@gmail.com> | 2025-01-15 15:50:57 -0600 |
| commit | c02015fb050f8707e0d5a40d15bc5e5be4e7f1bf (patch) | |
| tree | 02ce933d6cea20f19cb866c7fad1fc7f212a8d58 /src | |
| parent | 5aac47e2fafb99678fc21e7839ec0e9cc7d65f70 (diff) | |
Reimplemented built-in generation
Diffstat (limited to 'src')
| -rw-r--r-- | src/port/Engine.cpp | 50 | ||||
| -rw-r--r-- | src/port/Engine.h | 2 | ||||
| -rw-r--r-- | src/port/extractor/GameExtractor.cpp | 51 | ||||
| -rw-r--r-- | src/port/extractor/GameExtractor.h | 17 | ||||
| -rw-r--r-- | src/port/ui/UIWidgets.cpp | 7 |
5 files changed, 113 insertions, 14 deletions
diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index 9d577583..65ba8570 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -2,6 +2,7 @@ #include "ui/ImguiUI.h" #include "StringHelper.h" +#include "extractor/GameExtractor.h" #include "libultraship/src/Context.h" #include "resource/type/ResourceType.h" #include "resource/importers/AnimFactory.h" @@ -47,7 +48,6 @@ namespace fs = std::filesystem; extern "C" { bool prevAltAssets = false; -float gInterpolationStep = 0.0f; #include <sf64thread.h> #include <macros.h> #include "sf64audio_provisional.h" @@ -59,14 +59,24 @@ static GamePool MemoryPool = { .chunk = 1024 * 512, .cursor = 0, .length = 0, .m GameEngine::GameEngine() { std::vector<std::string> archiveFiles; - if (const std::string cube_path = Ship::Context::GetPathRelativeToAppDirectory("starship.o2r"); - std::filesystem::exists(cube_path)) { - archiveFiles.push_back(cube_path); + const std::string main_path = Ship::Context::GetPathRelativeToAppDirectory("sf64.o2r"); + const std::string assets_path = Ship::Context::GetPathRelativeToAppDirectory("starship.o2r"); + +#ifdef _WIN32 + AllocConsole(); +#endif + + if (std::filesystem::exists(main_path)) { + archiveFiles.push_back(main_path); + } else { + GenAssetFile(); + archiveFiles.push_back(main_path); } - if (const std::string sm64_otr_path = Ship::Context::GetPathRelativeToAppDirectory("sf64.o2r"); - std::filesystem::exists(sm64_otr_path)) { - archiveFiles.push_back(sm64_otr_path); + + if (std::filesystem::exists(assets_path)) { + archiveFiles.push_back(assets_path); } + if (const std::string patches_path = Ship::Context::GetPathRelativeToAppDirectory("mods"); !patches_path.empty() && std::filesystem::exists(patches_path)) { if (std::filesystem::is_directory(patches_path)) { @@ -187,6 +197,23 @@ GameEngine::GameEngine() { context->GetResourceManager()->SetAltAssetsEnabled(prevAltAssets); } +void GameEngine::GenAssetFile() { + auto extractor = new GameExtractor(); + + if (!extractor->SelectGameFromUI()) { + ShowMessage("Extractor", "No game selected."); + return; + } + if (!extractor->ValidateChecksum()) { + ShowMessage("Extractor", "Invalid checksum."); + return; + } + + if (!extractor->GenerateOTR()) { + ShowMessage("Extractor", "Failed to generate OTR."); + } +} + void GameEngine::Create() { const auto instance = Instance = new GameEngine(); instance->AudioInit(); @@ -421,6 +448,15 @@ uint32_t GameEngine::GetInterpolationFPS() { CVarGetInteger("gInterpolationFPS", 60)); } +void GameEngine::ShowMessage(const char* title, const char* message) { +#if defined(__SWITCH__) + SPDLOG_ERROR(message); +#else + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, nullptr); + SPDLOG_ERROR(message); +#endif +} + 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 62af3283..5b09f1e5 100644 --- a/src/port/Engine.h +++ b/src/port/Engine.h @@ -24,6 +24,7 @@ class GameEngine { std::shared_ptr<Ship::Context> context; GameEngine(); + static void GenAssetFile(); static void Create(); void StartFrame() const; static void HandleAudioThread(); @@ -37,6 +38,7 @@ class GameEngine { static void Destroy(); static void ProcessGfxCommands(Gfx* commands); static uint32_t GetInterpolationFPS(); + static void ShowMessage(const char* title, const char* message); }; extern "C" void* GameEngine_Malloc(size_t size); diff --git a/src/port/extractor/GameExtractor.cpp b/src/port/extractor/GameExtractor.cpp new file mode 100644 index 00000000..9cfd7ea4 --- /dev/null +++ b/src/port/extractor/GameExtractor.cpp @@ -0,0 +1,51 @@ +#include "GameExtractor.h" + +#include <fstream> + +#include "Context.h" +#include "spdlog/spdlog.h" +#include "portable-file-dialogs.h" +#include <port/Engine.h> + +std::unordered_map<std::string, std::string> mGameList = { + { "f7475fb11e7e6830f82883412638e8390791ab87", "Star Fox 64 (U) (V1.1) (Uncompressed)" }, + { "09f0d105f476b00efa5303a3ebc42e60a7753b7a", "Star Fox 64 (U) (V1.1)" } +}; + +bool GameExtractor::SelectGameFromUI() { +#if !defined(__IOS__) || !defined(__ANDROID__) || !defined(__SWITCH__) + auto selection = pfd::open_file("Select a file", ".", { "N64 Roms", "*.z64 *.n64 *.v64" }).result(); + + if (selection.empty()) { + return false; + } + + this->mGamePath = selection[0]; +#else + this->mGamePath = Ship::Context::GetPathRelativeToAppDirectory("baserom.us.rev1.z64"); +#endif + + std::ifstream file(this->mGamePath, std::ios::binary); + this->mGameData = std::vector<uint8_t>( std::istreambuf_iterator( file ), {} ); + file.close(); + return true; +} + +std::optional<std::string> GameExtractor::ValidateChecksum() const { + const auto rom = new N64::Cartridge(this->mGameData); + rom->Initialize(); + return mGameList[rom->GetHash()]; +} + +bool GameExtractor::GenerateOTR() const { + Companion::Instance = new Companion(this->mGameData, ArchiveType::O2R, false); + + try { + Companion::Instance->Init(ExportType::Binary); + } catch (const std::exception& e) { + GameEngine::ShowMessage("Failed to generate OTR", e.what()); + exit(1); + } + + return true; +}
\ No newline at end of file diff --git a/src/port/extractor/GameExtractor.h b/src/port/extractor/GameExtractor.h new file mode 100644 index 00000000..da5de754 --- /dev/null +++ b/src/port/extractor/GameExtractor.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Companion.h" +#include <filesystem> +#include <vector> +#include <cstdint> + +class GameExtractor { +public: + static void GenAssetFile(); + std::optional<std::string> ValidateChecksum() const; + bool SelectGameFromUI(); + bool GenerateOTR() const; +private: + fs::path mGamePath; + std::vector<uint8_t> mGameData; +};
\ No newline at end of file diff --git a/src/port/ui/UIWidgets.cpp b/src/port/ui/UIWidgets.cpp index 3bac9f3a..00f6499b 100644 --- a/src/port/ui/UIWidgets.cpp +++ b/src/port/ui/UIWidgets.cpp @@ -1,10 +1,3 @@ -// -// UIWidgets.cpp -// soh -// -// Created by David Chavez on 25.08.22. -// - #include "UIWidgets.h" #include "libultraship/src/Context.h" |
