refactor(CheatEnabler/UniverseGen): consume more centralized constants

This commit is contained in:
2026-06-23 20:48:35 +08:00
parent 25b33144b8
commit 1939a9cf22
6 changed files with 50 additions and 46 deletions
+13 -12
View File
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using UXAssist.Common;
using UXAssist.Common.GameConstants;
using UXAssist.Common.ModFeatures;
namespace CheatEnabler.Functions;
@@ -101,10 +102,10 @@ public static class PlayerFunctions
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)))
var itemCnt = new int[ItemIds.Metaverse - ItemIds.HydrogenFuelRod + 1];
foreach (var cons in propertySystem.propertyDatas.SelectMany(data => data.totalConsumption.Where(cons => cons.id is >= ItemIds.HydrogenFuelRod and <= ItemIds.Metaverse)))
{
itemCnt[cons.id - 6001] += cons.count;
itemCnt[cons.id - ItemIds.HydrogenFuelRod] += cons.count;
}
if (itemCnt.All(cnt => cnt == 0))
@@ -113,11 +114,11 @@ public static class PlayerFunctions
return;
}
var msg = "ClearAllMetadataConsumptionDetails".Translate();
for (var i = 0; i < 6; i++)
for (var i = 0; i < itemCnt.Length; i++)
{
if (itemCnt[i] > 0)
{
msg += $"\n {LDB.items.Select(i + 6001).propertyName} x{itemCnt[i]}";
msg += $"\n {LDB.items.Select(i + ItemIds.HydrogenFuelRod).propertyName} x{itemCnt[i]}";
}
}
UIMessageBox.Show("Remove all metadata consumption records".Translate(), msg, "取消".Translate(), "确定".Translate(), UIMessageBox.QUESTION, null, () =>
@@ -141,7 +142,7 @@ public static class PlayerFunctions
var propertySystem = DSPGame.propertySystem;
if (propertySystem == null) return;
PurgePropertySystem(propertySystem);
var itemCnt = new int[6];
var itemCnt = new int[ItemIds.Metaverse - ItemIds.HydrogenFuelRod + 1];
var seedKey = DSPGame.GameDesc.seedKey64;
var clusterPropertyData = propertySystem.propertyDatas.FirstOrDefault(cpd => cpd.seedKey == seedKey);
if (clusterPropertyData == null)
@@ -150,9 +151,9 @@ public static class PlayerFunctions
return;
}
var currentGamePropertyData = GameMain.data.history.propertyData;
foreach (var cons in currentGamePropertyData.totalConsumption.Where(cons => cons.id is >= 6001 and <= 6006))
foreach (var cons in currentGamePropertyData.totalConsumption.Where(cons => cons.id is >= ItemIds.HydrogenFuelRod and <= ItemIds.Metaverse))
{
itemCnt[cons.id - 6001] += cons.count;
itemCnt[cons.id - ItemIds.HydrogenFuelRod] += cons.count;
}
if (itemCnt.All(cnt => cnt == 0))
@@ -161,11 +162,11 @@ public static class PlayerFunctions
return;
}
var msg = "ClearCurrentMetadataConsumptionDetails".Translate();
for (var i = 0; i < 6; i++)
for (var i = 0; i < itemCnt.Length; i++)
{
if (itemCnt[i] > 0)
{
msg += $"\n {LDB.items.Select(i + 6001).propertyName} x{itemCnt[i]}";
msg += $"\n {LDB.items.Select(i + ItemIds.HydrogenFuelRod).propertyName} x{itemCnt[i]}";
}
}
UIMessageBox.Show("Remove metadata consumption record in current game".Translate(), msg, "取消".Translate(), "确定".Translate(), UIMessageBox.QUESTION, null, () =>
@@ -174,8 +175,8 @@ public static class PlayerFunctions
{
if (clusterPropertyData.totalConsumption[i].count == 0) continue;
var id = clusterPropertyData.totalConsumption[i].id;
if (id < 6001 || id > 6006) continue;
var currentGameCount = itemCnt[id - 6001];
if (id < ItemIds.HydrogenFuelRod || id > ItemIds.Metaverse) continue;
var currentGameCount = itemCnt[id - ItemIds.HydrogenFuelRod];
if (currentGameCount == 0) continue;
var totalCount = clusterPropertyData.totalConsumption[i].count;
clusterPropertyData.totalConsumption[i] = new IDCNT(id, totalCount > currentGameCount ? totalCount - currentGameCount : 0);
@@ -246,7 +246,7 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
if (result.TryGetValue(ItemIds.ProliferatorMkIII, out var pv))
{
proliferatorCount = pv;
result.Remove(1143);
result.Remove(ItemIds.ProliferatorMkIII);
}
if (FactoryPatch.BeltSignalUseProliferatorEnabled.Value)
{
+4 -3
View File
@@ -5,6 +5,7 @@ using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine.UI;
using UXAssist.Common;
using UXAssist.Common.GameConstants;
using UXAssist.Common.ModFeatures;
namespace UniverseGenTweaks;
@@ -87,7 +88,7 @@ public static class EpicDifficulty
[HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect._OnInit))]
private static void PatchGalaxyUI_OnInit(UIGalaxySelect __instance)
{
__instance.resourceMultiplierSlider.maxValue = 11f;
__instance.resourceMultiplierSlider.maxValue = UniverseGenConstants.ResourceMultiplierSliderMax;
}
[HarmonyPrefix]
@@ -165,10 +166,10 @@ public static class EpicDifficulty
matcher.Start().InsertAndAdvance(
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(GameDesc), nameof(GameDesc.resourceMultiplier))),
new CodeInstruction(OpCodes.Ldc_R4, 0.05f),
new CodeInstruction(OpCodes.Ldc_R4, UniverseGenConstants.OilMultiplierThreshold),
new CodeInstruction(OpCodes.Ble_S, label1)
).End().Advance(1).Insert(
new CodeInstruction(OpCodes.Ldc_R4, 0.5f * OilMultiplier.Value).WithLabels(label1),
new CodeInstruction(OpCodes.Ldc_R4, UniverseGenConstants.OilMultiplierBase * OilMultiplier.Value).WithLabels(label1),
new CodeInstruction(OpCodes.Ret)
);
}
@@ -80,15 +80,15 @@ public static class GalaxySelectUIPatch
_maxStepTitle.name = "max-step";
_flattenTitle.name = "flatten";
TransformDeltaY(_minDistTitle.transform, -36f);
TransformDeltaY(_minStepTitle.transform, -36f * 2);
TransformDeltaY(_maxStepTitle.transform, -36f * 3);
TransformDeltaY(_flattenTitle.transform, -36f * 4);
TransformDeltaY(__instance.darkFogToggle.transform.parent, -36f * 4);
TransformDeltaY(__instance.resourceMultiplierSlider.transform.parent, -36f * 4);
TransformDeltaY(__instance.sandboxToggle.transform.parent, -36f * 4);
TransformDeltaY(__instance.propertyMultiplierText.transform, -36f * 4);
TransformDeltaY(__instance.addrText.transform.parent, -36f * 4);
TransformDeltaY(_minDistTitle.transform, UniverseGenConstants.SliderRowSpacing);
TransformDeltaY(_minStepTitle.transform, UniverseGenConstants.SliderRowSpacing * 2);
TransformDeltaY(_maxStepTitle.transform, UniverseGenConstants.SliderRowSpacing * 3);
TransformDeltaY(_flattenTitle.transform, UniverseGenConstants.SliderRowSpacing * 4);
TransformDeltaY(__instance.darkFogToggle.transform.parent, UniverseGenConstants.SliderRowSpacing * 4);
TransformDeltaY(__instance.resourceMultiplierSlider.transform.parent, UniverseGenConstants.SliderRowSpacing * 4);
TransformDeltaY(__instance.sandboxToggle.transform.parent, UniverseGenConstants.SliderRowSpacing * 4);
TransformDeltaY(__instance.propertyMultiplierText.transform, UniverseGenConstants.SliderRowSpacing * 4);
TransformDeltaY(__instance.addrText.transform.parent, UniverseGenConstants.SliderRowSpacing * 4);
RemoveAllListeners();
UpdateSliderControls();
@@ -138,21 +138,21 @@ public static class GalaxySelectUIPatch
private static void UpdateSliderControls()
{
_minDistSlider.minValue = 10f;
_minDistSlider.maxValue = 50f;
_minDistSlider.value = (float)(GalaxyGenSettingsPatch.MinDist * 10.0);
_minDistSlider.minValue = UniverseGenConstants.MinDistSliderMin;
_minDistSlider.maxValue = UniverseGenConstants.MinDistSliderMax;
_minDistSlider.value = (float)(GalaxyGenSettingsPatch.MinDist * UniverseGenConstants.StepSliderScale);
_minStepSlider.minValue = (float)(GalaxyGenSettingsPatch.MinDist * 10.0);
_minStepSlider.maxValue = (float)(GalaxyGenSettingsPatch.MaxStep * 10.0);
_minStepSlider.value = (float)(GalaxyGenSettingsPatch.MinStep * 10.0);
_minStepSlider.minValue = (float)(GalaxyGenSettingsPatch.MinDist * UniverseGenConstants.StepSliderScale);
_minStepSlider.maxValue = (float)(GalaxyGenSettingsPatch.MaxStep * UniverseGenConstants.StepSliderScale);
_minStepSlider.value = (float)(GalaxyGenSettingsPatch.MinStep * UniverseGenConstants.StepSliderScale);
_maxStepSlider.minValue = (float)(GalaxyGenSettingsPatch.MinStep * 10.0);
_maxStepSlider.maxValue = 100f;
_maxStepSlider.value = (float)(GalaxyGenSettingsPatch.MaxStep * 10.0);
_maxStepSlider.minValue = (float)(GalaxyGenSettingsPatch.MinStep * UniverseGenConstants.StepSliderScale);
_maxStepSlider.maxValue = UniverseGenConstants.MaxStepSliderMax;
_maxStepSlider.value = (float)(GalaxyGenSettingsPatch.MaxStep * UniverseGenConstants.StepSliderScale);
_flattenSlider.minValue = 1f;
_flattenSlider.maxValue = 50f;
_flattenSlider.value = (float)(GalaxyGenSettingsPatch.Flatten * 50.0);
_flattenSlider.minValue = UniverseGenConstants.FlattenSliderMin;
_flattenSlider.maxValue = UniverseGenConstants.FlattenSliderMax;
_flattenSlider.value = (float)(GalaxyGenSettingsPatch.Flatten * UniverseGenConstants.FlattenSliderScale);
_minDistText.text = GalaxyGenSettingsPatch.MinDist.ToString();
_minStepText.text = GalaxyGenSettingsPatch.MinStep.ToString();
@@ -174,7 +174,7 @@ public static class GalaxySelectUIPatch
{
_minDistSlider.onValueChanged.AddListener(val =>
{
var newVal = Mathf.Round(val) / 10.0;
var newVal = Mathf.Round(val) / UniverseGenConstants.StepSliderScale;
if (newVal.Equals(GalaxyGenSettingsPatch.MinDist)) return;
GalaxyGenSettingsPatch.MinDist = newVal;
_minDistText.text = GalaxyGenSettingsPatch.MinDist.ToString();
@@ -195,7 +195,7 @@ public static class GalaxySelectUIPatch
});
_minStepSlider.onValueChanged.AddListener(val =>
{
var newVal = Mathf.Round(val) / 10.0;
var newVal = Mathf.Round(val) / UniverseGenConstants.StepSliderScale;
if (newVal.Equals(GalaxyGenSettingsPatch.MinStep)) return;
GalaxyGenSettingsPatch.MinStep = newVal;
_maxStepSlider.minValue = (float)(newVal * 10.0);
@@ -204,7 +204,7 @@ public static class GalaxySelectUIPatch
});
_maxStepSlider.onValueChanged.AddListener(val =>
{
var newVal = Mathf.Round(val) / 10.0;
var newVal = Mathf.Round(val) / UniverseGenConstants.StepSliderScale;
if (newVal.Equals(GalaxyGenSettingsPatch.MaxStep)) return;
GalaxyGenSettingsPatch.MaxStep = newVal;
_minStepSlider.maxValue = (float)(newVal * 10.0);
@@ -213,7 +213,7 @@ public static class GalaxySelectUIPatch
});
_flattenSlider.onValueChanged.AddListener(val =>
{
var newVal = Mathf.Round(val) / 50.0;
var newVal = Mathf.Round(val) / UniverseGenConstants.FlattenSliderScale;
if (newVal.Equals(GalaxyGenSettingsPatch.Flatten)) return;
GalaxyGenSettingsPatch.Flatten = newVal;
_flattenText.text = GalaxyGenSettingsPatch.Flatten.ToString();
+3 -2
View File
@@ -1,6 +1,7 @@
using UnityEngine;
using UXAssist.UI;
using UXAssist.Common;
using UXAssist.Common.GameConstants;
namespace UniverseGenTweaks;
@@ -51,10 +52,10 @@ public static class UIConfigWindow
MyWindow.AddText(x, y, tab1, "Maximum star count", 16);
x += 20f;
y += 26f;
var sl0 = MySlider.CreateSlider(x, y, tab1, MoreSettings.MaxStarCount.Value, 64f, 1024f, "G", 240f);
var sl0 = MySlider.CreateSlider(x, y, tab1, MoreSettings.MaxStarCount.Value, UniverseGenConstants.StarCountSliderMin, UniverseGenConstants.StarCountSliderMax, "G", 240f);
sl0.OnValueChanged += () =>
{
sl0.Value = MoreSettings.MaxStarCount.Value = (Mathf.RoundToInt(sl0.Value) + 7) & ~7;
sl0.Value = MoreSettings.MaxStarCount.Value = (Mathf.RoundToInt(sl0.Value) + UniverseGenConstants.StarCountAlignmentMask) & ~UniverseGenConstants.StarCountAlignmentMask;
};
x -= 30f;
y += 36f;
+4 -3
View File
@@ -3,6 +3,7 @@ using System.Reflection;
using BepInEx;
using BepInEx.Configuration;
using crecheng.DSPModSave;
using UXAssist.Common.GameConstants;
using UXAssist.Common.ModFeatures;
namespace UniverseGenTweaks;
@@ -19,9 +20,9 @@ public class UniverseGenTweaks : BaseUnityPlugin, IModCanSave
private void Awake()
{
MoreSettings.Enabled = Config.Bind("MoreSettings", "Enabled", true, "Enable more settings on Universe Generation");
MoreSettings.MaxStarCount = Config.Bind("MoreSettings", "MaxStarCount", 128,
new ConfigDescription("(32 ~ 1024)\nMaximum star count for Universe Generation, enable MoreSettings.Enabled to take effect",
new AcceptableValueRange<int>(32, 1024), new { }));
MoreSettings.MaxStarCount = Config.Bind("MoreSettings", "MaxStarCount", UniverseGenConstants.DefaultMaxStarCount,
new ConfigDescription($"({UniverseGenConstants.MinStarCount} ~ {UniverseGenConstants.MaxStarCount})\nMaximum star count for Universe Generation, enable MoreSettings.Enabled to take effect",
new AcceptableValueRange<int>(UniverseGenConstants.MinStarCount, UniverseGenConstants.MaxStarCount), new { }));
EpicDifficulty.Enabled = Config.Bind("EpicDifficulty", "Enabled", true, "Enable Epic difficulty");
EpicDifficulty.ResourceMultiplier = Config.Bind("EpicDifficulty", "ResourceMultiplier", 0.01f,