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
|
||||
|
||||
- `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.
|
||||
- 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.
|
||||
- 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.
|
||||
- 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.
|
||||
- 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.
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
## 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
|
||||
* 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.
|
||||
|
||||
@@ -181,25 +181,27 @@ internal static class WindTurbinesPowerGlobalCoverage
|
||||
if (enable)
|
||||
{
|
||||
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;
|
||||
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
|
||||
{
|
||||
if (!_patched) return;
|
||||
_patched = false;
|
||||
_prefabdesc.powerCoverRadius = _oldCoverRadius;
|
||||
_prefabdesc.powerConnectDistance = _oldConnectDistance;
|
||||
_patched = false;
|
||||
}
|
||||
|
||||
// Iterate all factories and update wind turbines power nodes
|
||||
if (GameMain.data == null) return;
|
||||
foreach (var factory in GameMain.data.factories)
|
||||
var factories = GameMain.data?.factories;
|
||||
if (factories == null) return;
|
||||
foreach (var factory in factories)
|
||||
{
|
||||
var powerSystem = factory?.powerSystem;
|
||||
if (powerSystem == null) continue;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
## 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
|
||||
* Support Dyson Sphere Program 0.10.35.29057.
|
||||
* New feature: `Orbital Collector product limit`, with an `Apply to universe` option.
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Runtime.CompilerServices;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UXAssist.Common;
|
||||
using UXAssist.Common.Patching;
|
||||
using GameLogicProc = UXAssist.Common.GameLogic;
|
||||
|
||||
namespace UXAssist.Patches.Factory;
|
||||
@@ -51,39 +52,42 @@ internal static class RenderingPatch
|
||||
}
|
||||
// Harmony transpiler: RaycastLogic_GameTick_Transpiler
|
||||
// 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]
|
||||
[HarmonyPatch(typeof(RaycastLogic), nameof(RaycastLogic.GameTick))]
|
||||
private static IEnumerable<CodeInstruction> RaycastLogic_GameTick_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldc_I4_0),
|
||||
new CodeMatch(OpCodes.Brtrue));
|
||||
var branch1 = (Label)matcher.Advance(1).Operand;
|
||||
var branch2 = generator.DefineLabel();
|
||||
matcher.Start().MatchForward(false,
|
||||
new CodeMatch(OpCodes.Call),
|
||||
new CodeMatch(ci => ci.IsStloc()),
|
||||
new CodeMatch(OpCodes.Call),
|
||||
new CodeMatch(ci => ci.IsStloc()),
|
||||
new CodeMatch(OpCodes.Call),
|
||||
new CodeMatch(ci => ci.IsStloc()),
|
||||
new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(Phys), nameof(Phys.RayCastOBB))),
|
||||
new CodeMatch(instruction => instruction.opcode == OpCodes.Brfalse || instruction.opcode == OpCodes.Brfalse_S));
|
||||
if (matcher.IsInvalid)
|
||||
return matcher.Finish(instructions, UXAssist.Logger, nameof(RaycastLogic_GameTick_Transpiler));
|
||||
var skipCollider = (Label)matcher.InstructionAt(1).operand;
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PlanetFactory), nameof(PlanetFactory.entityPool))),
|
||||
new CodeMatch(ci => ci.IsLdloc()),
|
||||
new CodeMatch(ci => ci.Branches(out _)),
|
||||
new CodeMatch(OpCodes.Ldarg_0)
|
||||
).Advance(8).InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Ldloc_S, 45),
|
||||
new CodeInstruction(OpCodes.Brtrue, branch2),
|
||||
new CodeInstruction(OpCodes.Ldarg_0),
|
||||
new CodeInstruction(OpCodes.Ldloc_S, 33),
|
||||
new CodeInstruction(OpCodes.Ldloc_S, 35),
|
||||
Transpilers.EmitDelegate((RaycastLogic l, ColliderData[] colliderPool, int j) => !HideSorters && l.factory.entityPool[colliderPool[j].objId].inserterId > 0),
|
||||
new CodeInstruction(OpCodes.Brfalse, branch1)
|
||||
new CodeMatch(OpCodes.Ldelema, typeof(EntityData)),
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(EntityData), nameof(EntityData.modelIndex))));
|
||||
if (matcher.IsInvalid)
|
||||
return matcher.Finish(instructions, UXAssist.Logger, nameof(RaycastLogic_GameTick_Transpiler));
|
||||
var visibleEntity = generator.DefineLabel();
|
||||
matcher.Advance(3).InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Dup).MoveLabelsFrom(matcher.Instruction),
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(DoNotRenderEntities), nameof(IsVisibleEntity))),
|
||||
new CodeInstruction(OpCodes.Brtrue, visibleEntity),
|
||||
new CodeInstruction(OpCodes.Pop),
|
||||
new CodeInstruction(OpCodes.Br, skipCollider)
|
||||
);
|
||||
matcher.Labels.Add(branch2);
|
||||
matcher.Labels.Add(visibleEntity);
|
||||
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>
|
||||
|
||||
Reference in new issue
Block a user