From c27a7fa28252a84c6a7037adfea7aca1a8364f27 Mon Sep 17 00:00:00 2001 From: Dario Date: Sat, 27 Jul 2024 12:12:54 -0300 Subject: [PATCH] Add a placeholder mod loader for texture packs. --- include/zelda_render.h | 2 ++ lib/rt64 | 2 +- src/main/rt64_render_context.cpp | 40 ++++++++++++++++++++++++++++++++ src/ui/ui_launcher.cpp | 2 +- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/include/zelda_render.h b/include/zelda_render.h index 684672b..884f374 100644 --- a/include/zelda_render.h +++ b/include/zelda_render.h @@ -26,9 +26,11 @@ namespace zelda64 { uint32_t get_display_framerate() const override; float get_resolution_scale() const override; void load_shader_cache(std::span cache_binary) override; + bool load_texture_packs(); protected: std::unique_ptr app; + bool texture_packs_checked = false; }; std::unique_ptr create_render_context(uint8_t *rdram, ultramodern::renderer::WindowHandle window_handle, bool developer_mode); diff --git a/lib/rt64 b/lib/rt64 index 8747507..b91d6a7 160000 --- a/lib/rt64 +++ b/lib/rt64 @@ -1 +1 @@ -Subproject commit 8747507cf96a4921efe83ea492dd0afbac1481f5 +Subproject commit b91d6a74410ad9afb1d491cb34d543d648dc06bc diff --git a/src/main/rt64_render_context.cpp b/src/main/rt64_render_context.cpp index 497e504..3954be1 100644 --- a/src/main/rt64_render_context.cpp +++ b/src/main/rt64_render_context.cpp @@ -8,6 +8,7 @@ #include "ultramodern/ultramodern.hpp" #include "ultramodern/config.hpp" +#include "zelda_config.h" #include "zelda_render.h" #include "recomp_ui.h" @@ -285,7 +286,46 @@ zelda64::renderer::RT64Context::RT64Context(uint8_t* rdram, ultramodern::rendere zelda64::renderer::RT64Context::~RT64Context() = default; +bool zelda64::renderer::RT64Context::load_texture_packs() { + const std::u8string RTZExtension(u8".rtz"); + std::filesystem::path mods_folder_path = zelda64::get_app_folder_path() / "mods" / "mm"; + if (!std::filesystem::exists(mods_folder_path)) { + return true; + } + + std::vector replacement_directories; + for (std::filesystem::directory_entry entry : std::filesystem::directory_iterator(mods_folder_path)) { + if (!entry.is_regular_file()) { + continue; + } + + std::filesystem::path path = entry.path(); + std::u8string ext = path.extension().u8string(); + std::transform(ext.begin(), ext.end(), ext.begin(), [](char8_t c) { return std::tolower(c); }); + if (ext != RTZExtension) { + continue; + } + + replacement_directories.emplace_back(path); + } + + if (!replacement_directories.empty()) { + return app->textureCache->loadReplacementDirectories(replacement_directories); + } + else { + return true; + } +} + void zelda64::renderer::RT64Context::send_dl(const OSTask* task) { + if (!texture_packs_checked) { + if (!load_texture_packs()) { + ultramodern::error_handling::message_box("One or more texture packs could not be loaded successfully. Make sure the files are not corrupt.\n\nNo texture packs will be loaded in the game."); + } + + texture_packs_checked = true; + } + app->state->rsp->reset(); app->interpreter->loadUCodeGBI(task->t.ucode & 0x3FFFFFF, task->t.ucode_data & 0x3FFFFFF, true); app->processDisplayLists(app->core.RDRAM, task->t.data_ptr & 0x3FFFFFF, 0, true); diff --git a/src/ui/ui_launcher.cpp b/src/ui/ui_launcher.cpp index b4b6312..52847e0 100644 --- a/src/ui/ui_launcher.cpp +++ b/src/ui/ui_launcher.cpp @@ -6,7 +6,7 @@ #include "nfd.h" #include -std::string version_number = "v1.1.1"; +std::string version_number = "v1.1.1-texturepacks"; Rml::DataModelHandle model_handle; bool mm_rom_valid = false;