diff --git a/UXAssist/Patches/FactoryPatch.cs b/UXAssist/Patches/FactoryPatch.cs index c6b3fb2..5e4695e 100644 --- a/UXAssist/Patches/FactoryPatch.cs +++ b/UXAssist/Patches/FactoryPatch.cs @@ -28,6 +28,7 @@ public class FactoryPatch: PatchImpl public static ConfigEntry DragBuildPowerPolesEnabled; public static ConfigEntry BeltSignalsForBuyOutEnabled; private static PressKeyBind _doNotRenderEntitiesKey; + private static PressKeyBind _offgridfForPathsKey; public static void Init() { @@ -40,6 +41,15 @@ public class FactoryPatch: PatchImpl } ); I18N.Add("KEYToggleDoNotRenderEntities", "Toggle Do Not Render Factory Entities", "切换不渲染工厂建筑实体"); + _offgridfForPathsKey = KeyBindings.RegisterKeyBinding(new BuiltinKey + { + key = new CombineKey((int)KeyCode.LeftControl, 0, ECombineKeyAction.OnceClick, false), + conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.UI | KeyBindConflict.FLYING | KeyBindConflict.SAILING | KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.KEYBOARD_KEYBIND, + name = "OffgridForPaths", + canOverride = true + } + ); + I18N.Add("KEYOffgridForPaths", "Build belts offgrid", "脱离网格建造传送带"); BeltSignalsForBuyOut.InitPersist(); UnlimitInteractiveEnabled.SettingChanged += (_, _) => UnlimitInteractive.Enable(UnlimitInteractiveEnabled.Value); @@ -699,8 +709,8 @@ public class FactoryPatch: PatchImpl var jmp0 = generator.DefineLabel(); var jmp1 = generator.DefineLabel(); matcher.InsertAndAdvance( - new CodeInstruction(OpCodes.Ldc_I4, (int)KeyCode.LeftControl), - new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Input), nameof(Input.GetKeyInt))), + new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(FactoryPatch), nameof(_offgridfForPathsKey))), + new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(PressKeyBind), nameof(PressKeyBind.keyValue))), new CodeInstruction(OpCodes.Brfalse, jmp0), new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldarg_0), @@ -720,6 +730,7 @@ public class FactoryPatch: PatchImpl return matcher.InstructionEnumeration(); } + /* public static IEnumerable PatchToPerformSteppedRotate(IEnumerable instructions, ILGenerator generator) { var matcher = new CodeMatcher(instructions, generator); @@ -774,6 +785,7 @@ public class FactoryPatch: PatchImpl instance.yaw = Mathf.Round(instance.yaw / SteppedRotationDegrees) * SteppedRotationDegrees; } } + */ } public class TreatStackingAsSingle: PatchImpl diff --git a/UXAssist/Patches/PersistPatch.cs b/UXAssist/Patches/PersistPatch.cs index ebdb8ea..5539ad0 100644 --- a/UXAssist/Patches/PersistPatch.cs +++ b/UXAssist/Patches/PersistPatch.cs @@ -94,22 +94,22 @@ public class PersistPatch : PatchImpl Array.Sort(buildings, (a, b) => { var tmpItemId = a.itemId - b.itemId; - if (tmpItemId != 0) - return tmpItemId; + if (tmpItemId != 0) return tmpItemId; + var tmpModelIndex = a.modelIndex - b.modelIndex; - if (tmpModelIndex != 0) - return tmpModelIndex; + if (tmpModelIndex != 0) return tmpModelIndex; + var tmpRecipeId = a.recipeId - b.recipeId; - if (tmpRecipeId != 0) - return tmpRecipeId; + if (tmpRecipeId != 0) return tmpRecipeId; + var tmpAreaIndex = a.areaIndex - b.areaIndex; - if (tmpAreaIndex != 0) - return tmpAreaIndex; - const double ky = 256.0; - const double kx = 1024.0; - var scorePosA = (a.localOffset_y * ky + a.localOffset_x) * kx + a.localOffset_z; - var scorePosB = (b.localOffset_y * ky + b.localOffset_x) * kx + b.localOffset_z; - return scorePosA < scorePosB ? 1 : -1; + if (tmpAreaIndex != 0) return tmpAreaIndex; + + var sign = Math.Sign(b.localOffset_y - a.localOffset_y); + if (sign != 0) return sign; + + sign = Math.Sign(b.localOffset_x - a.localOffset_x); + return sign != 0 ? sign : Math.Sign(b.localOffset_z - a.localOffset_z); }); for (var i = buildings.Length - 1; i >= 0; i--) {