Skip to content

Private Field Captures

Kiooeht edited this page Nov 2, 2020 · 1 revision

Private Field Captures allow you to receive private field values as parameters to your patch.

To receive a Private Field Capture, add a parameter to your patch method with the same name as the field you want to capture, but prepended with three underscores (e.g. fieldName becomes ___fieldName).

  • Private Field Captures works on Prefix, Insert, and Postfix patches.
  • Private Field Captures come after the formal parameters of the method you are patching.
  • @ByRef works with Private Capture Fields.
// This will pass you the private field 'renderTip' of AbstractCard
public static void Prefix(AbstractCard __instance, SpriteBatch sb, boolean ___renderTip)
{
    // ...
}

Note about Insert patches:

Private Capture Fields must appear in the parameter list before any localvars. This means the order of the parameters is:

  1. Instance (if applicable)
  2. Formal parameters of the method you are patching
  3. Private Field Captures
  4. localvars

Example:

@SpireInsertPatch(
    locator=/*Locator*/,
    localvars={"word", "sbuilder2"}
)
public static void Insert(AbstractCard __instance, String description, GlyphLayout ___gl, String word, StringBuilder sbuilder2)
{
    // description is a formal parameter of the method being patched
    // ___gl is a Private Field Capture
    // word and sbuilder2 are localvars
}