diff --git a/include/d/actor/d_a_e_hz.h b/include/d/actor/d_a_e_hz.h index 7e5902e016d..539d808cf5e 100644 --- a/include/d/actor/d_a_e_hz.h +++ b/include/d/actor/d_a_e_hz.h @@ -87,7 +87,7 @@ class daE_HZ_c : public fopEn_enemy_c { /* 0x6B4 */ s16 field_0x6b4; /* 0x6B6 */ s16 field_0x6b6; /* 0x6B8 */ u8 field_0x6B8[0x6BC - 0x6B8]; - /* 0x6BC */ char* mpName; + /* 0x6BC */ const char* mpName; /* 0x6C0 */ s32 mAction; /* 0x6C4 */ s32 mPrevAction; /* 0x6C8 */ s32 mMode; // That's just a guess. Might need a better name for it's usage diff --git a/include/d/actor/d_a_npc2.h b/include/d/actor/d_a_npc2.h index ea5548696a0..d1d06d7764f 100644 --- a/include/d/actor/d_a_npc2.h +++ b/include/d/actor/d_a_npc2.h @@ -134,7 +134,7 @@ class daBaseNpc_c : public fopAc_ac_c { /* 0x842 */ u16 field_0x842; /* 0x844 */ u8 field_0x844; /* 0x845 */ u8 field_0x845[0x848 - 0x845]; - /* 0x848 */ s32 field_0x848; + /* 0x848 */ s32 mFlowID; /* 0x84C */ dMsgFlow_c mMsgFlow; /* 0x898 */ u8 field_0x898[0x89A - 0x898]; /* 0x89A */ s16 mEvtIdx; diff --git a/include/d/actor/d_a_npc_bouS.h b/include/d/actor/d_a_npc_bouS.h index bd3b1ff0b6b..27eafb48fd2 100644 --- a/include/d/actor/d_a_npc_bouS.h +++ b/include/d/actor/d_a_npc_bouS.h @@ -72,7 +72,7 @@ class daNpcBouS_c : public daNpcF_c { void setExpression(int, f32); bool talk(void*); bool demo(void*); - inline fopAc_ac_c* searchInstructionTag(); + inline fopAc_ac_c* searchInstructionTag(); bool instruction(void*); bool checkIntroDemoStart(); int EvCut_BousIntroSumo1(int); diff --git a/include/d/actor/d_a_npc_gra.h b/include/d/actor/d_a_npc_gra.h index 3209329a76f..236755aba70 100644 --- a/include/d/actor/d_a_npc_gra.h +++ b/include/d/actor/d_a_npc_gra.h @@ -160,7 +160,7 @@ class daNpc_grA_c : public daNpcF_c { /* 0x14B0 */ int field_0x1460; /* 0x1464 */ int field_0x1464; /* 0x1468 */ int field_0x1468; - /* 0x146C */ int field_0x146C; + /* 0x146C */ int mFlowID; /* 0x1470 */ s16 mLookMode; /* 0x1472 */ u16 field_0x1472; /* 0x1474 */ u8 mType; diff --git a/include/d/actor/d_a_npc_grs.h b/include/d/actor/d_a_npc_grs.h index 202dd252674..d2a0c5359d5 100644 --- a/include/d/actor/d_a_npc_grs.h +++ b/include/d/actor/d_a_npc_grs.h @@ -103,7 +103,7 @@ class daNpc_grS_c : public daNpcF_c { /* 0xE00 */ int field_0xe00; /* 0xE04 */ int field_0xe04; /* 0xE08 */ int field_0xe08; - /* 0xE0C */ int field_0xe0c; + /* 0xE0C */ int mFlowID; /* 0xE10 */ s16 mLookMode; /* 0xE12 */ u16 mActionState; /* 0xE14 */ u8 mType; diff --git a/include/d/actor/d_a_npc_gwolf.h b/include/d/actor/d_a_npc_gwolf.h index adcdb75adb2..fcf5d804d0d 100644 --- a/include/d/actor/d_a_npc_gwolf.h +++ b/include/d/actor/d_a_npc_gwolf.h @@ -121,7 +121,7 @@ class daNpc_GWolf_c : public daNpcF_c { /* 0xDFC */ int field_0xdfc; /* 0xE00 */ int field_0xe00; /* 0xE04 */ int field_0xe04; - /* 0xE08 */ int field_0xe08; + /* 0xE08 */ int mFlowID; /* 0xE0C */ s16 mLookMode; /* 0xE0E */ u16 mMode; /* 0xE10 */ u8 mType; diff --git a/include/d/actor/d_a_npc_kasi_hana.h b/include/d/actor/d_a_npc_kasi_hana.h index 54b0cf914b7..e355ed8c554 100644 --- a/include/d/actor/d_a_npc_kasi_hana.h +++ b/include/d/actor/d_a_npc_kasi_hana.h @@ -182,7 +182,8 @@ class daNpcKasiHana_c : public daNpcF_c { s16 getMessageNo() { return s16(home.angle.x); } s8 getType() { s8 rv = fopAcM_GetParam(this) & 0xFF; - + + // !@bug Comparison of s8 with 0xFF will always evaluate to false if (rv == 0xFF) { rv = 0; } diff --git a/include/d/actor/d_a_npc_kasi_kyu.h b/include/d/actor/d_a_npc_kasi_kyu.h index 9ca549e46c7..0387c563b78 100644 --- a/include/d/actor/d_a_npc_kasi_kyu.h +++ b/include/d/actor/d_a_npc_kasi_kyu.h @@ -98,7 +98,8 @@ class daNpcKasiKyu_c : public daNpcF_c { s8 getType() { s8 rv = fopAcM_GetParam(this) & 0xFF; - + + // !@bug Comparison of s8 with 0xFF will always evaluate to false if (rv == 0xFF) { rv = 0; } diff --git a/include/d/actor/d_a_npc_kasi_mich.h b/include/d/actor/d_a_npc_kasi_mich.h index 9f38d3dd1c3..e3782f1b27d 100644 --- a/include/d/actor/d_a_npc_kasi_mich.h +++ b/include/d/actor/d_a_npc_kasi_mich.h @@ -99,7 +99,8 @@ class daNpcKasiMich_c : public daNpcF_c { s8 getType() { s8 rv = fopAcM_GetParam(this) & 0xFF; - + + // !@bug Comparison of s8 with 0xFF will always evaluate to false if (rv == 0xFF) { rv = 0; } diff --git a/include/d/actor/d_a_npc_kn.h b/include/d/actor/d_a_npc_kn.h index a14a89aefe9..e97431baef0 100644 --- a/include/d/actor/d_a_npc_kn.h +++ b/include/d/actor/d_a_npc_kn.h @@ -77,7 +77,7 @@ class daNpc_Kn_c : public fopEn_enemy_c { class daNpc_Kn_prtclMngr_c { public: - /* 0x00 */ bool mpModel; + /* 0x00 */ bool field_0x00; /* 0x04 */ cXyz mPos; /* 0x10 */ csXyz mAngle; /* 0x18 */ cXyz mScale; diff --git a/include/d/actor/d_a_npc_ks.h b/include/d/actor/d_a_npc_ks.h index ba14540735d..7ec5fd129d8 100644 --- a/include/d/actor/d_a_npc_ks.h +++ b/include/d/actor/d_a_npc_ks.h @@ -89,7 +89,7 @@ class npc_ks_class { /* 0x5B7 */ u8 field_0x5b7; /* 0x5B8 */ int order; /* 0x5BC */ int bitTRB; - /* 0x5C0 */ char* res_name; + /* 0x5C0 */ const char* res_name; /* 0x5C4 */ f32 dis; /* 0x5C8 */ s16 target_angle; /* 0x5CC */ mDoExt_McaMorfSO* model; diff --git a/include/d/actor/d_a_npc_myna2.h b/include/d/actor/d_a_npc_myna2.h index bf97f43124b..ac6af4d8f70 100644 --- a/include/d/actor/d_a_npc_myna2.h +++ b/include/d/actor/d_a_npc_myna2.h @@ -104,7 +104,7 @@ class daNpc_myna2_c : public daNpcF_c { /* 0xDF8 */ int field_0xdf8; /* 0xDFC */ int field_0xdfc; /* 0xE00 */ int field_0xe00; - /* 0xE04 */ int field_0xe04; + /* 0xE04 */ int mFlowID; /* 0xE08 */ s16 mLookMode; /* 0xE0A */ u16 mMode; /* 0xE0C */ u8 mType; diff --git a/include/d/actor/d_a_npc_ne.h b/include/d/actor/d_a_npc_ne.h index 10474cc8289..51f9f06e816 100644 --- a/include/d/actor/d_a_npc_ne.h +++ b/include/d/actor/d_a_npc_ne.h @@ -95,7 +95,7 @@ class npc_ne_class : public fopEn_enemy_c { /* 0x5D8 */ f32 mDistToTarget; /* 0x5DC */ s16 mAngleToPlayer; /* 0x5E0 */ f32 mDistScale; - /* 0x5E4 */ char* mResName; + /* 0x5E4 */ const char* mResName; /* 0x5E8 */ mDoExt_McaMorf* mpMorf; /* 0x5EC */ mDoExt_btkAnm* mpBtkAnm; /* 0x5F0 */ mDoExt_btpAnm* mpBtpAnm; diff --git a/include/d/actor/d_a_tag_push.h b/include/d/actor/d_a_tag_push.h index 3a20b5ed77f..a1f0b75b228 100644 --- a/include/d/actor/d_a_tag_push.h +++ b/include/d/actor/d_a_tag_push.h @@ -24,6 +24,9 @@ class daTag_Push_c : public fopAc_ac_c { u8 getBitSW2() { return (fopAcM_GetParam(this) & 0xFF00) >> 8; } u32 getFlowNodeNo() { + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { return (u16)home.angle.x; } diff --git a/include/d/actor/d_a_tag_shop_item.h b/include/d/actor/d_a_tag_shop_item.h index 826f867ad87..1b04b6ef8e2 100644 --- a/include/d/actor/d_a_tag_shop_item.h +++ b/include/d/actor/d_a_tag_shop_item.h @@ -19,6 +19,10 @@ class daTag_ShopItem_c : public fopAc_ac_c { u32 getProcessID() { return mProcessID; } + int getFlowNodeNum() { + return (u16)home.angle.x == 0xFFFF ? -1 : (u16)home.angle.x; + } + /* 0x56C */ u32 mProcessID; /* 0x570 */ s16 mCreateTimer; /* 0x572 */ u8 field_0x572; diff --git a/include/d/d_demo.h b/include/d/d_demo.h index 45e99a85d9a..ff0a2fe9de9 100644 --- a/include/d/d_demo.h +++ b/include/d/d_demo.h @@ -336,27 +336,6 @@ class dDemo_particle_c : public JStudio_JParticle::TCreateObject { virtual JPABaseEmitter* emitter_create(u32); }; -namespace { -class jstudio_tAdaptor_message : public JStudio::TAdaptor_message { -public: - typedef JStudio::TObject_message ObjectType; - - jstudio_tAdaptor_message() {} - - virtual ~jstudio_tAdaptor_message(); - virtual void adaptor_do_MESSAGE(JStudio::data::TEOperationData, const void*, u32); -}; - -class jstudio_tCreateObject_message : public JStudio::TCreateObject { -public: - jstudio_tCreateObject_message() {} - - virtual ~jstudio_tCreateObject_message(); - virtual bool create(JStudio::TObject**, const JStudio::stb::data::TParse_TBlock_object&); -}; - -}; // namespace - int dDemo_setDemoData(fopAc_ac_c*, u8, mDoExt_McaMorf*, char const*, int, u16*, u32, s8); class dDemo_c { @@ -405,7 +384,7 @@ class dDemo_c { static JStudio_JStage::TCreateObject* m_stage; static JStudio_JAudio2::TCreateObject* m_audio; static dDemo_particle_c* m_particle; - static jstudio_tCreateObject_message* m_message; + static JStudio::TCreateObject* m_message; static JStudio::TFactory* m_factory; static jmessage_tControl* m_mesgControl; static dDemo_object_c* m_object; diff --git a/include/d/d_menu_window.h b/include/d/d_menu_window.h index 35c67891278..65e415077df 100644 --- a/include/d/d_menu_window.h +++ b/include/d/d_menu_window.h @@ -190,7 +190,7 @@ class dMw_c : public msg_class { bool isPauseWindow() { return mPauseWindow != false; } void onShowFlag() { mShowFlag |= 1; } void offShowFlag() { mShowFlag &= ~1; } - bool isShowFlag() { return mShowFlag & 1 != 0; } + bool isShowFlag() { return (mShowFlag & 1) != 0; } bool isFadeNowCheck() { return mDoGph_gInf_c::getFader()->getStatus() == 1; } private: diff --git a/include/d/d_msg_scrn_howl.h b/include/d/d_msg_scrn_howl.h index aa51249e170..bf28682d425 100644 --- a/include/d/d_msg_scrn_howl.h +++ b/include/d/d_msg_scrn_howl.h @@ -112,7 +112,4 @@ struct dMsgScrnHowl_c : public dMsgScrnBase_c { /* 0x27A8 */ f32 field_0x27a8; }; -#define LINE_MAX 30 -#define PLOT_BUFFER_MAX_e 0x300 - #endif /* MSG_SCRN_D_MSG_SCRN_HOWL_H */ diff --git a/include/f_op/f_op_actor_mng.h b/include/f_op/f_op_actor_mng.h index 8bfa4c068ea..d6ef3605a15 100644 --- a/include/f_op/f_op_actor_mng.h +++ b/include/f_op/f_op_actor_mng.h @@ -425,11 +425,11 @@ inline void fopAcM_SetAngle(fopAc_ac_c* i_actor, s16 x, s16 y, s16 z) { i_actor->current.angle.set(x, y, z); } -inline void dComIfGs_onSwitch(int i_no, int i_roomNo); -inline void dComIfGs_offSwitch(int i_no, int i_roomNo); -inline void dComIfGs_revSwitch(int i_no, int i_roomNo); -inline BOOL dComIfGs_isSwitch(int i_no, int i_roomNo); -inline void dComIfGs_offActor(int i_no, int i_roomNo); +void dComIfGs_onSwitch(int i_no, int i_roomNo); +void dComIfGs_offSwitch(int i_no, int i_roomNo); +void dComIfGs_revSwitch(int i_no, int i_roomNo); +BOOL dComIfGs_isSwitch(int i_no, int i_roomNo); +void dComIfGs_offActor(int i_no, int i_roomNo); inline void fopAcM_onSwitch(const fopAc_ac_c* i_actor, int sw) { return dComIfGs_onSwitch(sw, fopAcM_GetHomeRoomNo(i_actor)); @@ -451,12 +451,12 @@ inline fopAc_ac_c* fopAcM_SearchByName(s16 proc_id) { return (fopAc_ac_c*)fopAcIt_Judge(fpcSch_JudgeForPName, &proc_id); } -inline void dComIfGs_onItem(int bitNo, int roomNo); +void dComIfGs_onItem(int bitNo, int roomNo); inline void fopAcM_onItem(const fopAc_ac_c* item, int bitNo) { dComIfGs_onItem(bitNo, fopAcM_GetHomeRoomNo(item)); } -inline bool dComIfGs_isItem(int bitNo, int roomNo); +bool dComIfGs_isItem(int bitNo, int roomNo); inline bool fopAcM_isItem(const fopAc_ac_c* item, int bitNo) { return dComIfGs_isItem(bitNo, fopAcM_GetHomeRoomNo(item)); } @@ -469,7 +469,7 @@ inline int fopAcM_GetSetId(const fopAc_ac_c* i_actor) { return i_actor->setID; } -inline void dComIfGs_onActor(int bitNo, int roomNo); +void dComIfGs_onActor(int bitNo, int roomNo); inline void fopAcM_onActor(const fopAc_ac_c* i_actor) { dComIfGs_onActor(fopAcM_GetSetId(i_actor), fopAcM_GetHomeRoomNo(i_actor)); @@ -704,7 +704,7 @@ inline void make_prm_warp_hole(u32* o_params, u8 prm1, u8 prm2, u8 prm3) { *o_params = pprm2 | pprm3 | pprm1; } -inline fopAc_ac_c* dComIfGp_getPlayer(int); +fopAc_ac_c* dComIfGp_getPlayer(int); inline s16 fopAcM_searchPlayerAngleY(const fopAc_ac_c* actor) { return fopAcM_searchActorAngleY(actor, dComIfGp_getPlayer(0)); diff --git a/include/global.h b/include/global.h index fc8abb5431e..a8c2b0e07e6 100644 --- a/include/global.h +++ b/include/global.h @@ -106,7 +106,7 @@ static const float INF = 2000000000.0f; #define NO_INLINE #endif #endif - + // Hack to trick the compiler into not inlining functions that use this macro. #define FORCE_DONT_INLINE \ (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \ @@ -176,4 +176,15 @@ static const float INF = 2000000000.0f; using std::isnan; #endif +// Comparing a non-volatile reference type to NULL is tautological +// and triggers a warning on modern compilers, but in some cases is +// required to match the original assembly. +#if defined(__MWERKS__) || defined(DECOMPCTX) +#define IS_REF_NULL(r) (&(r) == NULL) +#define IS_REF_NONNULL(r) (&(r) != NULL) +#else +#define IS_REF_NULL(r) (0) +#define IS_REF_NONNULL(r) (1) +#endif + #endif diff --git a/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DMaterialAnm.h b/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DMaterialAnm.h index ff41bc4f01a..4c3f0f75bbe 100644 --- a/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DMaterialAnm.h +++ b/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DMaterialAnm.h @@ -3,6 +3,8 @@ #include "JSystem/J3DGraphAnimator/J3DAnimation.h" +class J3DMaterial; + /** * @ingroup jsystem-j3d * diff --git a/libs/JSystem/src/JAudio2/JASAramStream.cpp b/libs/JSystem/src/JAudio2/JASAramStream.cpp index ea0fb5776fe..68a1b7988c7 100644 --- a/libs/JSystem/src/JAudio2/JASAramStream.cpp +++ b/libs/JSystem/src/JAudio2/JASAramStream.cpp @@ -434,7 +434,7 @@ void JASAramStream::updateChannel(u32 i_callbackType, JASChannel* i_channel, field_0x120 = 0; field_0x12c |= 2; if (field_0x0c4 < 0xffffffff) { - field_0x0c4++; + field_0x0c4 += 1; } field_0x0c0 = false; } diff --git a/libs/JSystem/src/JAudio2/JASAudioThread.cpp b/libs/JSystem/src/JAudio2/JASAudioThread.cpp index be06ff53888..8be67f3d60d 100644 --- a/libs/JSystem/src/JAudio2/JASAudioThread.cpp +++ b/libs/JSystem/src/JAudio2/JASAudioThread.cpp @@ -89,7 +89,7 @@ void* JASAudioThread::run() { case AUDIOMSG_DSP: JUT_ASSERT(125, snIntCount != 0); - snIntCount--; + snIntCount -= 1; if (snIntCount == 0) { JASProbe::stop(7); JASDriver::finishDSPFrame(); diff --git a/libs/JSystem/src/JAudio2/JASBasicBank.cpp b/libs/JSystem/src/JAudio2/JASBasicBank.cpp index 510d7a718d6..5a5a21be3dc 100644 --- a/libs/JSystem/src/JAudio2/JASBasicBank.cpp +++ b/libs/JSystem/src/JAudio2/JASBasicBank.cpp @@ -21,7 +21,7 @@ bool JASBasicBank::getInstParam(int prg_no, int param_1, int param_2, JASInstParam* o_param) const { JASInst* inst = getInst(prg_no); if (inst == NULL) { - return NULL; + return false; } return inst->getParam(param_1, param_2, o_param); } diff --git a/libs/JSystem/src/JAudio2/JASCalc.cpp b/libs/JSystem/src/JAudio2/JASCalc.cpp index 339e09e4c6f..55d40826234 100644 --- a/libs/JSystem/src/JAudio2/JASCalc.cpp +++ b/libs/JSystem/src/JAudio2/JASCalc.cpp @@ -5,7 +5,7 @@ #include void JASCalc::imixcopy(const s16* s1, const s16* s2, s16* dst, u32 n) { - for (n; n != 0; n--) { + for (; n != 0; n--) { *dst++ = *(s1)++; *dst++ = *(s2)++; } diff --git a/libs/JSystem/src/JAudio2/JASSeqParser.cpp b/libs/JSystem/src/JAudio2/JASSeqParser.cpp index e68d880e173..fa3060952ac 100644 --- a/libs/JSystem/src/JAudio2/JASSeqParser.cpp +++ b/libs/JSystem/src/JAudio2/JASSeqParser.cpp @@ -295,7 +295,7 @@ u32 JASSeqParser::readReg(JASTrack* param_0, u32 param_1) const { case 0x6a: result = param_0->getReleasePrio(); // @bug this should have been <<= - result << 8; + (void)(result << 8); result |= param_0->getNoteOnPrio(); break; case 0x6b: diff --git a/libs/JSystem/src/JParticle/JPABaseShape.cpp b/libs/JSystem/src/JParticle/JPABaseShape.cpp index fffcf05cad1..f28add564e5 100644 --- a/libs/JSystem/src/JParticle/JPABaseShape.cpp +++ b/libs/JSystem/src/JParticle/JPABaseShape.cpp @@ -1260,7 +1260,7 @@ JPABaseShape::JPABaseShape(u8 const* pData, JKRHeap* pHeap) { } if (isTexAnm()) { - JUT_ASSERT(1698, pBsd->texAnmKeyNum != NULL); + JUT_ASSERT(1698, pBsd->texAnmKeyNum != 0); u32 offs = sizeof(JPABaseShapeData); if (isTexCrdAnm()) { offs += 0x28; @@ -1271,7 +1271,7 @@ JPABaseShape::JPABaseShape(u8 const* pData, JKRHeap* pHeap) { } if (isPrmAnm()) { - JUT_ASSERT(1707, pBsd->prmAnmKeyNum != NULL); + JUT_ASSERT(1707, pBsd->prmAnmKeyNum != 0); JPAClrAnmKeyData* anmKeyData = (JPAClrAnmKeyData*)(pData + pBsd->mClrPrmAnmOffset); makeColorTable(&mpPrmClrAnmTbl, anmKeyData, pBsd->prmAnmKeyNum, pBsd->mClrAnmFrmMax, pHeap); @@ -1280,7 +1280,7 @@ JPABaseShape::JPABaseShape(u8 const* pData, JKRHeap* pHeap) { } if (isEnvAnm()) { - JUT_ASSERT(1716, pBsd->envAnmKeyNum != NULL); + JUT_ASSERT(1716, pBsd->envAnmKeyNum != 0); JPAClrAnmKeyData* anmKeyData = (JPAClrAnmKeyData*)(pData + pBsd->mClrEnvAnmOffset); makeColorTable(&mpEnvClrAnmTbl, anmKeyData, pBsd->envAnmKeyNum, pBsd->mClrAnmFrmMax, pHeap); diff --git a/libs/JSystem/src/JStudio/JStudio_JStage/control.cpp b/libs/JSystem/src/JStudio/JStudio_JStage/control.cpp index 5ba81c8fc99..641348b87b9 100644 --- a/libs/JSystem/src/JStudio/JStudio_JStage/control.cpp +++ b/libs/JSystem/src/JStudio/JStudio_JStage/control.cpp @@ -37,7 +37,7 @@ bool JStudio_JStage::TCreateObject::create( eObject = JStage::OBJECT_FOG; break; default: - return NULL; + return false; } JUT_ASSERT(99, pfnCreateObject!=NULL); JUT_ASSERT(100, eObject!=JStage::OBJECT_UNDEFINED); diff --git a/libs/JSystem/src/JUtility/JUTConsole.cpp b/libs/JSystem/src/JUtility/JUTConsole.cpp index 5f923984006..ff2c4f932f7 100644 --- a/libs/JSystem/src/JUtility/JUTConsole.cpp +++ b/libs/JSystem/src/JUtility/JUTConsole.cpp @@ -180,7 +180,7 @@ void JUTConsole::doDraw(JUTConsole::EConsoleType consoleType) const { mFont->drawString_scale((int)f31, sp94, mFontSizeX, mFontSizeY, mVisible ? "[ON]" : "[OFF]", TRUE); f31 += (int)(mFontSizeX * 6.0f); - if (this == NULL) // ???? + if (IS_REF_NULL(*this)) // ???? { mFont->setCharColor(JUtility::TColor(0xff, 0xff, 0x64, 0xff)); mFont->drawString_scale((int)(f31 - mFontSizeX), mFontSizeX, mFontSizeY, sp94, diff --git a/libs/JSystem/src/JUtility/JUTException.cpp b/libs/JSystem/src/JUtility/JUTException.cpp index 6fe1078c4af..8666700d1c6 100644 --- a/libs/JSystem/src/JUtility/JUTException.cpp +++ b/libs/JSystem/src/JUtility/JUTException.cpp @@ -947,7 +947,7 @@ bool JUTException::queryMapAddress_single(char* mapPath, u32 address, s32 sectio dst--; i--; } - (void)*src; // needed to match debug + UNUSED(*src); // needed to match debug *dst = 0; if (print) { if (begin_with_newline) { diff --git a/src/d/actor/d_a_alink.cpp b/src/d/actor/d_a_alink.cpp index 8d2cb7b6355..12d1cd397a6 100644 --- a/src/d/actor/d_a_alink.cpp +++ b/src/d/actor/d_a_alink.cpp @@ -15712,7 +15712,7 @@ int daAlink_c::procMoveTurnInit(int param_0) { dComIfGp_setPlayerStatus0(0, 0x800); if (param_0 != 0) { - mProcVar3.field_0x300e = (mpHIO->mMove.m.mMaxTurnAngle * 4) + 19030; + mProcVar3.field_0x300e = (s16)((mpHIO->mMove.m.mMaxTurnAngle * 4) + 19030); mProcVar4.field_0x3010 = mpHIO->mMove.m.mMaxTurnAngle * 2; mProcVar1.field_0x300a = 2; current.angle.y = mMoveAngle; diff --git a/src/d/actor/d_a_b_bq.cpp b/src/d/actor/d_a_b_bq.cpp index 96155f18a25..83a811a59cb 100644 --- a/src/d/actor/d_a_b_bq.cpp +++ b/src/d/actor/d_a_b_bq.cpp @@ -1872,7 +1872,7 @@ static void demo_camera(b_bq_class* i_this) { spFC.set(BREG_F(5) + -30.0f, 0.0f, BREG_F(6) + 1938.0f); } - daPy_getPlayerActorClass()->setPlayerPosAndAngle(&spFC, BREG_S(5) + 0x8000, 0); + daPy_getPlayerActorClass()->setPlayerPosAndAngle(&spFC, (s16)(BREG_S(5) + 0x8000), 0); if (i_this->field_0x5c8 != 0) { i_this->field_0x5cc.y += i_this->field_0x5d8; diff --git a/src/d/actor/d_a_b_mgn.cpp b/src/d/actor/d_a_b_mgn.cpp index 2fac141f1f1..396bc443277 100644 --- a/src/d/actor/d_a_b_mgn.cpp +++ b/src/d/actor/d_a_b_mgn.cpp @@ -1325,6 +1325,7 @@ void daB_MGN_c::executeDash() { } if (mMoveMode == 11) { + // @bug - parenthesis should not be on the condition if (abs((s16)(angle - field_0xa90) < 0x1800) != 0) { if ((s16)(angle - field_0xa90) < 0) { angle = field_0xa90 - 0x1800; diff --git a/src/d/actor/d_a_bg_obj.cpp b/src/d/actor/d_a_bg_obj.cpp index dbab04fa6ee..21716cb33d3 100644 --- a/src/d/actor/d_a_bg_obj.cpp +++ b/src/d/actor/d_a_bg_obj.cpp @@ -881,7 +881,7 @@ void daBgObj_c::setParticle() { for (; partNum != 0; partNum--) { u32 flags = *partBlockItems++; u16 res_id = *partBlockItems; - *partBlockItems++; + partBlockItems++; GXColor prmColor = { 0xFF, 0xFF, 0xFF, 0xFF }; GXColor envColor = { 0xFF, 0xFF, 0xFF, 0xFF }; diff --git a/src/d/actor/d_a_door_boss.cpp b/src/d/actor/d_a_door_boss.cpp index ce6e662229f..c68d882236e 100644 --- a/src/d/actor/d_a_door_boss.cpp +++ b/src/d/actor/d_a_door_boss.cpp @@ -254,7 +254,7 @@ BOOL daBdoor_c::checkArea() { if (fabsf(vec.z) > 100.0f) { return false; } - return (s16)fabs(current.angle.y - 0x7fff - player->current.angle.y) <= 0x4000 ? 1 : 0; + return (s16)fabs((f64)(current.angle.y - 0x7fff - player->current.angle.y)) <= 0x4000 ? 1 : 0; } BOOL daBdoor_c::checkFront() { diff --git a/src/d/actor/d_a_door_bossL1.cpp b/src/d/actor/d_a_door_bossL1.cpp index 5f64e88534b..7b7f2ab6ff2 100644 --- a/src/d/actor/d_a_door_bossL1.cpp +++ b/src/d/actor/d_a_door_bossL1.cpp @@ -825,7 +825,7 @@ int daBdoorL1_c::checkArea() { if (fabsf(local_48.z) > 100.0f) { return 0; } - if ((s16)fabs(current.angle.y - 0x7fff - player->current.angle.y) <= 0x4000) { + if ((s16)fabs((f64)(current.angle.y - 0x7fff - player->current.angle.y)) <= 0x4000) { return 1; } else { return 0; diff --git a/src/d/actor/d_a_door_bossL5.cpp b/src/d/actor/d_a_door_bossL5.cpp index 864a5052e94..1d54749ebbb 100644 --- a/src/d/actor/d_a_door_bossL5.cpp +++ b/src/d/actor/d_a_door_bossL5.cpp @@ -348,7 +348,7 @@ int daBdoorL5_c::checkArea() { if (fabsf(local_48.z) > 100.0f) { return 0; } - if ((s16)fabs(current.angle.y - 0x7fff - player->current.angle.y) <= 0x4000) { + if ((s16)fabs((f64)(current.angle.y - 0x7fff - player->current.angle.y)) <= 0x4000) { return 1; } else { return 0; diff --git a/src/d/actor/d_a_door_mbossL1.cpp b/src/d/actor/d_a_door_mbossL1.cpp index 027677f7eca..35bb2d56efb 100644 --- a/src/d/actor/d_a_door_mbossL1.cpp +++ b/src/d/actor/d_a_door_mbossL1.cpp @@ -1318,7 +1318,7 @@ int daMBdoorL1_c::checkArea() { return 0; } - if ((s16)fabs(angle - 0x7fff - player->current.angle.y) > 0x4000) { + if ((s16)fabs((f64)(angle - 0x7fff - player->current.angle.y)) > 0x4000) { return 0; } else { return 1; diff --git a/src/d/actor/d_a_e_hz.cpp b/src/d/actor/d_a_e_hz.cpp index df760a4f7d9..789d8823054 100644 --- a/src/d/actor/d_a_e_hz.cpp +++ b/src/d/actor/d_a_e_hz.cpp @@ -1934,7 +1934,13 @@ int daE_HZ_c::CreateHeap() { return 0; } + // This happens to work with MWCC since the member will only ever be initialized a pointer to a + // string in this TU's .data section, but comparing against a string literal is still UB. +#if AVOID_UB + if (strcmp(mpName, "E_hzp") == 0) { +#else if (mpName == "E_hzp") { +#endif modelData = (J3DModelData*)dComIfG_getObjectRes(mpName, 3); } else { modelData = (J3DModelData*)dComIfG_getObjectRes(mpName, 3); diff --git a/src/d/actor/d_a_e_kr.cpp b/src/d/actor/d_a_e_kr.cpp index 5b6e472f0d6..d58b926ecc7 100644 --- a/src/d/actor/d_a_e_kr.cpp +++ b/src/d/actor/d_a_e_kr.cpp @@ -496,6 +496,7 @@ static s8 e_kr_path_move(e_kr_class* i_this) { if (totalDiff < 10.0f * TREG_F(10) + 300.0f) { point = &i_this->field_0x6e4->m_points[i_this->field_0x6e2]; u8 pointArg1 = point->mArg1; + // !@bug Comparison of u8 with -1 will always evaluate to false if (pointArg1 == -1) { i_this->field_0x684 = 50.0f * 1.2f; } else { diff --git a/src/d/actor/d_a_e_mm_mt.cpp b/src/d/actor/d_a_e_mm_mt.cpp index b745fa31c99..205cebab780 100644 --- a/src/d/actor/d_a_e_mm_mt.cpp +++ b/src/d/actor/d_a_e_mm_mt.cpp @@ -370,7 +370,7 @@ static void e_mm_mt_drop(e_mm_mt_class* i_this) { i_this->enemy.speed.y += -5.0f; i_this->enemy.eyePos = i_this->enemy.current.pos; i_this->enemy.attention_info.position = i_this->enemy.current.pos; - cLib_addCalcAngleS2(&i_this->m_rotation.z, (TREG_S(6)+0x10000)-0x8000, 1, 0x1000); + cLib_addCalcAngleS2(&i_this->m_rotation.z, (s16)((TREG_S(6) + 0x10000) - 0x8000), 1, 0x1000); cLib_onBit(i_this->enemy.attention_info.flags, fopAc_AttnFlag_CARRY_e); i_this->enemy.attention_info.distances[fopAc_attn_CARRY_e] = 7; i_this->m_rotation.y += i_this->m_spin; diff --git a/src/d/actor/d_a_e_oc.cpp b/src/d/actor/d_a_e_oc.cpp index 4bd6dd3353e..bac4901f684 100644 --- a/src/d/actor/d_a_e_oc.cpp +++ b/src/d/actor/d_a_e_oc.cpp @@ -724,7 +724,13 @@ void daE_OC_c::damage_check() { } else if (mAtInfo.mpCollider->ChkAtType(AT_TYPE_40)) { S16_ADD(health, 10); } else if (mAtInfo.mpCollider->ChkAtType(AT_TYPE_SLINGSHOT)) { + // This happens to work with MWCC since the member will only ever be initialized a pointer to a + // string in this TU's .data section, but comparing against a string literal is still UB. +#if AVOID_UB + if (strcmp(mName, "E_OC") == 0) { +#else if (mName == "E_OC") { +#endif S16_SUB(health, 5); if (health < 0) { health = 0; @@ -855,7 +861,12 @@ void daE_OC_c::setDashSound() { } else if (mpMorf->checkFrame(8.5f)) { mSound.startCreatureSound(Z2SE_EN_OC_FOOTNOTE_R, 0, -1); } + // See comment in damage_check +#if AVOID_UB + if (strcmp(mName, "E_OC") == 0) { +#else if (mName == "E_OC") { +#endif mSound.startCreatureSoundLevel(Z2SE_EN_OC_CLUB_DAGGLE, 0, -1); } else { mSound.startCreatureSoundLevel(Z2SE_EN_OC_NATA_DAGGLE, 0, -1); @@ -1421,7 +1432,12 @@ void daE_OC_c::executeAttack() { } else if (mpMorf->checkFrame(12.5f)) { mSound.startCreatureSound(Z2SE_EN_OC_ATTACK_B, 0, -1); } else if (mpMorf->checkFrame(19.0f)) { + // See comment in damage_check +#if AVOID_UB + if (strcmp(mName, "E_OC") == 0) { +#else if (mName == "E_OC") { +#endif mSound.startCreatureSound(Z2SE_EN_OC_CLUB_HIT, 0, -1); } else { mSound.startCreatureSound(Z2SE_EN_OC_NATA_HIT, 0, -1); @@ -1843,7 +1859,12 @@ void daE_OC_c::executeDeath() { case 2: cLib_chaseF(&speedF, 0.0f, 1.0f); if (field_0x6c0 == 0) { + // See comment in damage_check +#if AVOID_UB + if (strcmp(mName, "E_OC") == 0) { +#else if (mName == "E_OC") { +#endif fopAcM_createDisappear(this, ¤t.pos, 10, 0, 4); } else { fopAcM_createDisappear(this, ¤t.pos, 10, 0, 0x34); @@ -1917,7 +1938,12 @@ void daE_OC_c::executeWaterDeath() { } if (mpMorf->isStop()) { + // See comment in damage_check +#if AVOID_UB + if (strcmp(mName, "E_OC") == 0) { +#else if (mName == "E_OC") { +#endif fopAcM_createDisappear(this, ¤t.pos, 10, 0, 4); } else { fopAcM_createDisappear(this, ¤t.pos, 10, 0, 0x34); @@ -2741,7 +2767,12 @@ cPhs_Step daE_OC_c::create() { mAcchCir.SetWallH(70.0f); } mAcchCir.SetWallR(100.0f); + // See comment in damage_check +#if AVOID_UB + if (strcmp(mName, "E_OC") == 0) { +#else if (mName == "E_OC") { +#endif field_0x560 = health = 40; } else { field_0x560 = health = 220; @@ -2756,7 +2787,12 @@ cPhs_Step daE_OC_c::create() { mSphs_at[0].SetStts(&mStts); mSphs_at[1].Set(E_OC_n::at_sph_src); mSphs_at[1].SetStts(&mStts); + // See comment in damage_check +#if AVOID_UB + if (strcmp(mName, "E_OC") == 0) { +#else if (mName == "E_OC") { +#endif mSphs_at[0].SetAtAtp(1); mSphs_at[1].SetAtAtp(1); fopAcM_OnStatus(this, fopAcStts_UNK_0x10000_e); diff --git a/src/d/actor/d_a_e_rdy.cpp b/src/d/actor/d_a_e_rdy.cpp index 17708bdf300..6488313150d 100644 --- a/src/d/actor/d_a_e_rdy.cpp +++ b/src/d/actor/d_a_e_rdy.cpp @@ -2155,7 +2155,7 @@ static void e_rdy_damage(e_rdy_class* i_this) { case 1: if (i_this->mAcch.ChkWallHit() && i_this->mTimer[0] == 0) { - if (check = kado_check(i_this)) { + if ((check = kado_check(i_this))) { OS_REPORT(" ..KADO KABE ..%x\n", check); if (check == 2) { i_this->field_0xac6 = 0x1000; @@ -4721,7 +4721,7 @@ static int daE_RDY_Execute(e_rdy_class* i_this) { } MTXCopy(i_this->mpMorf->getModel()->getAnmMtx(JNT_HAND_R), *calc_mtx); MtxTrans(20.0f + NREG_F(0), 5.0f + NREG_F(1), -10.0f + NREG_F(2), 1); - cMtx_XrotM(*calc_mtx, NREG_S(0) + 0x8000); + cMtx_XrotM(*calc_mtx, (s16)(NREG_S(0) + 0x8000)); cMtx_YrotM(*calc_mtx, NREG_S(1) + ang_y + -0x15cd); cMtx_ZrotM(*calc_mtx, NREG_S(2) + 0x28cd); i_this->mpHawkGrassModel->setBaseTRMtx(*calc_mtx); diff --git a/src/d/actor/d_a_e_wb.cpp b/src/d/actor/d_a_e_wb.cpp index 399542abe51..d6806dbb016 100644 --- a/src/d/actor/d_a_e_wb.cpp +++ b/src/d/actor/d_a_e_wb.cpp @@ -1100,7 +1100,7 @@ static void e_wb_f_run(e_wb_class* i_this) { } else { e_rd_class* local_90 = (e_rd_class*)fopAcM_SearchByID(i_this->rd_id); int saku; - if (saku = e_wb_saku_check(i_this)) { + if ((saku = e_wb_saku_check(i_this))) { i_this->field_0x6d4 = 60; if ((saku & 2) != 0) { i_this->field_0x6d6 = 0x3000; diff --git a/src/d/actor/d_a_e_yg.cpp b/src/d/actor/d_a_e_yg.cpp index 92133d2ce91..3a228593863 100644 --- a/src/d/actor/d_a_e_yg.cpp +++ b/src/d/actor/d_a_e_yg.cpp @@ -1235,7 +1235,7 @@ static int daE_YG_Execute(e_yg_class* i_this) { MTXCopy(daPy_getLinkPlayerActorClass()->getWolfMouthMatrix(), mDoMtx_stack_c::get()); mDoMtx_stack_c::multVecZero(&actor->current.pos); mDoMtx_stack_c::YrotM(KREG_S(0)); - mDoMtx_stack_c::XrotM(KREG_S(1) + 0x8000); + mDoMtx_stack_c::XrotM((s16)(KREG_S(1) + 0x8000)); mDoMtx_stack_c::ZrotM(KREG_S(2) + 2500); mDoMtx_stack_c::transM(KREG_F(0) + 10.0f, KREG_F(1) + -60.0f, KREG_F(2) + -20.0f); model->setBaseTRMtx(mDoMtx_stack_c::get()); diff --git a/src/d/actor/d_a_e_yh.cpp b/src/d/actor/d_a_e_yh.cpp index 6f462b2cdcb..cbc0a4ea34d 100644 --- a/src/d/actor/d_a_e_yh.cpp +++ b/src/d/actor/d_a_e_yh.cpp @@ -1930,7 +1930,7 @@ static void eff_set(e_yh_class* i_this) { dComIfGp_particle_set(i_this->mParticleIds2[2], dPa_RM(ID_ZI_S_YD_YODAHIT_A), &a_this->current.pos, 0, NULL); { - JPABaseEmitter* emitter = dComIfGp_particle_getEmitter(i_this->mParticleIds[5]); + JPABaseEmitter* emitter = dComIfGp_particle_getEmitter(i_this->mParticleIds2[2]); if (emitter != NULL) { MTXCopy(model->getAnmMtx(1), *calc_mtx); emitter->setGlobalRTMatrix(*calc_mtx); diff --git a/src/d/actor/d_a_e_ymb.cpp b/src/d/actor/d_a_e_ymb.cpp index c4015e3f2ac..a7441b8b195 100644 --- a/src/d/actor/d_a_e_ymb.cpp +++ b/src/d/actor/d_a_e_ymb.cpp @@ -516,7 +516,7 @@ void daE_YMB_c::checkWaterPos() { field_0x6cc = wtr_pos; field_0x69c.y = wtr_pos + 1000.0f + l_HIO.fly_height_adjust; - std::fabsf(field_0x6cc - current.pos.y); + UNUSED(std::fabsf(field_0x6cc - current.pos.y)); if (current.pos.y < (200.0f + field_0x6cc)) { if (field_0x715 == 0) { setWaterEffect1(); diff --git a/src/d/actor/d_a_e_zh.cpp b/src/d/actor/d_a_e_zh.cpp index 5bba783e045..63c60b06c4a 100644 --- a/src/d/actor/d_a_e_zh.cpp +++ b/src/d/actor/d_a_e_zh.cpp @@ -542,7 +542,7 @@ bool daE_ZH_c::mBallBgLineCheck() { bool daE_ZH_c::mSearchMove(u8 param_1) { if (mS_Ball == NULL) { setActionMode(ACTION_EXECUTE_FLY_DELETE, 0); - return NULL; + return false; } cXyz sp50, sp5c; diff --git a/src/d/actor/d_a_horse.cpp b/src/d/actor/d_a_horse.cpp index 6edd60a620a..6f621fa650e 100644 --- a/src/d/actor/d_a_horse.cpp +++ b/src/d/actor/d_a_horse.cpp @@ -51,9 +51,10 @@ #define ANM_HS_WALK_FAST 34 #define ANM_HS_WALK_SLOW 35 -static f32* strippedFunc() { - f32 v[3] = {}; - return v; +static void strippedFunc() { + extern void F(f32*); + f32 v[3] = {0.0f}; + F(v); } static char const l_arcName[] = "Horse"; diff --git a/src/d/actor/d_a_mg_rod.cpp b/src/d/actor/d_a_mg_rod.cpp index 816deb528e3..c7d9bdfb4e5 100644 --- a/src/d/actor/d_a_mg_rod.cpp +++ b/src/d/actor/d_a_mg_rod.cpp @@ -2977,8 +2977,8 @@ static void hook_set(dmg_rod_class* i_this, cXyz* param_1, int param_2) { mDoMtx_stack_c::XrotM(-0x4000); if (param_2 == 1 && (i_this->action <= ACTION_LURE_STANDBY || (i_this->lure_type != MG_LURE_SP && i_this->action == ACTION_LURE_CATCH))) { - sp38.x = fabsf(hook->field_0x18.y); - sp38.z = fabsf(hook->field_0x18.x - 0x4000); + sp38.x = fabsf((f32)hook->field_0x18.y); + sp38.z = fabsf((f32)(hook->field_0x18.x - 0x4000)); f32 var_f31 = JMAFastSqrt(SQUARE(sp38.x) + SQUARE(sp38.z)); if (var_f31 > 7000.0f) { diff --git a/src/d/actor/d_a_nbomb.cpp b/src/d/actor/d_a_nbomb.cpp index 1d09b39bfdb..67282050409 100644 --- a/src/d/actor/d_a_nbomb.cpp +++ b/src/d/actor/d_a_nbomb.cpp @@ -986,7 +986,7 @@ BOOL daNbomb_c::procWait() { speedF *= player->getBombBoundRate(); current.angle.y = (mAcchCir.GetWallAngleY() * 2) - (current.angle.y + 0x8000); } else if (mAcch.ChkGroundLanding() && speedF > 5.0f && cM_deg2s(50.0f) <= field_0xb5a) { - if ((f32)fabs(var_r28) >= (f32)0x4000) { + if ((f32)fabs((f64)var_r28) >= (f32)0x4000) { speedF *= player->getBombBoundRate(); current.angle.y = (var_r27 * 2) - (current.angle.y + 0x8000); mAcch.ClrGroundLanding(); diff --git a/src/d/actor/d_a_npc2.cpp b/src/d/actor/d_a_npc2.cpp index 2558f4c092f..3b3a22f66f7 100644 --- a/src/d/actor/d_a_npc2.cpp +++ b/src/d/actor/d_a_npc2.cpp @@ -544,7 +544,7 @@ void daBaseNpc_c::orderEvent(int param_0, char* i_evtName) { if (i_evtName != NULL) { mEvtIdx = dComIfGp_getEventManager().getEventIdx(this, i_evtName, -1); fopAcM_orderOtherEventId(this, mEvtIdx, 0xFF, 0xFFFF, 0, 1); - } else if (field_0x848 >= 0 && attention_info.flags == (fopAc_AttnFlag_SPEAK_e | fopAc_AttnFlag_TALK_e)) { + } else if (mFlowID >= 0 && attention_info.flags == (fopAc_AttnFlag_SPEAK_e | fopAc_AttnFlag_TALK_e)) { eventInfo.onCondition(1); if (param_0 != 0) { fopAcM_orderSpeakEvent(this, 0, 0); diff --git a/src/d/actor/d_a_npc_bou.cpp b/src/d/actor/d_a_npc_bou.cpp index 10139191f33..9c36dfb506b 100644 --- a/src/d/actor/d_a_npc_bou.cpp +++ b/src/d/actor/d_a_npc_bou.cpp @@ -635,7 +635,7 @@ void daNpc_Bou_c::action() { hit_actor = field_0xba0.getActorP(); if (hit_actor != NULL) { - abs( (s16)(fopAcM_searchPlayerAngleY(this) - mCurAngle.y) ); + UNUSED(abs((s16)(fopAcM_searchPlayerAngleY(this) - mCurAngle.y))); switch (((daTag_Push_c*) hit_actor)->getId()) { case 7: { mEvtNo = 8; diff --git a/src/d/actor/d_a_npc_chat.cpp b/src/d/actor/d_a_npc_chat.cpp index 3b6ac5279fc..345a33ab00d 100644 --- a/src/d/actor/d_a_npc_chat.cpp +++ b/src/d/actor/d_a_npc_chat.cpp @@ -2628,7 +2628,7 @@ BOOL daNpcChat_c::setAttention(int param_1) { cXyz(0.0f, 10.0f, 0.0f), }; - int jointNo = isM_() ? JNTM_HEAD : JNTW_HEAD; + int jointNo = isM_() ? (int)JNTM_HEAD : (int)JNTW_HEAD; mDoMtx_stack_c::copy(mAnm_p->getModel()->getAnmMtx(jointNo)); mDoMtx_stack_c::multVec(&a_eyeOfsTbl[param_1], &eyePos); mBaseAttnPos.set(current.pos.x, current.pos.y + AtnOfs(param_1), current.pos.z); diff --git a/src/d/actor/d_a_npc_coach.cpp b/src/d/actor/d_a_npc_coach.cpp index 1c315d63324..4d69e637166 100644 --- a/src/d/actor/d_a_npc_coach.cpp +++ b/src/d/actor/d_a_npc_coach.cpp @@ -517,8 +517,7 @@ BOOL daNpcChPath_c::setPath(int path_index, int room_no, cXyz& i_vec, bool param mCurrentID = path_index; mPntIndex = 0; - // Is this really what the Nintendo devs wrote?? The debug ROM suggests as such. - if (param_4 && &i_vec) { + if (param_4 && IS_REF_NONNULL(i_vec)) { f32 fVar1 = G_CM3D_F_INF; for (int pnt_index = 0; pnt_index < mpPath->m_num; pnt_index++) { dPnt* pnt = dPath_GetPnt(mpPath, pnt_index); @@ -534,8 +533,7 @@ BOOL daNpcChPath_c::setPath(int path_index, int room_no, cXyz& i_vec, bool param field_0x8 = G_CM3D_F_INF; - // ditto. - if (&i_vec) { + if (IS_REF_NONNULL(i_vec)) { field_0x4 = &i_vec; cXyz targetPoint; getTargetPoint(targetPoint); diff --git a/src/d/actor/d_a_npc_gra.cpp b/src/d/actor/d_a_npc_gra.cpp index 9f303d8f3f4..364b4b0fc6f 100644 --- a/src/d/actor/d_a_npc_gra.cpp +++ b/src/d/actor/d_a_npc_gra.cpp @@ -343,10 +343,13 @@ BOOL daNpc_grA_c::create() { mType = getTypeFromParam(); mMode = getMode(); mSwBit = getSwBit(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xffff) { - field_0x146C = home.angle.x; + mFlowID = home.angle.x; } else{ - field_0x146C = -1; + mFlowID = -1; } if (isDelete()) { return cPhs_ERROR_e; @@ -2146,7 +2149,7 @@ BOOL daNpc_grA_c::ECut_talkSpa(int i_staffID) { setLookMode(5); break; case 1: - initTalk(field_0x146C, arr); + initTalk(mFlowID, arr); break; case 2: if (daNpcF_chkEvtBit(6) && daNpcF_chkEvtBit(0x3e) == FALSE) { @@ -3020,7 +3023,7 @@ BOOL daNpc_grA_c::ECut_rollRockCrash(int i_staffID) { break; case 0x14: { setLookMode(0); - initTalk(field_0x146C, NULL); + initTalk(mFlowID, NULL); cXyz c(200.0f, 100.0f, 0.0f); mDoMtx_stack_c::YrotS(home.angle.y); mDoMtx_stack_c::multVec(&c, &c); @@ -3588,7 +3591,7 @@ BOOL daNpc_grA_c::waitSpaWater(void*) { } setLookMode(0); mTurnMode = 0; - field_0x146C = 0x28; + mFlowID = 0x28; field_0x1472 = 2; field_0x9ea = 1; // fallthrough @@ -3968,7 +3971,7 @@ BOOL daNpc_grA_c::talk(void*) { setGateWalk(); } } else { - r27 = field_0x146C; + r27 = mFlowID; } initTalk(r27, NULL); field_0x1484 = fopAcM_searchPlayerAngleY(this); diff --git a/src/d/actor/d_a_npc_grc.cpp b/src/d/actor/d_a_npc_grc.cpp index e3f3949a558..a5828bad919 100644 --- a/src/d/actor/d_a_npc_grc.cpp +++ b/src/d/actor/d_a_npc_grc.cpp @@ -308,6 +308,9 @@ cPhs_Step daNpc_grC_c::create() { mTwilight = dKy_darkworld_check(); mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { mFlowID = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_grd.cpp b/src/d/actor/d_a_npc_grd.cpp index a5630c17dfb..ffbb71286b6 100644 --- a/src/d/actor/d_a_npc_grd.cpp +++ b/src/d/actor/d_a_npc_grd.cpp @@ -172,6 +172,9 @@ int daNpc_Grd_c::create() { mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xffff) { mFlowID = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_gro.cpp b/src/d/actor/d_a_npc_gro.cpp index 20b432c1b04..317e043ff8c 100644 --- a/src/d/actor/d_a_npc_gro.cpp +++ b/src/d/actor/d_a_npc_gro.cpp @@ -396,6 +396,9 @@ cPhs_Step daNpc_grO_c::create() { mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { mMsgNo = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_grr.cpp b/src/d/actor/d_a_npc_grr.cpp index 0ba9b44d646..0c50e0e5a28 100644 --- a/src/d/actor/d_a_npc_grr.cpp +++ b/src/d/actor/d_a_npc_grr.cpp @@ -264,6 +264,9 @@ cPhs_Step daNpc_grR_c::create() { mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { mFlowID = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_grs.cpp b/src/d/actor/d_a_npc_grs.cpp index 05d1356a479..f9ef95fbec9 100644 --- a/src/d/actor/d_a_npc_grs.cpp +++ b/src/d/actor/d_a_npc_grs.cpp @@ -138,10 +138,13 @@ int daNpc_grS_c::create() { mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xffff) { - field_0xe0c = home.angle.x; + mFlowID = home.angle.x; } else { - field_0xe0c = -1; + mFlowID = -1; } if (isDelete()) { @@ -856,7 +859,7 @@ int daNpc_grS_c::selectAction() { mpNextActionFn = &daNpc_grS_c::test; } else { - (int)mType; + UNUSED((int)mType); mpNextActionFn = &daNpc_grS_c::wait; } @@ -936,7 +939,7 @@ int daNpc_grS_c::doEvent() { if (eventInfo.checkCommandDemoAccrpt() && mEventIdx != -1 && eventManager->endCheck(mEventIdx)) { - (int)mOrderEvtNo; + UNUSED((int)mOrderEvtNo); dComIfGp_event_reset(); mOrderEvtNo = 0; mEventIdx = -1; @@ -1157,7 +1160,7 @@ int daNpc_grS_c::talk(void* param_0) { daNpcF_offTmpBit(11); } - unkInt1 = field_0xe0c; + unkInt1 = mFlowID; mIsSpeaking = false; initTalk(unkInt1, NULL); mTurnMode = 0; diff --git a/src/d/actor/d_a_npc_grz.cpp b/src/d/actor/d_a_npc_grz.cpp index 40558fee1b8..a38e499c9d5 100644 --- a/src/d/actor/d_a_npc_grz.cpp +++ b/src/d/actor/d_a_npc_grz.cpp @@ -455,6 +455,9 @@ cPhs_Step daNpc_Grz_c::create() { mType = getTypeFromParam(); mSwNo = fopAcM_GetParam(this) >> 16; + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { mMsgNo = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_gwolf.cpp b/src/d/actor/d_a_npc_gwolf.cpp index 64d376705d3..746f4766c94 100644 --- a/src/d/actor/d_a_npc_gwolf.cpp +++ b/src/d/actor/d_a_npc_gwolf.cpp @@ -291,10 +291,13 @@ cPhs_Step daNpc_GWolf_c::create() { mExitId = fopAcM_GetParam(this) >> 24; + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { - field_0xe08 = home.angle.x; + mFlowID = home.angle.x; } else { - field_0xe08 = -1; + mFlowID = -1; } swBit = getSwBitFromParam(); @@ -1817,7 +1820,7 @@ BOOL daNpc_GWolf_c::talk(void* param_1) { break; } - int msgNo = field_0xe08; + int msgNo = mFlowID; mOrderSpeakEvt = false; initTalk(msgNo, NULL); mTurnMode = 0; diff --git a/src/d/actor/d_a_npc_kn.cpp b/src/d/actor/d_a_npc_kn.cpp index c8b374a3b12..e76338b537e 100644 --- a/src/d/actor/d_a_npc_kn.cpp +++ b/src/d/actor/d_a_npc_kn.cpp @@ -4961,11 +4961,11 @@ int daNpc_Kn_c::setPrtcl() { // cXyz* pos = mParticleMngr[i].mpModel == true ? &mParticleMngr[i].mPos : NULL; mParticleMngr[i].mManager.setEffectCenter(&tevStr, &mParticleMngr[i].mPos, check, sp_0x18, - mParticleMngr[i].mpModel == true ? &mParticleMngr[i].mPos : NULL, - mParticleMngr[i].mpModel == true ? &mParticleMngr[i].mAngle : NULL, + mParticleMngr[i].field_0x00 == true ? &mParticleMngr[i].mPos : NULL, + mParticleMngr[i].field_0x00 == true ? &mParticleMngr[i].mAngle : NULL, 0, fopAcM_GetRoomNo(this), 0.0f, speedF); - if (mParticleMngr[i].mpModel != false) { + if (mParticleMngr[i].field_0x00 != false) { emitter = mParticleMngr[i].mManager.getCenterEmitter(0, 0); if (emitter != NULL) { switch (i) { @@ -4984,7 +4984,7 @@ int daNpc_Kn_c::setPrtcl() { } } - mParticleMngr[i].mpModel = NULL; + mParticleMngr[i].field_0x00 = false; } return 1; @@ -4996,21 +4996,21 @@ int daNpc_Kn_c::setSlipPrtcl() { mParticleMngr[0].mPos.y -= 20.0f; mParticleMngr[0].mAngle = current.angle; ANGLE_SUB_2(mParticleMngr[0].mAngle.y, 0x8000); - mParticleMngr[0].mpModel = true; + mParticleMngr[0].field_0x00 = true; mDoMtx_stack_c::copy(mpModelMorf[0]->getModel()->getAnmMtx(0x1b)); mDoMtx_stack_c::multVecZero(&mParticleMngr[1].mPos); mParticleMngr[1].mPos.y -= 20.0f; mParticleMngr[1].mAngle = current.angle; ANGLE_SUB_2(mParticleMngr[1].mAngle.y, 0x8000); - mParticleMngr[1].mpModel = true; + mParticleMngr[1].field_0x00 = true; return 1; } int daNpc_Kn_c::setLandingPrtcl() { mParticleMngr[2].mPos = current.pos; mParticleMngr[2].mAngle = mCurAngle; - mParticleMngr[2].mpModel = true; + mParticleMngr[2].field_0x00 = true; return 1; } diff --git a/src/d/actor/d_a_npc_ks.cpp b/src/d/actor/d_a_npc_ks.cpp index 8b0abd9fb78..e2b312a22a6 100644 --- a/src/d/actor/d_a_npc_ks.cpp +++ b/src/d/actor/d_a_npc_ks.cpp @@ -250,7 +250,13 @@ static int daNpc_Ks_Draw(npc_ks_class* i_this) { fopAc_ac_c* actor = &i_this->actor; J3DModel* model = i_this->model->getModel(); + // This happens to work with MWCC since the member will only ever be initialized a pointer to a + // string in this TU's .data section, but comparing against a string literal is still UB. +#if AVOID_UB + if (strcmp(i_this->res_name, "Npc_kst") == 0) { +#else if (i_this->res_name == "Npc_kst") { +#endif g_env_light.settingTevStruct(4, &actor->current.pos, &actor->tevStr); } else { g_env_light.settingTevStruct(0, &actor->current.pos, &actor->tevStr); diff --git a/src/d/actor/d_a_npc_myna2.cpp b/src/d/actor/d_a_npc_myna2.cpp index 2d55cbf8369..a251a2518f7 100644 --- a/src/d/actor/d_a_npc_myna2.cpp +++ b/src/d/actor/d_a_npc_myna2.cpp @@ -189,10 +189,13 @@ int daNpc_myna2_c::create() { mType = getTypeFromParam(); field_0xe0d = (fopAcM_GetParam(this) & 0xFF00) >> 8; + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { - field_0xe04 = home.angle.x; + mFlowID = home.angle.x; } else { - field_0xe04 = -1; + mFlowID = -1; } if (isDelete()) { @@ -928,7 +931,7 @@ int daNpc_myna2_c::talk(void* param_0) { switch (mMode) { case 0: if (!mIsDamaged) { - initTalk(field_0xe04, NULL); + initTalk(mFlowID, NULL); mTurnMode = 0; mAnm_p->setPlaySpeed(1.0f); mMode = 2; @@ -1014,7 +1017,7 @@ int daNpc_myna2_c::ECut_firstTalk(int i_staffId) { case 10: break; case 20: - initTalk(field_0xe04, NULL); + initTalk(mFlowID, NULL); break; } } @@ -1063,7 +1066,7 @@ int daNpc_myna2_c::ECut_gameFailure(int i_staffId) { case 20: break; case 10: - initTalk(field_0xe04, NULL); + initTalk(mFlowID, NULL); break; } } @@ -1121,7 +1124,7 @@ int daNpc_myna2_c::ECut_gameGoal(int i_staffId) { } break; case 10: - initTalk(field_0xe04, NULL); + initTalk(mFlowID, NULL); break; case 20: break; @@ -1183,7 +1186,7 @@ int daNpc_myna2_c::ECut_gameGoalSuccess(int i_staffId) { } break; case 10: - initTalk(field_0xe04, NULL); + initTalk(mFlowID, NULL); break; case 20: { int itemNo = 0; @@ -1193,7 +1196,7 @@ int daNpc_myna2_c::ECut_gameGoalSuccess(int i_staffId) { break; } case 25: - initTalk(field_0xe04, NULL); + initTalk(mFlowID, NULL); break; case 30: break; diff --git a/src/d/actor/d_a_npc_ne.cpp b/src/d/actor/d_a_npc_ne.cpp index 7144e77fe84..f74baadab38 100644 --- a/src/d/actor/d_a_npc_ne.cpp +++ b/src/d/actor/d_a_npc_ne.cpp @@ -135,7 +135,13 @@ static int daNpc_Ne_Draw(npc_ne_class* i_this) { } J3DModel* model = i_this->mpMorf->getModel(); + // This happens to work with MWCC since the member will only ever be initialized a pointer to a + // string in this TU's .data section, but comparing against a string literal is still UB. +#if AVOID_UB + if (strcmp(i_this->mResName, "Npc_net") == 0) { +#else if (i_this->mResName == "Npc_net") { +#endif if (!dComIfGs_wolfeye_effect_check()) { return 1; } @@ -426,7 +432,12 @@ static void npc_ne_wait(npc_ne_class* i_this) { daPy_py_c* player = static_cast(dComIfGp_getPlayer(0)); cLib_addCalc0(&_this->speedF, 1.0f, 1.3f); + // See comment in daNpc_Ne_Draw +#if AVOID_UB + if (strcmp(i_this->mResName, "Npc_net") == 0) { +#else if (i_this->mResName == "Npc_net") { +#endif switch (i_this->mMode) { case 0: i_this->mTargetAngleY = cM_rndF(0x10000); @@ -2173,7 +2184,12 @@ static void action(npc_ne_class* i_this) { _this->gravity = -7.0f; + // See comment in daNpc_Ne_Draw +#if AVOID_UB + if (strcmp(i_this->mResName, "Npc_net") == 0) { +#else if (i_this->mResName == "Npc_net") { +#endif i_this->mDistToTarget = 10000.0f; } else { i_this->mDistToTarget = i_this->mDistScale * fopAcM_searchPlayerDistance(_this); @@ -2298,9 +2314,15 @@ static void action(npc_ne_class* i_this) { break; } + // See comment in daNpc_Ne_Draw +#if AVOID_UB + if (strcmp(i_this->mResName, "Npc_net") != 0) { +#else if (i_this->mResName != "Npc_net") { - if (i_this->mMessageState == 1 && daPy_py_c::checkNowWolf() - && i_this->mDistToTarget < 300.0f) { +#endif + if (i_this->mMessageState == 1 && + daPy_py_c::checkNowWolf() && + i_this->mDistToTarget < 300.0f) { i_this->mAction = npc_ne_class::ACT_MESSAGE; i_this->mMode = 0; bird_check = false; @@ -2846,8 +2868,15 @@ static void demo_camera(npc_ne_class* i_this) { } static int message(npc_ne_class* i_this) { - if (i_this->mResName == "Npc_net" && !dComIfGs_wolfeye_effect_check()) { - i_this->mMessageState = 0; + // See comment in daNpc_Ne_Draw +#if AVOID_UB + if (strcmp(i_this->mResName, "Npc_net") == 0) { +#else + if (i_this->mResName == "Npc_net") { +#endif + if (!dComIfGs_wolfeye_effect_check()) { + i_this->mMessageState = 0; + } } if (i_this->mIsTalking) { @@ -2872,7 +2901,12 @@ static int message(npc_ne_class* i_this) { !fopAcM_otherBgCheck(daPy_getLinkPlayerActorClass(), i_this)) { fopAcM_OnStatus(i_this, 0); cLib_onBit(i_this->attention_info.flags, fopAc_AttnFlag_SPEAK_e | fopAc_AttnFlag_TALK_e); + // See comment in daNpc_Ne_Draw +#if AVOID_UB + if (strcmp(i_this->mResName, "Npc_net") == 0) { +#else if (i_this->mResName == "Npc_net") { +#endif cLib_onBit(i_this->attention_info.flags, fopAc_AttnFlag_UNK_0x800000 | fopAc_AttnFlag_UNK_0x400000); } i_this->eventInfo.onCondition(dEvtCnd_CANTALK_e); @@ -2978,14 +3012,21 @@ static int daNpc_Ne_Execute(npc_ne_class* i_this) { message(i_this); demo_camera(i_this); - if (i_this->mResName == "Npc_net" && !dComIfGs_wolfeye_effect_check()) { - static u16 e_name[2] = {0x8497, 0x8498}; - for (int i = 0; i < 2; i++) { - i_this->mParticle[i] = dComIfGp_particle_set(i_this->mParticle[i], e_name[i], - &i_this->eyePos, NULL, NULL); - JPABaseEmitter* emitter = dComIfGp_particle_getEmitter(i_this->mParticle[i]); - if (emitter != NULL) { - emitter->setGlobalAlpha(!dComIfGs_wolfeye_effect_check() ? 0xff : 0); + // See comment in daNpc_Ne_Draw +#if AVOID_UB + if (strcmp(i_this->mResName, "Npc_net") == 0) { +#else + if (i_this->mResName == "Npc_net") { +#endif + if (!dComIfGs_wolfeye_effect_check()) { + static u16 e_name[2] = {0x8497, 0x8498}; + for (int i = 0; i < 2; i++) { + i_this->mParticle[i] = dComIfGp_particle_set(i_this->mParticle[i], e_name[i], + &i_this->eyePos, NULL, NULL); + JPABaseEmitter* emitter = dComIfGp_particle_getEmitter(i_this->mParticle[i]); + if (emitter != NULL) { + emitter->setGlobalAlpha(!dComIfGs_wolfeye_effect_check() ? 0xff : 0); + } } } } @@ -3231,7 +3272,12 @@ static cPhs_Step daNpc_Ne_Create(fopAc_ac_c* i_this) { _this->mAcchCir.SetWall(_this->mBaseScale.y * 30.0f, _this->mBaseScale.z * 35.0f); _this->mDistScale = cM_rndFX(0.2f) + 1.0f; _this->mGroundY = i_this->current.pos.y; + // See comment in daNpc_Ne_Draw +#if AVOID_UB + if (strcmp(_this->mResName, "Npc_net") == 0) { +#else if (_this->mResName == "Npc_net") { +#endif _this->mAction = npc_ne_class::ACT_WAIT; _this->mMode = 0; } diff --git a/src/d/actor/d_a_npc_pachi_maro.cpp b/src/d/actor/d_a_npc_pachi_maro.cpp index 6c9b34d5c7a..6f29d620062 100644 --- a/src/d/actor/d_a_npc_pachi_maro.cpp +++ b/src/d/actor/d_a_npc_pachi_maro.cpp @@ -1098,7 +1098,7 @@ int daNpc_Pachi_Maro_c::wait(void* param_1) { } if (mJntAnm.getMode() == 0) { - (s32)mType; + UNUSED((int)mType); } } break; diff --git a/src/d/actor/d_a_npc_pachi_taro.cpp b/src/d/actor/d_a_npc_pachi_taro.cpp index e54dba6fecc..99d47bc5b55 100644 --- a/src/d/actor/d_a_npc_pachi_taro.cpp +++ b/src/d/actor/d_a_npc_pachi_taro.cpp @@ -1464,7 +1464,7 @@ int daNpc_Pachi_Taro_c::wait(void* param_1) { // ??? if (mJntAnm.getMode() == 0) { - (int)mType; + UNUSED((int)mType); } if (field_0x1004 == 0) { diff --git a/src/d/actor/d_a_npc_post.cpp b/src/d/actor/d_a_npc_post.cpp index 52a392bafd9..7880a64b91d 100644 --- a/src/d/actor/d_a_npc_post.cpp +++ b/src/d/actor/d_a_npc_post.cpp @@ -696,7 +696,7 @@ BOOL daNpc_Post_c::checkChangeEvt() { return TRUE; } - (int)mType; + UNUSED((int)mType); } return FALSE; diff --git a/src/d/actor/d_a_npc_soldierA.cpp b/src/d/actor/d_a_npc_soldierA.cpp index 1d5d1ecfe5b..618407d4ef8 100644 --- a/src/d/actor/d_a_npc_soldierA.cpp +++ b/src/d/actor/d_a_npc_soldierA.cpp @@ -206,6 +206,9 @@ cPhs_Step daNpc_SoldierA_c::create() { mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { mMsgNo = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_soldierB.cpp b/src/d/actor/d_a_npc_soldierB.cpp index 7d42e522aba..83f9ef4ba08 100644 --- a/src/d/actor/d_a_npc_soldierB.cpp +++ b/src/d/actor/d_a_npc_soldierB.cpp @@ -171,6 +171,9 @@ cPhs_Step daNpc_SoldierB_c::create() { mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { mMsgNo = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_theB.cpp b/src/d/actor/d_a_npc_theB.cpp index d01063d3d47..5c535ad1da9 100644 --- a/src/d/actor/d_a_npc_theB.cpp +++ b/src/d/actor/d_a_npc_theB.cpp @@ -244,6 +244,9 @@ cPhs_Step daNpcTheB_c::create() { return cPhs_ERROR_e; } + // !@bug The return value (an s16) is promoted to a 32-bit signed + // integer prior to being compared, so the compared value can + // never exceed SHORT_MAX and the condition always passes. if (getMessageNo() != 0xFFFF) { mMsgNo = getMessageNo(); } else { diff --git a/src/d/actor/d_a_npc_wrestler.cpp b/src/d/actor/d_a_npc_wrestler.cpp index 1d3ae764042..a36774a0997 100644 --- a/src/d/actor/d_a_npc_wrestler.cpp +++ b/src/d/actor/d_a_npc_wrestler.cpp @@ -2219,8 +2219,8 @@ bool daNpcWrestler_c::sumouReady(void* param_1) { // fallthrough case 2: field_0xe5e += field_0xbd8->field_0xac; - field_0xe54 -= fabsf(field_0xbd8->field_0xac); - if (field_0xe54 < fabsf(field_0xbd8->field_0xac)) { + field_0xe54 -= fabsf((f32)field_0xbd8->field_0xac); + if (field_0xe54 < fabsf((f32)field_0xbd8->field_0xac)) { field_0xe80 = 1; field_0xe84++; } diff --git a/src/d/actor/d_a_npc_zra.cpp b/src/d/actor/d_a_npc_zra.cpp index 8e0ec2415f5..cf630eda051 100644 --- a/src/d/actor/d_a_npc_zra.cpp +++ b/src/d/actor/d_a_npc_zra.cpp @@ -493,6 +493,9 @@ cPhs_Step daNpc_zrA_c::create() { fopAcM_ct(this, daNpc_zrA_c); mType = getTypeFromArgument(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xffff) { mFlowID = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_zrc.cpp b/src/d/actor/d_a_npc_zrc.cpp index 83345259012..b050a9f9bbd 100644 --- a/src/d/actor/d_a_npc_zrc.cpp +++ b/src/d/actor/d_a_npc_zrc.cpp @@ -222,6 +222,9 @@ cPhs_Step daNpc_zrC_c::create() { fopAcM_ct(this, daNpc_zrC_c); mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xffff) { mFlowID = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_zrz.cpp b/src/d/actor/d_a_npc_zrz.cpp index b0c9c204dc7..ece2931be99 100644 --- a/src/d/actor/d_a_npc_zrz.cpp +++ b/src/d/actor/d_a_npc_zrz.cpp @@ -203,6 +203,9 @@ cPhs_Step daNpc_zrZ_c::create() { mSwitch1 = home.angle.z & 0xff; mSwitch2 = (home.angle.z >> 8) & 0xff; mSwitch3 = fopAcM_GetParam(this) >> 0x18; + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xffff) { mFlowID = home.angle.x; } else { diff --git a/src/d/actor/d_a_obj_brg.cpp b/src/d/actor/d_a_obj_brg.cpp index 6257f1740f9..bc6a087c712 100644 --- a/src/d/actor/d_a_obj_brg.cpp +++ b/src/d/actor/d_a_obj_brg.cpp @@ -665,8 +665,8 @@ static void obj_brg_move(obj_brg_class* i_this) { if ((i_this->mType & 1) == 1) { i_this->mBr[i].field_0x0e0 = 1.0f; } else { - var_f27 = ( f32(i) / (i_this->field_0xb1ea - 1)) * M_PI; - i_this->mBr[i].field_0x0e0 = fabsf(sin(var_f27)); + var_f27 = ((f32)i / (i_this->field_0xb1ea - 1)) * M_PI; + i_this->mBr[i].field_0x0e0 = fabsf(sinf(var_f27)); } i_this->mBr[i].field_0x704 = i_this->mBr[i].field_0x705 = 3; @@ -993,11 +993,11 @@ static int daObj_Brg_Execute(obj_brg_class* i_this) { f32 dbg_0x5c; for (int i = 0; i < i_this->field_0xb1ea; i++, part++) { if (i_this->field_0xb1ed == 2) { - dbg_0x5c = f32(i) / f32(i_this->field_0xb1ea - 1) * M_PI; - var_f26 = (-300.0f + WREG_F(15)) * f32(sin(dbg_0x5c)); + dbg_0x5c = (f32)i / (f32)(i_this->field_0xb1ea - 1) * M_PI; + var_f26 = (-300.0f + WREG_F(15)) * (f32)sin(dbg_0x5c); } else if (i_this->field_0xb1ed == 1) { - dbg_0x5c = f32(i) / f32(i_this->field_0xb1ea - 1) * M_PI; - var_f26 = (-100.0f + WREG_F(13)) * f32(sin(dbg_0x5c)); + dbg_0x5c = (f32)i / (f32)(i_this->field_0xb1ea - 1) * M_PI; + var_f26 = (-100.0f + WREG_F(13)) * (f32)sin(dbg_0x5c); } MtxTrans(part->field_0x0bc.x, part->field_0x0bc.y, part->field_0x0bc.z, 0); @@ -1794,7 +1794,7 @@ static int daObj_Brg_Create(fopAc_ac_c* i_this) { }; for (brno = 0; brno < a_this->field_0xb1ea; brno++) { - a_this->mBr[brno].field_0x098[2] = brg_init_pos[brno]; + a_this->mBr[brno].field_0x0b0 = brg_init_pos[brno]; } } diff --git a/src/d/actor/d_a_obj_cwall.cpp b/src/d/actor/d_a_obj_cwall.cpp index 600f433c1a5..9d48a90c3ea 100644 --- a/src/d/actor/d_a_obj_cwall.cpp +++ b/src/d/actor/d_a_obj_cwall.cpp @@ -333,6 +333,10 @@ void daObjCwall_c::getChainBasePos(cXyz* pBasePos) { void daObjCwall_c::setChainMtx() { chain_s* pChain = mChains; s16 sVar7 = home.angle.y; + + // !@bug The variable is promoted to a 32-bit signed integer prior + // to being compared to 0xC000, so the compared value can never + // exceed SHORT_MAX and the subcondition fails. if (sVar7 == 0x4000 || sVar7 == 0xc000) { sVar7 += 0x4000; } diff --git a/src/d/actor/d_a_obj_gra2.cpp b/src/d/actor/d_a_obj_gra2.cpp index a5d3c5fb699..58802a63ea9 100644 --- a/src/d/actor/d_a_obj_gra2.cpp +++ b/src/d/actor/d_a_obj_gra2.cpp @@ -277,7 +277,10 @@ cPhs_Step daObj_GrA_c::create() { } } - field_0x848 = ((int)home.angle.x == 0xFFFF) ? -1 : home.angle.x; + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always fails. + mFlowID = home.angle.x == 0xFFFF ? -1 : home.angle.x; field_0x1fe8 = (fopAcM_GetParam(this) & 0xC0000000) >> 30; field_0xa7f = home.angle.z & 0xFF; @@ -1435,7 +1438,7 @@ int daObj_GrA_c::talk(void* param_1) { int iVar1, iVar2; int rv = 0; int iVar3; - int iVar4 = field_0x848; + int iVar4 = mFlowID; s16 sVar1; switch (field_0xa7c) { case 0: @@ -2013,7 +2016,7 @@ int daObj_GrA_c::face999(int param_1) { } int daObj_GrA_c::evtcutTalk(int param_1, int param_2) { - s32 sVar1 = field_0x848; + s32 sVar1 = mFlowID; if (param_2 != 0) { mMsgFlow.init(this, sVar1, 0, NULL); field_0xaa0 = 0; diff --git a/src/d/actor/d_a_obj_gra2_soldier.inc b/src/d/actor/d_a_obj_gra2_soldier.inc index 5bb137c1674..32274435db2 100644 --- a/src/d/actor/d_a_obj_gra2_soldier.inc +++ b/src/d/actor/d_a_obj_gra2_soldier.inc @@ -768,7 +768,7 @@ int daObj_GrA_c::rollDemo(void* param_1) { field_0x91a.y = current.angle.y; if (mDemoCamMode >= 5) { - field_0x848 = 4; + mFlowID = 4; evtcutTalk(-1, 1); field_0x2000 = 0; } @@ -1169,7 +1169,7 @@ int daObj_GrA_c::rollAttacked(void* param_1) { case 2: if (mDemoCamMode >= 5) { - field_0x848 = 5; + mFlowID = 5; evtcutTalk(-1, 1); field_0x2018 = 3; } diff --git a/src/d/actor/d_a_obj_magne_arm.cpp b/src/d/actor/d_a_obj_magne_arm.cpp index 422ee5d6a4e..af0567c209e 100644 --- a/src/d/actor/d_a_obj_magne_arm.cpp +++ b/src/d/actor/d_a_obj_magne_arm.cpp @@ -947,7 +947,7 @@ void daObjMarm_c::calcHimo() { getRopeStartPos(&offset1); getFpartsOffset(&offset2); - fabs(offset1.y - offset2.y); + UNUSED(fabs(offset1.y - offset2.y)); cXyz* line_mat1_pos = mpRope1->getPos(0); *line_mat1_pos = offset1; diff --git a/src/d/actor/d_a_obj_pumpkin.cpp b/src/d/actor/d_a_obj_pumpkin.cpp index ff90ed6a740..6dcd0988f70 100644 --- a/src/d/actor/d_a_obj_pumpkin.cpp +++ b/src/d/actor/d_a_obj_pumpkin.cpp @@ -288,8 +288,9 @@ int daObj_Pumpkin_c::Execute() { if (field_0xBAE) { int item_table_no = getItemTableNo(); if (item_table_no >= 0 && mItemProcId == fpcM_ERROR_PROCESS_ID_e) { - mItemProcId = fopAcM_createItemFromTable(¤t.pos, item_table_no, -1, fopAcM_GetRoomNo(this), - NULL, 0, NULL, NULL, NULL, NULL); + mItemProcId = fopAcM_createItemFromTable(¤t.pos, item_table_no, -1, + fopAcM_GetRoomNo(this), NULL, 0, NULL, NULL, + NULL, false); } if (mItemProcId == fpcM_ERROR_PROCESS_ID_e || fopAcM_IsExecuting(mItemProcId)) { diff --git a/src/d/actor/d_a_obj_sekidoor.cpp b/src/d/actor/d_a_obj_sekidoor.cpp index 7be65ab45b4..498282f4b4e 100644 --- a/src/d/actor/d_a_obj_sekidoor.cpp +++ b/src/d/actor/d_a_obj_sekidoor.cpp @@ -112,7 +112,9 @@ int daObj_SekiDoor_c::Execute(Mtx** i_mtx) { if (mOpening != 0) { if (mDestroyed != 0) { - if(!dComIfGp_event_runCheck){ + // !@bug Missing parentheses - the function is not callled and + // this always evaluates to false. + if (!dComIfGp_event_runCheck) { fopAcM_delete(this); } } diff --git a/src/d/actor/d_a_obj_sekizoa.cpp b/src/d/actor/d_a_obj_sekizoa.cpp index 57be8845a9c..baba4a7fb25 100644 --- a/src/d/actor/d_a_obj_sekizoa.cpp +++ b/src/d/actor/d_a_obj_sekizoa.cpp @@ -1008,9 +1008,14 @@ bool daObj_Sekizoa_c::afterSetMotionAnm(int i_frame, int i_mode, f32 i_morf, int if (mBtkAnm.getBtkAnm() == anm_text) { mAnmFlags |= ANM_PLAY_BTK; } else { - if (setBtkAnm(anm_text, mpMorf[0]->getModel()->getModelData(), 1.0f, - btkAnmData[4].field_0x4)) - { +#if AVOID_UB + // negative attribute values are ignored in favor of the animation's default value + if (setBtkAnm(anm_text, mpMorf[0]->getModel()->getModelData(), 1.0f, -1)) { +#else + // !@bug Out-of-bounds array read, in practice this ends up reading from a jump table + // positioned immediately after btkAnmData in .data. + if (setBtkAnm(anm_text, mpMorf[0]->getModel()->getModelData(), 1.0f, btkAnmData[4].field_0x4)) { +#endif if (frame_1 == 3) { mBtkAnm.setPlaySpeed(0.0f); } @@ -1032,8 +1037,15 @@ bool daObj_Sekizoa_c::afterSetMotionAnm(int i_frame, int i_mode, f32 i_morf, int if (mBrkAnm.getBrkAnm() == anm_tev) { mAnmFlags |= ANM_PLAY_BRK; } else { - frame_1 = setBrkAnm(anm_tev, mpMorf[0]->getModel()->getModelData(), 1.0, + // !@bug OoB index into brkAnmData ends up indexing into btkAnmData instead. + // This was probably supposed to use brkAnmData[5] instead. +#if AVOID_UB + frame_1 = setBrkAnm(anm_tev, mpMorf[0]->getModel()->getModelData(), 1.0f, + btkAnmData[0].field_0x4); +#else + frame_1 = setBrkAnm(anm_tev, mpMorf[0]->getModel()->getModelData(), 1.0f, brkAnmData[6].field_0x4); +#endif if (frame_1 != 0) { if (frame_2 == 5) { mBrkAnm.setPlaySpeed(0.0f); diff --git a/src/d/actor/d_a_obj_ss_drink.cpp b/src/d/actor/d_a_obj_ss_drink.cpp index 50d4fcd4cba..846eb561244 100644 --- a/src/d/actor/d_a_obj_ss_drink.cpp +++ b/src/d/actor/d_a_obj_ss_drink.cpp @@ -384,6 +384,7 @@ int daObj_SSDrink_c::chkEvent() { } int daObj_SSDrink_c::orderEvent() { + // !@bug Comparison of u16 (getFlowNodeNum()) with -1 always evaluates to false if (!daPy_py_c::checkNowWolf() && field_0xb0c != 0x60 && getFlowNodeNum() != -1) { attention_info.flags = fopAc_AttnFlag_TALKREAD_e | fopAc_AttnFlag_SPEAK_e; } else { diff --git a/src/d/actor/d_a_tag_evt.cpp b/src/d/actor/d_a_tag_evt.cpp index 2552f59e24b..8dc5954ef07 100644 --- a/src/d/actor/d_a_tag_evt.cpp +++ b/src/d/actor/d_a_tag_evt.cpp @@ -168,6 +168,7 @@ int daTag_Evt_c::isDelete() { if (field_0x5DD == 0xFF || (field_0x5DD != 0xFF && dComIfGs_isSwitch(field_0x5DD, fopAcM_GetRoomNo(this)) != 0)) { + // !@bug Comparison of u8 field with 0xFFF will always evaluate to false if (field_0x5DE != 0xFFF) { return dComIfGs_isSwitch(field_0x5DE, fopAcM_GetRoomNo(this)); } else { diff --git a/src/d/actor/d_a_tag_evtmsg.cpp b/src/d/actor/d_a_tag_evtmsg.cpp index 8a2035f147b..b5e71f00e3e 100644 --- a/src/d/actor/d_a_tag_evtmsg.cpp +++ b/src/d/actor/d_a_tag_evtmsg.cpp @@ -36,6 +36,9 @@ int daTag_EvtMsg_c::create() { scale.y *= 100.0f; scale.z = scale.x; + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.z != 0xFFFF) { mFlowID = home.angle.z; } else { diff --git a/src/d/actor/d_a_tag_lantern.cpp b/src/d/actor/d_a_tag_lantern.cpp index 264a0c19874..88660a029d8 100644 --- a/src/d/actor/d_a_tag_lantern.cpp +++ b/src/d/actor/d_a_tag_lantern.cpp @@ -126,6 +126,9 @@ void daTag_Lantern_c::initialize() { mpHIO->entryHIO("カンテラチェックタグ"); #endif + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.z != 0xFFFF) { mFlowIndex = home.angle.z; } else { diff --git a/src/d/actor/d_a_tag_setrestart.cpp b/src/d/actor/d_a_tag_setrestart.cpp index c7134fbae44..4230abb920e 100644 --- a/src/d/actor/d_a_tag_setrestart.cpp +++ b/src/d/actor/d_a_tag_setrestart.cpp @@ -163,7 +163,7 @@ static int daTagRestart_Execute(daTagRestart_c* i_this) { } static int daTagRestart_Delete(daTagRestart_c* i_this) { - ("Delete -> TagRestart( =%d)\n", fopAcM_GetID(i_this)); + fopAcM_RegisterDeleteID(i_this, "TagRestart"); return i_this->_delete(); } diff --git a/src/d/actor/d_a_tag_ss_drink.cpp b/src/d/actor/d_a_tag_ss_drink.cpp index 645fc16a503..f4f8b5fbe21 100644 --- a/src/d/actor/d_a_tag_ss_drink.cpp +++ b/src/d/actor/d_a_tag_ss_drink.cpp @@ -136,7 +136,7 @@ int daTag_SSDrink_c::chkEvent() { if (!dComIfGp_getEvent()->isOrderOK()) { retVal = 0; if (eventInfo.checkCommandTalk()) { - if (!checkProcess(&daTag_SSDrink_c::talk) == 0) { + if (checkProcess(&daTag_SSDrink_c::talk) != 0) { retVal = (this->*mProcessFunc)(0); } else { if (dComIfGp_event_chkTalkXY() == 0 || dComIfGp_evmng_ChkPresentEnd() != 0) { diff --git a/src/d/actor/d_a_tag_theB_hint.cpp b/src/d/actor/d_a_tag_theB_hint.cpp index d368d726df7..58887f976eb 100644 --- a/src/d/actor/d_a_tag_theB_hint.cpp +++ b/src/d/actor/d_a_tag_theB_hint.cpp @@ -23,6 +23,7 @@ int daTagTheBHint_c::execute() { if (fopAcM_searchPlayerDistanceXZ2(this) < field_0x568) { daNpcTheB_c* the_b = (daNpcTheB_c*)fpcM_SearchByName(fpcNm_NPC_THEB_e); if (the_b) { + // !@bug Comparison of s8 (getRoomNo) with 0xFF always evaluates to false int roomNo = getRoomNo() == 0xff ? fopAcM_GetRoomNo(this) : getRoomNo(); the_b->setHintEvent(getMessageNo(), getLinkID(), roomNo); diff --git a/src/d/d_debug_camera.cpp b/src/d/d_debug_camera.cpp index 10c5edd71f9..ca41c517d63 100644 --- a/src/d/d_debug_camera.cpp +++ b/src/d/d_debug_camera.cpp @@ -1719,7 +1719,7 @@ JUtility::TColor get_color(JUtility::TColor color) { JUtility::TColor(0x80, 0x80, 0xFF, 0xFF), }; - (void)(u32)color; + UNUSED((u32)color); int var_r30 = 1; if (var_r30 && (u32)color < 9) { diff --git a/src/d/d_demo.cpp b/src/d/d_demo.cpp index 2af725c1626..651d89e1269 100644 --- a/src/d/d_demo.cpp +++ b/src/d/d_demo.cpp @@ -14,6 +14,24 @@ s16 dDemo_c::m_branchId = -1; namespace { +class jstudio_tAdaptor_message : public JStudio::TAdaptor_message { +public: + typedef JStudio::TObject_message ObjectType; + + jstudio_tAdaptor_message() {} + + virtual ~jstudio_tAdaptor_message(); + virtual void adaptor_do_MESSAGE(JStudio::data::TEOperationData, const void*, u32); +}; + +class jstudio_tCreateObject_message : public JStudio::TCreateObject { +public: + jstudio_tCreateObject_message() {} + + virtual ~jstudio_tCreateObject_message(); + virtual bool create(JStudio::TObject**, const JStudio::stb::data::TParse_TBlock_object&); +}; + jstudio_tAdaptor_message::~jstudio_tAdaptor_message() {} void jstudio_tAdaptor_message::adaptor_do_MESSAGE(JStudio::data::TEOperationData iType, @@ -168,7 +186,7 @@ JStudio_JAudio2::TCreateObject* dDemo_c::m_audio; dDemo_particle_c* dDemo_c::m_particle; -jstudio_tCreateObject_message* dDemo_c::m_message; +JStudio::TCreateObject* dDemo_c::m_message; JStudio::TFactory* dDemo_c::m_factory; diff --git a/src/d/d_drawlist.cpp b/src/d/d_drawlist.cpp index b79a594eff7..bea73d76c6b 100644 --- a/src/d/d_drawlist.cpp +++ b/src/d/d_drawlist.cpp @@ -1820,7 +1820,7 @@ int dDlst_list_c::set(dDlst_base_c**& p_start, dDlst_base_c**& p_end, dDlst_base return 0; } *p_start = p_newDlst; - *p_start++; + UNUSED(*p_start++); return 1; } diff --git a/src/d/d_ev_camera.cpp b/src/d/d_ev_camera.cpp index f737d35ddaf..593d723b35d 100644 --- a/src/d/d_ev_camera.cpp +++ b/src/d/d_ev_camera.cpp @@ -2160,7 +2160,7 @@ bool dCamera_c::gameOverEvCamera() { mViewCache.mEye = sp230; gover_p->field_0x0++; mViewCache.mFovy = 75.0f; - bVar9 = 75.0f; + bVar9 = true; } // fallthrough intentional. case 4: { diff --git a/src/d/d_kankyo.cpp b/src/d/d_kankyo.cpp index 624a30b7b00..2490209efde 100644 --- a/src/d/d_kankyo.cpp +++ b/src/d/d_kankyo.cpp @@ -10483,7 +10483,7 @@ BOOL dKy_camera_water_in_status_check() { u8 dKy_pol_efftype_get(const cBgS_PolyInfo* polyinfo_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10513,7 +10513,7 @@ u8 dKy_pol_efftype_get(const cBgS_PolyInfo* polyinfo_p) { u8 dKy_pol_efftype2_get(const cBgS_PolyInfo* polyinfo_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10543,7 +10543,7 @@ u8 dKy_pol_efftype2_get(const cBgS_PolyInfo* polyinfo_p) { u8 dKy_pol_sound_get(const cBgS_PolyInfo* polyinfo_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0; } @@ -10574,7 +10574,7 @@ u8 dKy_pol_sound_get(const cBgS_PolyInfo* polyinfo_p) { u8 dKy_pol_argument_get(const cBgS_PolyInfo* polyinfo_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0; } @@ -10599,7 +10599,7 @@ u8 dKy_pol_argument_get(const cBgS_PolyInfo* polyinfo_p) { u8 dKy_pol_eff_prim_get(const cBgS_PolyInfo* polyinfo_p, GXColor* out_color_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); u8 eff_id = 0; - if (polyinfo_p == NULL || out_color_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || out_color_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10636,7 +10636,7 @@ u8 dKy_pol_eff_prim_get(const cBgS_PolyInfo* polyinfo_p, GXColor* out_color_p) { u8 dKy_pol_eff_env_get(const cBgS_PolyInfo* polyinfo_p, GXColor* out_color_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); u8 eff_id = 0; - if (polyinfo_p == NULL || out_color_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || out_color_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10673,7 +10673,7 @@ u8 dKy_pol_eff_env_get(const cBgS_PolyInfo* polyinfo_p, GXColor* out_color_p) { u8 dKy_pol_eff2_prim_get(const cBgS_PolyInfo* polyinfo_p, GXColor* out_color_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); u8 eff_id = 0; - if (polyinfo_p == NULL || out_color_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || out_color_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10710,7 +10710,7 @@ u8 dKy_pol_eff2_prim_get(const cBgS_PolyInfo* polyinfo_p, GXColor* out_color_p) u8 dKy_pol_eff2_env_get(const cBgS_PolyInfo* polyinfo_p, GXColor* out_color_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); u8 eff_id = 0; - if (polyinfo_p == NULL || out_color_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || out_color_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10748,7 +10748,7 @@ u8 dKy_pol_eff_alpha_get(const cBgS_PolyInfo* polyinfo_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); int z0; u8 eff_id = 0; - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10785,7 +10785,7 @@ f32 dKy_pol_eff_ratio_get(const cBgS_PolyInfo* polyinfo_p) { u8 eff_id; f32 ratio = 0.0f; - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0.0f; } @@ -10822,7 +10822,7 @@ u8 dKy_pol_eff2_alpha_get(const cBgS_PolyInfo* polyinfo_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); int z0; u8 retval = 0; - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10858,7 +10858,7 @@ f32 dKy_pol_eff2_ratio_get(const cBgS_PolyInfo* polyinfo_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); f32 ratio = 0.0f; - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0.0f; } diff --git a/src/d/d_lib.cpp b/src/d/d_lib.cpp index 8f3597a55b8..34c626ea754 100644 --- a/src/d/d_lib.cpp +++ b/src/d/d_lib.cpp @@ -108,7 +108,7 @@ u8 STControl::checkTrigger() { f32 stickValue = getValueStick(); s16 stickAngle = getAngleStick(); u8 var_r6 = 0; - s16 temp_r7 = 0x2000 - field_0x26 >> 1; + s16 temp_r7 = (0x2000 - field_0x26) >> 1; if (!cM3d_IsZero(stickValue)) { if (stickAngle < field_0x22 - 0x7000 + temp_r7) { diff --git a/src/d/d_map_path_dmap.cpp b/src/d/d_map_path_dmap.cpp index 4f45717806a..8652462434a 100644 --- a/src/d/d_map_path_dmap.cpp +++ b/src/d/d_map_path_dmap.cpp @@ -199,10 +199,10 @@ void dMapInfo_n::getRoomMinMaxXZ(int i_roomNo, f32* i_roomLeftX, f32* i_roomInne void dMapInfo_n::getFloorParameter(f32 param_0, s8* i_floorNo, f32* param_2, f32* param_3, f32* param_4, f32* param_5) { - f32 gap_level = dStage_stagInfo_GetGapLevel(dComIfGp_getStageStagInfo()); - f32 range_up = fabsf(dStage_stagInfo_GetRangeUp(dComIfGp_getStageStagInfo())); - f32 range_down = fabsf(dStage_stagInfo_GetRangeDown(dComIfGp_getStageStagInfo())); - s8 floorNo = (f32)floor(param_0 / gap_level); + f32 gap_level = (f32)dStage_stagInfo_GetGapLevel(dComIfGp_getStageStagInfo()); + f32 range_up = fabsf((f32)dStage_stagInfo_GetRangeUp(dComIfGp_getStageStagInfo())); + f32 range_down = fabsf((f32)dStage_stagInfo_GetRangeDown(dComIfGp_getStageStagInfo())); + s8 floorNo = (s8)(f32)floor(param_0 / gap_level); if (i_floorNo != NULL) { *i_floorNo = floorNo; diff --git a/src/d/d_menu_letter.cpp b/src/d/d_menu_letter.cpp index efb35e6d503..7cb78f8bd55 100644 --- a/src/d/d_menu_letter.cpp +++ b/src/d/d_menu_letter.cpp @@ -18,9 +18,9 @@ #include "d/d_lib.h" #if VERSION == VERSION_GCN_JPN -#define LINE_MAX 9 +#define D_MENU_LETTER_LINE_MAX 9 #else -#define LINE_MAX 12 +#define D_MENU_LETTER_LINE_MAX 12 #endif typedef void (dMenu_Letter_c::*initFunc)(); @@ -258,8 +258,8 @@ void dMenu_Letter_c::_draw() { uVar10 = (J2DTextBox*)field_0x2f4[i]->getPanePtr(); } J2DTextBox* uVar18 = (J2DTextBox*)field_0x2ec[i]->getPanePtr(); - mpString->getStringPage(dMenu_Letter::getLetterText(dVar1), field_0x3e3 - 1, LINE_MAX, - uVar18, uVar10, NULL, NULL, 0); + mpString->getStringPage(dMenu_Letter::getLetterText(dVar1), field_0x3e3 - 1, + D_MENU_LETTER_LINE_MAX, uVar18, uVar10, NULL, NULL, 0); } mpString->drawOutFont((J2DTextBox*)field_0x2ec[1]->getPanePtr(), -1.0f); if (mProcess == 4) { @@ -491,10 +491,10 @@ void dMenu_Letter_c::read_open_init() { text1 = (J2DTextBox*)field_0x2f4[i]->getPanePtr(); } J2DTextBox* text2 = (J2DTextBox*)field_0x2ec[i]->getPanePtr(); - mpString->getStringPage(dMenu_Letter::getLetterText(idx), field_0x3e3 - 1, LINE_MAX, text2, text1, - 0, NULL, NULL); + mpString->getStringPage(dMenu_Letter::getLetterText(idx), field_0x3e3 - 1, + D_MENU_LETTER_LINE_MAX, text2, text1, NULL, NULL, 0); } - field_0x3e2 = mpString->getPageMax(LINE_MAX); + field_0x3e2 = mpString->getPageMax(D_MENU_LETTER_LINE_MAX); if (field_0x3e2 > 1) { char acStack_30[20]; sprintf(acStack_30, "%d/%d", field_0x3e3, field_0x3e2); @@ -642,7 +642,8 @@ void dMenu_Letter_c::read_next_fadein_init() { text1 = (J2DTextBox*)field_0x2f4[i]->getPanePtr(); } J2DTextBox* text2 = (J2DTextBox*)field_0x2ec[i]->getPanePtr(); - mpString->getStringPage(dMenu_Letter::getLetterText(idx), field_0x3e3 - 1, LINE_MAX, text2, text1, 0, NULL, NULL); + mpString->getStringPage(dMenu_Letter::getLetterText(idx), field_0x3e3 - 1, + D_MENU_LETTER_LINE_MAX, text2, text1, NULL, NULL, 0); } char acStack_30[10]; sprintf(acStack_30, "%d/%d", field_0x3e3, field_0x3e2); diff --git a/src/d/d_menu_ring.cpp b/src/d/d_menu_ring.cpp index 878c5342207..4374dd18265 100644 --- a/src/d/d_menu_ring.cpp +++ b/src/d/d_menu_ring.cpp @@ -1503,6 +1503,8 @@ void dMenu_Ring_c::setSelectItem(int i_idx, u8 i_itemNo) { } else { field_0x6be[i_idx] = 0; } + // !@bug Out-of-bounds access into mpSelectItemTexBuf + // (innermost dimension is 2, we take index 2 which is invalid) field_0x686[i_idx] = dMeter2Info_readItemTexture( i_itemNo, mpSelectItemTexBuf[i_idx][field_0x6be[i_idx]][0], mpSelectItemTex[i_idx][0], mpSelectItemTexBuf[i_idx][field_0x6be[i_idx]][1], mpSelectItemTex[i_idx][1], diff --git a/src/d/d_msg_object.cpp b/src/d/d_msg_object.cpp index 0cb515113cb..29b8cbdd41c 100644 --- a/src/d/d_msg_object.cpp +++ b/src/d/d_msg_object.cpp @@ -1602,7 +1602,16 @@ u8 dMsgObject_c::isSend() { } void dMsgObject_c::readMessageGroupLocal(mDoDvdThd_mountXArchive_c** p_arcMount) { +#if AVOID_UB + // largest possible value msgGroup appears to be 99, but just in case + // we leave enough space to fit INT_MAX + static char arcName[32]; +#else + // We write at least 23 bytes into this which causes an overflow, + // but in practice arcName is followed by two bytes of padding + // at the end of .bss which mitigates the problem. static char arcName[22]; +#endif int msgGroup = dStage_stagInfo_GetMsgGroup(dComIfGp_getStage()->getStagInfo()); #if REGION_PAL @@ -2133,7 +2142,7 @@ u16 dMsgObject_c::getSmellTypeMessageIDLocal() { if (smell < dItemNo_SMELL_MEDICINE_e + 1 && smell >= dItemNo_SMELL_YELIA_POUCH_e) { msgId = smell + 0x165; } else { - if (dComIfGs_getCollectSmell() != -1) { + if (dComIfGs_getCollectSmell() != 0xFF) { OS_REPORT("smell type ====> %d\n", dComIfGs_getCollectSmell()); JUT_WARN(4858, "smell type no entry!"); } diff --git a/src/d/d_msg_scrn_howl.cpp b/src/d/d_msg_scrn_howl.cpp index 473de9c3502..102a5d95e0e 100644 --- a/src/d/d_msg_scrn_howl.cpp +++ b/src/d/d_msg_scrn_howl.cpp @@ -19,6 +19,16 @@ #include "JSystem/J2DGraph/J2DScreen.h" #include "Z2AudioLib/Z2WolfHowlMgr.h" +// POSIX already defines a macro with this name, but we know that this specific name is +// used in TP based on assertion messages. This redefinition is scoped to this TU which +// is unlikely to ever actually need the POSIX define, so we can just redefine it. +#if defined(LINE_MAX) +#undef LINE_MAX +#endif +#define LINE_MAX 30 +//TODO: This is likely an enum value based on its name +#define PLOT_BUFFER_MAX_e 0x300 + typedef void (dMsgScrnHowl_c::*dMsgScrnHowl_cFunc)(); static dMsgScrnHowl_cFunc init_proc[5] = { diff --git a/src/d/d_particle.cpp b/src/d/d_particle.cpp index 8b171047aa5..54f24549dd0 100644 --- a/src/d/d_particle.cpp +++ b/src/d/d_particle.cpp @@ -506,7 +506,7 @@ bool dPa_modelEcallBack::model_c::set(J3DModelData* i_modelData, dKy_tevstr_c co field_0x8.field_0x344 = param_1.field_0x344; typedef struct Arr{ int field_0x0[2]; - }; + } Arr; *(Arr*)&field_0x8.AmbCol = *(Arr*)¶m_1.AmbCol; *(Arr*)&field_0x8.FogCol = *(Arr*)¶m_1.FogCol; *(Arr*)&field_0x8.TevColor = *(Arr*)¶m_1.TevColor; @@ -838,11 +838,11 @@ u32 dPa_simpleEcallBack::set(cXyz const* i_pos, dKy_tevstr_c const* param_2, u8 GXColor local_60; GXColor local_64 = {0xff, 0xff, 0xff, 0xff}; GXColor local_68 = {0xff, 0xff, 0xff, 0xff}; - if (¶m_5 != NULL) { + if (IS_REF_NONNULL(param_5)) { local_64 = param_5; } - if (¶m_4 != NULL) { + if (IS_REF_NONNULL(param_4)) { local_68 = param_4; } @@ -859,11 +859,11 @@ u32 dPa_simpleEcallBack::set(cXyz const* i_pos, dKy_tevstr_c const* param_2, u8 GXColor local_70; GXColor local_74 = {0xff, 0xff, 0xff, 0xff}; GXColor local_78 = {0xff, 0xff, 0xff, 0xff}; - if (¶m_5 != NULL) { + if (IS_REF_NONNULL(param_5)) { local_74 = param_5; } - if (¶m_4 != NULL) { + if (IS_REF_NONNULL(param_4)) { local_78 = param_4; } @@ -881,13 +881,13 @@ u32 dPa_simpleEcallBack::set(cXyz const* i_pos, dKy_tevstr_c const* param_2, u8 pData->field_0x10.g = local_6c.g; pData->field_0x10.b = local_6c.b; } else { - if (¶m_4 != NULL) { + if (IS_REF_NONNULL(param_4)) { pData->field_0x0c.r = param_4.r; pData->field_0x0c.g = param_4.g; pData->field_0x0c.b = param_4.b; } - if (¶m_5 != NULL) { + if (IS_REF_NONNULL(param_5)) { pData->field_0x10.r = param_5.r; pData->field_0x10.g = param_5.g; pData->field_0x10.b = param_5.b; diff --git a/src/d/d_save.cpp b/src/d/d_save.cpp index 52daf21404b..aaa59edcf17 100644 --- a/src/d/d_save.cpp +++ b/src/d/d_save.cpp @@ -1790,7 +1790,7 @@ int dSv_info_c::memory_to_card(char* card_ptr, int dataNum) { OS_REPORT("(dSv_reserve_c) size %d\n", sizeof(dSv_reserve_c)); OS_REPORT("(dSv_MiniGame_c) size %d\n", sizeof(dSv_MiniGame_c)); OS_REPORT("セーブ全体情報(dSv_save_c) size %d\n", sizeof(dSv_save_c)); - printf("Write size:%d\n", card_ptr - var_r29); + printf("Write size:%d\n", (int)(card_ptr - var_r29)); // Now that we've saved, reset events if needed if (lantern_not_recovered == true) { @@ -1809,11 +1809,11 @@ int dSv_info_c::memory_to_card(char* card_ptr, int dataNum) { } if (card_ptr - var_r29 > (QUEST_LOG_SIZE - 8)) { - printf("SAVE size over(%d/%d)\n", (QUEST_LOG_SIZE - 8), card_ptr - var_r29); + printf("SAVE size over(%d/%d)\n", (QUEST_LOG_SIZE - 8), (int)(card_ptr - var_r29)); return -1; } - printf("SAVE size:%d\n", card_ptr - var_r29); + printf("SAVE size:%d\n", (int)(card_ptr - var_r29)); return 0; } @@ -1859,11 +1859,11 @@ int dSv_info_c::card_to_memory(char* i_cardPtr, int i_dataNum) { OS_REPORT("########### save stage ====> %s\n", dMeter2Info_getSaveStageName()); if (i_cardPtr - var_r30 > (QUEST_LOG_SIZE - 8)) { - printf("LOAD size over(%d/%d)\n", (QUEST_LOG_SIZE - 8), i_cardPtr - var_r30); + printf("LOAD size over(%d/%d)\n", (QUEST_LOG_SIZE - 8), (int)(i_cardPtr - var_r30)); return -1; } - printf("LOAD size:%d\n", i_cardPtr - var_r30); + printf("LOAD size:%d\n", (int)(i_cardPtr - var_r30)); return 0; } @@ -1880,11 +1880,11 @@ int dSv_info_c::initdata_to_card(char* i_cardPtr, int i_dataNum) { i_cardPtr += sizeof(dSv_save_c); if (i_cardPtr - var_r30 > (QUEST_LOG_SIZE - 8)) { - printf("INIT size over %d/%d\n", (QUEST_LOG_SIZE - 8), i_cardPtr - var_r30); + printf("INIT size over %d/%d\n", (QUEST_LOG_SIZE - 8), (int)(i_cardPtr - var_r30)); return -1; } - printf("INIT size:%d\n", i_cardPtr - var_r30); + printf("INIT size:%d\n", (int)(i_cardPtr - var_r30)); return 0; } diff --git a/src/d/d_shop_system.cpp b/src/d/d_shop_system.cpp index 1c955f00763..52941ebd0cb 100644 --- a/src/d/d_shop_system.cpp +++ b/src/d/d_shop_system.cpp @@ -1459,9 +1459,8 @@ bool dShopSystem_c::searchItemActor() { for (int i = 0; i < dShopSystem_sellItemMax; i++) { u32 processId = dShopSystem_itemActor[i]->getProcessID(); mItemCtrl.setItemIndex(i, processId); - mItemCtrl.setMessageIndex(i, (u16)dShopSystem_itemActor[i]->home.angle.x != 0xFFFF ? - (u16)dShopSystem_itemActor[i]->home.angle.x : - -1); + int itemFlowId = dShopSystem_itemActor[i]->getFlowNodeNum(); + mItemCtrl.setMessageIndex(i, itemFlowId); if (processId + 0x10000 == 0xFFFF) { onFlag(i); diff --git a/src/f_pc/f_pc_priority.cpp b/src/f_pc/f_pc_priority.cpp index cbd62a40530..35f331d6875 100644 --- a/src/f_pc/f_pc_priority.cpp +++ b/src/f_pc/f_pc_priority.cpp @@ -110,7 +110,7 @@ int fpcPi_Change(process_priority_class* i_procPriority, fpc_ProcID i_layerID, u int fpcPi_Handler() { process_priority_class* i_procPriority; - while (i_procPriority = fpcPi_GetFromQueue()) { + while ((i_procPriority = fpcPi_GetFromQueue())) { base_process_class* process = (base_process_class*)i_procPriority->base.mpTagData; layer_management_tag_class* pLayerTag = &process->layer_tag; line_tag* pLineTag = &process->line_tag_; diff --git a/src/m_Do/m_Do_dvd_thread.cpp b/src/m_Do/m_Do_dvd_thread.cpp index 0d9eabfad99..550cb9b5871 100644 --- a/src/m_Do/m_Do_dvd_thread.cpp +++ b/src/m_Do/m_Do_dvd_thread.cpp @@ -155,7 +155,7 @@ static void cb(void* param_0) { void mDoDvdThd_param_c::mainLoop() { mDoDvdThd_command_c* command; while (this->waitForKick() != 0) { - while (command = this->getFirstCommand()) { + while ((command = this->getFirstCommand())) { this->cut(command); if (mDoDvdThd::SyncWidthSound) { JASDvd::getThreadPointer()->sendCmdMsg(cb, &command, 4); diff --git a/src/m_Do/m_Do_ext.cpp b/src/m_Do/m_Do_ext.cpp index b0d2a8a8213..735c8684e7e 100644 --- a/src/m_Do/m_Do_ext.cpp +++ b/src/m_Do/m_Do_ext.cpp @@ -71,11 +71,11 @@ static void mDoExt_setJ3DData(Mtx mtx, const J3DTransformInfo* transformInfo, u1 *mtx_p++ *= sp0C.x; *mtx_p++ *= sp0C.x; *mtx_p++ *= sp0C.x; - *mtx_p++; + UNUSED(*mtx_p++); *mtx_p++ *= sp0C.y; *mtx_p++ *= sp0C.y; *mtx_p++ *= sp0C.y; - *mtx_p++; + UNUSED(*mtx_p++); *mtx_p++ *= sp0C.z; *mtx_p++ *= sp0C.z; *mtx_p++ *= sp0C.z;