Advertisement
Guest User

Untitled

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