From 653056bd10600009c82cd1c11721ae9e56d03f50 Mon Sep 17 00:00:00 2001 From: PeachyPeachSM64 <72323920+PeachyPeachSM64@users.noreply.github.com> Date: Tue, 2 Sep 2025 20:28:03 +0200 Subject: [PATCH] Revert "Reset Mario animations on server shutdown" This reverts commit 7405ae7244d02eab2bac1bb70340c7a99a149954. Make Animation and AnimationTable fields immutable Fix variable type in music_changed_through_warp --- autogen/convert_functions.py | 2 +- autogen/convert_structs.py | 10 +++------- docs/lua/structs.md | 20 ++++++++++---------- src/game/game_init.h | 2 -- src/game/level_update.c | 2 +- src/pc/lua/smlua.c | 1 - src/pc/lua/smlua_cobject_autogen.c | 22 +++++++++++----------- src/pc/lua/utils/smlua_anim_utils.c | 28 ---------------------------- src/pc/lua/utils/smlua_anim_utils.h | 1 - tools/mario_anims_converter.py | 1 - 10 files changed, 26 insertions(+), 63 deletions(-) diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py index 1f0bf46fa..8f0e8758a 100644 --- a/autogen/convert_functions.py +++ b/autogen/convert_functions.py @@ -132,7 +132,7 @@ override_disallowed_functions = { "src/pc/djui/djui_hud_utils.h": [ "djui_hud_render_texture_raw", "djui_hud_render_texture_tile_raw" ], "src/pc/lua/utils/smlua_level_utils.h": [ "smlua_level_util_reset" ], "src/pc/lua/utils/smlua_text_utils.h": [ "smlua_text_utils_init", "smlua_text_utils_shutdown", "get_dialog_text_ascii", "smlua_text_utils_dialog_get_unmodified"], - "src/pc/lua/utils/smlua_anim_utils.h": [ "smlua_anim_util_init", "smlua_anim_util_reset", "smlua_anim_util_register_animation" ], + "src/pc/lua/utils/smlua_anim_utils.h": [ "smlua_anim_util_reset", "smlua_anim_util_register_animation" ], "src/pc/lua/utils/smlua_gfx_utils.h": [ "gfx_allocate_internal", "vtx_allocate_internal", "gfx_get_length_no_sentinel" ], "src/pc/network/lag_compensation.h": [ "lag_compensation_clear" ], "src/game/first_person_cam.h": [ "first_person_update" ], diff --git a/autogen/convert_structs.py b/autogen/convert_structs.py index 177719680..c8af5f8e1 100644 --- a/autogen/convert_structs.py +++ b/autogen/convert_structs.py @@ -83,10 +83,6 @@ override_field_mutable = { "overridePalette", "overridePaletteIndex", ], - "Animation": [ - "values", - "index", - ], } override_field_invisible = { @@ -135,9 +131,9 @@ override_field_immutable = { "GraphNodePerspective": [ "unused" ], "GraphNodeSwitchCase": [ "fnNode", "unused" ], "GraphNodeRoot": ["node", "areaIndex", "numViews"], - "ObjectWarpNode": [ "next "], - "Animation": [ "length" ], - "AnimationTable": [ "count" ], + "ObjectWarpNode": [ "next" ], + "Animation": [ "*" ], + "AnimationTable": [ "*" ], "Controller": [ "controllerData", "statusData" ], "FirstPersonCamera": [ "enabled" ], "ModAudio": [ "isStream", "loaded" ], diff --git a/docs/lua/structs.md b/docs/lua/structs.md index eb6ff0813..e603068cb 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -155,16 +155,16 @@ | Field | Type | Access | | ----- | ---- | ------ | -| flags | `integer` | | -| animYTransDivisor | `integer` | | -| startFrame | `integer` | | -| loopStart | `integer` | | -| loopEnd | `integer` | | -| values | `Pointer` <`integer`> | | -| index | `Pointer` <`integer`> | | +| flags | `integer` | read-only | +| animYTransDivisor | `integer` | read-only | +| startFrame | `integer` | read-only | +| loopStart | `integer` | read-only | +| loopEnd | `integer` | read-only | +| values | `Pointer` <`integer`> | read-only | +| index | `Pointer` <`integer`> | read-only | | length | `integer` | read-only | -| valuesLength | `integer` | | -| indexLength | `integer` | | +| valuesLength | `integer` | read-only | +| indexLength | `integer` | read-only | [:arrow_up_small:](#) @@ -2899,7 +2899,7 @@ | ----- | ---- | ------ | | node | [WarpNode](structs.md#WarpNode) | read-only | | object | [Object](structs.md#Object) | | -| next | [ObjectWarpNode](structs.md#ObjectWarpNode) | | +| next | [ObjectWarpNode](structs.md#ObjectWarpNode) | read-only | [:arrow_up_small:](#) diff --git a/src/game/game_init.h b/src/game/game_init.h index b997c4a3f..86710b1e0 100644 --- a/src/game/game_init.h +++ b/src/game/game_init.h @@ -54,8 +54,6 @@ extern struct MarioAnimation D_80339D10[MAX_PLAYERS]; extern struct MarioAnimation gDemo; extern u8 gMarioAnims[]; -extern size_t gMarioAnimsSize; - extern u8 gDemoInputs[]; extern u16 frameBufferIndex; diff --git a/src/game/level_update.c b/src/game/level_update.c index c19b9a7c9..722dd7a47 100644 --- a/src/game/level_update.c +++ b/src/game/level_update.c @@ -713,7 +713,7 @@ s16 music_changed_through_warp(s16 arg) { s16 destArea = warpNode->node.destArea; s16 val4 = TRUE; - s16 sp2C; + u16 sp2C; if (levelNum == LEVEL_BOB && levelNum == gCurrLevelNum && destArea == gCurrAreaIndex) { sp2C = get_current_background_music(); diff --git a/src/pc/lua/smlua.c b/src/pc/lua/smlua.c index a254485fe..b93b5679a 100644 --- a/src/pc/lua/smlua.c +++ b/src/pc/lua/smlua.c @@ -337,7 +337,6 @@ void smlua_init(void) { smlua_cobject_init_globals(); smlua_model_util_initialize(); - smlua_anim_util_init(); // load scripts mods_size_enforce(&gActiveMods); diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index 4f852abf1..0fb70f2a1 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -180,16 +180,16 @@ static struct LuaObjectField sAnimInfoFields[LUA_ANIM_INFO_FIELD_COUNT] = { #define LUA_ANIMATION_FIELD_COUNT 10 static struct LuaObjectField sAnimationFields[LUA_ANIMATION_FIELD_COUNT] = { - { "animYTransDivisor", LVT_S16, offsetof(struct Animation, animYTransDivisor), false, LOT_NONE, 1, sizeof(s16) }, - { "flags", LVT_S16, offsetof(struct Animation, flags), false, LOT_NONE, 1, sizeof(s16) }, - { "index", LVT_U16_P, offsetof(struct Animation, index), false, LOT_POINTER, 1, sizeof(u16*) }, - { "indexLength", LVT_U32, offsetof(struct Animation, indexLength), false, LOT_NONE, 1, sizeof(u32) }, - { "length", LVT_U32, offsetof(struct Animation, length), true, LOT_NONE, 1, sizeof(u32) }, - { "loopEnd", LVT_S16, offsetof(struct Animation, loopEnd), false, LOT_NONE, 1, sizeof(s16) }, - { "loopStart", LVT_S16, offsetof(struct Animation, loopStart), false, LOT_NONE, 1, sizeof(s16) }, - { "startFrame", LVT_S16, offsetof(struct Animation, startFrame), false, LOT_NONE, 1, sizeof(s16) }, - { "values", LVT_U16_P, offsetof(struct Animation, values), false, LOT_POINTER, 1, sizeof(u16*) }, - { "valuesLength", LVT_U32, offsetof(struct Animation, valuesLength), false, LOT_NONE, 1, sizeof(u32) }, + { "animYTransDivisor", LVT_S16, offsetof(struct Animation, animYTransDivisor), true, LOT_NONE, 1, sizeof(s16) }, + { "flags", LVT_S16, offsetof(struct Animation, flags), true, LOT_NONE, 1, sizeof(s16) }, + { "index", LVT_U16_P, offsetof(struct Animation, index), true, LOT_POINTER, 1, sizeof(u16*) }, + { "indexLength", LVT_U32, offsetof(struct Animation, indexLength), true, LOT_NONE, 1, sizeof(u32) }, + { "length", LVT_U32, offsetof(struct Animation, length), true, LOT_NONE, 1, sizeof(u32) }, + { "loopEnd", LVT_S16, offsetof(struct Animation, loopEnd), true, LOT_NONE, 1, sizeof(s16) }, + { "loopStart", LVT_S16, offsetof(struct Animation, loopStart), true, LOT_NONE, 1, sizeof(s16) }, + { "startFrame", LVT_S16, offsetof(struct Animation, startFrame), true, LOT_NONE, 1, sizeof(s16) }, + { "values", LVT_U16_P, offsetof(struct Animation, values), true, LOT_POINTER, 1, sizeof(u16*) }, + { "valuesLength", LVT_U32, offsetof(struct Animation, valuesLength), true, LOT_NONE, 1, sizeof(u32) }, }; #define LUA_ANIMATION_TABLE_FIELD_COUNT 1 @@ -2510,7 +2510,7 @@ static struct LuaObjectField sObjectNodeFields[LUA_OBJECT_NODE_FIELD_COUNT] = { #define LUA_OBJECT_WARP_NODE_FIELD_COUNT 3 static struct LuaObjectField sObjectWarpNodeFields[LUA_OBJECT_WARP_NODE_FIELD_COUNT] = { - { "next", LVT_COBJECT_P, offsetof(struct ObjectWarpNode, next), false, LOT_OBJECTWARPNODE, 1, sizeof(struct ObjectWarpNode*) }, + { "next", LVT_COBJECT_P, offsetof(struct ObjectWarpNode, next), true, LOT_OBJECTWARPNODE, 1, sizeof(struct ObjectWarpNode*) }, { "node", LVT_COBJECT, offsetof(struct ObjectWarpNode, node), true, LOT_WARPNODE, 1, sizeof(struct WarpNode) }, { "object", LVT_COBJECT_P, offsetof(struct ObjectWarpNode, object), false, LOT_OBJECT, 1, sizeof(struct Object*) }, }; diff --git a/src/pc/lua/utils/smlua_anim_utils.c b/src/pc/lua/utils/smlua_anim_utils.c index 0c12c605f..84a09fbc2 100644 --- a/src/pc/lua/utils/smlua_anim_utils.c +++ b/src/pc/lua/utils/smlua_anim_utils.c @@ -88,28 +88,6 @@ struct GlobalObjectAnimations gGlobalObjectAnimations = { .yoshi_seg5_anims_05024100 = (struct AnimationTable*) &yoshi_seg5_anims_05024100, }; - ////////////////////// - // mario animations // -////////////////////// - -static u8 *sMarioAnimsOrig = NULL; - -static void smlua_anim_util_init_mario_animations() { - if (!sMarioAnimsOrig) { - sMarioAnimsOrig = malloc(gMarioAnimsSize); - if (!sMarioAnimsOrig) { - sys_fatal("Cannot initialize Mario animations"); - } - memcpy(sMarioAnimsOrig, gMarioAnims, gMarioAnimsSize); - } -} - -static void smlua_anim_util_reset_mario_animations() { - if (sMarioAnimsOrig) { - memcpy(gMarioAnims, sMarioAnimsOrig, gMarioAnimsSize); - } -} - struct Animation *get_mario_vanilla_animation(u16 index) { static struct MarioAnimDmaRelatedThing *marioAnims = (struct MarioAnimDmaRelatedThing *) gMarioAnims; @@ -147,13 +125,7 @@ static struct CustomAnimation *get_custom_animation_node(const char *name) { return NULL; } -void smlua_anim_util_init(void) { - smlua_anim_util_init_mario_animations(); -} - void smlua_anim_util_reset(void) { - smlua_anim_util_reset_mario_animations(); - for (struct CustomAnimation *node = sCustomAnimationHead; node;) { struct CustomAnimation *next = node->next; if (node->name) { diff --git a/src/pc/lua/utils/smlua_anim_utils.h b/src/pc/lua/utils/smlua_anim_utils.h index 78e40d56b..ef7dff061 100644 --- a/src/pc/lua/utils/smlua_anim_utils.h +++ b/src/pc/lua/utils/smlua_anim_utils.h @@ -69,7 +69,6 @@ extern struct GlobalObjectAnimations gGlobalObjectAnimations; /* |description|Gets a vanilla mario Animation with `index`|descriptionEnd| */ struct Animation *get_mario_vanilla_animation(u16 index); -void smlua_anim_util_init(); void smlua_anim_util_reset(); void smlua_anim_util_register_animation(const char *name, s16 flags, s16 animYTransDivisor, s16 startFrame, s16 loopStart, s16 loopEnd, u16 *values, u32 valuesLength, u16 *index, u32 indexLength); /* |description|Sets the animation of `obj` to the animation `name` corresponds to|descriptionEnd| */ diff --git a/tools/mario_anims_converter.py b/tools/mario_anims_converter.py index 0635f5661..7d99ba86d 100755 --- a/tools/mario_anims_converter.py +++ b/tools/mario_anims_converter.py @@ -179,7 +179,6 @@ try: for s in structobj: print(s) print("};") - print("size_t gMarioAnimsSize = sizeof(gMarioAnims);") for asset in asset_loads: print(asset)