fix(uxassist): prevent mining speed corruption with extended power

Keep the extended mining-speed calculation integer-valued so the native handler writes a valid speed. Guard the complete native arithmetic pattern and document the slider range and recovery steps.
This commit is contained in:
soarqin committed 2026-10-13 23:17:25 +08:00
1 parent 0015c16f0c
commit a7ddb395b2
4 files changed
+35 -17

No files matched your search

+2
View File
@@ -4,6 +4,7 @@
## Changlog
* 1.6.2 - Unrelease
* `Increase maximum power usage in Logistic Stations and Advanced Mining Machines`: Fix zero or corrupted mining speeds when adjusting an Advanced Mining Machine's speed slider with the option enabled.
* `Tweak building buffers`: Restore the Ray Receiver Graviton Lens buffer setting on DSP 0.10.35.29104 and later, and correct the displayed native buffer value to 2.
* `Drag building power poles`: Fix invalid alternating previews when enabling the option after loading a save, and restore original spacing when disabling it.
* Close building and belt hover popups when opening the pause menu so they cannot obscure menu controls.
@@ -434,6 +435,7 @@
## 更新日志
* 1.6.2 - Unreleased
* `提升物流塔和大型采矿机的最大功耗`:修复启用后调整大型采矿机开采速度时出现 0% 或异常速度的问题。
* `调整建筑输入缓冲`:修复 DSP 0.10.35.29104 及后续版本中射线接收器透镜缓冲设置不生效的问题,并将显示的游戏原始值更正为 2。
* `拖建电线杆`:修复载入存档后才启用功能时交替放置的预览异常,并在关闭时恢复原有间距。
* 打开暂停菜单时关闭建筑和传送带的悬浮提示,避免提示遮挡菜单。
+23 -16
View File
@@ -8,6 +8,7 @@ using UnityEngine.EventSystems;
using UnityEngine.UI;
using UXAssist.Common;
using UXAssist.Common.GameConstants;
using UXAssist.Common.Patching;
namespace UXAssist.Patches.Logistics;
@@ -360,32 +361,38 @@ internal class GreaterPowerUsageInLogistics : PatchImpl<GreaterPowerUsageInLogis
}
// Harmony transpiler: UIStationWindow_OnMaxMiningSpeedChange_Transpiler
// Target: UIStationWindow.OnMaxMiningSpeedChange
// Fallback: None — patch will fail loudly if the target method body changes.
// Fallback: Return the original instructions if the native mining-speed calculation is not found.
[HarmonyTranspiler]
[HarmonyPatch(typeof(UIStationWindow), nameof(UIStationWindow.OnMaxMiningSpeedChange))]
private static IEnumerable<CodeInstruction> UIStationWindow_OnMaxMiningSpeedChange_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
var matcher = new CodeMatcher(instructions, generator);
var original = instructions.ToList();
var matcher = new CodeMatcher(original, generator);
matcher.MatchForward(false,
new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(LogisticsConstants.MinMiningSpeedBase)),
new CodeMatch(OpCodes.Ldarg_1)
new CodeMatch(ci => ci.LoadsConstant(LogisticsConstants.MinMiningSpeedBase)),
new CodeMatch(OpCodes.Ldarg_1),
new CodeMatch(OpCodes.Ldc_R4, 0.5f),
new CodeMatch(OpCodes.Add),
new CodeMatch(OpCodes.Conv_I4),
new CodeMatch(ci => ci.LoadsConstant(LogisticsConstants.MiningSpeedFineStep)),
new CodeMatch(OpCodes.Mul),
new CodeMatch(OpCodes.Add),
new CodeMatch(ci => ci.IsStloc())
);
var pos = matcher.Pos;
matcher.MatchForward(false,
new CodeMatch(OpCodes.Stloc_1)
);
var pos2 = matcher.Pos;
matcher.Start().Advance(pos);
var labels = matcher.Labels;
matcher.RemoveInstructions(pos2 - pos);
if (matcher.IsInvalid)
return matcher.Finish(original, UXAssist.Logger, nameof(UIStationWindow_OnMaxMiningSpeedChange_Transpiler));
var loadValue = new CodeInstruction(OpCodes.Ldarg_1).WithLabels(matcher.Labels);
loadValue.blocks.AddRange(matcher.Instruction.blocks);
matcher.RemoveInstructions(8);
matcher.Insert(
new CodeInstruction(OpCodes.Ldarg_1).WithLabels(labels),
Transpilers.EmitDelegate((float value) =>
loadValue,
Transpilers.EmitDelegate<Func<float, int>>(value =>
{
var intval = (int)(value + 0.5f);
if (intval <= LogisticsConstants.MiningSpeedSliderMaxDefault)
var defaultMax = (int)LogisticsConstants.MiningSpeedSliderMaxDefault;
if (intval <= defaultMax)
return intval * LogisticsConstants.MiningSpeedFineStep + LogisticsConstants.MinMiningSpeedBase;
return (intval - LogisticsConstants.MiningSpeedSliderMaxDefault) * LogisticsConstants.MiningSpeedCoarseStep + LogisticsConstants.MaxMiningSpeedBase;
return (intval - defaultMax) * LogisticsConstants.MiningSpeedCoarseStep + LogisticsConstants.MaxMiningSpeedBase;
})
);
return matcher.InstructionEnumeration();
+4
View File
@@ -104,6 +104,8 @@
* `Ejector Solar Sails buffer count`: Range 5-400 (step by 5); the game's original buffer holds 20
* `Silo Rockets buffer count`: Range 1-40; the game's original buffer holds 20
* Logistics
* Increase maximum power usage in Logistic Stations and Advanced Mining Machines
* Extend the Advanced Mining Machine's speed slider from 100%–300% to 100%–1,000%, retaining 10-percentage-point steps through 300% and using 100-percentage-point steps above it.
* Enhanced control for logistic storage capacities
* Logistic storage capacities are not scaled on upgrading `Logistics Carrier Capacity`, if they are not set to maximum capacity or already greater than maximum capacity.
* You can use arrow keys to adjust logistic storage capacities gracefully.
@@ -294,6 +296,8 @@
* `弹射太阳帆缓冲区数量`:范围 5 至 400(步进值为 5);游戏原始缓冲数量为 20
* `发射井火箭缓冲区数量`:范围 1 至 40;游戏原始缓冲数量为 20
* 物流
* 提升物流塔和大型采矿机的最大功耗
* 将大型采矿机开采速度滑条的范围从 100%–300% 扩展为 100%–1,000%;300% 以内每档增加 10 个百分点,之后每档增加 100 个百分点。
* 物流塔存储数量限制控制改进
* 当升级`运输机舱扩容`时,不会对各种物流塔的存储限制按比例提升,除非设置为最大允许容量或者已经超过升级后的最大容量。
* 你可以使用方向键微调物流塔存储限制