1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2026-03-22 10:23:26 +08:00
This commit is contained in:
2026-02-10 01:11:12 +08:00
parent 60d14c9401
commit 29b30996e6
2 changed files with 40 additions and 12 deletions

View File

@@ -1541,12 +1541,14 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
private static void OnGameBegin() private static void OnGameBegin()
{ {
_powerPoleProto ??= LDB.items.Select(2201);
FixProto(); FixProto();
} }
private static void OnGameEnd() private static void OnGameEnd()
{ {
UnfixProto(); UnfixProto();
_powerPoleProto = null;
} }
private static int PlanetGridSnapDotsNonAllocNotAligned(PlanetGrid planetGrid, Vector3 begin, Vector3 end, Vector2 interval, float yaw, float planetRadius, float gap, Vector3[] snaps) 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<FactoryPatch>
); );
var operand = matcher.Operand; var operand = matcher.Operand;
matcher.Start().Advance(pos); 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; if (click.handItem.ID != 2202 || (i & 1) == 0 || !DragBuildPowerPolesAlternatelyEnabled.Value)
var id = click.handItem.ID; return click.handItem;
if (id != 2202) return click.handItem; return _powerPoleProto;
return LDB.items.Select(id ^ 3); })).Advance(3).InsertAndAdvance(
})).Advance(3).InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, operand)).SetInstructionAndAdvance(Transpilers.EmitDelegate((BuildTool_Click click, int i) => new CodeInstruction(OpCodes.Ldloc_S, operand)
).SetInstructionAndAdvance(Transpilers.EmitDelegate((BuildTool_Click click, int i) =>
{ {
if (!DragBuildPowerPolesAlternatelyEnabled.Value || (i & 1) == 0) return click.handPrefabDesc; if (click.handItem.ID != 2202 || (i & 1) == 0 || !DragBuildPowerPolesAlternatelyEnabled.Value)
var id = click.handItem.ID; return click.handPrefabDesc;
if (id != 2202) return click.handPrefabDesc; return _powerPoleProto.prefabDesc;
return LDB.items.Select(id ^ 3).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(); return matcher.InstructionEnumeration();
} }
private static ItemProto _powerPoleProto;
} }
private class BeltSignalsForBuyOut : PatchImpl<BeltSignalsForBuyOut> private class BeltSignalsForBuyOut : PatchImpl<BeltSignalsForBuyOut>

View File

@@ -134,7 +134,9 @@ public static class TechPatch
_protoPatched = false; _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() 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();
} }
} }