Beispiel #1
0
 public Bot getBot(final Object o) {
   final ClassLoader cl = o.getClass().getClassLoader();
   for (final Bot bot : bots) {
     if (cl == bot.getLoader().getClient().getClass().getClassLoader()) {
       panel.offset();
       return bot;
     }
   }
   return null;
 }
Beispiel #2
0
 public void addBot() {
   if (bots.size() > MAX_BOTS) {
     return;
   }
   final Bot bot = new Bot();
   bots.add(bot);
   toolBar.addTab();
   toolBar.setAddTabVisible(bots.size() < MAX_BOTS);
   bot.getScriptHandler().addScriptListener(this);
   new Thread(
           new Runnable() {
             public void run() {
               bot.start();
             }
           })
       .start();
 }
Beispiel #3
0
 private void showStopScript(final Bot bot) {
   final ScriptHandler sh = bot.getScriptHandler();
   final Map<Integer, LoopTask> running = sh.getRunningScripts();
   if (running.size() > 0) {
     final int result =
         JOptionPane.showConfirmDialog(
             this,
             "Would you like to stop the script?",
             "Script",
             JOptionPane.OK_CANCEL_OPTION,
             JOptionPane.QUESTION_MESSAGE);
     if (result == JOptionPane.OK_OPTION) {
       sh.stopAllScripts();
       bot.getMethodContext().web.unloadWebScripts();
       updateScriptControls();
     }
   }
 }
Beispiel #4
0
 private void showScriptSelector(final Bot bot) {
   if (bot.getMethodContext() == null) {
     log.warning("The client is still loading");
   } else {
     if (AccountManager.getAccountNames().length == 0) {
       log.warning("No accounts saved, Facebook connect will be used");
     }
     new ScriptSelector(this, bot).showGUI();
   }
 }
Beispiel #5
0
  public void updateScriptControls() {
    boolean idle = true, paused = false;
    final Bot bot = getCurrentBot();

    if (bot != null) {
      final Map<Integer, LoopTask> scriptMap = bot.getScriptHandler().getRunningScripts();
      if (scriptMap.size() > 0) {
        idle = false;
        paused = scriptMap.values().iterator().next().isPaused();
      } else {
        idle = true;
      }
    }

    menuBar.getMenuItem(Messages.RUNSCRIPT).setVisible(idle);
    menuBar.getMenuItem(Messages.STOPSCRIPT).setVisible(!idle);
    menuBar.getMenuItem(Messages.PAUSESCRIPT).setEnabled(!idle);
    menuBar.setPauseScript(paused);
    toolBar.setInputButtonVisible(!idle);
    menuBar.setEnabled(Messages.FORCEINPUT, !idle);

    if (idle) {
      toolBar.setOverrideInput(false);
      menuBar.setOverrideInput(false);
      toolBar.setInputState(Environment.INPUT_KEYBOARD | Environment.INPUT_MOUSE);
      toolBar.setScriptButton(BotToolBar.RUN_SCRIPT);
    } else {
      toolBar.setOverrideInput(bot.overrideInput);
      menuBar.setOverrideInput(bot.overrideInput);
      toolBar.setInputState(bot.inputFlags);
      toolBar.setScriptButton(paused ? BotToolBar.RESUME_SCRIPT : BotToolBar.PAUSE_SCRIPT);
    }

    toolBar.updateInputButton();
    repaint();
  }
Beispiel #6
0
 public void removeBot(final Bot bot) {
   final int idx = bots.indexOf(bot);
   bot.getScriptHandler().stopAllScripts();
   bot.getScriptHandler().removeScriptListener(this);
   if (idx >= 0) {
     toolBar.removeTab(idx);
   }
   bots.remove(idx);
   toolBar.setAddTabVisible(bots.size() < MAX_BOTS);
   new Thread(
           new Runnable() {
             public void run() {
               bot.stop();
               System.gc();
             }
           })
       .start();
 }
  public void clickDoor(RSTile location, char direction) {
    if (Bot.getClient().getCameraPitch() != 3072) {
      camera.setAltitude(true);
    }

    if (location.isOnScreen()) {
      RSObject door = objects.getTopAt(location);
      if (!door.action("Open")) {
        rotateCameraRandomly();
      } else {
        if (door.distanceTo() > 0) {
          player.waitToMove(3000);
        }

        player.waitForAnim(random(2500, 3000));
        waitToStop();
      }
    } else {
      walk.to(location);
    }
  }
Beispiel #8
0
 public void disableRendering(final boolean mode) {
   for (final Bot bot : bots) {
     bot.disableRendering = mode;
   }
 }
Beispiel #9
0
 void pauseScript(final Bot bot) {
   for (final Entry<Integer, LoopTask> script :
       bot.getScriptHandler().getRunningScripts().entrySet()) {
     bot.getScriptHandler().pauseScript(script.getKey());
   }
 }
  @Override
  public int loop() {
    if (!inventory.contains(foodID)) {
      needBank = true;
      atSpiders = false;
      if (changeRooms) {
        room = random(1, 3);
      }
    }
    if (eat()) {
      return random(100, 250);
    }
    if (dropRewards()) {
      return random(600, 700);
    }
    if (atSpiders) {
      if ((RSNPC) player.getMine().getInteracting() == null) {
        attackSpider();
      } else {
        if (!drinkPots()) {
          mouseAntiban();
          antiban();
        }
      }
      return random(100, 250);
    }
    loc = player.getMine().getLocation();
    if (loc != null) {
      base = Bot.getClient().getBaseY();
      if (needBank && teleport && base > 4000 && teleport()) {
        return random(5000, 6000);
      }
      if (needBank && inventory.contains(229) && base < 4000) {
        if (dropVial()) {
          return random(600, 700);
        }
      }
      if (base < 4000) {
        if (needBank) {
          if (calculate.distanceTo(bankTile) < 4) {
            int ct = 0;
            try {
              if (!bank.isOpen()) {
                if (bank.open()) {
                  wait(random(500, 800));
                }
                while (!bank.isOpen()) {
                  wait(180);
                  ct++;
                  if (ct > 30) {
                    tries++;
                  }
                }
              }
            } catch (final Exception e) {
            }
            if (bank.isOpen()) {
              if (tries != 0) {
                tries = 0;
              }
              if (teleport) {
                if (tabs) {
                  if (bank.getCount(8007) > 0 && !inventory.contains(8007)) {
                    bank.withdraw(8007, 1);
                    return random(800, 1000);
                  }
                } else {
                  if (!inventory.contains(563)
                      || inventory.getCount(556) < 3
                      || !inventory.contains(554)) {
                    if (!inventory.contains(563) && bank.getCount(563) > 0) {
                      bank.withdraw(563, 1);
                      return random(800, 1000);
                    }
                    if (!inventory.contains(554) && bank.getCount(554) > 0) {
                      bank.withdraw(554, 1);
                      return random(800, 1000);
                    }
                    if (inventory.getCount(556) < 3 && bank.getCount(556) >= 3) {
                      bank.withdraw(556, 3);
                      return random(800, 1000);
                    }
                  }
                }
              }
              if (pots) {
                if (potions[0] == 1
                    && bank.getCount(potionID[0]) > 0
                    && inventory.getCount(potionID[0]) < amounts[0]) {
                  withdrawPotion(potionID[0], amounts[0]);
                  return random(800, 1000);
                } else if (potions[1] == 1
                    && bank.getCount(potionID[1]) > 0
                    && inventory.getCount(potionID[1]) < amounts[1]) {
                  withdrawPotion(potionID[1], amounts[1]);
                  return random(800, 1000);
                } else if (potions[2] == 1
                    && bank.getCount(potionID[2]) > 0
                    && inventory.getCount(potionID[2]) < amounts[2]) {
                  withdrawPotion(potionID[2], amounts[2]);
                  return random(800, 1000);
                } else if (potions[3] == 1
                    && bank.getCount(potionID[3]) > 0
                    && inventory.getCount(potionID[3]) < amounts[3]) {
                  withdrawPotion(potionID[3], amounts[3]);
                  return random(800, 1000);
                }
              }
              if (inventory.contains(foodID)) {
                needBank = false;
              } else {
                if (bank.getCount(foodID) < 1) {
                  log("no food left, stopping script...");
                  stopScript();
                }
                bank.withdraw(foodID, 0);
                return random(800, 1000);
              }
            } else {
              if (tries > 3) {
                walk.to(bankTile);
                tries = 0;
              } else {
                try {
                  if (!bank.isOpen()) {
                    if (bank.open()) {
                      wait(random(500, 800));
                    }
                    while (!bank.isOpen()) {
                      wait(180);
                      ct++;
                      if (ct > 30) {
                        tries++;
                      }
                    }
                  }
                } catch (final Exception e) {
                }
                // clickObject((!edge ? 782 : 26972), "Use-quickly");

              }
            }
          } else {
            walk.pathMM((!edge ? bankingPath : edgeBankingPath));
          }
        } else {
          if (calculate.distanceTo(entranceTile) < 5) {
            clickObject(16154, "Climb-down");
          } else {
            walk.pathMM(walk.reversePath((!edge ? bankingPath : edgeBankingPath)));
          }
        }
      } else if (base >= 5192 && base < 5200 && floor1.contains(loc)) {
        if (!needBank) {
          clickObject(16150, "Enter");
        } else {
          clickObject(16148, "Climb-up");
        }
      } else if (base >= 5168 && base < 5192 && floor1Middle.contains(loc)) {
        clickObject(16149, "Climb-down");
      } else if (base >= 5192 && base < 5200 && floor2.contains(loc)) {
        if (!needBank) {
          clickObject(16082, "Enter");
        } else {
          clickObject(16080, "Climb-up");
        }
      } else if (base >= 5192 && base < 5200 && floor2Middle.contains(loc)) {
        clickObject(16081, "Climb-down");
      } else if (base >= 5200 && floor3.contains(loc)) {
        if (!needBank) {
          clickDoor(doors[0], 's');
        } else {
          clickObject(16114, "Climb-up");
        }
      } else if (base >= 5200 && floor3Front.contains(loc)) {
        if (!needBank) {
          clickDoor(doors[0], 's');
        } else {
          clickObject(16114, "Climb-up");
        }
      } else if (base >= 5200 && doors1.contains(loc)) {
        if (!needBank) {
          clickDoor(doors[1], 's');
        } else {
          clickDoor(doors[0], 's');
        }
      } else if (base >= 5200 && loc.getY() >= 5260 && loc.getY() <= 5278) {
        if (!needBank) {
          if (room == 1) {
            if (room1.contains(loc)) {
              atSpiders = true;
            } else {
              walk.to(room1.getRandomTile());
            }
          } else {
            clickDoor(doors[2], 'n');
          }
        } else {
          clickDoor(doors[1], 's');
        }
      } else if (base >= 5200 && doors2.contains(loc)) {
        if (!needBank && room == 2) {
          clickDoor(doors[3], 'n');
        } else {
          clickDoor(doors[2], 'n');
        }
      } else if (base >= 5200 && loc.getY() >= 5282 && loc.getY() <= 5295 && loc.getX() <= 2137) {
        if (!needBank && room == 2) {
          clickDoor(doors[4], 'w');
        } else {
          clickDoor(doors[3], 'n');
        }
      } else if (base >= 5200 && doors3.contains(loc)) {
        if (!needBank && room == 2) {
          clickDoor(doors[5], 'w');
        } else {
          clickDoor(doors[4], 'w');
        }
      } else if (base >= 5200 && loc.getY() >= 5294 && loc.getY() <= 5298 && loc.getX() >= 2141) {
        if (!needBank && room == 2) {
          clickDoor(doors[6], 's');
        } else {
          clickDoor(doors[5], 'w');
        }
      } else if (base >= 5200 && doors4.contains(loc)) {
        if (!needBank && room == 2) {
          clickDoor(doors[7], 's');
        } else {
          clickDoor(doors[6], 's');
        }
      } else if (base >= 5200 && loc.getY() >= 5302) {
        if (!needBank && room == 2) {
          walk.to(room2);
          atSpiders = true;
        } else {
          clickDoor(doors[7], 's');
        }
      }
    }
    return random(100, 250);
  }
Beispiel #11
0
 public void actionPerformed(final ActionEvent evt) {
   final String action = evt.getActionCommand();
   final String menu, option;
   final int z = action.indexOf('.');
   if (z == -1) {
     menu = action;
     option = "";
   } else {
     menu = action.substring(0, z);
     option = action.substring(z + 1);
   }
   if (menu.equals(Messages.CLOSEBOT)) {
     final int idx = Integer.parseInt(option);
     removeBot(bots.get(idx));
   } else if (menu.equals(Messages.FILE)) {
     if (option.equals(Messages.NEWBOT)) {
       addBot();
     } else if (option.equals(Messages.CLOSEBOT)) {
       removeBot(getCurrentBot());
     } else if (option.equals(Messages.ADDSCRIPT)) {
       final String pretext = "";
       final String key =
           (String)
               JOptionPane.showInputDialog(
                   this,
                   "Enter the script URL e.g. pastebin link or direct compiled file:",
                   option,
                   JOptionPane.QUESTION_MESSAGE,
                   null,
                   null,
                   pretext);
       if (!(key == null || key.trim().isEmpty())) {
         ScriptDownloader.save(key);
       }
     } else if (option.equals(Messages.RUNSCRIPT)) {
       final Bot current = getCurrentBot();
       if (current != null) {
         showScriptSelector(current);
       }
     } else if (option.equals(Messages.STOPSCRIPT)) {
       final Bot current = getCurrentBot();
       if (current != null) {
         showStopScript(current);
       }
     } else if (option.equals(Messages.PAUSESCRIPT)) {
       final Bot current = getCurrentBot();
       if (current != null) {
         pauseScript(current);
       }
     } else if (option.equals(Messages.SAVESCREENSHOT)) {
       final Bot current = getCurrentBot();
       if (current != null && current.getMethodContext() != null) {
         ScreenshotUtil.saveScreenshot(current, current.getMethodContext().game.isLoggedIn());
       }
     } else if (option.equals(Messages.HIDE)) {
       setTray();
     } else if (option.equals(Messages.EXIT)) {
       cleanExit();
     }
   } else if (menu.equals(Messages.EDIT)) {
     if (option.equals(Messages.ACCOUNTS)) {
       AccountManager.getInstance().showGUI();
     } else {
       final Bot current = getCurrentBot();
       if (current != null) {
         if (option.equals(Messages.FORCEINPUT)) {
           current.overrideInput = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
           updateScriptControls();
         } else if (option.equals(Messages.LESSCPU)) {
           current.disableRendering = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
         } else if (option.equals(Messages.DISABLECANVAS)) {
           current.disableGraphics = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
         } else if (option.equals(Messages.EXTDVIEWS)) {
           menuBar.setExtendedView(((JCheckBoxMenuItem) evt.getSource()).isSelected());
         } else if (option.equals(Messages.DISABLEANTIRANDOMS)) {
           current.disableRandoms = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
         } else if (option.equals(Messages.DISABLEAUTOLOGIN)) {
           current.disableAutoLogin = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
         } else if (option.equals(Messages.DISABLETHEME)) {
           Preferences.getInstance().theme = !((JCheckBoxMenuItem) evt.getSource()).isSelected();
           log.info(
               "Themes will be "
                   + (Preferences.getInstance().theme ? "enabled" : "disabled")
                   + " next time you run the application");
         } else if (option.equals(Messages.DISABLEADS)) {
           Preferences.getInstance().hideAds = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
         }
       }
     }
   } else if (menu.equals(Messages.VIEW)) {
     final Bot current = getCurrentBot();
     final boolean selected = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
     if (option.equals(Messages.HIDETOOLBAR)) {
       toggleViewState(toolBar, selected);
     } else if (option.equals(Messages.HIDELOGPANE)) {
       toggleViewState(textScroll, selected);
     } else if (current != null) {
       if (option.equals(Messages.ALLDEBUGGING)) {
         for (final String key : BotMenuBar.DEBUG_MAP.keySet()) {
           final Class<?> el = BotMenuBar.DEBUG_MAP.get(key);
           if (menuBar.getCheckBox(key).isVisible()) {
             final boolean wasSelected = menuBar.getCheckBox(key).isSelected();
             menuBar.getCheckBox(key).setSelected(selected);
             if (selected) {
               if (!wasSelected) {
                 current.addListener(el);
               }
             } else {
               if (wasSelected) {
                 current.removeListener(el);
               }
             }
           }
         }
       } else {
         final Class<?> el = BotMenuBar.DEBUG_MAP.get(option);
         menuBar.getCheckBox(option).setSelected(selected);
         if (selected) {
           current.addListener(el);
         } else {
           menuBar.getCheckBox(Messages.ALLDEBUGGING).setSelected(false);
           current.removeListener(el);
         }
       }
     }
   } else if (menu.equals(Messages.TOOLS)) {
     if (option.equals(Messages.LICENSES)) {
       log.warning("License manager coming soon");
     }
   } else if (menu.equals(Messages.HELP)) {
     if (option.equals(Messages.SITE)) {
       openURL(Configuration.Paths.URLs.SITE);
     } else if (option.equals(Messages.PROJECT)) {
       openURL(Configuration.Paths.URLs.PROJECT);
     } else if (option.equals(Messages.LICENSE)) {
       openURL(Configuration.Paths.URLs.LICENSE);
     } else if (option.equals(Messages.ABOUT)) {
       JOptionPane.showMessageDialog(
           this,
           new String[] {
             "An open source bot developed by the community.",
             "",
             "RuneScape® is a trademark of Jagex © 1999 - 2011 Jagex, Ltd.",
             "RuneScape content and materials are trademarks and copyrights of Jagex or its licensees.",
             "This program is issued with no warranty and is not affiliated with Jagex Ltd., nor do they endorse usage of our software.",
             "",
             "Visit " + Configuration.Paths.URLs.SITE + "/ for more information."
           },
           option,
           JOptionPane.INFORMATION_MESSAGE);
     }
   } else if (menu.equals("Tab")) {
     final Bot curr = getCurrentBot();
     menuBar.setBot(curr);
     panel.setBot(curr);
     panel.repaint();
     toolBar.setHome(curr == null);
     setTitle(curr == null ? null : curr.getAccountName());
     updateScriptControls();
   }
 }
