1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-09 16:13:31 +08:00

CheatEnabler: fire all bullets

This commit is contained in:
2025-05-25 23:35:49 +08:00
parent 944a4d7948
commit 23aa8c1f13
4 changed files with 255 additions and 179 deletions

View File

@@ -71,6 +71,8 @@ public class CheatEnabler : BaseUnityPlugin
"Enable warp without warper"); "Enable warp without warper");
DysonSpherePatch.SkipBulletEnabled = Config.Bind("DysonSphere", "SkipBullet", false, DysonSpherePatch.SkipBulletEnabled = Config.Bind("DysonSphere", "SkipBullet", false,
"Skip bullet"); "Skip bullet");
DysonSpherePatch.FireAllBulletsEnabled = Config.Bind("DysonSphere", "FireAllBullets", false,
"Fire all bullets at once");
DysonSpherePatch.SkipAbsorbEnabled = Config.Bind("DysonSphere", "SkipAbsorb", false, DysonSpherePatch.SkipAbsorbEnabled = Config.Bind("DysonSphere", "SkipAbsorb", false,
"Skip absorption"); "Skip absorption");
DysonSpherePatch.QuickAbsorbEnabled = Config.Bind("DysonSphere", "QuickAbsorb", false, DysonSpherePatch.QuickAbsorbEnabled = Config.Bind("DysonSphere", "QuickAbsorb", false,

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Reflection.Emit; using System.Reflection.Emit;
using BepInEx.Configuration; using BepInEx.Configuration;
using HarmonyLib; using HarmonyLib;
using UnityEngine;
using UXAssist.Common; using UXAssist.Common;
namespace CheatEnabler.Patches; namespace CheatEnabler.Patches;
@@ -11,6 +10,7 @@ namespace CheatEnabler.Patches;
public class DysonSpherePatch : PatchImpl<DysonSpherePatch> public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
{ {
public static ConfigEntry<bool> SkipBulletEnabled; public static ConfigEntry<bool> SkipBulletEnabled;
public static ConfigEntry<bool> FireAllBulletsEnabled;
public static ConfigEntry<bool> SkipAbsorbEnabled; public static ConfigEntry<bool> SkipAbsorbEnabled;
public static ConfigEntry<bool> QuickAbsorbEnabled; public static ConfigEntry<bool> QuickAbsorbEnabled;
public static ConfigEntry<bool> EjectAnywayEnabled; public static ConfigEntry<bool> EjectAnywayEnabled;
@@ -29,6 +29,8 @@ public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
OverclockEjectorEnabled.SettingChanged += (_, _) => OverclockEjector.Enable(OverclockEjectorEnabled.Value); OverclockEjectorEnabled.SettingChanged += (_, _) => OverclockEjector.Enable(OverclockEjectorEnabled.Value);
OverclockSiloEnabled.SettingChanged += (_, _) => OverclockSilo.Enable(OverclockSiloEnabled.Value); OverclockSiloEnabled.SettingChanged += (_, _) => OverclockSilo.Enable(OverclockSiloEnabled.Value);
UnlockMaxOrbitRadiusEnabled.SettingChanged += (_, _) => UnlockMaxOrbitRadius.Enable(UnlockMaxOrbitRadiusEnabled.Value); UnlockMaxOrbitRadiusEnabled.SettingChanged += (_, _) => UnlockMaxOrbitRadius.Enable(UnlockMaxOrbitRadiusEnabled.Value);
FireAllBulletsEnabled.SettingChanged += (_, _) => SkipBulletPatch.SetFireAllBullets(FireAllBulletsEnabled.Value);
} }
public static void Start() public static void Start()
@@ -41,6 +43,7 @@ public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
OverclockSilo.Enable(OverclockSiloEnabled.Value); OverclockSilo.Enable(OverclockSiloEnabled.Value);
UnlockMaxOrbitRadius.Enable(UnlockMaxOrbitRadiusEnabled.Value); UnlockMaxOrbitRadius.Enable(UnlockMaxOrbitRadiusEnabled.Value);
Enable(true); Enable(true);
SkipBulletPatch.SetFireAllBullets(FireAllBulletsEnabled.Value);
} }
public static void Uninit() public static void Uninit()
@@ -94,6 +97,12 @@ public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
private static long _sailLifeTime; private static long _sailLifeTime;
private static DysonSailCache[][] _sailsCache; private static DysonSailCache[][] _sailsCache;
private static int[] _sailsCacheLen, _sailsCacheCapacity; private static int[] _sailsCacheLen, _sailsCacheCapacity;
private static bool _fireAllBullets;
public static void SetFireAllBullets(bool value)
{
_fireAllBullets = value;
}
private struct DysonSailCache private struct DysonSailCache
{ {
@@ -181,25 +190,28 @@ public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
).Advance(2); ).Advance(2);
var start = matcher.Pos; var start = matcher.Pos;
matcher.MatchForward(false, matcher.MatchForward(false,
new CodeMatch(OpCodes.Pop) new CodeMatch(OpCodes.Ldc_I4_M1),
).Advance(1); new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(EjectorComponent), nameof(EjectorComponent.direction)))
).Advance(2);
var end = matcher.Pos; var end = matcher.Pos;
matcher.Start().Advance(start).RemoveInstructions(end - start).Insert( matcher.Start().Advance(start).RemoveInstructions(end - start).Insert(
new CodeInstruction(OpCodes.Ldarg_3),
new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(EjectorComponent), nameof(EjectorComponent.orbitId))), new CodeInstruction(OpCodes.Ldarg_3),
new CodeInstruction(OpCodes.Ldloc_S, 9), new CodeInstruction(OpCodes.Ldloc_S, 9),
new CodeInstruction(OpCodes.Ldloc_S, 11), new CodeInstruction(OpCodes.Ldloc_S, 11),
new CodeInstruction(OpCodes.Ldarg_S, 6),
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(SkipBulletPatch), nameof(SkipBulletPatch.AddDysonSail))) new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(SkipBulletPatch), nameof(SkipBulletPatch.AddDysonSail)))
); );
return matcher.InstructionEnumeration(); return matcher.InstructionEnumeration();
} }
private static void AddDysonSail(DysonSwarm swarm, int orbitId, VectorLF3 uPos, VectorLF3 endVec) private static void AddDysonSail(ref EjectorComponent ejector, DysonSwarm swarm, VectorLF3 uPos, VectorLF3 endVec, int[] consumeRegister)
{ {
var index = swarm.starData.index; var index = swarm.starData.index;
var orbitId = ejector.orbitId;
var delta1 = endVec - swarm.starData.uPosition; var delta1 = endVec - swarm.starData.uPosition;
var delta2 = VectorLF3.Cross(endVec - uPos, swarm.orbits[orbitId].up).normalized * Math.Sqrt(swarm.dysonSphere.gravity / swarm.orbits[orbitId].radius); var delta2 = VectorLF3.Cross(endVec - uPos, swarm.orbits[orbitId].up).normalized * Math.Sqrt(swarm.dysonSphere.gravity / swarm.orbits[orbitId].radius);
var bulletCount = ejector.bulletCount;
lock (swarm) lock (swarm)
{ {
var cache = _sailsCache[index]; var cache = _sailsCache[index];
@@ -209,6 +221,24 @@ public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
SetSailsCacheCapacity(index, 256); SetSailsCacheCapacity(index, 256);
cache = _sailsCache[index]; cache = _sailsCache[index];
} }
if (_fireAllBullets)
{
var capacity = _sailsCacheCapacity[index];
var leastCapacity = len + bulletCount;
if (leastCapacity > capacity)
{
do
{
capacity *= 2;
} while (leastCapacity > capacity);
SetSailsCacheCapacity(index, capacity);
cache = _sailsCache[index];
}
_sailsCacheLen[index] = len + bulletCount;
var end = len + bulletCount;
for (var i = len; i < end; i++)
cache[i].FromData(delta1, delta2 + RandomTable.SphericNormal(ref swarm.randSeed, 0.5), orbitId);
}
else else
{ {
var capacity = _sailsCacheCapacity[index]; var capacity = _sailsCacheCapacity[index];
@@ -217,12 +247,46 @@ public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
SetSailsCacheCapacity(index, capacity * 2); SetSailsCacheCapacity(index, capacity * 2);
cache = _sailsCache[index]; cache = _sailsCache[index];
} }
}
_sailsCacheLen[index] = len + 1; _sailsCacheLen[index] = len + 1;
cache[len].FromData(delta1, delta2 + RandomTable.SphericNormal(ref swarm.randSeed, 0.5), orbitId); cache[len].FromData(delta1, delta2 + RandomTable.SphericNormal(ref swarm.randSeed, 0.5), orbitId);
} }
} }
if (_fireAllBullets)
{
if (!ejector.incUsed)
{
ejector.incUsed = ejector.bulletInc >= bulletCount;
}
ejector.bulletInc = 0;
ejector.bulletCount = 0;
lock (consumeRegister)
{
consumeRegister[ejector.bulletId] += bulletCount;
}
}
else
{
var inc = ejector.bulletInc / bulletCount;
if (!ejector.incUsed)
{
ejector.incUsed = inc > 0;
}
ejector.bulletInc -= inc;
ejector.bulletCount = bulletCount - 1;
if (ejector.bulletCount == 0)
{
ejector.bulletInc = 0;
}
lock (consumeRegister)
{
consumeRegister[ejector.bulletId]++;
}
}
ejector.time = ejector.coldSpend;
ejector.direction = -1;
}
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(DysonSwarm), "GameTick")] [HarmonyPatch(typeof(DysonSwarm), "GameTick")]
public static void DysonSwarm_GameTick_Prefix(DysonSwarm __instance, long time) public static void DysonSwarm_GameTick_Prefix(DysonSwarm __instance, long time)

