From b3c4114a9374f3e5cbac4d4f40381318746212f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Na=C5=9Bciszewski?= Date: Tue, 23 Jul 2024 00:58:26 +0200 Subject: [PATCH] Less hacky mismatched declaration, plus removal of unneeded union --- include/code_80A26CC.h | 5 +++++ include/ground_main.h | 10 ++++++++++ src/ground_script_1.c | 28 ++++++++-------------------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/include/code_80A26CC.h b/include/code_80A26CC.h index b01fbeb6d..6d3c4e7a1 100644 --- a/include/code_80A26CC.h +++ b/include/code_80A26CC.h @@ -23,7 +23,12 @@ void sub_80A2558(s32, s16 *); void sub_80A2584(s16, s16); void sub_80A2598(s16, s16); u32 sub_80A25AC(u16); +#if !defined(NONMATCHING) && defined(GROUND_SCRIPT_INCOMPLETE_DECLARATIONS) +// Workaround for ExecuteScriptCommand relying on s32 behavior of arguments +const DungeonInfo *sub_80A2608(s32 index); +#else const DungeonInfo *sub_80A2608(s16 index); +#endif const DungeonInfo *sub_80A2620(s16 index); s16 sub_80A2654(s16 index); s16 sub_80A2668(u32); diff --git a/include/ground_main.h b/include/ground_main.h index c9ff64a27..432b7c2ac 100644 --- a/include/ground_main.h +++ b/include/ground_main.h @@ -13,8 +13,18 @@ typedef struct GroundConversionStruct bool8 sub_8098F88(void); const char *sub_8098FB4(void); + +#if !defined(NONMATCHING) && defined(GROUND_SCRIPT_INCOMPLETE_DECLARATIONS) +// Workaround for ExecuteScriptCommand relying on s32 behavior of arguments +// Arguments could be left fully implicit (as I think they were in the original code), +// but this way at least verifies the argument count +bool8 GroundMainGroundRequest(s32 r0, s32 r1, s32 r2); +bool8 GroundMainRescueRequest(s32 r0, s32 r1); +#else bool8 GroundMainGroundRequest(s16 r0, u32 r1, s32 r2); bool8 GroundMainRescueRequest(s16 r0, u32 r1); +#endif + bool32 GroundMainGameEndRequest(u32 r0); bool32 GroundMainGameCancelRequest(u32 r0); diff --git a/src/ground_script_1.c b/src/ground_script_1.c index 67752d0cf..db1bebda2 100644 --- a/src/ground_script_1.c +++ b/src/ground_script_1.c @@ -4,20 +4,12 @@ #include "ground_map.h" #include "dungeon.h" -// Needs incorrect redeclaration -#define GroundMainGroundRequest jaksdlasjdklajksdklajsd -#define GroundMainRescueRequest pudmvjhieasmlzgvouh -#include "ground_main.h" -#undef GroundMainGroundRequest -#undef GroundMainRescueRequest -bool8 GroundMainGroundRequest(s32 r0, u32 r1, s32 r2); -bool8 GroundMainRescueRequest(s32 r0, u32 r1); +#ifndef NONMATCHING +#define GROUND_SCRIPT_INCOMPLETE_DECLARATIONS +#endif -// Needs incorrect redeclaration -#define sub_80A2608 vpoiuj345nmoszuozgvdyhz +#include "ground_main.h" #include "code_80A26CC.h" -#undef sub_80A2608 -const DungeonInfo *sub_80A2608(s32 index); typedef struct { u8 xTiles; @@ -25,16 +17,12 @@ typedef struct { u8 yTiles; u8 yFlags; } PosInfo; -typedef union { - u32 raw; - PosInfo fields; -} UPos; typedef struct GroundObjectData { u8 kind; u8 unk1; u8 widthTiles; u8 heightTiles; - UPos pos; + PosInfo pos; ScriptCommand *scripts[4]; // 2 - dialogue script } GroundObjectData; typedef struct GroundEffectData { @@ -42,7 +30,7 @@ typedef struct GroundEffectData { u8 unk1; u8 widthTiles; //??? u8 heightTiles; - UPos pos; + PosInfo pos; ScriptCommand *script; } GroundEffectData; @@ -466,7 +454,7 @@ s32 ExecuteScriptCommand(Action *action) { .unk1 = *unk, .widthTiles = 1, .heightTiles = 1, - .pos = {.raw = 0}, + .pos = {}, .kind = curCmd.arg2, .scripts = { [3] = gFunctionScriptTable[curCmd.arg1].script }, }; @@ -493,7 +481,7 @@ s32 ExecuteScriptCommand(Action *action) { .unk1 = unk, .widthTiles = 1, .heightTiles = 1, - .pos = {.raw = 0}, + .pos = {}, .kind = curCmd.arg2, .script = gFunctionScriptTable[curCmd.arg1].script, };