Class BeforeFieldAccess
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
- named argument: array
- For matching accesses to an array field element following a GETFIELD or GETSTATIC. Specify get, set or length to match the desired operation.
- named argument: fuzz
- When matching array operations using array the injection point will by default search up to 8 instructions after the matched field insn. However in some cases the array operation may be further from the matched GETFIELD or GETSTATIC and the amount to search (the "fuzz factor" can be specified using this argument. Likewise to optimise the search against false positives, this value can be specified as a lower value if desired. Has no effect if array is not specified.
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", opcode
= Opcodes.GETFIELD, 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.Flags, InjectionPoint.RestrictTargetLevel, InjectionPoint.Specifier -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault fuzz factor for searching for array access opcodesFields inherited from class org.spongepowered.asm.mixin.injection.points.BeforeInvoke
allowPermissive, className, context, logger, mixin, ordinal, targetFields inherited from class org.spongepowered.asm.mixin.injection.InjectionPoint
DEFAULT_ALLOWED_SHIFT_BY, MAX_ALLOWED_SHIFT_BY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanaddInsn(org.objectweb.asm.tree.InsnList insns, 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.intintprotected 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, getId, getSlice, getSpecifier, getTargetRestriction, nextNode, or, parse, parse, parse, parse, parse, parse, parse, parse, register, register, setTargetRestriction, shift, toString
-
Field Details
-
ARRAY_SEARCH_FUZZ_DEFAULT
public static final int ARRAY_SEARCH_FUZZ_DEFAULTDefault fuzz factor for searching for array access opcodes- See Also:
-
-
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, 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
-