summaryrefslogtreecommitdiff
path: root/soh/src/code
diff options
context:
space:
mode:
authorGarrett Cox <garrettjcox@gmail.com>2022-10-12 16:20:13 -0500
committerGitHub <noreply@github.com>2022-10-12 17:20:13 -0400
commit41bcad78a3068e8ff8d0bbccb0f2d43967831f69 (patch)
treeecbc6cb5e0d86b091a0f6238e2e1e03e746b2770 /soh/src/code
parent98af2c468cc84a00d055f2fd850cf5a724f61294 (diff)
Support for patching DLists outside of OTR (#1696)
* Support for patching DLists outside of OTR, mostly for cosmetics and bug fixes * Store original dlist instruction for unpatching * Rename sandstorm patch variable * Use unordered map for originalGfx;
Diffstat (limited to 'soh/src/code')
-rw-r--r--soh/src/code/z_kankyo.c34
1 files changed, 13 insertions, 21 deletions
diff --git a/soh/src/code/z_kankyo.c b/soh/src/code/z_kankyo.c
index 540e58a76..b1144d966 100644
--- a/soh/src/code/z_kankyo.c
+++ b/soh/src/code/z_kankyo.c
@@ -2290,27 +2290,22 @@ Color_RGB8 sSandstormEnvColors[] = {
{ 50, 40, 0 },
};
-Gfx* gFieldSandstormDL_Custom = NULL;
+u16 previousPatchedSandstormScreenSize = 0;
void Environment_PatchSandstorm(GlobalContext* globalCtx) {
- if (gFieldSandstormDL_Custom) return;
-
- gFieldSandstormDL_Custom = ResourceMgr_PatchGfxByName(gFieldSandstormDL, -3);
+ if (previousPatchedSandstormScreenSize == ABS(OTRGetRectDimensionFromLeftEdge(0)) + ABS(OTRGetRectDimensionFromRightEdge(SCREEN_WIDTH))) {
+ return;
+ }
- const Gfx gFSPatchDL[2] = { gsSPEndDisplayList() };
- bool patched = false;
- Gfx* cmd = gFieldSandstormDL_Custom;
- int id = 0;
+ Gfx gfxPatchSandstormRect[] = {
+ gsSPWideTextureRectangle(OTRGetRectDimensionFromLeftEdge(0) << 2, 0,
+ OTRGetRectDimensionFromRightEdge(SCREEN_WIDTH) << 2, 0x03C0, G_TX_RENDERTILE, 0, 0, 0x008C, -0x008C),
+ };
+ ResourceMgr_PatchGfxByName(gFieldSandstormDL, "gfxPatchSandstormRect0", 48, gfxPatchSandstormRect[0]);
+ ResourceMgr_PatchGfxByName(gFieldSandstormDL, "gfxPatchSandstormRect1", 50, gfxPatchSandstormRect[1]);
+ ResourceMgr_PatchGfxByName(gFieldSandstormDL, "gfxPatchSandstormRect2", 52, gfxPatchSandstormRect[2]);
- while (!patched) {
- const uint32_t opcode = cmd->words.w0 >> 24;
- if (opcode == G_TEXRECT) {
- gFieldSandstormDL_Custom[id] = gFSPatchDL[0];
- patched = true;
- }
- ++cmd;
- id++;
- }
+ previousPatchedSandstormScreenSize = ABS(OTRGetRectDimensionFromLeftEdge(0)) + ABS(OTRGetRectDimensionFromRightEdge(SCREEN_WIDTH));
}
void Environment_DrawSandstorm(GlobalContext* globalCtx, u8 sandstormState) {
@@ -2435,10 +2430,7 @@ void Environment_DrawSandstorm(GlobalContext* globalCtx, u8 sandstormState) {
0xFFF - ((u32)sp92 % 0x1000), 0x100, 0x40));
gDPSetTextureLUT(POLY_XLU_DISP++, G_TT_NONE);
- gSPDisplayList(POLY_XLU_DISP++, gFieldSandstormDL_Custom);
- gSPWideTextureRectangle(POLY_XLU_DISP++, OTRGetRectDimensionFromLeftEdge(0) << 2, 0,
- OTRGetRectDimensionFromRightEdge(SCREEN_WIDTH) << 2, 0x03C0, G_TX_RENDERTILE, 0, 0, 0x008C,
- -0x008C);
+ gSPDisplayList(POLY_XLU_DISP++, gFieldSandstormDL);
CLOSE_DISPS(globalCtx->state.gfxCtx);
D_8015FDB0 += (s32)sp98;