Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.04 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. //Suggested edit
  143. if (notLoggedOffCount > 3) {
  144. log.warning("Account not logged out after 3 attempts. Stopping script.");
  145. log("Make sure you're logged off or hasn't been h@x0r3d.");
  146. stopScript(false);
  147. }
  148. interfaces.get(INTERFACE_LOGIN_SCREEN)
  149. .getComponent(60).doClick();
  150. notLoggedOffCount ;
  151. return random(3000, 7000);
  152. }
  153. if (returnText.contains("incorrect")) {
  154. log.warning("Failed to login five times in a row. Stopping script.");
  155. stopScript(false);
  156. }
  157. if (returnText.contains("invalid")) {
  158. if (invalidCount > 6) {
  159. log.warning("Unable to login after 6 attempts. Stopping script.");
  160. log("Please verify that your RSBot account profile is correct.");
  161. stopScript(false);
  162. }
  163. interfaces.get(INTERFACE_LOGIN_SCREEN)
  164. .getComponent(INTERFACE_BUTTON_BACK).doClick();
  165. invalidCount ;
  166. return random(500, 2000);
  167. }
  168. if (returnText.contains("error connecting")) {
  169. interfaces.get(INTERFACE_LOGIN_SCREEN)
  170. .getComponent(INTERFACE_BUTTON_BACK).doClick();
  171. stopScript(false);
  172. return random(500, 2000);
  173. }
  174. if (returnText.contains("full")) {
  175. if (worldFullCount > 30) {
  176. log("World Is Full. Waiting for 15 seconds.");
  177. sleep(random(10000, 15000));
  178. worldFullCount = 0;
  179. }
  180. sleep(random(1000, 1200));
  181. worldFullCount ;
  182. }
  183. if (returnText.contains("world")) {
  184. return random(1500, 2000);
  185. }
  186. if (returnText.contains("performing login")) {
  187. return random(1500, 2000);
  188. }
  189. }
  190. if (game.getClientState() == INDEX_LOGGED_OUT) {
  191. if (interfaces.getComponent(INTERFACE_GRAPHICS_NOTICE,
  192. INTERFACE_GRAPHICS_LEAVE_ALONE).isValid()) {
  193. interfaces.getComponent(INTERFACE_GRAPHICS_NOTICE,
  194. INTERFACE_GRAPHICS_LEAVE_ALONE).doClick();
  195. return random(500, 600);
  196. }
  197. if (!atLoginScreen()) {
  198. interfaces.getComponent(INTERFACE_MAIN, INTERFACE_MAIN_CHILD)
  199. .getComponent(INTERFACE_MAIN_CHILD_COMPONENT_ID)
  200. .doAction("");
  201. return random(500, 600);
  202. }
  203. if (isUsernameFilled() && isPasswordFilled()) {
  204. interfaces.get(INTERFACE_LOGIN_SCREEN)
  205. .getComponent(INTERFACE_BUTTON_LOGIN).doClick();
  206. return random(500, 600);
  207. }
  208. if (!isUsernameFilled()) {
  209. atLoginInterface(interfaces.get(INTERFACE_LOGIN_SCREEN)
  210. .getComponent(INTERFACE_USERNAME_WINDOW));
  211. sleep(random(500, 700));
  212. textlength = interfaces.get(INTERFACE_LOGIN_SCREEN)
  213. .getComponent(INTERFACE_USERNAME).getText().length()
  214. random(3, 5);
  215. for (int i = 0; i <= textlength random(1, 5); i ) {
  216. keyboard.sendText("\b", false);
  217. if (random(0, 2) == 1) {
  218. sleep(random(25, 100));
  219. }
  220. }
  221. keyboard.sendText(username, false);
  222. return random(500, 600);
  223. }
  224. if (isUsernameFilled() && !isPasswordFilled()) {
  225. atLoginInterface(interfaces.get(INTERFACE_LOGIN_SCREEN)
  226. .getComponent(INTERFACE_PASSWORD_WINDOW));
  227. sleep(random(500, 700));
  228. textlength = interfaces.get(INTERFACE_LOGIN_SCREEN)
  229. .getComponent(INTERFACE_PASSWORD).getText().length()
  230. random(3, 5);
  231. for (int i = 0; i <= textlength random(1, 5); i ) {
  232. keyboard.sendText("\b", false);
  233. if (random(0, 2) == 1) {
  234. sleep(random(25, 100));
  235. }
  236. }
  237. keyboard.sendText(AccountManager.getPassword(account.getName(),
  238. getClass()), false);
  239. }
  240. }
  241. return random(500, 2000);
  242. }
  243.  
  244. // Clicks past all of the letters
  245. private boolean atLoginInterface(RSComponent i) {
  246. if (!i.isValid())
  247. return false;
  248. Rectangle pos = i.getArea();
  249. if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1)
  250. return false;
  251. int dy = (int) (pos.getHeight() - 4) / 2;
  252. int maxRandomX = (int) (pos.getMaxX() - pos.getCenterX());
  253. int midx = (int) (pos.getCenterX());
  254. int midy = (int) (pos.getMinY() pos.getHeight() / 2);
  255. if (i.getIndex() == INTERFACE_PASSWORD_WINDOW) {
  256. mouse.click(minX(i), midy random(-dy, dy), true);
  257. } else {
  258. mouse.click(midx random(1, maxRandomX), midy random(-dy, dy),
  259. true);
  260. }
  261. return true;
  262. }
  263.  
  264. /*
  265. * Returns x int based on the letters in a Child Only the password text is
  266. * needed as the username text cannot reach past the middle of the interface
  267. */
  268. private int minX(RSComponent a) {
  269. int x = 0;
  270. Rectangle pos = a.getArea();
  271. int dx = (int) (pos.getWidth() - 4) / 2;
  272. int midx = (int) (pos.getMinX() pos.getWidth() / 2);
  273. if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1)
  274. return 0;
  275. for (int i = 0; i < interfaces.get(INTERFACE_LOGIN_SCREEN)
  276. .getComponent(INTERFACE_PASSWORD).getText().length(); i ) {
  277. x = 11;
  278. }
  279. if (x > 44) {
  280. return (int) (pos.getMinX() x 15);
  281. } else {
  282. return midx random(-dx, dx);
  283. }
  284. }
  285.  
  286. private boolean atLoginScreen() {
  287. return interfaces.get(596).isValid();
  288. }
  289.  
  290. private boolean isUsernameFilled() {
  291. String username = account.getName().toLowerCase().trim();
  292. return interfaces.get(INTERFACE_LOGIN_SCREEN)
  293. .getComponent(INTERFACE_USERNAME).getText().toLowerCase()
  294. .equalsIgnoreCase(username);
  295. }
  296.  
  297. private boolean isPasswordFilled() {
  298. String passWord = AccountManager.getPassword(account.getName(),
  299. getClass());
  300. return interfaces.get(INTERFACE_LOGIN_SCREEN)
  301. .getComponent(INTERFACE_PASSWORD).getText().toLowerCase()
  302. .length() == (passWord == null ? 0 : passWord.length());
  303. }
  304. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement