mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-06-21 08:41:10 +08:00
chore: move Increase maximum power usage in Logistic Stations and Advanced Mining Machines from CheatEnabler to UXAssist
This commit is contained in:
@@ -30,7 +30,6 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
||||
public static ConfigEntry<bool> BoostFuelPowerEnabled;
|
||||
public static ConfigEntry<bool> BoostGeothermalPowerEnabled;
|
||||
public static ConfigEntry<bool> WindTurbinesPowerGlobalCoverageEnabled;
|
||||
public static ConfigEntry<bool> GreaterPowerUsageInLogisticsEnabled;
|
||||
public static ConfigEntry<bool> ControlPanelRemoteLogisticsEnabled;
|
||||
|
||||
private static PressKeyBind _noConditionKey;
|
||||
@@ -76,7 +75,6 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
||||
BoostFuelPowerEnabled.SettingChanged += (_, _) => BoostFuelPower.Enable(BoostFuelPowerEnabled.Value);
|
||||
BoostGeothermalPowerEnabled.SettingChanged += (_, _) => BoostGeothermalPower.Enable(BoostGeothermalPowerEnabled.Value);
|
||||
WindTurbinesPowerGlobalCoverageEnabled.SettingChanged += (_, _) => WindTurbinesPowerGlobalCoverage.Enable(WindTurbinesPowerGlobalCoverageEnabled.Value);
|
||||
GreaterPowerUsageInLogisticsEnabled.SettingChanged += (_, _) => GreaterPowerUsageInLogistics.Enable(GreaterPowerUsageInLogisticsEnabled.Value);
|
||||
ControlPanelRemoteLogisticsEnabled.SettingChanged += (_, _) => ControlPanelRemoteLogistics.Enable(ControlPanelRemoteLogisticsEnabled.Value);
|
||||
}
|
||||
|
||||
@@ -92,7 +90,6 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
||||
BoostSolarPower.Enable(BoostSolarPowerEnabled.Value);
|
||||
BoostFuelPower.Enable(BoostFuelPowerEnabled.Value);
|
||||
BoostGeothermalPower.Enable(BoostGeothermalPowerEnabled.Value);
|
||||
GreaterPowerUsageInLogistics.Enable(GreaterPowerUsageInLogisticsEnabled.Value);
|
||||
ControlPanelRemoteLogistics.Enable(ControlPanelRemoteLogisticsEnabled.Value);
|
||||
Enable(true);
|
||||
CargoTrafficPatch.Enable(true);
|
||||
@@ -116,7 +113,6 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
||||
BoostFuelPower.Enable(false);
|
||||
BoostGeothermalPower.Enable(false);
|
||||
WindTurbinesPowerGlobalCoverage.Enable(false);
|
||||
GreaterPowerUsageInLogistics.Enable(false);
|
||||
ControlPanelRemoteLogistics.Enable(false);
|
||||
}
|
||||
|
||||
@@ -1681,156 +1677,6 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
||||
}
|
||||
}
|
||||
|
||||
private class GreaterPowerUsageInLogistics : PatchImpl<GreaterPowerUsageInLogistics>
|
||||
{
|
||||
protected override void OnEnable()
|
||||
{
|
||||
var window = UIRoot.instance?.uiGame?.stationWindow;
|
||||
if (window == null) return;
|
||||
window._Close();
|
||||
window.maxMiningSpeedSlider.maxValue = 27f;
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
var window = UIRoot.instance?.uiGame?.stationWindow;
|
||||
if (window == null) return;
|
||||
window._Close();
|
||||
window.maxMiningSpeedSlider.maxValue = 20f;
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIStationWindow), nameof(UIStationWindow.OnStationIdChange))]
|
||||
private static IEnumerable<CodeInstruction> UIStationWindow_OnStationIdChange_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.Start().Insert(
|
||||
new CodeInstruction(OpCodes.Ldarg_0),
|
||||
Transpilers.EmitDelegate((UIStationWindow window) =>
|
||||
{
|
||||
window.maxMiningSpeedSlider.maxValue = 27f;
|
||||
})
|
||||
).MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldarg_0),
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIStationWindow), nameof(UIStationWindow.maxChargePowerSlider))),
|
||||
new CodeMatch(ci => ci.IsLdloc()),
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(0xC350)),
|
||||
new CodeMatch(OpCodes.Conv_I8)
|
||||
);
|
||||
var pos = matcher.Pos + 1;
|
||||
matcher.Advance(5).MatchForward(false,
|
||||
new CodeMatch(OpCodes.Conv_R4),
|
||||
new CodeMatch(OpCodes.Callvirt, AccessTools.PropertySetter(typeof(Slider), nameof(Slider.value)))
|
||||
);
|
||||
var pos2 = matcher.Pos + 2;
|
||||
matcher.Start().Advance(pos);
|
||||
var ldvar = matcher.InstructionAt(1).Clone();
|
||||
var locWorkEnergyPerTick = matcher.InstructionAt(-2).operand;
|
||||
matcher.RemoveInstructions(pos2 - pos).InsertAndAdvance(
|
||||
ldvar,
|
||||
new CodeInstruction(OpCodes.Ldloc_S, locWorkEnergyPerTick),
|
||||
Transpilers.EmitDelegate((UIStationWindow window, long maxWorkEnergy, long workEnergyPerTick) =>
|
||||
{
|
||||
var maxSliderValue = maxWorkEnergy / 50000L;
|
||||
window.maxChargePowerSlider.maxValue = maxSliderValue + 9;
|
||||
window.maxChargePowerSlider.minValue = maxWorkEnergy / 500000L;
|
||||
if (workEnergyPerTick <= maxWorkEnergy)
|
||||
window.maxChargePowerSlider.Set(workEnergyPerTick / 50000L, false);
|
||||
else
|
||||
window.maxChargePowerSlider.Set(maxSliderValue + (workEnergyPerTick - 1) / maxWorkEnergy + 1, false);
|
||||
})
|
||||
);
|
||||
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldarg_0),
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIStationWindow), nameof(UIStationWindow.maxMiningSpeedSlider))),
|
||||
new CodeMatch(OpCodes.Ldarg_0),
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIStationWindow), nameof(UIStationWindow.factorySystem))),
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(FactorySystem), nameof(FactorySystem.minerPool))),
|
||||
new CodeMatch(ci => ci.IsLdloc()),
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(StationComponent), nameof(StationComponent.minerId))),
|
||||
new CodeMatch(OpCodes.Ldelema, typeof(MinerComponent)),
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(MinerComponent), nameof(MinerComponent.speed)))
|
||||
);
|
||||
pos = matcher.Pos + 9;
|
||||
matcher.Advance(5).MatchForward(false,
|
||||
new CodeMatch(OpCodes.Conv_R4),
|
||||
new CodeMatch(OpCodes.Callvirt, AccessTools.PropertySetter(typeof(Slider), nameof(Slider.value)))
|
||||
);
|
||||
pos2 = matcher.Pos;
|
||||
matcher.Start().Advance(pos).RemoveInstructions(pos2 - pos).Insert(
|
||||
Transpilers.EmitDelegate((int speed) =>
|
||||
{
|
||||
if (speed <= 30000)
|
||||
return (speed - 10000) / 1000;
|
||||
return (speed - 30000) / 10000 + 20;
|
||||
})
|
||||
);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
[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);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(10000)),
|
||||
new CodeMatch(OpCodes.Ldarg_1)
|
||||
);
|
||||
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);
|
||||
matcher.Insert(
|
||||
new CodeInstruction(OpCodes.Ldarg_1).WithLabels(labels),
|
||||
Transpilers.EmitDelegate((float value) =>
|
||||
{
|
||||
var intval = (int)(value + 0.5f);
|
||||
if (intval <= 20)
|
||||
return intval * 1000 + 10000;
|
||||
return (intval - 20) * 10000 + 30000;
|
||||
})
|
||||
);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIStationWindow), nameof(UIStationWindow.OnMaxChargePowerSliderValueChange))]
|
||||
private static IEnumerable<CodeInstruction> UIStationWindow_OnMaxChargePowerSliderValueChange_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldarg_0),
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIStationWindow), nameof(UIStationWindow.factory))),
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PlanetFactory), nameof(PlanetFactory.powerSystem))),
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PowerSystem), nameof(PowerSystem.consumerPool)))
|
||||
);
|
||||
var labels = matcher.Labels;
|
||||
matcher.Labels = null;
|
||||
matcher.Insert(
|
||||
new CodeInstruction(OpCodes.Ldarg_0).WithLabels(labels),
|
||||
new CodeInstruction(OpCodes.Ldarg_1),
|
||||
Transpilers.EmitDelegate((UIStationWindow window, float value) =>
|
||||
{
|
||||
float prevMax = window.workEnergyPrefab * 5L / 50000L;
|
||||
if (value <= prevMax)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return prevMax * (value - prevMax + 1);
|
||||
}),
|
||||
new CodeInstruction(OpCodes.Starg_S, 1)
|
||||
);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
}
|
||||
|
||||
private class ControlPanelRemoteLogistics : PatchImpl<ControlPanelRemoteLogistics>
|
||||
{
|
||||
[HarmonyTranspiler]
|
||||
|
||||
Reference in New Issue
Block a user