Skip to content

Skip Class::GetDefaultFieldValue when the xref is not a function entry - #280

Open
Joshtt23 wants to merge 2 commits into
BepInEx:masterfrom
Joshtt23:getdefaultfieldvalue-aligned-xref
Open

Skip Class::GetDefaultFieldValue when the xref is not a function entry#280
Joshtt23 wants to merge 2 commits into
BepInEx:masterfrom
Joshtt23:getdefaultfieldvalue-aligned-xref

Conversation

@Joshtt23

Copy link
Copy Markdown

Summary

  • On some Unity 6 IL2CPP builds, FindClassGetFieldDefaultValueXref lands on an unaligned epilogue (a jmp into the ret path), not Class::GetDefaultFieldValue.
  • Detouring that address aborts the CLR (0x80131506).
  • Keep the existing First/Last / [^2] heuristic when that pointer is 16-byte aligned. Otherwise pick another aligned jump target, or skip this hook only with a warning (no throw).
  • Same alignment rule as imageGetTypeXrefs in MetadataCache_GetTypeInfoFromTypeDefinitionIndex_Hook.
  • Signature-based finds are unchanged. This does not skip every unaligned hook in Hook.ApplyHook.

Test plan

  • Games where the current xref is already aligned: hook still applies.
  • Unity 6 IL2CPP where the xref is an interior/epilogue address: log a warning, chainloader completes, other hooks still apply.
  • Injected enum field defaults may be unavailable when this hook is skipped (same as not finding the method).

Runtime-tested on Unity 6000.3.15x1 / metadata 39 (Rust client). Class::Init is a separate change (#277).

On some Unity 6 IL2CPP builds the jump-target walk lands on an unaligned epilogue (jmp into ret). Detouring that aborts the CLR. Keep the existing First/Last heuristic when that address is 16-byte aligned; otherwise pick another aligned target or skip this hook with a warning. Same rule as imageGetTypeXrefs. Do not refuse every unaligned hook globally. Signature hits are unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
nint has no ToInt64 on this TF; (ptr & 0xF) is the same 16-byte entry check.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

1 participant