diff --git a/include/dusk/dvd_asset.hpp b/include/dusk/dvd_asset.hpp index 3c36b75195..014c683d44 100644 --- a/include/dusk/dvd_asset.hpp +++ b/include/dusk/dvd_asset.hpp @@ -10,9 +10,9 @@ namespace dusk { bool LoadDolAsset(void* dst, u32 virtualAddress, s32 size); /** - * Load bytes from a REL file in the ISO filesystem + * Load bytes from a REL file in the ISO filesystem, dst must be 32-byte aligned */ -void* LoadRelAsset(const char* dvdPath, s32 offset, s32 size); +bool LoadRelAsset(void* dst, const char* dvdPath, s32 offset, s32 size); /** * Load bytes from a REL inside RELS.arc diff --git a/src/d/actor/d_a_mant.cpp b/src/d/actor/d_a_mant.cpp index 1760db60fa..bcd7f05986 100644 --- a/src/d/actor/d_a_mant.cpp +++ b/src/d/actor/d_a_mant.cpp @@ -12,9 +12,9 @@ #if TARGET_PC #include "dusk/dvd_asset.hpp" -static u8* l_Egnd_mantTEX_get() { static u8* p = (u8*)dusk::LoadRelAsset("/rel/Final/Release/d_a_mant.rel", 0x1C00, 0x4000); return p; } -static u8* l_Egnd_mantTEX_U_get() { static u8* p = (u8*)dusk::LoadRelAsset("/rel/Final/Release/d_a_mant.rel", 0x5C00, 0x4000); return p; } -static u8* l_Egnd_mantPAL_get() { static u8* p = (u8*)dusk::LoadRelAsset("/rel/Final/Release/d_a_mant.rel", 0x9C00, 0x60); return p; } +static u8* l_Egnd_mantTEX_get() { alignas(32) static u8 buf[0x4000]; static bool _ = (dusk::LoadRelAsset(buf, "/rel/Final/Release/d_a_mant.rel", 0x1C00, 0x4000), true); return buf; } +static u8* l_Egnd_mantTEX_U_get() { alignas(32) static u8 buf[0x4000]; static bool _ = (dusk::LoadRelAsset(buf, "/rel/Final/Release/d_a_mant.rel", 0x5C00, 0x4000), true); return buf; } +static u8* l_Egnd_mantPAL_get() { alignas(32) static u8 buf[0x60]; static bool _ = (dusk::LoadRelAsset(buf, "/rel/Final/Release/d_a_mant.rel", 0x9C00, 0x60), true); return buf; } #define l_Egnd_mantTEX (l_Egnd_mantTEX_get()) #define l_Egnd_mantTEX_U (l_Egnd_mantTEX_U_get()) #define l_Egnd_mantPAL (l_Egnd_mantPAL_get()) @@ -250,7 +250,7 @@ static u32 l_texCoord[338] = { }; #if TARGET_PC -static u8* l_Egnd_mantDL_get() { static u8* p = (u8*)dusk::LoadRelAsset("/rel/Final/Release/d_a_mant.rel", 0xA9A0, 0x3EC); return p; } +static u8* l_Egnd_mantDL_get() { alignas(32) static u8 buf[0x3EC]; static bool _ = (dusk::LoadRelAsset(buf, "/rel/Final/Release/d_a_mant.rel", 0xA9A0, 0x3EC), true); return buf; } #define l_Egnd_mantDL (l_Egnd_mantDL_get()) #else #include "assets/l_Egnd_mantDL.h" diff --git a/src/d/actor/d_flower.inc b/src/d/actor/d_flower.inc index 93a7e35097..de6ac7c1dc 100644 --- a/src/d/actor/d_flower.inc +++ b/src/d/actor/d_flower.inc @@ -619,9 +619,9 @@ void dFlower_packet_c::draw() { } if (sp4C <= 2) { - GXCallDisplayList(&l_matLight4DL, 0x80); + GXCallDisplayList(l_matLight4DL, 0x80); } else { - GXCallDisplayList(&l_matDL, 0x80); + GXCallDisplayList(l_matDL, 0x80); } GXSetTevColorS10(GX_TEVREG0, sp80); @@ -677,9 +677,9 @@ void dFlower_packet_c::draw() { #endif if (!cLib_checkBit(sp44->m_state, 8)) { - GXCallDisplayList(&l_J_hana00DL, 0x140); + GXCallDisplayList(l_J_hana00DL, 0x140); } else { - GXCallDisplayList(&l_J_hana00_cDL, 0xC0); + GXCallDisplayList(l_J_hana00_cDL, 0xC0); } } } @@ -826,7 +826,7 @@ void dFlower_packet_c::draw() { if (!cLib_checkBit(sp34->m_state, 0x10)) { GXCallDisplayList(mp_Jhana01DL, m_Jhana01DL_size); } else { - GXCallDisplayList(&l_J_hana01_c_00DL, 0xC0); + GXCallDisplayList(l_J_hana01_c_00DL, 0xC0); } } else { GXCallDisplayList(mp_Jhana01_cDL, m_Jhana01_cDL_size); diff --git a/src/dusk/dvd_asset.cpp b/src/dusk/dvd_asset.cpp index bfa30cc941..9bcea14077 100644 --- a/src/dusk/dvd_asset.cpp +++ b/src/dusk/dvd_asset.cpp @@ -12,7 +12,22 @@ namespace dusk { static const u8* s_dolData = nullptr; // pointer to dol data static size_t s_dolSize = 0; -struct DolSection { u32 fileOffset, vaddr, size; }; + +struct DolHeader { + BE(u32) textOffset[7]; + BE(u32) dataOffset[11]; + BE(u32) textAddr[7]; + BE(u32) dataAddr[11]; + BE(u32) textSize[7]; + BE(u32) dataSize[11]; +}; + +struct DolSection { + u32 fileOffset; + u32 vaddr; + u32 size; +}; + static DolSection s_dolSections[18]; // 7 text + 11 data static int s_dolSectionCount = 0; @@ -22,25 +37,29 @@ static bool EnsureDolParsed() { s32 sz = 0; const u8* p = aurora_dvd_get_dol(sz); if (!p || sz < 256) { - DuskLog.fatal("dvd_asset: aurora_dvd_get_dol failed (size={})", sz); return false; + DuskLog.fatal("dvd_asset: aurora_dvd_get_dol failed (size={})", sz); + return false; } s_dolData = p; s_dolSize = sz; - const BE(u32)* hdr = (const BE(u32)*)s_dolData; + const auto* hdr = (const DolHeader*)s_dolData; s_dolSectionCount = 0; - // 0x00: text file offsets 0x12: text vaddrs 0x24: text sizes for (int i = 0; i < 7; i++) { - u32 off = hdr[0x00+i], addr = hdr[0x12+i], sz = hdr[0x24+i]; + u32 off = hdr->textOffset[i]; + u32 addr = hdr->textAddr[i]; + u32 sz = hdr->textSize[i]; if (sz > 0 && off > 0) { s_dolSections[s_dolSectionCount++] = {off, addr, sz}; } } - // 0x07: data file offsets 0x19: data vaddrs 0x2B: data sizes + for (int i = 0; i < 11; i++) { - u32 off = hdr[0x07+i], addr = hdr[0x19+i], sz = hdr[0x2B+i]; + u32 off = hdr->dataOffset[i]; + u32 addr = hdr->dataAddr[i]; + u32 sz = hdr->dataSize[i]; if (sz > 0 && off > 0) { s_dolSections[s_dolSectionCount++] = {off, addr, sz}; } @@ -76,10 +95,10 @@ bool LoadDolAsset(void* dst, u32 virtualAddress, s32 size) { return true; } -void* LoadRelAsset(const char* dvdPath, s32 offset, s32 size) { - void* p = JKRDvdRipper::loadToMainRAM(dvdPath, nullptr, EXPAND_SWITCH_UNKNOWN1, (u32)size, nullptr, JKRDvdRipper::ALLOC_DIRECTION_FORWARD, (u32)offset, nullptr, nullptr); +bool LoadRelAsset(void* dst, const char* dvdPath, s32 offset, s32 size) { + void* p = JKRDvdRipper::loadToMainRAM(dvdPath, (u8*)dst, EXPAND_SWITCH_UNKNOWN1, (u32)size, nullptr, JKRDvdRipper::ALLOC_DIRECTION_FORWARD, (u32)offset, nullptr, nullptr); if (!p) DuskLog.fatal("dvd_asset: failed to load {} (offset={:#x} size={:#x})", dvdPath, offset, size); - return p; + return p != nullptr; } bool LoadArchivedRelAsset(void* dst, u32 memType, const char* relFileName, s32 offset, s32 size) {