From f8836c4c8867881afb67ae82bb3f8d9f1d6d732e Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Sun, 28 Aug 2022 10:58:03 +0800 Subject: [PATCH] rename DevShortcuts to CheatEnabler and add more cheat functions --- CheatEnabler/CheatEnabler.cs | 123 ++++++++++++++++++ .../CheatEnabler.csproj | 7 +- DSP_Mods.sln | 2 +- DevShortcuts/DevShortcuts.cs | 42 ------ LogisticMiner/LogisticMiner.csproj | 4 +- README.md | 42 +++--- 6 files changed, 152 insertions(+), 68 deletions(-) create mode 100644 CheatEnabler/CheatEnabler.cs rename DevShortcuts/DevShortcuts.csproj => CheatEnabler/CheatEnabler.csproj (81%) delete mode 100644 DevShortcuts/DevShortcuts.cs diff --git a/CheatEnabler/CheatEnabler.cs b/CheatEnabler/CheatEnabler.cs new file mode 100644 index 0000000..dc5c945 --- /dev/null +++ b/CheatEnabler/CheatEnabler.cs @@ -0,0 +1,123 @@ +using System.Collections.Generic; +using System.Reflection; +using System.Reflection.Emit; +using BepInEx; +using HarmonyLib; + +namespace CheatEnabler; + +[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] +public class CheatEnabler : BaseUnityPlugin +{ + private new static readonly BepInEx.Logging.ManualLogSource Logger = + BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME); + + private bool _devShortcuts = true; + private bool _disableAbnormalChecks = true; + private bool _alwaysInfiniteResource = true; + + private void Awake() + { + _devShortcuts = Config.Bind("General", "DevShortcuts", _devShortcuts, "enable DevMode shortcuts").Value; + _disableAbnormalChecks = Config.Bind("General", "DisableAbnormalChecks", _disableAbnormalChecks, + "disable all abnormal checks").Value; + _alwaysInfiniteResource = Config.Bind("General", "AlwaysInfiniteResource", _alwaysInfiniteResource, + "always infinite resource").Value; + if (_devShortcuts) + { + Harmony.CreateAndPatchAll(typeof(DevShortcuts)); + } + if (_disableAbnormalChecks) + { + Harmony.CreateAndPatchAll(typeof(AbnormalDisabler)); + } + if (_alwaysInfiniteResource) + { + Harmony.CreateAndPatchAll(typeof(AlwaysInfiniteResource)); + } + } + + private class DevShortcuts + { + [HarmonyPostfix] + [HarmonyPatch(typeof(PlayerController), "Init")] + private static void PlayerControllerInit(PlayerController __instance) + { + var cnt = __instance.actions.Length; + var newActions = new PlayerAction[cnt + 1]; + for (var i = 0; i < cnt; i++) + { + newActions[i] = __instance.actions[i]; + } + + var test = new PlayerAction_Test(); + test.Init(__instance.player); + newActions[cnt] = test; + __instance.actions = newActions; + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(PlayerAction_Test), "GameTick")] + private static void PlayerAction_TestGameTick(PlayerAction_Test __instance) + { + __instance.Update(); + } + } + + private class AbnormalDisabler + { + [HarmonyPrefix] + [HarmonyPatch(typeof(AbnormalityLogic), "NotifyBeforeGameSave")] + [HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnAssemblerRecipePick")] + [HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnGameBegin")] + [HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnMechaForgeTaskComplete")] + [HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnUnlockTech")] + [HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnUseConsole")] + private static bool DisableAbnormalLogic() + { + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(AbnormalityLogic), "InitDeterminators")] + private static bool DisableAbnormalDeterminators(ref Dictionary ___determinators) + { + ___determinators = new Dictionary(); + return false; + } + } + + private class AlwaysInfiniteResource + { + private static FieldInfo _rmulField = AccessTools.Field(typeof(GameDesc), nameof(GameDesc.resourceMultiplier)); + + [HarmonyTranspiler] + [HarmonyPatch(typeof(GameDesc), "isInfiniteResource", MethodType.Getter)] + private static IEnumerable ForceInfiniteResource(IEnumerable instructions) + { + yield return new CodeInstruction(OpCodes.Ldc_I4, 1); + yield return new CodeInstruction(OpCodes.Ret); + } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(FactorySystem), "GameTick", typeof(long), typeof(bool))] + [HarmonyPatch(typeof(FactorySystem), "GameTick", typeof(long), typeof(bool), typeof(int), typeof(int), + typeof(int))] + [HarmonyPatch(typeof(UIMinerWindow), "_OnUpdate")] + [HarmonyPatch(typeof(UIVeinCollectorPanel), "_OnUpdate")] + private static IEnumerable Transpiler(IEnumerable instructions) + { + foreach (var instruction in instructions) + { + if (instruction.opcode == OpCodes.Ldc_R4 && instruction.operand.Equals(99.5f)) + { + yield return new CodeInstruction(OpCodes.Ldc_R4, 0f); + } + else + { + yield return instruction; + } + } + } + } +} \ No newline at end of file diff --git a/DevShortcuts/DevShortcuts.csproj b/CheatEnabler/CheatEnabler.csproj similarity index 81% rename from DevShortcuts/DevShortcuts.csproj rename to CheatEnabler/CheatEnabler.csproj index 3eda80a..3c2e0a7 100644 --- a/DevShortcuts/DevShortcuts.csproj +++ b/CheatEnabler/CheatEnabler.csproj @@ -2,12 +2,13 @@ netstandard2.0 - DevShortcuts - org.soardev.devshortcuts - DSP MOD - DevShortcuts + org.soardev.cheatenabler + DSP MOD - CheatEnabler 1.0.0 true latest + CheatEnabler + CheatEnabler diff --git a/DSP_Mods.sln b/DSP_Mods.sln index e9ea4a2..0f2d97d 100644 --- a/DSP_Mods.sln +++ b/DSP_Mods.sln @@ -1,6 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevShortcuts", "DevShortcuts\DevShortcuts.csproj", "{F9F16B62-D1D3-466B-BE22-E64B9EA957C2}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CheatEnabler", "CheatEnabler\CheatEnabler.csproj", "{F9F16B62-D1D3-466B-BE22-E64B9EA957C2}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LogisticMiner", "LogisticMiner\LogisticMiner.csproj", "{7149D717-C913-4153-9425-38CB9D087F83}" EndProject diff --git a/DevShortcuts/DevShortcuts.cs b/DevShortcuts/DevShortcuts.cs deleted file mode 100644 index 9657bac..0000000 --- a/DevShortcuts/DevShortcuts.cs +++ /dev/null @@ -1,42 +0,0 @@ -using BepInEx; -using HarmonyLib; - -namespace DevShortcuts; - -[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] -public class DevShortcuts : BaseUnityPlugin -{ - private new static readonly BepInEx.Logging.ManualLogSource Logger = BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME); - - private bool _cfgEnabled = true; - - private void Awake() - { - _cfgEnabled = Config.Bind("General", "Enabled", _cfgEnabled, "enable/disable this plugin").Value; - if (!_cfgEnabled) return; - Harmony.CreateAndPatchAll(typeof(DevShortcuts)); - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(PlayerController), "Init")] - private static void PlayerControllerInit(ref PlayerAction[] ___actions, Player ___player) - { - var cnt = ___actions.Length; - var newActions = new PlayerAction[cnt + 1]; - for (int i = 0; i < cnt; i++) - { - newActions[i] = ___actions[i]; - } - var test = new PlayerAction_Test(); - test.Init(___player); - newActions[cnt] = test; - ___actions = newActions; - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(PlayerAction_Test), "GameTick")] - private static void PlayerAction_TestGameTick(PlayerAction_Test __instance, long timei) - { - __instance.Update(); - } -} diff --git a/LogisticMiner/LogisticMiner.csproj b/LogisticMiner/LogisticMiner.csproj index 0b5c358..ae7757b 100644 --- a/LogisticMiner/LogisticMiner.csproj +++ b/LogisticMiner/LogisticMiner.csproj @@ -5,7 +5,7 @@ LogisticMiner org.soardev.logisticminer DSP MOD - LogisticMiner - 1.0.0 + 0.1.0 true latest @@ -17,7 +17,7 @@ - + diff --git a/README.md b/README.md index 6358d95..1d67865 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,28 @@ # DSP Mods by Soar Qin -## [DevShortcuts](DevShortcuts) -### Restore Developer Mode keyboard Shortcuts hidden in original game codes, as following: +## [CheatEnabler](CheatEnabler) +### Enable cheat functions as below +* Disable abnormal determinants (Allow get achievements on using Console and DevShortcuts) * Shift+F4 to switch Developer Mode on/off (no message, tip or sounds on switch). -* Numpad 1: Gets all items and extends bag. -* Numpad 2: Boosts walk speed, gathering speed and mecha energy restoration. -* Numpad 3: Fills planet with foundations and bury all veins. -* Numpad 4: +1 construction drone. -* Numpad 5: Upgrades drone engine tech to full. -* Numpad 6: Unlocks researching tech. -* Numpad 7: Unlocks Drive Engine 1. -* Numpad 8: Unlocks Drive Engine 2 and maximize energy. -* Numpad 9: Unlocks ability to warp. -* Numpad 0: No costs for Logistic Storages' output. -* LCtrl + T: Unlocks all techs (not upgrades) -* LCtrl + A: Resets all local achievements. -* LCtrl + Q: Adds 10000 to every metadata. -* LCtrl + W: Enters Sandbox Mode. -* Numpad *: Proliferates items on hand. -* Numpad /: Removes proliferations from items on hand. -* PageDown: Remembers Pose of game camera. -* PageUp: Locks game camera using remembered Pose. + * Numpad 1: Gets all items and extends bag. + * Numpad 2: Boosts walk speed, gathering speed and mecha energy restoration. + * Numpad 3: Fills planet with foundations and bury all veins. + * Numpad 4: +1 construction drone. + * Numpad 5: Upgrades drone engine tech to full. + * Numpad 6: Unlocks researching tech. + * Numpad 7: Unlocks Drive Engine 1. + * Numpad 8: Unlocks Drive Engine 2 and maximize energy. + * Numpad 9: Unlocks ability to warp. + * Numpad 0: No costs for Logistic Storages' output. + * LCtrl + T: Unlocks all techs (not upgrades) + * LCtrl + A: Resets all local achievements. + * LCtrl + Q: Adds 10000 to every metadata. + * LCtrl + W: Enters Sandbox Mode. + * Numpad *: Proliferates items on hand. + * Numpad /: Removes proliferations from items on hand. + * PageDown: Remembers Pose of game camera. + * PageUp: Locks game camera using remembered Pose. +* Always infinite resource ## [LogisticMiner](LogisticMiner)