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:
It should look something like this:
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 :)
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 :)