mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 03:33:29 +08:00
WIP
This commit is contained in:
@@ -10,7 +10,7 @@ public class PatchImplGuidAttribute(string guid) : Attribute
|
||||
public string Guid { get; } = guid;
|
||||
}
|
||||
|
||||
public class PatchImpl<T> where T : new()
|
||||
public class PatchImpl<T> where T : PatchImpl<T>, new()
|
||||
{
|
||||
private static T Instance { get; } = new();
|
||||
|
||||
@@ -18,14 +18,10 @@ public class PatchImpl<T> where T : new()
|
||||
|
||||
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;
|
||||
}
|
||||
var thisInstance = Instance;
|
||||
if (enable)
|
||||
{
|
||||
var guid = typeof(T).GetCustomAttribute<PatchImplGuidAttribute>()?.Guid;
|
||||
var guid = typeof(T).GetCustomAttribute<PatchImplGuidAttribute>()?.Guid ?? $"PatchImpl.{typeof(T).FullName ?? typeof(T).ToString()}";
|
||||
thisInstance._patch ??= Harmony.CreateAndPatchAll(typeof(T), guid);
|
||||
thisInstance.OnEnable();
|
||||
return;
|
||||
@@ -35,7 +31,7 @@ public class PatchImpl<T> where T : new()
|
||||
thisInstance._patch = null;
|
||||
}
|
||||
|
||||
public static Harmony GetHarmony() => (Instance as PatchImpl<T>)?._patch;
|
||||
public static Harmony GetHarmony() => Instance._patch;
|
||||
|
||||
protected virtual void OnEnable() { }
|
||||
protected virtual void OnDisable() { }
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Reflection.Emit;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using UXAssist.Common;
|
||||
|
||||
namespace UXAssist.ModsCompat;
|
||||
|
||||
@@ -14,6 +15,7 @@ public static class BulletTimeWrapper
|
||||
{
|
||||
HasBulletTime = BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue(BulletTimeGuid, out var pluginInfo);
|
||||
if (!HasBulletTime) return;
|
||||
I18N.Add("Increase game speed (max 10x)", "Increase game speed (max 10x)", "提升游戏速度(最高10倍)");
|
||||
var assembly = pluginInfo.Instance.GetType().Assembly;
|
||||
try
|
||||
{
|
||||
|
||||
@@ -21,13 +21,17 @@ public class DysonSpherePatch: PatchImpl<DysonSpherePatch>
|
||||
Enable(true);
|
||||
StopEjectOnNodeCompleteEnabled.SettingChanged += (_, _) => StopEjectOnNodeComplete.Enable(StopEjectOnNodeCompleteEnabled.Value);
|
||||
OnlyConstructNodesEnabled.SettingChanged += (_, _) => OnlyConstructNodes.Enable(OnlyConstructNodesEnabled.Value);
|
||||
StopEjectOnNodeComplete.Enable(StopEjectOnNodeCompleteEnabled.Value);
|
||||
OnlyConstructNodes.Enable(OnlyConstructNodesEnabled.Value);
|
||||
_totalNodeSpInfo = AccessTools.Field(typeof(DysonSphereLayer), "totalNodeSP");
|
||||
_totalFrameSpInfo = AccessTools.Field(typeof(DysonSphereLayer), "totalFrameSP");
|
||||
_totalCpInfo = AccessTools.Field(typeof(DysonSphereLayer), "totalCP");
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
StopEjectOnNodeComplete.Enable(StopEjectOnNodeCompleteEnabled.Value);
|
||||
OnlyConstructNodes.Enable(OnlyConstructNodesEnabled.Value);
|
||||
}
|
||||
|
||||
public static void Uninit()
|
||||
{
|
||||
StopEjectOnNodeComplete.Enable(false);
|
||||
|
||||
@@ -55,6 +55,10 @@ public class FactoryPatch: PatchImpl<FactoryPatch>
|
||||
DoNotRenderEntitiesEnabled.SettingChanged += (_, _) => DoNotRenderEntities.Enable(DoNotRenderEntitiesEnabled.Value);
|
||||
DragBuildPowerPolesEnabled.SettingChanged += (_, _) => DragBuildPowerPoles.Enable(DragBuildPowerPolesEnabled.Value);
|
||||
BeltSignalsForBuyOutEnabled.SettingChanged += (_, _) => BeltSignalsForBuyOut.Enable(BeltSignalsForBuyOutEnabled.Value);
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
UnlimitInteractive.Enable(UnlimitInteractiveEnabled.Value);
|
||||
RemoveSomeConditionBuild.Enable(RemoveSomeConditionEnabled.Value);
|
||||
NightLight.Enable(NightLightEnabled.Value);
|
||||
|
||||
@@ -96,6 +96,10 @@ public class GamePatch: PatchImpl<GamePatch>
|
||||
}
|
||||
FPSController.SetFixUPS(GameMain.tickPerSec * GameUpsFactor.Value);
|
||||
};
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
EnableWindowResize.Enable(EnableWindowResizeEnabled.Value);
|
||||
LoadLastWindowRect.Enable(LoadLastWindowRectEnabled.Value);
|
||||
MouseCursorScaleUp.reload = false;
|
||||
|
||||
@@ -27,14 +27,19 @@ 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()
|
||||
{
|
||||
LogisticsCapacityTweaks.Enable(LogisticsCapacityTweaksEnabled.Value);
|
||||
AllowOverflowInLogistics.Enable(AllowOverflowInLogisticsEnabled.Value);
|
||||
LogisticsConstrolPanelImprovement.Enable(LogisticsConstrolPanelImprovementEnabled.Value);
|
||||
RealtimeLogisticsInfoPanel.Enable(RealtimeLogisticsInfoPanelEnabled.Value);
|
||||
RealtimeLogisticsInfoPanel.EnableBars(RealtimeLogisticsInfoPanelBarsEnabled.Value);
|
||||
|
||||
GameLogic.OnGameBegin += RealtimeLogisticsInfoPanel.OnGameBegin;
|
||||
GameLogic.OnDataLoaded += RealtimeLogisticsInfoPanel.OnDataLoaded;
|
||||
RealtimeLogisticsInfoPanel.InitGUI();
|
||||
}
|
||||
|
||||
public static void Uninit()
|
||||
@@ -48,11 +53,6 @@ public static class LogisticsPatch
|
||||
RealtimeLogisticsInfoPanel.Enable(false);
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
RealtimeLogisticsInfoPanel.InitGUI();
|
||||
}
|
||||
|
||||
public static void OnUpdate()
|
||||
{
|
||||
if (RealtimeLogisticsInfoPanelEnabled.Value)
|
||||
|
||||
201
UXAssist/Patches/PersistPatch.cs
Normal file
201
UXAssist/Patches/PersistPatch.cs
Normal file
@@ -0,0 +1,201 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Emit;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UXAssist.Common;
|
||||
|
||||
namespace UXAssist.Patches;
|
||||
|
||||
public class PersistPatch : PatchImpl<PersistPatch>
|
||||
{
|
||||
public static void Start()
|
||||
{
|
||||
Enable(true);
|
||||
}
|
||||
|
||||
public static void Uninit()
|
||||
{
|
||||
Enable(false);
|
||||
}
|
||||
|
||||
// Check for noModifier while pressing hotkeys on build bar
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIBuildMenu), nameof(UIBuildMenu._OnUpdate))]
|
||||
private static IEnumerable<CodeInstruction> UIBuildMenu__OnUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(typeof(VFInput), nameof(VFInput.inScreen)))
|
||||
);
|
||||
matcher.Repeat(codeMatcher =>
|
||||
{
|
||||
var jumpPos = codeMatcher.Advance(1).Operand;
|
||||
codeMatcher.Advance(-1).InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(VFInput), nameof(VFInput.noModifier))),
|
||||
new CodeInstruction(OpCodes.Brfalse_S, jumpPos)
|
||||
).Advance(2);
|
||||
});
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Patch to fix the issue that warning popup on VeinUtil upgraded to level 8000+
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(ABN_VeinsUtil), nameof(ABN_VeinsUtil.CheckValue))]
|
||||
private static IEnumerable<CodeInstruction> ABN_VeinsUtil_CheckValue_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldelem_R8),
|
||||
new CodeMatch(OpCodes.Conv_R4),
|
||||
new CodeMatch(OpCodes.Add),
|
||||
new CodeMatch(OpCodes.Stloc_1)
|
||||
);
|
||||
// loc1 = Mathf.Round(n * 1000f) / 1000f;
|
||||
matcher.Advance(3).Insert(
|
||||
new CodeInstruction(OpCodes.Ldc_R4, 1000f),
|
||||
new CodeInstruction(OpCodes.Mul),
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Mathf), nameof(Mathf.Round))),
|
||||
new CodeInstruction(OpCodes.Ldc_R4, 1000f),
|
||||
new CodeInstruction(OpCodes.Div)
|
||||
);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Bring popup tip window to top layer
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIButton), nameof(UIButton.LateUpdate))]
|
||||
private static IEnumerable<CodeInstruction> UIButton_LateUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldloc_2),
|
||||
new CodeMatch(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(Component), nameof(Component.gameObject))),
|
||||
new CodeMatch(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(GameObject), nameof(GameObject.activeSelf)))
|
||||
);
|
||||
var labels = matcher.Labels;
|
||||
matcher.Labels = null;
|
||||
matcher.Insert(
|
||||
new CodeInstruction(OpCodes.Ldloc_2).WithLabels(labels),
|
||||
new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(Component), nameof(Component.transform))),
|
||||
new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(Transform), nameof(Transform.parent))),
|
||||
new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(Transform), nameof(Transform.parent))),
|
||||
new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Transform), nameof(Transform.SetAsLastSibling)))
|
||||
);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Sort blueprint structures by item id, model index, recipe id, area index, and position before saving
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(BlueprintUtils), nameof(BlueprintUtils.GenerateBlueprintData))]
|
||||
private static void BlueprintUtils_GenerateBlueprintData_Postfix(BlueprintData _blueprintData)
|
||||
{
|
||||
var buildings = _blueprintData.buildings;
|
||||
Array.Sort(buildings, (a, b) =>
|
||||
{
|
||||
var tmpItemId = a.itemId - b.itemId;
|
||||
if (tmpItemId != 0)
|
||||
return tmpItemId;
|
||||
var tmpModelIndex = a.modelIndex - b.modelIndex;
|
||||
if (tmpModelIndex != 0)
|
||||
return tmpModelIndex;
|
||||
var tmpRecipeId = a.recipeId - b.recipeId;
|
||||
if (tmpRecipeId != 0)
|
||||
return tmpRecipeId;
|
||||
var tmpAreaIndex = a.areaIndex - b.areaIndex;
|
||||
if (tmpAreaIndex != 0)
|
||||
return tmpAreaIndex;
|
||||
const double ky = 256.0;
|
||||
const double kx = 1024.0;
|
||||
var scorePosA = (a.localOffset_y * ky + a.localOffset_x) * kx + a.localOffset_z;
|
||||
var scorePosB = (b.localOffset_y * ky + b.localOffset_x) * kx + b.localOffset_z;
|
||||
return scorePosA < scorePosB ? 1 : -1;
|
||||
});
|
||||
for (var i = buildings.Length - 1; i >= 0; i--)
|
||||
{
|
||||
buildings[i].index = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Increase maximum value of property realizing, 2000 -> 20000
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIPropertyEntry), nameof(UIPropertyEntry.UpdateUIElements))]
|
||||
[HarmonyPatch(typeof(UIPropertyEntry), nameof(UIPropertyEntry.OnRealizeButtonClick))]
|
||||
[HarmonyPatch(typeof(UIPropertyEntry), nameof(UIPropertyEntry.OnInputValueEnd))]
|
||||
private static IEnumerable<CodeInstruction> UIProductEntry_UpdateUIElements_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldc_I4, 2000)
|
||||
);
|
||||
matcher.Repeat(m => { m.SetAndAdvance(OpCodes.Ldc_I4, 20000); });
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIPropertyEntry), nameof(UIPropertyEntry.OnInputValueEnd))]
|
||||
private static IEnumerable<CodeInstruction> UIProductEntry_OnInputValueEnd_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Ldc_R4 && ci.OperandIs(2000f))
|
||||
);
|
||||
matcher.Repeat(m => { m.SetAndAdvance(OpCodes.Ldc_R4, 20000f); });
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Increase capacity of player order queue, 16 -> 128
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(PlayerOrder), MethodType.Constructor, typeof(Player))]
|
||||
private static IEnumerable<CodeInstruction> PlayerOrder_Constructor_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(ci => (ci.opcode == OpCodes.Ldc_I4_S || ci.opcode == OpCodes.Ldc_I4) && ci.OperandIs(16))
|
||||
);
|
||||
matcher.Repeat(m => { m.SetAndAdvance(OpCodes.Ldc_I4, 128); });
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Increase Player Command Queue from 16 to 128
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(PlayerOrder), nameof(PlayerOrder._trimEnd))]
|
||||
[HarmonyPatch(typeof(PlayerOrder), nameof(PlayerOrder.Enqueue))]
|
||||
private static IEnumerable<CodeInstruction> PlayerOrder_ExtendCount_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(ci => (ci.opcode == OpCodes.Ldc_I4_S || ci.opcode == OpCodes.Ldc_I4) && ci.OperandIs(16))
|
||||
);
|
||||
matcher.Repeat(m => { m.SetAndAdvance(OpCodes.Ldc_I4, 128); });
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Allow F11 in star map
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIGame), nameof(UIGame._OnLateUpdate))]
|
||||
private static IEnumerable<CodeInstruction> UIGame__OnLateUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(typeof(VFInput), nameof(VFInput.inFullscreenGUI))),
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Brfalse || ci.opcode == OpCodes.Brfalse_S)
|
||||
);
|
||||
var jumpPos = matcher.Advance(1).Operand;
|
||||
matcher.Advance(-1).Insert(
|
||||
new CodeInstruction(OpCodes.Ldarg_0),
|
||||
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(UIGame), nameof(UIGame.starmap))),
|
||||
new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(ManualBehaviour), nameof(ManualBehaviour.active))),
|
||||
new CodeInstruction(OpCodes.Brtrue_S, jumpPos)
|
||||
);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Ignore UIDFCommunicatorWindow.Determine()
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(UIDFCommunicatorWindow), nameof(UIDFCommunicatorWindow.Determine))]
|
||||
private static bool UIDFCommunicatorWindow_Determine_Prefix()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,10 @@ public static class PlanetPatch
|
||||
public static void Init()
|
||||
{
|
||||
PlayerActionsInGlobeViewEnabled.SettingChanged += (_, _) => PlayerActionsInGlobeView.Enable(PlayerActionsInGlobeViewEnabled.Value);
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
PlayerActionsInGlobeView.Enable(PlayerActionsInGlobeViewEnabled.Value);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,6 @@ public static class PlayerPatch
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
EnhancedMechaForgeCountControlEnabled.SettingChanged += (_, _) => EnhancedMechaForgeCountControl.Enable(EnhancedMechaForgeCountControlEnabled.Value);
|
||||
HideTipsForSandsChangesEnabled.SettingChanged += (_, _) => HideTipsForSandsChanges.Enable(HideTipsForSandsChangesEnabled.Value);
|
||||
AutoNavigationEnabled.SettingChanged += (_, _) => AutoNavigation.Enable(AutoNavigationEnabled.Value);
|
||||
EnhancedMechaForgeCountControl.Enable(EnhancedMechaForgeCountControlEnabled.Value);
|
||||
HideTipsForSandsChanges.Enable(HideTipsForSandsChangesEnabled.Value);
|
||||
AutoNavigation.Enable(AutoNavigationEnabled.Value);
|
||||
_autoDriveKey = KeyBindings.RegisterKeyBinding(new BuiltinKey
|
||||
{
|
||||
key = new CombineKey(0, 0, ECombineKeyAction.OnceClick, true),
|
||||
@@ -35,6 +29,16 @@ public static class PlayerPatch
|
||||
});
|
||||
I18N.Add("AutoCruiseOn", "Auto-cruise enabled", "已启用自动巡航");
|
||||
I18N.Add("AutoCruiseOff", "Auto-cruise disabled", "已禁用自动巡航");
|
||||
EnhancedMechaForgeCountControlEnabled.SettingChanged += (_, _) => EnhancedMechaForgeCountControl.Enable(EnhancedMechaForgeCountControlEnabled.Value);
|
||||
HideTipsForSandsChangesEnabled.SettingChanged += (_, _) => HideTipsForSandsChanges.Enable(HideTipsForSandsChangesEnabled.Value);
|
||||
AutoNavigationEnabled.SettingChanged += (_, _) => AutoNavigation.Enable(AutoNavigationEnabled.Value);
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
EnhancedMechaForgeCountControl.Enable(EnhancedMechaForgeCountControlEnabled.Value);
|
||||
HideTipsForSandsChanges.Enable(HideTipsForSandsChangesEnabled.Value);
|
||||
AutoNavigation.Enable(AutoNavigationEnabled.Value);
|
||||
}
|
||||
|
||||
public static void OnUpdate()
|
||||
|
||||
@@ -18,6 +18,10 @@ public static class TechPatch
|
||||
I18N.Add("分拣器运货量", "Sorter Mk.III cargo stacking : ", "极速分拣器每次可运送 ");
|
||||
SorterCargoStackingEnabled.SettingChanged += (_, _) => SorterCargoStacking.Enable(SorterCargoStackingEnabled.Value);
|
||||
BatchBuyoutTechEnabled.SettingChanged += (_, _) => BatchBuyoutTech.Enable(BatchBuyoutTechEnabled.Value);
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
SorterCargoStacking.Enable(SorterCargoStackingEnabled.Value);
|
||||
BatchBuyoutTech.Enable(BatchBuyoutTechEnabled.Value);
|
||||
}
|
||||
|
||||
@@ -238,8 +238,8 @@ public static class UIConfigWindow
|
||||
if (ModsCompat.AuxilaryfunctionWrapper.ShowStationInfo != null)
|
||||
{
|
||||
ModsCompat.AuxilaryfunctionWrapper.ShowStationInfo.SettingChanged += (_, _) => { OnAuxilaryInfoPanelChanged(); };
|
||||
}
|
||||
OnAuxilaryInfoPanelChanged();
|
||||
}
|
||||
|
||||
var tab3 = wnd.AddTab(trans, "Player/Mecha");
|
||||
x = 0f;
|
||||
|
||||
@@ -158,8 +158,6 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
// UI Patches
|
||||
UIPatch.Enable(true);
|
||||
|
||||
// Persistant Patches
|
||||
Persist.Enable(true);
|
||||
GameLogic.Enable(true);
|
||||
|
||||
MyWindowManager.Init();
|
||||
@@ -179,7 +177,6 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
private void Start()
|
||||
{
|
||||
_patches?.Do(type => type.GetMethod("Start")?.Invoke(null, null));
|
||||
LogisticsPatch.Start();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -189,7 +186,6 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
MyWindowManager.Uninit();
|
||||
|
||||
GameLogic.Enable(false);
|
||||
Persist.Enable(false);
|
||||
UIPatch.Enable(false);
|
||||
}
|
||||
|
||||
@@ -325,187 +321,4 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class Persist: PatchImpl<Persist>
|
||||
{
|
||||
// Check for noModifier while pressing hotkeys on build bar
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIBuildMenu), nameof(UIBuildMenu._OnUpdate))]
|
||||
private static IEnumerable<CodeInstruction> UIBuildMenu__OnUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(typeof(VFInput), nameof(VFInput.inScreen)))
|
||||
);
|
||||
matcher.Repeat(codeMatcher =>
|
||||
{
|
||||
var jumpPos = codeMatcher.Advance(1).Operand;
|
||||
codeMatcher.Advance(-1).InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(VFInput), nameof(VFInput.noModifier))),
|
||||
new CodeInstruction(OpCodes.Brfalse_S, jumpPos)
|
||||
).Advance(2);
|
||||
});
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Patch to fix the issue that warning popup on VeinUtil upgraded to level 8000+
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(ABN_VeinsUtil), nameof(ABN_VeinsUtil.CheckValue))]
|
||||
private static IEnumerable<CodeInstruction> ABN_VeinsUtil_CheckValue_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldelem_R8),
|
||||
new CodeMatch(OpCodes.Conv_R4),
|
||||
new CodeMatch(OpCodes.Add),
|
||||
new CodeMatch(OpCodes.Stloc_1)
|
||||
);
|
||||
// loc1 = Mathf.Round(n * 1000f) / 1000f;
|
||||
matcher.Advance(3).Insert(
|
||||
new CodeInstruction(OpCodes.Ldc_R4, 1000f),
|
||||
new CodeInstruction(OpCodes.Mul),
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Mathf), nameof(Mathf.Round))),
|
||||
new CodeInstruction(OpCodes.Ldc_R4, 1000f),
|
||||
new CodeInstruction(OpCodes.Div)
|
||||
);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Bring popup tip window to top layer
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIButton), nameof(UIButton.LateUpdate))]
|
||||
private static IEnumerable<CodeInstruction> UIButton_LateUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldloc_2),
|
||||
new CodeMatch(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(Component), nameof(Component.gameObject))),
|
||||
new CodeMatch(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(GameObject), nameof(GameObject.activeSelf)))
|
||||
);
|
||||
var labels = matcher.Labels;
|
||||
matcher.Labels = null;
|
||||
matcher.Insert(
|
||||
new CodeInstruction(OpCodes.Ldloc_2).WithLabels(labels),
|
||||
new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(Component), nameof(Component.transform))),
|
||||
new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(Transform), nameof(Transform.parent))),
|
||||
new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(Transform), nameof(Transform.parent))),
|
||||
new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Transform), nameof(Transform.SetAsLastSibling)))
|
||||
);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Sort blueprint structures by item id, model index, recipe id, area index, and position before saving
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(BlueprintUtils), nameof(BlueprintUtils.GenerateBlueprintData))]
|
||||
private static void BlueprintUtils_GenerateBlueprintData_Postfix(BlueprintData _blueprintData)
|
||||
{
|
||||
var buildings = _blueprintData.buildings;
|
||||
Array.Sort(buildings, (a, b) =>
|
||||
{
|
||||
var tmpItemId = a.itemId - b.itemId;
|
||||
if (tmpItemId != 0)
|
||||
return tmpItemId;
|
||||
var tmpModelIndex = a.modelIndex - b.modelIndex;
|
||||
if (tmpModelIndex != 0)
|
||||
return tmpModelIndex;
|
||||
var tmpRecipeId = a.recipeId - b.recipeId;
|
||||
if (tmpRecipeId != 0)
|
||||
return tmpRecipeId;
|
||||
var tmpAreaIndex = a.areaIndex - b.areaIndex;
|
||||
if (tmpAreaIndex != 0)
|
||||
return tmpAreaIndex;
|
||||
const double ky = 256.0;
|
||||
const double kx = 1024.0;
|
||||
var scorePosA = (a.localOffset_y * ky + a.localOffset_x) * kx + a.localOffset_z;
|
||||
var scorePosB = (b.localOffset_y * ky + b.localOffset_x) * kx + b.localOffset_z;
|
||||
return scorePosA < scorePosB ? 1 : -1;
|
||||
});
|
||||
for (var i = buildings.Length - 1; i >= 0; i--)
|
||||
{
|
||||
buildings[i].index = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Increase maximum value of property realizing, 2000 -> 20000
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIPropertyEntry), nameof(UIPropertyEntry.UpdateUIElements))]
|
||||
[HarmonyPatch(typeof(UIPropertyEntry), nameof(UIPropertyEntry.OnRealizeButtonClick))]
|
||||
[HarmonyPatch(typeof(UIPropertyEntry), nameof(UIPropertyEntry.OnInputValueEnd))]
|
||||
private static IEnumerable<CodeInstruction> UIProductEntry_UpdateUIElements_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldc_I4, 2000)
|
||||
);
|
||||
matcher.Repeat(m => { m.SetAndAdvance(OpCodes.Ldc_I4, 20000); });
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIPropertyEntry), nameof(UIPropertyEntry.OnInputValueEnd))]
|
||||
private static IEnumerable<CodeInstruction> UIProductEntry_OnInputValueEnd_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Ldc_R4 && ci.OperandIs(2000f))
|
||||
);
|
||||
matcher.Repeat(m => { m.SetAndAdvance(OpCodes.Ldc_R4, 20000f); });
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Increase capacity of player order queue, 16 -> 128
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(PlayerOrder), MethodType.Constructor, typeof(Player))]
|
||||
private static IEnumerable<CodeInstruction> PlayerOrder_Constructor_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(ci => (ci.opcode == OpCodes.Ldc_I4_S || ci.opcode == OpCodes.Ldc_I4) && ci.OperandIs(16))
|
||||
);
|
||||
matcher.Repeat(m => { m.SetAndAdvance(OpCodes.Ldc_I4, 128); });
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Increase Player Command Queue from 16 to 128
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(PlayerOrder), nameof(PlayerOrder._trimEnd))]
|
||||
[HarmonyPatch(typeof(PlayerOrder), nameof(PlayerOrder.Enqueue))]
|
||||
private static IEnumerable<CodeInstruction> PlayerOrder_ExtendCount_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(ci => (ci.opcode == OpCodes.Ldc_I4_S || ci.opcode == OpCodes.Ldc_I4) && ci.OperandIs(16))
|
||||
);
|
||||
matcher.Repeat(m => { m.SetAndAdvance(OpCodes.Ldc_I4, 128); });
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Allow F11 in star map
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UIGame), nameof(UIGame._OnLateUpdate))]
|
||||
private static IEnumerable<CodeInstruction> UIGame__OnLateUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(typeof(VFInput), nameof(VFInput.inFullscreenGUI))),
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Brfalse || ci.opcode == OpCodes.Brfalse_S)
|
||||
);
|
||||
var jumpPos = matcher.Advance(1).Operand;
|
||||
matcher.Advance(-1).Insert(
|
||||
new CodeInstruction(OpCodes.Ldarg_0),
|
||||
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(UIGame), nameof(UIGame.starmap))),
|
||||
new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(ManualBehaviour), nameof(ManualBehaviour.active))),
|
||||
new CodeInstruction(OpCodes.Brtrue_S, jumpPos)
|
||||
);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Ignore UIDFCommunicatorWindow.Determine()
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(UIDFCommunicatorWindow), nameof(UIDFCommunicatorWindow.Determine))]
|
||||
private static bool UIDFCommunicatorWindow_Determine_Prefix()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user