├── .gitignore ├── .vscode ├── c_cpp_properties.json ├── ActorBase.code-snippets ├── ActorCollision.code-snippets ├── Enemy.code-snippets ├── ModelCreate.code-snippets ├── State.code-snippets └── settings.json ├── LICENSE ├── Makefile ├── README.md ├── hooks ├── AllocationFailedHandler.hks ├── CourseSpriteMgr.hks ├── Profiles.hks ├── ScCourse.hks ├── Startup.hks └── seadExpHeap.hks ├── include ├── actors │ ├── ActorBase.h │ ├── ActorCollision.h │ ├── ActorMultiState.h │ ├── ActorState.h │ ├── BlockCoin.h │ ├── Boss.h │ ├── BossDemo.h │ ├── CarryableEnemy.h │ ├── Enemy.h │ ├── FlagSwitchBase.h │ ├── Item.h │ ├── LiftBase.h │ ├── ScoreMgr.h │ ├── ShellEnemy.h │ ├── dBase.h │ └── fBase.h ├── collider │ ├── ActorBgCollisionCheck.h │ ├── ActorBgCollisionMgr.h │ ├── ActorCollisionCheck.h │ ├── ActorEllipseBgCollision.h │ ├── BasicBgCollisionCheck.h │ ├── BasicRideLine.h │ ├── BgCollision.h │ ├── FollowArg.h │ ├── LoopRideLineBgCollision.h │ ├── PlayerBgCollisionCheck.h │ ├── PlayerKoopalingBgCollisionCheck.h │ ├── RectCollider.h │ ├── SolidCollider.h │ ├── SolidOnTopCollider.h │ └── UnkCollisionClass.h ├── course │ ├── ActorCoinMgr.h │ ├── BgScrollMgr.h │ ├── BgmAnimMgr.h │ ├── CoinOrigin.h │ ├── Course.h │ ├── CourseActorMgr.h │ ├── CourseSpriteMgr.h │ ├── DemoMgr.h │ ├── FlagMgr.h │ ├── LineFollower.h │ ├── ModelMgr.h │ ├── PairChild.h │ ├── ProfileId.h │ ├── Profiles.h │ ├── QuakeMgr.h │ ├── TileLayer.h │ ├── TileMgr.h │ └── TilesetGfxMgr.h ├── effect │ ├── Effect.h │ └── EffectId.h ├── enemy │ └── EnemyDeathInfo.h ├── fragment │ ├── BigBlockFragment.h │ ├── Fragment.h │ └── FragmentMgr.h ├── gfx │ ├── AnimModel.h │ ├── AnimModelBase.h │ ├── Animation.h │ ├── GL.h │ ├── GfxWrapper.h │ ├── Light.h │ ├── Model.h │ ├── Renderer.h │ └── Texture.h ├── mapobj │ ├── DoorBase.h │ └── LiftRenderer.h ├── math │ ├── Calc.h │ ├── Interpolation.h │ ├── Mtx33.h │ ├── Mtx34.h │ ├── Mtx44.h │ ├── NumericLimits.h │ ├── RNG.h │ ├── Rect.h │ └── Vec.h ├── nn │ ├── handle.h │ ├── hid.h │ ├── math │ │ ├── Matrix22.h │ │ ├── Matrix23.h │ │ ├── Matrix33.h │ │ ├── Matrix34.h │ │ ├── Matrix44.h │ │ ├── Types.h │ │ ├── Vector2.h │ │ ├── Vector3.h │ │ └── Vector4.h │ ├── result.h │ └── ulcd │ │ └── StereoCamera.h ├── nw │ ├── anim │ │ ├── AnimResult.h │ │ └── res │ │ │ ├── ResAnim.h │ │ │ └── ResAnimGroup.h │ ├── gfx │ │ ├── AnimBinding.h │ │ ├── AnimGroup.h │ │ ├── AnimObject.h │ │ ├── CalculatedTransform.h │ │ ├── Common.h │ │ ├── GfxObject.h │ │ ├── ISceneVisitor.h │ │ ├── Material.h │ │ ├── Model.h │ │ ├── SceneNode.h │ │ ├── SceneObject.h │ │ ├── TransformNode.h │ │ └── res │ │ │ ├── ResGraphicsFile.h │ │ │ ├── ResMaterial.h │ │ │ ├── ResMesh.h │ │ │ ├── ResModel.h │ │ │ ├── ResSceneObject.h │ │ │ ├── ResShader.h │ │ │ ├── ResTexture.h │ │ │ └── ResTextureMapper.h │ ├── os │ │ └── Memory.h │ ├── types.h │ └── ut │ │ ├── BinaryFileFormat.h │ │ ├── Children.h │ │ ├── Color.h │ │ ├── Inline.h │ │ ├── MoveArray.h │ │ ├── MovePtr.h │ │ ├── ResArray.h │ │ ├── ResArrayTypes.h │ │ ├── ResDictionary.h │ │ ├── ResMetaData.h │ │ ├── ResTypes.h │ │ ├── ResUtil.h │ │ └── RuntimeTypeInfo.h ├── player │ ├── PlayerBase.h │ ├── PlayerEnum.h │ ├── PlayerInput.h │ ├── PlayerLookTarget.h │ ├── PlayerMgr.h │ ├── PlayerModel.h │ ├── PlayerModelBase.h │ └── PlayerObject.h ├── scene │ ├── ScCourse.h │ ├── Scene.h │ └── StateScene.h ├── sead.h ├── sead │ ├── basis │ │ └── seadNew.h │ ├── heap │ │ ├── seadArena.h │ │ ├── seadDisposer.h │ │ ├── seadExpHeap.h │ │ ├── seadHeap.h │ │ ├── seadHeapMgr.h │ │ └── seadMemBlock.h │ ├── seadBitFlag.h │ ├── seadBoundBox.h │ ├── seadBoundBox.hpp │ ├── seadBuffer.h │ ├── seadCamera.h │ ├── seadColor.h │ ├── seadCriticalSection.h │ ├── seadDelegate.h │ ├── seadGraphics.h │ ├── seadLine.h │ ├── seadListImpl.h │ ├── seadMathCalcCommon.h │ ├── seadMathCalcCommon.hpp │ ├── seadMathCalcCommonCtr.h │ ├── seadMathCalcCommonCtr.hpp │ ├── seadMathPolicies.h │ ├── seadNamable.h │ ├── seadOffsetList.h │ ├── seadProjection.h │ ├── seadPtrArray.h │ ├── seadRuntimeTypeInfo.h │ ├── seadSafeString.h │ ├── seadSystem.h │ ├── seadVector.h │ ├── seadVector.hpp │ ├── seadVectorCalcCommon.h │ └── seadVectorCalcCommon.hpp ├── sound │ └── SoundId.h ├── state │ ├── FState.h │ ├── FStateFactory.h │ ├── FStateID.h │ ├── FStateMgr.h │ ├── FStateStateMgr.h │ ├── FStateVirtualID.h │ ├── IState.h │ ├── IStateFactory.h │ ├── StateID.h │ ├── StateIDHolder.h │ ├── StateMethod.h │ ├── StateMgr.h │ ├── StateStateMethod.h │ └── StateStateMgr.h ├── sys │ ├── Allocator.h │ ├── Common.h │ ├── LineNodeMgr.h │ ├── PersistentDataMgr.h │ ├── Preprocessor.h │ ├── ResourceMgr.h │ ├── Svc.h │ └── clib │ │ ├── ctype.h │ │ ├── math.h │ │ ├── stdarg.h │ │ ├── stddef.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.h │ │ └── wchar.h └── types.h ├── loader ├── Makefile └── source │ ├── hooks.hks │ ├── loader.c │ ├── newcodeinfo.h │ └── svc.s ├── source ├── Startup.c ├── Thumb_Thunk_asm.s ├── actors │ └── ActorBase.cpp ├── course │ ├── CourseSpriteMgr.cpp │ ├── CourseSpriteMgr_asm.s │ ├── Profiles.cpp │ └── Profiles_asm.s ├── math │ ├── Interpolation.cpp │ └── Mtx44.cpp ├── scene │ └── ScCourse_asm.s ├── sead │ ├── heap │ │ └── seadExpHeap.cpp │ ├── seadAssertCtr.cpp │ ├── seadRawPrintCtr.cpp │ ├── seadSafeString.cpp │ └── seadWarning.cpp └── sys │ ├── AllocationFailedHandler.cpp │ ├── File.s │ └── Svc_asm.s └── symbols.ld /.gitignore: -------------------------------------------------------------------------------- 1 | code.bin 2 | exheader.bin 3 | newcode.bin 4 | newcodeinfo.h 5 | loader.bin 6 | linker.ld 7 | 8 | *.elf 9 | *.sym 10 | *.o 11 | *.d 12 | *.map 13 | /build 14 | 15 | /gcc-arm-none-eabi 16 | 17 | *.directory 18 | .vscode 19 | 20 | *.user 21 | 22 | *.id0 23 | *.id1 24 | *.id2 25 | *.nam 26 | *.til 27 | 28 | *.idb 29 | *.i64 30 | 31 | /tmp 32 | test* 33 | 34 | .DS_Store 35 | -------------------------------------------------------------------------------- /.vscode/ c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "defines": [], 9 | "compilerPath": "${workspaceFolder}/gcc-arm-none-eabi/bin/arm-none-eabi-gcc", 10 | "cStandard": "c17", 11 | "cppStandard": "c++17", 12 | "intelliSenseMode": "linux-gcc-arm" 13 | } 14 | ], 15 | "version": 4 16 | } -------------------------------------------------------------------------------- /.vscode/ActorBase.code-snippets: -------------------------------------------------------------------------------- 1 | { 2 | "Enemy Template": { 3 | "prefix": "Actor", 4 | "body": [ 5 | "#include \"actors/${2:ActorBase}.h\"", 6 | "", 7 | "#include \"course/ProfileId.h\"", 8 | "", 9 | "", 10 | "class ${1:$TM_FILENAME_BASE}: public ${2:ActorBase}", 11 | "{", 12 | "public:", 13 | " DECLARE_PROC_GLUE_CODE(${1:$TM_FILENAME_BASE});", 14 | " static ActorInfo info;", 15 | " ", 16 | " int onCreate() override;", 17 | " int onExecute() override;", 18 | "", 19 | " static const bool someFlag;", 20 | "};", 21 | "", 22 | "CREATE_PROC_GLUE_CODE(${1:$TM_FILENAME_BASE});", 23 | "", 24 | "", 25 | "ActorInfo ${1:$TM_FILENAME_BASE}::info =", 26 | "{", 27 | " { 0, 0 },", 28 | " { 0, 0 },", 29 | " { 0, 0 },", 30 | " { 0, 0, 0, 0 },", 31 | " ActorInfo::SPAWNFLAG_NORMAL,", 32 | " ActorInfo::FLAG_NORMAL", 33 | "};", 34 | "", 35 | "", 36 | "RegisterStageProfile<${1:$TM_FILENAME_BASE}> ${1:$TM_FILENAME_BASE}Profile", 37 | "(", 38 | " ProfileId::${1:$TM_FILENAME_BASE}, \"${1:$TM_FILENAME_BASE}\",", 39 | " ProfileId::${1:$TM_FILENAME_BASE}, ProfileId::${1:$TM_FILENAME_BASE},", 40 | " &${1:$TM_FILENAME_BASE}::info,", 41 | " nullptr, RES_LOAD_MODE_COURSE,", 42 | " SOUND_ACTOR_TYPE_NONE", 43 | ");", 44 | "", 45 | "", 46 | "int ${1:$TM_FILENAME_BASE}::onCreate()", 47 | "{", 48 | "", 49 | " return 2;", 50 | "}", 51 | "", 52 | "", 53 | "int ${1:$TM_FILENAME_BASE}::onExecute()", 54 | "{", 55 | "", 56 | " return 2;", 57 | "}", 58 | "", 59 | ], 60 | "description": "Creates code for an actor" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /.vscode/ModelCreate.code-snippets: -------------------------------------------------------------------------------- 1 | { 2 | "Model Create Template": { 3 | "prefix": "ModelCreate", 4 | "body": [ 5 | "allocator.link(ActorHeap);", 6 | "", 7 | "Resource* resource = ResourceMgr::instance->getResource(\"model\");", 8 | "model = Model::create(resource, \"model\", &allocator);", 9 | ], 10 | "description": "Creates a model" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.vscode/State.code-snippets: -------------------------------------------------------------------------------- 1 | { 2 | "State Template": { 3 | "prefix": "State", 4 | "body": [ 5 | "void ${1:$TM_FILENAME_BASE}::initializeState_${2:ActorState}()", 6 | "{", 7 | " ", 8 | "}", 9 | "", 10 | "void ${1:$TM_FILENAME_BASE}::executeState_${2:ActorState}()", 11 | "{", 12 | " ", 13 | "}", 14 | "", 15 | "void ${1:$TM_FILENAME_BASE}::finalizeState_${2:ActorState}() { }", 16 | "", 17 | "", 18 | ], 19 | "description": "Creates code for a state" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "*.s": "arm", 4 | "*.tcc": "cpp", 5 | "exception": "cpp", 6 | "locale": "cpp", 7 | "ostream": "cpp", 8 | "*.inc": "cpp", 9 | "qtcoredepends": "cpp", 10 | "qtdbusdepends": "cpp", 11 | "*.def": "cpp", 12 | "cmath": "cpp", 13 | "ios": "cpp", 14 | "any": "cpp", 15 | "bit": "cpp", 16 | "charconv": "cpp", 17 | "codecvt": "cpp", 18 | "compare": "cpp", 19 | "condition_variable": "cpp", 20 | "cstddef": "cpp", 21 | "forward_list": "cpp", 22 | "list": "cpp", 23 | "string": "cpp", 24 | "optional": "cpp", 25 | "rope": "cpp", 26 | "future": "cpp", 27 | "limits": "cpp", 28 | "memory": "cpp", 29 | "new": "cpp", 30 | "ranges": "cpp", 31 | "functional": "cpp", 32 | "regex": "cpp", 33 | "numeric": "cpp" 34 | }, 35 | 36 | "C_Cpp.default.compilerArgs": [ 37 | "-nostdinc" 38 | ] 39 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Gimzie 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /hooks/AllocationFailedHandler.hks: -------------------------------------------------------------------------------- 1 | RegisterAllocationFailedHandler: 2 | type: branch 3 | link: true 4 | addr: 0x00101020 5 | func: AllocationFailedHandler::registerCallback() 6 | -------------------------------------------------------------------------------- /hooks/CourseSpriteMgr.hks: -------------------------------------------------------------------------------- 1 | CourseSpriteMgr_spriteToProfileIds_1: 2 | type: branch 3 | link: true 4 | addr: 0x002E29B0 5 | func: CourseSpriteMgr_spriteToProfileIds_r1 6 | 7 | CourseSpriteMgr_spriteToProfileIds_2: 8 | type: branch 9 | link: true 10 | addr: 0x002E2E2C 11 | func: CourseSpriteMgr_spriteToProfileIds_r10 12 | 13 | CourseSpriteMgr_spriteToProfileIds_3: 14 | type: branch 15 | link: true 16 | addr: 0x002E3104 17 | func: CourseSpriteMgr_spriteToProfileIds_r11 18 | 19 | CourseSpriteMgr_spriteToProfileIds_4: 20 | type: branch 21 | link: true 22 | addr: 0x002E37F4 23 | func: CourseSpriteMgr_spriteToProfileIds_r1 24 | 25 | CourseSpriteMgr_spriteToProfileIds_5: 26 | type: branch 27 | link: true 28 | addr: 0x002E3DE4 29 | func: CourseSpriteMgr_spriteToProfileIds_r3 30 | 31 | CourseSpriteMgr_spriteToProfileIds_6: 32 | type: branch 33 | link: true 34 | addr: 0x002E40E0 35 | func: CourseSpriteMgr_spriteToProfileIds_r1 36 | 37 | 38 | CourseSpriteMgr_spriteCount_1: 39 | type: branch 40 | link: true 41 | addr: 0x002E2E24 42 | func: CourseSpriteMgr_spriteCount_r9 43 | 44 | CourseSpriteMgr_spriteCount_2: 45 | type: branch 46 | link: true 47 | addr: 0x002E3100 48 | func: CourseSpriteMgr_spriteCount_r9 49 | 50 | CourseSpriteMgr_spriteCount_3: 51 | type: branch 52 | link: true 53 | addr: 0x002E3D8C 54 | func: CourseSpriteMgr_spriteCount_r9 55 | -------------------------------------------------------------------------------- /hooks/ScCourse.hks: -------------------------------------------------------------------------------- 1 | ScCourse_alloc_size: 2 | type: branch 3 | link: false 4 | addr: 0x0055AB54 5 | func: ScCourse_alloc_size_hook 6 | -------------------------------------------------------------------------------- /hooks/Startup.hks: -------------------------------------------------------------------------------- 1 | StaticInit: 2 | type: branch 3 | link: true 4 | func: static_init 5 | addr: 0x00100014 6 | -------------------------------------------------------------------------------- /hooks/seadExpHeap.hks: -------------------------------------------------------------------------------- 1 | seadExpHeapGetSize: 2 | type: symptr 3 | addr: 0x005D2F98 4 | sym: sead::ExpHeap::getSize() const 5 | 6 | seadExpHeapGetFreeSize: 7 | type: symptr 8 | addr: 0x005D2F9C 9 | sym: sead::ExpHeap::getFreeSize() const 10 | -------------------------------------------------------------------------------- /include/actors/ActorCollision.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "actors/ActorBase.h" 4 | #include "collider/ActorBgCollisionCheck.h" 5 | 6 | 7 | class ActorCollision : public ActorBase // size: 0xFC4 8 | { 9 | SEAD_RTTI_OVERRIDE(ActorCollision, ActorBase); 10 | 11 | public: 12 | ActorCollision(); 13 | 14 | void afterCreate(int) override; 15 | int onDelete() override; 16 | int beforeExecute() override; 17 | void afterExecute(int) override; 18 | 19 | ActorBgCollisionCheck* getBgCollisionCheck() override; // returns collisionCheck 20 | ActorBgCollisionCheck* getBgCollisionCheck2() override; // returns collisionCheck 21 | 22 | virtual void vfD8(); // deleted 23 | virtual void vfDC(); // deleted 24 | virtual void vfE0(); // deleted 25 | virtual void vfE4(); // deleted 26 | virtual void vfE8(); // deleted 27 | virtual void vfEC(); // deleted 28 | virtual void vfF0(); // deleted 29 | virtual void vfF4(); // deleted 30 | virtual bool vfF8(); // returns false 31 | virtual void vfFC(u32); // called from beforeExecute if vfF8 returns true and _190 is 0 32 | virtual void onCollisionLava(ActorBase* other); // null, called when in lava, depending on flags 33 | virtual f32 vf104(); // returns 0.25 34 | virtual f32 vf108(); 35 | 36 | void applyYAcceleration(); // calls Actor::incrementYSpeed with verticalAccel + speedMax.y 37 | void applyFallAcceleration(); // calls Actor::moveToTargetYSpeed with verticalAccel + maxFallSpeed 38 | 39 | void processMovement(); 40 | 41 | ActorBgCollisionObjCheck collisionCheck; // 1C8 42 | 43 | f32 _F88; // F88 inited to 0.0 44 | f32 _F8C; // F8C inited to 0.0 45 | Vec3f* liquidCheckPosition; // F90 inited to &position 46 | f32 liquidSplashScale; // F94 inited to 1.0 47 | f32 _F98; // F98 inited to 0.0 48 | f32 _F9C; // F9C inited to 0.0 49 | f32 _FA0; // FA0 inited to 0.0 50 | f32 _FA4; // FA4 inited to 0.0 51 | f32 yMaxSpeedLiquid; // FA8 inited to 1.5 52 | f32 yMinSpeedLiquid; // FAC inited to -1.5 53 | f32 ySpeedIncrementLiquid; // FBO inited to -0.0625 54 | u8 inLiquidType; // FB4 inited to 0 55 | u8 _FB5; // FB5 ^ 56 | u8 _FB6; // FB6 ^ 57 | u8 isInLiquid; // FB7 ^ 58 | u8 _FB8; // FB8 ^ 59 | u8 _FB9; // FB9 ^ 60 | u8 _FBA; // FBA ^ 61 | u8 _FBB; // FBB ^ 62 | u8 _FBC; // FBC ^ 63 | u32 _FC0; // FC0 ^ 64 | }; 65 | -------------------------------------------------------------------------------- /include/actors/ActorMultiState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ActorCollision.h" 4 | #include "state/FStateStateMgr.h" 5 | #include "state/FStateVirtualID.h" 6 | 7 | class ActorMultiState : public ActorCollision 8 | { 9 | SEAD_RTTI_OVERRIDE(ActorMultiState, ActorCollision); 10 | 11 | public: 12 | ActorMultiState(); 13 | 14 | virtual void changeState(const StateID& stateID); 15 | 16 | FStateStateMgr stateMgr; // FC4 17 | }; 18 | 19 | size_assert(ActorMultiState, 0xFEC); 20 | -------------------------------------------------------------------------------- /include/actors/ActorState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ActorCollision.h" 4 | #include "state/FStateMgr.h" 5 | #include "state/FStateID.h" 6 | 7 | class ActorState : public ActorCollision 8 | { 9 | SEAD_RTTI_OVERRIDE(ActorState, ActorCollision); 10 | 11 | public: 12 | ActorState(); 13 | 14 | void changeState(const StateID& stateID); 15 | 16 | FStateMgr stateMgr; // FC4 17 | }; 18 | 19 | size_assert(ActorState, 0xFE8); 20 | 21 | inline void ActorState::changeState(const StateID& stateID) 22 | { 23 | stateMgr.changeState(stateID); 24 | } 25 | -------------------------------------------------------------------------------- /include/actors/BossDemo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "actors/ActorState.h" 4 | #include "state/FStateVirtualID.h" 5 | 6 | class BossDemo : public ActorState 7 | { 8 | SEAD_RTTI_OVERRIDE(BossDemo, ActorState); 9 | 10 | public: 11 | BossDemo(); 12 | 13 | int onCreate() override; 14 | int onDelete() override; 15 | int onExecute() override; 16 | int beforeDraw() override; 17 | 18 | DECLARE_STATE_VIRTUAL_ID_BASE(BossDemo, Wait); 19 | DECLARE_STATE_VIRTUAL_ID_BASE(BossDemo, Intro); 20 | DECLARE_STATE_VIRTUAL_ID_BASE(BossDemo, Fight); 21 | DECLARE_STATE_VIRTUAL_ID_BASE(BossDemo, Outro); 22 | 23 | virtual u32 vf13C(); 24 | virtual u32 vf140(); 25 | virtual void killActors(); // Called before intro and outro 26 | virtual void vf148(); 27 | virtual void vf14C(); // Called at start of intro and outro 28 | virtual bool canStartBossDemo(); // Used to walk player into fight area 29 | virtual void isFightStillGoingMaybe(); 30 | virtual bool canStartIntro(); 31 | virtual ActorBase* searchBossActor(); 32 | virtual ActorBase* searchOutroActor(); 33 | virtual void created(); // called from onCreate 34 | virtual bool hasOutroActor(); 35 | virtual void spawnOutroActor(); 36 | virtual bool isOutroActorFinished(); 37 | virtual void vf174(); 38 | virtual bool hasOutroCameraPan(); 39 | virtual void unkShutters1(); 40 | virtual void unkShutters2(); 41 | virtual void openShutters(); 42 | virtual void vf188(); 43 | virtual void vf18C(); 44 | virtual void setAfterFightState(); 45 | virtual void vf194(); 46 | virtual void vf198(); 47 | 48 | bool walkInPlayer(f32 distance); 49 | 50 | f32 _FE8; 51 | f32 _FEC; 52 | f32 _FF0; 53 | f32 _FF4; 54 | u8 _FF8; 55 | u8 _FF9; 56 | u8 _FFA; 57 | u8 canSpawnKeyRelated; // FFB 58 | u8 _FFC; 59 | u8 _FFD; 60 | u8 outroSubstate; // FFE 3: celebrate, 4: zero timer 61 | Vec3f bossShutterPosition; // 1000 62 | s32 bossId; // 100C 63 | ActorBase* boss; // 1010 64 | u8 _unk1014[4]; 65 | u32 _1018; 66 | f32 _101C; 67 | f32 _1020; 68 | f32 _1024; 69 | u8 _1028; 70 | u8 _1029; 71 | u8 _102A; 72 | s32 timer; // 102C 73 | u32 _1030; 74 | u32 _1034; 75 | }; 76 | 77 | size_assert(BossDemo, 0x1038); 78 | -------------------------------------------------------------------------------- /include/actors/CarryableEnemy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Enemy.h" 4 | 5 | 6 | class CarryableEnemy : public Enemy 7 | { 8 | SEAD_RTTI_OVERRIDE(CarryableEnemy, Enemy); 9 | 10 | public: 11 | CarryableEnemy(); 12 | 13 | void collisionPlayer(ActorCollisionCheck* thisCheck, ActorCollisionCheck* otherCheck) override; 14 | 15 | virtual void vf1D4(); 16 | virtual void jumpedOn(ActorBase* other); // Only called when not carryable 17 | virtual void jumpedOnMini(ActorBase* other); // ^ 18 | virtual void collisionPlayerNormal(ActorCollisionCheck* thisCheck, ActorCollisionCheck* otherCheck); // Called when colliding with player without pickup 19 | virtual void collisionPlayerLiftable(ActorCollisionCheck* thisCheck, ActorCollisionCheck* otherCheck); // Called when player pickup fails 20 | 21 | DECLARE_STATE_VIRTUAL_ID_BASE(CarryableEnemy, Carry); 22 | DECLARE_STATE_VIRTUAL_ID_BASE(CarryableEnemy, Liftable); 23 | DECLARE_STATE_VIRTUAL_ID_BASE(CarryableEnemy, Throw); 24 | 25 | void getCarryPosition(Vec3f& outPos); 26 | 27 | 28 | f32 _1060; 29 | f32 _1064; 30 | f32 _1068; 31 | 32 | u8 _unk106C[0x107C-0x106C]; // unknown size, max 0x107C 33 | }; 34 | -------------------------------------------------------------------------------- /include/actors/FlagSwitchBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "actors/ActorMultiState.h" 4 | 5 | 6 | class FlagSwitchBase : public ActorMultiState 7 | { 8 | SEAD_RTTI_OVERRIDE(FlagSwitchBase, ActorMultiState); 9 | 10 | public: 11 | FlagSwitchBase(); 12 | 13 | int onExecute() override; 14 | int beforeDraw() override; 15 | }; 16 | -------------------------------------------------------------------------------- /include/actors/LiftBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "actors/ActorState.h" 4 | 5 | class LiftBase : public ActorState 6 | { 7 | public: 8 | LiftBase(); 9 | 10 | bool isOn(BgCollision* collider, u32 unk); 11 | 12 | u8 _FE8; 13 | }; 14 | -------------------------------------------------------------------------------- /include/actors/dBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "fBase.h" 4 | 5 | class dBase : public fBase // size: 0x14 6 | { 7 | public: 8 | dBase(); 9 | virtual ~dBase(); 10 | 11 | int beforeCreate() override; 12 | void afterCreate(int) override; 13 | int beforeDelete() override; 14 | void afterDelete(int) override; 15 | int beforeExecute() override; 16 | void afterExecute(int) override; 17 | int beforeDraw() override; 18 | void afterDraw(int) override; 19 | 20 | virtual void vf3C(); // deleted 21 | }; 22 | -------------------------------------------------------------------------------- /include/actors/fBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | class fBase // size: 0x14 6 | { 7 | public: 8 | fBase(); 9 | virtual ~fBase(); 10 | 11 | virtual int beforeCreate(); 12 | virtual int onCreate(); 13 | virtual void afterCreate(int); 14 | 15 | virtual int beforeDelete(); 16 | virtual int onDelete(); 17 | virtual void afterDelete(int); 18 | 19 | virtual int beforeExecute(); 20 | virtual int onExecute(); 21 | virtual void afterExecute(int); 22 | 23 | virtual int beforeDraw(); 24 | virtual int onDraw(); 25 | virtual void afterDraw(int); 26 | 27 | virtual void onErase(); 28 | 29 | void erase(); 30 | 31 | fBase* getParent(); 32 | static fBase* search(u32 unused, s32 id); // not part of this class 33 | static inline fBase* search(s32 id) { return search(0, id); } 34 | 35 | 36 | s32 id; // 4 Inited to -1 37 | u32 settings; // 8 First 4 bytes from real sprite data, inited to 0 38 | u16 profileId; // C Inited to 0 39 | u8 created; // E ^ 40 | u8 erased; // F ^ 41 | u8 _10; // 10 ^ Set to 1 in ProcMgr::createAll if _1142C == 3 42 | u8 _11; // 11 ^ 43 | u8 _12; // 12 ^ 44 | u8 direction; // 13 ^ 45 | }; 46 | 47 | 48 | 49 | void* AllocFromActorHeap(size_t size); 50 | void FreeToActorHeap(void* ptr); 51 | 52 | #define DECLARE_PROC_GLUE_CODE(CLASS) \ 53 | void* operator new(size_t size); \ 54 | void operator delete(void* p); \ 55 | static fBase* build(); \ 56 | static void destroy(fBase* p); 57 | 58 | #define CREATE_PROC_GLUE_CODE(CLASS) \ 59 | void* CLASS::operator new(size_t size) { return AllocFromActorHeap(size); } \ 60 | void CLASS::operator delete(void* p) { FreeToActorHeap(p); } \ 61 | fBase* CLASS::build() { return new CLASS; } \ 62 | void CLASS::destroy(fBase* p) { if (p) delete p; } 63 | -------------------------------------------------------------------------------- /include/collider/ActorBgCollisionMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "collider/BgCollision.h" 4 | #include "sys/LineNodeMgr.h" 5 | 6 | class ActorBgCollisionMgr : public sead::IDisposer 7 | { 8 | public: 9 | static ActorBgCollisionMgr* instance; // 0x005E3CE0 10 | 11 | void addToList(BgCollision* collider); // 0x002E4C94 12 | void removeFromList(BgCollision* collider); // 0x002E519C 13 | 14 | LineNodeMgr lists[6]; 15 | }; 16 | -------------------------------------------------------------------------------- /include/collider/ActorEllipseBgCollision.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "collider/ActorBgCollisionMgr.h" 4 | 5 | 6 | class ActorEllipseBgCollision : public BgCollision // size: 0x170 7 | { 8 | public: 9 | struct Info // size: 0x20 10 | { 11 | Vec2f positionOffset; // 0 12 | u32 _8; // 8 13 | u32 _C; // C 14 | u32 _10; // 10 15 | u32 _14; // 14 16 | f32 radius; // 18 17 | f32 rotation; // 1C 18 | }; 19 | 20 | ActorEllipseBgCollision(); 21 | 22 | void setup(ActorBase* owner, const Info& info); 23 | 24 | void vfC(u32*, u32) override; 25 | void vf10(u32*, u32) override; 26 | void vf14() override; 27 | void execute() override; 28 | void vf1C(u32*, u32, u32*, Vec2f*, u8) override; 29 | void vf20(u32, u32*, u32, u32) override; 30 | u32 vf24(u32, Vec2f*) override; 31 | Vec2f vf28() override; 32 | void vf2C() override; // deleted 33 | u32* vf30() override; 34 | void vf34() override; 35 | void vf38() override; 36 | 37 | Vec2f _138; 38 | Vec2f _140; 39 | Vec2f _148; 40 | Vec2f halfSize; 41 | u32 _158; 42 | u32 _15C; 43 | u32 _160; 44 | u32 _164; 45 | u32 _168; 46 | u32 _16C; 47 | }; 48 | -------------------------------------------------------------------------------- /include/collider/BasicBgCollisionCheck.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead/seadBitFlag.h" 4 | 5 | 6 | class ActorBase; 7 | 8 | class BasicBgCollisionCheck // size: 0x4C 9 | { 10 | public: 11 | BasicBgCollisionCheck(); // 0044A37C 12 | 13 | u8 _0; // inited to 0 14 | bool ignoreQuicksand; 15 | sead::BitFlag8 collisionMask; 16 | u32 _4; 17 | u32 _8; 18 | ActorBase *actor; 19 | void *_10; // points to this+0x50? 20 | void *_14; // points to this+0x24? 21 | u32 _18; 22 | u32 _1C; 23 | u32 _20; 24 | u32 *_unk24[10]; // first element is pointer to owner? 25 | }; 26 | -------------------------------------------------------------------------------- /include/collider/BasicRideLine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "collider/BgCollision.h" 4 | #include "sead/seadLine.h" 5 | 6 | class Ride2Point 7 | { 8 | sead::Segment2f mSegment; 9 | }; 10 | 11 | 12 | class BasicRideLine // size: 0x20 13 | { 14 | public: 15 | BasicRideLine(); // 0x421394 16 | 17 | u8 _0; 18 | u8 _1; 19 | Ride2Point ride2Point; 20 | u32 _14; 21 | BgCheckUnitInfo bgCheckData; 22 | }; 23 | -------------------------------------------------------------------------------- /include/collider/FollowArg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead.h" 4 | 5 | class FollowArg 6 | { 7 | public: 8 | Vec3f* position; 9 | Vec3f* prevPosition; 10 | u8* layer; 11 | s8* playerIdx; 12 | }; 13 | -------------------------------------------------------------------------------- /include/collider/LoopRideLineBgCollision.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "collider/ActorBgCollisionMgr.h" 4 | #include "collider/BasicRideLine.h" 5 | 6 | 7 | class LoopRideLineBgCollision : public BgCollision 8 | { 9 | public: 10 | struct Info 11 | { 12 | Vec2f positionOffset; 13 | Vec2f distToCenter; 14 | Vec2f* points; 15 | s32 rotation; 16 | }; 17 | 18 | LoopRideLineBgCollision(u32 numSides, Vec2f* pointBuffer, BasicRideLine* rideLineBuffer, BasicRideLine* rideLinePrevBuffer); 19 | ~LoopRideLineBgCollision(); 20 | 21 | void setup(ActorBase* owner, const Info& info); 22 | 23 | void vf14() override; 24 | void execute() override; 25 | void vf1C(u32*, u32, u32*, Vec2f*, u8) override; 26 | void vf20(u32, u32*, u32, u32) override; 27 | u32 vf24(u32, Vec2f*) override; 28 | Vec2f vf28() override; 29 | void vf2C() override; // deleted 30 | u32* vf30() override; 31 | void vf34() override; 32 | void vf38() override; 33 | 34 | sead::Buffer point; // 138 size: numSides + 1 35 | sead::Buffer rideLine; // 140 size: numSides 36 | sead::Buffer rideLinePrev; // 148 size: numSides 37 | }; 38 | -------------------------------------------------------------------------------- /include/collider/PlayerBgCollisionCheck.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "collider/PlayerKoopalingBgCollisionCheck.h" 4 | #include "collider/UnkCollisionClass.h" 5 | 6 | class ActorBase; 7 | 8 | // vtable: 005B8B10 9 | class PlayerBgCollisionCheck : public PlayerKoopalingBgCollisionCheck 10 | { 11 | public: 12 | PlayerBgCollisionCheck(); // 0032E698 13 | ~PlayerBgCollisionCheck(); // 0032E730 14 | 15 | void process() override; // 0032DEBC 16 | void dispose() override; // 0021CEE0 17 | void update() override; // 003054F8 18 | ActorBase* getOwner() override; // 004A4470 19 | ActorBase* vf1C(BgCollision*, u32) override; // 004A43F4 20 | s8* getPlayerId() override; 21 | 22 | s8 playerId; // Inited to -1 23 | u16 _E5A; // Inited to 0 24 | u8 _E5C; // Inited to 0 25 | u8 _E5D; // Inited to 0 26 | u8 _E5E; // Inited to 0 27 | u8 _E5F; // Inited to 0 28 | u8 _E60; // Inited to 0 29 | u8 _E61; // Inited to 1 30 | u32 _E64; // Inited to 0 31 | f32 _E68; // Inited to 0.0f 32 | f32 _E6C; // Inited to 0.0f 33 | f32 _E70; // Inited to 0.0f 34 | f32 _E74; // Inited to 0.0f 35 | f32 _E78; // Inited to 0.0f 36 | f32 _E7C; // Inited to 0.0f 37 | f32 _E80; // Inited to 0.0f 38 | f32 _E84; // Inited to 0.0f 39 | UnkCollisionClass _E88; 40 | UnkCollisionClass _EC0; 41 | u8 _EF8[4]; ///< unk 42 | s32 _EFC; 43 | u8 _400[8]; 44 | }; 45 | 46 | size_assert(PlayerBgCollisionCheck, 0xF08); 47 | -------------------------------------------------------------------------------- /include/collider/PlayerKoopalingBgCollisionCheck.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "collider/ActorBgCollisionCheck.h" 4 | 5 | // vtable: 005B4974 6 | class PlayerKoopalingBgCollisionCheck : public ActorBgCollisionCheck // size: 0xE58 7 | { 8 | public: 9 | PlayerKoopalingBgCollisionCheck(); // 00305A18 10 | ~PlayerKoopalingBgCollisionCheck(); // 00305A84 11 | 12 | void update() override; // 003054FC 13 | 14 | ActorBase* getOwner() override; // 004A2A40 15 | ActorBase* vf1C(BgCollision*, u32) override; // 004A2A38 16 | s8* getPlayerId() override; // 004A2A24 17 | 18 | f32 _DBC; // Inited to 0.0f 19 | f32 _DC0; // Inited to 0.0f 20 | f32 _DC4; // Inited to 0.0f 21 | f32 _DC8; // Inited to 0.0f 22 | f32 _DCC; // Inited to 0.0f 23 | f32 _DD0; // Inited to 0.0f 24 | f32 _DD4; // Inited to 0.0f 25 | f32 _DD8; // Inited to 0.0f 26 | u8 _DDC[4]; 27 | UnkCollisionClass _DE0; 28 | UnkCollisionClass _E18; 29 | u8 _E50[4]; 30 | s32 ownerId; // E54 Inited to -1 31 | }; -------------------------------------------------------------------------------- /include/collider/RectCollider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "SolidCollider.h" 4 | 5 | 6 | class RectCollider : public SolidCollider<4> // size: 0x270 7 | { 8 | public: 9 | struct Info 10 | { 11 | Vec2f centerOffset; 12 | Vec2f halfSize; 13 | Vec2f topLeft; 14 | Vec2f bottomRight; 15 | s32 rotation; 16 | }; 17 | 18 | RectCollider(); 19 | ~RectCollider(); 20 | 21 | void setup(ActorBase* owner, const Info& info); 22 | void setBounds(const Vec2f& topLeft, const Vec2f& bottomRight); 23 | }; 24 | -------------------------------------------------------------------------------- /include/collider/SolidCollider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "collider/BasicRideLine.h" 4 | #include "collider/LoopRideLineBgCollision.h" 5 | 6 | 7 | template 8 | class SolidCollider : public LoopRideLineBgCollision // size: 0x150 + 0x48*TNumSides 9 | { 10 | public: 11 | SolidCollider() : LoopRideLineBgCollision(TNumSides, pointArray, rideLineArray, rideLinePrevArray) { } 12 | ~SolidCollider() { } 13 | 14 | Vec2f pointArray[TNumSides]; 15 | BasicRideLine rideLineArray[TNumSides]; 16 | BasicRideLine rideLinePrevArray[TNumSides]; 17 | }; 18 | -------------------------------------------------------------------------------- /include/collider/SolidOnTopCollider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "collider/ActorBgCollisionMgr.h" 4 | #include "collider/BasicRideLine.h" 5 | 6 | 7 | class SolidOnTopColliderBase : public BgCollision // size: 0x154 8 | { 9 | public: 10 | struct Info 11 | { 12 | Vec2f positionOffset; 13 | Vec2f distToCenter; 14 | Vec2f* points; 15 | s32 rotation; 16 | }; 17 | 18 | SolidOnTopColliderBase(u32 numSides, Vec2f* pointBuffer, BasicRideLine* rideLineBuffer, BasicRideLine* rideLinePrevBuffer); 19 | ~SolidOnTopColliderBase(); 20 | 21 | void setup(ActorBase* owner, const Info& info); 22 | 23 | void vf14() override; 24 | void execute() override; 25 | void vf1C(u32*, u32, u32*, Vec2f*, u8) override; 26 | void vf20(u32, u32*, u32, u32) override; 27 | u32 vf24(u32, Vec2f*) override; 28 | Vec2f vf28() override; 29 | void vf2C() override; // deleted 30 | u32* vf30() override; 31 | void vf34() override; 32 | void vf38() override; 33 | 34 | sead::Buffer points; // 138 size: numSides + 1 35 | sead::Buffer sides1; // 140 size: numSides 36 | sead::Buffer sides2; // 148 size: numSides 37 | f32 thickness; // 150 inited to 4.0 38 | }; 39 | 40 | 41 | template 42 | class SolidOnTopCollider : public SolidOnTopColliderBase // size: 0x154 + 0x40*TNumSides + 0x8*(TNumSides+1) 43 | { 44 | public: 45 | SolidOnTopCollider() : SolidOnTopColliderBase(TNumSides, pointArray, rideLineArray, rideLinePrevArray) { } 46 | 47 | Vec2f pointArray[TNumSides + 1]; 48 | u32 _164; 49 | BasicRideLine rideLineArray[TNumSides]; 50 | BasicRideLine rideLinePrevArray[TNumSides]; 51 | }; 52 | -------------------------------------------------------------------------------- /include/collider/UnkCollisionClass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | class UnkCollisionClass // size: 0x38 6 | { 7 | public: 8 | UnkCollisionClass(); 9 | void reset(); 10 | void copy(UnkCollisionClass* other); 11 | 12 | u8 _0; // Inited to 0 13 | u8 _1; // Inited to 0 14 | u8 _2; // Inited to 0 15 | u8 _3; // Inited to 0 16 | s32 _4; // Inited to -1 17 | u32 _8; // Inited to 0 18 | f32 _C; // Inited to 0.0f 19 | f32 _10; // Inited to 0.0f 20 | f32 _14; // Inited to 0.0f 21 | f32 _18; // Inited to 0.0f 22 | u32 _1C; // Inited to 0 23 | u32 _20; // Inited to 0 24 | u32 _24; // Inited to 0 25 | f32 _28; // Inited to 0.0f 26 | u32 _2C; // Inited to 0 27 | u8 _30; // Inited to 0 28 | u32 _unk34; // Most likely part of this class 29 | }; 30 | -------------------------------------------------------------------------------- /include/course/BgmAnimMgr.h: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | 3 | class BgmAnimMgr 4 | { 5 | public: 6 | static BgmAnimMgr* instance; 7 | 8 | u32 getState(); 9 | }; 10 | -------------------------------------------------------------------------------- /include/course/CoinOrigin.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead.h" 4 | 5 | // Most functionality of this class is removed in NSMB2 6 | 7 | class CoinOrigin : public sead::IDisposer // size 0x130 8 | { 9 | public: 10 | static CoinOrigin* instance; 11 | 12 | sead::IDisposer unkDisposer; // 10 13 | s32 coinAngle; // 14 14 | void *modelCoin; // 18 - Unused NSMBU Leftover 15 | void *modelBlueCoin; // 1C ^ 16 | sead::OrthoProjection projection; // 20 ^ 17 | sead::OrthoCamera camera; // CC ^ 18 | 19 | }; 20 | -------------------------------------------------------------------------------- /include/course/CourseActorMgr.h: -------------------------------------------------------------------------------- 1 | #include "sead.h" 2 | #include "math/Vec.h" 3 | #include "actors/ActorBase.h" 4 | 5 | 6 | class CourseActorMgr 7 | { 8 | 9 | // createInstance() Address: 0x003FD554 10 | // deleteInstance() Address: 0x003FD5E4 11 | // sInstance Address: 0x005E2D18 12 | // SingletonDisposer_::~SingletonDisposer_() Address: 0x003FD6B0 13 | // SingletonDisposer_::sStaticDisposer Address: 0x005E2D1C 14 | // SingletonDisposer_::vtbl Address: 0x005C9CA8 15 | SEAD_SINGLETON_DISPOSER(CourseActorMgr); 16 | 17 | struct ActorList 18 | { 19 | u32 maxCapacity; 20 | ActorBase** actorList; 21 | u32 currentCapacity; 22 | ActorBase** actorListEnd; 23 | }; 24 | size_assert(ActorList, 0x10); 25 | 26 | public: 27 | ActorBase* create(ActorBase::CreateInfo* info); 28 | ActorBase* searchById(s32 id); 29 | ActorBase* searchByProfileId(u32 id); 30 | ActorBase* searchByProfileId(u32 id, ActorBase* prev); 31 | ActorBase* countByProfileId(u32 id); 32 | 33 | sead::FixedPtrArray mActors; 34 | ActorList mActorList; 35 | }; 36 | 37 | size_assert(CourseActorMgr, 0x82C); -------------------------------------------------------------------------------- /include/course/CourseSpriteMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead.h" 4 | 5 | 6 | class CourseSpriteMgr : public sead::IDisposer 7 | { 8 | public: 9 | static CourseSpriteMgr* instance; 10 | 11 | static const u16 spriteToProfileIds[]; 12 | static const u32 spriteCount; 13 | }; 14 | -------------------------------------------------------------------------------- /include/course/DemoMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead.h" 4 | 5 | class DemoMgr : public sead::IDisposer 6 | { 7 | public: 8 | static DemoMgr* instance; 9 | 10 | bool freeze(); 11 | bool freezeIfOnGround(); 12 | 13 | void unfreeze(); 14 | 15 | bool setDemoState(u32 id); 16 | }; 17 | -------------------------------------------------------------------------------- /include/course/FlagMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead.h" 4 | 5 | class FlagMgr : public sead::IDisposer // size: 0x930 6 | { 7 | public: 8 | struct Entry 9 | { 10 | u32 timer; 11 | u32 _4; 12 | u32 _8; 13 | }; 14 | 15 | u64 flags; // 10 16 | Entry entries[64]; // 18 17 | // More member vars 18 | 19 | // Delay is in 10x frames, 1=1/6 second 20 | void set(u8 id, u32 delay, bool active, bool unk1, bool unk2, u32 unk3); 21 | 22 | inline u64 mask(u8 id) 23 | { 24 | return (u64)1 << id; 25 | } 26 | 27 | inline bool isActive(u8 id) 28 | { 29 | return (flags & mask(id)) != 0; 30 | } 31 | 32 | inline bool isInactive(u8 id) 33 | { 34 | return (flags & mask(id)) == 0; 35 | } 36 | 37 | inline void set(u8 id, bool active) 38 | { 39 | flags &= ~mask(id); 40 | if (active) 41 | flags |= mask(id); 42 | } 43 | 44 | 45 | static FlagMgr* instance; 46 | }; 47 | -------------------------------------------------------------------------------- /include/course/LineFollower.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "state/FStateMgr.h" 4 | 5 | class LineFollower // size: 0x90 6 | { 7 | public: 8 | LineFollower(); 9 | 10 | void init(const Vec2f& initialPosition, f32 lineSpeed, u8 layer, u8 unk2, bool reverseDirecton=false); 11 | void initState(bool unk=false); 12 | 13 | inline void execute() 14 | { 15 | stateMgr.executeState(); 16 | } 17 | 18 | 19 | FStateMgr stateMgr; // 0 20 | f32 _24; 21 | f32 _28; 22 | Vec2f _2C[6]; 23 | Vec2f speed; // 5C 24 | Vec2f position; // 64 25 | Vec2f _6C; 26 | Vec2f _74; 27 | f32 _7C; 28 | f32 _80; 29 | u32 _84; 30 | f32 lineSpeed; // 88 31 | u8 _8C; 32 | u8 layer; // 8D 33 | u8 reversedDirection; // 8E 34 | u8 _8F; 35 | }; 36 | -------------------------------------------------------------------------------- /include/course/ModelMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sys/Allocator.h" 4 | #include "gfx/AnimModel.h" 5 | #include "sys/ResourceMgr.h" 6 | 7 | 8 | template 9 | class ModelMgr 10 | { 11 | public: 12 | HeapAllocator allocator; 13 | 14 | AnimModelBase* models[TNumModelTypes][TNumModels]; 15 | bool usedIndices[TNumModels]; 16 | 17 | u32 numModels; 18 | u8 numModelTypes; 19 | u32 numModelsCreated; 20 | 21 | 22 | ModelMgr() 23 | { 24 | this->numModels = TNumModels; 25 | this->numModelTypes = TNumModelTypes; 26 | 27 | numModelsCreated = 0; 28 | 29 | for (u8 i = 0; i < TNumModelTypes; i++) 30 | { 31 | for (u32 j = 0; j < TNumModels; j++) 32 | { 33 | models[i][j] = nullptr; 34 | usedIndices[j] = false; 35 | } 36 | } 37 | } 38 | 39 | virtual ~ModelMgr() 40 | { 41 | freeModels(); 42 | } 43 | 44 | virtual bool createModels() = 0; 45 | 46 | void freeModels() 47 | { 48 | for (u8 i = 0; i < TNumModelTypes; i++) 49 | { 50 | for (u32 j = 0; j < TNumModels; j++) 51 | { 52 | AnimModelBase* model = models[i][j]; 53 | if (model) 54 | { 55 | model->cleanup(); 56 | delete model; 57 | } 58 | models[i][j] = nullptr; 59 | } 60 | } 61 | } 62 | 63 | s32 getFreeIdx() 64 | { 65 | for (u32 i = 0; i < numModels; i++) 66 | { 67 | if (usedIndices[i] == false) 68 | return i; 69 | } 70 | 71 | return -1; 72 | } 73 | 74 | bool acquireIdx(s32 idx) 75 | { 76 | if (usedIndices[idx]) 77 | return false; 78 | 79 | usedIndices[idx] = true; 80 | return true; 81 | } 82 | 83 | void freeIdx(s32 idx) 84 | { 85 | usedIndices[idx] = false; 86 | } 87 | 88 | AnimModelBase* getModel(u8 type, s32 idx) 89 | { 90 | return models[type][idx]; 91 | } 92 | }; 93 | -------------------------------------------------------------------------------- /include/course/PairChild.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "state/FStateMgr.h" 4 | 5 | class PairChild // size: 0xD0 or larger 6 | { 7 | public: 8 | 9 | enum MovementType 10 | { 11 | MOVEMENT_NONE = 0, 12 | MOVEMENT_ROTATION = 1, 13 | MOVEMENT_UNK2 = 2, 14 | MOVEMENT_PATH = 3, 15 | MOVEMENT_BACKFORTH = 4, 16 | MOVEMENT_UNK5 = 5, 17 | MOVEMENT_UNK6 = 6, 18 | MOVEMENT_UNK7 = 7, 19 | MOVEMENT_UNK8 = 8, 20 | MOVEMENT_UNK9 = 9, 21 | MOVEMENT_UNKA = 10, 22 | MOVEMENT_UNKB = 11 23 | }; 24 | 25 | 26 | PairChild(); 27 | 28 | void link(const Vec3f& initialPosition, u32 movementMask, u8 movementId); 29 | void execute(); 30 | u32 getMaskForMovementType(u32 movementType); 31 | 32 | 33 | Vec3f position; // 0 34 | Vec3f position2; // C 35 | Vec3f _18; // 18 36 | Vec3f _24; // 24 37 | bool isMoving; // 30 Inited to 0 38 | u8 _31; // 31 39 | // pad? 40 | s32 parentId; // 34 41 | f32 _38; // 38 Inited to 0.0 42 | u32 _3C; // 3C 43 | u32 _40; // 40 Inited to 0 44 | u32 movementMask; // 44 45 | u8 movementId; // 48 46 | s32 rotation; // 4C Inited to 0 47 | u32 _50; // 50 48 | f32 _54; // 54 Inited to 1.0 49 | u32 _58; // 58 Set by function at 0x2A7410 50 | f32 _5C; // 5C 51 | f32 _60; // 60 52 | u32 _64; // 64 53 | u32 _68; // 68 54 | f32 _6C; // 6C 55 | f32 _70; // 70 56 | u32 _74; // 74 Inited to 0 57 | u32 _78; // 78 Inited to 0 58 | u32 _7C; // 7C Inited to 0 59 | u8 _80; // 80 60 | u8 _81; // 81 61 | u8 _82; // 82 62 | u8 _83; // 83 63 | u32 _84; // 84 64 | f32 _88; // 88 65 | u32 _8C; // 8C Inited to 0 66 | u32 _90; // 90 Inited to 0 67 | u32 _94; // 94 Inited to 0 68 | 69 | u8 _unk98[0xAC-0x98]; // 98 70 | 71 | FStateMgr stateMgr; // AC up to D0, Used with two different states 72 | }; 73 | -------------------------------------------------------------------------------- /include/course/QuakeMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead.h" 4 | 5 | 6 | class QuakeMgr : public sead::IDisposer 7 | { 8 | public: 9 | enum Flags : u32 10 | { 11 | FLAG_HOP_ENEMIES = 0x1, 12 | FLAG_STUN_ENEMIES = 0x2, 13 | FLAG_HOP_PLAYER = 0x10, 14 | FLAG_STUN_PLAYER = 0x20, 15 | }; 16 | 17 | void quake(u32 patternIdx, bool doShake = true, u32 flags = 0); 18 | 19 | void UnkQuake(char a2, u32 patternIdx, bool doShake = true, u32 flags = 0); 20 | void UnkQuake2(char a2, u32 patternIdx, u32 flags = 0); 21 | void UnkQuake3(u32 patternIdx, bool doShake = true); 22 | 23 | void stopQuake(); 24 | 25 | u32 _10; // 10 26 | f32 currentPatternConstants[2][5]; // 14 27 | u32 _3C; // 3C 28 | u8 _40; // 40 29 | u8 _41; // 41 30 | u8 _42; // 42 31 | u32 _44; // 44 32 | u32 _48; // 48 33 | Vec2f cameraShift; // 4C 34 | u32 _54; // 54 35 | 36 | static QuakeMgr* instance; 37 | }; -------------------------------------------------------------------------------- /include/course/TileLayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | class TileLayer 6 | { 7 | public: 8 | static TileLayer* Layer1; 9 | 10 | u16* getTilePtr(u32 x, u32 y, u32* unkOut = nullptr); 11 | }; 12 | -------------------------------------------------------------------------------- /include/course/TileMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead.h" 4 | #include "mapobj/BgActorLiquid.h" 5 | 6 | class TileMgr : public sead::IDisposer 7 | { 8 | public: 9 | static TileMgr* instance; 10 | 11 | u8 _unk10[0x18-0x10]; // 10 12 | f32 liquidLevel; // 18 13 | u8 _unk1C[0x160-0x1C]; // 1C 14 | u8 liquidType; // 160 15 | u8 _unk161[0x10B4-0x161]; // 161 16 | 17 | LiquidTop* waveLiquidTop; // 10B4 Custom 18 | 19 | void setTileType(u16 x, u16 y, u32 tileIdx); 20 | 21 | void initWaveLiquidTop(); 22 | f32 getWaveLiquidLevel(f32 x) const; 23 | }; 24 | -------------------------------------------------------------------------------- /include/course/TilesetGfxMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "gfx/Texture.h" 4 | 5 | 6 | class TilesetGfxMgr : public sead::IDisposer 7 | { 8 | public: 9 | static TilesetGfxMgr* instance; 10 | 11 | struct AnimatedTileEntry 12 | { 13 | u8 _0; 14 | u8 _1; 15 | u8 _2; 16 | bool shouldBeCopied; 17 | u32 _4; 18 | void* _8; 19 | u32 _C; 20 | u32 _10; 21 | u32 _14; 22 | u32 _18; 23 | }; 24 | 25 | CtpkTexture mainTexture; 26 | CtpkTexture _2C[14]; 27 | AnimatedTileEntry animatedTiles[19]; 28 | bool isTex8Loaded; 29 | bool isTex0to7Loaded; 30 | bool isTex9Loaded; 31 | bool isTex11Loaded; 32 | CtpkTexture* tilesetTextures[4]; 33 | void* mainTextureAddr; 34 | void* mainTexturePhysicalAddr; 35 | u8 _3E4[0x494-0x3E4]; 36 | bool isRainbowCourse; 37 | }; 38 | -------------------------------------------------------------------------------- /include/effect/Effect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "math/Mtx34.h" 4 | 5 | #include "sys/Common.h" 6 | 7 | #include "sead/seadRuntimeTypeInfo.h" 8 | 9 | struct EffectParam // size: 0x28 10 | { 11 | u32 emitterSetId; // 0 12 | f32 scale; // 4 13 | Vec3f positionOffset; // 8 14 | ColorF32 tintColor; // 14 15 | u32 flags; // 24 16 | }; 17 | 18 | 19 | class Effect // size: 0x40 20 | { 21 | public: 22 | Effect(); 23 | Effect(u32 id); 24 | 25 | void setEffectId(u32 id); 26 | void update(const Vec3f* position = nullptr, const Vec3i* rotation = nullptr, const Vec3f* scale = nullptr); 27 | void remove(); 28 | 29 | bool isAlive(); 30 | 31 | Mtx34 mtx; // 0 32 | bool mMtxHasScale; // 30 33 | void* mHandleEmitterSet; // 34 34 | u32 mHandleCreateID; // 38 35 | EffectParam* paramEntry; // 3C 36 | }; 37 | 38 | 39 | class ScopedEffect : public Effect // size: 0x5C 40 | { 41 | public: 42 | ScopedEffect(); 43 | ~ScopedEffect(); // Calls remove() 44 | 45 | virtual void vf0(); // deleted 46 | virtual void vf4(); // deleted 47 | 48 | SEAD_RTTI_BASE(ScopedEffect); 49 | 50 | void createEffect(u32 id, const Vec3f* position = nullptr, const Vec3i* rotation = nullptr, const Vec3f* scale = nullptr); 51 | 52 | 53 | u32 _44; 54 | u32 _48; 55 | u32 _4C; 56 | u32 _50; // Vec2 probably 57 | u32 _54; // ^ 58 | s16 effectID; 59 | bool mIsActive; 60 | }; 61 | 62 | class UnkEffectType : public ScopedEffect // size: 0x5C 63 | { 64 | public: 65 | UnkEffectType(); 66 | 67 | SEAD_RTTI_OVERRIDE(UnkEffectType, ScopedEffect); 68 | 69 | }; -------------------------------------------------------------------------------- /include/enemy/EnemyDeathInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | #include "math/Vec.h" 5 | 6 | #include "actors/ScoreMgr.h" 7 | #include "state/StateID.h" 8 | 9 | // Size: 0x1C 10 | class EnemyDeathInfo 11 | { 12 | struct KillArg 13 | { 14 | KillArg(u32 arg = 0) : 15 | arg(arg) {} 16 | 17 | KillArg(ScoreMgr::RewardType rewardType, u8 killDirection, s8 playerId) : 18 | rewardType(rewardType), killDirection(killDirection), playerId(playerId) {} 19 | 20 | union 21 | { 22 | struct 23 | { 24 | ScoreMgr::RewardType rewardType; 25 | u8 killDirection; 26 | s8 playerId; 27 | }; 28 | u32 arg; 29 | }; 30 | }; 31 | 32 | public: 33 | 34 | // Address: 0x005733F4 35 | static f32 sDefaultFallSpeedMax; // -4.0 36 | 37 | // Address: 0x005E64E8 38 | static f32 sDefaultFallAcceleration; // -0.24375 39 | 40 | public: 41 | EnemyDeathInfo() : 42 | mSpeed({ 1.5f, 3.9f }), 43 | mFallSpeedMax(sDefaultFallSpeedMax), 44 | mFallAcceleration(sDefaultFallAcceleration), 45 | mStateID(nullptr), 46 | mKillArg({ ScoreMgr::RewardType::Points_100, 0, -1 }), 47 | mNoRespawn(false) {} 48 | 49 | EnemyDeathInfo(const Vec2f& speed, f32 fallSpeedMax, f32 fallAcceleration, const StateID* stateID) : 50 | mSpeed(speed), 51 | mFallSpeedMax(fallSpeedMax), 52 | mFallAcceleration(fallAcceleration), 53 | mStateID(stateID) {} 54 | 55 | void setKillArg(ScoreMgr::RewardType rewardType, u8 killDirection, s8 playerId) 56 | { 57 | mKillArg.rewardType = rewardType; 58 | mKillArg.killDirection = killDirection; 59 | mKillArg.playerId = playerId; 60 | } 61 | 62 | // Address: 0x002E84B0 63 | void setNoRespawn(const EnemyDeathInfo& info); 64 | 65 | private: 66 | Vec2f mSpeed; 67 | f32 mFallSpeedMax; 68 | f32 mFallAcceleration; 69 | const StateID* mStateID; 70 | KillArg mKillArg; 71 | bool mNoRespawn; 72 | }; 73 | 74 | size_assert(EnemyDeathInfo, 0x1C); -------------------------------------------------------------------------------- /include/fragment/BigBlockFragment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "fragment/Fragment.h" 4 | #include "sead/heap/seadHeap.h" 5 | #include "math/Vec.h" 6 | #include "gfx/AnimModel.h" 7 | 8 | // Size: 0x5C 9 | // Vtable: 0x005CB510 10 | class BigBlockFragment : Fragment 11 | { 12 | // Unknown class with nullsub constructor at 0x0031A7F4 13 | struct PartInfo 14 | { 15 | Vec3f mPosition; 16 | Vec3f mSpeed; 17 | }; 18 | size_assert(PartInfo, 0x18); 19 | 20 | public: 21 | enum class Type : u8 22 | { 23 | // Retail 24 | Big_Renga_Block = 0x0, // NSMBU Leftover 25 | Box_Wood_A = 0x1, // NSMBU Leftover 26 | Box_Wood_B = 0x2, // NSMBU Leftover 27 | Obj_Turaka_Rakka = 0x3, // NSMBU Leftover 28 | Kazan_Rock_A = 0x4, // 29 | Kazan_Rock_B = 0x5, // 30 | Poltergeist = 0x6, // NSMBU Leftover 31 | Boss_Kameck_Block_A = 0x7, // NSMBU Leftover 32 | Boss_Kameck_Block_B = 0x8, // NSMBU Leftover 33 | Boss_Kameck_Block_C = 0x9, // NSMBU Leftover 34 | Rock_A = 0xA, // 35 | Rock_B = 0xB, // 36 | Block_Hunka = 0xC, // 37 | Boss_Koopa_Lift = 0xD, // 38 | Battan_A = 0xE, // 39 | Battan_B = 0xF, // 40 | 41 | Count 42 | }; 43 | 44 | static constexpr u8 TypeCount = static_cast(BigBlockFragment::Type::Count); 45 | 46 | public: 47 | // Original Address: 0x006123BC 48 | static sead::SafeString sResourceNames[]; 49 | 50 | // Original Address: 0x0061243C 51 | static sead::SafeString sModelNames[][4]; 52 | 53 | // Address: 0x005E6F10 54 | static s32 sRotationIncrement; // ((11.25 * 2147500000.0) / 180.0) 55 | 56 | public: 57 | // Address: 0x0031AE04 58 | BigBlockFragment(sead::Heap* heap, const Vec3f& position, u32 flags); 59 | 60 | // Address: 0x0031A848 61 | void onCreate() override; 62 | 63 | // Address: 0x0031AC88 64 | void onExecute() override; 65 | 66 | // Address: 0x0031A7F8 67 | void onDraw() override; 68 | 69 | // Address: 0x0031AC38 70 | void onDelete() override; 71 | 72 | // Address: 0x0031A728 73 | void updateModelMatrix(); 74 | 75 | AnimModelBase* mModels[4]; 76 | HeapAllocator mAllocator; 77 | PartInfo mPartInfo[4]; 78 | Type mType; 79 | u8 _D5[7]; 80 | }; 81 | 82 | size_assert(BigBlockFragment, 0xDC); 83 | -------------------------------------------------------------------------------- /include/fragment/Fragment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead/heap/seadHeap.h" 4 | #include "math/Vec.h" 5 | 6 | // This class is entirely inlined 7 | class UnkFragmentBase 8 | { 9 | public: 10 | UnkFragmentBase(sead::Heap* heap) : 11 | mHeap(heap) {} 12 | 13 | u32 _4; 14 | u32 _8; 15 | sead::Heap* mHeap; 16 | bool mIsFinished; 17 | }; 18 | 19 | size_assert(UnkFragmentBase, 0x10); 20 | 21 | // Size: 0x5C 22 | // Vtable: 0x005CB510 23 | class Fragment : UnkFragmentBase 24 | { 25 | public: 26 | Fragment(sead::Heap* heap) : 27 | UnkFragmentBase(heap) {} 28 | 29 | virtual void onCreate() = 0; 30 | 31 | // Address: 0x002568AC 32 | virtual void onExecute(); 33 | 34 | // Address: 0x002568A4 35 | virtual void onDraw(); 36 | 37 | // Address: 0x002568A8 38 | virtual void onDelete(); 39 | 40 | Vec3f mPosition; 41 | Vec3f mSpeed; 42 | Vec3f mMaxSpeed; 43 | Vec3f mScale; 44 | Vec3i mRotation; 45 | f32 mAcceleration; 46 | u32 mFlags; 47 | u16 mTimer; 48 | s8 mPlayerId; 49 | }; 50 | 51 | size_assert(Fragment, 0x5C); -------------------------------------------------------------------------------- /include/gfx/AnimModel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "gfx/AnimModelBase.h" 4 | 5 | template 6 | class AnimModel : public AnimModelBase 7 | { 8 | public: 9 | 10 | AnimModel() : 11 | AnimModelBase( 12 | skeletalCount, &animBuf[skeletalOffset], 13 | materialCount, &animBuf[materialOffset], 14 | visibilityCount, &animBuf[visibilityOffset] 15 | ) {} 16 | 17 | private: 18 | static constexpr s32 totalCount = skeletalCount + materialCount + visibilityCount; 19 | 20 | static constexpr s32 skeletalOffset = 0; 21 | static constexpr s32 skeletalEnd = skeletalOffset + skeletalCount; 22 | 23 | static constexpr s32 materialOffset = skeletalEnd; 24 | static constexpr s32 materialEnd = materialOffset + materialCount; 25 | 26 | static constexpr s32 visibilityOffset = materialEnd; 27 | 28 | AnimBase* animBuf[totalCount > 0 ? totalCount : 1]; 29 | }; 30 | 31 | // Specialization for all counts being `0` 32 | template <> 33 | class AnimModel<0, 0, 0> : public AnimModelBase 34 | { 35 | public: 36 | AnimModel() : 37 | AnimModelBase(0, nullptr, 0, nullptr, 0, nullptr) {} 38 | }; 39 | 40 | static_assert(sizeof(AnimModel<0,0,0>) == 0x38); 41 | static_assert(sizeof(AnimModel<0,0,1>) == 0x3C); 42 | static_assert(sizeof(AnimModel<1,1,1>) == 0x44); 43 | static_assert(sizeof(AnimModel<1,2,1>) == 0x48); 44 | static_assert(sizeof(AnimModel<2,2,1>) == 0x4C); -------------------------------------------------------------------------------- /include/gfx/AnimModelBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "gfx/Model.h" 4 | #include "gfx/Animation.h" 5 | 6 | // Size: 0x38 7 | // Vtable: 0x005AC908 8 | class AnimModelBase : public Model 9 | { 10 | public: 11 | 12 | // Address: 0x0028A880 13 | AnimModelBase( 14 | u32 numSkeletalAnim, AnimBase** skeletalAnims, 15 | u32 numMaterialAnim, AnimBase** materialAnims, 16 | u32 numVisibilityAnim, AnimBase** visibilityAnims 17 | ); 18 | 19 | // Address: 0x0028A620 20 | void cleanup() override; 21 | 22 | // Address: 0x0028A838 23 | void update() override; 24 | 25 | // Address: 0x0028A814 26 | void updateAnimation(); 27 | 28 | // Address: 0x0028A140 29 | void setup( 30 | nw::gfx::res::ResModel* model, nw::anim::res::ResAnim* anim, 31 | HeapAllocator* allocator, Resource* modeRes, Resource* animRes, 32 | nw::gfx::Model::BufferOption bufferOption = nw::gfx::Model::MULTI_FLAG_ANIMATABLE_MATERIAL 33 | ); 34 | 35 | // Address: 0x0028A744 36 | void setSkeletalAnim(Resource* res, const sead::SafeString& key); 37 | 38 | // Address: 0x001B1B60 39 | void setSkeletalAnim(u32 slot, Resource* res, const sead::SafeString& key); 40 | 41 | // Address: 0x001B454C 42 | void setMaterialAnim(u32 slot, Resource* res, const sead::SafeString& key); 43 | 44 | // Address: 0x001B4724 45 | void setVisibilityAnim(u32 slot, Resource* res, const sead::SafeString& key); 46 | 47 | inline AnimBase* skeletalAnim(u32 slot) const 48 | { 49 | return mSkeletalAnims[slot]; 50 | } 51 | 52 | inline AnimBase* materialAnim(u32 slot) const 53 | { 54 | return mMaterialAnims[slot]; 55 | } 56 | 57 | inline AnimBase* visibilityAnim(u32 slot) const 58 | { 59 | return mVisibilityAnims[slot]; 60 | } 61 | 62 | private: 63 | u32 mNumSkeletalAnim; // 1C 64 | AnimBase** mSkeletalAnims; // 20 65 | 66 | u32 mNumMaterialAnim; // 24 67 | AnimBase** mMaterialAnims; // 28 68 | 69 | u32 mNumVisibilityAnim; // 2C 70 | AnimBase** mVisibilityAnims; // 30 71 | 72 | bool mHasNoAnimations; // 34 73 | u8 _35; // 35 74 | }; 75 | 76 | size_assert(AnimModelBase, 0x38); -------------------------------------------------------------------------------- /include/gfx/Animation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | #include "sys/Allocator.h" 5 | 6 | enum class PlayPolicy : u8 7 | { 8 | One_Time = 0, 9 | Loop = 1, 10 | }; 11 | 12 | // Size: 0x18 13 | // Vtable: 0x0059E344 14 | class AnimBase 15 | { 16 | public: 17 | virtual ~AnimBase(); 18 | 19 | // Address: 0x001B549C 20 | virtual void* animEvaluator(); // nw::gfx::BaseAnimEvaluator* 21 | 22 | // Address: 0x00495CE4 23 | virtual const void* animEvaluator() const; // const nw::gfx::BaseAnimEvaluator* 24 | 25 | // Address: 0x001B54A4 26 | virtual void vf10(nw::anim::res::ResAnim resAnim); // 27 | 28 | virtual void cleanup(); // Deleted 29 | virtual void vf18(nw::anim::res::ResAnim animData, s32 a3) = 0; // 30 | virtual bool tryBind() = 0; // 31 | 32 | // Address: 0x001B271C 33 | void setPlayPolicy(PlayPolicy playPolicy); 34 | 35 | // Address: 0x001B2770 36 | void unkA(nw::anim::res::ResAnim animData); 37 | 38 | // Address: 0x001B281C 39 | void setFrameStep(f32 step); 40 | 41 | // Address: 0x001B284C 42 | void setFrame(f32 frame); 43 | 44 | // Address: 0x001B548C 45 | void updateFrame(); 46 | 47 | // Address: 0x004955AC 48 | bool isAtFrame(f32 frame); 49 | 50 | // Address: 0x004956EC 51 | f32 getEndFrame(); 52 | 53 | // Address: 0x00495704 54 | f32 getStartFrame(); 55 | 56 | // Address: 0x00495728 57 | bool isDone(); 58 | 59 | // Address: 0x004957E8 60 | f32 getFrameStep(); 61 | 62 | // Address: 0x0049580C 63 | f32 getCurrentFrame(); 64 | 65 | private: 66 | PlayPolicy mPlayPolicy; // 67 | void* mAnimEvaluator; // nw::gfx::BaseAnimEvaluator 68 | HeapAllocator mAllocator; // 69 | SkeletalModelWrapper* mModel; // 70 | }; 71 | 72 | size_assert(AnimBase, 0x18); -------------------------------------------------------------------------------- /include/gfx/Light.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead.h" 4 | 5 | 6 | class Light 7 | { 8 | public: 9 | Light(); 10 | ~Light(); 11 | 12 | void load(const sead::SafeString& identifier, u32 idx); 13 | void unload(); 14 | void execute(); 15 | 16 | u8 _0[0x2C]; 17 | }; 18 | -------------------------------------------------------------------------------- /include/gfx/Model.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sys/Allocator.h" 4 | #include "math/Mtx34.h" 5 | 6 | #include "nw/gfx/Model.h" 7 | #include "nw/gfx/CalculatedTransform.h" 8 | 9 | #include "sys/ResourceMgr.h" 10 | 11 | #include "gfx/GfxWrapper.h" 12 | 13 | // Size: 0x1C 14 | // Vtable: 0x005A8698 15 | class Model 16 | { 17 | public: 18 | 19 | // Address: 0x0024B5FC 20 | Model(); 21 | 22 | // Address: 0x0024B640 (free: 0024B620) 23 | virtual ~Model(); 24 | 25 | // Address: 0x0024B5D4 26 | virtual SkeletalModelWrapper* getGfxWrapper(); 27 | 28 | // Address: 0x0024B5B4 29 | virtual void cleanup(); 30 | 31 | // Address: 0x0024B5DC 32 | virtual void update(); 33 | 34 | // Address: 0x0024B46C 35 | void create( 36 | nw::gfx::res::ResSceneObject* resource, nw::os::IAllocator* allocator, 37 | nw::gfx::Model::BufferOption bufferOption 38 | ); 39 | 40 | // Address: 0x0024B4B4 41 | static Model* create( 42 | Resource* container, const sead::SafeString& key, Allocator* allocator, 43 | nw::gfx::Model::BufferOption bufferOption = nw::gfx::Model::FLAG_BUFFER_NOT_USE 44 | ); 45 | 46 | inline void setScale(const Vec3f& scale) 47 | { 48 | getGfxWrapper()->getModel()->Transform().SetScale(scale); 49 | } 50 | 51 | inline void setDrawMatrix(Mtx34* mtx) 52 | { 53 | getGfxWrapper()->setDrawMatrix(mtx); 54 | } 55 | 56 | inline s32 getBoneIdx(const char* boneName) 57 | { 58 | return getGfxWrapper()->getBoneIdx(boneName); 59 | } 60 | 61 | inline bool getBoneWorldMatrix(Mtx34& out, s32 boneIdx) 62 | { 63 | return getGfxWrapper()->getBoneWorldTransformMatrix(out, boneIdx); 64 | } 65 | 66 | inline bool getBonePosition(Vec3f& out, s32 boneIdx) 67 | { 68 | return getGfxWrapper()->getBonePosition(out, boneIdx); 69 | } 70 | 71 | inline bool getBoneLocalMatrix(Mtx34& out, s32 boneIdx) 72 | { 73 | return getGfxWrapper()->getBoneLocalTransformMatrix(out, boneIdx); 74 | } 75 | 76 | inline bool getBoneLocalScale(Vec3f& out, s32 boneIdx) 77 | { 78 | return getGfxWrapper()->getBoneLocalTransformScale(out, boneIdx); 79 | } 80 | 81 | inline void setBoneLocalMatrix(s32 boneIdx, const Mtx34& mtx) 82 | { 83 | return getGfxWrapper()->setBoneLocalTransformMatrix(boneIdx, mtx); 84 | } 85 | 86 | inline void setBoneLocalScale(s32 boneIdx, const Vec3f& vec) 87 | { 88 | return getGfxWrapper()->setBoneLocalTransformScale(boneIdx, vec); 89 | } 90 | 91 | inline nw::gfx::CalculatedTransform* getBoneWorldTransform(s32 boneIdx) 92 | { 93 | return getGfxWrapper()->getBoneWorldTransform(boneIdx); 94 | } 95 | 96 | inline nw::gfx::CalculatedTransform* getBoneLocalTransform(s32 boneIdx) 97 | { 98 | return getGfxWrapper()->getBoneLocalTransform(boneIdx); 99 | } 100 | 101 | private: 102 | SkeletalModelWrapper mModelWrapper; 103 | }; 104 | 105 | size_assert(Model, 0x1C); -------------------------------------------------------------------------------- /include/gfx/Renderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "gfx/AnimModel.h" 4 | #include "sead.h" 5 | #include "nn/ulcd/StereoCamera.h" 6 | 7 | // Size 0x3A0 8 | class Renderer 9 | { 10 | // createInstance() Address: 0x00429264 11 | // deleteInstance() Address: deleted 12 | // sInstance Address: 0x005E74F0 13 | // SingletonDisposer_::~SingletonDisposer_() Address: 0x00429314 14 | // SingletonDisposer_::sStaticDisposer Address: 0x005E74F4 15 | // SingletonDisposer_::vtbl Address: 0x005CD250 16 | SEAD_SINGLETON_DISPOSER(Renderer); 17 | 18 | typedef u8 OrthoCamWrapper[0x10C]; 19 | 20 | public: 21 | 22 | // Address: 0x00429A90 23 | Renderer(); 24 | 25 | // Address: 0x00428F78 26 | void initialize(); 27 | 28 | // Address: 0x004290B4 29 | void setViewRect(const sead::BoundBox2f& viewRect); 30 | 31 | // Address: 0x004290D8 32 | void updateCamera(); 33 | 34 | // Address: 0x00429A1C 35 | void drawModel(SkeletalModelWrapper* model); 36 | 37 | // Address: 0x00429370 38 | void drawTile(u16 tileId, const Vec3f& position); 39 | 40 | // Address: 0x004293D8 41 | void drawTile(u16 tileId, const Vec3f& position, const s32& rotationZ, const Vec3f& scale); 42 | 43 | // Address: 0x00429474 44 | void drawTile(u16 tileId, const Vec3f& position, const Vec3i& rotation, const Vec3f& scale); 45 | 46 | // Address: 0x004292C0 47 | // Draws tile with Layer ID 3 (foreground layer) 48 | void drawTileForeground(u16 tileId, const Vec3f& position, const s32& rotationZ, const Vec3f& scale); 49 | 50 | // Address: 0x004294F8 51 | void drawTile(u16 tileId, const Vec3f& position, const Vec3f& position2, Vec3f** position3, Vec3f** position4); 52 | 53 | inline u32 zPosToLayerId(f32 zPos) 54 | { 55 | if (zPos < 0.0) return 1; 56 | if (zPos >= 2500.0) return 3; 57 | if (zPos >= 500.0) return 2; 58 | return 0; 59 | } 60 | 61 | inline void drawModel(Model* model) 62 | { 63 | drawModel(model->getGfxWrapper()); 64 | } 65 | 66 | inline const sead::BoundBox2f& viewRect() const 67 | { 68 | return mViewRect; 69 | } 70 | 71 | inline const sead::OrthoProjection& projection() const 72 | { 73 | return mProjection; 74 | } 75 | 76 | inline const sead::OrthoCamera& camera() const 77 | { 78 | return mCamera; 79 | } 80 | 81 | private: 82 | sead::BoundBox2f mViewRect; // 0x10 83 | sead::OrthoProjection mProjection; // 0x20 84 | sead::OrthoCamera mCamera; // 0xCC 85 | OrthoCamWrapper _124; // 0x124 86 | OrthoCamWrapper _320; // 0x320 87 | nn::ulcd::CTR::StereoCamera mStereoCam; // 0x33C 88 | f32 mParallax; // 0x39C 89 | }; 90 | 91 | size_assert(Renderer, 0x3A0); -------------------------------------------------------------------------------- /include/gfx/Texture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead.h" 4 | #include "gfx/GL.h" 5 | #include "nw/gfx/res/ResTexture.h" 6 | 7 | 8 | class TextureBase 9 | { 10 | TextureBase(); 11 | virtual ~TextureBase(); 12 | 13 | virtual void vf8(); // nulled 14 | virtual u32 getWidth() = 0; 15 | virtual u32 getHeight() = 0; 16 | virtual void* getPhysicalAddr() = 0; 17 | virtual u32 getFormat() = 0; 18 | virtual void vf1C() = 0; 19 | }; 20 | 21 | class CtpkTexture : public TextureBase 22 | { 23 | public: 24 | CtpkTexture(); 25 | ~CtpkTexture(); 26 | 27 | u32 getWidth() override; 28 | u32 getHeight() override; 29 | void* getPhysicalAddr() override; 30 | u32 getFormat() override; 31 | void vf1C() override; // nulled 32 | 33 | void loadFromCtpk(void* ctpkData, const sead::SafeString& identifier, u32 gpuRegion = 0); 34 | 35 | void loadFromRes(nw::gfx::res::ResTexture* resTexture); 36 | 37 | // Address: 0x0045C328 38 | void loadFromArchive(const sead::SafeString& path, s32 textureId, u32 gpuRegion, sead::Heap* heap); 39 | 40 | inline void cleanup() { 41 | glDeleteTextures(1, &textureGl); 42 | } 43 | 44 | u32 width; // 4 45 | u32 height; // 8 46 | u32 format; // C 47 | u32 type; // 10 48 | u32 textureGl; // 14 49 | u32 mipLevel; // 18 50 | }; 51 | -------------------------------------------------------------------------------- /include/mapobj/DoorBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "actors/Enemy.h" 4 | #include "gfx/AnimModel.h" 5 | 6 | // Size: 0x1088 7 | // Vtable: 0x005CAC9C 8 | class DoorBase : public Enemy 9 | { 10 | 11 | SEAD_RTTI_OVERRIDE(DoorBase, Enemy); 12 | 13 | public: 14 | 15 | DoorBase(); 16 | 17 | s32 onCreate() override; 18 | s32 onDelete() override; 19 | s32 onExecute() override; 20 | s32 onDraw() override; 21 | 22 | DECLARE_STATE_VIRTUAL_ID_BASE(DoorBase, Open); // 23 | DECLARE_STATE_VIRTUAL_ID_BASE(DoorBase, Close); // 24 | DECLARE_STATE_VIRTUAL_ID_BASE(DoorBase, Idle); // 25 | DECLARE_STATE_VIRTUAL_ID_BASE(DoorBase, Vanish); // Used by fake door 26 | 27 | virtual bool isOpenable(); // 28 | virtual bool isFakeDoor(); // 29 | virtual void vf20C(); // Deleted 30 | virtual void vf210(); // Deleted 31 | virtual void createModels(); // 32 | virtual void setupCollisionCheck(); // 33 | virtual void vf21C(); // Called in onCreate, used by ghost house door 34 | virtual void vf220(); // Called in executeState_Idle, used by ghost house door 35 | virtual void setAnimOpen(); // 36 | virtual void playSoundOpen(); // 37 | virtual void setAnimClose(); // 38 | virtual void playSoundClose(); // 39 | virtual void playSoundMove(); // 40 | virtual void setAnimIdle(); // Sets the current anim to the idle anim 41 | 42 | // Address: 0x0040B628 43 | static bool collisionCallback(ActorCollisionCheck* thisCheck, ActorCollisionCheck* otherCheck); 44 | 45 | // Address: 0x0040B834 46 | void spawnAppearEffect(); 47 | 48 | // Address: 0x0040B888 49 | bool isEventActive(); 50 | 51 | // Address: 0x0040BD08 52 | void updateModelMatrix(); 53 | 54 | // Address: 0x0040BE50 55 | void setupModelMatrix(); 56 | 57 | protected: 58 | AnimModelBase* mModel; // 59 | Resource* mResource; // 60 | HeapAllocator mAllocator; // 61 | s32 _1070; // 62 | s32 _1074; // 63 | s32 _1078; // 64 | bool _107C; // Set to True in ctor for Toride Castle and Koopa doors 65 | u8 _107D[3]; // Probably padding 66 | s32 _1080; // 67 | bool mIsVisible; // 68 | u8 _1085[3]; // Probably padding 69 | }; 70 | 71 | size_assert(DoorBase, 0x1088); -------------------------------------------------------------------------------- /include/mapobj/LiftRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sys/ResourceMgr.h" 4 | #include "gfx/AnimModel.h" 5 | 6 | class LiftRenderer // size: 0x7C 7 | { 8 | public: 9 | enum Type : u32 10 | { 11 | TYPE_HAN_WOOD = 0, 12 | TYPE_HAN_STONE = 1, 13 | TYPE_KINOKO_YOKO = 2, 14 | TYPE_HAN_WOOD_GHOST = 3, 15 | TYPE_HAN_WOOD_TOTEM = 4, 16 | TYPE_BOSS_KOOPA = 5, 17 | TYPE_KINOKO_SHISO = 6, 18 | }; 19 | 20 | LiftRenderer() 21 | : rotation({ 0, 0, 0 }), centerBlockWidth(0.0f), 22 | scale(1.0f), _68(0.0f), blockWidth(0), type(0) { } 23 | 24 | void init(); 25 | void cleanup(); 26 | void execute(const Vec3f& position, f32 unk); 27 | void draw(); 28 | 29 | Resource* resource; // 0 30 | Model* models[3]; // 4 31 | HeapAllocator allocator; // 10 32 | Vec3f _18; 33 | Vec3f _24; 34 | Vec3f _30; 35 | u8 _unk3C[0x54-0x3C]; 36 | Vec3i rotation; // 54 37 | f32 centerBlockWidth; // 60 38 | f32 scale; 39 | f32 _68; 40 | u32 blockWidth; // 6C 41 | u32 type; // 70 42 | u32 _74; 43 | u32 _78; 44 | 45 | static const char* LiftResources[]; 46 | static const char* LiftSegments[]; 47 | }; 48 | -------------------------------------------------------------------------------- /include/math/Calc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead/seadMathCalcCommon.h" 4 | 5 | using sead::Mathi; 6 | using sead::Mathu; 7 | using sead::Mathf; 8 | -------------------------------------------------------------------------------- /include/math/Interpolation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "math/Vec.h" 4 | 5 | f32 smoothStepTowards(f32& value, f32 target, f32 scaleFactor, f32 maxStep, f32 minStep); 6 | 7 | // Convenience methods 8 | 9 | bool directedSmoothRotation(s32& rotation, const s32& destination, const s32& amount); 10 | bool directedSmoothRotation(Vec2i& rotation, const Vec2i& destination, const Vec2i& amount); 11 | bool directedSmoothRotation(Vec3i& rotation, const Vec3i& destination, const Vec3i& amount); 12 | 13 | bool moveValueTowardsTarget(s32& value, const s32& target, s32 speed); 14 | bool moveValueTowardsTarget(f32& value, const f32& target, f32 speed); 15 | bool moveValueTowardsTarget(Vec2f& value, const Vec2f& target, const Vec2f& speed); 16 | bool moveValueTowardsTarget(Vec3f& value, const Vec3f& target, const Vec3f& speed); 17 | -------------------------------------------------------------------------------- /include/math/Mtx33.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | #include "nn/math/Matrix33.h" 6 | 7 | class Mtx33 8 | { 9 | public: 10 | union 11 | { 12 | f32 rows[3][3]; 13 | f32 cells[3*3]; 14 | }; 15 | 16 | static Mtx33* copy(Mtx33& out, const Mtx33& in); 17 | static void makeRzxyIdx(Mtx33& out, u32 rotationX, u32 rotationY, u32 rotationZ); 18 | static void makeR(Mtx33& out, Vec3f rotation); 19 | 20 | inline operator nn::math::MTX33() const 21 | { 22 | nn::math::MTX33 result; 23 | 24 | result.f._00 = this->rows[0][0]; 25 | result.f._01 = this->rows[0][1]; 26 | result.f._02 = this->rows[0][2]; 27 | 28 | result.f._10 = this->rows[1][0]; 29 | result.f._11 = this->rows[1][1]; 30 | result.f._12 = this->rows[1][2]; 31 | 32 | result.f._20 = this->rows[2][0]; 33 | result.f._21 = this->rows[2][1]; 34 | result.f._22 = this->rows[2][2]; 35 | 36 | return result; 37 | } 38 | 39 | inline operator const nn::math::MTX33*() const 40 | { 41 | return reinterpret_cast(this); 42 | } 43 | }; 44 | -------------------------------------------------------------------------------- /include/math/Mtx34.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sys/Common.h" 4 | #include "math/Vec.h" 5 | 6 | #include "nn/math/Matrix34.h" 7 | 8 | class Mtx34 9 | { 10 | public: 11 | union 12 | { 13 | f32 rows[3][4]; 14 | f32 cells[12]; 15 | }; 16 | 17 | void setRotationAndTranslation(const Vec3i& rotation, const Vec3f& translate); // 004620D8 18 | 19 | inline void setTranslation(f32 x, f32 y, f32 z) 20 | { 21 | cells[3] = x; 22 | cells[7] = y; 23 | cells[11] = z; 24 | } 25 | 26 | inline void translateX(f32 x) { cells[3] += x; } 27 | inline void translateY(f32 y) { cells[7] += y; } 28 | inline void translateZ(f32 z) { cells[11] += z; } 29 | 30 | inline void translate(f32 x, f32 y, f32 z) 31 | { 32 | translateX(x); 33 | translateY(y); 34 | translateZ(z); 35 | } 36 | 37 | inline void identity() 38 | { 39 | cells[0] = 1.0f; 40 | cells[1] = 0.0f; 41 | cells[2] = 0.0f; 42 | cells[3] = 0.0f; 43 | 44 | cells[4] = 0.0f; 45 | cells[5] = 1.0f; 46 | cells[6] = 0.0f; 47 | cells[7] = 0.0f; 48 | 49 | cells[8] = 0.0f; 50 | cells[9] = 0.0f; 51 | cells[10] = 1.0f; 52 | cells[11] = 0.0f; 53 | } 54 | 55 | void rotateX(const u32& rot); // 0040A610 56 | void rotateY(const u32& rot); // 0040A6A0 57 | void rotateZ(const u32& rot); // 0040A730 58 | 59 | inline void rotate(u32 x, u32 y, u32 z) 60 | { 61 | rotateX(x); 62 | rotateY(y); 63 | rotateZ(z); 64 | } 65 | 66 | inline void rotate(f32 x, f32 y, f32 z) 67 | { 68 | rotateX(Mathf::rad2idx(x)); 69 | rotateY(Mathf::rad2idx(y)); 70 | rotateZ(Mathf::rad2idx(z)); 71 | } 72 | 73 | static Mtx34* copy(Mtx34* out, const Mtx34* in); // 0011D3B8 74 | static void multiply(Mtx34* out, const Mtx34& a, const Mtx34& b); // 0011E4F0 75 | 76 | static const Mtx34 ident; 77 | 78 | inline operator nn::math::MTX34() const 79 | { 80 | nn::math::MTX34 result; 81 | 82 | result.f._00 = this->rows[0][0]; 83 | result.f._01 = this->rows[0][1]; 84 | result.f._02 = this->rows[0][2]; 85 | result.f._03 = this->rows[0][3]; 86 | 87 | result.f._10 = this->rows[1][0]; 88 | result.f._11 = this->rows[1][1]; 89 | result.f._12 = this->rows[1][2]; 90 | result.f._13 = this->rows[1][3]; 91 | 92 | result.f._20 = this->rows[2][0]; 93 | result.f._21 = this->rows[2][1]; 94 | result.f._22 = this->rows[2][2]; 95 | result.f._23 = this->rows[2][3]; 96 | 97 | return result; 98 | } 99 | }; 100 | -------------------------------------------------------------------------------- /include/math/Mtx44.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "math/Mtx34.h" 4 | #include "types.h" 5 | 6 | #include "nn/math/Matrix44.h" 7 | 8 | class Mtx44 9 | { 10 | public: 11 | union 12 | { 13 | f32 rows[4][4]; 14 | f32 cells[4*4]; 15 | }; 16 | 17 | inline void ortho(f32 left, f32 right, f32 bottom, f32 top, f32 near, f32 far, bool isLeftHanded) 18 | { 19 | rows[0][0] = 2.0f / (right - left); 20 | rows[0][3] = (left + right) / (left - right); 21 | rows[1][1] = 2.0f / (top - bottom); 22 | rows[1][3] = (bottom + top) / (bottom - top); 23 | if (isLeftHanded) 24 | rows[2][2] = 1.0f / (far - near); 25 | else 26 | rows[2][2] = 1.0f / (near - far); 27 | rows[2][3] = 0.5f*(near + far) / (near - far) - 0.5f; 28 | rows[3][3] = 1.0f; 29 | } 30 | 31 | void swapXY(); 32 | static void multiply(Mtx44& dst, const Mtx34& a, const Mtx44& b); 33 | 34 | // Rotates the matrix as the 3ds physical screens actually are rotated 90° 35 | inline void device() 36 | { 37 | rows[0][0] = -rows[0][0]; 38 | rows[0][1] = -rows[0][1]; 39 | rows[0][2] = -rows[0][2]; 40 | rows[0][3] = -rows[0][3]; 41 | swapXY(); 42 | } 43 | 44 | inline operator nn::math::MTX44() const 45 | { 46 | nn::math::MTX44 result; 47 | 48 | result.f._00 = this->rows[0][0]; 49 | result.f._01 = this->rows[0][1]; 50 | result.f._02 = this->rows[0][2]; 51 | result.f._03 = this->rows[0][3]; 52 | 53 | result.f._10 = this->rows[1][0]; 54 | result.f._11 = this->rows[1][1]; 55 | result.f._12 = this->rows[1][2]; 56 | result.f._13 = this->rows[1][3]; 57 | 58 | result.f._20 = this->rows[2][0]; 59 | result.f._21 = this->rows[2][1]; 60 | result.f._22 = this->rows[2][2]; 61 | result.f._23 = this->rows[2][3]; 62 | 63 | result.f._30 = this->rows[3][0]; 64 | result.f._31 = this->rows[3][1]; 65 | result.f._32 = this->rows[3][2]; 66 | result.f._33 = this->rows[3][3]; 67 | 68 | return result; 69 | } 70 | 71 | inline operator const nn::math::MTX44*() const 72 | { 73 | return reinterpret_cast(this); 74 | } 75 | 76 | }; 77 | -------------------------------------------------------------------------------- /include/math/RNG.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | class RNG 6 | { 7 | public: 8 | static RNG* instance; 9 | 10 | f32 randF32(); 11 | f32 randF32(f32 max); 12 | f32 randF32(f32 min, f32 max); 13 | u32 randU32(); 14 | u32 randU32(u32 max); 15 | u32 randS32(s32 min, s32 max); 16 | bool randBool(); 17 | }; 18 | 19 | // Convenience 20 | inline f32 randF32() { return RNG::instance->randF32(); } 21 | inline f32 randF32(f32 max) { return RNG::instance->randF32(max); } 22 | inline f32 randF32(f32 min, f32 max) { return RNG::instance->randF32(min, max); } 23 | inline u32 randU32() { return RNG::instance->randU32(); } 24 | inline u32 randU32(u32 max) { return RNG::instance->randU32(max); } 25 | inline s32 randS32(s32 min, s32 max) { return RNG::instance->randS32(min, max); } 26 | inline bool randBool() { return RNG::instance->randBool(); } 27 | -------------------------------------------------------------------------------- /include/math/Rect.h: -------------------------------------------------------------------------------- 1 | // TODO: Remove this entirely 2 | 3 | #pragma once 4 | 5 | #include "Vec.h" 6 | 7 | struct RectU16 8 | { 9 | u16 x1; 10 | u16 y1; 11 | u16 x2; 12 | u16 y2; 13 | 14 | Vec2u& v(int idx) { return *reinterpret_cast(&x1 + 2*idx); } 15 | Vec2u& v1() { return v(0); } 16 | Vec2u& v2() { return v(1); } 17 | }; 18 | -------------------------------------------------------------------------------- /include/math/Vec.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | #include "sead/seadVector.h" 6 | 7 | using Vec2f = sead::Vector2; 8 | using Vec2d = sead::Vector2; 9 | using Vec2u = sead::Vector2; 10 | using Vec2i = sead::Vector2; 11 | 12 | using Vec3f = sead::Vector3; 13 | using Vec3d = sead::Vector3; 14 | using Vec3u = sead::Vector3; 15 | using Vec3i = sead::Vector3; 16 | 17 | using Vec4f = sead::Vector4; 18 | using Vec4d = sead::Vector4; 19 | using Vec4u = sead::Vector4; 20 | using Vec4i = sead::Vector4; 21 | 22 | inline f32 calcAngleCos(const Vec2f& a, const Vec2f& b) 23 | { 24 | return a.dot(b) / (a.length() * b.length()); 25 | } 26 | 27 | inline f32 calcAngle(const Vec2f& a, const Vec2f& b) 28 | { 29 | return acosf(calcAngleCos(a, b)); 30 | } -------------------------------------------------------------------------------- /include/nn/handle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | 6 | namespace nn { 7 | 8 | struct Handle 9 | { 10 | Handle() : handle(0) {} 11 | 12 | u32 handle; 13 | }; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /include/nn/hid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | namespace nn { namespace hid { 6 | 7 | enum Button 8 | { 9 | BUTTON_A = 0x00000001, 10 | BUTTON_B = 0x00000002, 11 | PSEUDO_BUTTON_SELECT = 0x00000004, 12 | BUTTON_SELECT_FOR_DEBUGGING = 0x00000004, 13 | BUTTON_START = 0x00000008, 14 | BUTTON_RIGHT = 0x00000010, 15 | BUTTON_LEFT = 0x00000020, 16 | BUTTON_UP = 0x00000040, 17 | BUTTON_DOWN = 0x00000080, 18 | BUTTON_R = 0x00000100, 19 | BUTTON_L = 0x00000200, 20 | BUTTON_X = 0x00000400, 21 | BUTTON_Y = 0x00000800, 22 | BUTTON_DEBUG = 0x00001000, 23 | BUTTON_RESERVED = 0x00002000, 24 | BUTTON_EMULATION_RIGHT = 0x10000000, 25 | BUTTON_EMULATION_LEFT = 0x20000000, 26 | BUTTON_EMULATION_UP = 0x40000000, 27 | BUTTON_EMULATION_DOWN = 0x80000000, 28 | 29 | BUTTON_MASK = BUTTON_A | BUTTON_B | BUTTON_START | BUTTON_R | BUTTON_L | BUTTON_X | BUTTON_Y | BUTTON_DEBUG, 30 | PLUS_BUTTON_MASK = BUTTON_RIGHT | BUTTON_LEFT | BUTTON_UP | BUTTON_DOWN, 31 | PLUS_BUTTON_EMULATION_MASK = BUTTON_EMULATION_RIGHT | BUTTON_EMULATION_LEFT | BUTTON_EMULATION_UP | BUTTON_EMULATION_DOWN, 32 | ALL_MASK = BUTTON_MASK | PLUS_BUTTON_MASK | PLUS_BUTTON_EMULATION_MASK, 33 | 34 | BUTTON_ZL = 0x00004000, 35 | BUTTON_ZR = 0x00008000, 36 | 37 | BUTTON_EMULATION_R_RIGHT = 0x01000000, 38 | BUTTON_EMULATION_R_LEFT = 0x02000000, 39 | BUTTON_EMULATION_R_UP = 0x04000000, 40 | BUTTON_EMULATION_R_DOWN = 0x08000000, 41 | 42 | PLUS_BUTTON_EMULATION_R_MASK = BUTTON_EMULATION_R_RIGHT | BUTTON_EMULATION_R_LEFT | BUTTON_EMULATION_R_UP | BUTTON_EMULATION_R_DOWN, 43 | }; 44 | 45 | struct StickStatus 46 | { 47 | s16 x; 48 | s16 y; 49 | }; 50 | 51 | struct PadStatus 52 | { 53 | u32 pressed; 54 | u32 down; 55 | u32 up; 56 | StickStatus stick; 57 | }; 58 | 59 | struct Pad; 60 | Pad& getPad(); 61 | 62 | class PadReader // Size: 0x40 63 | { 64 | public: 65 | PadReader(Pad& pad = getPad()); 66 | 67 | void Read(PadStatus* statusBuffer, s32* readLen, s32 bufferLen); 68 | bool ReadLatest(PadStatus* status); 69 | 70 | private: 71 | u8 _unk[0x40]; 72 | }; 73 | 74 | } } 75 | -------------------------------------------------------------------------------- /include/nn/math/Matrix22.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nn/math/Vector2.h" 4 | 5 | namespace nn { 6 | namespace math { 7 | 8 | struct MTX22_ 9 | { 10 | struct BaseData 11 | { 12 | f32 _00, _01; 13 | f32 _10, _11; 14 | }; 15 | 16 | union 17 | { 18 | BaseData f; 19 | f32 m[2][2]; 20 | f32 a[4]; 21 | VEC2_ v[2]; 22 | }; 23 | }; 24 | 25 | struct MTX22 : public MTX22_ 26 | { 27 | 28 | }; 29 | 30 | typedef MTX22 Matrix22; 31 | 32 | } // namespace math 33 | } // namespace nn 34 | -------------------------------------------------------------------------------- /include/nn/math/Matrix23.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nn/math/Vector3.h" 4 | 5 | namespace nn { 6 | namespace math { 7 | 8 | struct MTX23_ 9 | { 10 | struct BaseData 11 | { 12 | f32 _00, _01, _02; 13 | f32 _10, _11, _12; 14 | }; 15 | 16 | union 17 | { 18 | BaseData f; 19 | f32 m[2][3]; 20 | f32 a[6]; 21 | VEC3_ v[2]; 22 | }; 23 | }; 24 | 25 | struct MTX23 : public MTX23_ 26 | { 27 | 28 | }; 29 | 30 | typedef MTX23 Matrix23; 31 | 32 | } // namespace math 33 | } // namespace nn 34 | -------------------------------------------------------------------------------- /include/nn/math/Matrix33.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nn/math/Vector3.h" 4 | 5 | namespace nn { 6 | namespace math { 7 | 8 | struct MTX33_ 9 | { 10 | struct BaseData 11 | { 12 | f32 _00, _01, _02; 13 | f32 _10, _11, _12; 14 | f32 _20, _21, _22; 15 | }; 16 | 17 | union 18 | { 19 | BaseData f; 20 | f32 m[3][3]; 21 | f32 a[9]; 22 | VEC3_ v[3]; 23 | }; 24 | }; 25 | 26 | struct MTX33 : public MTX33_ 27 | { 28 | 29 | }; 30 | 31 | typedef MTX33 Matrix33; 32 | 33 | } // namespace math 34 | } // namespace nn 35 | -------------------------------------------------------------------------------- /include/nn/math/Matrix34.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nn/math/Vector4.h" 4 | 5 | namespace nn { 6 | namespace math { 7 | 8 | struct MTX34_ 9 | { 10 | struct BaseData 11 | { 12 | f32 _00, _01, _02, _03; 13 | f32 _10, _11, _12, _13; 14 | f32 _20, _21, _22, _23; 15 | }; 16 | 17 | union 18 | { 19 | BaseData f; 20 | f32 m[3][4]; 21 | f32 a[12]; 22 | VEC4_ v[3]; 23 | }; 24 | }; 25 | 26 | struct MTX34 : public MTX34_ 27 | { 28 | 29 | }; 30 | 31 | typedef MTX34 Matrix34; 32 | 33 | } // namespace math 34 | } // namespace nn 35 | -------------------------------------------------------------------------------- /include/nn/math/Matrix44.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nn/math/Vector4.h" 4 | 5 | namespace nn { 6 | namespace math { 7 | 8 | enum PivotDirection 9 | { 10 | PIVOT_NONE, 11 | PIVOT_UPSIDE_TO_TOP, 12 | PIVOT_UPSIDE_TO_RIGHT, 13 | PIVOT_UPSIDE_TO_BOTTOM, 14 | PIVOT_UPSIDE_TO_LEFT, 15 | PIVOT_NUM 16 | }; 17 | 18 | struct MTX44_ 19 | { 20 | struct BaseData 21 | { 22 | f32 _00, _01, _02, _03; 23 | f32 _10, _11, _12, _13; 24 | f32 _20, _21, _22, _23; 25 | f32 _30, _31, _32, _33; 26 | }; 27 | 28 | union 29 | { 30 | BaseData f; 31 | f32 m[4][4]; 32 | f32 a[16]; 33 | VEC4_ v[4]; 34 | }; 35 | }; 36 | 37 | struct MTX44 : public MTX44_ 38 | { 39 | 40 | }; 41 | 42 | typedef MTX44 Matrix44; 43 | 44 | } // namespace math 45 | } // namespace nn 46 | -------------------------------------------------------------------------------- /include/nn/math/Types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nn/math/Vector2.h" 4 | #include "nn/math/Vector3.h" 5 | #include "nn/math/Vector4.h" 6 | 7 | #include "nn/math/Matrix22.h" 8 | #include "nn/math/Matrix23.h" 9 | #include "nn/math/Matrix33.h" 10 | #include "nn/math/Matrix34.h" 11 | #include "nn/math/Matrix44.h" -------------------------------------------------------------------------------- /include/nn/math/Vector2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | namespace nn { 6 | namespace math { 7 | 8 | struct VEC2_ 9 | { 10 | f32 x; 11 | f32 y; 12 | }; 13 | 14 | struct VEC2 : public VEC2_ 15 | { 16 | 17 | }; 18 | 19 | typedef VEC2 Vector2; 20 | 21 | 22 | } // namespace math 23 | } // namespace nn 24 | -------------------------------------------------------------------------------- /include/nn/math/Vector3.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | namespace nn { 6 | namespace math { 7 | 8 | struct VEC3_ 9 | { 10 | f32 x; 11 | f32 y; 12 | f32 z; 13 | }; 14 | 15 | struct VEC3 : public VEC3_ 16 | { 17 | 18 | }; 19 | 20 | typedef VEC3 Vector3; 21 | 22 | } // namespace math 23 | } // namespace nn 24 | -------------------------------------------------------------------------------- /include/nn/math/Vector4.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | namespace nn { 6 | namespace math { 7 | 8 | struct VEC4_ 9 | { 10 | f32 x; 11 | f32 y; 12 | f32 z; 13 | f32 w; 14 | }; 15 | 16 | struct VEC4 : public VEC4_ 17 | { 18 | 19 | }; 20 | 21 | typedef VEC4 Vector4; 22 | 23 | 24 | } // namespace math 25 | } // namespace nn 26 | -------------------------------------------------------------------------------- /include/nn/result.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | 6 | namespace nn { 7 | 8 | struct Result 9 | { 10 | Result(u32 code = 0) : code(code) {} 11 | 12 | u32 code; 13 | 14 | bool isFailure() { return (code & 0x80000000) != 0; } 15 | bool isSuccess() { return !isFailure(); } 16 | }; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /include/nw/anim/AnimResult.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/types.h" 4 | 5 | namespace nw { 6 | namespace anim { 7 | 8 | 9 | class AnimResult 10 | { 11 | public: 12 | AnimResult() : 13 | m_Flags(0) {} 14 | 15 | virtual ~AnimResult() {} 16 | 17 | private: 18 | bit32 m_Flags; 19 | f32 m_ValueBuf[16]; 20 | }; 21 | 22 | } // namespace anim 23 | } // namespace nw -------------------------------------------------------------------------------- /include/nw/anim/res/ResAnim.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/gfx/res/ResSceneObject.h" 4 | 5 | #include "nw/ut/BinaryFileFormat.h" 6 | #include "nw/ut/ResDictionary.h" 7 | #include "nw/ut/ResMetaData.h" 8 | #include "nw/ut/ResTypes.h" 9 | #include "nw/ut/ResUtil.h" 10 | 11 | namespace nw { 12 | namespace anim { 13 | namespace res { 14 | 15 | struct ResAnimData 16 | { 17 | enum LoopMode 18 | { 19 | LOOP_MODE_ONETIME, 20 | LOOP_MODE_LOOP 21 | }; 22 | 23 | ut::BinaryRevisionHeader m_Header; 24 | ut::BinString toName; 25 | ut::BinString toTargetAnimGroupName; 26 | u8 m_LoopMode; 27 | u8 padding_[3]; 28 | f32 m_FrameSize; 29 | s32 m_MemberAnimSetDicCount; 30 | ut::Offset toMemberAnimSetDic; 31 | s32 m_UserDataDicCount; 32 | ut::Offset toUserDataDic; 33 | }; 34 | 35 | class ResAnim : public ut::ResCommon 36 | { 37 | public: 38 | explicit ResAnim(const void* p = nullptr) : 39 | nw::ut::ResCommon(p) {} 40 | 41 | ResAnimData& ref() { return *ptr(); } 42 | const ResAnimData& ref() const { return *ptr(); } 43 | 44 | nw::ut::BinaryRevisionHeader& GetHeader() { return ref().m_Header; } 45 | const nw::ut::BinaryRevisionHeader& GetHeader() const { return ref().m_Header; } 46 | 47 | u32 GetRevision() const { return this->GetHeader().revision; } 48 | 49 | const char* GetName() const { return ref().toName.to_ptr(); } 50 | 51 | const char* GetTargetAnimGroupName() const { return ref().toTargetAnimGroupName.to_ptr(); } 52 | 53 | u8 GetLoopMode() const { return static_cast(ref().m_LoopMode); } 54 | void SetLoopMode(u8 value) { ref().m_LoopMode = value; } 55 | 56 | f32 GetFrameSize() const { return static_cast(ref().m_FrameSize); } 57 | void SetFrameSize(f32 value) { ref().m_FrameSize = value; } 58 | 59 | s32 GetMemberAnimSetCount() const { return ref().m_MemberAnimSetDicCount; } 60 | // TODO: GetMemberAnimSet() 61 | 62 | s32 GetUserDataCount() const { return ref().m_UserDataDicCount; } 63 | 64 | nw::ut::ResMetaData GetUserData(int idx) 65 | { 66 | ut::ResDicPatricia dic = ut::ResDicPatricia(ref().toUserDataDic.to_ptr()); 67 | return nw::ut::ResMetaData(dic[idx]); 68 | } 69 | 70 | nw::ut::ResMetaData GetUserData(const char* key) 71 | { 72 | ut::ResDicPatricia dic = ut::ResDicPatricia(ref().toUserDataDic.to_ptr()); 73 | return nw::ut::ResMetaData(dic[key]); 74 | } 75 | 76 | s32 GetUserDataIndex(const char* key) const 77 | { 78 | ut::ResDicPatricia dic = ut::ResDicPatricia(ref().toUserDataDic.to_ptr()); 79 | return dic.GetIndex(key); 80 | } 81 | 82 | }; 83 | 84 | } // namespace res 85 | } // namespace anim 86 | } // namespace nw 87 | -------------------------------------------------------------------------------- /include/nw/anim/res/ResAnimGroup.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/ut/ResArray.h" 4 | #include "nw/ut/ResDictionary.h" 5 | #include "nw/ut/ResTypes.h" 6 | #include "nw/ut/ResUtil.h" 7 | 8 | namespace nw { 9 | 10 | namespace gfx { class SceneNode; } 11 | 12 | namespace anim { 13 | 14 | class AnimBlendOp; 15 | 16 | namespace res { 17 | 18 | struct ResAnimGroupData 19 | { 20 | nw::ut::ResTypeInfo typeInfo; 21 | u32 m_Flags; 22 | ut::BinString toName; 23 | s32 m_TargetType; 24 | s32 m_MemberInfoSetDicCount; 25 | ut::Offset toMemberInfoSetDic; 26 | s32 m_BlendOperationsTableCount; 27 | ut::Offset toBlendOperationsTable; 28 | }; 29 | 30 | class ResAnimGroup : public ut::ResCommon 31 | { 32 | public: 33 | typedef ResAnimGroup SelfType; 34 | typedef ResAnimGroupData ResDataType; 35 | 36 | explicit ResAnimGroup(const void* p = nullptr) : 37 | nw::ut::ResCommon(p) {} 38 | 39 | ResAnimGroupData& ref() { return *ptr(); } 40 | const ResAnimGroupData& ref() const { return *ptr(); } 41 | 42 | u32 GetFlags() const { return static_cast(ref().m_Flags); } 43 | void SetFlags(u32 value) { ref().m_Flags = value; } 44 | 45 | const char* GetName() const { return ref().toName.to_ptr(); } 46 | 47 | s32 GetTargetType() const { return static_cast(ref().m_TargetType); } 48 | void SetTargetType(s32 value) { ref().m_TargetType = value; } 49 | 50 | s32 GetMemberInfoSetCount() const { return ref().m_MemberInfoSetDicCount; } 51 | 52 | s32 GetBlendOperationsCount() const { return ref().m_BlendOperationsTableCount; } 53 | s32 GetBlendOperations(int idx) const 54 | { 55 | const s32* tablePtr = static_cast(ref().toBlendOperationsTable.to_table_ptr()); 56 | return tablePtr[idx]; 57 | } 58 | 59 | void SetBlendOperations(int idx, s32 value) 60 | { 61 | s32* tablePtr = GetBlendOperations(); 62 | tablePtr[idx] = value; 63 | } 64 | 65 | s32* GetBlendOperations() { return static_cast(ref().toBlendOperationsTable.to_table_ptr()); } 66 | const s32* GetBlendOperations() const { return static_cast(ref().toBlendOperationsTable.to_table_ptr()); } 67 | }; 68 | 69 | } // namespace res 70 | } // namespace anim 71 | } // namespace nw -------------------------------------------------------------------------------- /include/nw/gfx/AnimBinding.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/gfx/AnimGroup.h" 4 | #include "nw/gfx/AnimObject.h" 5 | #include "nw/gfx/GfxObject.h" 6 | 7 | #include "nw/ut/MoveArray.h" 8 | 9 | namespace nw { 10 | namespace gfx { 11 | 12 | class AnimBinding : public GfxObject 13 | { 14 | public: 15 | typedef ut::MoveArray AnimGroupArray; 16 | typedef ut::MoveArray AnimObjectArray; 17 | 18 | // TODO: functions 19 | 20 | protected: 21 | AnimBinding(os::IAllocator* allocator, int maxAnimObjects) : 22 | GfxObject(allocator), m_AnimObjectCountPerGroup(maxAnimObjects) {} 23 | 24 | 25 | // 0x00167DD8 26 | virtual ~AnimBinding() noexcept; 27 | 28 | private: 29 | AnimGroupArray m_AnimGroups; 30 | AnimObjectArray m_AnimObjects; 31 | const int m_AnimObjectCountPerGroup; 32 | }; 33 | 34 | } // namespace gfx 35 | } // namespace nw -------------------------------------------------------------------------------- /include/nw/gfx/AnimObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/anim/AnimResult.h" 4 | 5 | #include "nw/gfx/AnimGroup.h" 6 | #include "nw/gfx/Common.h" 7 | #include "nw/gfx/GfxObject.h" 8 | 9 | #include "nw/ut/MoveArray.h" 10 | #include "nw/ut/RuntimeTypeInfo.h" 11 | 12 | namespace nw { namespace gfx { 13 | 14 | class AnimObject : public GfxObject 15 | { 16 | public: 17 | // Deleted 18 | virtual const nw::ut::internal::RuntimeTypeInfo* GetRuntimeTypeInfo(); 19 | 20 | // 0x005F32C0 21 | static const nw::ut::internal::RuntimeTypeInfo s_TypeInfo; 22 | 23 | // Inlined 24 | AnimObject(os::IAllocator* allocator, u32 animType) : 25 | GfxObject(allocator), m_AnimGroup(nullptr), m_AnimType(animType) {} 26 | 27 | // Deleted 28 | virtual ~AnimObject() noexcept; 29 | 30 | // Deleted 31 | virtual Result TryBind(AnimGroup* animGroup) = 0; 32 | 33 | // Deleted 34 | virtual void Release() = 0; 35 | 36 | // Deleted 37 | virtual void UpdateFrame() = 0; 38 | 39 | // Deleted 40 | virtual const nw::anim::AnimResult* GetResult(void* target, int memberIdx) const = 0; 41 | 42 | // Deleted 43 | virtual bool HasMemberAnim(int memberIdx) const = 0; 44 | 45 | // Deleted 46 | virtual void UpdateCache() = 0; 47 | 48 | bool Bind(AnimGroup* animGroup) { return TryBind(animGroup).IsSuccess(); } 49 | 50 | const AnimGroup* GetAnimGroup() const { return m_AnimGroup; } 51 | AnimGroup* GetAnimGroup() { return m_AnimGroup; } 52 | void SetAnimGroup(AnimGroup* group) { m_AnimGroup = group; } 53 | 54 | enum 55 | { 56 | ANIMTYPE_SIMPLE, 57 | ANIMTYPE_TRANSFORM_SIMPLE, 58 | ANIMTYPE_BLENDER 59 | }; 60 | 61 | u32 GetAnimType() const { return m_AnimType; } 62 | 63 | protected: 64 | AnimGroup* m_AnimGroup; 65 | u32 m_AnimType; 66 | }; 67 | 68 | } // namespace gfx 69 | } // namespace nw -------------------------------------------------------------------------------- /include/nw/gfx/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | namespace nw { namespace gfx { 6 | 7 | class Result 8 | { 9 | public: 10 | Result() : 11 | m_Code(0) {} 12 | 13 | Result(u32 code) : m_Code(code) {} 14 | 15 | Result operator = (u32 code) { m_Code = code; return *this; } 16 | Result operator |= (u32 code) { m_Code |= code; return *this; } 17 | Result operator &= (u32 code) { m_Code &= code; return *this; } 18 | Result operator = (Result result) { m_Code = result.GetCode(); return *this; } 19 | Result operator |= (Result result) { m_Code |= result.GetCode(); return *this; } 20 | Result operator &= (Result result) { m_Code &= result.GetCode(); return *this; } 21 | 22 | u32 GetCode() const { return m_Code; } 23 | 24 | bool IsFailure() const { return (m_Code & 0x80000000) != 0; } 25 | 26 | bool IsSuccess() const { return !IsFailure(); } 27 | 28 | int GetDescription() const { return static_cast( m_Code & 0x0000ffff ); } 29 | 30 | private: 31 | u32 m_Code; 32 | }; 33 | 34 | 35 | } // namespace gfx 36 | } // namespace nw -------------------------------------------------------------------------------- /include/nw/gfx/GfxObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/os/Memory.h" 4 | 5 | #include "nw/ut/MovePtr.h" 6 | 7 | namespace nw { namespace gfx { 8 | 9 | // This entire class got optimized away... 10 | class GfxObject 11 | { 12 | public: 13 | GfxObject(nw::os::IAllocator* allocator) : 14 | m_Allocator(*allocator) {} 15 | 16 | // Inlined 17 | inline void Destroy() 18 | { 19 | this->~GfxObject(); 20 | m_Allocator.Free(this); 21 | } 22 | 23 | inline nw::os::IAllocator& getAllocator() { return m_Allocator; } 24 | 25 | protected: 26 | virtual ~GfxObject() {} 27 | 28 | private: 29 | nw::os::IAllocator& m_Allocator; 30 | }; 31 | 32 | 33 | class GfxDeleter 34 | { 35 | public: 36 | GfxDeleter() : 37 | m_HasOwnership(true) {} 38 | 39 | GfxDeleter(bool hasOwnership) : 40 | m_HasOwnership(hasOwnership) {} 41 | 42 | private: 43 | bool m_HasOwnership; 44 | }; 45 | 46 | 47 | template 48 | class GfxPtr 49 | { 50 | public: 51 | typedef ut::MovePtr GfxMovePtr; 52 | typedef typename GfxMovePtr::element_type element_type; 53 | 54 | GfxPtr() : 55 | m_MovePtr() {} 56 | 57 | GfxPtr(const GfxPtr& pointer) : 58 | m_MovePtr(const_cast(&pointer)->m_MovePtr) {} 59 | 60 | ~GfxPtr() {} 61 | 62 | inline element_type* Get() const { return m_MovePtr.Get(); } 63 | inline element_type* Release() { return m_MovePtr.Release(); } 64 | 65 | inline element_type& operator*() const { return *m_MovePtr; } 66 | inline element_type* operator->() const { return m_MovePtr.operator->(); } 67 | 68 | inline GfxPtr& operator=(GfxPtr rhs) 69 | { 70 | m_MovePtr.operator=(rhs.m_MovePtr); 71 | return *this; 72 | } 73 | 74 | inline void Reset() { m_MovePtr.Reset(); } 75 | 76 | inline void Swap(GfxPtr& pointer) { m_MovePtr.Swap(pointer.m_MovePtr); } 77 | 78 | private: 79 | GfxMovePtr m_MovePtr; 80 | }; 81 | 82 | 83 | } // namespace gfx 84 | } // namespace nw 85 | 86 | 87 | -------------------------------------------------------------------------------- /include/nw/gfx/ISceneVisitor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/gfx/GfxObject.h" 4 | 5 | #include "nw/ut/RuntimeTypeInfo.h" 6 | 7 | namespace nw { namespace gfx { 8 | 9 | class SceneNode; 10 | class TransformNode; 11 | class UserRenderNode; 12 | class Model; 13 | class SkeletalModel; 14 | class Camera; 15 | class Fog; 16 | class Light; 17 | class FragmentLight; 18 | class AmbientLight; 19 | class VertexLight; 20 | class HemiSphereLight; 21 | class ParticleSet; 22 | class ParticleEmitter; 23 | class ParticleModel; 24 | 25 | class ISceneVisitor : public GfxObject 26 | { 27 | private: 28 | ISceneVisitor(const ISceneVisitor&); 29 | void operator=(const ISceneVisitor&); 30 | 31 | public: 32 | virtual const nw::ut::internal::RuntimeTypeInfo* GetRuntimeTypeInfo() const { return &s_TypeInfo; } 33 | 34 | static const nw::ut::internal::RuntimeTypeInfo s_TypeInfo; 35 | 36 | virtual void VisitSceneNode(SceneNode* node) = 0; 37 | 38 | virtual void VisitTransformNode(TransformNode* node) = 0; 39 | 40 | virtual void VisitUserRenderNode(UserRenderNode* node) = 0; 41 | 42 | virtual void VisitModel(Model* model) = 0; 43 | 44 | virtual void VisitSkeletalModel(SkeletalModel* model) = 0; 45 | 46 | virtual void VisitCamera(Camera* camera) = 0; 47 | 48 | virtual void VisitFog(Fog* fog) = 0; 49 | 50 | virtual void VisitLight(Light* light) = 0; 51 | 52 | virtual void VisitFragmentLight(FragmentLight* light) = 0; 53 | 54 | virtual void VisitAmbientLight(AmbientLight* light) = 0; 55 | 56 | virtual void VisitHemiSphereLight(HemiSphereLight* light) = 0; 57 | 58 | virtual void VisitParticleSet(ParticleSet* particleSet) = 0; 59 | 60 | virtual void VisitParticleEmitter(ParticleEmitter* particleEmitter) = 0; 61 | 62 | virtual void VisitParticleModel(ParticleModel* particleModel) = 0; 63 | 64 | protected: 65 | ISceneVisitor(os::IAllocator* allocator) : GfxObject(allocator) {} 66 | }; 67 | 68 | 69 | } // namespace gfx 70 | } // namespace nw 71 | 72 | 73 | -------------------------------------------------------------------------------- /include/nw/gfx/SceneObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/gfx/GfxObject.h" 4 | #include "nw/gfx/res/ResSceneObject.h" 5 | 6 | namespace nw { namespace gfx { 7 | 8 | class SceneObject : public GfxObject 9 | { 10 | 11 | public: 12 | res::ResSceneObject GetResSceneObject() { return m_ResObject; } 13 | const res::ResSceneObject GetResSceneObject() const { return m_ResObject; } 14 | 15 | protected: 16 | SceneObject(os::IAllocator* allocator, res::ResSceneObject resObj) : 17 | GfxObject(allocator), m_ResObject(resObj) {} 18 | 19 | virtual ~SceneObject(); 20 | 21 | private: 22 | res::ResSceneObject m_ResObject; 23 | }; 24 | 25 | } // namespace gfx 26 | } // namespace nw 27 | 28 | 29 | -------------------------------------------------------------------------------- /include/nw/gfx/TransformNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/types.h" 4 | 5 | #include "nw/gfx/CalculatedTransform.h" 6 | #include "nw/gfx/SceneNode.h" 7 | 8 | #include "nw/gfx/res/ResSceneObject.h" 9 | 10 | #include "nw/ut/Children.h" 11 | 12 | namespace nw { 13 | namespace gfx { 14 | 15 | class TransformNode : public SceneNode 16 | { 17 | 18 | public: 19 | 20 | // 0x0048B668 21 | virtual const nw::ut::internal::RuntimeTypeInfo* GetRuntimeTypeInfo(); 22 | 23 | struct Description : public SceneNode::Description 24 | { 25 | Description() {} 26 | }; 27 | 28 | // 0x00173AEC 29 | static TransformNode* Create(SceneNode* parent, res::ResSceneObject resource, const TransformNode::Description& description, os::IAllocator* allocator); 30 | 31 | CalculatedTransform& Transform() { return m_Transform; } 32 | const CalculatedTransform& Transform() const { return m_Transform; } 33 | 34 | math::MTX34& WorldMatrix() { return m_WorldMatrix; } 35 | const math::MTX34& WorldMatrix() const { return m_WorldMatrix; } 36 | 37 | CalculatedTransform& WorldTransform() { return m_CalculatedTransform; } 38 | const CalculatedTransform& WorldTransform() const { return m_CalculatedTransform; } 39 | 40 | // 0x0048B674 41 | const math::MTX34& InverseWorldMatrix(); 42 | 43 | // 0x00173A8C 44 | void InvalidateInverseWorldMatrix(); 45 | 46 | virtual void UpdateDirection() {} 47 | 48 | // 0x001B37AC 49 | virtual void UpdateTransform(WorldMatrixUpdater* worldMatrixUpdater, SceneContext* sceneContext); 50 | 51 | // 0x00173A98 52 | virtual void Accept(ISceneVisitor* visitor); 53 | 54 | // 0x0048B6D4 55 | virtual const math::MTX34& TrackbackWorldMatrix(); 56 | 57 | // 0x0048B6E4 58 | virtual const CalculatedTransform& TrackbackWorldTransform() const { return this->WorldTransform(); } 59 | 60 | // 0x0048B6DC 61 | virtual const CalculatedTransform& TrackbackLocalTransform(); 62 | 63 | inline virtual void InheritTraversalResults(); 64 | 65 | protected: 66 | 67 | // 0x00173CB0 68 | TransformNode(os::IAllocator* allocator, res::ResTransformNode resObj, const TransformNode::Description& description); 69 | 70 | // 0x00174038 71 | virtual ~TransformNode() noexcept; 72 | 73 | // 0x00173764 74 | virtual Result Initialize(os::IAllocator* allocator); 75 | 76 | // 0x001738E8 77 | static void GetMemorySizeForInitialize(os::MemorySizeCalculator* pSize, res::ResTransformNode resTransformNode, Description description); 78 | 79 | private: 80 | // 0x0017379C 81 | Result CreateCallbacks(os::IAllocator* allocator); 82 | 83 | CalculatedTransform m_Transform; 84 | math::MTX34 m_WorldMatrix; 85 | CalculatedTransform m_CalculatedTransform; 86 | 87 | mutable math::MTX34 m_InverseWorldMatrix; 88 | mutable bool m_IsInverseWorldMatrixValid; 89 | 90 | void* m_PostCalculateWorldMatrixSignal; // CalculateMatrixSignal 91 | bool m_IsBranchWorldMatrixCalculationEnabled; 92 | Description m_Description; 93 | }; 94 | 95 | } // namespace gfx 96 | } // namespace nw 97 | 98 | 99 | -------------------------------------------------------------------------------- /include/nw/gfx/res/ResMesh.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/gfx/res/ResSceneObject.h" 4 | #include "nw/ut/ResArrayTypes.h" 5 | 6 | namespace nw { 7 | namespace gfx { 8 | namespace res { 9 | 10 | struct ResMeshNodeVisibilityData 11 | { 12 | nw::ut::BinString toName; 13 | bool m_IsVisible; 14 | }; 15 | 16 | struct ResMeshData : public ResSceneObjectData 17 | { 18 | s32 m_ShapeIndex; 19 | s32 m_MaterialIndex; 20 | nw::ut::Offset toOwnerModel; 21 | bool m_IsVisible; 22 | u8 m_RenderPriority; 23 | s16 m_MeshNodeVisibilityIndex; 24 | s32 m_CurrentPrimitiveIndex; 25 | u32 m_Flags; 26 | u32 m_IrScaleCommand[12]; 27 | void* m_ActivateCommandCache; 28 | s32 m_ActivateCommandCacheSize; 29 | void* m_DeactivateCommandCache; 30 | s32 m_DeactivateCommandCacheSize; 31 | nw::ut::BinString toMeshNodeName; 32 | u64 m_RenderKeyCache; 33 | nw::os::IAllocator* m_CommandAllocator; 34 | }; 35 | 36 | class ResMesh : public ResSceneObject 37 | { 38 | public: 39 | enum Flag 40 | { 41 | FLAG_HAS_VERTEX_ALPHA = 0x1, 42 | FLAG_HAS_BONE_WEIGHT_W = 0x1 << 1, 43 | FLAG_VALID_RENDER_KEY_CACHE = 0x1 << 2, 44 | FLAG_HAS_BEEN_SETUP = 0x1 << 3 45 | }; 46 | 47 | typedef ResMesh SelfType; 48 | typedef ResMeshData ResDataType; 49 | explicit ResMesh(const void* p = 0) : ResSceneObject(p) {} 50 | 51 | ResDataType* ptr() { return reinterpret_cast(void_ptr()); } 52 | const ResDataType* ptr() const { return reinterpret_cast(void_ptr()); } 53 | 54 | ResDataType& ref() { return *reinterpret_cast(void_ptr()); } 55 | const ResDataType& ref() const { return *reinterpret_cast(void_ptr()); } 56 | 57 | bool operator==(const ResMesh& rhs) const { return ptr() == rhs.ptr(); } 58 | bool operator!=(const ResMesh& rhs) const { return ptr() != rhs.ptr(); } 59 | }; 60 | 61 | typedef nw::ut::ResArrayClass::type ResMeshArray; 62 | 63 | } // namespace res 64 | } // namespace gfx 65 | } // namespace nw 66 | 67 | 68 | -------------------------------------------------------------------------------- /include/nw/gfx/res/ResShader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/gfx/GfxObject.h" 4 | #include "nw/ut/ResUtil.h" 5 | #include "nw/ut/BinaryFileFormat.h" 6 | #include "nw/ut/ResTypes.h" 7 | #include "nw/ut/ResMetaData.h" 8 | #include "nw/ut/ResDictionary.h" 9 | #include "nw/ut/ResArray.h" 10 | #include "nw/ut/ResArrayTypes.h" 11 | 12 | 13 | namespace nw { 14 | namespace gfx { 15 | namespace res { 16 | 17 | 18 | struct ResShaderProgramDescriptionData 19 | { 20 | u32 m_Flags; 21 | u32 m_VertexShaderObject; 22 | u32 m_GeometryShaderObject; 23 | s32 m_VertexShaderIndex; 24 | s32 m_GeometryShaderIndex; 25 | s32 m_SymbolsTableCount; 26 | nw::ut::Offset toSymbolsTable; 27 | nw::ut::BinString toAttributeSymbols[12]; 28 | s8 m_AttributeIndices[22]; 29 | s32 m_MaxBoneCount; 30 | s32 m_MaxVertexLightCount; 31 | s32 m_VertexLightEndUniform; 32 | s32 m_GeometryShaderMode; 33 | u32 m_ProgramObject; 34 | void* m_UniformLocation; 35 | void* m_CommandCache; 36 | u32 m_CommandCacheSize; 37 | nw::ut::Offset toOwnerShader; 38 | }; 39 | 40 | class ResShaderProgramDescription : public nw::ut::ResCommon< ResShaderProgramDescriptionData > 41 | { 42 | public: 43 | explicit ResShaderProgramDescription(const void* p = 0) : nw::ut::ResCommon(p) {} 44 | ResShaderProgramDescriptionData& ref() { return *ptr();} 45 | const ResShaderProgramDescriptionData& ref() const { return *ptr(); } 46 | 47 | bool operator==(const ResShaderProgramDescription& rhs) const { return ptr() == rhs.ptr(); } 48 | bool operator!=(const ResShaderProgramDescription& rhs) const { return ptr() != rhs.ptr(); } 49 | }; 50 | 51 | } // namespace res 52 | } // namespace gfx 53 | } // namespace nw 54 | 55 | 56 | -------------------------------------------------------------------------------- /include/nw/gfx/res/ResTexture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/gfx/res/ResSceneObject.h" 4 | #include "nw/ut/ResUtil.h" 5 | #include "nw/ut/BinaryFileFormat.h" 6 | #include "nw/ut/ResTypes.h" 7 | #include "nw/ut/ResMetaData.h" 8 | #include "nw/ut/ResDictionary.h" 9 | #include "nw/ut/ResArray.h" 10 | #include "nw/ut/ResArrayTypes.h" 11 | #include "nw/anim/res/ResAnimGroup.h" 12 | #include "nw/gfx/res/ResMaterial.h" 13 | 14 | namespace nw { 15 | namespace gfx { 16 | namespace res { 17 | 18 | struct ResTextureData : public ResSceneObjectData 19 | { 20 | }; 21 | 22 | class ResTexture : public ResSceneObject 23 | { 24 | public: 25 | typedef ResTexture SelfType; 26 | typedef ResTextureData ResDataType; 27 | 28 | explicit ResTexture(const void* p = 0) : ResSceneObject(p) {} 29 | 30 | ResDataType* ptr() { return reinterpret_cast(void_ptr()); } 31 | const ResDataType* ptr() const { return reinterpret_cast(void_ptr()); } 32 | 33 | ResDataType& ref() { return *reinterpret_cast(void_ptr()); } 34 | const ResDataType& ref() const { return *reinterpret_cast(void_ptr()); } 35 | 36 | bool operator==(const ResTexture& rhs) const { return ptr() == rhs.ptr(); } 37 | bool operator!=(const ResTexture& rhs) const { return ptr() != rhs.ptr(); } 38 | }; 39 | 40 | } // namespace res 41 | } // namespace gfx 42 | } // namespace nw 43 | 44 | 45 | -------------------------------------------------------------------------------- /include/nw/gfx/res/ResTextureMapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/gfx/res/ResSceneObject.h" 4 | #include "nw/ut/ResUtil.h" 5 | #include "nw/ut/BinaryFileFormat.h" 6 | #include "nw/ut/ResTypes.h" 7 | #include "nw/ut/ResMetaData.h" 8 | #include "nw/ut/ResDictionary.h" 9 | #include "nw/ut/ResArray.h" 10 | #include "nw/ut/ResArrayTypes.h" 11 | #include "nw/anim/res/ResAnimGroup.h" 12 | #include "nw/gfx/res/ResMaterial.h" 13 | #include "nw/gfx/res/ResTexture.h" 14 | 15 | namespace nw { 16 | namespace gfx { 17 | namespace res { 18 | 19 | struct ResTextureMapperData 20 | { 21 | nw::ut::ResTypeInfo typeInfo; 22 | nw::os::IAllocator* m_DynamicAllocator; 23 | nw::ut::Offset toTexture; 24 | }; 25 | 26 | struct ResPixelBasedTextureMapperData : public ResTextureMapperData 27 | { 28 | nw::ut::Offset toSampler; 29 | u32 m_CommandCache[14]; 30 | u32 m_CommandSizeToSend; 31 | }; 32 | 33 | class ResTextureMapper : public nw::ut::ResCommon< ResTextureMapperData > 34 | { 35 | public: 36 | typedef ResTextureMapper SelfType; 37 | typedef ResTextureMapperData ResDataType; 38 | 39 | explicit ResTextureMapper(const void* p = 0) : nw::ut::ResCommon(p) {} 40 | 41 | void SetTexture(ResTexture resTexture); 42 | 43 | ResTextureMapperData& ref() { return *ptr();} 44 | const ResTextureMapperData& ref() const { return *ptr(); } 45 | 46 | bool operator==(const ResTextureMapper& rhs) const { return ptr() == rhs.ptr(); } 47 | bool operator!=(const ResTextureMapper& rhs) const { return ptr() != rhs.ptr(); } 48 | }; 49 | 50 | class ResPixelBasedTextureMapper : public ResTextureMapper 51 | { 52 | public: 53 | typedef ResPixelBasedTextureMapper SelfType; 54 | typedef ResPixelBasedTextureMapperData ResDataType; 55 | 56 | explicit ResPixelBasedTextureMapper(const void* p = 0) : ResTextureMapper(p) {} 57 | 58 | ResDataType* ptr() { return reinterpret_cast(void_ptr()); } 59 | const ResDataType* ptr() const { return reinterpret_cast(void_ptr()); } 60 | 61 | ResDataType& ref() { return *reinterpret_cast(void_ptr()); } 62 | const ResDataType& ref() const { return *reinterpret_cast(void_ptr()); } 63 | 64 | bool operator==(const ResPixelBasedTextureMapper& rhs) const { return ptr() == rhs.ptr(); } 65 | bool operator!=(const ResPixelBasedTextureMapper& rhs) const { return ptr() != rhs.ptr(); } 66 | }; 67 | 68 | } // namespace res 69 | } // namespace gfx 70 | } // namespace nw 71 | 72 | 73 | -------------------------------------------------------------------------------- /include/nw/os/Memory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | namespace nw { namespace os { 6 | 7 | class IAllocator 8 | { 9 | 10 | public: 11 | virtual ~IAllocator(); 12 | virtual void* Alloc(size_t size, u8 alignment) = 0; 13 | virtual void Free(void* memory) = 0; 14 | 15 | void* Alloc(size_t size) { return this->Alloc( size, 4 ); } 16 | 17 | }; 18 | 19 | } // namespace os 20 | } // namespace nw 21 | 22 | 23 | -------------------------------------------------------------------------------- /include/nw/types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "math/Vec.h" 4 | #include "math/Mtx33.h" 5 | #include "math/Mtx34.h" 6 | #include "math/Mtx44.h" 7 | 8 | namespace nw { 9 | 10 | typedef unsigned long IntPtr; 11 | typedef signed long PtrDiff; 12 | 13 | typedef unsigned int bit32; 14 | 15 | namespace math 16 | { 17 | using VEC2 = Vec2f; 18 | using VEC3 = Vec3f; 19 | using MTX33 = Mtx33; 20 | using MTX34 = Mtx34; 21 | using MTX44 = Mtx44; 22 | 23 | struct Transform3 24 | { 25 | VEC3 scale; 26 | VEC3 rotate; 27 | VEC3 translate; 28 | }; 29 | 30 | } // namespace Math 31 | 32 | } // namespace nw -------------------------------------------------------------------------------- /include/nw/ut/BinaryFileFormat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | namespace nw { namespace ut { 6 | 7 | struct BinaryRevisionHeader 8 | { 9 | s32 signature; 10 | u32 revision; 11 | }; 12 | 13 | struct BinaryBlockHeader 14 | { 15 | u32 kind; 16 | u32 size; 17 | }; 18 | 19 | struct BinaryFileHeader 20 | { 21 | s32 signature; 22 | u16 byteOrder; 23 | u16 headerSize; 24 | u32 version; 25 | u32 fileSize; 26 | u16 dataBlocks; 27 | u16 reserved; 28 | }; 29 | 30 | 31 | } // namespace ut 32 | } // namespace nw 33 | -------------------------------------------------------------------------------- /include/nw/ut/Children.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/ut/MoveArray.h" 4 | 5 | namespace nw { namespace ut { 6 | 7 | template 8 | class ChildDeleter 9 | { 10 | public: 11 | ChildDeleter() : 12 | m_Allocator(0) {} 13 | 14 | // TODO: More... 15 | 16 | os::IAllocator* m_Allocator; 17 | }; 18 | 19 | template 20 | class ChildDetacher 21 | { 22 | public: 23 | ChildDetacher() {} 24 | 25 | // TODO: More... 26 | }; 27 | 28 | template, typename TChildList = MoveArray > 29 | class Children 30 | { 31 | public: 32 | typedef TDeleter deleter_type; 33 | typedef TDeleter& deleter_reference; 34 | typedef const TDeleter& deleter_const_reference; 35 | 36 | public: 37 | Children() : 38 | m_Children(), 39 | m_Deleter() {} 40 | 41 | ~Children() {} 42 | 43 | deleter_reference GetDeleter() { return m_Deleter; } 44 | deleter_const_reference GetDeleter() const { return m_Deleter; } 45 | 46 | // TODO: More... 47 | 48 | private: 49 | TParent* m_Parent; 50 | TChildList m_Children; 51 | deleter_type m_Deleter; 52 | }; 53 | 54 | } // namespace ut 55 | } // namespace nw 56 | 57 | 58 | -------------------------------------------------------------------------------- /include/nw/ut/Inline.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/types.h" 4 | 5 | namespace nw { namespace ut { 6 | 7 | inline IntPtr GetIntPtr(const void* ptr) 8 | { 9 | return reinterpret_cast(ptr); 10 | } 11 | 12 | inline PtrDiff GetOffsetFromPtr(const void* start, const void* end) 13 | { 14 | return static_cast(GetIntPtr(end) - GetIntPtr(start)); 15 | } 16 | 17 | } // namespace ut 18 | } // namespace nw 19 | -------------------------------------------------------------------------------- /include/nw/ut/MoveArray.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace nw { namespace ut { 4 | 5 | enum ArrayKind 6 | { 7 | ARRAY_WRAPPER, 8 | ARRAY_FIXED, 9 | }; 10 | 11 | template 12 | class MoveArray 13 | { 14 | public: 15 | typedef TElement* iterator; 16 | typedef const TElement* const_iterator; 17 | 18 | public: 19 | MoveArray() : 20 | m_Allocator(nullptr), 21 | m_Elements(nullptr), 22 | m_End(nullptr) {} 23 | 24 | ~MoveArray() 25 | { 26 | clear(); 27 | if (m_Allocator && m_Elements) 28 | { 29 | m_Allocator->Free(m_Elements); 30 | } 31 | } 32 | 33 | public: 34 | 35 | MoveArray& operator=(MoveArray rhs) 36 | { 37 | rhs.swap(*this); 38 | return *this; 39 | } 40 | 41 | const TElement* Elements() const { return m_Elements; } 42 | 43 | TElement& operator[](int index) { return m_Elements[index]; } 44 | const TElement& operator[](int index) const { return m_Elements[index]; } 45 | 46 | int size() const { return m_End - m_Elements; } 47 | 48 | iterator begin() { return m_Elements; } 49 | const_iterator begin() const { return m_Elements; } 50 | 51 | iterator end() { return m_End; } 52 | const_iterator end() const { return m_End; } 53 | 54 | TElement& front() { return *m_Elements; } 55 | const TElement& front() const { return *m_Elements; } 56 | 57 | TElement& back() { return *(m_End - 1); } 58 | const TElement& back() const { return *(m_End - 1); } 59 | 60 | bool empty() const { return m_Elements == m_End; } 61 | 62 | os::IAllocator& GetAllocator() { return *m_Allocator; } 63 | 64 | template 65 | TIterator erase(TIterator first); 66 | 67 | template 68 | TIterator erase(TIterator first, TIterator last); 69 | 70 | void clear() { erase(begin()); } 71 | 72 | // TODO: More 73 | 74 | protected: 75 | os::IAllocator* m_Allocator; 76 | TElement* m_Elements; 77 | TElement* m_End; 78 | 79 | private: 80 | size_t m_Capacity; 81 | }; 82 | 83 | } // namespace ut 84 | } // namespace nw 85 | 86 | 87 | -------------------------------------------------------------------------------- /include/nw/ut/MovePtr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/ut/MoveArray.h" 4 | 5 | namespace nw { namespace ut { 6 | 7 | // Not accurate.... 8 | template 9 | class GfxDeleter 10 | { 11 | bool m_HasOwnership; 12 | }; 13 | 14 | 15 | template> 16 | class MovePtr 17 | { 18 | public: 19 | typedef TObject element_type; 20 | typedef TDeleter deleter_type; 21 | 22 | element_type* Get() const { return Ptr(); } 23 | 24 | private: 25 | element_type*& Ptr() { return m_Object; } 26 | element_type* Ptr() const { return m_Object; } 27 | 28 | element_type* m_Object; 29 | deleter_type m_Deleter; 30 | }; 31 | 32 | } // namespace ut 33 | } // namespace nw 34 | -------------------------------------------------------------------------------- /include/nw/ut/ResArrayTypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/ut/ResTypes.h" 4 | #include "nw/ut/ResArray.h" 5 | #include "nw/ut/ResDictionary.h" 6 | 7 | namespace nw { namespace ut { namespace internal { 8 | 9 | template 10 | class ResArrayDicTraits 11 | { 12 | public: 13 | 14 | template 15 | class Traits 16 | { 17 | public: 18 | typedef typename TDic::ResDicNodeData* pointer; 19 | typedef const typename TDic::ResDicNodeData* const_pointer; 20 | typedef T reference; 21 | typedef const T const_reference; 22 | 23 | static reference GetValue(void* ptr) { return GetValue( reinterpret_cast(ptr) ); } 24 | static reference GetValue(pointer ptr) { return T( ptr->ofsData.to_ptr() ); } 25 | static const_reference GetValue(const void* ptr) { return GetValue( reinterpret_cast(ptr) ); } 26 | static const_reference GetValue(const_pointer ptr) { return T(ptr->ofsData.to_ptr()); } 27 | 28 | static pointer GetNext(pointer ptr) { return ptr + 1; } 29 | static const_pointer GetNext(const_pointer ptr) { return ptr + 1; } 30 | static size_t ValueSize() { return sizeof(TDic::ResDicNodeData); } 31 | }; 32 | }; 33 | 34 | template 35 | class ResArrayClassTraits 36 | { 37 | public: 38 | typedef Offset* pointer; 39 | typedef const Offset* const_pointer; 40 | typedef T reference; 41 | typedef const T const_reference; 42 | 43 | static reference GetValue(void* ptr) { return GetValue( reinterpret_cast(ptr) ); } 44 | static reference GetValue(pointer ptr) { return T(ptr->to_ptr()); } 45 | static const_reference GetValue(const void* ptr) { return GetValue( reinterpret_cast(ptr) ); } 46 | static const_reference GetValue(const_pointer ptr) { return T(ptr->to_ptr()); } 47 | 48 | static pointer GetNext(pointer ptr){ return ptr + 1; } 49 | static const_pointer GetNext(const_pointer ptr) { return ptr + 1; } 50 | static size_t ValueSize() { return sizeof(Offset); } 51 | }; 52 | 53 | } // namespace internal 54 | 55 | template 56 | class ResArrayClass 57 | { 58 | public: 59 | typedef internal::ResArray type; 60 | }; 61 | 62 | template 63 | class ResArrayPatricia 64 | { 65 | public: 66 | typedef internal::ResArray::Traits> type; 67 | }; 68 | 69 | } // namespace ut 70 | } // namespace nw 71 | 72 | 73 | -------------------------------------------------------------------------------- /include/nw/ut/ResMetaData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nw/gfx/GfxObject.h" 4 | #include "nw/ut/ResUtil.h" 5 | #include "nw/ut/BinaryFileFormat.h" 6 | #include "nw/ut/ResTypes.h" 7 | 8 | namespace nw { namespace ut { 9 | 10 | struct ResMetaDataData 11 | { 12 | nw::ut::ResTypeInfo typeInfo; 13 | nw::ut::BinString toKey; 14 | s32 m_DataType; 15 | }; 16 | 17 | class ResMetaData : public nw::ut::ResCommon 18 | { 19 | 20 | public: 21 | explicit ResMetaData(const void* p = 0) : 22 | nw::ut::ResCommon(p) {} 23 | 24 | ResMetaDataData& ref() { return *ptr(); } 25 | const ResMetaDataData& ref() const { return *ptr(); } 26 | 27 | bool operator==(const ResMetaData& rhs) const { return ptr() == rhs.ptr(); } 28 | bool operator!=(const ResMetaData& rhs) const { return ptr() != rhs.ptr(); } 29 | 30 | inline const char* GetKey() const { return ref().toKey.to_ptr(); } 31 | 32 | inline s32 GetDataType() const { return static_cast(ref().m_DataType); } 33 | inline void SetDataType(s32 value) { ref().m_DataType = value; } 34 | 35 | nw::ut::ResTypeInfo GetTypeInfo() const { return ref().typeInfo; } 36 | }; 37 | 38 | } // namespace ut 39 | } // namespace nw 40 | 41 | 42 | -------------------------------------------------------------------------------- /include/nw/ut/ResTypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | #include "nw/ut/Inline.h" 5 | 6 | namespace nw { namespace ut { 7 | 8 | typedef u32 Size; 9 | typedef u32 Length; 10 | typedef u32 ResTypeInfo; 11 | 12 | struct BinString 13 | { 14 | s32 offset; 15 | 16 | inline const char* to_ptr() const 17 | { 18 | const u8* p = reinterpret_cast(this); 19 | if ( offset != 0 ) 20 | return reinterpret_cast(p + offset); 21 | else 22 | return nullptr; 23 | } 24 | 25 | inline void set_ptr(const char* ptr) 26 | { 27 | if (ptr == nullptr) 28 | offset = 0; 29 | else 30 | offset = GetOffsetFromPtr(this, ptr); 31 | } 32 | 33 | operator const char*() const { return to_ptr(); } 34 | }; 35 | 36 | typedef struct Offset 37 | { 38 | s32 offset; 39 | 40 | static Offset s32_to_ofs(s32 ofs) { return *reinterpret_cast(&ofs); } 41 | 42 | Offset operator=(s32 ofs) { offset = ofs; return *this; } 43 | operator s32() const { return offset; } 44 | Offset operator+(s32 ofs) const { return s32_to_ofs(this->offset + ofs); } 45 | Offset operator-(s32 ofs) const { return s32_to_ofs(this->offset - ofs); } 46 | Offset operator+=(s32 ofs) { this->offset += ofs; return *this; } 47 | Offset operator-=(s32 ofs) { this->offset -= ofs; return *this; } 48 | 49 | void set_ptr(const void* ptr) 50 | { 51 | ptr == nullptr ? offset = 0 : offset = GetOffsetFromPtr(this, ptr); 52 | } 53 | 54 | void* to_ptr() 55 | { 56 | u8* p = reinterpret_cast(this); 57 | if ( offset != 0 ) 58 | return p + offset; 59 | else 60 | return nullptr; 61 | } 62 | 63 | const void* to_ptr() const 64 | { 65 | const u8* p = reinterpret_cast(this); 66 | if ( offset != 0 ) 67 | return p + offset; 68 | else 69 | return nullptr; 70 | } 71 | 72 | template 73 | inline const T* to_ptr() const { return static_cast(to_ptr()); } 74 | 75 | template 76 | inline T* to_ptr() { return static_cast(to_ptr()); } 77 | 78 | inline void* to_table_ptr() { return to_ptr(); } 79 | inline const void* to_table_ptr() const { return to_ptr(); } 80 | } Offset; 81 | 82 | } // namespace ut 83 | } // namespace nw 84 | -------------------------------------------------------------------------------- /include/nw/ut/RuntimeTypeInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace nw { 4 | namespace ut { 5 | namespace internal { 6 | 7 | struct RuntimeTypeInfo 8 | { 9 | const RuntimeTypeInfo* mParentTypeInfo; 10 | 11 | explicit RuntimeTypeInfo( const RuntimeTypeInfo* parent ) : 12 | mParentTypeInfo(parent) {} 13 | 14 | bool IsDerivedFrom( const RuntimeTypeInfo* s_TypeInfo ) const 15 | { 16 | const RuntimeTypeInfo *self = this; 17 | 18 | while (self != nullptr) 19 | { 20 | if (self == s_TypeInfo) 21 | { 22 | return true; 23 | } 24 | self = self->mParentTypeInfo; 25 | } 26 | return false; 27 | } 28 | }; 29 | 30 | } // namespace internal 31 | } // namespace ut 32 | } // namespace nw 33 | 34 | 35 | -------------------------------------------------------------------------------- /include/player/PlayerInput.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | 6 | class PlayerInput // size: 0x98 7 | { 8 | public: 9 | enum Button 10 | { 11 | BUTTON_JUMP = 0x1, // A/B or A/X 12 | BUTTON_RUN = 0x2, // X/Y or B/Y 13 | BUTTON_ACTION = 0x4, // L/R 14 | BUTTON_UP = 0x8, // Up 15 | BUTTON_DOWN = 0x10, // Down 16 | BUTTON_LEFT = 0x20, // Left 17 | BUTTON_RIGHT = 0x40 // Right 18 | }; 19 | 20 | public: 21 | PlayerInput(); // 0044DA40 22 | 23 | void execute(); // 0044D840 24 | 25 | bool isJumpHeld(); 26 | bool isJumpPressed(); 27 | bool isRunHeld(); 28 | bool isRunPressed(); 29 | bool getDirectionHeld(u8* directionOut); // Returns whether any direction is held 30 | 31 | u32 _0; // 0 Inited to 0 32 | u32 _4; // 4 Inited to 0 33 | u32 buttonsHeld; // 8 Inited to 0 34 | u32 buttonsPressed; // C Inited to 0 35 | u32 buttonsHeldLast; // 10 Inited to 0 36 | u32 buttonsPressedLast; // 14 Inited to 0 37 | u32 _18; // 18 Inited to 0 38 | u32 _1C; // 1C Inited to 0 39 | u32 _20; // 20 Inited to 0 40 | u32 _24; // 24 Inited to 0 41 | u32 _28[10]; // 28 Inited to 0 42 | u32 _50; // 50 Inited to 0 43 | u32 _54; // 54 Inited to 0 44 | u32 _58; // 58 Inited to 0 45 | u32 _5C; // 5C Inited to 0 46 | u32 _60[10]; // 60 Inited to 0 47 | u32 _88; // 88 Inited to 0 48 | u32 _8C; // 8C Inited to 0 49 | u8 _90; // 90 Inited to 0 50 | u8 _91; // 91 Inited to 0 51 | u8 _92; // 92 Inited to 0 52 | u32 _94; // 94 Inited to 0 53 | }; 54 | -------------------------------------------------------------------------------- /include/player/PlayerLookTarget.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead.h" 4 | 5 | class PlayerLookTarget : public sead::IDisposer // size: 0x2C 6 | { 7 | public: 8 | PlayerLookTarget(s32 id); // 0028A940 9 | ~PlayerLookTarget(); // 0028A988 Removes from list 10 | 11 | s32 id; 12 | Vec2f position; 13 | u8 _1C; 14 | u8 radius; 15 | u32 _20; 16 | u32 _24; 17 | u32 _28; 18 | }; 19 | 20 | 21 | class PlayerLookTargetMgr : public sead::IDisposer 22 | { 23 | public: 24 | static PlayerLookTargetMgr* instance; 25 | 26 | void addToList(PlayerLookTarget* target); 27 | void removeFromList(PlayerLookTarget* target); 28 | 29 | }; -------------------------------------------------------------------------------- /include/player/PlayerMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "player/PlayerObject.h" 4 | 5 | class PlayerStateData; 6 | 7 | // Size: 0x78 8 | // Vtable: 0x005D0374 9 | class PlayerMgr 10 | { 11 | // createInstance() Address: 0x0044DC84 12 | // deleteInstance() Address: 0x0044DCE8 13 | // sInstance Address: 0x005EB530 14 | // SingletonDisposer_::~SingletonDisposer_() Address: 0x0044DE2C 15 | // SingletonDisposer_::sStaticDisposer Address: 0x005EB534 16 | // SingletonDisposer_::vtbl Address: 0x005D0364 17 | SEAD_SINGLETON_DISPOSER(PlayerMgr); 18 | 19 | public: 20 | 21 | // Address: 0x0044E58C 22 | PlayerMgr(); 23 | 24 | // D1: 0x0044E640 25 | // D2: 0x0044E6B0 26 | virtual ~PlayerMgr(); 27 | 28 | // Address: 0x0044E2D0 29 | void execute(); 30 | 31 | // Address: 0x0044E43C 32 | void reset(); 33 | 34 | // Address: 0x0044E47C 35 | void createPlayers(PlayerStateData* playerState); 36 | 37 | // Address: 0x0044DECC 38 | void removePlayer(s32 playerId); 39 | 40 | // Address: 0x0044DE90 41 | void addPlayer(s32 playerId, PlayerBase* player); 42 | 43 | // Address: 0x0044E000 44 | void gotoEntrance(u8 areaId, u8 entranceId); 45 | 46 | // Address: 0x0044DE7C 47 | PlayerObject* getPlayer(s32 playerId = 0); 48 | 49 | // Address: 0x0044DE7C 50 | const PlayerObject* getPlayer(s32 playerId = 0) const; 51 | 52 | // Address: 0x0044DF0C 53 | void doCoopQuake(); 54 | 55 | enum class QuakeType 56 | { 57 | Normal = 0, // Used for co-op ground pound 58 | Mega = 1, // Used for mega mario ground pound 59 | Mini = 2 // Used for mini mario (prevents quake) 60 | }; 61 | 62 | // Address: 0x0044DD48 63 | void doQuake(QuakeType quakeType, s32 playerId); 64 | 65 | // Address: 0x0044DC44 66 | void enableStarMusic(); 67 | 68 | // Address: 0x0044DB7C 69 | void disableStarMusic(); 70 | 71 | // Address: 0x0044DBF4 72 | void enableMegaMusic(); 73 | 74 | // Address: 0x0044DB04 75 | void disableMegaMusic(); 76 | 77 | // Address: 0x0044DC08 78 | void doPlayerDown(s32 playerId); 79 | 80 | // Address: 0x004AFC04 81 | s32 numPlayers(); 82 | 83 | // Address: 0x004AFC60 84 | s32 numPlayersAlive(); 85 | 86 | // Address: 0x004AFCD8 87 | sead::BitFlag16* getUnkFlag(); 88 | 89 | private: 90 | u32 _14; 91 | u32 _18; 92 | u32 _1C; 93 | u32 _20; 94 | u32 _24; 95 | u32 _28; 96 | u32 _2C; 97 | u32 _30; 98 | u32 _34; 99 | u32 _38; 100 | u32 _3C; 101 | PlayerObject *mPlayers[2]; 102 | PlayerObject *mPlayers2[2]; // idk why there's two of these 103 | sead::BitFlag16 mPlayerFlags; // 1: Player 1 exists, 2: Player 2 exists 104 | u32 _54; 105 | u32 _58; 106 | u32 _5C; 107 | u32 _60; 108 | u8 _64; 109 | sead::BitFlag16 mMusicFlags; // 1: Star Active, 2: Mega Active 110 | u8 _68; 111 | u8 _69; 112 | u8 _6A; 113 | u32 _6C[2]; 114 | u8 _74[2]; 115 | u8 _76; 116 | 117 | }; 118 | 119 | size_assert(PlayerMgr, 0x78); -------------------------------------------------------------------------------- /include/player/PlayerModelBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "gfx/AnimModel.h" 4 | #include "player/PlayerEnum.h" 5 | #include "sys/ResourceMgr.h" 6 | 7 | class PlayerModelBase 8 | { 9 | public: 10 | virtual f32* vf0(); 11 | virtual void setTextureAnim(s32 animIdx); 12 | virtual bool vf8(Resource *resourceOut, sead::SafeString* animNameOut, s32 animIdx, int a4); 13 | virtual bool getTailAnimName(sead::SafeString* out, AnimId animIdx); // returns matching Tail anim name for a given anim idx 14 | virtual bool getGoldBlockAnimName(sead::SafeString* out, AnimId animIdx); // returns matching goldBlock stoop anim name for a given anim idx (has gold block hat) 15 | virtual bool getEndingAnimName(sead::SafeString* out, AnimId animIdx); // returns matching ending anim name for a given anim idx (carrying peach) 16 | virtual void vf18(Resource *animRes, const sead::SafeString* animName, PlayPolicy playPolicy, f32 frameStep, f32 frame, f32 a7); 17 | virtual void vf1C(Resource *animRes, const sead::SafeString* animName, PlayPolicy playPolicy, f32 frameStep, f32 frame, f32 a7); 18 | virtual void vf20(); 19 | virtual void update(); 20 | virtual ~PlayerModelBase(); 21 | virtual s32 getBoneIdx(s32 boneId); 22 | virtual void vf34(int a2); // related to setting powerup id 23 | virtual void vf38(int a2); 24 | virtual void vf3C(f32 a2); 25 | virtual void vf40(f32 a2); 26 | virtual void vf44(); 27 | virtual void vf48(Vec2f* a2, f32 a3); 28 | virtual void vf4C(int* a2); 29 | virtual u32 vf50(); 30 | virtual void vf54(u8 a2); 31 | virtual void vf58(int* a2); 32 | virtual void setPowerup(Powerup powerupId); 33 | virtual void setAnimation(s32 animIdx, f32 frameStep, f32 startFrame, f32 a3); 34 | virtual void vf64(); 35 | virtual void vf68(f32 a2); 36 | virtual bool vf6C(sead::SafeString* out, int a2, int a3); 37 | virtual void getBoneWorldTransformMatrix(Mtx34* out, s32 boneIdx); 38 | virtual void vf74(); 39 | virtual void draw(); 40 | virtual void playBigEndColorAnim(); 41 | virtual void vf80(); 42 | virtual void setStarActive(); 43 | virtual void setStarDisabled(); 44 | virtual void setStoneActive(); 45 | virtual void setStoneDisabled(); 46 | virtual f32 vf94(); 47 | virtual void applyEnvLight(); 48 | 49 | Resource* modelResource; 50 | Resource* animResource; 51 | AnimModelBase* bodyModel; 52 | void* _10; // this is something related to animations 53 | HeapAllocator allocator; 54 | Powerup currentPowerupId; 55 | AnimId animId; 56 | AnimId animId2; // idk what this is for 57 | void* _24; 58 | Mtx34 _28; 59 | Mtx34 _58; 60 | Vec3f _88; 61 | bool isLuigi; // alternatively playerId? 62 | u8 _95; 63 | u8 _96; 64 | u8 _97; 65 | u32 _98; 66 | f32 _9C; 67 | u32 _A0; // bitflag 68 | u32 _A4; 69 | u32 flags; // seems to control visibility of stuff, may control other stuff too, see [PlayerRendererBaseBase::FlagMask] enum 70 | u32 jumpAnimIdx; // maybe also other stuff... subAnimIdx? 71 | }; 72 | 73 | size_assert(PlayerModelBase, 0x00B0); 74 | 75 | -------------------------------------------------------------------------------- /include/scene/ScCourse.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "StateScene.h" 4 | 5 | class ScCourse : public StateScene // size: 0x18C 6 | { 7 | public: 8 | void zeroTimer(); // 0x0042B304 9 | void showCourseCompleteMsg(); // 0x00429DD8 10 | 11 | u8 getStockItemId(u8 playerId); 12 | void setStockItemId(u8 playerId, u8 stockItemId); 13 | 14 | void setCollectionCoinStatus(u8 collectionCoinId, bool status); 15 | 16 | 17 | static ScCourse* instance; // 0x005E7210 18 | 19 | fBase* bsArea; // 3C created and set in onCreate 20 | u8 _unk40[0xEC-0X40]; // 40 21 | u32 ticks; // EC counts the ticks in which actors are executed 22 | u8 _unkF0[0x174-0xF0]; // F0 23 | u8 stockItemIds[2]; // 174 24 | u8 _unk176[0x18C-0x176]; // 176 25 | }; 26 | -------------------------------------------------------------------------------- /include/scene/Scene.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "actors/dBase.h" 4 | 5 | class Scene : public fBase // size: 0x14 6 | { 7 | public: 8 | Scene(); 9 | virtual ~Scene(); 10 | 11 | int beforeCreate() override; 12 | void afterCreate(int) override; 13 | int beforeDelete() override; 14 | void afterDelete(int) override; 15 | int beforeExecute() override; 16 | void afterExecute(int) override; 17 | int beforeDraw() override; 18 | void afterDraw(int) override; 19 | 20 | virtual void vf3C(); // deleted 21 | virtual s32 vf40(u32); // does nothing 22 | 23 | 24 | enum TransitionType : u8 25 | { 26 | TRANSITION_FADE = 0, 27 | TRANSITION_FADE_SLOWER = 1, 28 | TRANSITION_CIRCLE = 2, 29 | TRANSITION_CIRCLE_PLAYER = 3, 30 | TRANSITION_CIRCLE_2 = 4, 31 | TRANSITION_HEAD = 5, 32 | TRANSITION_BOWSER = 6, 33 | TRANSITION_SWIPE_DOWN = 7, 34 | TRANSITION_SWIPE_UP = 8, 35 | TRANSITION_FADE_FASTER = 9, 36 | TRANSITION_INSTANT = 10, 37 | TRANSITION_FADE_2 = 11 38 | }; 39 | 40 | static void changeScene(u32 profileId, u8 transitionType, u8 unk1, u8 unk2, u8 unk3, u32 settings); 41 | static void changeScene(u32 profileId, u32 settings); 42 | 43 | static void setTransition(u8 type, u8 unk1, u8 unk2, u8 unk3); 44 | 45 | static Scene* currentScene; 46 | static u16 nextSceneId; 47 | static u16 currentSceneId; 48 | static u16 lastSceneId; 49 | }; 50 | -------------------------------------------------------------------------------- /include/scene/StateScene.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Scene.h" 4 | #include "state/FStateStateMgr.h" 5 | 6 | class StateScene : public Scene // size: 0x3C 7 | { 8 | public: 9 | StateScene(); 10 | virtual ~StateScene(); 11 | 12 | s32 vf40(u32) override; // returns -1 13 | 14 | virtual void vf44(); // deleted 15 | virtual void changeState(const StateID& stateID); 16 | 17 | FStateStateMgr stateMgr; 18 | }; 19 | -------------------------------------------------------------------------------- /include/sead.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* ------------ Heap ------------ */ 4 | #include "sead/heap/seadArena.h" 5 | #include "sead/heap/seadDisposer.h" 6 | #include "sead/heap/seadExpHeap.h" 7 | // #include "sead/heap/seadFrameHeap.h" 8 | #include "sead/heap/seadHeap.h" 9 | #include "sead/heap/seadHeapMgr.h" 10 | #include "sead/heap/seadMemBlock.h" 11 | 12 | #include "sead/seadRuntimeTypeInfo.h" 13 | #include "sead/seadBuffer.h" 14 | #include "sead/seadPtrArray.h" 15 | #include "sead/seadSafeString.h" 16 | #include "sead/seadColor.h" 17 | #include "sead/seadBoundBox.h" 18 | #include "sead/seadSystem.h" 19 | #include "sead/seadMathCalcCommonCtr.h" 20 | #include "sead/seadProjection.h" 21 | #include "sead/seadCamera.h" 22 | -------------------------------------------------------------------------------- /include/sead/basis/seadNew.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | namespace sead { 6 | 7 | class Heap; 8 | 9 | } // namespace sead 10 | 11 | 12 | void* operator new(size_t size); 13 | void* operator new[](size_t size); 14 | 15 | void* operator new(size_t size, sead::Heap* heap, u32 align = 4); 16 | void* operator new[](size_t size, sead::Heap* heap, u32 align = 4); 17 | 18 | void operator delete(void* ptr); 19 | void operator delete[](void* ptr); -------------------------------------------------------------------------------- /include/sead/heap/seadArena.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | namespace sead { 6 | 7 | // Size: 0xC 8 | class Arena 9 | { 10 | public: 11 | // C1 Address: 0x0047788C 12 | Arena(); 13 | 14 | // D1 Address: 0x004778A0 15 | ~Arena(); 16 | 17 | // Address: 0x001193B4 18 | u8* initialize(size_t size); 19 | 20 | u8* getStartAddr() { return mStart; } 21 | size_t getSize() const { return mSize; } 22 | bool isInclude(void* ptr) const { return mStart <= ptr && ptr < mStart + mSize; } 23 | 24 | protected: 25 | u8* mStart; 26 | size_t mSize; 27 | bool mInitWithStartAddress; 28 | }; 29 | 30 | size_assert(Arena, 0xC); 31 | 32 | } // namespace sead 33 | -------------------------------------------------------------------------------- /include/sead/heap/seadExpHeap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead/heap/seadHeap.h" 4 | #include "sead/heap/seadMemBlock.h" 5 | 6 | namespace sead { 7 | 8 | typedef OffsetList MemBlockList; 9 | 10 | class ExpHeap : public Heap // size: 0x94 11 | { 12 | public: 13 | enum AllocMode : u8 14 | { 15 | cAllocMode_FirstFit = 0, 16 | cAllocMode_BestFit = 1, 17 | }; 18 | 19 | void destroy() override; 20 | u32 adjust() override; 21 | void* tryAlloc(size_t size, s32 alignment) override; 22 | void free(void* ptr) override; 23 | void* resizeFront(void* p_void, size_t size) override; 24 | void* resizeBack(void* p_void, size_t size) override; 25 | void freeAll() override; 26 | void* getStartAddress() const override; 27 | void* getEndAddress() const override; 28 | u32 getSize() const override; 29 | u32 getFreeSize() const override; 30 | u32 getMaxAllocatableSize(s32 alignment) const override; 31 | bool isInclude(const void* p_void) const override; 32 | bool isFreeable() const override; 33 | bool isResizable() const override; 34 | bool isAdjustable() const override; 35 | void dump() const override; 36 | void genInformation_(hostio::Context* context) override; 37 | 38 | virtual void setAllocMode(AllocMode mode); 39 | virtual AllocMode getAllocMode() const; 40 | 41 | AllocMode mAllocMode; // 70 42 | MemBlockList mFreeList; // 74 43 | MemBlockList mUseList; // 84 44 | }; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /include/sead/heap/seadHeapMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead/heap/seadHeap.h" 4 | #include "sead/heap/seadArena.h" 5 | #include "sead/seadDelegate.h" 6 | #include "sead/seadPtrArray.h" 7 | 8 | namespace sead { 9 | 10 | // Size: 0x8 11 | // Vtable: 0x005D2FCC 12 | class HeapMgr 13 | { 14 | public: 15 | 16 | struct AllocFailedCallbackArg // size: 0x14 17 | { 18 | sead::Heap* heap; // 0 19 | u32 request_size; // 4 20 | s32 request_alignment; // 8 21 | u32 alloc_size; // C 22 | s32 alloc_alignment; // 10 23 | }; 24 | 25 | typedef IDelegate1 IAllocFailedCallback; 26 | 27 | private: 28 | typedef FixedPtrArray RootHeaps; 29 | 30 | public: 31 | // D2 Address: 0x00478A64 32 | virtual ~HeapMgr(); 33 | 34 | // Address: 0x0011732C 35 | static void initialize(u32 size); 36 | 37 | // TODO 38 | // static void initialize(Arena* arena); 39 | 40 | // TODO 41 | // static void destroy(); 42 | 43 | static bool isInitialized() { return sInstancePtr != nullptr; } 44 | static HeapMgr* instance() { return sInstancePtr; } 45 | 46 | // Address: 0x001197C8 47 | Heap* findContainHeap(const void* memBlock) const; 48 | 49 | // Address: 0x0011340C 50 | Heap* getCurrentHeap() const; 51 | 52 | // TODO 53 | // static Heap* getRootHeap(s32 n) { return sRootHeaps.at(n); } 54 | // static s32 getRootHeapNum() { return sRootHeaps.size(); } 55 | // static void addRootHeap(Heap* heap); 56 | // static const Arena* getArena(); 57 | // static IndependentHeaps* getIndependentHeaps() { return &sIndependentHeaps; } 58 | // static bool isContainedInAnyHeap(const void* ptr) { return sInstancePtr->findContainHeap(ptr) != nullptr; } 59 | 60 | // TODO 61 | // IAllocFailedCallback* setAllocFailedCallback(IAllocFailedCallback* callback); 62 | // IAllocFailedCallback* getAllocFailedCallback(); 63 | 64 | 65 | IAllocFailedCallback* mAllocFailedCallback; // 4 66 | protected: 67 | 68 | // Address: 0x00109E10 69 | Heap* setCurrentHeap_(Heap* heap); 70 | 71 | 72 | // Address: 0x005F3E50 73 | static HeapMgr sInstance; 74 | 75 | // Address: 0x005F3E48 76 | static HeapMgr* sInstancePtr; 77 | 78 | // Address: 0x005F3E4C 79 | static Arena* sArena; 80 | 81 | // Address: 0x006B6624 82 | static Arena sDefaultArena; 83 | 84 | // Address: 0x006B6630 85 | static RootHeaps sRootHeaps; 86 | 87 | // Address: 0x006B664C 88 | static CriticalSection sHeapTreeLockCS; 89 | 90 | // TODO 91 | // static IndependentHeaps sIndependentHeaps; 92 | 93 | friend class AllocationFailedHandler; 94 | }; 95 | 96 | } 97 | -------------------------------------------------------------------------------- /include/sead/heap/seadMemBlock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | #include "sead/seadListImpl.h" 5 | 6 | namespace sead 7 | { 8 | 9 | // size: 0x18 10 | class MemBlock 11 | { 12 | public: 13 | // static MemBlock* FindManageArea(void* ptr); 14 | 15 | static u32 getOffset() { return offsetof(MemBlock, mListNode); } 16 | 17 | u32 getSize() const { return mSize; } 18 | 19 | protected: 20 | sead::ListNode mListNode; // 0 21 | u32 mSize; // 10 22 | u32 mOffset; // 14 23 | }; 24 | 25 | } // namespace sead 26 | -------------------------------------------------------------------------------- /include/sead/seadBitFlag.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | namespace sead { 6 | 7 | template 8 | class BitFlag 9 | { 10 | public: 11 | BitFlag() 12 | : mBits(0) 13 | { 14 | } 15 | 16 | explicit BitFlag(T t) 17 | : mBits(t) 18 | { 19 | } 20 | 21 | operator T() const { return mBits; } 22 | 23 | void makeAllZero() { mBits = 0; } 24 | void makeAllOne() { mBits = T(-1); } 25 | 26 | void setDirect(T bits) { mBits = bits; } 27 | T getDirect() const { return mBits; } 28 | T* getPtr() { return &mBits; } 29 | const T* getPtr() const { return &mBits; } 30 | size_t getByteSize() const { return sizeof(T); } 31 | 32 | void set(T mask) { mBits |= mask; } 33 | void reset(T mask) { mBits &= ~mask; } 34 | void toggle(T mask) { mBits ^= mask; } 35 | void change(T mask, bool b) { b ? set(mask) : reset(mask); } 36 | 37 | bool isZero() const { return mBits == 0; } 38 | bool isOn(T mask) const { return (mBits & mask) != 0; } 39 | bool isOnAll(T mask) const { return (mBits & mask) == mask; } 40 | bool isOff(T mask) const { return !isOn(mask); } 41 | 42 | T getMask(T mask) const { return mBits & mask; } 43 | 44 | static T makeMask(s32 bit) 45 | { 46 | return T(1) << bit; 47 | } 48 | 49 | void setBit(s32 bit) { set(makeMask(bit)); } 50 | void resetBit(s32 bit) { reset(makeMask(bit)); } 51 | void changeBit(s32 bit, bool b) { change(makeMask(bit), b); } 52 | void toggleBit(s32 bit) { toggle(makeMask(bit)); } 53 | 54 | bool isOnBit(s32 bit) const { return isOn(makeMask(bit)); } 55 | bool isOffBit(s32 bit) const { return isOff(makeMask(bit)); } 56 | 57 | // s32 countOnBit() const; 58 | // inline s32 countContinuousOffBitFromRight() const; 59 | // s32 countRightOnBit(s32) const; 60 | // s32 findOnBitFromRight(s32) const; 61 | 62 | protected: 63 | T mBits; 64 | }; 65 | 66 | typedef BitFlag BitFlag8; 67 | typedef BitFlag BitFlag16; 68 | typedef BitFlag BitFlag32; 69 | 70 | } 71 | -------------------------------------------------------------------------------- /include/sead/seadBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | 6 | namespace sead { 7 | 8 | template 9 | class Buffer 10 | { 11 | public: 12 | Buffer() : mSize(0), mBuffer(nullptr) { } 13 | 14 | T* get(s32 i) 15 | { 16 | if (i < mSize && i >= 0) 17 | return &mBuffer[i]; 18 | return nullptr; 19 | } 20 | 21 | const T* get(s32 i) const 22 | { 23 | if (i < mSize && i >= 0) 24 | return &mBuffer[i]; 25 | return nullptr; 26 | } 27 | 28 | T& operator[](s32 i) 29 | { 30 | return *get(i); 31 | } 32 | 33 | const T& operator[](s32 i) const 34 | { 35 | return *get(i); 36 | } 37 | 38 | s32 size() const 39 | { 40 | return mSize; 41 | } 42 | 43 | private: 44 | s32 mSize; 45 | T* mBuffer; 46 | }; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /include/sead/seadCamera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "seadProjection.h" 4 | #include "math/Mtx34.h" 5 | 6 | 7 | namespace sead { 8 | 9 | 10 | class Camera // size: 0x34 11 | { 12 | public: 13 | Camera() 14 | : mMatrix(Mtx34::ident) { } 15 | 16 | virtual void* getRuntimeTypeInfo() const; 17 | virtual void doUpdateMatrix(Mtx34* dst) const = 0; 18 | 19 | Mtx34 mMatrix; // 4 20 | 21 | void worldPosToCameraPosByMatrix(Vec3f* dst, const Vec3f& world_pos) const; 22 | }; 23 | 24 | 25 | class LookAtCamera : public Camera // size: 0x58 26 | { 27 | public: 28 | LookAtCamera() 29 | : mPos(0.0f, 0.0f, 1.0f), mAt(0.0f, 0.0f, 0.0f), mUp(0.0f, 1.0f, 0.0f) { } 30 | 31 | virtual void* getRuntimeTypeInfo() const override; 32 | virtual void doUpdateMatrix(Mtx34* dst) const override; 33 | 34 | Vec3f mPos; // 34 Inited to (0.0f, 0.0f, 1.0f) 35 | Vec3f mAt; // 40 Inited to (0.0f, 0.0f, 0.0f) 36 | Vec3f mUp; // 4C Inited to (0.0f, 1.0f, 0.0f) 37 | }; 38 | 39 | 40 | class OrthoCamera : public LookAtCamera // size: 0x58 41 | { 42 | public: 43 | OrthoCamera(); 44 | OrthoCamera(const OrthoProjection& proj); 45 | OrthoCamera(const Vec2f& center, f32 distance); 46 | }; 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /include/sead/seadColor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | namespace sead { 6 | 7 | 8 | class Color4f 9 | { 10 | public: 11 | union 12 | { 13 | struct 14 | { 15 | f32 r; 16 | f32 g; 17 | f32 b; 18 | f32 a; 19 | }; 20 | 21 | f32 c[4]; 22 | }; 23 | 24 | Color4f(f32 r=0.0f, f32 g=0.0f, f32 b=0.0f, f32 a=1.0f) 25 | : r(r), g(g), b(b), a(a) { } 26 | }; 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /include/sead/seadCriticalSection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead/heap/seadDisposer.h" 4 | 5 | namespace sead { 6 | 7 | class CriticalSection : public IDisposer 8 | { 9 | public: 10 | CriticalSection(); 11 | virtual ~CriticalSection(); 12 | 13 | void lock(); 14 | void unlock(); 15 | bool tryLock(); 16 | 17 | private: 18 | u32 nnOsCriticalSection[3]; 19 | }; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /include/sead/seadGraphics.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | #include "sead/heap/seadDisposer.h" 6 | 7 | namespace sead { 8 | 9 | class Graphics : public sead::IDisposer 10 | { 11 | public: 12 | enum DevicePosture : u8 13 | { 14 | DevicePosture_Same = 0x0, 15 | DevicePosture_RotateRight = 0x1, 16 | DevicePosture_RotateLeft = 0x2, 17 | DevicePosture_RotateHalfAround = 0x3, 18 | DevicePosture_FlipXY = 0x3, 19 | DevicePosture_FlipX = 0x4, 20 | DevicePosture_Invalid = 0x4, 21 | DevicePosture_FlipY = 0x5, 22 | }; 23 | 24 | // 005F3D98 25 | static Graphics* sInstance; 26 | 27 | // 005F3D9C 28 | static DevicePosture sDefaultDevicePosture; 29 | // 005F3DA0 30 | static f32 sDefaultDeviceZScale; 31 | // 005F3DA4 32 | static f32 sDefaultDeviceZOffset; 33 | }; 34 | 35 | 36 | } // namespace sead 37 | -------------------------------------------------------------------------------- /include/sead/seadLine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead/seadVector.h" 4 | 5 | namespace sead { 6 | 7 | template 8 | class Segment 9 | { 10 | public: 11 | using T = typename VectorType::ValueType; 12 | 13 | public: 14 | Segment() : 15 | mP0(VectorType::zero), mP1(VectorType::ex) {} 16 | 17 | Segment(const VectorType& p0, const VectorType& p1) : 18 | mP0(p0), mP1(p1) {} 19 | 20 | const VectorType& getPos0() const 21 | { 22 | return mP0; 23 | } 24 | 25 | void setPos0(const VectorType& p0) 26 | { 27 | mP0 = p0; 28 | } 29 | 30 | const VectorType& getPos1() const 31 | { 32 | return mP1; 33 | } 34 | 35 | void setPos1(const VectorType& p1) 36 | { 37 | mP1 = p1; 38 | } 39 | 40 | private: 41 | VectorType mP0; 42 | VectorType mP1; 43 | }; 44 | 45 | typedef Segment Segment2f; 46 | typedef Segment Segment3f; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /include/sead/seadListImpl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | namespace sead { 6 | 7 | class ListNode // size: 0x8 8 | { 9 | public: 10 | ListNode* mPrev; // 0 11 | ListNode* mNext; // 4 12 | }; 13 | 14 | class ListImpl // size: 0xC 15 | { 16 | public: 17 | ListNode mStartEnd; // 0 18 | s32 mCount; // 8 19 | }; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /include/sead/seadMathCalcCommonCtr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | namespace sead { 6 | 7 | template 8 | class MathCtr 9 | { 10 | 11 | }; 12 | 13 | } // namespace sead 14 | 15 | #define SEAD_MATHCALCCOMMONCTR_H_ 16 | #include "sead/seadMathCalcCommonCtr.hpp" 17 | #undef SEAD_MATHCALCCOMMONCTR_H_ -------------------------------------------------------------------------------- /include/sead/seadMathCalcCommonCtr.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace sead { 4 | 5 | 6 | } // namespace sead -------------------------------------------------------------------------------- /include/sead/seadMathPolicies.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace sead { 4 | 5 | template 6 | class Policies 7 | { 8 | public: 9 | struct Vec2Base 10 | { 11 | T x; 12 | T y; 13 | 14 | Vec2Base(T x = 0, T y = 0) : 15 | x(x), y(y) {} 16 | }; 17 | 18 | struct Vec3Base 19 | { 20 | T x; 21 | T y; 22 | T z; 23 | 24 | Vec3Base(T x = 0, T y = 0, T z = 0) : 25 | x(x), y(y), z(z) {} 26 | }; 27 | 28 | struct Vec4Base 29 | { 30 | T x; 31 | T y; 32 | T z; 33 | T w; 34 | 35 | Vec4Base(T x = 0, T y = 0, T z = 0, T w = 0) : 36 | x(x), y(y), z(z), w(w) {} 37 | }; 38 | 39 | struct QuatBase 40 | { 41 | T x; 42 | T y; 43 | T z; 44 | T w; 45 | 46 | QuatBase(T x = 0, T y = 0, T z = 0, T w = 0) : 47 | x(x), y(y), z(z), w(w) {} 48 | }; 49 | 50 | struct Mtx22Base 51 | { 52 | union 53 | { 54 | T m[2][2]; 55 | T a[4]; 56 | }; 57 | }; 58 | 59 | struct Mtx33Base 60 | { 61 | union 62 | { 63 | T m[3][3]; 64 | T a[9]; 65 | }; 66 | }; 67 | 68 | struct Mtx34Base 69 | { 70 | union 71 | { 72 | T m[3][4]; 73 | T a[12]; 74 | }; 75 | }; 76 | 77 | struct Mtx44Base 78 | { 79 | union 80 | { 81 | T m[4][4]; 82 | T a[16]; 83 | }; 84 | }; 85 | }; 86 | 87 | } // namespace sead -------------------------------------------------------------------------------- /include/sead/seadNamable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "seadSafeString.h" 4 | 5 | namespace sead { 6 | 7 | class INamable 8 | { 9 | public: 10 | sead::SafeString mINamableName; 11 | }; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /include/sead/seadOffsetList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "seadListImpl.h" 4 | 5 | namespace sead { 6 | 7 | template 8 | class OffsetList : public ListImpl // size: 0x10 9 | { 10 | public: 11 | class iterator 12 | { 13 | public: 14 | iterator(T* ptr, s32 offset) 15 | : mPtr(ptr), mOffset(offset) { } 16 | 17 | bool operator==(const iterator& other) const 18 | { 19 | return mPtr == other.mPtr; 20 | } 21 | 22 | bool operator!=(const iterator& other) const 23 | { 24 | return !(*this == other); 25 | } 26 | 27 | iterator& operator++() 28 | { 29 | ListNode* node = reinterpret_cast(reinterpret_cast(mPtr) + mOffset)->mNext; 30 | mPtr = reinterpret_cast(reinterpret_cast(node) - mOffset); 31 | return *this; 32 | } 33 | 34 | T& operator*() const 35 | { 36 | return *mPtr; 37 | } 38 | 39 | T* operator->() const 40 | { 41 | return mPtr; 42 | } 43 | 44 | T* mPtr; 45 | s32 mOffset; 46 | }; 47 | 48 | iterator begin() const 49 | { 50 | return iterator(reinterpret_cast(reinterpret_cast(mStartEnd.mNext) - mOffset), mOffset); 51 | } 52 | 53 | iterator end() const 54 | { 55 | return iterator(reinterpret_cast(reinterpret_cast(const_cast(&mStartEnd)) - mOffset), mOffset); 56 | } 57 | 58 | s32 mOffset; // 0xC 59 | }; 60 | 61 | } 62 | -------------------------------------------------------------------------------- /include/sead/seadSafeString.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | namespace sead { 6 | 7 | 8 | template 9 | class SafeStringBase 10 | { 11 | public: 12 | SafeStringBase(const T* cstr = &cNullChar) : mStringTop(cstr) { } 13 | virtual ~SafeStringBase() { } 14 | virtual void assureTerminationImpl_() const { } 15 | 16 | inline const T* cstr() const 17 | { 18 | assureTerminationImpl_(); 19 | return mStringTop; 20 | } 21 | 22 | s32 findIndex(const SafeStringBase& token) const; 23 | s32 rfindIndex(const SafeStringBase& token) const; 24 | bool isEqual(const SafeStringBase& rhs) const; 25 | s32 comparen(const SafeStringBase& rhs, s32 n) const; 26 | const T& at(s32 idx) const; 27 | 28 | static const T cNullChar; 29 | 30 | protected: 31 | const T* mStringTop; 32 | }; 33 | 34 | 35 | template 36 | class BufferedSafeStringBase : public SafeStringBase 37 | { 38 | public: 39 | BufferedSafeStringBase(T* buffer, s32 size) 40 | : SafeStringBase(buffer) 41 | { 42 | this->mBufferSize = size; 43 | assureTerminationImpl_(); 44 | } 45 | 46 | ~BufferedSafeStringBase() { } 47 | 48 | void assureTerminationImpl_() const override 49 | { 50 | const_cast(this->mStringTop)[mBufferSize-1] = 0; 51 | } 52 | 53 | s32 format(const T* fmt, ...); 54 | void copy(const T* str, s32 maxLen = -1); 55 | 56 | s32 mBufferSize; 57 | }; 58 | 59 | 60 | template 61 | class FixedSafeStringBase : public BufferedSafeStringBase 62 | { 63 | public: 64 | FixedSafeStringBase() 65 | : BufferedSafeStringBase(mBuffer, L) 66 | { 67 | const_cast(this->mStringTop)[0] = 0; 68 | } 69 | 70 | FixedSafeStringBase(const T* str) 71 | : BufferedSafeStringBase(mBuffer, L) 72 | { 73 | this->copy(str); 74 | } 75 | 76 | ~FixedSafeStringBase() { } 77 | 78 | T mBuffer[L]; 79 | }; 80 | 81 | 82 | using SafeString = SafeStringBase; 83 | using WSafeString = SafeStringBase; 84 | 85 | using BufferedSafeString = BufferedSafeStringBase; 86 | using WBufferedSafeString = BufferedSafeStringBase; 87 | 88 | template 89 | using FixedSafeString = FixedSafeStringBase; 90 | template 91 | using WFixedSafeString = FixedSafeStringBase; 92 | 93 | } 94 | -------------------------------------------------------------------------------- /include/sead/seadSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | namespace sead { namespace system { 6 | 7 | void PrintString(const char* str, s32 len); 8 | void Print(const char* format, ...); 9 | void PrintV(const char* format, va_list list); 10 | 11 | void Warning(const char* pos, s32 line, const char* format, ...); 12 | void SetWarningEnable(bool enable); 13 | 14 | void Halt(); 15 | void HaltWithDetail(const char* pos, s32 line, const char* format, ...); 16 | void HaltWithDetailNoFormat(const char* pos, s32 line, const char* str); 17 | 18 | } } 19 | 20 | 21 | #define SEAD_WARNING(...) \ 22 | sead::system::Warning(__FILE__, __LINE__, __VA_ARGS__) 23 | 24 | #define SEAD_HALT_WITH_DETAIL(...) \ 25 | sead::system::HaltWithDetail(__FILE__, __LINE__, __VA_ARGS__) 26 | 27 | #define SEAD_HALT_WITH_DETAIL_NO_FORMAT(str) \ 28 | sead::system::HaltWithDetailNoFormat(__FILE__, __LINE__, str) 29 | 30 | #define SEAD_ASSERT(exp) \ 31 | (void) ((exp) || (SEAD_HALT_WITH_DETAIL_NO_FORMAT(#exp), 0)) 32 | 33 | #define SEAD_ASSERT_FMT(exp, ...) \ 34 | (void) ((exp) || (SEAD_HALT_WITH_DETAIL(__VA_ARGS__), 0)) 35 | -------------------------------------------------------------------------------- /include/state/FState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "state/FStateID.h" 4 | #include "state/IState.h" 5 | 6 | template 7 | class FState : public IState 8 | { 9 | public: 10 | FState(T& obj) : 11 | mObject(obj), mStateID(nullptr) {} 12 | 13 | T& getObject() const 14 | { 15 | return mObject; 16 | } 17 | 18 | const StateID* getStateID() const override 19 | { 20 | return mStateID; 21 | } 22 | 23 | void setStateID(const FStateID* stateID) 24 | { 25 | mStateID = stateID; 26 | } 27 | 28 | void initialize() 29 | { 30 | mStateID->initializeState(mObject); 31 | } 32 | 33 | void execute() override 34 | { 35 | mStateID->executeState(mObject); 36 | } 37 | 38 | void finalize() 39 | { 40 | mStateID->finalizeState(mObject); 41 | } 42 | 43 | protected: 44 | T& mObject; 45 | const FStateID* mStateID; 46 | }; -------------------------------------------------------------------------------- /include/state/FStateFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "state/FState.h" 4 | #include "state/IStateFactory.h" 5 | 6 | template 7 | class FStateFactory : public IStateFactory 8 | { 9 | public: 10 | FStateFactory(T& obj) : 11 | mState(obj) {} 12 | 13 | virtual ~FStateFactory() {} 14 | 15 | IState* buildWithInitialize(const StateID& stateId) override 16 | { 17 | mState.setStateID(static_cast*>(&stateId)); 18 | mState.initialize(); 19 | return &mState; 20 | } 21 | 22 | void disposeWithFinalize(IState*& state) override 23 | { 24 | mState.finalize(); 25 | mState.setStateID(nullptr); 26 | state = nullptr; 27 | } 28 | 29 | IState* build(const StateID& stateId) override 30 | { 31 | mState.setStateID(static_cast*>(&stateId)); 32 | return &mState; 33 | } 34 | 35 | void dispose(IState*& state) override 36 | { 37 | mState.setStateID(nullptr); 38 | state = nullptr; 39 | } 40 | 41 | void initializeState(IState* state) override 42 | { 43 | static_cast*>(state)->initialize(); 44 | } 45 | 46 | protected: 47 | FState mState; 48 | }; -------------------------------------------------------------------------------- /include/state/FStateID.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "state/StateID.h" 4 | 5 | template 6 | class FStateID : public StateID 7 | { 8 | public: 9 | using FuncPtr = void (T::*)(); 10 | 11 | public: 12 | FStateID(FuncPtr initialize, FuncPtr execute, FuncPtr finalize) : 13 | mInitialize(initialize), mExecute(execute), mFinalize(finalize) {} 14 | 15 | virtual ~FStateID() {} 16 | 17 | void initializeState(T& obj) const 18 | { 19 | (obj.*mInitialize)(); 20 | } 21 | 22 | void executeState(T& obj) const 23 | { 24 | (obj.*mExecute)(); 25 | } 26 | 27 | void finalizeState(T& obj) const 28 | { 29 | (obj.*mFinalize)(); 30 | } 31 | 32 | protected: 33 | FuncPtr mInitialize; 34 | FuncPtr mExecute; 35 | FuncPtr mFinalize; 36 | }; 37 | 38 | #define DECLARE_STATE_ID(CLASS, NAME) \ 39 | static FStateID StateID_##NAME; \ 40 | void initializeState_##NAME(); \ 41 | void executeState_##NAME(); \ 42 | void finalizeState_##NAME(); 43 | 44 | #define CREATE_STATE_ID(CLASS, NAME) \ 45 | FStateID CLASS::StateID_##NAME \ 46 | (&CLASS::initializeState_##NAME, \ 47 | &CLASS::executeState_##NAME, \ 48 | &CLASS::finalizeState_##NAME); 49 | -------------------------------------------------------------------------------- /include/state/FStateMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "state/FStateFactory.h" 4 | #include "state/StateMgr.h" 5 | 6 | template 7 | class FStateMgr : public StateMgr 8 | { 9 | public: 10 | FStateMgr(T& obj, const StateID& stateID = StateID::cNull) : 11 | StateMgr(obj, stateID) {} 12 | 13 | virtual ~FStateMgr() {} 14 | }; -------------------------------------------------------------------------------- /include/state/FStateStateMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "state/FStateFactory.h" 4 | #include "state/StateStateMgr.h" 5 | 6 | template 7 | class FStateStateMgr : public StateStateMgr 8 | { 9 | public: 10 | FStateStateMgr(T& obj, const StateID& stateID = StateID::cNull) : 11 | StateStateMgr(obj, stateID) {} 12 | 13 | virtual ~FStateStateMgr() {} 14 | }; -------------------------------------------------------------------------------- /include/state/FStateVirtualID.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "state/FStateID.h" 4 | 5 | template 6 | class FStateVirtualID : public FStateID 7 | { 8 | public: 9 | using FuncPtr = typename FStateID::FuncPtr; 10 | 11 | public: 12 | FStateVirtualID(FuncPtr initialize, FuncPtr execute, FuncPtr finalize, const StateID& baseID) : 13 | FStateID(initialize, execute, finalize), mBaseID(&baseID) {} 14 | 15 | virtual ~FStateVirtualID() {} 16 | 17 | s32 number() const override 18 | { 19 | if (!mBaseID->isNull()) 20 | return mBaseID->number(); 21 | 22 | return StateID::mNumber; 23 | } 24 | 25 | const StateID* superID() const 26 | { 27 | return mBaseID; 28 | } 29 | 30 | protected: 31 | const StateID* mBaseID; 32 | }; 33 | 34 | #define DECLARE_STATE_VIRTUAL_ID_BASE(CLASS, NAME) \ 35 | static FStateVirtualID StateID_##NAME; \ 36 | virtual void initializeState_##NAME(); \ 37 | virtual void executeState_##NAME(); \ 38 | virtual void finalizeState_##NAME(); 39 | 40 | #define DECLARE_STATE_VIRTUAL_ID_OVERRIDE(CLASS, NAME) \ 41 | static FStateVirtualID StateID_##NAME; \ 42 | void initializeState_##NAME() override; \ 43 | void executeState_##NAME() override; \ 44 | void finalizeState_##NAME() override; \ 45 | 46 | #define CREATE_STATE_VIRTUAL_ID_BASE(CLASS, NAME) \ 47 | FStateVirtualID CLASS::StateID_##NAME \ 48 | (&CLASS::initializeState_##NAME, \ 49 | &CLASS::executeState_##NAME, \ 50 | &CLASS::finalizeState_##NAME, \ 51 | StateID::cNull); 52 | 53 | #define CREATE_STATE_VIRTUAL_ID_OVERRIDE(CLASS, BASE, NAME) \ 54 | FStateVirtualID CLASS::StateID_##NAME \ 55 | (&CLASS::initializeState_##NAME, \ 56 | &CLASS::executeState_##NAME, \ 57 | &CLASS::finalizeState_##NAME, \ 58 | BASE::StateID_##NAME); 59 | -------------------------------------------------------------------------------- /include/state/IState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | class StateID; 6 | 7 | class IState 8 | { 9 | public: 10 | IState() {} 11 | 12 | virtual ~IState() {} 13 | 14 | virtual const StateID* getStateID() const = 0; 15 | virtual void execute() = 0; 16 | }; 17 | 18 | static_assert(sizeof(IState) == 4); -------------------------------------------------------------------------------- /include/state/IStateFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | class IState; 6 | class StateID; 7 | 8 | class IStateFactory 9 | { 10 | public: 11 | IStateFactory() {} 12 | 13 | virtual ~IStateFactory() {} 14 | 15 | virtual IState* buildWithInitialize(const StateID& stateId) = 0; 16 | virtual void disposeWithFinalize(IState*& state) = 0; 17 | virtual IState* build(const StateID& stateId) = 0; 18 | virtual void dispose(IState*& state) = 0; 19 | virtual void initializeState(IState* state) = 0; 20 | }; 21 | 22 | size_assert(IStateFactory, 4); -------------------------------------------------------------------------------- /include/state/StateID.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | // vtable: 0059ABE4 6 | class StateID 7 | { 8 | public: 9 | // Address: 0x005ED2A8 10 | static const StateID cNull; 11 | static const s32 cNullNumber = -1; 12 | 13 | public: 14 | StateID() 15 | { 16 | mNumber = ++sNumberMemo; 17 | } 18 | 19 | explicit StateID(s32 number) : 20 | mNumber(number) {} 21 | 22 | virtual ~StateID() {} 23 | 24 | // Address: 0x004B3514 25 | virtual s32 number() const 26 | { 27 | return mNumber; 28 | } 29 | 30 | bool isNull() const 31 | { 32 | return mNumber == cNullNumber; 33 | } 34 | 35 | bool isEqual(const StateID& rhs) const 36 | { 37 | return number() == rhs.number(); 38 | } 39 | 40 | bool operator==(const StateID& rhs) const 41 | { 42 | return isEqual(rhs); 43 | } 44 | 45 | bool operator!=(const StateID& rhs) const 46 | { 47 | return !isEqual(rhs); 48 | } 49 | 50 | protected: 51 | s32 mNumber; 52 | 53 | private: 54 | // Address: 0x00603360 55 | static s32 sNumberMemo; 56 | }; 57 | 58 | static_assert(sizeof(StateID) == 8); -------------------------------------------------------------------------------- /include/state/StateIDHolder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | class StateID; 6 | 7 | class StateIDHolder 8 | { 9 | public: 10 | StateIDHolder() 11 | { 12 | reset(); 13 | } 14 | 15 | void set(const StateID* stateID) 16 | { 17 | mStateID = stateID; 18 | } 19 | 20 | void reset() 21 | { 22 | mStateID = nullptr; 23 | } 24 | 25 | bool isSet() const 26 | { 27 | return mStateID != nullptr; 28 | } 29 | 30 | const StateID* get() const 31 | { 32 | return mStateID; 33 | } 34 | 35 | protected: 36 | const StateID* mStateID; 37 | }; 38 | 39 | size_assert(StateIDHolder, 4); -------------------------------------------------------------------------------- /include/state/StateMethod.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "state/IState.h" 4 | #include "state/IStateFactory.h" 5 | #include "state/StateID.h" 6 | 7 | class StateMethod 8 | { 9 | public: 10 | // Address: 0x00138800 11 | StateMethod(IStateFactory& factory, const StateID& stateID); 12 | 13 | void executeStateMethod() { executeStateLocalMethod_(); } 14 | 15 | // Address: 0x00138720 16 | void changeStateMethod(const StateID& stateID); 17 | 18 | IState* getState() const { return mState; } 19 | 20 | const StateID* getNewStateID() const { return mNewStateID; } 21 | 22 | // Address: 0x004855D0 23 | const StateID* getStateID() const; 24 | 25 | const StateID* getOldStateID() const { return mOldStateID; } 26 | 27 | protected: 28 | void initializeStateLocalMethod_(); 29 | // Address: 0x001387B0 30 | void executeStateLocalMethod_(); 31 | void finalizeStateLocalMethod_(); 32 | void changeStateLocalMethod_(); 33 | 34 | protected: 35 | IStateFactory& mFactory; 36 | const StateID* mNewStateID; 37 | IState* mState; 38 | const StateID* mOldStateID; 39 | }; 40 | 41 | size_assert(StateMethod, 0x10); 42 | 43 | inline void StateMethod::initializeStateLocalMethod_() 44 | { 45 | if (mNewStateID != nullptr) 46 | { 47 | mState = mFactory.buildWithInitialize(*mNewStateID); 48 | mNewStateID = nullptr; 49 | } 50 | } 51 | 52 | inline void StateMethod::finalizeStateLocalMethod_() 53 | { 54 | if (mState != nullptr && mNewStateID != nullptr) 55 | { 56 | mOldStateID = mState->getStateID(); 57 | mFactory.disposeWithFinalize(mState); 58 | } 59 | } 60 | 61 | inline void StateMethod::changeStateLocalMethod_() 62 | { 63 | finalizeStateLocalMethod_(); 64 | initializeStateLocalMethod_(); 65 | } -------------------------------------------------------------------------------- /include/state/StateMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "state/StateMethod.h" 4 | 5 | #define STATE_MGR_BASE_BODY(CLASS, METHOD) \ 6 | public: \ 7 | CLASS(T& obj, const StateID& stateID) : \ 8 | mFactory(obj), mMethod(mFactory, stateID) {} \ 9 | \ 10 | virtual ~CLASS() {} \ 11 | \ 12 | void executeState() \ 13 | { \ 14 | mMethod.executeStateMethod(); \ 15 | } \ 16 | \ 17 | void changeState(const StateID& stateID) \ 18 | { \ 19 | mMethod.changeStateMethod(stateID); \ 20 | } \ 21 | \ 22 | IState* getState() const \ 23 | { \ 24 | return mMethod.getState(); \ 25 | } \ 26 | \ 27 | const StateID* getNewStateID() const \ 28 | { \ 29 | return mMethod.getNewStateID(); \ 30 | } \ 31 | \ 32 | const StateID* getStateID() const \ 33 | { \ 34 | return mMethod.getStateID(); \ 35 | } \ 36 | \ 37 | const StateID* getOldStateID() const \ 38 | { \ 39 | return mMethod.getOldStateID(); \ 40 | } \ 41 | \ 42 | protected: \ 43 | Factory mFactory; \ 44 | METHOD mMethod; 45 | 46 | template class Factory> 47 | class StateMgr 48 | { 49 | STATE_MGR_BASE_BODY(StateMgr, StateMethod) 50 | }; -------------------------------------------------------------------------------- /include/state/StateStateMethod.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "state/StateIDHolder.h" 4 | #include "state/StateMethod.h" 5 | 6 | class StateStateMethod : public StateMethod 7 | { 8 | public: 9 | StateStateMethod(IStateFactory& factory, const StateID& stateID) : 10 | StateMethod(factory, stateID) {} 11 | 12 | void changeToSubStateMethod(const StateID& stateID) 13 | { 14 | mMain.set(getStateID()); 15 | mOldStateID = mState->getStateID(); 16 | mFactory.dispose(mState); 17 | mState = mFactory.buildWithInitialize(stateID); 18 | } 19 | 20 | bool isSubStateMethod() const 21 | { 22 | return mMain.isSet(); 23 | } 24 | 25 | void returnStateMethod() 26 | { 27 | mOldStateID = mState->getStateID(); 28 | mFactory.disposeWithFinalize(mState); 29 | const StateID& mainStateID = *(mMain.get()); 30 | mMain.reset(); 31 | mState = mFactory.build(mainStateID); 32 | } 33 | 34 | void replaceStateMethod(const StateID& stateID) 35 | { 36 | mFactory.disposeWithFinalize(mState); 37 | mState = mFactory.buildWithInitialize(stateID); 38 | } 39 | 40 | const StateID* getMainStateID() const 41 | { 42 | const StateID* stateID = mMain.get(); 43 | if (stateID == nullptr) 44 | stateID = getStateID(); 45 | return stateID; 46 | } 47 | 48 | protected: 49 | StateIDHolder mMain; 50 | }; 51 | 52 | size_assert(StateStateMethod, 0x14); -------------------------------------------------------------------------------- /include/state/StateStateMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "state/StateStateMethod.h" 4 | #include "state/StateMgr.h" 5 | 6 | template class Factory> 7 | class StateStateMgr 8 | { 9 | STATE_MGR_BASE_BODY(StateStateMgr, StateStateMethod) 10 | 11 | public: 12 | void changeToSubState(const StateID& stateID) 13 | { 14 | mMethod.changeToSubStateMethod(stateID); 15 | } 16 | 17 | bool isSubState() const 18 | { 19 | return mMethod.isSubStateMethod(); 20 | } 21 | 22 | void returnState() 23 | { 24 | mMethod.returnStateMethod(); 25 | } 26 | 27 | void replaceState(const StateID& stateID) 28 | { 29 | mMethod.replaceStateMethod(stateID); 30 | } 31 | 32 | const StateID* getMainStateID() const 33 | { 34 | return mMethod.getMainStateID(); 35 | } 36 | }; -------------------------------------------------------------------------------- /include/sys/Allocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | #include "sead/heap/seadHeap.h" 6 | #include "sead/basis/seadNew.h" 7 | 8 | // TODO: Move these 9 | extern sead::Heap* SystemHeap; 10 | extern sead::Heap* ActorHeap; 11 | extern sead::Heap* ModelResourceHeap; 12 | extern sead::Heap* ModelSetupHeap; 13 | extern sead::Heap* BgUnitHeap; 14 | extern sead::Heap* CourseHeap; 15 | extern sead::Heap* AreaHeap; 16 | extern sead::Heap* SeadParticleHeap; 17 | extern sead::Heap* FontHeap; 18 | extern sead::Heap* SaveHeap; 19 | extern sead::Heap* UIHeap; 20 | extern sead::Heap* SoundResourceHeap; 21 | extern sead::Heap* SoundHeap; 22 | extern sead::Heap* NetHeap; 23 | extern sead::Heap* WorkHeap; 24 | extern sead::Heap* DebugHeap; 25 | 26 | 27 | class Allocator 28 | { 29 | public: 30 | virtual void unk00(); // 004B39CC 31 | 32 | virtual void* alloc(size_t size, u8 align) = 0; 33 | virtual void* free(void* memblock) = 0; 34 | }; 35 | 36 | 37 | /* There is a class between these two. dtor at 0x47EAD8 */ 38 | 39 | class HeapAllocator : public Allocator // vtable: 005D35CC 40 | { 41 | public: 42 | HeapAllocator(); // 0010A210 43 | void unk00(); // 0047EAD8 Not sure if dtor or not. It's NOPed. 44 | 45 | void* alloc(size_t size, u8 align); // 0047EABC 46 | void* free(void* memblock); // 0047EAAC 47 | 48 | bool link(sead::Heap* heap); // 0010A204 49 | 50 | sead::Heap* heap; 51 | }; 52 | -------------------------------------------------------------------------------- /include/sys/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | // Clean this mess up eventually... 5 | 6 | #include "math/Calc.h" 7 | #include "math/Mtx34.h" 8 | #include "math/Vec.h" 9 | 10 | struct Color8 11 | { 12 | Color8(u8 r = 0, u8 g = 0, u8 b = 0, u8 a = 0xFF) : 13 | r(r), g(g), b(b), a(a) { } 14 | 15 | u8 r; 16 | u8 g; 17 | u8 b; 18 | u8 a; 19 | 20 | u16 rgb565() 21 | { 22 | return ((r & 0b11111000) << 8) | ((g & 0b11111100) << 3) | (b >> 3); 23 | } 24 | }; 25 | 26 | struct ColorF32 27 | { 28 | f32 r; 29 | f32 g; 30 | f32 b; 31 | f32 a; 32 | }; 33 | 34 | // Misc 35 | 36 | void playSfx(u32 id, const Vec3f& pos, u32 unk = 1); 37 | void playSfx(const char* name, const Vec3f& pos, u32 unk = 1); 38 | void playSfxWhileCalled(u32 id, u32 unk, const Vec3f& pos); // unk always set to actor id 39 | 40 | void spawnEffect(u32 id, const Vec3f& pos, Vec3i* rotation = nullptr, Vec3f* scale = nullptr); 41 | 42 | bool smoothRotation(s32& rotation, const s32& destination, const s32& amount); 43 | bool moveTowards(Vec3f& position, const Vec3f& destination, f32 speed); 44 | -------------------------------------------------------------------------------- /include/sys/LineNodeMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead.h" 4 | 5 | template 6 | class LineNodeMgr 7 | { 8 | public: 9 | struct Node 10 | { 11 | Node(T* obj_) 12 | : obj(obj_) 13 | , next(nullptr) 14 | , prev(nullptr) 15 | {} 16 | 17 | T* obj; 18 | Node* next; 19 | Node* prev; 20 | }; 21 | 22 | size_assert(Node, 0xC); 23 | 24 | public: 25 | LineNodeMgr() 26 | : mpHead(nullptr) 27 | , mpTail(nullptr) 28 | {} 29 | 30 | Node* front() const 31 | { 32 | return mpHead; 33 | } 34 | 35 | Node* back() const 36 | { 37 | return mpTail; 38 | } 39 | 40 | bool contains(const Node* node) const 41 | { 42 | if (node == nullptr) 43 | return false; 44 | 45 | return node->next != nullptr || node->prev != nullptr || node == mpHead; 46 | } 47 | 48 | void insertAfter(Node* node, Node* basis) 49 | { 50 | if (basis == nullptr) 51 | { 52 | pushFront(node); 53 | return; 54 | } 55 | 56 | if (node == nullptr) 57 | return; 58 | 59 | node->next = basis->next; 60 | node->prev = basis; 61 | basis->next = node; 62 | 63 | if (node->next != nullptr) 64 | node->next->prev = node; 65 | 66 | if (node->next == nullptr) 67 | mpTail = node; 68 | } 69 | 70 | void erase(Node* node) 71 | { 72 | if (node == nullptr) 73 | return; 74 | 75 | if (node->prev != nullptr) 76 | node->prev->next = node->next; 77 | 78 | else if (node == mpHead) 79 | mpHead = node->next; 80 | 81 | if (node->next != nullptr) 82 | node->next->prev = node->prev; 83 | 84 | else if (node == mpTail) 85 | mpTail = node->prev; 86 | 87 | node->next = nullptr; 88 | node->prev = nullptr; 89 | } 90 | 91 | void pushBack(Node* node) 92 | { 93 | if (node == nullptr) 94 | return; 95 | 96 | if (mpTail != nullptr) 97 | { 98 | mpTail->next = node; 99 | node->prev = mpTail; 100 | } 101 | else 102 | { 103 | mpHead = node; 104 | } 105 | 106 | mpTail = node; 107 | } 108 | 109 | void pushFront(Node* node) 110 | { 111 | if (node == nullptr) 112 | return; 113 | 114 | if (mpHead != nullptr) 115 | { 116 | mpHead->prev = node; 117 | node->next = mpHead; 118 | } 119 | else 120 | { 121 | mpTail = node; 122 | } 123 | 124 | mpHead = node; 125 | } 126 | 127 | void clear() 128 | { 129 | while (mpHead != nullptr) 130 | erase(mpHead); 131 | } 132 | 133 | protected: 134 | Node* mpHead; 135 | Node* mpTail; 136 | }; 137 | 138 | size_assert(LineNodeMgr, 0x8); 139 | -------------------------------------------------------------------------------- /include/sys/PersistentDataMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead.h" 4 | 5 | 6 | class PersistentDataMgr : public sead::IDisposer 7 | { 8 | public: 9 | static PersistentDataMgr* instance; 10 | 11 | u16 get(f32 x, f32 y); 12 | void set(f32 x, f32 y, u16 data); 13 | }; 14 | -------------------------------------------------------------------------------- /include/sys/Preprocessor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Concatenates both arguments 4 | #define PP_CONCAT(x, y) x##y 5 | 6 | 7 | #define PP_ARG_N( \ 8 | _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, \ 9 | _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ 10 | _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ 11 | _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, \ 12 | _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, \ 13 | _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, \ 14 | _60, _61, _62, _63, _64, N, ...) N 15 | 16 | #define PP_RSEQ \ 17 | 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, \ 18 | 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, \ 19 | 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, \ 20 | 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, \ 21 | 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, \ 22 | 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, \ 23 | 4, 3, 2, 1, 0 24 | 25 | 26 | // Returns number of arguments (range: 0-64) 27 | #define PP_NARG(...) \ 28 | PP_NARG_(0, ## __VA_ARGS__, PP_RSEQ) 29 | 30 | #define PP_NARG_(...) \ 31 | PP_ARG_N(__VA_ARGS__) 32 | 33 | 34 | // foreach for specific argument counts 35 | #define PP_FOR_EACH_0(M, X, ...) 36 | #define PP_FOR_EACH_1(M, X, ...) M(X) 37 | #define PP_FOR_EACH_2(M, X, ...) M(X) PP_FOR_EACH_1(M, __VA_ARGS__) 38 | #define PP_FOR_EACH_3(M, X, ...) M(X) PP_FOR_EACH_2(M, __VA_ARGS__) 39 | #define PP_FOR_EACH_4(M, X, ...) M(X) PP_FOR_EACH_3(M, __VA_ARGS__) 40 | #define PP_FOR_EACH_5(M, X, ...) M(X) PP_FOR_EACH_4(M, __VA_ARGS__) 41 | #define PP_FOR_EACH_6(M, X, ...) M(X) PP_FOR_EACH_5(M, __VA_ARGS__) 42 | #define PP_FOR_EACH_7(M, X, ...) M(X) PP_FOR_EACH_6(M, __VA_ARGS__) 43 | #define PP_FOR_EACH_8(M, X, ...) M(X) PP_FOR_EACH_7(M, __VA_ARGS__) 44 | #define PP_FOR_EACH_9(M, X, ...) M(X) PP_FOR_EACH_8(M, __VA_ARGS__) 45 | #define PP_FOR_EACH_10(M, X, ...) M(X) PP_FOR_EACH_9(M, __VA_ARGS__) 46 | #define PP_FOR_EACH_11(M, X, ...) M(X) PP_FOR_EACH_10(M, __VA_ARGS__) 47 | #define PP_FOR_EACH_12(M, X, ...) M(X) PP_FOR_EACH_11(M, __VA_ARGS__) 48 | #define PP_FOR_EACH_13(M, X, ...) M(X) PP_FOR_EACH_12(M, __VA_ARGS__) 49 | #define PP_FOR_EACH_14(M, X, ...) M(X) PP_FOR_EACH_13(M, __VA_ARGS__) 50 | #define PP_FOR_EACH_15(M, X, ...) M(X) PP_FOR_EACH_14(M, __VA_ARGS__) 51 | #define PP_FOR_EACH_16(M, X, ...) M(X) PP_FOR_EACH_15(M, __VA_ARGS__) 52 | 53 | // foreach with argument count as first argument (range: 0-16) 54 | #define PP_FOR_EACH_N(N, M, ...) \ 55 | PP_CONCAT(PP_FOR_EACH_, N)(M, __VA_ARGS__) 56 | 57 | // Applies M to all arguments (count range: 0-16) 58 | #define PP_FOR_EACH(M, ...) \ 59 | PP_FOR_EACH_N(PP_NARG(__VA_ARGS__), M, __VA_ARGS__) 60 | -------------------------------------------------------------------------------- /include/sys/ResourceMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sead.h" 4 | #include "nw/gfx/res/ResGraphicsFile.h" 5 | 6 | class Resource 7 | { 8 | public: 9 | u32 vtable; 10 | void* data; // points to the raw bcres data 11 | nw::gfx::res::ResGraphicsFile bcres; 12 | // more 13 | }; 14 | 15 | class ResourceMgr 16 | { 17 | public: 18 | static ResourceMgr* instance; 19 | 20 | Resource* getResource(const sead::SafeString& key); 21 | 22 | bool loadFile(const sead::SafeString& file, u32 unk1, u32 unk2, u32 unk3, bool unk4); 23 | bool loadFile2(const sead::SafeString& file, u32 unk1, u32 unk2, u32 unk3, bool unk4, const sead::SafeString& unk = ""); 24 | bool unloadFile(const sead::SafeString& file); 25 | }; 26 | 27 | class WorldmapResourceMgr 28 | { 29 | public: 30 | static WorldmapResourceMgr* instance; 31 | 32 | Resource* getResource(const sead::SafeString& key); 33 | bool load(const sead::SafeString& name, u32 unk1 = 0x20000, u32 unk2 = 0x30000); 34 | 35 | static const sead::SafeString commonResources[]; 36 | static const u32 commonResourceCount; 37 | 38 | static const sead::SafeString worldSpecificResources[9][0x10]; 39 | static const u32 worldSpecificResourceCounts[9]; 40 | }; 41 | -------------------------------------------------------------------------------- /include/sys/Svc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | #include "nn/result.h" 5 | #include "nn/handle.h" 6 | 7 | enum UserBreakType 8 | { 9 | USERBREAK_PANIC = 0, 10 | USERBREAK_ASSERT = 1, 11 | USERBREAK_USER = 2, 12 | USERBREAK_LOAD_RO = 3, 13 | USERBREAK_UNLOAD_RO = 4 14 | }; 15 | 16 | extern "C" 17 | { 18 | nn::Result svcCloseHandle(nn::Handle handle); // 23 19 | u64 svcGetSystemTick(); // 28 20 | nn::Result svcSendSyncRequest(nn::Handle handle); // 32 21 | void svcBreak(UserBreakType breakReason); // 3C 22 | nn::Result svcOutputDebugString(const char* str, s32 length); // 3D 23 | } 24 | -------------------------------------------------------------------------------- /include/sys/clib/ctype.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | int tolower(int c); 8 | 9 | #ifdef __cplusplus 10 | } 11 | #endif 12 | -------------------------------------------------------------------------------- /include/sys/clib/math.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #define M_E 2.7182818284590452354 // e 8 | #define M_LOG2E 1.4426950408889634074 // log_2 e 9 | #define M_LOG10E 0.43429448190325182765 // log_10 e 10 | #define M_LN2 0.69314718055994530942 // log_e 2 11 | #define M_LN10 2.30258509299404568402 // log_e 10 12 | #define M_PI 3.14159265358979323846 // pi 13 | #define M_PI_2 1.57079632679489661923 // pi/2 14 | #define M_PI_4 0.78539816339744830962 // pi/4 15 | #define M_1_PI 0.31830988618379067154 // 1/pi 16 | #define M_2_PI 0.63661977236758134308 // 2/pi 17 | #define M_2_SQRTPI 1.12837916709551257390 // 2/sqrt(pi) 18 | #define M_SQRT2 1.41421356237309504880 // sqrt(2) 19 | #define M_SQRT1_2 0.70710678118654752440 // 1/sqrt(2) 20 | 21 | float sinf(float x); 22 | float cosf(float x); 23 | float tanf(float x); 24 | float acosf(float x); 25 | float atan2f(float y, float x); 26 | float fmodf(float x, float d); 27 | float powf(float b, float e); 28 | 29 | inline float absf(float x) { return (x >= 0) ? x : -x; } 30 | 31 | inline float sqrtf(float x) 32 | { 33 | float result; 34 | asm("vsqrt.f32 %0, %1" : "=w" (result) : "w" (x)); 35 | return result; 36 | } 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /include/sys/clib/stdarg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define va_start(v,l) __builtin_va_start(v,l) 4 | #define va_end(v) __builtin_va_end(v) 5 | typedef __builtin_va_list va_list; 6 | -------------------------------------------------------------------------------- /include/sys/clib/stddef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #ifndef NULL 8 | #define NULL 0 9 | #endif 10 | 11 | #ifndef offsetof 12 | #define offsetof(t, d) __builtin_offsetof(t, d) 13 | #endif 14 | 15 | typedef unsigned int size_t; 16 | typedef int ptrdiff_t; 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | -------------------------------------------------------------------------------- /include/sys/clib/stdio.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #ifndef NULL 10 | #define NULL 0 11 | #endif 12 | 13 | typedef unsigned int size_t; 14 | 15 | int vsnprintf(char* buffer, size_t n, const char* format, va_list arg); 16 | int snprintf(char* buffer, size_t n, const char* format, ...); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | -------------------------------------------------------------------------------- /include/sys/clib/stdlib.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | int atoi(const char* str); 8 | long strtol(const char* str, char** strEnd, int base); 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | -------------------------------------------------------------------------------- /include/sys/clib/string.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | typedef unsigned int size_t; 8 | 9 | void* memcpy(void* dest, const void* src, size_t num); 10 | void* memclr(void* ptr, size_t num); 11 | void* memset(void* ptr, int c, size_t n); 12 | 13 | int strcmp(const char* str1, const char* str2); 14 | int strncmp(const char* str1, const char* str2, size_t n); 15 | char* strcpy(char* dst, const char* src); 16 | char* strncpy(char* dst, const char* src, size_t n); 17 | int strlen(const char* str); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | -------------------------------------------------------------------------------- /include/sys/clib/wchar.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | typedef unsigned int size_t; 8 | typedef signed short wchar_t; /* fix this */ 9 | 10 | wchar_t* wcscpy(wchar_t* dst, const wchar_t* src); 11 | wchar_t* wcsncpy(wchar_t* dst, const wchar_t* src, size_t n); 12 | size_t wcslen(const wchar_t* wcs); 13 | int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n); 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | -------------------------------------------------------------------------------- /include/types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | typedef unsigned char u8; 7 | typedef unsigned short u16; 8 | typedef unsigned int u32; 9 | typedef unsigned long long u64; 10 | 11 | typedef signed char s8; 12 | typedef signed short s16; 13 | typedef signed int s32; 14 | typedef signed long long s64; 15 | 16 | typedef char char8; 17 | typedef wchar_t char16; 18 | 19 | typedef float f32; 20 | typedef double f64; 21 | 22 | 23 | enum Direction : u8 24 | { 25 | RIGHT = 0, 26 | LEFT = 1, 27 | UP = 2, 28 | DOWN = 3, 29 | }; 30 | 31 | 32 | typedef struct 33 | { 34 | s32 offset; 35 | 36 | void* ptr() 37 | { 38 | if (offset == 0) return nullptr; 39 | u8* ret = reinterpret_cast(this); 40 | return (ret + offset); 41 | } 42 | 43 | } Offset; 44 | 45 | template 46 | struct TOffset : public Offset 47 | { 48 | T* ptr() 49 | { 50 | return reinterpret_cast(Offset::ptr()); 51 | } 52 | 53 | T& operator*() 54 | { 55 | return *ptr(); 56 | } 57 | 58 | T* operator->() 59 | { 60 | return ptr(); 61 | } 62 | }; 63 | 64 | #define array_length(arr) \ 65 | (sizeof(arr) / sizeof((arr)[0])) 66 | 67 | #define array_length_assert(arr, size) \ 68 | static_assert(array_length(arr) == size, "array_length(" #arr ") must be " #size); 69 | 70 | #define size_assert(type, size) \ 71 | static_assert(sizeof(type) == size, "sizeof(" #type ") must be " #size); 72 | 73 | #define offset_assert(type, member, offset) \ 74 | static_assert(offsetof(type, member) == offset, "offsetof(" #type ", " #member ") must be " #offset); 75 | -------------------------------------------------------------------------------- /loader/source/hooks.hks: -------------------------------------------------------------------------------- 1 | LoaderEntryPoint: 2 | type: softbranch 3 | opcode: post 4 | func: LoaderMain 5 | addr: 0x00100000 6 | -------------------------------------------------------------------------------- /loader/source/loader.c: -------------------------------------------------------------------------------- 1 | #include "newcodeinfo.h" // Automatically generated 2 | 3 | typedef signed int s32; 4 | typedef unsigned int u32; 5 | 6 | typedef s32 Result; 7 | typedef u32 Handle; 8 | 9 | Result svcOpenProcess(Handle* process, u32 processId); 10 | Result svcGetProcessId(u32* out, Handle handle); 11 | void svcBreak(u32 breakReason); 12 | Result svcControlProcessMemory(Handle process, u32 addr0, u32 addr1, u32 size, u32 type, u32 perm); 13 | 14 | Handle getCurrentProcessHandle(); 15 | 16 | void LoaderMain() 17 | { 18 | Result res; 19 | 20 | u32 address = NEWCODE_OFFSET; 21 | u32 neededMemory = (NEWCODE_SIZE + 0xFFF) & ~0xFFF; // Dunno if rounding this up is needed 22 | 23 | Handle processHandle = getCurrentProcessHandle(); 24 | 25 | // Reprotect custom code as RWX 26 | res = svcControlProcessMemory(processHandle, address, address, neededMemory, 6, 7); 27 | if (res < 0) 28 | svcBreak(1); 29 | 30 | // Reprotect rodata as RW 31 | res = svcControlProcessMemory(processHandle, 0x0056B000, 0x0056B000, 0x70000, 6, 3); 32 | if (res < 0) 33 | svcBreak(1); 34 | } 35 | 36 | 37 | Handle getCurrentProcessHandle() 38 | { 39 | Handle handle = 0; 40 | u32 currentPid = 0; 41 | Result res; 42 | 43 | svcGetProcessId(¤tPid, 0xffff8001); 44 | res = svcOpenProcess(&handle, currentPid); 45 | 46 | if (res != 0) 47 | return 0; 48 | 49 | return handle; 50 | } 51 | -------------------------------------------------------------------------------- /loader/source/newcodeinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef NEWCODEINFO_H 2 | #define NEWCODEINFO_H 3 | 4 | #define NEWCODE_OFFSET 0x006c5000 5 | #define NEWCODE_SIZE 0x00006100 6 | 7 | #endif // NEWCODEINFO_H 8 | -------------------------------------------------------------------------------- /loader/source/svc.s: -------------------------------------------------------------------------------- 1 | .arm 2 | .align 4 3 | 4 | .macro SVC_BEGIN name 5 | .section .text.\name, "ax", %progbits 6 | .global \name 7 | .type \name, %function 8 | .align 2 9 | .cfi_startproc 10 | \name: 11 | .endm 12 | 13 | .macro SVC_END 14 | .cfi_endproc 15 | .endm 16 | 17 | SVC_BEGIN svcOpenProcess 18 | push {r0} 19 | svc 0x33 20 | pop {r2} 21 | str r1, [r2] 22 | bx lr 23 | SVC_END 24 | 25 | SVC_BEGIN svcGetProcessId 26 | str r0, [sp, #-0x4]! 27 | svc 0x35 28 | ldr r3, [sp], #4 29 | str r1, [r3] 30 | bx lr 31 | SVC_END 32 | 33 | SVC_BEGIN svcBreak 34 | svc 0x3C 35 | bx lr 36 | SVC_END 37 | 38 | SVC_BEGIN svcControlProcessMemory 39 | push {r4-r5} 40 | ldr r4, [sp, #0x8] 41 | ldr r5, [sp, #0xC] 42 | svc 0x70 43 | pop {r4-r5} 44 | bx lr 45 | SVC_END 46 | -------------------------------------------------------------------------------- /source/Startup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GCC generates a table for us with function pointers that initialize global object. As we config 3 | * our linker to "bare metal" we need to implement this function on our own. We just have to add 4 | * correct symbols to our linker script and we have to insert a hook to this of course. 5 | */ 6 | 7 | typedef void (*InitFunc)(void); 8 | extern InitFunc __init_array_start; 9 | extern InitFunc __init_array_end; 10 | 11 | void static_init() 12 | { 13 | for (InitFunc* p = &__init_array_start; p < &__init_array_end; p++) 14 | (*p)(); 15 | } 16 | 17 | 18 | /* 19 | * This function registers global objects in C++. On program exit dtors are then called for these. 20 | * NSMB2 should have one but at the expected position there is just a NOP. Unless we do something 21 | * very memory critical just ignoring these should work out for now. 22 | * Just keep in mind that your static variables might not be destructed for now. 23 | */ 24 | void __aeabi_atexit(void* object, void (*dtor)(void* this), void* handle) { } 25 | 26 | unsigned int __dso_handle = 0xDEADC0DE; 27 | 28 | 29 | /* 30 | * Just like global objects, NSMB2 also does not destruct local static variables. 31 | */ 32 | void __cxa_guard_release(int* guardObject) { } 33 | -------------------------------------------------------------------------------- /source/Thumb_Thunk_asm.s: -------------------------------------------------------------------------------- 1 | .arm 2 | 3 | .macro thumb_thunk name address 4 | .global \name 5 | \name: 6 | push {r4, lr} 7 | ldr r4, =(\address+1) 8 | blx r4 9 | pop {r4, pc} 10 | .endm 11 | 12 | thumb_thunk vsnprintf 0x00100048 13 | thumb_thunk __cxa_guard_acquire 0x00100492 14 | thumb_thunk tolower 0x001006C4 15 | thumb_thunk atoi 0x00100764 16 | thumb_thunk strtol 0x00100780 17 | thumb_thunk wcscpy 0x001009F4 18 | thumb_thunk wcsncpy 0x00100A06 19 | thumb_thunk wcsncmp 0x00100A22 20 | thumb_thunk wcslen 0x00100A4A 21 | thumb_thunk __cxa_pure_virtual 0x00100ECE 22 | -------------------------------------------------------------------------------- /source/actors/ActorBase.cpp: -------------------------------------------------------------------------------- 1 | #include "actors/ActorBase.h" 2 | 3 | #include "gfx/AnimModel.h" 4 | 5 | void ActorBase::updateModelMatrixWithOffset(Model* model) 6 | { 7 | if (!model) 8 | return; 9 | 10 | Mtx34 mtx, offsetMtx; 11 | 12 | mtx.identity(); 13 | mtx.translate(position.x, position.y, position.z); 14 | mtx.rotateY(rotation.y); 15 | 16 | offsetMtx.identity(); 17 | offsetMtx.translateY(centerOffset.y); 18 | Mtx34::multiply(&mtx, mtx, offsetMtx); 19 | 20 | mtx.rotateX(rotation.x); 21 | 22 | offsetMtx.identity(); 23 | offsetMtx.translateY(-centerOffset.y); 24 | Mtx34::multiply(&mtx, mtx, offsetMtx); 25 | 26 | mtx.rotateZ(rotation.z); 27 | 28 | model->setScale(scale); 29 | model->setDrawMatrix(&mtx); 30 | model->update(); 31 | } 32 | 33 | void ActorBase::updateModelMatrixWithOffset(AnimModelBase* model) 34 | { 35 | if (!model) 36 | return; 37 | 38 | model->updateAnimation(); 39 | updateModelMatrixWithOffset(static_cast(model)); 40 | } 41 | 42 | 43 | void ActorBase::updateModelMatrix(Model* model) 44 | { 45 | if (!model) 46 | return; 47 | 48 | Mtx34 mtx; 49 | mtx.setRotationAndTranslation(rotation, position); 50 | 51 | model->setScale(scale); 52 | model->setDrawMatrix(&mtx); 53 | model->update(); 54 | } 55 | 56 | void ActorBase::updateModelMatrix(AnimModelBase* model) 57 | { 58 | if (!model) 59 | return; 60 | 61 | model->updateAnimation(); 62 | updateModelMatrix(static_cast(model)); 63 | } 64 | -------------------------------------------------------------------------------- /source/course/CourseSpriteMgr_asm.s: -------------------------------------------------------------------------------- 1 | .arm 2 | .fpu vfpv2 3 | 4 | 5 | .global CourseSpriteMgr_spriteToProfileIds_r1 6 | CourseSpriteMgr_spriteToProfileIds_r1: 7 | ldr r1, =_ZN15CourseSpriteMgr18spriteToProfileIdsE 8 | bx lr 9 | 10 | .global CourseSpriteMgr_spriteToProfileIds_r3 11 | CourseSpriteMgr_spriteToProfileIds_r3: 12 | ldr r3, =_ZN15CourseSpriteMgr18spriteToProfileIdsE 13 | bx lr 14 | 15 | .global CourseSpriteMgr_spriteToProfileIds_r10 16 | CourseSpriteMgr_spriteToProfileIds_r10: 17 | ldr r10, =_ZN15CourseSpriteMgr18spriteToProfileIdsE 18 | bx lr 19 | 20 | .global CourseSpriteMgr_spriteToProfileIds_r11 21 | CourseSpriteMgr_spriteToProfileIds_r11: 22 | ldr r11, =_ZN15CourseSpriteMgr18spriteToProfileIdsE 23 | bx lr 24 | 25 | 26 | .global CourseSpriteMgr_spriteCount_r9 27 | CourseSpriteMgr_spriteCount_r9: 28 | ldr r9, =_ZN15CourseSpriteMgr11spriteCountE 29 | bx lr 30 | -------------------------------------------------------------------------------- /source/course/Profiles_asm.s: -------------------------------------------------------------------------------- 1 | .text 2 | .align 4 3 | 4 | .global ProfileResTableR0 5 | ProfileResTableR0: 6 | ldr r0, =ResTable 7 | bx lr 8 | 9 | .global ProfileResTableR2 10 | ProfileResTableR2: 11 | ldr r2, =ResTable 12 | bx lr 13 | 14 | .global ProfileResTableR9 15 | ProfileResTableR9: 16 | ldrgt r9, =ResTable 17 | bx lr 18 | 19 | 20 | .global ProfileSoundActorKindsR7 21 | ProfileSoundActorKindsR7: 22 | ldr r7, =ProfileSoundActorKinds 23 | bx lr 24 | 25 | 26 | .global ActorInfosR0 27 | ActorInfosR0: 28 | ldr r0, =ActorInfos 29 | bx lr 30 | 31 | .global ActorInfosR1 32 | ActorInfosR1: 33 | ldr r1, =ActorInfos 34 | bx lr 35 | 36 | .global ActorInfosR2 37 | ActorInfosR2: 38 | ldr r2, =ActorInfos 39 | bx lr 40 | 41 | .global ActorInfosR4 42 | ActorInfosR4: 43 | ldr r4, =ActorInfos 44 | bx lr 45 | 46 | .global ActorInfosR10 47 | ActorInfosR10: 48 | ldr r10, =ActorInfos 49 | bx lr 50 | 51 | .global ActorInfosR11 52 | ActorInfosR11: 53 | ldr r11, =ActorInfos 54 | bx lr 55 | 56 | .global ActorInfosR2S 57 | ActorInfosR2S: 58 | ldr r2, =ActorInfos 59 | b 0x00403784 60 | 61 | 62 | .global NumProfiles2R0 63 | NumProfiles2R0: 64 | ldr r0, =numProfiles2 65 | bx lr 66 | 67 | .global NumProfiles2R8 68 | NumProfiles2R8: 69 | ldr r8, =numProfiles2 70 | bx lr 71 | -------------------------------------------------------------------------------- /source/math/Interpolation.cpp: -------------------------------------------------------------------------------- 1 | #include "math/Interpolation.h" 2 | 3 | #include "Common.h" 4 | 5 | bool directedSmoothRotation(s32& rotation, const s32& destination, const s32& amount) 6 | { 7 | if (rotation == destination) 8 | return true; 9 | 10 | bool positive = amount > 0; 11 | s32 newRotation = rotation + amount; 12 | 13 | bool willWrapAround = (positive && destination < rotation) || (!positive && rotation < destination); 14 | 15 | if (!willWrapAround) 16 | { 17 | if (positive) 18 | rotation = Mathf::min(destination, newRotation); 19 | else 20 | rotation = Mathf::max(destination, newRotation); 21 | } 22 | else 23 | rotation = newRotation; 24 | 25 | return (rotation == destination); 26 | } 27 | 28 | bool directedSmoothRotation(Vec2i& rotation, const Vec2i& destination, const Vec2i& amount) 29 | { 30 | bool xComplete = directedSmoothRotation(rotation.x, destination.x, amount.x); 31 | bool yComplete = directedSmoothRotation(rotation.y, destination.y, amount.y); 32 | return xComplete && yComplete; 33 | } 34 | 35 | bool directedSmoothRotation(Vec3i& rotation, const Vec3i& destination, const Vec3i& amount) 36 | { 37 | bool xComplete = directedSmoothRotation(rotation.x, destination.x, amount.x); 38 | bool yComplete = directedSmoothRotation(rotation.y, destination.y, amount.y); 39 | bool zComplete = directedSmoothRotation(rotation.z, destination.z, amount.z); 40 | return xComplete && yComplete && zComplete; 41 | } 42 | 43 | 44 | bool moveValueTowardsTarget(s32& value, const s32& target, s32 speed) 45 | { 46 | if (value != target) 47 | { 48 | if ((target < value && speed > 0) || (value < target && speed < 0)) 49 | speed *= 0; 50 | 51 | if (speed < 0) 52 | value = Mathf::max(target, value + speed); 53 | else 54 | value = Mathf::min(target, value + speed); 55 | } 56 | 57 | return (value == target); 58 | } 59 | 60 | bool moveValueTowardsTarget(f32& value, const f32& target, f32 speed) 61 | { 62 | if (!Mathf::equalsEpsilon(value, target)) 63 | { 64 | if ((target < value && speed > 0.0f) || (value < target && speed < 0.0f)) 65 | speed *= -1.0f; 66 | 67 | if (speed < 0.0f) 68 | value = Mathf::max(target, value + speed); 69 | else 70 | value = Mathf::min(target, value + speed); 71 | } 72 | 73 | return Mathf::equalsEpsilon(value, target); 74 | } 75 | 76 | bool moveValueTowardsTarget(Vec2f& value, const Vec2f& target, const Vec2f& speed) 77 | { 78 | bool xComplete = moveValueTowardsTarget(value.x, target.x, speed.x); 79 | bool yComplete = moveValueTowardsTarget(value.y, target.y, speed.y); 80 | return xComplete && yComplete; 81 | } 82 | 83 | bool moveValueTowardsTarget(Vec3f& value, const Vec3f& target, const Vec3f& speed) 84 | { 85 | bool xComplete = moveValueTowardsTarget(value.x, target.x, speed.x); 86 | bool yComplete = moveValueTowardsTarget(value.y, target.y, speed.y); 87 | bool zComplete = moveValueTowardsTarget(value.z, target.z, speed.z); 88 | return xComplete && yComplete && zComplete; 89 | } 90 | -------------------------------------------------------------------------------- /source/math/Mtx44.cpp: -------------------------------------------------------------------------------- 1 | #include "math/Mtx44.h" 2 | #include "math/Mtx34.h" 3 | 4 | void Mtx44::multiply(Mtx44& dst, const Mtx34& a, const Mtx44& b) 5 | { 6 | const f32 a11 = a.rows[0][0]; 7 | const f32 a12 = a.rows[0][1]; 8 | const f32 a13 = a.rows[0][2]; 9 | const f32 a14 = a.rows[0][3]; 10 | 11 | const f32 a21 = a.rows[1][0]; 12 | const f32 a22 = a.rows[1][1]; 13 | const f32 a23 = a.rows[1][2]; 14 | const f32 a24 = a.rows[1][3]; 15 | 16 | const f32 a31 = a.rows[2][0]; 17 | const f32 a32 = a.rows[2][1]; 18 | const f32 a33 = a.rows[2][2]; 19 | const f32 a34 = a.rows[2][3]; 20 | 21 | const f32 b11 = b.rows[0][0]; 22 | const f32 b12 = b.rows[0][1]; 23 | const f32 b13 = b.rows[0][2]; 24 | const f32 b14 = b.rows[0][3]; 25 | 26 | const f32 b21 = b.rows[1][0]; 27 | const f32 b22 = b.rows[1][1]; 28 | const f32 b23 = b.rows[1][2]; 29 | const f32 b24 = b.rows[1][3]; 30 | 31 | const f32 b31 = b.rows[2][0]; 32 | const f32 b32 = b.rows[2][1]; 33 | const f32 b33 = b.rows[2][2]; 34 | const f32 b34 = b.rows[2][3]; 35 | 36 | const f32 b41 = b.rows[3][0]; 37 | const f32 b42 = b.rows[3][1]; 38 | const f32 b43 = b.rows[3][2]; 39 | const f32 b44 = b.rows[3][3]; 40 | 41 | dst.rows[0][0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41; 42 | dst.rows[0][1] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42; 43 | dst.rows[0][2] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43; 44 | dst.rows[0][3] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44; 45 | 46 | dst.rows[1][0] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41; 47 | dst.rows[1][1] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42; 48 | dst.rows[1][2] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43; 49 | dst.rows[1][3] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44; 50 | 51 | dst.rows[2][0] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41; 52 | dst.rows[2][1] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42; 53 | dst.rows[2][2] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43; 54 | dst.rows[2][3] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44; 55 | 56 | dst.rows[3][0] = b41; 57 | dst.rows[3][1] = b42; 58 | dst.rows[3][2] = b43; 59 | dst.rows[3][3] = b44; 60 | } 61 | -------------------------------------------------------------------------------- /source/scene/ScCourse_asm.s: -------------------------------------------------------------------------------- 1 | .arm 2 | 3 | .global ScCourse_alloc_size_hook 4 | ScCourse_alloc_size_hook: 5 | mov r0, #0x190 6 | b 0x0055AB58 7 | -------------------------------------------------------------------------------- /source/sead/heap/seadExpHeap.cpp: -------------------------------------------------------------------------------- 1 | #include "sead.h" 2 | 3 | namespace sead { 4 | 5 | u32 ExpHeap::getSize() const 6 | { 7 | return mSize; 8 | } 9 | 10 | u32 ExpHeap::getFreeSize() const 11 | { 12 | u32 freeSize = 0; 13 | for (MemBlockList::iterator it = mFreeList.begin(); it != mFreeList.end(); ++it) 14 | freeSize += it->getSize(); 15 | return freeSize; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /source/sead/seadAssertCtr.cpp: -------------------------------------------------------------------------------- 1 | #include "sead.h" 2 | #include "sys/Svc.h" 3 | #include 4 | 5 | 6 | namespace sead { namespace system { 7 | 8 | void Halt() 9 | { 10 | svcBreak(USERBREAK_PANIC); 11 | while(true); 12 | } 13 | 14 | void HaltWithDetail(const char* pos, s32 line, const char* format, ...) 15 | { 16 | va_list list; 17 | va_start(list, format); 18 | 19 | sead::system::Print("\n//================= PROGRAM HALT ==================//\nSource File: %s\nLine Number: %d\nDescription: ", pos, line); 20 | sead::system::PrintV(format, list); 21 | sead::system::Print("\n//=================================================//\n"); 22 | 23 | va_end(list); 24 | 25 | svcBreak(USERBREAK_PANIC); 26 | while(true); 27 | } 28 | 29 | void HaltWithDetailNoFormat(const char* pos, s32 line, const char* str) 30 | { 31 | HaltWithDetail(pos, line, "%s", str); 32 | } 33 | 34 | } } 35 | -------------------------------------------------------------------------------- /source/sead/seadRawPrintCtr.cpp: -------------------------------------------------------------------------------- 1 | #include "sead.h" 2 | 3 | #include "types.h" 4 | #include "sys/Svc.h" 5 | 6 | #include 7 | 8 | 9 | namespace sead { namespace system { 10 | 11 | void PrintString(const char* str, s32 len) 12 | { 13 | if (str != nullptr) 14 | svcOutputDebugString(str, len); 15 | } 16 | 17 | void Print(const char* format, ...) 18 | { 19 | va_list list; 20 | va_start(list, format); 21 | 22 | char buffer[256]; 23 | 24 | s32 fmt_len = vsnprintf(buffer, 256, format, list); 25 | s32 print_len; 26 | 27 | if (fmt_len <= 256) 28 | { 29 | print_len = fmt_len; 30 | if (print_len <= 0) 31 | return; 32 | } 33 | else 34 | print_len = 256; 35 | 36 | svcOutputDebugString(buffer, print_len); 37 | 38 | va_end(list); 39 | } 40 | 41 | void PrintV(const char* format, va_list list) 42 | { 43 | char buffer[256]; 44 | 45 | s32 fmt_len = vsnprintf(buffer, 256, format, list); 46 | s32 print_len; 47 | 48 | if (fmt_len <= 256) 49 | { 50 | print_len = fmt_len; 51 | if (print_len <= 0) 52 | return; 53 | } 54 | else 55 | print_len = 256; 56 | 57 | svcOutputDebugString(buffer, print_len); 58 | } 59 | 60 | } } 61 | -------------------------------------------------------------------------------- /source/sead/seadSafeString.cpp: -------------------------------------------------------------------------------- 1 | #include "sead.h" 2 | 3 | #include 4 | #include 5 | 6 | 7 | template<> 8 | void sead::BufferedSafeStringBase::copy(const char* str, s32 maxLen) 9 | { 10 | if (maxLen < 0 || maxLen > mBufferSize) 11 | maxLen = mBufferSize; 12 | 13 | strncpy(const_cast(mStringTop), str, maxLen); 14 | assureTerminationImpl_(); 15 | } 16 | 17 | template<> 18 | void sead::BufferedSafeStringBase::copy(const wchar_t* str, s32 maxLen) 19 | { 20 | if (maxLen < 0 || maxLen > mBufferSize) 21 | maxLen = mBufferSize; 22 | 23 | wcsncpy(const_cast(mStringTop), str, maxLen); 24 | assureTerminationImpl_(); 25 | } 26 | -------------------------------------------------------------------------------- /source/sead/seadWarning.cpp: -------------------------------------------------------------------------------- 1 | #include "sead.h" 2 | 3 | namespace sead { namespace system { 4 | 5 | static bool sIsWarningEnable = false; 6 | 7 | void Warning(const char* pos, s32 line, const char* format, ...) 8 | { 9 | va_list varg; 10 | va_start(varg, format); 11 | 12 | if (sIsWarningEnable) 13 | { 14 | Print("%s(%d) Warning: ", pos, line); 15 | PrintV(format, varg); 16 | } 17 | 18 | va_end(varg); 19 | } 20 | 21 | void SetWarningEnable(bool enable) 22 | { 23 | sIsWarningEnable = enable; 24 | } 25 | 26 | } } 27 | -------------------------------------------------------------------------------- /source/sys/AllocationFailedHandler.cpp: -------------------------------------------------------------------------------- 1 | #include "sead.h" 2 | #include "sys/Allocator.h" 3 | 4 | 5 | class AllocationFailedHandler : sead::HeapMgr::IAllocFailedCallback 6 | { 7 | public: 8 | static AllocationFailedHandler sAllocationFailedHandler; 9 | static void registerCallback(); 10 | 11 | void invoke(const sead::HeapMgr::AllocFailedCallbackArg* arg) override; 12 | }; 13 | 14 | 15 | AllocationFailedHandler AllocationFailedHandler::sAllocationFailedHandler; 16 | 17 | void AllocationFailedHandler::registerCallback() 18 | { 19 | sead::HeapMgr::instance()->mAllocFailedCallback = &sAllocationFailedHandler; 20 | } 21 | 22 | void AllocationFailedHandler::invoke(const sead::HeapMgr::AllocFailedCallbackArg* arg) 23 | { 24 | SEAD_HALT_WITH_DETAIL 25 | ( 26 | "sead allocation failed\n" 27 | "\n" 28 | "Requested size: 0x%X\n" 29 | "Requested alignment: 0x%X\n" 30 | "Alloc size: 0x%X\n" 31 | "Alloc alignment: 0x%X\n" 32 | "Heap: %s", 33 | arg->request_size, 34 | arg->request_alignment, 35 | arg->alloc_size, 36 | arg->alloc_alignment, 37 | arg->heap->mINamableName.cstr() 38 | ); 39 | } 40 | -------------------------------------------------------------------------------- /source/sys/File.s: -------------------------------------------------------------------------------- 1 | .arm 2 | .align 4 3 | 4 | 5 | @ Unable to locate non-inlined version of this 6 | 7 | .global _Z9CloseFilePv 8 | _Z9CloseFilePv: 9 | cmp r0, #0 10 | beq _Z9CloseFilePv_error 11 | ldr r1, [r0] 12 | ldr r1, [r1,#0x30] 13 | bx r1 14 | 15 | _Z9CloseFilePv_error: 16 | bx lr 17 | -------------------------------------------------------------------------------- /source/sys/Svc_asm.s: -------------------------------------------------------------------------------- 1 | .arm 2 | .align 4 3 | 4 | .macro SVC_BEGIN name 5 | .section .text.\name, "ax", %progbits 6 | .global \name 7 | .type \name, %function 8 | .align 2 9 | .cfi_startproc 10 | \name: 11 | .endm 12 | 13 | .macro SVC_END 14 | .cfi_endproc 15 | .endm 16 | 17 | SVC_BEGIN svcCloseHandle 18 | svc 0x23 19 | bx lr 20 | SVC_END 21 | 22 | SVC_BEGIN svcGetSystemTick 23 | svc 0x28 24 | bx lr 25 | SVC_END 26 | 27 | SVC_BEGIN svcSendSyncRequest 28 | svc 0x32 29 | bx lr 30 | SVC_END 31 | 32 | SVC_BEGIN svcBreak 33 | svc 0x3C 34 | bx lr 35 | SVC_END 36 | 37 | SVC_BEGIN svcOutputDebugString 38 | svc 0x3D 39 | bx lr 40 | SVC_END 41 | --------------------------------------------------------------------------------