PolishCivil Posted January 16, 2014 Share Posted January 16, 2014 (edited) 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 January 16, 2014 by PolishCivil 1 Link to comment Share on other sites More sharing options...
NxJr Posted January 16, 2014 Share Posted January 16, 2014 works great thanks 1 Link to comment Share on other sites More sharing options...
Kittens Posted January 16, 2014 Share Posted January 16, 2014 hmm divine was talking to me about this yesterday lol Link to comment Share on other sites More sharing options...
While Posted January 16, 2014 Share Posted January 16, 2014 Good job. Link to comment Share on other sites More sharing options...
Parameter Posted January 16, 2014 Share Posted January 16, 2014 Just use mine, it's a lot cleaner and more properly written. http://osbot.org/forum/topic/32514-some-inventory-methods/ 2 Link to comment Share on other sites More sharing options...
PolishCivil Posted January 16, 2014 Author Share Posted January 16, 2014 (edited) 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 January 16, 2014 by PolishCivil Link to comment Share on other sites More sharing options...
Parameter Posted January 16, 2014 Share Posted January 16, 2014 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. 2 Link to comment Share on other sites More sharing options...
PolishCivil Posted January 17, 2014 Author Share Posted January 17, 2014 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 More sharing options...
pitoluwa Posted January 17, 2014 Share Posted January 17, 2014 wow polisz taki mondry 1 Link to comment Share on other sites More sharing options...
PolishCivil Posted March 25, 2014 Author Share Posted March 25, 2014 (edited) someone asked me for update so : private final String selectedItemCheckFieldName = "id", selectedSlotIdFieldName = "gc" Mod: -1160674909 Edited March 25, 2014 by PolishCivil 1 Link to comment Share on other sites More sharing options...
Botre Posted April 14, 2014 Share Posted April 14, 2014 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? Link to comment Share on other sites More sharing options...
Xerion Posted April 14, 2014 Share Posted April 14, 2014 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) 1 Link to comment Share on other sites More sharing options...
PolishCivil Posted April 14, 2014 Author Share Posted April 14, 2014 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 More sharing options...
Dog_ Posted May 10, 2014 Share Posted May 10, 2014 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 More sharing options...