From e44fc5dc40b0d6a8af0487b487c5d8e9d085fae7 Mon Sep 17 00:00:00 2001 From: MysterD Date: Wed, 17 May 2023 23:32:39 -0700 Subject: [PATCH] Fix sync of models on late join --- data/dynos.c.h | 3 ++- data/dynos.cpp.h | 1 + data/dynos_c.cpp | 8 +++++-- data/dynos_mgr_models.cpp | 34 +++++++++++++++++++++++----- src/pc/gfx/gfx_cc.c | 1 + src/pc/network/packets/packet_area.c | 2 +- 6 files changed, 39 insertions(+), 10 deletions(-) diff --git a/data/dynos.c.h b/data/dynos.c.h index 75011a7a..5524a766 100644 --- a/data/dynos.c.h +++ b/data/dynos.c.h @@ -77,7 +77,8 @@ struct GraphNode* dynos_model_load_dl(u32* aId, enum ModelPool aModelPool, u8 aL struct GraphNode* dynos_model_store_geo(u32* aId, enum ModelPool aModelPool, void* aAsset, struct GraphNode* aGraphNode); struct GraphNode* dynos_model_get_geo(u32 aId); void dynos_model_overwrite_slot(u32 srcSlot, u32 dstSlot); -u32 dynos_model_get_id_from_asset(void* asset); +u32 dynos_model_get_id_from_asset(void* aAsset); +u32 dynos_model_get_id_from_graph_node(struct GraphNode* aGraphNode); void dynos_model_clear_pool(enum ModelPool aModelPool); // -- other -- // diff --git a/data/dynos.cpp.h b/data/dynos.cpp.h index 6fc7f7ed..e95a3f4c 100644 --- a/data/dynos.cpp.h +++ b/data/dynos.cpp.h @@ -968,6 +968,7 @@ struct GraphNode* DynOS_Model_LoadDl(u32* aId, enum ModelPool aModelPool, u8 aLa struct GraphNode* DynOS_Model_StoreGeo(u32* aId, enum ModelPool aModelPool, void* aAsset, struct GraphNode* aGraphNode); struct GraphNode* DynOS_Model_GetGeo(u32 aId); u32 DynOS_Model_GetIdFromAsset(void* asset); +u32 DynOS_Model_GetIdFromGraphNode(struct GraphNode* aNode); void DynOS_Model_OverwriteSlot(u32 srcSlot, u32 dstSlot); void DynOS_Model_ClearPool(enum ModelPool aModelPool); void DynOS_Model_Update(); diff --git a/data/dynos_c.cpp b/data/dynos_c.cpp index 4a13d61f..069b02de 100644 --- a/data/dynos_c.cpp +++ b/data/dynos_c.cpp @@ -237,8 +237,12 @@ struct GraphNode* dynos_model_store_geo(u32* aId, enum ModelPool aModelPool, voi return DynOS_Model_StoreGeo(aId, aModelPool, aAsset, aGraphNode); } -u32 dynos_model_get_id_from_asset(void* asset) { - return DynOS_Model_GetIdFromAsset(asset); +u32 dynos_model_get_id_from_asset(void* aAsset) { + return DynOS_Model_GetIdFromAsset(aAsset); +} + +u32 dynos_model_get_id_from_graph_node(struct GraphNode* aGraphNode) { + return DynOS_Model_GetIdFromGraphNode(aGraphNode); } void dynos_model_clear_pool(enum ModelPool aModelPool) { diff --git a/data/dynos_mgr_models.cpp b/data/dynos_mgr_models.cpp index f2033cac..52fefbf4 100644 --- a/data/dynos_mgr_models.cpp +++ b/data/dynos_mgr_models.cpp @@ -130,7 +130,9 @@ struct GraphNode* DynOS_Model_GetErrorGeo() { struct GraphNode* DynOS_Model_GetGeo(u32 aId) { if (!aId) { return NULL; } - if (sOverwriteMap.count(aId)) { aId = sOverwriteMap[aId]; } + if (sOverwriteMap.count(aId)) { + aId = sOverwriteMap[aId]; + } if (sIdMap.count(aId) == 0) { return DynOS_Model_GetErrorGeo(); @@ -144,13 +146,33 @@ struct GraphNode* DynOS_Model_GetGeo(u32 aId) { return vec.back().graphNode; } -u32 DynOS_Model_GetIdFromAsset(void* asset) { - if (!asset) { return MODEL_NONE; } - for (int i = 0; i < MODEL_POOL_MAX; i++) { - if (sAssetMap[i].count(asset)) { - return sAssetMap[i][asset].id; +u32 DynOS_Model_GetIdFromGraphNode(struct GraphNode* aNode) { + u32 lowest = 9999; + for (auto& it : sIdMap) { + if (it.first > lowest) { continue; } + if (!it.second.size() || it.second.empty()) { continue; } + auto& node = it.second.back(); + if (aNode == node.graphNode) { + lowest = it.first; } } + if (lowest < 9999) { return lowest; } + return MODEL_ERROR_MODEL; +} + +u32 DynOS_Model_GetIdFromAsset(void* asset) { + if (!asset) { return MODEL_NONE; } + u32 lowest = 9999; + for (int i = 0; i < MODEL_POOL_MAX; i++) { + if (!sAssetMap[i].count(asset)) { continue; } + u32 id = sAssetMap[i][asset].id; + if (id < lowest) { lowest = id; } + if (sOverwriteMap.count(id)) { + id = sOverwriteMap[id]; + if (id < lowest) { lowest = id; } + } + } + if (lowest < 9999) { return lowest; } return MODEL_ERROR_MODEL; } diff --git a/src/pc/gfx/gfx_cc.c b/src/pc/gfx/gfx_cc.c index f0699d6e..3d43ef32 100644 --- a/src/pc/gfx/gfx_cc.c +++ b/src/pc/gfx/gfx_cc.c @@ -109,6 +109,7 @@ void gfx_cc_precomp(void) { gfx_pc_precomp_shader(0x04060401, 0x04000000, 0x04060402, 0x04000b0b, 0x00000000); // 84c6842100596a45 gfx_pc_precomp_shader(0x04060401, 0x05000000, 0x04060402, 0x05000b0b, 0x00000001); // 1d970841b086b2e6 gfx_pc_precomp_shader(0x01000000, 0x04000000, 0x02000000, 0x04000b0b, 0x00000001); // 410000008f86b2e6 + gfx_pc_precomp_shader(0x04060401, 0x05000000, 0x04060402, 0x05000b0b, 0x00000009); // 1d970841b086b2ee sAllowCCPrint = 1; } diff --git a/src/pc/network/packets/packet_area.c b/src/pc/network/packets/packet_area.c index 5c7a9d05..001183f0 100644 --- a/src/pc/network/packets/packet_area.c +++ b/src/pc/network/packets/packet_area.c @@ -102,7 +102,7 @@ void network_send_area(struct NetworkPlayer* toNp) { // TODO: move find model to a utility file/function // find model - u32 model = dynos_model_get_id_from_asset(so->o->header.gfx.sharedChild); + u32 model = dynos_model_get_id_from_graph_node(so->o->header.gfx.sharedChild); u32 models[] = { model }; network_send_spawn_objects_to(toNp->localIndex, spawn_objects, models, 1);