Skip to content

Encode injected I4 and U4 enum defaults for Unity 2021.2+ - #287

Open
jweivy wants to merge 1 commit into
BepInEx:masterfrom
jweivy:fix/enum-default-encoding
Open

jweivy wants to merge 1 commit into
BepInEx:masterfrom
jweivy:fix/enum-default-encoding

Conversation

@jweivy

@jweivy jweivy commented Oct 2, 2026

Copy link
Copy Markdown

Injected 32-bit enum literals use fixed-width default-value blobs, but Unity 2021.2+ reads I4/U4 defaults using compressed unsigned/zigzag signed decoding. In a Unity 6 integration test, an injected value of 7 was consequently read back incorrectly.

Use Unity's valid five-byte full-width compressed representation for I4/U4 on released Unity 2021.2 and later. Keep older Unity versions and other underlying types on their existing paths. Both new enum literals and overridden defaults use the same writer/storage size.

Validation:

  • Managed production codec piped into an independent C decoder: 10 signed/unsigned boundary vectors pass.
  • Runtime Release build passes.
  • Native BTD6 56.3/Unity 6000.0.58f2 reads back injected 7, -19, Int32.MinValue, Int32.MaxValue and UInt32.MaxValue correctly, alongside a pre-existing Unity enum literal. The game reaches injected callbacks and normal exit 0 using additional local ARM64 integration fixes; this PR is the enum fix only.

The fixture README links the archived Unity transition from 2021.2.0a21 fixed readers to 2021.2.0b7 compressed readers. System.Version does not retain prerelease suffixes, so the gate claims released 2021.2+ support. No game files are included.

Run: DOTNET=/path/to/dotnet ./tests/EnumDefaultValueRegression/run.sh.

@ds5678

ds5678 commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

This seems like AI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants