From 54b75a869da9fb825951aec6a528aeccef050c03 Mon Sep 17 00:00:00 2001 From: Guus Waals <_@guusw.nl> Date: Sat, 6 Jan 2024 11:59:17 +0100 Subject: [PATCH] Fix mod for new game version --- mod/Patches/Deconstructable.cs | 100 ++++++++++++++++++--------------- mod/Strings.cs | 18 ++++-- mod/build | 6 +- 3 files changed, 72 insertions(+), 52 deletions(-) diff --git a/mod/Patches/Deconstructable.cs b/mod/Patches/Deconstructable.cs index 1fb0332..0e51056 100644 --- a/mod/Patches/Deconstructable.cs +++ b/mod/Patches/Deconstructable.cs @@ -1,14 +1,18 @@ using System.Collections.Generic; using System.Reflection; using System.Reflection.Emit; +using System; using HarmonyLib; using KMod; -namespace PriorityUX { +namespace PriorityUX +{ [HarmonyDebug] [HarmonyPatch(typeof(Deconstructable))] - public class DeconstructablePatches { - public static PrioritySetting getChorePriority() { + public class DeconstructablePatches + { + public static PrioritySetting getChorePriority() + { Debug.Log("Getting deconstruct chore priority"); if (Options.Instance.deconstructInheritPriority) return Utils.getLastPriority(); @@ -16,59 +20,63 @@ namespace PriorityUX { return Utils.getDefaultPriority(); } + [HarmonyPatch(new Type[] { typeof(bool) })] [HarmonyPatch("QueueDeconstruction")] [HarmonyPostfix] - static void QueueDeconstruction_Postfix(Deconstructable __instance) { + static void QueueDeconstruction_Postfix(Deconstructable __instance) + { Prioritizable prioritizable = __instance.GetComponent(); - if (prioritizable != null) { + if (prioritizable != null) + { Debug.Log("Updating deconstruct priority"); prioritizable.SetMasterPriority(getChorePriority()); } } - /* - [HarmonyPatch("QueueDeconstruction")] - [HarmonyTranspiler] - static IEnumerable QueueDeconstruction_Transpiler(IEnumerable instructions, ILGenerator ilGenerator) { - Harmony.DEBUG = true; - var priorityLocal = ilGenerator.DeclareLocal(typeof(int)); - var priorityClassLocal = ilGenerator.DeclareLocal(typeof(PriorityScreen.PriorityClass)); - var tmpLocal0 = ilGenerator.DeclareLocal(typeof(int)); - var tmpLocal1 = ilGenerator.DeclareLocal(typeof(int)); - yield return CodeInstruction.Call(typeof(DeconstructablePatches), nameof(getChorePriority)); - yield return new CodeInstruction(OpCodes.Dup); - // yield return new CodeInstruction(OpCodes.Pop); - // yield return new CodeInstruction(OpCodes.Pop); - yield return CodeInstruction.LoadField(typeof(PrioritySetting), nameof(PrioritySetting.priority_value)); - yield return new CodeInstruction(OpCodes.Stloc, priorityLocal.LocalIndex); - yield return CodeInstruction.LoadField(typeof(PrioritySetting), nameof(PrioritySetting.priority_class)); - yield return new CodeInstruction(OpCodes.Stloc, priorityClassLocal.LocalIndex); + /* + [HarmonyPatch("QueueDeconstruction")] + [HarmonyTranspiler] + static IEnumerable QueueDeconstruction_Transpiler(IEnumerable instructions, ILGenerator ilGenerator) { + Harmony.DEBUG = true; - ConstructorInfo choreConstructor = typeof(WorkChore).GetConstructors()[0]; - // FieldInfo field = typeof(Deconstructable).GetField(nameof(Deconstructable.chore)); - foreach (var instruction in instructions) { - // IL_0087: ldc.i4.1 - // IL_0088: ldc.i4.0 // priority_class - // IL_0089: ldc.i4.5 // priority_value - // IL_008a: ldc.i4.1 - // IL_008b: ldc.i4.1 - // IL_008c: newobj instance void class WorkChore`1::.ctor(class ChoreType, class ['Assembly-CSharp-firstpass']IStateMachineTarget, class ChoreProvider, bool, class [mscorlib]System.Action`1, class [mscorlib]System.Action`1, class [mscorlib]System.Action`1, bool, class ScheduleBlockType, bool, bool, class ['Assembly-CSharp-firstpass']KAnimFile, bool, bool, bool, valuetype PriorityScreen/PriorityClass, int32, bool, bool) - // IL_0091: stfld class Chore Deconstructable::chore - if (instruction.OperandIs(choreConstructor)) { - Debug.Log("PATCHING CHORE CONSTRUCTOR\n" + System.Environment.StackTrace); - yield return new CodeInstruction(OpCodes.Stloc, tmpLocal1.LocalIndex); - yield return new CodeInstruction(OpCodes.Stloc, tmpLocal0.LocalIndex); - yield return new CodeInstruction(OpCodes.Pop); - yield return new CodeInstruction(OpCodes.Pop); - yield return new CodeInstruction(OpCodes.Ldloc, priorityClassLocal.LocalIndex); - yield return new CodeInstruction(OpCodes.Ldloc, priorityLocal.LocalIndex); - yield return new CodeInstruction(OpCodes.Ldloc, tmpLocal0.LocalIndex); - yield return new CodeInstruction(OpCodes.Ldloc, tmpLocal1.LocalIndex); + var priorityLocal = ilGenerator.DeclareLocal(typeof(int)); + var priorityClassLocal = ilGenerator.DeclareLocal(typeof(PriorityScreen.PriorityClass)); + var tmpLocal0 = ilGenerator.DeclareLocal(typeof(int)); + var tmpLocal1 = ilGenerator.DeclareLocal(typeof(int)); + yield return CodeInstruction.Call(typeof(DeconstructablePatches), nameof(getChorePriority)); + yield return new CodeInstruction(OpCodes.Dup); + // yield return new CodeInstruction(OpCodes.Pop); + // yield return new CodeInstruction(OpCodes.Pop); + yield return CodeInstruction.LoadField(typeof(PrioritySetting), nameof(PrioritySetting.priority_value)); + yield return new CodeInstruction(OpCodes.Stloc, priorityLocal.LocalIndex); + yield return CodeInstruction.LoadField(typeof(PrioritySetting), nameof(PrioritySetting.priority_class)); + yield return new CodeInstruction(OpCodes.Stloc, priorityClassLocal.LocalIndex); + + ConstructorInfo choreConstructor = typeof(WorkChore).GetConstructors()[0]; + // FieldInfo field = typeof(Deconstructable).GetField(nameof(Deconstructable.chore)); + foreach (var instruction in instructions) { + // IL_0087: ldc.i4.1 + // IL_0088: ldc.i4.0 // priority_class + // IL_0089: ldc.i4.5 // priority_value + // IL_008a: ldc.i4.1 + // IL_008b: ldc.i4.1 + // IL_008c: newobj instance void class WorkChore`1::.ctor(class ChoreType, class ['Assembly-CSharp-firstpass']IStateMachineTarget, class ChoreProvider, bool, class [mscorlib]System.Action`1, class [mscorlib]System.Action`1, class [mscorlib]System.Action`1, bool, class ScheduleBlockType, bool, bool, class ['Assembly-CSharp-firstpass']KAnimFile, bool, bool, bool, valuetype PriorityScreen/PriorityClass, int32, bool, bool) + // IL_0091: stfld class Chore Deconstructable::chore + if (instruction.OperandIs(choreConstructor)) { + Debug.Log("PATCHING CHORE CONSTRUCTOR\n" + System.Environment.StackTrace); + yield return new CodeInstruction(OpCodes.Stloc, tmpLocal1.LocalIndex); + yield return new CodeInstruction(OpCodes.Stloc, tmpLocal0.LocalIndex); + yield return new CodeInstruction(OpCodes.Pop); + yield return new CodeInstruction(OpCodes.Pop); + yield return new CodeInstruction(OpCodes.Ldloc, priorityClassLocal.LocalIndex); + yield return new CodeInstruction(OpCodes.Ldloc, priorityLocal.LocalIndex); + yield return new CodeInstruction(OpCodes.Ldloc, tmpLocal0.LocalIndex); + yield return new CodeInstruction(OpCodes.Ldloc, tmpLocal1.LocalIndex); + yield return instruction; + continue; + } yield return instruction; - continue; } - yield return instruction; - } - } */ + } */ } } diff --git a/mod/Strings.cs b/mod/Strings.cs index 7970e92..38d0b72 100644 --- a/mod/Strings.cs +++ b/mod/Strings.cs @@ -12,10 +12,20 @@ namespace PriorityUX { public static LocString TOOLTIP = "Used for reset and as a default priority"; public static LocString CATEGORY = "Tweaks"; } - public static class ENABLEPRIORITYHOTKEYSEVERYWHERE { - public static LocString NAME = "Enable priority keys everywhere"; - public static LocString TOOLTIP = "Allows the 1-9 keys to select priority for all tools. Close the tool to open the building menus."; - public static LocString CATEGORY = "Tweaks"; + public static class ENABLEKEYSFORBUILDING { + public static LocString NAME = "Enable priority keys in the build menu"; + public static LocString TOOLTIP = "Allows the 1-9 keys to select priority in the building menu. Close the tool to open the building menus."; + public static LocString CATEGORY = "Toggles"; + } + public static class DECONSTRUCTINHERITPRIORITY { + public static LocString NAME = "Use last priority for deconstruction"; + public static LocString TOOLTIP = "Use the last priority for deconstruction. If disabled, the default priority will be used every time the menu is opened."; + public static LocString CATEGORY = "Toggles"; + } + public static class ENABLEKEYSFORALLTOOLS { + public static LocString NAME = "Enable priority keys for all tools"; + public static LocString TOOLTIP = "Will enable the 1-9 keys for all tools."; + public static LocString CATEGORY = "Toggles"; } } } diff --git a/mod/build b/mod/build index 2eb2bb3..11cb79f 100755 --- a/mod/build +++ b/mod/build @@ -6,10 +6,12 @@ ROOT=$( cd "$(dirname "$0")" ; pwd -P ) pushd $ROOT # Do the build (need to use mono) -$msbuild +# $msbuild +$msbuild -p:Configuration=Release set -x rm -rf dist mkdir dist -cp bin/Debug/net48/oni-prio.dll dist/ +# cp bin/Debug/net48/oni-prio.dll dist/ +cp bin/Release/net48/oni-prio.dll dist/ cp -r meta/* dist/