diff --git a/Source/Client/Syncing/Game/SyncMethods.cs b/Source/Client/Syncing/Game/SyncMethods.cs index 7817c63b9..7199000de 100644 --- a/Source/Client/Syncing/Game/SyncMethods.cs +++ b/Source/Client/Syncing/Game/SyncMethods.cs @@ -419,6 +419,9 @@ public static void Init() SyncMethod.Lambda(typeof(Gene_Healing), nameof(Gene_Healing.GetGizmos), 0).SetDebugOnly(); // Heal permament wound SyncMethod.Lambda(typeof(Gene_PsychicBonding), nameof(Gene_PsychicBonding.GetGizmos), 0).SetDebugOnly(); // Bond to random pawn + // Outfit stand + SyncMethod.Register(typeof(Building_OutfitStand), nameof(Building_OutfitStand.TryDrop)); + // Baby feeding SyncMethod.Register(typeof(Pawn_MindState), nameof(Pawn_MindState.SetAutofeeder)); // Called from ITab_Pawn_Feeding.GenerateFloatMenuOption @@ -866,6 +869,41 @@ public static void TryDirtyCurrentPawnTable(object instance = null, object[] arg table.SetDirty(); } } - } + [HarmonyPatch(typeof(ITab_ContentsBooks), nameof(ITab_ContentsBooks.DoRow))] + static class ITab_ContentsBooks_DoRow_Patch + { + static IEnumerable Transpiler(IEnumerable insts) + { + var getDirectlyHeldThings = AccessTools.Method(typeof(Building_Bookcase), nameof(Building_Bookcase.GetDirectlyHeldThings)); + var tryDrop = AccessTools.Method(typeof(ThingOwner), nameof(ThingOwner.TryDrop), new[] { typeof(Thing), typeof(IntVec3), typeof(Map), typeof(ThingPlaceMode), typeof(int), typeof(Thing).MakeByRefType(), typeof(Action), typeof(Predicate) }); + var replacement = AccessTools.Method(typeof(SyncMethods), nameof(SyncBookcaseTryDrop)); + + foreach (var ci in insts) + { + if (ci.Calls(getDirectlyHeldThings)) + continue; + + if (ci.Calls(tryDrop)) + ci.operand = replacement; + yield return ci; + } + } + } + + // Seems can't sync Action & Predicate so have to deduct params + // This is enough for bookcase to use but needs update for new situation if needed. + + static bool SyncBookcaseTryDrop(Building_Bookcase bookcase, Thing thing, IntVec3 dropLoc, Map map, ThingPlaceMode mode, int count, out Thing resultingThing, Action placedAction = null, Predicate nearPlaceValidator = null) + { + return DoSyncBookcaseTryDrop(bookcase, thing, dropLoc, map, mode, count, out resultingThing); + } + [SyncMethod] + static bool DoSyncBookcaseTryDrop(Building_Bookcase bookcase, Thing thing, IntVec3 dropLoc, Map map, ThingPlaceMode mode, int count, out Thing resultingThing) + { + ThingOwner owner = bookcase.GetDirectlyHeldThings(); + return owner.TryDrop(thing, dropLoc, map, mode, count, out resultingThing, + null, null); + } + } }