From 25b33144b8a14292d9649c084b7e9e60795ae9d7 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Tue, 23 Jun 2026 20:41:20 +0800 Subject: [PATCH] refactor(CheatEnabler/UniverseGen): consume centralized constants --- .../DysonSphere/FrameRemovalFunctions.cs | 3 +- .../Functions/DysonSphere/GeometryHelpers.cs | 21 +++-- .../DysonSphere/IllegalShellFunctions.cs | 91 ++++++++++--------- .../Patches/Factory/BeltSignalPatch.cs | 19 ++-- .../Patches/Factory/PowerBoostPatch.cs | 3 +- .../Patches/GalaxyGenSettingsPatch.cs | 40 ++++---- .../Patches/GalaxySelectUIPatch.cs | 9 +- 7 files changed, 92 insertions(+), 94 deletions(-) diff --git a/CheatEnabler/Functions/DysonSphere/FrameRemovalFunctions.cs b/CheatEnabler/Functions/DysonSphere/FrameRemovalFunctions.cs index d13565e..1adb207 100644 --- a/CheatEnabler/Functions/DysonSphere/FrameRemovalFunctions.cs +++ b/CheatEnabler/Functions/DysonSphere/FrameRemovalFunctions.cs @@ -2,6 +2,7 @@ using System; using HarmonyLib; using UnityEngine; using UXAssist.Common; +using UXAssist.Common.GameConstants; using UXAssist.Common.ModFeatures; namespace CheatEnabler.Functions.DysonSphere; @@ -46,7 +47,7 @@ public static class FrameRemovalFunctions } dysonSphereLayer.frameCursor = 1; dysonSphereLayer.frameRecycleCursor = 0; - dysonSphereLayer.SetFrameCapacity(64); + dysonSphereLayer.SetFrameCapacity(DysonSphereConstants.DefaultLayerPoolCapacity); totalFrameSpInfo?.SetValue(dysonSphereLayer, 0); } dysonSphere.CheckAutoNodes(); diff --git a/CheatEnabler/Functions/DysonSphere/GeometryHelpers.cs b/CheatEnabler/Functions/DysonSphere/GeometryHelpers.cs index 9085da0..3218470 100644 --- a/CheatEnabler/Functions/DysonSphere/GeometryHelpers.cs +++ b/CheatEnabler/Functions/DysonSphere/GeometryHelpers.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading; using UnityEngine; using UXAssist.Common; +using UXAssist.Common.GameConstants; namespace CheatEnabler.Functions.DysonSphere; @@ -39,7 +40,7 @@ public static class GeometryHelpers new PrecalculatedTriangle() { MaxOrbitRadius = 209946, PosA = new Vector3() { x = RawToFloat(0x00000000U), y = RawToFloat(0x00000000U), z = RawToFloat(0x484D0500U)}, PosB = new Vector3() { x = RawToFloat(0x48092F52U), y = RawToFloat(0x00000000U), z = RawToFloat(0x48185BF5U)}, PosC = new Vector3() { x = RawToFloat(0x2F02C70CU), y = RawToFloat(0x00000000U), z = RawToFloat(0xC84D0500U)} }, new PrecalculatedTriangle() { MaxOrbitRadius = 224422, PosA = new Vector3() { x = RawToFloat(0x00000000U), y = RawToFloat(0x00000000U), z = RawToFloat(0x485B2900U)}, PosB = new Vector3() { x = RawToFloat(0x4812A593U), y = RawToFloat(0x00000000U), z = RawToFloat(0x4822DE24U)}, PosC = new Vector3() { x = RawToFloat(0x2F0BCC2BU), y = RawToFloat(0x00000000U), z = RawToFloat(0xC85B2900U)} }, new PrecalculatedTriangle() { MaxOrbitRadius = 239136, PosA = new Vector3() { x = RawToFloat(0x00000000U), y = RawToFloat(0x00000000U), z = RawToFloat(0x48698680U)}, PosB = new Vector3() { x = RawToFloat(0x481C424DU), y = RawToFloat(0x00000000U), z = RawToFloat(0x482D8B0EU)}, PosC = new Vector3() { x = RawToFloat(0x2F14F5F7U), y = RawToFloat(0x00000000U), z = RawToFloat(0xC8698680U)} }, - new PrecalculatedTriangle() { MaxOrbitRadius = 250000, PosA = new Vector3() { x = RawToFloat(0x00000000U), y = RawToFloat(0x00000000U), z = RawToFloat(0x48742180U)}, PosB = new Vector3() { x = RawToFloat(0x48235AFEU), y = RawToFloat(0x00000000U), z = RawToFloat(0x48356CB1U)}, PosC = new Vector3() { x = RawToFloat(0x2F1BB9CEU), y = RawToFloat(0x00000000U), z = RawToFloat(0xC8742180U)} }, + new PrecalculatedTriangle() { MaxOrbitRadius = DysonSphereConstants.MaxOrbitRadius, PosA = new Vector3() { x = RawToFloat(0x00000000U), y = RawToFloat(0x00000000U), z = RawToFloat(0x48742180U)}, PosB = new Vector3() { x = RawToFloat(0x48235AFEU), y = RawToFloat(0x00000000U), z = RawToFloat(0x48356CB1U)}, PosC = new Vector3() { x = RawToFloat(0x2F1BB9CEU), y = RawToFloat(0x00000000U), z = RawToFloat(0xC8742180U)} }, ]; public struct PrecalculatedTriangle @@ -181,11 +182,11 @@ public static class GeometryHelpers num3 = num4; } } - var gridScale = (int)(Math.Pow(radius / 4000.0, 0.75) + 0.5); + var gridScale = (int)(Math.Pow(radius / DysonSphereConstants.GridScaleBaseRadius, 0.75) + 0.5); gridScale = ((gridScale < 1) ? 1 : gridScale); - var gridSize = gridScale * 80f; + var gridSize = gridScale * DysonSphereConstants.GridSizeBase; var gridSizeDouble = (double)gridSize; - var cpPerVertex = gridScale * gridScale * 2; + var cpPerVertex = gridScale * gridScale * DysonSphereConstants.CpPerVertexFactor; var num5 = (int)((double)num3 / factor3 / gridSizeDouble + 2.5); var xaxis = VectorLF3.Cross(center, Vector3.up).normalized; @@ -317,11 +318,11 @@ public static class GeometryHelpers num3 = num4; } } - shell.gridScale = (int)(Math.Pow(shell.radius / 4000.0, 0.75) + 0.5); + shell.gridScale = (int)(Math.Pow(shell.radius / DysonSphereConstants.GridScaleBaseRadius, 0.75) + 0.5); shell.gridScale = ((shell.gridScale < 1) ? 1 : shell.gridScale); - shell.gridSize = shell.gridScale * 80f; + shell.gridSize = shell.gridScale * DysonSphereConstants.GridSizeBase; var gridSizeDouble = (double)shell.gridSize; - shell.cpPerVertex = shell.gridScale * shell.gridScale * 2; + shell.cpPerVertex = shell.gridScale * shell.gridScale * DysonSphereConstants.CpPerVertexFactor; int num5 = (int)((double)num3 / factor3 / gridSizeDouble + 2.5); shell.xaxis = VectorLF3.Cross(normalized, Vector3.up).normalized; if (shell.xaxis.magnitude < 0.1) @@ -427,7 +428,7 @@ public static class GeometryHelpers } } int count2 = DysonShell.s_vmap.Count; - if (count2 > 32767) + if (count2 > DysonSphereConstants.MaxShellVertices) { return false; } @@ -694,7 +695,7 @@ public static class GeometryHelpers shell.id = shellId; shell.layerId = layer.id; shell.protoId = protoId; - shell.randSeed = layer.id * 10000 + shellId; + shell.randSeed = layer.id * DysonSphereConstants.ShellRandSeedMultiplier + shellId; for (int j = 0; j < nodes.Length; j++) { DysonNode dysonNode = nodes[j]; @@ -718,7 +719,7 @@ public static class GeometryHelpers shell.nodes.Add(dysonNode); shell.frames.Add(dysonFrame); } - if (!shell.GenerateCustomShellGeometry() || (limit && DysonShell.s_vmap.Count < 32000)) + if (!shell.GenerateCustomShellGeometry() || (limit && DysonShell.s_vmap.Count < DysonSphereConstants.MinShellVertexThreshold)) { CheatEnabler.Logger.LogDebug($"Stripped VertCount: {DysonShell.s_vmap.Count}"); shell.Free(); diff --git a/CheatEnabler/Functions/DysonSphere/IllegalShellFunctions.cs b/CheatEnabler/Functions/DysonSphere/IllegalShellFunctions.cs index 74193e5..2e11a39 100644 --- a/CheatEnabler/Functions/DysonSphere/IllegalShellFunctions.cs +++ b/CheatEnabler/Functions/DysonSphere/IllegalShellFunctions.cs @@ -6,6 +6,7 @@ using CheatEnabler.Functions; using static CheatEnabler.Functions.DysonSphere.GeometryHelpers; using UnityEngine; using UXAssist.Common; +using UXAssist.Common.GameConstants; using UXAssist.Common.ModFeatures; namespace CheatEnabler.Functions.DysonSphere; @@ -22,20 +23,20 @@ public static class IllegalShellFunctions private static void ResetLayerPools(DysonSphereLayer layer) { - layer.nodePool = new DysonNode[64]; - layer.nodeRecycle = new int[64]; + layer.nodePool = new DysonNode[DysonSphereConstants.DefaultLayerPoolCapacity]; + layer.nodeRecycle = new int[DysonSphereConstants.DefaultLayerPoolCapacity]; layer.nodeRecycleCursor = 0; - layer.nodeCapacity = 64; + layer.nodeCapacity = DysonSphereConstants.DefaultLayerPoolCapacity; layer.nodeCursor = 1; - layer.framePool = new DysonFrame[64]; - layer.frameRecycle = new int[64]; + layer.framePool = new DysonFrame[DysonSphereConstants.DefaultLayerPoolCapacity]; + layer.frameRecycle = new int[DysonSphereConstants.DefaultLayerPoolCapacity]; layer.frameRecycleCursor = 0; - layer.frameCapacity = 64; + layer.frameCapacity = DysonSphereConstants.DefaultLayerPoolCapacity; layer.frameCursor = 1; - layer.shellPool = new DysonShell[64]; - layer.shellRecycle = new int[64]; + layer.shellPool = new DysonShell[DysonSphereConstants.DefaultLayerPoolCapacity]; + layer.shellRecycle = new int[DysonSphereConstants.DefaultLayerPoolCapacity]; layer.shellRecycleCursor = 0; - layer.shellCapacity = 64; + layer.shellCapacity = DysonSphereConstants.DefaultLayerPoolCapacity; layer.shellCursor = 1; } @@ -119,7 +120,7 @@ public static class IllegalShellFunctions for (var j = 0; j < nodeCount; j++) { totalCpMax[j] += cpMax[j]; - if (totalCpMax[j] > int.MaxValue) + if (totalCpMax[j] > DysonSphereConstants.TotalCpMaxCeiling) { totalCpMax[j] = cpMax[j]; dirtyFrames.Add(j > 0 ? j - 1 : nodeCount - 1); @@ -166,7 +167,7 @@ public static class IllegalShellFunctions shells[j] = null; } var poolCapacity = GeometryHelpers.AlignUpToPowerOfTwo(retainCount + 1); - if (poolCapacity < 64) poolCapacity = 64; + if (poolCapacity < DysonSphereConstants.DefaultLayerPoolCapacity) poolCapacity = DysonSphereConstants.DefaultLayerPoolCapacity; layer.shellPool = new DysonShell[poolCapacity]; layer.shellRecycle = new int[poolCapacity]; layer.shellRecycleCursor = 0; @@ -192,7 +193,7 @@ public static class IllegalShellFunctions var nodes = layer.nodePool.Where(node => node != null && retainNodes.Contains(node.id)).ToArray(); var frames = layer.framePool.Where(frame => frame != null && retainFrames.Contains((frame.nodeA.id, frame.nodeB.id))).ToArray(); poolCapacity = GeometryHelpers.AlignUpToPowerOfTwo(frames.Length + 1); - if (poolCapacity < 64) poolCapacity = 64; + if (poolCapacity < DysonSphereConstants.DefaultLayerPoolCapacity) poolCapacity = DysonSphereConstants.DefaultLayerPoolCapacity; layer.framePool = new DysonFrame[poolCapacity]; layer.frameRecycle = new int[poolCapacity]; layer.frameRecycleCursor = 0; @@ -212,7 +213,7 @@ public static class IllegalShellFunctions } } poolCapacity = GeometryHelpers.AlignUpToPowerOfTwo(nodes.Length + 1); - if (poolCapacity < 64) poolCapacity = 64; + if (poolCapacity < DysonSphereConstants.DefaultLayerPoolCapacity) poolCapacity = DysonSphereConstants.DefaultLayerPoolCapacity; layer.nodePool = new DysonNode[poolCapacity]; layer.nodeRecycle = new int[poolCapacity]; layer.nodeRecycleCursor = 0; @@ -262,7 +263,7 @@ public static class IllegalShellFunctions continue; } var radius = dysonSphere.maxOrbitRadius; - for (; radius > 4000; radius -= 10) + for (; radius > DysonSphereConstants.MinOrbitRadiusSearch; radius -= DysonSphereConstants.OrbitRadiusSearchStep) { if (dysonSphere.CheckLayerRadius(radius) == 0) { @@ -279,7 +280,7 @@ public static class IllegalShellFunctions UIMessageBox.Show("CheatEnabler".Translate(), string.Format("No precalculated triangle found for radius {0}.".Translate(), radius), "确定".Translate(), UIMessageBox.ERROR, null); return; } - layer = dysonSphere.AddLayerOnId(i, radius, Quaternion.Euler(0f, 0f, 0f), Mathf.Sqrt(dysonSphere.gravity / radius) / radius * 57.2957802f); + layer = dysonSphere.AddLayerOnId(i, radius, Quaternion.Euler(0f, 0f, 0f), Mathf.Sqrt(dysonSphere.gravity / radius) / radius * DysonSphereConstants.RadiansToDegrees); if (layer == null) return; Vector3[] nodePos = [triangle.PosA.normalized * radius, triangle.PosB.normalized * radius, triangle.PosC.normalized * radius]; DysonNode[] nodes = [layer.QuickAddDysonNode(0, nodePos[0]), layer.QuickAddDysonNode(0, nodePos[1]), layer.QuickAddDysonNode(0, nodePos[2])]; @@ -296,7 +297,7 @@ public static class IllegalShellFunctions for (var k = 0; k < 3; k++) { totalCpMax[k] += cpMax[k]; - if (totalCpMax[k] > int.MaxValue) + if (totalCpMax[k] > DysonSphereConstants.TotalCpMaxCeiling) { totalCpMax[k] = cpMax[k]; dirtyFrames.Add(k > 0 ? k - 1 : 2); @@ -325,17 +326,17 @@ public static class IllegalShellFunctions EnsureDysonShellMaps(); var shellsChanged = false; var mutex = new object(); - var supposedShells = new List(60 * 59 * 58); - Vector3[] nodePos = new Vector3[60]; - for (var i = 0; i < 60; i++) + var supposedShells = new List(DysonSphereConstants.MaxShellSearchCombinations); + Vector3[] nodePos = new Vector3[DysonSphereConstants.MaxShellSearchNodeCount]; + for (var i = 0; i < DysonSphereConstants.MaxShellSearchNodeCount; i++) { - nodePos[i] = new Vector3((float)Math.Sin(Math.PI * 2 * i / 60), 0, (float)Math.Cos(Math.PI * 2 * i / 60)) * layer.orbitRadius; + nodePos[i] = new Vector3((float)Math.Sin(Math.PI * 2 * i / DysonSphereConstants.MaxShellSearchNodeCount), 0, (float)Math.Cos(Math.PI * 2 * i / DysonSphereConstants.MaxShellSearchNodeCount)) * layer.orbitRadius; } - for (var i = 0; i < 58; i++) + for (var i = 0; i < DysonSphereConstants.MaxShellSearchNodeCount - 2; i++) { - for (var j = i + 1; j < 59; j++) + for (var j = i + 1; j < DysonSphereConstants.MaxShellSearchNodeCount - 1; j++) { - for (var k = j + 1; k < 60; k++) + for (var k = j + 1; k < DysonSphereConstants.MaxShellSearchNodeCount; k++) { var area = Vector3.Cross(nodePos[j] - nodePos[i], nodePos[k] - nodePos[i]).sqrMagnitude; supposedShells.Add(new SupposedShell { posA = nodePos[i], posB = nodePos[j], posC = nodePos[k], area = area }); @@ -348,11 +349,11 @@ public static class IllegalShellFunctions var maxJ = -1; var options = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount - 1 }; - var gridScale = (int)(Math.Pow(layer.orbitRadius / 4000.0, 0.75) + 0.5); + var gridScale = (int)(Math.Pow(layer.orbitRadius / DysonSphereConstants.GridScaleBaseRadius, 0.75) + 0.5); gridScale = (gridScale < 1) ? 1 : gridScale; - var cpPerVertex = gridScale * gridScale * 2; - var barrier = 0x7FFFFFFF / cpPerVertex; - if (barrier > 32767) barrier = 32767; + var cpPerVertex = gridScale * gridScale * DysonSphereConstants.CpPerVertexFactor; + var barrier = DysonSphereConstants.TotalCpMaxCeiling / cpPerVertex; + if (barrier > DysonSphereConstants.MaxShellVertices) barrier = DysonSphereConstants.MaxShellVertices; var truncValue = barrier / 1000 * 1000; CheatEnabler.Logger.LogDebug($"cpPerVertex: {cpPerVertex}, Barrier: {barrier}, TruncValue: {truncValue}"); @@ -409,7 +410,7 @@ public static class IllegalShellFunctions dysonSphere.RemoveLayer(1); } var maxOrbitRadius = Patches.DysonSpherePatch.UnlockMaxOrbitRadiusEnabled.Value ? Patches.DysonSpherePatch.UnlockMaxOrbitRadiusValue.Value : dysonSphere.maxOrbitRadius; - layer = dysonSphere.AddLayerOnId(1, maxOrbitRadius, Quaternion.Euler(0f, 0f, 0f), Mathf.Sqrt(dysonSphere.gravity / maxOrbitRadius) / maxOrbitRadius * 57.2957802f); + layer = dysonSphere.AddLayerOnId(1, maxOrbitRadius, Quaternion.Euler(0f, 0f, 0f), Mathf.Sqrt(dysonSphere.gravity / maxOrbitRadius) / maxOrbitRadius * DysonSphereConstants.RadiansToDegrees); if (layer == null) return; var shellsChanged = CreateIllegalDysonShellWithMaxOutputForLayer(layer); @@ -437,16 +438,16 @@ public static class IllegalShellFunctions { var lastGridScale = 0; var radiusList = new List(); - for (var r = 4000; r <= 250000; r++) + for (var r = DysonSphereConstants.MinOrbitRadiusSearch; r <= DysonSphereConstants.MaxOrbitRadius; r++) { - var gridScale = (int)(Math.Pow(r / 4000.0, 0.75) + 0.5); + var gridScale = (int)(Math.Pow(r / DysonSphereConstants.GridScaleBaseRadius, 0.75) + 0.5); gridScale = (gridScale < 1) ? 1 : gridScale; if (gridScale == lastGridScale) continue; lastGridScale = gridScale; radiusList.Add(r); CheatEnabler.Logger.LogDebug($"Grid Scale: {gridScale} from {r}"); } - radiusList.Add(250000); + radiusList.Add(DysonSphereConstants.MaxOrbitRadius); var resolved = DysonSphereResolver.ResolveEditorOrLocalSphere(requireLayer: false); if (resolved == null) return; var (dysonSphere, star) = resolved.Value; @@ -466,20 +467,20 @@ public static class IllegalShellFunctions dysonSphere.RemoveLayer(idx); } var orbitRadius = (radiusList[idx] - 1) / 10 * 10f; - layer = dysonSphere.AddLayerOnId(idx, orbitRadius, Quaternion.Euler(0f, 0f, 0f), Mathf.Sqrt(dysonSphere.gravity / orbitRadius) / orbitRadius * 57.2957802f); + layer = dysonSphere.AddLayerOnId(idx, orbitRadius, Quaternion.Euler(0f, 0f, 0f), Mathf.Sqrt(dysonSphere.gravity / orbitRadius) / orbitRadius * DysonSphereConstants.RadiansToDegrees); if (layer == null) return; - var supposedShells = new List(60 * 59 * 58); - Vector3[] nodePos = new Vector3[60]; - for (var i = 0; i < 60; i++) + var supposedShells = new List(DysonSphereConstants.MaxShellSearchCombinations); + Vector3[] nodePos = new Vector3[DysonSphereConstants.MaxShellSearchNodeCount]; + for (var i = 0; i < DysonSphereConstants.MaxShellSearchNodeCount; i++) { - nodePos[i] = new Vector3((float)Math.Sin(Math.PI * 2 * i / 60), 0, (float)Math.Cos(Math.PI * 2 * i / 60)); + nodePos[i] = new Vector3((float)Math.Sin(Math.PI * 2 * i / DysonSphereConstants.MaxShellSearchNodeCount), 0, (float)Math.Cos(Math.PI * 2 * i / DysonSphereConstants.MaxShellSearchNodeCount)); } - for (var i = 0; i < 58; i++) + for (var i = 0; i < DysonSphereConstants.MaxShellSearchNodeCount - 2; i++) { - for (var j = i + 1; j < 59; j++) + for (var j = i + 1; j < DysonSphereConstants.MaxShellSearchNodeCount - 1; j++) { - for (var k = j + 1; k < 60; k++) + for (var k = j + 1; k < DysonSphereConstants.MaxShellSearchNodeCount; k++) { var area = Vector3.Cross(nodePos[j] - nodePos[i], nodePos[k] - nodePos[i]).sqrMagnitude; supposedShells.Add(new SupposedShell { posA = nodePos[i], posB = nodePos[j], posC = nodePos[k], area = area }); @@ -490,10 +491,10 @@ public static class IllegalShellFunctions var options = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount - 1 }; - var gridScale = (int)(Math.Pow(orbitRadius / 4000.0, 0.75) + 0.5); + var gridScale = (int)(Math.Pow(orbitRadius / DysonSphereConstants.GridScaleBaseRadius, 0.75) + 0.5); gridScale = (gridScale < 1) ? 1 : gridScale; - var cpPerVertex = gridScale * gridScale * 2; - var barrier = 0x7FFFFFFF / cpPerVertex; + var cpPerVertex = gridScale * gridScale * DysonSphereConstants.CpPerVertexFactor; + var barrier = DysonSphereConstants.TotalCpMaxCeiling / cpPerVertex; if (barrier > 30000) barrier = 30000; Parallel.For(0, supposedShells.Count, options, (j, _) => @@ -517,10 +518,10 @@ public static class IllegalShellFunctions var result = Parallel.For((radiusList[idx - 1] + 9) / 10, (radiusList[idx] + 9) / 10, options, (k, loopState) => { var orbitRadius = k * 10f; - var gridScale = (int)(Math.Pow(orbitRadius / 4000.0, 0.75) + 0.5); + var gridScale = (int)(Math.Pow(orbitRadius / DysonSphereConstants.GridScaleBaseRadius, 0.75) + 0.5); gridScale = (gridScale < 1) ? 1 : gridScale; - var cpPerVertex = gridScale * gridScale * 2; - var barrier = 0x7FFFFFFF / cpPerVertex; + var cpPerVertex = gridScale * gridScale * DysonSphereConstants.CpPerVertexFactor; + var barrier = DysonSphereConstants.TotalCpMaxCeiling / cpPerVertex; if (barrier > 31000) barrier = 31000; if (loopState.ShouldExitCurrentIteration) return; var vertCount = GeometryHelpers.CalculateTriangleVertCount([sshell.posA * orbitRadius, sshell.posB * orbitRadius, sshell.posC * orbitRadius]); diff --git a/CheatEnabler/Patches/Factory/BeltSignalPatch.cs b/CheatEnabler/Patches/Factory/BeltSignalPatch.cs index b3e453f..11e1403 100644 --- a/CheatEnabler/Patches/Factory/BeltSignalPatch.cs +++ b/CheatEnabler/Patches/Factory/BeltSignalPatch.cs @@ -5,6 +5,7 @@ using HarmonyLib; using UnityEngine; using UXAssist.Common; using GameLogicProc = UXAssist.Common.GameLogic; +using UXAssist.Common.GameConstants; namespace CheatEnabler.Patches.Factory; @@ -242,7 +243,7 @@ internal class BeltSignalGenerator : PatchImpl CalculateAllProductions(result, extra, ref sprayedCount, itemId); var proliferatorCount = 0f; - if (result.TryGetValue(1143, out var pv)) + if (result.TryGetValue(ItemIds.ProliferatorMkIII, out var pv)) { proliferatorCount = pv; result.Remove(1143); @@ -260,7 +261,7 @@ internal class BeltSignalGenerator : PatchImpl } if (proliferatorCount > 0f) { - foreach (var p in ProliferatorSources) + foreach (var p in ItemIds.ProliferatorSources) { result[p.Item1] = (result.TryGetValue(p.Item1, out var v) ? v : 0) + p.Item2 * proliferatorCount / ProliferatorDenom; } @@ -591,11 +592,7 @@ internal class BeltSignalGenerator : PatchImpl } /* BEGIN: Item sources calculation */ - private static readonly int[] ExtraOreItemIds = [1000, 1116, 1120, 1121, 1208, 5201, 5202, 5203, 5204, 5205, 5206]; - private static readonly HashSet ExtraProliferationItemIds = [1107, 1111, 1125, 1142, 1143, 1202, 1203, 1204, 1205, 1209, 1210, 1301, 1305, 1401, 1402, 1403, 1405, 1406, 1502, 1503, 1802, 6001, 6003, 6004, 6005, 6006]; - private static readonly HashSet NoProliferationItemIds = [1126, 6002]; - // All source items used to create 25 proliferators mk.III (not self-sprayed) - private static readonly List<(int, float)> ProliferatorSources = [(1015, 60f), (1124, 20f), (1006, 64f), (1012, 16f), (1112, 32f), (1141, 64f), (1142, 40f), (1143, 25f)]; + // Item ID constants are provided by UXAssist.Common.GameConstants.ItemIds. private const float ProliferatorDenom = 21f; // One sprayed proliferator mk.III can spray 75 items, but one is used for spray itself, so the actual count is 74 private const float ProliferatorSpayCount = 74f; @@ -626,7 +623,7 @@ internal class BeltSignalGenerator : PatchImpl } // 水、硫酸、氢、重氢、光子 - foreach (var itemId in ExtraOreItemIds) + foreach (var itemId in ItemIds.ExtraOreItemIds) { ItemSources[itemId] = new ItemSource { Count = 1 }; } @@ -725,16 +722,16 @@ internal class BeltSignalGenerator : PatchImpl } } - if (itemId == 1143 || itemSource.From == null) return; + if (itemId == ItemIds.ProliferatorMkIII || itemSource.From == null) return; var useProliferator = FactoryPatch.BeltSignalUseProliferatorEnabled.Value; - if (useProliferator && ExtraProliferationItemIds.Contains(itemId)) + if (useProliferator && ItemIds.ExtraProliferationItemIds.Contains(itemId)) { times *= 0.8f; } foreach (var p in itemSource.From) { var value = p.Value * times; - if (useProliferator && !NoProliferationItemIds.Contains(p.Key)) sprayedCount += value; + if (useProliferator && !ItemIds.NoProliferationItemIds.Contains(p.Key)) sprayedCount += value; if (extra.TryGetValue(p.Key, out var rcount)) { if (value <= rcount) diff --git a/CheatEnabler/Patches/Factory/PowerBoostPatch.cs b/CheatEnabler/Patches/Factory/PowerBoostPatch.cs index 0679074..3c1fec6 100644 --- a/CheatEnabler/Patches/Factory/PowerBoostPatch.cs +++ b/CheatEnabler/Patches/Factory/PowerBoostPatch.cs @@ -3,6 +3,7 @@ using System.Reflection.Emit; using HarmonyLib; using UnityEngine; using UXAssist.Common; +using UXAssist.Common.GameConstants; namespace CheatEnabler.Patches.Factory; @@ -157,7 +158,7 @@ internal static class WindTurbinesPowerGlobalCoverage private static PrefabDesc _prefabdesc; private static float _oldCoverRadius; private static float _oldConnectDistance; - private const int WindTurbineId = 2203; + private const int WindTurbineId = ItemIds.WindTurbine; private const float WindTurbineNewCoverageDistance = 500f; public static void Enable(bool enable) diff --git a/UniverseGenTweaks/Patches/GalaxyGenSettingsPatch.cs b/UniverseGenTweaks/Patches/GalaxyGenSettingsPatch.cs index cd4309f..d33177e 100644 --- a/UniverseGenTweaks/Patches/GalaxyGenSettingsPatch.cs +++ b/UniverseGenTweaks/Patches/GalaxyGenSettingsPatch.cs @@ -3,6 +3,7 @@ using System.Reflection.Emit; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; +using UXAssist.Common.GameConstants; using UXAssist.Common.ModFeatures; namespace UniverseGenTweaks; @@ -10,20 +11,15 @@ namespace UniverseGenTweaks; [ModFeature("UniverseGenGalaxyGen", Order = 11)] public static class GalaxyGenSettingsPatch { - internal const double DefaultMinDist = 2; - internal const double DefaultMinStep = 2; - internal const double DefaultMaxStep = 3.2; - internal const double DefaultFlatten = 0.18; + internal static double MinDist = UniverseGenConstants.DefaultMinDist; + internal static double MinStep = UniverseGenConstants.DefaultMinStep; + internal static double MaxStep = UniverseGenConstants.DefaultMaxStep; + internal static double Flatten = UniverseGenConstants.DefaultFlatten; - internal static double MinDist = DefaultMinDist; - internal static double MinStep = DefaultMinStep; - internal static double MaxStep = DefaultMaxStep; - internal static double Flatten = DefaultFlatten; - - internal static double GameMinDist = DefaultMinDist; - internal static double GameMinStep = DefaultMinStep; - internal static double GameMaxStep = DefaultMaxStep; - internal static double GameFlatten = DefaultFlatten; + internal static double GameMinDist = UniverseGenConstants.DefaultMinDist; + internal static double GameMinStep = UniverseGenConstants.DefaultMinStep; + internal static double GameMaxStep = UniverseGenConstants.DefaultMaxStep; + internal static double GameFlatten = UniverseGenConstants.DefaultFlatten; private static Harmony _patch; private static Harmony _permanentPatch; @@ -68,7 +64,7 @@ public static class GalaxyGenSettingsPatch // Increase hard-coded maximum star count from 80 to MaxStarCount.Value var matcher = new CodeMatcher(instructions, generator); matcher.MatchForward(false, - new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4_S && ci.OperandIs(80)) + new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4_S && ci.OperandIs(UniverseGenConstants.VanillaMaxStarCount)) ).SetAndAdvance(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(MoreSettings.MaxStarCount))).Insert( new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(ConfigEntry), nameof(ConfigEntry.Value))) ); @@ -92,10 +88,10 @@ public static class GalaxyGenSettingsPatch } else { - GameMinDist = DefaultMinDist; - GameMinStep = DefaultMinStep; - GameMaxStep = DefaultMaxStep; - GameFlatten = DefaultFlatten; + GameMinDist = UniverseGenConstants.DefaultMinDist; + GameMinStep = UniverseGenConstants.DefaultMinStep; + GameMaxStep = UniverseGenConstants.DefaultMaxStep; + GameFlatten = UniverseGenConstants.DefaultFlatten; } } @@ -106,9 +102,9 @@ public static class GalaxyGenSettingsPatch // 25700 -> 102500 var matcher = new CodeMatcher(instructions, generator); matcher.MatchForward(false, - new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(25700)) + new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(UniverseGenConstants.VanillaGalaxyCapacity)) ); - matcher.Repeat(m => m.SetAndAdvance(OpCodes.Ldc_I4, 102500)); + matcher.Repeat(m => m.SetAndAdvance(OpCodes.Ldc_I4, UniverseGenConstants.ExpandedGalaxyCapacity)); return matcher.InstructionEnumeration(); } @@ -120,9 +116,9 @@ public static class GalaxyGenSettingsPatch // 25600 -> 102500 var matcher = new CodeMatcher(instructions, generator); matcher.MatchForward(false, - new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(25600)) + new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(UniverseGenConstants.VanillaSectorCapacity)) ); - matcher.Repeat(m => m.SetAndAdvance(OpCodes.Ldc_I4, 102500)); + matcher.Repeat(m => m.SetAndAdvance(OpCodes.Ldc_I4, UniverseGenConstants.ExpandedSectorCapacity)); return matcher.InstructionEnumeration(); } diff --git a/UniverseGenTweaks/Patches/GalaxySelectUIPatch.cs b/UniverseGenTweaks/Patches/GalaxySelectUIPatch.cs index cbbf5d2..37c6700 100644 --- a/UniverseGenTweaks/Patches/GalaxySelectUIPatch.cs +++ b/UniverseGenTweaks/Patches/GalaxySelectUIPatch.cs @@ -2,6 +2,7 @@ using HarmonyLib; using UnityEngine; using UnityEngine.UI; using UXAssist.Common; +using UXAssist.Common.GameConstants; using UXAssist.Common.ModFeatures; using Object = UnityEngine.Object; @@ -98,10 +99,10 @@ public static class GalaxySelectUIPatch [HarmonyPatch(typeof(UIGalaxySelect), nameof(UIGalaxySelect._OnOpen))] private static void UIGalaxySelect__OnOpen_Prefix(UIGalaxySelect __instance) { - GalaxyGenSettingsPatch.MinDist = GalaxyGenSettingsPatch.DefaultMinDist; - GalaxyGenSettingsPatch.MinStep = GalaxyGenSettingsPatch.DefaultMinStep; - GalaxyGenSettingsPatch.MaxStep = GalaxyGenSettingsPatch.DefaultMaxStep; - GalaxyGenSettingsPatch.Flatten = GalaxyGenSettingsPatch.DefaultFlatten; + GalaxyGenSettingsPatch.MinDist = UniverseGenConstants.DefaultMinDist; + GalaxyGenSettingsPatch.MinStep = UniverseGenConstants.DefaultMinStep; + GalaxyGenSettingsPatch.MaxStep = UniverseGenConstants.DefaultMaxStep; + GalaxyGenSettingsPatch.Flatten = UniverseGenConstants.DefaultFlatten; RemoveAllListeners(); UpdateSliderControls();