From 251ddcc4ebf00e3fb6e949140a8f6dfd308a81d3 Mon Sep 17 00:00:00 2001 From: Cuyler36 Date: Sun, 15 Oct 2023 01:47:21 -0400 Subject: [PATCH] Implement & link m_melody.c --- config/rel_disasm_overrides.yml | 4 +- config/rel_slices.yml | 4 ++ include/ac_npc.h | 18 ++++++--- include/m_melody.h | 10 +++++ include/m_npc.h | 19 +++++++++ rel/m_melody.c | 69 +++++++++++++++++++++++++++++++++ 6 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 rel/m_melody.c diff --git a/config/rel_disasm_overrides.yml b/config/rel_disasm_overrides.yml index c4f9e8af..bc416a6c 100644 --- a/config/rel_disasm_overrides.yml +++ b/config/rel_disasm_overrides.yml @@ -8,4 +8,6 @@ symbol_aligns: 0x806D4D40: 32 # align fFTR_myhome_off_pal_table to 32 bytes 0x8064F860: 32 # data right after m_camera2 TU 0x80C78B20: 32 # mFM_grd_s_cliff_tex - 0x80F8C460: 32 # mFM_grd_s_rail_tex \ No newline at end of file + 0x80F8C460: 32 # mFM_grd_s_rail_tex + 0x80657200: 32 # .data msg.o + 0x81297E80: 32 # .bss msg.o \ No newline at end of file diff --git a/config/rel_slices.yml b/config/rel_slices.yml index c1299cd9..f35ff402 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -149,6 +149,10 @@ m_mail_password_check.c: m_mark_room.c: .text: [0x803BEC9C, 0x803BF210] .rodata: [0x806426D8, 0x806426E8] +m_melody.c: + .text: [0x803BF210, 0x803BF464] + .data: [0x806571D8, 0x80657200] + .bss: [0x81297E68, 0x81297E80] m_museum.c: .text: [0x803C6228, 0x803C74C0] .rodata: [0x80642938, 0x80642950] diff --git a/include/ac_npc.h b/include/ac_npc.h index 23b0fda5..f14f1465 100644 --- a/include/ac_npc.h +++ b/include/ac_npc.h @@ -7,6 +7,7 @@ #include "ac_npc_h.h" #include "m_npc_schedule.h" #include "m_actor_dlftbls.h" +#include "m_npc.h" #ifdef __cplusplus extern "C" { @@ -55,19 +56,24 @@ struct ac_npc_clip_s { }; typedef struct npc_info_s { - mNPS_schedule_c* schedule; - mNpc_NpcList_c* list; Animal_c* animal; - void* event; // TODO: EventNpc struct + mNpc_NpcList_c* list; + mNPS_schedule_c* schedule; + mNpc_EventNpc_c* event; + mNpc_MaskNpc_c* mask; + mActor_name_t npc_name; } NpcActorInfo_c; struct npc_actor_s { ACTOR actor_class; + int _174; + int _178; NpcActorInfo_c npc_info; - // TODO: finish - u8 _174[0x718 - 0x184]; + u8 _194[0x718 - 0x194]; int texture_bank_idx; // TEMP: this is part of draw struct - u8 _71C[0x9D8 - 0x71C]; + u8 _71C[0x978 - 0x71C]; + s16 melody_inst; + u8 _97A[0x9D8 - 0x97A]; }; extern ACTOR_PROFILE Npc_Profile; diff --git a/include/m_melody.h b/include/m_melody.h index 906b9752..aeb44e8a 100644 --- a/include/m_melody.h +++ b/include/m_melody.h @@ -2,12 +2,22 @@ #define M_MELODY_H #include "types.h" +#include "m_actor_type.h" #ifdef __cplusplus extern "C" { #endif +#define mMld_MELODY_LEN 16 + extern void mMld_SetDefaultMelody(); +extern void mMld_TransformMelodyData_u64_2_u8(u8* dst, u64 src); +extern void mMld_TransformMelodyData_u8_2_u64(u64* dst, u8* src); +extern void mMld_GetMelody(u8* dst); +extern void mMld_SetSaveMelody(u8* melody); +extern void mMld_MakeMelody(u16 inst); +extern void mMld_ActorMakeThisMelody(u8* melody, ACTOR* actor); +extern void mMld_ActorMakeMelody(ACTOR* actor); #ifdef __cplusplus } diff --git a/include/m_npc.h b/include/m_npc.h index 2ae1854e..28233f63 100644 --- a/include/m_npc.h +++ b/include/m_npc.h @@ -196,6 +196,25 @@ typedef struct npc_list_s { mActor_name_t reward_furniture; } mNpc_NpcList_c; +typedef struct event_npc_s { + mActor_name_t event_id; /* event NPC id */ + mActor_name_t texture_id; /* real NPC id which is used for texture data */ + mActor_name_t npc_id; /* non-texture NPC id used for other NPC data */ + mActor_name_t cloth_id; /* cloth texture id */ + u8 exists; /* has the actor been spawned yet? */ + u8 in_use; /* is this event npc structure being used? */ + u16 _A; /* exists based on size of structure, seems unused */ +} mNpc_EventNpc_c; + +typedef struct mask_npc_s { + mActor_name_t mask_id; /* 'mask' actor id */ + mActor_name_t npc_id; /* NPC actor id whose data will be used */ + mActor_name_t cloth_id; /* cloth actor id */ + u8 exists; /* has the actor been spawned yet? */ + u8 in_use; /* is this mask npc structure being used? */ + Animal_c animal_data; /* animal data is copied if the mask npc is a standard villager NPC */ +} mNpc_MaskNpc_c; + /* anm_id could also just be a Animal_c pointer */ extern void mNpc_GetNpcWorldNameAnm(u8* name, AnmPersonalID_c* anm_id); extern int mNpc_CheckFreeAnimalPersonalID(AnmPersonalID_c* anm_id); diff --git a/rel/m_melody.c b/rel/m_melody.c new file mode 100644 index 00000000..5c0a4700 --- /dev/null +++ b/rel/m_melody.c @@ -0,0 +1,69 @@ +#include "m_melody.h" + +#include "ac_npc.h" +#include "m_common_data.h" + +extern void mMld_SetDefaultMelody() { + static u8 melody[mMld_MELODY_LEN] = { + 0x7, 0xC, 0xF, 0x7, 0x6, 0xB, 0xF, 0x9, + 0xA, 0xE, 0xD, 0xE, 0x3, 0xF, 0xE, 0xE + }; + + mMld_SetSaveMelody(melody); +} + +extern void mMld_TransformMelodyData_u64_2_u8(u8* dst, u64 src) { + int i; + + for (i = 0; i < mMld_MELODY_LEN; i++) { + *dst++ = (src >> (60 - i * 4)) & 0xF; + } +} + +extern void mMld_TransformMelodyData_u8_2_u64(u64* dst, u8* src) { + int i; + + dst[0] = 0; + + for (i = 0; i < mMld_MELODY_LEN; i++) { + dst[0] |= (u64)(src[0] & 0xF) << (60 - i * 4); + src++; + } +} + +extern void mMld_GetMelody(u8* dst) { + mMld_TransformMelodyData_u64_2_u8(dst, Save_Get(melody)); +} + +extern void mMld_SetSaveMelody(u8* melody) { + mMld_TransformMelodyData_u8_2_u64(Save_GetPointer(melody), melody); +} + +extern void mMld_MakeMelody(u16 inst) { + static u8 melody[mMld_MELODY_LEN]; + + mMld_GetMelody(melody); + sAdo_Inst(inst, melody); +} + +extern void mMld_ActorMakeThisMelody(u8* melody, ACTOR* actor) { + if (actor != NULL && actor->part == ACTOR_PART_NPC) { + NPC_ACTOR* npc_actor = (NPC_ACTOR*)actor; + int melody_inst = npc_actor->melody_inst; + + if (melody_inst != 0) { + sAdo_Inst(melody_inst, melody); + } + } +} + +extern void mMld_ActorMakeMelody(ACTOR* actor) { + if (actor != NULL && actor->part == ACTOR_PART_NPC) { + NPC_ACTOR* npc_actor = (NPC_ACTOR*)actor; + int melody_inst = npc_actor->melody_inst; + + if (melody_inst != 0) { + mMld_MakeMelody(melody_inst); + } + } +}