Advertisement
Guest User

Untitled

a guest
Jun 17th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.91 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 = 178;
  30. private static final int INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_2 = 180;
  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 = getLoginIndex();
  39. if (idx == INDEX_LOGGED_OUT || idx == INDEX_LOBBY) {
  40. return true;
  41. }
  42. return false;
  43. }
  44.  
  45. public int loop() {
  46. String username = Bot.getAccountName().replaceAll("_", " ").toLowerCase().trim();
  47. String returnText = RSInterface.getInterface(INTERFACE_LOGIN_SCREEN).
  48. getChild(INTERFACE_TEXT_RETURN).getText().toLowerCase();
  49. int textlength;
  50. if (getLoginIndex() != INDEX_LOGGED_OUT) {
  51. if (!isWelcomeScreen()) {
  52. wait(random(1000, 2000));
  53. }
  54. if (getLoginIndex() == INDEX_LOBBY) {
  55. RSInterface welcome_screen = getInterface(INTERFACE_WELCOME_SCREEN);
  56. RSInterfaceChild welcome_screen_button_play_1 = welcome_screen.getChild(INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_1);
  57. RSInterfaceChild welcome_screen_button_play_2 = welcome_screen.getChild(INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_2);
  58.  
  59. clickMouse(
  60. welcome_screen_button_play_1.getAbsoluteX(),
  61. welcome_screen_button_play_1.getAbsoluteY(),
  62. welcome_screen_button_play_2.getAbsoluteX() + welcome_screen_button_play_2.getWidth() - welcome_screen_button_play_1.getAbsoluteX(),
  63. welcome_screen_button_play_1.getHeight(),
  64. true
  65. );
  66. wait(random(5000, 10000));
  67. clickMouse(290, 455, true);
  68. clickMouse(290, 455, true);
  69. clickMouse(290, 455, true);
  70. clickMouse(290, 455, true);
  71. clickMouse(290, 455, true);
  72.  
  73. for (int i = 0; i < 4 && getLoginIndex() == INDEX_LOBBY; i++)
  74. wait(500);
  75. }
  76. return -1;
  77. }
  78. if (!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("members")) {
  88. log("We have attempted to log into a members world as a free to play player, stopping script.");
  89. stopScript(false);
  90. }
  91. if (returnText.contains("incorrect")) {
  92. log("Failed to login five times in a row. Stopping all scripts.");
  93. stopScript(false);
  94. }
  95. if (returnText.contains("already")) {
  96. wait(random(500, 700));
  97. clickMouse(337, 337, true);
  98. wait(random(500, 700));
  99. }
  100. if (returnText.contains("invalid")) {
  101. if (invalidCount > 6) {
  102. log("Unable To Login After 6 Attempts, Stopping Script.");
  103. log("Please verify that your RSBot account profile is correct.");
  104. stopScript(false);
  105. }
  106. atInterface(RSInterface.getInterface(INTERFACE_LOGIN_SCREEN).getChild(38));
  107. invalidCount++;
  108. return (random(500, 2000));
  109. }
  110. if (returnText.contains("already")) {
  111. wait(random(500, 700));
  112. clickMouse(337, 337, true);
  113. wait(random(500, 700));
  114. }
  115. if (returnText.contains("full")) {
  116. if (worldFullCount > 30) {
  117. log("World Is Full. Waiting for 15 seconds.");
  118. wait(random(10000, 15000));
  119. worldFullCount = 0;
  120. }
  121. wait(random(1000, 1200));
  122. worldFullCount++;
  123. }
  124. if (returnText.contains("world")) {
  125. return random(1000, 1200);
  126. }
  127. if (returnText.contains("performing login")) {
  128. return random(1000, 1200);
  129. }
  130. }
  131. if (getLoginIndex() == INDEX_LOGGED_OUT) {
  132. if (!atLoginScreen()) {
  133. atComponent(RSInterface.getChildInterface(INTERFACE_MAIN, INTERFACE_MAIN_CHILD).getComponents()[INTERFACE_MAIN_CHILD_COMPONENT_ID], "");
  134. return random(500, 600);
  135. }
  136. if (isUsernameFilled() && isPasswordFilled()) {
  137. atInterface(RSInterface.getInterface(INTERFACE_LOGIN_SCREEN).getChild(INTERFACE_BUTTON_LOGIN));
  138. return random(500,600);
  139. }
  140. if (!isUsernameFilled()) {
  141. atLoginInterface(RSInterface.getInterface(INTERFACE_LOGIN_SCREEN).getChild(INTERFACE_USERNAME_WINDOW));
  142. wait(random(500,700));
  143. textlength = RSInterface.getInterface(INTERFACE_LOGIN_SCREEN).getChild(INTERFACE_USERNAME).getText().length() + random(3, 5);
  144. for (int i = 0; i <= textlength + random(1,5); i++) {
  145. sendText("\b", false);
  146. if (random(0, 2) == 1) {
  147. wait(random(25, 100));
  148. }
  149. }
  150. sendText(username, false);
  151. }
  152. if (isUsernameFilled() && !isPasswordFilled()) {
  153. atLoginInterface(RSInterface.getInterface(INTERFACE_LOGIN_SCREEN).getChild(INTERFACE_PASSWORD_WINDOW));
  154. wait(random(500,700));
  155. textlength = RSInterface.getInterface(INTERFACE_LOGIN_SCREEN).getChild(INTERFACE_PASSWORD).getText().length() + random(3, 5);
  156. for (int i = 0; i <= textlength + random(1,5); i++) {
  157. sendText("\b", false);
  158. if (random(0, 2) == 1) {
  159. wait(random(25, 100));
  160. }
  161. }
  162. sendText(AccountManager.getPassword(Bot.getAccountName()), false);
  163. }
  164. }
  165. return random(500, 2000);
  166. }
  167.  
  168. //Clicks past all of the letters
  169. private boolean atLoginInterface(RSInterfaceChild i) {
  170. if (!i.isValid())
  171. return false;
  172. Rectangle pos = i.getArea();
  173. if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1)
  174. return false;
  175. int dy = (int) (pos.getHeight() - 4) / 2;
  176. int maxRandomX = (int) (pos.getMaxX() - pos.getCenterX());
  177. int midx = (int) (pos.getCenterX());
  178. int midy = (int) (pos.getMinY() + pos.getHeight() / 2);
  179. if (i.getIndex() == INTERFACE_PASSWORD_WINDOW) {
  180. clickMouse(MinX(i), midy + random(-dy, dy), true);
  181. } else {
  182. clickMouse(midx + random(1,maxRandomX), midy + random(-dy, dy), true);
  183. }
  184. return true;
  185. }
  186.  
  187. /*
  188. * Returns x int based on the letters in a Child
  189. * Only the password text is needed as the username text cannot reach past the middle of the interface
  190. */
  191. private int MinX(RSInterfaceChild a) {
  192. int x = 0;
  193. Rectangle pos = a.getArea();
  194. int dx = (int) (pos.getWidth() - 4) / 2;
  195. int midx = (int) (pos.getMinX() + pos.getWidth() / 2);
  196. if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1)
  197. return 0;
  198. for (int i = 0; i < RSInterface.getInterface(INTERFACE_LOGIN_SCREEN).getChild(INTERFACE_PASSWORD).getText().length(); i++) {
  199. x += 11;
  200. }
  201. if (x > 44) {
  202. return (int) (pos.getMinX() + x + 15);
  203. } else {
  204. return midx + random(-dx,dx);
  205. }
  206. }
  207.  
  208. private boolean atLoginScreen() {
  209. return getInterface(596).isValid();
  210. }
  211.  
  212. private boolean isUsernameFilled() {
  213. String username = Bot.getAccountName().replaceAll("_", " ").toLowerCase().trim();
  214. return RSInterface.getInterface(INTERFACE_LOGIN_SCREEN).getChild(INTERFACE_USERNAME).getText().toLowerCase().equalsIgnoreCase(username);
  215. }
  216.  
  217. private boolean isPasswordFilled() {
  218. return RSInterface.getInterface(INTERFACE_LOGIN_SCREEN).getChild(INTERFACE_PASSWORD).getText().toLowerCase().length() == AccountManager.getPassword(Bot.getAccountName()).length();
  219. }
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement