Skip to content

Commit

Permalink
Fixed issues related with bills and their thingfilters
Browse files Browse the repository at this point in the history
  • Loading branch information
havietisov committed Nov 30, 2018
1 parent c4a4b2a commit 43f92da
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 50 deletions.
43 changes: 29 additions & 14 deletions CooperateRim/BillSurrogate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,47 @@ 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;
info.AddValue("bill_stack", st);
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 ? "<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;
}
}
Expand Down
33 changes: 33 additions & 0 deletions CooperateRim/Bill_ProductionWithUft_surrogate.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
1 change: 1 addition & 0 deletions CooperateRim/CooperateRim.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="BillSurrogate.cs" />
<Compile Include="Bill_ctor_patch.cs" />
<Compile Include="Bill_exposeDataPatch.cs" />
<Compile Include="Bill_ProductionWithUft_surrogate.cs" />
<Compile Include="Bill_production_patch.cs" />
<Compile Include="bill_reorder_patch.cs" />
<Compile Include="BlueprintBuildSurrogate.cs" />
Expand Down
20 changes: 10 additions & 10 deletions CooperateRim/CooperateRimming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -34,11 +34,11 @@ public HarmonyInstance harmonyInst
return base.HarmonyInst;
}
}

public static void GenerateWorld()
{
ThingIDMakerPatch.stopID = true;

ThinkTreeKeyAssigner.Reset();

foreach (var def in DefDatabase<ThinkTreeDef>.AllDefsListForReading)
Expand All @@ -53,10 +53,10 @@ public static void GenerateWorld()
}
else
{
LongEventHandler.QueueLongEvent(() =>
LongEventHandler.QueueLongEvent(() =>
{
NetDemo.LoadFromRemoteSFD();
for (; NetDemo.GetSFD() == null ;)
for (; NetDemo.GetSFD() == null;)
{

}
Expand All @@ -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" });

Expand Down Expand Up @@ -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
{
Expand All @@ -145,7 +145,7 @@ public static void Postfix()
ThingFilterPatch.avoidThingFilterUsage = false;
}
}

static void InitBullshit()
{
/*
Expand Down Expand Up @@ -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());
Expand Down
26 changes: 1 addition & 25 deletions CooperateRim/Dialog_Coop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ModFolder/RimAlong/About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
<author>6opoDuJIo</author>
<url>http://rimworldgame.com</url>
<targetVersion>1.0.0</targetVersion>
<description>Map cooperative mod. Build 0.2.6909.3110 </description>
<description>Map cooperative mod. Build 0.2.6909.3439 </description>
</ModMetaData>

0 comments on commit 43f92da

Please sign in to comment.