From 5123729e01a32d76704ea71d15e9ab0b860f85a6 Mon Sep 17 00:00:00 2001 From: Zac Date: Sun, 27 Oct 2024 01:54:25 +0000 Subject: [PATCH] Match SetFsp --- config/symbol_addrs.txt | 7 ++++ include/clock.h | 5 +++ include/common.h | 1 + include/jt.h | 92 +++++++++++++++++++++++++++++++++++++++-- include/po.h | 9 +++- include/screen.h | 13 +++++- include/steppower.h | 20 ++++++--- include/steprail.h | 21 ++++++++++ include/types.h | 1 + include/vtables.h | 83 ++++++++++++++++++++----------------- src/P2/steppower.c | 57 ++++++++++++++++++++++++- src/P2/steprail.c | 6 +++ 12 files changed, 263 insertions(+), 52 deletions(-) create mode 100644 include/steprail.h create mode 100644 src/P2/steprail.c diff --git a/config/symbol_addrs.txt b/config/symbol_addrs.txt index ed22d845..efaf9899 100644 --- a/config/symbol_addrs.txt +++ b/config/symbol_addrs.txt @@ -763,6 +763,13 @@ RT_JtSpeedUpClock = 0x274f84; // size:0x4 RT_JtSlowDownClock = 0x274f88; // size:0x4 +//////////////////////////////////////////////////////////////// +// P2/steprail.c +//////////////////////////////////////////////////////////////// +func_001D32D8__FiP2JTl = 0x1D32D8; // type:func +func_001D31D0__FP2LOi = 0x1D31D0; // type:func + + //////////////////////////////////////////////////////////////// // P2/sw.c //////////////////////////////////////////////////////////////// diff --git a/include/clock.h b/include/clock.h index f3dc050b..f5f70076 100644 --- a/include/clock.h +++ b/include/clock.h @@ -24,6 +24,11 @@ struct CLOCK TICK tickFrame; }; +extern float g_rtClock; +extern float g_rtClockPowerUp; +extern CLOCK g_clock; +//extern TICK s_tickLastRaw;; // Should be static? + /** * @brief Sets the rate of the global clock. * diff --git a/include/common.h b/include/common.h index c38596cb..60923733 100644 --- a/include/common.h +++ b/include/common.h @@ -9,6 +9,7 @@ #include "include_asm.h" #include "include_rodata.h" #include "types.h" +#include "vtables.h" /** * @brief RGBA color value. diff --git a/include/jt.h b/include/jt.h index 939622fd..ed15149e 100644 --- a/include/jt.h +++ b/include/jt.h @@ -9,22 +9,108 @@ #include "common.h" #include +/** + * JT state. + * + * @note Based on May proto, may be inaccurate. + */ +enum JTS +{ + JTS_Stand = 0, + JTS_Run = 1, + JTS_Jump = 2, + JTS_Hang = 3, + JTS_Zap = 4, + JTS_Sidestep = 5, + JTS_Hide = 6, + JTS_Pipe = 7, + JTS_Edge = 8, + JTS_Celebrate = 9, + JTS_Rush = 10, + JTS_Puppet = 11, + JTS_Peek = 12, + JTS_Ski = 13, + JTS_Ball = 14, + JTS_Max = 15 +}; + +/** + * JT body state. + * + * @note Based on May proto, may be inaccurate. + */ +enum JTBS +{ + JTBS_Nil = -1, + JTBS_Jump_Init = 0, + JTBS_Jump_Rise = 1, + JTBS_Jump_Fall = 2, + JTBS_Jump_Boost = 3, + JTBS_Jump_In = 4, + JTBS_Jump_Out = 5, + JTBS_Jump_Thrown = 6, + JTBS_Jump_Smash = 7, + JTBS_Jump_Dive = 8, + JTBS_Jump_Target = 9, + JTBS_Jump_Spire = 10, + JTBS_Jump_Rail = 11, + JTBS_Jump_Hshape = 12, + JTBS_Jump_Hpnt = 13, + JTBS_Hide_Stand = 14, + JTBS_Hide_Sidestep = 15, + JTBS_Hide_PeekLeft = 16, + JTBS_Hide_PeekRight = 17, + JTBS_Hide_Run = 18, + JTBS_Hide_Spin = 19, + JTBS_Pipe_Init = 20, + JTBS_Pipe_Stay = 21, + JTBS_Pipe_Up = 22, + JTBS_Pipe_Down = 23, + JTBS_Pipe_Spin = 24, + JTBS_Celebrate_Key = 25, + JTBS_Celebrate_Timed = 26, + JTBS_Celebrate_UseKey = 27, + JTBS_Rush_Attack = 28, + JTBS_Rush_Bounce = 29, + JTBS_Peek_Enter = 30, + JTBS_Peek_Peek = 31, + JTBS_Peek_Exit = 32, + JTBS_Zap_Blunt = 33, + JTBS_Zap_Electric = 34, + JTBS_Zap_Fire = 35, + JTBS_Zap_Water = 36 +}; + /** * @brief Sly entity. * * JT = "jewel thief" = codename for Sly. * - * @todo Implement struct. + * @todo Match all structs it inherits from. */ struct JT : public STEP { - // ... + uchar padding[0x1248]; + LO *ploMine_1518; + uchar padding2[0xd03]; + int unk2220; + uchar padding3[0x52c]; + int unk2750; }; +/** + * @brief Sets the JT state and JT body state on the given JT. + * + * @param pjt Pointer to the JT instance. + * @param jts JT state value + * @param JTBS JT body state value + */ +void SetJtJts(JT *pjt, JTS jts, JTBS jtbs); + /** * @brief Stubbed, does nothing. * - * @param pjt Pointer to JT entity. + * @param pjt Pointer to JT instance. * @param fProfile Profile flag. * * @deprecated diff --git a/include/po.h b/include/po.h index a404b8ad..db0d0250 100644 --- a/include/po.h +++ b/include/po.h @@ -10,13 +10,18 @@ #include /** - * @brief TBD + * @brief Player object. * - * @todo Implement struct. + * @todo Implement struct fields. */ struct PO : public SO { // ... }; +/** + * @brief Gets a pointer to the current PO. + */ +PO *PpoCur(); + #endif // PO_H diff --git a/include/screen.h b/include/screen.h index 7b8d2a03..d30ac360 100644 --- a/include/screen.h +++ b/include/screen.h @@ -53,7 +53,8 @@ struct BLOTI struct BLOT { union { - void *pvtblot; + VTBLOT *pvtblot; + VTNOTE *pvtnote; }; CFont *pfont; char achzDraw[512]; @@ -144,9 +145,17 @@ extern TOTALS g_totals; struct NOTE : public BLOT { - // empty + u32 unk260; + u32 unk264; + u32 unk268; + u32 unk26C; + u32 unk270; + u32 unk274; + struct NOTE* unk278; }; +extern NOTE g_note; + // MARK: Letterbox struct LETTERBOX : public BLOT diff --git a/include/steppower.h b/include/steppower.h index 2a5f8b1e..b315a512 100644 --- a/include/steppower.h +++ b/include/steppower.h @@ -13,14 +13,19 @@ */ enum FSP { - FSP_Nil = -1, - FSP_Dive = 0, - FSP_SpeedUpClock = 1, - FSP_SlowDownClock = 2, - FSP_Ball = 3, - FSP_Max = 4 + FSP_Nil=-1, + FSP_Dive=0, + FSP_Ball=1, + FSP_SlowDownClock=2, + FSP_Mine=3, + FSP_SpeedUpClock=4, + FSP_Decoy=5, + FSP_Stun=6, + FSP_Max=7 }; +extern FSP g_fsp; + /*static const char *s_mpfspachz[] = { "&2T&.: Dive", "&2T&.: Roll", @@ -32,6 +37,9 @@ enum FSP };*/ extern const char *s_mpfspachz[]; +extern float RT_JtSpeedUpClock; +extern float RT_JtSlowDownClock; + /** * @brief Set the selected powerup. */ diff --git a/include/steprail.h b/include/steprail.h new file mode 100644 index 00000000..65ed6223 --- /dev/null +++ b/include/steprail.h @@ -0,0 +1,21 @@ +/** + * @file steprail.h + * + * @brief Rail behavior for STEP objects. + */ +#ifndef STEPRAIL_H +#define STEPRAIL_H +#include "common.h" +#include + +/** + * @brief Unknown function, more research needed. + */ +void func_001D31D0(LO *param_1, int param_2); + +/** + * @brief Unknown function, more research needed. + */ +void func_001D32D8(int param_1, JT *param_2, long param_3); + +#endif // STEPRAIL_H diff --git a/include/types.h b/include/types.h index 7ca8ab9d..755f228b 100644 --- a/include/types.h +++ b/include/types.h @@ -52,5 +52,6 @@ typedef float f32; typedef double f64; typedef uint size_t; +#define nullptr (void *)0x0 #endif // TYPES_H diff --git a/include/vtables.h b/include/vtables.h index f1a1d6e0..11da9cfe 100644 --- a/include/vtables.h +++ b/include/vtables.h @@ -1,45 +1,52 @@ +#ifndef VTABLES_H +#define VTABLES_H + +struct BLOT; + struct VTBLOT { - void *pfnInitBlot; - void *pfnPostBlotLoad; - void *pfnUpdateBlot; - void *pfnOnBlotActive; - void *pfnUpdateBlotActive; - void *pfnOnBlotReset; - void *pfnOnBlotPush; - void *pfnOnBlotPop; - void *pfnSetBlotAchzDraw; - void *pfnDrawBlot; - void *pfnRenderBlot; - void *pfnDtAppearBlot; - void *pfnDtVisibleBlot; - void *pfnDtDisappearBlot; - void *pfnShowBlot; - void *pfnHideBlot; - void *pfnSetBlotBlots; - void *pfnSetBlotClock; - void *pfnFIncludeBlotForPeg; + void (*pfnInitBlot)(BLOT *); + void (*pfnPostBlotLoad)(BLOT *); + void (*pfnUpdateBlot)(BLOT *); + void (*pfnOnBlotActive)(BLOT *); + void (*pfnUpdateBlotActive)(BLOT *); + void (*pfnOnBlotReset)(BLOT *); + void (*pfnOnBlotPush)(BLOT *); + void (*pfnOnBlotPop)(BLOT *); + void (*pfnSetBlotAchzDraw)(BLOT *, const char *); + void (*pfnDrawBlot)(BLOT *); + void (*pfnRenderBlot)(BLOT *); + void (*pfnDtAppearBlot)(BLOT *); + void (*pfnDtVisibleBlot)(BLOT *); + void (*pfnDtDisappearBlot)(BLOT *); + void (*pfnShowBlot)(BLOT *); + void (*pfnHideBlot)(BLOT *); + void (*pfnSetBlotBlots)(BLOT *); + void (*pfnSetBlotClock)(BLOT *); + int (*pfnFIncludeBlotForPeg)(BLOT *); }; struct VTNOTE { - void *pfnInitBlot; - void *pfnPostNoteLoad; - void *pfnUpdateBlot; - void *pfnOnBlotActive; - void *pfnUpdateBlotActive; - void *pfnOnBlotReset; - void *pfnOnBlotPush; - void *pfnOnBlotPop; - void *pfnSetNoteAchzDraw; - void *pfnDrawNote; - void *pfnRenderBlot; - void *pfnDtAppearBlot; - void *pfnDtVisibleBlot; - void *pfnDtDisappearBlot; - void *pfnShowBlot; - void *pfnHideBlot; - void *pfnSetBlotBlots; - void *pfnSetBlotClock; - void *pfnFIncludeBlotForPeg; + void (*pfnInitBlot)(BLOT *); + void (*pfnPostNoteLoad)(BLOT *); + void (*pfnUpdateBlot)(BLOT *); + void (*pfnOnBlotActive)(BLOT *); + void (*pfnUpdateBlotActive)(BLOT *); + void (*pfnOnBlotReset)(BLOT *); + void (*pfnOnBlotPush)(BLOT *); + void (*pfnOnBlotPop)(BLOT *); + void (*pfnSetNoteAchzDraw)(BLOT *, const char *); + void (*pfnDrawNote)(BLOT *); + void (*pfnRenderBlot)(BLOT *); + void (*pfnDtAppearBlot)(BLOT *); + void (*pfnDtVisibleBlot)(BLOT *); + void (*pfnDtDisappearBlot)(BLOT *); + void (*pfnShowBlot)(BLOT *); + void (*pfnHideBlot)(BLOT *); + void (*pfnSetBlotBlots)(BLOT *); + void (*pfnSetBlotClock)(BLOT *); + int (*pfnFIncludeBlotForPeg)(BLOT *); }; + +#endif // VTABLES_H diff --git a/src/P2/steppower.c b/src/P2/steppower.c index f68842dc..797c2092 100644 --- a/src/P2/steppower.c +++ b/src/P2/steppower.c @@ -1,7 +1,62 @@ #include "steppower.h" #include +#include +#include +#include +#include +#define N_POWERUP_MAX 7U -INCLUDE_ASM(const s32, "P2/steppower", SetFsp__F3FSP); +//FSP g_fsp = FSP_Nil; + +void SetFsp(FSP fsp) { + // Cleanup current powerup + switch (g_fsp) { + case FSP_Ball: + // If cur powerup is roll, reset JT's body state + if (g_pjt != nullptr && g_pjt->unk2220 == 13) { + SetJtJts(g_pjt, JTS_Stand, JTBS_Nil); + } + break; + case FSP_Mine: + // If cur powerup is mine, fade out the mine + if (g_pjt != nullptr) { + LO *ploMine = g_pjt->ploMine_1518; + if ((ploMine != nullptr) && (FIsLoInWorld(ploMine))) { + FadeAloOut((ALO *)g_pjt->ploMine_1518, 0.5f); + } + } + break; + default: + break; + } + + if (g_pjt != nullptr) { + g_rtClockPowerUp = 1.0f; + if ((g_pjt->unk2750 != 0) && FIsLoInWorld((JT*)g_pjt->unk2750)) { + func_001D32D8(g_pjt->unk2750, g_pjt, 1); + } + + func_001D31D0(g_pjt, 0); + if (g_pjt != nullptr && g_pjt == PpoCur()) { + g_fsp = fsp; + } + } + + // If fsp is unchanged or invalid, return + int nPowerupLast = g_pgsCur->nPowerupLast; + if (fsp == nPowerupLast || fsp >= N_POWERUP_MAX) { + return; + } + + // Show note + SetBlotDtVisible((NOTE*)&g_note.unk278, (g_pjt != nullptr) && (g_pjt == PpoCur()) ? 3.0 : 8.0); + SetBlotFontScale(0.6, (NOTE*)&g_note.unk278); + ((NOTE*)&g_note.unk278)->pvtnote->pfnSetNoteAchzDraw((NOTE*)&g_note.unk278, s_mpfspachz[fsp]); + ((NOTE*)&g_note.unk278)->pvtnote->pfnShowBlot((NOTE*)&g_note.unk278); + + // Update last powerup index + g_pgsCur->nPowerupLast = fsp; +} INCLUDE_ASM(const s32, "P2/steppower", UpdateJtActivePowerUp__FP2JTP3JOY); diff --git a/src/P2/steprail.c b/src/P2/steprail.c new file mode 100644 index 00000000..45341daf --- /dev/null +++ b/src/P2/steprail.c @@ -0,0 +1,6 @@ +/** + * @file steprail.c + * + * @brief Rail behavior for STEP objects. + */ +#include