From efe792b81cfaf37003190795f862669b0610f80f Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 5 Feb 2022 23:39:23 -0500 Subject: [PATCH] Override npc spawn function This doesn't change how the function works; essentially it just relocates it somewhere else so we have the ability to make changes/extend it. --- base/src/execute_npc_spawner.c | 10 ++++++++++ base/src/main.asm | 8 ++++++++ base/src/ph.asm | 1 + base/src/ph.h | 13 +++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 base/src/execute_npc_spawner.c create mode 100644 base/src/ph.asm create mode 100644 base/src/ph.h diff --git a/base/src/execute_npc_spawner.c b/base/src/execute_npc_spawner.c new file mode 100644 index 00000000..e934bd67 --- /dev/null +++ b/base/src/execute_npc_spawner.c @@ -0,0 +1,10 @@ +#include "ph.h" +#include + +uint32_t execute_npc_spawner(void *param_1, uint32_t npc_id) { + NPC *npc = get_npc_address(npc_id); + if (npc != 0x0) { + return npc->spawn_function(); + } + return 0; +} diff --git a/base/src/main.asm b/base/src/main.asm index 23405d3e..f8afb7b4 100644 --- a/base/src/main.asm +++ b/base/src/main.asm @@ -2,6 +2,8 @@ .relativeinclude on .erroronwarning on +.include "ph.asm" + .open "../arm9_original.bin","../arm9_compressed.bin",0x02004000 .arm .org 0x54894 + 0x2004000 @@ -10,6 +12,7 @@ .importobj "src/set_initial_flags.o" // .importobj "src/faster_boat.o" .importobj "src/spawn_custom_freestanding_item.o" + .importobj "src/execute_npc_spawner.o" @init_flags: sub r0, lr, 0x30 ; set_initial_flags() function parameter @@ -51,6 +54,11 @@ .area 0x4 b @init_flags .endarea + + .org 0x20c402c + .area 0x4 + bl execute_npc_spawner + .endarea .close diff --git a/base/src/ph.asm b/base/src/ph.asm new file mode 100644 index 00000000..6763ffde --- /dev/null +++ b/base/src/ph.asm @@ -0,0 +1 @@ +.definelabel get_npc_address, 0x203e824 diff --git a/base/src/ph.h b/base/src/ph.h new file mode 100644 index 00000000..4e200f1d --- /dev/null +++ b/base/src/ph.h @@ -0,0 +1,13 @@ +#include + +typedef struct { + uint32_t npc_id; + uint32_t (*spawn_function)(void); + uint32_t unknown1; + uint32_t unknown2; + struct NPC *next; +} NPC; + +// searches the list of NPC structs in memory for the given NPC and returns its +// address. +extern NPC *get_npc_address(uint32_t npc_id); // 203e824