Advertisement
Guest User

Untitled

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