Skip to content

Commit

Permalink
fix(game/five): sync ped inventory on update
Browse files Browse the repository at this point in the history
In the base game the CPedInventoryDataNode is defined as MIGRATE_NODE.
I.e. is it synced on creation and when owner is changed. However in
onesync we don't support the migration event currently. This leads to
inventory data being lost when ped owner is changed. E.g. peds loose
their weapon when players moves too far away and then returns.

Update the inventory node synchronisation flags to make it sync on
update event as well. One sync caches the data, so the inventory data is
sent over the network only when there is a change.
  • Loading branch information
Nobelium-cfx committed Jan 16, 2025
1 parent c95b323 commit 81115dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4530,11 +4530,11 @@ using CPedSyncTree = SyncTree<
NodeWrapper<NodeIds<87, 87, 0>, CPedSectorPosNavMeshNode, 4>
>,
ParentNode<
NodeIds<5, 0, 0>,
NodeIds<87, 0, 0>,
NodeWrapper<NodeIds<4, 0, 0>, CMigrationDataNode, 13>,
NodeWrapper<NodeIds<4, 0, 0>, CPhysicalMigrationDataNode, 1>,
NodeWrapper<NodeIds<4, 0, 1>, CPhysicalScriptMigrationDataNode, 1>,
NodeWrapper<NodeIds<5, 0, 0>, CPedInventoryDataNode, 321>,
NodeWrapper<NodeIds<87, 0, 0>, CPedInventoryDataNode, 321>, // Changed from 5 to 87 in CloneManager.cpp
NodeWrapper<NodeIds<4, 4, 1>, CPedTaskSequenceDataNode, 1>
>
>
Expand Down
7 changes: 7 additions & 0 deletions code/components/gta-net-five/src/CloneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,13 @@ static HookFunction hookFunctionSceneUpdateWorkaround([]()
MH_CreateHook(hook::get_pattern("F7 D3 21 58 10 0F", -0x3F), fwSceneUpdate__RemoveFromSceneUpdate_Track, (void**)&fwSceneUpdate__RemoveFromSceneUpdate);
MH_EnableHook(MH_ALL_HOOKS);
});

static HookFunction hookFunctionModifySyncTrees([]()
{
// Change to "mov r8d, ebx; nop;" (44 8B C3 90). ebx value is 87
// Change inventory node flags from MIGRATE_NODE to UPDATE_CREATE_NODE.
hook::put<uint32_t>(xbr::IsGameBuildOrGreater<3407>() ? hook::get_pattern("45 8D 47 ? 49 8D 96 ? ? ? ? 45 33 C9") : hook::get_pattern("44 8D 46 ? 45 33 C9 49 8B D4"), 0x90C38B44);
});
#endif

void CloneManagerLocal::Update()
Expand Down

0 comments on commit 81115dd

Please sign in to comment.