using System.Reflection; using HarmonyLib; using RimWorld; using Verse; namespace LTS_Implants { [StaticConstructorOnStartup] public static class HarmonyPatches { public static bool IsCombatExtended = false; public static bool IsSarg = false; static HarmonyPatches() { Harmony harmony = new Harmony("rimworld.LTS.implants"); Harmony.DEBUG = false; //Check if we are in a CE enabled env if (ModLister.GetModWithIdentifier("ceteam.combatextended") != null) { IsCombatExtended = true; Verse.Log.Message("[LTS-II-Forked]Found CombatExtended,Will unpatch some harmony patches to reduce overlap"); } //TODO Detect Sarg`s mod and unpatch accordingly. if (ModLister.BiotechInstalled) { Verse.Log.Message("[LTS-II-Forked]Biotech found, harmony patch running"); if (IsCombatExtended) { Verse.Log.Message("[LTS-II-Forked]Unpatching CE Biotech Mechanitor Command Range patches to reduce overlap,CE range is used instead vanilla range"); var mechanitorCanCommand = typeof(Pawn_MechanitorTracker).GetMethod("CanCommandTo"); harmony.Unpatch(mechanitorCanCommand,HarmonyPatchType.All,"CombatExtended.HarmonyCE"); var mechanitorDrawCommandRange = typeof(Pawn_MechanitorTracker).GetMethod("DrawCommandRadius"); harmony.Unpatch(mechanitorDrawCommandRange,HarmonyPatchType.All,"CombatExtended.HarmonyCE"); } harmony.PatchCategory(Assembly.GetExecutingAssembly(), "Biotech"); } harmony.PatchAllUncategorized(Assembly.GetExecutingAssembly()); #if DEBUG foreach (var method in harmony.GetPatchedMethods()) { Verse.Log.Message($"[LTSIIF]Patched Method {method.Name}"); var patchinfo = Harmony.GetPatchInfo(method); foreach (var VARIABLE in patchinfo.Owners) { Verse.Log.Message("The Method has been patched by:" + VARIABLE); } foreach (var VARIABLE in patchinfo.Prefixes) { Verse.Log.Message("has Prefix:" + VARIABLE.PatchMethod); } foreach (var VARIABLE in patchinfo.Postfixes) { Verse.Log.Message("has Postfix:" + VARIABLE.PatchMethod); } foreach (var VARIABLE in patchinfo.Transpilers) { Verse.Log.Message("has Transpiler:" + VARIABLE.PatchMethod); } Verse.Log.Message("Displaying next method"); } #endif } } }