mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 16:13:31 +08:00
refactoring UXAssist and CheatEnabler
This commit is contained in:
152
CheatEnabler/Functions/DysonSphereFunctions.cs
Normal file
152
CheatEnabler/Functions/DysonSphereFunctions.cs
Normal file
@@ -0,0 +1,152 @@
|
||||
using HarmonyLib;
|
||||
using UXAssist.Common;
|
||||
|
||||
namespace CheatEnabler.Functions;
|
||||
|
||||
public static class DysonSphereFunctions
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
I18N.Add("You are not in any system.", "You are not in any system.", "你不在任何星系中");
|
||||
I18N.Add("There is no Dyson Sphere shell on \"{0}\".", "There is no Dyson Sphere shell on \"{0}\".", "“{0}”上没有可建造的戴森壳");
|
||||
I18N.Add("This will complete all Dyson Sphere shells on \"{0}\" instantly. Are you sure?", "This will complete all Dyson Sphere shells on \"{0}\" instantly. Are you sure?", "这将立即完成“{0}”上的所有戴森壳。你确定吗?");
|
||||
}
|
||||
|
||||
public static void CompleteShellsInstantly()
|
||||
{
|
||||
StarData star = null;
|
||||
var dysonEditor = UIRoot.instance?.uiGame?.dysonEditor;
|
||||
if (dysonEditor != null && dysonEditor.gameObject.activeSelf)
|
||||
{
|
||||
star = dysonEditor.selection.viewStar;
|
||||
}
|
||||
if (star == null)
|
||||
{
|
||||
star = GameMain.data?.localStar;
|
||||
if (star == null)
|
||||
{
|
||||
UIMessageBox.Show("CheatEnabler".Translate(), "You are not in any system.".Translate(), "确定".Translate(), 3, null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
var dysonSphere = GameMain.data?.dysonSpheres[star.index];
|
||||
if (dysonSphere == null || dysonSphere.layerCount == 0)
|
||||
{
|
||||
UIMessageBox.Show("CheatEnabler".Translate(), string.Format("There is no Dyson Sphere shell on \"{0}\".".Translate(), star.displayName), "确定".Translate(), 3, null);
|
||||
return;
|
||||
}
|
||||
|
||||
UIMessageBox.Show("CheatEnabler".Translate(), string.Format("This will complete all Dyson Sphere shells on \"{0}\" instantly. Are you sure?".Translate(), star.displayName), "取消".Translate(), "确定".Translate(), 2, null, () =>
|
||||
{
|
||||
var totalNodeSpInfo = AccessTools.Field(typeof(DysonSphereLayer), "totalNodeSP");
|
||||
var totalFrameSpInfo = AccessTools.Field(typeof(DysonSphereLayer), "totalFrameSP");
|
||||
var totalCpInfo = AccessTools.Field(typeof(DysonSphereLayer), "totalCP");
|
||||
|
||||
var rocketCount = 0L;
|
||||
var solarSailCount = 0L;
|
||||
foreach (var dysonSphereLayer in dysonSphere.layersIdBased)
|
||||
{
|
||||
if (dysonSphereLayer == null) continue;
|
||||
long totalNodeSp = 0;
|
||||
long totalFrameSp = 0;
|
||||
long totalCp = 0;
|
||||
for (var i = dysonSphereLayer.frameCursor - 1; i >= 0; i--)
|
||||
{
|
||||
var dysonFrame = dysonSphereLayer.framePool[i];
|
||||
if (dysonFrame == null || dysonFrame.id != i) continue;
|
||||
totalFrameSp += dysonFrame.spMax;
|
||||
var spMax = dysonFrame.spMax / 2;
|
||||
if (dysonFrame.spA < spMax)
|
||||
{
|
||||
rocketCount += spMax - dysonFrame.spA;
|
||||
dysonFrame.spA = spMax;
|
||||
dysonSphere.UpdateProgress(dysonFrame);
|
||||
}
|
||||
if (dysonFrame.spB < spMax)
|
||||
{
|
||||
rocketCount += spMax - dysonFrame.spB;
|
||||
dysonFrame.spB = spMax;
|
||||
dysonSphere.UpdateProgress(dysonFrame);
|
||||
}
|
||||
}
|
||||
for (var i = dysonSphereLayer.nodeCursor - 1; i >= 0; i--)
|
||||
{
|
||||
var dysonNode = dysonSphereLayer.nodePool[i];
|
||||
if (dysonNode == null || dysonNode.id != i) continue;
|
||||
dysonNode.spOrdered = 0;
|
||||
dysonNode._spReq = 0;
|
||||
totalNodeSp += dysonNode.spMax;
|
||||
var diff = dysonNode.spMax - dysonNode.sp;
|
||||
if (diff > 0)
|
||||
{
|
||||
rocketCount += diff;
|
||||
dysonNode.sp = dysonNode.spMax;
|
||||
dysonSphere.UpdateProgress(dysonNode);
|
||||
}
|
||||
dysonNode._cpReq = 0;
|
||||
dysonNode.cpOrdered = 0;
|
||||
foreach (var shell in dysonNode.shells)
|
||||
{
|
||||
var nodeIndex = shell.nodeIndexMap[dysonNode.id];
|
||||
var cpMax = (shell.vertsqOffset[nodeIndex + 1] - shell.vertsqOffset[nodeIndex]) * shell.cpPerVertex;
|
||||
totalCp += cpMax;
|
||||
diff = cpMax - shell.nodecps[nodeIndex];
|
||||
shell.nodecps[nodeIndex] = cpMax;
|
||||
shell.nodecps[shell.nodecps.Length - 1] += diff;
|
||||
solarSailCount += diff;
|
||||
if (totalCpInfo != null)
|
||||
{
|
||||
shell.SetMaterialDynamicVars();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
totalNodeSpInfo?.SetValue(dysonSphereLayer, totalNodeSp);
|
||||
totalFrameSpInfo?.SetValue(dysonSphereLayer, totalFrameSp);
|
||||
totalCpInfo?.SetValue(dysonSphereLayer, totalCp);
|
||||
}
|
||||
dysonSphere.CheckAutoNodes();
|
||||
|
||||
var productRegister = dysonSphere.productRegister;
|
||||
if (productRegister != null)
|
||||
{
|
||||
lock (productRegister)
|
||||
{
|
||||
var count = rocketCount;
|
||||
while (count > 0x40000000L)
|
||||
{
|
||||
productRegister[11902] += 0x40000000;
|
||||
count -= 0x40000000;
|
||||
}
|
||||
if (count > 0L) productRegister[11902] += (int)count;
|
||||
count = solarSailCount;
|
||||
while (count > 0x40000000L)
|
||||
{
|
||||
productRegister[11901] += 0x40000000;
|
||||
productRegister[11903] += 0x40000000;
|
||||
count -= 0x40000000;
|
||||
}
|
||||
if (count > 0L)
|
||||
{
|
||||
productRegister[11901] += (int)count;
|
||||
productRegister[11903] += (int)count;
|
||||
}
|
||||
}
|
||||
}
|
||||
var consumeRegister = dysonSphere.consumeRegister;
|
||||
if (consumeRegister != null)
|
||||
{
|
||||
lock (consumeRegister)
|
||||
{
|
||||
var count = solarSailCount;
|
||||
while (count > 0x40000000L)
|
||||
{
|
||||
consumeRegister[11901] += 0x40000000;
|
||||
count -= 0x40000000;
|
||||
}
|
||||
if (count > 0L) consumeRegister[11901] += (int)count;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
29
CheatEnabler/Functions/PlanetFunctions.cs
Normal file
29
CheatEnabler/Functions/PlanetFunctions.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace CheatEnabler.Functions;
|
||||
public static class PlanetFunctions
|
||||
{
|
||||
public static void BuryAllVeins(bool bury)
|
||||
{
|
||||
var planet = GameMain.localPlanet;
|
||||
var factory = planet?.factory;
|
||||
if (factory == null) return;
|
||||
var physics = planet.physics;
|
||||
var height = bury ? planet.realRadius - 50f : planet.realRadius + 0.07f;
|
||||
var array = factory.veinPool;
|
||||
var num = factory.veinCursor;
|
||||
for (var m = 1; m < num; m++)
|
||||
{
|
||||
var pos = array[m].pos;
|
||||
var colliderId = array[m].colliderId;
|
||||
var colliderData = physics.GetColliderData(colliderId);
|
||||
var vector = colliderData.pos.normalized * (height + 0.4f);
|
||||
physics.colChunks[colliderId >> 20].colliderPool[colliderId & 0xFFFFF].pos = vector;
|
||||
array[m].pos = pos.normalized * height;
|
||||
var quaternion = Maths.SphericalRotation(array[m].pos, Random.value * 360f);
|
||||
physics.SetPlanetPhysicsColliderDirty();
|
||||
GameMain.gpuiManager.AlterModel(array[m].modelIndex, array[m].modelId, m, array[m].pos, quaternion, false);
|
||||
}
|
||||
GameMain.gpuiManager.SyncAllGPUBuffer();
|
||||
}
|
||||
}
|
||||
184
CheatEnabler/Functions/PlayerFunctions.cs
Normal file
184
CheatEnabler/Functions/PlayerFunctions.cs
Normal file
@@ -0,0 +1,184 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UXAssist.Common;
|
||||
|
||||
namespace CheatEnabler.Functions;
|
||||
|
||||
public static class PlayerFunctions
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
I18N.Add("ClearAllMetadataConsumptionDetails",
|
||||
"""
|
||||
Metadata consumption records of all gamesaves are about to be cleared.
|
||||
You will gain following metadata back:
|
||||
""",
|
||||
"""
|
||||
所有存档的元数据消耗记录即将被清除,
|
||||
此操作将返还以下元数据:
|
||||
""");
|
||||
I18N.Add("ClearCurrentMetadataConsumptionDetails",
|
||||
"""
|
||||
Metadata consumption records of current gamesave are about to be cleared.
|
||||
You will gain following metadata back:
|
||||
""",
|
||||
"""
|
||||
当前存档的元数据消耗记录即将被清除,
|
||||
此操作将返还以下元数据:
|
||||
""");
|
||||
I18N.Add("NoMetadataConsumptionRecord",
|
||||
"No metadata consumption records found.",
|
||||
"未找到元数据消耗记录。");
|
||||
}
|
||||
|
||||
public static void TeleportToOuterSpace()
|
||||
{
|
||||
var maxSqrDistance = 0.0;
|
||||
var starPosition = VectorLF3.zero;
|
||||
foreach (var star in GameMain.galaxy.stars)
|
||||
{
|
||||
var sqrDistance = star.position.sqrMagnitude;
|
||||
if (sqrDistance > maxSqrDistance)
|
||||
{
|
||||
maxSqrDistance = sqrDistance;
|
||||
starPosition = star.position;
|
||||
}
|
||||
}
|
||||
if (starPosition == VectorLF3.zero) return;
|
||||
var distance = Math.Sqrt(maxSqrDistance);
|
||||
GameMain.mainPlayer.controller.actionSail.StartFastTravelToUPosition((starPosition + starPosition.normalized * 50) * GalaxyData.LY);
|
||||
}
|
||||
|
||||
public static void TeleportToSelectedAstronomical()
|
||||
{
|
||||
var starmap = UIRoot.instance?.uiGame?.starmap;
|
||||
if (starmap == null) return;
|
||||
if (starmap.focusPlanet != null)
|
||||
{
|
||||
GameMain.mainPlayer.controller.actionSail.StartFastTravelToPlanet(starmap.focusPlanet.planet);
|
||||
return;
|
||||
}
|
||||
var targetUPos = VectorLF3.zero;
|
||||
if (starmap.focusStar != null)
|
||||
{
|
||||
var star = starmap.focusStar.star;
|
||||
targetUPos = star.uPosition + VectorLF3.unit_x * star.physicsRadius;
|
||||
}
|
||||
else if (starmap.focusHive != null)
|
||||
{
|
||||
var hive = starmap.focusHive.hive;
|
||||
var id = hive.hiveAstroId - 1000000;
|
||||
if (id > 0 && id < starmap.spaceSector.astros.Length)
|
||||
{
|
||||
ref var astro = ref starmap.spaceSector.astros[id];
|
||||
targetUPos = astro.uPos + VectorLF3.unit_x * astro.uRadius;
|
||||
}
|
||||
}
|
||||
GameMain.mainPlayer.controller.actionSail.StartFastTravelToUPosition(targetUPos);
|
||||
}
|
||||
|
||||
private static void PurgePropertySystem(PropertySystem propertySystem)
|
||||
{
|
||||
var propertyDatas = propertySystem.propertyDatas;
|
||||
for (var i = 0; i < propertyDatas.Count;)
|
||||
{
|
||||
if (propertyDatas[i].totalProduction.Any(idcnt => idcnt.count > 0) || propertyDatas[i].totalConsumption.Any(idcnt => idcnt.count > 0))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
propertyDatas.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveAllMetadataConsumptions()
|
||||
{
|
||||
var propertySystem = DSPGame.propertySystem;
|
||||
if (propertySystem == null) return;
|
||||
PurgePropertySystem(propertySystem);
|
||||
var itemCnt = new int[6];
|
||||
foreach (var cons in propertySystem.propertyDatas.SelectMany(data => data.totalConsumption.Where(cons => cons.id is >= 6001 and <= 6006)))
|
||||
{
|
||||
itemCnt[cons.id - 6001] += cons.count;
|
||||
}
|
||||
|
||||
if (itemCnt.All(cnt => cnt == 0))
|
||||
{
|
||||
UIMessageBox.Show("Remove all metadata consumption records".Translate(), "NoMetadataConsumptionRecord".Translate(), "OK".Translate(), 0);
|
||||
return;
|
||||
}
|
||||
var msg = "ClearAllMetadataConsumptionDetails".Translate();
|
||||
for (var i = 0; i < 6; i++)
|
||||
{
|
||||
if (itemCnt[i] > 0)
|
||||
{
|
||||
msg += $"\n {LDB.items.Select(i + 6001).propertyName} x{itemCnt[i]}";
|
||||
}
|
||||
}
|
||||
UIMessageBox.Show("Remove all metadata consumption records".Translate(), msg, "取消".Translate(), "确定".Translate(), 2, null, () =>
|
||||
{
|
||||
foreach (var data in propertySystem.propertyDatas)
|
||||
{
|
||||
for (var i = 0; i < data.totalConsumption.Count; i++)
|
||||
{
|
||||
if (data.totalConsumption[i].count == 0) continue;
|
||||
var id = data.totalConsumption[i].id;
|
||||
data.totalConsumption[i] = new IDCNT(id, 0);
|
||||
}
|
||||
}
|
||||
PurgePropertySystem(propertySystem);
|
||||
propertySystem.SaveToFile();
|
||||
});
|
||||
}
|
||||
|
||||
public static void RemoveCurrentMetadataConsumptions()
|
||||
{
|
||||
var propertySystem = DSPGame.propertySystem;
|
||||
if (propertySystem == null) return;
|
||||
PurgePropertySystem(propertySystem);
|
||||
var itemCnt = new int[6];
|
||||
var seedKey = DSPGame.GameDesc.seedKey64;
|
||||
var clusterPropertyData = propertySystem.propertyDatas.FirstOrDefault(cpd => cpd.seedKey == seedKey);
|
||||
if (clusterPropertyData == null)
|
||||
{
|
||||
UIMessageBox.Show("Remove metadata consumption record in current game".Translate(), "NoMetadataConsumptionRecord".Translate(), "OK".Translate(), 0);
|
||||
return;
|
||||
}
|
||||
foreach (var cons in clusterPropertyData.totalConsumption.Where(cons => cons.id is >= 6001 and <= 6006))
|
||||
{
|
||||
itemCnt[cons.id - 6001] += cons.count;
|
||||
}
|
||||
|
||||
if (itemCnt.All(cnt => cnt == 0))
|
||||
{
|
||||
UIMessageBox.Show("Remove metadata consumption record in current game".Translate(), "NoMetadataConsumptionRecord".Translate(), "OK".Translate(), 0);
|
||||
return;
|
||||
}
|
||||
var msg = "ClearCurrentMetadataConsumptionDetails".Translate();
|
||||
for (var i = 0; i < 6; i++)
|
||||
{
|
||||
if (itemCnt[i] > 0)
|
||||
{
|
||||
msg += $"\n {LDB.items.Select(i + 6001).propertyName} x{itemCnt[i]}";
|
||||
}
|
||||
}
|
||||
UIMessageBox.Show("Remove metadata consumption record in current game".Translate(), msg, "取消".Translate(), "确定".Translate(), 2, null, () =>
|
||||
{
|
||||
for (var i = 0; i < clusterPropertyData.totalConsumption.Count; i++)
|
||||
{
|
||||
if (clusterPropertyData.totalConsumption[i].count == 0) continue;
|
||||
var id = clusterPropertyData.totalConsumption[i].id;
|
||||
clusterPropertyData.totalConsumption[i] = new IDCNT(id, 0);
|
||||
}
|
||||
PurgePropertySystem(propertySystem);
|
||||
propertySystem.SaveToFile();
|
||||
});
|
||||
}
|
||||
|
||||
public static void ClearMetadataBanAchievements()
|
||||
{
|
||||
GameMain.history.hasUsedPropertyBanAchievement = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user