Remove colision from walls towers and gates

To be able to ACTUALLY place wire
This commit is contained in:
2024-09-29 01:47:39 +02:00
parent f0e4a2d64b
commit dee8e85eb9

View File

@@ -648,5 +648,56 @@ namespace InfectionFreeZone {
}
}
}
// TODO: Add toggle for this
[HarmonyTranspiler]
[HarmonyPatch(typeof(ValidatableStructure), "Awake")]
public static IEnumerable<CodeInstruction> PostfixValidatableStructure(
IEnumerable<CodeInstruction> instructions) {
var codes = new List<CodeInstruction>(instructions);
int start = 0;
int start2 = 0;
int end = 0;
int end2 = 0;
for (var i = 0; i < codes.Count; i++) {
if (codes[i].opcode == OpCodes.Ldc_I4_5) {
Console.WriteLine($"Opcode is {codes[i].opcode} and operand is {codes[i].operand} at index {i}");
codes[i] = new CodeInstruction(OpCodes.Ldc_I4_2); // Array size after our deletion is 3 from 5
}
if (codes[i].opcode == OpCodes.Ldstr && codes[i].operand.ToString() == "Tower") {
Console.WriteLine($"Opcode is {codes[i].opcode} and operand is {codes[i].operand} at index {i}");
start2 = i - 2;
end2 = i + 2;
}
if (codes[i].opcode == OpCodes.Ldstr && codes[i].operand.ToString() == "Farmland") {
Console.WriteLine($"Opcode is {codes[i].opcode} and operand is {codes[i].operand} at index {i}");
Console.WriteLine(
$"Opcode is {codes[i - 1].opcode} and operand is {codes[i - 1].operand} at index {i - 1}");
codes[i - 1].opcode =
OpCodes.Ldc_I4_1; // Because we deleted the previous element this one is now index 1 instead of 2
}
if (codes[i].opcode == OpCodes.Ldstr && codes[i].operand.ToString() == "Wall") {
Console.WriteLine($"Opcode is {codes[i].opcode} and operand is {codes[i].operand} at index {i}");
start = i - 2;
end = i + 6;
break;
}
}
Console.WriteLine($"Start is {start} with opcode {codes[start].opcode} and operand {codes[start].operand}");
Console.WriteLine($"End is {end} with opcode {codes[end].opcode} and operand {codes[end].operand}");
codes.RemoveRange(start, end - start);
Console.WriteLine($"Removed {end - start} instructions");
Console.WriteLine(
$"Start2 is {start2} with opcode {codes[start2].opcode} and operand {codes[start2].operand}");
Console.WriteLine($"End2 is {end2} with opcode {codes[end2].opcode} and operand {codes[end2].operand}");
codes.RemoveRange(start2, end2 - start2);
Console.WriteLine($"Removed {end2 - start2} instructions");
return codes.AsEnumerable();
}
}
}