Advertisement
Guest User

Untitled

a guest
Jul 1st, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.23 KB | None | 0 0
  1. package org.rsbot.script.randoms;
  2.  
  3. import org.rsbot.script.Random;
  4. import org.rsbot.script.ScriptManifest;
  5. import org.rsbot.script.wrappers.RSInterface;
  6. import org.rsbot.script.wrappers.RSComponent;
  7.  
  8. import java.awt.*;
  9.  
  10. /**
  11. * @author Iscream
  12. */
  13. @ScriptManifest(authors = {"Iscream","Kahzel"}, name = "Login", version = 1.21)
  14. public class LoginBot extends Random {
  15.  
  16. private static final int INTERFACE_MAIN = 905;
  17. private static final int INTERFACE_MAIN_CHILD = 59;
  18. private static final int INTERFACE_MAIN_CHILD_COMPONENT_ID = 4;
  19. private static final int INTERFACE_LOGIN_SCREEN = 596;
  20. private static final int INTERFACE_USERNAME = 65;
  21. private static final int INTERFACE_USERNAME_WINDOW = 37;
  22. private static final int INTERFACE_PASSWORD = 71;
  23. private static final int INTERFACE_PASSWORD_WINDOW = 39;
  24. private static final int INTERFACE_BUTTON_LOGIN = 42;
  25. private static final int INTERFACE_TEXT_RETURN = 11;
  26. private static final int INTERFACE_BUTTON_BACK = 60;
  27. private static final int INTERFACE_WELCOME_SCREEN = 906;
  28. private static final int INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_1 = 145;
  29. private static final int INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_2 = 155;
  30. private static final int INTERFACE_WELCOME_SCREEN_TEXT_RETURN = 221;
  31.  
  32. private static final int INDEX_LOGGED_OUT = 3;
  33. private static final int INDEX_LOBBY = 7;
  34.  
  35. private int invalidCount, worldFullCount;
  36.  
  37. public boolean activateCondition() {
  38. int idx = game.getClientState();
  39. return (idx == INDEX_LOGGED_OUT || idx == INDEX_LOBBY) && account.getName() != null;
  40. }
  41.  
  42. public int loop() {
  43. String username = account.getName().replaceAll("_", " ").toLowerCase().trim();
  44. String returnText = interfaces.get(INTERFACE_LOGIN_SCREEN).
  45. getComponent(INTERFACE_TEXT_RETURN).getText().toLowerCase();
  46. int textlength;
  47. if (game.getClientState() != INDEX_LOGGED_OUT) {
  48. if (!game.isWelcomeScreen()) {
  49. sleep(random(1000, 2000));
  50. }
  51. if (game.getClientState() == INDEX_LOBBY) {
  52. RSInterface welcome_screen = interfaces.get(INTERFACE_WELCOME_SCREEN);
  53. RSComponent welcome_screen_button_play_1 = welcome_screen.getComponent(INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_1);
  54. RSComponent welcome_screen_button_play_2 = welcome_screen.getComponent(INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_2);
  55.  
  56. mouse.click(
  57. welcome_screen_button_play_1.getAbsoluteX(),
  58. welcome_screen_button_play_1.getAbsoluteY(),
  59. welcome_screen_button_play_2.getAbsoluteX() + welcome_screen_button_play_2.getWidth() - welcome_screen_button_play_1.getAbsoluteX(),
  60. welcome_screen_button_play_1.getHeight(),
  61. true
  62. );
  63.  
  64. for (int i = 0; i < 4 && game.getClientState() == 6; i++) {
  65. sleep(500);
  66. }
  67. returnText = interfaces.get(INTERFACE_WELCOME_SCREEN).
  68. getComponent(INTERFACE_WELCOME_SCREEN_TEXT_RETURN).getText().toLowerCase();
  69.  
  70. if (returnText.contains("members")) {
  71. log("Unable to login to a members world. Stopping script.");
  72. RSComponent back_button1 = interfaces.get(INTERFACE_WELCOME_SCREEN).getComponent(38);
  73. RSComponent back_button2 = interfaces.get(INTERFACE_WELCOME_SCREEN).getComponent(41);
  74. mouse.click(back_button1.getAbsoluteX(),back_button1.getAbsoluteY(),
  75. back_button2.getAbsoluteX() + back_button2.getWidth() - back_button1.getAbsoluteX(),
  76. back_button1.getHeight(),true);
  77. interfaces.get(INTERFACE_WELCOME_SCREEN).getComponent(203).doClick();
  78. stopScript(false);
  79. }
  80. }
  81. return -1;
  82. }
  83. if (!game.isLoggedIn()) {
  84. if (returnText.contains("update")) {
  85. log("Runescape has been updated, please reload RSBot.");
  86. stopScript(false);
  87. }
  88. if (returnText.contains("disable")) {
  89. log("Your account is banned/disabled.");
  90. stopScript(false);
  91. }
  92. if (returnText.contains("incorrect")) {
  93. log("Failed to login five times in a row. Stopping script.");
  94. stopScript(false);
  95. }
  96. if (returnText.contains("invalid")) {
  97. if (invalidCount > 6) {
  98. log("Unable to login after 6 attempts. Stopping script.");
  99. log("Please verify that your RSBot account profile is correct.");
  100. stopScript(false);
  101. }
  102. interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_BUTTON_BACK).doClick();
  103. invalidCount++;
  104. return random(500, 2000);
  105. }
  106. if (returnText.contains("error connecting")) {
  107. interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_BUTTON_BACK).doClick();
  108. stopScript(false);
  109. return random(500, 2000);
  110. }
  111. if (returnText.contains("full")) {
  112. if (worldFullCount > 30) {
  113. log("World Is Full. Waiting for 15 seconds.");
  114. sleep(random(10000, 15000));
  115. worldFullCount = 0;
  116. }
  117. sleep(random(1000, 1200));
  118. worldFullCount++;
  119. }
  120. if (returnText.contains("world")) {
  121. return random(1000, 1200);
  122. }
  123. if (returnText.contains("performing login")) {
  124. return random(1000, 1200);
  125. }
  126. }
  127. if (game.getClientState() == INDEX_LOGGED_OUT) {
  128. if (!atLoginScreen()) {
  129. interfaces.getComponent(INTERFACE_MAIN, INTERFACE_MAIN_CHILD).getComponent(INTERFACE_MAIN_CHILD_COMPONENT_ID).doAction("");
  130. return random(500, 600);
  131. }
  132. if (isUsernameFilled() && isPasswordFilled()) {
  133. interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_BUTTON_LOGIN).doClick();
  134. return random(500, 600);
  135. }
  136. if (!isUsernameFilled()) {
  137. atLoginInterface(interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_USERNAME_WINDOW));
  138. sleep(random(500, 700));
  139. textlength = interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_USERNAME).getText().length() + random(3, 5);
  140. for (int i = 0; i <= textlength + random(1, 5); i++) {
  141. keyboard.sendText("\b", false);
  142. if (random(0, 2) == 1) {
  143. sleep(random(25, 100));
  144. }
  145. }
  146. keyboard.sendText(username, false);
  147. return random(500, 600);
  148. }
  149. if (isUsernameFilled() && !isPasswordFilled()) {
  150. atLoginInterface(interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_PASSWORD_WINDOW));
  151. sleep(random(500, 700));
  152. textlength = interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_PASSWORD).getText().length() + random(3, 5);
  153. for (int i = 0; i <= textlength + random(1, 5); i++) {
  154. keyboard.sendText("\b", false);
  155. if (random(0, 2) == 1) {
  156. sleep(random(25, 100));
  157. }
  158. }
  159. keyboard.sendText(account.getPassword(), false);
  160. }
  161. }
  162. return random(500, 2000);
  163. }
  164.  
  165. // Clicks past all of the letters
  166. private boolean atLoginInterface(RSComponent i) {
  167. if (!i.isValid())
  168. return false;
  169. Rectangle pos = i.getArea();
  170. if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1)
  171. return false;
  172. int dy = (int) (pos.getHeight() - 4) / 2;
  173. int maxRandomX = (int) (pos.getMaxX() - pos.getCenterX());
  174. int midx = (int) (pos.getCenterX());
  175. int midy = (int) (pos.getMinY() + pos.getHeight() / 2);
  176. if (i.getIndex() == INTERFACE_PASSWORD_WINDOW) {
  177. mouse.click(minX(i), midy + random(-dy, dy), true);
  178. } else {
  179. mouse.click(midx + random(1, maxRandomX), midy + random(-dy, dy), true);
  180. }
  181. return true;
  182. }
  183.  
  184. /*
  185. * Returns x int based on the letters in a Child
  186. * Only the password text is needed as the username text cannot reach past the middle of the interface
  187. */
  188. private int minX(RSComponent a) {
  189. int x = 0;
  190. Rectangle pos = a.getArea();
  191. int dx = (int) (pos.getWidth() - 4) / 2;
  192. int midx = (int) (pos.getMinX() + pos.getWidth() / 2);
  193. if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1)
  194. return 0;
  195. for (int i = 0; i < interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_PASSWORD).getText().length(); i++) {
  196. x += 11;
  197. }
  198. if (x > 44) {
  199. return (int) (pos.getMinX() + x + 15);
  200. } else {
  201. return midx + random(-dx, dx);
  202. }
  203. }
  204.  
  205. private boolean atLoginScreen() {
  206. return interfaces.get(596).isValid();
  207. }
  208.  
  209. private boolean isUsernameFilled() {
  210. String username = account.getName().replaceAll("_", " ").toLowerCase().trim();
  211. return interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_USERNAME).getText().toLowerCase().equalsIgnoreCase(username);
  212. }
  213.  
  214. private boolean isPasswordFilled() {
  215. return interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_PASSWORD).getText().toLowerCase().length() == account.getPassword().length();
  216. }
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement