mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-25 19:02:19 -05:00
LUS Cleanup: Removes unnecessary ModManager class.
This commit is contained in:
parent
212d774613
commit
6d3d5e7da5
@ -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"
|
||||
|
||||
|
@ -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> GlobalCtx2::Context;
|
||||
ModManager* INSTANCE;
|
||||
std::shared_ptr<GlobalCtx2> 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() {
|
||||
|
@ -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"
|
||||
|
@ -1,23 +0,0 @@
|
||||
#include "ModManager.h"
|
||||
#include "TextureMod.h"
|
||||
#include "ModModule.h"
|
||||
#include "ImGuiImpl.h"
|
||||
|
||||
namespace Ship {
|
||||
std::vector<ModModule*> modules;
|
||||
|
||||
void ModManager::Init() {
|
||||
// ResManager->GetArchive()->loa
|
||||
// modules.push_back(new TextureModule(this));
|
||||
// std::shared_ptr<Ship::Archive> archive = std::make_shared<Ship::Archive>("mods/TexMods.otr", "", false);
|
||||
for (auto& mod : modules) {
|
||||
mod->Init();
|
||||
// mod->Open(archive);
|
||||
}
|
||||
}
|
||||
|
||||
void ModManager::Exit() {
|
||||
for (auto& mod : modules)
|
||||
mod->Exit();
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
#include "ResourceMgr.h"
|
||||
|
||||
namespace Ship {
|
||||
class ModManager {
|
||||
public:
|
||||
std::shared_ptr<Ship::ResourceMgr> ResManager;
|
||||
explicit ModManager(std::shared_ptr<Ship::ResourceMgr> manager) : ResManager(manager) {}
|
||||
void Init();
|
||||
void Exit();
|
||||
};
|
||||
}
|
@ -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<Ship::Archive> archive) = 0;
|
||||
virtual void Close(Ship::Archive archive) = 0;
|
||||
virtual void Exit() = 0;
|
||||
};
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
#include "TextureMod.h"
|
||||
|
||||
#if 0
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#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<std::string>&) {
|
||||
INFO("Reloading all textures!");
|
||||
gfx_texture_cache_clear();
|
||||
this->TexturePool.clear();
|
||||
this->TextureCache.clear();
|
||||
return true;
|
||||
} });
|
||||
}
|
||||
|
||||
void TextureModule::Open(std::shared_ptr<Ship::Archive> 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<Ship::File> raw_data = std::make_shared<Ship::File>();
|
||||
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<uint8_t>(fmt), static_cast<uint8_t>(siz), static_cast<uint8_t>(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<const stbi_uc*>(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
|
@ -1,55 +0,0 @@
|
||||
#pragma once
|
||||
#include "ModModule.h"
|
||||
#include <PR/ultra64/gbi.h>
|
||||
#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<Ship::Archive> parent;
|
||||
TextureMod color_modifier = NONE;
|
||||
};
|
||||
|
||||
class TextureModule : public ModModule {
|
||||
public:
|
||||
explicit TextureModule(ModManager* Manager) : ModModule(Manager) {}
|
||||
private:
|
||||
std::vector<std::shared_ptr<Ship::Archive>> LoadedOTRS;
|
||||
std::map<std::string, TextureData*> TexturePool;
|
||||
std::map<std::string, std::vector<TextureCacheNode*>> TextureCache;
|
||||
void Init() override;
|
||||
void Open(std::shared_ptr<Ship::Archive> 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
|
@ -267,7 +267,6 @@
|
||||
<ClCompile Include="Lib\Mercury\Mercury.cpp" />
|
||||
<ClCompile Include="luslog.cpp" />
|
||||
<ClCompile Include="mixer.c" />
|
||||
<ClCompile Include="ModManager.cpp" />
|
||||
<ClCompile Include="SDLAudioPlayer.cpp" />
|
||||
<ClCompile Include="Console.cpp" />
|
||||
<ClCompile Include="Factories\AnimationFactory.cpp" />
|
||||
@ -332,7 +331,6 @@
|
||||
<ClCompile Include="SkeletonLimb.cpp" />
|
||||
<ClCompile Include="Text.cpp" />
|
||||
<ClCompile Include="Texture.cpp" />
|
||||
<ClCompile Include="TextureMod.cpp" />
|
||||
<ClCompile Include="Utils.cpp" />
|
||||
<ClCompile Include="Vertex.cpp" />
|
||||
<ClCompile Include="WasapiAudioPlayer.cpp" />
|
||||
@ -364,8 +362,6 @@
|
||||
<ClInclude Include="Lib\stb\stb_image_write.h" />
|
||||
<ClInclude Include="luslog.h" />
|
||||
<ClInclude Include="mixer.h" />
|
||||
<ClInclude Include="ModManager.h" />
|
||||
<ClInclude Include="ModModule.h" />
|
||||
<ClInclude Include="SDLAudioPlayer.h" />
|
||||
<ClInclude Include="Console.h" />
|
||||
<ClInclude Include="Factories\ArrayFactory.h" />
|
||||
@ -404,7 +400,6 @@
|
||||
<ClInclude Include="Matrix.h" />
|
||||
<ClInclude Include="Path.h" />
|
||||
<ClInclude Include="Text.h" />
|
||||
<ClInclude Include="TextureMod.h" />
|
||||
<ClInclude Include="Utils.h" />
|
||||
<ClInclude Include="Vertex.h" />
|
||||
<ClInclude Include="stox.h" />
|
||||
|
@ -70,12 +70,6 @@
|
||||
<Filter Include="Source Files\CustomImpl\Utils">
|
||||
<UniqueIdentifier>{0dca2d94-45ba-4916-b03a-1dd5f949114c}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\ModManager">
|
||||
<UniqueIdentifier>{8e970531-d0cd-4c29-9800-a7e6edc92036}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\ModManager\ModModule">
|
||||
<UniqueIdentifier>{05f273a3-f147-430e-9853-aeef59e6288d}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\CustomImpl\Hooks">
|
||||
<UniqueIdentifier>{cc8de11b-7305-4482-853f-7f0f843eef28}</UniqueIdentifier>
|
||||
</Filter>
|
||||
@ -321,12 +315,6 @@
|
||||
<ClCompile Include="Cvar.cpp">
|
||||
<Filter>Source Files\Globals</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TextureMod.cpp">
|
||||
<Filter>Source Files\ModManager\ModModule</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ModManager.cpp">
|
||||
<Filter>Source Files\ModManager</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="luslog.cpp">
|
||||
<Filter>Source Files\Logging</Filter>
|
||||
</ClCompile>
|
||||
@ -614,15 +602,6 @@
|
||||
<ClInclude Include="Lib\stb\stb_image_write.h">
|
||||
<Filter>Source Files\Lib\stb</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="TextureMod.h">
|
||||
<Filter>Source Files\ModManager\ModModule</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ModManager.h">
|
||||
<Filter>Source Files\ModManager</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ModModule.h">
|
||||
<Filter>Source Files\ModManager\ModModule</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Hooks.h">
|
||||
<Filter>Source Files\CustomImpl\Hooks</Filter>
|
||||
</ClInclude>
|
||||
|
Loading…
Reference in New Issue
Block a user