mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-11-19 17:05:20 +08:00
fix(compat): support DSP 0.10.35.29057
Adapt UXAssist and CheatEnabler to the new terrain workflows, view modes, receiver inventory, and mineral-depletion API. Preserve crafting shortcuts, batch buyout visibility, soil progression, and saved brush safety. Refresh game references and document compatibility changes. Release builds, static compatibility checks, behavior assertions, and diff checks pass; user testing is also confirmed.
This commit is contained in:
1 parent
367a72b375
commit
ac4210fe5d
15 files changed
+214
-131
No files matched your search
@@ -3,6 +3,11 @@
|
||||
|
||||
## Changlog
|
||||
|
||||
* Unreleased
|
||||
* Support Dyson Sphere Program 0.10.35.29057. See [compatibility analysis](../docs/GameCompatibility-0.10.35.md).
|
||||
* Restore expanded foundation brushes, Restore Terrain support, and player actions in globe view.
|
||||
* Update Ray Receiver buffers and item refunds, vein-depletion alerts, handcrafting shortcuts, and batch technology buyout controls.
|
||||
* Preserve soil progression when hiding soil-change tips and safely restore saved brush sizes when expanded brushes are disabled.
|
||||
* 1.5.9
|
||||
* `Do not render factory entities (except belts and sorters)`: Add sub-option `Hide sorters too` to also hide sorters, leaving only belts visible.
|
||||
* 1.5.8
|
||||
|
||||
@@ -351,9 +351,8 @@ public static class PlanetFunctions
|
||||
var productId = powerGen.productId;
|
||||
var productCount = (int)powerGen.productCount;
|
||||
if (productId != 0 && productCount > 0) AddReturnedItem(productId, productCount, 0, returnedItems);
|
||||
int catalystId = powerGen.catalystId;
|
||||
var catalystPointDiv = powerGen.catalystPoint / 3600;
|
||||
if (catalystId != 0 && catalystPointDiv > 0) AddReturnedItem(catalystId, catalystPointDiv, powerGen.catalystIncPoint / 3600, returnedItems);
|
||||
var catalystId = powerGen.catalystId;
|
||||
if (catalystId != 0 && powerGen.catalystCount > 0) AddReturnedItem(catalystId, powerGen.catalystCount, powerGen.catalystInc, returnedItems);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Reflection.Emit;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UXAssist.Common;
|
||||
using UXAssist.Common.Patching;
|
||||
|
||||
namespace UXAssist.Patches.Factory;
|
||||
|
||||
@@ -163,8 +164,8 @@ internal static class ArchitectModePatch
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
// Harmony transpiler: BuildAreaLimitRemoval_Transpiler
|
||||
// Target: BuildTool_Addon.CheckBuildConditions, BuildTool_Click.CheckBuildConditions, BuildTool_Dismantle.DetermineMoreChainTargets, BuildTool_Dismantle.DeterminePreviews, BuildTool_Inserter.CheckBuildConditions, BuildTool_Path.CheckBuildConditions, BuildTool_Reform.ReformAction, BuildTool_Upgrade.DetermineMoreChainTargets, BuildTool_Upgrade.DeterminePreviews
|
||||
// Fallback: None — patch will fail loudly if the target method body changes.
|
||||
// Target: BuildTool_Addon.CheckBuildConditions, BuildTool_Click.CheckBuildConditions, BuildTool_Dismantle.DetermineMoreChainTargets, BuildTool_Dismantle.DeterminePreviews, BuildTool_Inserter.CheckBuildConditions, BuildTool_Path.CheckBuildConditions, BuildTool_Reform.ExecuteBrushAction, BuildTool_Upgrade.DetermineMoreChainTargets, BuildTool_Upgrade.DeterminePreviews
|
||||
// Fallback: TranspilerGuard returns original instructions when the build-area check is not found.
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(BuildTool_Addon), nameof(BuildTool_Addon.CheckBuildConditions))]
|
||||
[HarmonyPatch(typeof(BuildTool_Click), nameof(BuildTool_Click.CheckBuildConditions))]
|
||||
@@ -172,7 +173,7 @@ internal static class ArchitectModePatch
|
||||
[HarmonyPatch(typeof(BuildTool_Dismantle), nameof(BuildTool_Dismantle.DeterminePreviews))]
|
||||
[HarmonyPatch(typeof(BuildTool_Inserter), nameof(BuildTool_Inserter.CheckBuildConditions))]
|
||||
[HarmonyPatch(typeof(BuildTool_Path), nameof(BuildTool_Path.CheckBuildConditions))]
|
||||
[HarmonyPatch(typeof(BuildTool_Reform), nameof(BuildTool_Reform.ReformAction))]
|
||||
[HarmonyPatch(typeof(BuildTool_Reform), nameof(BuildTool_Reform.ExecuteBrushAction))]
|
||||
[HarmonyPatch(typeof(BuildTool_Upgrade), nameof(BuildTool_Upgrade.DetermineMoreChainTargets))]
|
||||
[HarmonyPatch(typeof(BuildTool_Upgrade), nameof(BuildTool_Upgrade.DeterminePreviews))]
|
||||
private static IEnumerable<CodeInstruction> BuildAreaLimitRemoval_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
@@ -190,6 +191,8 @@ internal static class ArchitectModePatch
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(Mecha), nameof(Mecha.buildArea))),
|
||||
new CodeMatch(OpCodes.Mul)
|
||||
);
|
||||
if (matcher.IsInvalid)
|
||||
return matcher.Finish(instructions, UXAssist.Logger, nameof(BuildAreaLimitRemoval_Transpiler));
|
||||
matcher.Repeat(m => m.RemoveInstructions(9).InsertAndAdvance(new CodeInstruction(OpCodes.Ldc_R4, 100000000.0f)));
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
@@ -216,23 +219,40 @@ internal static class ArchitectModePatch
|
||||
|
||||
internal class LargerAreaForTerraform : PatchImpl<LargerAreaForTerraform>
|
||||
{
|
||||
// Harmony transpiler: BuildTool_Reform_ReformAction_Transpiler
|
||||
// Target: BuildTool_Reform.ReformAction
|
||||
// Fallback: None — patch will fail loudly if the target method body changes.
|
||||
[HarmonyTranspiler, HarmonyPatch(typeof(BuildTool_Reform), nameof(BuildTool_Reform.ReformAction))]
|
||||
private static IEnumerable<CodeInstruction> BuildTool_Reform_ReformAction_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
private const int MaxBrushSize = 30;
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
var reformTool = GameMain.mainPlayer?.controller?.actionBuild?.reformTool;
|
||||
if (reformTool != null)
|
||||
reformTool.brushSize = Math.Min(reformTool.brushSize, BuildTool_Reform.MAX_BRUSH_SIZE);
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(BuildTool_Reform), nameof(BuildTool_Reform.PrepareBrushPoints))]
|
||||
private static void BuildTool_Reform_PrepareBrushPoints_Prefix(BuildTool_Reform __instance)
|
||||
{
|
||||
__instance.brushSize = Math.Max(1, Math.Min(__instance.brushSize, MaxBrushSize));
|
||||
if (__instance.cursorPoints.Length < MaxBrushSize * MaxBrushSize)
|
||||
Array.Resize(ref __instance.cursorPoints, MaxBrushSize * MaxBrushSize);
|
||||
if (__instance.cursorIndices.Length < MaxBrushSize * MaxBrushSize)
|
||||
Array.Resize(ref __instance.cursorIndices, MaxBrushSize * MaxBrushSize);
|
||||
}
|
||||
|
||||
// Harmony transpiler: BuildTool_Reform_ExecuteBrushAction_Transpiler
|
||||
// Target: BuildTool_Reform.ExecuteBrushAction
|
||||
// Fallback: TranspilerGuard returns original instructions when the brush limit is not found.
|
||||
[HarmonyTranspiler, HarmonyPatch(typeof(BuildTool_Reform), nameof(BuildTool_Reform.ExecuteBrushAction))]
|
||||
private static IEnumerable<CodeInstruction> BuildTool_Reform_ExecuteBrushAction_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(BuildTool_Reform), nameof(BuildTool_Reform.brushSize))),
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4_S && ci.OperandIs(10))
|
||||
new CodeMatch(ci => ci.LoadsConstant(BuildTool_Reform.MAX_BRUSH_SIZE))
|
||||
);
|
||||
matcher.Repeat(m => m.Advance(1).SetAndAdvance(OpCodes.Ldc_I4_S, 30));
|
||||
matcher.Start().MatchForward(false,
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4_S && ci.OperandIs(10)),
|
||||
new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(BuildTool_Reform), nameof(BuildTool_Reform.brushSize)))
|
||||
);
|
||||
matcher.Repeat(m => m.SetAndAdvance(OpCodes.Ldc_I4_S, 30));
|
||||
if (matcher.IsInvalid)
|
||||
return matcher.Finish(instructions, UXAssist.Logger, nameof(BuildTool_Reform_ExecuteBrushAction_Transpiler));
|
||||
matcher.Advance(1).Set(OpCodes.Ldc_I4, MaxBrushSize);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||
using System.Reflection.Emit;
|
||||
using HarmonyLib;
|
||||
using UXAssist.Common;
|
||||
using UXAssist.Common.Patching;
|
||||
|
||||
namespace UXAssist.Patches.Factory;
|
||||
|
||||
@@ -69,26 +70,22 @@ internal static class BuildingBufferPatch
|
||||
}
|
||||
// Harmony transpiler: PowerGeneratorComponent_GameTick_Gamma_Transpiler
|
||||
// Target: PowerGeneratorComponent.GameTick_Gamma
|
||||
// Fallback: None — patch will fail loudly if the target method body changes.
|
||||
// Fallback: TranspilerGuard returns original instructions when the catalyst buffer check is not found.
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(PowerGeneratorComponent), nameof(PowerGeneratorComponent.GameTick_Gamma))]
|
||||
private static IEnumerable<CodeInstruction> PowerGeneratorComponent_GameTick_Gamma_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
/*
|
||||
* Patch:
|
||||
* bool flag3 = keyFrame && useIon && (float)this.catalystPoint < 72000f;
|
||||
* To:
|
||||
* bool flag3 = keyFrame && useIon && this.catalystPoint < 3600 * ReceiverBufferCount.Value;
|
||||
*/
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldarg_0),
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PowerGeneratorComponent), nameof(PowerGeneratorComponent.catalystPoint))),
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PowerGeneratorComponent), nameof(PowerGeneratorComponent.catalystCount))),
|
||||
new CodeMatch(OpCodes.Conv_R4),
|
||||
new CodeMatch(OpCodes.Ldc_R4, 72000f),
|
||||
new CodeMatch(OpCodes.Ldc_R4, 20f),
|
||||
new CodeMatch(OpCodes.Clt)
|
||||
);
|
||||
matcher.Advance(2).RemoveInstructions(2).Insert(new CodeInstruction(OpCodes.Ldc_I4, FactoryPatch.ReceiverBufferCount.Value * 3600));
|
||||
if (matcher.IsInvalid)
|
||||
return matcher.Finish(instructions, UXAssist.Logger, nameof(PowerGeneratorComponent_GameTick_Gamma_Transpiler));
|
||||
matcher.Advance(2).RemoveInstructions(2).Insert(new CodeInstruction(OpCodes.Ldc_I4, FactoryPatch.ReceiverBufferCount.Value));
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
// Harmony transpiler: AssemblerComponent_UpdateNeeds_Transpiler
|
||||
|
||||
@@ -138,9 +138,11 @@ internal static class VeinProtectionPatch
|
||||
{
|
||||
var venType = (int)veinPool[veinId].type;
|
||||
var pos = veinPool[veinId].pos;
|
||||
var hasMinerLostAllVeins = GameMain.preferences.mineralExhaustionAlertMode == 2 &&
|
||||
factory.factorySystem.WillMinerLoseAllVeins(veinId);
|
||||
factory.RemoveVeinWithComponents(veinId);
|
||||
factory.RecalculateVeinGroup(groupIndex);
|
||||
factory.NotifyVeinExhausted(venType, groupIndex, pos);
|
||||
factory.NotifyVeinExhausted(venType, groupIndex, pos, hasMinerLostAllVeins);
|
||||
veinCount = __instance.veinCount;
|
||||
}
|
||||
else
|
||||
@@ -242,7 +244,7 @@ internal static class VeinProtectionPatch
|
||||
factory.veinAnimPool[veinId].time = amount >= 25000 ? 0f : 1f - amount * VeinData.oilSpeedMultiplier;
|
||||
if (amount <= 2500)
|
||||
{
|
||||
factory.NotifyVeinExhausted((int)veinPool[veinId].type, groupIndex, veinPool[veinId].pos);
|
||||
factory.NotifyVeinExhausted((int)veinPool[veinId].type, groupIndex, veinPool[veinId].pos, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,16 @@ public class PersistPatch : PatchImpl<PersistPatch>
|
||||
Enable(false);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(GamePrefsData), nameof(GamePrefsData.LateRestore))]
|
||||
private static void GamePrefsData_LateRestore_Postfix(GamePrefsData __instance)
|
||||
{
|
||||
if (Factory.ArchitectModePatch.LargerAreaForTerraform.GetHarmony() != null) return;
|
||||
var reformTool = __instance.gameData?.mainPlayer?.controller?.actionBuild?.reformTool;
|
||||
if (reformTool != null)
|
||||
reformTool.brushSize = System.Math.Min(reformTool.brushSize, BuildTool_Reform.MAX_BRUSH_SIZE);
|
||||
}
|
||||
|
||||
// Check for noModifier while pressing hotkeys on build bar
|
||||
// Harmony transpiler: UIBuildMenu__OnUpdate_Transpiler
|
||||
// Target: UIBuildMenu._OnUpdate
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Reflection.Emit;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using UXAssist.Common;
|
||||
using UXAssist.Common.Patching;
|
||||
|
||||
namespace UXAssist.Patches;
|
||||
|
||||
@@ -29,21 +30,19 @@ public static class PlanetPatch
|
||||
{
|
||||
// Harmony transpiler: VFInput_UpdateGameStates_Transpiler
|
||||
// Target: VFInput.UpdateGameStates
|
||||
// Fallback: None — patch will fail loudly if the target method body changes.
|
||||
// Fallback: TranspilerGuard returns original instructions when the globe-view checks are not found.
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(VFInput), nameof(VFInput.UpdateGameStates))]
|
||||
private static IEnumerable<CodeInstruction> VFInput_UpdateGameStates_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
/* remove UIGame.viewMode != EViewMode.Globe in two places:
|
||||
* so search for:
|
||||
* ldsfld bool VFInput::viewMode
|
||||
* ldc.i4.3
|
||||
*/
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(typeof(UIGame), nameof(UIGame.viewMode))),
|
||||
new CodeMatch(OpCodes.Ldc_I4_3)
|
||||
new CodeMatch(instruction => instruction.LoadsConstant((int)EViewMode.Globe)),
|
||||
new CodeMatch(instruction => instruction.Branches(out _))
|
||||
);
|
||||
if (matcher.IsInvalid)
|
||||
return matcher.Finish(instructions, UXAssist.Logger, nameof(VFInput_UpdateGameStates_Transpiler));
|
||||
matcher.Repeat(codeMatcher =>
|
||||
{
|
||||
var labels = codeMatcher.Labels;
|
||||
@@ -54,54 +53,46 @@ public static class PlanetPatch
|
||||
}
|
||||
// Harmony transpiler: PlayerController_GetInput_Transpiler
|
||||
// Target: PlayerController.GetInput
|
||||
// Fallback: None — patch will fail loudly if the target method body changes.
|
||||
// Fallback: TranspilerGuard returns original instructions when the view-mode input limit is not found.
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(PlayerController), nameof(PlayerController.GetInput))]
|
||||
private static IEnumerable<CodeInstruction> PlayerController_GetInput_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
// replace `UIGame.viewMode >= EViewMode.Globe` with `UIGame.viewMode >= EViewMode.Starmap`
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(typeof(UIGame), nameof(UIGame.viewMode))),
|
||||
new CodeMatch(OpCodes.Ldc_I4_3)
|
||||
).Advance(1).Opcode = OpCodes.Ldc_I4_4;
|
||||
new CodeMatch(instruction => instruction.LoadsConstant((int)EViewMode.Globe))
|
||||
);
|
||||
if (matcher.IsInvalid)
|
||||
return matcher.Finish(instructions, UXAssist.Logger, nameof(PlayerController_GetInput_Transpiler));
|
||||
matcher.Advance(1).Set(OpCodes.Ldc_I4, (int)EViewMode.Starmap);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
// Harmony transpiler: PlayerAction_Rts_GameTick_Transpiler
|
||||
// Target: PlayerAction_Rts.GameTick
|
||||
// Fallback: None — patch will fail loudly if the target method body changes.
|
||||
// Fallback: TranspilerGuard returns original instructions when the camera-conflict getters are not found.
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(PlayerAction_Rts), nameof(PlayerAction_Rts.GameTick))]
|
||||
private static IEnumerable<CodeInstruction> PlayerAction_Rts_GameTick_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
var local1 = generator.DeclareLocal(typeof(bool));
|
||||
// var local1 = UIGame.viewMode == 3;
|
||||
var moveConflict = AccessTools.PropertyGetter(typeof(VFInput), nameof(VFInput.rtsMoveCameraConflict));
|
||||
var mineConflict = AccessTools.PropertyGetter(typeof(VFInput), nameof(VFInput.rtsMineCameraConflict));
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Call, AccessTools.PropertyGetter(typeof(VFInput), nameof(VFInput.rtsMoveCameraConflict))),
|
||||
new CodeMatch(OpCodes.Stloc_1)
|
||||
);
|
||||
var labels = matcher.Labels;
|
||||
matcher.Labels = [];
|
||||
matcher.InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(UIGame), nameof(UIGame.viewMode))).WithLabels(labels),
|
||||
new CodeInstruction(OpCodes.Ldc_I4_3),
|
||||
new CodeInstruction(OpCodes.Ceq),
|
||||
new CodeInstruction(OpCodes.Stloc, local1)
|
||||
);
|
||||
// Add extra condition:
|
||||
// VFInput.rtsMoveCameraConflict / VFInput.rtsMineCameraConflict `|| local1`
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(instr => instr.opcode == OpCodes.Ldloc_1 || instr.opcode == OpCodes.Ldloc_2)
|
||||
new CodeMatch(instruction => instruction.Calls(moveConflict) || instruction.Calls(mineConflict))
|
||||
);
|
||||
if (matcher.IsInvalid)
|
||||
return matcher.Finish(instructions, UXAssist.Logger, nameof(PlayerAction_Rts_GameTick_Transpiler));
|
||||
matcher.Repeat(codeMatcher =>
|
||||
{
|
||||
codeMatcher.Advance(1).InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Ldloc, local1),
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(UIGame), nameof(UIGame.viewMode))),
|
||||
new CodeInstruction(OpCodes.Ldc_I4, (int)EViewMode.Globe),
|
||||
new CodeInstruction(OpCodes.Ceq),
|
||||
new CodeInstruction(OpCodes.Or)
|
||||
);
|
||||
});
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
using BepInEx.Configuration;
|
||||
using CommonAPI.Systems;
|
||||
@@ -147,60 +148,28 @@ public class PlayerPatch : PatchImpl<PlayerPatch>
|
||||
matcher.Repeat(m => m.SetAndAdvance(OpCodes.Ldc_I4, 1000));
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
// Harmony transpiler: UIReplicatorWindow_OnPlusButtonClick_Transpiler
|
||||
// Target: UIReplicatorWindow.OnPlusButtonClick, UIReplicatorWindow.OnMinusButtonClick
|
||||
// Fallback: None — patch will fail loudly if the target method body changes.
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(UIReplicatorWindow), nameof(UIReplicatorWindow.OnPlusButtonClick))]
|
||||
[HarmonyPatch(typeof(UIReplicatorWindow), nameof(UIReplicatorWindow.OnMinusButtonClick))]
|
||||
private static IEnumerable<CodeInstruction> UIReplicatorWindow_OnPlusButtonClick_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
private static bool UIReplicatorWindow_ChangeMultiplier_Prefix(UIReplicatorWindow __instance, RecipeProto ___selectedRecipe, MethodBase __originalMethod)
|
||||
{
|
||||
var label1 = generator.DefineLabel();
|
||||
var label2 = generator.DefineLabel();
|
||||
var label3 = generator.DefineLabel();
|
||||
var label4 = generator.DefineLabel();
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldloc_0),
|
||||
new CodeMatch(OpCodes.Ldc_I4_1),
|
||||
new CodeMatch(o => o.opcode == OpCodes.Add || o.opcode == OpCodes.Sub)
|
||||
).Advance(1).RemoveInstruction().InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(VFInput), nameof(VFInput.control))),
|
||||
new CodeInstruction(OpCodes.Brfalse_S, label1),
|
||||
new CodeInstruction(OpCodes.Ldc_I4_S, 10),
|
||||
new CodeInstruction(OpCodes.Br_S, label4),
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(VFInput), nameof(VFInput.shift))).WithLabels(label1),
|
||||
new CodeInstruction(OpCodes.Brfalse_S, label2),
|
||||
new CodeInstruction(OpCodes.Ldc_I4_S, 100),
|
||||
new CodeInstruction(OpCodes.Br_S, label4),
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(VFInput), nameof(VFInput.alt))).WithLabels(label2),
|
||||
new CodeInstruction(OpCodes.Brfalse_S, label3),
|
||||
new CodeInstruction(OpCodes.Ldc_I4, 1000),
|
||||
new CodeInstruction(OpCodes.Br_S, label4),
|
||||
new CodeInstruction(OpCodes.Ldc_I4_1).WithLabels(label3)
|
||||
).Labels.Add(label4);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4_S && ci.OperandIs(10))
|
||||
);
|
||||
matcher.Repeat(m => m.SetAndAdvance(OpCodes.Ldc_I4, 1000));
|
||||
return matcher.InstructionEnumeration();
|
||||
var recipe = ___selectedRecipe;
|
||||
if (recipe == null) return false;
|
||||
var multiplier = __instance.multipliers.TryGetValue(recipe.ID, out var current) ? current : 1;
|
||||
var step = VFInput.control ? 10 : VFInput.shift ? 100 : VFInput.alt ? 1000 : 1;
|
||||
var direction = __originalMethod.Name == nameof(UIReplicatorWindow.OnPlusButtonClick) ? 1 : -1;
|
||||
__instance.multipliers[recipe.ID] = Math.Max(1, Math.Min(1000, multiplier + direction * step));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class HideTipsForSandsChanges : PatchImpl<HideTipsForSandsChanges>
|
||||
{
|
||||
// Harmony transpiler: Player_SetSandCount_Transpiler
|
||||
// Target: Player.SetSandCount
|
||||
// Fallback: None — patch will fail loudly if the target method body changes.
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(Player), nameof(Player.SetSandCount))]
|
||||
private static IEnumerable<CodeInstruction> Player_SetSandCount_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(UIGame), nameof(UIGame.OnSandCountChanged))]
|
||||
private static bool UIGame_OnSandCountChanged_Prefix()
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Call, AccessTools.PropertySetter(typeof(Player), nameof(Player.sandCount)))
|
||||
).Advance(1).Insert(new CodeInstruction(OpCodes.Ret));
|
||||
return matcher.InstructionEnumeration();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UXAssist.Common;
|
||||
using UXAssist.Common.GameConstants;
|
||||
using UXAssist.Common.Patching;
|
||||
using GameLogicProc = UXAssist.Common.GameLogic;
|
||||
|
||||
namespace UXAssist.Patches;
|
||||
@@ -265,23 +266,37 @@ public static class TechPatch
|
||||
{
|
||||
// Harmony transpiler: UITechNode_UpdateInfoDynamic_Transpiler
|
||||
// Target: UITechNode.UpdateInfoDynamic
|
||||
// Fallback: None — patch will fail loudly if the target method body changes.
|
||||
// Fallback: TranspilerGuard returns original instructions when the buyout visibility expression is not found.
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UITechNode), nameof(UITechNode.UpdateInfoDynamic))]
|
||||
private static IEnumerable<CodeInstruction> UITechNode_UpdateInfoDynamic_Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(typeof(UITechTree), nameof(UITechTree.showProperty))),
|
||||
new CodeMatch(ci => ci.IsLdloc()),
|
||||
new CodeMatch(OpCodes.And)
|
||||
).Advance(1).SetAndAdvance(OpCodes.Ldloc_3, null).InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Ldc_I4_0),
|
||||
new CodeInstruction(OpCodes.Ceq)
|
||||
new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(typeof(UITechTree), nameof(UITechTree.showProperty)))
|
||||
);
|
||||
if (matcher.IsInvalid)
|
||||
return matcher.Finish(instructions, UXAssist.Logger, nameof(UITechNode_UpdateInfoDynamic_Transpiler));
|
||||
var start = matcher.Pos;
|
||||
var labels = matcher.Labels.ToArray();
|
||||
matcher.MatchForward(false, new CodeMatch(instruction => instruction.IsStloc()));
|
||||
if (matcher.IsInvalid)
|
||||
return matcher.Finish(instructions, UXAssist.Logger, nameof(UITechNode_UpdateInfoDynamic_Transpiler));
|
||||
var count = matcher.Pos - start;
|
||||
matcher.Start().Advance(start).RemoveInstructions(count).Insert(
|
||||
new CodeInstruction(OpCodes.Ldarg_0).WithLabels(labels),
|
||||
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(UITechNode), nameof(UITechNode.techProto))),
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(BatchBuyoutTech), nameof(CanShowBuyoutButton)))
|
||||
);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
private static bool CanShowBuyoutButton(TechProto techProto)
|
||||
{
|
||||
return UITechTree.showProperty && !GameMain.sandboxToolsEnabled &&
|
||||
!techProto.IsHiddenTech && !techProto.IsObsolete && !GameMain.history.TechUnlocked(techProto.ID);
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(UITechNode), nameof(UITechNode.OnBuyoutButtonClick))]
|
||||
private static bool UITechNode_OnBuyoutButtonClick_Prefix(UITechNode __instance)
|
||||
|
||||
Reference in new issue
Block a user