4 funcs in code_1A5830

This commit is contained in:
Ethan Roseman 2020-11-15 22:04:33 -05:00
parent 0432eef67c
commit e67d69b88e
8 changed files with 97 additions and 168 deletions

View File

@ -1,48 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel DispatchDamageEvent
/* 1ABA9C 8027D1BC 27BDFFE0 */ addiu $sp, $sp, -0x20
/* 1ABAA0 8027D1C0 AFB20018 */ sw $s2, 0x18($sp)
/* 1ABAA4 8027D1C4 0080902D */ daddu $s2, $a0, $zero
/* 1ABAA8 8027D1C8 AFBF001C */ sw $ra, 0x1c($sp)
/* 1ABAAC 8027D1CC AFB10014 */ sw $s1, 0x14($sp)
/* 1ABAB0 8027D1D0 AFB00010 */ sw $s0, 0x10($sp)
/* 1ABAB4 8027D1D4 8E50000C */ lw $s0, 0xc($s2)
/* 1ABAB8 8027D1D8 8E050000 */ lw $a1, ($s0)
/* 1ABABC 8027D1DC 0C0B1EAF */ jal get_variable
/* 1ABAC0 8027D1E0 26100004 */ addiu $s0, $s0, 4
/* 1ABAC4 8027D1E4 0040202D */ daddu $a0, $v0, $zero
/* 1ABAC8 8027D1E8 2402FF81 */ addiu $v0, $zero, -0x7f
/* 1ABACC 8027D1EC 14820002 */ bne $a0, $v0, .L8027D1F8
/* 1ABAD0 8027D1F0 00000000 */ nop
/* 1ABAD4 8027D1F4 8E440148 */ lw $a0, 0x148($s2)
.L8027D1F8:
/* 1ABAD8 8027D1F8 0C09A75B */ jal get_actor
/* 1ABADC 8027D1FC 00000000 */ nop
/* 1ABAE0 8027D200 8E050000 */ lw $a1, ($s0)
/* 1ABAE4 8027D204 26100004 */ addiu $s0, $s0, 4
/* 1ABAE8 8027D208 0240202D */ daddu $a0, $s2, $zero
/* 1ABAEC 8027D20C 0C0B1EAF */ jal get_variable
/* 1ABAF0 8027D210 0040882D */ daddu $s1, $v0, $zero
/* 1ABAF4 8027D214 0240202D */ daddu $a0, $s2, $zero
/* 1ABAF8 8027D218 8E050000 */ lw $a1, ($s0)
/* 1ABAFC 8027D21C 0C0B1EAF */ jal get_variable
/* 1ABB00 8027D220 0040802D */ daddu $s0, $v0, $zero
/* 1ABB04 8027D224 0220202D */ daddu $a0, $s1, $zero
/* 1ABB08 8027D228 0200282D */ daddu $a1, $s0, $zero
/* 1ABB0C 8027D22C 0C09E23E */ jal dispatch_damage_event_actor_0
/* 1ABB10 8027D230 0040302D */ daddu $a2, $v0, $zero
/* 1ABB14 8027D234 04420005 */ bltzl $v0, .L8027D24C
/* 1ABB18 8027D238 0000102D */ daddu $v0, $zero, $zero
/* 1ABB1C 8027D23C 0C0B1069 */ jal does_script_exist_by_ref
/* 1ABB20 8027D240 0240202D */ daddu $a0, $s2, $zero
/* 1ABB24 8027D244 0002102B */ sltu $v0, $zero, $v0
/* 1ABB28 8027D248 00021040 */ sll $v0, $v0, 1
.L8027D24C:
/* 1ABB2C 8027D24C 8FBF001C */ lw $ra, 0x1c($sp)
/* 1ABB30 8027D250 8FB20018 */ lw $s2, 0x18($sp)
/* 1ABB34 8027D254 8FB10014 */ lw $s1, 0x14($sp)
/* 1ABB38 8027D258 8FB00010 */ lw $s0, 0x10($sp)
/* 1ABB3C 8027D25C 03E00008 */ jr $ra
/* 1ABB40 8027D260 27BD0020 */ addiu $sp, $sp, 0x20

View File

