From 43f92daaa15e0caef82eafa5fee3414f76129b7a Mon Sep 17 00:00:00 2001 From: borodilo Date: Sat, 1 Dec 2018 00:49:43 +0200 Subject: [PATCH] Fixed issues related with bills and their thingfilters --- CooperateRim/BillSurrogate.cs | 43 +++++++++++++------ .../Bill_ProductionWithUft_surrogate.cs | 33 ++++++++++++++ CooperateRim/CooperateRim.csproj | 1 + CooperateRim/CooperateRimming.cs | 20 ++++----- CooperateRim/Dialog_Coop.cs | 26 +---------- ModFolder/RimAlong/About/About.xml | 2 +- 6 files changed, 75 insertions(+), 50 deletions(-) create mode 100644 CooperateRim/Bill_ProductionWithUft_surrogate.cs diff --git a/CooperateRim/BillSurrogate.cs b/CooperateRim/BillSurrogate.cs index 43a28e5..5d57767 100644 --- a/CooperateRim/BillSurrogate.cs +++ b/CooperateRim/BillSurrogate.cs @@ -10,7 +10,7 @@ namespace CooperateRim public class BillSurrogate : ISerializationSurrogate { - public void GetObjectData(object obj, SerializationInfo info, StreamingContext context) + public virtual void GetObjectData(object obj, SerializationInfo info, StreamingContext context) { Bill b = (Bill)obj; BillStack st = b.billStack; @@ -18,24 +18,39 @@ public void GetObjectData(object obj, SerializationInfo info, StreamingContext c info.AddValue("recipedef", b.recipe.defName); } - public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) + public virtual object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) { - string recipeDefName = info.GetString("recipedef"); - BillStack st = (BillStack)info.GetValue("bill_stack", typeof(BillStack)); - Utilities.RimLog.Message("bill lacks pawn restriction in surrogate!"); - Utilities.RimLog.Message("billstack is null ? " + (st == null ? "yes" : "no")); - Utilities.RimLog.Message("bill giver as thing : " + (st.billGiver as Thing)); - Utilities.RimLog.Message("bill giver def as thing : " + (st.billGiver as Thing).def); - - foreach (var rec in (st.billGiver as Thing).def.recipes) + int stage = 0; + int iter = -1; + try { - if (rec.defName == recipeDefName) + string recipeDefName = info.GetString("recipedef"); + BillStack st = (BillStack)info.GetValue("bill_stack", typeof(BillStack)); + stage = 1; + Utilities.RimLog.Message("bill lacks pawn restriction in surrogate!"); + stage = 2; + Utilities.RimLog.Message("billstack is null ? " + (st == null ? "yes" : "no")); + stage = 3; + Utilities.RimLog.Message("bill giver as thing : " + (st.billGiver as Thing)); + stage = 4; + Utilities.RimLog.Message("bill giver def as thing : " + (st.billGiver as Thing).def); + stage = 5; + iter++; + Utilities.RimLog.Message("bill giver def recipes : " + (st.billGiver as Thing).def.AllRecipes); + foreach (var rec in (st.billGiver as Thing).def.AllRecipes) { - return BillUtility.MakeNewBill(rec); + Utilities.RimLog.Message("rec is " + (rec == null || rec.defName == null ? "" : rec.ToString())); + if (rec.defName == recipeDefName) + { + iter++; + return BillUtility.MakeNewBill(rec); + } } } - - Utilities.RimLog.Message("could not make bill!"); + catch (System.Exception ee) + { + Utilities.RimLog.Error("stage " + stage + " at iter " + iter + "could not make bill! " + ee.ToString()); + } return null; } } diff --git a/CooperateRim/Bill_ProductionWithUft_surrogate.cs b/CooperateRim/Bill_ProductionWithUft_surrogate.cs new file mode 100644 index 0000000..453193b --- /dev/null +++ b/CooperateRim/Bill_ProductionWithUft_surrogate.cs @@ -0,0 +1,33 @@ +using RimWorld; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using Verse; + +namespace CooperateRim +{ + class Bill_ProductionWithUft_surrogate : BillSurrogate + { + public override void GetObjectData(object obj, SerializationInfo info, StreamingContext context) + { + Bill_ProductionWithUft bpwu = (Bill_ProductionWithUft)obj; + base.GetObjectData(obj, info, context); + info.AddValue("uft", bpwu.BoundUft); + } + + public override object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) + { + Bill_ProductionWithUft _obj = (Bill_ProductionWithUft)base.SetObjectData(obj, info, context, selector); + UnfinishedThing uft = (UnfinishedThing)info.GetValue("uft", typeof(UnfinishedThing)); + + if (_obj != null) + { + _obj.SetBoundUft(uft, true); + } + + return _obj; + } + } +} diff --git a/CooperateRim/CooperateRim.csproj b/CooperateRim/CooperateRim.csproj index ae65caf..f1d9880 100644 --- a/CooperateRim/CooperateRim.csproj +++ b/CooperateRim/CooperateRim.csproj @@ -73,6 +73,7 @@ + diff --git a/CooperateRim/CooperateRimming.cs b/CooperateRim/CooperateRimming.cs index e94347d..82a6cda 100644 --- a/CooperateRim/CooperateRimming.cs +++ b/CooperateRim/CooperateRimming.cs @@ -22,7 +22,7 @@ public partial class CooperateRimming : ModBase public static bool dumpRand = false; public static CooperateRimming inst; - public CooperateRimming () + public CooperateRimming() { RimLog.Init(this.Logger); } @@ -34,11 +34,11 @@ public HarmonyInstance harmonyInst return base.HarmonyInst; } } - + public static void GenerateWorld() { ThingIDMakerPatch.stopID = true; - + ThinkTreeKeyAssigner.Reset(); foreach (var def in DefDatabase.AllDefsListForReading) @@ -53,10 +53,10 @@ public static void GenerateWorld() } else { - LongEventHandler.QueueLongEvent(() => + LongEventHandler.QueueLongEvent(() => { NetDemo.LoadFromRemoteSFD(); - for (; NetDemo.GetSFD() == null ;) + for (; NetDemo.GetSFD() == null;) { } @@ -75,7 +75,7 @@ public static bool Prefix(string saveFileName) if (SyncTickData.cliendID == 0) { - PirateRPC.PirateRPC.SendInvocation(NetDemo.ns, u => + PirateRPC.PirateRPC.SendInvocation(NetDemo.ns, u => { NetDemo.SetSFD(new NetDemo.SaveFileData() { tcontext = fileContent, partial_name = fileName + "_received" }); @@ -129,7 +129,7 @@ public static void Postfix() ThingFilterPatch.avoidThingFilterUsage = false; } } - + [HarmonyPatch(typeof(Dialog_ManageFoodRestrictions), MethodType.Constructor, new Type[] { typeof(FoodRestriction) })] public class Dialog_ManageFoodRestrictions_patch { @@ -145,7 +145,7 @@ public static void Postfix() ThingFilterPatch.avoidThingFilterUsage = false; } } - + static void InitBullshit() { /* @@ -187,8 +187,8 @@ static void InitBullshit() } } } - - SerializationService.AppendSurrogate(typeof(Bill_Production), new BillProductionSurrogate()); + SerializationService.AppendSurrogate(typeof(Bill_ProductionWithUft), new Bill_ProductionWithUft_surrogate()); + SerializationService.AppendSurrogate(typeof(Bill_Production), new BillSurrogate()); SerializationService.AppendSurrogate(typeof(JobDef), new JobDefSurrogate()); SerializationService.AppendSurrogate(typeof(ThingDef), new ThingDefSurrogate()); SerializationService.AppendSurrogate(typeof(SpecialThingFilterDef), new SpecialThingFilterDefSurrogate()); diff --git a/CooperateRim/Dialog_Coop.cs b/CooperateRim/Dialog_Coop.cs index a35d8c4..883df6d 100644 --- a/CooperateRim/Dialog_Coop.cs +++ b/CooperateRim/Dialog_Coop.cs @@ -68,31 +68,7 @@ public static void Postfix(Thing t) } } } - - [HarmonyPatch(typeof(Thing), "set_ThingID")] - public class ThingIDset_patch - { - public static bool stopID; - - [HarmonyPostfix] - public static void Postfix(Thing __instance) - { - ThingRegistry.AddThing(__instance, __instance.thingIDNumber); - - if (!stopID) - { - if (__instance is Pawn) - { - //Utilities.RimLog.Message("Made id for " + (__instance as Pawn) + " | " + Rand.Int + "|" + System.Threading.Thread.CurrentThread.ManagedThreadId); - } - else - { - //Utilities.RimLog.Message("Made id for " + (__instance) + " | " + Rand.Int + "|" + System.Threading.Thread.CurrentThread.ManagedThreadId); - } - } - } - } - + public partial class CooperateRimming { public class Dialog_Coop : Window diff --git a/ModFolder/RimAlong/About/About.xml b/ModFolder/RimAlong/About/About.xml index 0b6390e..f678d51 100644 --- a/ModFolder/RimAlong/About/About.xml +++ b/ModFolder/RimAlong/About/About.xml @@ -4,5 +4,5 @@ 6opoDuJIo http://rimworldgame.com 1.0.0 - Map cooperative mod. Build 0.2.6909.3110 + Map cooperative mod. Build 0.2.6909.3439 \ No newline at end of file