From 7dd02b5c4d756f2eb2ff9db3d21830d231be2d51 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+Agent-11@users.noreply.github.com> Date: Sun, 17 Mar 2024 20:58:38 -0400 Subject: [PATCH] Massively improve "Global Player Models" option --- autogen/lua_definitions/functions.lua | 8 -------- data/dynos.c.h | 2 +- data/dynos.cpp.h | 2 +- data/dynos_c.cpp | 4 ++-- data/dynos_mgr_actor.cpp | 18 ++++++++++++++++-- docs/lua/functions-4.md | 22 ---------------------- docs/lua/functions.md | 1 - src/engine/graph_node.c | 8 ++++---- src/engine/graph_node_manager.c | 2 +- src/game/behaviors/mushroom_1up.inc.c | 2 +- src/game/mario.c | 2 +- src/game/mario_misc.c | 5 +---- src/game/object_helpers.c | 10 +--------- src/game/object_helpers.h | 1 - src/pc/lua/smlua_functions_autogen.c | 23 ----------------------- src/pc/network/network_player.c | 2 +- 16 files changed, 30 insertions(+), 82 deletions(-) diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index f3862fac..4eb932c1 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -7693,14 +7693,6 @@ function obj_set_billboard(obj) -- ... end ---- @param obj Object ---- @param index integer ---- @param modelID integer ---- @return nil -function obj_set_character_model(obj, index, modelID) - -- ... -end - --- @param obj Object --- @return nil function obj_set_cylboard(obj) diff --git a/data/dynos.c.h b/data/dynos.c.h index 3eb16b44..0b568b55 100644 --- a/data/dynos.c.h +++ b/data/dynos.c.h @@ -36,7 +36,7 @@ void dynos_pack_init(void); void dynos_generate_packs(const char* directory); // -- geos -- // -void dynos_actor_override(void** aSharedChild); +void dynos_actor_override(struct Object* obj, void** aSharedChild); void dynos_add_actor_custom(const char *filePath, const char* geoName); const void* dynos_geolayout_get(const char *name); diff --git a/data/dynos.cpp.h b/data/dynos.cpp.h index 143099b1..e30bcf2b 100644 --- a/data/dynos.cpp.h +++ b/data/dynos.cpp.h @@ -887,7 +887,7 @@ const void *DynOS_Actor_GetLayoutFromName(const char *aActorName); ActorGfx* DynOS_Actor_GetActorGfx(const GraphNode* aGraphNode); void DynOS_Actor_Valid(const void* aGeoref, ActorGfx& aActorGfx); void DynOS_Actor_Invalid(const void* aGeoref, s32 aPackIndex); -void DynOS_Actor_Override(void** aSharedChild); +void DynOS_Actor_Override(struct Object* obj, void** aSharedChild); void DynOS_Actor_Override_All(void); void DynOS_Actor_ModShutdown(); diff --git a/data/dynos_c.cpp b/data/dynos_c.cpp index 4d82906e..0bb07821 100644 --- a/data/dynos_c.cpp +++ b/data/dynos_c.cpp @@ -115,8 +115,8 @@ void dynos_generate_packs(const char* directory) { // -- geos -- // -void dynos_actor_override(void** aSharedChild) { - DynOS_Actor_Override(aSharedChild); +void dynos_actor_override(struct Object* obj, void** aSharedChild) { + DynOS_Actor_Override(obj, aSharedChild); } void dynos_add_actor_custom(const char *filePath, const char* geoName) { diff --git a/data/dynos_mgr_actor.cpp b/data/dynos_mgr_actor.cpp index a03e3c07..82678e2d 100644 --- a/data/dynos_mgr_actor.cpp +++ b/data/dynos_mgr_actor.cpp @@ -7,6 +7,7 @@ extern "C" { #include "game/level_update.h" #include "game/object_list_processor.h" #include "pc/configfile.h" +#include "pc/lua/smlua_hooks.h" } // Static maps/arrays @@ -148,7 +149,7 @@ void DynOS_Actor_Invalid(const void* aGeoref, s32 aPackIndex) { _ValidActors.erase(aGeoref); } -void DynOS_Actor_Override(void** aSharedChild) { +void DynOS_Actor_Override(struct Object* obj, void** aSharedChild) { if ((aSharedChild == NULL) || (*aSharedChild == NULL)) { return; } const void* georef = (*(GraphNode**)aSharedChild)->georef; @@ -157,6 +158,19 @@ void DynOS_Actor_Override(void** aSharedChild) { auto& _ValidActors = DynosValidActors(); if (_ValidActors.count(georef) == 0) { return; } + // Check if the behavior uses a character specific model + if (obj && (obj->behavior == smlua_override_behavior(bhvMario) || + obj->behavior == smlua_override_behavior(bhvNormalCap) || + obj->behavior == smlua_override_behavior(bhvWingCap) || + obj->behavior == smlua_override_behavior(bhvMetalCap) || + obj->behavior == smlua_override_behavior(bhvVanishCap))) { + struct NetworkPlayer* np = network_player_from_global_index(obj->globalPlayerIndex); + if (np && np->localIndex > 0 && !configGlobalPlayerModels) { + return; + } + } + + *aSharedChild = (void*)_ValidActors[georef].mGraphNode; } @@ -171,7 +185,7 @@ void DynOS_Actor_Override_All(void) { u32 id = 0; _Object->header.gfx.sharedChild = DynOS_Model_LoadGeo(&id, MODEL_POOL_PERMANENT, georef, true); } - DynOS_Actor_Override((void**)&_Object->header.gfx.sharedChild); + DynOS_Actor_Override(_Object, (void**)&_Object->header.gfx.sharedChild); } } } diff --git a/docs/lua/functions-4.md b/docs/lua/functions-4.md index 81fef432..5651f739 100644 --- a/docs/lua/functions-4.md +++ b/docs/lua/functions-4.md @@ -5979,28 +5979,6 @@
-## [obj_set_character_model](#obj_set_character_model) - -### Lua Example -`obj_set_character_model(obj, index, modelID)` - -### Parameters -| Field | Type | -| ----- | ---- | -| obj | [Object](structs.md#Object) | -| index | `integer` | -| modelID | `integer` | - -### Returns -- None - -### C Prototype -`void obj_set_character_model(struct Object* obj, u16 index, s32 modelID);` - -[:arrow_up_small:](#) - -
- ## [obj_set_cylboard](#obj_set_cylboard) ### Lua Example diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 1ae22ed4..3a79989c 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -1444,7 +1444,6 @@ - [obj_set_angle](functions-4.md#obj_set_angle) - [obj_set_behavior](functions-4.md#obj_set_behavior) - [obj_set_billboard](functions-4.md#obj_set_billboard) - - [obj_set_character_model](functions-4.md#obj_set_character_model) - [obj_set_cylboard](functions-4.md#obj_set_cylboard) - [obj_set_face_angle](functions-4.md#obj_set_face_angle) - [obj_set_face_angle_to_move_angle](functions-4.md#obj_set_face_angle_to_move_angle) diff --git a/src/engine/graph_node.c b/src/engine/graph_node.c index 0da10f3c..46029905 100644 --- a/src/engine/graph_node.c +++ b/src/engine/graph_node.c @@ -329,7 +329,7 @@ struct GraphNodeObject *init_graph_node_object(struct DynamicPool *pool, graphNode->animInfo.animAccel = 0x10000; graphNode->animInfo.animTimer = 0; graphNode->node.flags |= GRAPH_RENDER_HAS_ANIMATION; - dynos_actor_override((void*)&graphNode->sharedChild); + dynos_actor_override(NULL, (void*)&graphNode->sharedChild); } return graphNode; @@ -447,7 +447,7 @@ struct GraphNodeObjectParent *init_graph_node_object_parent(struct DynamicPool * if (graphNode != NULL) { init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_OBJECT_PARENT); graphNode->sharedChild = sharedChild; - dynos_actor_override((void*)&graphNode->sharedChild); + dynos_actor_override(NULL, (void*)&graphNode->sharedChild); } return graphNode; @@ -745,7 +745,7 @@ void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, Vec3f po graphNode->unk4C = 0; graphNode->throwMatrix = NULL; graphNode->animInfo.curAnim = NULL; - dynos_actor_override((void*)&graphNode->sharedChild); + dynos_actor_override(NULL, (void*)&graphNode->sharedChild); graphNode->node.flags |= GRAPH_RENDER_ACTIVE; graphNode->node.flags &= ~GRAPH_RENDER_INVISIBLE; @@ -770,7 +770,7 @@ void geo_obj_init_spawninfo(struct GraphNodeObject *graphNode, struct SpawnInfo graphNode->unk4C = spawn; graphNode->throwMatrix = NULL; graphNode->animInfo.curAnim = 0; - dynos_actor_override((void*)&graphNode->sharedChild); + dynos_actor_override(NULL, (void*)&graphNode->sharedChild); graphNode->node.flags |= GRAPH_RENDER_ACTIVE; graphNode->node.flags &= ~GRAPH_RENDER_INVISIBLE; diff --git a/src/engine/graph_node_manager.c b/src/engine/graph_node_manager.c index fbf0ab3e..8815b78d 100644 --- a/src/engine/graph_node_manager.c +++ b/src/engine/graph_node_manager.c @@ -72,7 +72,7 @@ void register_scene_graph_node(struct GraphNode *graphNode) { if (gCurGraphNodeList[gCurGraphNodeIndex - 1]->type == GRAPH_NODE_TYPE_OBJECT_PARENT) { struct GraphNodeObjectParent* objParent = ((struct GraphNodeObjectParent *) gCurGraphNodeList[gCurGraphNodeIndex - 1]); objParent->sharedChild = graphNode; - dynos_actor_override((void*)&objParent->sharedChild); + dynos_actor_override(NULL, (void*)&objParent->sharedChild); } else { geo_add_child(gCurGraphNodeList[gCurGraphNodeIndex - 1], graphNode); } diff --git a/src/game/behaviors/mushroom_1up.inc.c b/src/game/behaviors/mushroom_1up.inc.c index 210c1592..cab0c285 100644 --- a/src/game/behaviors/mushroom_1up.inc.c +++ b/src/game/behaviors/mushroom_1up.inc.c @@ -20,7 +20,7 @@ void bhv_1up_interact(void) { } void bhv_1up_trigger_init(void) { - obj_set_model_extended(o, E_MODEL_NONE); + obj_set_model(o, MODEL_NONE); cur_obj_hide(); } diff --git a/src/game/mario.c b/src/game/mario.c index bed16a32..08575e68 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -2369,7 +2369,7 @@ void init_single_mario(struct MarioState* m) { u8 modelIndex = gNetworkPlayers[playerIndex].overrideModelIndex; if (modelIndex >= CT_MAX) { modelIndex = 0; } m->character = &gCharacters[modelIndex]; - obj_set_character_model(m->marioObj, m->playerIndex, m->character->modelId); + obj_set_model(m->marioObj, m->character->modelId); } void init_mario(void) { diff --git a/src/game/mario_misc.c b/src/game/mario_misc.c index 70abdd0e..0d0a7a94 100644 --- a/src/game/mario_misc.c +++ b/src/game/mario_misc.c @@ -691,9 +691,7 @@ Gfx* geo_render_mirror_mario(s32 callContext, struct GraphNode* node, UNUSED Mat if (mario && (((struct GraphNode*)&mario->header.gfx)->flags & GRAPH_RENDER_ACTIVE) && np->connected) { // TODO: Is this a geo layout copy or a graph node copy? gMirrorMario[i].sharedChild = mario->header.gfx.sharedChild; - if (configGlobalPlayerModels || i == 0) { - dynos_actor_override((void*)&gMirrorMario[i].sharedChild); - } + dynos_actor_override(mario, (void*)&gMirrorMario[i].sharedChild); gMirrorMario[i].areaIndex = mario->header.gfx.areaIndex; vec3s_copy(gMirrorMario[i].angle, mario->header.gfx.angle); vec3f_copy(gMirrorMario[i].pos, mario->header.gfx.pos); @@ -707,7 +705,6 @@ Gfx* geo_render_mirror_mario(s32 callContext, struct GraphNode* node, UNUSED Mat gMirrorMario[i].pos[0] = mirroredX + MIRROR_X; gMirrorMario[i].angle[1] = -gMirrorMario[i].angle[1]; gMirrorMario[i].scale[0] *= -1.0f; - // TODO: does rendering the mirror room still crash? gMirrorMario[i].node.flags |= GRAPH_RENDER_ACTIVE; smlua_call_event_hooks_graph_node_object_and_int_param(HOOK_MIRROR_MARIO_RENDER, &gMirrorMario[i], i); diff --git a/src/game/object_helpers.c b/src/game/object_helpers.c index 49012137..0784c6ef 100644 --- a/src/game/object_helpers.c +++ b/src/game/object_helpers.c @@ -1437,15 +1437,7 @@ void cur_obj_set_model(s32 modelID) { void obj_set_model(struct Object* obj, s32 modelID) { obj->header.gfx.sharedChild = dynos_model_get_geo(modelID); - dynos_actor_override((void*)&obj->header.gfx.sharedChild); - smlua_call_event_hooks_object_model_param(HOOK_OBJECT_SET_MODEL, obj, modelID); -} - -void obj_set_character_model(struct Object* obj, u16 index, s32 modelID) { - obj->header.gfx.sharedChild = dynos_model_get_geo(modelID); - if (configGlobalPlayerModels || index == 0) { - dynos_actor_override((void*)&obj->header.gfx.sharedChild); - } + dynos_actor_override(obj, (void*)&obj->header.gfx.sharedChild); smlua_call_event_hooks_object_model_param(HOOK_OBJECT_SET_MODEL, obj, modelID); } diff --git a/src/game/object_helpers.h b/src/game/object_helpers.h index 1804de3d..5934ce93 100644 --- a/src/game/object_helpers.h +++ b/src/game/object_helpers.h @@ -175,7 +175,6 @@ void cur_obj_get_thrown_or_placed(f32 forwardVel, f32 velY, s32 thrownAction); void cur_obj_get_dropped(void); void cur_obj_set_model(s32 modelID); void obj_set_model(struct Object* obj, s32 modelID); -void obj_set_character_model(struct Object* obj, u16 index, s32 modelID); void mario_set_flag(s32 flag); s32 cur_obj_clear_interact_status_flag(s32 flag); void obj_mark_for_deletion(struct Object *obj); diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 866cf8c2..8d627290 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -25833,28 +25833,6 @@ int smlua_func_obj_set_billboard(lua_State* L) { return 1; } -int smlua_func_obj_set_character_model(lua_State* L) { - if (L == NULL) { return 0; } - - int top = lua_gettop(L); - if (top != 3) { - LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "obj_set_character_model", 3, top); - return 0; - } - - struct Object* obj = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT); - if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "obj_set_character_model"); return 0; } - u16 index = smlua_to_integer(L, 2); - if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "obj_set_character_model"); return 0; } - s32 modelID = smlua_to_integer(L, 3); - if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "obj_set_character_model"); return 0; } - - extern void obj_set_character_model(struct Object* obj, u16 index, s32 modelID); - obj_set_character_model(obj, index, modelID); - - return 1; -} - /* int smlua_func_obj_set_collision_data(lua_State* L) { if (L == NULL) { return 0; } @@ -32814,7 +32792,6 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "obj_set_angle", smlua_func_obj_set_angle); smlua_bind_function(L, "obj_set_behavior", smlua_func_obj_set_behavior); smlua_bind_function(L, "obj_set_billboard", smlua_func_obj_set_billboard); - smlua_bind_function(L, "obj_set_character_model", smlua_func_obj_set_character_model); //smlua_bind_function(L, "obj_set_collision_data", smlua_func_obj_set_collision_data); <--- UNIMPLEMENTED smlua_bind_function(L, "obj_set_cylboard", smlua_func_obj_set_cylboard); smlua_bind_function(L, "obj_set_face_angle", smlua_func_obj_set_face_angle); diff --git a/src/pc/network/network_player.c b/src/pc/network/network_player.c index 9a451e80..7f332b3b 100644 --- a/src/pc/network/network_player.c +++ b/src/pc/network/network_player.c @@ -39,7 +39,7 @@ void network_player_update_model(u8 localIndex) { m->character = &gCharacters[index]; if (m->marioObj == NULL) { return; } - obj_set_character_model(m->marioObj, m->playerIndex, m->character->modelId); + obj_set_model(m->marioObj, m->character->modelId); } bool network_player_any_connected(void) {