match GetAngleToNPC and GetAngleToPlayer

This commit is contained in:
Alex Bates 2020-08-15 06:00:29 +01:00
parent 0f34468a77
commit b6f7087c82
6 changed files with 36 additions and 84 deletions

View File

@ -1,37 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel GetAngleToNPC
/* 0F9164 802D47B4 27BDFFE0 */ addiu $sp, $sp, -0x20
/* 0F9168 802D47B8 AFB10014 */ sw $s1, 0x14($sp)
/* 0F916C 802D47BC 0080882D */ daddu $s1, $a0, $zero
/* 0F9170 802D47C0 AFBF0018 */ sw $ra, 0x18($sp)
/* 0F9174 802D47C4 AFB00010 */ sw $s0, 0x10($sp)
/* 0F9178 802D47C8 8E30000C */ lw $s0, 0xc($s1)
/* 0F917C 802D47CC 8E050000 */ lw $a1, ($s0)
/* 0F9180 802D47D0 0C0B1EAF */ jal get_variable
/* 0F9184 802D47D4 26100004 */ addiu $s0, $s0, 4
/* 0F9188 802D47D8 0220202D */ daddu $a0, $s1, $zero
/* 0F918C 802D47DC 8E100000 */ lw $s0, ($s0)
/* 0F9190 802D47E0 0C0B36B0 */ jal resolve_npc
/* 0F9194 802D47E4 0040282D */ daddu $a1, $v0, $zero
/* 0F9198 802D47E8 3C038011 */ lui $v1, 0x8011
/* 0F919C 802D47EC 2463EFC8 */ addiu $v1, $v1, -0x1038
/* 0F91A0 802D47F0 8C460038 */ lw $a2, 0x38($v0)
/* 0F91A4 802D47F4 C46C0028 */ lwc1 $f12, 0x28($v1)
/* 0F91A8 802D47F8 C46E0030 */ lwc1 $f14, 0x30($v1)
/* 0F91AC 802D47FC 0C00A720 */ jal atan2
/* 0F91B0 802D4800 8C470040 */ lw $a3, 0x40($v0)
/* 0F91B4 802D4804 0220202D */ daddu $a0, $s1, $zero
/* 0F91B8 802D4808 4600008D */ trunc.w.s $f2, $f0
/* 0F91BC 802D480C 44061000 */ mfc1 $a2, $f2
/* 0F91C0 802D4810 0C0B2026 */ jal set_variable
/* 0F91C4 802D4814 0200282D */ daddu $a1, $s0, $zero
/* 0F91C8 802D4818 8FBF0018 */ lw $ra, 0x18($sp)
/* 0F91CC 802D481C 8FB10014 */ lw $s1, 0x14($sp)
/* 0F91D0 802D4820 8FB00010 */ lw $s0, 0x10($sp)
/* 0F91D4 802D4824 24020002 */ addiu $v0, $zero, 2
/* 0F91D8 802D4828 03E00008 */ jr $ra
/* 0F91DC 802D482C 27BD0020 */ addiu $sp, $sp, 0x20

View File

@ -1,37 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel GetAngleToPlayer
/* 0F91E0 802D4830 27BDFFE0 */ addiu $sp, $sp, -0x20
/* 0F91E4 802D4834 AFB10014 */ sw $s1, 0x14($sp)
/* 0F91E8 802D4838 0080882D */ daddu $s1, $a0, $zero
/* 0F91EC 802D483C AFBF0018 */ sw $ra, 0x18($sp)
/* 0F91F0 802D4840 AFB00010 */ sw $s0, 0x10($sp)
/* 0F91F4 802D4844 8E30000C */ lw $s0, 0xc($s1)
/* 0F91F8 802D4848 8E050000 */ lw $a1, ($s0)
/* 0F91FC 802D484C 0C0B1EAF */ jal get_variable
/* 0F9200 802D4850 26100004 */ addiu $s0, $s0, 4
/* 0F9204 802D4854 0220202D */ daddu $a0, $s1, $zero
/* 0F9208 802D4858 8E100000 */ lw $s0, ($s0)
/* 0F920C 802D485C 0C0B36B0 */ jal resolve_npc
/* 0F9210 802D4860 0040282D */ daddu $a1, $v0, $zero
/* 0F9214 802D4864 3C038011 */ lui $v1, 0x8011
/* 0F9218 802D4868 2463EFC8 */ addiu $v1, $v1, -0x1038
/* 0F921C 802D486C 8C660028 */ lw $a2, 0x28($v1)
/* 0F9220 802D4870 C44C0038 */ lwc1 $f12, 0x38($v0)
/* 0F9224 802D4874 C44E0040 */ lwc1 $f14, 0x40($v0)
/* 0F9228 802D4878 0C00A720 */ jal atan2
/* 0F922C 802D487C 8C670030 */ lw $a3, 0x30($v1)
/* 0F9230 802D4880 0220202D */ daddu $a0, $s1, $zero
/* 0F9234 802D4884 4600008D */ trunc.w.s $f2, $f0
/* 0F9238 802D4888 44061000 */ mfc1 $a2, $f2
/* 0F923C 802D488C 0C0B2026 */ jal set_variable
/* 0F9240 802D4890 0200282D */ daddu $a1, $s0, $zero
/* 0F9244 802D4894 8FBF0018 */ lw $ra, 0x18($sp)
/* 0F9248 802D4898 8FB10014 */ lw $s1, 0x14($sp)
/* 0F924C 802D489C 8FB00010 */ lw $s0, 0x10($sp)
/* 0F9250 802D48A0 24020002 */ addiu $v0, $zero, 2
/* 0F9254 802D48A4 03E00008 */ jr $ra
/* 0F9258 802D48A8 27BD0020 */ addiu $sp, $sp, 0x20