@ -1,45 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel dispatch_event_actor
/* 1A5A40 80277160 27BDFFE0 */ addiu $sp, $sp, -0x20
/* 1A5A44 80277164 AFB00010 */ sw $s0, 0x10($sp)
/* 1A5A48 80277168 0080802D */ daddu $s0, $a0, $zero
/* 1A5A4C 8027716C AFBF001C */ sw $ra, 0x1c($sp)
/* 1A5A50 80277170 AFB20018 */ sw $s2, 0x18($sp)
/* 1A5A54 80277174 AFB10014 */ sw $s1, 0x14($sp)
/* 1A5A58 80277178 8E1201D8 */ lw $s2, 0x1d8($s0)
/* 1A5A5C 8027717C 8E0201C8 */ lw $v0, 0x1c8($s0)
/* 1A5A60 80277180 8E1101E8 */ lw $s1, 0x1e8($s0)
/* 1A5A64 80277184 1040000A */ beqz $v0, .L802771B0
/* 1A5A68 80277188 0040202D */ daddu $a0, $v0, $zero
/* 1A5A6C 8027718C A20501F0 */ sb $a1, 0x1f0($s0)
/* 1A5A70 80277190 2405000A */ addiu $a1, $zero, 0xa
/* 1A5A74 80277194 0C0B0CF8 */ jal start_script
/* 1A5A78 80277198 24060020 */ addiu $a2, $zero, 0x20
/* 1A5A7C 8027719C AE0201D8 */ sw $v0, 0x1d8($s0)
/* 1A5A80 802771A0 8C430144 */ lw $v1, 0x144($v0)
/* 1A5A84 802771A4 86040192 */ lh $a0, 0x192($s0)
/* 1A5A88 802771A8 AE0301E8 */ sw $v1, 0x1e8($s0)
/* 1A5A8C 802771AC AC440148 */ sw $a0, 0x148($v0)
.L802771B0:
/* 1A5A90 802771B0 8E0201D4 */ lw $v0, 0x1d4($s0)
/* 1A5A94 802771B4 10400006 */ beqz $v0, .L802771D0
/* 1A5A98 802771B8 00000000 */ nop
/* 1A5A9C 802771BC 0C0B11E4 */ jal get_script_by_index
/* 1A5AA0 802771C0 8E0401E4 */ lw $a0, 0x1e4($s0)
/* 1A5AA4 802771C4 0C0B102B */ jal kill_script_by_ID
/* 1A5AA8 802771C8 8E0401E4 */ lw $a0, 0x1e4($s0)
/* 1A5AAC 802771CC AE0001D4 */ sw $zero, 0x1d4($s0)
.L802771D0:
/* 1A5AB0 802771D0 12400003 */ beqz $s2, .L802771E0
/* 1A5AB4 802771D4 00000000 */ nop
/* 1A5AB8 802771D8 0C0B102B */ jal kill_script_by_ID
/* 1A5ABC 802771DC 0220202D */ daddu $a0, $s1, $zero
.L802771E0:
/* 1A5AC0 802771E0 8FBF001C */ lw $ra, 0x1c($sp)
/* 1A5AC4 802771E4 8FB20018 */ lw $s2, 0x18($sp)
/* 1A5AC8 802771E8 8FB10014 */ lw $s1, 0x14($sp)
/* 1A5ACC 802771EC 8FB00010 */ lw $s0, 0x10($sp)
/* 1A5AD0 802771F0 03E00008 */ jr $ra
/* 1A5AD4 802771F4 27BD0020 */ addiu $sp, $sp, 0x20

View File

@ -1,22 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel func_80276F50
/* 1A5830 80276F50 8C8301F4 */ lw $v1, 0x1f4($a0)
/* 1A5834 80276F54 1060000B */ beqz $v1, .L80276F84
/* 1A5838 80276F58 0000202D */ daddu $a0, $zero, $zero
/* 1A583C 80276F5C 3C05000C */ lui $a1, 0xc
.L80276F60:
/* 1A5840 80276F60 8C62007C */ lw $v0, 0x7c($v1)
/* 1A5844 80276F64 00451024 */ and $v0, $v0, $a1
/* 1A5848 80276F68 10400003 */ beqz $v0, .L80276F78
/* 1A584C 80276F6C 00000000 */ nop
/* 1A5850 80276F70 0809DBE1 */ j .L80276F84
/* 1A5854 80276F74 24040001 */ addiu $a0, $zero, 1
.L80276F78:
/* 1A5858 80276F78 8C63000C */ lw $v1, 0xc($v1)
/* 1A585C 80276F7C 1460FFF8 */ bnez $v1, .L80276F60
/* 1A5860 80276F80 00000000 */ nop
.L80276F84:
/* 1A5864 80276F84 03E00008 */ jr $ra
/* 1A5868 80276F88 0080102D */ daddu $v0, $a0, $zero

View File

@ -1,42 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel func_8027D434
/* 1ABD14 8027D434 27BDFFE0 */ addiu $sp, $sp, -0x20
/* 1ABD18 8027D438 AFB20018 */ sw $s2, 0x18($sp)
/* 1ABD1C 8027D43C 0080902D */ daddu $s2, $a0, $zero
/* 1ABD20 8027D440 AFBF001C */ sw $ra, 0x1c($sp)
/* 1ABD24 8027D444 AFB10014 */ sw $s1, 0x14($sp)
/* 1ABD28 8027D448 AFB00010 */ sw $s0, 0x10($sp)
/* 1ABD2C 8027D44C 8E51000C */ lw $s1, 0xc($s2)
/* 1ABD30 8027D450 8E250000 */ lw $a1, ($s1)
/* 1ABD34 8027D454 0C0B1EAF */ jal get_variable
/* 1ABD38 8027D458 26310004 */ addiu $s1, $s1, 4
/* 1ABD3C 8027D45C 0040802D */ daddu $s0, $v0, $zero
/* 1ABD40 8027D460 2402FF81 */ addiu $v0, $zero, -0x7f
/* 1ABD44 8027D464 16020002 */ bne $s0, $v0, .L8027D470
/* 1ABD48 8027D468 00000000 */ nop
/* 1ABD4C 8027D46C 8E500148 */ lw $s0, 0x148($s2)
.L8027D470:
/* 1ABD50 8027D470 8E250000 */ lw $a1, ($s1)
/* 1ABD54 8027D474 26310004 */ addiu $s1, $s1, 4
/* 1ABD58 8027D478 0C0B1EAF */ jal get_variable
/* 1ABD5C 8027D47C 0240202D */ daddu $a0, $s2, $zero
/* 1ABD60 8027D480 0200202D */ daddu $a0, $s0, $zero
/* 1ABD64 8027D484 0C09A75B */ jal get_actor
/* 1ABD68 8027D488 0040802D */ daddu $s0, $v0, $zero
/* 1ABD6C 8027D48C 0040202D */ daddu $a0, $v0, $zero
/* 1ABD70 8027D490 0C099117 */ jal get_actor_part
/* 1ABD74 8027D494 0200282D */ daddu $a1, $s0, $zero
/* 1ABD78 8027D498 0240202D */ daddu $a0, $s2, $zero
/* 1ABD7C 8027D49C 8E250000 */ lw $a1, ($s1)
/* 1ABD80 8027D4A0 0C0B1EAF */ jal get_variable
/* 1ABD84 8027D4A4 0040802D */ daddu $s0, $v0, $zero
/* 1ABD88 8027D4A8 A6020070 */ sh $v0, 0x70($s0)
/* 1ABD8C 8027D4AC 8FBF001C */ lw $ra, 0x1c($sp)
/* 1ABD90 8027D4B0 8FB20018 */ lw $s2, 0x18($sp)
/* 1ABD94 8027D4B4 8FB10014 */ lw $s1, 0x14($sp)
/* 1ABD98 8027D4B8 8FB00010 */ lw $s0, 0x10($sp)
/* 1ABD9C 8027D4BC 24020002 */ addiu $v0, $zero, 2
/* 1ABDA0 8027D4C0 03E00008 */ jr $ra
/* 1ABDA4 8027D4C4 27BD0020 */ addiu $sp, $sp, 0x20

View File

@ -581,7 +581,7 @@ typedef struct BattleStatus {
/* 0x196 */ char unk_196; /* 0x196 */ char unk_196;
/* 0x197 */ u8 targetHomeIndex; /* some sort of home idnex used for target list construction */ /* 0x197 */ u8 targetHomeIndex; /* some sort of home idnex used for target list construction */
/* 0x198 */ u8 powerBounceCounter; /* 0x198 */ u8 powerBounceCounter;
/* 0x199 */ u8 wasStatusInflicted; /* during last attack */ /* 0x199 */ s8 wasStatusInflicted; /* during last attack */
/* 0x19A */ s8 unk_19A; /* 0x19A */ s8 unk_19A;
/* 0x19B */ char unk_19B[5]; /* 0x19B */ char unk_19B[5];
/* 0x1A0 */ s16 currentTargetID; /* selected? */ /* 0x1A0 */ s16 currentTargetID; /* selected? */
@ -1034,7 +1034,7 @@ typedef struct ActorPart {
/* 0x64 */ f32 yaw; /* 0x64 */ f32 yaw;
/* 0x68 */ s16 unkOffset[2]; /* 0x68 */ s16 unkOffset[2];
/* 0x6C */ s16 targetOffset[2]; /* 0x6C */ s16 targetOffset[2];
/* 0x70 */ s16 unk; /* 0x70 */ s16 unk_70;
/* 0x72 */ u8 size[2]; /* 0x72 */ u8 size[2];
/* 0x74 */ u8 verticalStretch; /* 0x74 */ u8 verticalStretch;
/* 0x75 */ char unk_75[3]; /* 0x75 */ char unk_75[3];

View File

@ -95,6 +95,7 @@ void func_800ED5D0(Npc* partner);
s32 func_800EF394(f32); s32 func_800EF394(f32);
s32 does_script_exist(s32 id); s32 does_script_exist(s32 id);
s32 does_script_exist_by_ref(ScriptInstance* script);
ScriptInstance* start_script(Bytecode* initialLine, s32 priority, s32 initialState); ScriptInstance* start_script(Bytecode* initialLine, s32 priority, s32 initialState);
ScriptInstance* start_script_in_group(Bytecode* initialLine, u8 priority, u8 initialState, u8 groupFlags); ScriptInstance* start_script_in_group(Bytecode* initialLine, u8 priority, u8 initialState, u8 groupFlags);

View File

@ -1,12 +1,51 @@
#include "common.h" #include "common.h"
INCLUDE_ASM(s32, "code_1A5830", func_80276F50); void dispatch_event_actor(Actor* actor, Event event);
INCLUDE_ASM(s32, "code_1A5830", dispatch_event_general); s32 func_80276F50(Actor* actor) {
ActorPart* partIt = actor->partsTable;
s32 ret = FALSE;
while (partIt != NULL) {
if (partIt->eventFlags & 0xC0000) {
ret = TRUE;
break;
} else {
partIt = partIt->nextPart;
}
}
return ret;
}
void dispatch_event_general(Actor* actor, Event event);
INCLUDE_ASM(void, "code_1A5830", dispatch_event_general, Actor* actor, Event event);
INCLUDE_ASM(s32, "code_1A5830", play_hit_sound); INCLUDE_ASM(s32, "code_1A5830", play_hit_sound);
INCLUDE_ASM(s32, "code_1A5830", dispatch_event_actor); void dispatch_event_actor(Actor* actor, Event event) {
ScriptInstance* onHitScript = actor->onHitScript;
ScriptID onHitID = actor->onHitID;
if (actor->onHitCode != NULL) {
ScriptInstance* newScript;
actor->lastEventType = event;
newScript = start_script(actor->onHitCode, 0xA, 0x20);
actor->onHitScript = newScript;
actor->onHitID = newScript->id;
newScript->owner1.actorID = actor->actorID;
}
if (actor->takeTurnScript != NULL) {
get_script_by_index(actor->takeTurnID);
kill_script_by_ID(actor->takeTurnID);
actor->takeTurnScript = NULL;
}
if (onHitScript != NULL) {
kill_script_by_ID(onHitID);
}
}
INCLUDE_ASM(s32, "code_1A5830", calc_enemy_test_target); INCLUDE_ASM(s32, "code_1A5830", calc_enemy_test_target);
@ -229,7 +268,27 @@ INCLUDE_ASM(s32, "code_1A5830", EnemyFollowupAfflictTarget);
INCLUDE_ASM(s32, "code_1A5830", EnemyTestTarget); INCLUDE_ASM(s32, "code_1A5830", EnemyTestTarget);
INCLUDE_ASM(s32, "code_1A5830", DispatchDamageEvent); ApiStatus DispatchDamageEvent(ScriptInstance* script, s32 isInitialCall) {
Bytecode* args = script->ptrReadPos;
ActorId actorID = get_variable(script, *args++);
Actor* actor;
s32 damageAmount;
s32 scriptExists;
if (actorID == ActorId_SELF) {
actorID = script->owner1.actorID;
}
actor = get_actor(actorID);
damageAmount = get_variable(script, *args++);
if (dispatch_damage_event_actor_0(actor, damageAmount, get_variable(script, *args++)) < 0) {
return ApiStatus_BLOCK;
}
scriptExists = does_script_exist_by_ref(script) != 0;
return scriptExists * ApiStatus_DONE2;
}
ApiStatus DispatchEvent(ScriptInstance* script, s32 isInitialCall) { ApiStatus DispatchEvent(ScriptInstance* script, s32 isInitialCall) {
Bytecode* args = script->ptrReadPos; Bytecode* args = script->ptrReadPos;
@ -267,7 +326,21 @@ ApiStatus func_8027D32C(ScriptInstance* script, s32 isInitialCall) {
INCLUDE_ASM(s32, "code_1A5830", SetTargetOffset); INCLUDE_ASM(s32, "code_1A5830", SetTargetOffset);
INCLUDE_ASM(s32, "code_1A5830", func_8027D434); ApiStatus func_8027D434(ScriptInstance* script, s32 isInitialCall) {
Bytecode* args = script->ptrReadPos;
ActorId actorID = get_variable(script, *args++);
s32 partIndex;
ActorPart* part;
if (actorID == ActorId_SELF) {
actorID = script->owner1.actorID;
}
partIndex = get_variable(script, *args++);
part = get_actor_part(get_actor(actorID), partIndex);
part->unk_70 = get_variable(script, *args++);
return ApiStatus_DONE2;
}
INCLUDE_ASM(s32, "code_1A5830", func_8027D4C8); INCLUDE_ASM(s32, "code_1A5830", func_8027D4C8);
@ -392,7 +465,19 @@ ApiStatus GetLastDamage(ScriptInstance* script, s32 isInitialCall) {
INCLUDE_ASM(s32, "code_1A5830", EnableActorGlow); INCLUDE_ASM(s32, "code_1A5830", EnableActorGlow);
// Cannot get gBattleStatus to load via lui+addiu no matter what I do
#ifdef NON_MATCHING
ApiStatus WasStatusInflicted(ScriptInstance* script, s32 isInitialCall) {
Bytecode* args = script->ptrReadPos;
get_variable(script, *args++);
set_variable(script, *args++, gBattleStatus.wasStatusInflicted);
return ApiStatus_DONE2;
}
#else
INCLUDE_ASM(s32, "code_1A5830", WasStatusInflicted); INCLUDE_ASM(s32, "code_1A5830", WasStatusInflicted);
#endif
INCLUDE_ASM(s32, "code_1A5830", CopyStatusEffects); INCLUDE_ASM(s32, "code_1A5830", CopyStatusEffects);

View File

@ -528,10 +528,10 @@ s32 does_script_exist(s32 id) {
for (i = 0; i < MAX_SCRIPTS; i++) { for (i = 0; i < MAX_SCRIPTS; i++) {
scriptContextPtr = (*gCurrentScriptListPtr)[i]; scriptContextPtr = (*gCurrentScriptListPtr)[i];
if (scriptContextPtr != NULL && scriptContextPtr->id == id) { if (scriptContextPtr != NULL && scriptContextPtr->id == id) {
return 1; return TRUE;
} }
} }
return 0; return FALSE;
} }
s32 does_script_exist_by_ref(ScriptInstance* script) { s32 does_script_exist_by_ref(ScriptInstance* script) {
@ -539,10 +539,10 @@ s32 does_script_exist_by_ref(ScriptInstance* script) {
for (i = 0; i < MAX_SCRIPTS; i++) { for (i = 0; i < MAX_SCRIPTS; i++) {
if (script == (*gCurrentScriptListPtr)[i]) { if (script == (*gCurrentScriptListPtr)[i]) {
return 1; return TRUE;
} }
} }
return 0; return FALSE;
} }
void set_script_priority(ScriptInstance* script, s8 priority) { void set_script_priority(ScriptInstance* script, s8 priority) {