diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py index 8f0e8758a..1f0bf46fa 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_reset", "smlua_anim_util_register_animation" ], + "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_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 e39219fbf..721139597 100644 --- a/autogen/convert_structs.py +++ b/autogen/convert_structs.py @@ -98,6 +98,7 @@ override_field_invisible = { "GraphNodeRoot": ["unk15", "views"], "FnGraphNode": [ "luaTokenIndex" ], "Object": [ "firstSurface" ], + "Animation": [ "unusedBoneCount" ], "ModAudio": [ "sound", "decoder", "buffer", "bufferSize", "sampleCopiesTail" ], "DialogEntry": [ "str" ], "ModFsFile": [ "data", "capacity" ], diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua index d9a4c330b..14a8159fd 100644 --- a/autogen/lua_definitions/structs.lua +++ b/autogen/lua_definitions/structs.lua @@ -22,7 +22,6 @@ --- @field public loopEnd integer --- @field public loopStart integer --- @field public startFrame integer ---- @field public unusedBoneCount integer --- @field public values Pointer_integer --- @field public valuesLength integer diff --git a/docs/lua/structs.md b/docs/lua/structs.md index 31e0a2fc1..9570c105e 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -161,7 +161,6 @@ | loopEnd | `integer` | | | loopStart | `integer` | | | startFrame | `integer` | | -| unusedBoneCount | `integer` | | | values | `Pointer` <`integer`> | | | valuesLength | `integer` | | diff --git a/src/game/game_init.h b/src/game/game_init.h index 86710b1e0..b997c4a3f 100644 --- a/src/game/game_init.h +++ b/src/game/game_init.h @@ -54,6 +54,8 @@ 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/pc/lua/smlua.c b/src/pc/lua/smlua.c index b93b5679a..a254485fe 100644 --- a/src/pc/lua/smlua.c +++ b/src/pc/lua/smlua.c @@ -337,6 +337,7 @@ 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 31abf4de9..4327a9f3d 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -178,7 +178,7 @@ static struct LuaObjectField sAnimInfoFields[LUA_ANIM_INFO_FIELD_COUNT] = { { "prevAnimPtr", LVT_COBJECT_P, offsetof(struct AnimInfo, prevAnimPtr), false, LOT_ANIMATION, 1, sizeof(struct Animation*) }, }; -#define LUA_ANIMATION_FIELD_COUNT 11 +#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) }, @@ -188,7 +188,6 @@ static struct LuaObjectField sAnimationFields[LUA_ANIMATION_FIELD_COUNT] = { { "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) }, - { "unusedBoneCount", LVT_S16, offsetof(struct Animation, unusedBoneCount), 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) }, }; diff --git a/src/pc/lua/utils/smlua_anim_utils.c b/src/pc/lua/utils/smlua_anim_utils.c index 84a09fbc2..0c12c605f 100644 --- a/src/pc/lua/utils/smlua_anim_utils.c +++ b/src/pc/lua/utils/smlua_anim_utils.c @@ -88,6 +88,28 @@ 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; @@ -125,7 +147,13 @@ 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 ef7dff061..78e40d56b 100644 --- a/src/pc/lua/utils/smlua_anim_utils.h +++ b/src/pc/lua/utils/smlua_anim_utils.h @@ -69,6 +69,7 @@ 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 7d99ba86d..0635f5661 100755 --- a/tools/mario_anims_converter.py +++ b/tools/mario_anims_converter.py @@ -179,6 +179,7 @@ try: for s in structobj: print(s) print("};") + print("size_t gMarioAnimsSize = sizeof(gMarioAnims);") for asset in asset_loads: print(asset)