Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.02 KB | None | 0 0
  1. package org.rsbot.script.randoms;
  2.  
  3. import java.awt.Rectangle;
  4.  
  5. import org.rsbot.gui.AccountManager;
  6. import org.rsbot.script.Random;
  7. import org.rsbot.script.ScriptManifest;
  8. import org.rsbot.script.wrappers.RSComponent;
  9. import org.rsbot.script.wrappers.RSInterface;
  10.  
  11. /**
  12. * @author Iscream
  13. */
  14. @ScriptManifest(authors = { "Iscream", "Pervy Shuya" }, name = "Login", version = 1.5)
  15. public class LoginBot extends Random {
  16.  
  17. private static final int INTERFACE_MAIN = 905;
  18. private static final int INTERFACE_MAIN_CHILD = 59;
  19. private static final int INTERFACE_MAIN_CHILD_COMPONENT_ID = 4;
  20. private static final int INTERFACE_LOGIN_SCREEN = 596;
  21. private static final int INTERFACE_USERNAME = 65;
  22. private static final int INTERFACE_USERNAME_WINDOW = 37;
  23. private static final int INTERFACE_PASSWORD = 71;
  24. private static final int INTERFACE_PASSWORD_WINDOW = 39;
  25. private static final int INTERFACE_BUTTON_LOGIN = 42;
  26. private static final int INTERFACE_TEXT_RETURN = 11;
  27. private static final int INTERFACE_BUTTON_BACK = 55;
  28. private static final int INTERFACE_WELCOME_SCREEN = 906;
  29. private static final int INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_1 = 160;
  30. private static final int INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_2 = 171;
  31. private static final int INTERFACE_WELCOME_SCREEN_BUTTON_LOGOUT = 193;
  32. private static final int INTERFACE_WELCOME_SCREEN_TEXT_RETURN = 221;
  33. private static final int INTERFACE_WELCOME_SCREEN_BUTTON_BACK = 228;
  34. private static final int INTERFACE_WELCOME_SCREEN_HIGH_RISK_WORLD_TEXT = 86;
  35. private static final int INTERFACE_WELCOME_SCREEN_HIGH_RISK_WORLD_LOGIN_BUTTON = 93;
  36. private static final int INTERFACE_GRAPHICS_NOTICE = 976;
  37. private static final int INTERFACE_GRAPHICS_LEAVE_ALONE = 6;
  38.  
  39. private static final int INDEX_LOGGED_OUT = 3;
  40. private static final int INDEX_LOBBY = 7;
  41.  
  42. private int notLoggedOffCount, invalidCount, worldFullCount;
  43.  
  44. @Override
  45. public boolean activateCondition() {
  46. int idx = game.getClientState();
  47. return (idx == INDEX_LOGGED_OUT || idx == INDEX_LOBBY)
  48. && account.getName() != null;
  49. }
  50.  
  51. @Override
  52. public int loop() {
  53. String username = account.getName().toLowerCase().trim();
  54. String returnText = interfaces.get(INTERFACE_LOGIN_SCREEN)
  55. .getComponent(INTERFACE_TEXT_RETURN).getText().toLowerCase();
  56. int textlength;
  57. if (game.getClientState() != INDEX_LOGGED_OUT) {
  58. if (!game.isWelcomeScreen()) {
  59. sleep(random(1000, 2000));
  60. }
  61. if (game.getClientState() == INDEX_LOBBY) {
  62. RSInterface welcome_screen = interfaces
  63. .get(INTERFACE_WELCOME_SCREEN);
  64. RSComponent welcome_screen_button_play_1 = welcome_screen
  65. .getComponent(INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_1);
  66. RSComponent welcome_screen_button_play_2 = welcome_screen
  67. .getComponent(INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_2);
  68.  
  69. mouse.click(welcome_screen_button_play_1.getAbsoluteX(),
  70. welcome_screen_button_play_1.getAbsoluteY(),
  71. welcome_screen_button_play_2.getAbsoluteX()
  72. welcome_screen_button_play_2.getWidth()
  73. - welcome_screen_button_play_1.getAbsoluteX(),
  74. welcome_screen_button_play_1.getHeight(), true);
  75.  
  76. for (int i = 0; i < 4 && game.getClientState() == 6; i ) {
  77. sleep(500);
  78. }
  79. returnText = interfaces.get(INTERFACE_WELCOME_SCREEN)
  80. .getComponent(INTERFACE_WELCOME_SCREEN_TEXT_RETURN)
  81. .getText().toLowerCase();
  82.  
  83. if (returnText.contains("total skill level of")) {
  84. log("Log back in when you total level of 1000/1500 ");
  85. interfaces.getComponent(INTERFACE_WELCOME_SCREEN,
  86. INTERFACE_WELCOME_SCREEN_BUTTON_BACK).doClick();
  87. stopScript(false);
  88. }
  89.  
  90. if (returnText.contains("login limit exceeded")) {
  91. log("If login limit screws up, tell Pervy.");
  92. if (interfaces.getComponent(INTERFACE_WELCOME_SCREEN,
  93. INTERFACE_WELCOME_SCREEN_BUTTON_BACK).doClick())
  94. interfaces.getComponent(INTERFACE_WELCOME_SCREEN,
  95. INTERFACE_WELCOME_SCREEN_BUTTON_LOGOUT)
  96. .doClick();
  97. }
  98.  
  99. if (returnText.contains("member")) {
  100. log("Unable to login to a members world. Stopping script.");
  101. RSComponent back_button1 = interfaces.get(
  102. INTERFACE_WELCOME_SCREEN).getComponent(228);
  103. RSComponent back_button2 = interfaces.get(
  104. INTERFACE_WELCOME_SCREEN).getComponent(231);
  105. mouse.click(
  106. back_button1.getAbsoluteX(),
  107. back_button1.getAbsoluteY(),
  108. back_button2.getAbsoluteX()
  109. back_button2.getWidth()
  110. - back_button1.getAbsoluteX(),
  111. back_button1.getHeight(), true);
  112. interfaces.get(INTERFACE_WELCOME_SCREEN).getComponent(203)
  113. .doClick();
  114. stopScript(false);
  115. }
  116.  
  117. if (interfaces
  118. .get(INTERFACE_WELCOME_SCREEN)
  119. .getComponent(
  120. INTERFACE_WELCOME_SCREEN_HIGH_RISK_WORLD_TEXT)
  121. .getText().toLowerCase().trim()
  122. .contains("high-risk wilderness world")) {
  123. interfaces
  124. .get(INTERFACE_WELCOME_SCREEN)
  125. .getComponent(
  126. INTERFACE_WELCOME_SCREEN_HIGH_RISK_WORLD_LOGIN_BUTTON)
  127. .doClick();
  128. }
  129. }
  130. return -1;
  131. }
  132. if (!game.isLoggedIn()) {
  133. if (returnText.contains("update")) {
  134. log("Runescape has been updated, please reload RSBot.");
  135. stopScript(false);
  136. }
  137. if (returnText.contains("disable")) {
  138. log.severe("Your account is banned/disabled.");
  139. stopScript(false);
  140. }
  141. if (returnText.contains("your account has not logged out")) {
  142. if (notLoggedOffCount > 3) {
  143. log.warning("Account not logged out after 3 attempts. Stopping script.");
  144. log("Make sure you're logged off or hasn't been h@x0r3d.");
  145. stopScript(false);
  146. }
  147. interfaces.get(INTERFACE_LOGIN_SCREEN)
  148. .getComponent(60).doClick();
  149. notLoggedOffCount ;
  150. return random(3000, 7000);
  151. }
  152. if (returnText.contains("incorrect")) {
  153. log.warning("Failed to login five times in a row. Stopping script.");
  154. stopScript(false);
  155. }
  156. if (returnText.contains("invalid")) {
  157. if (invalidCount > 6) {
  158. log.warning("Unable to login after 6 attempts. Stopping script.");
  159. log("Please verify that your RSBot account profile is correct.");
  160. stopScript(false);
  161. }
  162. interfaces.get(INTERFACE_LOGIN_SCREEN)
  163. .getComponent(INTERFACE_BUTTON_BACK).doClick();
  164. invalidCount ;
  165. return random(500, 2000);
  166. }
  167. if (returnText.contains("error connecting")) {
  168. interfaces.get(INTERFACE_LOGIN_SCREEN)
  169. .getComponent(INTERFACE_BUTTON_BACK).doClick();
  170. stopScript(false);
  171. return random(500, 2000);
  172. }
  173. if (returnText.contains("full")) {
  174. if (worldFullCount > 30) {
  175. log("World Is Full. Waiting for 15 seconds.");
  176. sleep(random(10000, 15000));
  177. worldFullCount = 0;
  178. }
  179. sleep(random(1000, 1200));
  180. worldFullCount ;
  181. }
  182. if (returnText.contains("world")) {
  183. return random(1500, 2000);
  184. }
  185. if (returnText.contains("performing login")) {
  186. return random(1500, 2000);
  187. }
  188. }
  189. if (game.getClientState() == INDEX_LOGGED_OUT) {
  190. if (interfaces.getComponent(INTERFACE_GRAPHICS_NOTICE,
  191. INTERFACE_GRAPHICS_LEAVE_ALONE).isValid()) {
  192. interfaces.getComponent(INTERFACE_GRAPHICS_NOTICE,
  193. INTERFACE_GRAPHICS_LEAVE_ALONE).doClick();
  194. return random(500, 600);
  195. }
  196. if (!atLoginScreen()) {
  197. interfaces.getComponent(INTERFACE_MAIN, INTERFACE_MAIN_CHILD)
  198. .getComponent(INTERFACE_MAIN_CHILD_COMPONENT_ID)
  199. .doAction("");
  200. return random(500, 600);
  201. }
  202. if (isUsernameFilled() && isPasswordFilled()) {
  203. interfaces.get(INTERFACE_LOGIN_SCREEN)
  204. .getComponent(INTERFACE_BUTTON_LOGIN).doClick();
  205. return random(500, 600);
  206. }
  207. if (!isUsernameFilled()) {
  208. atLoginInterface(interfaces.get(INTERFACE_LOGIN_SCREEN)
  209. .getComponent(INTERFACE_USERNAME_WINDOW));
  210. sleep(random(500, 700));
  211. textlength = interfaces.get(INTERFACE_LOGIN_SCREEN)
  212. .getComponent(INTERFACE_USERNAME).getText().length()
  213. random(3, 5);
  214. for (int i = 0; i <= textlength random(1, 5); i ) {
  215. keyboard.sendText("\b", false);
  216. if (random(0, 2) == 1) {
  217. sleep(random(25, 100));
  218. }
  219. }
  220. keyboard.sendText(username, false);
  221. return random(500, 600);
  222. }
  223. if (isUsernameFilled() && !isPasswordFilled()) {
  224. atLoginInterface(interfaces.get(INTERFACE_LOGIN_SCREEN)
  225. .getComponent(INTERFACE_PASSWORD_WINDOW));
  226. sleep(random(500, 700));
  227. textlength = interfaces.get(INTERFACE_LOGIN_SCREEN)
  228. .getComponent(INTERFACE_PASSWORD).getText().length()
  229. random(3, 5);
  230. for (int i = 0; i <= textlength random(1, 5); i ) {
  231. keyboard.sendText("\b", false);
  232. if (random(0, 2) == 1) {
  233. sleep(random(25, 100));
  234. }
  235. }
  236. keyboard.sendText(AccountManager.getPassword(account.getName(),
  237. getClass()), false);
  238. }
  239. }
  240. return random(500, 2000);
  241. }
  242.  
  243. // Clicks past all of the letters
  244. private boolean atLoginInterface(RSComponent i) {
  245. if (!i.isValid())
  246. return false;
  247. Rectangle pos = i.getArea();
  248. if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1)
  249. return false;
  250. int dy = (int) (pos.getHeight() - 4) / 2;
  251. int maxRandomX = (int) (pos.getMaxX() - pos.getCenterX());
  252. int midx = (int) (pos.getCenterX());
  253. int midy = (int) (pos.getMinY() pos.getHeight() / 2);
  254. if (i.getIndex() == INTERFACE_PASSWORD_WINDOW) {
  255. mouse.click(minX(i), midy random(-dy, dy), true);
  256. } else {
  257. mouse.click(midx random(1, maxRandomX), midy random(-dy, dy),
  258. true);
  259. }
  260. return true;
  261. }
  262.  
  263. /*
  264. * Returns x int based on the letters in a Child Only the password text is
  265. * needed as the username text cannot reach past the middle of the interface
  266. */
  267. private int minX(RSComponent a) {
  268. int x = 0;
  269. Rectangle pos = a.getArea();
  270. int dx = (int) (pos.getWidth() - 4) / 2;
  271. 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. for (int i = 0; i < interfaces.get(INTERFACE_LOGIN_SCREEN)
  275. .getComponent(INTERFACE_PASSWORD).getText().length(); i ) {
  276. x = 11;
  277. }
  278. if (x > 44) {
  279. return (int) (pos.getMinX() x 15);
  280. } else {
  281. return midx random(-dx, dx);
  282. }
  283. }
  284.  
  285. private boolean atLoginScreen() {
  286. return interfaces.get(596).isValid();
  287. }
  288.  
  289. private boolean isUsernameFilled() {
  290. String username = account.getName().toLowerCase().trim();
  291. return interfaces.get(INTERFACE_LOGIN_SCREEN)
  292. .getComponent(INTERFACE_USERNAME).getText().toLowerCase()
  293. .equalsIgnoreCase(username);
  294. }
  295.  
  296. private boolean isPasswordFilled() {
  297. String passWord = AccountManager.getPassword(account.getName(),
  298. getClass());
  299. return interfaces.get(INTERFACE_LOGIN_SCREEN)
  300. .getComponent(INTERFACE_PASSWORD).getText().toLowerCase()
  301. .length() == (passWord == null ? 0 : passWord.length());
  302. }
  303. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement