From b598f856b4a8e7398018cf074a1d21af7545c908 Mon Sep 17 00:00:00 2001 From: PJB3005 Date: Sat, 28 Feb 2026 13:17:05 +0100 Subject: [PATCH] Make stage loading work on LE & 64-bit --- include/d/actor/d_a_spinner.h | 2 +- include/d/d_map.h | 2 +- include/d/d_map_path.h | 14 +- include/d/d_map_path_dmap.h | 10 +- include/d/d_menu_fmap.h | 32 ++--- include/d/d_path.h | 8 +- include/d/d_stage.h | 201 ++++++++++++++++----------- include/d/d_tresure.h | 8 +- include/dusk/endian.h | 30 ++++ include/dusk/endian_ssystem.h | 65 +++++++++ include/f_op/f_op_actor_mng.h | 9 +- include/m_Do/m_Do_mtx.h | 8 ++ src/JSystem/J3DGraphBase/J3DTevs.cpp | 4 + src/d/actor/d_a_e_kr.cpp | 2 +- src/d/actor/d_a_e_ym.cpp | 4 +- src/d/actor/d_a_horse.cpp | 6 +- src/d/actor/d_a_kago.cpp | 14 +- src/d/actor/d_a_kytag03.cpp | 5 + src/d/actor/d_a_npc_cd2.cpp | 5 + src/d/actor/d_a_npc_tk.cpp | 16 ++- src/d/actor/d_a_obj_laundry_rope.cpp | 4 +- src/d/actor/d_a_spinner.cpp | 13 +- src/d/actor/d_a_tag_Lv7Gate.cpp | 4 +- src/d/actor/d_a_tag_guard.cpp | 6 + src/d/actor/d_a_tbox.cpp | 6 +- src/d/d_camera.cpp | 10 +- src/d/d_com_inf_game.cpp | 12 +- src/d/d_envse.cpp | 12 ++ src/d/d_map.cpp | 2 +- src/d/d_map_path.cpp | 6 +- src/d/d_map_path_dmap.cpp | 59 ++++++-- src/d/d_map_path_fmap.cpp | 8 +- src/d/d_menu_dmap_map.cpp | 2 +- src/d/d_msg_flow.cpp | 5 + src/d/d_spline_path.cpp | 8 +- src/d/d_stage.cpp | 28 +++- src/d/d_tresure.cpp | 2 +- 37 files changed, 431 insertions(+), 201 deletions(-) create mode 100644 include/dusk/endian_ssystem.h diff --git a/include/d/actor/d_a_spinner.h b/include/d/actor/d_a_spinner.h index dd5b098e57..1dac4594a3 100644 --- a/include/d/actor/d_a_spinner.h +++ b/include/d/actor/d_a_spinner.h @@ -35,7 +35,7 @@ public: void setWallHit(s16, u32); void setAnm(); int setNextPathNum(); - Vec* getPathNextPos(); + BE(Vec)* getPathNextPos(); int checkLineWallHit(cXyz*, cXyz*); int checkPathMove(); void setSpreadEffect(); diff --git a/include/d/d_map.h b/include/d/d_map.h index bbd21787ca..caf691f69b 100644 --- a/include/d/d_map.h +++ b/include/d/d_map.h @@ -169,7 +169,7 @@ public: virtual int getRoomNoSingle(); virtual bool isDrawRoom(int, int) const; virtual bool isDrawRoomIcon(int, int) const; - virtual const Vec* getIconPosition(dTres_c::typeGroupData_c*) const; + virtual const BE(Vec)* getIconPosition(dTres_c::typeGroupData_c*) const; virtual dTres_c::typeGroupData_c* getFirstData(u8); virtual dTres_c::typeGroupData_c* getNextData(dTres_c::typeGroupData_c*); virtual void setAmapPaletteColor(int, u8, u8, u8, u8); diff --git a/include/d/d_map_path.h b/include/d/d_map_path.h index a082a3c2e7..0704d3eb5a 100644 --- a/include/d/d_map_path.h +++ b/include/d/d_map_path.h @@ -115,13 +115,13 @@ public: /* 0x01 */ u8 field_0x1; /* 0x02 */ u8 mDataNum; /* 0x03 */ u8 field_0x3; - /* 0x04 */ u16* mpData; + /* 0x04 */ STAGE_OFFSET_PTR(BE(u16)) mpData; }; // Size: 0x8 struct poly_class { /* 0x00 */ u8 field_0x0; /* 0x01 */ u8 mDataNum; - /* 0x04 */ u16* mpData; + /* 0x04 */ STAGE_OFFSET_PTR(BE(u16)) mpData; }; // Size: 0x8 struct group_class { @@ -130,21 +130,21 @@ public: /* 0x02 */ u8 mLineNum; /* 0x03 */ u8 field_0x3; /* 0x04 */ u8 mPolyNum; - /* 0x08 */ dDrawPath_c::line_class* mpLine; + /* 0x08 */ STAGE_OFFSET_PTR(dDrawPath_c::line_class) mpLine; /* 0x0C */ u8 field_0xc[4]; - /* 0x10 */ dDrawPath_c::poly_class* mpPoly; + /* 0x10 */ STAGE_OFFSET_PTR(dDrawPath_c::poly_class) mpPoly; }; // Size: 0x14 struct floor_class { /* 0x0 */ s8 mFloorNo; /* 0x1 */ u8 mGroupNum; - /* 0x4 */ dDrawPath_c::group_class* mpGroup; + /* 0x4 */ STAGE_OFFSET_PTR(dDrawPath_c::group_class) mpGroup; }; // Size: 0x8 struct room_class { /* 0x0 */ u8 mFloorNum; - /* 0x4 */ dDrawPath_c::floor_class* mpFloor; - /* 0x8 */ f32* mpFloatData; // might be Vec or cXyz instead + /* 0x4 */ STAGE_OFFSET_PTR(dDrawPath_c::floor_class) mpFloor; + /* 0x8 */ STAGE_OFFSET_PTR(BE(f32)) mpFloatData; // might be Vec or cXyz instead }; struct layer_data { diff --git a/include/d/d_map_path_dmap.h b/include/d/d_map_path_dmap.h index c66d4861f8..bbffcd7809 100644 --- a/include/d/d_map_path_dmap.h +++ b/include/d/d_map_path_dmap.h @@ -50,9 +50,9 @@ struct dMapInfo_n { static bool chkGetCompass(); static bool chkGetMap(); static bool isVisitedRoom(int); - static void correctionOriginPos(s8, Vec*); - static void offsetPlus(dStage_FileList2_dt_c const*, Vec*); - static void rotAngle(dStage_FileList2_dt_c const*, Vec*); + static void correctionOriginPos(s8, BE(Vec)*); + static void offsetPlus(dStage_FileList2_dt_c const*, BE(Vec)*); + static void rotAngle(dStage_FileList2_dt_c const*, BE(Vec)*); static Vec getMapPlayerPos(); static s16 getMapPlayerAngleY(); static const dTres_c::typeGroupData_c* getConstRestartIconPointer(); @@ -127,7 +127,7 @@ public: virtual int getNextDrawLayerNo(int); virtual bool isDrawIconSingle(dTres_c::data_s const*, int, int, bool, bool, - Vec const*) const; + BE(Vec) const*) const; virtual int getIconGroupNumber(u8) const; virtual bool hasMap() const = 0; virtual bool isRendAllRoom() const = 0; @@ -177,7 +177,7 @@ public: virtual ~renderingPlusDoorAndCursor_c() {} virtual void afterDrawPath(); virtual f32 getIconSize(u8) const = 0; - virtual const Vec* getIconPosition(dTres_c::typeGroupData_c*) const; + virtual const BE(Vec)* getIconPosition(dTres_c::typeGroupData_c*) const; virtual dTres_c::typeGroupData_c* getFirstData(u8); virtual dTres_c::typeGroupData_c* getNextData(dTres_c::typeGroupData_c*); virtual f32 getPlayerCursorSize() = 0; diff --git a/include/d/d_menu_fmap.h b/include/d/d_menu_fmap.h index a8c528ac9d..a0648698bc 100644 --- a/include/d/d_menu_fmap.h +++ b/include/d/d_menu_fmap.h @@ -25,11 +25,11 @@ class mDoDvdThd_mountArchive_c; // Unknown name class dMenu_Fmap_field_data_c { public: - /* 0x00 */ u32 field_0x0; - /* 0x04 */ u32 mStageDataOffset; - /* 0x08 */ u32 mRegionDataOffset; - /* 0x0C */ u32 mVirtualStageOffset; - /* 0x10 */ u32 mRoomDataOffset; + /* 0x00 */ BE(u32) field_0x0; + /* 0x04 */ BE(u32) mStageDataOffset; + /* 0x08 */ BE(u32) mRegionDataOffset; + /* 0x0C */ BE(u32) mVirtualStageOffset; + /* 0x10 */ BE(u32) mRoomDataOffset; }; // Unknown name @@ -38,16 +38,16 @@ public: struct data { /* 0x00 */ u8 mTextureReadNum; /* 0x01 */ u8 field_0x1; - /* 0x02 */ u16 mTitleName; - /* 0x04 */ f32 mOriginX; - /* 0x08 */ f32 mOriginZ; - /* 0x0C */ f32 field_0xc; - /* 0x10 */ f32 field_0x10; - /* 0x14 */ f32 field_0x14; - /* 0x18 */ f32 field_0x18; - /* 0x1C */ f32 field_0x1c; - /* 0x20 */ f32 field_0x20; - /* 0x24 */ f32 field_0x24; + /* 0x02 */ BE(u16) mTitleName; + /* 0x04 */ BE(f32) mOriginX; + /* 0x08 */ BE(f32) mOriginZ; + /* 0x0C */ BE(f32) field_0xc; + /* 0x10 */ BE(f32) field_0x10; + /* 0x14 */ BE(f32) field_0x14; + /* 0x18 */ BE(f32) field_0x18; + /* 0x1C */ BE(f32) field_0x1c; + /* 0x20 */ BE(f32) field_0x20; + /* 0x24 */ BE(f32) field_0x24; }; /* 0x0 */ u8 mCount; @@ -72,7 +72,7 @@ class dMenu_Fmap_field_room_data_c { public: struct data { /* 0x0 */ char mStageName[8]; - /* 0x8 */ u16 mAreaName; + /* 0x8 */ BE(u16) mAreaName; /* 0xA */ u8 mCount; #ifdef _MSVC_LANG u8* __get_mRoomNos() const { return (u8*)(this + 1); } diff --git a/include/d/d_path.h b/include/d/d_path.h index 7a4e6576ac..71398e71bf 100644 --- a/include/d/d_path.h +++ b/include/d/d_path.h @@ -12,17 +12,17 @@ struct dPnt { /* 0x1 */ u8 mArg2; /* 0x2 */ u8 mArg3; /* 0x3 */ u8 mArg0; - /* 0x4 */ Vec m_position; + /* 0x4 */ BE(Vec) m_position; }; // Size: 0x10 struct dPath { - /* 0x0 */ u16 m_num; - /* 0x2 */ u16 m_nextID; + /* 0x0 */ BE(u16) m_num; + /* 0x2 */ BE(u16) m_nextID; /* 0x4 */ u8 field_0x4; /* 0x5 */ bool m_closed; /* 0x6 */ u8 field_0x6; /* 0x7 */ u8 field_0x7; - /* 0x8 */ dPnt* m_points; + /* 0x8 */ STAGE_OFFSET_PTR(dPnt) m_points; }; inline BOOL dPath_ChkClose(const dPath* i_path) { return i_path->m_closed & 1; } diff --git a/include/d/d_stage.h b/include/d/d_stage.h index 2575505291..db1b7ee02c 100644 --- a/include/d/d_stage.h +++ b/include/d/d_stage.h @@ -12,7 +12,8 @@ struct StageOffsetPtr { // Top bit is used to store "already relocated" flag as a guard thing. BE value; - void setBase(void* base); + bool setBase(void* base); + bool isRelocated(); template explicit operator T*() const { @@ -31,6 +32,36 @@ struct StageOffsetPtr { return (T*)POINTER_ADD(this, realOffset); } }; + +template +struct StageOffsetPtrT { + StageOffsetPtr value; + + bool setBase(void* base) { + return value.setBase(base); + } + bool isRelocated() { + return value.isRelocated(); + } + + T* operator->() { + return (T*) this; + } + + operator T*() const { + return (T*) value; + } + + template + explicit operator TOther*() const { + return (TOther*) value; + } +}; + + +#define STAGE_OFFSET_PTR(T) StageOffsetPtrT +#else +#define STAGE_OFFSET_PTR(T) T* #endif enum StageType { @@ -87,8 +118,8 @@ struct stage_tresure_data_class { }; // Size: 0x20 struct stage_tresure_class { - /* 0x00 */ int num; - /* 0x04 */ stage_tresure_data_class* m_entries; + /* 0x00 */ BE(int) num; + /* 0x04 */ STAGE_OFFSET_PTR(stage_tresure_data_class) m_entries; }; // STAG @@ -133,17 +164,17 @@ struct stage_scls_info_class { }; // Size: 0xD struct stage_scls_info_dummy_class { - /* 0x00 */ int num; - /* 0x04 */ stage_scls_info_class* m_entries; + /* 0x00 */ BE(int) num; + /* 0x04 */ STAGE_OFFSET_PTR(stage_scls_info_class) m_entries; }; // LGT struct stage_pure_lightvec_info_class { - /* 0x00 */ Vec position; - /* 0x0C */ f32 radius; - /* 0x10 */ f32 directionX; - /* 0x14 */ f32 directionY; - /* 0x18 */ f32 spotCutoff; + /* 0x00 */ BE(Vec) position; + /* 0x0C */ BE(f32) radius; + /* 0x10 */ BE(f32) directionX; + /* 0x14 */ BE(f32) directionY; + /* 0x18 */ BE(f32) spotCutoff; /* 0x1C */ u8 spot_type; /* 0x1D */ u8 dist_atten_type; /* 0x1E */ u8 flags; @@ -153,13 +184,13 @@ struct stage_pure_lightvec_info_class { // COLO struct stage_pselect_info_class { /* 0x0 */ u8 palette_id[8]; - /* 0x8 */ f32 change_rate; + /* 0x8 */ BE(f32) change_rate; }; // Size: 0xC // LGHT struct stage_plight_info_class { - /* 0x00 */ Vec position; - /* 0x0C */ f32 power; + /* 0x00 */ BE(Vec) position; + /* 0x0C */ BE(f32) power; /* 0x10 */ u8 field_0x10[0x18 - 0x10]; /* 0x18 */ color_RGB_class color; /* 0x1B */ u8 fluctuation; @@ -171,8 +202,8 @@ struct stage_palette_info_class { /* 0x03 */ color_RGB_class bg_amb_col[4]; /* 0x0F */ color_RGB_class plight_col[6]; /* 0x21 */ color_RGB_class fog_col; - /* 0x24 */ f32 fog_start_z; - /* 0x28 */ f32 fog_end_z; + /* 0x24 */ BE(f32) fog_start_z; + /* 0x28 */ BE(f32) fog_end_z; /* 0x2C */ u8 vrboxcol_id; /* 0x2D */ u8 bg_light_influence; /* 0x2E */ u8 cloud_shadow_density; @@ -190,8 +221,8 @@ struct stage_map_info_class { }; // Size: 0x38 struct stage_map_info_dummy_class { - /* 0x0 */ int num; - /* 0x4 */ stage_map_info_class* m_entries; + /* 0x0 */ BE(int) num; + /* 0x4 */ STAGE_OFFSET_PTR(stage_map_info_class) m_entries; }; // Env @@ -206,29 +237,29 @@ struct stage_camera2_data_class { /* 0x11 */ u8 field_0x11; /* 0x12 */ u8 field_0x12; /* 0x13 */ u8 field_0x13; - /* 0x14 */ u16 field_0x14; - /* 0x16 */ u16 field_0x16; + /* 0x14 */ BE(u16) field_0x14; + /* 0x16 */ BE(u16) field_0x16; }; // Size: 0x18 struct stage_camera_class { - /* 0x0 */ int num; - /* 0x4 */ stage_camera2_data_class* m_entries; + /* 0x0 */ BE(int) num; + /* 0x4 */ STAGE_OFFSET_PTR(stage_camera2_data_class) m_entries; }; // AROB / RARO struct stage_arrow_data_class { - /* 0x00 */ f32 posX; - /* 0x04 */ f32 posY; - /* 0x08 */ f32 posZ; - /* 0x0C */ s16 angleX; - /* 0x0E */ s16 angleY; - /* 0x10 */ s16 angleZ; - /* 0x12 */ s16 field_0x12; + /* 0x00 */ BE(f32) posX; + /* 0x04 */ BE(f32) posY; + /* 0x08 */ BE(f32) posZ; + /* 0x0C */ BE(s16) angleX; + /* 0x0E */ BE(s16) angleY; + /* 0x10 */ BE(s16) angleZ; + /* 0x12 */ BE(s16) field_0x12; }; // Size: 0x14 struct stage_arrow_class { - /* 0x00 */ int num; - /* 0x04 */ stage_arrow_data_class* m_entries; + /* 0x00 */ BE(int) num; + /* 0x04 */ STAGE_OFFSET_PTR(stage_arrow_data_class) m_entries; }; // ACT @@ -238,8 +269,8 @@ struct stage_actor_data_class { }; // Size: 0x20 struct stage_actor_class { - /* 0x0 */ int num; - /* 0x4 */ stage_actor_data_class* m_entries; + /* 0x0 */ BE(int) num; + /* 0x4 */ STAGE_OFFSET_PTR(stage_actor_data_class) m_entries; }; // TGSC / SCOB / TGDR / Door @@ -252,14 +283,14 @@ struct stage_tgsc_data_class { STATIC_ASSERT(sizeof(stage_tgsc_data_class) == 0x24); struct stage_tgsc_class { - /* 0x00 */ int num; - /* 0x04 */ stage_tgsc_data_class* m_entries; + /* 0x00 */ BE(int) num; + /* 0x04 */ STAGE_OFFSET_PTR(stage_tgsc_data_class) m_entries; }; // MPAT struct map_path_class { - /* 0x0 */ int num; - /* 0x4 */ void* m_entries; + /* 0x0 */ BE(int) num; + /* 0x4 */ STAGE_OFFSET_PTR(void) m_entries; }; // RTBL @@ -267,18 +298,18 @@ struct roomRead_data_class { /* 0x0 */ u8 num; /* 0x1 */ u8 field_0x1; /* 0x2 */ u8 field_0x2; - /* 0x4 */ u8* m_rooms; + /* 0x4 */ STAGE_OFFSET_PTR(u8) m_rooms; }; // Size: 0x8 struct roomRead_class { - /* 0x0 */ int num; - /* 0x4 */ roomRead_data_class** m_entries; + /* 0x0 */ BE(int) num; + /* 0x4 */ STAGE_OFFSET_PTR(STAGE_OFFSET_PTR(roomRead_data_class)) m_entries; }; // MEM struct dStage_MemoryMap_c { - /* 0x0 */ int m_num; - /* 0x4 */ u32* field_0x4; + /* 0x0 */ BE(int) m_num; + /* 0x4 */ STAGE_OFFSET_PTR(BE(u32)) field_0x4; }; // MEC @@ -288,41 +319,41 @@ struct dStage_MemoryConfig_data { }; // Size: 0x2 struct dStage_MemoryConfig_c { - /* 0x0 */ int m_num; - /* 0x4 */ dStage_MemoryConfig_data* field_0x4; + /* 0x0 */ BE(int) m_num; + /* 0x4 */ STAGE_OFFSET_PTR(dStage_MemoryConfig_data) field_0x4; }; // PATH / RPAT struct dPath; struct dStage_dPath_c { - /* 0x0 */ int m_num; - /* 0x4 */ dPath* m_path; + /* 0x0 */ BE(int) m_num; + /* 0x4 */ STAGE_OFFSET_PTR(dPath) m_path; }; // PPNT / RPPN struct dStage_dPnt_c { - /* 0x0 */ int num; - /* 0x4 */ u32 m_pnt_offset; + /* 0x0 */ BE(int) num; + /* 0x4 */ STAGE_OFFSET_PTR(void) m_pnt_offset; }; // Size: 0x8 // MULT struct dStage_Mult_info { - /* 0x0 */ f32 mTransX; - /* 0x4 */ f32 mTransY; - /* 0x8 */ s16 mAngle; + /* 0x0 */ BE(f32) mTransX; + /* 0x4 */ BE(f32) mTransY; + /* 0x8 */ BE(s16) mAngle; /* 0xA */ u8 mRoomNo; }; // Size: 0xC class dStage_Multi_c { public: - /* 0x0 */ int num; - /* 0x4 */ dStage_Mult_info* m_entries; + /* 0x0 */ BE(int) num; + /* 0x4 */ STAGE_OFFSET_PTR(dStage_Mult_info) m_entries; }; // SOND struct stage_sound_data { /* 0x00 */ char field_0x0[8]; - /* 0x08 */ Vec field_0x8; + /* 0x08 */ BE(Vec) field_0x8; /* 0x14 */ u8 field_0x14; /* 0x15 */ u8 field_0x15; /* 0x16 */ u8 field_0x16; @@ -333,55 +364,55 @@ struct stage_sound_data { }; // Size: 0x1C struct dStage_SoundInfo_c { - /* 0x0 */ int num; - /* 0x4 */ stage_sound_data* entries; + /* 0x0 */ BE(int) num; + /* 0x4 */ STAGE_OFFSET_PTR(stage_sound_data) entries; }; // FILI class dStage_FileList_dt_c { public: - /* 0x00 */ u32 mParameters; - /* 0x04 */ f32 mSeaLevel; - /* 0x08 */ f32 field_0x8; - /* 0x0C */ f32 field_0xc; + /* 0x00 */ BE(u32) mParameters; + /* 0x04 */ BE(f32) mSeaLevel; + /* 0x08 */ BE(f32) field_0x8; + /* 0x0C */ BE(f32) field_0xc; /* 0x10 */ u8 field_0x10[10]; /* 0x1A */ u8 mDefaultCamera; /* 0x1B */ u8 mBitSw; - /* 0x1C */ u16 mMsg; + /* 0x1C */ BE(u16) mMsg; }; // Size: 0x20 // FILI class dStage_FileList2_dt_c { public: - /* 0x00 */ f32 mLeftRmX; - /* 0x04 */ f32 mInnerRmZ; - /* 0x08 */ f32 mRightRmX; - /* 0x0C */ f32 mFrontRmZ; + /* 0x00 */ BE(f32) mLeftRmX; + /* 0x04 */ BE(f32) mInnerRmZ; + /* 0x08 */ BE(f32) mRightRmX; + /* 0x0C */ BE(f32) mFrontRmZ; /* 0x10 */ u8 mMinFloorNo; /* 0x11 */ u8 mMaxFloorNo; /* 0x12 */ u8 field_0x12; /* 0x13 */ u8 field_0x13; - /* 0x14 */ f32 field_0x14; - /* 0x18 */ f32 field_0x18; - /* 0x1C */ s16 field_0x1c; + /* 0x14 */ BE(f32) field_0x14; + /* 0x18 */ BE(f32) field_0x18; + /* 0x1C */ BE(s16) field_0x1c; }; // Size: 0x20 struct dStage_FileList2_c { - /* 0x0 */ int num; - /* 0x4 */ dStage_FileList2_dt_c* entries; + /* 0x0 */ BE(int) num; + /* 0x4 */ STAGE_OFFSET_PTR(dStage_FileList2_dt_c) entries; }; // FLOR struct dStage_FloorInfo_dt_c { // Copied from TWW, may not be right - /* 0x00 */ int field_0x00; + /* 0x00 */ BE(int) field_0x00; /* 0x04 */ u8 floorNo; /* 0x05 */ s8 field_0x05[14]; }; // Size: 0x14 struct dStage_FloorInfo_c { - /* 0x00 */ int num; - /* 0x04 */ dStage_FloorInfo_dt_c* m_entries; + /* 0x00 */ BE(int) num; + /* 0x04 */ STAGE_OFFSET_PTR(dStage_FloorInfo_dt_c) m_entries; }; // LBNK @@ -393,8 +424,8 @@ public: }; struct dStage_Lbnk_c { - /* 0x0 */ int num; - /* 0x4 */ dStage_Lbnk_dt_c* entries; + /* 0x0 */ BE(int) num; + /* 0x4 */ STAGE_OFFSET_PTR(dStage_Lbnk_dt_c) entries; }; struct dStage_Elst_dt_c { @@ -402,22 +433,22 @@ struct dStage_Elst_dt_c { }; // Size: 0xF struct dStage_Elst_c { - /* 0x0 */ int m_entryNum; - /* 0x4 */ dStage_Elst_dt_c* m_entries; + /* 0x0 */ BE(int) m_entryNum; + /* 0x4 */ STAGE_OFFSET_PTR(dStage_Elst_dt_c) m_entries; }; // DMAP struct dStage_DMap_dt_c { // Copied from TWW, may not be right - /* 0x00 */ int field_0x00; - /* 0x04 */ int field_0x04; - /* 0x08 */ int field_0x08; - /* 0x0C */ f32 offsetY; + /* 0x00 */ BE(int) field_0x00; + /* 0x04 */ BE(int) field_0x04; + /* 0x08 */ BE(int) field_0x08; + /* 0x0C */ BE(f32) offsetY; }; // Size: 0x10 struct dStage_DMap_c { - /* 0x00 */ int num; - /* 0x04 */ dStage_DMap_dt_c* entries; + /* 0x00 */ BE(int) num; + /* 0x04 */ STAGE_OFFSET_PTR(dStage_DMap_dt_c) entries; }; /** @@ -449,7 +480,7 @@ struct dStage_MapEvent_dt_c { /* 0x0D */ char event_name[13]; struct { /* 0x0D */ u8 field_0xd[0x14 - 0xD]; - /* 0x14 */ u16 field_0x14; + /* 0x14 */ BE(u16) field_0x14; /* 0x16 */ u8 field_0x16; /* 0x17 */ u8 field_0x17; /* 0x18 */ u8 sound_type; @@ -469,8 +500,8 @@ enum dStage_MapEvent_dt_type { }; struct dStage_MapEventInfo_c { - /* 0x0 */ int num; - /* 0x4 */ dStage_MapEvent_dt_c* m_entries; + /* 0x0 */ BE(int) num; + /* 0x4 */ STAGE_OFFSET_PTR(dStage_MapEvent_dt_c) m_entries; }; class dStage_dt_c { diff --git a/include/d/d_tresure.h b/include/d/d_tresure.h index 53315bacdc..5cb52e563b 100644 --- a/include/d/d_tresure.h +++ b/include/d/d_tresure.h @@ -12,7 +12,7 @@ public: /* 0x01 */ s8 mRoomNo; /* 0x02 */ u8 mStatus; /* 0x03 */ u8 mArg1; - /* 0x04 */ Vec mPos; + /* 0x04 */ BE(Vec) mPos; /* 0x10 */ u8 mSwBit; /* 0x11 */ u8 mType; /* 0x12 */ u8 mArg2; @@ -30,7 +30,7 @@ public: u8 getStatus() const { return mStatus; } void setStatus(u8 status) { mStatus = status; } void setArg1(u8 arg1) { mArg1 = arg1; } - const Vec* getPos() const { return &mPos; } + const BE(Vec)* getPos() const { return &mPos; } void setPos(const Vec& pos) { mPos = pos; } u8 getSwBit() const { return mSwBit; } void setSwBit(u8 swBit) { mSwBit = swBit; } @@ -48,8 +48,8 @@ public: }; // Size: 0x1C struct list_class { - /* 0x0 */ int field_0x0; - /* 0x4 */ typeGroupData_c* field_0x4; + /* 0x0 */ BE(int) field_0x0; + /* 0x4 */ STAGE_OFFSET_PTR(typeGroupData_c) field_0x4; /* 0x8 */ u8 mNumber; }; diff --git a/include/dusk/endian.h b/include/dusk/endian.h index 179bdf046e..756c391fe0 100644 --- a/include/dusk/endian.h +++ b/include/dusk/endian.h @@ -84,6 +84,24 @@ struct BE { static T swap[[nodiscard]](T val); }; +#define BIN_ASSIGN_OP(op) \ + \ +template \ +constexpr BE& operator op(BE& a, TB b) { \ + TA aCopy = a; \ + aCopy op b; \ + a = aCopy; \ + return a; \ +} + + +BIN_ASSIGN_OP(&=); +BIN_ASSIGN_OP(|=); +BIN_ASSIGN_OP(+=); +BIN_ASSIGN_OP(/=); + +#undef BIN_ASSIGN_OP + template<> inline u16 BE::swap(u16 val) { return RES_U16(val); @@ -115,6 +133,18 @@ struct BE { BE y; BE z; + BE() = default; + BE(f32 x, f32 y, f32 z) { + this->x = x; + this->y = y; + this->z = z; + } + BE(const Vec& from) { + x = from.x; + y = from.y; + z = from.z; + } + operator Vec() const { return { x, y, z }; } diff --git a/include/dusk/endian_ssystem.h b/include/dusk/endian_ssystem.h new file mode 100644 index 0000000000..fe9248ffa4 --- /dev/null +++ b/include/dusk/endian_ssystem.h @@ -0,0 +1,65 @@ +#ifndef _DUSK_ENDIAN_SSYSTEM_H_ +#define _DUSK_ENDIAN_SSYSTEM_H_ + +#include "SSystem/SComponent/c_sxyz.h" +#include "endian.h" + +template<> +struct BE { + BE x; + BE y; + BE z; + + auto & operator =(const csXyz & arg) { + this->x = arg.x; + this->y = arg.y; + this->z = arg.z; + return *this; + } + + void set(s16 oX, s16 oY, s16 oZ) { + x = oX; + y = oY; + z = oZ; + } + + operator csXyz() const { + return { x, y, z }; + } + + static csXyz swap(csXyz val) { + return { + BE::swap(val.x), + BE::swap(val.y), + BE::swap(val.z), + }; + } +}; + +template<> +struct BE { + BE x; + BE y; + BE z; + + auto & operator =(const cXyz & arg) { + this->x = arg.x; + this->y = arg.y; + this->z = arg.z; + return *this; + } + + operator cXyz() const { + return { x, y, z }; + } + + static cXyz swap(cXyz val) { + return { + BE::swap(val.x), + BE::swap(val.y), + BE::swap(val.z), + }; + } +}; + +#endif \ No newline at end of file diff --git a/include/f_op/f_op_actor_mng.h b/include/f_op/f_op_actor_mng.h index 868671d2d8..22e8953e19 100644 --- a/include/f_op/f_op_actor_mng.h +++ b/include/f_op/f_op_actor_mng.h @@ -11,6 +11,7 @@ #include "f_op/f_op_draw_tag.h" #include "f_pc/f_pc_manager.h" #include "m_Do/m_Do_hostIO.h" +#include "dusk/endian_ssystem.h" #define fopAcM_ct(ptr, ClassName) \ if (!fopAcM_CheckCondition(ptr, fopAcCnd_INIT_e)) { \ @@ -48,10 +49,10 @@ extern int HeapAdjustMargin; } // namespace fopAcM struct fopAcM_prmBase_class { - /* 0x00 */ u32 parameters; - /* 0x04 */ cXyz position; - /* 0x10 */ csXyz angle; - /* 0x16 */ u16 setID; + /* 0x00 */ BE(u32) parameters; + /* 0x04 */ BE(cXyz) position; + /* 0x10 */ BE(csXyz) angle; + /* 0x16 */ BE(u16) setID; }; // Size: 0x18 struct fopAcM_prmScale_class { diff --git a/include/m_Do/m_Do_mtx.h b/include/m_Do/m_Do_mtx.h index 01acd05b50..07197f557d 100644 --- a/include/m_Do/m_Do_mtx.h +++ b/include/m_Do/m_Do_mtx.h @@ -4,7 +4,9 @@ #include "SSystem/SComponent/c_sxyz.h" #include "SSystem/SComponent/c_xyz.h" #include + #include "JSystem/JMath/JMath.h" +#include "dusk/endian.h" extern u8 g_printCurrentHeapDebug; extern u8 g_printOtherHeapDebug; @@ -263,6 +265,12 @@ public: * @param b The output Vec */ static void multVec(const Vec* a, Vec* b) { PSMTXMultVec(now, a, b); } +#if TARGET_LITTLE_ENDIAN + static void multVec(const BE(Vec)* a, Vec* b) { + Vec aCopy = *a; + multVec(&aCopy, b); + } +#endif /** * Multiplies a given Vec `a` by the `now` Matrix's "Scale-and-Rotate" component and places the result into Vec `b` diff --git a/src/JSystem/J3DGraphBase/J3DTevs.cpp b/src/JSystem/J3DGraphBase/J3DTevs.cpp index d71aa20255..bc6ba63ac9 100644 --- a/src/JSystem/J3DGraphBase/J3DTevs.cpp +++ b/src/JSystem/J3DGraphBase/J3DTevs.cpp @@ -362,7 +362,11 @@ J3DFogInfo const j3dDefaultFogInfo = { }; J3DNBTScaleInfo const j3dDefaultNBTScaleInfo = { +#if TARGET_PC + 0x00, {1.0f, 1.0f, 1.0f}, +#else 0x00, 1.0f, 1.0f, 1.0f, +#endif }; static u8 j3dTexCoordTable[7623]; diff --git a/src/d/actor/d_a_e_kr.cpp b/src/d/actor/d_a_e_kr.cpp index 4001092815..7fc010678a 100644 --- a/src/d/actor/d_a_e_kr.cpp +++ b/src/d/actor/d_a_e_kr.cpp @@ -398,7 +398,7 @@ static BOOL coach_path_check(e_kr_class* i_this) { return FALSE; } - Vec* pointPos = &i_this->field_0x6e4->m_points[0].m_position; + BE(Vec)* pointPos = &i_this->field_0x6e4->m_points[0].m_position; f32 x = pointPos->x - coach->current.pos.x; f32 z = pointPos->z - coach->current.pos.z; if (JMAFastSqrt(x * x + z * z) < 500.0f + KREG_F(9)) { diff --git a/src/d/actor/d_a_e_ym.cpp b/src/d/actor/d_a_e_ym.cpp index 9180972082..b28780c193 100644 --- a/src/d/actor/d_a_e_ym.cpp +++ b/src/d/actor/d_a_e_ym.cpp @@ -2314,7 +2314,7 @@ void daE_YM_c::executeRail() { void daE_YM_c::executeBackRail() { static f32 YM_DIG_POS_Y[] = {-15.0f, -30.0f, -70.0f}; - cXyz my_vec_0 = dPath_GetPnt(mpPath, mCurrentPntNo)->m_position; + cXyz my_vec_0 = (Vec)dPath_GetPnt(mpPath, mCurrentPntNo)->m_position; switch (mMode) { case 0: { if (current.pos.abs(my_vec_0) < 150.0f) { @@ -2774,7 +2774,7 @@ void daE_YM_c::setLockByCargo() { void daE_YM_c::executeRiver() { cXyz player_pos = daPy_getPlayerActorClass()->current.pos; - cXyz pnt_pos = dPath_GetPnt(mpPath, mCurrentPntNo)->m_position; + cXyz pnt_pos = (Vec)dPath_GetPnt(mpPath, mCurrentPntNo)->m_position; cXyz my_vec_0; f32 next_path; switch (mMode) { diff --git a/src/d/actor/d_a_horse.cpp b/src/d/actor/d_a_horse.cpp index e6303ca10e..22c18f61e5 100644 --- a/src/d/actor/d_a_horse.cpp +++ b/src/d/actor/d_a_horse.cpp @@ -1086,7 +1086,7 @@ int daHorse_c::checkDemoAction() { void daHorse_c::setStickRodeoMove() { if (m_rodeoPath != NULL) { - Vec* path_pnt_pos = &m_rodeoPath->m_points[m_rodeoPoint].m_position; + BE(Vec)* path_pnt_pos = &m_rodeoPath->m_points[m_rodeoPoint].m_position; cXyz pos_vec(path_pnt_pos->x - current.pos.x, path_pnt_pos->y - current.pos.y, path_pnt_pos->z - current.pos.z); f32 dist_to_pnt = pos_vec.absXZ(); @@ -3324,8 +3324,8 @@ int daHorse_c::callHorseSubstance(cXyz const* i_pos) { if (m_path != NULL && (checkStateFlg0(FLG0_NO_DRAW_WAIT) || dist_xz2 > SQUARE(2000.0f))) { daAlink_c* player = daAlink_getAlinkActorClass(); - Vec* farthest_pos; - Vec* path_pnt_pos; + BE(Vec)* farthest_pos; + BE(Vec)* path_pnt_pos; for (int i = 0; i < m_path->m_num; i++) { path_pnt_pos = &m_path->m_points[i].m_position; diff --git a/src/d/actor/d_a_kago.cpp b/src/d/actor/d_a_kago.cpp index 4e2b90659d..50c12fe4eb 100644 --- a/src/d/actor/d_a_kago.cpp +++ b/src/d/actor/d_a_kago.cpp @@ -1228,8 +1228,8 @@ void daKago_c::executeFly() { void daKago_c::executeStagger() { dCamera_c* camera = dCam_getBody(); - cXyz cStack_94 = dPath_GetPnt(mpPath1, mPathIdx)->m_position; - cXyz cStack_a0 = dPath_GetPnt(mpPath1, mPathIdx - mPathIdxOffset)->m_position; + cXyz cStack_94 = (Vec)dPath_GetPnt(mpPath1, mPathIdx)->m_position; + cXyz cStack_a0 = (Vec)dPath_GetPnt(mpPath1, mPathIdx - mPathIdxOffset)->m_position; field_0x714 = cLib_targetAngleY(&cStack_a0, &cStack_94); @@ -1732,14 +1732,14 @@ void daKago_c::initPerchDemo() { field_0x771 = 0; } - cXyz cStack_48 = dPath_GetPnt(mpPath2, field_0x771)->m_position; + cXyz cStack_48 = (Vec)dPath_GetPnt(mpPath2, field_0x771)->m_position; s16 sVar5 = cLib_targetAngleY(¤t.pos, &cStack_48); int local_80 = 2; if (local_80 >= (int)mpPath2->m_num) { local_80 = mpPath2->m_num - 1; } - cXyz cStack_54 = dPath_GetPnt(mpPath2, local_80)->m_position; + cXyz cStack_54 = (Vec)dPath_GetPnt(mpPath2, local_80)->m_position; s16 sp08 = cLib_targetAngleY(¤t.pos, &cStack_48); if ((s16)(sVar5 - sp08) < 0) { sVar5 = sVar5 - 0x1000; @@ -1888,7 +1888,7 @@ bool daKago_c::executePerchDemo() { current.pos.y = current.pos.y + field_0x6fc; if (field_0x72c != 0) { - cXyz cStack_64 = dPath_GetPnt(mpPath2, field_0x771)->m_position; + cXyz cStack_64 = (Vec)dPath_GetPnt(mpPath2, field_0x771)->m_position; cLib_addCalcAngleS(¤t.angle.y, cLib_targetAngleY(¤t.pos, &cStack_64), 0x20, 0x100, 0x40); if (current.pos.abs(cStack_64) < 200.0f) { field_0x771++; @@ -3272,8 +3272,8 @@ void daKago_c::moveDemoFly() { } } - cXyz unkXyz1 = dPath_GetPnt(mpPath1, mPathIdx)->m_position; - cXyz unkXyz2 = dPath_GetPnt(mpPath1, mPathIdx - mPathIdxOffset)->m_position; + cXyz unkXyz1 = (Vec)dPath_GetPnt(mpPath1, mPathIdx)->m_position; + cXyz unkXyz2 = (Vec)dPath_GetPnt(mpPath1, mPathIdx - mPathIdxOffset)->m_position; s16 targetYaw = field_0x714 = cLib_targetAngleY(&unkXyz2, &unkXyz1); if (dComIfGp_getStartStagePoint() == 0) { diff --git a/src/d/actor/d_a_kytag03.cpp b/src/d/actor/d_a_kytag03.cpp index b1a5c745ea..84de5f2b46 100644 --- a/src/d/actor/d_a_kytag03.cpp +++ b/src/d/actor/d_a_kytag03.cpp @@ -28,7 +28,12 @@ static void dEnvSe_getNearPathPos(cXyz* param_0, cXyz* param_1, dPath* i_path) { cM3dGLin sp14; for (i = 0; i < i_path->m_num; i++) { +#if TARGET_LITTLE_ENDIAN + Vec copy = point_p->m_position; + sp8 = cM3d_LenSq(param_1, ©); +#else sp8 = cM3d_LenSq(param_1, &point_p->m_position); +#endif if (var_f31 > sp8) { var_f31 = sp8; var_r31 = i; diff --git a/src/d/actor/d_a_npc_cd2.cpp b/src/d/actor/d_a_npc_cd2.cpp index 503bff2d3f..c3bfee4aff 100644 --- a/src/d/actor/d_a_npc_cd2.cpp +++ b/src/d/actor/d_a_npc_cd2.cpp @@ -1025,7 +1025,12 @@ void PathTrace_c::setAvoidPoint() { JUT_ASSERT(1604, mObstacle != NULL); cXyz& selfPos = fopAcM_GetPosition(mMyself); s16 obstacleAngle = cLib_targetAngleY(&selfPos, &fopAcM_GetPosition(mObstacle)); +#if TARGET_LITTLE_ENDIAN + Vec copy = dPath_GetPnt(mPath, field_0x20)->m_position; + s16 diff = (s16)obstacleAngle - cLib_targetAngleY(&selfPos, ©); +#else s16 diff = (s16)obstacleAngle - cLib_targetAngleY(&selfPos, &dPath_GetPnt(mPath, field_0x20)->m_position); +#endif s16 rot; if (diff > 0) { rot = (s16)obstacleAngle + 0x4000; diff --git a/src/d/actor/d_a_npc_tk.cpp b/src/d/actor/d_a_npc_tk.cpp index e9980c953e..db8ce55c19 100644 --- a/src/d/actor/d_a_npc_tk.cpp +++ b/src/d/actor/d_a_npc_tk.cpp @@ -1970,8 +1970,8 @@ void daNPC_TK_c::calcWolfDemoCam() { void daNPC_TK_c::calcWolfDemoCam2() { cXyz targetPos; - cXyz curPos = dPath_GetPnt(mWolfPathData, mPathStep2)->m_position; - cXyz prevPos = dPath_GetPnt(mWolfPathData, mPathStep2 - 1)->m_position; + cXyz curPos = (Vec)dPath_GetPnt(mWolfPathData, mPathStep2)->m_position; + cXyz prevPos = (Vec)dPath_GetPnt(mWolfPathData, mPathStep2 - 1)->m_position; cLib_addCalcPos2(&field_0x6fc, curPos, 0.2f, field_0x714); cXyz offset(0.0f, 0.0f, 400.0f); @@ -2273,11 +2273,11 @@ void daNPC_TK_c::executeWolfPerch() { field_0x6e0 = field_0x6e0 + field_0x6e4; } - cXyz pathPnt3 = dPath_GetPnt(mWolfPathData, mWolfPathData->m_num - 1)->m_position; + cXyz pathPnt3 = (Vec)dPath_GetPnt(mWolfPathData, mWolfPathData->m_num - 1)->m_position; if (pathPnt3.abs(current.pos) < 500.0f) { cXyz cStack_8c; - cXyz cStack_98 = dPath_GetPnt(mWolfPathData, mWolfPathData->m_num - 2)->m_position; - cXyz cStack_a4 = dPath_GetPnt(mWolfPathData, mWolfPathData->m_num - 1)->m_position; + cXyz cStack_98 = (Vec)dPath_GetPnt(mWolfPathData, mWolfPathData->m_num - 2)->m_position; + cXyz cStack_a4 = (Vec)dPath_GetPnt(mWolfPathData, mWolfPathData->m_num - 1)->m_position; mDoMtx_stack_c::YrotS(-cLib_targetAngleY(&cStack_98, &cStack_a4)); mDoMtx_stack_c::transM(-current.pos.x, -current.pos.y, -current.pos.z); mDoMtx_stack_c::multVec(&cStack_98, &cStack_8c); @@ -2368,8 +2368,14 @@ void daNPC_TK_c::executeWolfPerch() { pathPnt2 = dPath_GetPnt(mWolfPathData, mPathStep2)->m_position; cLib_addCalcPos2(&field_0x6fc, pathPnt2, 0.1f, 3.0f); +#if TARGET_LITTLE_ENDIAN + Vec copy = dPath_GetPnt(mWolfPathData, mPathStep2 - 1)->m_position; + s16 angleY = cLib_targetAngleY(¤t.pos, + ©); +#else s16 angleY = cLib_targetAngleY(¤t.pos, &dPath_GetPnt(mWolfPathData, mPathStep2 - 1)->m_position); +#endif cLib_addCalcAngleS(&shape_angle.y, angleY + 0x2000, 8, 0x100, 0x10); cLib_chaseF(&speed.y, field_0x678, 0.5f); diff --git a/src/d/actor/d_a_obj_laundry_rope.cpp b/src/d/actor/d_a_obj_laundry_rope.cpp index f23271db21..4c73bccc51 100644 --- a/src/d/actor/d_a_obj_laundry_rope.cpp +++ b/src/d/actor/d_a_obj_laundry_rope.cpp @@ -26,8 +26,8 @@ void daObjLndRope_c::create_init() { dPath* roomPath = dPath_GetRoomPath(getPathId(), fopAcM_GetRoomNo(this)); dPnt* pathPoints = roomPath->m_points; - cXyz startPoint = pathPoints[0].m_position; - cXyz endPoint = pathPoints[1].m_position; + cXyz startPoint = (Vec)pathPoints[0].m_position; + cXyz endPoint = (Vec)pathPoints[1].m_position; current.pos = (startPoint + endPoint) * 0.5f; mPos = endPoint - startPoint; diff --git a/src/d/actor/d_a_spinner.cpp b/src/d/actor/d_a_spinner.cpp index 497f8a75d5..9d43468e1f 100644 --- a/src/d/actor/d_a_spinner.cpp +++ b/src/d/actor/d_a_spinner.cpp @@ -223,8 +223,8 @@ int daSpinner_c::posMove() { cXyz sp54; while (var_f31 > 0.0f) { - Vec* curr_path_pos = &mpPathMove->m_points[mPathNo].m_position; - Vec* next_path_pos = getPathNextPos(); + BE(Vec)* curr_path_pos = &mpPathMove->m_points[mPathNo].m_position; + BE(Vec)* next_path_pos = getPathNextPos(); cXyz sp48(current.pos.x, current.pos.y - -20.0f, current.pos.z); cXyz sp3C(curr_path_pos->x - next_path_pos->x, curr_path_pos->y - next_path_pos->y, curr_path_pos->z - next_path_pos->z); @@ -420,8 +420,13 @@ void daSpinner_c::setAnm() { mButtonJump = true; } - if (mpPathMove != NULL) { + if (mpPathMove != NULL) { +#if TARGET_PC + Vec copy = mpPathMove->m_points[mPathNo].m_position; + s16 targetAngle = cLib_targetAngleY(©, ¤t.pos); +#else s16 targetAngle = cLib_targetAngleY(&mpPathMove->m_points[mPathNo].m_position, ¤t.pos); +#endif if (s16(targetAngle - current.angle.y) > 0) { current.angle.y += 0x3000; } else { @@ -447,7 +452,7 @@ int daSpinner_c::setNextPathNum() { return 0; } -Vec* daSpinner_c::getPathNextPos() { +BE(Vec)* daSpinner_c::getPathNextPos() { int next_point_no = mPathNo + mPathDirection; if (next_point_no < 0) { return &(mpPathMove->m_points + mpPathMove->m_num - 1)->m_position; diff --git a/src/d/actor/d_a_tag_Lv7Gate.cpp b/src/d/actor/d_a_tag_Lv7Gate.cpp index cf402f4848..a55a7fa517 100644 --- a/src/d/actor/d_a_tag_Lv7Gate.cpp +++ b/src/d/actor/d_a_tag_Lv7Gate.cpp @@ -77,8 +77,8 @@ int daTagLv7Gate_c::setPath(int i_path_ID) { return 0; } - cXyz pos1 = dPath_GetPnt(mRoomPath, 0)->m_position; - cXyz pos2 = dPath_GetPnt(mRoomPath, 1)->m_position; + cXyz pos1 = (Vec)dPath_GetPnt(mRoomPath, 0)->m_position; + cXyz pos2 = (Vec)dPath_GetPnt(mRoomPath, 1)->m_position; mPos1.set(pos1); diff --git a/src/d/actor/d_a_tag_guard.cpp b/src/d/actor/d_a_tag_guard.cpp index 661a907e70..7b28c3df1a 100644 --- a/src/d/actor/d_a_tag_guard.cpp +++ b/src/d/actor/d_a_tag_guard.cpp @@ -54,7 +54,13 @@ void daTagGuard_c::create_init() { current.pos.z = pnt1->m_position.z; #endif +#if TARGET_LITTLE_ENDIAN + Vec copy1 = pnt1->m_position; + Vec copy2 = pnt1->m_position; + current.angle.y = cLib_targetAngleY(©1, ©2); +#else current.angle.y = cLib_targetAngleY(&pnt1->m_position, &pnt2->m_position); +#endif } static int daTagGuard_Create(fopAc_ac_c* i_this) { diff --git a/src/d/actor/d_a_tbox.cpp b/src/d/actor/d_a_tbox.cpp index a9a58b44fd..827b85695e 100644 --- a/src/d/actor/d_a_tbox.cpp +++ b/src/d/actor/d_a_tbox.cpp @@ -642,7 +642,7 @@ void daTbox_c::dropProcInit() { JUT_ASSERT(0x56A, path_p != NULL); cXyz pos = current.pos; - cXyz pnt1 = path_p->m_points[1].m_position; + cXyz pnt1 = (Vec)path_p->m_points[1].m_position; f32 var_f30; if (path_p->m_num == 2) { @@ -681,7 +681,7 @@ int daTbox_c::calcJumpGoalAndAngle(cXyz* i_pos, s16* i_angle) { dPath* path_p = dPath_GetRoomPath(getPathId(), -1); if (path_p != NULL) { cXyz home_pos = home.pos; - cXyz vec2 = path_p->m_points[1].m_position; + cXyz vec2 = (Vec)path_p->m_points[1].m_position; f32 dist_xz = home_pos.absXZ(vec2); s16 angle; @@ -748,7 +748,7 @@ void daTbox_c::dropProcInit2() { f32 temp; if (path_p->m_num == 2) { cXyz vec1 = current.pos; - cXyz vec2 = path_p->m_points[1].m_position; + cXyz vec2 = (Vec)path_p->m_points[1].m_position; field_0x97c = false; f32 delta_y = vec1.y - vec2.y; f32 abs_gravity = fabsf(fopAcM_GetGravity(this)); diff --git a/src/d/d_camera.cpp b/src/d/d_camera.cpp index cd2c187a20..647e958159 100644 --- a/src/d/d_camera.cpp +++ b/src/d/d_camera.cpp @@ -7431,7 +7431,7 @@ bool dCamera_c::towerCamera(s32 param_0) { tower->field_0x54.x = mRoomMapTool.mArrowData.posX; tower->field_0x54.y = mRoomMapTool.mArrowData.posY; tower->field_0x54.z = mRoomMapTool.mArrowData.posZ; - tower->field_0x60 = mRoomMapTool.mArrowData.angleY; + tower->field_0x60 = (s16)mRoomMapTool.mArrowData.angleY; tower->field_0x64 = stack_454 <= cSAngle::_90 ? 1 : 0; } @@ -8013,8 +8013,8 @@ bool dCamera_c::railCamera(s32 param_0) { rail->field_0x20.z = mRoomMapTool.mArrowData.posZ; if (mCamParam.Flag(param_0, 0x800)) { cXyz attnPos = attentionPos(mpPlayerActor); - cXyz curPointPos = roomPath->m_points->m_position; - cXyz prevPointPos = roomPath->m_points[roomPathLen - 1].m_position; + cXyz curPointPos = (Vec)roomPath->m_points->m_position; + cXyz prevPointPos = (Vec)roomPath->m_points[roomPathLen - 1].m_position; f32 horDist1 = dCamMath::xyzHorizontalDistance(curPointPos, attnPos); f32 horDist2 = dCamMath::xyzHorizontalDistance(prevPointPos, attnPos); if (horDist1 < horDist2) { @@ -8343,8 +8343,8 @@ bool dCamera_c::paraRailCamera(s32 param_0) { if (!unkFlag2) { cXyz sp1F4 = attentionPos(mpPlayerActor); - cXyz sp1E8 = path->m_points->m_position; - cXyz sp1DC = path->m_points[pathLen - 1].m_position; + cXyz sp1E8 = (Vec)path->m_points->m_position; + cXyz sp1DC = (Vec)path->m_points[pathLen - 1].m_position; f32 horDist1 = dCamMath::xyzHorizontalDistance(sp1E8, sp1F4); f32 horDist2 = dCamMath::xyzHorizontalDistance(sp1DC, sp1F4); if (horDist1 < horDist2) { diff --git a/src/d/d_com_inf_game.cpp b/src/d/d_com_inf_game.cpp index 57b76d8b10..518efa1304 100644 --- a/src/d/d_com_inf_game.cpp +++ b/src/d/d_com_inf_game.cpp @@ -2152,12 +2152,12 @@ u32 dComIfG_getTrigA(u32 i_padNo) { } struct field_data_header { - /* 0x00 */ u32 field_0x0; - /* 0x04 */ u32 field_0x4; - /* 0x08 */ u32 field_0x8; - /* 0x0C */ u32 field_0xc; - /* 0x10 */ u32 field_0x10; - /* 0x14 */ u32 field_0x14; + /* 0x00 */ BE(u32) field_0x0; + /* 0x04 */ BE(u32) field_0x4; + /* 0x08 */ BE(u32) field_0x8; + /* 0x0C */ BE(u32) field_0xc; + /* 0x10 */ BE(u32) field_0x10; + /* 0x14 */ BE(u32) field_0x14; }; struct field_data { diff --git a/src/d/d_envse.cpp b/src/d/d_envse.cpp index df9a133bec..ab188fded1 100644 --- a/src/d/d_envse.cpp +++ b/src/d/d_envse.cpp @@ -29,7 +29,12 @@ static void dEnvSe_getNearPathPos(cXyz* param_0, cXyz* param_1, dPath* i_path) { cM3dGLin sp14; for (i = 0; i < i_path->m_num; i++) { +#if TARGET_PC + Vec posCopy = point_p->m_position; + sp8 = cM3d_LenSq(param_1, &posCopy); +#else sp8 = cM3d_LenSq(param_1, &point_p->m_position); +#endif if (var_f31 > sp8) { var_f31 = sp8; var_r31 = i; @@ -88,9 +93,16 @@ int dEnvSe_c::execute_common(dStage_SoundInfo_c* i_soundInf, s8* param_1, u8 par if (memcmp(data_p->field_0x0, "sndtag", 6) == 0) { if (!(*param_1 & 1)) { if (data_p->field_0x17 != 0) { +#if TARGET_LITTLE_ENDIAN + Vec copy = data_p->field_0x8; + mDoAud_mEnvse_initStaticEnvSe(data_p->field_0x17, data_p->field_0x14, + data_p->field_0x19, data_p->field_0x1a, + ©); +#else mDoAud_mEnvse_initStaticEnvSe(data_p->field_0x17, data_p->field_0x14, data_p->field_0x19, data_p->field_0x1a, &data_p->field_0x8); +#endif } *param_1 |= 1; } diff --git a/src/d/d_map.cpp b/src/d/d_map.cpp index 1cc6a4dfb4..ec24566ae7 100644 --- a/src/d/d_map.cpp +++ b/src/d/d_map.cpp @@ -730,7 +730,7 @@ const GXColor* renderingAmap_c::getDecoLineColor(int param_0, int param_1) { } } -const Vec* dMap_c::getIconPosition(dTres_c::typeGroupData_c* i_data) const { +const BE(Vec)* dMap_c::getIconPosition(dTres_c::typeGroupData_c* i_data) const { #if DEBUG if (dMap_HIO_prm_res_dst_s::m_other.field_0x8a && i_data) { u8 r29 = i_data->getTypeGroupNo(); diff --git a/src/d/d_map_path.cpp b/src/d/d_map_path.cpp index ca95a043fd..0ad5f42f19 100644 --- a/src/d/d_map_path.cpp +++ b/src/d/d_map_path.cpp @@ -235,7 +235,7 @@ void dDrawPath_c::rendering(dDrawPath_c::line_class const* p_line) { GXSetTevColor(GX_TEVREG0, *getLineColor(p_line->field_0x0 & 0x3F, p_line->field_0x1)); GXBegin(GX_LINESTRIP, GX_VTXFMT0, p_line->mDataNum); - u16* tmp = p_line->mpData; + BE(u16)* tmp = p_line->mpData; for (int i = 0; i < p_line->mDataNum; i++) { GXPosition1x16(*tmp); tmp++; @@ -252,7 +252,7 @@ void dDrawPath_c::rendering(dDrawPath_c::poly_class const* p_poly) { if (p_poly->mDataNum >= 3) { GXBegin(GX_TRIANGLESTRIP, GX_VTXFMT0, p_poly->mDataNum); - u16* tmp = p_poly->mpData; + BE(u16)* tmp = p_poly->mpData; for (int i = 0; i < p_poly->mDataNum; i++) { GXPosition1x16(*tmp); tmp++; @@ -457,7 +457,7 @@ void dRenderingFDAmap_c::renderingDecoration(dDrawPath_c::line_class const* p_li GXSetNumTevStages(1); GXLoadTexObj(dMpath_n::m_texObjAgg.getTexObjPointer(6), GX_TEXMAP0); - u16* data_p = p_line->mpData; + BE(u16)* data_p = p_line->mpData; s32 data_num = p_line->mDataNum; GXSetLineWidth(width, GX_TO_ONE); GXSetPointSize(width, GX_TO_ONE); diff --git a/src/d/d_map_path_dmap.cpp b/src/d/d_map_path_dmap.cpp index 4f45717806..77491eb467 100644 --- a/src/d/d_map_path_dmap.cpp +++ b/src/d/d_map_path_dmap.cpp @@ -24,7 +24,7 @@ bool dMapInfo_n::isVisitedRoom(int i_roomNo) { return g_fmapHIO.mAllRegionsUnlocked || dComIfGs_isVisitedRoom(i_roomNo); } -void dMapInfo_n::correctionOriginPos(s8 i_roomNo, Vec* o_pos) { +void dMapInfo_n::correctionOriginPos(s8 i_roomNo, BE(Vec)* o_pos) { dStage_FileList2_dt_c* filelist = dStage_roomControl_c::getFileList2(i_roomNo); if (o_pos != NULL) { @@ -33,7 +33,7 @@ void dMapInfo_n::correctionOriginPos(s8 i_roomNo, Vec* o_pos) { } } -void dMapInfo_n::offsetPlus(dStage_FileList2_dt_c const* filelist, Vec* o_pos) { +void dMapInfo_n::offsetPlus(dStage_FileList2_dt_c const* filelist, BE(Vec)* o_pos) { if (filelist == NULL) { return; } @@ -42,7 +42,7 @@ void dMapInfo_n::offsetPlus(dStage_FileList2_dt_c const* filelist, Vec* o_pos) { o_pos->z += filelist->field_0x18; } -void dMapInfo_n::rotAngle(dStage_FileList2_dt_c const* filelist, Vec* o_pos) { +void dMapInfo_n::rotAngle(dStage_FileList2_dt_c const* filelist, BE(Vec)* o_pos) { s16 rot = 0; if (filelist != NULL) { @@ -57,7 +57,7 @@ void dMapInfo_n::rotAngle(dStage_FileList2_dt_c const* filelist, Vec* o_pos) { } Vec dMapInfo_n::getMapPlayerPos() { - Vec pos; + BE(Vec) pos; fopAc_ac_c* player = daPy_getPlayerActorClass(); if (player != NULL) { pos = player->current.pos; @@ -117,7 +117,7 @@ const dTres_c::typeGroupData_c* dMapInfo_n::getConstRestartIconPointer() { } Vec dMapInfo_n::getMapRestartPos() { - Vec pos; + BE(Vec) pos; const dTres_c::typeGroupData_c* icon_data = getConstRestartIconPointer(); if (icon_data != NULL) { @@ -389,8 +389,12 @@ void dMpath_c::createWork() { } int dMpath_c::setPointer(dDrawPath_c::room_class* i_room, s8* param_1, s8* param_2) { - int var_r6 = 0; + intptr_t var_r6 = 0; +#if TARGET_PC + if (i_room->mpFloor.isRelocated()) { +#else if ((uintptr_t)i_room->mpFloor >= 0x80000000) { +#endif dDrawPath_c::floor_class* floor_p = i_room->mpFloor; for (int i = 0; i < i_room->mFloorNum; i++) { if (floor_p->mFloorNo < *param_1) { @@ -415,33 +419,58 @@ int dMpath_c::setPointer(dDrawPath_c::room_class* i_room, s8* param_1, s8* param dDrawPath_c::line_class* line_e = &group_e->mpLine[group_e->mLineNum - 1]; return (uintptr_t)(line_e->mpData + line_e->mDataNum) - (uintptr_t)i_room; } - + +#if TARGET_PC + i_room->mpFloor.setBase(i_room); + i_room->mpFloatData.setBase(i_room); +#else i_room->mpFloor = (dDrawPath_c::floor_class*)((uintptr_t)i_room + (uintptr_t)i_room->mpFloor); i_room->mpFloatData = (f32*)((uintptr_t)i_room + (uintptr_t)i_room->mpFloatData); +#endif dDrawPath_c::floor_class* floor_p = i_room->mpFloor; - int room = (intptr_t)i_room; + intptr_t room = (intptr_t)i_room; for (int i = 0; i < i_room->mFloorNum; i++) { +#if TARGET_PC + floor_p->mpGroup.setBase((void*) room); +#else floor_p->mpGroup = (dDrawPath_c::group_class*)(room + (uintptr_t)floor_p->mpGroup); +#endif dDrawPath_c::group_class* group_p = floor_p->mpGroup; for (int j = 0; j < floor_p->mGroupNum; j++) { - var_r6 = (uintptr_t)group_p->mpPoly; + var_r6 = (intptr_t)(void*)group_p->mpPoly; +#if TARGET_PC + group_p->mpLine.setBase((void*) room); +#else group_p->mpLine = (dDrawPath_c::line_class*)(room + (uintptr_t)group_p->mpLine); +#endif dDrawPath_c::line_class* line_p = group_p->mpLine; for (int k = 0; k < group_p->mLineNum; k++) { var_r6 = (uintptr_t)(line_p->mpData + line_p->mDataNum); +#if TARGET_PC + line_p->mpData.setBase((void*)room); +#else line_p->mpData = (u16*)(room + (uintptr_t)line_p->mpData); +#endif line_p++; } +#if TARGET_PC + group_p->mpPoly.setBase((void*)room); +#else group_p->mpPoly = (dDrawPath_c::poly_class*)(room + (uintptr_t)group_p->mpPoly); - +#endif + dDrawPath_c::poly_class* poly_p = group_p->mpPoly; for (int l = 0; l < group_p->mPolyNum; l++) { var_r6 = (uintptr_t)(poly_p->mpData + poly_p->mDataNum); +#if TARGET_PC + poly_p->mpData.setBase((void*)room); +#else poly_p->mpData = (u16*)(room + (uintptr_t)poly_p->mpData); +#endif poly_p++; } @@ -874,7 +903,7 @@ void renderingPlusDoor_c::drawNormalDoorS(stage_tgsc_data_class const* i_doorDat GXSetTevColor(GX_TEVREG2, l_doorWhiteNoStay2); } - Vec spC; + BE(Vec) spC; spC.x = i_doorData->base.position.x; spC.y = i_doorData->base.position.y; spC.z = i_doorData->base.position.z; @@ -903,7 +932,7 @@ bool renderingDAmap_c::isDrawRoomIcon(int param_0, int param_1) const { } bool renderingDAmap_c::isDrawIconSingle(dTres_c::data_s const* data, int param_1, int param_2, - bool param_3, bool param_4, Vec const* param_5) const { + bool param_3, bool param_4, BE(Vec) const* param_5) const { bool draw_room_icon = isDrawRoomIcon(data->mRoomNo, param_1); bool tmp = false; @@ -926,7 +955,7 @@ renderingPlusDoorAndCursor_c::getNextData(dTres_c::typeGroupData_c* param_0) { return dTres_c::getNextData(param_0); } -const Vec* +const BE(Vec)* renderingPlusDoorAndCursor_c::getIconPosition(dTres_c::typeGroupData_c* i_typeGroupData) const { return i_typeGroupData->getPos(); } @@ -1005,7 +1034,7 @@ void renderingPlusDoorAndCursor_c::drawTreasure() { GXSetTevColor(GX_TEVREG2, sp18); for (int j = 0; j < group_num && typeGroupData_p != NULL; j++) { - const Vec* icon_pos = getIconPosition(typeGroupData_p); + const BE(Vec)* icon_pos = getIconPosition(typeGroupData_p); if (tmp == 0) { if (mRoomNoSingle != typeGroupData_p->getRoomNo()) { @@ -1079,7 +1108,7 @@ void renderingPlusDoorAndCursor_c::drawTreasureAfterPlayer() { GXSetTevColor(GX_TEVREG2, sp18); for (int j = 0; j < group_num && typeGroupData_p != NULL; j++) { - const Vec* icon_pos = getIconPosition(typeGroupData_p); + const BE(Vec)* icon_pos = getIconPosition(typeGroupData_p); if (tmp == 0) { if (mRoomNoSingle != typeGroupData_p->getRoomNo()) { diff --git a/src/d/d_map_path_fmap.cpp b/src/d/d_map_path_fmap.cpp index f3fbef9441..cde2e800b7 100644 --- a/src/d/d_map_path_fmap.cpp +++ b/src/d/d_map_path_fmap.cpp @@ -130,12 +130,12 @@ dMenu_Fmap_stage_data_c* dMenu_Fmap_region_data_c::getMenuFmapStageData(int para int dMenu_Fmap_region_data_c::getPointStagePathInnerNo(f32 i_pointX, f32 i_pointZ, int i_stageNo, int* o_stageNo, int* o_roomNo) { int line_num, group_num, floor_num; - f32* point; - u16* point_index; + BE(f32)* point; + BE(u16)* point_index; dDrawPath_c::line_class* line; dDrawPath_c::group_class* group; dDrawPath_c::floor_class* floor; - f32* points; + BE(f32)* points; dMenu_Fmap_room_data_c* room; dMenu_Fmap_stage_data_c* stage; int point_num, point_no; @@ -191,7 +191,7 @@ int dMenu_Fmap_region_data_c::getPointStagePathInnerNo(f32 i_pointX, f32 i_point outside = false; point_index = line->mpData; - f32* prev_point = &points[point_index[0] * 2]; + BE(f32)* prev_point = &points[point_index[0] * 2]; point = &points[point_index[1] * 2]; point_no = 2; point_index += 2; diff --git a/src/d/d_menu_dmap_map.cpp b/src/d/d_menu_dmap_map.cpp index e2f157ff88..1f5e43dd49 100644 --- a/src/d/d_menu_dmap_map.cpp +++ b/src/d/d_menu_dmap_map.cpp @@ -366,7 +366,7 @@ bool dMenu_StageMapCtrl_c::getTreasureList(f32* o_posX, f32* o_posY, s8* param_2 bool var_r30 = false; while (field_0xe4 != 0 && !var_r30) { - Vec sp10; + BE(Vec) sp10; sp10 = *field_0x8c->getPos(); if (getRendPointer(0)->isDrawIconSingle(field_0x8c->getDataPointer(), (s8)dComIfGp_roomControl_getStayNo(), field_0xf7, 1, true, &sp10)) { diff --git a/src/d/d_msg_flow.cpp b/src/d/d_msg_flow.cpp index 29075fe597..a2a9590554 100644 --- a/src/d/d_msg_flow.cpp +++ b/src/d/d_msg_flow.cpp @@ -2101,7 +2101,12 @@ int dMsgFlow_c::event020(mesg_flow_node_event* i_flowNode_p, fopAc_ac_c* i_speak for (int i = 0; i < room->getPlayerNum(); i++, actor_data++) { if ((u8)actor_data->base.angle.z == prm0) { +#if TARGET_LITTLE_ENDIAN + cXyz copy = actor_data->base.position; + player->setPlayerPosAndAngle(©, player->current.angle.y, 0); +#else player->setPlayerPosAndAngle(&actor_data->base.position, player->current.angle.y, 0); +#endif break; } } diff --git a/src/d/d_spline_path.cpp b/src/d/d_spline_path.cpp index 40b0b61300..5e27450a2a 100644 --- a/src/d/d_spline_path.cpp +++ b/src/d/d_spline_path.cpp @@ -99,7 +99,7 @@ cXyz dPathCurve::bSpline2(f32 param_0) { cXyz local_7c; int uVar12 = mpPath->m_num; if (uVar12 <= 1) { - return mpPath->m_points[0].m_position; + return (Vec)mpPath->m_points[0].m_position; } else if (uVar12 == 2) { local_7c.x = param_0 * (mpPath->m_points[1].m_position.x - mpPath->m_points[0].m_position.x); @@ -134,9 +134,9 @@ cXyz dPathCurve::bSpline2(f32 param_0) { uVar9 = uVar4; iVar8 = uVar4 + 1; } - Vec* point11 = &mpPath->m_points[iVar10].m_position; - Vec* point10 = &mpPath->m_points[uVar9].m_position; - Vec* point8 = &mpPath->m_points[iVar8].m_position; + BE(Vec)* point11 = &mpPath->m_points[iVar10].m_position; + BE(Vec)* point10 = &mpPath->m_points[uVar9].m_position; + BE(Vec)* point8 = &mpPath->m_points[iVar8].m_position; local_7c.x = point11->x * fVar7 + point10->x * fVar6 + point8->x * fVar5; local_7c.y = point11->y * fVar7 + point10->y * fVar6 + point8->y * fVar5; local_7c.z = point11->z * fVar7 + point10->z * fVar6 + point8->z * fVar5; diff --git a/src/d/d_stage.cpp b/src/d/d_stage.cpp index 494a858752..1cc14d7796 100644 --- a/src/d/d_stage.cpp +++ b/src/d/d_stage.cpp @@ -2064,15 +2064,20 @@ static int dStage_doorInfoInit(dStage_dt_c* i_stage, void* i_data, int entryNum, static int dStage_roomReadInit(dStage_dt_c* i_stage, void* i_data, int param_2, void* param_3) { UNUSED(param_2); roomRead_class* p_node = (roomRead_class*)((int*)i_data + 1); - roomRead_data_class** rtbl = p_node->m_entries; + STAGE_OFFSET_PTR(roomRead_data_class)* rtbl = p_node->m_entries; i_stage->setRoom(p_node); for (int i = 0; i < p_node->num; i++) { +#if TARGET_PC + rtbl[i].setBase(param_3); + rtbl[i]->m_rooms.setBase(param_3); +#else if ((intptr_t)rtbl[i] < 0x80000000) { rtbl[i] = (roomRead_data_class*)((intptr_t)rtbl[i] + (intptr_t)param_3); rtbl[i]->m_rooms = (u8*)((intptr_t)rtbl[i]->m_rooms + (intptr_t)param_3); } +#endif } return 1; @@ -2104,9 +2109,13 @@ static int dStage_pathInfoInit(dStage_dt_c* i_stage, void* i_data, int entryNum, i_stage->setPathInfo(path_c); for (int i = 0; i < path_c->m_num; i++) { +#if TARGET_PC + path->m_points.setBase(i_stage->getPntInf()->m_pnt_offset); +#else if ((uintptr_t)path->m_points < 0x80000000) { path->m_points = (dPnt*)((uintptr_t)path->m_points + i_stage->getPntInf()->m_pnt_offset); } +#endif path++; } @@ -2129,10 +2138,14 @@ static int dStage_rpatInfoInit(dStage_dt_c* i_stage, void* i_data, int i_num, vo i_stage->setPath2Info(pStagePath); for (s32 i = 0; i < pStagePath->m_num; pPath++, i++, (void)0) { +#if TARGET_PC + pPath->m_points.setBase(i_stage->getPnt2Inf()->m_pnt_offset); +#else if ((uintptr_t)pPath->m_points >= 0x80000000) { continue; } pPath->m_points = (dPnt*)((uintptr_t)pPath->m_points + i_stage->getPnt2Inf()->m_pnt_offset); +#endif } return 1; } @@ -2226,7 +2239,7 @@ static int dStage_memaInfoInit(dStage_dt_c* i_stage, void* i_data, int param_2, if (pd != NULL) { OS_REPORT("Memory Block Create !\n"); - u32* entry_p = pd->field_0x4; + BE(u32)* entry_p = pd->field_0x4; JUT_ASSERT(3208, pd->m_num <= dStage_roomControl_c::MEMORY_BLOCK_MAX); for (int i = 0; i < pd->m_num; i++) { @@ -2911,12 +2924,16 @@ void dStage_escapeRestart() { #endif #if TARGET_PC -void StageOffsetPtr::setBase(void* base) { +bool StageOffsetPtr::isRelocated() { + return value & 0x8000'0000; +} + +bool StageOffsetPtr::setBase(void* base) { JUT_ASSERT(__LINE__, value != 0); - if (value & 0x8000'0000) { + if (isRelocated()) { // Already relocated, don't touch it again! - return; + return false; } ptrdiff_t diff = (u8*)this - (u8*)base; @@ -2927,5 +2944,6 @@ void StageOffsetPtr::setBase(void* base) { } value = newDiff | 0x8000'0000; + return true; } #endif diff --git a/src/d/d_tresure.cpp b/src/d/d_tresure.cpp index b6083b6294..b00dc294dd 100644 --- a/src/d/d_tresure.cpp +++ b/src/d/d_tresure.cpp @@ -213,7 +213,7 @@ void dTres_c::setPosition(int dataNo, u8 listIdx, Vec const* i_pos, int i_roomNo for (int i = getTypeGroupNumber(listIdx); i > 0; i--) { if (dataNo == groupData->getNo()) { - Vec pos; + BE(Vec) pos; pos.x = i_pos->x; pos.y = i_pos->y; pos.z = i_pos->z;