From 0b0daa5c46b44a5baa5f4e61554965ab24312e95 Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 23 Apr 2022 19:26:43 -0400 Subject: [PATCH 1/4] Make NKEY actor drop sword instead of key --- base/src/main.asm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/base/src/main.asm b/base/src/main.asm index 6599ad70..98bfac43 100644 --- a/base/src/main.asm +++ b/base/src/main.asm @@ -217,6 +217,15 @@ .close +.open "../overlay/overlay_0035.bin", 0x0215b400 + .arm + .org 0x2160760 + .area 0x4, 0xff + mov r0, 0x3 ; make NKEY drop sword + .endarea +.close + + .open "../overlay/overlay_0037.bin", 0x0215b400 .arm .org 0x216278c From 222077259384ac6eee05037c27c4520976fe0806 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 25 Apr 2022 00:32:20 -0400 Subject: [PATCH 2/4] Support spawning custom items (with models) for EGTI/NKEY actor --- base/src/get_npc_model_offset.c | 16 +++++++++ base/src/main.asm | 42 +++++++++++++++++++++-- base/src/spawn_custom_freestanding_item.c | 25 +++++++------- 3 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 base/src/get_npc_model_offset.c diff --git a/base/src/get_npc_model_offset.c b/base/src/get_npc_model_offset.c new file mode 100644 index 00000000..0ffab603 --- /dev/null +++ b/base/src/get_npc_model_offset.c @@ -0,0 +1,16 @@ +#include + +uint32_t get_npc_model_offset(uint32_t item_id) { + // These values are offsets that are used to calculate the char* that contains + // the name of the .bin + // file (see: Npc/ directory in the rom) of the NPC being spawned. The exact + // way it is used is: + // char *npc = 20ddf40 + ( * 0xC) + switch (item_id) { + case 0x1: // key + return 0xC; + case 0x3: // oshus sword + return 0xE3; + } + // TODO: calculate values for rest of items +} diff --git a/base/src/main.asm b/base/src/main.asm index 98bfac43..f4a49796 100644 --- a/base/src/main.asm +++ b/base/src/main.asm @@ -13,7 +13,43 @@ .importobj "src/faster_boat.o" .importobj "src/fixed_random_treasure_in_shop.o" .importobj "src/progressive_sword_check.o" + .importobj "src/get_npc_model_offset.o" .include "_island_shop_files.asm" + + @spawn_custom_item_with_nkey: + ldr r0, =0x21608a8 + ldr r0, [r0] + ldr r0, [r0] + add r0, r0, 0x2a0 + + ; Dynamically determine pointer to string of + ; nsbmd/nsbtx model. + push r0, r1, r4, r5 + mov r5, r0 + ldr r0, [r4, 0x20] + bl get_npc_model_offset + str r0, [r5, 0x10] + pop r0, r1, r4, r5 + mov r1, 0x0 + str r1, [r0] + bl 0x20c4528 + + mov r1, r0 + add r0, r4, 0x158 + ldr r2, [r0] + ldr r2, [r2, 0xc] + blx r2 + + ; Note, this instruction differs from the original code. + ; Instead of a `mov r0, 0x1` (i.e. always setting the item id + ; to 0x1 for a small key), we're loading the item id dynamically + ; from the value given in the ITGE actor in the ZMB. See + ; `spawn_custom_freestanding_item.c` for more info. + ldr r0, [r4, 0x20] + + str r0, [r4, 0x1b4] + b 0x2160798 + .endarea .org 0x54894 + 0x2004000 @@ -219,9 +255,9 @@ .open "../overlay/overlay_0035.bin", 0x0215b400 .arm - .org 0x2160760 - .area 0x4, 0xff - mov r0, 0x3 ; make NKEY drop sword + .org 0x216072c + .area 0x24, 0x00 + beq @spawn_custom_item_with_nkey .endarea .close diff --git a/base/src/spawn_custom_freestanding_item.c b/base/src/spawn_custom_freestanding_item.c index 0823228b..221a77c3 100644 --- a/base/src/spawn_custom_freestanding_item.c +++ b/base/src/spawn_custom_freestanding_item.c @@ -2,6 +2,16 @@ #define RUPY 0x52555059 +static uint16_t get_item_id() { + uint16_t *item_id_address; + // Pull the base address of the NPCA entry's item_id off of the stack. + // This value is set in the NPCA section of the + // ZMB file in byte 0xC of an ITGE actor. + asm volatile("ldr %0, [sp, #0x4]" : "=r"(item_id_address) :); + // return the item id + return item_id_address[0x10]; +} + /** * @param param_1 - original function arg, don't modify * @param npc_type - 4 character string representing NPC type. @@ -14,19 +24,8 @@ uint16_t spawn_custom_freestanding_item(void *param_1, uint32_t npc_type, uint16_t (*spawn_npc)(void *, uint32_t, void *, uint16_t *) = (void *)0x20C3FE8; - uint16_t *item_id_address; - // pull the base address of the NPCA entry's item_id off of the stack - asm volatile("ldr %0, [sp, #0x4]" : "=r"(item_id_address) :); - - // get the item id - uint16_t item_id = item_id_address[0x10]; + uint16_t item_id = get_item_id(); - // if item_id is 0x1, continue as the vanilla game does. - if (item_id == 0x1) { - return (*spawn_npc)(param_1, npc_type, param_3, param_4); - } - // Otherwise, set rupy_type to the item_id and spawn a RUPY NPC: - // (see `extend_RUPY_npc.c` to see how this value is used) *param_4 = item_id; - return (*spawn_npc)(param_1, RUPY, param_3, param_4); + return (*spawn_npc)(param_1, npc_type, param_3, param_4); } From 30eab193841d8e99f2249db18d5ddd7e88e112c4 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 29 May 2022 22:29:07 -0400 Subject: [PATCH 3/4] Fix alignment error --- base/src/main.asm | 1 + 1 file changed, 1 insertion(+) diff --git a/base/src/main.asm b/base/src/main.asm index f4a49796..ec14794d 100644 --- a/base/src/main.asm +++ b/base/src/main.asm @@ -16,6 +16,7 @@ .importobj "src/get_npc_model_offset.o" .include "_island_shop_files.asm" + .align @spawn_custom_item_with_nkey: ldr r0, =0x21608a8 ldr r0, [r0] From 0638851252f2d2f2016f4f76a687c8185de5af1b Mon Sep 17 00:00:00 2001 From: Mike <91105575+mike8699@users.noreply.github.com> Date: Sun, 7 Aug 2022 14:22:47 -0400 Subject: [PATCH 4/4] Add configuration for pre-commit ci --- .pre-commit-config.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8a913e05..932cc72a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -77,3 +77,15 @@ repos: rev: v14.0.6 hooks: - id: clang-format + +ci: + autofix_commit_msg: | + [pre-commit.ci] auto fixes from pre-commit.com hooks + + for more information, see https://pre-commit.ci + autofix_prs: true + autoupdate_branch: '' + autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate' + autoupdate_schedule: weekly + skip: [] + submodules: false