Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Checking if item is selected rev 35

Featured Replies

    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

  • Author

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

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.

  • Author

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?

  • 2 months later...
  • Author

someone asked me for update so :

private final String selectedItemCheckFieldName = "id", selectedSlotIdFieldName = "gc"

 

Mod:  -1160674909

Edited by PolishCivil

  • 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?

 

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) 

  • Author

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;
 

 

  • 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 ^

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.