Skip to content

Commit 642179d

Browse files
committed
add workaround for single terrain block XML skipping the collision drawing logic collision view
1 parent 0bdf9e6 commit 642179d

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

UnleashedRecomp/patches/misc_patches.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "misc_patches.h"
12
#include <api/SWA.h>
23
#include <ui/game_window.h>
34
#include <user/achievement_manager.h>
@@ -204,3 +205,43 @@ bool StageCollisionDebugViewMidAsmHook(PPCRegister& r27)
204205

205206
return false;
206207
}
208+
209+
// The game is set up so that after parsing the Stage.set.xml it checks if TerrainInfoFile is found or not.
210+
// Based on the result of that it will either draw terrain or debug collision (if enabled).
211+
//
212+
// The XMLs in the game are populated like this generally speaking:
213+
// <Terrain>
214+
// <TerrainInfoFile>terrain</TerrainInfoFile>
215+
// <GIAtlas>1</GIAtlas>
216+
// </Terrain>
217+
// <Terrain>
218+
// <RigidBodyContainer>collision</RigidBodyContainer>
219+
// <IsCollisionRender>false</IsCollisionRender>
220+
// </Terrain>
221+
//
222+
// In some cases however, the information in these two Terrain blocks however combined into one block,
223+
// which makes the logic checking TerrainInfoFile's contents only fire once, and with success only, as such
224+
// the logic for drawing collision will never execute.
225+
//
226+
// To combat this we check if both types returned with some value from the XML file, which indicates that its
227+
// a single Terrain block, and if so we store that information so we can later on re-use to manually fire the
228+
// logic controlling the drawing of the debug collision view.
229+
void StageCollisionDebugViewStoreXmlTypeMidAsmHook(PPCRegister& r1)
230+
{
231+
uint8_t* base = g_memory.base;
232+
233+
const char* rigidBodyContainer = (const char*)(base + PPC_LOAD_U32(r1.u32 + 108));
234+
const char* terrainInfoFile = (const char*)(base + PPC_LOAD_U32(r1.u32 + 132));
235+
if (*rigidBodyContainer != '\0' && *terrainInfoFile != '\0')
236+
{
237+
g_singleTerrainBlockXml = true;
238+
}
239+
}
240+
241+
bool StageCollisionDebugViewSingleTerrainBlockXmlMidAsmHook()
242+
{
243+
bool runCollisionViewDrawLogic = g_singleTerrainBlockXml;
244+
g_singleTerrainBlockXml = false;
245+
246+
return runCollisionViewDrawLogic;
247+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
static bool g_singleTerrainBlockXml = false;

UnleashedRecompLib/config/SWA.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,3 +1147,13 @@ name = "StageCollisionDebugViewMidAsmHook"
11471147
address = 0x825648F8
11481148
registers = ["r27"]
11491149
jump_address_on_true = 0x825648FC
1150+
1151+
[[midasm_hook]]
1152+
name = "StageCollisionDebugViewStoreXmlTypeMidAsmHook"
1153+
address = 0x8256422C
1154+
registers = ["r1"]
1155+
1156+
[[midasm_hook]]
1157+
name = "StageCollisionDebugViewSingleTerrainBlockXmlMidAsmHook"
1158+
address = 0x82564B00
1159+
jump_address_on_true = 0x82564764

0 commit comments

Comments
 (0)