From 29b30996e6a061eb5fdb00d6badf9a4b723f0ac9 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Tue, 10 Feb 2026 01:11:12 +0800 Subject: [PATCH] bugfix --- UXAssist/Patches/FactoryPatch.cs | 44 ++++++++++++++++++++++++-------- UXAssist/Patches/TechPatch.cs | 8 ++++-- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/UXAssist/Patches/FactoryPatch.cs b/UXAssist/Patches/FactoryPatch.cs index 893b496..5abbd68 100644 --- a/UXAssist/Patches/FactoryPatch.cs +++ b/UXAssist/Patches/FactoryPatch.cs @@ -1541,12 +1541,14 @@ public class FactoryPatch : PatchImpl private static void OnGameBegin() { + _powerPoleProto ??= LDB.items.Select(2201); FixProto(); } private static void OnGameEnd() { UnfixProto(); + _powerPoleProto = null; } private static int PlanetGridSnapDotsNonAllocNotAligned(PlanetGrid planetGrid, Vector3 begin, Vector3 end, Vector2 interval, float yaw, float planetRadius, float gap, Vector3[] snaps) @@ -1645,21 +1647,43 @@ public class FactoryPatch : PatchImpl ); var operand = matcher.Operand; matcher.Start().Advance(pos); - matcher.Advance(2).InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, operand)).SetInstructionAndAdvance(Transpilers.EmitDelegate((BuildTool_Click click, int i) => + matcher.Advance(2).InsertAndAdvance( + new CodeInstruction(OpCodes.Ldloc_S, operand) + ).SetInstructionAndAdvance(Transpilers.EmitDelegate((BuildTool_Click click, int i) => { - if (!DragBuildPowerPolesAlternatelyEnabled.Value || (i & 1) == 0) return click.handItem; - var id = click.handItem.ID; - if (id != 2202) return click.handItem; - return LDB.items.Select(id ^ 3); - })).Advance(3).InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, operand)).SetInstructionAndAdvance(Transpilers.EmitDelegate((BuildTool_Click click, int i) => + if (click.handItem.ID != 2202 || (i & 1) == 0 || !DragBuildPowerPolesAlternatelyEnabled.Value) + return click.handItem; + return _powerPoleProto; + })).Advance(3).InsertAndAdvance( + new CodeInstruction(OpCodes.Ldloc_S, operand) + ).SetInstructionAndAdvance(Transpilers.EmitDelegate((BuildTool_Click click, int i) => { - if (!DragBuildPowerPolesAlternatelyEnabled.Value || (i & 1) == 0) return click.handPrefabDesc; - var id = click.handItem.ID; - if (id != 2202) return click.handPrefabDesc; - return LDB.items.Select(id ^ 3).prefabDesc; + if (click.handItem.ID != 2202 || (i & 1) == 0 || !DragBuildPowerPolesAlternatelyEnabled.Value) + return click.handPrefabDesc; + return _powerPoleProto.prefabDesc; + })); + matcher.MatchForward(false, + new CodeMatch(ci => ci.IsLdloc()), + new CodeMatch(ci => ci.IsLdloc()), + new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(BuildPreview), nameof(BuildPreview.Clone))) + ).Advance(2).InsertAndAdvance( + new CodeInstruction(OpCodes.Ldloc_S, operand) + ).SetInstructionAndAdvance(Transpilers.EmitDelegate((BuildPreview to, BuildPreview from, int i) => + { + if (from.item.ID != 2202 || (i & 1) == 0 || !DragBuildPowerPolesAlternatelyEnabled.Value) + { + to.Clone(from); + return; + } + to.ResetAll(); + to.item = _powerPoleProto; + to.desc = _powerPoleProto.prefabDesc; + to.needModel = _powerPoleProto.prefabDesc.lodCount > 0 && _powerPoleProto.prefabDesc.lodMeshes[0] != null; })); return matcher.InstructionEnumeration(); } + + private static ItemProto _powerPoleProto; } private class BeltSignalsForBuyOut : PatchImpl diff --git a/UXAssist/Patches/TechPatch.cs b/UXAssist/Patches/TechPatch.cs index e19361b..12e1253 100644 --- a/UXAssist/Patches/TechPatch.cs +++ b/UXAssist/Patches/TechPatch.cs @@ -134,7 +134,9 @@ public static class TechPatch _protoPatched = false; } - UIRoot.instance.uiGame.techTree.OnPageChanged(); + var techTree = UIRoot.instance?.uiGame?.techTree; + if (techTree != null && techTree.isActiveAndEnabled) + techTree.OnPageChanged(); } private static void VFPreload_InvokeOnLoadWorkEnded_Postfix() @@ -305,7 +307,9 @@ public static class TechPatch } } } - UIRoot.instance.uiGame.techTree.OnPageChanged(); + var techTree = UIRoot.instance?.uiGame?.techTree; + if (techTree != null && techTree.isActiveAndEnabled) + techTree.OnPageChanged(); } }