View File

@@ -418,6 +418,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
return matcher.InstructionEnumeration(); return matcher.InstructionEnumeration();
} }
/*
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(ConstructionSystem), nameof(ConstructionSystem.AddBuildTargetToModules))] [HarmonyPatch(typeof(ConstructionSystem), nameof(ConstructionSystem.AddBuildTargetToModules))]
private static IEnumerable<CodeInstruction> ConstructionSystem_AddBuildTargetToModules_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> ConstructionSystem_AddBuildTargetToModules_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
@@ -449,6 +450,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
); );
return matcher.InstructionEnumeration(); return matcher.InstructionEnumeration();
} }
*/
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(UXAssist.Functions.PlanetFunctions), nameof(UXAssist.Functions.PlanetFunctions.BuildOrbitalCollectors))] [HarmonyPatch(typeof(UXAssist.Functions.PlanetFunctions), nameof(UXAssist.Functions.PlanetFunctions.BuildOrbitalCollectors))]

View File

@@ -53,12 +53,14 @@ public static class UIConfigWindow
I18N.Add("Boost fuel power 2", "(x20,000 for deuteron, x10,000 for antimatter)", "(氘核燃料棒x20,000反物质燃料棒x10,000)"); I18N.Add("Boost fuel power 2", "(x20,000 for deuteron, x10,000 for antimatter)", "(氘核燃料棒x20,000反物质燃料棒x10,000)");
I18N.Add("Wind Turbines do global power coverage", "Wind Turbines do global power coverage", "风力涡轮机供电覆盖全球"); I18N.Add("Wind Turbines do global power coverage", "Wind Turbines do global power coverage", "风力涡轮机供电覆盖全球");
I18N.Add("Boost geothermal power", "Boost geothermal power(x50,000)", "提升地热发电(x50,000)"); I18N.Add("Boost geothermal power", "Boost geothermal power(x50,000)", "提升地热发电(x50,000)");
I18N.Add("Increase maximum power usage in Logistic Stations and Advanced Mining Machines", "Increase maximum power usage in Logistic Stations and Advanced Mining Machines", "提升物流塔和大型采矿机的最大功耗"); I18N.Add("Increase maximum power usage in Logistic Stations and Advanced Mining Machines", "Increase maximum power usage in Logistic Stations and Advanced Mining Machines",
"提升物流塔和大型采矿机的最大功耗");
I18N.Add("Retrieve/Place items from/to remote planets on logistics control panel", "Retrieve/Place items from/to remote planets on logistics control panel", "在物流总控面板上可以从非本地行星取放物品"); I18N.Add("Retrieve/Place items from/to remote planets on logistics control panel", "Retrieve/Place items from/to remote planets on logistics control panel", "在物流总控面板上可以从非本地行星取放物品");
I18N.Add("Infinite Natural Resources", "Infinite natural resources", "自然资源采集不消耗"); I18N.Add("Infinite Natural Resources", "Infinite natural resources", "自然资源采集不消耗");
I18N.Add("Fast Mining", "Fast mining", "高速采集"); I18N.Add("Fast Mining", "Fast mining", "高速采集");
I18N.Add("Pump Anywhere", "Pump anywhere", "平地抽水"); I18N.Add("Pump Anywhere", "Pump anywhere", "平地抽水");
I18N.Add("Skip bullet period", "Skip bullet period", "跳过子弹阶段"); I18N.Add("Skip bullet period", "Skip bullet period", "跳过子弹阶段");
I18N.Add("Fire all bullets at once", "Fire all bullets at once", "一次弹射所有太阳帆");
I18N.Add("Skip absorption period", "Skip absorption period", "跳过吸收阶段"); I18N.Add("Skip absorption period", "Skip absorption period", "跳过吸收阶段");
I18N.Add("Quick absorb", "Quick absorb", "快速吸收"); I18N.Add("Quick absorb", "Quick absorb", "快速吸收");
I18N.Add("Eject anyway", "Eject anyway", "全球弹射"); I18N.Add("Eject anyway", "Eject anyway", "全球弹射");
@@ -164,6 +166,7 @@ public static class UIConfigWindow
FactoryPatch.BeltSignalGeneratorEnabled.SettingChanged += OnBeltSignalChanged; FactoryPatch.BeltSignalGeneratorEnabled.SettingChanged += OnBeltSignalChanged;
wnd.OnFree += () => { FactoryPatch.BeltSignalGeneratorEnabled.SettingChanged -= OnBeltSignalChanged; }; wnd.OnFree += () => { FactoryPatch.BeltSignalGeneratorEnabled.SettingChanged -= OnBeltSignalChanged; };
OnBeltSignalChanged(null, null); OnBeltSignalChanged(null, null);
void OnBeltSignalChanged(object o, EventArgs e) void OnBeltSignalChanged(object o, EventArgs e)
{ {
var on = FactoryPatch.BeltSignalGeneratorEnabled.Value; var on = FactoryPatch.BeltSignalGeneratorEnabled.Value;
@@ -232,6 +235,8 @@ public static class UIConfigWindow
x = 0f; x = 0f;
y = 10f; y = 10f;
wnd.AddCheckBox(x, y, tab4, DysonSpherePatch.SkipBulletEnabled, "Skip bullet period"); wnd.AddCheckBox(x, y, tab4, DysonSpherePatch.SkipBulletEnabled, "Skip bullet period");
y += 26f;
wnd.AddCheckBox(x + 26f, y, tab4, DysonSpherePatch.FireAllBulletsEnabled, "Fire all bullets at once", 13);
y += 36f; y += 36f;
wnd.AddCheckBox(x, y, tab4, DysonSpherePatch.SkipAbsorbEnabled, "Skip absorption period"); wnd.AddCheckBox(x, y, tab4, DysonSpherePatch.SkipAbsorbEnabled, "Skip absorption period");
y += 36f; y += 36f;
@@ -250,10 +255,12 @@ public static class UIConfigWindow
DysonSpherePatch.UnlockMaxOrbitRadiusEnabled.SettingChanged += UnlockMaxOrbitRadiusChanged; DysonSpherePatch.UnlockMaxOrbitRadiusEnabled.SettingChanged += UnlockMaxOrbitRadiusChanged;
wnd.OnFree += () => { DysonSpherePatch.UnlockMaxOrbitRadiusEnabled.SettingChanged -= UnlockMaxOrbitRadiusChanged; }; wnd.OnFree += () => { DysonSpherePatch.UnlockMaxOrbitRadiusEnabled.SettingChanged -= UnlockMaxOrbitRadiusChanged; };
UnlockMaxOrbitRadiusChanged(null, null); UnlockMaxOrbitRadiusChanged(null, null);
void UnlockMaxOrbitRadiusChanged(object o, EventArgs e) void UnlockMaxOrbitRadiusChanged(object o, EventArgs e)
{ {
slider.slider.enabled = DysonSpherePatch.UnlockMaxOrbitRadiusEnabled.Value; slider.slider.enabled = DysonSpherePatch.UnlockMaxOrbitRadiusEnabled.Value;
} }
; ;
} }
x = 300f; x = 300f;
@@ -289,6 +296,7 @@ public static class UIConfigWindow
{ {
_resignGameBtn.gameObject.SetActive(resignEnabled); _resignGameBtn.gameObject.SetActive(resignEnabled);
} }
var history = data.history; var history = data.history;
if (history == null) return; if (history == null) return;
var banEnabled = history.hasUsedPropertyBanAchievement; var banEnabled = history.hasUsedPropertyBanAchievement;