add workaround for single terrain block XML skipping the collision drawing logic collision view

This commit is contained in:
DeaTh-G
2026-02-01 11:33:10 +01:00
parent 0bdf9e6413
commit ea86d8b6c0
3 changed files with 54 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
#include "misc_patches.h"
#include <api/SWA.h>
#include <ui/game_window.h>
#include <user/achievement_manager.h>
@@ -204,3 +205,43 @@ bool StageCollisionDebugViewMidAsmHook(PPCRegister& r27)
return false;
}
// The game is set up so that after parsing the Stage.set.xml it checks if TerrainInfoFile is found or not.
// Based on the result of that it will either draw terrain or debug collision (if enabled).
//
// The XMLs in the game are populated like this generally speaking:
// <Terrain>
// <TerrainInfoFile>terrain</TerrainInfoFile>
// <GIAtlas>1</GIAtlas>
// </Terrain>
// <Terrain>
// <RigidBodyContainer>collision</RigidBodyContainer>
// <IsCollisionRender>false</IsCollisionRender>
// </Terrain>
//
// In some cases however, the information in these two Terrain blocks is combined into one block,
// which makes the logic checking TerrainInfoFile's contents only fire once, and with success only, as such
// the logic for drawing collision will never execute.
//
// To combat this we check if both types returned with some value from the XML file, which indicates that its
// a single Terrain block, and if so we store that information so we can later on re-use to manually fire the
// logic controlling the drawing of the debug collision view.
void StageCollisionDebugViewStoreXmlTypeMidAsmHook(PPCRegister& r1)
{
uint8_t* base = g_memory.base;
const char* rigidBodyContainer = (const char*)(base + PPC_LOAD_U32(r1.u32 + 108));
const char* terrainInfoFile = (const char*)(base + PPC_LOAD_U32(r1.u32 + 132));
if (*rigidBodyContainer != '\0' && *terrainInfoFile != '\0')
{
g_singleTerrainBlockXml = true;
}
}
bool StageCollisionDebugViewSingleTerrainBlockXmlMidAsmHook()
{
bool runCollisionViewDrawLogic = g_singleTerrainBlockXml;
g_singleTerrainBlockXml = false;
return runCollisionViewDrawLogic;
}

View File

@@ -0,0 +1,3 @@
#pragma once
static bool g_singleTerrainBlockXml = false;

View File

@@ -1147,3 +1147,13 @@ name = "StageCollisionDebugViewMidAsmHook"
address = 0x825648F8
registers = ["r27"]
jump_address_on_true = 0x825648FC
[[midasm_hook]]
name = "StageCollisionDebugViewStoreXmlTypeMidAsmHook"
address = 0x8256422C
registers = ["r1"]
[[midasm_hook]]
name = "StageCollisionDebugViewSingleTerrainBlockXmlMidAsmHook"
address = 0x82564B00
jump_address_on_true = 0x82564764