diff --git a/Source/CompatibilityPatches/Initialization.cs b/Source/CompatibilityPatches/Initialization.cs index 05bcba7f..03a22e49 100644 --- a/Source/CompatibilityPatches/Initialization.cs +++ b/Source/CompatibilityPatches/Initialization.cs @@ -8,8 +8,7 @@ namespace PrisonLabor.CompatibilityPatches internal static class Initialization { internal static void Run() - { - SeedsPlease.Init(); + { //NoWaterNoLife.Init(); WorkTab.Init(); Quarry.Init(); diff --git a/Source/CompatibilityPatches/SeedsPlease.cs b/Source/CompatibilityPatches/SeedsPlease.cs deleted file mode 100644 index b9c22395..00000000 --- a/Source/CompatibilityPatches/SeedsPlease.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Verse; -using RimWorld; - -namespace PrisonLabor.CompatibilityPatches -{ - static internal class SeedsPlease - { - static internal void Init() - { - if (Check()) - Work(); - } - - static internal bool Check() - { - if (DefDatabase.GetNamed("SowWithSeeds", false) != null) - return true; - else - return false; - } - - static internal void Work() - { - try - { - WorkGiverDef seedsPleaseDef = DefDatabase.GetNamed("GrowerSow"); - seedsPleaseDef.giverClass = typeof(SeedsPlease_WorkGiver); - JobDef prisonLaborDef = JobDefOf.Harvest; - SeedsPlease_WorkDriver_Patch.Run(); - prisonLaborDef.driverClass = DefDatabase.GetNamed("Harvest").driverClass; - } - catch (Exception e) - { - Log.Error("PrisonLaborException: encountered problem with SeedsPlease mod. Failed to patch:\n" + e.ToString()); - } - } - - static internal bool CanOverrideHarvest() - { - return DefDatabase.GetNamed("SowWithSeeds", false) == null; - } - } -} diff --git a/Source/CompatibilityPatches/SeedsPlease_WorkDriver_Patch.cs b/Source/CompatibilityPatches/SeedsPlease_WorkDriver_Patch.cs deleted file mode 100644 index 1af687ce..00000000 --- a/Source/CompatibilityPatches/SeedsPlease_WorkDriver_Patch.cs +++ /dev/null @@ -1,102 +0,0 @@ -using HarmonyLib; -using RimWorld; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Reflection.Emit; -using System.Text; -using UnityEngine; -using Verse; -using Verse.AI; -using Verse.Sound; - -namespace PrisonLabor.CompatibilityPatches -{ - internal static class SeedsPlease_WorkDriver_Patch - { - static MethodInfo method = null; - - public static void Run() - { - var harmony = new Harmony("Harmony_PrisonLabor_SeedsPlease"); - var harvestDriverClass = JobDefOf.Harvest.driverClass.BaseType; - harmony.Patch( - harvestDriverClass.GetMethod("HarvestSeedsToil", BindingFlags.NonPublic | BindingFlags.Instance), - transpiler: new HarmonyMethod(typeof(SeedsPlease_WorkDriver_Patch).GetMethod("MethodFinder"))); - harmony.Patch(method, transpiler: new HarmonyMethod(typeof(SeedsPlease_WorkDriver_Patch).GetMethod("DelegateTranspiler"))); - } - - public static IEnumerable MethodFinder(ILGenerator gen, MethodBase mBase, IEnumerable instr) - { - bool first = true; - foreach (CodeInstruction instruction in instr) - { - if (first && instruction.opcode == OpCodes.Ldftn) - { - method = instruction.operand as MethodInfo; - first = false; - } - yield return instruction; - } - } - - public static IEnumerable DelegateTranspiler(ILGenerator gen, MethodBase mBase, IEnumerable instr) - { - int step = 0; - int virtCall = 5; - - foreach (var ci in instr) - { - if (step == 0 && ci.opcode == OpCodes.Ldloc_0) - { - step++; - yield return ci; - } - else if (step == 1) - { - if (ci.opcode == OpCodes.Callvirt) - { - if (virtCall != 0) - { - yield return ci; - virtCall--; - step--; - } - else - { - step++; - } - } - else - { - step--; - yield return ci; - } - } - else if (step == 2) - { - if (ci.opcode == OpCodes.Beq) - { - yield return new CodeInstruction(OpCodes.Call, typeof(SeedsPlease_WorkDriver_Patch).GetMethod(nameof(CorrectCondition))); - yield return new CodeInstruction(OpCodes.Brfalse, ci.operand); - step++; - } - } - else - { - yield return ci; - } - } - } - - public static bool CorrectCondition(Pawn pawn) - { - if (!pawn.IsColonist && !pawn.IsPrisonerOfColony) - return true; - return false; - } - } -} diff --git a/Source/CompatibilityPatches/SeedsPlease_WorkGiver.cs b/Source/CompatibilityPatches/SeedsPlease_WorkGiver.cs deleted file mode 100644 index a8d276bc..00000000 --- a/Source/CompatibilityPatches/SeedsPlease_WorkGiver.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using PrisonLabor.Tweaks; -using RimWorld; -using Verse; -using Verse.AI; - -namespace PrisonLabor.CompatibilityPatches -{ - public class SeedsPlease_WorkGiver : WorkGiver_GrowerSow_Tweak - { - private const int SEEDS_TO_CARRY = 25; - - public override Job JobOnCell(Pawn pawn, IntVec3 c, bool forced = false) - { - Job job = base.JobOnCell(pawn, c); - if (job == null || job.plantDefToSow == null || job.plantDefToSow.blueprintDef == null) - { - return job; - } - Zone zone = GridsUtility.GetZone(c, pawn.Map); - if (zone != null) - { - foreach (IntVec3 current in GenAdj.AdjacentCells8WayRandomized()) - { - IntVec3 intVec = c + current; - if (zone.ContainsCell(intVec)) - { - foreach (Thing current2 in pawn.Map.thingGrid.ThingsAt(intVec)) - { - if (current2.def != job.plantDefToSow && current2.def.BlockPlanting && ReservationUtility.CanReserve(pawn, current2, 1, -1, null, false) && !ForbidUtility.IsForbidden(current2, pawn)) - { - if (current2.def.category == ThingCategory.Plant) - { - Job result = new Job(JobDefOf.CutPlant, current2); - return result; - } - if (current2.def.EverHaulable) - { - Job result = HaulAIUtility.HaulAsideJobFor(pawn, current2); - return result; - } - } - } - } - } - } - Predicate predicate = (Thing tempThing) => !ForbidUtility.IsForbidden(tempThing, pawn.Faction) && PawnLocalAwareness.AnimalAwareOf(pawn, tempThing) && ReservationUtility.CanReserve(pawn, tempThing, 1, -1, null, false); - Thing thing = GenClosest.ClosestThingReachable(c, pawn.Map, ThingRequest.ForDef(job.plantDefToSow.blueprintDef), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, 0, false), 9999f, predicate, null, 0, -1, false, RegionType.Set_Passable, false); - if (thing != null) - { - return new Job(DefDatabase.GetNamed("SowWithSeeds"), c, thing) - { - plantDefToSow = job.plantDefToSow, - count = 25 - }; - } - return null; - } - } -}