1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-09 16:13:31 +08:00

Work in progress

This commit is contained in:
2023-09-28 03:21:46 +08:00
parent c092ae81bb
commit b3e216bc6a
12 changed files with 241 additions and 211 deletions

View File

@@ -11,14 +11,12 @@ public static class AbnormalDisabler
public static void Init() public static void Init()
{ {
if (_patch != null) return; _patch ??= Harmony.CreateAndPatchAll(typeof(AbnormalDisabler));
_patch = Harmony.CreateAndPatchAll(typeof(AbnormalDisabler));
} }
public static void Uninit() public static void Uninit()
{ {
if (_patch == null) return; _patch?.UnpatchSelf();
_patch.UnpatchSelf();
_patch = null; _patch = null;
} }

View File

@@ -72,13 +72,12 @@ public static class BirthPlanetPatch
FlatBirthPlanet.SettingChanged += (_, _) => PatchBirthThemeData(); FlatBirthPlanet.SettingChanged += (_, _) => PatchBirthThemeData();
HighLuminosityBirthStar.SettingChanged += (_, _) => PatchBirthThemeData(); HighLuminosityBirthStar.SettingChanged += (_, _) => PatchBirthThemeData();
PatchBirthThemeData(); PatchBirthThemeData();
_patch = Harmony.CreateAndPatchAll(typeof(BirthPlanetPatch)); _patch ??= Harmony.CreateAndPatchAll(typeof(BirthPlanetPatch));
} }
public static void Uninit() public static void Uninit()
{ {
if (_patch == null) return; _patch?.UnpatchSelf();
_patch.UnpatchSelf();
_patch = null; _patch = null;
} }

View File

@@ -63,9 +63,9 @@ public class CheatEnabler : BaseUnityPlugin
"Boost geothermal power"); "Boost geothermal power");
PlanetFunctions.PlayerActionsInGlobeViewEnabled = Config.Bind("Planet", "PlayerActionsInGlobeView", false, PlanetFunctions.PlayerActionsInGlobeViewEnabled = Config.Bind("Planet", "PlayerActionsInGlobeView", false,
"Enable player actions in globe view"); "Enable player actions in globe view");
ResourcePatch.InfiniteEnabled = Config.Bind("Planet", "AlwaysInfiniteResource", false, ResourcePatch.InfiniteResourceEnabled = Config.Bind("Planet", "AlwaysInfiniteResource", false,
"always infinite natural resource"); "always infinite natural resource");
ResourcePatch.FastEnabled = Config.Bind("Planet", "FastMining", false, ResourcePatch.FastMiningEnabled = Config.Bind("Planet", "FastMining", false,
"super-fast mining speed"); "super-fast mining speed");
WaterPumperPatch.Enabled = Config.Bind("Planet", "WaterPumpAnywhere", false, WaterPumperPatch.Enabled = Config.Bind("Planet", "WaterPumpAnywhere", false,
"Can pump water anywhere (while water type is not None)"); "Can pump water anywhere (while water type is not None)");
@@ -109,8 +109,8 @@ public class CheatEnabler : BaseUnityPlugin
I18N.Apply(); I18N.Apply();
// UI Patch // UI Patch
_windowPatch = Harmony.CreateAndPatchAll(typeof(UI.MyWindowManager.Patch)); _windowPatch ??= Harmony.CreateAndPatchAll(typeof(UI.MyWindowManager.Patch));
_patch = Harmony.CreateAndPatchAll(typeof(CheatEnabler)); _patch ??= Harmony.CreateAndPatchAll(typeof(CheatEnabler));
DevShortcuts.Init(); DevShortcuts.Init();
AbnormalDisabler.Init(); AbnormalDisabler.Init();
@@ -272,7 +272,6 @@ public class CheatEnabler : BaseUnityPlugin
} }
else else
{ {
UIRoot.instance.uiGame.ShutPlayerInventory();
_configWin.Open(); _configWin.Open();
} }
} }

View File

