mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 16:13:31 +08:00
WIP
This commit is contained in:
@@ -71,18 +71,12 @@ public class CheatEnabler : BaseUnityPlugin
|
|||||||
"Birth planet is solid flat (no water)").Value;
|
"Birth planet is solid flat (no water)").Value;
|
||||||
_highLuminosityBirthStar = Config.Bind("Birth", "HighLuminosityBirthStar", _highLuminosityBirthStar,
|
_highLuminosityBirthStar = Config.Bind("Birth", "HighLuminosityBirthStar", _highLuminosityBirthStar,
|
||||||
"Birth star has high luminosity").Value;
|
"Birth star has high luminosity").Value;
|
||||||
_terraformAnyway = Config.Bind("General", "TerraformAnyway", _terraformAnyway,
|
TerraformPatch.Enabled = Config.Bind("General", "TerraformAnyway", false,
|
||||||
"Can do terraform without enough sands").Value;
|
"Can do terraform without enough sands");
|
||||||
|
|
||||||
I18N.Init();
|
I18N.Init();
|
||||||
I18N.Add("CheatEnabler Config", "CheatEnabler Config", "CheatEnabler设置");
|
I18N.Add("CheatEnabler Config", "CheatEnabler Config", "CheatEnabler设置");
|
||||||
I18N.Add("General", "General", "常规");
|
I18N.Apply();
|
||||||
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", "平地抽水");
|
|
||||||
|
|
||||||
// UI Patch
|
// UI Patch
|
||||||
_windowPatch = Harmony.CreateAndPatchAll(typeof(UI.MyWindowManager.Patch));
|
_windowPatch = Harmony.CreateAndPatchAll(typeof(UI.MyWindowManager.Patch));
|
||||||
@@ -114,14 +108,12 @@ public class CheatEnabler : BaseUnityPlugin
|
|||||||
Harmony.CreateAndPatchAll(typeof(BirthPlanetCheat));
|
Harmony.CreateAndPatchAll(typeof(BirthPlanetCheat));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_terraformAnyway)
|
TerraformPatch.Init();
|
||||||
{
|
|
||||||
Harmony.CreateAndPatchAll(typeof(TerraformAnyway));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnDestroy()
|
public void OnDestroy()
|
||||||
{
|
{
|
||||||
|
TerraformPatch.Uninit();
|
||||||
WaterPumperPatch.Uninit();
|
WaterPumperPatch.Uninit();
|
||||||
ResourcePatch.Uninit();
|
ResourcePatch.Uninit();
|
||||||
AbnormalDisabler.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,
|
ZHCN = string.IsNullOrEmpty(zhcn) ? enus : zhcn,
|
||||||
FRFR = string.IsNullOrEmpty(frfr) ? enus : frfr
|
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();
|
strProto.ID = GetNextID();
|
||||||
strings.dataArray = strings.dataArray.Append(strProto).ToArray();
|
|
||||||
strings.dataIndices[strProto.ID] = index;
|
strings.dataIndices[strProto.ID] = index;
|
||||||
strings.nameIndices[strProto.Name] = index;
|
strings.nameIndices[strings.dataArray[index].Name] = index;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
StringsToAdd.Add(strProto);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,18 +58,8 @@ public class I18N
|
|||||||
OnInitialized?.Invoke();
|
OnInitialized?.Invoke();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var strings = LDB._strings;
|
|
||||||
var index = strings.dataArray.Length;
|
Apply();
|
||||||
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;
|
|
||||||
}
|
|
||||||
OnInitialized?.Invoke();
|
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;
|
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()
|
public static UIConfigWindow CreateInstance()
|
||||||
{
|
{
|
||||||
return UI.MyWindowManager.CreateWindow<UIConfigWindow>("CEConfigWindow", "CheatEnabler Config".Translate());
|
return UI.MyWindowManager.CreateWindow<UIConfigWindow>("CEConfigWindow", "CheatEnabler Config".Translate());
|
||||||
@@ -23,21 +36,23 @@ public class UIConfigWindow : UI.MyWindowWithTabs
|
|||||||
{
|
{
|
||||||
// General tab
|
// General tab
|
||||||
var x = 0f;
|
var x = 0f;
|
||||||
var y = 0f;
|
var y = 10f;
|
||||||
var tab1 = AddTab(36f, 0, _windowTrans, "General".Translate());
|
var tab1 = AddTab(36f, 0, _windowTrans, "General".Translate());
|
||||||
UI.MyCheckBox.CreateCheckBox(x, y, tab1, DevShortcuts.Enabled, "Enable Dev Shortcuts".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());
|
UI.MyCheckBox.CreateCheckBox(x, y, tab1, AbnormalDisabler.Enabled, "Disable Abnormal Checks".Translate());
|
||||||
|
|
||||||
// Planet Tab
|
// Planet Tab
|
||||||
var tab2 = AddTab(136f, 1, _windowTrans, "Planet".Translate());
|
var tab2 = AddTab(136f, 1, _windowTrans, "Planet".Translate());
|
||||||
x = 0f;
|
x = 0f;
|
||||||
y = 0f;
|
y = 10f;
|
||||||
UI.MyCheckBox.CreateCheckBox(x, y, tab2, ResourcePatch.InfiniteEnabled, "Infinite Natural Resources".Translate());
|
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());
|
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());
|
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);
|
SetCurrentTab(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public class EpicDifficulty
|
|||||||
{
|
{
|
||||||
I18N.Add("究极少", "Micro", "究极少");
|
I18N.Add("究极少", "Micro", "究极少");
|
||||||
I18N.Add("史诗难度", "Epic Difficulty !!", "史诗难度 !!");
|
I18N.Add("史诗难度", "Epic Difficulty !!", "史诗难度 !!");
|
||||||
|
I18N.Apply();
|
||||||
Harmony.CreateAndPatchAll(typeof(EpicDifficulty));
|
Harmony.CreateAndPatchAll(typeof(EpicDifficulty));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
|
||||||
@@ -8,6 +9,8 @@ public class I18N
|
|||||||
{
|
{
|
||||||
private static bool _initialized;
|
private static bool _initialized;
|
||||||
|
|
||||||
|
public static Action OnInitialized;
|
||||||
|
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
Harmony.CreateAndPatchAll(typeof(I18N));
|
Harmony.CreateAndPatchAll(typeof(I18N));
|
||||||
@@ -25,29 +28,12 @@ public class I18N
|
|||||||
ZHCN = string.IsNullOrEmpty(zhcn) ? enus : zhcn,
|
ZHCN = string.IsNullOrEmpty(zhcn) ? enus : zhcn,
|
||||||
FRFR = string.IsNullOrEmpty(frfr) ? enus : frfr
|
FRFR = string.IsNullOrEmpty(frfr) ? enus : frfr
|
||||||
};
|
};
|
||||||
if (_initialized)
|
StringsToAdd.Add(strProto);
|
||||||
{
|
|
||||||
var index = strings.dataArray.Length;
|
|
||||||
strProto.ID = GetNextID();
|
|
||||||
strings.dataArray = strings.dataArray.Append(strProto).ToArray();
|
|
||||||
strings.dataIndices[strProto.ID] = index;
|
|
||||||
strings.nameIndices[strProto.Name] = index;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
StringsToAdd.Add(strProto);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPostfix, HarmonyPriority(Priority.Last), HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
|
public static void Apply()
|
||||||
private static void VFPreload_InvokeOnLoadWorkEnded_Postfix()
|
|
||||||
{
|
{
|
||||||
if (_initialized) return;
|
if (!_initialized) return;
|
||||||
_initialized = true;
|
|
||||||
if (StringsToAdd.Count == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var strings = LDB._strings;
|
var strings = LDB._strings;
|
||||||
var index = strings.dataArray.Length;
|
var index = strings.dataArray.Length;
|
||||||
strings.dataArray = strings.dataArray.Concat(StringsToAdd).ToArray();
|
strings.dataArray = strings.dataArray.Concat(StringsToAdd).ToArray();
|
||||||
@@ -62,6 +48,21 @@ public class I18N
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix, HarmonyPriority(Priority.Last), HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
|
||||||
|
private static void VFPreload_InvokeOnLoadWorkEnded_Postfix()
|
||||||
|
{
|
||||||
|
if (_initialized) return;
|
||||||
|
_initialized = true;
|
||||||
|
if (StringsToAdd.Count == 0)
|
||||||
|
{
|
||||||
|
OnInitialized?.Invoke();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Apply();
|
||||||
|
OnInitialized?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
private static int GetNextID()
|
private static int GetNextID()
|
||||||
{
|
{
|
||||||
var strings = LDB._strings;
|
var strings = LDB._strings;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public class MoreSettings
|
|||||||
I18N.Add("步进最小距离", "Step Distance Min", "步进最小距离");
|
I18N.Add("步进最小距离", "Step Distance Min", "步进最小距离");
|
||||||
I18N.Add("步进最大距离", "Step Distance Max", "步进最大距离");
|
I18N.Add("步进最大距离", "Step Distance Max", "步进最大距离");
|
||||||
I18N.Add("扁平度", "Flatness", "扁平度");
|
I18N.Add("扁平度", "Flatness", "扁平度");
|
||||||
|
I18N.Apply();
|
||||||
Harmony.CreateAndPatchAll(typeof(MoreSettings));
|
Harmony.CreateAndPatchAll(typeof(MoreSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user