1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-09 02:53:29 +08:00

CheatEnabler 2.2.4

This commit is contained in:
2023-09-26 02:46:40 +08:00
parent 58e45dc186
commit ee883bc66e
7 changed files with 159 additions and 29 deletions

View File

@@ -61,6 +61,8 @@ public class CheatEnabler : BaseUnityPlugin
"Boost fuel power");
FactoryPatch.BoostGeothermalPowerEnabled = Config.Bind("Build", "BoostGeothermalPower", false,
"Boost geothermal power");
PlanetFunctions.PlayerActionsInGlobeViewEnabled = Config.Bind("Planet", "PlayerActionsInGlobeView", false,
"Enable player actions in globe view");
ResourcePatch.InfiniteEnabled = Config.Bind("Planet", "AlwaysInfiniteResource", false,
"always infinite natural resource");
ResourcePatch.FastEnabled = Config.Bind("Planet", "FastMining", false,
@@ -114,6 +116,7 @@ public class CheatEnabler : BaseUnityPlugin
AbnormalDisabler.Init();
TechPatch.Init();
FactoryPatch.Init();
PlanetFunctions.Init();
ResourcePatch.Init();
WaterPumperPatch.Init();
TerraformPatch.Init();
@@ -128,6 +131,7 @@ public class CheatEnabler : BaseUnityPlugin
TerraformPatch.Uninit();
WaterPumperPatch.Uninit();
ResourcePatch.Uninit();
PlanetFunctions.Uninit();
FactoryPatch.Uninit();
TechPatch.Uninit();
AbnormalDisabler.Uninit();
@@ -252,7 +256,7 @@ public class CheatEnabler : BaseUnityPlugin
);
return matcher.InstructionEnumeration();
}
private static void ToggleConfigWindow()
{
if (!_configWinInitialized)

View File

@@ -5,7 +5,7 @@
<TargetFramework>net472</TargetFramework>
<BepInExPluginGuid>org.soardev.cheatenabler</BepInExPluginGuid>
<Description>DSP MOD - CheatEnabler</Description>
<Version>2.2.3</Version>
<Version>2.2.4</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<PackageId>CheatEnabler</PackageId>

View File

@@ -26,8 +26,6 @@ public static class FactoryPatch
public static ConfigEntry<bool> BoostGeothermalPowerEnabled;
private static Harmony _factoryPatch;
private static Harmony _removeSomeConditionPatch;
private static Harmony _noConditionPatch;
public static void Init()
{
@@ -66,12 +64,10 @@ public static class FactoryPatch
{
_factoryPatch?.UnpatchSelf();
_factoryPatch = null;
_removeSomeConditionPatch?.UnpatchSelf();
_removeSomeConditionPatch = null;
_noConditionPatch?.UnpatchSelf();
_noConditionPatch = null;
ImmediateBuild.Enable(false);
ArchitectMode.Enable(false);
RemoveSomeConditionBuild.Enable(false);
NoConditionBuild.Enable(false);
UnlimitInteractive.Enable(false);
BeltSignalGenerator.Enable(false);
NightLight.Enable(false);
@@ -99,24 +95,12 @@ public static class FactoryPatch
private static void RemoveSomeConditionValueChanged()
{
if (RemoveSomeConditionEnabled.Value)
{
_removeSomeConditionPatch ??= Harmony.CreateAndPatchAll(typeof(RemoveSomeConditionBuild));
return;
}
_removeSomeConditionPatch?.UnpatchSelf();
_removeSomeConditionPatch = null;
RemoveSomeConditionBuild.Enable(RemoveSomeConditionEnabled.Value);
}
private static void NoConditionValueChanged()
{
if (NoConditionEnabled.Value)
{
_noConditionPatch ??= Harmony.CreateAndPatchAll(typeof(NoConditionBuild));
return;
}
_noConditionPatch?.UnpatchSelf();
_noConditionPatch = null;
NoConditionBuild.Enable(NoConditionEnabled.Value);
}
private static void NoCollisionValueChanged()
@@ -498,6 +482,17 @@ public static class FactoryPatch
private static class RemoveSomeConditionBuild
{
private static Harmony _patch;
public static void Enable(bool on)
{
if (on)
{
_patch ??= Harmony.CreateAndPatchAll(typeof(RemoveSomeConditionBuild));
return;
}
_patch?.UnpatchSelf();
_patch = null;
}
[HarmonyTranspiler, HarmonyPriority(Priority.First)]
[HarmonyPatch(typeof(BuildTool_BlueprintPaste), nameof(BuildTool_BlueprintPaste.CheckBuildConditions))]
[HarmonyPatch(typeof(BuildTool_Click), nameof(BuildTool_Click.CheckBuildConditions))]
@@ -594,6 +589,18 @@ public static class FactoryPatch
private static class NoConditionBuild
{
private static Harmony _noConditionPatch;
public static void Enable(bool on)
{
if (on)
{
_noConditionPatch ??= Harmony.CreateAndPatchAll(typeof(NoConditionBuild));
return;
}
_noConditionPatch?.UnpatchSelf();
_noConditionPatch = null;
}
[HarmonyTranspiler, HarmonyPriority(Priority.Last)]
[HarmonyPatch(typeof(BuildTool_Addon), nameof(BuildTool_Addon.CheckBuildConditions))]
// [HarmonyPatch(typeof(BuildTool_Click), nameof(BuildTool_Click.CheckBuildConditions))]

View File

@@ -1,9 +1,117 @@
using System.Threading;
using System.Collections.Generic;
using System.Reflection.Emit;
using System.Threading;
using BepInEx.Configuration;
using HarmonyLib;
using Random = UnityEngine.Random;
namespace CheatEnabler;
public static class PlanetFunctions
{
public static ConfigEntry<bool> PlayerActionsInGlobeViewEnabled;
public static void Init()
{
PlayerActionsInGlobeViewEnabled.SettingChanged += (_, _) => PlayerActionInGlobeViewValueChanged();
PlayerActionInGlobeViewValueChanged();
}
public static void Uninit()
{
PlayerActionInGlobeView.Enable(false);
}
private static void PlayerActionInGlobeViewValueChanged()
{
PlayerActionInGlobeView.Enable(PlayerActionsInGlobeViewEnabled.Value);
}
public static class PlayerActionInGlobeView
{
private static Harmony _patch;
public static void Enable(bool on)
{
if (on)
{
_patch ??= Harmony.CreateAndPatchAll(typeof(PlayerActionInGlobeView));
return;
}
_patch?.UnpatchSelf();
_patch = null;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(VFInput), nameof(VFInput.UpdateGameStates))]
private static IEnumerable<CodeInstruction> VFInput_UpdateGameStates_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
var matcher = new CodeMatcher(instructions, generator);
/* remove UIGame.viewMode != EViewMode.Globe in two places:
* so search for:
* ldsfld bool VFInput::viewMode
* ldc.i4.3
*/
matcher.MatchForward(false,
new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(typeof(UIGame), nameof(UIGame.viewMode))),
new CodeMatch(OpCodes.Ldc_I4_3)
);
matcher.Repeat(codeMatcher =>
{
var labels = codeMatcher.Labels;
codeMatcher.Labels = new List<Label>();
codeMatcher.RemoveInstructions(3).Labels.AddRange(labels);
});
return matcher.InstructionEnumeration();
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(PlayerController), nameof(PlayerController.GetInput))]
private static IEnumerable<CodeInstruction> PlayerController_GetInput_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
var matcher = new CodeMatcher(instructions, generator);
// replace `UIGame.viewMode >= EViewMode.Globe` with `UIGame.viewMode >= EViewMode.Starmap`
matcher.MatchForward(false,
new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(typeof(UIGame), nameof(UIGame.viewMode))),
new CodeMatch(OpCodes.Ldc_I4_3)
).Advance(1).Opcode = OpCodes.Ldc_I4_4;
return matcher.InstructionEnumeration();
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(PlayerAction_Rts), nameof(PlayerAction_Rts.GameTick))]
private static IEnumerable<CodeInstruction> PlayerAction_Rts_GameTick_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
var matcher = new CodeMatcher(instructions, generator);
var local1 = generator.DeclareLocal(typeof(bool));
// var local1 = UIGame.viewMode == 3;
matcher.MatchForward(false,
new CodeMatch(OpCodes.Call, AccessTools.PropertyGetter(typeof(VFInput), nameof(VFInput.rtsMoveCameraConflict))),
new CodeMatch(OpCodes.Stloc_1)
);
var labels = matcher.Labels;
matcher.Labels = new List<Label>();
matcher.InsertAndAdvance(
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(UIGame), nameof(UIGame.viewMode))).WithLabels(labels),
new CodeInstruction(OpCodes.Ldc_I4_3),
new CodeInstruction(OpCodes.Ceq),
new CodeInstruction(OpCodes.Stloc, local1)
);
// Add extra condition:
// VFInput.rtsMoveCameraConflict / VFInput.rtsMineCameraConflict `|| local1`
matcher.MatchForward(false,
new CodeMatch(instr => instr.opcode == OpCodes.Ldloc_1 || instr.opcode == OpCodes.Ldloc_2)
);
matcher.Repeat(codeMatcher =>
{
matcher.Advance(1);
matcher.InsertAndAdvance(
new CodeInstruction(OpCodes.Ldloc, local1),
new CodeInstruction(OpCodes.Or)
);
});
return matcher.InstructionEnumeration();
}
}
public static void DismantleAll(bool toBag)
{
var player = GameMain.mainPlayer;

View File

@@ -4,6 +4,9 @@
#### 添加一些作弊功能,同时屏蔽异常检测
## Changlog
* 2.2.4
+ New function: `Enable player actions in globe view`
+ Fix UI bug
* 2.2.3
+ New function: `Remove some build conditions`
+ Fix compatibility with some mods
@@ -54,6 +57,7 @@
+ Remove space limit between wind turbines and solar panels
+ Boost power generations for kinds of power generators
+ Planet:
+ Enable player actions in globe view
+ Infinite Natural Resources
+ Fast Mining
+ Pump Anywhere
@@ -84,6 +88,9 @@
* [LSTM](https://github.com/hetima/DSP_LSTM) & [PlanetFinder](https://github.com/hetima/DSP_PlanetFinder): UI implementations
## 更新日志
* 2.2.4
+ 新功能:`在行星视图中允许玩家操作`
+ 修复了UI显示问题
* 2.2.3
+ 新功能:`移除部分不影响游戏逻辑的建造条件`
+ 修复了与一些mod的兼容性问题
@@ -134,6 +141,7 @@
+ 风力发电机和太阳能板无间距限制
+ 提升各种发电设备发电量
+ 行星:
+ 在行星视图中允许玩家操作
+ 自然资源采集不消耗
+ 高速采集
+ 平地抽水

View File

@@ -45,11 +45,12 @@ public class UIConfigWindow : UI.MyWindowWithTabs
I18N.Add("Boost fuel power 2", "(x20,000 for deuteron, x10,000 for antimatter)", "(氘核燃料棒x20,000反物质燃料棒x10,000)");
I18N.Add("Boost geothermal power", "Boost geothermal power(x50,000)", "提升地热发电(x50,000)");
I18N.Add("Planet", "Planet", "行星");
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("Enable player actions in globe view", "Enable player actions in globe view", "在行星视图中允许玩家操作");
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", "跳过吸收阶段");
@@ -163,6 +164,8 @@ public class UIConfigWindow : UI.MyWindowWithTabs
var tab3 = AddTab(236f, 2, _windowTrans, "Planet");
x = 0f;
y = 10f;
UI.MyCheckBox.CreateCheckBox(x, y, tab3, PlanetFunctions.PlayerActionsInGlobeViewEnabled, "Enable player actions in globe view");
y += 36f;
UI.MyCheckBox.CreateCheckBox(x, y, tab3, ResourcePatch.InfiniteEnabled, "Infinite Natural Resources");
y += 36f;
UI.MyCheckBox.CreateCheckBox(x, y, tab3, ResourcePatch.FastEnabled, "Fast Mining");

View File

@@ -1,6 +1,6 @@
{
"name": "CheatEnabler",
"version_number": "2.2.3",
"version_number": "2.2.4",
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/CheatEnabler",
"description": "Add various cheat functions while disabling abnormal determinants / 添加一些作弊功能,同时屏蔽异常检测",
"dependencies": [