From de7a521857f98f3f9a7a8e507dfbf7c00aaa9234 Mon Sep 17 00:00:00 2001 From: Rozelette Date: Sat, 29 Aug 2020 00:10:24 -0500 Subject: [PATCH] Decompile z_snap (#11) --- include/functions.h | 19 ++-- include/structs.h | 5 +- linker_scripts/code_script.txt | 2 +- src/code/z_snap.c | 160 +++++++++++++++++++++++++++++++++ tables/objects.txt | 2 +- 5 files changed, 176 insertions(+), 12 deletions(-) create mode 100644 src/code/z_snap.c diff --git a/include/functions.h b/include/functions.h index a38942722d..584a5d5305 100644 --- a/include/functions.h +++ b/include/functions.h @@ -995,7 +995,7 @@ void func_800C5538(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_ void func_800C55C4(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); // func_800C55C4 void func_800C5650(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); // func_800C5650 void func_800C56E0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11, UNK_TYPE4 param_12); // func_800C56E0 -void func_800C576C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); // func_800C576C +s32 func_800C576C(CollisionContext* bgCtxt, Vec3f* param_2, Vec3f* param_3, Vec3f* param_4, UNK_PTR param_5, s32 param_6, s32 param_7, s32 param_8, s32 param_9, UNK_PTR param_10); // func_800C576C void func_800C57F8(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); // func_800C57F8 void func_800C583C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9); // func_800C583C void func_800C58C8(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); // func_800C58C8 @@ -1289,8 +1289,8 @@ void func_800DFC1C(void); // func_800DFC1C void func_800DFC40(void); // func_800DFC40 int func_800DFC68(Camera* camera); // func_800DFC68 void func_800DFC90(void); // func_800DFC90 -void func_800DFCB4(void); // func_800DFCB4 -void func_800DFCDC(void); // func_800DFCDC +s16 func_800DFCB4(Camera* camera); // func_800DFCB4 +s16 func_800DFCDC(Camera* camera); // func_800DFCDC void func_800DFD04(void); // func_800DFD04 void func_800DFD78(void); // func_800DFD78 UNK_TYPE4 func_800DFEF0(s32 param_1, u16 param_2); // func_800DFEF0 @@ -1504,7 +1504,7 @@ void func_800E7B54(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_ void func_800E7BCC(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); // func_800E7BCC void func_800E7C64(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); // func_800E7C64 void func_800E7DA8(void); // func_800E7DA8 -void func_800E7DCC(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); // func_800E7DCC +s32 func_800E7DCC(GlobalContext* ctxt, CollisionCheckContext* colCtxt, Vec3f* param_3, Vec3f* param_4, Actor** param_5, s32 param_6); // func_800E7DCC void Collision_CylinderMoveToActor(Actor* actor, ColCylinder* cylinder); // func_800E7DF8 void Collision_CylinderSetLoc(ColCylinder* cylinder, Vec3s* loc); // func_800E7E3C void Collision_QuadSetCoords(ColQuad* iParm1, Vec3f* pzParm2, Vec3f* pzParm3, Vec3f* pzParm4, Vec3f* param_5); // func_800E7E5C @@ -2659,11 +2659,12 @@ void Matrix_XRotation(z_Matrix* matrix, s16 rotation); // func_80139E98 void Matrix_MakeYRotation(z_Matrix* matrix, s16 rotation); // func_80139FA0 void Matrix_YRotation(z_Matrix* matrix, s16 rotation); // func_8013A068 void Matrix_MakeZRotation(z_Matrix* matrix, s16 rotation); // func_8013A174 -void func_8013A240(void); // func_8013A240 -void func_8013A41C(void); // func_8013A41C -void func_8013A4C4(void); // func_8013A4C4 -void func_8013A504(void); // func_8013A504 -void func_8013A530(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE2 param_8); // func_8013A530 +s32 func_8013A240(GlobalContext* ctxt); // func_8013A240 +void func_8013A41C(s32 flag); // func_8013A41C +void func_8013A46C(s32 flag); // func_8013A46C +u32 func_8013A4C4(s32 flag); // func_8013A4C4 +s16 func_8013A504(s16 val); // func_8013A504 +s32 func_8013A530(GlobalContext* ctxt, Actor* actor, s32 flag, Vec3f* pos, Vec3s* rot, f32 distanceMin, f32 distanceMax, s16 angleError); // func_8013A530 void func_8013A7C0(void); // func_8013A7C0 void func_8013A860(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); // func_8013A860 void func_8013AB00(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9); // func_8013AB00 diff --git a/include/structs.h b/include/structs.h index 6890744d76..bc4529ce54 100644 --- a/include/structs.h +++ b/include/structs.h @@ -1452,7 +1452,10 @@ typedef struct { /* 0x006E */ UNK_TYPE1 pad6E[0x2]; /* 0x0070 */ SaveContextInventory inv; /* 0x00F8 */ PermanentSceneFlags sceneFlags[120]; -/* 0x0E18 */ UNK_TYPE1 padE18[0xE0]; +/* 0x0E18 */ UNK_TYPE1 padE18[0x60]; +/* 0x0E78 */ u32 pictoFlags0; +/* 0x0E7C */ u32 pictoFlags1; +/* 0x0E80 */ UNK_TYPE1 padE80[0x78]; /* 0x0EF8 */ u8 weekEventReg[100]; /* 0x0F5C */ u32 mapsVisited; /* 0x0F60 */ UNK_TYPE1 padF60[0x8C]; diff --git a/linker_scripts/code_script.txt b/linker_scripts/code_script.txt index 5d6bfff283..08aa91eb65 100644 --- a/linker_scripts/code_script.txt +++ b/linker_scripts/code_script.txt @@ -385,7 +385,7 @@ SECTIONS build/asm/z_skin.o(.text) build/asm/z_skin_awb.o(.text) build/asm/code_0x80138BA0.o(.text) - build/asm/code_0x8013A240.o(.text) + build/src/code/z_snap.o(.text) build/asm/z_sub_s.o(.text) build/asm/code_0x8013EC10.o(.text) build/src/code/z_view.o(.text) diff --git a/src/code/z_snap.c b/src/code/z_snap.c new file mode 100644 index 0000000000..bbf9045232 --- /dev/null +++ b/src/code/z_snap.c @@ -0,0 +1,160 @@ +#include +#include + +typedef struct { + Actor actor; + s32 (*pictoFunc)(GlobalContext* ctxt, Actor* actor); +} PictoActor; + +s32 func_8013A240(GlobalContext* ctxt) { + PictoActor* pictoActor; + Actor* actor; + s32 type = 0; + s32 seen; + s32 count = 0; + + gSaveContext.perm.pictoFlags0 = 0; + gSaveContext.perm.pictoFlags1 = 0; + + if (ctxt->sceneNum == SCENE_20SICHITAI) { + func_8013A41C(1); + } + + for (; type < 12; type++) { + for (actor = ctxt->actorCtx.actorList[type].first; actor != NULL; actor = actor->next) { + seen = 0; + + switch (ctxt->sceneNum) { + case SCENE_20SICHITAI: + if ((actor->id == ACTOR_EN_MNK) || (actor->id == ACTOR_EN_BIGOKUTA)) { + seen = 1; + } + break; + default: + seen = 0; + } + + if (actor->id); // Needed to match + + switch (actor->id) { + case ACTOR_EN_KAKASI: + if ((actor->params & 1) == 1) { + seen |= 2; + break; //! @bug break is inside conditional, meaning it falls through if it is false + } + case ACTOR_EN_ZOV: + seen |= 2; + break; + case ACTOR_EN_BAL: + seen |= 2; + break; + case ACTOR_EN_DNQ: + seen |= 2; + break; + case ACTOR_EN_GE1: + case ACTOR_EN_GE3: + case ACTOR_EN_KAIZOKU: + case ACTOR_EN_GE2: + seen |= 2; + break; + } + + if (seen != 0) { + pictoActor = (PictoActor*)actor; + if (pictoActor->pictoFunc != NULL) { + if ((pictoActor->pictoFunc)(ctxt, actor) == 0) { + count++; + } + } + } + } + } + + return count; +} + +void func_8013A41C(s32 flag) { + if (flag < 0x20) { + gSaveContext.perm.pictoFlags0 |= (1 << flag); + } else { + flag &= 0x1F; + gSaveContext.perm.pictoFlags1 |= (1 << flag); + } +} + +void func_8013A46C(s32 flag) { + if (flag < 0x20) { + gSaveContext.perm.pictoFlags0 &= ~(1 << flag); + } else { + flag &= 0x1F; + gSaveContext.perm.pictoFlags1 &= ~(1 << flag); + } +} + +u32 func_8013A4C4(s32 flag) { + SaveContextPerm* save = &gSaveContext.perm; + if (flag < 0x20) { + return save->pictoFlags0 & (1 << flag); + } else { + flag &= 0x1F; + return save->pictoFlags1 & (1 << flag); + } +} + +s16 func_8013A504(s16 val) { + return (val >= 0) ? val : -val; +} + +s32 func_8013A530(GlobalContext* ctxt, Actor* actor, s32 flag, Vec3f* pos, Vec3s* rot, f32 distanceMin, f32 distanceMax, s16 angleError) { + Vec3f screenSpace; + s16 x; + s16 y; + f32 distance; + UNK_TYPE unk1; + Camera* camera; + Actor* actors[2]; + s32 ret = 0; + UNK_TYPE unk2; + + camera = ctxt->cameraCtx.activeCameraPtrs[ctxt->cameraCtx.activeCamera]; + + distance = CamMath_Distance(pos, &camera->eye); + if ((distance < distanceMin) || (distanceMax < distance)) { + func_8013A41C(0x3f); + ret = 0x3f; + } + + x = func_8013A504(func_800DFCB4(camera) + rot->x); + y = func_8013A504(func_800DFCDC(camera) - (s16)(rot->y - 0x7FFF)); + if ((0 < angleError) && ((angleError < x) || (angleError < y))) { + func_8013A41C(0x3e); + ret |= 0x3e; + } + + func_800B4EDC(ctxt, pos, &screenSpace, &distance); + x = (s16)(screenSpace.x * distance * 160.0f + 160.0f) - 85; + y = (s16)(screenSpace.y * distance * -120.0f + 120.0f) - 67; + if ((x < 0) || (0x96 < x) || (y < 0) || (0x69 < y)) { + func_8013A41C(0x3d); + ret |= 0x3d; + } + + if (func_800C576C(&ctxt->colCtx, pos, &camera->eye, &screenSpace, &unk1, 1, 1, 1, 1, &unk2) != 0) { + func_8013A41C(0x3c); + ret |= 0x3c; + } + + actors[0] = actor; + actors[1] = ctxt->actorCtx.actorList[2].first; // TODO PLAYER macro + if (func_800E7DCC(ctxt, &ctxt->colCheckCtx, pos, &camera->eye, actors, 2) != 0) { + func_8013A41C(0x3b); + ret |= 0x3b; + } + + if (ret == 0) { + func_8013A41C(flag); + } + + return ret; +} + diff --git a/tables/objects.txt b/tables/objects.txt index 82d493a439..33946ce7b7 100644 --- a/tables/objects.txt +++ b/tables/objects.txt @@ -323,7 +323,7 @@ 0x80137970:"z_skin", 0x80138410:"z_skin_awb", 0x80138BA0:"", - 0x8013A240:"", + 0x8013A240:"z_snap", 0x8013A7C0:"z_sub_s", 0x8013EC10:"", 0x8013EE60:"z_view",