Fix #2525: clamp negative Cyclops power readout with no powercells#2748
Open
SkiLark1 wants to merge 1 commit into
Open
Fix #2525: clamp negative Cyclops power readout with no powercells#2748SkiLark1 wants to merge 1 commit into
SkiLark1 wants to merge 1 commit into
Conversation
Member
|
What about transpiling patch the actual code, instead of adding a workaround ? |
…no powercells
Vanilla CyclopsHelmHUDManager.Update computes
int num = Mathf.CeilToInt(powerRelay.GetPower() / powerRelay.GetMaxPower() * 100f);
With all powercells removed GetMaxPower() returns 0, so 0f/0f is NaN and
Mathf.CeilToInt(NaN) is int.MinValue, making the HUD read -2147483648%.
Transpile Update to clamp the CeilToInt result with Mathf.Max(0, ...) so
the bad value is never written and vanilla's own {num}% formatting
renders 0%. Registered in PatchesTranspilerTest so the IL match is
covered by the test suite.
Verified locally: spawn a Cyclops, enter, remove all 6 cells - HUD shows
0%. Insert and remove a cell again: readout behaves correctly.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
bac21c5 to
9b497e9
Compare
Author
Pushed the transpiler version. It clamps the Mathf.CeilToInt result with Mathf.Max(0, ...) right after the call, so vanilla's own "{num}%" formatting renders 0% correctly. Added it to PatchesTranspilerTest too, and confirmed in-game the HUD reads 0% now. Good call on doing it at the source. The old Postfix was dropping the % sign anyway, so this ended up cleaner all around. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked Issues / Context
Fixes #2525
Description of Change
Vanilla
CyclopsHelmHUDManager.Updatecomputes the displayed power percent as:With all powercells removed,
GetMaxPower()returns0, so0f / 0fisNaNandMathf.CeilToInt(NaN)isint.MinValue. The HUD then reads-2147483648%instead of0%.This state is normally unreachable in vanilla Subnautica because the engine auto-shuts when the player exits the helm, but Nitrox intentionally patches that out for MP reasons (see
CyclopsMotorMode_SaveEngineStateAndPowerDown_Patch.cs). With auto-shutdown disabled, pulling all powercells at the helm exposes the divide-by-zero path.The fix transpiles
Updateto clamp theMathf.CeilToIntresult withMathf.Max(0, …), so the bad value never gets written and vanilla's own$"{num}%"formatting renders0%. The clamp is a single insertion right after the uniquely-matchableMathf.CeilToIntcall.The patch is registered in
PatchesTranspilerTestso the IL match is covered by the test suite.This patches a vanilla Subnautica bug (closed-source, can't be upstreamed), but the clamp is a no-op for all legitimate power values (0–100), so it has no effect in normal play.
Validation
Tested locally on Windows, Subnautica build 83031, Nitrox InDev master (bbf5124):
0%(was-2147483648%before the fix).0%.The transpiler is also covered by
PatchesTranspilerTest.AllPatchesTranspilerSanity, which runs it against the real game IL and asserts it matches and inserts exactly 2 instructions.PR Checklist
masterat the time of openingPatchesTranspilerTest)🤖 This code was created with the help of AI.