Beispiel #12
0
 private Client getClient() {
   return Bot.getClient();
 }
Beispiel #13
0
 public TCamera(final Bot bot) {
   client = bot.getClient();
 }
Beispiel #14
0
 public TMenuActions(final Bot bot) {
   menu = bot.getMethodContext().menu;
 }
Beispiel #15
0
 public void disableGraphics(final boolean mode) {
   for (final Bot bot : bots) {
     bot.disableGraphics = mode;
   }
 }
Beispiel #16
0
 public void inputChanged(final Bot bot, final int mask) {
   bot.inputFlags = mask;
   updateScriptControls();
 }
 @Override
 public boolean onStart(Map<String, String> args) {
   if (!game.isLoggedIn()) {
     log("login before starting!");
     return false;
   }
   try {
     foodID = Integer.parseInt(args.get("food"));
     eatAt = new int[] {0, Integer.parseInt(args.get("eat1")), Integer.parseInt(args.get("eat2"))};
     eatAt[0] = random(eatAt[1], eatAt[2]);
   } catch (NumberFormatException e) {
     log("you didn't type valid number! (note: food ID must be number)");
     return false;
   }
   if (args.get("edge") != null && args.get("edge").equals("use")) {
     edge = true;
     bankTile = new RSTile(3094, 3491);
   }
   if (args.get("room") != null) {
     if (!args.get("room").equals("change randomly every run")) {
       changeRooms = false;
       if (args.get("room").equals("only fight in room 1")) {
         room = 1;
       } else {
         room = 2;
       }
     } else {
       changeRooms = true;
     }
   }
   if (args.get("teleport") != null
       && !args.get("teleport").equals("don't use")
       && skills.getRealLvl(Constants.STAT_MAGIC) >= 25
       && !edge) {
     if (args.get("teleport").equals("use varrock teletablets")) {
       tabs = true;
     }
     teleport = true;
   }
   if (args.get("str") != null && args.get("str").equals("use")) {
     potions[0] = 1;
     amounts[0] = Integer.parseInt(args.get("str_amount"));
     pots = true;
   }
   if (args.get("super_str") != null && args.get("super_str").equals("use")) {
     potions[1] = 1;
     amounts[1] = Integer.parseInt(args.get("super_str_amount"));
     pots = true;
   }
   if (args.get("super_att") != null && args.get("super_att").equals("use")) {
     potions[2] = 1;
     amounts[2] = Integer.parseInt(args.get("super_att_amount"));
     pots = true;
   }
   if (args.get("super_def") != null && args.get("super_def").equals("use")) {
     potions[3] = 1;
     amounts[3] = Integer.parseInt(args.get("super_def_amount"));
     pots = true;
   }
   stats =
       new int[][] {
         {skills.getRealLvl(Constants.STAT_ATTACK), skills.getCurrentXP(STAT_ATTACK)},
         {skills.getRealLvl(Constants.STAT_STRENGTH), skills.getCurrentXP(STAT_STRENGTH)},
         {skills.getRealLvl(Constants.STAT_DEFENSE), skills.getCurrentXP(Constants.STAT_DEFENSE)},
         {
           skills.getRealLvl(Constants.STAT_HITPOINTS),
           skills.getCurrentXP(Constants.STAT_HITPOINTS)
         }
       };
   if (settings.get(Constants.SETTING_AUTO_RETALIATE) == 1) {
     game.openTab(Constants.TAB_ATTACK);
     wait(random(800, 1000));
     if (!iface.clickChild(884, 18, "Auto")) {
       log("failed to turn auto retaliate on");
       return false;
     }
   }
   if (Bot.getClient().getCameraPitch() != 3072) {
     camera.setAltitude(true);
   }
   startTime = System.currentTimeMillis();
   antiban = startTime;
   mouseAntiban = antiban;
   allowPaint = true;
   return true;
 }