From 5edae8c75fd9bdf8aa326ffe0532b8ec0dcc7c15 Mon Sep 17 00:00:00 2001 From: Prince Frizzy Date: Wed, 22 Feb 2023 00:32:19 -0500 Subject: [PATCH 1/5] Fix empty .bhv in Star Road. (#290) --- mods/star-road/data/bhvSMSRBulletMine.bhv | Bin 26 -> 106 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/mods/star-road/data/bhvSMSRBulletMine.bhv b/mods/star-road/data/bhvSMSRBulletMine.bhv index 2d31b3ce2ba800def665622285a45325cbcf8205..9b9dc47956703ca995dd09d0d09c9c1dd9c1e5ea 100644 GIT binary patch delta 89 zcmb2jnjjV;!~g;;4FCT#Sb8fk3IaL0K&)-VU<9NG?>2=%w^yN0PxZY`2YX_ delta 9 Ocmd0jnjpr)00aOD8v!o> From 1c5cadcce265771c80eab4a78714b017620b6f37 Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Wed, 22 Feb 2023 15:56:30 +1000 Subject: [PATCH 2/5] rerun autogen (#291) --- autogen/lua_definitions/constants.lua | 2 +- docs/lua/constants.md | 2 +- src/pc/lua/smlua_constants_autogen.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index c97a939c..ba3e1f95 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -3926,7 +3926,7 @@ HUD_DISPLAY_FLAG_EMPHASIZE_POWER = 0x8000 HUD_DISPLAY_NONE = 0x0000 --- @type HUDDisplayFlag -HUD_DISPLAY_DEFAULT = HUD_DISPLAY_FLAG_LIVES | HUD_DISPLAY_FLAG_COIN_COUNT | HUD_DISPLAY_FLAG_STAR_COUNT | HUD_DISPLAY_FLAG_CAMERA | HUD_DISPLAY_FLAG_POWER | HUD_DISPLAY_FLAG_KEYS | HUD_DISPLAY_FLAG_UNKNOWN_0020 +HUD_DISPLAY_DEFAULT = HUD_DISPLAY_FLAG_LIVES | HUD_DISPLAY_FLAG_COIN_COUNT | HUD_DISPLAY_FLAG_STAR_COUNT | HUD_DISPLAY_FLAG_CAMERA_AND_POWER | HUD_DISPLAY_FLAG_CAMERA | HUD_DISPLAY_FLAG_POWER | HUD_DISPLAY_FLAG_KEYS | HUD_DISPLAY_FLAG_UNKNOWN_0020 --- @class MarioAnimID diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 2d421ac3..38107ff6 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -1364,7 +1364,7 @@ | HUD_DISPLAY_FLAG_POWER | 0x0100 | | HUD_DISPLAY_FLAG_EMPHASIZE_POWER | 0x8000 | | HUD_DISPLAY_NONE | 0x0000 | -| HUD_DISPLAY_DEFAULT | HUD_DISPLAY_FLAG_LIVES | HUD_DISPLAY_FLAG_COIN_COUNT | HUD_DISPLAY_FLAG_STAR_COUNT | HUD_DISPLAY_FLAG_CAMERA | HUD_DISPLAY_FLAG_POWER | HUD_DISPLAY_FLAG_KEYS | HUD_DISPLAY_FLAG_UNKNOWN_0020 | +| HUD_DISPLAY_DEFAULT | HUD_DISPLAY_FLAG_LIVES | HUD_DISPLAY_FLAG_COIN_COUNT | HUD_DISPLAY_FLAG_STAR_COUNT | HUD_DISPLAY_FLAG_CAMERA_AND_POWER | HUD_DISPLAY_FLAG_CAMERA | HUD_DISPLAY_FLAG_POWER | HUD_DISPLAY_FLAG_KEYS | HUD_DISPLAY_FLAG_UNKNOWN_0020 | [:arrow_up_small:](#) diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 77040d4f..f1b2a483 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -1496,7 +1496,7 @@ char gSmluaConstants[] = "" "HUD_DISPLAY_FLAG_POWER = 0x0100\n" "HUD_DISPLAY_FLAG_EMPHASIZE_POWER = 0x8000\n" "HUD_DISPLAY_NONE = 0x0000\n" -"HUD_DISPLAY_DEFAULT = HUD_DISPLAY_FLAG_LIVES | HUD_DISPLAY_FLAG_COIN_COUNT | HUD_DISPLAY_FLAG_STAR_COUNT | HUD_DISPLAY_FLAG_CAMERA | HUD_DISPLAY_FLAG_POWER | HUD_DISPLAY_FLAG_KEYS | HUD_DISPLAY_FLAG_UNKNOWN_0020\n" +"HUD_DISPLAY_DEFAULT = HUD_DISPLAY_FLAG_LIVES | HUD_DISPLAY_FLAG_COIN_COUNT | HUD_DISPLAY_FLAG_STAR_COUNT | HUD_DISPLAY_FLAG_CAMERA_AND_POWER | HUD_DISPLAY_FLAG_CAMERA | HUD_DISPLAY_FLAG_POWER | HUD_DISPLAY_FLAG_KEYS | HUD_DISPLAY_FLAG_UNKNOWN_0020\n" "MARIO_ANIM_SLOW_LEDGE_GRAB = 0\n" "MARIO_ANIM_FALL_OVER_BACKWARDS = 1\n" "MARIO_ANIM_BACKWARD_AIR_KB = 2\n" From 0db1a7dbc82ffe5a187d515329447d175669e00b Mon Sep 17 00:00:00 2001 From: Prince Frizzy Date: Wed, 22 Feb 2023 01:32:52 -0500 Subject: [PATCH 3/5] Bump version number (#292) * Fix empty .bhv in Star Road. * Bump version number. --- src/pc/network/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pc/network/version.h b/src/pc/network/version.h index 1deab335..7909f53c 100644 --- a/src/pc/network/version.h +++ b/src/pc/network/version.h @@ -1,7 +1,7 @@ #ifndef VERSION_H #define VERSION_H -#define VERSION_NUMBER 31 +#define VERSION_NUMBER 32 #define MINOR_VERSION_NUMBER 0 #define MAX_VERSION_LENGTH 10 From 6299fe35d001dac132cd81bf2edf6c10ae91625e Mon Sep 17 00:00:00 2001 From: Prince Frizzy Date: Wed, 22 Feb 2023 15:12:09 -0500 Subject: [PATCH 4/5] Sanity checks for the .bhv system (#293) * Barebones fix. * Sanity checks for the .bhv system. * Two more sanity checks. --- data/dynos.cpp.h | 1 + data/dynos_bin_behavior.cpp | 38 ++++++++++++++++++++++++++----------- data/dynos_mgr_bhv.cpp | 7 ++++++- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/data/dynos.cpp.h b/data/dynos.cpp.h index 97072fdc..ccbbf46f 100644 --- a/data/dynos.cpp.h +++ b/data/dynos.cpp.h @@ -89,6 +89,7 @@ public: inline s32 Offset() const { return mOffset; } inline bool EoF() const { return mOffset >= mSize; } inline void SetOffset(s32 aOffset) const { mOffset = aOffset; } + inline const char *GetFilename() const { return mFilename; } public: static BinFile *OpenR(const char *aFilename) { diff --git a/data/dynos_bin_behavior.cpp b/data/dynos_bin_behavior.cpp index 0d8b8454..a93d283f 100644 --- a/data/dynos_bin_behavior.cpp +++ b/data/dynos_bin_behavior.cpp @@ -44,7 +44,7 @@ extern "C" { // Current Behavior Version #define BEHAVIOR_MAJOR_VER 1 #define BEHAVIOR_MINOR_VER 0 -#define BEHAVIOR_PATCH_VER 0 +#define BEHAVIOR_PATCH_VER 1 // Minimum Behavior Version (That can be read) #define BEHAVIOR_MIN_MAJOR_VER 1 @@ -2485,6 +2485,15 @@ static bool DynOS_Bhv_WriteBinary(const SysPath &aOutputFilename, GfxData *aGfxD ///////////// static DataNode *DynOS_Bhv_Load(BinFile *aFile, GfxData *aGfxData) { + // Sanity check the files size. The minimum valid size is 9 bytes. + // 1 byte for the type, 1 bytes for the name length, 3 bytes for the version, And 4 bytes for the behaviors size. + if (aFile->Size() < 9) { + PrintError(" ERROR: Behavior file is smaller then it should be, Rejecting '%s'.", aFile->GetFilename()); + // We have nothing to return, So return NULL. + return NULL; + } + + // Allocate our node. DataNode *_Node = New>(); // Name @@ -2500,12 +2509,19 @@ static DataNode *DynOS_Bhv_Load(BinFile *aFile, GfxData *aGfxDat // If the major version doesn't match, then a drasitc change has happened and // we can't read it no matter what. If it's just minor or patch. We might have // code to support it. - u32 dataSize = aFile->Read(); if (majorVersion != BEHAVIOR_MIN_MAJOR_VER || (minorVersion < BEHAVIOR_MIN_MINOR_VER || patchVersion < BEHAVIOR_MIN_PATCH_VER)) { - PrintError(" ERROR: Behavior version is %u.%u.%u, but reading behaviors under %u.%u.%u is not supported!", majorVersion, minorVersion, patchVersion, BEHAVIOR_MIN_MAJOR_VER, BEHAVIOR_MIN_MINOR_VER, BEHAVIOR_MIN_PATCH_VER); - - // Skip the rest of the bytes saved for this behavior. - aFile->Skip(dataSize); + PrintError(" ERROR: Behavior file is version %u.%u.%u, which is not supported! Rejecting '%s'.", majorVersion, minorVersion, patchVersion, aFile->GetFilename()); + // We don't return this since we failed to read the behavior. + Delete(_Node); + // We have nothing to return, So return NULL. + return NULL; + } + + // If we have nothing in the .bhv file, It compiled incorrectly or is maliciously crafted. + // We also check if the specified behavior size is valid for the file. + u32 dataSize = aFile->Read(); + if (dataSize == 0 || (dataSize > (aFile->Size() - aFile->Offset()))) { + PrintError(" ERROR: Behavior file has a invalid behavior in it! Rejecting '%s'.", aFile->GetFilename()); // We don't return this since we failed to read the behavior. Delete(_Node); // We have nothing to return, So return NULL. @@ -2516,11 +2532,6 @@ static DataNode *DynOS_Bhv_Load(BinFile *aFile, GfxData *aGfxDat _Node->mSize = dataSize; _Node->mData = New(_Node->mSize); - // Add it - if (aGfxData != NULL) { - aGfxData->mBehaviorScripts.Add(_Node); - } - // Read it for (u32 i = 0; i != _Node->mSize; ++i) { if (aFile->EoF()) { @@ -2535,6 +2546,11 @@ static DataNode *DynOS_Bhv_Load(BinFile *aFile, GfxData *aGfxDat _Node->mData[i] = (uintptr_t) _Value; } } + + // Add it + if (aGfxData != NULL) { + aGfxData->mBehaviorScripts.Add(_Node); + } return _Node; } diff --git a/data/dynos_mgr_bhv.cpp b/data/dynos_mgr_bhv.cpp index 3ea85784..061c864d 100644 --- a/data/dynos_mgr_bhv.cpp +++ b/data/dynos_mgr_bhv.cpp @@ -54,6 +54,7 @@ GfxData *DynOS_Bhv_GetActiveGfx(BehaviorScript *bhvScript) { for (s32 i = 0; i < _CustomBehaviorScripts.Count(); ++i) { auto &gfxData = _CustomBehaviorScripts[i].second; auto &scripts = gfxData->mBehaviorScripts; + if (scripts.Count() == 0) { continue; } if (bhvScript == scripts[scripts.Count() - 1]->mData) { return gfxData; } @@ -67,6 +68,7 @@ s32 DynOS_Bhv_GetActiveModIndex(BehaviorScript *bhvScript) { for (s32 i = 0; i < _CustomBehaviorScripts.Count(); ++i) { auto &gfxData = _CustomBehaviorScripts[i].second; auto &scripts = gfxData->mBehaviorScripts; + if (scripts.Count() == 0) { continue; } if (bhvScript == scripts[scripts.Count() - 1]->mData) { return gfxData->mModIndex; } @@ -96,7 +98,10 @@ void DynOS_Bhv_HookAllCustomBehaviors() { for (s32 i = 0; i < _CustomBehaviorScripts.Count(); ++i) { auto &scriptName = _CustomBehaviorScripts[i].first; auto &aGfxData = _CustomBehaviorScripts[i].second; - auto &script = aGfxData->mBehaviorScripts[aGfxData->mBehaviorScripts.Count() - 1]->mData; + if (aGfxData->mBehaviorScripts.Count() == 0) { continue; } + auto *node = aGfxData->mBehaviorScripts[aGfxData->mBehaviorScripts.Count() - 1]; + if (node == nullptr) { continue; } + auto &script = node->mData; // Theres currently no better place but to do this here. if (smlua_hook_custom_bhv(script, scriptName) == 0) { From a6021ff3604b3f69f6ac61308fab95f36bb02032 Mon Sep 17 00:00:00 2001 From: Sunk <69110309+Sunketchupm@users.noreply.github.com> Date: Wed, 22 Feb 2023 15:13:11 -0500 Subject: [PATCH 5/5] Force the player to stop moving upon being popped (#289) --- src/game/mario_actions_automatic.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/game/mario_actions_automatic.c b/src/game/mario_actions_automatic.c index ecea7404..5eaca685 100644 --- a/src/game/mario_actions_automatic.c +++ b/src/game/mario_actions_automatic.c @@ -1047,9 +1047,7 @@ s32 act_bubbled(struct MarioState* m) { m->health = 0x100; m->marioObj->oIntangibleTimer = 0; m->peakHeight = m->pos[1]; - m->vel[0] = 0; - m->vel[1] = 0; - m->vel[2] = 0; + mario_set_forward_vel(m, 0.0f); m->marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE; if (m->playerIndex == 0) { soft_reset_camera(m->area->camera);