1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2026-03-31 13:27:33 +08:00

Fix potential bugs in UXAssist and CheatEnabler

UXAssist:
- PlanetFunctions: fix infinite loop in constructStats cleanup (i++ -> i--)
- PlanetFunctions: skip entityPool slot 0 (sentinel) in DismantleAll foreach
- PlanetFunctions: fix belt buffer walk infinite loop when buffer[j]==250,
  add cargoPool bounds check
- FactoryPatch: fix UnfixProto guard condition (< 3 -> < PowerPoleIds.Length)
- FactoryPatch: fix Array.Resize(index*2) -> (index+1)*2 to handle index==0
- LogisticsPatch: fix UpdateStorageMax early-exit to check both local and remote
- LogisticsPatch: fix storage max scan to use Math.Max instead of last-write
- LogisticsPatch: add divide-by-zero guard in station storage ratio calculation
- LogisticsPatch: fix station entry right-click delegates using per-instance
  dictionary instead of shared static array to prevent unsubscribe mismatch
- LogisticsPatch: add null checks for GameObject.Find results in InitGUI
- GamePatch: log exception in previously empty catch block
- GameLogic: invoke event handlers individually with try/catch so one failing
  subscriber does not abort subsequent ones
- DysonSpherePatch/LogisticsPatch/PersistPatch/PlayerPatch: replace
  matcher.Labels = null with matcher.Labels = [] (5 sites)
- UIConfigWindow: remove duplicate I18N.Add for 'Outgoing integration count'
- UIConfigWindow: remove two orphaned y += 36f spacing increments

CheatEnabler:
- GamePatch: add null check for GameMain.gameScenario in AbnormalDisabler.OnEnable
- FactoryPatch: add null check for GameMain.mainPlayer in TakeTailItemsPatch
  and GetItemCountPatch
- FactoryPatch: add null check for GameMain.mainPlayer in
  ConstructionSystem_GameTick_Prefix
- FactoryPatch: fix _portalFrom.Remove(beltId) -> Remove(v) (wrong key)
- FactoryPatch: add null guard for GameMain.data before iterating factories
  in WindTurbinesPowerGlobalCoverage
- DysonSphereFunctions: fix shell pool rebuild loop writing all shells to
  slot 1 (id=1); now uses j+1 per iteration
- DysonSphereFunctions: replace GameMain.gameScenario.NotifyOnPlanDysonShell()
  with null-conditional call (?.) at 4 sites
- DysonSpherePatch: fix SkipAbsorbPatch/QuickAbsorbPatch sharing _instantAbsorb:
  OnDisable now recalculates the flag instead of unconditionally clearing it
- PlayerFunctions: add null check for GameMain.galaxy in TeleportToOuterSpace
- UIConfigWindow: add null guard in UpdateButtons before accessing button fields
- PlanetFunctions: add colliderId bounds check in BuryAllVeins
This commit is contained in:
2026-03-16 19:51:16 +08:00
parent e91271e137
commit f69a90d452
16 changed files with 116 additions and 62 deletions

View File

@@ -1101,7 +1101,7 @@ public static class DysonSphereFunctions
dysonSphere.PickAutoNode();
}
dysonSphere.modelRenderer.RebuildModels();
GameMain.gameScenario.NotifyOnPlanDysonShell();
GameMain.gameScenario?.NotifyOnPlanDysonShell();
dysonSphere.inEditorRenderMaskS = 0;
dysonSphere.inEditorRenderMaskL = 0;
dysonSphere.inGameRenderMaskS = 0;
@@ -1163,8 +1163,9 @@ public static class DysonSphereFunctions
{
var shell = shells[j];
retainNodes.UnionWith(shell.nodes.Select(node => node.id));
layer.shellPool[1] = shell;
shell.id = 1;
int shellId = j + 1;
layer.shellPool[shellId] = shell;
shell.id = shellId;
for (var k = 0; k < shell.nodes.Count; k++)
{
var idA = shell.nodes[k].id;
@@ -1328,7 +1329,7 @@ public static class DysonSphereFunctions
dysonSphere.CheckAutoNodes();
if (dysonSphere.autoNodeCount <= 0) dysonSphere.PickAutoNode();
dysonSphere.modelRenderer.RebuildModels();
GameMain.gameScenario.NotifyOnPlanDysonShell();
GameMain.gameScenario?.NotifyOnPlanDysonShell();
return;
}
}
@@ -1460,7 +1461,7 @@ public static class DysonSphereFunctions
dysonSphere.CheckAutoNodes();
if (dysonSphere.autoNodeCount <= 0) dysonSphere.PickAutoNode();
dysonSphere.modelRenderer.RebuildModels();
if (shellsChanged) GameMain.gameScenario.NotifyOnPlanDysonShell();
if (shellsChanged) GameMain.gameScenario?.NotifyOnPlanDysonShell();
dysonSphere.inEditorRenderMaskS = 0;
dysonSphere.inEditorRenderMaskL = 0;
dysonSphere.inGameRenderMaskS = 0;
@@ -1623,7 +1624,7 @@ public static class DysonSphereFunctions
dysonSphere.CheckAutoNodes();
if (dysonSphere.autoNodeCount <= 0) dysonSphere.PickAutoNode();
dysonSphere.modelRenderer.RebuildModels();
if (shellsChanged) GameMain.gameScenario.NotifyOnPlanDysonShell();
if (shellsChanged) GameMain.gameScenario?.NotifyOnPlanDysonShell();
dysonSphere.inEditorRenderMaskS = 0;
dysonSphere.inEditorRenderMaskL = 0;
dysonSphere.inGameRenderMaskS = 0;

