You last visited: Today at 09:12
Advertisement
[Java]MHTC AutoPot Source
Discussion on [Java]MHTC AutoPot Source within the SRO Coding Corner forum part of the Silkroad Online category.
01/11/2013, 22:47
#1
elite*gold: 0
Join Date: Mar 2009
Posts: 248
Received Thanks: 118
[Java]MHTC AutoPot Source
Hey guys I wrote an auto-pot for mhtc file based servers a while back, here is my source.
It's not much and today I'd code it differently because in it's current state it's very messey, but maybe it'll help someone. So feel free to use them for whatever you want.
BotConnection.java
Code:
package bot;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.swing.JOptionPane;
/**
* Class for Silkroad packet transaction via proxy
*
* @author Vinator
*
*/
public class BotConnection {
public static final String botName = "FuseBot";
public static boolean connectionFlag;
public static String opCode;
public static int size;
public static int packetIndex;
private Socket botSocket;
private BufferedWriter send;
private BufferedReader receive;
private String packet;
static {
connectionFlag = false;
packetIndex = 0;
opCode = "";
size = 0;
}
public BotConnection(String ip, int port) {
try {
botSocket = new Socket(ip, port);
// botSocket.setTrafficClass(0x04);
// botSocket.setKeepAlive(true);
send = new BufferedWriter(new OutputStreamWriter(botSocket.getOutputStream()));
receive = new BufferedReader(new InputStreamReader(botSocket.getInputStream(), "ISO-8859-1"));
} catch (UnknownHostException e) {
JOptionPane.showMessageDialog(null, "Proxy connection failed!");
System.exit(0);
e.printStackTrace();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Proxy connection failed!");
System.exit(0);
e.printStackTrace();
}
}
/**
* Sets the index to zero
*/
public void startParsing() {
BotConnection.packetIndex = 0;
}
/**
* Sets the index to the given value
* @param i
*/
public void startParsingAt(int i) {
BotConnection.packetIndex = i;
}
/**
* Sends a notice to the Silkroad-Client
*
* @param data Message to send
*/
public void sendNotice(String data) {
StringBuffer strB = new StringBuffer();
String msg = "AutoPot: " + data;
strB.append(ToHex((byte)7));
strB.append(getHex(msg.length()));
strB.append(stringToHex(msg));
sendPacket("3026", strB.toString(), "0002");
}
/**
* Converts an ASCII-String to a Hex-String
*
* @param data
* @return Hex-String from ASCII-String
*/
public String stringToHex(String data) {
StringBuffer strB = new StringBuffer();
char[] tempArray = data.toCharArray();
for(int i = 0; i < tempArray.length; i++) {
strB.append(ToHex((byte)tempArray[i]));
}
return strB.toString();
}
/**
* Converts a byte to a Hex-String
*
* @param data
* @return Hex-String from byte
*/
public String ToHex(byte data) {
if(data < 16) {
return "0" + Integer.toHexString(data).toUpperCase();
} else {
return Integer.toHexString(data).toUpperCase();
}
}
/**
* Converts a Word to a Hex-String
*
* @param data
* @return Hex-String from Word
*/
public String ToHex(char data) {
if(data <= 255) {
if(data < 16) {
return "0" + Integer.toHexString(data).toUpperCase();
} else {
return Integer.toHexString(data).toUpperCase();
}
} else if(data < 4096) {
return "0" + Integer.toHexString(data).toUpperCase();
} else {
return Integer.toHexString(data).toUpperCase();
}
}
/**
* Converts a Word to a Hex-String
*
* @param data
* @return Hex-String from Word
*/
public String ToHex(short data) {
if(data <= 255) {
if(data < 16) {
return "0" + Integer.toHexString(data).toUpperCase();
} else {
return Integer.toHexString(data).toUpperCase();
}
} else if(data < 4096) {
return "0" + Integer.toHexString(data).toUpperCase();
} else {
return Integer.toHexString(data).toUpperCase();
}
}
/**
* Sends a packet to the Silkroad-Proxy
*
* @param opCode OPCode of the Packet
* @param data Data of the Packet
* @param security Security Bytes
*/
public void sendPacket(String opCode, String data, String security) {
StringBuffer strB = new StringBuffer();
strB.append(getHex(data.length() / 2));
strB.append(reverseWord(opCode));
strB.append(reverseWord(security));
strB.append(data);
try {
send.write(getHexArray(strB.toString()));
send.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Couldn't send.");
e.printStackTrace();
}
}
/**
* Converts a Word into a reversed Hex-String
*
* @param len
* @return reversed Hex-String from Word
*/
public String getHex(int data) {
if(data < 255) {
if(data < 16) {
return reverseWord("000" + Integer.toHexString(data).toUpperCase());
} else {
return reverseWord("00" + Integer.toHexString(data).toUpperCase());
}
} else {
return reverseWord("00" + Integer.toHexString(data).toUpperCase());
}
}
/**
* Reverses a Hex-Word String
*
* @param b
* @return Reversed Hex-String wordwise
*/
public String reverseWord(String b) {
StringBuffer strB = new StringBuffer();
strB.append(b.substring(2, 4));
strB.append(b.substring(0, 2));
return strB.toString();
}
public String parseByte() {
String tempStr = packet.substring(BotConnection.packetIndex, (BotConnection.packetIndex + 2));
BotConnection.packetIndex += 2;
return tempStr;
}
public String parseWord() {
String low = parseByte();
String hi = parseByte();
return hi + low;
}
public String parseDWord() {
String low = parseWord();
String hi = parseWord();
return hi + low;
}
public String parseQWord() {
String low = parseDWord();
String hi = parseDWord();
return hi + low;
}
public String getPacket() {
return packet;
}
/**
* Converts the Hex-String to a char array
*
* @param packet
* @return char Array from Hex-String
*/
public char[] getHexArray(String packet) {
char[] retArray = new char[packet.length() / 2];
String[] tempArray = packet.split("(?<=\\G..)");
for(int i = 0; i < retArray.length; i++) {
retArray[i] = (char) Integer.parseInt(tempArray[i], 16);
}
return retArray;
}
/**
* Reads a packet from the Inputstream
*
* @return Packet as String
*/
public void readPacket() {
char[] packetLength = new char[2];
String packetString;
try {
// for(int i = 0; i < packetLength.length; i++) {
// packetLength[i] = receive.read();
// }
receive.read(packetLength);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(packetLength[0] == -1) {
packet = "";
} else {
BotConnection.size = Integer.parseInt(ToHex(packetLength[1]) + ToHex(packetLength[0]), 16);
// System.out.println("Length: " + BotConnection.size + " " + byteToHex(packetLength[1]) + byteToHex(packetLength[0]));
char[] packetArray = new char[BotConnection.size + 4];
// char[] packetArray = new char[(BotConnection.size / 2) + 2];
try {
// for(int i = 0; i < packetArray.length; i++) {
// packetArray[i] = receive.read();
// }
receive.read(packetArray);
} catch (IOException e) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null, "Couldn't read packet data.");
e.printStackTrace();
System.exit(0);
}
packetString = getPacketString(packetArray);
BotConnection.opCode = reverseWord(packetString.substring(0, 4));
// StringBuffer strB = new StringBuffer();
// strB.append("P: ");
// for(int i = 0; i < packetArray.length; i++) {
// strB.append(Integer.toHexString(packetArray[i]));
// strB.append(", ");
// }
// System.out.println(strB.toString());
if(packetString.length() > 8) {
packet = packetString.substring(8, packetString.length());
} else {
packet = "0";
}
}
}
public byte[] getByteArray(char[] charArray) {
byte[] tempArray = new byte[charArray.length];
for(int i = 0; i < tempArray.length; i++) {
tempArray[i] = (byte)charArray[i];
}
return tempArray;
}
/**
* Creates a String out of an Array
*
* @param value
* @return Packet as a String
*/
public String getPacketString(char[] value) {
StringBuffer strB = new StringBuffer(BotConnection.size * 2 + 4);
for(int i = 0; i < value.length; i++) {
strB.append(ToHex(value[i]));
}
return strB.toString();
}
/**
* Converts a Hex-String to an ASCII-String
*
* @param packet
* @return Ascii-String
*/
public String hexToAscii(String packet) {
StringBuffer strB = new StringBuffer();
char[] tempCharArray = getHexArray(packet);
for(char value : tempCharArray) {
strB.append(value);
}
return strB.toString();
}
}
BotCore.java
Code:
package bot;
public class BotCore implements Runnable{
public static final String[] hpSlots = {"0D", "0E", "0F", "10"};
public static final String[] mpSlots = {"11", "12", "13", "14"};
public static final String[] pillSlots = {"15", "16", "17", "18"};
public static boolean runState;
public static boolean startFlag;
public static boolean titleFlag;
public static boolean hpFlag;
public static boolean mpFlag;
public static boolean pillFlag;
public static boolean pillAmount;
public static byte hpLimit;
public static byte mpLimit;
public static String userName;
public static int maxHP;
public static int maxMP;
public static int curHP;
public static int curMP;
public static byte percentageMP;
public static byte percentageHP;
private boolean hmMax;
private int potCount;
private int gcCount;
private Inventory inventory;
private BotConnection bConnection;
private BotGUI guiObj;
static {
runState = false;
startFlag = false;
titleFlag = false;
hpFlag = false;
mpFlag = false;
userName = "";
percentageMP = 100;
percentageHP = 100;
maxHP = 0;
maxMP = 0;
curHP = 0;
curMP = 0;
}
public BotCore() {
hmMax = false;
potCount = 0;
gcCount = 0;
guiObj = new BotGUI(this);
bConnection = new BotConnection("localhost", 19002);
guiObj.setVisible(true);
}
public void initBot() {
hpFlag = true;
mpFlag = true;
pillAmount = true;
BotCore.runState = true;
bConnection.sendNotice("Started!");
}
public void stopBot() {
BotCore.runState = false;
bConnection.sendNotice("Stopped!");
}
public String getUsableHP(int slotIndex) {
// System.out.println("HP slot:" + Integer.toHexString(slotIndex).toUpperCase());
if(inventory.getItemType(slotIndex) == Inventory.shpPot) {
return bConnection.ToHex((byte) slotIndex) + "ED08";
} else {
return bConnection.ToHex((byte) slotIndex) + "EC08";
}
}
public int hpIsAvailable() {
for(int i = 0; i < inventory.getInvSize(); i++) {
if(inventory.getItemType(i) == Inventory.hpPot || inventory.getItemType(i) == Inventory.shpPot) {
return i;
}
}
return -1;
}
public String getUsableMP(int slotIndex) {
// System.out.println("MP slot:" + Integer.toHexString(slotIndex).toUpperCase());
if(inventory.getItemType(slotIndex) == Inventory.smpPot) {
return bConnection.ToHex((byte) slotIndex) + "ED10";
} else {
return bConnection.ToHex((byte) slotIndex) + "EC10";
}
}
public int mpIsAvailable() {
for(int i = 0; i < inventory.getInvSize(); i++) {
if(inventory.getItemType(i) == Inventory.mpPot || inventory.getItemType(i) == Inventory.smpPot) {
return i;
}
}
return -1;
}
public String getUsablePill(int slotIndex) {
// System.out.println("Pill slot:" + Integer.toHexString(slotIndex).toUpperCase());
return bConnection.ToHex((byte) slotIndex) + "6C31";
}
public int pillIsAvailable() {
for(int i = 0; i < inventory.getInvSize(); i++) {
if(inventory.getItemType(i) == Inventory.pill) {
return i;
}
}
return -1;
}
public void useHP() {
int useabelSlot = hpIsAvailable();
if(useabelSlot != -1) {
bConnection.sendPacket("704C", getUsableHP(useabelSlot), "0003");
} else {
hpFlag = false;
bConnection.sendNotice("Out of HP Potions!");
}
}
public void useMP() {
int useabelSlot = mpIsAvailable();
if(useabelSlot != -1) {
bConnection.sendPacket("704C", getUsableMP(useabelSlot), "0003");
} else {
mpFlag = false;
bConnection.sendNotice("Out of MP Potions!");
}
}
public void usePill() {
int useabelSlot = pillIsAvailable();
if(useabelSlot != -1) {
bConnection.sendPacket("704C", getUsablePill(useabelSlot), "0003");
} else {
pillAmount = false;
bConnection.sendNotice("Out of Pills!");
}
}
public void testSender() {
bConnection.sendPacket("704C", "1C6C31", "0003");
}
public String getCharacterName(int nameLength) {
StringBuffer strB = new StringBuffer(nameLength);
for(int i = 0; i < nameLength; i++) {
strB.append(bConnection.hexToAscii(bConnection.parseByte()));
}
return strB.toString();
}
public boolean checkSlots(String[] slotArray, String curSlot) {
for(String aVal : slotArray) {
if(aVal.contentEquals(curSlot)) {
return true;
}
}
return false;
}
public void parsePacket() {
// if(!BotConnection.opCode.startsWith("2002") && BotConnection.opCode.contentEquals("3011")) {
// System.out.println("Current OPCode: " + BotConnection.opCode);
//// System.out.println("Length: " + BotConnection.size);
// System.out.println(bConnection.getPacket());
// }
// && BotConnection.opCode.contentEquals("3013")
// && (BotConnection.opCode.contentEquals("3057") || BotConnection.opCode.contentEquals("B04C"))
// && BotConnection.opCode.contentEquals("B034")
// BotConnection.opCode.startsWith("7")
if(BotConnection.opCode.contentEquals("3013")) {
String currHP;
String currMP;
byte slotID;
byte blueVal;
byte petStatus;
short petNameLength;
int itemID;
if(!titleFlag) { //parsing Charactername
bConnection.startParsingAt(8);
userName = getCharacterName(Integer.parseInt(bConnection.parseWord(), 16));
guiObj.setTitle();
titleFlag = true;
} else {
bConnection.startParsingAt(8);
getCharacterName(Integer.parseInt(bConnection.parseWord(), 16));
}
if(!hpFlag) {
hpFlag = true;
}
if(!mpFlag) {
mpFlag = true;
}
if(!pillAmount) {
pillAmount = true;
}
bConnection.parseByte();
bConnection.parseByte();
bConnection.parseByte();
bConnection.parseQWord();
bConnection.parseDWord();
bConnection.parseQWord();
bConnection.parseDWord();
bConnection.parseWord();
bConnection.parseByte();
bConnection.parseDWord();
currHP = bConnection.parseDWord();
currMP = bConnection.parseDWord();
BotCore.curHP = Integer.parseInt(currHP, 16);
BotCore.curMP = Integer.parseInt(currMP, 16);
if(BotCore.maxHP != 0 && BotCore.maxMP != 0) { //parsing HP and MP
guiObj.setHP();
guiObj.setMP();
}
bConnection.startParsingAt(70 + BotConnection.packetIndex);
inventory = new Inventory(Integer.parseInt(bConnection.parseByte(), 16));
inventory.setItemCount((byte)Integer.parseInt(bConnection.parseByte(), 16));
System.out.println("Inventory size: " + inventory.getInvSize());
System.out.println("Item amount: " + inventory.getItemCount());
for(int i = 0; i < inventory.getItemCount(); i++) {
slotID = (byte) Integer.parseInt(bConnection.parseByte(), 16);
itemID = Integer.parseInt(bConnection.parseDWord(), 16);
switch(checkItemID(itemID)) {
case 0: //Other Items (ETC)
if(checkForHP(itemID)) {
inventory.setSlot(slotID, (byte) 0x01, (short)Integer.parseInt(bConnection.parseWord(), 16));
} else if(checkForSHP(itemID)) {
inventory.setSlot(slotID, (byte) 0x10, (short)Integer.parseInt(bConnection.parseWord(), 16));
} else if(checkForMP(itemID)) {
inventory.setSlot(slotID, (byte) 0x02, (short)Integer.parseInt(bConnection.parseWord(), 16));
} else if(checkForSMP(itemID)) {
inventory.setSlot(slotID, (byte) 0x20, (short)Integer.parseInt(bConnection.parseWord(), 16));
} else if(checkForPills(itemID)) {
inventory.setSlot(slotID, (byte) 0x04, (short)Integer.parseInt(bConnection.parseWord(), 16));
} else {
bConnection.parseWord();
}
break;
case 1: //Equipment
bConnection.parseByte();
bConnection.parseQWord();
bConnection.parseDWord();
blueVal = (byte) Integer.parseInt(bConnection.parseByte(), 16);
if(blueVal > 0) {
for(int j = 0; j < blueVal; j++) {
bConnection.parseQWord();
}
}
break;
case 2: //growth pets
petStatus = (byte) Integer.parseInt(bConnection.parseByte(), 16);
if(petStatus == 3 || petStatus == 2) {
bConnection.parseDWord();
petNameLength = (short)Integer.parseInt(bConnection.parseWord(), 16);
for(int j = 0; j < petNameLength; j++) {
bConnection.parseByte();
}
}
break;
case 3: //pick pets
petStatus = (byte) Integer.parseInt(bConnection.parseByte(), 16);
if(petStatus == 3 || petStatus == 2) {
bConnection.parseDWord();
petNameLength = (short)Integer.parseInt(bConnection.parseWord(), 16);
for(int j = 0; j < petNameLength; j++) {
bConnection.parseByte();
}
bConnection.parseDWord();
}
break;
default:
return;
}
}
// System.out.println(inventory.toString());
}
if(BotConnection.opCode.contentEquals("7046")) {
bConnection.startParsing();
short tempID = (short)Integer.parseInt(bConnection.parseDWord(), 16);
if(titleFlag) {
if(tempID == Inventory.jgNPC) {
inventory.setNPC(tempID);
} else if(tempID == Inventory.dwNPC) {
inventory.setNPC(tempID);
} else if(tempID == Inventory.htNPC) {
inventory.setNPC(tempID);
} else {
inventory.setNPC(0);
}
}
}
if(BotConnection.opCode.contentEquals("B04B")) {
bConnection.startParsing();
byte closeFlag = (byte)Integer.parseInt(bConnection.parseByte(), 16);
if(titleFlag && inventory.getNPC() != 0 && closeFlag == 0x01) {
inventory.setNPC(0);
hpFlag = false;
mpFlag = false;
pillAmount = false;
}
}
if(BotConnection.opCode.contentEquals("3011")) {
bConnection.startParsing();
byte dieFlag = (byte)Integer.parseInt(bConnection.parseByte(), 16);
if(dieFlag == 0x04) {
hpFlag = false;
mpFlag = false;
pillAmount = false;
}
}
if(BotConnection.opCode.contentEquals("B034")) {
byte slotValue;
short itemIDValue;
byte arrayID;
byte sourceSlot;
byte swapType;
byte npcSlot;
short amount;
if(titleFlag) {
bConnection.startParsing();
bConnection.parseByte();
switch(Integer.parseInt(bConnection.parseByte(), 16)) {
case 0:
sourceSlot = (byte) Integer.parseInt(bConnection.parseByte(), 16);
slotValue = (byte) Integer.parseInt(bConnection.parseByte(), 16);
amount = (short)Integer.parseInt(bConnection.parseWord(), 16);
if(inventory.isEmpty(sourceSlot) && !inventory.isEmpty(slotValue)) {
arrayID = inventory.getItemType(slotValue);
inventory.setSlot(sourceSlot, inventory.getItemType(slotValue), inventory.getItemAmount(slotValue));
inventory.clearSlot(slotValue);
} else if(!inventory.isEmpty(sourceSlot) && inventory.isEmpty(slotValue)) {
if(inventory.getItemAmount(sourceSlot) > amount) {
arrayID = inventory.getItemType(sourceSlot);
inventory.setSlot(slotValue, arrayID, amount);
inventory.subItemAmount(sourceSlot, amount);
} else {
arrayID = inventory.getItemType(sourceSlot);
inventory.setSlot(slotValue, arrayID, amount);
inventory.clearSlot(sourceSlot);
}
} else if(!inventory.isEmpty(sourceSlot) && !inventory.isEmpty(slotValue)) {
if(inventory.slotConententEquals(sourceSlot, slotValue)) {
if(inventory.getItemAmount(sourceSlot) > amount) {
inventory.subItemAmount(sourceSlot, amount);
if(inventory.isEmpty(slotValue)) {
arrayID = inventory.getItemType(sourceSlot);
inventory.setSlot(slotValue, arrayID, amount);
} else {
inventory.addItemAmount(slotValue, amount);
}
} else {
inventory.addItemAmount(slotValue, amount);
inventory.clearSlot(sourceSlot);
}
} else {
swapType = inventory.getItemType(sourceSlot);
inventory.setSlot(sourceSlot, inventory.getItemType(slotValue), inventory.getItemAmount(slotValue));
inventory.setSlot(slotValue, swapType, amount);
}
}
// System.out.println(inventory.toString()); //####
break;
case 2:
break;
case 3:
break;
case 6:
slotValue = (byte) Integer.parseInt(bConnection.parseByte(), 16);
itemIDValue = (short) Integer.parseInt(bConnection.parseDWord(), 16);
arrayID = checkMoveItemID(itemIDValue);
if(arrayID == Inventory.hpPot ||
arrayID == Inventory.shpPot ||
arrayID == Inventory.mpPot ||
arrayID == Inventory.smpPot ||
arrayID == Inventory.pill) {
if(arrayID == Inventory.hpPot || arrayID == Inventory.shpPot) {
if(!hpFlag) {
hpFlag = true;
}
} else if(arrayID == Inventory.mpPot || arrayID == Inventory.smpPot) {
if(!mpFlag) {
mpFlag = true;
}
} else if(arrayID == Inventory.pill) {
if(!pillAmount) {
pillAmount = true;
}
}
amount = (short)Integer.parseInt(bConnection.parseWord(), 16);
inventory.setSlot(slotValue, arrayID, amount);
}
// System.out.println(inventory.toString()); //####
break;
case 7:
inventory.clearSlot((byte) Integer.parseInt(bConnection.parseByte(), 16));
// System.out.println(inventory.toString()); //####
break;
case 8:
bConnection.parseByte(); //NPC tab
if(inventory.getNPC() == Inventory.jgNPC) {
npcSlot = (byte) Integer.parseInt(bConnection.parseByte(), 16);
slotValue = (byte) Integer.parseInt(bConnection.parseByte(), 16);
amount = (short)Integer.parseInt(bConnection.parseWord(), 16);
if(npcSlot == 0 || npcSlot == 1) {
inventory.setSlot(slotValue, Inventory.hpPot, amount);
if(!hpFlag) {
hpFlag = true;
}
} else if(npcSlot == 2 || npcSlot == 3) {
inventory.setSlot(slotValue, Inventory.mpPot, amount);
if(!mpFlag) {
mpFlag = true;
}
} else if(npcSlot == 4 || npcSlot == 5) {
inventory.setSlot(slotValue, Inventory.pill, amount);
if(!pillAmount) {
pillAmount = true;
}
}
} else if(inventory.getNPC() == Inventory.dwNPC) {
npcSlot = (byte) Integer.parseInt(bConnection.parseByte(), 16);
slotValue = (byte) Integer.parseInt(bConnection.parseByte(), 16);
amount = (short)Integer.parseInt(bConnection.parseWord(), 16);
if(npcSlot == 0 || npcSlot == 1) {
inventory.setSlot(slotValue, Inventory.hpPot, amount);
if(!hpFlag) {
hpFlag = true;
}
} else if(npcSlot == 2 || npcSlot == 3) {
inventory.setSlot(slotValue, Inventory.mpPot, amount);
if(!mpFlag) {
mpFlag = true;
}
} else if(npcSlot == 4 || npcSlot == 5) {
inventory.setSlot(slotValue, Inventory.pill, amount);
if(!pillAmount) {
pillAmount = true;
}
}
} else if(inventory.getNPC() == Inventory.htNPC) {
npcSlot = (byte) Integer.parseInt(bConnection.parseByte(), 16);
slotValue = (byte) Integer.parseInt(bConnection.parseByte(), 16);
amount = (short)Integer.parseInt(bConnection.parseWord(), 16);
if(npcSlot == 0 || npcSlot == 1) {
inventory.setSlot(slotValue, Inventory.hpPot, amount);
if(!hpFlag) {
hpFlag = true;
}
} else if(npcSlot == 2 || npcSlot == 3) {
inventory.setSlot(slotValue, Inventory.mpPot, amount);
if(!mpFlag) {
mpFlag = true;
}
} else if(npcSlot == 4 || npcSlot == 5) {
inventory.setSlot(slotValue, Inventory.pill, amount);
if(!pillAmount) {
pillAmount = true;
}
}
}
break;
case 9:
sourceSlot = (byte) Integer.parseInt(bConnection.parseByte(), 16);
amount = (short)Integer.parseInt(bConnection.parseWord(), 16);
if(amount >= inventory.getItemAmount(sourceSlot)) {
inventory.clearSlot(sourceSlot);
} else {
inventory.subItemAmount(sourceSlot, amount);
}
// System.out.println(inventory.toString()); //####
break;
case 15:
inventory.clearSlot(Integer.parseInt(bConnection.parseByte(), 16));
break;
case 24:
if(Integer.parseInt(bConnection.parseByte(), 16) == 1) {
bConnection.parseByte();
if(Integer.parseInt(bConnection.parseByte(), 16) == 2) {
npcSlot = (byte) Integer.parseInt(bConnection.parseByte(), 16);
slotValue = (byte) Integer.parseInt(bConnection.parseByte(), 16);
amount = (short)Integer.parseInt(bConnection.parseWord(), 16);
if(npcSlot == 0 || npcSlot == 1 || npcSlot == 2) {
inventory.setSlot(slotValue, Inventory.shpPot, amount);
if(!hpFlag) {
hpFlag = true;
}
} else if(npcSlot == 3 || npcSlot == 4 || npcSlot == 5) {
inventory.setSlot(slotValue, Inventory.smpPot, amount);
if(!mpFlag) {
mpFlag = true;
}
}
// System.out.println(inventory.toString()); //####
}
}
break;
case 26:
break;
case 27:
break;
}
}
}
if(BotConnection.opCode.contentEquals("B04C")) {
byte packetFlag;
short tempV;
int amount;
byte slotV;
if(titleFlag) {
bConnection.startParsing();
packetFlag = (byte) Integer.parseInt(bConnection.parseByte(), 16);
if(packetFlag == 1) {
slotV = (byte) Integer.parseInt(bConnection.parseByte(), 16);
amount = Integer.parseInt(bConnection.parseWord(), 16);
tempV = (short) Integer.parseInt(bConnection.parseWord(), 16);
if(tempV == 2285 || tempV == 2284 || tempV == 4333 || tempV == 4332 || tempV == 12652) {
if(amount > 0) {
inventory.setItemAmount(slotV, (short) amount);
} else {
inventory.clearSlot(slotV);
}
}
// System.out.println(inventory.toString()); //####
}
}
}
if(BotConnection.opCode.contentEquals("30D2")) {
String tempStr;
bConnection.startParsing();
tempStr = bConnection.parseByte();
if(tempStr.contentEquals("00")) {
BotCore.pillFlag = false;
} else {
BotCore.pillFlag = true;
}
}
if(BotConnection.opCode.contentEquals("303D")) {
String mHP;
String mMP;
bConnection.startParsingAt(48);
mHP = bConnection.parseDWord();
mMP = bConnection.parseDWord();
BotCore.maxHP = Integer.parseInt(mHP, 16);
BotCore.maxMP = Integer.parseInt(mMP, 16);
if(!startFlag) {
startFlag = true;
guiObj.setHP();
guiObj.setMP();
// bConnection.sendNotice("maxHP: " + BotCore.maxHP + " maxMP: " + BotCore.maxMP);
// bConnection.sendNotice("curHP: " + BotCore.curHP + " curMP: " + BotCore.curMP); //#########
// bConnection.sendNotice("HP: " + mHP + " MP: " + mMP);
}
if(!hmMax) {
hmMax = true;
}
}
if(BotConnection.opCode.contentEquals("3057") && hmMax) {
bConnection.startParsingAt(10);
int a = Integer.parseInt(bConnection.parseByte(), 16);
// bConnection.sendNotice("" + a); //#########
switch(a) {
case 1:
int curHPVal = Integer.parseInt(bConnection.parseWord(), 16);
if(curHPVal != 0) {
BotCore.curHP = curHPVal;
}
guiObj.setHP();
// bConnection.sendNotice("HP: " + curHPVal); //#########
break;
case 2:
int curMPVal = Integer.parseInt(bConnection.parseWord(), 16);
if(curMPVal != 0) {
BotCore.curMP = curMPVal;
}
guiObj.setMP();
// bConnection.sendNotice("MP: " + curMPVal); //#########
break;
case 3:
int curHPD = Integer.parseInt(bConnection.parseDWord(), 16);
int curMPD = Integer.parseInt(bConnection.parseDWord(), 16);
// bConnection.sendNotice("HP: " + curHPD + " MP: " + curMPD); //#########
if(curHPD != 0) {
BotCore.curHP = curHPD;
}
if(curMPD != 0) {
BotCore.curMP = curMPD;
}
guiObj.setHP();
guiObj.setMP();
break;
}
}
}
public byte checkItemID(int id) {
if((id >= 71 && id <= 1897) ||
(id >= 2160 && id <= 2176) ||
(id >= 2200 && id <= 3663) ||
(id >= 3707 && id <= 3755) ||
(id >= 3748 && id <= 3766) ||
(id >= 3837 && id <= 3846) ||
(id >= 3888 && id <= 3899) ||
(id >= 3940 && id <= 3945) ||
(id >= 4014 && id <= 5840) ||
(id >= 7066 && id <= 7077) ||
(id >= 7486 && id <= 7487) ||
(id >= 9011 && id <= 9052) ||
(id >= 9992 && id <= 9993) ||
(id >= 9996 && id <= 10004)) {
return 1;
} else if(id == 7488 || id == 8999 || id == 9983) {
return 2;
} else if(id == 9000 || id == 7489 || id == 10224 || id == 10225) {
return 3;
} else {
return 0;
}
}
public byte checkMoveItemID(int id) {
if(checkForHP(id)) {
return 0x01;
} else if(checkForSHP(id)) {
return 0x10;
} else if(checkForMP(id)) {
return 0x02;
} else if(checkForSMP(id)) {
return 0x20;
} else if(checkForPills(id)) {
return 0x04;
} else {
return 0x00;
}
}
public boolean checkForHP(int id) {
for(int value : Inventory.hpPots) {
if(value == id) {
return true;
}
}
return false;
}
public boolean checkForSHP(int id) {
for(int value : Inventory.shpPots) {
if(value == id) {
return true;
}
}
return false;
}
public boolean checkForMP(int id) {
for(int value : Inventory.mpPots) {
if(value == id) {
return true;
}
}
return false;
}
public boolean checkForSMP(int id) {
for(int value : Inventory.smpPots) {
if(value == id) {
return true;
}
}
return false;
}
public boolean checkForPills(int id) {
for(int value : Inventory.pills) {
if(value == id) {
return true;
}
}
return false;
}
public void updateCount() {
potCount++;
gcCount++;
if(potCount > 3) {
potCount = 0;
}
if(gcCount > 50) {
gcCount = 0;
}
}
@Override
public void run() {
while(Thread.currentThread().isInterrupted() == false) {
bConnection.readPacket();
parsePacket();
if(BotCore.runState) {
if((BotCore.percentageHP <= BotCore.hpLimit) && hpFlag && potCount == 0) {
useHP();
}
if((BotCore.percentageMP <= BotCore.mpLimit) && mpFlag && potCount == 1) {
useMP();
}
if(pillFlag && pillAmount && potCount == 2) {
usePill();
}
}
updateCount();
if(gcCount == 0) {
Runtime.getRuntime().gc();
}
try {
Thread.sleep(20);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Inventory.java
Code:
package bot;
public class Inventory {
public static final byte hpPot = 0x01;
public static final byte shpPot = 0x10;
public static final byte mpPot = 0x02;
public static final byte smpPot = 0x20;
public static final byte pill = 0x04;
public static final int jgNPC = 197;
public static final int dwNPC = 316;
public static final int htNPC = 504;
public static final int[] hpPots = {4, 5, 6, 7, 8, 9};
public static final int[] shpPots = {3817, 3818, 3819};
public static final int[] mpPots = {11, 12, 13, 14, 15, 16};
public static final int[] smpPots = {3820, 3821, 3822};
public static final int[] pills = {55, 56, 57, 58};
private short[][] inventoryArray;
private byte itemCount;
private short invSize;
private int curNPC;
public Inventory(int size) {
invSize = (short)size;
inventoryArray = new short[size][2];
curNPC = 0;
}
public void setNPC(int npcID) {
curNPC = npcID;
}
public int getNPC() {
return curNPC;
}
public void setSlot(int slot, byte id, short amount) {
inventoryArray[slot][0] = id;
inventoryArray[slot][1] = amount;
}
public boolean isEmpty(int slot) {
if(inventoryArray[slot][1] == 0) {
return true;
} else {
return false;
}
}
public byte getItemCount() {
return itemCount;
}
public void setItemCount(byte amount) {
itemCount = amount;
}
public boolean slotConententEquals(int slotEins, int slotZwei) {
if(inventoryArray[slotEins][0] == inventoryArray[slotZwei][0]) {
return true;
} else {
return false;
}
}
public void clearSlot(int slot) {
inventoryArray[slot][0] = 0;
inventoryArray[slot][1] = 0;
}
public void setItemAmount(int slot, short amount) {
inventoryArray[slot][1] = amount;
}
public byte getItemType(int slot) {
return (byte) inventoryArray[slot][0];
}
public void subItemAmount(int slot, short amount) {
inventoryArray[slot][1] -= amount;
}
public void addItemAmount(int slot, short amount) {
inventoryArray[slot][1] += amount;
}
public short getItemAmount(int slot) {
return inventoryArray[slot][1];
}
public short getInvSize() {
return invSize;
}
public int getSlot(int slot, byte typeFlag) {
if(slot > 0 && slot < inventoryArray.length) {
if((typeFlag & 0x01) == 0x01) {
return inventoryArray[slot][0];
} else if((typeFlag & 0x02) == 0x02) {
return inventoryArray[slot][1];
} else {
return -1;
}
} else {
return -1;
}
}
public String toString() {
StringBuffer strB = new StringBuffer();
strB.append("Inventar: ");
for(int i = 0; i < inventoryArray.length; i++) {
strB.append("[");
for(int j = 0; j < inventoryArray[i].length; j++) {
if(j < 1) {
strB.append(inventoryArray[i][j] + ", ");
} else {
strB.append(inventoryArray[i][j]);
}
}
strB.append("] ");
}
return strB.toString();
}
}
Complete Source added as an attachment.
Attached Files
mhtc_autopot.zip
(9.9 KB, 64 views)
01/12/2013, 15:55
#2
elite*gold: 130
Join Date: Mar 2008
Posts: 2,485
Received Thanks: 934
Cool!
I like this release.
Is it decompiled, or a newly reworked, or you're the original writer of the autopot?
01/13/2013, 05:16
#3
elite*gold: 0
Join Date: Mar 2009
Posts: 248
Received Thanks: 118
Quote:
Originally Posted by
intercsaki
Cool!
I like this release.
Is it decompiled, or a newly reworked, or you're the original writer of the autopot?
I'm the original writer.
I'd love to do some more work like some multiclient that sends packets to serveral connections and thus act kinda like the multiboxing programs but just clientless or an auto fusing tool which could do all the alchemy automated.
The problem is, I've got no more time to do such fun things, and no server to test on. Since this tool uses MHTC packet opcodes I would have to analyze vsro packets or any other's sro client's opcode because of lacking MHTC based servers.
Nevertheless it was a nice time back when I wrote this AutoPotter. Like successfully sending your first Sit-Packet which makes you feel almighty and motivates you very much! From there on you'll do a lot of progress and can do pretty much everything.
01/14/2013, 16:30
#4
elite*gold: 130
Join Date: Mar 2008
Posts: 2,485
Received Thanks: 934
I have quite a some source codes of programs which are made for vsro servers. Surely I can extract some of the opcodes for you, if you would like me to.
01/14/2013, 16:44
#5
elite*gold: 0
Join Date: Mar 2009
Posts: 248
Received Thanks: 118
Quote:
Originally Posted by
intercsaki
I have quite a some source codes of programs which are made for vsro servers. Surely I can extract some of the opcodes for you, if you would like me to.
Thanks but I think I'll keep it like it currently is and will not return to silkroad development, Silkroad was a great time back then and it should remain as this in my memory. And I wouldn't even know on what Server to start on because of the short life expectancy.
01/14/2013, 18:39
#6
elite*gold: 130
Join Date: Mar 2008
Posts: 2,485
Received Thanks: 934
I agree, when sro was a great game, it was many years ago. You do it wisely, by not returning..
01/16/2013, 22:30
#7
elite*gold: 0
Join Date: Jan 2013
Posts: 74
Received Thanks: 12
Cool! I like this release.
01/21/2013, 22:17
#8
elite*gold: 130
Join Date: Mar 2008
Posts: 2,485
Received Thanks: 934
Wow! You learnt how to copy and paste!
Similar Threads
Open Source Aion Emulator [JAVA]
02/15/2013 - Aion Hacks, Bots, Cheats & Exploits - 2 Replies
SVN: aion-emu - Revision 572: /
Trac: aion-emu - Trac
Have Fun :)
Aion-Emu development forum - Index - main page with forum, for aion-emu project
[New Release] MHS-AutoPot-PW v1.0 (Memory Country Customizer And Source Code)
01/08/2012 - PW Hacks, Bots, Cheats, Exploits - 13 Replies
MHS-AutoPot-PW v1.0 With Country Memory Customizer And Source Code
================================================= =
(English)
This release is default configured to Perfect World (Brazil). If you want to adjust to your country the Perfect World application title, memory base address and memory offsets to find Target, HP, Max HP, Max MP please see read notes for CustomOffSets.ini.
You can try to find the memory addresses using softwares like Cheat Engine (memory searchers).
This...
[Source Code] Zahlensystem Rechner [Java]
11/07/2011 - General Coding - 2 Replies
Schaut es euch an und ich wäre froh wenn ihr Verbesserungsvorschläge habt
Auch wenn ihr Fragen habt bin ich natürlich bereit diese zu beantworten.
Eine Erklärung zu dem Code befindet sich in den Kommentaren.
Vllt kann es jemand gebrauchen, vllt aber auch nicht :P
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.Object.*;
[DEV] Java source
01/22/2010 - CO2 Private Server - 1 Replies
Well since the only language (it seems) in the co section is C#
Ive decided to start a project
This project will be coded in java and since im ALRIGHT in java i could probaly use some help
Ill need approximatly 2 more people to help with this project
you can add me on msn at [email protected]
If you have no clue how to code in java do not bother adding me
[Java] Source Question
11/11/2008 - CO2 Private Server - 3 Replies
hey i go learn java since everything is ok in normal life again i have the time to learn java and i probally come back to epvp sometimes but is it possible to make a source based on java? (no im not going to learn java for that its just a question:p)
All times are GMT +2. The time now is 09:12 .