@@ -12,7 +12,7 @@ public static class DevShortcuts
public static void Init() public static void Init()
{ {
_patch = Harmony.CreateAndPatchAll(typeof(DevShortcuts)); _patch ??= Harmony.CreateAndPatchAll(typeof(DevShortcuts));
Enabled.SettingChanged += (_, _) => Enabled.SettingChanged += (_, _) =>
{ {
if (_test != null) _test.active = Enabled.Value; if (_test != null) _test.active = Enabled.Value;
@@ -21,8 +21,7 @@ public static class DevShortcuts
public static void Uninit() public static void Uninit()
{ {
if (_patch == null) return; _patch?.UnpatchSelf();
_patch.UnpatchSelf();
_patch = null; _patch = null;
} }

View File

@@ -8,6 +8,7 @@ namespace CheatEnabler;
public static class DysonSpherePatch public static class DysonSpherePatch
{ {
public static ConfigEntry<bool> StopEjectOnNodeCompleteEnabled;
public static ConfigEntry<bool> SkipBulletEnabled; public static ConfigEntry<bool> SkipBulletEnabled;
public static ConfigEntry<bool> SkipAbsorbEnabled; public static ConfigEntry<bool> SkipAbsorbEnabled;
public static ConfigEntry<bool> QuickAbsorbEnabled; public static ConfigEntry<bool> QuickAbsorbEnabled;
@@ -20,18 +21,20 @@ public static class DysonSpherePatch
private static Harmony _ejectAnywayPatch; private static Harmony _ejectAnywayPatch;
private static Harmony _overclockEjector; private static Harmony _overclockEjector;
private static Harmony _overclockSilo; private static Harmony _overclockSilo;
private static Harmony _patch; private static Harmony _dysonSpherePatch;
private static bool _instantAbsorb; private static bool _instantAbsorb;
public static void Init() public static void Init()
{ {
_patch ??= Harmony.CreateAndPatchAll(typeof(DysonSpherePatch)); _dysonSpherePatch ??= Harmony.CreateAndPatchAll(typeof(DysonSpherePatch));
StopEjectOnNodeCompleteEnabled.SettingChanged += (_, _) => StopEjectOnNodeComplete.Enable(StopEjectOnNodeCompleteEnabled.Value);
SkipBulletEnabled.SettingChanged += (_, _) => SkipBulletValueChanged(); SkipBulletEnabled.SettingChanged += (_, _) => SkipBulletValueChanged();
SkipAbsorbEnabled.SettingChanged += (_, _) => SkipAbsorbValueChanged(); SkipAbsorbEnabled.SettingChanged += (_, _) => SkipAbsorbValueChanged();
QuickAbsorbEnabled.SettingChanged += (_, _) => QuickAbsorbValueChanged(); QuickAbsorbEnabled.SettingChanged += (_, _) => QuickAbsorbValueChanged();
EjectAnywayEnabled.SettingChanged += (_, _) => EjectAnywayValueChanged(); EjectAnywayEnabled.SettingChanged += (_, _) => EjectAnywayValueChanged();
OverclockEjectorEnabled.SettingChanged += (_, _) => OverclockEjectorValueChanged(); OverclockEjectorEnabled.SettingChanged += (_, _) => OverclockEjectorValueChanged();
OverclockSiloEnabled.SettingChanged += (_, _) => OverclockSiloValueChanged(); OverclockSiloEnabled.SettingChanged += (_, _) => OverclockSiloValueChanged();
StopEjectOnNodeComplete.Enable(StopEjectOnNodeCompleteEnabled.Value);
SkipBulletValueChanged(); SkipBulletValueChanged();
SkipAbsorbValueChanged(); SkipAbsorbValueChanged();
QuickAbsorbValueChanged(); QuickAbsorbValueChanged();
@@ -42,6 +45,7 @@ public static class DysonSpherePatch
public static void Uninit() public static void Uninit()
{ {
StopEjectOnNodeComplete.Enable(false);
_skipBulletPatch?.UnpatchSelf(); _skipBulletPatch?.UnpatchSelf();
_skipBulletPatch = null; _skipBulletPatch = null;
_skipAbsorbPatch?.UnpatchSelf(); _skipAbsorbPatch?.UnpatchSelf();
@@ -54,8 +58,8 @@ public static class DysonSpherePatch
_overclockEjector = null; _overclockEjector = null;
_overclockSilo?.UnpatchSelf(); _overclockSilo?.UnpatchSelf();
_overclockSilo = null; _overclockSilo = null;
_patch?.UnpatchSelf(); _dysonSpherePatch?.UnpatchSelf();
_patch = null; _dysonSpherePatch = null;
} }
private static void SkipBulletValueChanged() private static void SkipBulletValueChanged()
@@ -191,10 +195,10 @@ public static class DysonSpherePatch
} }
ds.RemoveLayer(index); ds.RemoveLayer(index);
} }
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(DysonNode), nameof(DysonNode.ConstructCp))] [HarmonyPatch(typeof(DysonNode), nameof(DysonNode.ConstructCp))]
private static IEnumerable<CodeInstruction> DysonNode_ConstructCp_Patch(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> DysonSpherePatch_DysonNode_ConstructCp_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{ {
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
matcher.MatchBack(false, matcher.MatchBack(false,
@@ -220,6 +224,136 @@ public static class DysonSpherePatch
return matcher.InstructionEnumeration(); return matcher.InstructionEnumeration();
} }
private static class StopEjectOnNodeComplete
{
private static Harmony _patch;
private static HashSet<int>[] _nodeForAbsorb;
public static void Enable(bool on)
{
if (on)
{
InitNodeForAbsorb();
_patch ??= Harmony.CreateAndPatchAll(typeof(StopEjectOnNodeComplete));
}
else
{
_patch?.UnpatchSelf();
_patch = null;
_nodeForAbsorb = null;
}
}
private static void InitNodeForAbsorb()
{
_nodeForAbsorb = new HashSet<int>[GameMain.data.galaxy.starCount];
foreach (var sphere in GameMain.data.dysonSpheres)
{
if (sphere?.layersSorted == null) continue;
var starIndex = sphere.starData.index;
foreach (var layer in sphere.layersSorted)
{
if (layer == null) continue;
for (var i = layer.nodeCursor - 1; i > 0; i--)
{
var node = layer.nodePool[i];
if (node == null || node.id != i) continue;
SetNodeForAbsorb(starIndex, layer.id, node.id, node.sp == node.spMax && node.cpReqOrder > 0);
}
}
}
}
private static void SetNodeForAbsorb(int index, int layerId, int nodeId, bool canAbsorb)
{
ref var comp = ref _nodeForAbsorb[index];
comp ??= new HashSet<int>();
var idx = nodeId * 10 + layerId;
if (canAbsorb)
comp.Add(idx);
else
comp.Remove(idx);
}
private static void UpdateNodeForAbsorb(DysonNode node)
{
var shells = node.shells;
if (shells.Count == 0) return;
SetNodeForAbsorb(shells[0].dysonSphere.starData.index, node.layerId, node.id, node.sp == node.spMax && node.cpReqOrder > 0);
}
private static bool AnyNodeForAbsorb(int starIndex)
{
var comp = _nodeForAbsorb[starIndex];
return comp != null && comp.Count > 0;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameMain), nameof(GameMain.Begin))]
private static void GameMain_Begin_Postfix()
{
InitNodeForAbsorb();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(DysonNode), nameof(DysonNode.RecalcCpReq))]
private static void DysonNode_RecalcCpReq_Postfix(DysonNode __instance)
{
UpdateNodeForAbsorb(__instance);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(DysonSphereLayer), nameof(DysonSphereLayer.RemoveDysonNode))]
private static void DysonSphereLayer_RemoveDysonNode_Prefix(DysonSphereLayer __instance, int nodeId)
{
SetNodeForAbsorb(__instance.starData.index, __instance.id, nodeId, false);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(DysonSphere), nameof(DysonSphere.ResetNew))]
private static void DysonSphere_ResetNew_Prefix(DysonSphere __instance)
{
var starIndex = __instance.starData.index;
if (_nodeForAbsorb[starIndex] == null) return;
_nodeForAbsorb[starIndex].Clear();
_nodeForAbsorb[starIndex] = null;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(EjectorComponent), nameof(EjectorComponent.InternalUpdate))]
private static IEnumerable<CodeInstruction> EjectorComponent_InternalUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
var matcher = new CodeMatcher(instructions, generator);
var label1 = generator.DefineLabel();
matcher.Start().InsertAndAdvance(
new CodeInstruction(OpCodes.Ldarg_2),
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(DysonSwarm), nameof(DysonSwarm.starData))),
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(StarData), nameof(StarData.index))),
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(StopEjectOnNodeComplete), nameof(StopEjectOnNodeComplete.AnyNodeForAbsorb))),
new CodeInstruction(OpCodes.Brtrue, label1)
);
matcher.Labels.Add(label1);
return matcher.InstructionEnumeration();
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(DysonNode), nameof(DysonNode.ConstructCp))]
private static IEnumerable<CodeInstruction> DysonNode_ConstructCp_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
var matcher = new CodeMatcher(instructions, generator);
matcher.Start().MatchForward(false,
new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(DysonNode), nameof(DysonNode.sp)))
).Advance(1);
var labels = matcher.Labels;
matcher.Labels = new List<Label>();
matcher.Insert(
new CodeInstruction(OpCodes.Ldarg_0).WithLabels(labels),
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(StopEjectOnNodeComplete), nameof(StopEjectOnNodeComplete.UpdateNodeForAbsorb)))
);
return matcher.InstructionEnumeration();
}
}
private static class SkipBulletPatch private static class SkipBulletPatch
{ {
private static long _sailLifeTime; private static long _sailLifeTime;
@@ -294,7 +428,7 @@ public static class DysonSpherePatch
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(EjectorComponent), nameof(EjectorComponent.InternalUpdate))] [HarmonyPatch(typeof(EjectorComponent), nameof(EjectorComponent.InternalUpdate))]
private static IEnumerable<CodeInstruction> EjectorComponent_InternalUpdate_Patch(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> EjectorComponent_InternalUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{ {
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false, matcher.MatchForward(false,
@@ -407,7 +541,7 @@ public static class DysonSpherePatch
{ {
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(DysonNode), nameof(DysonNode.OrderConstructCp))] [HarmonyPatch(typeof(DysonNode), nameof(DysonNode.OrderConstructCp))]
private static IEnumerable<CodeInstruction> DysonNode_OrderConstructCp_Patch(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> DysonNode_OrderConstructCp_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{ {
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false, matcher.MatchForward(false,
@@ -422,7 +556,7 @@ public static class DysonSpherePatch
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(DysonSwarm), nameof(DysonSwarm.AbsorbSail))] [HarmonyPatch(typeof(DysonSwarm), nameof(DysonSwarm.AbsorbSail))]
private static IEnumerable<CodeInstruction> DysonSwarm_AbsorbSail_Patch(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> DysonSwarm_AbsorbSail_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{ {
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
var label1 = generator.DefineLabel(); var label1 = generator.DefineLabel();
@@ -472,7 +606,7 @@ public static class DysonSpherePatch
{ {
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(DysonSphereLayer), nameof(DysonSphereLayer.GameTick))] [HarmonyPatch(typeof(DysonSphereLayer), nameof(DysonSphereLayer.GameTick))]
private static IEnumerable<CodeInstruction> DysonSphereLayer_GameTick_Patch(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> DysonSphereLayer_GameTick_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{ {
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
/* Insert absorption functions on beginning */ /* Insert absorption functions on beginning */
@@ -506,7 +640,7 @@ public static class DysonSpherePatch
for (var i = layer.nodeCursor - 1; i > 0; i--) for (var i = layer.nodeCursor - 1; i > 0; i--)
{ {
var node = layer.nodePool[i]; var node = layer.nodePool[i];
if (node == null || node.id != i || node.sp != node.spMax) continue; if (node == null || node.id != i || node.sp < node.spMax) continue;
var req = node._cpReq; var req = node._cpReq;
var ordered = node.cpOrdered; var ordered = node.cpOrdered;
if (req <= ordered) continue; if (req <= ordered) continue;
@@ -526,7 +660,7 @@ public static class DysonSpherePatch
{ {
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(EjectorComponent), nameof(EjectorComponent.InternalUpdate))] [HarmonyPatch(typeof(EjectorComponent), nameof(EjectorComponent.InternalUpdate))]
private static IEnumerable<CodeInstruction> EjectorComponent_InternalUpdate_Patch(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> EjectorComponent_InternalUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{ {
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false, matcher.MatchForward(false,
@@ -557,7 +691,7 @@ public static class DysonSpherePatch
{ {
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(EjectorComponent), nameof(EjectorComponent.InternalUpdate))] [HarmonyPatch(typeof(EjectorComponent), nameof(EjectorComponent.InternalUpdate))]
private static IEnumerable<CodeInstruction> EjectAndSiloComponent_InternalUpdate_Patch(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> EjectAndSiloComponent_InternalUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{ {
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
/* Add a multiply to ejector speed */ /* Add a multiply to ejector speed */
@@ -580,7 +714,7 @@ public static class DysonSpherePatch
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(UIEjectorWindow), nameof(UIEjectorWindow._OnUpdate))] [HarmonyPatch(typeof(UIEjectorWindow), nameof(UIEjectorWindow._OnUpdate))]
private static IEnumerable<CodeInstruction> UIEjectAndSiloWindow__OnUpdate_Patch(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> UIEjectAndSiloWindow__OnUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{ {
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
/* Add a multiply to ejector speed */ /* Add a multiply to ejector speed */
@@ -610,7 +744,7 @@ public static class DysonSpherePatch
{ {
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(SiloComponent), nameof(SiloComponent.InternalUpdate))] [HarmonyPatch(typeof(SiloComponent), nameof(SiloComponent.InternalUpdate))]
private static IEnumerable<CodeInstruction> EjectAndSiloComponent_InternalUpdate_Patch(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> EjectAndSiloComponent_InternalUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{ {
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
/* Add a multiply to ejector speed */ /* Add a multiply to ejector speed */
@@ -633,7 +767,7 @@ public static class DysonSpherePatch
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(UISiloWindow), nameof(UISiloWindow._OnUpdate))] [HarmonyPatch(typeof(UISiloWindow), nameof(UISiloWindow._OnUpdate))]
private static IEnumerable<CodeInstruction> UIEjectAndSiloWindow__OnUpdate_Patch(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> UIEjectAndSiloWindow__OnUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{ {
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
/* Add a multiply to ejector speed */ /* Add a multiply to ejector speed */

View File

@@ -30,33 +30,33 @@ public static class FactoryPatch
public static void Init() public static void Init()
{ {
if (_factoryPatch != null) return; if (_factoryPatch != null) return;
ImmediateEnabled.SettingChanged += (_, _) => ImmediateValueChanged(); ImmediateEnabled.SettingChanged += (_, _) => ImmediateBuild.Enable(ImmediateEnabled.Value);
ArchitectModeEnabled.SettingChanged += (_, _) => ArchitectModeValueChanged(); ArchitectModeEnabled.SettingChanged += (_, _) => ArchitectMode.Enable(ArchitectModeEnabled.Value);
UnlimitInteractiveEnabled.SettingChanged += (_, _) => UnlimitInteractiveValueChanged(); UnlimitInteractiveEnabled.SettingChanged += (_, _) => UnlimitInteractive.Enable(UnlimitInteractiveEnabled.Value);
RemoveSomeConditionEnabled.SettingChanged += (_, _) => RemoveSomeConditionValueChanged(); RemoveSomeConditionEnabled.SettingChanged += (_, _) => RemoveSomeConditionBuild.Enable(RemoveSomeConditionEnabled.Value);
NoConditionEnabled.SettingChanged += (_, _) => NoConditionValueChanged(); NoConditionEnabled.SettingChanged += (_, _) => NoConditionBuild.Enable(NoConditionEnabled.Value);
NoCollisionEnabled.SettingChanged += (_, _) => NoCollisionValueChanged(); NoCollisionEnabled.SettingChanged += (_, _) => NoCollisionValueChanged();
BeltSignalGeneratorEnabled.SettingChanged += (_, _) => BeltSignalGeneratorValueChanged(); BeltSignalGeneratorEnabled.SettingChanged += (_, _) => BeltSignalGenerator.Enable(BeltSignalGeneratorEnabled.Value);
BeltSignalNumberAltFormat.SettingChanged += (_, _) => { BeltSignalGenerator.OnAltFormatChanged(); }; BeltSignalNumberAltFormat.SettingChanged += (_, _) => { BeltSignalGenerator.OnAltFormatChanged(); };
NightLightEnabled.SettingChanged += (_, _) => NightLightValueChanged(); NightLightEnabled.SettingChanged += (_, _) => NightLight.Enable(NightLightEnabled.Value);
RemovePowerSpaceLimitEnabled.SettingChanged += (_, _) => RemovePowerSpaceLimitValueChanged(); RemovePowerSpaceLimitEnabled.SettingChanged += (_, _) => RemovePowerSpaceLimit.Enable(RemovePowerSpaceLimitEnabled.Value);
BoostWindPowerEnabled.SettingChanged += (_, _) => BoostWindPowerValueChanged(); BoostWindPowerEnabled.SettingChanged += (_, _) => BoostWindPower.Enable(BoostWindPowerEnabled.Value);
BoostSolarPowerEnabled.SettingChanged += (_, _) => BoostSolarPowerValueChanged(); BoostSolarPowerEnabled.SettingChanged += (_, _) => BoostSolarPower.Enable(BoostSolarPowerEnabled.Value);
BoostFuelPowerEnabled.SettingChanged += (_, _) => BoostFuelPowerValueChanged(); BoostFuelPowerEnabled.SettingChanged += (_, _) => BoostFuelPower.Enable(BoostFuelPowerEnabled.Value);
BoostGeothermalPowerEnabled.SettingChanged += (_, _) => BoostGeothermalPowerValueChanged(); BoostGeothermalPowerEnabled.SettingChanged += (_, _) => BoostGeothermalPower.Enable(BoostGeothermalPowerEnabled.Value);
ImmediateValueChanged(); ImmediateBuild.Enable(ImmediateEnabled.Value);
ArchitectModeValueChanged(); ArchitectMode.Enable(ArchitectModeEnabled.Value);
UnlimitInteractiveValueChanged(); UnlimitInteractive.Enable(UnlimitInteractiveEnabled.Value);
RemoveSomeConditionValueChanged(); RemoveSomeConditionBuild.Enable(RemoveSomeConditionEnabled.Value);
NoConditionValueChanged(); NoConditionBuild.Enable(NoConditionEnabled.Value);
NoCollisionValueChanged(); NoCollisionValueChanged();
BeltSignalGeneratorValueChanged(); BeltSignalGenerator.Enable(BeltSignalGeneratorEnabled.Value);
NightLightValueChanged(); NightLight.Enable(NightLightEnabled.Value);
RemovePowerSpaceLimitValueChanged(); RemovePowerSpaceLimit.Enable(RemovePowerSpaceLimitEnabled.Value);
BoostWindPowerValueChanged(); BoostWindPower.Enable(BoostWindPowerEnabled.Value);
BoostSolarPowerValueChanged(); BoostSolarPower.Enable(BoostSolarPowerEnabled.Value);
BoostFuelPowerValueChanged(); BoostFuelPower.Enable(BoostFuelPowerEnabled.Value);
BoostGeothermalPowerValueChanged(); BoostGeothermalPower.Enable(BoostGeothermalPowerEnabled.Value);
_factoryPatch = Harmony.CreateAndPatchAll(typeof(FactoryPatch)); _factoryPatch = Harmony.CreateAndPatchAll(typeof(FactoryPatch));
} }
@@ -78,31 +78,6 @@ public static class FactoryPatch
BoostGeothermalPower.Enable(false); BoostGeothermalPower.Enable(false);
} }
private static void ImmediateValueChanged()
{
ImmediateBuild.Enable(ImmediateEnabled.Value);
}
private static void ArchitectModeValueChanged()
{
ArchitectMode.Enable(ArchitectModeEnabled.Value);
}
private static void UnlimitInteractiveValueChanged()
{
UnlimitInteractive.Enable(UnlimitInteractiveEnabled.Value);
}
private static void RemoveSomeConditionValueChanged()
{
RemoveSomeConditionBuild.Enable(RemoveSomeConditionEnabled.Value);
}
private static void NoConditionValueChanged()
{
NoConditionBuild.Enable(NoConditionEnabled.Value);
}
private static void NoCollisionValueChanged() private static void NoCollisionValueChanged()
{ {
var coll = ColliderPool.instance; var coll = ColliderPool.instance;
@@ -112,41 +87,6 @@ public static class FactoryPatch
obj.gameObject.SetActive(!NoCollisionEnabled.Value); obj.gameObject.SetActive(!NoCollisionEnabled.Value);
} }
private static void BeltSignalGeneratorValueChanged()
{
BeltSignalGenerator.Enable(BeltSignalGeneratorEnabled.Value);
}
private static void NightLightValueChanged()
{
NightLight.Enable(NightLightEnabled.Value);
}
private static void RemovePowerSpaceLimitValueChanged()
{
RemovePowerSpaceLimit.Enable(RemovePowerSpaceLimitEnabled.Value);
}
private static void BoostWindPowerValueChanged()
{
BoostWindPower.Enable(BoostWindPowerEnabled.Value);
}
private static void BoostSolarPowerValueChanged()
{
BoostSolarPower.Enable(BoostSolarPowerEnabled.Value);
}
private static void BoostFuelPowerValueChanged()
{
BoostFuelPower.Enable(BoostFuelPowerEnabled.Value);
}
private static void BoostGeothermalPowerValueChanged()
{
BoostGeothermalPower.Enable(BoostGeothermalPowerEnabled.Value);
}
public static void ArrivePlanet(PlanetFactory factory) public static void ArrivePlanet(PlanetFactory factory)
{ {
var imm = ImmediateEnabled.Value; var imm = ImmediateEnabled.Value;

View File

@@ -12,21 +12,16 @@ public static class PlanetFunctions
public static void Init() public static void Init()
{ {
PlayerActionsInGlobeViewEnabled.SettingChanged += (_, _) => PlayerActionInGlobeViewValueChanged(); PlayerActionsInGlobeViewEnabled.SettingChanged += (_, _) => PlayerActionsInGlobeView.Enable(PlayerActionsInGlobeViewEnabled.Value);
PlayerActionInGlobeViewValueChanged(); PlayerActionsInGlobeView.Enable(PlayerActionsInGlobeViewEnabled.Value);
} }
public static void Uninit() public static void Uninit()
{ {
PlayerActionInGlobeView.Enable(false); PlayerActionsInGlobeView.Enable(false);
} }
private static void PlayerActionInGlobeViewValueChanged() public static class PlayerActionsInGlobeView
{
PlayerActionInGlobeView.Enable(PlayerActionsInGlobeViewEnabled.Value);
}
public static class PlayerActionInGlobeView
{ {
private static Harmony _patch; private static Harmony _patch;
@@ -34,7 +29,7 @@ public static class PlanetFunctions
{ {
if (on) if (on)
{ {
_patch ??= Harmony.CreateAndPatchAll(typeof(PlayerActionInGlobeView)); _patch ??= Harmony.CreateAndPatchAll(typeof(PlayerActionsInGlobeView));
return; return;
} }
_patch?.UnpatchSelf(); _patch?.UnpatchSelf();

View File

@@ -7,71 +7,40 @@ namespace CheatEnabler;
public static class ResourcePatch public static class ResourcePatch
{ {
public static ConfigEntry<bool> InfiniteEnabled; public static ConfigEntry<bool> InfiniteResourceEnabled;
public static ConfigEntry<bool> FastEnabled; public static ConfigEntry<bool> FastMiningEnabled;
private static Harmony _infinitePatch;
private static Harmony _fastPatch;
public static void Init() public static void Init()
{ {
InfiniteEnabled.SettingChanged += (_, _) => InfiniteValueChanged(); InfiniteResourceEnabled.SettingChanged += (_, _) => InfiniteResource.Enable(InfiniteResourceEnabled.Value);
FastEnabled.SettingChanged += (_, _) => FastValueChanged(); FastMiningEnabled.SettingChanged += (_, _) => FastMining.Enable(FastMiningEnabled.Value);
InfiniteValueChanged(); InfiniteResource.Enable(InfiniteResourceEnabled.Value);
FastValueChanged(); FastMining.Enable(FastMiningEnabled.Value);
} }
public static void Uninit() public static void Uninit()
{ {
if (_infinitePatch != null) InfiniteResource.Enable(false);
{ FastMining.Enable(false);
_infinitePatch.UnpatchSelf();
_infinitePatch = null;
}
if (_fastPatch != null)
{
_fastPatch.UnpatchSelf();
_fastPatch = null;
}
}
private static void InfiniteValueChanged()
{
if (InfiniteEnabled.Value)
{
if (_infinitePatch != null)
{
return;
}
_infinitePatch = Harmony.CreateAndPatchAll(typeof(InfiniteResource));
}
else if (_infinitePatch != null)
{
_infinitePatch.UnpatchSelf();
_infinitePatch = null;
}
}
private static void FastValueChanged()
{
if (FastEnabled.Value)
{
if (_fastPatch != null)
{
return;
}
_fastPatch = Harmony.CreateAndPatchAll(typeof(FastMining));
}
else if (_fastPatch != null)
{
_fastPatch.UnpatchSelf();
_fastPatch = null;
}
} }
private static class InfiniteResource private static class InfiniteResource
{ {
private static Harmony _patch;
public static void Enable(bool on)
{
if (on)
{
_patch ??= Harmony.CreateAndPatchAll(typeof(InfiniteResource));
}
else
{
_patch?.UnpatchSelf();
_patch = null;
}
}
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(FactorySystem), "GameTick", typeof(long), typeof(bool))] [HarmonyPatch(typeof(FactorySystem), "GameTick", typeof(long), typeof(bool))]
[HarmonyPatch(typeof(FactorySystem), "GameTick", typeof(long), typeof(bool), typeof(int), typeof(int), [HarmonyPatch(typeof(FactorySystem), "GameTick", typeof(long), typeof(bool), typeof(int), typeof(int),
@@ -103,6 +72,21 @@ public static class ResourcePatch
private static class FastMining private static class FastMining
{ {
private static Harmony _patch;
public static void Enable(bool on)
{
if (on)
{
_patch ??= Harmony.CreateAndPatchAll(typeof(FastMining));
}
else
{
_patch?.UnpatchSelf();
_patch = null;
}
}
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(FactorySystem), "GameTick", typeof(long), typeof(bool))] [HarmonyPatch(typeof(FactorySystem), "GameTick", typeof(long), typeof(bool))]
[HarmonyPatch(typeof(FactorySystem), "GameTick", typeof(long), typeof(bool), typeof(int), typeof(int), [HarmonyPatch(typeof(FactorySystem), "GameTick", typeof(long), typeof(bool), typeof(int), typeof(int),

View File

@@ -20,8 +20,7 @@ public static class TechPatch
public static void Uninit() public static void Uninit()
{ {
if (_patch == null) return; _patch?.UnpatchSelf();
_patch.UnpatchSelf();
_patch = null; _patch = null;
} }
@@ -29,16 +28,11 @@ public static class TechPatch
{ {
if (Enabled.Value) if (Enabled.Value)
{ {
if (_patch != null) _patch ??= Harmony.CreateAndPatchAll(typeof(TechPatch));
{
return;
}
_patch = Harmony.CreateAndPatchAll(typeof(TechPatch));
} }
else if (_patch != null) else
{ {
_patch.UnpatchSelf(); _patch?.UnpatchSelf();
_patch = null; _patch = null;
} }
} }

View File

@@ -18,8 +18,7 @@ public static class TerraformPatch
public static void Uninit() public static void Uninit()
{ {
if (_patch == null) return; _patch?.UnpatchSelf();
_patch.UnpatchSelf();
_patch = null; _patch = null;
} }
@@ -27,16 +26,11 @@ public static class TerraformPatch
{ {
if (Enabled.Value) if (Enabled.Value)
{ {
if (_patch != null) _patch ??= Harmony.CreateAndPatchAll(typeof(TerraformPatch));
{
return;
}
_patch = Harmony.CreateAndPatchAll(typeof(TerraformPatch));
} }
else if (_patch != null) else
{ {
_patch.UnpatchSelf(); _patch?.UnpatchSelf();
_patch = null; _patch = null;
} }
} }

View File

@@ -166,9 +166,9 @@ public class UIConfigWindow : UI.MyWindowWithTabs
y = 10f; y = 10f;
UI.MyCheckBox.CreateCheckBox(x, y, tab3, PlanetFunctions.PlayerActionsInGlobeViewEnabled, "Enable player actions in globe view"); UI.MyCheckBox.CreateCheckBox(x, y, tab3, PlanetFunctions.PlayerActionsInGlobeViewEnabled, "Enable player actions in globe view");
y += 36f; y += 36f;
UI.MyCheckBox.CreateCheckBox(x, y, tab3, ResourcePatch.InfiniteEnabled, "Infinite Natural Resources"); UI.MyCheckBox.CreateCheckBox(x, y, tab3, ResourcePatch.InfiniteResourceEnabled, "Infinite Natural Resources");
y += 36f; y += 36f;
UI.MyCheckBox.CreateCheckBox(x, y, tab3, ResourcePatch.FastEnabled, "Fast Mining"); UI.MyCheckBox.CreateCheckBox(x, y, tab3, ResourcePatch.FastMiningEnabled, "Fast Mining");
y += 36f; y += 36f;
UI.MyCheckBox.CreateCheckBox(x, y, tab3, WaterPumperPatch.Enabled, "Pump Anywhere"); UI.MyCheckBox.CreateCheckBox(x, y, tab3, WaterPumperPatch.Enabled, "Pump Anywhere");
y += 36f; y += 36f;

View File

@@ -17,8 +17,7 @@ public static class WaterPumperPatch
public static void Uninit() public static void Uninit()
{ {
if (_patch == null) return; _patch?.UnpatchSelf();
_patch.UnpatchSelf();
_patch = null; _patch = null;
} }
@@ -26,16 +25,11 @@ public static class WaterPumperPatch
{ {
if (Enabled.Value) if (Enabled.Value)
{ {
if (_patch != null) _patch ??= Harmony.CreateAndPatchAll(typeof(WaterPumperPatch));
{
return;
}
_patch = Harmony.CreateAndPatchAll(typeof(WaterPumperPatch));
} }
else if (_patch != null) else
{ {
_patch.UnpatchSelf(); _patch?.UnpatchSelf();
_patch = null; _patch = null;
} }
} }