From 046c595f92fe757e340e7f0755463d6e1a23ad11 Mon Sep 17 00:00:00 2001 From: MysterD Date: Sat, 2 Apr 2022 15:14:04 -0700 Subject: [PATCH] More progress toward custom DynOS levels --- autogen/common.py | 2 +- autogen/lua_definitions/functions.lua | 7 + data/behavior_table.c | 1066 +++++++++++++------------ data/dynos.c.h | 7 +- data/dynos.cpp.h | 19 +- data/dynos_bin_col.cpp | 9 +- data/dynos_bin_geo.cpp | 2 +- data/dynos_bin_gfx.cpp | 2 +- data/dynos_bin_lvl.cpp | 168 +++- data/dynos_bin_macro_object.cpp | 43 + data/dynos_bin_pointer.cpp | 33 +- data/dynos_bin_read.cpp | 2 + data/dynos_c.cpp | 16 +- data/dynos_misc.cpp | 62 +- docs/lua/functions.md | 21 + include/behavior_table.h | 5 +- src/pc/lua/smlua_cobject.c | 2 + src/pc/lua/smlua_cobject.h | 2 + src/pc/lua/smlua_functions_autogen.c | 12 + src/pc/lua/utils/smlua_misc_utils.c | 4 + src/pc/lua/utils/smlua_misc_utils.h | 2 + src/pc/mods/mod.c | 113 ++- 22 files changed, 1017 insertions(+), 582 deletions(-) diff --git a/autogen/common.py b/autogen/common.py index 1575eb69..8fcd5c7a 100644 --- a/autogen/common.py +++ b/autogen/common.py @@ -2,7 +2,7 @@ import os usf_types = ['u8', 'u16', 'u32', 'u64', 's8', 's16', 's32', 's64', 'f32'] vec3_types = ['Vec3s', 'Vec3f'] -typedef_pointers = ['BehaviorScript', 'ObjectAnimPointer', 'Collision'] +typedef_pointers = ['BehaviorScript', 'ObjectAnimPointer', 'Collision', 'LevelScript'] exclude_structs = [ 'SPTask', diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 45459311..6e97e6ad 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -4171,6 +4171,12 @@ function hud_show() -- ... end +--- @param name string +--- @return Pointer_LevelScript +function smlua_level_util_get(name) + -- ... +end + --- @param aDelay integer --- @return boolean function warp_exit_level(aDelay) @@ -4507,3 +4513,4 @@ end --- @class Pointer_number --- @class Pointer_integer --- @class Pointer_Collision +--- @class Pointer_LevelScript diff --git a/data/behavior_table.c b/data/behavior_table.c index 8fd06cfa..5c45e1f2 100644 --- a/data/behavior_table.c +++ b/data/behavior_table.c @@ -2,529 +2,544 @@ #include "behavior_table.h" #include "pc/lua/smlua_hooks.h" -const BehaviorScript* gBehaviorTable[id_bhv_max_count] = { - [id_bhvStarDoor] = bhvStarDoor, - [id_bhvMrI] = bhvMrI, - [id_bhvMrIBody] = bhvMrIBody, - [id_bhvMrIParticle] = bhvMrIParticle, - [id_bhvPurpleParticle] = bhvPurpleParticle, - [id_bhvGiantPole] = bhvGiantPole, - [id_bhvPoleGrabbing] = bhvPoleGrabbing, - [id_bhvThiHugeIslandTop] = bhvThiHugeIslandTop, - [id_bhvThiTinyIslandTop] = bhvThiTinyIslandTop, - [id_bhvCapSwitchBase] = bhvCapSwitchBase, - [id_bhvCapSwitch] = bhvCapSwitch, - [id_bhvKingBobomb] = bhvKingBobomb, - [id_bhvBobombAnchorMario] = bhvBobombAnchorMario, - [id_bhvBetaChestBottom] = bhvBetaChestBottom, - [id_bhvBetaChestLid] = bhvBetaChestLid, - [id_bhvBubbleParticleSpawner] = bhvBubbleParticleSpawner, - [id_bhvBubbleMaybe] = bhvBubbleMaybe, - [id_bhvBubblePlayer] = bhvBubblePlayer, - [id_bhvSmallWaterWave] = bhvSmallWaterWave, - [id_bhvWaterAirBubble] = bhvWaterAirBubble, - [id_bhvSmallParticle] = bhvSmallParticle, - [id_bhvPlungeBubble] = bhvPlungeBubble, - [id_bhvSmallParticleSnow] = bhvSmallParticleSnow, - [id_bhvSmallParticleBubbles] = bhvSmallParticleBubbles, - [id_bhvFishGroup] = bhvFishGroup, - [id_bhvCannon] = bhvCannon, - [id_bhvCannonBarrel] = bhvCannonBarrel, - [id_bhvCannonBaseUnused] = bhvCannonBaseUnused, - [id_bhvChuckya] = bhvChuckya, - [id_bhvChuckyaAnchorMario] = bhvChuckyaAnchorMario, - [id_bhvUnused05A8] = bhvUnused05A8, - [id_bhvRotatingPlatform] = bhvRotatingPlatform, - [id_bhvTower] = bhvTower, - [id_bhvBulletBillCannon] = bhvBulletBillCannon, - [id_bhvWfBreakableWallRight] = bhvWfBreakableWallRight, - [id_bhvWfBreakableWallLeft] = bhvWfBreakableWallLeft, - [id_bhvKickableBoard] = bhvKickableBoard, - [id_bhvTowerDoor] = bhvTowerDoor, - [id_bhvRotatingCounterClockwise] = bhvRotatingCounterClockwise, - [id_bhvWfRotatingWoodenPlatform] = bhvWfRotatingWoodenPlatform, - [id_bhvKoopaShellUnderwater] = bhvKoopaShellUnderwater, - [id_bhvExitPodiumWarp] = bhvExitPodiumWarp, - [id_bhvFadingWarp] = bhvFadingWarp, - [id_bhvWarp] = bhvWarp, - [id_bhvWarpPipe] = bhvWarpPipe, - [id_bhvWhitePuffExplosion] = bhvWhitePuffExplosion, - [id_bhvSpawnedStar] = bhvSpawnedStar, - [id_bhvSpawnedStarNoLevelExit] = bhvSpawnedStarNoLevelExit, - [id_bhvMrIBlueCoin] = bhvMrIBlueCoin, - [id_bhvCoinInsideBoo] = bhvCoinInsideBoo, - [id_bhvCoinFormationSpawn] = bhvCoinFormationSpawn, - [id_bhvCoinFormation] = bhvCoinFormation, - [id_bhvOneCoin] = bhvOneCoin, - [id_bhvYellowCoin] = bhvYellowCoin, - [id_bhvTemporaryYellowCoin] = bhvTemporaryYellowCoin, - [id_bhvThreeCoinsSpawn] = bhvThreeCoinsSpawn, - [id_bhvTenCoinsSpawn] = bhvTenCoinsSpawn, - [id_bhvSingleCoinGetsSpawned] = bhvSingleCoinGetsSpawned, - [id_bhvCoinSparkles] = bhvCoinSparkles, - [id_bhvGoldenCoinSparkles] = bhvGoldenCoinSparkles, - [id_bhvWallTinyStarParticle] = bhvWallTinyStarParticle, - [id_bhvVertStarParticleSpawner] = bhvVertStarParticleSpawner, - [id_bhvPoundTinyStarParticle] = bhvPoundTinyStarParticle, - [id_bhvHorStarParticleSpawner] = bhvHorStarParticleSpawner, - [id_bhvPunchTinyTriangle] = bhvPunchTinyTriangle, - [id_bhvTriangleParticleSpawner] = bhvTriangleParticleSpawner, - [id_bhvDoorWarp] = bhvDoorWarp, - [id_bhvDoor] = bhvDoor, - [id_bhvGrindel] = bhvGrindel, - [id_bhvThwomp2] = bhvThwomp2, - [id_bhvThwomp] = bhvThwomp, - [id_bhvTumblingBridgePlatform] = bhvTumblingBridgePlatform, - [id_bhvWfTumblingBridge] = bhvWfTumblingBridge, - [id_bhvBbhTumblingBridge] = bhvBbhTumblingBridge, - [id_bhvLllTumblingBridge] = bhvLllTumblingBridge, - [id_bhvFlame] = bhvFlame, - [id_bhvAnotherElavator] = bhvAnotherElavator, - [id_bhvRrElevatorPlatform] = bhvRrElevatorPlatform, - [id_bhvHmcElevatorPlatform] = bhvHmcElevatorPlatform, - [id_bhvWaterMist] = bhvWaterMist, - [id_bhvBreathParticleSpawner] = bhvBreathParticleSpawner, - [id_bhvBreakBoxTriangle] = bhvBreakBoxTriangle, - [id_bhvWaterMist2] = bhvWaterMist2, - [id_bhvUnused0DFC] = bhvUnused0DFC, - [id_bhvMistCircParticleSpawner] = bhvMistCircParticleSpawner, - [id_bhvDirtParticleSpawner] = bhvDirtParticleSpawner, - [id_bhvSnowParticleSpawner] = bhvSnowParticleSpawner, - [id_bhvWind] = bhvWind, - [id_bhvEndToad] = bhvEndToad, - [id_bhvEndPeach] = bhvEndPeach, - [id_bhvUnusedParticleSpawn] = bhvUnusedParticleSpawn, - [id_bhvUkiki] = bhvUkiki, - [id_bhvUkikiCageChild] = bhvUkikiCageChild, - [id_bhvUkikiCageStar] = bhvUkikiCageStar, - [id_bhvUkikiCage] = bhvUkikiCage, - [id_bhvBitfsSinkingPlatforms] = bhvBitfsSinkingPlatforms, - [id_bhvBitfsSinkingCagePlatform] = bhvBitfsSinkingCagePlatform, - [id_bhvDddMovingPole] = bhvDddMovingPole, - [id_bhvBitfsTiltingInvertedPyramid] = bhvBitfsTiltingInvertedPyramid, - [id_bhvSquishablePlatform] = bhvSquishablePlatform, - [id_bhvCutOutObject] = bhvCutOutObject, - [id_bhvBetaMovingFlames] = bhvBetaMovingFlames, - [id_bhvRrRotatingBridgePlatform] = bhvRrRotatingBridgePlatform, - [id_bhvFlamethrower] = bhvFlamethrower, - [id_bhvFlamethrowerFlame] = bhvFlamethrowerFlame, - [id_bhvBouncingFireball] = bhvBouncingFireball, - [id_bhvBouncingFireballFlame] = bhvBouncingFireballFlame, - [id_bhvBowserShockWave] = bhvBowserShockWave, - [id_bhvFireParticleSpawner] = bhvFireParticleSpawner, - [id_bhvBlackSmokeMario] = bhvBlackSmokeMario, - [id_bhvBlackSmokeBowser] = bhvBlackSmokeBowser, - [id_bhvBlackSmokeUpward] = bhvBlackSmokeUpward, - [id_bhvBetaFishSplashSpawner] = bhvBetaFishSplashSpawner, - [id_bhvSpindrift] = bhvSpindrift, - [id_bhvTowerPlatformGroup] = bhvTowerPlatformGroup, - [id_bhvWfSlidingTowerPlatform] = bhvWfSlidingTowerPlatform, - [id_bhvWfElevatorTowerPlatform] = bhvWfElevatorTowerPlatform, - [id_bhvWfSolidTowerPlatform] = bhvWfSolidTowerPlatform, - [id_bhvLeafParticleSpawner] = bhvLeafParticleSpawner, - [id_bhvTreeSnow] = bhvTreeSnow, - [id_bhvTreeLeaf] = bhvTreeLeaf, - [id_bhvAnotherTiltingPlatform] = bhvAnotherTiltingPlatform, - [id_bhvSquarishPathMoving] = bhvSquarishPathMoving, - [id_bhvSquarishPathParent] = bhvSquarishPathParent, - [id_bhvPiranhaPlantBubble] = bhvPiranhaPlantBubble, - [id_bhvPiranhaPlantWakingBubbles] = bhvPiranhaPlantWakingBubbles, - [id_bhvFloorSwitchAnimatesObject] = bhvFloorSwitchAnimatesObject, - [id_bhvFloorSwitchGrills] = bhvFloorSwitchGrills, - [id_bhvFloorSwitchHardcodedModel] = bhvFloorSwitchHardcodedModel, - [id_bhvFloorSwitchHiddenObjects] = bhvFloorSwitchHiddenObjects, - [id_bhvHiddenObject] = bhvHiddenObject, - [id_bhvBreakableBox] = bhvBreakableBox, - [id_bhvPushableMetalBox] = bhvPushableMetalBox, - [id_bhvHeaveHo] = bhvHeaveHo, - [id_bhvHeaveHoThrowMario] = bhvHeaveHoThrowMario, - [id_bhvCcmTouchedStarSpawn] = bhvCcmTouchedStarSpawn, - [id_bhvUnusedPoundablePlatform] = bhvUnusedPoundablePlatform, - [id_bhvBetaTrampolineTop] = bhvBetaTrampolineTop, - [id_bhvBetaTrampolineSpring] = bhvBetaTrampolineSpring, - [id_bhvJumpingBox] = bhvJumpingBox, - [id_bhvBooCage] = bhvBooCage, - [id_bhvStub] = bhvStub, - [id_bhvIgloo] = bhvIgloo, - [id_bhvBowserKey] = bhvBowserKey, - [id_bhvGrandStar] = bhvGrandStar, - [id_bhvBetaBooKey] = bhvBetaBooKey, - [id_bhvAlphaBooKey] = bhvAlphaBooKey, - [id_bhvBulletBill] = bhvBulletBill, - [id_bhvWhitePuffSmoke] = bhvWhitePuffSmoke, - [id_bhvUnused1820] = bhvUnused1820, - [id_bhvBowserTailAnchor] = bhvBowserTailAnchor, - [id_bhvBowser] = bhvBowser, - [id_bhvBowserBodyAnchor] = bhvBowserBodyAnchor, - [id_bhvBowserFlameSpawn] = bhvBowserFlameSpawn, - [id_bhvTiltingBowserLavaPlatform] = bhvTiltingBowserLavaPlatform, - [id_bhvFallingBowserPlatform] = bhvFallingBowserPlatform, - [id_bhvBlueBowserFlame] = bhvBlueBowserFlame, - [id_bhvFlameFloatingLanding] = bhvFlameFloatingLanding, - [id_bhvBlueFlamesGroup] = bhvBlueFlamesGroup, - [id_bhvFlameBouncing] = bhvFlameBouncing, - [id_bhvFlameMovingForwardGrowing] = bhvFlameMovingForwardGrowing, - [id_bhvFlameBowser] = bhvFlameBowser, - [id_bhvFlameLargeBurningOut] = bhvFlameLargeBurningOut, - [id_bhvBlueFish] = bhvBlueFish, - [id_bhvTankFishGroup] = bhvTankFishGroup, - [id_bhvCheckerboardElevatorGroup] = bhvCheckerboardElevatorGroup, - [id_bhvCheckerboardPlatformSub] = bhvCheckerboardPlatformSub, - [id_bhvBowserKeyUnlockDoor] = bhvBowserKeyUnlockDoor, - [id_bhvBowserKeyCourseExit] = bhvBowserKeyCourseExit, - [id_bhvInvisibleObjectsUnderBridge] = bhvInvisibleObjectsUnderBridge, - [id_bhvWaterLevelPillar] = bhvWaterLevelPillar, - [id_bhvDddWarp] = bhvDddWarp, - [id_bhvMoatGrills] = bhvMoatGrills, - [id_bhvClockMinuteHand] = bhvClockMinuteHand, - [id_bhvClockHourHand] = bhvClockHourHand, - [id_bhvMacroUkiki] = bhvMacroUkiki, - [id_bhvStub1D0C] = bhvStub1D0C, - [id_bhvLllRotatingHexagonalPlatform] = bhvLllRotatingHexagonalPlatform, - [id_bhvLllSinkingRockBlock] = bhvLllSinkingRockBlock, - [id_bhvStub1D70] = bhvStub1D70, - [id_bhvLllMovingOctagonalMeshPlatform] = bhvLllMovingOctagonalMeshPlatform, - [id_bhvLllRotatingBlockWithFireBars] = bhvLllRotatingBlockWithFireBars, - [id_bhvLllRotatingHexFlame] = bhvLllRotatingHexFlame, - [id_bhvLllWoodPiece] = bhvLllWoodPiece, - [id_bhvLllFloatingWoodBridge] = bhvLllFloatingWoodBridge, - [id_bhvVolcanoFlames] = bhvVolcanoFlames, - [id_bhvLllRotatingHexagonalRing] = bhvLllRotatingHexagonalRing, - [id_bhvLllSinkingRectangularPlatform] = bhvLllSinkingRectangularPlatform, - [id_bhvLllSinkingSquarePlatforms] = bhvLllSinkingSquarePlatforms, - [id_bhvLllTiltingInvertedPyramid] = bhvLllTiltingInvertedPyramid, - [id_bhvUnused1F30] = bhvUnused1F30, - [id_bhvKoopaShell] = bhvKoopaShell, - [id_bhvKoopaShellFlame] = bhvKoopaShellFlame, - [id_bhvToxBox] = bhvToxBox, - [id_bhvPiranhaPlant] = bhvPiranhaPlant, - [id_bhvLllHexagonalMesh] = bhvLllHexagonalMesh, - [id_bhvLllBowserPuzzlePiece] = bhvLllBowserPuzzlePiece, - [id_bhvLllBowserPuzzle] = bhvLllBowserPuzzle, - [id_bhvTuxiesMother] = bhvTuxiesMother, - [id_bhvPenguinBaby] = bhvPenguinBaby, - [id_bhvUnused20E0] = bhvUnused20E0, - [id_bhvSmallPenguin] = bhvSmallPenguin, - [id_bhvManyBlueFishSpawner] = bhvManyBlueFishSpawner, - [id_bhvFewBlueFishSpawner] = bhvFewBlueFishSpawner, - [id_bhvFishSpawner] = bhvFishSpawner, - [id_bhvFish] = bhvFish, - [id_bhvWdwExpressElevator] = bhvWdwExpressElevator, - [id_bhvWdwExpressElevatorPlatform] = bhvWdwExpressElevatorPlatform, - [id_bhvChirpChirp] = bhvChirpChirp, - [id_bhvBub] = bhvBub, - [id_bhvExclamationBox] = bhvExclamationBox, - [id_bhvRotatingExclamationMark] = bhvRotatingExclamationMark, - [id_bhvSoundSpawner] = bhvSoundSpawner, - [id_bhvRockSolid] = bhvRockSolid, - [id_bhvBowserSubDoor] = bhvBowserSubDoor, - [id_bhvBowsersSub] = bhvBowsersSub, - [id_bhvSushiShark] = bhvSushiShark, - [id_bhvSushiSharkCollisionChild] = bhvSushiSharkCollisionChild, - [id_bhvJrbSlidingBox] = bhvJrbSlidingBox, - [id_bhvShipPart3] = bhvShipPart3, - [id_bhvInSunkenShip3] = bhvInSunkenShip3, - [id_bhvSunkenShipPart] = bhvSunkenShipPart, - [id_bhvSunkenShipPart2] = bhvSunkenShipPart2, - [id_bhvInSunkenShip] = bhvInSunkenShip, - [id_bhvInSunkenShip2] = bhvInSunkenShip2, - [id_bhvMistParticleSpawner] = bhvMistParticleSpawner, - [id_bhvWhitePuff1] = bhvWhitePuff1, - [id_bhvWhitePuff2] = bhvWhitePuff2, - [id_bhvWhitePuffSmoke2] = bhvWhitePuffSmoke2, - [id_bhvPurpleSwitchHiddenBoxes] = bhvPurpleSwitchHiddenBoxes, - [id_bhvBlueCoinSwitch] = bhvBlueCoinSwitch, - [id_bhvHiddenBlueCoin] = bhvHiddenBlueCoin, - [id_bhvOpenableCageDoor] = bhvOpenableCageDoor, - [id_bhvOpenableGrill] = bhvOpenableGrill, - [id_bhvWaterLevelDiamond] = bhvWaterLevelDiamond, - [id_bhvInitializeChangingWaterLevel] = bhvInitializeChangingWaterLevel, - [id_bhvTweesterSandParticle] = bhvTweesterSandParticle, - [id_bhvTweester] = bhvTweester, - [id_bhvMerryGoRoundBooManager] = bhvMerryGoRoundBooManager, - [id_bhvAnimatedTexture] = bhvAnimatedTexture, - [id_bhvBooInCastle] = bhvBooInCastle, - [id_bhvBooWithCage] = bhvBooWithCage, - [id_bhvBalconyBigBoo] = bhvBalconyBigBoo, - [id_bhvMerryGoRoundBigBoo] = bhvMerryGoRoundBigBoo, - [id_bhvGhostHuntBigBoo] = bhvGhostHuntBigBoo, - [id_bhvCourtyardBooTriplet] = bhvCourtyardBooTriplet, - [id_bhvBoo] = bhvBoo, - [id_bhvMerryGoRoundBoo] = bhvMerryGoRoundBoo, - [id_bhvGhostHuntBoo] = bhvGhostHuntBoo, - [id_bhvHiddenStaircaseStep] = bhvHiddenStaircaseStep, - [id_bhvBooBossSpawnedBridge] = bhvBooBossSpawnedBridge, - [id_bhvBbhTiltingTrapPlatform] = bhvBbhTiltingTrapPlatform, - [id_bhvHauntedBookshelf] = bhvHauntedBookshelf, - [id_bhvMeshElevator] = bhvMeshElevator, - [id_bhvMerryGoRound] = bhvMerryGoRound, - [id_bhvPlaysMusicTrackWhenTouched] = bhvPlaysMusicTrackWhenTouched, - [id_bhvBetaBowserAnchor] = bhvBetaBowserAnchor, - [id_bhvStaticCheckeredPlatform] = bhvStaticCheckeredPlatform, - [id_bhvUnused2A10] = bhvUnused2A10, - [id_bhvUnusedFakeStar] = bhvUnusedFakeStar, - [id_bhvStaticObject] = bhvStaticObject, - [id_bhvUnused2A54] = bhvUnused2A54, - [id_bhvCastleFloorTrap] = bhvCastleFloorTrap, - [id_bhvFloorTrapInCastle] = bhvFloorTrapInCastle, - [id_bhvTree] = bhvTree, - [id_bhvSparkle] = bhvSparkle, - [id_bhvSparkleSpawn] = bhvSparkleSpawn, - [id_bhvSparkleParticleSpawner] = bhvSparkleParticleSpawner, - [id_bhvScuttlebug] = bhvScuttlebug, - [id_bhvScuttlebugSpawn] = bhvScuttlebugSpawn, - [id_bhvWhompKingBoss] = bhvWhompKingBoss, - [id_bhvSmallWhomp] = bhvSmallWhomp, - [id_bhvWaterSplash] = bhvWaterSplash, - [id_bhvWaterDroplet] = bhvWaterDroplet, - [id_bhvWaterDropletSplash] = bhvWaterDropletSplash, - [id_bhvBubbleSplash] = bhvBubbleSplash, - [id_bhvIdleWaterWave] = bhvIdleWaterWave, - [id_bhvObjectWaterSplash] = bhvObjectWaterSplash, - [id_bhvShallowWaterWave] = bhvShallowWaterWave, - [id_bhvShallowWaterSplash] = bhvShallowWaterSplash, - [id_bhvObjectWaveTrail] = bhvObjectWaveTrail, - [id_bhvWaveTrail] = bhvWaveTrail, - [id_bhvTinyStrongWindParticle] = bhvTinyStrongWindParticle, - [id_bhvStrongWindParticle] = bhvStrongWindParticle, - [id_bhvSLSnowmanWind] = bhvSLSnowmanWind, - [id_bhvSLWalkingPenguin] = bhvSLWalkingPenguin, - [id_bhvYellowBall] = bhvYellowBall, - [id_bhvMario] = bhvMario, - [id_bhvToadMessage] = bhvToadMessage, - [id_bhvUnlockDoorStar] = bhvUnlockDoorStar, - [id_bhvRandomAnimatedTexture] = bhvRandomAnimatedTexture, - [id_bhvYellowBackgroundInMenu] = bhvYellowBackgroundInMenu, - [id_bhvMenuButton] = bhvMenuButton, - [id_bhvMenuButtonManager] = bhvMenuButtonManager, - [id_bhvActSelectorStarType] = bhvActSelectorStarType, - [id_bhvActSelector] = bhvActSelector, - [id_bhvMovingYellowCoin] = bhvMovingYellowCoin, - [id_bhvMovingBlueCoin] = bhvMovingBlueCoin, - [id_bhvBlueCoinSliding] = bhvBlueCoinSliding, - [id_bhvBlueCoinJumping] = bhvBlueCoinJumping, - [id_bhvSeaweed] = bhvSeaweed, - [id_bhvSeaweedBundle] = bhvSeaweedBundle, - [id_bhvBobomb] = bhvBobomb, - [id_bhvBobombFuseSmoke] = bhvBobombFuseSmoke, - [id_bhvBobombBuddy] = bhvBobombBuddy, - [id_bhvBobombBuddyOpensCannon] = bhvBobombBuddyOpensCannon, - [id_bhvCannonClosed] = bhvCannonClosed, - [id_bhvWhirlpool] = bhvWhirlpool, - [id_bhvJetStream] = bhvJetStream, - [id_bhvMessagePanel] = bhvMessagePanel, - [id_bhvSignOnWall] = bhvSignOnWall, - [id_bhvHomingAmp] = bhvHomingAmp, - [id_bhvCirclingAmp] = bhvCirclingAmp, - [id_bhvButterfly] = bhvButterfly, - [id_bhvHoot] = bhvHoot, - [id_bhvBetaHoldableObject] = bhvBetaHoldableObject, - [id_bhvCarrySomething1] = bhvCarrySomething1, - [id_bhvCarrySomething2] = bhvCarrySomething2, - [id_bhvCarrySomething3] = bhvCarrySomething3, - [id_bhvCarrySomething4] = bhvCarrySomething4, - [id_bhvCarrySomething5] = bhvCarrySomething5, - [id_bhvCarrySomething6] = bhvCarrySomething6, - [id_bhvObjectBubble] = bhvObjectBubble, - [id_bhvObjectWaterWave] = bhvObjectWaterWave, - [id_bhvExplosion] = bhvExplosion, - [id_bhvBobombBullyDeathSmoke] = bhvBobombBullyDeathSmoke, - [id_bhvSmoke] = bhvSmoke, - [id_bhvBobombExplosionBubble] = bhvBobombExplosionBubble, - [id_bhvRespawner] = bhvRespawner, - [id_bhvSmallBully] = bhvSmallBully, - [id_bhvBigBully] = bhvBigBully, - [id_bhvBigBullyWithMinions] = bhvBigBullyWithMinions, - [id_bhvSmallChillBully] = bhvSmallChillBully, - [id_bhvBigChillBully] = bhvBigChillBully, - [id_bhvJetStreamRingSpawner] = bhvJetStreamRingSpawner, - [id_bhvJetStreamWaterRing] = bhvJetStreamWaterRing, - [id_bhvMantaRayWaterRing] = bhvMantaRayWaterRing, - [id_bhvMantaRayRingManager] = bhvMantaRayRingManager, - [id_bhvBowserBomb] = bhvBowserBomb, - [id_bhvBowserBombExplosion] = bhvBowserBombExplosion, - [id_bhvBowserBombSmoke] = bhvBowserBombSmoke, - [id_bhvCelebrationStar] = bhvCelebrationStar, - [id_bhvCelebrationStarSparkle] = bhvCelebrationStarSparkle, - [id_bhvStarKeyCollectionPuffSpawner] = bhvStarKeyCollectionPuffSpawner, - [id_bhvLllDrawbridgeSpawner] = bhvLllDrawbridgeSpawner, - [id_bhvLllDrawbridge] = bhvLllDrawbridge, - [id_bhvSmallBomp] = bhvSmallBomp, - [id_bhvLargeBomp] = bhvLargeBomp, - [id_bhvWfSlidingPlatform] = bhvWfSlidingPlatform, - [id_bhvMoneybag] = bhvMoneybag, - [id_bhvMoneybagHidden] = bhvMoneybagHidden, - [id_bhvPitBowlingBall] = bhvPitBowlingBall, - [id_bhvFreeBowlingBall] = bhvFreeBowlingBall, - [id_bhvBowlingBall] = bhvBowlingBall, - [id_bhvTtmBowlingBallSpawner] = bhvTtmBowlingBallSpawner, - [id_bhvBobBowlingBallSpawner] = bhvBobBowlingBallSpawner, - [id_bhvThiBowlingBallSpawner] = bhvThiBowlingBallSpawner, - [id_bhvRrCruiserWing] = bhvRrCruiserWing, - [id_bhvSpindel] = bhvSpindel, - [id_bhvSslMovingPyramidWall] = bhvSslMovingPyramidWall, - [id_bhvPyramidElevator] = bhvPyramidElevator, - [id_bhvPyramidElevatorTrajectoryMarkerBall] = bhvPyramidElevatorTrajectoryMarkerBall, - [id_bhvPyramidTop] = bhvPyramidTop, - [id_bhvPyramidTopFragment] = bhvPyramidTopFragment, - [id_bhvPyramidPillarTouchDetector] = bhvPyramidPillarTouchDetector, - [id_bhvWaterfallSoundLoop] = bhvWaterfallSoundLoop, - [id_bhvVolcanoSoundLoop] = bhvVolcanoSoundLoop, - [id_bhvCastleFlagWaving] = bhvCastleFlagWaving, - [id_bhvBirdsSoundLoop] = bhvBirdsSoundLoop, - [id_bhvAmbientSounds] = bhvAmbientSounds, - [id_bhvSandSoundLoop] = bhvSandSoundLoop, - [id_bhvHiddenAt120Stars] = bhvHiddenAt120Stars, - [id_bhvSnowmansBottom] = bhvSnowmansBottom, - [id_bhvSnowmansHead] = bhvSnowmansHead, - [id_bhvSnowmansBodyCheckpoint] = bhvSnowmansBodyCheckpoint, - [id_bhvBigSnowmanWhole] = bhvBigSnowmanWhole, - [id_bhvBigBoulder] = bhvBigBoulder, - [id_bhvBigBoulderGenerator] = bhvBigBoulderGenerator, - [id_bhvWingCap] = bhvWingCap, - [id_bhvMetalCap] = bhvMetalCap, - [id_bhvNormalCap] = bhvNormalCap, - [id_bhvVanishCap] = bhvVanishCap, - [id_bhvStar] = bhvStar, - [id_bhvStarSpawnCoordinates] = bhvStarSpawnCoordinates, - [id_bhvHiddenRedCoinStar] = bhvHiddenRedCoinStar, - [id_bhvRedCoin] = bhvRedCoin, - [id_bhvBowserCourseRedCoinStar] = bhvBowserCourseRedCoinStar, - [id_bhvHiddenStar] = bhvHiddenStar, - [id_bhvHiddenStarTrigger] = bhvHiddenStarTrigger, - [id_bhvTtmRollingLog] = bhvTtmRollingLog, - [id_bhvLllVolcanoFallingTrap] = bhvLllVolcanoFallingTrap, - [id_bhvLllRollingLog] = bhvLllRollingLog, - [id_bhv1upWalking] = bhv1upWalking, - [id_bhv1upRunningAway] = bhv1upRunningAway, - [id_bhv1upSliding] = bhv1upSliding, - [id_bhv1Up] = bhv1Up, - [id_bhv1upJumpOnApproach] = bhv1upJumpOnApproach, - [id_bhvHidden1up] = bhvHidden1up, - [id_bhvHidden1upTrigger] = bhvHidden1upTrigger, - [id_bhvHidden1upInPole] = bhvHidden1upInPole, - [id_bhvHidden1upInPoleTrigger] = bhvHidden1upInPoleTrigger, - [id_bhvHidden1upInPoleSpawner] = bhvHidden1upInPoleSpawner, - [id_bhvControllablePlatform] = bhvControllablePlatform, - [id_bhvControllablePlatformSub] = bhvControllablePlatformSub, - [id_bhvBreakableBoxSmall] = bhvBreakableBoxSmall, - [id_bhvSlidingSnowMound] = bhvSlidingSnowMound, - [id_bhvSnowMoundSpawn] = bhvSnowMoundSpawn, - [id_bhvWdwSquareFloatingPlatform] = bhvWdwSquareFloatingPlatform, - [id_bhvWdwRectangularFloatingPlatform] = bhvWdwRectangularFloatingPlatform, - [id_bhvJrbFloatingPlatform] = bhvJrbFloatingPlatform, - [id_bhvArrowLift] = bhvArrowLift, - [id_bhvOrangeNumber] = bhvOrangeNumber, - [id_bhvMantaRay] = bhvMantaRay, - [id_bhvFallingPillar] = bhvFallingPillar, - [id_bhvFallingPillarHitbox] = bhvFallingPillarHitbox, - [id_bhvPillarBase] = bhvPillarBase, - [id_bhvJrbFloatingBox] = bhvJrbFloatingBox, - [id_bhvDecorativePendulum] = bhvDecorativePendulum, - [id_bhvTreasureChestsShip] = bhvTreasureChestsShip, - [id_bhvTreasureChestsJrb] = bhvTreasureChestsJrb, - [id_bhvTreasureChests] = bhvTreasureChests, - [id_bhvTreasureChestBottom] = bhvTreasureChestBottom, - [id_bhvTreasureChestTop] = bhvTreasureChestTop, - [id_bhvMips] = bhvMips, - [id_bhvYoshi] = bhvYoshi, - [id_bhvKoopa] = bhvKoopa, - [id_bhvKoopaRaceEndpoint] = bhvKoopaRaceEndpoint, - [id_bhvKoopaFlag] = bhvKoopaFlag, - [id_bhvPokey] = bhvPokey, - [id_bhvPokeyBodyPart] = bhvPokeyBodyPart, - [id_bhvSwoop] = bhvSwoop, - [id_bhvFlyGuy] = bhvFlyGuy, - [id_bhvGoomba] = bhvGoomba, - [id_bhvGoombaTripletSpawner] = bhvGoombaTripletSpawner, - [id_bhvChainChomp] = bhvChainChomp, - [id_bhvChainChompChainPart] = bhvChainChompChainPart, - [id_bhvWoodenPost] = bhvWoodenPost, - [id_bhvChainChompGate] = bhvChainChompGate, - [id_bhvWigglerHead] = bhvWigglerHead, - [id_bhvWigglerBody] = bhvWigglerBody, - [id_bhvEnemyLakitu] = bhvEnemyLakitu, - [id_bhvCameraLakitu] = bhvCameraLakitu, - [id_bhvCloud] = bhvCloud, - [id_bhvCloudPart] = bhvCloudPart, - [id_bhvSpiny] = bhvSpiny, - [id_bhvMontyMole] = bhvMontyMole, - [id_bhvMontyMoleHole] = bhvMontyMoleHole, - [id_bhvMontyMoleRock] = bhvMontyMoleRock, - [id_bhvPlatformOnTrack] = bhvPlatformOnTrack, - [id_bhvTrackBall] = bhvTrackBall, - [id_bhvSeesawPlatform] = bhvSeesawPlatform, - [id_bhvFerrisWheelAxle] = bhvFerrisWheelAxle, - [id_bhvFerrisWheelPlatform] = bhvFerrisWheelPlatform, - [id_bhvWaterBombSpawner] = bhvWaterBombSpawner, - [id_bhvWaterBomb] = bhvWaterBomb, - [id_bhvWaterBombShadow] = bhvWaterBombShadow, - [id_bhvTTCRotatingSolid] = bhvTTCRotatingSolid, - [id_bhvTTCPendulum] = bhvTTCPendulum, - [id_bhvTTCTreadmill] = bhvTTCTreadmill, - [id_bhvTTCMovingBar] = bhvTTCMovingBar, - [id_bhvTTCCog] = bhvTTCCog, - [id_bhvTTCPitBlock] = bhvTTCPitBlock, - [id_bhvTTCElevator] = bhvTTCElevator, - [id_bhvTTC2DRotator] = bhvTTC2DRotator, - [id_bhvTTCSpinner] = bhvTTCSpinner, - [id_bhvMrBlizzard] = bhvMrBlizzard, - [id_bhvMrBlizzardSnowball] = bhvMrBlizzardSnowball, - [id_bhvSlidingPlatform2] = bhvSlidingPlatform2, - [id_bhvOctagonalPlatformRotating] = bhvOctagonalPlatformRotating, - [id_bhvAnimatesOnFloorSwitchPress] = bhvAnimatesOnFloorSwitchPress, - [id_bhvActivatedBackAndForthPlatform] = bhvActivatedBackAndForthPlatform, - [id_bhvRecoveryHeart] = bhvRecoveryHeart, - [id_bhvWaterBombCannon] = bhvWaterBombCannon, - [id_bhvCannonBarrelBubbles] = bhvCannonBarrelBubbles, - [id_bhvUnagi] = bhvUnagi, - [id_bhvUnagiSubobject] = bhvUnagiSubobject, - [id_bhvDorrie] = bhvDorrie, - [id_bhvHauntedChair] = bhvHauntedChair, - [id_bhvMadPiano] = bhvMadPiano, - [id_bhvFlyingBookend] = bhvFlyingBookend, - [id_bhvBookendSpawn] = bhvBookendSpawn, - [id_bhvHauntedBookshelfManager] = bhvHauntedBookshelfManager, - [id_bhvBookSwitch] = bhvBookSwitch, - [id_bhvFirePiranhaPlant] = bhvFirePiranhaPlant, - [id_bhvSmallPiranhaFlame] = bhvSmallPiranhaFlame, - [id_bhvFireSpitter] = bhvFireSpitter, - [id_bhvFlyguyFlame] = bhvFlyguyFlame, - [id_bhvSnufit] = bhvSnufit, - [id_bhvSnufitBalls] = bhvSnufitBalls, - [id_bhvHorizontalGrindel] = bhvHorizontalGrindel, - [id_bhvEyerokBoss] = bhvEyerokBoss, - [id_bhvEyerokHand] = bhvEyerokHand, - [id_bhvKlepto] = bhvKlepto, - [id_bhvBird] = bhvBird, - [id_bhvRacingPenguin] = bhvRacingPenguin, - [id_bhvPenguinRaceFinishLine] = bhvPenguinRaceFinishLine, - [id_bhvPenguinRaceShortcutCheck] = bhvPenguinRaceShortcutCheck, - [id_bhvCoffinSpawner] = bhvCoffinSpawner, - [id_bhvCoffin] = bhvCoffin, - [id_bhvClamShell] = bhvClamShell, - [id_bhvSkeeter] = bhvSkeeter, - [id_bhvSkeeterWave] = bhvSkeeterWave, - [id_bhvSwingPlatform] = bhvSwingPlatform, - [id_bhvDonutPlatformSpawner] = bhvDonutPlatformSpawner, - [id_bhvDonutPlatform] = bhvDonutPlatform, - [id_bhvDDDPole] = bhvDDDPole, - [id_bhvRedCoinStarMarker] = bhvRedCoinStarMarker, - [id_bhvTripletButterfly] = bhvTripletButterfly, - [id_bhvBubba] = bhvBubba, - [id_bhvBeginningLakitu] = bhvBeginningLakitu, - [id_bhvBeginningPeach] = bhvBeginningPeach, - [id_bhvEndBirds1] = bhvEndBirds1, - [id_bhvEndBirds2] = bhvEndBirds2, - [id_bhvIntroScene] = bhvIntroScene, +struct BehaviorTableEntry { + enum BehaviorId id; + const BehaviorScript* script; + const char* name; }; +#define BHV_ENTRY(BHV) [id_##BHV] = { .id = id_##BHV, .script = BHV, .name = #BHV } + +const struct BehaviorTableEntry gBehaviorTable[id_bhv_max_count] = { + BHV_ENTRY(bhvStarDoor), + BHV_ENTRY(bhvMrI), + BHV_ENTRY(bhvMrIBody), + BHV_ENTRY(bhvMrIParticle), + BHV_ENTRY(bhvPurpleParticle), + BHV_ENTRY(bhvGiantPole), + BHV_ENTRY(bhvPoleGrabbing), + BHV_ENTRY(bhvThiHugeIslandTop), + BHV_ENTRY(bhvThiTinyIslandTop), + BHV_ENTRY(bhvCapSwitchBase), + BHV_ENTRY(bhvCapSwitch), + BHV_ENTRY(bhvKingBobomb), + BHV_ENTRY(bhvBobombAnchorMario), + BHV_ENTRY(bhvBetaChestBottom), + BHV_ENTRY(bhvBetaChestLid), + BHV_ENTRY(bhvBubbleParticleSpawner), + BHV_ENTRY(bhvBubbleMaybe), + BHV_ENTRY(bhvBubblePlayer), + BHV_ENTRY(bhvSmallWaterWave), + BHV_ENTRY(bhvWaterAirBubble), + BHV_ENTRY(bhvSmallParticle), + BHV_ENTRY(bhvPlungeBubble), + BHV_ENTRY(bhvSmallParticleSnow), + BHV_ENTRY(bhvSmallParticleBubbles), + BHV_ENTRY(bhvFishGroup), + BHV_ENTRY(bhvCannon), + BHV_ENTRY(bhvCannonBarrel), + BHV_ENTRY(bhvCannonBaseUnused), + BHV_ENTRY(bhvChuckya), + BHV_ENTRY(bhvChuckyaAnchorMario), + BHV_ENTRY(bhvUnused05A8), + BHV_ENTRY(bhvRotatingPlatform), + BHV_ENTRY(bhvTower), + BHV_ENTRY(bhvBulletBillCannon), + BHV_ENTRY(bhvWfBreakableWallRight), + BHV_ENTRY(bhvWfBreakableWallLeft), + BHV_ENTRY(bhvKickableBoard), + BHV_ENTRY(bhvTowerDoor), + BHV_ENTRY(bhvRotatingCounterClockwise), + BHV_ENTRY(bhvWfRotatingWoodenPlatform), + BHV_ENTRY(bhvKoopaShellUnderwater), + BHV_ENTRY(bhvExitPodiumWarp), + BHV_ENTRY(bhvFadingWarp), + BHV_ENTRY(bhvWarp), + BHV_ENTRY(bhvWarpPipe), + BHV_ENTRY(bhvWhitePuffExplosion), + BHV_ENTRY(bhvSpawnedStar), + BHV_ENTRY(bhvSpawnedStarNoLevelExit), + BHV_ENTRY(bhvMrIBlueCoin), + BHV_ENTRY(bhvCoinInsideBoo), + BHV_ENTRY(bhvCoinFormationSpawn), + BHV_ENTRY(bhvCoinFormation), + BHV_ENTRY(bhvOneCoin), + BHV_ENTRY(bhvYellowCoin), + BHV_ENTRY(bhvTemporaryYellowCoin), + BHV_ENTRY(bhvThreeCoinsSpawn), + BHV_ENTRY(bhvTenCoinsSpawn), + BHV_ENTRY(bhvSingleCoinGetsSpawned), + BHV_ENTRY(bhvCoinSparkles), + BHV_ENTRY(bhvGoldenCoinSparkles), + BHV_ENTRY(bhvWallTinyStarParticle), + BHV_ENTRY(bhvVertStarParticleSpawner), + BHV_ENTRY(bhvPoundTinyStarParticle), + BHV_ENTRY(bhvHorStarParticleSpawner), + BHV_ENTRY(bhvPunchTinyTriangle), + BHV_ENTRY(bhvTriangleParticleSpawner), + BHV_ENTRY(bhvDoorWarp), + BHV_ENTRY(bhvDoor), + BHV_ENTRY(bhvGrindel), + BHV_ENTRY(bhvThwomp2), + BHV_ENTRY(bhvThwomp), + BHV_ENTRY(bhvTumblingBridgePlatform), + BHV_ENTRY(bhvWfTumblingBridge), + BHV_ENTRY(bhvBbhTumblingBridge), + BHV_ENTRY(bhvLllTumblingBridge), + BHV_ENTRY(bhvFlame), + BHV_ENTRY(bhvAnotherElavator), + BHV_ENTRY(bhvRrElevatorPlatform), + BHV_ENTRY(bhvHmcElevatorPlatform), + BHV_ENTRY(bhvWaterMist), + BHV_ENTRY(bhvBreathParticleSpawner), + BHV_ENTRY(bhvBreakBoxTriangle), + BHV_ENTRY(bhvWaterMist2), + BHV_ENTRY(bhvUnused0DFC), + BHV_ENTRY(bhvMistCircParticleSpawner), + BHV_ENTRY(bhvDirtParticleSpawner), + BHV_ENTRY(bhvSnowParticleSpawner), + BHV_ENTRY(bhvWind), + BHV_ENTRY(bhvEndToad), + BHV_ENTRY(bhvEndPeach), + BHV_ENTRY(bhvUnusedParticleSpawn), + BHV_ENTRY(bhvUkiki), + BHV_ENTRY(bhvUkikiCageChild), + BHV_ENTRY(bhvUkikiCageStar), + BHV_ENTRY(bhvUkikiCage), + BHV_ENTRY(bhvBitfsSinkingPlatforms), + BHV_ENTRY(bhvBitfsSinkingCagePlatform), + BHV_ENTRY(bhvDddMovingPole), + BHV_ENTRY(bhvBitfsTiltingInvertedPyramid), + BHV_ENTRY(bhvSquishablePlatform), + BHV_ENTRY(bhvCutOutObject), + BHV_ENTRY(bhvBetaMovingFlames), + BHV_ENTRY(bhvRrRotatingBridgePlatform), + BHV_ENTRY(bhvFlamethrower), + BHV_ENTRY(bhvFlamethrowerFlame), + BHV_ENTRY(bhvBouncingFireball), + BHV_ENTRY(bhvBouncingFireballFlame), + BHV_ENTRY(bhvBowserShockWave), + BHV_ENTRY(bhvFireParticleSpawner), + BHV_ENTRY(bhvBlackSmokeMario), + BHV_ENTRY(bhvBlackSmokeBowser), + BHV_ENTRY(bhvBlackSmokeUpward), + BHV_ENTRY(bhvBetaFishSplashSpawner), + BHV_ENTRY(bhvSpindrift), + BHV_ENTRY(bhvTowerPlatformGroup), + BHV_ENTRY(bhvWfSlidingTowerPlatform), + BHV_ENTRY(bhvWfElevatorTowerPlatform), + BHV_ENTRY(bhvWfSolidTowerPlatform), + BHV_ENTRY(bhvLeafParticleSpawner), + BHV_ENTRY(bhvTreeSnow), + BHV_ENTRY(bhvTreeLeaf), + BHV_ENTRY(bhvAnotherTiltingPlatform), + BHV_ENTRY(bhvSquarishPathMoving), + BHV_ENTRY(bhvSquarishPathParent), + BHV_ENTRY(bhvPiranhaPlantBubble), + BHV_ENTRY(bhvPiranhaPlantWakingBubbles), + BHV_ENTRY(bhvFloorSwitchAnimatesObject), + BHV_ENTRY(bhvFloorSwitchGrills), + BHV_ENTRY(bhvFloorSwitchHardcodedModel), + BHV_ENTRY(bhvFloorSwitchHiddenObjects), + BHV_ENTRY(bhvHiddenObject), + BHV_ENTRY(bhvBreakableBox), + BHV_ENTRY(bhvPushableMetalBox), + BHV_ENTRY(bhvHeaveHo), + BHV_ENTRY(bhvHeaveHoThrowMario), + BHV_ENTRY(bhvCcmTouchedStarSpawn), + BHV_ENTRY(bhvUnusedPoundablePlatform), + BHV_ENTRY(bhvBetaTrampolineTop), + BHV_ENTRY(bhvBetaTrampolineSpring), + BHV_ENTRY(bhvJumpingBox), + BHV_ENTRY(bhvBooCage), + BHV_ENTRY(bhvStub), + BHV_ENTRY(bhvIgloo), + BHV_ENTRY(bhvBowserKey), + BHV_ENTRY(bhvGrandStar), + BHV_ENTRY(bhvBetaBooKey), + BHV_ENTRY(bhvAlphaBooKey), + BHV_ENTRY(bhvBulletBill), + BHV_ENTRY(bhvWhitePuffSmoke), + BHV_ENTRY(bhvUnused1820), + BHV_ENTRY(bhvBowserTailAnchor), + BHV_ENTRY(bhvBowser), + BHV_ENTRY(bhvBowserBodyAnchor), + BHV_ENTRY(bhvBowserFlameSpawn), + BHV_ENTRY(bhvTiltingBowserLavaPlatform), + BHV_ENTRY(bhvFallingBowserPlatform), + BHV_ENTRY(bhvBlueBowserFlame), + BHV_ENTRY(bhvFlameFloatingLanding), + BHV_ENTRY(bhvBlueFlamesGroup), + BHV_ENTRY(bhvFlameBouncing), + BHV_ENTRY(bhvFlameMovingForwardGrowing), + BHV_ENTRY(bhvFlameBowser), + BHV_ENTRY(bhvFlameLargeBurningOut), + BHV_ENTRY(bhvBlueFish), + BHV_ENTRY(bhvTankFishGroup), + BHV_ENTRY(bhvCheckerboardElevatorGroup), + BHV_ENTRY(bhvCheckerboardPlatformSub), + BHV_ENTRY(bhvBowserKeyUnlockDoor), + BHV_ENTRY(bhvBowserKeyCourseExit), + BHV_ENTRY(bhvInvisibleObjectsUnderBridge), + BHV_ENTRY(bhvWaterLevelPillar), + BHV_ENTRY(bhvDddWarp), + BHV_ENTRY(bhvMoatGrills), + BHV_ENTRY(bhvClockMinuteHand), + BHV_ENTRY(bhvClockHourHand), + BHV_ENTRY(bhvMacroUkiki), + BHV_ENTRY(bhvStub1D0C), + BHV_ENTRY(bhvLllRotatingHexagonalPlatform), + BHV_ENTRY(bhvLllSinkingRockBlock), + BHV_ENTRY(bhvStub1D70), + BHV_ENTRY(bhvLllMovingOctagonalMeshPlatform), + BHV_ENTRY(bhvLllRotatingBlockWithFireBars), + BHV_ENTRY(bhvLllRotatingHexFlame), + BHV_ENTRY(bhvLllWoodPiece), + BHV_ENTRY(bhvLllFloatingWoodBridge), + BHV_ENTRY(bhvVolcanoFlames), + BHV_ENTRY(bhvLllRotatingHexagonalRing), + BHV_ENTRY(bhvLllSinkingRectangularPlatform), + BHV_ENTRY(bhvLllSinkingSquarePlatforms), + BHV_ENTRY(bhvLllTiltingInvertedPyramid), + BHV_ENTRY(bhvUnused1F30), + BHV_ENTRY(bhvKoopaShell), + BHV_ENTRY(bhvKoopaShellFlame), + BHV_ENTRY(bhvToxBox), + BHV_ENTRY(bhvPiranhaPlant), + BHV_ENTRY(bhvLllHexagonalMesh), + BHV_ENTRY(bhvLllBowserPuzzlePiece), + BHV_ENTRY(bhvLllBowserPuzzle), + BHV_ENTRY(bhvTuxiesMother), + BHV_ENTRY(bhvPenguinBaby), + BHV_ENTRY(bhvUnused20E0), + BHV_ENTRY(bhvSmallPenguin), + BHV_ENTRY(bhvManyBlueFishSpawner), + BHV_ENTRY(bhvFewBlueFishSpawner), + BHV_ENTRY(bhvFishSpawner), + BHV_ENTRY(bhvFish), + BHV_ENTRY(bhvWdwExpressElevator), + BHV_ENTRY(bhvWdwExpressElevatorPlatform), + BHV_ENTRY(bhvChirpChirp), + BHV_ENTRY(bhvBub), + BHV_ENTRY(bhvExclamationBox), + BHV_ENTRY(bhvRotatingExclamationMark), + BHV_ENTRY(bhvSoundSpawner), + BHV_ENTRY(bhvRockSolid), + BHV_ENTRY(bhvBowserSubDoor), + BHV_ENTRY(bhvBowsersSub), + BHV_ENTRY(bhvSushiShark), + BHV_ENTRY(bhvSushiSharkCollisionChild), + BHV_ENTRY(bhvJrbSlidingBox), + BHV_ENTRY(bhvShipPart3), + BHV_ENTRY(bhvInSunkenShip3), + BHV_ENTRY(bhvSunkenShipPart), + BHV_ENTRY(bhvSunkenShipPart2), + BHV_ENTRY(bhvInSunkenShip), + BHV_ENTRY(bhvInSunkenShip2), + BHV_ENTRY(bhvMistParticleSpawner), + BHV_ENTRY(bhvWhitePuff1), + BHV_ENTRY(bhvWhitePuff2), + BHV_ENTRY(bhvWhitePuffSmoke2), + BHV_ENTRY(bhvPurpleSwitchHiddenBoxes), + BHV_ENTRY(bhvBlueCoinSwitch), + BHV_ENTRY(bhvHiddenBlueCoin), + BHV_ENTRY(bhvOpenableCageDoor), + BHV_ENTRY(bhvOpenableGrill), + BHV_ENTRY(bhvWaterLevelDiamond), + BHV_ENTRY(bhvInitializeChangingWaterLevel), + BHV_ENTRY(bhvTweesterSandParticle), + BHV_ENTRY(bhvTweester), + BHV_ENTRY(bhvMerryGoRoundBooManager), + BHV_ENTRY(bhvAnimatedTexture), + BHV_ENTRY(bhvBooInCastle), + BHV_ENTRY(bhvBooWithCage), + BHV_ENTRY(bhvBalconyBigBoo), + BHV_ENTRY(bhvMerryGoRoundBigBoo), + BHV_ENTRY(bhvGhostHuntBigBoo), + BHV_ENTRY(bhvCourtyardBooTriplet), + BHV_ENTRY(bhvBoo), + BHV_ENTRY(bhvMerryGoRoundBoo), + BHV_ENTRY(bhvGhostHuntBoo), + BHV_ENTRY(bhvHiddenStaircaseStep), + BHV_ENTRY(bhvBooBossSpawnedBridge), + BHV_ENTRY(bhvBbhTiltingTrapPlatform), + BHV_ENTRY(bhvHauntedBookshelf), + BHV_ENTRY(bhvMeshElevator), + BHV_ENTRY(bhvMerryGoRound), + BHV_ENTRY(bhvPlaysMusicTrackWhenTouched), + BHV_ENTRY(bhvBetaBowserAnchor), + BHV_ENTRY(bhvStaticCheckeredPlatform), + BHV_ENTRY(bhvUnused2A10), + BHV_ENTRY(bhvUnusedFakeStar), + BHV_ENTRY(bhvStaticObject), + BHV_ENTRY(bhvUnused2A54), + BHV_ENTRY(bhvCastleFloorTrap), + BHV_ENTRY(bhvFloorTrapInCastle), + BHV_ENTRY(bhvTree), + BHV_ENTRY(bhvSparkle), + BHV_ENTRY(bhvSparkleSpawn), + BHV_ENTRY(bhvSparkleParticleSpawner), + BHV_ENTRY(bhvScuttlebug), + BHV_ENTRY(bhvScuttlebugSpawn), + BHV_ENTRY(bhvWhompKingBoss), + BHV_ENTRY(bhvSmallWhomp), + BHV_ENTRY(bhvWaterSplash), + BHV_ENTRY(bhvWaterDroplet), + BHV_ENTRY(bhvWaterDropletSplash), + BHV_ENTRY(bhvBubbleSplash), + BHV_ENTRY(bhvIdleWaterWave), + BHV_ENTRY(bhvObjectWaterSplash), + BHV_ENTRY(bhvShallowWaterWave), + BHV_ENTRY(bhvShallowWaterSplash), + BHV_ENTRY(bhvObjectWaveTrail), + BHV_ENTRY(bhvWaveTrail), + BHV_ENTRY(bhvTinyStrongWindParticle), + BHV_ENTRY(bhvStrongWindParticle), + BHV_ENTRY(bhvSLSnowmanWind), + BHV_ENTRY(bhvSLWalkingPenguin), + BHV_ENTRY(bhvYellowBall), + BHV_ENTRY(bhvMario), + BHV_ENTRY(bhvToadMessage), + BHV_ENTRY(bhvUnlockDoorStar), + BHV_ENTRY(bhvRandomAnimatedTexture), + BHV_ENTRY(bhvYellowBackgroundInMenu), + BHV_ENTRY(bhvMenuButton), + BHV_ENTRY(bhvMenuButtonManager), + BHV_ENTRY(bhvActSelectorStarType), + BHV_ENTRY(bhvActSelector), + BHV_ENTRY(bhvMovingYellowCoin), + BHV_ENTRY(bhvMovingBlueCoin), + BHV_ENTRY(bhvBlueCoinSliding), + BHV_ENTRY(bhvBlueCoinJumping), + BHV_ENTRY(bhvSeaweed), + BHV_ENTRY(bhvSeaweedBundle), + BHV_ENTRY(bhvBobomb), + BHV_ENTRY(bhvBobombFuseSmoke), + BHV_ENTRY(bhvBobombBuddy), + BHV_ENTRY(bhvBobombBuddyOpensCannon), + BHV_ENTRY(bhvCannonClosed), + BHV_ENTRY(bhvWhirlpool), + BHV_ENTRY(bhvJetStream), + BHV_ENTRY(bhvMessagePanel), + BHV_ENTRY(bhvSignOnWall), + BHV_ENTRY(bhvHomingAmp), + BHV_ENTRY(bhvCirclingAmp), + BHV_ENTRY(bhvButterfly), + BHV_ENTRY(bhvHoot), + BHV_ENTRY(bhvBetaHoldableObject), + BHV_ENTRY(bhvCarrySomething1), + BHV_ENTRY(bhvCarrySomething2), + BHV_ENTRY(bhvCarrySomething3), + BHV_ENTRY(bhvCarrySomething4), + BHV_ENTRY(bhvCarrySomething5), + BHV_ENTRY(bhvCarrySomething6), + BHV_ENTRY(bhvObjectBubble), + BHV_ENTRY(bhvObjectWaterWave), + BHV_ENTRY(bhvExplosion), + BHV_ENTRY(bhvBobombBullyDeathSmoke), + BHV_ENTRY(bhvSmoke), + BHV_ENTRY(bhvBobombExplosionBubble), + BHV_ENTRY(bhvRespawner), + BHV_ENTRY(bhvSmallBully), + BHV_ENTRY(bhvBigBully), + BHV_ENTRY(bhvBigBullyWithMinions), + BHV_ENTRY(bhvSmallChillBully), + BHV_ENTRY(bhvBigChillBully), + BHV_ENTRY(bhvJetStreamRingSpawner), + BHV_ENTRY(bhvJetStreamWaterRing), + BHV_ENTRY(bhvMantaRayWaterRing), + BHV_ENTRY(bhvMantaRayRingManager), + BHV_ENTRY(bhvBowserBomb), + BHV_ENTRY(bhvBowserBombExplosion), + BHV_ENTRY(bhvBowserBombSmoke), + BHV_ENTRY(bhvCelebrationStar), + BHV_ENTRY(bhvCelebrationStarSparkle), + BHV_ENTRY(bhvStarKeyCollectionPuffSpawner), + BHV_ENTRY(bhvLllDrawbridgeSpawner), + BHV_ENTRY(bhvLllDrawbridge), + BHV_ENTRY(bhvSmallBomp), + BHV_ENTRY(bhvLargeBomp), + BHV_ENTRY(bhvWfSlidingPlatform), + BHV_ENTRY(bhvMoneybag), + BHV_ENTRY(bhvMoneybagHidden), + BHV_ENTRY(bhvPitBowlingBall), + BHV_ENTRY(bhvFreeBowlingBall), + BHV_ENTRY(bhvBowlingBall), + BHV_ENTRY(bhvTtmBowlingBallSpawner), + BHV_ENTRY(bhvBobBowlingBallSpawner), + BHV_ENTRY(bhvThiBowlingBallSpawner), + BHV_ENTRY(bhvRrCruiserWing), + BHV_ENTRY(bhvSpindel), + BHV_ENTRY(bhvSslMovingPyramidWall), + BHV_ENTRY(bhvPyramidElevator), + BHV_ENTRY(bhvPyramidElevatorTrajectoryMarkerBall), + BHV_ENTRY(bhvPyramidTop), + BHV_ENTRY(bhvPyramidTopFragment), + BHV_ENTRY(bhvPyramidPillarTouchDetector), + BHV_ENTRY(bhvWaterfallSoundLoop), + BHV_ENTRY(bhvVolcanoSoundLoop), + BHV_ENTRY(bhvCastleFlagWaving), + BHV_ENTRY(bhvBirdsSoundLoop), + BHV_ENTRY(bhvAmbientSounds), + BHV_ENTRY(bhvSandSoundLoop), + BHV_ENTRY(bhvHiddenAt120Stars), + BHV_ENTRY(bhvSnowmansBottom), + BHV_ENTRY(bhvSnowmansHead), + BHV_ENTRY(bhvSnowmansBodyCheckpoint), + BHV_ENTRY(bhvBigSnowmanWhole), + BHV_ENTRY(bhvBigBoulder), + BHV_ENTRY(bhvBigBoulderGenerator), + BHV_ENTRY(bhvWingCap), + BHV_ENTRY(bhvMetalCap), + BHV_ENTRY(bhvNormalCap), + BHV_ENTRY(bhvVanishCap), + BHV_ENTRY(bhvStar), + BHV_ENTRY(bhvStarSpawnCoordinates), + BHV_ENTRY(bhvHiddenRedCoinStar), + BHV_ENTRY(bhvRedCoin), + BHV_ENTRY(bhvBowserCourseRedCoinStar), + BHV_ENTRY(bhvHiddenStar), + BHV_ENTRY(bhvHiddenStarTrigger), + BHV_ENTRY(bhvTtmRollingLog), + BHV_ENTRY(bhvLllVolcanoFallingTrap), + BHV_ENTRY(bhvLllRollingLog), + BHV_ENTRY(bhv1upWalking), + BHV_ENTRY(bhv1upRunningAway), + BHV_ENTRY(bhv1upSliding), + BHV_ENTRY(bhv1Up), + BHV_ENTRY(bhv1upJumpOnApproach), + BHV_ENTRY(bhvHidden1up), + BHV_ENTRY(bhvHidden1upTrigger), + BHV_ENTRY(bhvHidden1upInPole), + BHV_ENTRY(bhvHidden1upInPoleTrigger), + BHV_ENTRY(bhvHidden1upInPoleSpawner), + BHV_ENTRY(bhvControllablePlatform), + BHV_ENTRY(bhvControllablePlatformSub), + BHV_ENTRY(bhvBreakableBoxSmall), + BHV_ENTRY(bhvSlidingSnowMound), + BHV_ENTRY(bhvSnowMoundSpawn), + BHV_ENTRY(bhvWdwSquareFloatingPlatform), + BHV_ENTRY(bhvWdwRectangularFloatingPlatform), + BHV_ENTRY(bhvJrbFloatingPlatform), + BHV_ENTRY(bhvArrowLift), + BHV_ENTRY(bhvOrangeNumber), + BHV_ENTRY(bhvMantaRay), + BHV_ENTRY(bhvFallingPillar), + BHV_ENTRY(bhvFallingPillarHitbox), + BHV_ENTRY(bhvPillarBase), + BHV_ENTRY(bhvJrbFloatingBox), + BHV_ENTRY(bhvDecorativePendulum), + BHV_ENTRY(bhvTreasureChestsShip), + BHV_ENTRY(bhvTreasureChestsJrb), + BHV_ENTRY(bhvTreasureChests), + BHV_ENTRY(bhvTreasureChestBottom), + BHV_ENTRY(bhvTreasureChestTop), + BHV_ENTRY(bhvMips), + BHV_ENTRY(bhvYoshi), + BHV_ENTRY(bhvKoopa), + BHV_ENTRY(bhvKoopaRaceEndpoint), + BHV_ENTRY(bhvKoopaFlag), + BHV_ENTRY(bhvPokey), + BHV_ENTRY(bhvPokeyBodyPart), + BHV_ENTRY(bhvSwoop), + BHV_ENTRY(bhvFlyGuy), + BHV_ENTRY(bhvGoomba), + BHV_ENTRY(bhvGoombaTripletSpawner), + BHV_ENTRY(bhvChainChomp), + BHV_ENTRY(bhvChainChompChainPart), + BHV_ENTRY(bhvWoodenPost), + BHV_ENTRY(bhvChainChompGate), + BHV_ENTRY(bhvWigglerHead), + BHV_ENTRY(bhvWigglerBody), + BHV_ENTRY(bhvEnemyLakitu), + BHV_ENTRY(bhvCameraLakitu), + BHV_ENTRY(bhvCloud), + BHV_ENTRY(bhvCloudPart), + BHV_ENTRY(bhvSpiny), + BHV_ENTRY(bhvMontyMole), + BHV_ENTRY(bhvMontyMoleHole), + BHV_ENTRY(bhvMontyMoleRock), + BHV_ENTRY(bhvPlatformOnTrack), + BHV_ENTRY(bhvTrackBall), + BHV_ENTRY(bhvSeesawPlatform), + BHV_ENTRY(bhvFerrisWheelAxle), + BHV_ENTRY(bhvFerrisWheelPlatform), + BHV_ENTRY(bhvWaterBombSpawner), + BHV_ENTRY(bhvWaterBomb), + BHV_ENTRY(bhvWaterBombShadow), + BHV_ENTRY(bhvTTCRotatingSolid), + BHV_ENTRY(bhvTTCPendulum), + BHV_ENTRY(bhvTTCTreadmill), + BHV_ENTRY(bhvTTCMovingBar), + BHV_ENTRY(bhvTTCCog), + BHV_ENTRY(bhvTTCPitBlock), + BHV_ENTRY(bhvTTCElevator), + BHV_ENTRY(bhvTTC2DRotator), + BHV_ENTRY(bhvTTCSpinner), + BHV_ENTRY(bhvMrBlizzard), + BHV_ENTRY(bhvMrBlizzardSnowball), + BHV_ENTRY(bhvSlidingPlatform2), + BHV_ENTRY(bhvOctagonalPlatformRotating), + BHV_ENTRY(bhvAnimatesOnFloorSwitchPress), + BHV_ENTRY(bhvActivatedBackAndForthPlatform), + BHV_ENTRY(bhvRecoveryHeart), + BHV_ENTRY(bhvWaterBombCannon), + BHV_ENTRY(bhvCannonBarrelBubbles), + BHV_ENTRY(bhvUnagi), + BHV_ENTRY(bhvUnagiSubobject), + BHV_ENTRY(bhvDorrie), + BHV_ENTRY(bhvHauntedChair), + BHV_ENTRY(bhvMadPiano), + BHV_ENTRY(bhvFlyingBookend), + BHV_ENTRY(bhvBookendSpawn), + BHV_ENTRY(bhvHauntedBookshelfManager), + BHV_ENTRY(bhvBookSwitch), + BHV_ENTRY(bhvFirePiranhaPlant), + BHV_ENTRY(bhvSmallPiranhaFlame), + BHV_ENTRY(bhvFireSpitter), + BHV_ENTRY(bhvFlyguyFlame), + BHV_ENTRY(bhvSnufit), + BHV_ENTRY(bhvSnufitBalls), + BHV_ENTRY(bhvHorizontalGrindel), + BHV_ENTRY(bhvEyerokBoss), + BHV_ENTRY(bhvEyerokHand), + BHV_ENTRY(bhvKlepto), + BHV_ENTRY(bhvBird), + BHV_ENTRY(bhvRacingPenguin), + BHV_ENTRY(bhvPenguinRaceFinishLine), + BHV_ENTRY(bhvPenguinRaceShortcutCheck), + BHV_ENTRY(bhvCoffinSpawner), + BHV_ENTRY(bhvCoffin), + BHV_ENTRY(bhvClamShell), + BHV_ENTRY(bhvSkeeter), + BHV_ENTRY(bhvSkeeterWave), + BHV_ENTRY(bhvSwingPlatform), + BHV_ENTRY(bhvDonutPlatformSpawner), + BHV_ENTRY(bhvDonutPlatform), + BHV_ENTRY(bhvDDDPole), + BHV_ENTRY(bhvRedCoinStarMarker), + BHV_ENTRY(bhvTripletButterfly), + BHV_ENTRY(bhvBubba), + BHV_ENTRY(bhvBeginningLakitu), + BHV_ENTRY(bhvBeginningPeach), + BHV_ENTRY(bhvEndBirds1), + BHV_ENTRY(bhvEndBirds2), + BHV_ENTRY(bhvIntroScene), +}; enum BehaviorId get_id_from_behavior(const BehaviorScript* behavior) { - if (behavior == NULL) { return 0; } + if (behavior == NULL) { return id_bhv_max_count; } return (enum BehaviorId)(behavior[1] & 0xFFFF); } +enum BehaviorId get_id_from_vanilla_behavior(const BehaviorScript* behavior) { + if (behavior == NULL) { return id_bhv_max_count; } + enum BehaviorId id = (enum BehaviorId)(behavior[1] & 0xFFFF); + if (id == id_bhv_max_count) { return id_bhv_max_count; } + if (gBehaviorTable[id].script != behavior) { return id_bhv_max_count; } + return id; +} + const BehaviorScript* get_behavior_from_id(enum BehaviorId id) { const BehaviorScript* behavior = get_lua_behavior_from_id(id, true); if (behavior != NULL) { return behavior; } @@ -533,5 +548,22 @@ const BehaviorScript* get_behavior_from_id(enum BehaviorId id) { return NULL; } - return gBehaviorTable[id]; + return gBehaviorTable[id].script; +} + +const char* get_behavior_name_from_id(enum BehaviorId id) { + if (id < 0 || id >= id_bhv_max_count) { + return NULL; + } + + return gBehaviorTable[id].name; +} + +enum BehaviorId get_id_from_behavior_name(const char* name) { + for (enum BehaviorId i = 0; i < id_bhv_max_count; i++) { + if (!strcmp(name, gBehaviorTable[i].name)) { + return i; + } + } + return id_bhv_max_count; } diff --git a/data/dynos.c.h b/data/dynos.c.h index 848248b9..920a85a6 100644 --- a/data/dynos.c.h +++ b/data/dynos.c.h @@ -30,9 +30,14 @@ void dynos_add_actor_custom(const char *modPath, const char* geoName); const void* dynos_geolayout_get(const char *name); // -- collisions -- // -void dynos_add_collision_custom(const char *modPath, const char* collisionName); +void dynos_add_collision(const char *modPath, const char* collisionName); Collision* dynos_collision_get(const char* collisionName); +// -- levels -- // + +void dynos_add_level(const char *modPath, const char* levelName); +LevelScript* dynos_level_get(const char* levelName); + #endif #endif \ No newline at end of file diff --git a/data/dynos.cpp.h b/data/dynos.cpp.h index 4d465670..b99fd527 100644 --- a/data/dynos.cpp.h +++ b/data/dynos.cpp.h @@ -693,6 +693,9 @@ s16 *DynOS_Level_GetWarp(s32 aLevel, s32 aArea, u8 aWarpId); s16 *DynOS_Level_GetWarpEntry(s32 aLevel, s32 aArea); s16 *DynOS_Level_GetWarpDeath(s32 aLevel, s32 aArea); +void DynOS_Lvl_Add(const SysPath &aPackFolder, const char *aLevelName); +LevelScript* DynOS_Lvl_Get(const char* levelName); + // // Warps // @@ -709,8 +712,8 @@ const char *DynOS_Warp_GetParamName(s32 aLevel, s32 aIndex); // Collisions // -void DynOS_Col_AddCollisionCustom(const SysPath &aPackFolder, const char *aCollisionName); -Collision* DynOS_Col_GetCollision(const char* collisionName); +void DynOS_Col_Add(const SysPath &aPackFolder, const char *aCollisionName); +Collision* DynOS_Col_Get(const char* collisionName); // // Bin @@ -729,6 +732,7 @@ void DynOS_Anim_Table_Load(FILE *aFile, GfxData *aGfxData); DataNode* DynOS_Col_Parse(GfxData* aGfxData, DataNode* aNode, bool aDisplayPercent); void DynOS_Col_Write(FILE* aFile, GfxData* aGfxData, DataNode *aNode); +DataNode* DynOS_Col_Load(FILE *aFile, GfxData *aGfxData); DataNode* DynOS_Col_LoadFromBinary(const SysPath &aPackFolder, const char *aCollisionName); void DynOS_Col_Generate(const SysPath &aPackFolder, Array> _ActorsFolders, GfxData *_GfxData); @@ -745,8 +749,8 @@ void DynOS_Lights_Write(FILE* aFile, GfxData* aGfxData, DataNode *aNode void DynOS_Lights_Load(FILE *aFile, GfxData *aGfxData); DataNode* DynOS_MacroObject_Parse(GfxData* aGfxData, DataNode* aNode, bool aDisplayPercent); -// TODO: DynOS_MacroObject_Write -// TODO: DynOS_MacroObject_Load +void DynOS_MacroObject_Write(FILE* aFile, GfxData* aGfxData, DataNode *aNode); +DataNode* DynOS_MacroObject_Load(FILE *aFile, GfxData *aGfxData); DataNode* DynOS_Tex_Parse(GfxData* aGfxData, DataNode* aNode); void DynOS_Tex_Write(FILE* aFile, GfxData* aGfxData, DataNode *aNode); @@ -758,7 +762,7 @@ void DynOS_Vtx_Write(FILE* aFile, GfxData* aGfxData, DataNode *aNode); void DynOS_Vtx_Load(FILE *aFile, GfxData *aGfxData); void DynOS_Pointer_Write(FILE* aFile, const void* aPtr, GfxData* aGfxData); -void *DynOS_Pointer_Load(FILE *aFile, GfxData *aGfxData, u32 aValue); +void *DynOS_Pointer_Load(FILE *aFile, GfxData *aGfxData, u32 aValue, bool isLvl); void DynOS_GfxDynCmd_Load(FILE *aFile, GfxData *aGfxData); @@ -766,9 +770,10 @@ GfxData *DynOS_Actor_LoadFromBinary(const SysPath &aPackFolder, const char *aAct void DynOS_Actor_GeneratePack(const SysPath &aPackFolder); DataNode* DynOS_Lvl_Parse(GfxData* aGfxData, DataNode* aNode, bool aDisplayPercent); -// TODO: DynOS_Lvl_Write -// TODO: DynOS_Lvl_Load +GfxData *DynOS_Lvl_LoadFromBinary(const SysPath &aPackFolder, const char *aLevelName); void DynOS_Lvl_GeneratePack(const SysPath &aPackFolder); +s32 DynOS_Lvl_GetFunctionIndex(const void *aPtr); +void *DynOS_Lvl_GetFunctionPointerFromIndex(s32 aIndex); #endif #endif diff --git a/data/dynos_bin_col.cpp b/data/dynos_bin_col.cpp index c0aa1a88..57e39d83 100644 --- a/data/dynos_bin_col.cpp +++ b/data/dynos_bin_col.cpp @@ -436,7 +436,7 @@ static bool DynOS_Col_WriteBinary(const SysPath &aOutputFilename, GfxData *aGfxD // Loading // ///////////// -static DataNode* LoadCollisionData(FILE *aFile) { +DataNode* DynOS_Col_Load(FILE *aFile, GfxData *aGfxData) { DataNode *_Node = New>(); // Name @@ -449,6 +449,11 @@ static DataNode* LoadCollisionData(FILE *aFile) { _Node->mData[i] = ReadBytes(aFile); } + // Add it + if (aGfxData != NULL) { + aGfxData->mCollisions.Add(_Node); + } + return _Node; } @@ -460,7 +465,7 @@ DataNode* DynOS_Col_LoadFromBinary(const SysPath &aPackFolder, const if (_File) { u8 type = ReadBytes(_File); if (type == DATA_TYPE_COLLISION) { - collisionNode = LoadCollisionData(_File); + collisionNode = DynOS_Col_Load(_File, NULL); } fclose(_File); } diff --git a/data/dynos_bin_geo.cpp b/data/dynos_bin_geo.cpp index 820f38ee..229012c9 100644 --- a/data/dynos_bin_geo.cpp +++ b/data/dynos_bin_geo.cpp @@ -398,7 +398,7 @@ void DynOS_Geo_Load(FILE *aFile, GfxData *aGfxData) { _Node->mData = New(_Node->mSize); for (u32 i = 0; i != _Node->mSize; ++i) { u32 _Value = ReadBytes(aFile); - void *_Ptr = DynOS_Pointer_Load(aFile, aGfxData, _Value); + void *_Ptr = DynOS_Pointer_Load(aFile, aGfxData, _Value, false); if (_Ptr) { _Node->mData[i] = (uintptr_t) _Ptr; } else { diff --git a/data/dynos_bin_gfx.cpp b/data/dynos_bin_gfx.cpp index e4e10d43..7feed4aa 100644 --- a/data/dynos_bin_gfx.cpp +++ b/data/dynos_bin_gfx.cpp @@ -894,7 +894,7 @@ void DynOS_Gfx_Load(FILE *aFile, GfxData *aGfxData) { for (u32 i = 0; i != _Node->mSize; ++i) { u32 _WordsW0 = ReadBytes(aFile); u32 _WordsW1 = ReadBytes(aFile); - void *_Ptr = DynOS_Pointer_Load(aFile, aGfxData, _WordsW1); + void *_Ptr = DynOS_Pointer_Load(aFile, aGfxData, _WordsW1, false); if (_Ptr) { _Node->mData[i].words.w0 = (uintptr_t) _WordsW0; _Node->mData[i].words.w1 = (uintptr_t) _Ptr; diff --git a/data/dynos_bin_lvl.cpp b/data/dynos_bin_lvl.cpp index 6d3fd175..8f403c0b 100644 --- a/data/dynos_bin_lvl.cpp +++ b/data/dynos_bin_lvl.cpp @@ -33,14 +33,27 @@ return sLvlFunctions; #define sLvlFunctions __LvlFunctions() void *DynOS_Lvl_GetFunctionPointerFromName(const String &aName) { - for (const auto &_GeoFunction : sLvlFunctions) { - if (aName == _GeoFunction.first) { - return _GeoFunction.second; + for (const auto &_LvlFunction : sLvlFunctions) { + if (aName == _LvlFunction.first) { + return _LvlFunction.second; } }; return NULL; } +s32 DynOS_Lvl_GetFunctionIndex(const void *aPtr) { + for (const auto &_LvlFunction : sLvlFunctions) { + if (_LvlFunction.second == aPtr) { + return (s32) (&_LvlFunction - sLvlFunctions.begin()); + } + } + return -1; +} + +void *DynOS_Lvl_GetFunctionPointerFromIndex(s32 aIndex) { + return sLvlFunctions[aIndex].second; +} + ///////////// // Parsing // ///////////// @@ -1478,6 +1491,149 @@ static DataNode *GetLevelScript(GfxData *aGfxData, const String& aG return NULL; } + ///////////// + // Writing // +///////////// + +static void DynOS_Lvl_Write(FILE* aFile, GfxData* aGfxData, DataNode *aNode) { + if (!aNode->mData) return; + + // Name + WriteBytes(aFile, DATA_TYPE_LEVEL_SCRIPT); + aNode->mName.Write(aFile); + + // Data + WriteBytes(aFile, aNode->mSize); + for (u32 i = 0; i != aNode->mSize; ++i) { + LevelScript *_Head = &aNode->mData[i]; + if (aGfxData->mPointerList.Find((void *) _Head) != -1) { + DynOS_Pointer_Write(aFile, (const void *) (*_Head), aGfxData); + } else { + WriteBytes(aFile, *((u32 *) _Head)); + } + } +} + +static bool DynOS_Lvl_WriteBinary(const SysPath &aOutputFilename, GfxData *aGfxData) { + FILE *_File = fopen(aOutputFilename.c_str(), "wb"); + if (!_File) { + PrintError(" ERROR: Unable to create file \"%s\"", aOutputFilename.c_str()); + return false; + } + + for (u64 i = 0; i != aGfxData->mLoadIndex; ++i) { + for (auto &_Node : aGfxData->mLights) { + if (_Node->mLoadIndex == i) { + DynOS_Lights_Write(_File, aGfxData, _Node); + } + } + for (auto &_Node : aGfxData->mTextures) { + if (_Node->mLoadIndex == i) { + DynOS_Tex_Write(_File, aGfxData, _Node); + } + } + for (auto &_Node : aGfxData->mVertices) { + if (_Node->mLoadIndex == i) { + DynOS_Vtx_Write(_File, aGfxData, _Node); + } + } + for (auto &_Node : aGfxData->mDisplayLists) { + if (_Node->mLoadIndex == i) { + DynOS_Gfx_Write(_File, aGfxData, _Node); + } + } + for (auto &_Node : aGfxData->mGeoLayouts) { + if (_Node->mLoadIndex == i) { + DynOS_Geo_Write(_File, aGfxData, _Node); + } + } + for (auto &_Node : aGfxData->mCollisions) { + if (_Node->mLoadIndex == i) { + DynOS_Col_Write(_File, aGfxData, _Node); + } + } + for (auto &_Node : aGfxData->mLevelScripts) { + if (_Node->mLoadIndex == i) { + DynOS_Lvl_Write(_File, aGfxData, _Node); + } + } + for (auto &_Node : aGfxData->mMacroObjects) { + if (_Node->mLoadIndex == i) { + DynOS_MacroObject_Write(_File, aGfxData, _Node); + } + } + } + fclose(_File); + return true; +} + + ///////////// + // Reading // +///////////// + +static DataNode* DynOS_Lvl_Load(FILE *aFile, GfxData *aGfxData) { + DataNode *_Node = New>(); + + // Name + _Node->mName.Read(aFile); + + // Data + _Node->mSize = ReadBytes(aFile); + _Node->mData = New(_Node->mSize); + for (u32 i = 0; i != _Node->mSize; ++i) { + u32 _Value = ReadBytes(aFile); + void *_Ptr = DynOS_Pointer_Load(aFile, aGfxData, _Value, true); + if (_Ptr) { + _Node->mData[i] = (uintptr_t) _Ptr; + } else { + _Node->mData[i] = (uintptr_t) _Value; + } + } + + // Add it + if (aGfxData != NULL) { + aGfxData->mLevelScripts.Add(_Node); + } + + return _Node; +} + +GfxData *DynOS_Lvl_LoadFromBinary(const SysPath &aPackFolder, const char *aLevelName) { + struct DynosGfxDataCache { SysPath mPackFolder; Array> mGfxData; }; + static Array sDynosGfxDataCache; + + // Load data from binary file + GfxData *_GfxData = NULL; + SysPath _Filename = fstring("%s/%s.lvl", aPackFolder.begin(), aLevelName); + FILE *_File = fopen(_Filename.c_str(), "rb"); + if (_File) { + _GfxData = New(); + for (bool _Done = false; !_Done;) { + switch (ReadBytes(_File)) { + case DATA_TYPE_LIGHT: DynOS_Lights_Load (_File, _GfxData); break; + case DATA_TYPE_TEXTURE: DynOS_Tex_Load (_File, _GfxData); break; + case DATA_TYPE_VERTEX: DynOS_Vtx_Load (_File, _GfxData); break; + case DATA_TYPE_DISPLAY_LIST: DynOS_Gfx_Load (_File, _GfxData); break; + case DATA_TYPE_GEO_LAYOUT: DynOS_Geo_Load (_File, _GfxData); break; + case DATA_TYPE_ANIMATION: DynOS_Anim_Load (_File, _GfxData); break; + case DATA_TYPE_ANIMATION_TABLE: DynOS_Anim_Table_Load (_File, _GfxData); break; + case DATA_TYPE_GFXDYNCMD: DynOS_GfxDynCmd_Load (_File, _GfxData); break; + case DATA_TYPE_COLLISION: DynOS_Col_Load (_File, _GfxData); break; + case DATA_TYPE_LEVEL_SCRIPT: DynOS_Lvl_Load (_File, _GfxData); break; + case DATA_TYPE_MACRO_OBJECT: DynOS_MacroObject_Load(_File, _GfxData); break; + default: _Done = true; break; + } + } + fclose(_File); + } + + return _GfxData; +} + + ////////////// + // Generate // +////////////// + static bool DynOS_Lvl_GeneratePack_Internal(const SysPath &aPackFolder, Array> _ActorsFolders, GfxData *_GfxData) { bool generated = false; for (auto &_LvlNode : _GfxData->mLevelScripts) { @@ -1501,7 +1657,7 @@ static bool DynOS_Lvl_GeneratePack_Internal(const SysPath &aPackFolder, ArraymErrorCount == 0) { - //DynOS_Lvl_WriteBinary(_LvlFilename, _GfxData, _LvlRoot); + DynOS_Lvl_WriteBinary(_LvlFilename, _GfxData); } else { Print(" %u error(s): Unable to parse data", _GfxData->mErrorCount); } @@ -1513,10 +1669,6 @@ static bool DynOS_Lvl_GeneratePack_Internal(const SysPath &aPackFolder, Array> _ActorsFolders; diff --git a/data/dynos_bin_macro_object.cpp b/data/dynos_bin_macro_object.cpp index ab4c715d..98e34d67 100644 --- a/data/dynos_bin_macro_object.cpp +++ b/data/dynos_bin_macro_object.cpp @@ -464,3 +464,46 @@ DataNode* DynOS_MacroObject_Parse(GfxData* aGfxData, DataNode *aNode) { + if (!aNode->mData) return; + + // Name + WriteBytes(aFile, DATA_TYPE_MACRO_OBJECT); + aNode->mName.Write(aFile); + + // Data + WriteBytes(aFile, aNode->mSize); + for (u32 i = 0; i != aNode->mSize; ++i) { + WriteBytes(aFile, aNode->mData[i]); + } +} + + ///////////// + // Reading // +///////////// + +DataNode* DynOS_MacroObject_Load(FILE *aFile, GfxData *aGfxData) { + DataNode *_Node = New>(); + + // Name + _Node->mName.Read(aFile); + + // Data + _Node->mSize = ReadBytes(aFile); + _Node->mData = New(_Node->mSize); + for (u32 i = 0; i != _Node->mSize; ++i) { + _Node->mData[i] = ReadBytes(aFile); + } + + // Add it + if (aGfxData != NULL) { + aGfxData->mMacroObjects.Add(_Node); + } + + return _Node; +} diff --git a/data/dynos_bin_pointer.cpp b/data/dynos_bin_pointer.cpp index e1615c6e..9d7b13e6 100644 --- a/data/dynos_bin_pointer.cpp +++ b/data/dynos_bin_pointer.cpp @@ -1,12 +1,13 @@ #include "dynos.cpp.h" - +extern "C" { +#include "behavior_table.h" +} ///////////// // Writing // ///////////// typedef Pair PointerData; static PointerData GetDataFromPointer(const void* aPtr, GfxData* aGfxData) { - // Lights for (auto& _Node : aGfxData->mLights) { if (&_Node->mData->l[0] == aPtr) { // Light *, not Lights1 * @@ -59,6 +60,12 @@ static PointerData GetDataFromPointer(const void* aPtr, GfxData* aGfxData) { } } + // Behaviors + enum BehaviorId id = get_id_from_vanilla_behavior((const BehaviorScript*) aPtr); + if (id >= 0 && id < id_bhv_max_count) { + return { get_behavior_name_from_id(id), 0 }; + } + // Vertices String _VtxArrayName = ""; uintptr_t _VtxArrayStart = 0; @@ -91,6 +98,14 @@ void DynOS_Pointer_Write(FILE* aFile, const void* aPtr, GfxData* aGfxData) { return; } + // Lvl function + s32 _LvlFunctionIndex = DynOS_Lvl_GetFunctionIndex(aPtr); + if (_LvlFunctionIndex != -1) { + WriteBytes(aFile, FUNCTION_CODE); + WriteBytes(aFile, _LvlFunctionIndex); + return; + } + // Pointer PointerData _PtrData = GetDataFromPointer(aPtr, aGfxData); WriteBytes(aFile, POINTER_CODE); @@ -166,17 +181,25 @@ static void *GetPointerFromData(GfxData *aGfxData, const String &aPtrName, u32 a } } + // Behaviors + enum BehaviorId id = get_id_from_behavior_name(aPtrName.begin()); + if (id >= 0 && id < id_bhv_max_count) { + return (void*)get_behavior_from_id(id); + } + // Error sys_fatal("Pointer not found: %s", aPtrName.begin()); return NULL; } -void *DynOS_Pointer_Load(FILE *aFile, GfxData *aGfxData, u32 aValue) { +void *DynOS_Pointer_Load(FILE *aFile, GfxData *aGfxData, u32 aValue, bool isLvl) { // FUNC if (aValue == FUNCTION_CODE) { - s32 _GeoFunctionIndex = ReadBytes(aFile); - return DynOS_Geo_GetFunctionPointerFromIndex(_GeoFunctionIndex); + s32 _FunctionIndex = ReadBytes(aFile); + return isLvl + ? DynOS_Lvl_GetFunctionPointerFromIndex(_FunctionIndex) + : DynOS_Geo_GetFunctionPointerFromIndex(_FunctionIndex); } // PNTR diff --git a/data/dynos_bin_read.cpp b/data/dynos_bin_read.cpp index cd73eee2..1317e7f4 100644 --- a/data/dynos_bin_read.cpp +++ b/data/dynos_bin_read.cpp @@ -146,6 +146,8 @@ void DynOS_Read_Source(GfxData *aGfxData, const SysPath &aFilename) { } else if (!_DataIgnore) { _Buffer.Add(*c); } + } else if (*c == '<' || *c == '>') { + _DataIgnore = !_DataIgnore; } // Retrieving data type diff --git a/data/dynos_c.cpp b/data/dynos_c.cpp index 195d4f82..fd6d0d63 100644 --- a/data/dynos_c.cpp +++ b/data/dynos_c.cpp @@ -89,12 +89,22 @@ const void* dynos_geolayout_get(const char *name) { // -- collisions -- // -void dynos_add_collision_custom(const char *modPath, const char* collisionName) { - DynOS_Col_AddCollisionCustom(modPath, collisionName); +void dynos_add_collision(const char *modPath, const char* collisionName) { + DynOS_Col_Add(modPath, collisionName); } Collision* dynos_collision_get(const char* collisionName) { - return DynOS_Col_GetCollision(collisionName); + return DynOS_Col_Get(collisionName); +} + +// -- levels -- // + +void dynos_add_level(const char *modPath, const char* levelName) { + DynOS_Lvl_Add(modPath, levelName); +} + +LevelScript* dynos_level_get(const char* levelName) { + return DynOS_Lvl_Get(levelName); } } diff --git a/data/dynos_misc.cpp b/data/dynos_misc.cpp index c333ad0c..043598bc 100644 --- a/data/dynos_misc.cpp +++ b/data/dynos_misc.cpp @@ -564,14 +564,16 @@ void *DynOS_Geo_GetGraphNode(const void *aGeoLayout, bool aKeepInMemory) { return NULL; } -// Collisions + //////////////// + // Collisions // +//////////////// -static Array*>> sDynosCustomCollisions; +static Array*>> sDynosCollisions; -void DynOS_Col_AddCollisionCustom(const SysPath &aPackFolder, const char *aCollisionName) { +void DynOS_Col_Add(const SysPath &aPackFolder, const char *aCollisionName) { // check for duplicates - for (s32 i = 0; i < sDynosCustomCollisions.Count(); ++i) { - if (!strcmp(sDynosCustomCollisions[i].first, aCollisionName)) { + for (s32 i = 0; i < sDynosCollisions.Count(); ++i) { + if (!strcmp(sDynosCollisions[i].first, aCollisionName)) { return; } } @@ -586,14 +588,52 @@ void DynOS_Col_AddCollisionCustom(const SysPath &aPackFolder, const char *aColli return; } - // Add to custom collisions - sDynosCustomCollisions.Add({ collisionName, _Node }); + // Add to collisions + sDynosCollisions.Add({ collisionName, _Node }); } -Collision* DynOS_Col_GetCollision(const char* collisionName) { - for (s32 i = 0; i < sDynosCustomCollisions.Count(); ++i) { - if (!strcmp(sDynosCustomCollisions[i].first, collisionName)) { - return sDynosCustomCollisions[i].second->mData; +Collision* DynOS_Col_Get(const char* collisionName) { + for (s32 i = 0; i < sDynosCollisions.Count(); ++i) { + if (!strcmp(sDynosCollisions[i].first, collisionName)) { + return sDynosCollisions[i].second->mData; + } + } + return NULL; +} + + //////////// + // Levels // +//////////// + +static Array> sDynosCustomLevelScripts; + +void DynOS_Lvl_Add(const SysPath &aPackFolder, const char *aLevelName) { + // check for duplicates + for (s32 i = 0; i < sDynosCustomLevelScripts.Count(); ++i) { + if (!strcmp(sDynosCustomLevelScripts[i].first, aLevelName)) { + return; + } + } + + u16 levelLen = strlen(aLevelName); + char* levelName = (char*)calloc(1, sizeof(char) * (levelLen + 1)); + strcpy(levelName, aLevelName); + + GfxData* _Node = DynOS_Lvl_LoadFromBinary(aPackFolder, levelName); + if (!_Node) { + free(levelName); + return; + } + + // Add to levels + sDynosCustomLevelScripts.Add({ levelName, _Node }); +} + +LevelScript* DynOS_Lvl_Get(const char* levelName) { + for (s32 i = 0; i < sDynosCustomLevelScripts.Count(); ++i) { + if (!strcmp(sDynosCustomLevelScripts[i].first, levelName)) { + auto& scripts = sDynosCustomLevelScripts[i].second->mLevelScripts; + return scripts[scripts.Count() - 1]->mData; } } return NULL; diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 2e827466..39764b0f 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -733,6 +733,7 @@ - [get_network_area_timer](#get_network_area_timer) - [hud_hide](#hud_hide) - [hud_show](#hud_show) + - [smlua_level_util_get](#smlua_level_util_get) - [warp_exit_level](#warp_exit_level) - [warp_restart_level](#warp_restart_level) - [warp_to_castle](#warp_to_castle) @@ -13775,6 +13776,26 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
+## [smlua_level_util_get](#smlua_level_util_get) + +### Lua Example +`local PointerValue = smlua_level_util_get(name)` + +### Parameters +| Field | Type | +| ----- | ---- | +| name | `string` | + +### Returns +- `Pointer` <`LevelScript`> + +### C Prototype +`LevelScript* smlua_level_util_get(const char* name);` + +[:arrow_up_small:](#) + +
+ ## [warp_exit_level](#warp_exit_level) ### Lua Example diff --git a/include/behavior_table.h b/include/behavior_table.h index 8b01e8b6..a42bee7b 100644 --- a/include/behavior_table.h +++ b/include/behavior_table.h @@ -3,8 +3,6 @@ #include "behavior_data.h" -extern const BehaviorScript* gBehaviorTable[]; - enum BehaviorId { id_bhvStarDoor, id_bhvMrI, @@ -524,6 +522,9 @@ enum BehaviorId { }; enum BehaviorId get_id_from_behavior(const BehaviorScript* behavior); +enum BehaviorId get_id_from_vanilla_behavior(const BehaviorScript* behavior); const BehaviorScript* get_behavior_from_id(enum BehaviorId id); +const char* get_behavior_name_from_id(enum BehaviorId id); +enum BehaviorId get_id_from_behavior_name(const char* name); #endif diff --git a/src/pc/lua/smlua_cobject.c b/src/pc/lua/smlua_cobject.c index fa949b87..373e1e99 100644 --- a/src/pc/lua/smlua_cobject.c +++ b/src/pc/lua/smlua_cobject.c @@ -375,6 +375,7 @@ static int smlua__get_field(lua_State* L) { case LVT_BEHAVIORSCRIPT: lua_pushinteger(L, *(s32*)p); break; case LVT_OBJECTANIMPOINTER: lua_pushinteger(L, *(s32*)p); break; case LVT_COLLISION: lua_pushinteger(L, *(s32*)p); break; + case LVT_LEVELSCRIPT: lua_pushinteger(L, *(s32*)p); break; // pointers case LVT_U8_P: @@ -387,6 +388,7 @@ static int smlua__get_field(lua_State* L) { case LVT_BEHAVIORSCRIPT_P: case LVT_OBJECTANIMPOINTER_P: case LVT_COLLISION_P: + case LVT_LEVELSCRIPT_P: smlua_push_pointer(L, data->valueType, *(u8**)p); break; diff --git a/src/pc/lua/smlua_cobject.h b/src/pc/lua/smlua_cobject.h index eb8b0460..fc1de99a 100644 --- a/src/pc/lua/smlua_cobject.h +++ b/src/pc/lua/smlua_cobject.h @@ -27,6 +27,8 @@ enum LuaValueType { LVT_OBJECTANIMPOINTER_P, LVT_COLLISION, LVT_COLLISION_P, + LVT_LEVELSCRIPT, + LVT_LEVELSCRIPT_P, LVT_LUAFUNCTION, LVT_POINTER, LVT_MAX, diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 5d1e6702..6a3e5db4 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -9266,6 +9266,17 @@ int smlua_func_hud_show(UNUSED lua_State* L) { return 1; } +int smlua_func_smlua_level_util_get(lua_State* L) { + if(!smlua_functions_valid_param_count(L, 1)) { return 0; } + + const char* name = smlua_to_string(L, 1); + if (!gSmLuaConvertSuccess) { return 0; } + + smlua_push_pointer(L, LVT_LEVELSCRIPT_P, (void*)smlua_level_util_get(name)); + + return 1; +} + int smlua_func_warp_exit_level(lua_State* L) { if(!smlua_functions_valid_param_count(L, 1)) { return 0; } @@ -10709,6 +10720,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "get_network_area_timer", smlua_func_get_network_area_timer); smlua_bind_function(L, "hud_hide", smlua_func_hud_hide); smlua_bind_function(L, "hud_show", smlua_func_hud_show); + smlua_bind_function(L, "smlua_level_util_get", smlua_func_smlua_level_util_get); smlua_bind_function(L, "warp_exit_level", smlua_func_warp_exit_level); smlua_bind_function(L, "warp_restart_level", smlua_func_warp_restart_level); smlua_bind_function(L, "warp_to_castle", smlua_func_warp_to_castle); diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c index 462fb922..10b41bb6 100644 --- a/src/pc/lua/utils/smlua_misc_utils.c +++ b/src/pc/lua/utils/smlua_misc_utils.c @@ -54,3 +54,7 @@ f32 get_hand_foot_pos_z(struct MarioState* m, u8 index) { if (index >= 4) { index = 0; } return m->marioBodyState->handFootPos[index][2]; } + +LevelScript* smlua_level_util_get(const char* name) { + return dynos_level_get(name); +} diff --git a/src/pc/lua/utils/smlua_misc_utils.h b/src/pc/lua/utils/smlua_misc_utils.h index a44064f1..3d067b4f 100644 --- a/src/pc/lua/utils/smlua_misc_utils.h +++ b/src/pc/lua/utils/smlua_misc_utils.h @@ -17,4 +17,6 @@ f32 get_hand_foot_pos_x(struct MarioState* m, u8 index); f32 get_hand_foot_pos_y(struct MarioState* m, u8 index); f32 get_hand_foot_pos_z(struct MarioState* m, u8 index); +LevelScript* smlua_level_util_get(const char* name); + #endif diff --git a/src/pc/mods/mod.c b/src/pc/mods/mod.c index 7cf485bd..e95b34ab 100644 --- a/src/pc/mods/mod.c +++ b/src/pc/mods/mod.c @@ -59,10 +59,39 @@ static void mod_activate_col(struct Mod* mod, struct ModFile* file) { } // Add to custom actors - dynos_add_collision_custom(dynosPath, colName); + dynos_add_collision(dynosPath, colName); LOG_INFO("Activating DynOS col: '%s', '%s'", dynosPath, colName); } +static void mod_activate_lvl(struct Mod* mod, struct ModFile* file) { + char dynosPath[SYS_MAX_PATH] = { 0 }; + if (snprintf(dynosPath, SYS_MAX_PATH - 1, "%s/levels", mod->basePath) < 0) { + LOG_ERROR("Failed to concat dynos path"); + return; + } + + // copy geo name + char lvlName[64] = { 0 }; + if (snprintf(lvlName, 63, "%s", path_basename(file->relativePath)) < 0) { + LOG_ERROR("Truncated lvl name"); + return; + } + + // remove '.lvl' + char* g = lvlName; + while (*g != '\0') { + if (*g == '.') { + *g = '\0'; + break; + } + g++; + } + + // Add to levels + dynos_add_level(dynosPath, lvlName); + LOG_INFO("Activating DynOS lvl: '%s', '%s'", dynosPath, lvlName); +} + void mod_activate(struct Mod* mod) { // activate dynos models for (int i = 0; i < mod->fileCount; i++) { @@ -73,6 +102,9 @@ void mod_activate(struct Mod* mod) { if (str_ends_with(file->relativePath, ".col")) { mod_activate_col(mod, file); } + if (str_ends_with(file->relativePath, ".lvl")) { + mod_activate_lvl(mod, file); + } } } @@ -200,34 +232,69 @@ static bool mod_load_files(struct Mod* mod, char* modName, char* fullPath) { // open actors directory struct dirent* dir = NULL; DIR* d = opendir(actorsPath); - if (!d) { - return true; - } + if (d) { + // iterate mod directory + char path[SYS_MAX_PATH] = { 0 }; + char relativePath[SYS_MAX_PATH] = { 0 }; + while ((dir = readdir(d)) != NULL) { + // sanity check / fill path[] + if (!directory_sanity_check(dir, actorsPath, path)) { continue; } + if (snprintf(relativePath, SYS_MAX_PATH - 1, "actors/%s", dir->d_name) < 0) { + LOG_ERROR("Could not concat actor path!"); + return false; + } - // iterate mod directory - char path[SYS_MAX_PATH] = { 0 }; - char relativePath[SYS_MAX_PATH] = { 0 }; - while ((dir = readdir(d)) != NULL) { - // sanity check / fill path[] - if (!directory_sanity_check(dir, actorsPath, path)) { continue; } - if (snprintf(relativePath, SYS_MAX_PATH - 1, "actors/%s", dir->d_name) < 0) { - LOG_ERROR("Could not concat actor path!"); - return false; + // only consider bin, and col files + if (!str_ends_with(path, ".bin") && !str_ends_with(path, ".col")) { + continue; + } + + // allocate file + struct ModFile* file = mod_allocate_file(mod, relativePath); + if (file == NULL) { return false; } } - // only consider bin and col files - if (!str_ends_with(path, ".bin") && !str_ends_with(path, ".col")) { - continue; - } - - // allocate file - struct ModFile* file = mod_allocate_file(mod, relativePath); - if (file == NULL) { return false; } + closedir(d); } - - closedir(d); } + // deal with levels directory + { + // concat levels directory + char levelsPath[SYS_MAX_PATH] = { 0 }; + if (!concat_path(levelsPath, fullPath, "levels")) { + LOG_ERROR("Could not concat directory '%s' + '%s'", fullPath, "levels"); + return false; + } + + // open levels directory + struct dirent* dir = NULL; + DIR* d = opendir(levelsPath); + if (d) { + // iterate mod directory + char path[SYS_MAX_PATH] = { 0 }; + char relativePath[SYS_MAX_PATH] = { 0 }; + while ((dir = readdir(d)) != NULL) { + // sanity check / fill path[] + if (!directory_sanity_check(dir, levelsPath, path)) { continue; } + if (snprintf(relativePath, SYS_MAX_PATH - 1, "levels/%s", dir->d_name) < 0) { + LOG_ERROR("Could not concat level path!"); + return false; + } + + // only consider lvl files + if (!str_ends_with(path, ".lvl")) { + continue; + } + + // allocate file + struct ModFile* file = mod_allocate_file(mod, relativePath); + if (file == NULL) { return false; } + } + + closedir(d); + } + } return true; }