View File

@@ -17,9 +17,15 @@ public static class PlanetFunctions
{
var pos = array[m].pos;
var colliderId = array[m].colliderId;
if (colliderId <= 0) continue;
var chunkIdx = colliderId >> 20;
var poolIdx = colliderId & 0xFFFFF;
if (chunkIdx >= physics.colChunks.Length) continue;
var chunk = physics.colChunks[chunkIdx];
if (chunk == null || poolIdx >= chunk.colliderPool.Length) continue;
var colliderData = physics.GetColliderData(colliderId);
var vector = colliderData.pos.normalized * (height + 0.4f);
physics.colChunks[colliderId >> 20].colliderPool[colliderId & 0xFFFFF].pos = vector;
chunk.colliderPool[poolIdx].pos = vector;
array[m].pos = pos.normalized * height;
var quaternion = Maths.SphericalRotation(array[m].pos, Random.value * 360f);
physics.SetPlanetPhysicsColliderDirty();

View File

@@ -35,6 +35,7 @@ public static class PlayerFunctions
{
var maxSqrDistance = 0.0;
var starPosition = VectorLF3.zero;
if (GameMain.galaxy == null) return;
foreach (var star in GameMain.galaxy.stars)
{
var sqrDistance = star.position.sqrMagnitude;

View File

@@ -365,12 +365,12 @@ public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
{
protected override void OnEnable()
{
_instantAbsorb = QuickAbsorbEnabled.Value;
_instantAbsorb = QuickAbsorbEnabled.Value && QuickAbsorbPatch.GetHarmony() != null;
}
protected override void OnDisable()
{
_instantAbsorb = false;
_instantAbsorb = QuickAbsorbEnabled.Value && QuickAbsorbPatch.GetHarmony() != null;
}
[HarmonyTranspiler]
@@ -407,12 +407,12 @@ public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
{
protected override void OnEnable()
{
_instantAbsorb = SkipAbsorbEnabled.Value;
_instantAbsorb = SkipAbsorbEnabled.Value && SkipAbsorbPatch.GetHarmony() != null;
}
protected override void OnDisable()
{
_instantAbsorb = false;
_instantAbsorb = SkipAbsorbEnabled.Value && SkipAbsorbPatch.GetHarmony() != null;
}
[HarmonyTranspiler]

View File

@@ -448,6 +448,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
var factory = __instance.factory;
if (factory.prebuildCount <= 0) return;
var player = GameMain.mainPlayer;
if (player == null) return;
var total = factory.prebuildCursor - 1;
var stepCount = total switch
{
@@ -588,7 +589,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
[ArgumentType.Ref, ArgumentType.Ref, ArgumentType.Normal, ArgumentType.Out, ArgumentType.Normal])]
public static bool TakeTailItemsPatch(StorageComponent __instance, int itemId)
{
if (__instance == null || __instance.id != GameMain.mainPlayer.package.id) return true;
if (__instance == null || GameMain.mainPlayer == null || __instance.id != GameMain.mainPlayer.package.id) return true;
if (itemId <= 0) return true;
if (_canBuildItems == null)
{
@@ -603,7 +604,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
public static void GetItemCountPatch(StorageComponent __instance, int itemId, ref int __result)
{
if (__result > 99) return;
if (__instance == null || __instance.id != GameMain.mainPlayer.package.id) return;
if (__instance == null || GameMain.mainPlayer == null || __instance.id != GameMain.mainPlayer.package.id) return;
if (itemId <= 0) return;
if (_canBuildItems == null)
{
@@ -1020,7 +1021,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
{
var v = ((long)factory << 32) | (uint)beltId;
if (!_portalFrom.TryGetValue(v, out var number)) return;
_portalFrom.Remove(beltId);
_portalFrom.Remove(v);
if (!_portalTo.TryGetValue(number, out var set)) return;
set.Remove(v);
}
@@ -1649,6 +1650,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
}
// Iterate all factories and update wind turbines power nodes
if (GameMain.data == null) return;
foreach (var factory in GameMain.data.factories)
{
var powerSystem = factory?.powerSystem;

View File

@@ -42,7 +42,8 @@ public static class GamePatch
protected override void OnEnable()
{
if (_savedDeterminators == null) return;
var abnormalLogic = GameMain.gameScenario.abnormalityLogic;
var abnormalLogic = GameMain.gameScenario?.abnormalityLogic;
if (abnormalLogic == null) return;
foreach (var p in _savedDeterminators)
{
p.Value.OnUnregEvent();

View File

@@ -385,6 +385,7 @@ public static class UIConfigWindow
private static void UpdateButtons()
{
if (_resignGameBtn == null || _clearBanBtn == null) return;
var data = GameMain.data;
if (data == null) return;
var resignEnabled = data.account != AccountData.me;