Class BeforeFieldAccess
public class BeforeFieldAccess extends BeforeInvoke
This injection point searches for GETFIELD and PUTFIELD (and static
equivalent) opcodes matching its arguments and returns a list of insns
immediately prior to matching instructions. It accepts the following
parameters from At:
- target
- A
Target Selectorwhich identifies the target field. - opcode
- The
opcodeof the field access, must be one of GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD. - ordinal
- The ordinal position of the field access to match. For example if the field is referenced 3 times and you want to match the 3rd then you can specify an ordinal of 2 (ordinals are zero-indexed). The default value is -1 which supresses ordinal matching
Example:
@At(value = "FIELD", target="field_59_z:I", opcode = Opcodes.GETFIELD)
Matching array access:
For array fields, it is possible to match field accesses followed by a corresponding array element get, set or length operation. To enable this behaviour specify the array named-argument with the desired operation:
@At(value = "FIELD", target="myIntArray:[I", args = "array=get")
See Redirect for information on array element redirection.
Note that like all standard injection points, this class matches the insn
itself, putting the injection point immediately before the access in
question. Use At.shift() specifier to adjust the matched opcode as
necessary.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.spongepowered.asm.mixin.injection.points.BeforeInvoke
BeforeInvoke.SearchTypeNested classes/interfaces inherited from class org.spongepowered.asm.mixin.injection.InjectionPoint
InjectionPoint.AtCode, InjectionPoint.RestrictTargetLevel, InjectionPoint.Selector -
Field Summary
Fields Modifier and Type Field Description static intARRAY_SEARCH_FUZZ_DEFAULTDefault fuzz factor for searching for array access opcodesFields inherited from class org.spongepowered.asm.mixin.injection.points.BeforeInvoke
allowPermissive, className, context, logger, ordinal, targetFields inherited from class org.spongepowered.asm.mixin.injection.InjectionPoint
DEFAULT_ALLOWED_SHIFT_BY, MAX_ALLOWED_SHIFT_BY -
Constructor Summary
Constructors Constructor Description BeforeFieldAccess(InjectionPointData data) -
Method Summary
Modifier and Type Method Description protected booleanaddInsn(org.objectweb.asm.tree.InsnList insns, java.util.Collection<org.objectweb.asm.tree.AbstractInsnNode> nodes, org.objectweb.asm.tree.AbstractInsnNode insn)static org.objectweb.asm.tree.AbstractInsnNodefindArrayNode(org.objectweb.asm.tree.InsnList insns, org.objectweb.asm.tree.FieldInsnNode fieldNode, int opcode, int searchRange)Searches for an array access instruction in the supplied instruction list which is within searchRange instructions of the supplied field instruction.intgetArrayOpcode()intgetFuzzFactor()protected booleanmatchesInsn(org.objectweb.asm.tree.AbstractInsnNode insn)Methods inherited from class org.spongepowered.asm.mixin.injection.points.BeforeInvoke
find, find, inspectInsn, log, matchesOrdinal, setLoggingMethods inherited from class org.spongepowered.asm.mixin.injection.InjectionPoint
addMessage, after, and, before, checkPriority, getAtCode, getCancellationRestriction, getId, getSelector, getSlice, getTargetRestriction, nextNode, or, parse, parse, parse, parse, parse, parse, parse, parse, register, shift, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
ARRAY_SEARCH_FUZZ_DEFAULT
public static final int ARRAY_SEARCH_FUZZ_DEFAULTDefault fuzz factor for searching for array access opcodes- See Also:
- Constant Field Values
-
-
Constructor Details
-
BeforeFieldAccess
-
-
Method Details
-
getFuzzFactor
public int getFuzzFactor() -
getArrayOpcode
public int getArrayOpcode() -
matchesInsn
protected boolean matchesInsn(org.objectweb.asm.tree.AbstractInsnNode insn)- Overrides:
matchesInsnin classBeforeInvoke
-
addInsn
protected boolean addInsn(org.objectweb.asm.tree.InsnList insns, java.util.Collection<org.objectweb.asm.tree.AbstractInsnNode> nodes, org.objectweb.asm.tree.AbstractInsnNode insn)- Overrides:
addInsnin classBeforeInvoke
-
findArrayNode
public static org.objectweb.asm.tree.AbstractInsnNode findArrayNode(org.objectweb.asm.tree.InsnList insns, org.objectweb.asm.tree.FieldInsnNode fieldNode, int opcode, int searchRange)Searches for an array access instruction in the supplied instruction list which is within searchRange instructions of the supplied field instruction. Searching halts if the search range is exhausted, if anOpcodes.ARRAYLENGTHopcode is encountered immediately after the specified access, if a matching field access is found, or if the end of the method is reached.- Parameters:
insns- Instruction list to searchfieldNode- Field instruction to search fromopcode- array access opcode to search forsearchRange- search range- Returns:
- matching opcode or null if not matched
-