From da0375f3422453b9916fac96c91fd70c948ca372 Mon Sep 17 00:00:00 2001 From: JonnyNova Date: Thu, 23 May 2019 09:25:48 -0400 Subject: [PATCH 1/3] Remove unused DefDatabase enumeration on WipeExistingThings. Further fixes #4 --- Source/HarmonyPatches.cs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/Source/HarmonyPatches.cs b/Source/HarmonyPatches.cs index c8ac3c1..e98a1c0 100644 --- a/Source/HarmonyPatches.cs +++ b/Source/HarmonyPatches.cs @@ -617,17 +617,9 @@ public static void ShouldNotEnterCellInvisDoors(Pawn pawn, Map map, IntVec3 dest public static bool WipeExistingThings(IntVec3 thingPos, Rot4 thingRot, BuildableDef thingDef, Map map, DestroyMode mode) { - //Log.Message("1"); - var trueDef = DefDatabase.AllDefs.FirstOrDefault(predicate: x => x.defName == thingDef.defName); - //if (trueDef != null && trueDef.thingClass == typeof(Building_DoorExpanded) && !thingPos.GetThingList(map).Any(x => x is Building_DoorExpanded)) - // return false; - if (thingDef == HeronDefOf.HeronInvisibleDoor || - thingDef.defName == HeronDefOf.HeronInvisibleDoor.defName) - { - return false; - } - - return true; + // allow vanilla to run if this is not an invisible door + return thingDef.defName != HeronDefOf.HeronInvisibleDoor.defName + && thingDef != HeronDefOf.HeronInvisibleDoor; } //GenSpawn From d1082ed303cd3c6b7973b57627422a99db455274 Mon Sep 17 00:00:00 2001 From: JonnyNova Date: Sun, 2 Jun 2019 09:32:12 -0400 Subject: [PATCH 2/3] Bail earlier if TrueDefs are not needed --- Source/HarmonyPatches.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Source/HarmonyPatches.cs b/Source/HarmonyPatches.cs index e98a1c0..ca72017 100644 --- a/Source/HarmonyPatches.cs +++ b/Source/HarmonyPatches.cs @@ -631,24 +631,25 @@ public static void InvisDoorsDontWipe(BuildableDef newEntDef, BuildableDef oldEn return; } - var oldTrueDef = - DefDatabase.AllDefs.FirstOrDefault(predicate: x => x.defName == oldEntDef.defName); - var newTrueDef = - DefDatabase.AllDefs.FirstOrDefault(predicate: x => x.defName == newEntDef.defName); - if (newEntDef.defName == HeronDefOf.HeronInvisibleDoor.defName && + if (newEntDef.defName == HeronDefOf.HeronInvisibleDoor.defName || oldEntDef.defName == HeronDefOf.HeronInvisibleDoor.defName) { - __result = true; //false, meaning, don't wipe the old thing when you spawn + __result = false; //false, meaning, don't wipe the old thing when you spawn return; } - - if (newEntDef.defName == HeronDefOf.HeronInvisibleDoor.defName || + + if (newEntDef.defName == HeronDefOf.HeronInvisibleDoor.defName && oldEntDef.defName == HeronDefOf.HeronInvisibleDoor.defName) { - __result = false; //false, meaning, don't wipe the old thing when you spawn + __result = true; return; } + var oldTrueDef = + DefDatabase.AllDefs.FirstOrDefault(predicate: x => x.defName == oldEntDef.defName); + var newTrueDef = + DefDatabase.AllDefs.FirstOrDefault(predicate: x => x.defName == newEntDef.defName); + if (newTrueDef != null && newTrueDef.thingClass == typeof(Building_DoorExpanded) && oldTrueDef != null && oldTrueDef.thingClass == typeof(Building_DoorExpanded)) { From 51f1915ee56f5ad227733383181378b60bc422ae Mon Sep 17 00:00:00 2001 From: JonnyNova Date: Sun, 2 Jun 2019 10:06:49 -0400 Subject: [PATCH 3/3] Look up defs by name instead of double iterating the database --- Source/HarmonyPatches.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/HarmonyPatches.cs b/Source/HarmonyPatches.cs index ca72017..eeef23e 100644 --- a/Source/HarmonyPatches.cs +++ b/Source/HarmonyPatches.cs @@ -645,10 +645,8 @@ public static void InvisDoorsDontWipe(BuildableDef newEntDef, BuildableDef oldEn return; } - var oldTrueDef = - DefDatabase.AllDefs.FirstOrDefault(predicate: x => x.defName == oldEntDef.defName); - var newTrueDef = - DefDatabase.AllDefs.FirstOrDefault(predicate: x => x.defName == newEntDef.defName); + var oldTrueDef = DefDatabase.GetNamed(oldEntDef.defName); + var newTrueDef = DefDatabase.GetNamed(newEntDef.defName); if (newTrueDef != null && newTrueDef.thingClass == typeof(Building_DoorExpanded) && oldTrueDef != null && oldTrueDef.thingClass == typeof(Building_DoorExpanded))