mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 02:53:29 +08:00
WIP
This commit is contained in:
@@ -71,18 +71,12 @@ public class CheatEnabler : BaseUnityPlugin
|
||||
"Birth planet is solid flat (no water)").Value;
|
||||
_highLuminosityBirthStar = Config.Bind("Birth", "HighLuminosityBirthStar", _highLuminosityBirthStar,
|
||||
"Birth star has high luminosity").Value;
|
||||
_terraformAnyway = Config.Bind("General", "TerraformAnyway", _terraformAnyway,
|
||||
"Can do terraform without enough sands").Value;
|
||||
TerraformPatch.Enabled = Config.Bind("General", "TerraformAnyway", false,
|
||||
"Can do terraform without enough sands");
|
||||
|
||||
I18N.Init();
|
||||
I18N.Add("CheatEnabler Config", "CheatEnabler Config", "CheatEnabler设置");
|
||||
I18N.Add("General", "General", "常规");
|
||||
I18N.Add("Enable Dev Shortcuts", "Enable Dev Shortcuts", "启用开发模式快捷键");
|
||||
I18N.Add("Disable Abnormal Checks", "Disable Abnormal Checks", "关闭数据异常检查");
|
||||
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.Apply();
|
||||
|
||||
// UI Patch
|
||||
_windowPatch = Harmony.CreateAndPatchAll(typeof(UI.MyWindowManager.Patch));
|
||||
@@ -114,14 +108,12 @@ public class CheatEnabler : BaseUnityPlugin
|
||||
Harmony.CreateAndPatchAll(typeof(BirthPlanetCheat));
|
||||
}
|
||||
|
||||
if (_terraformAnyway)
|
||||
{
|
||||
Harmony.CreateAndPatchAll(typeof(TerraformAnyway));
|
||||
}
|
||||
TerraformPatch.Init();
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
TerraformPatch.Uninit();
|
||||
WaterPumperPatch.Uninit();
|
||||
ResourcePatch.Uninit();
|
||||
AbnormalDisabler.Uninit();
|
||||
@@ -375,46 +367,4 @@ public class CheatEnabler : BaseUnityPlugin
|
||||
}
|
||||
}
|
||||
|
||||
private class TerraformAnyway
|
||||
{
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(BuildTool_Reform), "ReformAction")]
|
||||
private static IEnumerable<CodeInstruction> BuildTool_Reform_ReformAction_Patch(
|
||||
IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
var list = instructions.ToList();
|
||||
for (var i = 0; i < list.Count; i++)
|
||||
{
|
||||
var instr = list[i];
|
||||
yield return instr;
|
||||
if (instr.opcode == OpCodes.Callvirt &&
|
||||
instr.OperandIs(AccessTools.Method(typeof(Player), "get_sandCount")))
|
||||
{
|
||||
/* ldloc.s 6 */
|
||||
i++;
|
||||
instr = list[i];
|
||||
yield return instr;
|
||||
/* sub */
|
||||
i++;
|
||||
instr = list[i];
|
||||
yield return instr;
|
||||
/* ldc.i4.0 */
|
||||
yield return new CodeInstruction(OpCodes.Ldc_I4_0);
|
||||
/* call Math.Max() */
|
||||
yield return new CodeInstruction(OpCodes.Call,
|
||||
AccessTools.Method(typeof(Math), "Max", new[] { typeof(int), typeof(int) }));
|
||||
/* stloc.s 21 */
|
||||
i++;
|
||||
instr = list[i];
|
||||
yield return instr;
|
||||
/* skip 3 instructions:
|
||||
* ldloc.s 21
|
||||
* ldc.i4.0
|
||||
* blt (633)
|
||||
*/
|
||||
i += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,17 +28,23 @@ public class I18N
|
||||
ZHCN = string.IsNullOrEmpty(zhcn) ? enus : zhcn,
|
||||
FRFR = string.IsNullOrEmpty(frfr) ? enus : frfr
|
||||
};
|
||||
if (_initialized)
|
||||
StringsToAdd.Add(strProto);
|
||||
}
|
||||
|
||||
public static void Apply()
|
||||
{
|
||||
if (!_initialized) return;
|
||||
var strings = LDB._strings;
|
||||
var index = strings.dataArray.Length;
|
||||
strings.dataArray = strings.dataArray.Concat(StringsToAdd).ToArray();
|
||||
StringsToAdd.Clear();
|
||||
var newIndex = strings.dataArray.Length;
|
||||
for (; index < newIndex; index++)
|
||||
{
|
||||
var index = strings.dataArray.Length;
|
||||
var strProto = strings.dataArray[index];
|
||||
strProto.ID = GetNextID();
|
||||
strings.dataArray = strings.dataArray.Append(strProto).ToArray();
|
||||
strings.dataIndices[strProto.ID] = index;
|
||||
strings.nameIndices[strProto.Name] = index;
|
||||
}
|
||||
else
|
||||
{
|
||||
StringsToAdd.Add(strProto);
|
||||
strings.nameIndices[strings.dataArray[index].Name] = index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,18 +58,8 @@ public class I18N
|
||||
OnInitialized?.Invoke();
|
||||
return;
|
||||
}
|
||||
var strings = LDB._strings;
|
||||
var index = strings.dataArray.Length;
|
||||
strings.dataArray = strings.dataArray.Concat(StringsToAdd).ToArray();
|
||||
StringsToAdd.Clear();
|
||||
var newIndex = strings.dataArray.Length;
|
||||
for (; index < newIndex; index++)
|
||||
{
|
||||
var strProto = strings.dataArray[index];
|
||||
strProto.ID = GetNextID();
|
||||
strings.dataIndices[strProto.ID] = index;
|
||||
strings.nameIndices[strings.dataArray[index].Name] = index;
|
||||
}
|
||||
|
||||
Apply();
|
||||
OnInitialized?.Invoke();
|
||||
}
|
||||
|
||||
|
||||
38
CheatEnabler/TerraformPatch.cs
Normal file
38
CheatEnabler/TerraformPatch.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Emit;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace CheatEnabler;
|
||||
public static class TerraformPatch
|
||||
{
|
||||
public static ConfigEntry<bool> Enabled;
|
||||
private static Harmony _patch;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
_patch = Harmony.CreateAndPatchAll(typeof(TerraformPatch));
|
||||
}
|
||||
|
||||
public static void Uninit()
|
||||
{
|
||||
if (_patch == null) return;
|
||||
_patch.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(BuildTool_Reform), nameof(BuildTool_Reform.ReformAction))]
|
||||
private static IEnumerable<CodeInstruction> BuildTool_Reform_ReformAction_Patch(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(Player), "get_sandCount"))
|
||||
).Advance(3).InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Ldc_I4_0),
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Math), "Max", new[] { typeof(int), typeof(int) }))
|
||||
).Advance(1).RemoveInstructions(3);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,19 @@ public class UIConfigWindow : UI.MyWindowWithTabs
|
||||
{
|
||||
private RectTransform _windowTrans;
|
||||
|
||||
static UIConfigWindow()
|
||||
{
|
||||
I18N.Add("General", "General", "常规");
|
||||
I18N.Add("Enable Dev Shortcuts", "Enable Dev Shortcuts", "启用开发模式快捷键");
|
||||
I18N.Add("Disable Abnormal Checks", "Disable Abnormal Checks", "关闭数据异常检查");
|
||||
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("Terraform without enought sands", "Terraform without enough sands", "沙土不够时依然可以整改地形");
|
||||
I18N.Apply();
|
||||
}
|
||||
|
||||
public static UIConfigWindow CreateInstance()
|
||||
{
|
||||
return UI.MyWindowManager.CreateWindow<UIConfigWindow>("CEConfigWindow", "CheatEnabler Config".Translate());
|
||||
@@ -23,21 +36,23 @@ public class UIConfigWindow : UI.MyWindowWithTabs
|
||||
{
|
||||
// General tab
|
||||
var x = 0f;
|
||||
var y = 0f;
|
||||
var y = 10f;
|
||||
var tab1 = AddTab(36f, 0, _windowTrans, "General".Translate());
|
||||
UI.MyCheckBox.CreateCheckBox(x, y, tab1, DevShortcuts.Enabled, "Enable Dev Shortcuts".Translate());
|
||||
y += 26f;
|
||||
y += 36f;
|
||||
UI.MyCheckBox.CreateCheckBox(x, y, tab1, AbnormalDisabler.Enabled, "Disable Abnormal Checks".Translate());
|
||||
|
||||
// Planet Tab
|
||||
var tab2 = AddTab(136f, 1, _windowTrans, "Planet".Translate());
|
||||
x = 0f;
|
||||
y = 0f;
|
||||
y = 10f;
|
||||
UI.MyCheckBox.CreateCheckBox(x, y, tab2, ResourcePatch.InfiniteEnabled, "Infinite Natural Resources".Translate());
|
||||
y += 26f;
|
||||
y += 36f;
|
||||
UI.MyCheckBox.CreateCheckBox(x, y, tab2, ResourcePatch.FastEnabled, "Fast Mining".Translate());
|
||||
y += 26f;
|
||||
y += 36f;
|
||||
UI.MyCheckBox.CreateCheckBox(x, y, tab2, WaterPumperPatch.Enabled, "Pump Anywhere".Translate());
|
||||
y += 36f;
|
||||
UI.MyCheckBox.CreateCheckBox(x, y, tab2, WaterPumperPatch.Enabled, "Terraform without enought sands".Translate());
|
||||
SetCurrentTab(0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user