mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-11-19 17:05:20 +08:00
fix(compat): restore wind coverage startup and entity hiding
Defer wind coverage changes until prefab data is ready and preserve retryable activation state. Replace fixed raycast local slots with semantic entity-field matching and guard fallback paths.
This commit is contained in:
1 parent
8a10fc909a
commit
60d54ac918
5 files changed
+44
-33
No files matched your search
@@ -26,12 +26,13 @@
|
|||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
- `ModFeatureRegistry` discovers dependent-mod features during `Awake`; feature initialization is eager, while UXAssist alone drives the deferred start, input, update, and uninitialization lifecycle. Keep dispatchers internal and idempotent.
|
- `ModFeatureRegistry` discovers dependent-mod features during `Awake`; feature initialization is eager, while UXAssist alone drives the deferred start, input, update, and uninitialization lifecycle. Keep dispatchers internal and idempotent.
|
||||||
|
- Proto-dependent features must tolerate calls before preload completes and retry via `UXAssist.Common.GameLogic.OnDataLoaded`. Mark changes applied only after capturing valid originals and successfully mutating the proto.
|
||||||
- Dispatch UXAssist shortcuts from the postfix of `VFInput.OnUpdate`, after DSP refreshes modifier and UI state. Keep typing/menu guards and per-frame registry guards; do not poll from an independent `Update()` or logic-tick callback.
|
- Dispatch UXAssist shortcuts from the postfix of `VFInput.OnUpdate`, after DSP refreshes modifier and UI state. Keep typing/menu guards and per-frame registry guards; do not poll from an independent `Update()` or logic-tick callback.
|
||||||
- Register localization keys through each project registration class and use `.Translate()` with keys. Do not add Chinese literals at call sites.
|
- Register localization keys through each project registration class and use `.Translate()` with keys. Do not add Chinese literals at call sites.
|
||||||
- Prefer `UXAssist/Common/GameConstants` for item, tech, logistics, and Dyson sphere constants instead of inline literals.
|
- Prefer `UXAssist/Common/GameConstants` for item, tech, logistics, and Dyson sphere constants instead of inline literals.
|
||||||
- Persist mod data through `IModCanSave` from DSPModSave.
|
- Persist mod data through `IModCanSave` from DSPModSave.
|
||||||
- Use `ModCompatHelper` for external plugin/type/member resolution and preserve legacy public type identities when refactoring reflection targets. Use `DysonSphereReflection` for DSPOptimizations-compatible Dyson sphere fields.
|
- Use `ModCompatHelper` for external plugin/type/member resolution and preserve legacy public type identities when refactoring reflection targets. Use `DysonSphereReflection` for DSPOptimizations-compatible Dyson sphere fields.
|
||||||
- Performance-sensitive Harmony transpilers must include the standard target/fallback header and use `TranspilerGuard` when a matcher can fail; returning original instructions is the fallback. Match named enum members and semantic calls or fields instead of hard-coded enum values or local-variable slots.
|
- Performance-sensitive Harmony transpilers must include the standard target/fallback header and use `TranspilerGuard` when a matcher can fail; returning original instructions is the fallback. Match named enum members and semantic calls or fields instead of hard-coded enum values or local-variable slots. Validate injected stack operand types and branch destinations, not just successful matching.
|
||||||
- `PatchImpl<T>.Enable(true)` must remain fail-soft: log, unpatch, and leave the patch unset if Harmony application fails so config delegate chains remain consistent.
|
- `PatchImpl<T>.Enable(true)` must remain fail-soft: log, unpatch, and leave the patch unset if Harmony application fails so config delegate chains remain consistent.
|
||||||
- Overlay UI state must converge from actual game state on periodic updates, not depend only on one-shot event or patch callbacks. Cloned controls must reset runtime state while retaining source styles; use `UXAssist.UI.Util.GetPreferredWidth` for dynamic text and `ResetButton` for cloned buttons.
|
- Overlay UI state must converge from actual game state on periodic updates, not depend only on one-shot event or patch callbacks. Cloned controls must reset runtime state while retaining source styles; use `UXAssist.UI.Util.GetPreferredWidth` for dynamic text and `ResetButton` for cloned buttons.
|
||||||
- UI-only options must preserve native progression, statistics, and event delivery. Suppress presentation handlers rather than bypassing authoritative game-state setters.
|
- UI-only options must preserve native progression, statistics, and event delivery. Suppress presentation handlers rather than bypassing authoritative game-state setters.
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
## Changlog
|
## Changlog
|
||||||
|
|
||||||
|
* Unreleased
|
||||||
|
* `PowerGlobalCoverage`: Fix a startup crash before wind-turbine prefabs finish loading. Retry after preload without corrupting activation state or the original power ranges, and tolerate unallocated factory data.
|
||||||
* 2.4.5
|
* 2.4.5
|
||||||
* Support Dyson Sphere Program 0.10.35.29057.
|
* Support Dyson Sphere Program 0.10.35.29057.
|
||||||
* Update `Terraform anyway` for the separate foundation and Restore Terrain workflows. Preserve soil gains and prevent negative soil balances when resources are insufficient.
|
* Update `Terraform anyway` for the separate foundation and Restore Terrain workflows. Preserve soil gains and prevent negative soil balances when resources are insufficient.
|
||||||
|
|||||||
@@ -181,25 +181,27 @@ internal static class WindTurbinesPowerGlobalCoverage
|
|||||||
if (enable)
|
if (enable)
|
||||||
{
|
{
|
||||||
if (_patched) return;
|
if (_patched) return;
|
||||||
|
var prefabDesc = LDB.items?.Select(WindTurbineId)?.prefabDesc;
|
||||||
|
if (prefabDesc == null) return;
|
||||||
|
_oldCoverRadius = prefabDesc.powerCoverRadius;
|
||||||
|
_oldConnectDistance = prefabDesc.powerConnectDistance;
|
||||||
|
prefabDesc.powerCoverRadius = WindTurbineNewCoverageDistance;
|
||||||
|
prefabDesc.powerConnectDistance = WindTurbineNewCoverageDistance;
|
||||||
|
_prefabdesc = prefabDesc;
|
||||||
_patched = true;
|
_patched = true;
|
||||||
var itemProto = LDB.items.Select(WindTurbineId);
|
|
||||||
_oldCoverRadius = itemProto.prefabDesc.powerCoverRadius;
|
|
||||||
_oldConnectDistance = itemProto.prefabDesc.powerConnectDistance;
|
|
||||||
itemProto.prefabDesc.powerCoverRadius = WindTurbineNewCoverageDistance;
|
|
||||||
itemProto.prefabDesc.powerConnectDistance = WindTurbineNewCoverageDistance;
|
|
||||||
_prefabdesc = itemProto.prefabDesc;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!_patched) return;
|
if (!_patched) return;
|
||||||
_patched = false;
|
|
||||||
_prefabdesc.powerCoverRadius = _oldCoverRadius;
|
_prefabdesc.powerCoverRadius = _oldCoverRadius;
|
||||||
_prefabdesc.powerConnectDistance = _oldConnectDistance;
|
_prefabdesc.powerConnectDistance = _oldConnectDistance;
|
||||||
|
_patched = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate all factories and update wind turbines power nodes
|
// Iterate all factories and update wind turbines power nodes
|
||||||
if (GameMain.data == null) return;
|
var factories = GameMain.data?.factories;
|
||||||
foreach (var factory in GameMain.data.factories)
|
if (factories == null) return;
|
||||||
|
foreach (var factory in factories)
|
||||||
{
|
{
|
||||||
var powerSystem = factory?.powerSystem;
|
var powerSystem = factory?.powerSystem;
|
||||||
if (powerSystem == null) continue;
|
if (powerSystem == null) continue;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
## Changlog
|
## Changlog
|
||||||
|
|
||||||
|
* Unreleased
|
||||||
|
* `Do not render factory entities`: Fix activation after DSP 0.10.35.29057 by removing fixed local-variable slots from raycast filtering. Preserve belts and optional sorter visibility.
|
||||||
* 1.6.0
|
* 1.6.0
|
||||||
* Support Dyson Sphere Program 0.10.35.29057.
|
* Support Dyson Sphere Program 0.10.35.29057.
|
||||||
* New feature: `Orbital Collector product limit`, with an `Apply to universe` option.
|
* New feature: `Orbital Collector product limit`, with an `Apply to universe` option.
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Runtime.CompilerServices;
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UXAssist.Common;
|
using UXAssist.Common;
|
||||||
|
using UXAssist.Common.Patching;
|
||||||
using GameLogicProc = UXAssist.Common.GameLogic;
|
using GameLogicProc = UXAssist.Common.GameLogic;
|
||||||
|
|
||||||
namespace UXAssist.Patches.Factory;
|
namespace UXAssist.Patches.Factory;
|
||||||
@@ -51,39 +52,42 @@ internal static class RenderingPatch
|
|||||||
}
|
}
|
||||||
// Harmony transpiler: RaycastLogic_GameTick_Transpiler
|
// Harmony transpiler: RaycastLogic_GameTick_Transpiler
|
||||||
// Target: RaycastLogic.GameTick
|
// Target: RaycastLogic.GameTick
|
||||||
// Fallback: None — patch will fail loudly if the target method body changes.
|
// Fallback: TranspilerGuard returns original instructions when the collider skip or entity lookup is not found.
|
||||||
[HarmonyTranspiler]
|
[HarmonyTranspiler]
|
||||||
[HarmonyPatch(typeof(RaycastLogic), nameof(RaycastLogic.GameTick))]
|
[HarmonyPatch(typeof(RaycastLogic), nameof(RaycastLogic.GameTick))]
|
||||||
private static IEnumerable<CodeInstruction> RaycastLogic_GameTick_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
private static IEnumerable<CodeInstruction> RaycastLogic_GameTick_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||||
{
|
{
|
||||||
var matcher = new CodeMatcher(instructions, generator);
|
var matcher = new CodeMatcher(instructions, generator);
|
||||||
matcher.MatchForward(false,
|
matcher.MatchForward(false,
|
||||||
new CodeMatch(OpCodes.Ldc_I4_0),
|
new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(Phys), nameof(Phys.RayCastOBB))),
|
||||||
new CodeMatch(OpCodes.Brtrue));
|
new CodeMatch(instruction => instruction.opcode == OpCodes.Brfalse || instruction.opcode == OpCodes.Brfalse_S));
|
||||||
var branch1 = (Label)matcher.Advance(1).Operand;
|
if (matcher.IsInvalid)
|
||||||
var branch2 = generator.DefineLabel();
|
return matcher.Finish(instructions, UXAssist.Logger, nameof(RaycastLogic_GameTick_Transpiler));
|
||||||
matcher.Start().MatchForward(false,
|
var skipCollider = (Label)matcher.InstructionAt(1).operand;
|
||||||
new CodeMatch(OpCodes.Call),
|
matcher.MatchForward(false,
|
||||||
new CodeMatch(ci => ci.IsStloc()),
|
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PlanetFactory), nameof(PlanetFactory.entityPool))),
|
||||||
new CodeMatch(OpCodes.Call),
|
|
||||||
new CodeMatch(ci => ci.IsStloc()),
|
|
||||||
new CodeMatch(OpCodes.Call),
|
|
||||||
new CodeMatch(ci => ci.IsStloc()),
|
|
||||||
new CodeMatch(ci => ci.IsLdloc()),
|
new CodeMatch(ci => ci.IsLdloc()),
|
||||||
new CodeMatch(ci => ci.Branches(out _)),
|
new CodeMatch(OpCodes.Ldelema, typeof(EntityData)),
|
||||||
new CodeMatch(OpCodes.Ldarg_0)
|
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(EntityData), nameof(EntityData.modelIndex))));
|
||||||
).Advance(8).InsertAndAdvance(
|
if (matcher.IsInvalid)
|
||||||
new CodeInstruction(OpCodes.Ldloc_S, 45),
|
return matcher.Finish(instructions, UXAssist.Logger, nameof(RaycastLogic_GameTick_Transpiler));
|
||||||
new CodeInstruction(OpCodes.Brtrue, branch2),
|
var visibleEntity = generator.DefineLabel();
|
||||||
new CodeInstruction(OpCodes.Ldarg_0),
|
matcher.Advance(3).InsertAndAdvance(
|
||||||
new CodeInstruction(OpCodes.Ldloc_S, 33),
|
new CodeInstruction(OpCodes.Dup).MoveLabelsFrom(matcher.Instruction),
|
||||||
new CodeInstruction(OpCodes.Ldloc_S, 35),
|
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(DoNotRenderEntities), nameof(IsVisibleEntity))),
|
||||||
Transpilers.EmitDelegate((RaycastLogic l, ColliderData[] colliderPool, int j) => !HideSorters && l.factory.entityPool[colliderPool[j].objId].inserterId > 0),
|
new CodeInstruction(OpCodes.Brtrue, visibleEntity),
|
||||||
new CodeInstruction(OpCodes.Brfalse, branch1)
|
new CodeInstruction(OpCodes.Pop),
|
||||||
|
new CodeInstruction(OpCodes.Br, skipCollider)
|
||||||
);
|
);
|
||||||
matcher.Labels.Add(branch2);
|
matcher.Labels.Add(visibleEntity);
|
||||||
return matcher.InstructionEnumeration();
|
return matcher.InstructionEnumeration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
private static bool IsVisibleEntity(ref EntityData entity)
|
||||||
|
{
|
||||||
|
return entity.beltId > 0 || !HideSorters && entity.inserterId > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class NightLight : PatchImpl<NightLight>
|
internal class NightLight : PatchImpl<NightLight>
|
||||||
|
|||||||
Reference in new issue
Block a user