Files
DSP_Mods/CheatEnabler/Patches/Tech/TechClickHandler.cs
T
soarqin 5fb8695348 fix(cheatenabler): make tech downgrades safe and refresh docs
Validate the full dependency cascade and capacity reductions before applying tech downgrades. Preserve shared recipes, restore native bonus values and station limits, and clamp stored energy to the remaining capacity.

Fix warning integration and tech-tree help button ownership, cleanup and localization. Use the shared patch lifecycle and guarded transpilers.

Refresh bilingual feature and usage documentation, and consolidate the 2.4.7 changelog around the final user-visible behavior.
2026-10-11 03:09:47 +08:00

58 lines
1.3 KiB
C#

using System;
namespace CheatEnabler.Patches.Tech;
/// <summary>
/// Entry point injected into UITechNode.OnPointerDown, shared by upgrade and downgrade clicks.
/// </summary>
internal static class TechClickHandler
{
public static void OnClickTech(UITechNode node)
{
// The handler runs inside the game's own click path, so nothing may escape from here and break
// the tech tree UI.
try
{
HandleClick(node);
}
catch (Exception e)
{
TechLog.Warn($"click handling failed: {e}");
}
}
private static void HandleClick(UITechNode node)
{
if (node == null || TechTweaksPatch.Enabled == null || !TechTweaksPatch.Enabled.Value)
{
return;
}
TechProto techProto = node.techProto;
if (techProto == null)
{
return;
}
GameHistoryData history = GameMain.history;
if (history == null || history.techStates == null)
{
return;
}
if (!TechKeyCombo.TryDecode(out int steps))
{
return;
}
if (DowngradeMode.IsOn)
{
TechDowngrade.Run(history, techProto, steps);
}
else
{
TechUnlock.Run(history, techProto, steps);
}
}
}