From 0fea52b87d3395069cd6f4ce149d2409e2d20641 Mon Sep 17 00:00:00 2001 From: Seeky <58006653+SeekyCt@users.noreply.github.com> Date: Thu, 29 Aug 2024 20:15:58 +0100 Subject: [PATCH] Changes from decomp --- README.md | 12 +- configure.py | 2 +- include/common.h | 14 +- include/spm/camdrv.h | 3 +- include/spm/evtmgr_cmd.h | 2 +- include/spm/fadedrv.h | 5 +- include/spm/hud.h | 2 +- include/spm/mario_pouch.h | 8 +- include/spm/seq_title.h | 61 +++- include/spm/spmario_snd.h | 14 +- include/spm/system.h | 6 +- include/wii/gx.h | 16 +- include/wii/mem.h | 20 +- include/wii/mtx.h | 28 +- include_cpp/msl/exception.h | 48 +++ include_cpp/msl/new.h | 36 ++ include_cpp/nw4r/db/panic.h | 14 + include_cpp/nw4r/lyt/animation.h | 29 ++ include_cpp/nw4r/lyt/arcResourceAccessor.h | 43 +++ include_cpp/nw4r/lyt/drawInfo.h | 30 ++ include_cpp/nw4r/lyt/layout.h | 54 +++ include_cpp/nw4r/lyt/material.h | 25 ++ include_cpp/nw4r/lyt/pane.h | 49 +++ include_cpp/nw4r/lyt/resourceAccessor.h | 19 ++ include_cpp/nw4r/math/types.h | 98 ++++++ {include => include_cpp}/nw4r/snd.h | 0 include_cpp/nw4r/ut/color.h | 48 +++ include_cpp/nw4r/ut/linkList.h | 380 +++++++++++++++++++++ include_cpp/nw4r/ut/nonCopyable.h | 21 ++ include_cpp/nw4r/ut/rect.h | 15 + 30 files changed, 1049 insertions(+), 53 deletions(-) create mode 100644 include_cpp/msl/exception.h create mode 100644 include_cpp/msl/new.h create mode 100644 include_cpp/nw4r/db/panic.h create mode 100644 include_cpp/nw4r/lyt/animation.h create mode 100644 include_cpp/nw4r/lyt/arcResourceAccessor.h create mode 100644 include_cpp/nw4r/lyt/drawInfo.h create mode 100644 include_cpp/nw4r/lyt/layout.h create mode 100644 include_cpp/nw4r/lyt/material.h create mode 100644 include_cpp/nw4r/lyt/pane.h create mode 100644 include_cpp/nw4r/lyt/resourceAccessor.h create mode 100644 include_cpp/nw4r/math/types.h rename {include => include_cpp}/nw4r/snd.h (100%) create mode 100644 include_cpp/nw4r/ut/color.h create mode 100644 include_cpp/nw4r/ut/linkList.h create mode 100644 include_cpp/nw4r/ut/nonCopyable.h create mode 100644 include_cpp/nw4r/ut/rect.h diff --git a/README.md b/README.md index 2015dcd..812a2c9 100644 --- a/README.md +++ b/README.md @@ -19,19 +19,19 @@ It is recommended to use this with [git subrepo](https://github.com/ingydotnet/g ## Decomp -For use in decomp, the `include` and `decomp` folders should be added to the include path, and the preprocessor define `DECOMP` should be used. +For use in decomp, the `include`, `include_cpp` and `decomp` folders should be added to the include path, and the preprocessor define `DECOMP` should be used. -### Testing +## Mods -The `SKIP_PPCDIS` preprocessor define will stop `ppcdis.h` being included. +For use in mods, the `include`, `include_cpp` and `mod` folder should be added to the include path and an lst from `linker` should be used. If including your compiler's C++ standard library, the preprocessor define `USE_STL` should be used. -## Mods +## C -For use in mods, the `include` and `mod` folder should be added to the include path and an lst from `linker` should be used. If including your compiler's C++ standard library, the preprocessor define `USE_STL` should be used. +For the cases where C is required (such as m2c or maybe some niche modding cases), omitting the `include_cpp` folder should be all that's neccessary. # Licensing -All code originally written for this project (everything under the `include`, `decomp` and `linker` directories) is available under the MIT license. +All code originally written for this project (everything under the `include`, `include_cpp`, `decomp` and `linker` directories) is available under the MIT license. Everything under the `mod` folder is available under the GPLv3 license as it's derived from other GPL code. diff --git a/configure.py b/configure.py index 14927e5..b18969f 100644 --- a/configure.py +++ b/configure.py @@ -245,7 +245,7 @@ def test_old_mod_ctx(regions: List[str]): def test_decomp_ctx(regions: List[str]): assert args.codewarrior, "Error: decomp_ctx test requires --codewarrior" compile_regions(os.path.join("$builddir", "{region}", "decomp.o"), "$decomp_source", regions, - DECOMP_INCLUDES, ["DECOMP", "SKIP_PPCDIS"], True) + DECOMP_INCLUDES, ["DECOMP"], True) # Test shuffled include orders def test_mod_ctx_shuffle(regions: List[str]): diff --git a/include/common.h b/include/common.h index 0f5457a..5d15183 100644 --- a/include/common.h +++ b/include/common.h @@ -1,12 +1,7 @@ #pragma once -#if (defined DECOMP) && !(defined SKIP_PPCDIS) -// Decomp should include ppcdis.h in all files -#include -#else -// Unknown function is useful outside of decomp too +// Unknown function declaration #define UNKNOWN_FUNCTION(name) void name(void) -#endif // Intellisense doesn't like asm compiler extensions #ifdef __INTELLISENSE__ @@ -110,6 +105,13 @@ typedef u8 unk8; #define DECOMP_STATIC(expr) extern expr; #endif +// Macro for something that is deadstripped outside of decomp +#ifdef DECOMP + #define STRIPPED(expr) expr; +#else + #define STRIPPED(expr) +#endif + // Use extern "C" in C++, use namespacing in mods #ifdef __cplusplus #ifndef DECOMP diff --git a/include/spm/camdrv.h b/include/spm/camdrv.h index ab9f248..3546028 100644 --- a/include/spm/camdrv.h +++ b/include/spm/camdrv.h @@ -11,6 +11,7 @@ CPP_WRAPPER(spm::camdrv) +USING(wii::gx::GXProjectionType) USING(wii::mtx::Vec3) USING(wii::mtx::Mtx34) USING(wii::mtx::Mtx44) @@ -63,7 +64,7 @@ typedef struct _CamEntry /* 0x0F8 */ f32 left; /* 0x0FC */ f32 right; /* 0x100 */ u8 unknown_0x100[0x158 - 0x100]; -/* 0x158 */ s32 isOrtho; +/* 0x158 */ GXProjectionType projectionType; /* 0x15C */ Vec3 pos; /* 0x168 */ Vec3 target; /* 0x174 */ Vec3 up; diff --git a/include/spm/evtmgr_cmd.h b/include/spm/evtmgr_cmd.h index c625183..f143767 100644 --- a/include/spm/evtmgr_cmd.h +++ b/include/spm/evtmgr_cmd.h @@ -351,7 +351,7 @@ f32 evtSetFloat(EvtEntry * entry, EvtVar variable, f32 value); Returns a pointer to the instruction after the specified label in an entry's script */ -EvtScriptCode * evtSearchLabel(EvtEntry * entry, s32 id); // inlined +STRIPPED(EvtScriptCode * evtSearchLabel(EvtEntry * entry, s32 id)) /* Returns a pointer to the instruction after the next else on the diff --git a/include/spm/fadedrv.h b/include/spm/fadedrv.h index d5f85c6..344fe84 100644 --- a/include/spm/fadedrv.h +++ b/include/spm/fadedrv.h @@ -1,11 +1,14 @@ #pragma once #include +#include CPP_WRAPPER(spm::fadedrv) +USING(wii::gx::GXColor) + void fadeInit(); -UNKNOWN_FUNCTION(fadeEntry); +void fadeEntry(u32 transitionType, s32 param_2, GXColor colour); UNKNOWN_FUNCTION(func_80066558); void fadeMain(); UNKNOWN_FUNCTION(func_80066e4c); diff --git a/include/spm/hud.h b/include/spm/hud.h index 071d6e4..f0c4e4d 100644 --- a/include/spm/hud.h +++ b/include/spm/hud.h @@ -28,7 +28,7 @@ UNKNOWN_FUNCTION(hudDisp); void func_8019af88(); void hudTurnOffFlipTimeBox(s32 idx); UNKNOWN_FUNCTION(func_8019b0dc); -UNKNOWN_FUNCTION(func_8019be84); +void func_8019be84(); UNKNOWN_FUNCTION(func_8019bea8); CPP_WRAPPER_END() diff --git a/include/spm/mario_pouch.h b/include/spm/mario_pouch.h index 5bba922..b12badf 100644 --- a/include/spm/mario_pouch.h +++ b/include/spm/mario_pouch.h @@ -118,14 +118,14 @@ DECOMP_STATIC(MarioPouchWork mario_pouch_work2) Returns a pointer to the MarioPouchWork / MarioPouchWork2 instance */ MarioPouchWork * pouchGetPtr(); -MarioPouchWork2 * pouch2GetPtr(); // inlined +STRIPPED(MarioPouchWork2 * pouch2GetPtr()) /* Initialise data used by pouch functions Overwritten later once a save is loaded */ void pouchInit(); -void pouch2Init(); // inlined +STRIPPED(void pouch2Init()) void pouchReInit(); /* @@ -169,7 +169,7 @@ s32 pouchGetMaxHp(); /* Get/add to the player's xp */ -void pouchSetXp(s32 xp); // inlined +STRIPPED(void pouchSetXp(s32 xp)) s32 pouchGetXp(); void pouchAddXp(s32 increase); @@ -178,7 +178,7 @@ void pouchAddXp(s32 increase); */ void pouchSetCoin(s32 coins); s32 pouchGetCoin(); -void pouchAddTotalCoin(s32 increase); // inlined +STRIPPED(void pouchAddTotalCoin(s32 increase)) void pouchAddCoin(s32 increase); // increases totalCoinsCollected /* diff --git a/include/spm/seq_title.h b/include/spm/seq_title.h index 1bb692b..8b118e0 100644 --- a/include/spm/seq_title.h +++ b/include/spm/seq_title.h @@ -2,19 +2,72 @@ #include #include +#include + +#ifdef __cplusplus +#include +#include +#include +#include +#endif CPP_WRAPPER(spm::seq_title) USING(spm::seqdrv::SeqWork) +USING(wii::mem::MEMAllocator) + +/* + seqWork stage values +*/ + +// Wait for button press, or to timeout and replay intro +#define SEQ_TITLE_WAIT_INPUT -1 + +// Button pressed, start file select transition +#define SEQ_TITLE_FILE_SELECT_PRESS 0 + +// Wait for file select transition +#define SEQ_TITLE_FILE_SELECT_FADE 1 + +// Timeout, replay intro +#define SEQ_TITLE_REPLAY_TIMEOUT 2 + +// Wait for intro replay transition +#define SEQ_TITLE_REPLAY_FADE 3 + +typedef struct +{ +/* 0x00 */ s32 openingReplayTimer; +/* 0x04 */ u32 unknown_0x4; // unused? +/* 0x08 */ void * arc; +/* 0x0C */ void * heap; +/* 0x10 */ u32 heapSize; +/* 0x14 */ void * heapHandle; +/* 0x18 */ MEMAllocator allocator; +#ifdef __cplusplus +/* 0x28 */ nw4r::lyt::ArcResourceAccessor * arcResAccessor; +/* 0x2C */ nw4r::lyt::Layout * layout; +/* 0x30 */ nw4r::lyt::Pane * pushu2Pane; +/* 0x30 */ nw4r::lyt::Pane * pushuBotanPane; +/* 0x38 */ nw4r::lyt::AnimTransform * animations[2]; // 0 start, 1 loop +/* 0x40 */ nw4r::lyt::DrawInfo drawInfo; +#else +/* 0x28 */ u8 cpp_pad[0x94 - 0x28]; +#endif +/* 0x94 */ s32 animNum; +/* 0x98 */ f32 animFrame; +} SeqTitleWork; +SIZE_ASSERT(SeqTitleWork, 0x9c) void seq_titleInit(SeqWork * work); void seq_titleMain(SeqWork * work); void seq_titleExit(SeqWork * work); -UNKNOWN_FUNCTION(func_8017b49c); -UNKNOWN_FUNCTION(seqTitleInitLayout); -UNKNOWN_FUNCTION(func_8017b8ac); +void seqTitleDispCb(s32 cameraId, void * param); +void seqTitleInitLayout(); +STRIPPED(void seqTitleDeleteLayout()) +void seqTitleDisp(); // No idea why this is in this file of all places, but it is -const char * getNextDanMapname(s32 dungeonNo); +const char * getDanMapName(s32 dungeonNo); CPP_WRAPPER_END() diff --git a/include/spm/spmario_snd.h b/include/spm/spmario_snd.h index 335f9d0..74f618e 100644 --- a/include/spm/spmario_snd.h +++ b/include/spm/spmario_snd.h @@ -13,11 +13,11 @@ UNKNOWN_FUNCTION(spsndPause); UNKNOWN_FUNCTION(spsndUnpause); UNKNOWN_FUNCTION(func_8023872c); UNKNOWN_FUNCTION(spsndSetPosDirListener); -UNKNOWN_FUNCTION(spsndSetSFXReverbMode); +void spsndSetSFXReverbMode(u8 mode); UNKNOWN_FUNCTION(func_80238804); UNKNOWN_FUNCTION(func_80238868); UNKNOWN_FUNCTION(spsndSetFlag); -UNKNOWN_FUNCTION(spsndClearFlag); +void spsndClearFlag(u16 flags); UNKNOWN_FUNCTION(spsndGetFlag); UNKNOWN_FUNCTION(func_802388f4); UNKNOWN_FUNCTION(func_80238b04); @@ -29,7 +29,7 @@ UNKNOWN_FUNCTION(spsndSFXOn_UnkEffect); UNKNOWN_FUNCTION(_spsndSFXOn); UNKNOWN_FUNCTION(spsndSFXOn_3D); UNKNOWN_FUNCTION(spsndSFXOff); -UNKNOWN_FUNCTION(func_8023b38c); +void func_8023b38c(u32 param_1, u32 param_2); UNKNOWN_FUNCTION(spsndSetSfxPlayerPos); UNKNOWN_FUNCTION(spsndSFX_vol); UNKNOWN_FUNCTION(spsndSFX_pit); @@ -50,13 +50,13 @@ bool spsndBGMOn(u32 flags, const char * name); UNKNOWN_FUNCTION(spsndBGMOn_f_d_alt); bool spsndBGMOff_f_d(s32 player, u32 fadeoutTime); UNKNOWN_FUNCTION(spsndBGMOff); -UNKNOWN_FUNCTION(spsndBGMOff_f_d_alt); +bool spsndBGMOff_f_d_alt(s32 player, s32 fadeoutTime); UNKNOWN_FUNCTION(func_8023cab4); UNKNOWN_FUNCTION(func_8023cc90); UNKNOWN_FUNCTION(func_8023cc98); UNKNOWN_FUNCTION(func_8023cc9c); UNKNOWN_FUNCTION(func_8023ce1c); -UNKNOWN_FUNCTION(func_8023ce20); +void func_8023ce20(s32 player, s32 param_2, s32 param_3); UNKNOWN_FUNCTION(func_8023cf14); UNKNOWN_FUNCTION(func_8023cfe8); UNKNOWN_FUNCTION(func_8023d0dc); @@ -68,9 +68,9 @@ UNKNOWN_FUNCTION(func_8023d2b8); UNKNOWN_FUNCTION(spsndENVMain); UNKNOWN_FUNCTION(spsndENVOn_f_d); UNKNOWN_FUNCTION(spsndENVOn); -UNKNOWN_FUNCTION(func_8023db5c); +bool func_8023db5c(s32 param_1, s32 param_2); UNKNOWN_FUNCTION(func_8023dc88); -UNKNOWN_FUNCTION(func_8023dc90); +bool func_8023dc90(s32 param_1, s32 param_2); UNKNOWN_FUNCTION(func_8023dc94); UNKNOWN_FUNCTION(func_8023dda4); UNKNOWN_FUNCTION(func_8023de90); diff --git a/include/spm/system.h b/include/spm/system.h index ca5be71..92d4539 100644 --- a/include/spm/system.h +++ b/include/spm/system.h @@ -89,9 +89,8 @@ s32 NORETURN ATTRIBUTE_FORMAT(printf, 4, 5) __assert2( /* Rounds a float to an int - Deadstripped, always inlined */ -s32 roundi(f32 x); +STRIPPED(s32 roundi(f32 x)) /* Adjusts an angle to be 0 <= x < 360 @@ -144,9 +143,8 @@ void sysRandInit(); /* Gets the current screen draw token - Deadstripped, always inlined */ -u16 sysGetToken(); +STRIPPED(u16 sysGetToken()) /* Waits until the next screen draw, or max 100ms diff --git a/include/wii/gx.h b/include/wii/gx.h index 1ed0739..0ed7c15 100644 --- a/include/wii/gx.h +++ b/include/wii/gx.h @@ -16,6 +16,13 @@ typedef struct { u8 r, g, b, a; } GXColor; +SIZE_ASSERT(GXColor, 0x4) + +typedef struct +{ + s16 r, g, b, a; +} GXColorS10; +SIZE_ASSERT(GXColorS10, 0x8) typedef struct { @@ -29,6 +36,13 @@ typedef struct } GXTexObj; SIZE_ASSERT(GXTexObj, 0x20) + +typedef enum +{ +/* 0x0 */ GX_PERSPECTIVE, +/* 0x1 */ GX_ORTHOGRAPHIC +} GXProjectionType; + // Parameters from libogc's gx.h UNKNOWN_FUNCTION(__GXDefaultTexRegionCallback); @@ -200,7 +214,7 @@ UNKNOWN_FUNCTION(GXEndDisplayList); UNKNOWN_FUNCTION(GXCallDisplayList); UNKNOWN_FUNCTION(GXProject); UNKNOWN_FUNCTION(__GXSetProjection); -void GXSetProjection(Mtx44 * mtx, u32 type); +void GXSetProjection(Mtx44 mtx, GXProjectionType type); UNKNOWN_FUNCTION(GXSetProjectionv); UNKNOWN_FUNCTION(GXGetProjectionv); void GXLoadPosMtxImm(Mtx34 * mtx, u32 pnidx); diff --git a/include/wii/mem.h b/include/wii/mem.h index 35a3b75..d7dbc41 100644 --- a/include/wii/mem.h +++ b/include/wii/mem.h @@ -35,6 +35,22 @@ typedef struct _MEMEXPHeap } MEMEXPHeap; SIZE_ASSERT(MEMEXPHeap, 0x50) +typedef struct +{ +/* 0x0 */ void * alloc; +/* 0x4 */ void * free; +} MEMAllocatorFunc; +SIZE_ASSERT(MEMAllocatorFunc, 8) + +typedef struct +{ +/* 0x0 */ MEMAllocatorFunc * func; +/* 0x4 */ void * heap; +/* 0x8 */ u32 heapP0; +/* 0x8 */ u32 heapP1; +} MEMAllocator; +SIZE_ASSERT(MEMAllocator, 0x10) + #define MEM_FLAG_FILL_0 (1 << 0) // initialise allocated memory as 0 #define MEM_FLAG_THREAD_CONTROL (1 << 2) // use mutexes for access when handling heap @@ -63,9 +79,9 @@ UNKNOWN_FUNCTION(AllocatorAllocForExpHeap_); UNKNOWN_FUNCTION(AllocatorFreeForExpHeap_); UNKNOWN_FUNCTION(AllocatorAllocForFrmHeap_); UNKNOWN_FUNCTION(AllocatorFreeForFrmHeap_); -UNKNOWN_FUNCTION(MEMAllocFromAllocator); +void * MEMAllocFromAllocator(MEMAllocator * allocator, size_t size); UNKNOWN_FUNCTION(MEMFreeToAllocator); -UNKNOWN_FUNCTION(MEMInitAllocatorForExpHeap); +void MEMInitAllocatorForExpHeap(MEMAllocator * allocator, MEMHeapHandle heap, u32 alignment); UNKNOWN_FUNCTION(MEMInitAllocatorForFrmHeap); UNKNOWN_FUNCTION(MEMInitList); UNKNOWN_FUNCTION(MEMAppendListObject); diff --git a/include/wii/mtx.h b/include/wii/mtx.h index 9fb63e7..f0a067c 100644 --- a/include/wii/mtx.h +++ b/include/wii/mtx.h @@ -33,8 +33,8 @@ typedef struct typedef f32 Mtx34[3][4]; typedef f32 Mtx44[4][4]; -void PSMTXIdentity(Mtx34 * dest); -UNKNOWN_FUNCTION(PSMTXCopy); +void PSMTXIdentity(Mtx34 dest); +void PSMTXCopy(const Mtx34 src, Mtx34 dest); UNKNOWN_FUNCTION(PSMTXConcat); UNKNOWN_FUNCTION(PSMTXInverse); UNKNOWN_FUNCTION(PSMTXInvXpose); @@ -42,10 +42,10 @@ UNKNOWN_FUNCTION(PSMTXRotRad); UNKNOWN_FUNCTION(PSMTXRotTrig); UNKNOWN_FUNCTION(__PSMTXRotAxisRadInternal); UNKNOWN_FUNCTION(PSMTXRotAxisRad); -void PSMTXTrans(Mtx34 * dest, f32 x, f32 y, f32 z); -void PSMTXTransApply(Mtx34 * src, Mtx34 * dest, f32 x, f32 y, f32 z); -void PSMTXScale(Mtx34 * dest, f32 x, f32 y, f32 z); -void PSMTXScaleApply(Mtx34 * src, Mtx34 * dest, f32 x, f32 y, f32 z); +void PSMTXTrans(Mtx34 dest, f32 x, f32 y, f32 z); +void PSMTXTransApply(const Mtx34 src, Mtx34 dest, f32 x, f32 y, f32 z); +void PSMTXScale(Mtx34 dest, f32 x, f32 y, f32 z); +void PSMTXScaleApply(const Mtx34 src, Mtx34 dest, f32 x, f32 y, f32 z); UNKNOWN_FUNCTION(PSMTXQuat); UNKNOWN_FUNCTION(C_MTXLookAt); UNKNOWN_FUNCTION(C_MTXLightFrustum); @@ -56,18 +56,18 @@ UNKNOWN_FUNCTION(PSMTXMultVecArray); UNKNOWN_FUNCTION(PSMTXMultVecSR); UNKNOWN_FUNCTION(C_MTXFrustum); UNKNOWN_FUNCTION(C_MTXPerspective); -void C_MTXOrtho(Mtx44 * dest, f32 top, f32 bottom, f32 left, f32 right, f32 near, f32 far); +void C_MTXOrtho(Mtx44 dest, f32 top, f32 bottom, f32 left, f32 right, f32 near, f32 far); UNKNOWN_FUNCTION(PSMTX44Copy); UNKNOWN_FUNCTION(PSMTX44MultVec); UNKNOWN_FUNCTION(PSMTX44MultVecArray); UNKNOWN_FUNCTION(PSVECAdd); -void PSVECSubtract(Vec3 * src1, Vec3 * src2, Vec3 * dest); -void PSVECScale(Vec3 * src, Vec3 * dest, f32 scale); -void PSVECNormalize(Vec3 * src, Vec3 * dest); -f32 PSVecSquareMag(Vec3 * src); -f32 PSVecMag(Vec3 * src); -f32 PSVECDotProduct(Vec3 * src1, Vec3 * src2); -void PSVECCrossProduct(Vec3 * src1, Vec3 * src2, Vec3 * dest); +void PSVECSubtract(const Vec3 * src1, const Vec3 * src2, Vec3 * dest); +void PSVECScale(const Vec3 * src, Vec3 * dest, f32 scale); +void PSVECNormalize(const Vec3 * src, Vec3 * dest); +f32 PSVecSquareMag(const Vec3 * src); +f32 PSVecMag(const Vec3 * src); +f32 PSVECDotProduct(const Vec3 * src1, const Vec3 * src2); +void PSVECCrossProduct(const Vec3 * src1, const Vec3 * src2, Vec3 * dest); UNKNOWN_FUNCTION(VECHalfAngle); UNKNOWN_FUNCTION(VECReflect); UNKNOWN_FUNCTION(PSVECSquareDistance); diff --git a/include_cpp/msl/exception.h b/include_cpp/msl/exception.h new file mode 100644 index 0000000..4c787dd --- /dev/null +++ b/include_cpp/msl/exception.h @@ -0,0 +1,48 @@ +/* + Based on the decompilation in xenoblade by CelestialAmber +*/ + +#pragma once + +// TODO: does this actually need to be hidden for modding? +#ifdef DECOMP + +namespace std { + +class exception +{ +public: + exception(){} + + virtual ~exception(){} + + virtual const char* what() const + { + return "exception"; + } +}; + +class bad_exception : public exception +{ +public: + bad_exception(){} + + virtual ~bad_exception(){} + + virtual const char* what() const + { + return "bad_exception"; + } +}; + +typedef void (*unexpected_handler)(); +unexpected_handler set_unexpected(unexpected_handler handler); +void unexpected(); + +typedef void (*terminate_handler)(); +terminate_handler set_terminate(terminate_handler handler); +void terminate(); + +} + +#endif diff --git a/include_cpp/msl/new.h b/include_cpp/msl/new.h new file mode 100644 index 0000000..5e559be --- /dev/null +++ b/include_cpp/msl/new.h @@ -0,0 +1,36 @@ +/* + Based on the decompilation in xenoblade by CelestialAmber +*/ + +#pragma once + +// TODO: does this actually need to be hidden for modding? +#ifdef DECOMP + +#include + +namespace std { + +class bad_alloc : public exception +{ +public: + virtual ~bad_alloc(){} + + virtual const char* what() const + { + return "bad_alloc"; + } +}; + +} + +void * operator new (size_t size, void * mem) throw(); +inline void * operator new (size_t size, void * mem) throw() +{ + (void) size; + + return mem; +} + + +#endif diff --git a/include_cpp/nw4r/db/panic.h b/include_cpp/nw4r/db/panic.h new file mode 100644 index 0000000..11d44e8 --- /dev/null +++ b/include_cpp/nw4r/db/panic.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +namespace nw4r { +namespace db { + +#define NW4R_ASSERT_PTR(line, ptr) \ + if (ptr == NULL) nw4r::db::Panic(__FILE__, line, "NW4R:Pointer must not be NULL (" #ptr ")") + +void Panic(const char * msg, ...); + +} +} diff --git a/include_cpp/nw4r/lyt/animation.h b/include_cpp/nw4r/lyt/animation.h new file mode 100644 index 0000000..08240a8 --- /dev/null +++ b/include_cpp/nw4r/lyt/animation.h @@ -0,0 +1,29 @@ +/* + Based on the decompilation in ogws by kiwi515 +*/ + +#pragma once + +#include + +namespace nw4r { +namespace lyt { + +struct AnimTransform +{ + virtual ~AnimTransform(); + + void SetFrame(f32 frame) + { + mFrame = frame; + } + + u16 GetFrameSize() const; + + u8 unknown_0x4[0x10 - 0x4]; + f32 mFrame; +}; +SIZE_ASSERT(AnimTransform, 0x14) + +} +} diff --git a/include_cpp/nw4r/lyt/arcResourceAccessor.h b/include_cpp/nw4r/lyt/arcResourceAccessor.h new file mode 100644 index 0000000..d40c2bb --- /dev/null +++ b/include_cpp/nw4r/lyt/arcResourceAccessor.h @@ -0,0 +1,43 @@ +#pragma once + +#include +#include +#include + +namespace nw4r { +namespace lyt { + +class FontRefLink +{ +public: + FontRefLink(); + ~FontRefLink() {} + + nw4r::ut::LinkListNode mLink; + + u8 unknown_0x8[0x8c - 0x8]; +}; +SIZE_ASSERT(FontRefLink, 0x8c) + +class ArcResourceAccessor : public ResourceAccessor +{ +public: + ArcResourceAccessor(); + virtual ~ArcResourceAccessor() + { + + } + + virtual void * GetResource(u32 type, const char * name, u32 * sizeOut); + virtual UNKNOWN_FUNCTION(GetFont); + + bool Attach(void * file, const char * rootDir); + + u8 unknown_0x4[0x24 - 0x4]; + nw4r::ut::LinkList mFontList; + u8 unknown_0x30[0xb0 - 0x30]; +}; +SIZE_ASSERT(ArcResourceAccessor, 0xb0) + +} // namespace lyt +} // namespace nw4r diff --git a/include_cpp/nw4r/lyt/drawInfo.h b/include_cpp/nw4r/lyt/drawInfo.h new file mode 100644 index 0000000..d0ea65f --- /dev/null +++ b/include_cpp/nw4r/lyt/drawInfo.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include + +namespace nw4r { +namespace lyt { + +class DrawInfo +{ +public: + virtual ~DrawInfo(); + DrawInfo(); + + void SetViewMtx(const struct math::MTX34 & mtx) + { + mViewMtx = mtx; + } + + math::MTX34 mViewMtx; + ut::Rect mViewRect; + math::VEC2 mLocationAdjustScale; + f32 mGlobalAlpha; + u8 mFlag; +}; +SIZE_ASSERT(DrawInfo, 0x54) + +} // namespace lyt +} // namespace nw4r diff --git a/include_cpp/nw4r/lyt/layout.h b/include_cpp/nw4r/lyt/layout.h new file mode 100644 index 0000000..f13ee3b --- /dev/null +++ b/include_cpp/nw4r/lyt/layout.h @@ -0,0 +1,54 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace nw4r { +namespace lyt { + +USING(wii::mem::MEMAllocator) + +class Layout +{ +public: + Layout(); + virtual ~Layout(); + + virtual bool Build(void * lytResBuf, ResourceAccessor * pResAcsr); + virtual AnimTransform * CreateAnimTransform(void * animResBuf, ResourceAccessor * pResAcsr); + virtual void BindAnimation(AnimTransform * pAnimTrans); + virtual void UnbindAnimation(AnimTransform * pAnimTrans); + virtual UNKNOWN_FUNCTION(UnbindAllAnimation); + virtual UNKNOWN_FUNCTION(SetAnimationEnable); + virtual void CalculateMtx(const DrawInfo& drawInfo); + virtual void Draw(const DrawInfo& drawInfo); + virtual void Animate(u32 option); + virtual UNKNOWN_FUNCTION(SetTagProcessor); + + ut::Rect GetLayoutRect(); + + static void SetAllocator(MEMAllocator * allocator) + { + mspAllocator = allocator; + } + + Pane * GetRootPane() + { + return mRootPane; + } + + u8 unknown_0x4[0x10 - 0x4]; + Pane * mRootPane; + u8 unknown_0x14[0x24 - 0x14]; + + static MEMAllocator * mspAllocator; +}; +SIZE_ASSERT(Layout, 0x24) + +} // namespace lyt +} // namespace nw4r diff --git a/include_cpp/nw4r/lyt/material.h b/include_cpp/nw4r/lyt/material.h new file mode 100644 index 0000000..47edaee --- /dev/null +++ b/include_cpp/nw4r/lyt/material.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include + +namespace nw4r { +namespace lyt { + +USING(wii::gx::GXColorS10) + +class Material +{ +public: + Material(); + virtual ~Material(); + + u8 unknown_0x4[0x10 - 0x4]; + GXColorS10 mTevCols[3]; + u8 unknown_0x28[0x5c - 0x28]; +}; +SIZE_ASSERT(Material, 0x5c) + +} // namespace lyt +} // namespace nw4r diff --git a/include_cpp/nw4r/lyt/pane.h b/include_cpp/nw4r/lyt/pane.h new file mode 100644 index 0000000..e628c28 --- /dev/null +++ b/include_cpp/nw4r/lyt/pane.h @@ -0,0 +1,49 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace nw4r { +namespace lyt { + +class Pane +{ +public: + virtual ~Pane(); + virtual UNKNOWN_FUNCTION(GetRuntimeTypeInfo); + virtual UNKNOWN_FUNCTION(CalculateMtx); + virtual UNKNOWN_FUNCTION(Draw); + virtual UNKNOWN_FUNCTION(DrawSelf); + virtual UNKNOWN_FUNCTION(Animate); + virtual UNKNOWN_FUNCTION(AnimateSelf); + virtual UNKNOWN_FUNCTION(GetVtxColor); + virtual UNKNOWN_FUNCTION(SetVtxColor); + virtual UNKNOWN_FUNCTION(GetColorElement); + virtual UNKNOWN_FUNCTION(SetColorElement); + virtual UNKNOWN_FUNCTION(GetVtxColorElement); + virtual UNKNOWN_FUNCTION(SetVtxColorElement); + virtual Pane * FindPaneByName(const char * findName, bool bRecursive); + virtual UNKNOWN_FUNCTION(FindMaterialByName); + virtual UNKNOWN_FUNCTION(BindAnimation); + virtual UNKNOWN_FUNCTION(UnbindAnimation_1); + virtual UNKNOWN_FUNCTION(UnbindAllAnimation); + virtual UNKNOWN_FUNCTION(UnbindAnimationSelf); + virtual UNKNOWN_FUNCTION(FindAnimationLinkSelf); + virtual UNKNOWN_FUNCTION(SetAnimationEnable); + virtual Material * GetMaterial(); + virtual UNKNOWN_FUNCTION(LoadMtx); + + u8 unknown_0x4[0xb4 - 0x4]; + u8 mAlpha; + u8 mGlbAlpha; + u8 mBasePosition; + u8 mFlag; + u8 unknown_0xb8[0xd4 - 0xb8]; +}; +SIZE_ASSERT(Pane, 0xd4) + +} // namespace lyt +} // namespace nw4r diff --git a/include_cpp/nw4r/lyt/resourceAccessor.h b/include_cpp/nw4r/lyt/resourceAccessor.h new file mode 100644 index 0000000..982dacc --- /dev/null +++ b/include_cpp/nw4r/lyt/resourceAccessor.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +namespace nw4r { +namespace lyt { + +class ResourceAccessor +{ +public: + ResourceAccessor(); + virtual ~ResourceAccessor(); + virtual void * GetResource(u32 type, const char * name, u32 * sizeOut); + virtual UNKNOWN_FUNCTION(GetFont); +}; +SIZE_ASSERT(ResourceAccessor, 0x4) + +} // namespace lyt +} // namespace nw4r diff --git a/include_cpp/nw4r/math/types.h b/include_cpp/nw4r/math/types.h new file mode 100644 index 0000000..af6e627 --- /dev/null +++ b/include_cpp/nw4r/math/types.h @@ -0,0 +1,98 @@ +/* + Based on the decompilation in ogws by kiwi515 +*/ + +#pragma once + +#include +#include + +namespace nw4r { +namespace math { + +USING(wii::mtx::Vec3) +USING(wii::mtx::Mtx34) + +struct _VEC2 +{ + f32 x, y; +}; + +struct VEC2 : _VEC2 +{ + VEC2() {} + VEC2(f32 x_, f32 y_) + { + this->x = x_; + this->y = y_; + } + + operator f32*() { return reinterpret_cast(this); } + operator const f32*() const { return reinterpret_cast(this); } +}; +SIZE_ASSERT(VEC2, 0x8) + +struct _VEC3 +{ + f32 x, y, z; +}; + +struct VEC3 : _VEC3 +{ + VEC3() {} + VEC3(f32 x_, f32 y_, f32 z_) + { + this->x = x_; + this->y = y_; + this->z = z_; + } + + operator Vec3*() { return reinterpret_cast(this); } + operator const Vec3*() const { return reinterpret_cast(this); } +}; +SIZE_ASSERT(VEC3, 0xc) + +struct _MTX34 +{ + union + { +#ifdef DECOMP + struct + { + f32 _00, _01, _02, _03, + _10, _11, _12, _13, + _20, _21, _22, _23; + }; +#endif + f32 m[3][4]; + f32 a[3 * 4]; + Mtx34 mtx; + }; +}; + +struct MTX34 : public _MTX34 +{ + typedef f32 (*MtxRef)[4]; + typedef const f32 (*MtxRefConst)[4]; + + MTX34() {} + +#ifdef DECOMP + // clang-format off + MTX34(f32 f00, f32 f01, f32 f02, f32 f03, + f32 f10, f32 f11, f32 f12, f32 f13, + f32 f20, f32 f21, f32 f22, f32 f23) { + _00 = f00; _01 = f01; _02 = f02; _03 = f03; + _10 = f10; _11 = f11; _12 = f12; _13 = f13; + _20 = f20; _21 = f21; _22 = f22; _23 = f23; + } + // clang-format on +#endif + + operator MtxRef() { return mtx; } + operator MtxRefConst() const { return mtx; } +}; +SIZE_ASSERT(MTX34, 0x30) + +} // namespace math +} // namespace nw4r diff --git a/include/nw4r/snd.h b/include_cpp/nw4r/snd.h similarity index 100% rename from include/nw4r/snd.h rename to include_cpp/nw4r/snd.h diff --git a/include_cpp/nw4r/ut/color.h b/include_cpp/nw4r/ut/color.h new file mode 100644 index 0000000..157cda9 --- /dev/null +++ b/include_cpp/nw4r/ut/color.h @@ -0,0 +1,48 @@ +/* + Based on the decompilation in ogws by kiwi515 +*/ + +#pragma once + +#include +#include + +namespace nw4r { +namespace ut { + +USING(wii::gx::GXColor) + +class Color : public GXColor { +public: + Color() { *this = 0xFFFFFFFF; } + Color(u32 color) { *this = color; } + Color(int red, int green, int blue, int alpha) { + Set(red, green, blue, alpha); + } + ~Color() {} + + void Set(int red, int green, int blue, int alpha) { + r = red; + g = green; + b = blue; + a = alpha; + } + + Color& operator=(u32 color) { + ToU32ref() = color; + return *this; + } + + Color operator|(u32 color) { return Color(ToU32() | color); } + Color operator&(u32 color) { return Color(ToU32() & color); } + + u32& ToU32ref() { return *reinterpret_cast(this); } + const u32& ToU32ref() const { return *reinterpret_cast(this); } + + u32 ToU32() const { return ToU32ref(); } + + operator u32() const { return ToU32ref(); } +}; + +} // namespace ut +} // namespace nw4r diff --git a/include_cpp/nw4r/ut/linkList.h b/include_cpp/nw4r/ut/linkList.h new file mode 100644 index 0000000..cb446b8 --- /dev/null +++ b/include_cpp/nw4r/ut/linkList.h @@ -0,0 +1,380 @@ +/* + Based on the decompilation in ogws by kiwi515 +*/ + +#pragma once + +#include +#include + +namespace nw4r { +namespace ut { + +// Forward declaration +namespace detail { +class LinkListImpl; +} + +class LinkListNode : private NonCopyable { + friend class detail::LinkListImpl; + +public: + LinkListNode() : mNext(NULL), mPrev(NULL) {} + + LinkListNode* GetNext() const { + return mNext; + } + LinkListNode* GetPrev() const { + return mPrev; + } + +private: + LinkListNode* mNext; // at 0x0 + LinkListNode* mPrev; // at 0x4 +}; +SIZE_ASSERT(LinkListNode, 0x8) + +namespace detail { + +class LinkListImpl : private NonCopyable { +public: + // Forward declaration + class ConstIterator; + + class Iterator { + friend class LinkListImpl; + friend class ConstIterator; + + public: + Iterator() : mNode(NULL) {} + Iterator(LinkListNode* node) : mNode(node) {} + + Iterator& operator++() { + mNode = mNode->GetNext(); + return *this; + } + + Iterator& operator--() { + mNode = mNode->GetPrev(); + return *this; + } + + LinkListNode* operator->() const { + return mNode; + } + + friend bool operator==(LinkListImpl::Iterator lhs, + LinkListImpl::Iterator rhs) { + return lhs.mNode == rhs.mNode; + } + + private: + LinkListNode* mNode; // at 0x0 + }; + SIZE_ASSERT(Iterator, 0x4) + + class ConstIterator { + friend class LinkListImpl; + + public: + ConstIterator(Iterator it) : mNode(it.mNode) {} + + ConstIterator& operator++() { + mNode = mNode->GetNext(); + return *this; + } + + ConstIterator& operator--() { + mNode = mNode->GetPrev(); + return *this; + } + + const LinkListNode* operator->() const { + return mNode; + } + + friend bool operator==(LinkListImpl::ConstIterator lhs, + LinkListImpl::ConstIterator rhs) { + return lhs.mNode == rhs.mNode; + } + + private: + LinkListNode* mNode; // at 0x0 + }; + SIZE_ASSERT(ConstIterator, 0x4) + +protected: + static Iterator GetIteratorFromPointer(LinkListNode* node) { + return Iterator(node); + } + + LinkListImpl() { + Initialize_(); + } + ~LinkListImpl(); + + Iterator GetBeginIter() { + return Iterator(mNode.GetNext()); + } + Iterator GetEndIter() { + return Iterator(&mNode); + } + + Iterator Insert(Iterator it, LinkListNode* node); + + Iterator Erase(Iterator it); + Iterator Erase(LinkListNode* node); + Iterator Erase(Iterator begin, Iterator end); + +public: + u32 GetSize() const { + return mSize; + } + bool IsEmpty() const { + return mSize == 0; + } + + void PopFront() { + Erase(GetBeginIter()); + } + void PopBack() { + Erase(GetEndIter()); + } + + void Clear(); + +private: + void Initialize_() { + mSize = 0; + mNode.mNext = &mNode; + mNode.mPrev = &mNode; + } + +private: + u32 mSize; // at 0x0 + LinkListNode mNode; // at 0x4 +}; + +template class ReverseIterator { +public: + ReverseIterator(TIter it) : mCurrent(it) {} + + TIter GetBase() const { + return mCurrent; + } + + ReverseIterator& operator++() { + --mCurrent; + return *this; + } + + const typename TIter::TElem* operator->() const { + return &this->operator*(); + } + + typename TIter::TElem& operator*() const { + TIter it = mCurrent; + --it; + return *it; + } + + friend bool operator==(const ReverseIterator& lhs, + const ReverseIterator& rhs) { + return lhs.mCurrent == rhs.mCurrent; + } + + friend bool operator!=(const ReverseIterator& lhs, + const ReverseIterator& rhs) { + return !(lhs.mCurrent == rhs.mCurrent); + } + +private: + TIter mCurrent; // at 0x0 +}; + +} // namespace detail + +template class LinkList : public detail::LinkListImpl { +public: + // Forward declaration + class ConstIterator; + + class Iterator { + friend class LinkList; + friend class ConstIterator; + + public: + // Element type must be visible to ReverseIterator + typedef T TElem; + + public: + Iterator() : mIterator(NULL) {} + Iterator(LinkListImpl::Iterator it) : mIterator(it) {} + + Iterator& operator++() { + ++mIterator; + return *this; + } + + Iterator& operator--() { + --mIterator; + return *this; + } + + Iterator operator++(int) { + Iterator ret = *this; + ++*this; + return ret; + } + + T* operator->() const { + return GetPointerFromNode(mIterator.operator->()); + } + + T& operator*() const { + return *this->operator->(); + } + + friend bool operator==(Iterator lhs, Iterator rhs) { + return lhs.mIterator == rhs.mIterator; + } + + friend bool operator!=(Iterator lhs, Iterator rhs) { + return !(lhs == rhs); + } + + private: + LinkListImpl::Iterator mIterator; // at 0x0 + }; + + class ConstIterator { + friend class LinkList; + + public: + // Element type must be visible to ReverseIterator + typedef T TElem; + + public: + ConstIterator(LinkListImpl::Iterator it) : mIterator(it) {} + ConstIterator(Iterator it) : mIterator(it.mIterator) {} + + ConstIterator& operator++() { + ++mIterator; + return *this; + } + + ConstIterator& operator--() { + --mIterator; + return *this; + } + + ConstIterator operator++(int) { + ConstIterator ret = *this; + ++*this; + return ret; + } + + const T* operator->() const { + return GetPointerFromNode(mIterator.operator->()); + } + + const T& operator*() const { + return *this->operator->(); + } + + friend bool operator==(ConstIterator lhs, ConstIterator rhs) { + return lhs.mIterator == rhs.mIterator; + } + + friend bool operator!=(ConstIterator lhs, ConstIterator rhs) { + return !(lhs == rhs); + } + + private: + LinkListImpl::ConstIterator mIterator; // at 0x0 + }; + +public: + // Shorthand names for reverse iterator types + typedef detail::ReverseIterator RevIterator; + typedef detail::ReverseIterator RevConstIterator; + +public: + LinkList() {} + ~LinkList() {} + + Iterator GetBeginIter() { + return Iterator(LinkListImpl::GetBeginIter()); + } + ConstIterator GetBeginIter() const { + return ConstIterator(const_cast(this)->GetBeginIter()); + } + detail::ReverseIterator GetBeginReverseIter() { + return detail::ReverseIterator(GetBeginIter()); + } + + Iterator GetEndIter() { + return Iterator(LinkListImpl::GetEndIter()); + } + ConstIterator GetEndIter() const { + return ConstIterator(const_cast(this)->GetEndIter()); + } + detail::ReverseIterator GetEndReverseIter() { + return detail::ReverseIterator(GetEndIter()); + } + + Iterator Insert(Iterator it, T* p) { + return Iterator( + LinkListImpl::Insert(it.mIterator, GetNodeFromPointer(p))); + } + + Iterator Erase(T* p) { + return Iterator(LinkListImpl::Erase(GetNodeFromPointer(p))); + } + Iterator Erase(Iterator it) { + return Iterator(LinkListImpl::Erase(it.mIterator)); + } + + void PushBack(T* p) { + Insert(GetEndIter(), p); + } + + T& GetFront() { + return *GetBeginIter(); + } + const T& GetFront() const { + return *GetBeginIter(); + } + + T& GetBack() { + return *--GetEndIter(); + } + const T& GetBack() const { + return *--GetEndIter(); + } + + static Iterator GetIteratorFromPointer(T* p) { + return GetIteratorFromPointer(GetNodeFromPointer(p)); + } + + static Iterator GetIteratorFromPointer(LinkListNode* node) { + return Iterator(LinkListImpl::GetIteratorFromPointer(node)); + } + + static LinkListNode* GetNodeFromPointer(T* p) { + return reinterpret_cast(reinterpret_cast(p) + + Ofs); + } + + static T* GetPointerFromNode(LinkListNode* node) { + return reinterpret_cast(reinterpret_cast(node) - Ofs); + } + + static const T* GetPointerFromNode(const LinkListNode* node) { + return reinterpret_cast(reinterpret_cast(node) - + Ofs); + } +}; + +} // namespace ut +} // namespace nw4r diff --git a/include_cpp/nw4r/ut/nonCopyable.h b/include_cpp/nw4r/ut/nonCopyable.h new file mode 100644 index 0000000..c03f064 --- /dev/null +++ b/include_cpp/nw4r/ut/nonCopyable.h @@ -0,0 +1,21 @@ +/* + Based on the decompilation in ogws by kiwi515 +*/ + +#pragma once + +#include + +namespace nw4r { +namespace ut { + +class NonCopyable { +protected: + NonCopyable() {} + NonCopyable(const NonCopyable&) {} + ~NonCopyable() {} +}; +SIZE_ASSERT(NonCopyable, 0x1) + +} // namespace ut +} // namespace nw4r diff --git a/include_cpp/nw4r/ut/rect.h b/include_cpp/nw4r/ut/rect.h new file mode 100644 index 0000000..6e3158e --- /dev/null +++ b/include_cpp/nw4r/ut/rect.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace nw4r { +namespace ut { + +struct Rect +{ + f32 left, top, bottom, right; +}; +SIZE_ASSERT(Rect, 0x10) + +} // namespace ut +} // namespace nw4r