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

+24 -7
View File
@@ -209,22 +209,32 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
[HarmonyPatch(typeof(WarningSystem), nameof(WarningSystem.hasCriticalWarning), MethodType.Getter)]
private static IEnumerable<CodeInstruction> WarningSystem_hasCriticalWarning_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
// The original body is `criticalWarnings.Count > 0`. The chain appended here ORs the feature
// switches on top of it, in display priority order: whichever one matches first owns the banner,
// because UpdateCriticalWarningText bails out before assigning any custom text when this getter is
// false. Tech downgrade mode therefore has to come first: it must show on its own, without either
// build toggle being on.
var matcher = new CodeMatcher(instructions, generator);
var label1 = generator.DefineLabel();
var label2 = generator.DefineLabel();
var downgrade = generator.DefineLabel();
var noCondition = generator.DefineLabel();
var noCollision = generator.DefineLabel();
matcher.End().MatchBack(false,
new CodeMatch(OpCodes.Ret)
).RemoveInstructions(1);
matcher.InsertAndAdvance(
new CodeInstruction(OpCodes.Brfalse, label1),
new CodeInstruction(OpCodes.Brfalse, downgrade),
new CodeInstruction(OpCodes.Ldc_I4_1),
new CodeInstruction(OpCodes.Ret),
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(FactoryPatch), nameof(NoConditionEnabled))).WithLabels(label1),
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(Tech.DowngradeMode), nameof(Tech.DowngradeMode.IsOn))).WithLabels(downgrade),
new CodeInstruction(OpCodes.Brfalse, noCondition),
new CodeInstruction(OpCodes.Ldc_I4_1),
new CodeInstruction(OpCodes.Ret),
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(FactoryPatch), nameof(NoConditionEnabled))).WithLabels(noCondition),
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(ConfigEntry<bool>), nameof(ConfigEntry<bool>.Value))),
new CodeInstruction(OpCodes.Brfalse, label2),
new CodeInstruction(OpCodes.Brfalse, noCollision),
new CodeInstruction(OpCodes.Ldc_I4_1),
new CodeInstruction(OpCodes.Ret),
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(FactoryPatch), nameof(NoCollisionEnabled))).WithLabels(label2),
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(FactoryPatch), nameof(NoCollisionEnabled))).WithLabels(noCollision),
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(ConfigEntry<bool>), nameof(ConfigEntry<bool>.Value))),
new CodeInstruction(OpCodes.Ret)
);
@@ -250,7 +260,14 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
new CodeInstruction(OpCodes.Ldarg_0),
Transpilers.EmitDelegate((WarningSystem w) =>
{
if (NoConditionEnabled.Value)
// Only one of these can own the banner, so they form a display priority chain:
// tech downgrade mode (a transient state the player has to notice) outranks the
// two build toggles the player turned on deliberately.
if (Tech.DowngradeMode.IsOn)
{
w.criticalWarningTexts = Localization.TechDowngradeModeWarning.Translate() + "\r\n";
}
else if (NoConditionEnabled.Value)
{
w.criticalWarningTexts = Localization.BuildWithoutConditionIsEnabled.Translate() + "\r\n";
}