Jump to content

Checking if item is selected rev 35


PolishCivil

Recommended Posts

    private final String selectedItemCheckFieldName = "is", selectedSlotIdFieldName = "gw";

    private Field selectedItemCheck = null, selectedSlotId = null;

 

public boolean isItemSelected(String name) {

try {

if (selectedItemCheck == null) {

try {

ClassLoader loader = client.instance.getClass().getClassLoader();

Class clazz = Class.forName("client", false, loader);

selectedItemCheck = clazz.getDeclaredField(selectedItemCheckFieldName);

selectedSlotId = clazz.getDeclaredField(selectedSlotIdFieldName);

selectedSlotId.setAccessible(true);

selectedItemCheck.setAccessible(true);

} catch (NoSuchFieldException | SecurityException | ClassNotFoundException ex) {

Logger.getLogger(AbstractScript.class.getName()).log(Level.SEVERE, null, ex);

}

}

int i = (int) selectedItemCheck.get(null);

if (i == 0) {

return false;

} else {

final Item item = client.getInventory().getItems()[(int) selectedSlotId.get(null) * 1168746611];

if (item.getName().equalsIgnoreCase(name)) {

return true;

}

}

} catch (IllegalArgumentException | IllegalAccessException ex) {

Logger.getLogger(AbstractScript.class.getName()).log(Level.SEVERE, null, ex);

}

return false;

}

Edited by PolishCivil
  • Like 1
Link to comment
Share on other sites

Just use mine, it's a lot cleaner and more properly written.

http://osbot.org/forum/topic/32514-some-inventory-methods/

Na, you're getting field each time you check, also you're getting item name not slot id which is bad too. Also, you are getting classloader from renamed method which is bad.

And its not working at all, thats why i added mine lol.

Edited by PolishCivil
Link to comment
Share on other sites

Na, you're getting field each time you check, also you're getting item name not slot id which is bad too. Also, you are getting classloader from renamed method which is bad.

And its not working at all, thats why i added mine lol.

You put way too much effort in checking whether or not an item is selected, and not only that, you are creating a new class loader when you could have simply used the one created by OSBot itself. You need to retrieve two fields to check if an item is selected whereas I only need to retrieve one. Instead of just initializing the fields in the classes constructor you are using redundant if statements which is both inefficient and unconventional. You can use final a lot more in your code to clean it up and you could have just put the whole block of code in one try catch statement, you used two. Again, both inefficient and unconventional. You do not use a method provided by the client and instead you create your own way of doing it.

 

As for my code, it's not working as I haven't updated it which would literally take a second. As I said, the classloader is from a method provided by OSBot which is, indeed, obfuscated however efficient compared to your way of doing it. There's a certain field in the client which states whether or not an item is selected, using that the check is a whole lot more efficient and a whole lot cleaner. Just listen to what I say.

  • Like 2
Link to comment
Share on other sites

You put way too much effort in checking whether or not an item is selected, and not only that, you are creating a new class loader when you could have simply used the one created by OSBot itself. You need to retrieve two fields to check if an item is selected whereas I only need to retrieve one. Instead of just initializing the fields in the classes constructor you are using redundant if statements which is both inefficient and unconventional. You can use final a lot more in your code to clean it up and you could have just put the whole block of code in one try catch statement, you used two. Again, both inefficient and unconventional. You do not use a method provided by the client and instead you create your own way of doing it.

 

As for my code, it's not working as I haven't updated it which would literally take a second. As I said, the classloader is from a method provided by OSBot which is, indeed, obfuscated however efficient compared to your way of doing it. There's a certain field in the client which states whether or not an item is selected, using that the check is a whole lot more efficient and a whole lot cleaner. Just listen to what I say.

Ok, lets start shitstorm.

"You need to retrieve two fields to check if an item is selected whereas I only need to retrieve one"

You're doing the same thing, except im doing it on slot which can be used to checking if magic spell is selected.

"you are creating a new class loader when you could have simply used the one created by OSBot"

I'm getting the same class loader as you (only one time tho) Using osbot class loader will cause changing method name ...

Ok, my time:

You are searching for field each time you check if your item is selected which is very bad, also you're seaching for loaded classes each time you check which is bad too.

"As for my code, it's not working as I haven't updated it which would literally take a second."

If it does, why wouldnt you do it instead of flaming my one, working?

Link to comment
Share on other sites

  • 2 months later...
  • 3 weeks later...

A couple of questions:

 

The import for Field is

import java.lang.reflect.Field;

right?

 

Also for AbstractScript there doesn't seem to be an import, or is it a class we are supposed to build ourselves?

 

The AbstaticScript is not required for this function to work. Its only used to print the exceptions.

The correct import for Field is java.lang.reflect.Field.

 

The hooks that are used in this function change every week. selectedItemCheckFieldName should be "im" now.

 

Int 'getSelectionState' returns 'client.im' * (-1085438207) 

  • Like 1
Link to comment
Share on other sites

sneaky jagex moved selected slot to other class for 44 its:

 

 ClassLoader loader = client.instance.getClass().getClassLoader();
            Class clazz = Class.forName("client", false, loader);
            Class clazz2 = Class.forName("v", false, loader);

            selectedItemCheck = clazz.getDeclaredField("im");
            selectedItemCheck.setAccessible(true);
            selectedSlotId = clazz2.getDeclaredField("ii");
            selectedSlotId.setAccessible(true);
            int slotId = (int) selectedSlotId.get(null) * 1661960989;
 

 

Link to comment
Share on other sites

  • 4 weeks later...

 

sneaky jagex moved selected slot to other class for 44 its:

 

 ClassLoader loader = client.instance.getClass().getClassLoader();
            Class clazz = Class.forName("client", false, loader);
            Class clazz2 = Class.forName("e", false, loader);

            selectedItemCheck = clazz.getDeclaredField("ig");
            selectedItemCheck.setAccessible(true);
            selectedSlotId = clazz2.getDeclaredField("is");
            selectedSlotId.setAccessible(true);
            int slotId = (int) selectedSlotId.get(null) * 1352514743;

 

Modified a bit for R45 fix ^

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...