Hello,
Wondered if you'd be able to help. I recently enabled the plugin and all is working after I disconnected/reconnected my player. One issue I have is when I remove something from my inventory, the virtual items reset. For example, I went to craft an armoured door and it showed I have 100k gears and 15k metal.refined (I removed this line from the craft_all_items_unlimited_ammo rule which is what I am using) and the item crafts ok. When I remove anything from my inventory, the gears then show as 0. For example I dropped my building plan from my inventory and the gears then show 0. When I disconnect and reconnect again, the gears show as 100k again.
Was wondering if you would know what would cause this? Thank you in advance!
Virtual items resetSolved
According to the symptom you described, where making a change to your inventory contents causes the virtual items to disappear from the crafting menu, the most likely cause is that the framework is having an issue calling the OnInventoryNetworkUpdate hook on the plugin. Another user reported a similar issue with Item Retriever (which handles the inventory update aspect) here. They were using the Carbon framework and the issue was resolved with a newer version of Carbon. If you are also using Carbon, perhaps you simply need to update, or there may be another issue with Carbon.
You can test if the OnInventoryNetworkUpdate is being called by editing ItemRetriever.cs as follows.
// Search for the following line, add the new code as directed
private void OnInventoryNetworkUpdate(PlayerInventory inventory, ItemContainer container, ProtoBuf.UpdateItemContainer updatedItemContainer, PlayerInventory.Type inventoryType)
{
// START NEW CODE
Puts("OnInventoryNetworkUpdate works!");
// END NEW CODE
if (inventoryType != PlayerInventory.Type.Main)
return;
SerializeForNetwork(inventory.baseEntity, updatedItemContainer.container[0]);
}After making that change and reloading the plugin, if you don't see the "OnInventoryNetworkUpdate works!" message in the logs, when moving items around your inventory, dropping them, picking them up, etc., then there's an issue with the framework.
Hi, thank you for the prompt reply. I am indeed using Carbon framework. I believe I am using the latest version but will check and will try the code amendment as suggested also.
Merged post
Hi, I edited the code as suggested. When I reload the plugin it give the following error -
Error while patching hook 'OnInventoryNetworkUpdate[16d943]' (Method System.Void PlayerInventory::SendUpdatedInventoryInternal(Type type, ItemContainer container, NetworkInventoryMode mode) cannot be patched. Reason: Invalid IL code in (wrapper dynamic-method) PlayerInventory:PlayerInventory.SendUpdatedInventoryInternal_Patch0 (PlayerInventory,PlayerInventory/Type,ItemContainer,PlayerInventory/NetworkInventoryMode): IL_0169: ret
)
at void HarmonyLib.Memory.DetourMethodAndPersist(MethodBase original, MethodBase replacement)
at MethodInfo HarmonyLib.PatchFunctions.UpdateWrapper(MethodBase original, PatchInfo patchInfo)
A general error occured while installing 'OnInventoryNetworkUpdate[16d943]'This is the code added in ItemRetriever.cs private void OnInventoryNetworkUpdate(PlayerInventory inventory, ItemContainer container, ProtoBuf.UpdateItemContainer updatedItemContainer, PlayerInventory.Type inventoryType)
{
// START NEW CODE
Puts("OnInventoryNetworkUpdate works!");
// END NEW CODE
if (inventoryType != PlayerInventory.Type.Main)
return;
SerializeForNetwork(inventory.baseEntity, updatedItemContainer.container[0]);
}I am running the latest production build of carbon v1.2024.1033.4309 I see. That first error indicates that the Carbon framework is basically unable to successfully apply the Harmony patch that calls the OnInventoryNetworkUpdate hook, hence plugins are unable to use the hook effectively (it never gets called). This will need to be reported to the Carbon developers so that they can fix the Harmony patch. Most likely, this is caused by the latest Rust update (February force wipe), for which the Oxide team had to change the hook signature to comply with the Rust changes. Most likely, Carbon needs to do the same thing.
Ah understood, thank you very much for the feedback. I will send this to the Carbon team.
Merged post
This has been fixed in Carbon and I can confirm is working as expected. Thank you for the help!