Guest User

Untitled

a guest
Nov 24th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.12 KB | None | 0 0
  1.  
  2. package org.rsbot.script.randoms;
  3.  
  4. import org.rsbot.Configuration;
  5. import org.rsbot.gui.AccountManager;
  6. import org.rsbot.script.Random;
  7. import org.rsbot.script.ScriptManifest;
  8. import org.rsbot.script.methods.Environment;
  9. import org.rsbot.script.methods.Game;
  10. import org.rsbot.script.methods.Lobby;
  11. import org.rsbot.script.wrappers.RSComponent;
  12.  
  13. import java.awt.*;
  14.  
  15. import static org.rsbot.script.methods.Environment.LOGIN_GAME;
  16. import static org.rsbot.script.methods.Environment.LOGIN_LOBBY;
  17.  
  18. /**
  19. * A simple script to login to the game.
  20. *
  21. * @author Timer
  22. */
  23. @ScriptManifest(authors = {"Timer"}, name = "Improved Login", version = 0.1)
  24. public class ImprovedLoginBot extends Random {
  25. public static final int INTERFACE_LOGIN_SCREEN = 596;
  26. public static final int INTERFACE_LOGIN_SCREEN_ENTER_GAME = 60;
  27. public static final int INTERFACE_LOGIN_SCREEN_USERNAME_TEXT = 73;
  28. public static final int INTERFACE_LOGIN_SCREEN_PASSWORD_TEXT = 79;
  29. public static final int INTERFACE_LOGIN_SCREEN_ALERT_TEXT = 14;
  30. public static final int INTERFACE_LOGIN_SCREEN_ALERT_BACK = 68;
  31. public static final int INTERFACE_GRAPHICS_NOTICE = 976;
  32. public static final int INTERFACE_GRAPHICS_LEAVE_ALONE = 6;
  33. public static final int INTERFACE_LOBBY_HIGH_RISK_WORLD_TEXT = 98;
  34. public static final int INTERFACE_LOBBY_HIGH_RISK_WORLD_LOGIN_BUTTON = 104;
  35. private int world = -1;
  36. private String cachePassword = "";
  37. private int stageFlags = LOGIN_LOBBY | LOGIN_GAME;
  38. private final solution[] loginSolutions = {new solution() {
  39. private int invalidCount = 0;
  40.  
  41. public boolean canApply(String message) {
  42. return message.contains("no reply from login server");
  43. }
  44.  
  45. public int apply() {
  46. if (invalidCount > 10) {
  47. log.severe("It seems the login server is down.");
  48. stopScript(false);
  49. }
  50. invalidCount++;
  51. return random(500, 2000);
  52. }
  53. }, new solution() {
  54. public boolean canApply(String message) {
  55. return message.contains("update");
  56. }
  57.  
  58. public int apply() {
  59. log("The game has been updated, please reload " + Configuration.NAME);
  60. stopScript(false);
  61. return 0;
  62. }
  63. }, new solution() {
  64. public boolean canApply(String message) {
  65. return message.contains("disable");
  66. }
  67.  
  68. public int apply() {
  69. log.severe("It seems that your account has been disabled, that's unfortunate.");
  70. stopScript(false);
  71. return 0;
  72. }
  73. }, new solution() {
  74. private int invalidCount = 0;
  75.  
  76. public boolean canApply(String message) {
  77. return message.contains("your account has not logged out");
  78. }
  79.  
  80. public int apply() {
  81. if (invalidCount > 10) {
  82. log.severe("Your account is already logged in, change your password!");
  83. stopScript(false);
  84. }
  85. invalidCount++;
  86. log.warning("Waiting for logout..");
  87. return random(5000, 15000);
  88. }
  89. }, new solution() {
  90. private int fails = 0;
  91.  
  92. public boolean canApply(String message) {
  93. return message.contains("invalid") || message.contains("incorrect");
  94. }
  95.  
  96. public int apply() {
  97. fails++;
  98. if (fails > 3) {
  99. stopScript(false);
  100. return 0;
  101. }
  102. log.info("Login information incorrect, attempting again.");
  103. return random(1200, 3000);
  104. }
  105. }, new solution() {
  106. public boolean canApply(String message) {
  107. return message.contains("error connecting");
  108. }
  109.  
  110. public int apply() {
  111. log.severe("No internet connection.");
  112. stopScript(false);
  113. return 0;
  114. }
  115. }, new solution() {
  116. private int invalidCount = 0;
  117.  
  118. public boolean canApply(String message) {
  119. return message.contains("login limit exceeded");
  120. }
  121.  
  122. public int apply() {
  123. if (invalidCount > 10) {
  124. log.warning("Unable to login after 10 attempts. Stopping script.");
  125. log.severe("It seems you are actually already logged in?");
  126. stopScript(false);
  127. }
  128. invalidCount++;
  129. return random(5000, 15000);
  130. }
  131. }, new solution() {
  132. public boolean canApply(String message) {
  133. return message.contains("world") || message.contains("performing login");
  134. }
  135.  
  136. public int apply() {
  137. return random(4000, 5000);
  138. }
  139. }};
  140. private final solution[] lobbySolutions = {new solution() {
  141. public boolean canApply(String message) {
  142. return message.contains("total skill level of");
  143. }
  144.  
  145. public int apply() {
  146. log.severe("Your combat level does not meet this world's requirements, run a skilling bot!");
  147. stopScript(true);
  148. return 0;
  149. }
  150. }, new solution() {
  151. public boolean canApply(String message) {
  152. return message.contains("login limit exceeded");
  153. }
  154.  
  155. public int apply() {
  156. return random(3000, 8000);
  157. }
  158. }, new solution() {
  159. private int invalidCount = 0;
  160.  
  161. public boolean canApply(String message) {
  162. return message.contains("your account has not logged out");
  163. }
  164.  
  165. public int apply() {
  166. if (invalidCount > 10) {
  167. log.severe("You're already logged in! Change your password!");
  168. stopScript(false);
  169. }
  170. invalidCount++;
  171. log.warning("Waiting for logout..");
  172. return random(5000, 15000);
  173. }
  174. }, new solution() {
  175. public boolean canApply(String message) {
  176. return message.contains("member");
  177. }
  178.  
  179. public int apply() {
  180. log.severe("Please run on a non-members world.");
  181. stopScript(false);
  182. return 0;
  183. }
  184. }, new solution() {
  185. public boolean canApply(String message) {
  186. return interfaces.getComponent(Lobby.INTERFACE_LOBBY, INTERFACE_LOBBY_HIGH_RISK_WORLD_TEXT).getText().toLowerCase().trim().c ontains("high-risk wilderness world");
  187. }
  188.  
  189. public int apply() {
  190. interfaces.getComponent(Lobby.INTERFACE_LOBBY, INTERFACE_LOBBY_HIGH_RISK_WORLD_LOGIN_BUTTON).doClick();
  191. return 500;
  192. }
  193. }};
  194.  
  195. private interface solution {
  196. boolean canApply(final String message);
  197.  
  198. int apply();
  199. }
  200.  
  201. @Override
  202. public boolean activateCondition() {
  203. final int idx = game.getClientState();
  204. return (((idx == Game.INDEX_LOGIN_SCREEN && (stageFlags & Environment.LOGIN_LOBBY) != 0) ||
  205. (idx == Game.INDEX_LOBBY_SCREEN && (stageFlags & Environment.LOGIN_GAME) != 0)) &&
  206. !switchingWorlds() && account.getName() != null) || (idx == Game.INDEX_LOBBY_SCREEN && (cachePassword.isEmpty() || cachePassword == null));
  207. }
  208.  
  209. @Override
  210. public int loop() {
  211. if (lobby.inLobby() && (stageFlags & Environment.LOGIN_GAME) != 0) {
  212. if (lobby.getSelectedTab() != Lobby.TAB_PLAYERS) {
  213. lobby.open(Lobby.TAB_PLAYERS);
  214. return random(500, 800);
  215. }
  216. if (world != -1 && lobby.getSelectedWorld() != world) {
  217. lobby.switchWorlds(world, false);
  218. return random(500, 800);
  219. }
  220. if (lobby.clickPlay()) {
  221. for (int i = 0; i <4> 0) {
  222. for (int i = 0; i <textLength> 0) {
  223. for (int i = 0; i <= textLength + random(1, 5); i++) {
  224. keyboard.sendText("\b", false);
  225. if (random(0, 2) == 1) {
  226. sleep(random(25, 100));
  227. }
  228. }
  229. return random(500, 600);
  230. }
  231. String passWord = AccountManager.getPassword(account.getName());
  232. keyboard.sendText(passWord, false);
  233. return random(500, 600);
  234. }
  235. }
  236. final int idx = game.getClientState();
  237. return ((idx == Game.INDEX_LOGIN_SCREEN && (stageFlags & Environment.LOGIN_LOBBY) == 0) ||
  238. (idx == Game.INDEX_LOBBY_SCREEN && (stageFlags & Environment.LOGIN_GAME) == 0) ||
  239. (game.isLoggedIn())) ? -1 : random(100, 500);
  240. }
  241.  
  242. private boolean switchingWorlds() {
  243. return interfaces.getComponent(Lobby.INTERFACE_LOBBY, Lobby.INTERFACE_LOBBY_ALERT_TEXT).isValid() &&
  244. interfaces.getComponent(Lobby.INTERFACE_LOBBY, Lobby.INTERFACE_LOBBY_ALERT_TEXT).containsText("just left another world");
  245. }
  246.  
  247. private boolean atLoginInterface(final RSComponent i) {
  248. if (!i.isValid()) {
  249. return false;
  250. }
  251. final Rectangle pos = i.getArea();
  252. if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1) {
  253. return false;
  254. }
  255. final int dy = (int) (pos.getHeight() - 4) / 2;
  256. final int maxRandomX = (int) (pos.getMaxX() - pos.getCenterX());
  257. final int midx = (int) pos.getCenterX();
  258. final int midy = (int) (pos.getMinY() + pos.getHeight() / 2);
  259. if (i.getIndex() == INTERFACE_LOGIN_SCREEN_PASSWORD_TEXT) {
  260. mouse.click(minX(i), midy + random(-dy, dy), true);
  261. } else {
  262. mouse.click(midx + random(1, maxRandomX), midy + random(-dy, dy), true);
  263. }
  264. return true;
  265. }
  266.  
  267. private int minX(final RSComponent a) {
  268. int x = 0;
  269. final Rectangle pos = a.getArea();
  270. final int dx = (int) (pos.getWidth() - 4) / 2;
  271. final int midx = (int) (pos.getMinX() + pos.getWidth() / 2);
  272. if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1) {
  273. return 0;
  274. }
  275. for (int i = 0; i <interfaces> 44) {
  276. return (int) (pos.getMinX() + x + 15);
  277. } else {
  278. return midx + random(-dx, dx);
  279. }
  280. }
  281.  
  282. private void attemptLogin() {
  283. if (random(0, 2) == 0) {
  284. keyboard.sendKey('\n');
  285. } else {
  286. interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_ENTER_GAME).doClick();
  287. }
  288. }
  289.  
  290. private boolean isUsernameCorrect() {
  291. final String userName = account.getName().toLowerCase().trim();
  292. return interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_USERNAME_TEXT).getText().toLowerCase().equalsIgnoreCase(userName);
  293. }
  294.  
  295. private boolean isPasswordValid() {
  296. String passWord = AccountManager.getPassword(account.getName());
  297. if (passWord.isEmpty()) {
  298. passWord = cachePassword;
  299. }
  300. return interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_PASSWORD_TEXT).getText().length() == (passWord == null ? 0 : passWord.length());
  301. }
  302.  
  303. /**
  304. * Sets the world to login to.
  305. *
  306. * @param world The world.
  307. */
  308. public void setWorld(final int world) {
  309. this.world = world;
  310. }
  311.  
  312. /**
  313. * Gets the current set world.
  314. *
  315. * @return The world currently designated to login to.
  316. */
  317. public int getWorld() {
  318. return this.world;
  319. }
  320.  
  321. /**
  322. * Sets login mask.
  323. */
  324. public void setMask(final int mask) {
  325. this.stageFlags = mask;
  326. }
  327.  
  328. /**
  329. * The current login mask.
  330. *
  331. * @return The bytes of the mask.
  332. */
  333. public int getMask() {
  334. return this.stageFlags;
  335. }
  336. }
Add Comment
Please, Sign In to add comment