From 44906598e4bd094543eb96a6f2be9fece9c7ece4 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Tue, 4 Apr 2023 03:12:09 -0400 Subject: [PATCH] fix: properly display static background scenes (#2669) --- soh/soh/OTRGlobals.cpp | 5 +++++ soh/soh/OTRGlobals.h | 1 + soh/src/code/z_room.c | 10 ++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 3093557ab..a3a969f67 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1056,6 +1056,11 @@ extern "C" char* ResourceMgr_LoadFileFromDisk(const char* filePath) { return data; } +extern "C" uint8_t ResourceMgr_ResourceIsBackground(char* texPath) { + auto res = GetResourceByNameHandlingMQ(texPath); + return res->InitData->Type == Ship::ResourceType::SOH_Background; +} + extern "C" char* ResourceMgr_LoadJPEG(char* data, int dataSize) { static char* finalBuffer = 0; diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index c77d6f56e..830d4f9e3 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -63,6 +63,7 @@ char** ResourceMgr_ListFiles(const char* searchMask, int* resultSize); char* GetResourceDataByNameHandlingMQ(const char* path); void ResourceMgr_LoadFile(const char* resName); char* ResourceMgr_LoadFileFromDisk(const char* filePath); +uint8_t ResourceMgr_ResourceIsBackground(char* texPath); char* ResourceMgr_LoadJPEG(char* data, int dataSize); uint16_t ResourceMgr_LoadTexWidthByName(char* texPath); uint16_t ResourceMgr_LoadTexHeightByName(char* texPath); diff --git a/soh/src/code/z_room.c b/soh/src/code/z_room.c index 59dea1ab3..d10a5089e 100644 --- a/soh/src/code/z_room.c +++ b/soh/src/code/z_room.c @@ -220,7 +220,7 @@ void func_80095D04(PlayState* play, Room* room, u32 flags) { #define JPEG_MARKER 0xFFD8FFE0 -s32 func_80096238(void* data) { +s32 swapAndConvertJPEG(void* data) { OSTime time; if (BE32SWAP(*(u32*)data) == JPEG_MARKER) @@ -265,7 +265,7 @@ void func_8009638C(Gfx** displayList, void* source, void* tlut, u16 width, u16 h s32 temp; displayListHead = *displayList; - func_80096238(SEGMENTED_TO_VIRTUAL(source)); + swapAndConvertJPEG(SEGMENTED_TO_VIRTUAL(source)); bg = (uObjBg*)(displayListHead + 1); gSPBranchList(displayListHead, (u8*)bg + sizeof(uObjBg)); @@ -282,6 +282,12 @@ void func_8009638C(Gfx** displayList, void* source, void* tlut, u16 width, u16 h bg->b.imagePal = 0; bg->b.imageFlip = 0; + if (ResourceMgr_ResourceIsBackground((char*) source)) { + char* blob = (char*) GetResourceDataByName((char*) source, true); + swapAndConvertJPEG(blob); + bg->b.imagePtr = (uintptr_t) blob; + } + displayListHead = (void*)(bg + 1); if (fmt == G_IM_FMT_CI) { gDPLoadTLUT(displayListHead++, tlutCount, 256, tlut);