feat(cheatenabler): add tech downgrade and make the tech modifiers upgradable

Rework `Unlock Tech with Key-Modifiers` into a full upgrade/downgrade feature,
ported from the standalone TechTweaks plugin.

- Holding Shift / Ctrl / Ctrl+Shift / Alt while clicking a tech adds 1 / 10 /
  100 / all levels and unlocks the direct prerequisites, as before.
- `Caps Lock` toggles a session downgrade mode; the same modifiers then
  subtract 1 / 10 / 100 levels or revert the tech to locked. Downgrading walks
  the dependent techs so no "prerequisite locked, dependent unlocked" state is
  left behind, and it reverts the upgrade values the tech had applied
  (`TechFuncRevert`), including the multiplicative, assignment and boolean
  `UnlockTechFunction` cases, so repeated up/down cycles do not drift.
- Toggling downgrade mode reports itself like the other toggles: a realtime tip
  popup plus the critical warning banner. The banner now shows on its own
  instead of requiring `Build without condition` or `No collision` to be on,
  and outranks both in the shared priority chains.
- The `?` button in the tech tree shows the full key reference, using the same
  title and text as the config panel's tip button. While the option is off, the
  button is absent and `Caps Lock` is inert, so the key cannot collide with
  other bindings.
- The option keeps its original `General/UnlockTech` config entry, so existing
  configurations carry over.

The old unlock-only handler in `Patches/GamePatch.cs` is replaced by
`Patches/TechTweaksPatch.cs`, which follows the repository's mod feature
lifecycle (per-frame input through the registry's `OnInputUpdate`).
This commit is contained in:
TTenYX authored and Soar Qin committed 2026-10-10 23:49:40 +08:00
1 parent 6a292e0816
commit 6ced106901
19 files changed
+2072 -143

No files matched your search

@@ -0,0 +1,50 @@
using UnityEngine;
namespace CheatEnabler.Patches.Tech;
/// <summary>
/// Session level downgrade mode, toggled with <c>Caps Lock</c>.
///
/// The flag is intentionally not persisted: it is a per-session switch, so a game restart always comes
/// back in the normal (upgrade) mode. The click handler reads <see cref="IsOn"/> at click time, so
/// whatever the mode is at that moment wins.
///
/// Toggling reports itself exactly like the other CheatEnabler toggles (no condition build / no
/// collision) do: a realtime tip ahead popup, plus an entry in the critical warning banner. The banner
/// entry outranks the other two so the mode cannot be missed while they are on as well.
/// </summary>
internal static class DowngradeMode
{
public static bool IsOn { get; private set; }
/// <summary>Per-frame <c>Caps Lock</c> poll; driven by the mod feature registry input hook.</summary>
public static void Update()
{
if (TechTweaksPatch.Enabled == null || !TechTweaksPatch.Enabled.Value)
{
return;
}
if (Input.GetKeyDown(KeyCode.CapsLock))
{
Toggle();
}
}
public static void Toggle()
{
IsOn = !IsOn;
if (!DSPGame.IsMenuDemo && GameMain.isRunning)
{
UIRoot.instance.uiGame.generalTips.InvokeRealtimeTipAhead(
(IsOn ? Localization.TechDowngradeModeOn : Localization.TechDowngradeModeOff).Translate());
GameMain.data?.warningSystem?.UpdateCriticalWarningText();
}
}
public static void Reset()
{
IsOn = false;
}
}