mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 06:13:36 +08:00
add TerraformAnyway
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection.Emit;
|
using System.Reflection.Emit;
|
||||||
using BepInEx;
|
using BepInEx;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
@@ -26,6 +27,7 @@ public class CheatEnabler : BaseUnityPlugin
|
|||||||
private static bool _unipolarOnBirthPlanet = false;
|
private static bool _unipolarOnBirthPlanet = false;
|
||||||
private static bool _flatBirthPlanet = true;
|
private static bool _flatBirthPlanet = true;
|
||||||
private static bool _highLuminosityBirthStar = true;
|
private static bool _highLuminosityBirthStar = true;
|
||||||
|
private static bool _terraformAnyway = false;
|
||||||
private static string _unlockTechToMaximumLevel = "";
|
private static string _unlockTechToMaximumLevel = "";
|
||||||
private static readonly List<int> TechToUnlock = new();
|
private static readonly List<int> TechToUnlock = new();
|
||||||
|
|
||||||
@@ -60,14 +62,18 @@ 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,
|
||||||
|
"Can do terraform without enough sands").Value;
|
||||||
if (_devShortcuts)
|
if (_devShortcuts)
|
||||||
{
|
{
|
||||||
Harmony.CreateAndPatchAll(typeof(DevShortcuts));
|
Harmony.CreateAndPatchAll(typeof(DevShortcuts));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_disableAbnormalChecks)
|
if (_disableAbnormalChecks)
|
||||||
{
|
{
|
||||||
Harmony.CreateAndPatchAll(typeof(AbnormalDisabler));
|
Harmony.CreateAndPatchAll(typeof(AbnormalDisabler));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_alwaysInfiniteResource)
|
if (_alwaysInfiniteResource)
|
||||||
{
|
{
|
||||||
Harmony.CreateAndPatchAll(typeof(AlwaysInfiniteResource));
|
Harmony.CreateAndPatchAll(typeof(AlwaysInfiniteResource));
|
||||||
@@ -80,18 +86,28 @@ public class CheatEnabler : BaseUnityPlugin
|
|||||||
TechToUnlock.Add(id);
|
TechToUnlock.Add(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TechToUnlock.Count > 0)
|
if (TechToUnlock.Count > 0)
|
||||||
{
|
{
|
||||||
Harmony.CreateAndPatchAll(typeof(UnlockTechOnGameStart));
|
Harmony.CreateAndPatchAll(typeof(UnlockTechOnGameStart));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_waterPumpAnywhere)
|
if (_waterPumpAnywhere)
|
||||||
{
|
{
|
||||||
Harmony.CreateAndPatchAll(typeof(WaterPumperCheat));
|
Harmony.CreateAndPatchAll(typeof(WaterPumperCheat));
|
||||||
}
|
}
|
||||||
if (_sitiVeinsOnBirthPlanet || _fireIceOnBirthPlanet || _kimberliteOnBirthPlanet || _fractalOnBirthPlanet || _organicOnBirthPlanet || _opticalOnBirthPlanet || _spiniformOnBirthPlanet || _unipolarOnBirthPlanet || _flatBirthPlanet || _highLuminosityBirthStar)
|
|
||||||
|
if (_sitiVeinsOnBirthPlanet || _fireIceOnBirthPlanet || _kimberliteOnBirthPlanet || _fractalOnBirthPlanet ||
|
||||||
|
_organicOnBirthPlanet || _opticalOnBirthPlanet || _spiniformOnBirthPlanet || _unipolarOnBirthPlanet ||
|
||||||
|
_flatBirthPlanet || _highLuminosityBirthStar)
|
||||||
{
|
{
|
||||||
Harmony.CreateAndPatchAll(typeof(BirthPlanetCheat));
|
Harmony.CreateAndPatchAll(typeof(BirthPlanetCheat));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_terraformAnyway)
|
||||||
|
{
|
||||||
|
Harmony.CreateAndPatchAll(typeof(TerraformAnyway));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DevShortcuts
|
private class DevShortcuts
|
||||||
@@ -121,7 +137,9 @@ public class CheatEnabler : BaseUnityPlugin
|
|||||||
__instance.Update();
|
__instance.Update();
|
||||||
if (lastActive != __instance.active)
|
if (lastActive != __instance.active)
|
||||||
{
|
{
|
||||||
UIRealtimeTip.PopupAhead((lastActive ? "Developer Mode Shortcuts Disabled" : "Developer Mode Shortcuts Enabled").Translate(), false);
|
UIRealtimeTip.PopupAhead(
|
||||||
|
(lastActive ? "Developer Mode Shortcuts Disabled" : "Developer Mode Shortcuts Enabled").Translate(),
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,15 +210,18 @@ public class CheatEnabler : BaseUnityPlugin
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var currentTech in TechToUnlock)
|
foreach (var currentTech in TechToUnlock)
|
||||||
{
|
{
|
||||||
UnlockTechRecursive(history, currentTech, currentTech == 3606 ? 7000 : 10000);
|
UnlockTechRecursive(history, currentTech, currentTech == 3606 ? 7000 : 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
var techQueue = history.techQueue;
|
var techQueue = history.techQueue;
|
||||||
if (techQueue == null || techQueue.Length == 0)
|
if (techQueue == null || techQueue.Length == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
history.VarifyTechQueue();
|
history.VarifyTechQueue();
|
||||||
if (history.currentTech > 0 && history.currentTech != techQueue[0])
|
if (history.currentTech > 0 && history.currentTech != techQueue[0])
|
||||||
{
|
{
|
||||||
@@ -215,17 +236,20 @@ public class CheatEnabler : BaseUnityPlugin
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var techProto = LDB.techs.Select(currentTech);
|
var techProto = LDB.techs.Select(currentTech);
|
||||||
if (techProto == null)
|
if (techProto == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var value = techStates[currentTech];
|
var value = techStates[currentTech];
|
||||||
var maxLvl = Math.Min(maxLevel, value.maxLevel);
|
var maxLvl = Math.Min(maxLevel, value.maxLevel);
|
||||||
if (value.unlocked)
|
if (value.unlocked)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var preid in techProto.PreTechs)
|
foreach (var preid in techProto.PreTechs)
|
||||||
{
|
{
|
||||||
UnlockTechRecursive(history, preid, maxLevel);
|
UnlockTechRecursive(history, preid, maxLevel);
|
||||||
@@ -250,8 +274,10 @@ public class CheatEnabler : BaseUnityPlugin
|
|||||||
{
|
{
|
||||||
history.UnlockTechFunction(techProto.UnlockFunctions[j], techProto.UnlockValues[j], value.curLevel);
|
history.UnlockTechFunction(techProto.UnlockFunctions[j], techProto.UnlockValues[j], value.curLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
value.curLevel++;
|
value.curLevel++;
|
||||||
}
|
}
|
||||||
|
|
||||||
value.unlocked = maxLvl >= value.maxLevel;
|
value.unlocked = maxLvl >= value.maxLevel;
|
||||||
value.curLevel = value.unlocked ? maxLvl : maxLvl + 1;
|
value.curLevel = value.unlocked ? maxLvl : maxLvl + 1;
|
||||||
value.hashNeeded = techProto.GetHashNeeded(value.curLevel);
|
value.hashNeeded = techProto.GetHashNeeded(value.curLevel);
|
||||||
@@ -280,43 +306,51 @@ public class CheatEnabler : BaseUnityPlugin
|
|||||||
theme.VeinOpacity[2] = 1f;
|
theme.VeinOpacity[2] = 1f;
|
||||||
theme.VeinOpacity[3] = 1f;
|
theme.VeinOpacity[3] = 1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<int> veins = new();
|
List<int> veins = new();
|
||||||
List<float> settings = new();
|
List<float> settings = new();
|
||||||
if (_fireIceOnBirthPlanet)
|
if (_fireIceOnBirthPlanet)
|
||||||
{
|
{
|
||||||
veins.Add(8);
|
veins.Add(8);
|
||||||
settings.AddRange(new [] {1f, 1f, 0.5f, 1f});
|
settings.AddRange(new[] { 1f, 1f, 0.5f, 1f });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_kimberliteOnBirthPlanet)
|
if (_kimberliteOnBirthPlanet)
|
||||||
{
|
{
|
||||||
veins.Add(9);
|
veins.Add(9);
|
||||||
settings.AddRange(new [] {1f, 1f, 0.5f, 1f});
|
settings.AddRange(new[] { 1f, 1f, 0.5f, 1f });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_fractalOnBirthPlanet)
|
if (_fractalOnBirthPlanet)
|
||||||
{
|
{
|
||||||
veins.Add(10);
|
veins.Add(10);
|
||||||
settings.AddRange(new [] {1f, 1f, 0.5f, 1f});
|
settings.AddRange(new[] { 1f, 1f, 0.5f, 1f });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_organicOnBirthPlanet)
|
if (_organicOnBirthPlanet)
|
||||||
{
|
{
|
||||||
veins.Add(11);
|
veins.Add(11);
|
||||||
settings.AddRange(new [] {1f, 1f, 0.5f, 1f});
|
settings.AddRange(new[] { 1f, 1f, 0.5f, 1f });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_opticalOnBirthPlanet)
|
if (_opticalOnBirthPlanet)
|
||||||
{
|
{
|
||||||
veins.Add(12);
|
veins.Add(12);
|
||||||
settings.AddRange(new [] {1f, 1f, 0.5f, 1f});
|
settings.AddRange(new[] { 1f, 1f, 0.5f, 1f });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_spiniformOnBirthPlanet)
|
if (_spiniformOnBirthPlanet)
|
||||||
{
|
{
|
||||||
veins.Add(13);
|
veins.Add(13);
|
||||||
settings.AddRange(new [] {1f, 1f, 0.5f, 1f});
|
settings.AddRange(new[] { 1f, 1f, 0.5f, 1f });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_unipolarOnBirthPlanet)
|
if (_unipolarOnBirthPlanet)
|
||||||
{
|
{
|
||||||
veins.Add(14);
|
veins.Add(14);
|
||||||
settings.AddRange(new [] {1f, 1f, 0.5f, 1f});
|
settings.AddRange(new[] { 1f, 1f, 0.5f, 1f });
|
||||||
}
|
}
|
||||||
|
|
||||||
theme.RareVeins = veins.ToArray();
|
theme.RareVeins = veins.ToArray();
|
||||||
theme.RareSettings = settings.ToArray();
|
theme.RareSettings = settings.ToArray();
|
||||||
if (_highLuminosityBirthStar)
|
if (_highLuminosityBirthStar)
|
||||||
@@ -331,7 +365,8 @@ public class CheatEnabler : BaseUnityPlugin
|
|||||||
[HarmonyTranspiler]
|
[HarmonyTranspiler]
|
||||||
[HarmonyPatch(typeof(BuildTool_BlueprintPaste), "CheckBuildConditions")]
|
[HarmonyPatch(typeof(BuildTool_BlueprintPaste), "CheckBuildConditions")]
|
||||||
[HarmonyPatch(typeof(BuildTool_Click), "CheckBuildConditions")]
|
[HarmonyPatch(typeof(BuildTool_Click), "CheckBuildConditions")]
|
||||||
private static IEnumerable<CodeInstruction> BuildTool_CheckBuildConditions_Transpiler(IEnumerable<CodeInstruction> instructions)
|
private static IEnumerable<CodeInstruction> BuildTool_CheckBuildConditions_Transpiler(
|
||||||
|
IEnumerable<CodeInstruction> instructions)
|
||||||
{
|
{
|
||||||
var isFirst = true;
|
var isFirst = true;
|
||||||
foreach (var instr in instructions)
|
foreach (var instr in instructions)
|
||||||
@@ -348,8 +383,52 @@ public class CheatEnabler : BaseUnityPlugin
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
yield return instr;
|
yield return instr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user