mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 00:53:39 +08:00
refactoring UXAssist and CheatEnabler
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace UXAssist;
|
||||
|
||||
public static class AuxilaryfunctionWrapper
|
||||
{
|
||||
private const string AuxilaryfunctionGuid = "cn.blacksnipe.dsp.Auxilaryfunction";
|
||||
public static ConfigEntry<bool> ShowStationInfo;
|
||||
|
||||
public static void Init(Harmony harmony)
|
||||
{
|
||||
if (!BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue(AuxilaryfunctionGuid, out var pluginInfo)) return;
|
||||
var assembly = pluginInfo.Instance.GetType().Assembly;
|
||||
try
|
||||
{
|
||||
var classType = assembly.GetType("Auxilaryfunction.Auxilaryfunction");
|
||||
ShowStationInfo = (ConfigEntry<bool>)AccessTools.Field(classType, "ShowStationInfo").GetValue(pluginInfo.Instance);
|
||||
}
|
||||
catch
|
||||
{
|
||||
UXAssist.Logger.LogWarning("Failed to get ShowStationInfo from Auxilaryfunction");
|
||||
}
|
||||
}
|
||||
}
|
||||
33
UXAssist/Common/PatchImpl.cs
Normal file
33
UXAssist/Common/PatchImpl.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using HarmonyLib;
|
||||
|
||||
namespace UXAssist.Common;
|
||||
|
||||
public class PatchImpl<T> where T : new()
|
||||
{
|
||||
private static T Instance { get; } = new();
|
||||
|
||||
private Harmony _patch;
|
||||
|
||||
public static void Enable(bool enable)
|
||||
{
|
||||
if (Instance is not PatchImpl<T> thisInstance)
|
||||
{
|
||||
UXAssist.Logger.LogError($"PatchImpl<{typeof(T).Name}> is not inherited correctly");
|
||||
return;
|
||||
}
|
||||
if (enable)
|
||||
{
|
||||
thisInstance._patch ??= Harmony.CreateAndPatchAll(typeof(T));
|
||||
thisInstance.OnEnable();
|
||||
return;
|
||||
}
|
||||
thisInstance.OnDisable();
|
||||
thisInstance._patch?.UnpatchSelf();
|
||||
thisInstance._patch = null;
|
||||
}
|
||||
|
||||
protected static Harmony GetPatch() => (Instance as PatchImpl<T>)?._patch;
|
||||
|
||||
protected virtual void OnEnable() { }
|
||||
protected virtual void OnDisable() { }
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -6,6 +8,11 @@ namespace UXAssist.Common;
|
||||
|
||||
public static class Util
|
||||
{
|
||||
public static Type[] GetTypesInNamespace(Assembly assembly, string nameSpace)
|
||||
{
|
||||
return assembly.GetTypes().Where(t => string.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray();
|
||||
}
|
||||
|
||||
public static byte[] LoadEmbeddedResource(string path, Assembly assembly = null)
|
||||
{
|
||||
if (assembly == null)
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Threading;
|
||||
using BepInEx.Configuration;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UXAssist;
|
||||
namespace UXAssist.Functions;
|
||||
|
||||
public static class PlanetFunctions
|
||||
{
|
||||
49
UXAssist/ModsCompat/AuxilaryfunctionWrapper.cs
Normal file
49
UXAssist/ModsCompat/AuxilaryfunctionWrapper.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using UXAssist.Patches;
|
||||
|
||||
namespace UXAssist.ModsCompat;
|
||||
|
||||
public static class AuxilaryfunctionWrapper
|
||||
{
|
||||
private const string AuxilaryfunctionGuid = "cn.blacksnipe.dsp.Auxilaryfunction";
|
||||
public static ConfigEntry<bool> ShowStationInfo;
|
||||
|
||||
public static void Init(Harmony harmony)
|
||||
{
|
||||
if (!BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue(AuxilaryfunctionGuid, out var pluginInfo)) return;
|
||||
var assembly = pluginInfo.Instance.GetType().Assembly;
|
||||
try
|
||||
{
|
||||
var classType = assembly.GetType("Auxilaryfunction.Auxilaryfunction");
|
||||
ShowStationInfo = (ConfigEntry<bool>)AccessTools.Field(classType, "ShowStationInfo").GetValue(pluginInfo.Instance);
|
||||
}
|
||||
catch
|
||||
{
|
||||
UXAssist.Logger.LogWarning("Failed to get ShowStationInfo from Auxilaryfunction");
|
||||
}
|
||||
try
|
||||
{
|
||||
var classType = assembly.GetType("Auxilaryfunction.Patch.SpeedUpPatch");
|
||||
harmony.Patch(AccessTools.PropertySetter(classType, "Enable"),
|
||||
new HarmonyMethod(AccessTools.Method(typeof(AuxilaryfunctionWrapper), nameof(PatchSpeedUpPatchEnable))));
|
||||
}
|
||||
catch
|
||||
{
|
||||
UXAssist.Logger.LogWarning("Failed to patch SpeedUpPatch.set_Enable() from Auxilaryfunction");
|
||||
}
|
||||
}
|
||||
|
||||
public static void PatchSpeedUpPatchEnable(bool value)
|
||||
{
|
||||
if (!value)
|
||||
{
|
||||
GamePatch.EnableGameUpsFactor = true;
|
||||
return;
|
||||
}
|
||||
if (Math.Abs(GamePatch.GameUpsFactor.Value - 1.0) < 0.001) return;
|
||||
GamePatch.EnableGameUpsFactor = false;
|
||||
UXAssist.Logger.LogInfo("Game UPS changing is disabled when using Auxilaryfunction's speed up feature");
|
||||
}
|
||||
}
|
||||
52
UXAssist/ModsCompat/BulletTimeWrapper.cs
Normal file
52
UXAssist/ModsCompat/BulletTimeWrapper.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Emit;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace UXAssist.ModsCompat;
|
||||
|
||||
public static class BulletTimeWrapper
|
||||
{
|
||||
private const string BulletTimeGuid = "com.starfi5h.plugin.BulletTime";
|
||||
public static bool HasBulletTime;
|
||||
|
||||
public static void Init(Harmony harmony)
|
||||
{
|
||||
HasBulletTime = BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue(BulletTimeGuid, out var pluginInfo);
|
||||
if (!HasBulletTime) return;
|
||||
var assembly = pluginInfo.Instance.GetType().Assembly;
|
||||
try
|
||||
{
|
||||
var classType = assembly.GetType("BulletTime.IngameUI");
|
||||
harmony.Patch(AccessTools.Method(classType, "Init"),
|
||||
null, null, new HarmonyMethod(AccessTools.Method(typeof(BulletTimeWrapper), nameof(IngameUI_Init_Transpiler))));
|
||||
harmony.Patch(AccessTools.Method(classType, "OnSpeedButtonClick"),
|
||||
null, null, new HarmonyMethod(AccessTools.Method(typeof(BulletTimeWrapper), nameof(IngameUI_OnSpeedButtonClick_Transpiler))));
|
||||
}
|
||||
catch
|
||||
{
|
||||
UXAssist.Logger.LogWarning("Failed to patch BulletTime functions()");
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<CodeInstruction> IngameUI_Init_Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldstr, "Increase game speed (max 4x)")
|
||||
).Set(OpCodes.Ldstr, "Increase game speed (max 10x)");
|
||||
UXAssist.Logger.LogDebug($"Patched IngameUI.Init @ {matcher.Pos}");
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
private static IEnumerable<CodeInstruction> IngameUI_OnSpeedButtonClick_Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldc_R8, 240.0)
|
||||
).Set(OpCodes.Ldc_R8, 600.0);
|
||||
UXAssist.Logger.LogDebug($"Patched IngameUI.OnSpeedButtonClick @ {matcher.Pos}");
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using UXAssist.Common;
|
||||
|
||||
namespace UXAssist;
|
||||
namespace UXAssist.Patches;
|
||||
|
||||
public static class DysonSpherePatch
|
||||
{
|
||||
@@ -286,30 +286,24 @@ public static class DysonSpherePatch
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
private static class StopEjectOnNodeComplete
|
||||
private class StopEjectOnNodeComplete: PatchImpl<StopEjectOnNodeComplete>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
private static HashSet<int>[] _nodeForAbsorb;
|
||||
private static bool _initialized;
|
||||
|
||||
public static void Enable(bool on)
|
||||
protected override void OnEnable()
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
InitNodeForAbsorb();
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(StopEjectOnNodeComplete));
|
||||
GameLogic.OnGameBegin += GameMain_Begin_Postfix;
|
||||
GameLogic.OnGameEnd += GameMain_End_Postfix;
|
||||
}
|
||||
else
|
||||
{
|
||||
GameLogic.OnGameEnd -= GameMain_End_Postfix;
|
||||
GameLogic.OnGameBegin -= GameMain_Begin_Postfix;
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
_initialized = false;
|
||||
_nodeForAbsorb = null;
|
||||
}
|
||||
InitNodeForAbsorb();
|
||||
GameLogic.OnGameBegin += GameMain_Begin_Postfix;
|
||||
GameLogic.OnGameEnd += GameMain_End_Postfix;
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
GameLogic.OnGameEnd -= GameMain_End_Postfix;
|
||||
GameLogic.OnGameBegin -= GameMain_Begin_Postfix;
|
||||
_initialized = false;
|
||||
_nodeForAbsorb = null;
|
||||
}
|
||||
|
||||
private static void InitNodeForAbsorb()
|
||||
@@ -506,22 +500,10 @@ public static class DysonSpherePatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class OnlyConstructNodes
|
||||
private class OnlyConstructNodes: PatchImpl<OnlyConstructNodes>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool on)
|
||||
protected override void OnEnable()
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(OnlyConstructNodes));
|
||||
}
|
||||
else
|
||||
{
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
var spheres = GameMain.data?.dysonSpheres;
|
||||
if (spheres == null) return;
|
||||
foreach (var sphere in spheres)
|
||||
@@ -10,7 +10,7 @@ using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UXAssist.Common;
|
||||
|
||||
namespace UXAssist;
|
||||
namespace UXAssist.Patches;
|
||||
|
||||
public static class FactoryPatch
|
||||
{
|
||||
@@ -162,9 +162,8 @@ public static class FactoryPatch
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
public static class NightLight
|
||||
public class NightLight: PatchImpl<NightLight>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
private const float NightLightAngleX = -8;
|
||||
private const float NightLightAngleY = -2;
|
||||
public static bool Enabled;
|
||||
@@ -173,25 +172,21 @@ public static class FactoryPatch
|
||||
private static AnimationState _sail;
|
||||
private static Light _sunlight;
|
||||
|
||||
public static void Enable(bool on)
|
||||
protected override void OnEnable()
|
||||
{
|
||||
Enabled = _mechaOnEarth;
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
Enabled = _mechaOnEarth;
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(NightLight));
|
||||
return;
|
||||
}
|
||||
|
||||
Enabled = false;
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
if (_sunlight == null) return;
|
||||
_sunlight.transform.localEulerAngles = new Vector3(0f, 180f);
|
||||
}
|
||||
|
||||
public static void LateUpdate()
|
||||
{
|
||||
if (_patch == null) return;
|
||||
if (!Enabled) return;
|
||||
|
||||
switch (_nightlightInitialized)
|
||||
{
|
||||
@@ -281,7 +276,7 @@ public static class FactoryPatch
|
||||
new CodeMatch(OpCodes.Ldarg_0),
|
||||
new CodeMatch(OpCodes.Call, AccessTools.PropertyGetter(typeof(Component), nameof(Component.transform)))
|
||||
).InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(NightLight), nameof(NightLight.Enabled))),
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(NightLight), nameof(Enabled))),
|
||||
new CodeInstruction(OpCodes.Brfalse_S, label1),
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(GameMain), nameof(GameMain.mainPlayer))),
|
||||
new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(Player), nameof(Player.transform))),
|
||||
@@ -307,7 +302,7 @@ public static class FactoryPatch
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Stloc_1)
|
||||
).Advance(1).InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(NightLight), nameof(NightLight.Enabled))),
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(NightLight), nameof(Enabled))),
|
||||
new CodeInstruction(OpCodes.Brfalse_S, label1),
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(GameMain), nameof(GameMain.mainPlayer))),
|
||||
new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(Player), nameof(Player.transform))),
|
||||
@@ -323,22 +318,8 @@ public static class FactoryPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class UnlimitInteractive
|
||||
private class UnlimitInteractive: PatchImpl<UnlimitInteractive>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(UnlimitInteractive));
|
||||
return;
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(PlayerAction_Inspect), nameof(PlayerAction_Inspect.GetObjectSelectDistance))]
|
||||
private static IEnumerable<CodeInstruction> PlayerAction_Inspect_GetObjectSelectDistance_Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||
@@ -348,22 +329,8 @@ public static class FactoryPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveSomeConditionBuild
|
||||
private class RemoveSomeConditionBuild: PatchImpl<RemoveSomeConditionBuild>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool on)
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(RemoveSomeConditionBuild));
|
||||
return;
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
[HarmonyTranspiler, HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(BuildTool_BlueprintPaste), nameof(BuildTool_BlueprintPaste.CheckBuildConditions))]
|
||||
[HarmonyPatch(typeof(BuildTool_Click), nameof(BuildTool_Click.CheckBuildConditions))]
|
||||
@@ -459,26 +426,14 @@ public static class FactoryPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveBuildRangeLimit
|
||||
private class RemoveBuildRangeLimit: PatchImpl<RemoveBuildRangeLimit>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool enable)
|
||||
protected override void OnEnable()
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(RemoveBuildRangeLimit));
|
||||
}
|
||||
else
|
||||
{
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
var controller = GameMain.mainPlayer?.controller;
|
||||
if (controller == null) return;
|
||||
controller.actionBuild?.clickTool?._OnInit();
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(BuildTool_Click), nameof(BuildTool_Click._OnInit))]
|
||||
@@ -522,22 +477,8 @@ public static class FactoryPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class LargerAreaForUpgradeAndDismantle
|
||||
private class LargerAreaForUpgradeAndDismantle: PatchImpl<LargerAreaForUpgradeAndDismantle>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(LargerAreaForUpgradeAndDismantle));
|
||||
return;
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(BuildTool_Dismantle), nameof(BuildTool_Dismantle.DeterminePreviews))]
|
||||
[HarmonyPatch(typeof(BuildTool_Upgrade), nameof(BuildTool_Upgrade.DeterminePreviews))]
|
||||
@@ -552,22 +493,8 @@ public static class FactoryPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class LargerAreaForTerraform
|
||||
private class LargerAreaForTerraform: PatchImpl<LargerAreaForTerraform>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(LargerAreaForTerraform));
|
||||
return;
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
[HarmonyTranspiler, HarmonyPatch(typeof(BuildTool_Reform), nameof(BuildTool_Reform.ReformAction))]
|
||||
private static IEnumerable<CodeInstruction> BuildTool_Reform_ReformAction_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
@@ -586,23 +513,10 @@ public static class FactoryPatch
|
||||
}
|
||||
}
|
||||
|
||||
public static class OffGridBuilding
|
||||
public class OffGridBuilding: PatchImpl<OffGridBuilding>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
private const float SteppedRotationDegrees = 15f;
|
||||
|
||||
public static void Enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(OffGridBuilding));
|
||||
return;
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
private static bool _initialized;
|
||||
|
||||
[HarmonyPostfix, HarmonyPatch(typeof(UIRoot), "_OnOpen")]
|
||||
@@ -784,8 +698,8 @@ public static class FactoryPatch
|
||||
var jmp0 = generator.DefineLabel();
|
||||
var jmp1 = generator.DefineLabel();
|
||||
matcher.InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(VFInput), nameof(VFInput._switchModelStyle))),
|
||||
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(VFInput.InputValue), nameof(VFInput.InputValue.pressing))),
|
||||
new CodeInstruction(OpCodes.Ldc_I4, (int)KeyCode.LeftControl),
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Input), nameof(Input.GetKeyInt))),
|
||||
new CodeInstruction(OpCodes.Brfalse, jmp0),
|
||||
new CodeInstruction(OpCodes.Ldarg_0),
|
||||
new CodeInstruction(OpCodes.Ldarg_0),
|
||||
@@ -836,7 +750,7 @@ public static class FactoryPatch
|
||||
matcher.InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Brfalse, existingEntryLabel),
|
||||
new CodeInstruction(OpCodes.Ldarg_0),
|
||||
CodeInstruction.Call(typeof(OffGridBuilding), nameof(OffGridBuilding.RotateStepped)),
|
||||
CodeInstruction.Call(typeof(OffGridBuilding), nameof(RotateStepped)),
|
||||
new CodeInstruction(OpCodes.Br, ifBlockExitLabel)
|
||||
);
|
||||
|
||||
@@ -861,22 +775,8 @@ public static class FactoryPatch
|
||||
}
|
||||
}
|
||||
|
||||
public static class TreatStackingAsSingle
|
||||
public class TreatStackingAsSingle: PatchImpl<TreatStackingAsSingle>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(TreatStackingAsSingle));
|
||||
return;
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(MonitorComponent), nameof(MonitorComponent.InternalUpdate))]
|
||||
private static IEnumerable<CodeInstruction> MonitorComponent_InternalUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
@@ -896,22 +796,8 @@ public static class FactoryPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class QuickBuildAndDismantleLab
|
||||
private class QuickBuildAndDismantleLab: PatchImpl<QuickBuildAndDismantleLab>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(QuickBuildAndDismantleLab));
|
||||
return;
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
private static bool DetermineMoreLabsForDismantle(BuildTool dismantle, int id)
|
||||
{
|
||||
if (!VFInput._chainReaction) return true;
|
||||
@@ -1056,25 +942,11 @@ public static class FactoryPatch
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProtectVeinsFromExhaustion
|
||||
public class ProtectVeinsFromExhaustion: PatchImpl<ProtectVeinsFromExhaustion>
|
||||
{
|
||||
public static int KeepVeinAmount = 100;
|
||||
public static float KeepOilSpeed = 1f;
|
||||
private static int _keepOilAmount = Math.Max((int)(KeepOilSpeed / 0.00004f + 0.5f), 2500);
|
||||
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(ProtectVeinsFromExhaustion));
|
||||
return;
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
private static readonly int KeepOilAmount = Math.Max((int)(KeepOilSpeed / 0.00004f + 0.5f), 2500);
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(MinerComponent), nameof(MinerComponent.InternalUpdate))]
|
||||
@@ -1243,10 +1115,10 @@ public static class FactoryPatch
|
||||
__instance.productId = veinPool[veinId].productId;
|
||||
times = __instance.time / __instance.period;
|
||||
var outputCount = 0;
|
||||
if (miningRate > 0f && amount > _keepOilAmount)
|
||||
if (miningRate > 0f && amount > KeepOilAmount)
|
||||
{
|
||||
var usedCount = 0;
|
||||
var maxAllowed = amount - _keepOilAmount;
|
||||
var maxAllowed = amount - KeepOilAmount;
|
||||
for (var j = 0; j < times; j++)
|
||||
{
|
||||
__instance.seed = (uint)((__instance.seed % 2147483646U + 1U) * 48271UL % 2147483647UL) - 1U;
|
||||
@@ -1272,7 +1144,7 @@ public static class FactoryPatch
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (_keepOilAmount <= 2500)
|
||||
else if (KeepOilAmount <= 2500)
|
||||
{
|
||||
outputCount = times;
|
||||
}
|
||||
@@ -1350,22 +1222,8 @@ public static class FactoryPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class DoNotRenderEntities
|
||||
private class DoNotRenderEntities: PatchImpl<DoNotRenderEntities>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(DoNotRenderEntities));
|
||||
return;
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(ObjectRenderer), nameof(ObjectRenderer.Render))]
|
||||
[HarmonyPatch(typeof(DynamicRenderer), nameof(DynamicRenderer.Render))]
|
||||
@@ -1422,29 +1280,24 @@ public static class FactoryPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class DragBuildPowerPoles
|
||||
private class DragBuildPowerPoles: PatchImpl<DragBuildPowerPoles>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
private static readonly List<bool> OldDragBuild = [];
|
||||
private static readonly List<Vector2> OldDragBuildDist = [];
|
||||
private static readonly int[] PowerPoleIds = [2201, 2202, 2212];
|
||||
|
||||
public static void Enable(bool enable)
|
||||
protected override void OnEnable()
|
||||
{
|
||||
GameLogic.OnGameBegin += GameMain_Begin_Postfix;
|
||||
GameLogic.OnGameEnd += GameMain_End_Postfix;
|
||||
FixProto();
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(DragBuildPowerPoles));
|
||||
GameLogic.OnGameBegin += GameMain_Begin_Postfix;
|
||||
GameLogic.OnGameEnd += GameMain_End_Postfix;
|
||||
FixProto();
|
||||
return;
|
||||
}
|
||||
|
||||
UnfixProto();
|
||||
GameLogic.OnGameEnd -= GameMain_End_Postfix;
|
||||
GameLogic.OnGameBegin -= GameMain_Begin_Postfix;
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
private static bool IsPowerPole(int id)
|
||||
@@ -1471,7 +1324,7 @@ public static class FactoryPatch
|
||||
|
||||
private static void UnfixProto()
|
||||
{
|
||||
if (_patch == null || OldDragBuild.Count < 3 || DSPGame.IsMenuDemo) return;
|
||||
if (GetPatch() == null || OldDragBuild.Count < 3 || DSPGame.IsMenuDemo) return;
|
||||
var i = 0;
|
||||
foreach (var id in PowerPoleIds)
|
||||
{
|
||||
@@ -1593,10 +1446,8 @@ public static class FactoryPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class BeltSignalsForBuyOut
|
||||
private class BeltSignalsForBuyOut: PatchImpl<BeltSignalsForBuyOut>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
private static Harmony _persistPatch;
|
||||
private static bool _initialized;
|
||||
private static bool _loaded;
|
||||
private static long _clusterSeedKey;
|
||||
@@ -1608,30 +1459,12 @@ public static class FactoryPatch
|
||||
|
||||
public static void InitPersist()
|
||||
{
|
||||
AddBeltSignalProtos();
|
||||
_persistPatch = Harmony.CreateAndPatchAll(typeof(Persist));
|
||||
GameLogic.OnDataLoaded += Persist.VFPreload_InvokeOnLoadWorkEnded_Postfix;
|
||||
GameLogic.OnGameBegin += Persist.GameMain_Begin_Postfix;
|
||||
Persist.Enable(true);
|
||||
}
|
||||
|
||||
public static void UninitPersist()
|
||||
{
|
||||
GameLogic.OnGameBegin -= Persist.GameMain_Begin_Postfix;
|
||||
GameLogic.OnDataLoaded -= Persist.VFPreload_InvokeOnLoadWorkEnded_Postfix;
|
||||
_persistPatch?.UnpatchSelf();
|
||||
_persistPatch = null;
|
||||
}
|
||||
|
||||
public static void Enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(BeltSignalsForBuyOut));
|
||||
return;
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
Persist.Enable(false);
|
||||
}
|
||||
|
||||
private static void AddBeltSignalProtos()
|
||||
@@ -1801,13 +1634,26 @@ public static class FactoryPatch
|
||||
SignalBeltFactoryIndices.Remove(factory);
|
||||
}
|
||||
|
||||
private static class Persist
|
||||
private class Persist: PatchImpl<Persist>
|
||||
{
|
||||
protected override void OnEnable()
|
||||
{
|
||||
AddBeltSignalProtos();
|
||||
GameLogic.OnDataLoaded += VFPreload_InvokeOnLoadWorkEnded_Postfix;
|
||||
GameLogic.OnGameBegin += GameMain_Begin_Postfix;
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
GameLogic.OnGameBegin -= GameMain_Begin_Postfix;
|
||||
GameLogic.OnDataLoaded -= VFPreload_InvokeOnLoadWorkEnded_Postfix;
|
||||
}
|
||||
|
||||
public static void VFPreload_InvokeOnLoadWorkEnded_Postfix()
|
||||
{
|
||||
if (BeltSignalsForBuyOut._initialized) return;
|
||||
BeltSignalsForBuyOut._initialized = true;
|
||||
BeltSignalsForBuyOut.AddBeltSignalProtos();
|
||||
if (_initialized) return;
|
||||
_initialized = true;
|
||||
AddBeltSignalProtos();
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
@@ -7,7 +7,7 @@ using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UXAssist.Common;
|
||||
|
||||
namespace UXAssist;
|
||||
namespace UXAssist.Patches;
|
||||
|
||||
public static class GamePatch
|
||||
{
|
||||
@@ -24,6 +24,32 @@ public static class GamePatch
|
||||
public static ConfigEntry<Vector4> LastWindowRect;
|
||||
public static ConfigEntry<bool> ProfileBasedSaveFolderEnabled;
|
||||
public static ConfigEntry<string> DefaultProfileName;
|
||||
public static ConfigEntry<double> GameUpsFactor;
|
||||
|
||||
private static bool _enableGameUpsFactor = true;
|
||||
public static bool EnableGameUpsFactor
|
||||
{
|
||||
get => _enableGameUpsFactor;
|
||||
set
|
||||
{
|
||||
_enableGameUpsFactor = value;
|
||||
if (value)
|
||||
{
|
||||
var oldFixUps = FPSController.instance.fixUPS;
|
||||
if (oldFixUps <= 1.0)
|
||||
{
|
||||
GameUpsFactor.Value = 1.0;
|
||||
return;
|
||||
}
|
||||
GameUpsFactor.Value = Maths.Clamp(FPSController.instance.fixUPS / GameMain.tickPerSec, 0.1, 10.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameUpsFactor.Value = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Harmony _gamePatch;
|
||||
|
||||
public static void Init()
|
||||
@@ -55,21 +81,27 @@ public static class GamePatch
|
||||
LoadLastWindowRectEnabled.SettingChanged += (_, _) => LoadLastWindowRect.Enable(LoadLastWindowRectEnabled.Value);
|
||||
MouseCursorScaleUpMultiplier.SettingChanged += (_, _) =>
|
||||
{
|
||||
MouseCursorScaleUp.Enable(MouseCursorScaleUpMultiplier.Value > 1, true);
|
||||
MouseCursorScaleUp.reload = true;
|
||||
MouseCursorScaleUp.Enable(MouseCursorScaleUpMultiplier.Value > 1);
|
||||
};
|
||||
// AutoSaveOptEnabled.SettingChanged += (_, _) => AutoSaveOpt.Enable(AutoSaveOptEnabled.Value);
|
||||
ConvertSavesFromPeaceEnabled.SettingChanged += (_, _) => ConvertSavesFromPeace.Enable(ConvertSavesFromPeaceEnabled.Value);
|
||||
ProfileBasedSaveFolderEnabled.SettingChanged += (_, _) =>
|
||||
ProfileBasedSaveFolderEnabled.SettingChanged += (_, _) => RefreshSavePath();
|
||||
DefaultProfileName.SettingChanged += (_, _) => RefreshSavePath();
|
||||
GameUpsFactor.SettingChanged += (_, _) =>
|
||||
{
|
||||
RefreshSavePath();
|
||||
};
|
||||
DefaultProfileName.SettingChanged += (_, _) =>
|
||||
{
|
||||
RefreshSavePath();
|
||||
if (!EnableGameUpsFactor || GameUpsFactor.Value == 0.0) return;
|
||||
if (Math.Abs(GameUpsFactor.Value - 1.0) < 0.001)
|
||||
{
|
||||
FPSController.SetFixUPS(0.0);
|
||||
return;
|
||||
}
|
||||
FPSController.SetFixUPS(GameMain.tickPerSec * GameUpsFactor.Value);
|
||||
};
|
||||
EnableWindowResize.Enable(EnableWindowResizeEnabled.Value);
|
||||
LoadLastWindowRect.Enable(LoadLastWindowRectEnabled.Value);
|
||||
MouseCursorScaleUp.Enable(MouseCursorScaleUpMultiplier.Value > 1, false);
|
||||
MouseCursorScaleUp.reload = false;
|
||||
MouseCursorScaleUp.Enable(MouseCursorScaleUpMultiplier.Value > 1);
|
||||
// AutoSaveOpt.Enable(AutoSaveOptEnabled.Value);
|
||||
ConvertSavesFromPeace.Enable(ConvertSavesFromPeaceEnabled.Value);
|
||||
_gamePatch ??= Harmony.CreateAndPatchAll(typeof(GamePatch));
|
||||
@@ -79,7 +111,8 @@ public static class GamePatch
|
||||
{
|
||||
LoadLastWindowRect.Enable(false);
|
||||
EnableWindowResize.Enable(false);
|
||||
MouseCursorScaleUp.Enable(false, false);
|
||||
MouseCursorScaleUp.reload = false;
|
||||
MouseCursorScaleUp.Enable(false);
|
||||
// AutoSaveOpt.Enable(false);
|
||||
ConvertSavesFromPeace.Enable(false);
|
||||
_gamePatch?.UnpatchSelf();
|
||||
@@ -121,28 +154,36 @@ public static class GamePatch
|
||||
LastWindowRect.Value = new Vector4(rect.Left, rect.Top, Screen.width, Screen.height);
|
||||
}
|
||||
|
||||
private static class EnableWindowResize
|
||||
private class EnableWindowResize: PatchImpl<EnableWindowResize>
|
||||
{
|
||||
|
||||
private static bool _enabled;
|
||||
private static Harmony _patch;
|
||||
public static void Enable(bool on)
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
var wnd = WinApi.FindWindow(GameWindowClass, _gameWindowTitle);
|
||||
if (wnd == IntPtr.Zero) return;
|
||||
_enabled = on;
|
||||
if (on)
|
||||
if (wnd == IntPtr.Zero)
|
||||
{
|
||||
WinApi.SetWindowLong(wnd, (int)WindowLongFlags.GWL_STYLE,
|
||||
WinApi.GetWindowLong(wnd, (int)WindowLongFlags.GWL_STYLE) | (int)WindowStyles.WS_THICKFRAME | (int)WindowStyles.WS_MAXIMIZEBOX);
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(EnableWindowResize));
|
||||
Enable(false);
|
||||
return;
|
||||
}
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
|
||||
_enabled = true;
|
||||
WinApi.SetWindowLong(wnd, (int)WindowLongFlags.GWL_STYLE,
|
||||
WinApi.GetWindowLong(wnd, (int)WindowLongFlags.GWL_STYLE) | (int)WindowStyles.WS_THICKFRAME | (int)WindowStyles.WS_MAXIMIZEBOX);
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
var wnd = WinApi.FindWindow(GameWindowClass, _gameWindowTitle);
|
||||
if (wnd == IntPtr.Zero)
|
||||
return;
|
||||
|
||||
_enabled = false;
|
||||
WinApi.SetWindowLong(wnd, (int)WindowLongFlags.GWL_STYLE,
|
||||
WinApi.GetWindowLong(wnd, (int)WindowLongFlags.GWL_STYLE) & ~((int)WindowStyles.WS_THICKFRAME | (int)WindowStyles.WS_MAXIMIZEBOX));
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(UIOptionWindow), nameof(UIOptionWindow.ApplyOptions))]
|
||||
private static void UIOptionWindow_ApplyOptions_Postfix()
|
||||
@@ -158,67 +199,64 @@ public static class GamePatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class LoadLastWindowRect
|
||||
private class LoadLastWindowRect: PatchImpl<LoadLastWindowRect>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
private static bool _loaded;
|
||||
public static void Enable(bool on)
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
if (on)
|
||||
GameLogic.OnDataLoaded += VFPreload_InvokeOnLoadWorkEnded_Postfix;
|
||||
if (Screen.fullScreenMode is not (FullScreenMode.ExclusiveFullScreen or FullScreenMode.FullScreenWindow or FullScreenMode.MaximizedWindow))
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(LoadLastWindowRect));
|
||||
GameLogic.OnDataLoaded += VFPreload_InvokeOnLoadWorkEnded_Postfix;
|
||||
if (Screen.fullScreenMode is not (FullScreenMode.ExclusiveFullScreen or FullScreenMode.FullScreenWindow or FullScreenMode.MaximizedWindow))
|
||||
var rect = LastWindowRect.Value;
|
||||
var x = Mathf.RoundToInt(rect.x);
|
||||
var y = Mathf.RoundToInt(rect.y);
|
||||
var w = Mathf.RoundToInt(rect.z);
|
||||
var h = Mathf.RoundToInt(rect.w);
|
||||
var needFix = false;
|
||||
if (w < 100)
|
||||
{
|
||||
var rect = LastWindowRect.Value;
|
||||
var x = Mathf.RoundToInt(rect.x);
|
||||
var y = Mathf.RoundToInt(rect.y);
|
||||
var w = Mathf.RoundToInt(rect.z);
|
||||
var h = Mathf.RoundToInt(rect.w);
|
||||
var needFix = false;
|
||||
if (w < 100)
|
||||
{
|
||||
w = 1280;
|
||||
needFix = true;
|
||||
}
|
||||
if (h < 100)
|
||||
{
|
||||
h = 720;
|
||||
needFix = true;
|
||||
}
|
||||
var sw = Screen.currentResolution.width;
|
||||
var sh = Screen.currentResolution.height;
|
||||
if (x + w > sw)
|
||||
{
|
||||
x = sw - w;
|
||||
needFix = true;
|
||||
}
|
||||
if (y + h > sh)
|
||||
{
|
||||
y = sh - h;
|
||||
needFix = true;
|
||||
}
|
||||
if (x < 0)
|
||||
{
|
||||
x = 0;
|
||||
needFix = true;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
y = 0;
|
||||
needFix = true;
|
||||
}
|
||||
if (needFix)
|
||||
{
|
||||
LastWindowRect.Value = new Vector4(x, y, w, h);
|
||||
}
|
||||
w = 1280;
|
||||
needFix = true;
|
||||
}
|
||||
if (h < 100)
|
||||
{
|
||||
h = 720;
|
||||
needFix = true;
|
||||
}
|
||||
var sw = Screen.currentResolution.width;
|
||||
var sh = Screen.currentResolution.height;
|
||||
if (x + w > sw)
|
||||
{
|
||||
x = sw - w;
|
||||
needFix = true;
|
||||
}
|
||||
if (y + h > sh)
|
||||
{
|
||||
y = sh - h;
|
||||
needFix = true;
|
||||
}
|
||||
if (x < 0)
|
||||
{
|
||||
x = 0;
|
||||
needFix = true;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
y = 0;
|
||||
needFix = true;
|
||||
}
|
||||
if (needFix)
|
||||
{
|
||||
LastWindowRect.Value = new Vector4(x, y, w, h);
|
||||
}
|
||||
MoveWindowPosition();
|
||||
return;
|
||||
}
|
||||
MoveWindowPosition();
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
GameLogic.OnDataLoaded -= VFPreload_InvokeOnLoadWorkEnded_Postfix;
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
private static void MoveWindowPosition()
|
||||
@@ -447,20 +485,9 @@ public static class GamePatch
|
||||
}
|
||||
*/
|
||||
|
||||
private static class ConvertSavesFromPeace
|
||||
private class ConvertSavesFromPeace: PatchImpl<ConvertSavesFromPeace>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
private static bool _needConvert;
|
||||
public static void Enable(bool on)
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(ConvertSavesFromPeace));
|
||||
return;
|
||||
}
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(GameDesc), nameof(GameDesc.Import))]
|
||||
@@ -496,24 +523,20 @@ public static class GamePatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class MouseCursorScaleUp
|
||||
private class MouseCursorScaleUp: PatchImpl<MouseCursorScaleUp>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
public static bool reload;
|
||||
|
||||
public static void Enable(bool on, bool reload)
|
||||
protected override void OnEnable()
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(MouseCursorScaleUp));
|
||||
if (!reload) return;
|
||||
if (!UICursor.loaded) return;
|
||||
UICursor.loaded = false;
|
||||
UICursor.LoadCursors();
|
||||
return;
|
||||
}
|
||||
if (!reload) return;
|
||||
if (!UICursor.loaded) return;
|
||||
UICursor.loaded = false;
|
||||
UICursor.LoadCursors();
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
protected override void OnDisable()
|
||||
{
|
||||
if (!reload) return;
|
||||
if (!UICursor.loaded) return;
|
||||
UICursor.loaded = false;
|
||||
@@ -10,7 +10,7 @@ using UnityEngine.Serialization;
|
||||
using UnityEngine.UI;
|
||||
using UXAssist.Common;
|
||||
|
||||
namespace UXAssist;
|
||||
namespace UXAssist.Patches;
|
||||
|
||||
public static class LogisticsPatch
|
||||
{
|
||||
@@ -61,22 +61,8 @@ public static class LogisticsPatch
|
||||
}
|
||||
}
|
||||
|
||||
public static class LogisticsCapacityTweaks
|
||||
public class LogisticsCapacityTweaks: PatchImpl<LogisticsCapacityTweaks>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(LogisticsCapacityTweaks));
|
||||
return;
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
private static KeyCode _lastKey = KeyCode.None;
|
||||
private static long _nextKeyTick;
|
||||
private static bool _skipNextEvent;
|
||||
@@ -263,22 +249,8 @@ public static class LogisticsPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class AllowOverflowInLogistics
|
||||
private class AllowOverflowInLogistics: PatchImpl<AllowOverflowInLogistics>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(AllowOverflowInLogistics));
|
||||
return;
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
// Do not check for overflow when try to send hand items into storages
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIStationStorage), nameof(UIStationStorage.OnItemIconMouseDown))]
|
||||
@@ -329,22 +301,8 @@ public static class LogisticsPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class LogisticsConstrolPanelImprovement
|
||||
private class LogisticsConstrolPanelImprovement: PatchImpl<LogisticsConstrolPanelImprovement>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(LogisticsConstrolPanelImprovement));
|
||||
return;
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
private static int ItemIdHintUnderMouse()
|
||||
{
|
||||
List<RaycastResult> targets = [];
|
||||
@@ -2,8 +2,9 @@
|
||||
using System.Reflection.Emit;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using UXAssist.Common;
|
||||
|
||||
namespace UXAssist;
|
||||
namespace UXAssist.Patches;
|
||||
public static class PlanetPatch
|
||||
{
|
||||
public static ConfigEntry<bool> PlayerActionsInGlobeViewEnabled;
|
||||
@@ -19,21 +20,8 @@ public static class PlanetPatch
|
||||
PlayerActionsInGlobeView.Enable(false);
|
||||
}
|
||||
|
||||
public static class PlayerActionsInGlobeView
|
||||
public class PlayerActionsInGlobeView: PatchImpl<PlayerActionsInGlobeView>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool on)
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(PlayerActionsInGlobeView));
|
||||
return;
|
||||
}
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(VFInput), nameof(VFInput.UpdateGameStates))]
|
||||
private static IEnumerable<CodeInstruction> VFInput_UpdateGameStates_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
@@ -6,7 +6,7 @@ using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UXAssist.Common;
|
||||
|
||||
namespace UXAssist;
|
||||
namespace UXAssist.Patches;
|
||||
|
||||
public static class PlayerPatch
|
||||
{
|
||||
@@ -52,23 +52,8 @@ public static class PlayerPatch
|
||||
AutoNavigation.Enable(false);
|
||||
}
|
||||
|
||||
private static class EnhancedMechaForgeCountControl
|
||||
private class EnhancedMechaForgeCountControl: PatchImpl<EnhancedMechaForgeCountControl>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool on)
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(EnhancedMechaForgeCountControl));
|
||||
}
|
||||
else
|
||||
{
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIReplicatorWindow), nameof(UIReplicatorWindow.OnOkButtonClick))]
|
||||
private static IEnumerable<CodeInstruction> UIReplicatorWindow_OnOkButtonClick_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
@@ -118,23 +103,8 @@ public static class PlayerPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class HideTipsForSandsChanges
|
||||
private class HideTipsForSandsChanges: PatchImpl<HideTipsForSandsChanges>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool on)
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(HideTipsForSandsChanges));
|
||||
}
|
||||
else
|
||||
{
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(Player), nameof(Player.SetSandCount))]
|
||||
private static IEnumerable<CodeInstruction> Player_SetSandCount_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
@@ -147,27 +117,12 @@ public static class PlayerPatch
|
||||
}
|
||||
}
|
||||
|
||||
public static class AutoNavigation
|
||||
public class AutoNavigation: PatchImpl<AutoNavigation>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
private static bool _canUseWarper;
|
||||
private static int _indicatorAstroId;
|
||||
private static bool _speedUp;
|
||||
private static Vector3 _direction;
|
||||
|
||||
public static void Enable(bool on)
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(AutoNavigation));
|
||||
}
|
||||
else
|
||||
{
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ToggleAutoCruise()
|
||||
{
|
||||
@@ -6,7 +6,7 @@ using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UXAssist.Common;
|
||||
|
||||
namespace UXAssist;
|
||||
namespace UXAssist.Patches;
|
||||
|
||||
public static class TechPatch
|
||||
{
|
||||
@@ -28,23 +28,20 @@ public static class TechPatch
|
||||
SorterCargoStacking.Enable(false);
|
||||
}
|
||||
|
||||
private static class SorterCargoStacking
|
||||
private class SorterCargoStacking: PatchImpl<SorterCargoStacking>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
private static bool _protoPatched;
|
||||
|
||||
public static void Enable(bool on)
|
||||
protected override void OnEnable()
|
||||
{
|
||||
TryPatchProto(true);
|
||||
GameLogic.OnDataLoaded += VFPreload_InvokeOnLoadWorkEnded_Postfix;
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
TryPatchProto(on);
|
||||
if (on)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(SorterCargoStacking));
|
||||
GameLogic.OnDataLoaded += VFPreload_InvokeOnLoadWorkEnded_Postfix;
|
||||
return;
|
||||
}
|
||||
GameLogic.OnDataLoaded -= VFPreload_InvokeOnLoadWorkEnded_Postfix;
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
TryPatchProto(false);
|
||||
}
|
||||
|
||||
private static void TryPatchProto(bool on)
|
||||
@@ -113,22 +110,8 @@ public static class TechPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static class BatchBuyoutTech
|
||||
private class BatchBuyoutTech: PatchImpl<BatchBuyoutTech>
|
||||
{
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Enable(bool on)
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(BatchBuyoutTech));
|
||||
return;
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
private static void GenerateTechList(GameHistoryData history, int techId, List<int> techIdList)
|
||||
{
|
||||
var techProto = LDB.techs.Select(techId);
|
||||
@@ -225,6 +225,7 @@ public class MyWindow : ManualBehaviour
|
||||
{
|
||||
var index = OnConfigValueChanged(config);
|
||||
slider.Value = index;
|
||||
slider.SetLabelText(valueMapper.FormatValue(format, config.Value));
|
||||
};
|
||||
slider.OnValueChanged += () =>
|
||||
{
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using UnityEngine;
|
||||
using UXAssist.UI;
|
||||
using UXAssist.Common;
|
||||
using UXAssist.Functions;
|
||||
using UXAssist.Patches;
|
||||
|
||||
namespace UXAssist;
|
||||
|
||||
@@ -30,6 +32,8 @@ public static class UIConfigWindow
|
||||
I18N.Add("Profile-based save folder tips", "Save files are stored in 'Save\\<ProfileName>' folder.\nWill use original save location if matching default profile name",
|
||||
"存档文件会存储在'Save\\<ProfileName>'文件夹中\n如果匹配默认配置档案名则使用原始存档位置");
|
||||
I18N.Add("Default profile name", "Default profile name", "默认配置档案名");
|
||||
I18N.Add("Logical Frame Rate", "Logical Frame Rate", "逻辑帧倍率");
|
||||
I18N.Add("Reset", "Reset", "重置");
|
||||
I18N.Add("Unlimited interactive range", "Unlimited interactive range", "无限交互距离");
|
||||
I18N.Add("Night Light", "Sunlight at night", "夜间日光灯");
|
||||
I18N.Add("Remove some build conditions", "Remove some build conditions", "移除部分不影响游戏逻辑的建造条件");
|
||||
@@ -108,6 +112,14 @@ public static class UIConfigWindow
|
||||
public override int ValueToIndex(double value) => Mathf.RoundToInt((float)(value * 2.0));
|
||||
}
|
||||
|
||||
private class UpsMapper : MyWindow.ValueMapper<double>
|
||||
{
|
||||
public override int Min => 1;
|
||||
public override int Max => 100;
|
||||
public override double IndexToValue(int index) => index * 0.1;
|
||||
public override int ValueToIndex(double value) => Mathf.RoundToInt((float)(value * 10.0));
|
||||
}
|
||||
|
||||
private static void CreateUI(MyConfigWindow wnd, RectTransform trans)
|
||||
{
|
||||
MyCheckBox checkBoxForMeasureTipsPos;
|
||||
@@ -121,9 +133,9 @@ public static class UIConfigWindow
|
||||
y += 36f;
|
||||
wnd.AddCheckBox(x, y, tab1, GamePatch.LoadLastWindowRectEnabled, "Remeber window position and size on last exit");
|
||||
y += 36f;
|
||||
var txt = wnd.AddText2(x, y, tab1, "Scale up mouse cursor", 15, "text-scale-up-mouse-cursor");
|
||||
var txt = wnd.AddText2(x + 2f, y, tab1, "Scale up mouse cursor", 15, "text-scale-up-mouse-cursor");
|
||||
x += txt.preferredWidth + 5f;
|
||||
wnd.AddSlider(x, y + 6f, tab1, GamePatch.MouseCursorScaleUpMultiplier, [1, 2, 3, 4], "0x", 100f);
|
||||
wnd.AddSlider(x + 2f, y + 6f, tab1, GamePatch.MouseCursorScaleUpMultiplier, [1, 2, 3, 4], "0x", 100f);
|
||||
x = 0f;
|
||||
/*
|
||||
y += 30f;
|
||||
@@ -147,6 +159,17 @@ public static class UIConfigWindow
|
||||
wnd.AddText2(x, y, tab1, "Default profile name", 15, "text-default-profile-name");
|
||||
y += 24f;
|
||||
wnd.AddInputField(x, y, 200f, tab1, GamePatch.DefaultProfileName, 15, "input-profile-save-folder");
|
||||
y += 18f;
|
||||
}
|
||||
|
||||
if (!ModsCompat.BulletTimeWrapper.HasBulletTime)
|
||||
{
|
||||
y += 36f;
|
||||
txt = wnd.AddText2(x + 2f, y, tab1, "Logical Frame Rate", 15, "game-frame-rate");
|
||||
x += txt.preferredWidth + 5f;
|
||||
wnd.AddSlider(x + 2f, y + 6f, tab1, GamePatch.GameUpsFactor, new UpsMapper(), "0.0x", 200f);
|
||||
var btn = wnd.AddFlatButton(x + 204f, y + 6f, tab1, "Reset", 13, "reset-game-frame-rate", () => GamePatch.GameUpsFactor.Value = 1.0f);
|
||||
((RectTransform)btn.transform).sizeDelta = new Vector2(40f, 20f);
|
||||
}
|
||||
|
||||
var tab2 = wnd.AddTab(trans, "Planet/Factory");
|
||||
@@ -212,13 +235,11 @@ public static class UIConfigWindow
|
||||
y += 36f;
|
||||
var cb0 = wnd.AddCheckBox(x, y, tab2, LogisticsPatch.RealtimeLogisticsInfoPanelEnabled, "Real-time logistic stations info panel");
|
||||
var cb1 = wnd.AddCheckBox(x + 26f, y + 26f, tab2, LogisticsPatch.RealtimeLogisticsInfoPanelBarsEnabled, "Show status bars for storage items", 13);
|
||||
if (AuxilaryfunctionWrapper.ShowStationInfo != null)
|
||||
if (ModsCompat.AuxilaryfunctionWrapper.ShowStationInfo != null)
|
||||
{
|
||||
AuxilaryfunctionWrapper.ShowStationInfo.SettingChanged += (_, _) => { OnAuxilaryInfoPanelChanged(); };
|
||||
ModsCompat.AuxilaryfunctionWrapper.ShowStationInfo.SettingChanged += (_, _) => { OnAuxilaryInfoPanelChanged(); };
|
||||
}
|
||||
LogisticsPatch.RealtimeLogisticsInfoPanelEnabled.SettingChanged += (_, _) => { OnRealtimeLogisticsInfoPanelChanged(); };
|
||||
OnAuxilaryInfoPanelChanged();
|
||||
OnRealtimeLogisticsInfoPanelChanged();
|
||||
|
||||
var tab3 = wnd.AddTab(trans, "Player/Mecha");
|
||||
x = 0f;
|
||||
@@ -324,13 +345,13 @@ public static class UIConfigWindow
|
||||
|
||||
void OnAuxilaryInfoPanelChanged()
|
||||
{
|
||||
if (AuxilaryfunctionWrapper.ShowStationInfo == null)
|
||||
if (ModsCompat.AuxilaryfunctionWrapper.ShowStationInfo == null)
|
||||
{
|
||||
cb0.gameObject.SetActive(true);
|
||||
cb1.gameObject.SetActive(true);
|
||||
return;
|
||||
}
|
||||
var on = !AuxilaryfunctionWrapper.ShowStationInfo.Value;
|
||||
var on = !ModsCompat.AuxilaryfunctionWrapper.ShowStationInfo.Value;
|
||||
cb0.gameObject.SetActive(on);
|
||||
cb1.gameObject.SetActive(on);
|
||||
if (!on)
|
||||
@@ -338,12 +359,6 @@ public static class UIConfigWindow
|
||||
LogisticsPatch.RealtimeLogisticsInfoPanelEnabled.Value = false;
|
||||
}
|
||||
}
|
||||
|
||||
void OnRealtimeLogisticsInfoPanelChanged()
|
||||
{
|
||||
var on = LogisticsPatch.RealtimeLogisticsInfoPanelEnabled.Value;
|
||||
cb1.gameObject.SetActive(on);
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateUI()
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using CommonAPI;
|
||||
using CommonAPI.Systems;
|
||||
using crecheng.DSPModSave;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UXAssist.Common;
|
||||
using UXAssist.Functions;
|
||||
using UXAssist.Patches;
|
||||
using UXAssist.UI;
|
||||
using crecheng.DSPModSave;
|
||||
|
||||
namespace UXAssist;
|
||||
|
||||
@@ -30,6 +33,7 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
private static Harmony _persistPatch;
|
||||
private static bool _initialized;
|
||||
private static PressKeyBind _toggleKey;
|
||||
private static ConfigFile _dummyConfig;
|
||||
|
||||
#region IModCanSave
|
||||
private const ushort ModSaveVersion = 1;
|
||||
@@ -54,6 +58,10 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_dummyConfig = new ConfigFile(Path.Combine(Paths.ConfigPath, PluginInfo.PLUGIN_GUID + "_dummy.cfg"), false)
|
||||
{
|
||||
SaveOnConfigSet = false
|
||||
};
|
||||
_toggleKey = KeyBindings.RegisterKeyBinding(new BuiltinKey
|
||||
{
|
||||
key = new CombineKey((int)KeyCode.BackQuote, CombineKey.ALT_COMB, ECombineKeyAction.OnceClick, false),
|
||||
@@ -79,6 +87,8 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
*/
|
||||
GamePatch.ConvertSavesFromPeaceEnabled = Config.Bind("Game", "ConvertSavesFromPeace", false,
|
||||
"Convert saves from Peace mode to Combat mode on save loading");
|
||||
GamePatch.GameUpsFactor = _dummyConfig.Bind("Game", "GameUpsFactor", 1.0,
|
||||
"Game UPS factor (1.0 for normal speed)");
|
||||
FactoryPatch.UnlimitInteractiveEnabled = Config.Bind("Factory", "UnlimitInteractive", false,
|
||||
"Unlimit interactive range");
|
||||
FactoryPatch.RemoveSomeConditionEnabled = Config.Bind("Factory", "RemoveSomeBuildConditionCheck", false,
|
||||
@@ -140,49 +150,42 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
DysonSpherePatch.OnlyConstructNodesEnabled = Config.Bind("DysonSphere", "OnlyConstructNodes", false,
|
||||
"Construct only nodes but frames");
|
||||
DysonSpherePatch.AutoConstructMultiplier = Config.Bind("DysonSphere", "AutoConstructMultiplier", 1, "Dyson Sphere auto-construct speed multiplier");
|
||||
|
||||
|
||||
I18N.Init();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
I18N.Add("UXAssist Config", "UXAssist Config", "UX助手设置");
|
||||
I18N.Add("KEYOpenUXAssistConfigWindow", "Open UXAssist Config Window", "打开UX助手设置面板");
|
||||
I18N.Add("KEYToggleAutoCruise", "Toggle auto-cruise", "切换自动巡航");
|
||||
|
||||
// UI Patch
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(UXAssist));
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(UXAssist), PluginInfo.PLUGIN_GUID);
|
||||
_persistPatch ??= Harmony.CreateAndPatchAll(typeof(Persist));
|
||||
|
||||
GameLogic.Init();
|
||||
|
||||
MyWindowManager.Init();
|
||||
UIConfigWindow.Init();
|
||||
GamePatch.Init();
|
||||
FactoryPatch.Init();
|
||||
LogisticsPatch.Init();
|
||||
PlanetPatch.Init();
|
||||
PlayerPatch.Init();
|
||||
TechPatch.Init();
|
||||
DysonSpherePatch.Init();
|
||||
|
||||
Common.Util.GetTypesInNamespace(Assembly.GetExecutingAssembly(), "UXAssist.Patches")
|
||||
.Do(type => type.GetMethod("Init")?.Invoke(null, null));
|
||||
|
||||
ModsCompat.AuxilaryfunctionWrapper.Init(_patch);
|
||||
ModsCompat.BulletTimeWrapper.Init(_patch);
|
||||
|
||||
I18N.Apply();
|
||||
I18N.OnInitialized += RecreateConfigWindow;
|
||||
GameLogic.OnDataLoaded += () =>
|
||||
{
|
||||
AuxilaryfunctionWrapper.Init(_patch);
|
||||
};
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
LogisticsPatch.Start();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
DysonSpherePatch.Uninit();
|
||||
TechPatch.Uninit();
|
||||
PlayerPatch.Uninit();
|
||||
PlanetPatch.Uninit();
|
||||
LogisticsPatch.Uninit();
|
||||
FactoryPatch.Uninit();
|
||||
GamePatch.Uninit();
|
||||
Common.Util.GetTypesInNamespace(Assembly.GetExecutingAssembly(), "UXAssist.Patches")
|
||||
.Do(type => type.GetMethod("Uninit")?.Invoke(null, null));
|
||||
|
||||
MyWindowManager.Uninit();
|
||||
|
||||
GameLogic.Uninit();
|
||||
|
||||
Reference in New Issue
Block a user