From 0126d356dac44081d13f423be4388ca7585e5d27 Mon Sep 17 00:00:00 2001 From: octorock <79596758+octorock@users.noreply.github.com> Date: Mon, 3 May 2021 19:02:54 +0200 Subject: [PATCH] Decompile festari --- asm/festari.s | 106 ---------------------------------------------- linker.ld | 1 - src/npc/festari.c | 54 ++++++++++++++++++++++- 3 files changed, 52 insertions(+), 109 deletions(-) delete mode 100644 asm/festari.s diff --git a/asm/festari.s b/asm/festari.s deleted file mode 100644 index ea917d79..00000000 --- a/asm/festari.s +++ /dev/null @@ -1,106 +0,0 @@ - .include "asm/macros.inc" - - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_0805FF2C -sub_0805FF2C: @ 0x0805FF2C - push {r4, r5, r6, lr} - adds r4, r0, #0 - adds r5, r1, #0 - ldr r0, [r5, #8] - ldr r1, _0805FF60 @ =0xFFF00004 - ands r1, r0 - eors r0, r1 - str r0, [r5, #8] - cmp r1, #0 - beq _0805FF94 - movs r6, #0x80 - lsls r6, r6, #0xd - adds r3, r4, #0 - adds r3, #0x80 -_0805FF48: - mvns r0, r1 - adds r2, r0, #1 - ands r2, r1 - eors r1, r2 - cmp r2, r6 - beq _0805FF8C - cmp r2, r6 - bhi _0805FF64 - cmp r2, #4 - beq _0805FF76 - b _0805FF90 - .align 2, 0 -_0805FF60: .4byte 0xFFF00004 -_0805FF64: - movs r0, #0x80 - lsls r0, r0, #0xe - cmp r2, r0 - beq _0805FF7A - movs r0, #0x80 - lsls r0, r0, #0xf - cmp r2, r0 - beq _0805FF7E - b _0805FF90 -_0805FF76: - movs r0, #9 - b _0805FF8E -_0805FF7A: - movs r0, #0xa - b _0805FF8E -_0805FF7E: - ldrb r0, [r4, #0x14] - cmp r0, #2 - bne _0805FF88 - movs r0, #0xb - b _0805FF8E -_0805FF88: - movs r0, #0xc - b _0805FF8E -_0805FF8C: - movs r0, #8 -_0805FF8E: - strh r0, [r3] -_0805FF90: - cmp r1, #0 - bne _0805FF48 -_0805FF94: - adds r0, r4, #0 - adds r1, r5, #0 - bl HandlePostScriptActions - pop {r4, r5, r6, pc} - .align 2, 0 - - thumb_func_start Festari_Fusion -Festari_Fusion: @ 0x0805FFA0 - push {r4, lr} - adds r4, r0, #0 - ldrb r0, [r4, #0xc] - cmp r0, #0 - bne _0805FFCE - adds r0, #1 - strb r0, [r4, #0xc] - ldrb r1, [r4, #0x18] - movs r0, #4 - rsbs r0, r0, #0 - ands r0, r1 - movs r1, #1 - orrs r0, r1 - strb r0, [r4, #0x18] - adds r0, r4, #0 - movs r1, #2 - bl sub_0805E3A0 - adds r0, r4, #0 - movs r1, #8 - bl InitAnimationForceUpdate - b _0805FFD4 -_0805FFCE: - adds r0, r4, #0 - bl UpdateAnimationSingleFrame -_0805FFD4: - pop {r4, pc} - .align 2, 0 diff --git a/linker.ld b/linker.ld index 25da9730..f892a40f 100644 --- a/linker.ld +++ b/linker.ld @@ -551,7 +551,6 @@ SECTIONS { /* npcs */ src/npc/gentari.o(.text); src/npc/festari.o(.text); - asm/festari.o(.text); src/npc/forestMinish.o(.text); src/npc/postman.o(.text); asm/postman.o(.text); diff --git a/src/npc/festari.c b/src/npc/festari.c index e7bb336d..4eeefd09 100644 --- a/src/npc/festari.c +++ b/src/npc/festari.c @@ -5,10 +5,12 @@ #include "player.h" #include "script.h" -extern void sub_0805FF2C(Entity*, void*); +extern void sub_0805FF2C(Entity*, ScriptExecutionContext*); extern void (*const gUnk_08109BBC[])(Entity*); +extern void HandlePostScriptActions(Entity*, ScriptExecutionContext*); + void Festari(Entity* this) { gUnk_08109BBC[this->action](this); } @@ -35,7 +37,7 @@ void sub_0805FE48(Entity* this) { sub_0806F118(this); } else { ExecuteScript(this, *(ScriptExecutionContext**)&this->cutsceneBeh); - sub_0805FF2C(this, *(void**)&this->cutsceneBeh); + sub_0805FF2C(this, *(ScriptExecutionContext**)&this->cutsceneBeh); uVar4 = this->field_0x80.HWORD; if (uVar4 < 8) { if ((this->field_0x82.HWORD & 1) != 0) { @@ -71,3 +73,51 @@ void sub_0805FF18(Entity* this) { this->action = 1; } } + +void sub_0805FF2C(Entity* this, ScriptExecutionContext* context) { + u32 actions; + u32 bit; + + // Handle some postScriptActions already before calling HandlePostScriptActions + actions = context->postScriptActions & 0xfff00004; + context->postScriptActions = context->postScriptActions ^ actions; + if (actions != 0) { + while (actions != 0) { + bit = (~actions + 1) & actions; + actions ^= bit; + switch(bit) { + case 4: + this->field_0x80.HWORD = 9; + break; + + case 0x200000: + this->field_0x80.HWORD = 10; + break; + case 0x400000: + if (this->animationState == 2) { + this->field_0x80.HWORD = 0xb; + } else { + this->field_0x80.HWORD = 0xc; + } + break; + case 0x100000: + this->field_0x80.HWORD = 8; + break; + + } + } + } + HandlePostScriptActions(this, context); +} + + +void Festari_Fusion(Entity* this) { + if (this->action == 0) { + this->action += 1; + this->spriteSettings.b.draw = 1; + sub_0805E3A0(this, 2); + InitAnimationForceUpdate(this, 8); + } else { + UpdateAnimationSingleFrame(this); + } +} \ No newline at end of file