Advertisement
TheBat

BatCooker

Feb 23rd, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.75 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import java.awt.Image;
  5. import java.awt.Point;
  6. import java.awt.Rectangle;
  7. import java.awt.event.MouseEvent;
  8. import java.awt.event.MouseListener;
  9. import java.io.IOException;
  10. import java.net.URL;
  11. import java.util.List;
  12. import javax.imageio.ImageIO;
  13. import org.runedream.api.Script;
  14. import org.runedream.api.ScriptManifest;
  15. import org.runedream.api.methods.Bank;
  16. import org.runedream.api.methods.Camera;
  17. import org.runedream.api.methods.Game;
  18. import org.runedream.api.methods.ImageUtil;
  19. import org.runedream.api.methods.Mouse;
  20. import org.runedream.api.util.Log;
  21. import org.runedream.api.util.Random;
  22. import org.runedream.api.util.Timer;
  23.  
  24. @ScriptManifest(
  25. authors = { "TheBat"},
  26. name = "BatCooker",
  27. version = 1.3,
  28. description = "Cooks shit at the rogues den.",
  29. keywords = {},
  30. language = { true, true, true, true })
  31.  
  32. public class BatCooker extends Script implements MouseListener{
  33.  
  34. final private static Color fire = new Color(203,125,35);
  35. final private static Color bankerF = new Color(108,124,55);
  36. final private static Color bankerB = new Color(30,41,23);
  37. final private static Rectangle viewPort = new Rectangle(4,4,513,335);
  38. private static String status = "";
  39. private static Image pic = null;
  40. private static Image back = null;
  41. private static long TIME = 0;
  42. private boolean showPaint = true;
  43. private int cooked = 0;
  44. private int burned = 0;
  45. private int row = 0;
  46. private int col = 0;
  47. private boolean first;
  48. Color temp0 = null;
  49. Color temp1 = null;
  50. Color temp2 = null;
  51. Color raw = null;
  52. private long cookTO = 0;
  53. private boolean checkCooked = true;
  54. private Color notB0 = null;
  55. private Color notB1 = null;
  56. private Color notB2 = null;
  57. private Antiban anti = null;
  58.  
  59.  
  60. public boolean onStart(){
  61. TIME = System.currentTimeMillis();
  62. try {
  63. back = ImageIO.read(new URL("http://i1066.photobucket.com/albums/u406/bootsncats/underPaint.png"));
  64. } catch (IOException e) {
  65. }
  66. try {
  67. pic = ImageIO.read(new URL("http://i1066.photobucket.com/albums/u406/bootsncats/fire.png"));
  68. } catch (IOException e) {
  69. }
  70. status = "Finding banker";
  71. anti = new Antiban();
  72. //anti.start();
  73. return true;
  74. }
  75.  
  76. public int loop() {
  77. if(System.currentTimeMillis() - TIME > 22320000){
  78. Log.log("Over 6 hours, you are probably Client token errored.", Color.RED);
  79. return 1;
  80. }
  81. Mouse.setSpeed(Random.random(6,12));
  82. if(status.equals("Finding banker")){
  83. Mouse.setSpeed(2);
  84. Point bankerPt = findBanker();
  85. if(bankerPt.x == -1){
  86. Mouse.move(Random.random(0,517),Random.random(0,339));
  87. if(Bank.isOpen()){
  88. status = "Banking";
  89. return 100;
  90. }
  91. Camera.rotateLeft(300);
  92. Camera.pitchDown(300);
  93. return 100;
  94. }
  95. Mouse.click(bankerPt, false);
  96. Script.sleep(100);
  97. String lol = OCR.findString(new Rectangle(bankerPt.x-200,bankerPt.y+30, 200,25), null);
  98. if(lol.contains("Bank") || lol.contains("ank") || lol.contains("nk") || lol.contains("Ba")
  99. || lol.contains("Ban") || lol.contains("an"))Mouse.click(bankerPt.x,bankerPt.y+46);
  100. else{
  101. Mouse.move(Random.random(0,517),Random.random(0,339));
  102. Camera.rotateLeft(300);
  103. Camera.pitchDown(300);
  104. return 100;
  105. }
  106. int i = 0;
  107. while(!Bank.isOpen() && i <= 40){
  108. Script.sleep(100);
  109. i++;
  110. }
  111. if(Bank.isOpen()){
  112. status = "Banking";
  113. }
  114. return 100;
  115. }
  116. if(status.equals("Banking")){
  117. if(Bank.isOpen()){
  118. raw = Game.getColorAt(45,111);
  119. int x = Random.random(50, 60);
  120. int y = Random.random(100, 110);
  121. Bank.depositAll();
  122. sleep(500,700);
  123. Mouse.click(x,y,false);
  124. sleep(500,700);
  125. Mouse.click(x, (y + Random.random(103,126)));
  126. sleep(500,700);
  127. Mouse.move(489,30);
  128. if(Mouse.getLocation()!= new Point(489,30)) Mouse.move(489,30);
  129. sleep(200,300);
  130. Mouse.click();
  131. sleep(100,200);
  132. Mouse.move(Random.random(0,765), Random.random(0,502));
  133. sleep(400,500);
  134. }
  135. status = "Finding fire";
  136. return 100;
  137. }
  138. if(status.equals("Finding fire")){
  139. if(Game.getColorAt(343,427).equals(new Color(89,81,68))){
  140. status = "Cooking";
  141. return 100;
  142. }
  143. if(Bank.isOpen()){
  144. status = "Banking";
  145. return 100;
  146. }
  147. if(!checkColor(raw,new Point(570,232), 20)){
  148. status = "Finding banker";
  149. return 100;
  150. }
  151. Camera.pitchUp(300);
  152. sleep(100);
  153. Camera.rotateRight(300);
  154. Mouse.click(Random.random(567,587),Random.random(219,240));
  155. Mouse.setSpeed(2);
  156. Point firePt = findFire();
  157. sleep(300);
  158. if(firePt.x == -1)return 100;
  159. Mouse.click(firePt,false);
  160. sleep(200);
  161. boolean found = false;
  162. int k = 0;
  163. if(checkColor(Color.WHITE,new Point(firePt.x,firePt.y+72),4)){
  164. k = 1;
  165. found = true;
  166. }else{
  167. for(; k <= 12; k++){
  168. if(Game.getColorAt(343,427).equals(new Color(89,81,68))){
  169. status = "Cooking";
  170. return 100;
  171. }
  172. String lol = OCR.findString(new Rectangle(firePt.x-60,firePt.y+(17*k),350,21), null, true);
  173. Mouse.move(firePt.x,firePt.y+(17*k)+11);
  174. if(lol.contains("Fire")){
  175. found = true;
  176. break;
  177. }
  178. if(checkColor(Color.WHITE,new Point(firePt.x,firePt.y+((k + 1)*17)),8)){
  179. found = true;
  180. break;
  181. }
  182.  
  183. }
  184. }
  185. if(found)Mouse.click(firePt.x,firePt.y+(17*k)+11);
  186. else Mouse.click(Random.random(567,587),Random.random(219,240));
  187. sleep(1000);
  188. if(Game.getColorAt(343,427).equals(new Color(89,81,68)))status = "Cooking";
  189. row = 0;
  190. col = 0;
  191. first = true;
  192. return 100;
  193. }
  194.  
  195. if(status.equals("Cooking")){
  196. if(first){
  197. temp0 = Game.getColorAt(570 ,229);
  198. temp1 = Game.getColorAt(586 ,222);
  199. temp2 = Game.getColorAt(574 ,231);
  200. Mouse.click(Random.random(240,282),Random.random(405,455));
  201. first = false;
  202. cookTO = System.currentTimeMillis();
  203. }
  204. if(System.currentTimeMillis()- cookTO > 120000){
  205. status = "Finding banker";
  206. return 100;
  207. }
  208. if(!checkColor(temp0,new Point(570 + (col*42),229 + (row*36)),15)
  209. || !checkColor(temp1,new Point(586 + (col*42),222 + (row*36)),15)
  210. || !checkColor(temp2,new Point(574 + (col*42),231 + (row*36)),15)){
  211. if(checkCooked){
  212. Mouse.move(Random.random(567,587),Random.random(219,240));
  213. String type = OCR.findString(new Rectangle(29,10,100,15), null);
  214. if(!type.contains("Burned") || !type.contains("Burn")){
  215. notB0 = Game.getColorAt(570 + (col*42),229 + (row*36));
  216. notB1 = Game.getColorAt(586 + (col*42),222 + (row*36));
  217. notB2 = Game.getColorAt(574 + (col*42),231 + (row*36));
  218. checkCooked = false;
  219. cooked++;
  220. }
  221. }else{
  222. if(!isDarker(Game.getColorAt(570 + (col*42),229 + (row*36)),notB0)
  223. || !isDarker(Game.getColorAt(586 + (col*42),222 + (row*36)),notB1)
  224. || !isDarker(Game.getColorAt(574 + (col*42),231 + (row*36)),notB2)){
  225. cooked++;
  226. }else{
  227. burned++;
  228. }
  229. }
  230. col++;
  231.  
  232. if(col == 4){
  233. col = 0;
  234. row++;
  235. if(row == 7){
  236. status = "Finding banker";
  237. return 100;
  238. }
  239. }
  240. return 100;
  241. }
  242. return 100;
  243. }
  244.  
  245. return 100;
  246. }
  247. public void onRepaint(Graphics g){
  248. int percent = 0;
  249. try{
  250. percent = (int) (100*((double)burned/(double)(cooked+burned)));
  251. }catch(ArithmeticException e){
  252. }
  253. if(showPaint){
  254. g.drawImage(back, 5, 343, null);
  255. g.setColor(Color.BLACK);
  256. g.setFont(new Font("Salaryman", 1, 14));
  257. g.drawString("Time Running: " + Timer.getTime(System.currentTimeMillis() - TIME), 11, 360);
  258. g.drawString("Total Cooked: " + cooked ,11,377);
  259. g.drawString("Cooks/Hour: " + (3600000*(long)cooked)/(int)(System.currentTimeMillis() - TIME),11,394);
  260. g.drawString("Burn Percentage: " + percent + "%",11,411);
  261. g.drawString("Status: " + status ,11,428);
  262. g.drawImage(pic, 240, 300, null, null);
  263. g.setFont(new Font("Salaryman", 1, 25));
  264. g.drawString("BatCooker",270,390);
  265. g.drawString("Version 1.3",265,420);
  266. g.setColor(Color.ORANGE);
  267. g.drawString("Ve",265,420);
  268.  
  269. g.setColor(Color.RED);
  270. g.drawString("x",500,360);
  271. }else{
  272. g.setColor(Color.GREEN);
  273. g.setFont(new Font("Salaryman", 1, 25));
  274. g.drawString("o",500,360);
  275. }
  276.  
  277. g.setColor(Color.CYAN);
  278. g.drawLine(Mouse.getLocation().x,0,Mouse.getLocation().x,2100);
  279. g.drawLine(0,Mouse.getLocation().y,2100,Mouse.getLocation().y);
  280. }
  281. public void onStop(){
  282. //anti.interrupt();
  283. Log.log("Thanks for using BatCooker!");
  284. Log.log("Total runtime of: " + Timer.getTime(System.currentTimeMillis() - TIME));
  285. Log.log("You cooked " + cooked + " food.");
  286. }
  287. private static Point findBanker(){
  288. Point thePoint = new Point();
  289. List<Point> test = ImageUtil.getPointsWithColor(Game.getImage(), viewPort, bankerF,.05);
  290. try{
  291. if(test.size() < 1)throw new IllegalArgumentException();
  292. thePoint = test.get(Random.random(0,test.size()-1));
  293. }catch(IllegalArgumentException e){
  294. try{
  295. test = ImageUtil.getPointsWithColor(Game.getImage(), viewPort, bankerB,.02);
  296. if(test.size() < 1)throw new IllegalArgumentException();
  297. thePoint = test.get(Random.random(0,test.size()-1));
  298. }catch(IllegalArgumentException e2){
  299. thePoint = new Point(-1,-1);
  300. }
  301. }
  302. return thePoint;
  303. }
  304. private static Point findFire(){
  305. Point thePoint = new Point();
  306. List<Point> test = ImageUtil.getPointsWithColor(Game.getImage(), viewPort, fire,.05);
  307. try{
  308. if(test.size() < 1)throw new IllegalArgumentException();
  309. thePoint = test.get(Random.random(0,test.size()-1));
  310. }catch(IllegalArgumentException e){
  311. // try{
  312. // test = ImageUtil.getPointsWithColor(Game.getImage(), viewPort, bankerB,.02);
  313. // if(test.size() < 1)throw new IllegalArgumentException();
  314. // thePoint = test.get(Random.random(0,test.size()-1));
  315. // }catch(IllegalArgumentException e2){
  316. thePoint = new Point(-1,-1);
  317. // }
  318. }
  319. return thePoint;
  320. }
  321. /**
  322. * Returns whether the given point is a certain color.
  323. * Accounts for the variable colors that runescape produces whenever you log in.
  324. * @param col
  325. * - Color to check for.
  326. * @param p
  327. * - Point to check at.
  328. * @return
  329. */
  330. private boolean checkColor(Color col, Point p, int tol){
  331. if(Math.abs(col.getRed() - Game.getColorAt(p).getRed()) < tol)
  332. if(Math.abs(col.getGreen() - Game.getColorAt(p).getGreen()) < tol)
  333. if(Math.abs(col.getBlue() - Game.getColorAt(p).getBlue()) < tol)
  334. return true;
  335. return false;
  336. }
  337. public boolean isDarker(final Color c1, final Color c2) {
  338. int col1 = c1.getRed() + c1.getGreen() + c1.getBlue();
  339. int col2 = c2.getRed() + c2.getGreen() + c2.getBlue();
  340. return col1 < col2 ? true : false;
  341. }
  342. /**
  343. * Mouse listener
  344. */
  345. public void mouseClicked(MouseEvent e) {
  346. Point pt = e.getPoint();
  347. if (pt.x >= 499 && pt.x <= 512 && pt.y >= 345 && pt.y <= 360) {
  348. showPaint = !showPaint;
  349. }
  350. }
  351. public void mouseEntered(MouseEvent arg0) {}
  352. public void mouseExited(MouseEvent arg0) {}
  353. public void mousePressed(MouseEvent arg0) {}
  354. public void mouseReleased(MouseEvent arg0) {}
  355.  
  356. //New class
  357. class Antiban extends Thread implements Runnable {
  358. public Antiban() {
  359. this.setPriority(MIN_PRIORITY);
  360. }
  361.  
  362. @Override
  363. public void run() {
  364. try{
  365. while (!Thread.interrupted()) {
  366. if(BatCooker.status.equals("Cooking")){
  367. if(Thread.interrupted()) return;
  368. int anti = Random.random(0, 10000000);
  369. // if(anti < 2){
  370. // Camera.rotateLeft(Random.random(0, 500));
  371. // if(Thread.interrupted()) return;
  372. // }else if(anti > 9999998){
  373. // Camera.rotateRight(Random.random(0, 500));
  374. // if(Thread.interrupted()) return;
  375. // }
  376. if(Thread.interrupted()) return;
  377. }
  378. }
  379. if(Thread.interrupted()) return;
  380. } finally{}
  381. return;
  382. }
  383. }
  384. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement