More custom bhv cleanup

This commit is contained in:
MysterD 2022-06-02 19:33:28 -07:00
parent b2bdf8859c
commit 091437c430
9 changed files with 42 additions and 27 deletions

View file

@ -343,6 +343,7 @@
--- @class GlobalObjectAnimations
--- @field public amp_seg8_anims_08004034 Pointer_ObjectAnimPointer
--- @field public birds_seg5_anims_050009E8 Pointer_ObjectAnimPointer
--- @field public blargg_seg5_anims_0500616C Pointer_ObjectAnimPointer
--- @field public blue_fish_seg3_anims_0301C2B0 Pointer_ObjectAnimPointer
--- @field public bobomb_seg8_anims_0802396C Pointer_ObjectAnimPointer
--- @field public bookend_seg5_anims_05002540 Pointer_ObjectAnimPointer
@ -357,6 +358,7 @@
--- @field public chilly_chief_seg6_anims_06003994 Pointer_ObjectAnimPointer
--- @field public chuckya_seg8_anims_0800C070 Pointer_ObjectAnimPointer
--- @field public clam_shell_seg5_anims_05001744 Pointer_ObjectAnimPointer
--- @field public cyan_fish_seg6_anims_0600E264 Pointer_ObjectAnimPointer
--- @field public door_seg3_anims_030156C0 Pointer_ObjectAnimPointer
--- @field public dorrie_seg6_anims_0600F638 Pointer_ObjectAnimPointer
--- @field public eyerok_seg5_anims_050116E4 Pointer_ObjectAnimPointer
@ -383,6 +385,7 @@
--- @field public skeeter_seg6_anims_06007DE0 Pointer_ObjectAnimPointer
--- @field public snowman_seg5_anims_0500D118 Pointer_ObjectAnimPointer
--- @field public spindrift_seg5_anims_05002D68 Pointer_ObjectAnimPointer
--- @field public spiny_egg_seg5_anims_050157E4 Pointer_ObjectAnimPointer
--- @field public spiny_seg5_anims_05016EAC Pointer_ObjectAnimPointer
--- @field public sushi_seg5_anims_0500AE54 Pointer_ObjectAnimPointer
--- @field public swoop_seg6_anims_060070D0 Pointer_ObjectAnimPointer
@ -421,6 +424,7 @@
--- @field public ddd_seg7_collision_submarine Pointer_Collision
--- @field public door_seg3_collision_0301CE78 Pointer_Collision
--- @field public dorrie_seg6_collision_0600F644 Pointer_Collision
--- @field public dorrie_seg6_collision_0600FBB8 Pointer_Collision
--- @field public exclamation_box_outline_seg8_collision_08025F78 Pointer_Collision
--- @field public hmc_seg7_collision_controllable_platform Pointer_Collision
--- @field public hmc_seg7_collision_controllable_platform_sub Pointer_Collision
@ -477,6 +481,7 @@
--- @field public ttm_seg7_collision_pitoune_2 Pointer_Collision
--- @field public ttm_seg7_collision_podium_warp Pointer_Collision
--- @field public ttm_seg7_collision_ukiki_cage Pointer_Collision
--- @field public unknown_seg8_collision_080262F8 Pointer_Collision
--- @field public warp_pipe_seg3_collision_03009AC8 Pointer_Collision
--- @field public wdw_seg7_collision_arrow_lift Pointer_Collision
--- @field public wdw_seg7_collision_express_elevator_platform Pointer_Collision

View file

@ -563,7 +563,7 @@ enum BehaviorId get_id_from_vanilla_behavior(const BehaviorScript* behavior) {
}
const BehaviorScript* get_behavior_from_id(enum BehaviorId id) {
const BehaviorScript* behavior = get_hooked_behavior_from_id(id, true);
const BehaviorScript* behavior = smlua_get_hooked_behavior_from_id(id, true);
if (behavior != NULL) { return behavior; }
if (id < 0 || id >= id_bhv_max_count) {

View file

@ -98,7 +98,7 @@ void DynOS_Bhv_HookAllCustomBehaviors() {
auto &script = aGfxData->mBehaviorScripts[aGfxData->mBehaviorScripts.Count() - 1]->mData;
// Theres currently no better place but to do this here.
if (hook_behavior(script, scriptName) == 0) {
if (smlua_hook_customn_bhv(script, scriptName) == 0) {
PrintError(" ERROR: Failed to add custom behavior '%s'!", scriptName);
}
}

View file

@ -553,6 +553,7 @@
| ----- | ---- | ------ |
| amp_seg8_anims_08004034 | `Pointer` <`ObjectAnimPointer`> | read-only |
| birds_seg5_anims_050009E8 | `Pointer` <`ObjectAnimPointer`> | read-only |
| blargg_seg5_anims_0500616C | `Pointer` <`ObjectAnimPointer`> | read-only |
| blue_fish_seg3_anims_0301C2B0 | `Pointer` <`ObjectAnimPointer`> | read-only |
| bobomb_seg8_anims_0802396C | `Pointer` <`ObjectAnimPointer`> | read-only |
| bookend_seg5_anims_05002540 | `Pointer` <`ObjectAnimPointer`> | read-only |
@ -567,6 +568,7 @@
| chilly_chief_seg6_anims_06003994 | `Pointer` <`ObjectAnimPointer`> | read-only |
| chuckya_seg8_anims_0800C070 | `Pointer` <`ObjectAnimPointer`> | read-only |
| clam_shell_seg5_anims_05001744 | `Pointer` <`ObjectAnimPointer`> | read-only |
| cyan_fish_seg6_anims_0600E264 | `Pointer` <`ObjectAnimPointer`> | read-only |
| door_seg3_anims_030156C0 | `Pointer` <`ObjectAnimPointer`> | read-only |
| dorrie_seg6_anims_0600F638 | `Pointer` <`ObjectAnimPointer`> | read-only |
| eyerok_seg5_anims_050116E4 | `Pointer` <`ObjectAnimPointer`> | read-only |
@ -593,6 +595,7 @@
| skeeter_seg6_anims_06007DE0 | `Pointer` <`ObjectAnimPointer`> | read-only |
| snowman_seg5_anims_0500D118 | `Pointer` <`ObjectAnimPointer`> | read-only |
| spindrift_seg5_anims_05002D68 | `Pointer` <`ObjectAnimPointer`> | read-only |
| spiny_egg_seg5_anims_050157E4 | `Pointer` <`ObjectAnimPointer`> | read-only |
| spiny_seg5_anims_05016EAC | `Pointer` <`ObjectAnimPointer`> | read-only |
| sushi_seg5_anims_0500AE54 | `Pointer` <`ObjectAnimPointer`> | read-only |
| swoop_seg6_anims_060070D0 | `Pointer` <`ObjectAnimPointer`> | read-only |
@ -638,6 +641,7 @@
| ddd_seg7_collision_submarine | `Pointer` <`Collision`> | |
| door_seg3_collision_0301CE78 | `Pointer` <`Collision`> | |
| dorrie_seg6_collision_0600F644 | `Pointer` <`Collision`> | |
| dorrie_seg6_collision_0600FBB8 | `Pointer` <`Collision`> | |
| exclamation_box_outline_seg8_collision_08025F78 | `Pointer` <`Collision`> | |
| hmc_seg7_collision_controllable_platform | `Pointer` <`Collision`> | |
| hmc_seg7_collision_controllable_platform_sub | `Pointer` <`Collision`> | |
@ -694,6 +698,7 @@
| ttm_seg7_collision_pitoune_2 | `Pointer` <`Collision`> | |
| ttm_seg7_collision_podium_warp | `Pointer` <`Collision`> | |
| ttm_seg7_collision_ukiki_cage | `Pointer` <`Collision`> | |
| unknown_seg8_collision_080262F8 | `Pointer` <`Collision`> | |
| warp_pipe_seg3_collision_03009AC8 | `Pointer` <`Collision`> | |
| wdw_seg7_collision_arrow_lift | `Pointer` <`Collision`> | |
| wdw_seg7_collision_express_elevator_platform | `Pointer` <`Collision`> | |

View file

@ -354,7 +354,7 @@ static void snap_object_to_floor(struct Object *obj) {
struct Object *create_object(const BehaviorScript *bhvScript) {
if (!bhvScript) { return NULL; }
s32 objListIndex = OBJ_LIST_DEFAULT;
bool luaBehavior = is_behavior_hooked_from_lua(bhvScript);
bool luaBehavior = smlua_is_behavior_hooked(bhvScript);
const BehaviorScript *behavior = smlua_override_behavior(bhvScript);
// If the first behavior script command is "begin <object list>", then

View file

@ -415,10 +415,11 @@ static struct LuaObjectField sFloorGeometryFields[LUA_FLOOR_GEOMETRY_FIELD_COUNT
// { "unused", LOT_???, offsetof(struct FloorGeometry, unused), false, LOT_??? }, <--- UNIMPLEMENTED
};
#define LUA_GLOBAL_OBJECT_ANIMATIONS_FIELD_COUNT 53
#define LUA_GLOBAL_OBJECT_ANIMATIONS_FIELD_COUNT 56
static struct LuaObjectField sGlobalObjectAnimationsFields[LUA_GLOBAL_OBJECT_ANIMATIONS_FIELD_COUNT] = {
{ "amp_seg8_anims_08004034", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, amp_seg8_anims_08004034), true, LOT_POINTER },
{ "birds_seg5_anims_050009E8", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, birds_seg5_anims_050009E8), true, LOT_POINTER },
{ "blargg_seg5_anims_0500616C", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, blargg_seg5_anims_0500616C), true, LOT_POINTER },
{ "blue_fish_seg3_anims_0301C2B0", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, blue_fish_seg3_anims_0301C2B0), true, LOT_POINTER },
{ "bobomb_seg8_anims_0802396C", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, bobomb_seg8_anims_0802396C), true, LOT_POINTER },
{ "bookend_seg5_anims_05002540", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, bookend_seg5_anims_05002540), true, LOT_POINTER },
@ -433,6 +434,7 @@ static struct LuaObjectField sGlobalObjectAnimationsFields[LUA_GLOBAL_OBJECT_ANI
{ "chilly_chief_seg6_anims_06003994", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, chilly_chief_seg6_anims_06003994), true, LOT_POINTER },
{ "chuckya_seg8_anims_0800C070", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, chuckya_seg8_anims_0800C070), true, LOT_POINTER },
{ "clam_shell_seg5_anims_05001744", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, clam_shell_seg5_anims_05001744), true, LOT_POINTER },
{ "cyan_fish_seg6_anims_0600E264", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, cyan_fish_seg6_anims_0600E264), true, LOT_POINTER },
{ "door_seg3_anims_030156C0", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, door_seg3_anims_030156C0), true, LOT_POINTER },
{ "dorrie_seg6_anims_0600F638", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, dorrie_seg6_anims_0600F638), true, LOT_POINTER },
{ "eyerok_seg5_anims_050116E4", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, eyerok_seg5_anims_050116E4), true, LOT_POINTER },
@ -459,6 +461,7 @@ static struct LuaObjectField sGlobalObjectAnimationsFields[LUA_GLOBAL_OBJECT_ANI
{ "skeeter_seg6_anims_06007DE0", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, skeeter_seg6_anims_06007DE0), true, LOT_POINTER },
{ "snowman_seg5_anims_0500D118", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, snowman_seg5_anims_0500D118), true, LOT_POINTER },
{ "spindrift_seg5_anims_05002D68", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, spindrift_seg5_anims_05002D68), true, LOT_POINTER },
{ "spiny_egg_seg5_anims_050157E4", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, spiny_egg_seg5_anims_050157E4), true, LOT_POINTER },
{ "spiny_seg5_anims_05016EAC", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, spiny_seg5_anims_05016EAC), true, LOT_POINTER },
{ "sushi_seg5_anims_0500AE54", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, sushi_seg5_anims_0500AE54), true, LOT_POINTER },
{ "swoop_seg6_anims_060070D0", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, swoop_seg6_anims_060070D0), true, LOT_POINTER },
@ -472,7 +475,7 @@ static struct LuaObjectField sGlobalObjectAnimationsFields[LUA_GLOBAL_OBJECT_ANI
{ "yoshi_seg5_anims_05024100", LVT_OBJECTANIMPOINTER_P, offsetof(struct GlobalObjectAnimations, yoshi_seg5_anims_05024100), true, LOT_POINTER },
};
#define LUA_GLOBAL_OBJECT_COLLISION_DATA_FIELD_COUNT 99
#define LUA_GLOBAL_OBJECT_COLLISION_DATA_FIELD_COUNT 101
static struct LuaObjectField sGlobalObjectCollisionDataFields[LUA_GLOBAL_OBJECT_COLLISION_DATA_FIELD_COUNT] = {
{ "bbh_seg7_collision_coffin", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, bbh_seg7_collision_coffin), false, LOT_POINTER },
{ "bbh_seg7_collision_haunted_bookshelf", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, bbh_seg7_collision_haunted_bookshelf), false, LOT_POINTER },
@ -499,6 +502,7 @@ static struct LuaObjectField sGlobalObjectCollisionDataFields[LUA_GLOBAL_OBJECT_
{ "ddd_seg7_collision_submarine", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, ddd_seg7_collision_submarine), false, LOT_POINTER },
{ "door_seg3_collision_0301CE78", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, door_seg3_collision_0301CE78), false, LOT_POINTER },
{ "dorrie_seg6_collision_0600F644", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, dorrie_seg6_collision_0600F644), false, LOT_POINTER },
{ "dorrie_seg6_collision_0600FBB8", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, dorrie_seg6_collision_0600FBB8), false, LOT_POINTER },
{ "exclamation_box_outline_seg8_collision_08025F78", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, exclamation_box_outline_seg8_collision_08025F78), false, LOT_POINTER },
{ "hmc_seg7_collision_controllable_platform", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, hmc_seg7_collision_controllable_platform), false, LOT_POINTER },
{ "hmc_seg7_collision_controllable_platform_sub", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, hmc_seg7_collision_controllable_platform_sub), false, LOT_POINTER },
@ -555,6 +559,7 @@ static struct LuaObjectField sGlobalObjectCollisionDataFields[LUA_GLOBAL_OBJECT_
{ "ttm_seg7_collision_pitoune_2", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, ttm_seg7_collision_pitoune_2), false, LOT_POINTER },
{ "ttm_seg7_collision_podium_warp", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, ttm_seg7_collision_podium_warp), false, LOT_POINTER },
{ "ttm_seg7_collision_ukiki_cage", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, ttm_seg7_collision_ukiki_cage), false, LOT_POINTER },
{ "unknown_seg8_collision_080262F8", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, unknown_seg8_collision_080262F8), false, LOT_POINTER },
{ "warp_pipe_seg3_collision_03009AC8", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, warp_pipe_seg3_collision_03009AC8), false, LOT_POINTER },
{ "wdw_seg7_collision_arrow_lift", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, wdw_seg7_collision_arrow_lift), false, LOT_POINTER },
{ "wdw_seg7_collision_express_elevator_platform", LVT_COLLISION_P, offsetof(struct GlobalObjectCollisionData, wdw_seg7_collision_express_elevator_platform), false, LOT_POINTER },

View file

@ -649,12 +649,12 @@ const BehaviorScript* smlua_override_behavior(const BehaviorScript *behavior) {
if (L == NULL) { return behavior; }
enum BehaviorId id = get_id_from_behavior(behavior);
const BehaviorScript *hookedBehavior = get_hooked_behavior_from_id(id, false);
const BehaviorScript *hookedBehavior = smlua_get_hooked_behavior_from_id(id, false);
if (hookedBehavior != NULL) { return hookedBehavior; }
return behavior + *sBehaviorOffset;
}
const BehaviorScript* get_hooked_behavior_from_id(enum BehaviorId id, bool returnOriginal) {
const BehaviorScript* smlua_get_hooked_behavior_from_id(enum BehaviorId id, bool returnOriginal) {
lua_State *L = gLuaState;
if (L == NULL) { return NULL; }
@ -667,7 +667,7 @@ const BehaviorScript* get_hooked_behavior_from_id(enum BehaviorId id, bool retur
return NULL;
}
bool is_behavior_hooked_from_lua(const BehaviorScript *behavior) {
bool smlua_is_behavior_hooked(const BehaviorScript *behavior) {
lua_State *L = gLuaState;
if (L == NULL) { return false; }
@ -681,7 +681,7 @@ bool is_behavior_hooked_from_lua(const BehaviorScript *behavior) {
return false;
}
int hook_behavior(BehaviorScript *bhvScript, const char *bhvName) {
int smlua_hook_customn_bhv(BehaviorScript *bhvScript, const char *bhvName) {
if (sHookedBehaviorsCount >= MAX_HOOKED_BEHAVIORS) {
LOG_ERROR("Hooked behaviors exceeded maximum references!");
return 0;

View file

@ -66,7 +66,7 @@ static const char* LuaHookedEventTypeName[] = {
extern u32 gLuaMarioActionIndex;
int hook_behavior(BehaviorScript *bhvScript, const char *bhvName);
int smlua_hook_customn_bhv(BehaviorScript *bhvScript, const char *bhvName);
void smlua_call_event_hooks(enum LuaHookedEventType hookType);
void smlua_call_event_hooks_bool_param(enum LuaHookedEventType hookType, bool value);
@ -84,8 +84,8 @@ void smlua_call_event_hooks_value_param(enum LuaHookedEventType hookType, int mo
enum BehaviorId smlua_get_original_behavior_id(const BehaviorScript* behavior);
const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior);
const BehaviorScript* get_hooked_behavior_from_id(enum BehaviorId id, bool returnOriginal);
bool is_behavior_hooked_from_lua(const BehaviorScript *behavior);
const BehaviorScript* smlua_get_hooked_behavior_from_id(enum BehaviorId id, bool returnOriginal);
bool smlua_is_behavior_hooked(const BehaviorScript *behavior);
bool smlua_call_behavior_hook(const BehaviorScript** behavior, struct Object* object, bool before);
int smlua_call_hook(lua_State* L, int nargs, int nresults, int errfunc, struct Mod* activeMod);