View File

@ -9,10 +9,10 @@ void osCleanupThread(void);
void clone_model(u16 srcModelID, u16 newModelID);
void update_collider_transform(s16 colliderID);
s32 get_variable(script_context* script, bytecode var);
void set_variable(script_context* script, bytecode var, s32 value);
f32 get_float_variable(script_context* script, bytecode var);
f32 set_float_variable(script_context* script, bytecode var, f32 value);
s32 get_variable(script_context* script, s32 var);
s32 set_variable(script_context* script, s32 var, s32 value);
f32 get_float_variable(script_context* script, s32 var);
f32 set_float_variable(script_context* script, s32 var, f32 value);
void set_script_timescale(script_context* script, f32 timescale);
f32 sin_deg(f32 x);
f32 cos_deg(f32 x);
@ -29,6 +29,10 @@ void sort_items(void);
s32 is_ability_active(s32 arg0);
f32 update_lerp(EASING easing, f32 start, f32 end, s32 elapsed, s32 duration);
npc* get_npc_safe(NPC npcID);
npc* get_npc_unsafe(NPC npcID);
npc* resolve_npc(script_context* script, NPC npcID);
s32 play_sound_at_position(s32 soundID, s32 value2, f32 posX, f32 posY, f32 posZ);
s32 set_music_track(s32 musicPlayer, s32 songID, s32 variation, s32 unk, s32 volume);
#endif

View File

@ -8,6 +8,6 @@
#define UNK_FUN_PTR(name) void(*name)(void)
#define UNK_ARGS
typedef s32* bytecode;
typedef s32 bytecode;
#endif

View File

@ -6,7 +6,7 @@ npc* resolve_npc(script_context* script, NPC npcID) {
} else if (npcID >= -270000000) {
return get_npc_safe(npcID);
} else {
return npcID;
return (npc*) npcID;
}
}

View File

@ -34,10 +34,10 @@ s32 UpdateLerp(script_context* script, s32 initialCall) {
s32 RandInt(script_context* script, s32 initialCall) {
bytecode* ptrReadPos = script->ptrReadPos;
s32 maxVar = get_variable(script, *ptrReadPos++);
s32 max = get_variable(script, *ptrReadPos++);
bytecode outVar = *ptrReadPos++;
set_variable(script, outVar, rand_int(maxVar));
set_variable(script, outVar, rand_int(max));
return 2;
}
@ -56,9 +56,31 @@ s32 GetAngleBetweenNPCs(script_context* script, s32 initialCall) {
return 2;
}
INCLUDE_ASM(code_f8f60_len_1560, GetAngleToNPC);
s32 GetAngleToNPC(script_context* script, s32 initialCall) {
player_status* playerStatus = &gPlayerStatus;
bytecode* ptrReadPos = script->ptrReadPos;
INCLUDE_ASM(code_f8f60_len_1560, GetAngleToPlayer);
NPC npcID = get_variable(script, *ptrReadPos++);
bytecode outVar = *ptrReadPos++;
npc* npc = resolve_npc(script, npcID);
set_variable(script, outVar, atan2(playerStatus->position.x, playerStatus->position.z, npc->pos.x, npc->pos.z));
return 2;
}
s32 GetAngleToPlayer(script_context* script, s32 initialCall) {
player_status* playerStatus = &gPlayerStatus;
bytecode* ptrReadPos = script->ptrReadPos;
NPC npcID = get_variable(script, *ptrReadPos++);
bytecode outVar = *ptrReadPos++;
npc* npc = resolve_npc(script, npcID);
set_variable(script, outVar, atan2(npc->pos.x, npc->pos.z, playerStatus->position.x, playerStatus->position.z));
return 2;
}
INCLUDE_ASM(code_f8f60_len_1560, AwaitPlayerApproach);