From e798055f7a283e9a3d9f6e6c0dfafc8bb984a618 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Tue, 12 Sep 2023 21:05:54 +0800 Subject: [PATCH] WIP --- CheatEnabler/AbnormalDiabler.cs | 1 + CheatEnabler/BirthPlanetPatch.cs | 2 +- CheatEnabler/BuildPatch.cs | 1 + CheatEnabler/DevShortcuts.cs | 58 +++++++++++------- CheatEnabler/README.md | 101 +++++++++++++++++-------------- CheatEnabler/UIConfigWindow.cs | 8 +-- 6 files changed, 100 insertions(+), 71 deletions(-) diff --git a/CheatEnabler/AbnormalDiabler.cs b/CheatEnabler/AbnormalDiabler.cs index 586c631..1f38cb7 100644 --- a/CheatEnabler/AbnormalDiabler.cs +++ b/CheatEnabler/AbnormalDiabler.cs @@ -11,6 +11,7 @@ public static class AbnormalDisabler public static void Init() { + if (_patch != null) return; _patch = Harmony.CreateAndPatchAll(typeof(AbnormalDisabler)); } diff --git a/CheatEnabler/BirthPlanetPatch.cs b/CheatEnabler/BirthPlanetPatch.cs index 2e6a358..e7485ec 100644 --- a/CheatEnabler/BirthPlanetPatch.cs +++ b/CheatEnabler/BirthPlanetPatch.cs @@ -72,7 +72,7 @@ public static class BirthPlanetPatch FlatBirthPlanet.SettingChanged += (_, _) => PatchBirthThemeData(); HighLuminosityBirthStar.SettingChanged += (_, _) => PatchBirthThemeData(); PatchBirthThemeData(); - _patch = Harmony.CreateAndPatchAll(typeof(DevShortcuts)); + _patch = Harmony.CreateAndPatchAll(typeof(BirthPlanetPatch)); } public static void Uninit() diff --git a/CheatEnabler/BuildPatch.cs b/CheatEnabler/BuildPatch.cs index 88b3cbd..6fb7cb1 100644 --- a/CheatEnabler/BuildPatch.cs +++ b/CheatEnabler/BuildPatch.cs @@ -18,6 +18,7 @@ public static class BuildPatch public static void Init() { + if (_patch != null) return; ImmediateEnabled.SettingChanged += (_, _) => ImmediateValueChanged(); NoCostEnabled.SettingChanged += (_, _) => NoCostValueChanged(); NoConditionEnabled.SettingChanged += (_, _) => NoConditionValueChanged(); diff --git a/CheatEnabler/DevShortcuts.cs b/CheatEnabler/DevShortcuts.cs index bdedf1d..2c1c3eb 100644 --- a/CheatEnabler/DevShortcuts.cs +++ b/CheatEnabler/DevShortcuts.cs @@ -1,4 +1,6 @@ -using BepInEx.Configuration; +using System.Collections.Generic; +using System.Reflection.Emit; +using BepInEx.Configuration; using HarmonyLib; namespace CheatEnabler; @@ -6,10 +8,15 @@ public static class DevShortcuts { public static ConfigEntry Enabled; private static Harmony _patch; + private static PlayerAction_Test _test; public static void Init() { _patch = Harmony.CreateAndPatchAll(typeof(DevShortcuts)); + Enabled.SettingChanged += (_, _) => + { + if (_test != null) _test.active = Enabled.Value; + }; } public static void Uninit() @@ -30,32 +37,41 @@ public static class DevShortcuts newActions[i] = __instance.actions[i]; } - var test = new PlayerAction_Test(); - test.Init(__instance.player); - newActions[cnt] = test; + _test = new PlayerAction_Test(); + _test.Init(__instance.player); + _test.active = Enabled.Value; + newActions[cnt] = _test; __instance.actions = newActions; - - Enabled.SettingChanged += (_, _) => - { - if (!Enabled.Value) - { - test.active = false; - } - }; } [HarmonyPostfix] [HarmonyPatch(typeof(PlayerAction_Test), "GameTick")] private static void PlayerAction_Test_GameTick_Postfix(PlayerAction_Test __instance) { - if (!Enabled.Value) return; - var lastActive = __instance.active; __instance.Update(); - if (lastActive != __instance.active) - { - UIRealtimeTip.PopupAhead( - (lastActive ? "Developer Mode Shortcuts Disabled" : "Developer Mode Shortcuts Enabled").Translate(), - false); - } } -} \ No newline at end of file + + [HarmonyTranspiler] + [HarmonyPatch(typeof(PlayerAction_Test), nameof(PlayerAction_Test.Update))] + private static IEnumerable PlayerAction_Test_Update_Transpiler(IEnumerable instructions, ILGenerator generator) + { + var matcher = new CodeMatcher(instructions, generator); + matcher.End().MatchBack(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PlayerAction_Test), nameof(PlayerAction_Test.active))) + ); + var pos = matcher.Pos; + /* Remove Shift+F4 part of the method */ + matcher.Start().RemoveInstructions(pos); + matcher.Start().MatchForward(false, + new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(GameMain), "get_sandboxToolsEnabled")), + new CodeMatch(OpCodes.Ldc_I4_0), + new CodeMatch(OpCodes.Ceq) + ); + var labels = matcher.Labels; + matcher.SetInstructionAndAdvance( + new CodeInstruction(OpCodes.Ldc_I4_1).WithLabels(labels) + ).RemoveInstructions(2); + return matcher.InstructionEnumeration(); + } +} diff --git a/CheatEnabler/README.md b/CheatEnabler/README.md index fa46f9e..0555c1e 100644 --- a/CheatEnabler/README.md +++ b/CheatEnabler/README.md @@ -5,51 +5,62 @@ ## Usage -* Disable abnormal determinants (Disable all sanity checks, and can get achievements on using Console and Developer Mode - shortcuts). -* Shift+F4 to switch Developer Mode on/off. - * 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. -* Each function can be enabled individually in config file. +* Press `` LAlt+`(BackQuote) `` to call up the config panel. You can change the shortcut on the panel. +* There are also buttons on title screen and planet minimap area to call up the config panel. +* Features: + + Enable Dev Shortcuts (check config panel for usage) + + Disable Abnormal Checks + + Build: + + Finish build immediately + + Infinite buildings + + Build without condition + + No collision + + Planet: + + Infinite Natural Resources + + Fast Mining + + Pump Anywhere + + Terraform without enought sands + + Re-intialize planet (without reseting veins) + + Quick dismantle all buildings (without drops) + + Dyson Sphere: + + Skip bullet period + + Skip absorption period + + Quick absorb + + Eject anyway + + Re-initialize Dyson Spheres + + Quick dismantle Dyson Shells + + Birth star: + + Rare resources on birth planet + + Solid flat on birth planet + + High luminosity for birth star ## 使用说明 -* 屏蔽游戏异常检测 (使用任何作弊功能都不影响正常获得成就)。 -* Shift+F4 切换开发模式开关 - * 按小键盘1:获得所有物品并扩展背包 - * 按小键盘2:加快行走速度及采集速度,加快能量恢复速度 - * 按小键盘3:将地基铺设整个星球并掩埋所有矿物 - * 按小键盘4:建设机器人 +1 - * 按小键盘5:建设机器人满级 - * 按小键盘6:解锁当前科技 - * 按小键盘7:解锁驱动技术I - * 按小键盘8:解锁驱动技术II 最大化能量 - * 按小键盘9:机甲曲速解锁 - * 按小键盘0:物流站通过传送带出物品无消耗 - * 左ctrl + T:解锁所有非升级科技 - * 左ctrl + A:重置所有本地成就 - * 左ctrl + Q:增加各项元数据10000点 - * 左ctrl + W:进入沙盒模式 - * 小键盘乘号 *:给手上的物品喷涂加速剂 - * 小键盘除号 /:清除手上的物品加速剂 - * PageDown:记录摄像机当前的Pose - * PageUp:用记录的Pose锁定摄像机 -* 总是无限资源。 -* 各功能可以在配置文件中单独开关。 +* 按 `` 左Alt+`(反引号) `` 键呼出主面板,可以在面板上修改快捷键。 +* 标题界面和行星小地图旁也有按钮呼出主面板。 +* 功能: + + 启用开发模式快捷键(使用说明见设置面板) + + 屏蔽异常检测 + + 建造: + + 建造秒完成 + + 无限建筑 + + 无条件建造 + + 无碰撞 + + 行星: + + 自然资源采集不消耗 + + 高速采集 + + 平地抽水 + + 沙土不够时依然可以整改地形 + + 初始化本行星(不重置矿脉) + + 快速拆除所有建筑(不掉落) + + 戴森球: + + 跳过子弹阶段 + + 跳过吸收阶段 + + 快速吸收 + + 全球弹射 + + 初始化戴森球 + + 快速拆除戴森壳 + + 母星系: + + 母星有稀有资源 + + 母星是纯平的 + + 母星系恒星高亮 \ No newline at end of file diff --git a/CheatEnabler/UIConfigWindow.cs b/CheatEnabler/UIConfigWindow.cs index f7f58f5..05a2c78 100644 --- a/CheatEnabler/UIConfigWindow.cs +++ b/CheatEnabler/UIConfigWindow.cs @@ -24,15 +24,17 @@ public class UIConfigWindow : UI.MyWindowWithTabs I18N.Add("Infinite Natural Resources", "Infinite Natural Resources", "自然资源采集不消耗"); I18N.Add("Fast Mining", "Fast Mining", "高速采集"); I18N.Add("Pump Anywhere", "Pump Anywhere", "平地抽水"); + I18N.Add("Initialize This Planet", "Initialize This Planet", "初始化本行星"); + I18N.Add("Dismantle All Buildings", "Dismantle All Buildings", "拆除所有建筑"); I18N.Add("Dyson Sphere", "Dyson Sphere", "戴森球"); I18N.Add("Skip bullet period", "Skip bullet period", "跳过子弹阶段"); I18N.Add("Skip absorption period", "Skip absorption period", "跳过吸收阶段"); I18N.Add("Quick absorb", "Quick absorb", "快速吸收"); I18N.Add("Eject anyway", "Eject anyway", "全球弹射"); + I18N.Add("Terraform without enough sands", "Terraform without enough sands", "沙土不够时依然可以整改地形"); I18N.Add("Initialize Dyson Sphere", "Initialize Dyson Sphere", "初始化戴森球"); I18N.Add("Click to dismantle selected layer", "Click to dismantle selected layer", "点击拆除对应的戴森壳"); I18N.Add("Birth", "Birth Sys", "母星系"); - I18N.Add("Terraform without enought sands", "Terraform without enough sands", "沙土不够时依然可以整改地形"); I18N.Add("Silicon/Titanium on birth planet", "Silicon/Titanium on birth planet", "母星有硅和钛"); I18N.Add("Fire ice on birth planet", "Fire ice on birth planet", "母星有可燃冰"); I18N.Add("Kimberlite on birth planet", "Kimberlite on birth planet", "母星有金伯利矿"); @@ -43,8 +45,6 @@ public class UIConfigWindow : UI.MyWindowWithTabs I18N.Add("Unipolar magnet on birth planet", "Unipolar magnet on birth planet", "母星有单极磁石"); I18N.Add("Birth planet is solid flat (no water at all)", "Birth planet is solid flat (no water at all)", "母星是纯平的(没有水)"); I18N.Add("Birth star has high luminosity", "Birth star has high luminosity", "母星系恒星高亮"); - I18N.Add("Initialize This Planet", "Initialize This Planet", "初始化本行星"); - I18N.Add("Dismantle All Buildings", "Dismantle All Buildings", "拆除所有建筑"); I18N.Apply(); } @@ -94,7 +94,7 @@ public class UIConfigWindow : UI.MyWindowWithTabs y += 36f; UI.MyCheckBox.CreateCheckBox(x, y, tab3, WaterPumperPatch.Enabled, "Pump Anywhere"); y += 36f; - UI.MyCheckBox.CreateCheckBox(x, y, tab3, TerraformPatch.Enabled, "Terraform without enought sands"); + UI.MyCheckBox.CreateCheckBox(x, y, tab3, TerraformPatch.Enabled, "Terraform without enough sands"); x = 300f; y = 10f; AddButton(x, y, tab3, "矿物掩埋标题", 16, "button-bury-all", () =>