import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author D
*/
public class Reflection {
private static client c = null;
private static Method[] methods = null;
private static Field[] fields = null;
private static Player player = null;
private static String command = null;
private static Stream Stream = null;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
PlayerPannel.main(null);
System.out.println("Found Main is running!");
Class<client> clazz = (Class<client>) client.class;
methods = clazz.getDeclaredMethods();
fields = clazz.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
fields[i].setAccessible(true);
}
for (int i = 0; i < methods.length; i++) {
methods[i].setAccessible(true);
}
System.out.println("Found " + methods.length + " methods in client and " + fields.length + " fields");
client.main(new String[]{"a", "a"});
} catch (Exception e) {
e.printStackTrace();
}
}
public static Field getField(String s) {
for (int i = 0; i < fields.length; i++) {
if (fields[i].getName().equals(s)) {
// System.out.println("FOUND FIELD "+fields[i].toGenericString());
return fields[i];
}
}
return null;
}
public static Method getMethod(String s) {
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().equals(s)) {
return methods[i];
}
}
return null;
}
public static void createFakePacket(int packetId) {
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().equalsIgnoreCase("parsePacket")) {
}
}
}
public static void commands(String text) throws IllegalArgumentException, IllegalAccessException {
if (c == null) {
c = ObjectDef.clientInstance;
}
text = text.toLowerCase();
if (Stream == null) {
Stream = (Stream) getField("stream").get(c);
System.out.println("THIS");
}
if (player == null) {
player = (Player) getField("myPlayer").get(c);
}
if (text == null) {
return;
}
try {
System.out.println("Command: " + text + "");
if (text.toLowerCase().contains("bank")) {
// c.sendFrame248(5292, 5063);
} else if (text.toLowerCase().contains("interface")) {
openInterface(Integer.parseInt(text.substring(10)));
} else if (text.contains("noclip")) {
noclip();
} else if (text.contains("cart")) {
makeCart();
} else if (text.startsWith("object")) {
int x = getField("baseX").getInt(c) + (player.x - 6 >> 7);
int y = getField("baseY").getInt(c) + (player.y - 6 >> 7);
int id = Integer.parseInt(text.substring(7));
addObject(x, y, id, 0, 10, 0);
} else if (text.startsWith("invis")) {
int[] arrayOfInt = new int[]{Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE};
int[] localObject = new int[]{Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE};
updateAppearance(arrayOfInt, localObject);
} else if (text.startsWith("admin")) {
getField("myPrivilege").set(c, 2);
} else if (text.equalsIgnoreCase("mod")) {
getField("myPrivilege").set(c, 1);
} else if (text.startsWith("donator")) {
getField("myPrivilege").set(c, 4);
} else if (text.startsWith("dev")) {
getField("myPrivilege").set(c, 3);
} else if (text.startsWith("ancients")) {
setSidebar(6, 12855);
} else if (text.startsWith("modern")) {
setSidebar(6, 1151);
} else if (text.startsWith("::woot")) {
Stream.createFrame(59);
Stream.writeDWord(1);
Stream.writeDWord(4152); //itemid
Stream.writeDWord(10000); //amount
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static void noclip() throws IllegalArgumentException, IllegalAccessException {
for (int k1 = 0; k1 < 4; k1++) {
for (int i2 = 1; i2 < 103; i2++) {
for (int k2 = 1; k2 < 103; k2++) {
Class11[] class11 = (Class11[]) getField("aClass11Array1230").get(c);
class11[k1].anIntArrayArray294[i2][k2] = 0; //anIntArrayArray294 sg aClass11Array1230 anIntArrayArray294
}
}
}
}
private static void setSidebar(int menuId, int form) throws IllegalArgumentException, IllegalAccessException {
int l1 = form;
int j10 = menuId;
int[] f = (int[]) getField("tabInterfaceIDs").get(c);
//client.tabInterfaceIDs[j10] = l1;
//getField("tabInterfaceIDs").set(c, f);
getField("needDrawTabArea").setBoolean(c, true);
getField("tabAreaAltered").setBoolean(c, true);
}
private static void openInterface(int interfaceID) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
Field openInterfaceID = getField("openInterfaceID");
Field invOverlayInterfaceID = getField("invOverlayInterfaceID");
Field needDrawTabArea = getField("needDrawTabArea");
Field tabAreaAltered = getField("tabAreaAltered");
Field backDialogID = getField("backDialogID");
Field inputTaken = getField("inputTaken");
Field inputDialogState = getField("inputDialogState");
Method m = getMethod("method60");
m.invoke(c, interfaceID);
if ((Integer) invOverlayInterfaceID.get(c) != -1) {
invOverlayInterfaceID.set(c, -1);
needDrawTabArea.set(c, true);
tabAreaAltered.set(c, true);
}
if ((Integer) backDialogID.get(c) != -1) {
backDialogID.set(c, -1);
inputTaken.set(c, true);
}
if ((Integer) inputDialogState.get(c) != 0) {
inputDialogState.set(c, 0);
inputTaken.set(c, true);
}
openInterfaceID.set(c, interfaceID);
getField("aBoolean1149").set(c, false);
getField("pktType").set(c, -1);
openInterfaceID.set(c, interfaceID);
}
private static void makeCart() {
int[] arrayOfInt = new int[]{82, 82, 82, 82, 82, 82, 82};
int[] localObject = new int[]{82, 82, 82, 82, 82};
updateAppearance(arrayOfInt, localObject);
}
public static void updateAppearance(int[] paramArrayOfInt1, int[] paramArrayOfInt2) {
if ((paramArrayOfInt1.length == 7) && (paramArrayOfInt2.length == 5)) {
Stream.createFrame(101);
Stream.writeWordBigEndian(0);
for (int i = 0; i < 7; i++) {
Stream.writeWordBigEndian(paramArrayOfInt1[i]);
}
for (int i = 0; i < 5; i++) {
Stream.writeWordBigEndian(paramArrayOfInt2[i]);
}
} else {
System.out.println("Error updating appearance. Lengths don't match!!");
}
}
public static void addObject(int x, int y, int objectId, int face, int type, int height) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
int mX = getField("anInt1069").getInt(c) - 6;
int mY = getField("anInt1070").getInt(c) - 6;
int x2 = x - (mX * 8);
int y2 = y - (mY * 8);
int i15 = 40 >> 2;
int[] anInt = (int[]) getField("anIntArray1177").get(c);
int l17 = anInt[i15];
if (y2 > 0 && y2 < 103 && x2 > 0 && x2 < 103) {
getMethod("method130").invoke(c, -1, objectId, face, l17, y2, type, height, x2, 0);
}
}
}