Skip to content

Commit

Permalink
Restore thingToIgnore check.
Browse files Browse the repository at this point in the history
I guess the check for "blocking thing" passes if it is the same def, so thingToIgnore needs to be kept?.
  • Loading branch information
alextd committed Dec 31, 2024
1 parent 1d05a22 commit 3e5d6c7
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions Source/OverMineable/BlueprintOverFogged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ public static AcceptanceReport BlueprintExistsAcceptance(Map map, IntVec3 center
}


// Change Conduit PlaceWorker to allow conduits over conduits.
// Note: before, I fixed this to properly use the thingToIgnore argument.
// This is redundant now ... but vanilla is technically incorrect to not use that arg.
// 1) Change Conduit PlaceWorker to allow conduits over conduits

// 2) TL;DR: actually ignore the thingToIgnore argument
//This patch fixes a vanilla bug/oversight, that forgot to check thingToIgnore in conduit's placeworker.
//This wasn't a problem in vanilla, but with replace stuff, conduit blueprints would disappear when doors are opened
//Since revealing new areas now triggers re-checking blueprints, power conduit blueprints would check their tile.
//They'd find themselves, and determine they can't exist because there's already a power conduit there.
//The thingToIgnore arguments already exists, to, you know, ignore that. But it wasn't checked.
[HarmonyPatch(typeof(PlaceWorker_Conduit), "AllowsPlacing")]
public static class FixConduitPlaceWorker
{
Expand Down Expand Up @@ -111,15 +116,28 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
foundLdLoc = true;

// At start of loop, insert:
// if(thingList[i].def.building.isPowerConduit)
// continue;

// Noop with start of loop label
yield return new CodeInstruction(OpCodes.Nop) { labels = i.labels };//start of loop label
i.labels = new List<Label>();


// if(thingList[i] == thingToIgnore)
// continue;
foreach (CodeInstruction ci in currentThing)
yield return new CodeInstruction(ci.opcode, ci.operand);//thingList[i] (Thing)
yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(FixConduitPlaceWorker), nameof(IsConduit)));
yield return new CodeInstruction(OpCodes.Brtrue, continueLabel);// if(thingList[i].IsConduit()) continue;

yield return new CodeInstruction(OpCodes.Ldarg_S, 5);//thingToIgnore
yield return new CodeInstruction(OpCodes.Beq, continueLabel);//if( ... == ... ) continue;


// if(thingList[i].def.building.isPowerConduit)
// continue;
foreach (CodeInstruction ci in currentThing)
yield return new CodeInstruction(ci.opcode, ci.operand);//thingList[i] (Thing)

yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(FixConduitPlaceWorker), nameof(IsConduit))); // ... .IsConduit()
yield return new CodeInstruction(OpCodes.Brtrue, continueLabel);// if(...) continue;
}
yield return i;
}
Expand Down

0 comments on commit 3e5d6c7

Please sign in to comment.