refactor: remove single-owner helpers and redundant plumbing

Return feature-only helpers to their owners, remove inactive scaffolding and duplicate state, and reuse existing calculation and UI work without changing public contracts or gameplay.

Record repository-wide coverage, justified retentions, independent reviews and validation, including baseline dashboard fixture failures.

Assisted-by: Cindy (https://cindy.app)
This commit is contained in:
soarqin committed 2026-11-04 23:06:50 +08:00
1 parent 64a23e9772
commit e35fba88ae
60 files changed
+1094 -994

No files matched your search

@@ -1,12 +1,10 @@
using System;
using UnityEngine;
using UXAssist.Common;
using UXAssist.Common.ModFeatures;
using CheatEnabler;
namespace CheatEnabler.Functions.DysonSphere;
[ModFeature("DysonSphereResolver")]
public static class DysonSphereResolver
{
public static (global::DysonSphere sphere, StarData star)? ResolveCurrent()
@@ -3,13 +3,11 @@ using HarmonyLib;
using UnityEngine;
using UXAssist.Common;
using UXAssist.Common.GameConstants;
using UXAssist.Common.ModFeatures;
using UXAssist.Common.Utils;
using CheatEnabler;
namespace CheatEnabler.Functions.DysonSphere;
[ModFeature("FrameRemovalFunctions")]
public static class FrameRemovalFunctions
{
public static void RemoveAllFrames()
@@ -7,12 +7,10 @@ using static CheatEnabler.Functions.DysonSphere.GeometryHelpers;
using UnityEngine;
using UXAssist.Common;
using UXAssist.Common.GameConstants;
using UXAssist.Common.ModFeatures;
using CheatEnabler;
namespace CheatEnabler.Functions.DysonSphere;
[ModFeature("IllegalShellFunctions")]
public static class IllegalShellFunctions
{
private static void EnsureDysonShellMaps()
@@ -41,7 +39,7 @@ public static class IllegalShellFunctions
layer.shellCursor = 1;
}
private static void FinalizeDysonSphereChanges(global::DysonSphere sphere, DysonSphereLayer layer, bool notify = false, bool resetRenderMasks = false)
private static void FinalizeDysonSphereChanges(global::DysonSphere sphere, bool notify = false, bool resetRenderMasks = false)
{
if (sphere == null) return;
sphere.CheckAutoNodes();
@@ -140,7 +138,7 @@ public static class IllegalShellFunctions
node.RecalcSpReq();
node.RecalcCpReq();
}
FinalizeDysonSphereChanges(dysonSphere, layer, true, true);
FinalizeDysonSphereChanges(dysonSphere, true, true);
}
public static void KeepMaxProductionShells()
@@ -245,7 +243,7 @@ public static class IllegalShellFunctions
node.RecalcCpReq();
}
}
FinalizeDysonSphereChanges(dysonSphere, null);
FinalizeDysonSphereChanges(dysonSphere);
}
public static void CreateIllegalDysonShellQuickly(int triangleCount)
@@ -317,7 +315,7 @@ public static class IllegalShellFunctions
node.RecalcSpReq();
node.RecalcCpReq();
}
FinalizeDysonSphereChanges(dysonSphere, layer, true);
FinalizeDysonSphereChanges(dysonSphere, true);
return;
}
}
@@ -433,7 +431,7 @@ public static class IllegalShellFunctions
var shellsChanged = CreateIllegalDysonShellWithMaxOutputForLayer(layer);
FinalizeDysonSphereChanges(dysonSphere, layer, shellsChanged, true);
FinalizeDysonSphereChanges(dysonSphere, shellsChanged, true);
}
public static void CreateIllegalDysonShellWithMaxOutputForAllLayers()
@@ -449,7 +447,7 @@ public static class IllegalShellFunctions
shellsChanged = CreateIllegalDysonShellWithMaxOutputForLayer(layer) || shellsChanged;
}
FinalizeDysonSphereChanges(dysonSphere, dysonSphere.layersSorted.FirstOrDefault(l => l != null), shellsChanged, true);
FinalizeDysonSphereChanges(dysonSphere, shellsChanged, true);
}
public static void CreateIllegalDysonShellsSpecially()
@@ -477,8 +475,6 @@ public static class IllegalShellFunctions
for (var idx = 1; idx <= 2; idx++)
{
Dictionary<(int, int), int> availableFrames = [];
HashSet<int> unusedFrameIds = [];
var layer = dysonSphere.layersIdBased[idx];
if (layer != null)
{
@@ -571,6 +567,6 @@ public static class IllegalShellFunctions
}
}
FinalizeDysonSphereChanges(dysonSphere, dysonSphere.layersIdBased[2], shellsChanged, true);
FinalizeDysonSphereChanges(dysonSphere, shellsChanged, true);
}
}
@@ -3,13 +3,11 @@ using System.Linq;
using HarmonyLib;
using UnityEngine;
using UXAssist.Common;
using UXAssist.Common.ModFeatures;
using UXAssist.Common.Utils;
using CheatEnabler;
namespace CheatEnabler.Functions.DysonSphere;
[ModFeature("ShellCompletionFunctions")]
public static class ShellCompletionFunctions
{
public static void CompleteShellsInstantly()
@@ -1,11 +1,9 @@
using BepInEx.Configuration;
using CheatEnabler.Functions.DysonSphere;
using UXAssist.Common;
using UXAssist.Common.ModFeatures;
namespace CheatEnabler.Functions;
[ModFeature("CheatDysonSphere", Order = 20)]
public static class DysonSphereFunctions
{
public const int MinShellsCountForFunctions = 1;
+1 -3
View File
@@ -1,9 +1,7 @@
using Random = UnityEngine.Random;
using UXAssist.Common.ModFeatures;
namespace CheatEnabler.Functions;
[ModFeature("PlanetFunctions")]
public static class PlanetFunctions
{
public static void BuryAllVeins(bool bury)
@@ -35,4 +33,4 @@ public static class PlanetFunctions
}
GameMain.gpuiManager.SyncAllGPUBuffer();
}
}
}
@@ -2,11 +2,9 @@
using System.Linq;
using UXAssist.Common;
using UXAssist.Common.GameConstants;
using UXAssist.Common.ModFeatures;
namespace CheatEnabler.Functions;
[ModFeature("PlayerFunctions")]
public static class PlayerFunctions
{
public static void Init()
@@ -16,7 +16,6 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
private static Dictionary<int, BeltSignal>[] _signalBelts;
private static Dictionary<long, int> _portalFrom;
private static Dictionary<int, HashSet<long>> _portalTo;
private static int _signalBeltsCapacity;
private static bool _initialized;
private static ProductionCatalog _sourceCatalog;
private static ProductionItem _preferredProliferator;
@@ -50,7 +49,6 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
_signalBelts = null;
_portalFrom = null;
_portalTo = null;
_signalBeltsCapacity = 0;
PendingSources.Clear();
ClearSourceCache();
}
@@ -84,7 +82,6 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
GameLogicProc.OnGameBegin -= OnGameBegin;
_initialized = false;
_signalBelts = null;
_signalBeltsCapacity = 0;
PendingSources.Clear();
ClearSourceCache();
}
@@ -181,7 +178,6 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
{
if (DSPGame.IsMenuDemo) return;
_signalBelts = new Dictionary<int, BeltSignal>[64];
_signalBeltsCapacity = 64;
_portalFrom = [];
_portalTo = [];
@@ -225,13 +221,12 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
{
Dictionary<int, BeltSignal> obj;
if (index < 0) return null;
if (index >= _signalBeltsCapacity)
if (index >= _signalBelts.Length)
{
var newCapacity = _signalBeltsCapacity * 2;
var newCapacity = _signalBelts.Length * 2;
var newSignalBelts = new Dictionary<int, BeltSignal>[newCapacity];
Array.Copy(_signalBelts, newSignalBelts, _signalBeltsCapacity);
Array.Copy(_signalBelts, newSignalBelts, _signalBelts.Length);
_signalBelts = newSignalBelts;
_signalBeltsCapacity = newCapacity;
}
else
{
@@ -246,7 +241,7 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
private static Dictionary<int, BeltSignal> GetSignalBelts(int index)
{
return index >= 0 && index < _signalBeltsCapacity ? _signalBelts[index] : null;
return index >= 0 && _signalBelts != null && index < _signalBelts.Length ? _signalBelts[index] : null;
}
private static void SetSignalBelt(int factory, int beltId, int signalId, int number)
+30 -2
View File
@@ -17,7 +17,7 @@ internal static class TechClickHandler
}
catch (Exception e)
{
TechLog.Warn($"click handling failed: {e}");
CheatEnabler.Logger.LogWarning($"[TechTweaks] click handling failed: {e}");
}
}
@@ -40,7 +40,7 @@ internal static class TechClickHandler
return;
}
if (!TechKeyCombo.TryDecode(out int steps))
if (!TryDecodeModifiers(out int steps))
{
return;
}
@@ -54,4 +54,32 @@ internal static class TechClickHandler
TechUnlock.Run(history, techProto, steps);
}
}
private static bool TryDecodeModifiers(out int steps)
{
steps = 0;
if (VFInput.shift)
{
if (VFInput.alt) return false;
steps = VFInput.control ? 100 : 1;
return true;
}
if (VFInput.control)
{
if (VFInput.alt) return false;
steps = 10;
return true;
}
if (VFInput.alt)
{
// Alt applies or reverts every level available to this click.
steps = int.MaxValue;
return true;
}
return false;
}
}
+1 -1
View File
@@ -20,7 +20,7 @@ internal static class TechDowngrade
{
if (!TryGetLastAppliedLevel(history, techProto, out int lastApplied) || steps <= 0) return;
int target = steps == TechKeyCombo.LevelToMax
int target = steps == int.MaxValue
? techProto.Level - 1
: System.Math.Max(techProto.Level - 1, lastApplied - steps);
Targets.Clear();
+4 -4
View File
@@ -410,7 +410,7 @@ namespace CheatEnabler.Patches.Tech
// a downgrade can walk thousands of levels and must not flood the log.
if (UnknownFuncsWarned.Add(func))
{
TechLog.Warn($"revert: no inverse known for tech function {func} (value={value}, level={level}); " +
CheatEnabler.Logger.LogWarning($"[TechTweaks] revert: no inverse known for tech function {func} (value={value}, level={level}); " +
"the field was left untouched. A game update may have added a new function.");
}
@@ -429,7 +429,7 @@ namespace CheatEnabler.Patches.Tech
ModeConfig freeMode = Configs.freeMode;
if (freeMode == null)
{
TechLog.Warn($"recompute of tech function {func} skipped: Configs.freeMode is not available");
CheatEnabler.Logger.LogWarning($"[TechTweaks] recompute of tech function {func} skipped: Configs.freeMode is not available");
return;
}
@@ -819,7 +819,7 @@ namespace CheatEnabler.Patches.Tech
if (Configs.freeMode == null || history.gameData == null || player?.mecha == null ||
player.package?.grids == null || player.deliveryPackage?.grids == null)
{
TechLog.Warn("downgrade skipped: game data is not ready");
CheatEnabler.Logger.LogWarning("[TechTweaks] downgrade skipped: game data is not ready");
return false;
}
@@ -836,7 +836,7 @@ namespace CheatEnabler.Patches.Tech
int func = proto.UnlockFunctions[j];
if (!(func is >= 1 and <= 45 or >= 61 and <= 86 or 99))
{
TechLog.Warn($"downgrade skipped: unsupported tech function {func} in tech {proto.ID}");
CheatEnabler.Logger.LogWarning($"[TechTweaks] downgrade skipped: unsupported tech function {func} in tech {proto.ID}");
UIRealtimeTip.Popup(Localization.TechDowngradeUnsupportedFunction.Translate());
return false;
}
-59
View File
@@ -1,59 +0,0 @@
namespace CheatEnabler.Patches.Tech;
/// <summary>
/// The key-modifier semantics shared by the upgrade and the downgrade side.
///
/// Both directions use the same modifier mapping:
///
/// <list type="table">
/// <item><term>Shift</term><description>+1 / -1</description></item>
/// <item><term>Ctrl</term><description>+10 / -10</description></item>
/// <item><term>Ctrl + Shift</term><description>+100 / -100</description></item>
/// <item><term>Alt</term><description>to MAX / back to locked</description></item>
/// <item><term>Shift + Alt, Ctrl + Alt</term><description>ignored</description></item>
/// </list>
/// </summary>
internal static class TechKeyCombo
{
/// <summary>Sentinel for the "Alt" combination: apply or revert everything this click can.</summary>
public const int LevelToMax = int.MaxValue;
/// <summary>
/// Decodes the currently held modifiers.
/// Returns false when the combination carries no meaning and the click must be left alone.
/// </summary>
public static bool TryDecode(out int steps)
{
steps = 0;
if (VFInput.shift)
{
if (VFInput.alt)
{
return false;
}
steps = VFInput.control ? 100 : 1;
return true;
}
if (VFInput.control)
{
if (VFInput.alt)
{
return false;
}
steps = 10;
return true;
}
if (VFInput.alt)
{
steps = LevelToMax;
return true;
}
return false;
}
}
-16
View File
@@ -1,16 +0,0 @@
namespace CheatEnabler.Patches.Tech;
/// <summary>
/// Single funnel for the tech unlock / downgrade feature's log output.
///
/// Only real problems are reported: a Harmony target that no longer resolves, a tech function without
/// a known inverse, or a refused package resize. Those are conditions the player or the maintainer
/// needs to know about after a game update.
/// </summary>
internal static class TechLog
{
public static void Warn(string message)
{
CheatEnabler.Logger.LogWarning("[TechTweaks] " + message);
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ internal static class TechUnlock
{
// Mirrors the built-in maxLevel argument: "to MAX" passes the default, the other combinations
// pass -(steps) so the loop advances exactly `steps` levels.
int maxLevel = steps == TechKeyCombo.LevelToMax ? 10000 : -steps;
int maxLevel = steps == int.MaxValue ? 10000 : -steps;
UnlockTechRecursive(history, techProto, maxLevel);
+5 -13
View File
@@ -12,8 +12,6 @@ namespace CheatEnabler;
public static class UIConfigWindow
{
private static RectTransform _windowTrans;
private static UIButton _resignGameBtn;
private static UIButton _clearBanBtn;
@@ -76,13 +74,12 @@ public static class UIConfigWindow
private static void CreateUI(MyConfigWindow wnd, RectTransform trans)
{
_windowTrans = trans;
// General tab
var x = 0f;
var y = 10f;
wnd.AddSplitter(trans, 10f);
wnd.AddTabGroup(trans, "Cheat Enabler", "tab-group-cheatenabler");
var tab1 = wnd.AddTab(_windowTrans, "General");
var tab1 = wnd.AddTab(trans, "General");
var cb = wnd.AddCheckBox(x, y, tab1, GamePatch.DevShortcutsEnabled, "Enable Dev Shortcuts");
x += cb.Width + 5f;
y += 6f;
@@ -107,7 +104,7 @@ public static class UIConfigWindow
y = 10f;
_resignGameBtn = wnd.AddButton(x, y, 300f, tab1, "Assign gamesave to current account", 16, "resign-game-btn", () => { GameMain.data.account = AccountData.me; });
var tab2 = wnd.AddTab(_windowTrans, "Factory");
var tab2 = wnd.AddTab(trans, "Factory");
x = 0f;
y = 10f;
wnd.AddCheckBox(x, y, tab2, FactoryPatch.ImmediateEnabled, "Finish build immediately");
@@ -170,7 +167,7 @@ public static class UIConfigWindow
wnd.AddText2(x + 32f, y, tab2, "Boost fuel power 2", 13);
// Planet Tab
var tab3 = wnd.AddTab(_windowTrans, "Planet");
var tab3 = wnd.AddTab(trans, "Planet");
x = 0f;
y = 10f;
wnd.AddCheckBox(x, y, tab3, ResourcePatch.InfiniteResourceEnabled, "Infinite Natural Resources");
@@ -207,7 +204,7 @@ public static class UIConfigWindow
GameMain.localPlanet.factory.PlanetReformRevert();
});
var tab4 = wnd.AddTab(_windowTrans, "Dyson Sphere");
var tab4 = wnd.AddTab(trans, "Dyson Sphere");
x = 0f;
y = 10f;
wnd.AddCheckBox(x, y, tab4, DysonSpherePatch.SkipBulletEnabled, "Skip bullet period");
@@ -299,7 +296,7 @@ public static class UIConfigWindow
}
}
var tab5 = wnd.AddTab(_windowTrans, "Mecha/Combat");
var tab5 = wnd.AddTab(trans, "Mecha/Combat");
x = 0f;
y = 10f;
wnd.AddCheckBox(x, y, tab5, CombatPatch.MechaInvincibleEnabled, "Mecha and Drones/Fleets invicible");
@@ -315,11 +312,6 @@ public static class UIConfigWindow
}
private static void UpdateUI()
{
UpdateButtons();
}
private static void UpdateButtons()
{
if (_resignGameBtn == null || _clearBanBtn == null) return;
var data = GameMain.data;