From 6d3d5e7da5e8728adcf678a9febfb01aa86746c0 Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Wed, 3 Aug 2022 21:22:07 -0400 Subject: [PATCH] LUS Cleanup: Removes unnecessary ModManager class. --- libultraship/libultraship/GameOverlay.cpp | 1 - libultraship/libultraship/GlobalCtx2.cpp | 5 - libultraship/libultraship/ImGuiImpl.cpp | 1 - libultraship/libultraship/ModManager.cpp | 23 ---- libultraship/libultraship/ModManager.h | 12 -- libultraship/libultraship/ModModule.h | 19 --- libultraship/libultraship/TextureMod.cpp | 128 ------------------ libultraship/libultraship/TextureMod.h | 55 -------- .../libultraship/libultraship.vcxproj | 5 - .../libultraship/libultraship.vcxproj.filters | 21 --- 10 files changed, 270 deletions(-) delete mode 100644 libultraship/libultraship/ModManager.cpp delete mode 100644 libultraship/libultraship/ModManager.h delete mode 100644 libultraship/libultraship/ModModule.h delete mode 100644 libultraship/libultraship/TextureMod.cpp delete mode 100644 libultraship/libultraship/TextureMod.h diff --git a/libultraship/libultraship/GameOverlay.cpp b/libultraship/libultraship/GameOverlay.cpp index 01d889dd6..00bab575f 100644 --- a/libultraship/libultraship/GameOverlay.cpp +++ b/libultraship/libultraship/GameOverlay.cpp @@ -6,7 +6,6 @@ #include "ResourceMgr.h" #include "Console.h" #include "ImGuiImpl.h" -#include "TextureMod.h" #include "Lib/ImGui/imgui_internal.h" #include "Utils/StringHelper.h" diff --git a/libultraship/libultraship/GlobalCtx2.cpp b/libultraship/libultraship/GlobalCtx2.cpp index 5eb449ad3..4d6046de3 100644 --- a/libultraship/libultraship/GlobalCtx2.cpp +++ b/libultraship/libultraship/GlobalCtx2.cpp @@ -7,7 +7,6 @@ #include "spdlog/sinks/rotating_file_sink.h" #include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/sinks/sohconsole_sink.h" -#include "ModManager.h" #ifdef __APPLE__ #include "OSXFolderManager.h" #elif defined(__SWITCH__) @@ -16,7 +15,6 @@ namespace Ship { std::weak_ptr GlobalCtx2::Context; - ModManager* INSTANCE; std::shared_ptr GlobalCtx2::GetInstance() { return Context.lock(); } @@ -56,7 +54,6 @@ namespace Ship { GlobalCtx2::~GlobalCtx2() { SPDLOG_INFO("destruct GlobalCtx2"); - INSTANCE->Exit(); } void GlobalCtx2::InitWindow() { @@ -84,8 +81,6 @@ namespace Ship { #ifdef __SWITCH__ Ship::Switch::Init(PostInitPhase); #endif - INSTANCE = new ModManager(ResMan); - INSTANCE->Init(); } void GlobalCtx2::InitLogging() { diff --git a/libultraship/libultraship/ImGuiImpl.cpp b/libultraship/libultraship/ImGuiImpl.cpp index 1a0a79bf9..583d36f01 100644 --- a/libultraship/libultraship/ImGuiImpl.cpp +++ b/libultraship/libultraship/ImGuiImpl.cpp @@ -15,7 +15,6 @@ #include "Lib/ImGui/imgui_internal.h" #include "GlobalCtx2.h" #include "ResourceMgr.h" -#include "TextureMod.h" #include "Window.h" #include "Cvar.h" #include "GameOverlay.h" diff --git a/libultraship/libultraship/ModManager.cpp b/libultraship/libultraship/ModManager.cpp deleted file mode 100644 index 8aa2715de..000000000 --- a/libultraship/libultraship/ModManager.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "ModManager.h" -#include "TextureMod.h" -#include "ModModule.h" -#include "ImGuiImpl.h" - -namespace Ship { - std::vector modules; - - void ModManager::Init() { - // ResManager->GetArchive()->loa - // modules.push_back(new TextureModule(this)); - // std::shared_ptr archive = std::make_shared("mods/TexMods.otr", "", false); - for (auto& mod : modules) { - mod->Init(); - // mod->Open(archive); - } - } - - void ModManager::Exit() { - for (auto& mod : modules) - mod->Exit(); - } -} \ No newline at end of file diff --git a/libultraship/libultraship/ModManager.h b/libultraship/libultraship/ModManager.h deleted file mode 100644 index ca25355b5..000000000 --- a/libultraship/libultraship/ModManager.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -#include "ResourceMgr.h" - -namespace Ship { - class ModManager { - public: - std::shared_ptr ResManager; - explicit ModManager(std::shared_ptr manager) : ResManager(manager) {} - void Init(); - void Exit(); - }; -} \ No newline at end of file diff --git a/libultraship/libultraship/ModModule.h b/libultraship/libultraship/ModModule.h deleted file mode 100644 index da62273db..000000000 --- a/libultraship/libultraship/ModModule.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once -#include "ModManager.h" -#include "Hooks.h" -#include "Console.h" -#include "Archive.h" - -namespace Ship { - class ModModule { - protected: - ModManager* Manager; - public: - virtual ~ModModule() = default; - explicit ModModule(ModManager* Manager) : Manager(Manager) {} - virtual void Init() = 0; - virtual void Open(std::shared_ptr archive) = 0; - virtual void Close(Ship::Archive archive) = 0; - virtual void Exit() = 0; - }; -} \ No newline at end of file diff --git a/libultraship/libultraship/TextureMod.cpp b/libultraship/libultraship/TextureMod.cpp deleted file mode 100644 index 87f17ed2c..000000000 --- a/libultraship/libultraship/TextureMod.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "TextureMod.h" - -#if 0 - -#include -#include -#include -#include -#include -#include "Lib/stb/stb_image.h" -#include "Lib/Fast3D/gfx_pc.h" -#define STB_IMAGE_WRITE_IMPLEMENTATION -#include "Lib/stb/stb_image_write.h" -#include "Lib/Fast3D/gfx_rendering_api.h" -#include "SohImGuiImpl.h" - -namespace fs = std::filesystem; - -namespace Ship { - void TextureModule::Init() { - BIND_HOOK(LOOKUP_TEXTURE, Hook_LookupTexture); - BIND_HOOK(GRAYOUT_TEXTURE, Hook_GrayScaleFilter); - BIND_HOOK(INVALIDATE_TEXTURE, Hook_InvalidateTexture); - - SohImGui::BindCmd("reload", { .handler = [&](const std::vector&) { - INFO("Reloading all textures!"); - gfx_texture_cache_clear(); - this->TexturePool.clear(); - this->TextureCache.clear(); - return true; - } }); - } - - void TextureModule::Open(std::shared_ptr archive) { - this->LoadedOTRS.push_back(archive); - } - - void TextureModule::Close(Ship::Archive otr) { - // Remove all loaded textures - // this->LoadedOTRS.erase(std::find(this->LoadedOTRS.begin(), this->LoadedOTRS.end(), otr)); - } - - void TextureModule::Hook_LookupTexture(HookEvent call) { - const auto raw_path = BIND_PTR("path", char*); - if (raw_path == nullptr) return; - - const auto api = BIND_PTR("gfx_api", GfxRenderingAPI*); - const auto path = std::string(raw_path) + ".png"; - const auto node = BIND_PTR("node", TextureCacheNode**); - const auto fmt = BIND_VAR("fmt", uint32_t*); - const auto siz = BIND_VAR("siz", uint32_t*); - const auto tile = BIND_VAR("tile", int*); - const auto palette = BIND_VAR("palette", uint32_t*); - const auto orig_addr = BIND_VAR("addr", const uint8_t**); - - // INFO("The game is trying to load %s", path.c_str()); - - if (this->TextureCache.contains(path) && this->TextureCache[path][tile] != nullptr) { - *node = this->TextureCache[path][tile]; - api->select_texture(tile, (*node)->second.texture_id); - call->cancelled = true; - return; - } - - // OTRTODO: Implement loading order - TextureData* tex_data = nullptr; - if (!this->TexturePool.contains(path)) { - std::shared_ptr raw_data = std::make_shared(); - this->Manager->ResManager->GetArchive()->LoadPatchFile(path, false, raw_data); - - if (raw_data->bIsLoaded) { - char* tdata = new char[raw_data->dwBufferSize]; - memcpy(tdata, raw_data->buffer.get(), raw_data->dwBufferSize); - tex_data = new TextureData({ .data = tdata, .size = raw_data->dwBufferSize }); - INFO("Loaded %s", path.c_str()); - this->TexturePool[path] = tex_data; - } - } - - if (tex_data == nullptr) - return; - - if (!this->TextureCache.contains(path)) this->TextureCache[path].resize(10); - - TextureCacheKey key = { orig_addr, { }, static_cast(fmt), static_cast(siz), static_cast(palette) }; - TextureCacheValue value = { api->new_texture(), 0, 0, false }; - const auto entry = new TextureCacheNode(key, value); - api->select_texture(tile, entry->second.texture_id); - api->set_sampler_parameters(tile, false, 0, 0); - *node = entry; - - uint8_t* img_data = stbi_load_from_memory(reinterpret_cast(tex_data->data), tex_data->size, &tex_data->width, &tex_data->height, nullptr, 4); - - if (!img_data) - return; - - switch (tex_data->color_modifier) { - case GRAYSCALE: { - GrayOutTexture(img_data, tex_data->width, tex_data->height); - } - default:; - } - - std::cout << "Uploading to the GPU" << std::endl; - api->upload_texture(img_data, tex_data->width, tex_data->height); - this->TextureCache[path][tile] = entry; - - stbi_image_free(img_data); - call->cancelled = true; - } - - - void TextureModule::Hook_GrayScaleFilter(HookEvent event) { - // this->Exit(); - } - - void TextureModule::Hook_InvalidateTexture(HookEvent event) { - // this->Exit(); - } - - void TextureModule::Exit() { - TextureCache.clear(); - TexturePool.clear(); - LoadedOTRS.clear(); - } -} - -#endif diff --git a/libultraship/libultraship/TextureMod.h b/libultraship/libultraship/TextureMod.h deleted file mode 100644 index 5f41873ca..000000000 --- a/libultraship/libultraship/TextureMod.h +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once -#include "ModModule.h" -#include -#include "Lib/Fast3D/gfx_pc.h" - -#if 0 - -namespace Ship { - enum TextureMod { - GRAYSCALE, - NONE - }; - - struct TextureData { - char* data; - uint32_t size; - int width; - int height; - char* loaded_data; - std::shared_ptr parent; - TextureMod color_modifier = NONE; - }; - - class TextureModule : public ModModule { - public: - explicit TextureModule(ModManager* Manager) : ModModule(Manager) {} - private: - std::vector> LoadedOTRS; - std::map TexturePool; - std::map> TextureCache; - void Init() override; - void Open(std::shared_ptr archive) override; - void Close(Ship::Archive mod) override; - void Exit() override; - protected: - void Hook_LookupTexture(HookEvent event); - void Hook_GrayScaleFilter(HookEvent event); - void Hook_InvalidateTexture(HookEvent event); - }; - - inline void GrayOutTexture(uint8_t* data, int width, int height) { - for (int x = 0; x < width * height * 4; x += 4) { - - int red = data[x]; - int green = data[x + 1]; - int blue = data[x + 2]; - int gray = (red + green + blue) / 3; - data[x] = gray; - data[x + 1] = gray; - data[x + 2] = gray; - } - } -} - -#endif diff --git a/libultraship/libultraship/libultraship.vcxproj b/libultraship/libultraship/libultraship.vcxproj index 95250d4b1..f677dfe5e 100644 --- a/libultraship/libultraship/libultraship.vcxproj +++ b/libultraship/libultraship/libultraship.vcxproj @@ -267,7 +267,6 @@ - @@ -332,7 +331,6 @@ - @@ -364,8 +362,6 @@ - - @@ -404,7 +400,6 @@ - diff --git a/libultraship/libultraship/libultraship.vcxproj.filters b/libultraship/libultraship/libultraship.vcxproj.filters index bf5193682..b7fe847ce 100644 --- a/libultraship/libultraship/libultraship.vcxproj.filters +++ b/libultraship/libultraship/libultraship.vcxproj.filters @@ -70,12 +70,6 @@ {0dca2d94-45ba-4916-b03a-1dd5f949114c} - - {8e970531-d0cd-4c29-9800-a7e6edc92036} - - - {05f273a3-f147-430e-9853-aeef59e6288d} - {cc8de11b-7305-4482-853f-7f0f843eef28} @@ -321,12 +315,6 @@ Source Files\Globals - - Source Files\ModManager\ModModule - - - Source Files\ModManager - Source Files\Logging @@ -614,15 +602,6 @@ Source Files\Lib\stb - - Source Files\ModManager\ModModule - - - Source Files\ModManager - - - Source Files\ModManager\ModModule - Source Files\CustomImpl\Hooks