Class ReflectionService


  • public class ReflectionService
    extends java.lang.Object
    Service for handling reflection operations, including field access and method invocation.

    This service maintains a cache of reflected fields and methods to improve performance for repeated accesses. It supports accessing obfuscated members via FieldHook and MethodHook definitions.

    • Constructor Summary

      Constructors 
      Constructor Description
      ReflectionService​(net.runelite.api.Client client)
      Constructs a new ReflectionService.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T getFieldValue​(FieldHook hook, java.lang.Object instance)
      Retrieves the value of a field specified by the given hook.
      java.lang.Object invoke​(MethodHook hook, java.lang.Object instance, java.lang.Object... args)
      Invokes a method specified by the given hook.
      void setFieldValue​(FieldHook hook, java.lang.Object instance, java.lang.Object value)
      Sets the value of a field specified by the given hook.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ReflectionService

        @Inject
        public ReflectionService​(net.runelite.api.Client client)
        Constructs a new ReflectionService.
        Parameters:
        client - The RuneLite client instance, used to obtain the class loader.
    • Method Detail

      • getFieldValue

        public <T> T getFieldValue​(FieldHook hook,
                                   java.lang.Object instance)
        Retrieves the value of a field specified by the given hook.
        Type Parameters:
        T - The expected type of the field value.
        Parameters:
        hook - The FieldHook defining the class and field name.
        instance - The object instance to retrieve the field value from.
        Returns:
        The value of the field, or null if an error occurs.
      • setFieldValue

        public void setFieldValue​(FieldHook hook,
                                  java.lang.Object instance,
                                  java.lang.Object value)
        Sets the value of a field specified by the given hook.
        Parameters:
        hook - The FieldHook defining the class and field name.
        instance - The object instance to set the field value on.
        value - The new value to set.
      • invoke

        public java.lang.Object invoke​(MethodHook hook,
                                       java.lang.Object instance,
                                       java.lang.Object... args)
        Invokes a method specified by the given hook.

        This method automatically handles garbage values if the hook specifies one, appending it to the arguments list.

        Parameters:
        hook - The MethodHook defining the class and method name.
        instance - The object instance to invoke the method on.
        args - The arguments to pass to the method.
        Returns:
        The result of the method invocation, or null if an error occurs.