From 6bd5f8dae46f6ab99aa9f20e02b933f43d534353 Mon Sep 17 00:00:00 2001 From: Ethan Roseman Date: Sun, 27 Dec 2020 23:23:36 +0900 Subject: [PATCH] 4 funcz --- .../code_1A5830/dispatch_event_general.s | 39 ---------------- asm/nonmatchings/code_1A5830/func_8027CC10.s | 46 ------------------- .../code_f2470_len_27f0/set_npc_animation.s | 44 ------------------ .../code_fa4c0_len_3bf0/func_802D5EE0.s | 22 --------- include/common_structs.h | 23 ++++++---- src/code_1A5830.c | 46 +++++++++++++++---- src/code_f2470_len_27f0.c | 27 +++++++---- src/code_fa4c0_len_3bf0.c | 7 ++- 8 files changed, 75 insertions(+), 179 deletions(-) delete mode 100644 asm/nonmatchings/code_1A5830/dispatch_event_general.s delete mode 100644 asm/nonmatchings/code_1A5830/func_8027CC10.s delete mode 100644 asm/nonmatchings/code_f2470_len_27f0/set_npc_animation.s delete mode 100644 asm/nonmatchings/code_fa4c0_len_3bf0/func_802D5EE0.s diff --git a/asm/nonmatchings/code_1A5830/dispatch_event_general.s b/asm/nonmatchings/code_1A5830/dispatch_event_general.s deleted file mode 100644 index 1cf3fcf4ca..0000000000 --- a/asm/nonmatchings/code_1A5830/dispatch_event_general.s +++ /dev/null @@ -1,39 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel dispatch_event_general -/* 1A586C 80276F8C 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 1A5870 80276F90 AFBF0010 */ sw $ra, 0x10($sp) -/* 1A5874 80276F94 94820192 */ lhu $v0, 0x192($a0) -/* 1A5878 80276F98 30430700 */ andi $v1, $v0, 0x700 -/* 1A587C 80276F9C 24020100 */ addiu $v0, $zero, 0x100 -/* 1A5880 80276FA0 1062000F */ beq $v1, $v0, .L80276FE0 -/* 1A5884 80276FA4 28620101 */ slti $v0, $v1, 0x101 -/* 1A5888 80276FA8 50400005 */ beql $v0, $zero, .L80276FC0 -/* 1A588C 80276FAC 24020200 */ addiu $v0, $zero, 0x200 -/* 1A5890 80276FB0 10600007 */ beqz $v1, .L80276FD0 -/* 1A5894 80276FB4 00000000 */ nop -/* 1A5898 80276FB8 0809DBFE */ j .L80276FF8 -/* 1A589C 80276FBC 00000000 */ nop -.L80276FC0: -/* 1A58A0 80276FC0 1062000B */ beq $v1, $v0, .L80276FF0 -/* 1A58A4 80276FC4 00000000 */ nop -/* 1A58A8 80276FC8 0809DBFE */ j .L80276FF8 -/* 1A58AC 80276FCC 00000000 */ nop -.L80276FD0: -/* 1A58B0 80276FD0 0C09C596 */ jal dispatch_event_player -/* 1A58B4 80276FD4 00A0202D */ daddu $a0, $a1, $zero -/* 1A58B8 80276FD8 0809DBFE */ j .L80276FF8 -/* 1A58BC 80276FDC 00000000 */ nop -.L80276FE0: -/* 1A58C0 80276FE0 0C09F7A0 */ jal dispatch_event_partner -/* 1A58C4 80276FE4 00A0202D */ daddu $a0, $a1, $zero -/* 1A58C8 80276FE8 0809DBFE */ j .L80276FF8 -/* 1A58CC 80276FEC 00000000 */ nop -.L80276FF0: -/* 1A58D0 80276FF0 0C09DC58 */ jal dispatch_event_actor -/* 1A58D4 80276FF4 00000000 */ nop -.L80276FF8: -/* 1A58D8 80276FF8 8FBF0010 */ lw $ra, 0x10($sp) -/* 1A58DC 80276FFC 03E00008 */ jr $ra -/* 1A58E0 80277000 27BD0018 */ addiu $sp, $sp, 0x18 diff --git a/asm/nonmatchings/code_1A5830/func_8027CC10.s b/asm/nonmatchings/code_1A5830/func_8027CC10.s deleted file mode 100644 index 4022d1b92b..0000000000 --- a/asm/nonmatchings/code_1A5830/func_8027CC10.s +++ /dev/null @@ -1,46 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel func_8027CC10 -/* 1AB4F0 8027CC10 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 1AB4F4 8027CC14 AFB3001C */ sw $s3, 0x1c($sp) -/* 1AB4F8 8027CC18 0080982D */ daddu $s3, $a0, $zero -/* 1AB4FC 8027CC1C AFBF0020 */ sw $ra, 0x20($sp) -/* 1AB500 8027CC20 AFB20018 */ sw $s2, 0x18($sp) -/* 1AB504 8027CC24 AFB10014 */ sw $s1, 0x14($sp) -/* 1AB508 8027CC28 AFB00010 */ sw $s0, 0x10($sp) -/* 1AB50C 8027CC2C 8E71000C */ lw $s1, 0xc($s3) -/* 1AB510 8027CC30 8E250000 */ lw $a1, ($s1) -/* 1AB514 8027CC34 0C0B1EAF */ jal get_variable -/* 1AB518 8027CC38 26310004 */ addiu $s1, $s1, 4 -/* 1AB51C 8027CC3C 0040902D */ daddu $s2, $v0, $zero -/* 1AB520 8027CC40 2402FF81 */ addiu $v0, $zero, -0x7f -/* 1AB524 8027CC44 16420002 */ bne $s2, $v0, .L8027CC50 -/* 1AB528 8027CC48 00000000 */ nop -/* 1AB52C 8027CC4C 8E720148 */ lw $s2, 0x148($s3) -.L8027CC50: -/* 1AB530 8027CC50 8E250000 */ lw $a1, ($s1) -/* 1AB534 8027CC54 26310004 */ addiu $s1, $s1, 4 -/* 1AB538 8027CC58 0C0B1EAF */ jal get_variable -/* 1AB53C 8027CC5C 0260202D */ daddu $a0, $s3, $zero -/* 1AB540 8027CC60 8E250000 */ lw $a1, ($s1) -/* 1AB544 8027CC64 26310004 */ addiu $s1, $s1, 4 -/* 1AB548 8027CC68 0260202D */ daddu $a0, $s3, $zero -/* 1AB54C 8027CC6C 0C0B1EAF */ jal get_variable -/* 1AB550 8027CC70 0040802D */ daddu $s0, $v0, $zero -/* 1AB554 8027CC74 8E250000 */ lw $a1, ($s1) -/* 1AB558 8027CC78 0C0B1EAF */ jal get_variable -/* 1AB55C 8027CC7C 0260202D */ daddu $a0, $s3, $zero -/* 1AB560 8027CC80 0C09A75B */ jal get_actor -/* 1AB564 8027CC84 0240202D */ daddu $a0, $s2, $zero -/* 1AB568 8027CC88 0040202D */ daddu $a0, $v0, $zero -/* 1AB56C 8027CC8C 0C099117 */ jal get_actor_part -/* 1AB570 8027CC90 0200282D */ daddu $a1, $s0, $zero -/* 1AB574 8027CC94 8FBF0020 */ lw $ra, 0x20($sp) -/* 1AB578 8027CC98 8FB3001C */ lw $s3, 0x1c($sp) -/* 1AB57C 8027CC9C 8FB20018 */ lw $s2, 0x18($sp) -/* 1AB580 8027CCA0 8FB10014 */ lw $s1, 0x14($sp) -/* 1AB584 8027CCA4 8FB00010 */ lw $s0, 0x10($sp) -/* 1AB588 8027CCA8 24020002 */ addiu $v0, $zero, 2 -/* 1AB58C 8027CCAC 03E00008 */ jr $ra -/* 1AB590 8027CCB0 27BD0028 */ addiu $sp, $sp, 0x28 diff --git a/asm/nonmatchings/code_f2470_len_27f0/set_npc_animation.s b/asm/nonmatchings/code_f2470_len_27f0/set_npc_animation.s deleted file mode 100644 index 41013a8ad2..0000000000 --- a/asm/nonmatchings/code_f2470_len_27f0/set_npc_animation.s +++ /dev/null @@ -1,44 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel set_npc_animation -/* F24BC 802CDB0C 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* F24C0 802CDB10 AFB10014 */ sw $s1, 0x14($sp) -/* F24C4 802CDB14 0080882D */ daddu $s1, $a0, $zero -/* F24C8 802CDB18 AFB00010 */ sw $s0, 0x10($sp) -/* F24CC 802CDB1C 00A0802D */ daddu $s0, $a1, $zero -/* F24D0 802CDB20 2604FEFF */ addiu $a0, $s0, -0x101 -/* F24D4 802CDB24 2C820009 */ sltiu $v0, $a0, 9 -/* F24D8 802CDB28 1040000D */ beqz $v0, .L802CDB60 -/* F24DC 802CDB2C AFBF0018 */ sw $ra, 0x18($sp) -/* F24E0 802CDB30 3C028011 */ lui $v0, %hi(gPlayerData) -/* F24E4 802CDB34 2442F290 */ addiu $v0, $v0, %lo(gPlayerData) -/* F24E8 802CDB38 80430012 */ lb $v1, 0x12($v0) -/* F24EC 802CDB3C 000310C0 */ sll $v0, $v1, 3 -/* F24F0 802CDB40 00431021 */ addu $v0, $v0, $v1 -/* F24F4 802CDB44 00441021 */ addu $v0, $v0, $a0 -/* F24F8 802CDB48 00021080 */ sll $v0, $v0, 2 -/* F24FC 802CDB4C 3C018010 */ lui $at, %hi(gPartnerAnimations) -/* F2500 802CDB50 00220821 */ addu $at, $at, $v0 -/* F2504 802CDB54 8C228348 */ lw $v0, %lo(gPartnerAnimations)($at) -/* F2508 802CDB58 080B36E4 */ j .L802CDB90 -/* F250C 802CDB5C AE220028 */ sw $v0, 0x28($s1) -.L802CDB60: -/* F2510 802CDB60 2602FDFF */ addiu $v0, $s0, -0x201 -/* F2514 802CDB64 2C420010 */ sltiu $v0, $v0, 0x10 -/* F2518 802CDB68 50400009 */ beql $v0, $zero, .L802CDB90 -/* F251C 802CDB6C AE300028 */ sw $s0, 0x28($s1) -/* F2520 802CDB70 822400A4 */ lb $a0, 0xa4($s1) -/* F2524 802CDB74 0C00FB3A */ jal get_enemy -/* F2528 802CDB78 00000000 */ nop -/* F252C 802CDB7C 8C4200CC */ lw $v0, 0xcc($v0) -/* F2530 802CDB80 00101880 */ sll $v1, $s0, 2 -/* F2534 802CDB84 00621821 */ addu $v1, $v1, $v0 -/* F2538 802CDB88 8C62F7FC */ lw $v0, -0x804($v1) -/* F253C 802CDB8C AE220028 */ sw $v0, 0x28($s1) -.L802CDB90: -/* F2540 802CDB90 8FBF0018 */ lw $ra, 0x18($sp) -/* F2544 802CDB94 8FB10014 */ lw $s1, 0x14($sp) -/* F2548 802CDB98 8FB00010 */ lw $s0, 0x10($sp) -/* F254C 802CDB9C 03E00008 */ jr $ra -/* F2550 802CDBA0 27BD0020 */ addiu $sp, $sp, 0x20 diff --git a/asm/nonmatchings/code_fa4c0_len_3bf0/func_802D5EE0.s b/asm/nonmatchings/code_fa4c0_len_3bf0/func_802D5EE0.s deleted file mode 100644 index 552becea95..0000000000 --- a/asm/nonmatchings/code_fa4c0_len_3bf0/func_802D5EE0.s +++ /dev/null @@ -1,22 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel func_802D5EE0 -/* FA890 802D5EE0 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* FA894 802D5EE4 AFBF0010 */ sw $ra, 0x10($sp) -/* FA898 802D5EE8 8C82000C */ lw $v0, 0xc($a0) -/* FA89C 802D5EEC 0C0B1EAF */ jal get_variable -/* FA8A0 802D5EF0 8C450000 */ lw $a1, ($v0) -/* FA8A4 802D5EF4 3C048016 */ lui $a0, %hi(gMusicPlayers) -/* FA8A8 802D5EF8 24849AF0 */ addiu $a0, $a0, %lo(gMusicPlayers) -/* FA8AC 802D5EFC 00021840 */ sll $v1, $v0, 1 -/* FA8B0 802D5F00 00621821 */ addu $v1, $v1, $v0 -/* FA8B4 802D5F04 00031900 */ sll $v1, $v1, 4 -/* FA8B8 802D5F08 00641821 */ addu $v1, $v1, $a0 -/* FA8BC 802D5F0C 94640000 */ lhu $a0, ($v1) -/* FA8C0 802D5F10 24020002 */ addiu $v0, $zero, 2 -/* FA8C4 802D5F14 00822025 */ or $a0, $a0, $v0 -/* FA8C8 802D5F18 A4640000 */ sh $a0, ($v1) -/* FA8CC 802D5F1C 8FBF0010 */ lw $ra, 0x10($sp) -/* FA8D0 802D5F20 03E00008 */ jr $ra -/* FA8D4 802D5F24 27BD0018 */ addiu $sp, $sp, 0x18 diff --git a/include/common_structs.h b/include/common_structs.h index f53b71e623..0728737f40 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -117,7 +117,7 @@ typedef struct Npc { /* 0x090 */ Vec3s homePos; /* 0x096 */ char unk_96[12]; /* 0x0A2 */ u16 unk_A2; - /* 0x0A4 */ u8 npcID; + /* 0x0A4 */ s8 npcID; /* 0x0A5 */ char unk_A5; /* 0x0A6 */ s16 collisionRadius; /* 0x0A8 */ s16 collisionHeight; @@ -969,16 +969,19 @@ typedef struct GameStatus { /* 0x16C */ char unk_16C[12]; } GameStatus; // size = 0x178 +/* +still; +walk; +jump; +fall; +fly; +idle; +run; +talk; +hurt; +*/ typedef struct PartnerAnimations { - /* 0x00 */ UNK_PTR still; - /* 0x04 */ UNK_PTR walk; - /* 0x08 */ UNK_PTR jump; - /* 0x0C */ UNK_PTR fall; - /* 0x10 */ UNK_PTR fly; - /* 0x14 */ UNK_PTR idle; - /* 0x18 */ UNK_PTR run; - /* 0x1C */ UNK_PTR talk; - /* 0x20 */ UNK_PTR hurt; + /* 0x00 */ UNK_PTR anims[9]; } PartnerAnimations; // size = 0x24 typedef struct Shadow { diff --git a/src/code_1A5830.c b/src/code_1A5830.c index 64de475aa0..f9ce9b8779 100644 --- a/src/code_1A5830.c +++ b/src/code_1A5830.c @@ -18,8 +18,19 @@ s32 func_80276F50(Actor* actor) { return ret; } -void dispatch_event_general(Actor* actor, Event event); -INCLUDE_ASM(void, "code_1A5830", dispatch_event_general, Actor* actor, Event event); +void dispatch_event_general(Actor* actor, Event event) { + switch (actor->actorID & 0x700) { + case 0: + dispatch_event_player(event); + break; + case 0x100: + dispatch_event_partner(event); + break; + case 0x200: + dispatch_event_actor(actor, event); + break; + } +} INCLUDE_ASM(s32, "code_1A5830", play_hit_sound); @@ -243,16 +254,16 @@ INCLUDE_ASM(s32, "code_1A5830", DropStarPoints); ApiStatus SetDefenseTable(ScriptInstance* script, s32 isInitialCall) { Bytecode* args = script->ptrReadPos; ActorID actorID = get_variable(script, *args++); - s32 var1; + s32 partIndex; s32 var2; if (actorID == ActorID_SELF) { actorID = script->owner1.actorID; } - var1 = get_variable(script, *args++); + partIndex = get_variable(script, *args++); var2 = get_variable(script, *args++); - get_actor_part(get_actor(actorID), var1)->defenseTable = var2; + get_actor_part(get_actor(actorID), partIndex)->defenseTable = var2; return ApiStatus_DONE2; } @@ -273,20 +284,37 @@ ApiStatus SetStatusTable(ScriptInstance* script, s32 isInitialCall) { ApiStatus SetIdleAnimations(ScriptInstance* script, s32 isInitialCall) { Bytecode* args = script->ptrReadPos; ActorID actorID = get_variable(script, *args++); - s32 var1; + s32 partIndex; s32 var2; if (actorID == ActorID_SELF) { actorID = script->owner1.actorID; } - var1 = get_variable(script, *args++); + partIndex = get_variable(script, *args++); var2 = get_variable(script, *args++); - get_actor_part(get_actor(actorID), var1)->idleAnimations = var2; + get_actor_part(get_actor(actorID), partIndex)->idleAnimations = var2; return ApiStatus_DONE2; } -INCLUDE_ASM(s32, "code_1A5830", func_8027CC10); +ApiStatus func_8027CC10(ScriptInstance* script, s32 isInitialCall) { + Bytecode* args = script->ptrReadPos; + ActorID actorID = get_variable(script, *args++); + s32 partIndex; + + if (actorID == ActorID_SELF) { + actorID = script->owner1.actorID; + } + + partIndex = get_variable(script, *args++); + + // weirdly unused + get_variable(script, *args++); + get_variable(script, *args++); + + get_actor_part(get_actor(actorID), partIndex); + return ApiStatus_DONE2; +} INCLUDE_ASM(s32, "code_1A5830", EnemyDamageTarget); diff --git a/src/code_f2470_len_27f0.c b/src/code_f2470_len_27f0.c index 2dedc37e82..5604e8392c 100644 --- a/src/code_f2470_len_27f0.c +++ b/src/code_f2470_len_27f0.c @@ -1,4 +1,5 @@ #include "common.h" +#include "map.h" Npc* resolve_npc(ScriptInstance* script, NpcId npcIdOrPtr) { if (npcIdOrPtr == NpcId_SELF) { @@ -10,9 +11,19 @@ Npc* resolve_npc(ScriptInstance* script, NpcId npcIdOrPtr) { } } -INCLUDE_ASM(void, "code_f2470_len_27f0", set_npc_animation, Npc* npc, u32 arg1); +void set_npc_animation(Npc* npc, u32 arg1) { + PlayerData* playerData = PLAYER_DATA; -INCLUDE_ASM(s32, "code_f2470_len_27f0", CreateNpc); + if (arg1 - 0x101 < 9) { + npc->currentAnim = gPartnerAnimations[playerData->currentPartner].anims[arg1 - 0x101]; + } else if ((arg1 - 0x201) < 0x10) { + npc->currentAnim = get_enemy(npc->npcID)->animList[arg1 - 0x201]; + } else { + npc->currentAnim = arg1; + } +} + +INCLUDE_ASM(ApiStatus, "code_f2470_len_27f0", CreateNpc, ScriptInstance* script, s32 isInitialCall); ApiStatus DeleteNpc(ScriptInstance* script, s32 isInitialCall) { Bytecode* args = script->ptrReadPos; @@ -199,12 +210,12 @@ INCLUDE_ASM(s32, "code_f2470_len_27f0", NpcMoveTo, ScriptInstance* script, s32 i INCLUDE_ASM(s32, "code_f2470_len_27f0", _npc_jump_to); -void NpcJump0(ScriptInstance* script, s32 isInitialCall) { - _npc_jump_to(script, isInitialCall, 0); +ApiStatus NpcJump0(ScriptInstance* script, s32 isInitialCall) { + return _npc_jump_to(script, isInitialCall, 0); } -void NpcJump1(ScriptInstance* script, s32 isInitialCall) { - _npc_jump_to(script, isInitialCall, 1); +ApiStatus NpcJump1(ScriptInstance* script, s32 isInitialCall) { + return _npc_jump_to(script, isInitialCall, 1); } INCLUDE_ASM(s32, "code_f2470_len_27f0", NpcFlyTo, ScriptInstance* script, s32 isInitialCall); @@ -420,9 +431,9 @@ ApiStatus func_802CF56C(ScriptInstance* script, s32 isInitialCall) { return ApiStatus_DONE2; } -INCLUDE_ASM(s32, "code_f2470_len_27f0", BringPartnerOut); +INCLUDE_ASM(ApiStatus, "code_f2470_len_27f0", BringPartnerOut, ScriptInstance* script, s32 isInitialCall); -INCLUDE_ASM(s32, "code_f2470_len_27f0", PutPartnerAway); +INCLUDE_ASM(ApiStatus, "code_f2470_len_27f0", PutPartnerAway, ScriptInstance* script, s32 isInitialCall); ApiStatus GetCurrentPartnerID(ScriptInstance* script, s32 isInitialCall) { set_variable(script, *script->ptrReadPos, gPlayerData.currentPartner); diff --git a/src/code_fa4c0_len_3bf0.c b/src/code_fa4c0_len_3bf0.c index 049cdfdfbc..8657e97f6d 100644 --- a/src/code_fa4c0_len_3bf0.c +++ b/src/code_fa4c0_len_3bf0.c @@ -34,7 +34,12 @@ ApiStatus FadeInMusic(ScriptInstance* script, s32 isInitialCall) { return (func_8014A964(var0, var1, var2, var3, var4, var5) != 0) * ApiStatus_DONE2; } -INCLUDE_ASM(s32, "code_fa4c0_len_3bf0", func_802D5EE0); +ApiStatus func_802D5EE0(ScriptInstance* script, s32 isInitialCall) { + Bytecode* args = script->ptrReadPos; + + (&gMusicPlayers[get_variable(script, *args++)])->flags |= 0x2; + return ApiStatus_DONE2; +} ApiStatus func_802D5F28(ScriptInstance* script, s32 isInitialCall) { Bytecode* args = script->ptrReadPos;