Skip to content
Kiooeht edited this page Jul 21, 2018 · 4 revisions

ByRef allows you to receive parameters to your patch method by-reference. ByRef parameters are encapsulated inside a single element array.

  • ByRef works on Prefix and Insert patches.
  • ByRef only works on Insert patches on captured local variables, not patched method parameters.
// Parameter i is of type int, when using @ByRef, it is passed as int[]
public static void Prefix(@ByRef int[] i, float f)
{
	i[0] = 14; // i will be changed outside this method
	f = 3.14;  // f will NOT be changed outside this method
}

When using ByRef on a parameter of type Object that was not originally of type Object, you must use the type parameter to specify the original type of the parameter. The type string must be the fully qualified class name, unless it is from the com.megacrit.cardcrawl package, in which case you can leave off com.megacrit.cardcrawl.

@SpireInsertPatch(loc=14, localvars={"p"})
// localvar 'p' is of type AbstractPlayer
public static void Insert(@ByRef(type="com.megacrit.cardcrawl.characters.AbstractPlayer") Object[] p) { ... }
// Or leave off com.megacrit.cardcrawl
public static void Insert(@ByRef(type="characters.AbstractPlayer") Object[] p) { ... }