mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 04:13:32 +08:00
WIP
This commit is contained in:
@@ -92,11 +92,12 @@ public class FactoryPatch: PatchImpl<FactoryPatch>
|
||||
ControlPanelRemoteLogistics.Enable(ControlPanelRemoteLogisticsEnabled.Value);
|
||||
Enable(true);
|
||||
GameLogic.OnGameBegin += GameMain_Begin_Postfix_For_ImmBuild;
|
||||
GameLogic.OnDataLoaded += () => WindTurbinesPowerGlobalCoverage.Enable(WindTurbinesPowerGlobalCoverageEnabled.Value);
|
||||
GameLogic.OnDataLoaded += OnDataLoaded;
|
||||
}
|
||||
|
||||
public static void Uninit()
|
||||
{
|
||||
GameLogic.OnDataLoaded -= OnDataLoaded;
|
||||
GameLogic.OnGameBegin -= GameMain_Begin_Postfix_For_ImmBuild;
|
||||
Enable(false);
|
||||
ImmediateBuild.Enable(false);
|
||||
@@ -113,6 +114,8 @@ public class FactoryPatch: PatchImpl<FactoryPatch>
|
||||
ControlPanelRemoteLogistics.Enable(false);
|
||||
}
|
||||
|
||||
private static void OnDataLoaded() => WindTurbinesPowerGlobalCoverage.Enable(WindTurbinesPowerGlobalCoverageEnabled.Value);
|
||||
|
||||
public static void OnUpdate()
|
||||
{
|
||||
if (_noConditionKey.keyValue)
|
||||
|
||||
@@ -23,7 +23,8 @@ public static class WindowFunctions
|
||||
public static ConfigEntry<int> ProcessPriority;
|
||||
public static ConfigEntry<int> ProcessAffinity;
|
||||
|
||||
private static readonly int[] ProrityFlags = [
|
||||
private static readonly int[] ProrityFlags =
|
||||
[
|
||||
WinApi.HIGH_PRIORITY_CLASS,
|
||||
WinApi.ABOVE_NORMAL_PRIORITY_CLASS,
|
||||
WinApi.NORMAL_PRIORITY_CLASS,
|
||||
@@ -44,13 +45,14 @@ public static class WindowFunctions
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
GameLogic.OnDataLoaded += () => { _gameLoaded = true; };
|
||||
GameLogic.OnDataLoaded += OnDataLoaded;
|
||||
var wndProc = new WinApi.WndProc(GameWndProc);
|
||||
var gameWnd = FindGameWindow();
|
||||
if (gameWnd != IntPtr.Zero)
|
||||
{
|
||||
_oldWndProc = WinApi.SetWindowLongPtr(gameWnd, WinApi.GWLP_WNDPROC, Marshal.GetFunctionPointerForDelegate(wndProc));
|
||||
}
|
||||
|
||||
if (GamePatch.LoadLastWindowRectEnabled.Value)
|
||||
GamePatch.LoadLastWindowRect.MoveWindowPosition(true);
|
||||
|
||||
@@ -67,6 +69,7 @@ public static class WindowFunctions
|
||||
{
|
||||
systemMask = ulong.MaxValue;
|
||||
}
|
||||
|
||||
switch (ProcessAffinity.Value)
|
||||
{
|
||||
case 0:
|
||||
@@ -88,6 +91,16 @@ public static class WindowFunctions
|
||||
}
|
||||
}
|
||||
|
||||
public static void Uninit()
|
||||
{
|
||||
GameLogic.OnDataLoaded -= OnDataLoaded;
|
||||
}
|
||||
|
||||
private static void OnDataLoaded()
|
||||
{
|
||||
_gameLoaded = true;
|
||||
}
|
||||
|
||||
private static IntPtr GameWndProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
switch (uMsg)
|
||||
|
||||
@@ -31,9 +31,13 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
||||
public static ConfigEntry<bool> DragBuildPowerPolesEnabled;
|
||||
public static ConfigEntry<bool> DragBuildPowerPolesAlternatelyEnabled;
|
||||
public static ConfigEntry<bool> BeltSignalsForBuyOutEnabled;
|
||||
public static ConfigEntry<bool> TankFastFillInAndTakeOutEnabled;
|
||||
public static ConfigEntry<int> TankFastFillInAndTakeOutMultiplier;
|
||||
private static PressKeyBind _doNotRenderEntitiesKey;
|
||||
private static PressKeyBind _offgridfForPathsKey;
|
||||
|
||||
private static int _tankFastFillInAndTakeOutMultiplierRealValue = 2;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
_doNotRenderEntitiesKey = KeyBindings.RegisterKeyBinding(new BuiltinKey
|
||||
@@ -72,6 +76,8 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
||||
DragBuildPowerPolesEnabled.SettingChanged += (_, _) => DragBuildPowerPoles.Enable(DragBuildPowerPolesEnabled.Value);
|
||||
DragBuildPowerPolesAlternatelyEnabled.SettingChanged += (_, _) => DragBuildPowerPoles.AlternatelyChanged();
|
||||
BeltSignalsForBuyOutEnabled.SettingChanged += (_, _) => BeltSignalsForBuyOut.Enable(BeltSignalsForBuyOutEnabled.Value);
|
||||
TankFastFillInAndTakeOutEnabled.SettingChanged += (_, _) => TankFastFillInAndTakeOut.Enable(TankFastFillInAndTakeOutEnabled.Value);
|
||||
TankFastFillInAndTakeOutMultiplier.SettingChanged += (_, _) => { UpdateTankFastFillInAndTakeOutMultiplierRealValue(); };
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
@@ -89,30 +95,39 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
||||
DoNotRenderEntities.Enable(DoNotRenderEntitiesEnabled.Value);
|
||||
DragBuildPowerPoles.Enable(DragBuildPowerPolesEnabled.Value);
|
||||
BeltSignalsForBuyOut.Enable(BeltSignalsForBuyOutEnabled.Value);
|
||||
TankFastFillInAndTakeOut.Enable(TankFastFillInAndTakeOutEnabled.Value);
|
||||
|
||||
Enable(true);
|
||||
UpdateTankFastFillInAndTakeOutMultiplierRealValue();
|
||||
}
|
||||
|
||||
public static void Uninit()
|
||||
{
|
||||
Enable(false);
|
||||
|
||||
TankFastFillInAndTakeOut.Enable(false);
|
||||
BeltSignalsForBuyOut.Enable(false);
|
||||
DragBuildPowerPoles.Enable(false);
|
||||
DoNotRenderEntities.Enable(false);
|
||||
ProtectVeinsFromExhaustion.Enable(false);
|
||||
QuickBuildAndDismantleLab.Enable(false);
|
||||
TreatStackingAsSingle.Enable(false);
|
||||
OffGridBuilding.Enable(false);
|
||||
LargerAreaForTerraform.Enable(false);
|
||||
LargerAreaForUpgradeAndDismantle.Enable(false);
|
||||
RemoveBuildRangeLimit.Enable(false);
|
||||
NightLight.Enable(false);
|
||||
RemoveSomeConditionBuild.Enable(false);
|
||||
UnlimitInteractive.Enable(false);
|
||||
NightLight.Enable(false);
|
||||
RemoveBuildRangeLimit.Enable(false);
|
||||
LargerAreaForUpgradeAndDismantle.Enable(false);
|
||||
LargerAreaForTerraform.Enable(false);
|
||||
OffGridBuilding.Enable(false);
|
||||
TreatStackingAsSingle.Enable(false);
|
||||
QuickBuildAndDismantleLab.Enable(false);
|
||||
ProtectVeinsFromExhaustion.Enable(false);
|
||||
DoNotRenderEntities.Enable(false);
|
||||
DragBuildPowerPoles.Enable(false);
|
||||
BeltSignalsForBuyOut.Enable(false);
|
||||
|
||||
BeltSignalsForBuyOut.UninitPersist();
|
||||
}
|
||||
|
||||
private static void UpdateTankFastFillInAndTakeOutMultiplierRealValue()
|
||||
{
|
||||
_tankFastFillInAndTakeOutMultiplierRealValue = Mathf.Max(1, TankFastFillInAndTakeOutMultiplier.Value) * 2;
|
||||
}
|
||||
|
||||
public static void OnUpdate()
|
||||
{
|
||||
if (_doNotRenderEntitiesKey.keyValue)
|
||||
@@ -1757,4 +1772,75 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
}
|
||||
|
||||
private class TankFastFillInAndTakeOut : PatchImpl<TankFastFillInAndTakeOut>
|
||||
{
|
||||
private static int GetRealCount()
|
||||
{
|
||||
return _tankFastFillInAndTakeOutMultiplierRealValue;
|
||||
}
|
||||
|
||||
private static int MultiplierWithCountCheck(int count)
|
||||
{
|
||||
return Math.Min(count, _tankFastFillInAndTakeOutMultiplierRealValue);
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(PlanetFactory), nameof(PlanetFactory.EntityFastFillIn))]
|
||||
private static IEnumerable<CodeInstruction> PlanetFactory_EntityFastFillIn_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(ci => ci.IsStloc()),
|
||||
new CodeMatch(OpCodes.Ldc_I4_2),
|
||||
new CodeMatch(ci => ci.IsStloc())
|
||||
).Advance(1).RemoveInstruction().InsertAndAdvance(Transpilers.EmitDelegate(GetRealCount)).MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldc_I4_1),
|
||||
new CodeMatch(ci => ci.Branches(out _)),
|
||||
new CodeMatch(OpCodes.Ldc_I4_1),
|
||||
new CodeMatch(ci => ci.Branches(out _)),
|
||||
new CodeMatch(OpCodes.Ldc_I4_2),
|
||||
new CodeMatch(ci => ci.IsStloc())
|
||||
).RemoveInstructions(5).Insert(Transpilers.EmitDelegate(MultiplierWithCountCheck));
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(PlanetFactory), nameof(PlanetFactory.EntityFastTakeOut))]
|
||||
private static IEnumerable<CodeInstruction> PlanetFactory_EntityFastTakeOut_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(ci => ci.IsLdloc()),
|
||||
new CodeMatch(OpCodes.Ldc_I4_2),
|
||||
new CodeMatch(OpCodes.Ldc_I4_0),
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Ldloca || ci.opcode == OpCodes.Ldloca_S)
|
||||
).Advance(1).RemoveInstruction().InsertAndAdvance(Transpilers.EmitDelegate(GetRealCount)).MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldc_I4_1),
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Bgt || ci.opcode == OpCodes.Bgt_S),
|
||||
new CodeMatch(OpCodes.Ldc_I4_1),
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Br || ci.opcode == OpCodes.Br_S),
|
||||
new CodeMatch(OpCodes.Ldc_I4_2),
|
||||
new CodeMatch(ci => ci.IsLdloc())
|
||||
).RemoveInstructions(5).Insert(Transpilers.EmitDelegate(MultiplierWithCountCheck));
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UITankWindow), nameof(UITankWindow._OnUpdate))]
|
||||
private static IEnumerable<CodeInstruction> UITankWindow__OnUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldc_I4_1),
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Bgt || ci.opcode == OpCodes.Bgt_S),
|
||||
new CodeMatch(OpCodes.Ldc_I4_1),
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Br || ci.opcode == OpCodes.Br_S),
|
||||
new CodeMatch(OpCodes.Ldc_I4_2),
|
||||
new CodeMatch(ci => ci.IsStloc())
|
||||
);
|
||||
matcher.Repeat(m => m.RemoveInstructions(5).InsertAndAdvance(Transpilers.EmitDelegate(MultiplierWithCountCheck)));
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,9 +28,6 @@ public static class LogisticsPatch
|
||||
LogisticsConstrolPanelImprovementEnabled.SettingChanged += (_, _) => LogisticsConstrolPanelImprovement.Enable(LogisticsConstrolPanelImprovementEnabled.Value);
|
||||
RealtimeLogisticsInfoPanelEnabled.SettingChanged += (_, _) => RealtimeLogisticsInfoPanel.Enable(RealtimeLogisticsInfoPanelEnabled.Value);
|
||||
RealtimeLogisticsInfoPanelBarsEnabled.SettingChanged += (_, _) => RealtimeLogisticsInfoPanel.EnableBars(RealtimeLogisticsInfoPanelBarsEnabled.Value);
|
||||
|
||||
GameLogic.OnGameBegin += RealtimeLogisticsInfoPanel.OnGameBegin;
|
||||
GameLogic.OnDataLoaded += RealtimeLogisticsInfoPanel.OnDataLoaded;
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
@@ -41,6 +38,9 @@ public static class LogisticsPatch
|
||||
RealtimeLogisticsInfoPanel.Enable(RealtimeLogisticsInfoPanelEnabled.Value);
|
||||
RealtimeLogisticsInfoPanel.EnableBars(RealtimeLogisticsInfoPanelBarsEnabled.Value);
|
||||
RealtimeLogisticsInfoPanel.InitGUI();
|
||||
|
||||
GameLogic.OnGameBegin += RealtimeLogisticsInfoPanel.OnGameBegin;
|
||||
GameLogic.OnDataLoaded += RealtimeLogisticsInfoPanel.OnDataLoaded;
|
||||
}
|
||||
|
||||
public static void Uninit()
|
||||
|
||||
@@ -67,6 +67,8 @@ public static class UIConfigWindow
|
||||
I18N.Add("Enhanced count control for hand-make", "Enhanced count control for hand-make", "手动制造物品的数量控制改进");
|
||||
I18N.Add("Enhanced count control for hand-make tips", "Maximum count is increased to 1000.\nHold Ctrl/Shift/Alt to change the count rapidly.", "最大数量提升至1000\n按住Ctrl/Shift/Alt可快速改变数量");
|
||||
I18N.Add("Quick build and dismantle stacking labs", "Quick build and dismantle stacking labs/storages/tanks(hold shift)", "快速建造和拆除堆叠研究站/储物仓/储液罐(按住shift)");
|
||||
I18N.Add("Fast fill in to and take out from tanks", "Fast fill in to and take out from tanks", "储液罐快速注入和抽取液体");
|
||||
I18N.Add("Speed Ratio", "Speed Ratio", "速度倍率");
|
||||
I18N.Add("Protect veins from exhaustion", "Protect veins from exhaustion", "保护矿脉不会耗尽");
|
||||
I18N.Add("Protect veins from exhaustion tips",
|
||||
"By default, the vein amount is protected at 100, and oil speed is protected at 1.0/s, you can set them yourself in config file.\nWhen reach the protection value, veins/oils steeps will not be mined/extracted any longer.\nClose this function to resume mining and pumping, usually when you have enough level on `Veins Utilization`",
|
||||
@@ -241,6 +243,20 @@ public static class UIConfigWindow
|
||||
y += 36f;
|
||||
wnd.AddCheckBox(x, y, tab2, FactoryPatch.QuickBuildAndDismantleLabsEnabled, "Quick build and dismantle stacking labs");
|
||||
y += 36f;
|
||||
var cb = wnd.AddCheckBox(x, y, tab2, FactoryPatch.TankFastFillInAndTakeOutEnabled, "Fast fill in to and take out from tanks");
|
||||
x += cb.Width + 5f;
|
||||
txt = wnd.AddText2(x, y + 2f, tab2, "Speed Ratio", 13, "text-tank-fast-fill-speed-ratio");
|
||||
var tankSlider = wnd.AddSlider(x + txt.preferredWidth + 5f, y + 7f, tab2, FactoryPatch.TankFastFillInAndTakeOutMultiplier, [2, 5, 10, 20, 50, 100, 500, 1000], "G", 100f).WithSmallerHandle();
|
||||
EventHandler tankSettingChanged = (_, _) =>
|
||||
{
|
||||
tankSlider.SetEnable(FactoryPatch.TankFastFillInAndTakeOutEnabled.Value);
|
||||
};
|
||||
FactoryPatch.TankFastFillInAndTakeOutEnabled.SettingChanged += tankSettingChanged;
|
||||
wnd.OnFree += () => { FactoryPatch.TankFastFillInAndTakeOutEnabled.SettingChanged -= tankSettingChanged; };
|
||||
tankSettingChanged(null, null);
|
||||
|
||||
x = 0;
|
||||
y += 36f;
|
||||
checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab2, FactoryPatch.ProtectVeinsFromExhaustionEnabled, "Protect veins from exhaustion");
|
||||
wnd.AddTipsButton2(x + checkBoxForMeasureTextWidth.Width + 5f, y + 6f, tab2, "Protect veins from exhaustion", "Protect veins from exhaustion tips", "protect-veins-tips");
|
||||
y += 36f;
|
||||
|
||||
@@ -131,6 +131,9 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
"Build Tesla Tower and Wireless Power Tower alternately");
|
||||
FactoryPatch.BeltSignalsForBuyOutEnabled = Config.Bind("Factory", "BeltSignalsForBuyOut", false,
|
||||
"Belt signals for buy out dark fog items automatically");
|
||||
FactoryPatch.TankFastFillInAndTakeOutEnabled = Config.Bind("Factory", "TankFastFillInAndTakeOut", false,
|
||||
"Fast fill in to and take out from tanks");
|
||||
FactoryPatch.TankFastFillInAndTakeOutMultiplier = Config.Bind("Factory", "TankFastFillInAndTakeOutMultiplier", 1000, "Speed multiplier for fast filling in to and takeing out from tanks");
|
||||
LogisticsPatch.LogisticsCapacityTweaksEnabled = Config.Bind("Factory", "LogisticsCapacityTweaks", true,
|
||||
"Logistics capacity related tweaks");
|
||||
LogisticsPatch.AllowOverflowInLogisticsEnabled = Config.Bind("Factory", "AllowOverflowInLogistics", false,
|
||||
|
||||
Reference in New Issue
Block a user