SRL Archive - Instructions & Tutorials S.M.A.R.T.

How To Update Reflection Hooks Using RSBot


Widget

2008-08-05 18:37:41

Well, I certainly am not on top of the Runescape updates, so I'll teach you all how to upload the hooks.ini files. I figured it should go here so we don't have everyone in the world *cough*ruler*cough* running around with RSBot hook's without effort on their part :)

First off, save and compile this script, but remember to change the line LinkedList<ClassGen> gens = getClassGens(new File("C:/Documents and Settings/Administrator/Desktop/RsBot/rs.jar")), which is at the beginning of the main loop. The rs.jar file mentioned is the one that comes with rsbot.
[PHP]import java.io.*;
import java.util.*;
import java.util.zip.*;
import org.apache.bcel.classfile.*;
import org.apache.bcel.generic.*;

/**
* Parses RSBot's rs.jar file looking for specified methods in specific
* interfaces via bytecode manipulation, in order to convert the fields to SMART
* format paths. Figure it out, its simple and self explanatory…
* @author BenLand100
*/

public class SMART_RSBot_Parser {

/**
* Expand this with what you need, once again, easy to undestand.
*/
private static final Interface[] stuff = new Interface[] {
new Interface("com.speljohan.rsbot.accessors.Client",
"getPlane=BaseLayer",
"getBaseX=BaseX",
"getBaseY=BaseY",
"getCamPosX=CamX",
"getCamPosY=CamY",
"getCamPosZ=CamZ",
"getCameraCurveX=CamYaw",
"getCameraCurveY=CamPitch",
"getMinimapInt1=CompassAngle",
"getSkillLevels=CurrentLevels",
"getSkillExperiences=Experiences",
"getDestX=FlagX",
"getDestY=FlagY",
"getGroundIntArray=GroundHeights",
"getGroundByteArray=GroundSettings",
"getLoopCycle=LoopCycle",
"getLoginIndex=LoginIndex",
"getMinimapInt2=MapOffsetAngle",
"getSkillLevelMaxes=MaxLevels",
"getMyPlayer=MyPlayer",
"getNPCArray=NPCArray",
"getNPCCount=NPCCount",
"getNPCIndexArray=NPCIndexArray",
"getPlayerArray=PlayerArray",
"getPlayerCount=PlayerCount",
"getPlayerIndexArray=PlayerIndArray",
"getSettingArray=SettingsArray"),
new Interface("com.speljohan.rsbot.accessors.Character",
"getAnimation=CharAnim",
"isMoving=CharMotion",
"getX=CurrentX",
"getY=CurrentY",
"getHeight=CharHeight",
"getHPRatio=CharHPRatio",
"getLoopCycleStatus=LoopCycleStatus"),
new Interface("com.speljohan.rsbot.accessors.Player",
"getName=CharName",
"getLevel=CharLevel"),
new Interface("com.speljohan.rsbot.accessors.NPC",
"getNPCDef=NPCDef"),
new Interface("com.speljohan.rsbot.accessors.NPCDef",
"getName=GetNPCName",
"getType=GetNPCType"),
new Interface("com.speljohan.rsbot.accessors.RSString",
"getBytes=StringBytes"),
};

/**
* Simple class to hold interface information
*/
private static class Interface {
public String name; //Name of the interface implemented
public String[] data; //Refactoring, MethodName=HookName
public Interface(String name, String… data) {
this.name = name;
this.data = data;
}
};

/**
* Does the work, should not have to mess with this, unless you want to make
* it "user friendly"
* @param args
*/
public static void main(String[] args) {
try {
LinkedList<ClassGen> gens = getClassGens(new File("C:/Documents and Settings/Administrator/Desktop/RsBot/rs.jar")); // CHANGE THIS!!
HashMap<String,Interface> imap = new HashMap<String,Interface>();
System.out.println("const");
for (Interface i : stuff)
imap.put(i.name, i);
for (ClassGen gen : gens) {
String[] inters = gen.getInterfaceNames();
for (String inter : inters) {
if (imap.containsKey(inter)) {
Interface i = imap.remove(inter);
System.out.println(" // " + inter.split("accessors.")[1]);
HashMap<String,String> hooks = new HashMap<String,String>();
for (String data : i.data) {
String[] parts = data.split("\\=");
hooks.put(parts[0], parts[1]);
}
ConstantPoolGen cpg = gen.getConstantPool();
for (Method m : gen.getMethods()) {
String name = m.getName();
if (hooks.containsKey(name)) {
String hook = hooks.remove(name);
MethodGen mg = new MethodGen(m, gen.getClassName(), cpg);
InstructionList il = mg.getInstructionList();
Instruction[] ins = il.getInstructions();
String field = "";
if (ins[0] instanceof GETSTATIC) {
GETSTATIC get = (GETSTATIC)ins[0];
field = get.getClassName(cpg) + "." + get.getFieldName(cpg);
System.out.println(" " + hook + " = '" + field + "';");
} else {
GETFIELD get = (GETFIELD)ins[1];
field = get.getFieldName(cpg);
System.out.println(" " + hook + " = '" + field + "';");
}
//System.out.println(" " + hook + " = " + field + "");
}
}
System.out.println();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Returns all ClassGens found in the rs.jar
* @param jar rs.jar file
* @return LinkedList of ClassGen
* @throws java.io.IOException
*/
private static LinkedList< ClassGen> getClassGens(File jar) throws IOException {
ZipInputStream zis = new ZipInputStream(new FileInputStream(jar));
LinkedList<ClassGen> gens = new LinkedList<ClassGen>();
byte buf[] = new byte[0xFFFF];
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
String name = entry.getName();
if (!name.endsWith(".class"))
continue;
name = name.replace(".class", "");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int len;
while ((len = zis.read(buf, 0, buf.length)) != -1) {
bos.write(buf, 0, len);
}
gens.add(new ClassGen(new ClassParser(new ByteArrayInputStream(bos.toByteArray()), name).parse()));
}
return gens;
}

}[/PHP]
And here's a batch file to compile and run it:
@echo off
javac SMART_RSBot_Parser.java
del hooks.txt
java SMART_RSBot_Parser >> hooks.txt
pause
Run the batch file, it'll make a hooks.txt file.

It should look something like this:
const
// NPC
NPCDef = 'Pb';

// Player
CharName = 'Zb';
CharLevel = 'ac';

// RSString
StringBytes = 'h';

// Client
NPCIndexArray = 'kg.v';
NPCArray = 'rf.a';
NPCCount = 'ke.p';
PlayerIndArray = 'oc.q';
PlayerArray = 'db.Q';
PlayerCount = 'client.ib';
MyPlayer = 'gg.B';
BaseX = 'fj.e';
BaseY = 'va.ab';
LoopCycle = 'be.C';
GroundHeights = 'mi.U';
GroundSettings = 'kk.c';
BaseLayer = 'jk.F';
CamX = 'gg.D';
CamY = 'oc.l';
CamZ = 'ef.s';
CamPitch = 'hc.a';
CamYaw = 'mg.j';
LoginIndex = 'ua.b';
SettingsArray = 'sb.i';
MaxLevels = 'of.j';
CurrentLevels = 'ed.i';
Experiences = 'qe.M';
MapOffsetAngle = 'ba.z';
CompassAngle = 'ok.eb';
FlagX = 'ph.f';
FlagY = 'fg.o';

// Character
CharAnim = 'ob';
CharMotion = 'zb';
CurrentX = 'hb';
CurrentY = 'J';
LoopCycleStatus = 'G';
CharHPRatio = 'T';
CharHeight = 'mb';

// NPCDef
GetNPCName = 'ib';
GetNPCType = 'ab';

And just paste it into Hooks.scar :D


Of course, it would be best if we had our own updater, but the only person I know of that's written one here is Ben :)

the scar noob

2008-08-06 06:12:32

How do we have to save the above code? As which type of file?? (java?)

-Tsn.

Starblaster100

2008-08-06 06:21:21

EDIT: I'm wrong. Paste into Notepad and save it as a .java file.

the scar noob

2008-08-06 10:14:51

From: Starblaster100
EDIT: I'm wrong. Paste into Notepad and save it as a .java file.


Thank you start, btw I guess I need RSBot aswell?
And the path we have to change, is it the path from the main jar file from RSBot?

-Tsn.

Starblaster100

2008-08-06 10:17:46

Yes you need RSBot on your computer.

You edit the string to the path where the RSBot jar file is stored on your computer.

the scar noob

2008-08-06 10:39:09

From: Starblaster100
Yes you need RSBot on your computer.

You edit the string to the path where the RSBot jar file is stored on your computer.


Ok, thank you Star:)

I guess I'll have to register at RSBot forum:)

-Tsn.

Starblaster100

2008-08-06 10:44:30

Latest revisions are found here:
http://trac2.assembla.com/rsbotsvn/browser

the scar noob

2008-08-06 10:47:50

From: Starblaster100
Latest revisions are found here:
http://trac2.assembla.com/rsbotsvn/browser


Thank you Star, hell you're very fast in replying:p

-Tsn.

EDIT: I have to download all the files?:p

Markus

2008-08-06 10:53:10

From: the scar noob
Thank you Star, hell you're very fast in replying:p

-Tsn.

EDIT: I have to download all the files?:p

read a bit and see you only need rs.jar :)

the scar noob

2008-08-06 11:01:27

From: Markus
read a bit and see you only need rs.jar :)


I already thought so, but it doesn't work:(

-Tsn.

marpis

2009-11-28 15:04:12

How do I save & compile a batch file?

E: Oh, it's .bat :)
E: Oh, it doesn't work..

YoHoJo

2009-11-28 16:17:33

From: marpis
How do I save & compile a batch file?

E: Oh, it's .bat :)
E: Oh, it doesn't work..


ROFL 1 year bump dude. :D

marpis

2009-11-29 05:57:51

From: YoHoJo
ROFL 1 year bump dude. :D


Lawl, like someone cared about gravedigs in these dead forums ^^
I had to try :)

Sir R. M8gic1an

2009-11-29 14:09:13

From: marpis
How do I save & compile a batch file?

E: Oh, it's .bat :)
E: Oh, it doesn't work..


Do u have java on your computer?

~RM

Widget

2009-11-29 15:07:17

You'll have to install JDK. Also, you'll have to update the fields in the script with what reflection and RSBot currently use.

http://java.sun.com/javase/downloads/widget/jdk6.jsp

marpis

2009-11-30 04:53:57

From: Widget
You'll have to install JDK. Also, you'll have to update the fields in the script with what reflection and RSBot currently use.

http://java.sun.com/javase/downloads/widget/jdk6.jsp


I do have JDK and I sure don't know anything about any fields o_O

Naike

2009-11-30 14:25:54

From: marpis
I do have JDK and I sure don't know anything about any fields o_O


Message me on msn when you see me on, and I teach you how to get RsBots output.. Or I might just make a tutorial… :p

RAM

2009-12-01 21:40:50

From: N1ke!
Message me on msn when you see me on, and I teach you how to get RsBots output.. Or I might just make a tutorial… :p


a tutorial would be nice :)