diff --git a/Source/Mods/RPGStyleInventory.cs b/Source/Mods/RPGStyleInventory.cs index ee260d3..e22900b 100644 --- a/Source/Mods/RPGStyleInventory.cs +++ b/Source/Mods/RPGStyleInventory.cs @@ -16,30 +16,36 @@ namespace Multiplayer.Compat [MpCompatFor("Sandy.RPGStyleInventory.avilmask.Revamped")] class RPGStyleInventory { + private static Type tabType; + public RPGStyleInventory(ModContentPack mod) { - Type type = AccessTools.TypeByName("Sandy_Detailed_RPG_Inventory.Sandy_Detailed_RPG_GearTab"); - - MP.RegisterSyncWorker(SyncITab, type); - MP.RegisterSyncMethod(type, "InterfaceDrop").SetContext(SyncContext.MapSelected); - MP.RegisterSyncMethod(type, "InterfaceIngest").SetContext(SyncContext.MapSelected); + tabType = AccessTools.TypeByName("Sandy_Detailed_RPG_Inventory.Sandy_Detailed_RPG_GearTab"); + + MP.RegisterSyncWorker(SyncITab, tabType); + + // Original re-implemented InterfaceDrop/InterfaceIngest, but some stopped doing that. + // Sync those methods if they're declared, but skip if they aren't since we don't want + // to sync vanilla methods (which are already synced). On top of that, vanilla marked + // InterfaceIngest as obsolete (use FoodUtility.IngestFromInventoryNow instead), + // so avoid HugsLib warnings about patching obsolete methods. + foreach (var methodName in new[] { "InterfaceDrop", "InterfaceIngest" }) + { + var method = AccessTools.DeclaredMethod(tabType, methodName); + if (method != null) + MP.RegisterSyncMethod(method).SetContext(SyncContext.MapSelected); + } // Remove/add forced apparel if (mod.PackageId == "Sandy.RPGStyleInventory.avilmask.Revamped".ToLower()) { - MpCompat.RegisterLambdaDelegate(type, "PopupMenu", 1, 2); + MpCompat.RegisterLambdaDelegate(tabType, "PopupMenu", 0, 1); } } private static void SyncITab(SyncWorker sync, ref ITab_Pawn_Gear gearITab) { - if (sync.isWriting) - { - sync.Write(gearITab.GetType()); - } - else - { - gearITab = (ITab_Pawn_Gear)InspectTabManager.GetSharedInstance(sync.Read()); - } + if (!sync.isWriting) + gearITab = Activator.CreateInstance(tabType) as ITab_Pawn_Gear; } } -} +} \ No newline at end of file