import impsoft.ibot.Areas; import impsoft.ibot.core.SettingsManager; import impsoft.ibot.methods.Menu; import impsoft.ibot.methods.Methods; import impsoft.ibot.methods.NPCChat; import impsoft.ibot.methods.Script; import java.awt.Canvas; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.util.ArrayList; import javax.swing.JFrame; public class ibotDeveloper extends Script { private class GuiMouseListener extends MouseAdapter { public void mouseClicked(MouseEvent e) { if (!scriptThread.isAlive()) { removeRSListener(); removeGui(); } } } private RSMouseListener theRSMouseListener; private class RSMouseListener extends MouseAdapter { public void mouseClicked(MouseEvent e) { if (!scriptThread.isAlive()) { removeRSListener(); removeGui(); } else { x = e.getX(); y = e.getY(); lastClickTime = System.currentTimeMillis(); } } } private class PaintingThread extends Thread { private ArrayList jobs; public paintJob newPaintJob = null; private BufferedImage framebf; private Graphics gfx; public PaintingThread() { jobs = new ArrayList(5); newPaintJob = null; framebf = (BufferedImage) can.createImage(SettingsManager.maxX, SettingsManager.maxY); gfx = framebf.getGraphics(); } public void addPaintJob(paintJob newPaintJob) { this.newPaintJob = newPaintJob; } private void addToRun() { if (newPaintJob != null) { jobs.add(newPaintJob); newPaintJob = null; } } public void run() { while (true) { addToRun(); BufferedImage appletbf = theBot.theBitMapManger .getBufferedImage(Methods.defaultmaxAgeInMillisecs); addToRun(); gfx.drawImage(appletbf, 0, 0, can); addToRun(); for (int i = 0; i < jobs.size(); i++) { paintJob pj = jobs.get(i); if (pj.timeUp()) { jobs.remove(i); i--; } else { pj.paint(gfx); } } addToRun(); can.getGraphics().drawImage(framebf, 0, 0, can); addToRun(); try { sleep(10); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } private interface paintJob { void paint(Graphics gfx); boolean timeUp(); } private class UpdaterThread extends Thread { public NPCChat lastNPCChat = null; public Menu lastMenu = null; @Override public void run() { try { while (scriptThread.isAlive()) { if (System.currentTimeMillis() > lastClickTime + 500) { lastNPCChat = getNPCChat(400); } if (System.currentTimeMillis() > lastClickTime + 500) { lastMenu = getMenu(Areas.ENTIRE, 400); } sleep(100); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public static double version = 0.0; public static String[] commands = new String[] { " " }; public static String author = " "; public String description = " "; public Thread scriptThread; public UpdaterThread theUpdaterThread; public PaintingThread theSwingThread; public JFrame frame; public Canvas can; public long lastClickTime = 0; int x = 0; int y = 0; private void addGui() { frame = new JFrame(); can = new Canvas(); can.setSize(SettingsManager.maxX, SettingsManager.maxY); can.addMouseListener(new GuiMouseListener()); frame.add(can); frame.pack(); frame.setVisible(true); } public void addRSListener() { theRSMouseListener = new RSMouseListener(); theBot.theApplet.getComponentAt(1, 1).addMouseListener( theRSMouseListener); } public boolean doStart(String cmd, String[] args) { return true; } private void removeGui() { frame.dispose(); } public void removeRSListener() { theBot.theApplet.getComponentAt(1, 1).removeMouseListener( theRSMouseListener); } public void script() throws InterruptedException { addRSListener(); addGui(); scriptThread = this; theUpdaterThread = new UpdaterThread(); theUpdaterThread.start(); theSwingThread = new PaintingThread(); theSwingThread.start(); while (true) { if (System.currentTimeMillis() < lastClickTime + 1000) { boolean found = false; if (Areas.CHAT.contains(x, y)) { NPCChat lastNPCChat = theUpdaterThread.lastNPCChat; if (lastNPCChat != null) { for (int i = 0; i < lastNPCChat.options.length; i++) { if (lastNPCChat.locations[i].contains(x, y)) { log("----------------------------------"); log("[NPCChat] Rectangle =" + lastNPCChat.locations[i]); log("[NPCChat] Color = " + lastNPCChat.colors[i]); log("[NPCChat] Text = " + lastNPCChat.options[i]); log("----------------------------------"); found = true; break; } } } else { for (int i = 0; i < 5; i++) { log(" getChat(" + i + ") = " + getChat(i)); } } } else { Menu lastMenu = theUpdaterThread.lastMenu; if (lastMenu != null) { if (lastMenu.location.contains(x, y)) { for (int i = 0; i < lastMenu.options.length; i++) { if (lastMenu.getRectange(i).contains(x, y)) { log("-----------------------------------"); log("[Menu] Rectangle =" + lastMenu.getRectange(i)); log("[Menu] Text = " + lastMenu.options[i]); log("----------------------------------"); found = true; break; } } } } } if (!found) log("x=" + x + " y=" + y + " getRGB(x, y)=" + getRGB(x, y)); final long endTime = System.currentTimeMillis() + 2000; final int xSpot = x; final int ySpot = y; theSwingThread.addPaintJob(new paintJob() { public void paint(Graphics gfx) { gfx.drawRect(xSpot - 3, ySpot - 3, 6, 6); } public boolean timeUp() { return System.currentTimeMillis() > endTime; } }); sleep(1000); } sleep(100); } } }