1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2026-02-04 20:22:17 +08:00
This commit is contained in:
2024-09-18 01:41:08 +08:00
parent fb916b3813
commit bd512a6b78
17 changed files with 232 additions and 207 deletions

View File

@@ -1,6 +1,6 @@
using System.Reflection; using System;
using System.Reflection;
using BepInEx; using BepInEx;
using CheatEnabler.Functions;
using CheatEnabler.Patches; using CheatEnabler.Patches;
using HarmonyLib; using HarmonyLib;
using UXAssist.Common; using UXAssist.Common;
@@ -83,19 +83,22 @@ public class CheatEnabler : BaseUnityPlugin
"Mecha and Drones/Fleets invincible"); "Mecha and Drones/Fleets invincible");
CombatPatch.BuildingsInvincibleEnabled = Config.Bind("Battle", "BuildingsInvincible", false, CombatPatch.BuildingsInvincibleEnabled = Config.Bind("Battle", "BuildingsInvincible", false,
"Buildings invincible"); "Buildings invincible");
}
private void Start() {
UIConfigWindow.Init(); UIConfigWindow.Init();
Util.GetTypesInNamespace(Assembly.GetExecutingAssembly(), "CheatEnabler.Patches") _patches = Util.GetTypesFiltered(Assembly.GetExecutingAssembly(),
.Do(type => type.GetMethod("Init")?.Invoke(null, null)); t => string.Equals(t.Namespace, "CheatEnabler.Patches", StringComparison.Ordinal) || string.Equals(t.Namespace, "CheatEnabler.Functions", StringComparison.Ordinal));
PlayerFunctions.Init(); _patches?.Do(type => type.GetMethod("Init")?.Invoke(null, null));
DysonSphereFunctions.Init(); }
private Type[] _patches;
private void Start()
{
_patches?.Do(type => type.GetMethod("Start")?.Invoke(null, null));
} }
private void OnDestroy() private void OnDestroy()
{ {
Util.GetTypesInNamespace(Assembly.GetExecutingAssembly(), "CheatEnabler.Patches") _patches?.Do(type => type.GetMethod("Uninit")?.Invoke(null, null));
.Do(type => type.GetMethod("Uninit")?.Invoke(null, null));
} }
private void Update() private void Update()

View File

@@ -16,6 +16,10 @@ public static class CombatPatch
{ {
MechaInvincibleEnabled.SettingChanged += (_, _) => MechaInvincible.Enable(MechaInvincibleEnabled.Value); MechaInvincibleEnabled.SettingChanged += (_, _) => MechaInvincible.Enable(MechaInvincibleEnabled.Value);
BuildingsInvincibleEnabled.SettingChanged += (_, _) => BuildingsInvincible.Enable(BuildingsInvincibleEnabled.Value); BuildingsInvincibleEnabled.SettingChanged += (_, _) => BuildingsInvincible.Enable(BuildingsInvincibleEnabled.Value);
}
public static void Start()
{
MechaInvincible.Enable(MechaInvincibleEnabled.Value); MechaInvincible.Enable(MechaInvincibleEnabled.Value);
BuildingsInvincible.Enable(BuildingsInvincibleEnabled.Value); BuildingsInvincible.Enable(BuildingsInvincibleEnabled.Value);
} }

View File

@@ -7,7 +7,7 @@ using UXAssist.Common;
namespace CheatEnabler.Patches; namespace CheatEnabler.Patches;
public static class DysonSpherePatch public class DysonSpherePatch: PatchImpl<DysonSpherePatch>
{ {
public static ConfigEntry<bool> SkipBulletEnabled; public static ConfigEntry<bool> SkipBulletEnabled;
public static ConfigEntry<bool> SkipAbsorbEnabled; public static ConfigEntry<bool> SkipAbsorbEnabled;
@@ -17,8 +17,6 @@ public static class DysonSpherePatch
public static ConfigEntry<bool> OverclockSiloEnabled; public static ConfigEntry<bool> OverclockSiloEnabled;
private static bool _instantAbsorb; private static bool _instantAbsorb;
private static Harmony _dysonSpherePatch;
public static void Init() public static void Init()
{ {
SkipBulletEnabled.SettingChanged += (_, _) => SkipBulletPatch.Enable(SkipBulletEnabled.Value); SkipBulletEnabled.SettingChanged += (_, _) => SkipBulletPatch.Enable(SkipBulletEnabled.Value);
@@ -27,19 +25,22 @@ public static class DysonSpherePatch
EjectAnywayEnabled.SettingChanged += (_, _) => EjectAnywayPatch.Enable(EjectAnywayEnabled.Value); EjectAnywayEnabled.SettingChanged += (_, _) => EjectAnywayPatch.Enable(EjectAnywayEnabled.Value);
OverclockEjectorEnabled.SettingChanged += (_, _) => OverclockEjector.Enable(OverclockEjectorEnabled.Value); OverclockEjectorEnabled.SettingChanged += (_, _) => OverclockEjector.Enable(OverclockEjectorEnabled.Value);
OverclockSiloEnabled.SettingChanged += (_, _) => OverclockSilo.Enable(OverclockSiloEnabled.Value); OverclockSiloEnabled.SettingChanged += (_, _) => OverclockSilo.Enable(OverclockSiloEnabled.Value);
}
public static void Start()
{
SkipBulletPatch.Enable(SkipBulletEnabled.Value); SkipBulletPatch.Enable(SkipBulletEnabled.Value);
SkipAbsorbPatch.Enable(SkipAbsorbEnabled.Value); SkipAbsorbPatch.Enable(SkipAbsorbEnabled.Value);
QuickAbsorbPatch.Enable(QuickAbsorbEnabled.Value); QuickAbsorbPatch.Enable(QuickAbsorbEnabled.Value);
EjectAnywayPatch.Enable(EjectAnywayEnabled.Value); EjectAnywayPatch.Enable(EjectAnywayEnabled.Value);
OverclockEjector.Enable(OverclockEjectorEnabled.Value); OverclockEjector.Enable(OverclockEjectorEnabled.Value);
OverclockSilo.Enable(OverclockSiloEnabled.Value); OverclockSilo.Enable(OverclockSiloEnabled.Value);
_dysonSpherePatch ??= Harmony.CreateAndPatchAll(typeof(DysonSpherePatch)); Enable(true);
} }
public static void Uninit() public static void Uninit()
{ {
_dysonSpherePatch?.UnpatchSelf(); Enable(false);
_dysonSpherePatch = null;
SkipBulletPatch.Enable(false); SkipBulletPatch.Enable(false);
SkipAbsorbPatch.Enable(false); SkipAbsorbPatch.Enable(false);
QuickAbsorbPatch.Enable(false); QuickAbsorbPatch.Enable(false);

View File

@@ -10,7 +10,7 @@ using UXAssist.Common;
namespace CheatEnabler.Patches; namespace CheatEnabler.Patches;
public static class FactoryPatch public class FactoryPatch: PatchImpl<FactoryPatch>
{ {
public static ConfigEntry<bool> ImmediateEnabled; public static ConfigEntry<bool> ImmediateEnabled;
public static ConfigEntry<bool> ArchitectModeEnabled; public static ConfigEntry<bool> ArchitectModeEnabled;
@@ -30,13 +30,11 @@ public static class FactoryPatch
public static ConfigEntry<bool> GreaterPowerUsageInLogisticsEnabled; public static ConfigEntry<bool> GreaterPowerUsageInLogisticsEnabled;
public static ConfigEntry<bool> ControlPanelRemoteLogisticsEnabled; public static ConfigEntry<bool> ControlPanelRemoteLogisticsEnabled;
private static Harmony _factoryPatch;
private static PressKeyBind _noConditionKey; private static PressKeyBind _noConditionKey;
private static PressKeyBind _noCollisionKey; private static PressKeyBind _noCollisionKey;
public static void Init() public static void Init()
{ {
if (_factoryPatch != null) return;
_noConditionKey = KeyBindings.RegisterKeyBinding(new BuiltinKey _noConditionKey = KeyBindings.RegisterKeyBinding(new BuiltinKey
{ {
key = new CombineKey(0, 0, ECombineKeyAction.OnceClick, true), key = new CombineKey(0, 0, ECombineKeyAction.OnceClick, true),
@@ -55,10 +53,13 @@ public static class FactoryPatch
); );
I18N.Add("KEYToggleNoCondition", "Toggle No Condition Build", "切换无条件建造"); I18N.Add("KEYToggleNoCondition", "Toggle No Condition Build", "切换无条件建造");
I18N.Add("KEYToggleNoCollision", "Toggle No Collision", "切换无碰撞"); I18N.Add("KEYToggleNoCollision", "Toggle No Collision", "切换无碰撞");
I18N.Add("NoConditionOn", "No condition build is enabled!", "无条件建造已启"); I18N.Add("NoConditionOn", "No condition build is enabled!", "无条件建造已启");
I18N.Add("NoConditionOff", "No condition build is disabled!", "无条件建造已禁用"); I18N.Add("NoConditionOff", "No condition build is disabled!", "无条件建造已关闭");
I18N.Add("NoCollisionOn", "No collision is enabled!", "无碰撞已启"); I18N.Add("NoCollisionOn", "No collision is enabled!", "无碰撞已启");
I18N.Add("NoCollisionOff", "No collision is disabled!", "无碰撞已禁用"); I18N.Add("NoCollisionOff", "No collision is disabled!", "无碰撞已关闭");
I18N.Add("Build without condition is enabled!", "!!Build without condition is enabled!!", "!!无条件建造已开启!!");
I18N.Add("No collision is enabled!", "!!No collision is enabled!!", "!!无碰撞已开启!!");
ImmediateEnabled.SettingChanged += (_, _) => ImmediateBuild.Enable(ImmediateEnabled.Value); ImmediateEnabled.SettingChanged += (_, _) => ImmediateBuild.Enable(ImmediateEnabled.Value);
ArchitectModeEnabled.SettingChanged += (_, _) => ArchitectMode.Enable(ArchitectModeEnabled.Value); ArchitectModeEnabled.SettingChanged += (_, _) => ArchitectMode.Enable(ArchitectModeEnabled.Value);
NoConditionEnabled.SettingChanged += (_, _) => NoConditionBuild.Enable(NoConditionEnabled.Value); NoConditionEnabled.SettingChanged += (_, _) => NoConditionBuild.Enable(NoConditionEnabled.Value);
@@ -73,6 +74,10 @@ public static class FactoryPatch
WindTurbinesPowerGlobalCoverageEnabled.SettingChanged += (_, _) => WindTurbinesPowerGlobalCoverage.Enable(WindTurbinesPowerGlobalCoverageEnabled.Value); WindTurbinesPowerGlobalCoverageEnabled.SettingChanged += (_, _) => WindTurbinesPowerGlobalCoverage.Enable(WindTurbinesPowerGlobalCoverageEnabled.Value);
GreaterPowerUsageInLogisticsEnabled.SettingChanged += (_, _) => GreaterPowerUsageInLogistics.Enable(GreaterPowerUsageInLogisticsEnabled.Value); GreaterPowerUsageInLogisticsEnabled.SettingChanged += (_, _) => GreaterPowerUsageInLogistics.Enable(GreaterPowerUsageInLogisticsEnabled.Value);
ControlPanelRemoteLogisticsEnabled.SettingChanged += (_, _) => ControlPanelRemoteLogistics.Enable(ControlPanelRemoteLogisticsEnabled.Value); ControlPanelRemoteLogisticsEnabled.SettingChanged += (_, _) => ControlPanelRemoteLogistics.Enable(ControlPanelRemoteLogisticsEnabled.Value);
}
public static void Start()
{
ImmediateBuild.Enable(ImmediateEnabled.Value); ImmediateBuild.Enable(ImmediateEnabled.Value);
ArchitectMode.Enable(ArchitectModeEnabled.Value); ArchitectMode.Enable(ArchitectModeEnabled.Value);
NoConditionBuild.Enable(NoConditionEnabled.Value); NoConditionBuild.Enable(NoConditionEnabled.Value);
@@ -85,7 +90,7 @@ public static class FactoryPatch
BoostGeothermalPower.Enable(BoostGeothermalPowerEnabled.Value); BoostGeothermalPower.Enable(BoostGeothermalPowerEnabled.Value);
GreaterPowerUsageInLogistics.Enable(GreaterPowerUsageInLogisticsEnabled.Value); GreaterPowerUsageInLogistics.Enable(GreaterPowerUsageInLogisticsEnabled.Value);
ControlPanelRemoteLogistics.Enable(ControlPanelRemoteLogisticsEnabled.Value); ControlPanelRemoteLogistics.Enable(ControlPanelRemoteLogisticsEnabled.Value);
_factoryPatch = Harmony.CreateAndPatchAll(typeof(FactoryPatch)); Enable(true);
GameLogic.OnGameBegin += GameMain_Begin_Postfix_For_ImmBuild; GameLogic.OnGameBegin += GameMain_Begin_Postfix_For_ImmBuild;
GameLogic.OnDataLoaded += () => WindTurbinesPowerGlobalCoverage.Enable(WindTurbinesPowerGlobalCoverageEnabled.Value); GameLogic.OnDataLoaded += () => WindTurbinesPowerGlobalCoverage.Enable(WindTurbinesPowerGlobalCoverageEnabled.Value);
} }
@@ -93,8 +98,7 @@ public static class FactoryPatch
public static void Uninit() public static void Uninit()
{ {
GameLogic.OnGameBegin -= GameMain_Begin_Postfix_For_ImmBuild; GameLogic.OnGameBegin -= GameMain_Begin_Postfix_For_ImmBuild;
_factoryPatch?.UnpatchSelf(); Enable(false);
_factoryPatch = null;
ImmediateBuild.Enable(false); ImmediateBuild.Enable(false);
ArchitectMode.Enable(false); ArchitectMode.Enable(false);
NoConditionBuild.Enable(false); NoConditionBuild.Enable(false);
@@ -136,6 +140,7 @@ public static class FactoryPatch
var obj = coll.gameObject; var obj = coll.gameObject;
if (obj == null) return; if (obj == null) return;
obj.gameObject.SetActive(!NoCollisionEnabled.Value); obj.gameObject.SetActive(!NoCollisionEnabled.Value);
GameMain.data?.warningSystem?.UpdateCriticalWarningText();
} }
public static void ArrivePlanet(PlanetFactory factory) public static void ArrivePlanet(PlanetFactory factory)
@@ -193,13 +198,23 @@ public static class FactoryPatch
private static IEnumerable<CodeInstruction> WarningSystem_hasCriticalWarning_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> WarningSystem_hasCriticalWarning_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{ {
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
var label1 = generator.DefineLabel();
var label2 = generator.DefineLabel();
matcher.End().MatchBack(false, matcher.End().MatchBack(false,
new CodeMatch(OpCodes.Ret) new CodeMatch(OpCodes.Ret)
); ).RemoveInstructions(1);
matcher.InsertAndAdvance( matcher.InsertAndAdvance(
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(FactoryPatch), nameof(NoConditionEnabled))), new CodeInstruction(OpCodes.Brfalse, label1),
new CodeInstruction(OpCodes.Ldc_I4_1),
new CodeInstruction(OpCodes.Ret),
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(FactoryPatch), nameof(NoConditionEnabled))).WithLabels(label1),
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(ConfigEntry<bool>), nameof(ConfigEntry<bool>.Value))), new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(ConfigEntry<bool>), nameof(ConfigEntry<bool>.Value))),
new CodeInstruction(OpCodes.Or) new CodeInstruction(OpCodes.Brfalse, label2),
new CodeInstruction(OpCodes.Ldc_I4_1),
new CodeInstruction(OpCodes.Ret),
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(FactoryPatch), nameof(NoCollisionEnabled))).WithLabels(label2),
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(ConfigEntry<bool>), nameof(ConfigEntry<bool>.Value))),
new CodeInstruction(OpCodes.Ret)
); );
return matcher.InstructionEnumeration(); return matcher.InstructionEnumeration();
} }
@@ -211,61 +226,54 @@ public static class FactoryPatch
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false, matcher.MatchForward(false,
new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldarg_0),
new CodeMatch(OpCodes.Ldstr), new CodeMatch(OpCodes.Ldstr, ""),
new CodeMatch(OpCodes.Call, AccessTools.PropertySetter(typeof(WarningSystem), nameof(WarningSystem.criticalWarningTexts))) new CodeMatch(OpCodes.Call, AccessTools.PropertySetter(typeof(WarningSystem), nameof(WarningSystem.criticalWarningTexts)))
); );
matcher.Repeat(m => matcher.Repeat(m =>
{ {
var label1 = generator.DefineLabel(); var label1 = generator.DefineLabel();
var label2 = generator.DefineLabel(); m.Advance(1).RemoveInstructions(2).InsertAndAdvance(
m.Advance(1).Labels.Add(label1); Transpilers.EmitDelegate((WarningSystem w) =>
m.InsertAndAdvance( {
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(FactoryPatch), nameof(NoConditionEnabled))), if (NoConditionEnabled.Value)
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(ConfigEntry<bool>), nameof(ConfigEntry<bool>.Value))), {
new CodeInstruction(OpCodes.Brfalse, label1), CheatEnabler.Logger.LogDebug("A");
new CodeInstruction(OpCodes.Ldstr, "Build without condition is enabled!"), w.criticalWarningTexts = "Build without condition is enabled!".Translate() + "\r\n";
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Localization), nameof(Localization.Translate), [typeof(string)])), }
new CodeInstruction(OpCodes.Ldstr, "\r\n"), else if (NoCollisionEnabled.Value)
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(string), nameof(string.Concat), [typeof(string), typeof(string)])), {
new CodeInstruction(OpCodes.Call, AccessTools.PropertySetter(typeof(WarningSystem), nameof(WarningSystem.criticalWarningTexts))) CheatEnabler.Logger.LogDebug("B");
w.criticalWarningTexts = "No collision is enabled!".Translate() + "\r\n";
}
CheatEnabler.Logger.LogDebug("C");
}
)
); );
if (m.InstructionAt(2).opcode == OpCodes.Ret) if (m.Opcode == OpCodes.Ret)
{ {
m.InsertAndAdvance( m.InsertAndAdvance(
new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(WarningSystem), nameof(WarningSystem.onCriticalWarningTextChanged))), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(WarningSystem), nameof(WarningSystem.onCriticalWarningTextChanged))),
new CodeInstruction(OpCodes.Brfalse_S, label2), new CodeInstruction(OpCodes.Brfalse_S, label1),
new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(WarningSystem), nameof(WarningSystem.onCriticalWarningTextChanged))), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(WarningSystem), nameof(WarningSystem.onCriticalWarningTextChanged))),
new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Action), nameof(Action.Invoke))) new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Action), nameof(Action.Invoke)))
); );
m.Labels.Add(label1);
} }
m.InsertAndAdvance(
new CodeInstruction(OpCodes.Br, label2)
).Advance(2).Labels.Add(label2);
}); });
return matcher.InstructionEnumeration(); return matcher.InstructionEnumeration();
} }
private static class ImmediateBuild private class ImmediateBuild: PatchImpl<ImmediateBuild>
{ {
private static Harmony _immediatePatch; protected override void OnEnable()
public static void Enable(bool enable)
{ {
if (enable) var factory = GameMain.mainPlayer?.factory;
if (factory != null)
{ {
if (_immediatePatch != null) return; ArrivePlanet(factory);
var factory = GameMain.mainPlayer?.factory;
if (factory != null)
{
ArrivePlanet(factory);
}
_immediatePatch = Harmony.CreateAndPatchAll(typeof(ImmediateBuild));
return;
} }
_immediatePatch?.UnpatchSelf();
_immediatePatch = null;
} }
[HarmonyTranspiler] [HarmonyTranspiler]
@@ -369,19 +377,16 @@ public static class FactoryPatch
} }
} }
private static class NoConditionBuild private class NoConditionBuild: PatchImpl<NoConditionBuild>
{ {
private static Harmony _noConditionPatch; protected override void OnEnable()
public static void Enable(bool on) {
GameMain.data?.warningSystem?.UpdateCriticalWarningText();
}
protected override void OnDisable()
{ {
GameMain.data?.warningSystem?.UpdateCriticalWarningText(); GameMain.data?.warningSystem?.UpdateCriticalWarningText();
if (on)
{
_noConditionPatch ??= Harmony.CreateAndPatchAll(typeof(NoConditionBuild));
return;
}
_noConditionPatch?.UnpatchSelf();
_noConditionPatch = null;
} }
[HarmonyTranspiler, HarmonyPriority(Priority.Last)] [HarmonyTranspiler, HarmonyPriority(Priority.Last)]
@@ -460,9 +465,8 @@ public static class FactoryPatch
} }
} }
public static class BeltSignalGenerator public class BeltSignalGenerator: PatchImpl<BeltSignalGenerator>
{ {
private static Harmony _beltSignalPatch;
private static Dictionary<int, BeltSignal>[] _signalBelts; private static Dictionary<int, BeltSignal>[] _signalBelts;
private static Dictionary<long, int> _portalFrom; private static Dictionary<long, int> _portalFrom;
private static Dictionary<int, HashSet<long>> _portalTo; private static Dictionary<int, HashSet<long>> _portalTo;
@@ -480,18 +484,15 @@ public static class FactoryPatch
public float[] SourceProgress; public float[] SourceProgress;
} }
public static void Enable(bool on) protected override void OnEnable()
{
InitSignalBelts();
GameLogic.OnGameBegin += GameMain_Begin_Postfix;
}
protected override void OnDisable()
{ {
if (on)
{
InitSignalBelts();
_beltSignalPatch ??= Harmony.CreateAndPatchAll(typeof(BeltSignalGenerator));
GameLogic.OnGameBegin += GameMain_Begin_Postfix;
return;
}
GameLogic.OnGameBegin -= GameMain_Begin_Postfix; GameLogic.OnGameBegin -= GameMain_Begin_Postfix;
_beltSignalPatch?.UnpatchSelf();
_beltSignalPatch = null;
_initialized = false; _initialized = false;
_signalBelts = null; _signalBelts = null;
_signalBeltsCapacity = 0; _signalBeltsCapacity = 0;

View File

@@ -19,6 +19,10 @@ public static class GamePatch
DevShortcutsEnabled.SettingChanged += (_, _) => DevShortcuts.Enable(DevShortcutsEnabled.Value); DevShortcutsEnabled.SettingChanged += (_, _) => DevShortcuts.Enable(DevShortcutsEnabled.Value);
AbnormalDisablerEnabled.SettingChanged += (_, _) => AbnormalDisabler.Enable(AbnormalDisablerEnabled.Value); AbnormalDisablerEnabled.SettingChanged += (_, _) => AbnormalDisabler.Enable(AbnormalDisablerEnabled.Value);
UnlockTechEnabled.SettingChanged += (_, _) => UnlockTech.Enable(UnlockTechEnabled.Value); UnlockTechEnabled.SettingChanged += (_, _) => UnlockTech.Enable(UnlockTechEnabled.Value);
}
public static void Start()
{
DevShortcuts.Enable(DevShortcutsEnabled.Value); DevShortcuts.Enable(DevShortcutsEnabled.Value);
AbnormalDisabler.Enable(AbnormalDisablerEnabled.Value); AbnormalDisabler.Enable(AbnormalDisablerEnabled.Value);
UnlockTech.Enable(UnlockTechEnabled.Value); UnlockTech.Enable(UnlockTechEnabled.Value);

View File

@@ -15,6 +15,10 @@ public static class PlanetPatch
{ {
WaterPumpAnywhereEnabled.SettingChanged += (_, _) => WaterPumperPatch.Enable(WaterPumpAnywhereEnabled.Value); WaterPumpAnywhereEnabled.SettingChanged += (_, _) => WaterPumperPatch.Enable(WaterPumpAnywhereEnabled.Value);
TerraformAnywayEnabled.SettingChanged += (_, _) => TerraformAnyway.Enable(TerraformAnywayEnabled.Value); TerraformAnywayEnabled.SettingChanged += (_, _) => TerraformAnyway.Enable(TerraformAnywayEnabled.Value);
}
public static void Start()
{
WaterPumperPatch.Enable(WaterPumpAnywhereEnabled.Value); WaterPumperPatch.Enable(WaterPumpAnywhereEnabled.Value);
TerraformAnyway.Enable(TerraformAnywayEnabled.Value); TerraformAnyway.Enable(TerraformAnywayEnabled.Value);
} }

View File

@@ -15,6 +15,10 @@ public static class PlayerPatch
{ {
InstantTeleportEnabled.SettingChanged += (_, _) => InstantTeleport.Enable(InstantTeleportEnabled.Value); InstantTeleportEnabled.SettingChanged += (_, _) => InstantTeleport.Enable(InstantTeleportEnabled.Value);
WarpWithoutSpaceWarpersEnabled.SettingChanged += (_, _) => WarpWithoutSpaceWarpers.Enable(WarpWithoutSpaceWarpersEnabled.Value); WarpWithoutSpaceWarpersEnabled.SettingChanged += (_, _) => WarpWithoutSpaceWarpers.Enable(WarpWithoutSpaceWarpersEnabled.Value);
}
public static void Start()
{
InstantTeleport.Enable(InstantTeleportEnabled.Value); InstantTeleport.Enable(InstantTeleportEnabled.Value);
WarpWithoutSpaceWarpers.Enable(WarpWithoutSpaceWarpersEnabled.Value); WarpWithoutSpaceWarpers.Enable(WarpWithoutSpaceWarpersEnabled.Value);
} }

View File

@@ -15,6 +15,10 @@ public static class ResourcePatch
{ {
InfiniteResourceEnabled.SettingChanged += (_, _) => InfiniteResource.Enable(InfiniteResourceEnabled.Value); InfiniteResourceEnabled.SettingChanged += (_, _) => InfiniteResource.Enable(InfiniteResourceEnabled.Value);
FastMiningEnabled.SettingChanged += (_, _) => FastMining.Enable(FastMiningEnabled.Value); FastMiningEnabled.SettingChanged += (_, _) => FastMining.Enable(FastMiningEnabled.Value);
}
public static void Start()
{
InfiniteResource.Enable(InfiniteResourceEnabled.Value); InfiniteResource.Enable(InfiniteResourceEnabled.Value);
FastMining.Enable(FastMiningEnabled.Value); FastMining.Enable(FastMiningEnabled.Value);
} }

View File

@@ -36,7 +36,6 @@ public static class UIConfigWindow
I18N.Add("Finish build immediately", "Finish build immediately", "建造秒完成"); I18N.Add("Finish build immediately", "Finish build immediately", "建造秒完成");
I18N.Add("Architect mode", "Architect mode", "建筑师模式"); I18N.Add("Architect mode", "Architect mode", "建筑师模式");
I18N.Add("Build without condition", "Build without condition check", "无条件建造"); I18N.Add("Build without condition", "Build without condition check", "无条件建造");
I18N.Add("Build without condition is enabled!", "!!Build without condition is enabled!!", "!!无条件建造已开启!!");
I18N.Add("No collision", "No collision", "无碰撞"); I18N.Add("No collision", "No collision", "无碰撞");
I18N.Add("Belt signal generator", "Belt signal generator", "传送带信号物品生成"); I18N.Add("Belt signal generator", "Belt signal generator", "传送带信号物品生成");
I18N.Add("Belt signal alt format", "Belt signal alt format", "传送带信号替换格式"); I18N.Add("Belt signal alt format", "Belt signal alt format", "传送带信号替换格式");

View File

@@ -3,24 +3,12 @@ using HarmonyLib;
namespace UXAssist.Common; namespace UXAssist.Common;
public static class GameLogic public class GameLogic: PatchImpl<GameLogic>
{ {
private static Harmony _harmony;
public static Action OnDataLoaded; public static Action OnDataLoaded;
public static Action OnGameBegin; public static Action OnGameBegin;
public static Action OnGameEnd; public static Action OnGameEnd;
public static void Init()
{
_harmony ??= Harmony.CreateAndPatchAll(typeof(GameLogic));
}
public static void Uninit()
{
_harmony?.UnpatchSelf();
_harmony = null;
}
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(VFPreload), nameof(VFPreload.InvokeOnLoadWorkEnded))] [HarmonyPatch(typeof(VFPreload), nameof(VFPreload.InvokeOnLoadWorkEnded))]
public static void VFPreload_InvokeOnLoadWorkEnded_Postfix() public static void VFPreload_InvokeOnLoadWorkEnded_Postfix()

View File

@@ -1,7 +1,15 @@
using HarmonyLib; using System;
using System.Reflection;
using HarmonyLib;
namespace UXAssist.Common; namespace UXAssist.Common;
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class PatchImplGuidAttribute(string guid) : Attribute
{
public string Guid { get; } = guid;
}
public class PatchImpl<T> where T : new() public class PatchImpl<T> where T : new()
{ {
private static T Instance { get; } = new(); private static T Instance { get; } = new();
@@ -17,7 +25,8 @@ public class PatchImpl<T> where T : new()
} }
if (enable) if (enable)
{ {
thisInstance._patch ??= Harmony.CreateAndPatchAll(typeof(T)); var guid = typeof(T).GetCustomAttribute<PatchImplGuidAttribute>()?.Guid;
thisInstance._patch ??= Harmony.CreateAndPatchAll(typeof(T), guid);
thisInstance.OnEnable(); thisInstance.OnEnable();
return; return;
} }
@@ -26,7 +35,7 @@ public class PatchImpl<T> where T : new()
thisInstance._patch = null; thisInstance._patch = null;
} }
protected static Harmony GetPatch() => (Instance as PatchImpl<T>)?._patch; public static Harmony GetHarmony() => (Instance as PatchImpl<T>)?._patch;
protected virtual void OnEnable() { } protected virtual void OnEnable() { }
protected virtual void OnDisable() { } protected virtual void OnDisable() { }

View File

@@ -8,11 +8,13 @@ namespace UXAssist.Common;
public static class Util public static class Util
{ {
public static Type[] GetTypesInNamespace(Assembly assembly, string nameSpace) public static Type[] GetTypesFiltered(Assembly assembly, Func<Type, bool> predicate)
{ {
return assembly.GetTypes().Where(t => string.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray(); return assembly.GetTypes().Where(predicate).ToArray();
} }
public static Type[] GetTypesInNamespace(Assembly assembly, string nameSpace) => GetTypesFiltered(assembly, t => string.Equals(t.Namespace, nameSpace, StringComparison.Ordinal));
public static byte[] LoadEmbeddedResource(string path, Assembly assembly = null) public static byte[] LoadEmbeddedResource(string path, Assembly assembly = null)
{ {
if (assembly == null) if (assembly == null)

View File

@@ -35,7 +35,6 @@ public static class BulletTimeWrapper
matcher.MatchForward(false, matcher.MatchForward(false,
new CodeMatch(OpCodes.Ldstr, "Increase game speed (max 4x)") new CodeMatch(OpCodes.Ldstr, "Increase game speed (max 4x)")
).Set(OpCodes.Ldstr, "Increase game speed (max 10x)"); ).Set(OpCodes.Ldstr, "Increase game speed (max 10x)");
UXAssist.Logger.LogDebug($"Patched IngameUI.Init @ {matcher.Pos}");
return matcher.InstructionEnumeration(); return matcher.InstructionEnumeration();
} }
@@ -45,7 +44,6 @@ public static class BulletTimeWrapper
matcher.MatchForward(false, matcher.MatchForward(false,
new CodeMatch(OpCodes.Ldc_R8, 240.0) new CodeMatch(OpCodes.Ldc_R8, 240.0)
).Set(OpCodes.Ldc_R8, 600.0); ).Set(OpCodes.Ldc_R8, 600.0);
UXAssist.Logger.LogDebug($"Patched IngameUI.OnSpeedButtonClick @ {matcher.Pos}");
return matcher.InstructionEnumeration(); return matcher.InstructionEnumeration();
} }

View File

@@ -7,19 +7,18 @@ using UXAssist.Common;
namespace UXAssist.Patches; namespace UXAssist.Patches;
public static class DysonSpherePatch public class DysonSpherePatch: PatchImpl<DysonSpherePatch>
{ {
public static ConfigEntry<bool> StopEjectOnNodeCompleteEnabled; public static ConfigEntry<bool> StopEjectOnNodeCompleteEnabled;
public static ConfigEntry<bool> OnlyConstructNodesEnabled; public static ConfigEntry<bool> OnlyConstructNodesEnabled;
public static ConfigEntry<int> AutoConstructMultiplier; public static ConfigEntry<int> AutoConstructMultiplier;
private static Harmony _dysonSpherePatch;
private static FieldInfo _totalNodeSpInfo, _totalFrameSpInfo, _totalCpInfo; private static FieldInfo _totalNodeSpInfo, _totalFrameSpInfo, _totalCpInfo;
public static void Init() public static void Init()
{ {
I18N.Add("[UXAssist] No node to fill", "[UXAssist] No node to fill", "[UXAssist] 无可建造节点"); I18N.Add("[UXAssist] No node to fill", "[UXAssist] No node to fill", "[UXAssist] 无可建造节点");
_dysonSpherePatch ??= Harmony.CreateAndPatchAll(typeof(DysonSpherePatch)); Enable(true);
StopEjectOnNodeCompleteEnabled.SettingChanged += (_, _) => StopEjectOnNodeComplete.Enable(StopEjectOnNodeCompleteEnabled.Value); StopEjectOnNodeCompleteEnabled.SettingChanged += (_, _) => StopEjectOnNodeComplete.Enable(StopEjectOnNodeCompleteEnabled.Value);
OnlyConstructNodesEnabled.SettingChanged += (_, _) => OnlyConstructNodes.Enable(OnlyConstructNodesEnabled.Value); OnlyConstructNodesEnabled.SettingChanged += (_, _) => OnlyConstructNodes.Enable(OnlyConstructNodesEnabled.Value);
StopEjectOnNodeComplete.Enable(StopEjectOnNodeCompleteEnabled.Value); StopEjectOnNodeComplete.Enable(StopEjectOnNodeCompleteEnabled.Value);
@@ -33,8 +32,7 @@ public static class DysonSpherePatch
{ {
StopEjectOnNodeComplete.Enable(false); StopEjectOnNodeComplete.Enable(false);
OnlyConstructNodes.Enable(false); OnlyConstructNodes.Enable(false);
_dysonSpherePatch?.UnpatchSelf(); Enable(false);
_dysonSpherePatch = null;
} }
public static void InitCurrentDysonSphere(int index) public static void InitCurrentDysonSphere(int index)

View File

@@ -12,7 +12,7 @@ using UXAssist.Common;
namespace UXAssist.Patches; namespace UXAssist.Patches;
public static class FactoryPatch public class FactoryPatch: PatchImpl<FactoryPatch>
{ {
public static ConfigEntry<bool> UnlimitInteractiveEnabled; public static ConfigEntry<bool> UnlimitInteractiveEnabled;
public static ConfigEntry<bool> RemoveSomeConditionEnabled; public static ConfigEntry<bool> RemoveSomeConditionEnabled;
@@ -29,8 +29,6 @@ public static class FactoryPatch
public static ConfigEntry<bool> BeltSignalsForBuyOutEnabled; public static ConfigEntry<bool> BeltSignalsForBuyOutEnabled;
private static PressKeyBind _doNotRenderEntitiesKey; private static PressKeyBind _doNotRenderEntitiesKey;
private static Harmony _factoryPatch;
public static void Init() public static void Init()
{ {
_doNotRenderEntitiesKey = KeyBindings.RegisterKeyBinding(new BuiltinKey _doNotRenderEntitiesKey = KeyBindings.RegisterKeyBinding(new BuiltinKey
@@ -71,11 +69,13 @@ public static class FactoryPatch
DragBuildPowerPoles.Enable(DragBuildPowerPolesEnabled.Value); DragBuildPowerPoles.Enable(DragBuildPowerPolesEnabled.Value);
BeltSignalsForBuyOut.Enable(BeltSignalsForBuyOutEnabled.Value); BeltSignalsForBuyOut.Enable(BeltSignalsForBuyOutEnabled.Value);
_factoryPatch ??= Harmony.CreateAndPatchAll(typeof(FactoryPatch)); Enable(true);
} }
public static void Uninit() public static void Uninit()
{ {
Enable(false);
RemoveSomeConditionBuild.Enable(false); RemoveSomeConditionBuild.Enable(false);
UnlimitInteractive.Enable(false); UnlimitInteractive.Enable(false);
NightLight.Enable(false); NightLight.Enable(false);
@@ -90,9 +90,6 @@ public static class FactoryPatch
DragBuildPowerPoles.Enable(false); DragBuildPowerPoles.Enable(false);
BeltSignalsForBuyOut.Enable(false); BeltSignalsForBuyOut.Enable(false);
BeltSignalsForBuyOut.UninitPersist(); BeltSignalsForBuyOut.UninitPersist();
_factoryPatch?.UnpatchSelf();
_factoryPatch = null;
} }
public static void OnUpdate() public static void OnUpdate()
@@ -1324,7 +1321,7 @@ public static class FactoryPatch
private static void UnfixProto() private static void UnfixProto()
{ {
if (GetPatch() == null || OldDragBuild.Count < 3 || DSPGame.IsMenuDemo) return; if (GetHarmony() == null || OldDragBuild.Count < 3 || DSPGame.IsMenuDemo) return;
var i = 0; var i = 0;
foreach (var id in PowerPoleIds) foreach (var id in PowerPoleIds)
{ {

View File

@@ -9,7 +9,7 @@ using UXAssist.Common;
namespace UXAssist.Patches; namespace UXAssist.Patches;
public static class GamePatch public class GamePatch: PatchImpl<GamePatch>
{ {
private const string GameWindowClass = "UnityWndClass"; private const string GameWindowClass = "UnityWndClass";
private static string _gameWindowTitle = "Dyson Sphere Program"; private static string _gameWindowTitle = "Dyson Sphere Program";
@@ -50,8 +50,6 @@ public static class GamePatch
} }
} }
private static Harmony _gamePatch;
public static void Init() public static void Init()
{ {
// Get profile name from command line arguments, and set window title accordingly // Get profile name from command line arguments, and set window title accordingly
@@ -104,19 +102,18 @@ public static class GamePatch
MouseCursorScaleUp.Enable(MouseCursorScaleUpMultiplier.Value > 1); MouseCursorScaleUp.Enable(MouseCursorScaleUpMultiplier.Value > 1);
// AutoSaveOpt.Enable(AutoSaveOptEnabled.Value); // AutoSaveOpt.Enable(AutoSaveOptEnabled.Value);
ConvertSavesFromPeace.Enable(ConvertSavesFromPeaceEnabled.Value); ConvertSavesFromPeace.Enable(ConvertSavesFromPeaceEnabled.Value);
_gamePatch ??= Harmony.CreateAndPatchAll(typeof(GamePatch)); Enable(true);
} }
public static void Uninit() public static void Uninit()
{ {
Enable(false);
LoadLastWindowRect.Enable(false); LoadLastWindowRect.Enable(false);
EnableWindowResize.Enable(false); EnableWindowResize.Enable(false);
MouseCursorScaleUp.reload = false; MouseCursorScaleUp.reload = false;
MouseCursorScaleUp.Enable(false); MouseCursorScaleUp.Enable(false);
// AutoSaveOpt.Enable(false); // AutoSaveOpt.Enable(false);
ConvertSavesFromPeace.Enable(false); ConvertSavesFromPeace.Enable(false);
_gamePatch?.UnpatchSelf();
_gamePatch = null;
} }
private static void RefreshSavePath() private static void RefreshSavePath()
@@ -341,21 +338,11 @@ public static class GamePatch
} }
/* /*
private static class AutoSaveOpt private class AutoSaveOpt: PatchImpl<AutoSaveOpt>
{ {
private static Harmony _patch; protected override void OnEnable()
public static void Enable(bool on)
{ {
if (on) Directory.CreateDirectory(GameConfig.gameSaveFolder + "AutoSaves/");
{
Directory.CreateDirectory(GameConfig.gameSaveFolder + "AutoSaves/");
_patch ??= Harmony.CreateAndPatchAll(typeof(AutoSaveOpt));
return;
}
_patch?.UnpatchSelf();
_patch = null;
} }
[HarmonyPrefix] [HarmonyPrefix]

View File

@@ -29,11 +29,10 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
private static bool _configWinInitialized; private static bool _configWinInitialized;
private static MyConfigWindow _configWin; private static MyConfigWindow _configWin;
private static Harmony _patch;
private static Harmony _persistPatch;
private static bool _initialized; private static bool _initialized;
private static PressKeyBind _toggleKey; private static PressKeyBind _toggleKey;
private static ConfigFile _dummyConfig; private static ConfigFile _dummyConfig;
private Type[] _patches;
#region IModCanSave #region IModCanSave
private const ushort ModSaveVersion = 1; private const ushort ModSaveVersion = 1;
@@ -152,47 +151,46 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
DysonSpherePatch.AutoConstructMultiplier = Config.Bind("DysonSphere", "AutoConstructMultiplier", 1, "Dyson Sphere auto-construct speed multiplier"); DysonSpherePatch.AutoConstructMultiplier = Config.Bind("DysonSphere", "AutoConstructMultiplier", 1, "Dyson Sphere auto-construct speed multiplier");
I18N.Init(); I18N.Init();
}
private void Start()
{
I18N.Add("UXAssist Config", "UXAssist Config", "UX助手设置"); I18N.Add("UXAssist Config", "UXAssist Config", "UX助手设置");
I18N.Add("KEYOpenUXAssistConfigWindow", "Open UXAssist Config Window", "打开UX助手设置面板"); I18N.Add("KEYOpenUXAssistConfigWindow", "Open UXAssist Config Window", "打开UX助手设置面板");
I18N.Add("KEYToggleAutoCruise", "Toggle auto-cruise", "切换自动巡航"); I18N.Add("KEYToggleAutoCruise", "Toggle auto-cruise", "切换自动巡航");
// UI Patch // UI Patches
_patch ??= Harmony.CreateAndPatchAll(typeof(UXAssist), PluginInfo.PLUGIN_GUID); UIPatch.Enable(true);
_persistPatch ??= Harmony.CreateAndPatchAll(typeof(Persist));
GameLogic.Init(); // Persistant Patches
Persist.Enable(true);
GameLogic.Enable(true);
MyWindowManager.Init(); MyWindowManager.Init();
UIConfigWindow.Init(); UIConfigWindow.Init();
Common.Util.GetTypesInNamespace(Assembly.GetExecutingAssembly(), "UXAssist.Patches") _patches = Common.Util.GetTypesInNamespace(Assembly.GetExecutingAssembly(), "UXAssist.Patches");
.Do(type => type.GetMethod("Init")?.Invoke(null, null)); _patches?.Do(type => type.GetMethod("Init")?.Invoke(null, null));
ModsCompat.AuxilaryfunctionWrapper.Init(_patch); var patch = UIPatch.GetHarmony();
ModsCompat.BulletTimeWrapper.Init(_patch); ModsCompat.AuxilaryfunctionWrapper.Init(patch);
ModsCompat.BulletTimeWrapper.Init(patch);
I18N.Apply(); I18N.Apply();
I18N.OnInitialized += RecreateConfigWindow; I18N.OnInitialized += RecreateConfigWindow;
}
private void Start()
{
_patches?.Do(type => type.GetMethod("Start")?.Invoke(null, null));
LogisticsPatch.Start(); LogisticsPatch.Start();
} }
private void OnDestroy() private void OnDestroy()
{ {
Common.Util.GetTypesInNamespace(Assembly.GetExecutingAssembly(), "UXAssist.Patches") _patches?.Do(type => type.GetMethod("Uninit")?.Invoke(null, null));
.Do(type => type.GetMethod("Uninit")?.Invoke(null, null));
MyWindowManager.Uninit(); MyWindowManager.Uninit();
GameLogic.Uninit(); GameLogic.Enable(false);
_patch?.UnpatchSelf(); Persist.Enable(false);
_patch = null; UIPatch.Enable(false);
_persistPatch?.UnpatchSelf();
_persistPatch = null;
} }
private void Update() private void Update()
@@ -245,66 +243,90 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
if (wasActive) ToggleConfigWindow(); if (wasActive) ToggleConfigWindow();
} }
// Add config button to main menu [PatchImplGuid(PluginInfo.PLUGIN_GUID)]
[HarmonyPostfix, HarmonyPatch(typeof(UIRoot), nameof(UIRoot.OpenMainMenuUI))] private class UIPatch: PatchImpl<UIPatch>
public static void UIRoot_OpenMainMenuUI_Postfix()
{ {
if (_initialized) return; private static GameObject _buttonOnPlanetGlobe;
// Add config button to main menu
[HarmonyPostfix, HarmonyPatch(typeof(UIRoot), nameof(UIRoot.OpenMainMenuUI))]
public static void UIRoot_OpenMainMenuUI_Postfix()
{ {
var mainMenu = UIRoot.instance.uiMainMenu; if (_initialized) return;
var src = mainMenu.newGameButton;
var parent = src.transform.parent;
var btn = Instantiate(src, parent);
btn.name = "button-cheatenabler-config";
var l = btn.text.GetComponent<Localizer>();
if (l != null)
{ {
l.stringKey = "UXAssist Config"; var mainMenu = UIRoot.instance.uiMainMenu;
l.translation = "UXAssist Config".Translate(); var src = mainMenu.newGameButton;
var parent = src.transform.parent;
var btn = Instantiate(src, parent);
btn.name = "button-cheatenabler-config";
var l = btn.text.GetComponent<Localizer>();
if (l != null)
{
l.stringKey = "UXAssist Config";
l.translation = "UXAssist Config".Translate();
}
btn.text.text = "UXAssist Config".Translate();
btn.text.fontSize = btn.text.fontSize * 7 / 8;
I18N.OnInitialized += () => { btn.text.text = "UXAssist Config".Translate(); };
var vec = ((RectTransform)mainMenu.exitButton.transform).anchoredPosition3D;
var vec2 = ((RectTransform)mainMenu.creditsButton.transform).anchoredPosition3D;
var transform1 = (RectTransform)btn.transform;
transform1.anchoredPosition3D = new Vector3(vec.x, vec.y + (vec.y - vec2.y) * 2, vec.z);
btn.button.onClick.RemoveAllListeners();
btn.button.onClick.AddListener(ToggleConfigWindow);
} }
btn.text.text = "UXAssist Config".Translate(); {
btn.text.fontSize = btn.text.fontSize * 7 / 8; var panel = UIRoot.instance.uiGame.planetGlobe;
I18N.OnInitialized += () => { btn.text.text = "UXAssist Config".Translate(); }; var src = panel.button2;
var vec = ((RectTransform)mainMenu.exitButton.transform).anchoredPosition3D; var sandboxMenu = UIRoot.instance.uiGame.sandboxMenu;
var vec2 = ((RectTransform)mainMenu.creditsButton.transform).anchoredPosition3D; var icon = sandboxMenu.categoryButtons[6].transform.Find("icon")?.GetComponent<Image>()?.sprite;
var transform1 = (RectTransform)btn.transform; var b = Instantiate(src, src.transform.parent);
transform1.anchoredPosition3D = new Vector3(vec.x, vec.y + (vec.y - vec2.y) * 2, vec.z); _buttonOnPlanetGlobe = b.gameObject;
btn.button.onClick.RemoveAllListeners(); var rect = (RectTransform)_buttonOnPlanetGlobe.transform;
btn.button.onClick.AddListener(ToggleConfigWindow); var btn = _buttonOnPlanetGlobe.GetComponent<UIButton>();
var img = _buttonOnPlanetGlobe.transform.Find("button-2/icon")?.GetComponent<Image>();
if (img != null)
{
img.sprite = icon;
}
if (_buttonOnPlanetGlobe != null && btn != null)
{
_buttonOnPlanetGlobe.name = "open-uxassist-config";
rect.localScale = new Vector3(0.6f, 0.6f, 0.6f);
rect.anchoredPosition3D = new Vector3(64f, -5f, 0f);
b.onClick.RemoveAllListeners();
btn.onClick += _ => { ToggleConfigWindow(); };
btn.tips.tipTitle = "UXAssist Config";
I18N.OnInitialized += () => { btn.tips.tipTitle = "UXAssist Config".Translate(); };
btn.tips.tipText = null;
btn.tips.corner = 9;
btn.tips.offset = new Vector2(-20f, -20f);
_buttonOnPlanetGlobe.SetActive(true);
}
}
_initialized = true;
} }
[HarmonyPostfix]
[HarmonyPatch(typeof(UIPlanetGlobe), nameof(UIPlanetGlobe.DistributeButtons))]
private static void UIPlanetGlobe_DistributeButtons_Postfix(UIPlanetGlobe __instance)
{ {
var panel = UIRoot.instance.uiGame.planetGlobe; if (_buttonOnPlanetGlobe == null) return;
var src = panel.button2; var rect = (RectTransform)_buttonOnPlanetGlobe.transform;
var sandboxMenu = UIRoot.instance.uiGame.sandboxMenu; if (__instance.dysonSphereSystemUnlocked || __instance.logisticsSystemUnlocked)
var icon = sandboxMenu.categoryButtons[6].transform.Find("icon")?.GetComponent<Image>()?.sprite;
var b = Instantiate(src, src.transform.parent);
var panelButtonGo = b.gameObject;
var rect = (RectTransform)panelButtonGo.transform;
var btn = panelButtonGo.GetComponent<UIButton>();
var img = panelButtonGo.transform.Find("button-2/icon")?.GetComponent<Image>();
if (img != null)
{ {
img.sprite = icon;
}
if (panelButtonGo != null && btn != null)
{
panelButtonGo.name = "open-uxassist-config";
rect.localScale = new Vector3(0.6f, 0.6f, 0.6f);
rect.anchoredPosition3D = new Vector3(64f, -5f, 0f); rect.anchoredPosition3D = new Vector3(64f, -5f, 0f);
b.onClick.RemoveAllListeners(); }
btn.onClick += _ => { ToggleConfigWindow(); }; else
btn.tips.tipTitle = "UXAssist Config"; {
I18N.OnInitialized += () => { btn.tips.tipTitle = "UXAssist Config".Translate(); }; rect.anchoredPosition3D = new Vector3(128f, -100f, 0f);
btn.tips.tipText = null;
btn.tips.corner = 9;
btn.tips.offset = new Vector2(-20f, -20f);
panelButtonGo.SetActive(true);
} }
} }
_initialized = true;
} }
private static class Persist private class Persist: PatchImpl<Persist>
{ {
// Check for noModifier while pressing hotkeys on build bar // Check for noModifier while pressing hotkeys on build bar
[HarmonyTranspiler] [HarmonyTranspiler]