Results 1 to 3 of 3

Thread: Reflection - Reading non-static Field values

  1. #1
    Join Date
    Dec 2011
    Posts
    23
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Post Reflection - Reading non-static Field values

    Hi,

    I would like to know how to read non-static Fields via Reflection in Java when using the URLClassloader to create a new Instance rather then just creating an object and use Reflection on it. This is all related to Reflection in Runescape.

    - I have successfully loaded Runescape into my own JFrame via URLClassloader.
    - I have a source for the Hooks which i downloaded, so i know which classes i have to load from the runescape-jar and what the fieldnames are and what values i get from them
    - I have implement (more or less copied it :P) a class which uses Reflection to read Field values

    Everything works fine for static fields since you dont need an object-instance/reference for reading those fields.
    But for non-static fields object-instance/reference is necessary.

    Currently iam using the created applet-instance of the Runescape client class as object-reference.

    Code:
    Applet applet = (Applet) reflector.loadClass(getParameter("initial_class").replaceAll(".class", "")).newInstance();			
           applet.setStub(this);
           applet.init();
           applet.start();
           applet.setPreferredSize(new Dimension(765, 503));
    But this is not working.

    Code:
    java.lang.IllegalArgumentException: Can not set java.lang.String field z.i to client
    	at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
    	at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
    	at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(Unknown Source)
    	at sun.reflect.UnsafeObjectFieldAccessorImpl.get(Unknown Source)
    	at java.lang.reflect.Field.get(Unknown Source)
    I need an object-instance/reference for the class z if iam understanding this correct. But how would i get this object-instance/reference out of the applet-instance?

    Field z.i should return the Players name by the way.

    Here is the Reflector source code (Line 33 produces the error)

    http://pastebin.com/iJJakGHE


    If the problem is not clear enough ( bad english ), feel free to ask questions and i will try to explain further more.

  2. #2
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    All entry points into useful information from the client is done through static references.
    Some are arrays, others are linked lists, etc. You find the container for whatever type of object, then use the reference of that object to get some field value.

    In this case, you are looking for a container of player objects or the local player instance.
    Local player is a static instance at "ad.hw" in client #129
    The player array(which contains all of the players in the currently loaded region) is in a static array(static access and size) at "client.gg" in client #129

    So you can either use the local player instance and get the "name" field from that, or you can get a reference to a different player in the player array.

  3. #3
    Join Date
    Dec 2011
    Posts
    23
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Thank you very much.

    Iam now able to read all the easy stuff like NPC-Information, Player-Information, CurrentWorld and Loginstatus.

    I guess working with the Widgets for the use of the Inventory will be a litte harder.

    But iam working slowly towards it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •