Guest User

Untitled

a guest
Jun 13th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. package input;
  2.  
  3. import java.awt.Point;
  4. import java.util.ArrayList;
  5.  
  6. import api.methods.Client;
  7.  
  8. public class BeizerSplineGenerator {
  9. Mouse parent =input.Mouse.getMouse();
  10.  
  11. public BeizerSplineGenerator() {
  12. this.parent = parent;
  13. }
  14.  
  15. protected final void moveMouseSpline(Point start, Point end) {
  16. if (start == null || end == null)
  17. return;
  18.  
  19. try {
  20. int curveHeight = (int) (Math
  21. .ceil(Point.distance(start.getX(),start.getY(),end.getX(),end.getY())) / Client
  22. .random(5, 15));
  23. int largeCurveHeight = (int) (curveHeight * Client
  24. .random(2, 3));
  25. int curveCount = Client.random(8, 10);
  26.  
  27. int small = Math.min(curveHeight, largeCurveHeight);
  28.  
  29. Point[] midpoints = new Point[curveCount - 1];
  30. for (int i = 1; i < curveCount; i++)
  31. midpoints[i - 1] = new Point(((start.x + end.x) * i)
  32. / curveCount, ((start.y + end.y) * i) / curveCount);
  33.  
  34. Point last = start;
  35.  
  36. Point c1 = randomCirclePoint(small, last);
  37. Point c2 = randomCirclePoint(small, end);
  38.  
  39. moveMouseBezier(last, c1, c2, end);
  40. } catch (Exception e) {
  41. e.printStackTrace();
  42. } finally {
  43. this.parent.mouseSpline.clear();
  44. }
  45. }
  46.  
  47. private void omitPoints(final ArrayList<Point> spline) {
  48.  
  49. if (spline.size() < 2)
  50. return;
  51.  
  52. ArrayList<Point> newSpline = new ArrayList<Point>();
  53.  
  54. Point last = spline.get(0);
  55. double mid = spline.size() / 2.00D;
  56. double multiplier1 = Client.random(11000, 13000) / 1000D;
  57. double multiplier2 = Client.random(11000, 13000) / 1000D;
  58. double nDist = Client.random(
  59. Client.random(8, 10), 12)
  60. - (Math.abs(0 - mid) / mid) * multiplier1;
  61.  
  62. for (int i = 1; i < spline.size(); i++) {
  63. if (i == spline.size() - 1) {
  64. if (!spline.get(i).equals(last))
  65. newSpline.add(spline.get(spline.size() - 1));
  66.  
  67. break;
  68. }
  69.  
  70. if (spline.get(i).equals(last))
  71. continue;
  72.  
  73. if (Point.distance(spline.get(i).getX(),spline.get(i).getY(),last.getX(), last.getY()) > nDist) {
  74. if (i > mid) {
  75. if (Client.random(0, 1) == 0)
  76. multiplier2 += (Client.random(0,
  77. 1000) / 100000D);
  78. else
  79. multiplier2 -= (Client.random(0,
  80. 1000) / 100000D);
  81. } else {
  82. if (Client.random(0, 1) == 0)
  83. multiplier1 += (Client.random(0,
  84. 1000) / 100000D);
  85. else
  86. multiplier1 -= (Client.random(0,
  87. 1000) / 100000D);
  88. }
  89.  
  90. newSpline.add(spline.get(i));
  91. last = spline.get(i);
  92. nDist = Client.random(
  93. Client.random(8, 10), 12)
  94. - (Math.abs(i - mid) / mid)
  95. * (i > mid ? multiplier2 : multiplier1);
  96. }
  97. }
  98.  
  99. spline.clear();
  100. spline.addAll(newSpline);
  101. }
  102.  
  103. private int fittsLaw(double delay, double dist, double size, double speed) {
  104. return (int) (delay + speed * Math.log10(dist / size + 1)
  105. / Math.log10(2));
  106. }
  107.  
  108. private void moveMouseBezier(Point p1, Point p2, Point p3, Point p4) {
  109. int baseSpeed = 45;
  110.  
  111. ArrayList<Point> spline = generateSpline(p1, p2, p3, p4);
  112. omitPoints((this.parent.mouseSpline = spline));
  113.  
  114. if (this.parent.stopMovement)
  115. this.parent.stopMovement = false;
  116.  
  117. for (int i = 0; i < this.parent.mouseSpline.size(); i++) {
  118. if (this.parent.stopMovement)
  119. break;
  120.  
  121. Point p = this.parent.mouseSpline.get(i);
  122.  
  123. Mouse.setMousePos(p.x, p.y);
  124.  
  125. if (i == this.parent.mouseSpline.size() - 1)
  126. break;
  127.  
  128. double dist = p.distance(this.parent.mouseSpline.get(i + 1));
  129.  
  130. sleep(fittsLaw((300.0D / this.parent.mouseSpline.size()),
  131. dist, 1, ((200 - 5)
  132. - baseSpeed + Client
  133. .random(2, 3)) / 20.0D));
  134. }
  135. }
  136. public static void sleep(int z) {
  137. try {
  138. Thread.sleep(z);
  139. } catch (InterruptedException e) {
  140. // TODO Auto-generated catch block
  141. e.printStackTrace();
  142. }
  143.  
  144. }
  145. public ArrayList<Point> generateSpline(Point start, Point controlPoint1,
  146. Point controlPoint2, Point end) {
  147.  
  148. ArrayList<Point> spline = new ArrayList<Point>();
  149.  
  150. double d = Math.ceil(start.distance(end));
  151. for (int i = 0; i < d; i++) {
  152. Point next = bezierFunction(start.x, start.y, controlPoint1.x,
  153. controlPoint1.y, controlPoint2.x, controlPoint2.y, end.x,
  154. end.y, i / d);
  155. spline.add(next);
  156.  
  157. if (next.equals(end))
  158. break;
  159. }
  160.  
  161. return spline;
  162. }
  163.  
  164. private Point bezierFunction(int x1, int y1, int x2, int y2, int x3,
  165. int y3, int x4, int y4, double t) {
  166.  
  167. double a = Math.pow(1 - t, 3);
  168. double b = 3 * Math.pow(1 - t, 2) * t;
  169. double c = (3 * (1 - t)) * Math.pow(t, 2);
  170. double d = Math.pow(t, 3);
  171.  
  172. double newX = (a * x1) + (b * x2) + (c * x3) + (d * x4);
  173. double newY = (a * y1) + (b * y2) + (c * y3) + (d * y4);
  174.  
  175. return new Point((int) newX, (int) newY);
  176. }
  177.  
  178. private int circleFunction(int r2, int val) {
  179. return (int) Math.round(Math.sqrt(r2 - Math.pow(val, 2)));
  180. }
  181.  
  182. private final Point randomCirclePoint(int radius, Point center) {
  183. boolean high = Client.random(0, 2) == 0;
  184. boolean negate = Client.random(0, 2) == 0;
  185.  
  186. int x, y;
  187. if (high) {
  188. y = Client.random(center.y - radius + 1,
  189. center.y + radius);
  190. x = circleFunction(radius * radius, y - center.y);
  191. x = negate ? center.x - x : x + center.x;
  192. } else {
  193. x = Client.random(center.x - radius + 1,
  194. center.x + radius);
  195. y = circleFunction(radius * radius, x - center.x);
  196. y = negate ? center.y - y : y + center.y;
  197. }
  198. return new Point(x, y);
  199. }
  200.  
  201. }
Add Comment
Please, Sign In to add comment