diff --git a/libultraship/libultraship/Archive.h b/libultraship/libultraship/Archive.h index f8fe3e0fd..1130518a1 100644 --- a/libultraship/libultraship/Archive.h +++ b/libultraship/libultraship/Archive.h @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include #include "Resource.h" @@ -43,9 +43,9 @@ namespace Ship private: std::string MainPath; std::string PatchesPath; - std::map mpqHandles; + std::unordered_map mpqHandles; std::vector addedFiles; - std::map hashes; + std::unordered_map hashes; HANDLE mainMPQ; bool LoadMainMPQ(bool enableWriting, bool genCRCMap); diff --git a/libultraship/libultraship/GlobalCtx2.cpp b/libultraship/libultraship/GlobalCtx2.cpp index dd8125bcc..a224787a2 100644 --- a/libultraship/libultraship/GlobalCtx2.cpp +++ b/libultraship/libultraship/GlobalCtx2.cpp @@ -82,4 +82,8 @@ namespace Ship { std::cout << "Log initialization failed: " << ex.what() << std::endl; } } + + ModManager* GlobalCtx2::GetModManager() { + return INSTANCE; + } } \ No newline at end of file diff --git a/libultraship/libultraship/GlobalCtx2.h b/libultraship/libultraship/GlobalCtx2.h index a10421ec0..8cf2163ca 100644 --- a/libultraship/libultraship/GlobalCtx2.h +++ b/libultraship/libultraship/GlobalCtx2.h @@ -6,6 +6,7 @@ #include "ConfigFile.h" namespace Ship { + class ModManager; class ResourceMgr; class Window; @@ -19,6 +20,7 @@ namespace Ship { std::shared_ptr GetResourceManager() { return ResMan; } std::shared_ptr GetLogger() { return Logger; } std::shared_ptr GetConfig() { return Config; } + ModManager* GetModManager(); GlobalCtx2(const std::string& Name); ~GlobalCtx2(); diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp index 1d03befe6..dd1782cb2 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp @@ -25,6 +25,8 @@ #include "gfx_rendering_api.h" #include "gfx_screen_config.h" #include "../../SohHooks.h" +#include "../../GlobalCtx2.h" +#include "../../TextureMod.h" #include "../../luslog.h" #include "../StrHash64.h" @@ -95,8 +97,8 @@ struct ColorCombiner { uint8_t shader_input_mapping[2][7]; }; -static map color_combiner_pool; -static map::iterator prev_combiner = color_combiner_pool.end(); +static unordered_map color_combiner_pool; +static unordered_map::iterator prev_combiner = color_combiner_pool.end(); static struct RSP { float modelview_matrix_stack[11][4][4]; @@ -203,8 +205,8 @@ struct FBInfo { }; static bool fbActive = 0; -static map::iterator active_fb; -static map framebuffers; +static unordered_map::iterator active_fb; +static unordered_map framebuffers; static set> get_pixel_depth_pending; static map, uint16_t> get_pixel_depth_cached; @@ -218,6 +220,7 @@ static unsigned long get_time(void) #else #include #include +#include "../../GlobalCtx2.h" static unsigned long get_time(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); @@ -826,6 +829,11 @@ static void import_texture(int i, int tile) { uint8_t siz = rdp.texture_tile[tile].siz; uint32_t tmem_index = rdp.texture_tile[tile].tmem_index; + Ship::TextureModule* tex_module = Ship::GlobalCtx2::GetInstance()->GetModManager()->TextureMod; + if(tex_module->LookupTexture(i, rdp.loaded_texture[tmem_index].otr_path, gfx_get_current_rendering_api(), &rendering_state.textures[i], fmt, siz, rdp.texture_tile[tile].palette, rdp.loaded_texture[tmem_index].addr)) { + return; + } + if (gfx_texture_cache_lookup(i, tile)) { return; @@ -848,7 +856,7 @@ static void import_texture(int i, int tile) { } else if (siz == G_IM_SIZ_16b) { import_texture_ia16(tile); } else { - abort(); + // abort(); } } else if (fmt == G_IM_FMT_CI) { if (siz == G_IM_SIZ_4b) { @@ -856,7 +864,7 @@ static void import_texture(int i, int tile) { } else if (siz == G_IM_SIZ_8b) { import_texture_ci8(tile); } else { - abort(); + // abort(); } } else if (fmt == G_IM_FMT_I) { if (siz == G_IM_SIZ_4b) { @@ -864,10 +872,10 @@ static void import_texture(int i, int tile) { } else if (siz == G_IM_SIZ_8b) { import_texture_i8(tile); } else { - abort(); + //abort(); } } else { - abort(); + // abort(); } int t1 = get_time(); //printf("Time diff: %d\n", t1 - t0); @@ -1616,7 +1624,7 @@ static void gfx_dp_set_scissor(uint32_t mode, uint32_t ulx, uint32_t uly, uint32 rdp.viewport_or_scissor_changed = true; } -static void gfx_dp_set_texture_image(uint32_t format, uint32_t size, uint32_t width, const void* addr, char* otr_path) { +void gfx_dp_set_texture_image(uint32_t format, uint32_t size, uint32_t width, const void* addr, char* otr_path) { rdp.texture_to_load.addr = (const uint8_t*)addr; rdp.texture_to_load.siz = size; rdp.texture_to_load.width = width; @@ -1713,7 +1721,10 @@ static void gfx_dp_load_block(uint8_t tile, uint32_t uls, uint32_t ult, uint32_t rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].full_image_line_size_bytes = size_bytes; //assert(size_bytes <= 4096 && "bug: too big texture"); rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].addr = rdp.texture_to_load.addr; - rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path = rdp.texture_to_load.otr_path; + + if(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path) + free(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path); + rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path = _strdup(rdp.texture_to_load.otr_path); rdp.textures_changed[rdp.texture_tile[tile].tmem_index] = true; } @@ -1746,7 +1757,9 @@ static void gfx_dp_load_tile(uint8_t tile, uint32_t uls, uint32_t ult, uint32_t assert(size_bytes <= 4096 && "bug: too big texture"); rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].addr = rdp.texture_to_load.addr + start_offset; - rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path = rdp.texture_to_load.otr_path; + if(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path) + free(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path); + rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path = _strdup(rdp.texture_to_load.otr_path); rdp.texture_tile[tile].uls = uls; rdp.texture_tile[tile].ult = ult; rdp.texture_tile[tile].lrs = lrs; @@ -2398,6 +2411,9 @@ static void gfx_run_dl(Gfx* cmd) { char* imgData = (char*)i; + if (strstr(imgData, "spot04_room_0Tex_")) + volatile u32 bla = 0; + if ((i & 0xF0000000) != 0xF0000000) if (ResourceMgr_OTRSigCheck(imgData) == 1) i = (uintptr_t)ResourceMgr_LoadTexByName(imgData); diff --git a/libultraship/libultraship/ModManager.cpp b/libultraship/libultraship/ModManager.cpp index c07f169ac..38da616bf 100644 --- a/libultraship/libultraship/ModManager.cpp +++ b/libultraship/libultraship/ModManager.cpp @@ -4,20 +4,15 @@ #include "SohImGuiImpl.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); - } + TextureMod = new TextureModule(this); + const std::shared_ptr archive = std::make_shared("mods/TexModDemo.otr", "", false); + static_cast(TextureMod)->Init(); + static_cast(TextureMod)->Open(archive); } void ModManager::Exit() { - for (auto& mod : modules) - mod->Exit(); + static_cast(TextureMod)->Exit(); } } \ No newline at end of file diff --git a/libultraship/libultraship/ModManager.h b/libultraship/libultraship/ModManager.h index ca25355b5..fbefeb6f8 100644 --- a/libultraship/libultraship/ModManager.h +++ b/libultraship/libultraship/ModManager.h @@ -2,11 +2,14 @@ #include "ResourceMgr.h" namespace Ship { + class TextureModule; + class ModManager { public: - std::shared_ptr ResManager; - explicit ModManager(std::shared_ptr manager) : ResManager(manager) {} + std::shared_ptr ResManager; + TextureModule* TextureMod; + explicit ModManager(std::shared_ptr manager) : ResManager(manager) {} void Init(); void Exit(); }; -} \ No newline at end of file +} diff --git a/libultraship/libultraship/TextureMod.cpp b/libultraship/libultraship/TextureMod.cpp index 2a7e39511..8185e1ccc 100644 --- a/libultraship/libultraship/TextureMod.cpp +++ b/libultraship/libultraship/TextureMod.cpp @@ -1,6 +1,6 @@ #include "TextureMod.h" -#include +#include #include #include #include @@ -16,8 +16,8 @@ namespace fs = std::filesystem; namespace Ship { void TextureModule::Init() { - BIND_HOOK(LOOKUP_TEXTURE, Hook_LookupTexture); BIND_HOOK(GRAYOUT_TEXTURE, Hook_GrayScaleFilter); + //BIND_HOOK(LOAD_TEXTURE, Hook_LoadTexture); BIND_HOOK(INVALIDATE_TEXTURE, Hook_InvalidateTexture); SohImGui::BindCmd("reload", { .handler = [&](const std::vector&) { @@ -29,54 +29,48 @@ namespace Ship { } }); } - void TextureModule::Open(std::shared_ptr archive) { + void TextureModule::Open(std::shared_ptr archive) { this->LoadedOTRS.push_back(archive); } - void TextureModule::Close(Ship::Archive otr) { + void TextureModule::Close(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; + bool TextureModule::LookupTexture(int tile, char* path, GfxRenderingAPI* api, TextureCacheNode** node, uint32_t fmt, uint32_t siz, uint32_t palette, const uint8_t* orig_addr) { - const auto api = BIND_PTR("gfx_api", GfxRenderingAPI*); - const auto path = normalize(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 (path == nullptr || (path != nullptr && (strlen(path) > 128 || path[0] == '\0'))) + return false; 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; + return true; } // 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); + for(auto &otr : LoadedOTRS) { + const auto fix_path = normalize(path) + ".png"; + std::shared_ptr raw_data = std::make_shared(); + if (!otr->HasFile(fix_path)) continue; - 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; + otr->LoadFile(fix_path, false, raw_data); + + if (raw_data->bIsLoaded) { + auto 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); + this->TexturePool[path] = tex_data; + } } } if (tex_data == nullptr) - return; + return false; if (!this->TextureCache.contains(path)) this->TextureCache[path].resize(10); @@ -90,7 +84,7 @@ namespace Ship { 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; + return false; switch (tex_data->color_modifier) { case GRAYSCALE: { @@ -104,14 +98,63 @@ namespace Ship { this->TextureCache[path][tile] = entry; stbi_image_free(img_data); - call->cancelled = true; + return true; } - void TextureModule::Hook_GrayScaleFilter(HookEvent event) { // this->Exit(); } + void TextureModule::Hook_LoadTexture(HookEvent event) { + char* path = (char*)event->baseArgs["path"] + 7; // __OTR__ + void** outPtr = (void**)event->baseArgs["texture"]; + + TextureData* tex_data = nullptr; + if (!this->TexturePool.contains(path)) { + for(auto &otr : LoadedOTRS) { + const auto fix_path = normalize(path) + ".png"; + std::shared_ptr raw_data = std::make_shared(); + if (!otr->HasFile(fix_path)) continue; + + otr->LoadFile(fix_path, false, raw_data); + + if (raw_data->bIsLoaded) { + auto 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); + } + } + } + + if (tex_data == nullptr) + return; + + 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) + { + delete[] tex_data->data; + delete tex_data; + return; + } + + switch (tex_data->color_modifier) { + case GRAYSCALE: { + GrayOutTexture(img_data, tex_data->width, tex_data->height); + } + default:; + } + + *outPtr = malloc(tex_data->size); + memcpy(*outPtr, img_data, tex_data->size); + + //*outPtr = img_data; + stbi_image_free(img_data); + delete[] tex_data->data; + delete tex_data; + } + void TextureModule::Hook_InvalidateTexture(HookEvent event) { // this->Exit(); } diff --git a/libultraship/libultraship/TextureMod.h b/libultraship/libultraship/TextureMod.h index 987a0c6f3..6900d8951 100644 --- a/libultraship/libultraship/TextureMod.h +++ b/libultraship/libultraship/TextureMod.h @@ -4,6 +4,7 @@ #include "Lib/Fast3D/gfx_pc.h" namespace Ship { + enum TextureMod { GRAYSCALE, NONE @@ -15,23 +16,24 @@ namespace Ship { int width; int height; char* loaded_data; - std::shared_ptr parent; + std::shared_ptr parent; TextureMod color_modifier = NONE; }; class TextureModule : public ModModule { public: explicit TextureModule(ModManager* Manager) : ModModule(Manager) {} + bool LookupTexture(int tile, char* path, GfxRenderingAPI* api, TextureCacheNode** node, uint32_t fmt, uint32_t siz, uint32_t palette, const uint8_t* addr); private: - std::vector> LoadedOTRS; - std::map TexturePool; - std::map> TextureCache; + std::vector> LoadedOTRS; + std::unordered_map TexturePool; + std::unordered_map> TextureCache; void Init() override; - void Open(std::shared_ptr archive) override; - void Close(Ship::Archive mod) override; + void Open(std::shared_ptr archive) override; + void Close(Archive mod) override; void Exit() override; protected: - void Hook_LookupTexture(HookEvent event); + void Hook_LoadTexture(HookEvent event); void Hook_GrayScaleFilter(HookEvent event); void Hook_InvalidateTexture(HookEvent event); }; diff --git a/libultraship/libultraship/Window.cpp b/libultraship/libultraship/Window.cpp index 2b57c547e..883cdb9f6 100644 --- a/libultraship/libultraship/Window.cpp +++ b/libultraship/libultraship/Window.cpp @@ -197,13 +197,17 @@ extern "C" { } char* ResourceMgr_LoadTexByName(char* texPath) { - const auto res = static_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(texPath).get()); + void* imageData = nullptr; ModInternal::bindHook(LOAD_TEXTURE); ModInternal::initBindHook(2, HookParameter({ .name = "path", .parameter = (void*)texPath }), - HookParameter({ .name = "texture", .parameter = static_cast(&res->imageData) }) + HookParameter({ .name = "texture", .parameter = &imageData }) ); ModInternal::callBindHook(0); + if(imageData) + return (char*)imageData; + + const auto res = static_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(texPath).get()); return (char*)res->imageData; } diff --git a/soh/soh/Enhancements/debugconsole.cpp b/soh/soh/Enhancements/debugconsole.cpp index 06126281f..e9b84b94b 100644 --- a/soh/soh/Enhancements/debugconsole.cpp +++ b/soh/soh/Enhancements/debugconsole.cpp @@ -2,6 +2,7 @@ #include "../libultraship/SohImGuiImpl.h" #include #include +#include #define Path _Path #define PATH_HACK diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index fca6d6b7d..fc3675744 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -188,7 +188,7 @@ extern "C" void ResourceMgr_CacheDirectory(const char* resName) { OTRGlobals::Instance->context->GetResourceManager()->CacheDirectory(resName); } extern "C" void ResourceMgr_DirtyDirectory(const char* resName) { - OTRGlobals::Instance->context->GetResourceManager()->DirtyDirectory(resName); + //OTRGlobals::Instance->context->GetResourceManager()->DirtyDirectory(resName); } extern "C" void ResourceMgr_InvalidateCache() { diff --git a/soh/src/code/z_actor.c b/soh/src/code/z_actor.c index eee9d8882..8cdf8fcec 100644 --- a/soh/src/code/z_actor.c +++ b/soh/src/code/z_actor.c @@ -728,9 +728,10 @@ void func_8002CDE4(GlobalContext* globalCtx, TitleCardContext* titleCtx) { void TitleCard_InitBossName(GlobalContext* globalCtx, TitleCardContext* titleCtx, void* texture, s16 x, s16 y, u8 width, u8 height) { - if (ResourceMgr_OTRSigCheck(texture)) - texture = ResourceMgr_LoadTexByName(texture); + //if (ResourceMgr_OTRSigCheck(texture)) + // texture = ResourceMgr_LoadTexByName(texture); + // Only works for english titleCtx->texture = texture; titleCtx->x = x; titleCtx->y = y; @@ -946,7 +947,7 @@ void TitleCard_InitPlaceName(GlobalContext* globalCtx, TitleCardContext* titleCt texture = newName; } - titleCtx->texture = ResourceMgr_LoadTexByName(texture); + titleCtx->texture = texture; //titleCtx->texture = texture; titleCtx->x = x; diff --git a/soh/src/code/z_construct.c b/soh/src/code/z_construct.c index c74d3c14c..6f9057dfb 100644 --- a/soh/src/code/z_construct.c +++ b/soh/src/code/z_construct.c @@ -56,8 +56,7 @@ void func_801109B0(GlobalContext* globalCtx) { doActionOffset = 0x5700; } - memcpy(interfaceCtx->doActionSegment, ResourceMgr_LoadTexByName(gAttackDoActionENGTex), 0x180); - memcpy(interfaceCtx->doActionSegment + 0x180, ResourceMgr_LoadTexByName(gCheckDoActionENGTex), 0x180); + memcpy(interfaceCtx->doActionSegment, gAttackDoActionENGTex, sizeof(gAttackDoActionENGTex) /* including 0 byte */); //DmaMgr_SendRequest1(interfaceCtx->doActionSegment, (uintptr_t)_do_action_staticSegmentRomStart + doActionOffset, 0x300, //"../z_construct.c", 174); @@ -69,7 +68,7 @@ void func_801109B0(GlobalContext* globalCtx) { doActionOffset = 0x5B80; } - memcpy(interfaceCtx->doActionSegment + 0x300, ResourceMgr_LoadTexByName(gReturnDoActionENGTex), 0x180); + memcpy(interfaceCtx->doActionSegment + 0x300, gReturnDoActionENGTex, sizeof(gReturnDoActionENGTex) /* including 0 byte */); //DmaMgr_SendRequest1(interfaceCtx->doActionSegment + 0x300, (uintptr_t)_do_action_staticSegmentRomStart + doActionOffset, //0x180, "../z_construct.c", 178); diff --git a/soh/src/code/z_kanfont.c b/soh/src/code/z_kanfont.c index c7f3234bb..57ff2915e 100644 --- a/soh/src/code/z_kanfont.c +++ b/soh/src/code/z_kanfont.c @@ -174,7 +174,7 @@ void Font_LoadChar(Font* font, u8 character, u16 codePointIndex) { //"../z_kanfont.c", 93); if (character < 0x8B) - memcpy(&font->charTexBuf[codePointIndex], ResourceMgr_LoadTexByName(fntTbl[character]), FONT_CHAR_TEX_SIZE); + memcpy(&font->charTexBuf[codePointIndex], fntTbl[character], strlen(fntTbl[character]) + 1); } /** @@ -183,7 +183,7 @@ void Font_LoadChar(Font* font, u8 character, u16 codePointIndex) { * The different icons are given in the MessageBoxIcon enum. */ void Font_LoadMessageBoxIcon(Font* font, u16 icon) { - memcpy(font->iconBuf, msgStaticTbl[4 + icon], FONT_CHAR_TEX_SIZE); + memcpy(font->iconBuf, msgStaticTbl[4 + icon], strlen(msgStaticTbl[4 + icon]) + 1); } /** @@ -218,7 +218,7 @@ void Font_LoadOrderedFont(Font* font) { osSyncPrintf("nes_mes_buf[%d]=%d\n", codePointIndex, font->msgBuf[codePointIndex]); offset = (font->msgBuf[codePointIndex] - '\x20') * FONT_CHAR_TEX_SIZE; - memcpy(fontBuf, ResourceMgr_LoadTexByName(fntTbl[offset / FONT_CHAR_TEX_SIZE]), FONT_CHAR_TEX_SIZE); + memcpy(fontBuf, fntTbl[offset / FONT_CHAR_TEX_SIZE], strlen(fntTbl[offset / FONT_CHAR_TEX_SIZE]) + 1); //DmaMgr_SendRequest1(fontBuf, fontStatic + offset, FONT_CHAR_TEX_SIZE, "../z_kanfont.c", 134); fontBufIndex += FONT_CHAR_TEX_SIZE / 8; } diff --git a/soh/src/code/z_map_exp.c b/soh/src/code/z_map_exp.c index cfef800c9..19d22fbd4 100644 --- a/soh/src/code/z_map_exp.c +++ b/soh/src/code/z_map_exp.c @@ -408,7 +408,7 @@ void Map_InitData(GlobalContext* globalCtx, s16 room) { //gMapData->owMinimapTexSize[mapIndex], "../z_map_exp.c", 309); if (sEntranceIconMapIndex < 24) - memcpy(globalCtx->interfaceCtx.mapSegment, ResourceMgr_LoadTexByName(minimapTableOW[sEntranceIconMapIndex]), gMapData->owMinimapTexSize[mapIndex]); + memcpy(globalCtx->interfaceCtx.mapSegment, minimapTableOW[sEntranceIconMapIndex], strlen(minimapTableOW[sEntranceIconMapIndex]) + 1); interfaceCtx->unk_258 = mapIndex; break; @@ -440,7 +440,7 @@ void Map_InitData(GlobalContext* globalCtx, s16 room) { //((gMapData->dgnMinimapTexIndexOffset[mapIndex] + room) * 0xFF0), //0xFF0, "../z_map_exp.c", 346); - memcpy(globalCtx->interfaceCtx.mapSegment, ResourceMgr_LoadTexByName(minimapTableDangeon[gMapData->dgnMinimapTexIndexOffset[mapIndex] + room]), 0xFF0); + memcpy(globalCtx->interfaceCtx.mapSegment, minimapTableDangeon[gMapData->dgnMinimapTexIndexOffset[mapIndex] + room], strlen(minimapTableDangeon[gMapData->dgnMinimapTexIndexOffset[mapIndex] + room]) + 1); R_COMPASS_OFFSET_X = gMapData->roomCompassOffsetX[mapIndex][room]; R_COMPASS_OFFSET_Y = gMapData->roomCompassOffsetY[mapIndex][room]; diff --git a/soh/src/code/z_message_PAL.c b/soh/src/code/z_message_PAL.c index 8b9410018..898abd974 100644 --- a/soh/src/code/z_message_PAL.c +++ b/soh/src/code/z_message_PAL.c @@ -1531,10 +1531,8 @@ void Message_Decode(GlobalContext* globalCtx) { msgCtx->textboxBackgroundYOffsetIdx = (font->msgBuf[msgCtx->msgBufPos + 3] & 0xF0) >> 4; msgCtx->textboxBackgroundUnkArg = font->msgBuf[msgCtx->msgBufPos + 3] & 0xF; - memcpy((uintptr_t)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE, - ResourceMgr_LoadTexByName(gRedMessageXLeftTex), 0x900); - memcpy((uintptr_t)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE + 0x900, - ResourceMgr_LoadTexByName(gRedMessageXRightTex), 0x900); + memcpy((uintptr_t)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE, gRedMessageXLeftTex, strlen(gRedMessageXLeftTex) + 1); + memcpy((uintptr_t)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE + 0x900, gRedMessageXRightTex, strlen(gRedMessageXRightTex) + 1); msgCtx->msgBufPos += 3; R_TEXTBOX_BG_YPOS = R_TEXTBOX_Y + 8; @@ -1668,7 +1666,7 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) { // "Text Box Type" osSyncPrintf("吹き出し種類=%d\n", msgCtx->textBoxType); if (textBoxType < TEXTBOX_TYPE_NONE_BOTTOM) { - memcpy(msgCtx->textboxSegment, ResourceMgr_LoadTexByName(msgStaticTbl[messageStaticIndices[textBoxType]]), MESSAGE_STATIC_TEX_SIZE); + memcpy(msgCtx->textboxSegment, msgStaticTbl[messageStaticIndices[textBoxType]], strlen(msgStaticTbl[messageStaticIndices[textBoxType]]) + 1); if (textBoxType == TEXTBOX_TYPE_BLACK) { msgCtx->textboxColorRed = 0; msgCtx->textboxColorGreen = 0; diff --git a/soh/src/code/z_parameter.c b/soh/src/code/z_parameter.c index edc4348b9..b46f2ee92 100644 --- a/soh/src/code/z_parameter.c +++ b/soh/src/code/z_parameter.c @@ -2117,8 +2117,7 @@ void Interface_LoadActionLabel(InterfaceContext* interfaceCtx, u16 action, s16 l if (action != DO_ACTION_NONE) { //osCreateMesgQueue(&interfaceCtx->loadQueue, &interfaceCtx->loadMsg, OS_MESG_BLOCK); - memcpy(interfaceCtx->doActionSegment + (loadOffset * DO_ACTION_TEX_SIZE), ResourceMgr_LoadTexByName(doAction), - DO_ACTION_TEX_SIZE); + memcpy(interfaceCtx->doActionSegment + (loadOffset * DO_ACTION_TEX_SIZE), doAction, strlen(doAction) + 1); //DmaMgr_SendRequest2(&interfaceCtx->dmaRequest_160, //interfaceCtx->doActionSegment + (loadOffset * DO_ACTION_TEX_SIZE), //(uintptr_t)_do_action_staticSegmentRomStart + (action * DO_ACTION_TEX_SIZE), DO_ACTION_TEX_SIZE, @@ -2203,7 +2202,7 @@ void Interface_LoadActionLabelB(GlobalContext* globalCtx, u16 action) { // OTRTODO osCreateMesgQueue(&interfaceCtx->loadQueue, &interfaceCtx->loadMsg, OS_MESG_BLOCK); - memcpy(interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE, ResourceMgr_LoadTexByName(doAction), DO_ACTION_TEX_SIZE); + memcpy(interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE, doAction, strlen(doAction) + 1); //DmaMgr_SendRequest2(&interfaceCtx->dmaRequest_160, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE, //(uintptr_t)_do_action_staticSegmentRomStart + (action * DO_ACTION_TEX_SIZE), DO_ACTION_TEX_SIZE, 0, //&interfaceCtx->loadQueue, NULL, "../z_parameter.c", 2228); diff --git a/soh/src/overlays/actors/ovl_En_Mag/z_en_mag.c b/soh/src/overlays/actors/ovl_En_Mag/z_en_mag.c index a7392e14c..0fd4e8268 100644 --- a/soh/src/overlays/actors/ovl_En_Mag/z_en_mag.c +++ b/soh/src/overlays/actors/ovl_En_Mag/z_en_mag.c @@ -539,7 +539,7 @@ void EnMag_DrawImageRGBA32(Gfx** gfxp, s16 centerX, s16 centerY, u8* source, u32 s32 pad; s32 i; - source = ResourceMgr_LoadTexByName(source); + //source = ResourceMgr_LoadTexByName(source); func_80094D28(&gfx); @@ -549,41 +549,21 @@ void EnMag_DrawImageRGBA32(Gfx** gfxp, s16 centerX, s16 centerY, u8* source, u32 textureHeight = 4096 / (width << 2); remainingSize = (width * height) << 2; textureSize = (width * textureHeight) << 2; - textureCount = remainingSize / textureSize; + textureCount = 1; //remainingSize / textureSize; if ((remainingSize % textureSize) != 0) { textureCount += 1; } - gDPSetTileCustom(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_32b, width, textureHeight, 0, G_TX_NOMIRROR | G_TX_CLAMP, + gDPSetTileCustom(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_32b, width, height, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - remainingSize -= textureSize; + gDPSetTextureImage(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_32b, width, curTexture); - for (i = 0; i < textureCount; i++) { - gDPSetTextureImage(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_32b, width, curTexture); + gDPLoadSync(gfx++); + gDPLoadTile(gfx++, G_TX_LOADTILE, 0, 0, (width - 1) << 2, (height - 1) << 2); - gDPLoadSync(gfx++); - gDPLoadTile(gfx++, G_TX_LOADTILE, 0, 0, (width - 1) << 2, (textureHeight - 1) << 2); - - gSPTextureRectangle(gfx++, rectLeft << 2, rectTop << 2, (rectLeft + (s32)width) << 2, - (rectTop + textureHeight) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); - - curTexture += textureSize; - rectTop += textureHeight; - - if ((remainingSize - textureSize) < 0) { - if (remainingSize > 0) { - textureHeight = remainingSize / (s32)(width << 2); - remainingSize -= textureSize; - - gDPSetTileCustom(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_32b, width, textureHeight, 0, - G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, - G_TX_NOLOD, G_TX_NOLOD); - } - } else { - remainingSize -= textureSize; - } - } + gSPTextureRectangle(gfx++, rectLeft << 2, rectTop << 2, (rectLeft + (s32)width) << 2, + (rectTop + height) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); *gfxp = gfx; } diff --git a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c index 60d3595aa..e4ad48a5a 100644 --- a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c +++ b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c @@ -1878,7 +1878,7 @@ void KaleidoScope_UpdateNamePanel(GlobalContext* globalCtx) { sp2A += 12; } - memcpy(pauseCtx->nameSegment, ResourceMgr_LoadTexByName(mapNameTextures[sp2A]), 0x400); + memcpy(pauseCtx->nameSegment, mapNameTextures[sp2A], strlen(mapNameTextures[sp2A]) + 1); } else { osSyncPrintf("zoom_name=%d\n", pauseCtx->namedItem); @@ -1891,7 +1891,7 @@ void KaleidoScope_UpdateNamePanel(GlobalContext* globalCtx) { osSyncPrintf("J_N=%d point=%d\n", gSaveContext.language, sp2A); - memcpy(pauseCtx->nameSegment, ResourceMgr_LoadTexByName(iconNameTextures[sp2A]), 0x400); + memcpy(pauseCtx->nameSegment, iconNameTextures[sp2A], strlen(iconNameTextures[sp2A]) + 1); } pauseCtx->nameDisplayTimer = 0; @@ -2985,7 +2985,10 @@ void KaleidoScope_UpdateCursorSize(PauseContext* pauseCtx) { void KaleidoScope_LoadDungeonMap(GlobalContext* globalCtx) { InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx; - + /* + memcpy(interfaceCtx->mapSegment, sDungeonMapTexs[R_MAP_TEX_INDEX], strlen(sDungeonMapTexs[R_MAP_TEX_INDEX]) + 1); + memcpy(interfaceCtx->mapSegment + 0x800, sDungeonMapTexs[R_MAP_TEX_INDEX + 1], strlen(sDungeonMapTexs[R_MAP_TEX_INDEX + 1]) + 1); + */ memcpy(interfaceCtx->mapSegment, ResourceMgr_LoadTexByName(sDungeonMapTexs[R_MAP_TEX_INDEX]), 0x800); memcpy(interfaceCtx->mapSegment + 0x800, ResourceMgr_LoadTexByName(sDungeonMapTexs[R_MAP_TEX_INDEX + 1]), 0x800); } @@ -3167,7 +3170,7 @@ void KaleidoScope_Update(GlobalContext* globalCtx) if (((void)0, gSaveContext.worldMapArea) < 22) { if (gSaveContext.language == LANGUAGE_ENG) { - memcpy(pauseCtx->nameSegment + 0x400, ResourceMgr_LoadTexByName(mapNameTextures[36 + gSaveContext.worldMapArea]), 0xA00); + memcpy(pauseCtx->nameSegment + 0x400, mapNameTextures[36 + gSaveContext.worldMapArea], strlen(mapNameTextures[36 + gSaveContext.worldMapArea]) + 1); } else if (gSaveContext.language == LANGUAGE_GER) { memcpy(pauseCtx->nameSegment + 0x400, ResourceMgr_LoadTexByName(mapNameTextures[59 + gSaveContext.worldMapArea]), 0xA00); } else {