Make stage loading work somewhat

BE & 64-bit support

Most nodes haven't been fixed yet but this at least avoids an immediate crash.
This commit is contained in:
PJB3005
2026-02-26 18:44:40 +01:00
parent c582d01cf7
commit 2ee3dae5d5
2 changed files with 69 additions and 13 deletions
+24
View File
@@ -2282,10 +2282,14 @@ static void dStage_dt_c_offsetToPtr(void* i_data) {
dStage_nodeHeader* p_tno = file->m_nodes;
for (int i = 0; i < file->m_chunkCount; i++) {
#if TARGET_PC
p_tno->m_offset.setBase(i_data);
#else
JUT_ASSERT(3381, p_tno->m_offset != 0);
if (p_tno->m_offset != 0 && p_tno->m_offset < 0x80000000) {
p_tno->m_offset += (uintptr_t)i_data;
}
#endif
p_tno++;
}
}
@@ -2905,3 +2909,23 @@ void dStage_escapeRestart() {
dComIfGp_setNextStage(dComIfGp_getStartStageName(), -2, dComIfGs_getTurnRestartRoomNo(), -1, 0.0f, 0, 0, 9, 0, 1, 0);
}
#endif
#if TARGET_PC
void StageOffsetPtr::setBase(void* base) {
JUT_ASSERT(__LINE__, value != 0);
if (value & 0x8000'0000) {
// Already relocated, don't touch it again!
return;
}
ptrdiff_t diff = (u8*)this - (u8*)base;
ptrdiff_t newDiff = value - diff;
// Check that it's in range given that we use the 31st bit as a flag.
if (newDiff < -0x4000'0000 || newDiff > 0x7FFF'FFFF) {
OSPanic(__FILE__, __LINE__, "Not enough space in StageOffsetPtr!");
}
value = newDiff | 0x8000'0000;
}
#endif