Skip to content

Commit

Permalink
EIOS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Jan 1, 2024
1 parent 852bf4e commit 92ebea7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 36 deletions.
62 changes: 32 additions & 30 deletions Source/simba.input.pas
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface
DEFAULT_CLICK_MAX = 220;

DEFAULT_MOUSE_TIMEOUT = 15000;
DEFAULT_MOUSE_SPEED = 10;
DEFAULT_MOUSE_SPEED = 12;
DEFAULT_MOUSE_GRAVITY = 9;
DEFAULT_MOUSE_WIND = 4;
public
Expand Down Expand Up @@ -261,17 +261,21 @@ procedure TSimbaInput.MouseMove(Dest: TPoint);
// Credit: BenLand100 (https://github.com/BenLand100/SMART/blob/master/src/EventNazi.java#L201)
procedure WindMouse(xs, ys, xe, ye, gravity, wind, minWait, maxWait, maxStep, targetArea: Double);
var
x, y: Double;
veloX, veloY, windX, windY, veloMag, randomDist, step, idle: Double;
traveledDistance, remainingDistance, acc: Double;
x, y, destX, destY: Double;
veloX, veloY, windX, windY, veloMag, randomDist, idle: Double;
remainingDist, acc, step: Double;
Timeout: UInt64;
begin
veloX := 0; veloY := 0;
windX := 0; windY := 0;

x := xs;
y := ys;
destX := xe;
destY := ye;

acc := MouseAccuracy + 0.5;
step := maxStep;

Timeout := GetTickCount64() + GetMouseTimeout();

Expand All @@ -280,36 +284,35 @@ procedure TSimbaInput.MouseMove(Dest: TPoint);
if (GetTickCount64() > Timeout) then
SimbaException('MouseMove timed out after %dms. Start: (%d,%d), Dest: (%d,%d)', [GetMouseTimeout(), Round(xs), Round(ys), Round(xe), Round(ye)]);

traveledDistance := Hypot(x - xs, y - ys);
remainingDistance := Hypot(x - xe, y - ye);
if (remainingDistance <= acc) then
remainingDist := Hypot(x - xe, y - ye);
if (remainingDist <= acc) then
Break;

wind := Min(wind, remainingDistance);
windX := windX / SQRT_3 + (Random(Round(wind) * 2 + 1) - wind) / SQRT_5;
windY := windY / SQRT_3 + (Random(Round(wind) * 2 + 1) - wind) / SQRT_5;
// If destination changed ensure step is appropriate
if ((xe <> destX) or (ye <> destY)) and (remainingDist > targetArea) then
step := maxStep;
destX := xe;
destY := ye;

if (remainingDistance < targetArea) then
step := (remainingDistance / 2) + (Random() * 6 - 3)
else
if (traveledDistance < targetArea) then
if (remainingDist > targetArea) then
begin
if (traveledDistance < 3) then
traveledDistance := 10 * Random();

step := traveledDistance * (1 + Random() * 3);
wind := Min(wind, remainingDist);
windX := windX / SQRT_3 + (Random(Round(wind) * 2 + 1) - wind) / SQRT_5;
windY := windY / SQRT_3 + (Random(Round(wind) * 2 + 1) - wind) / SQRT_5;
end else
step := maxStep;

if (step >= maxStep) then
step := maxStep - (Random() * (maxStep / 4));
if (step < 3) then
step := 3 + (Random() * 3);
begin
windX /= SQRT_3;
windY /= SQRT_3;
if (step < 3) then
step := 3 + (Random() * 3)
else
step /= SQRT_5;
end;

veloX := veloX + windX;
veloY := veloY + windY;
veloX := veloX + gravity * (xe - x) / remainingDistance;
veloY := veloY + gravity * (ye - y) / remainingDistance;
veloX := veloX + gravity * (xe - x) / remainingDist;
veloY := veloY + gravity * (ye - y) / remainingDist;

if (Hypot(veloX, veloY) > step) then
begin
Expand All @@ -320,10 +323,9 @@ procedure TSimbaInput.MouseMove(Dest: TPoint);
veloY := (veloY / veloMag) * randomDist;
end;

idle := (maxWait - minWait) * (Hypot(veloX, veloY) / maxStep) + minWait;

x := x + veloX;
y := y + veloY;
idle := (maxWait - minWait) * (Hypot(veloX, veloY) / step) + minWait;

Self.MouseTeleport(TPoint.Create(Round(x), Round(y)));

Expand All @@ -338,7 +340,7 @@ procedure TSimbaInput.MouseMove(Dest: TPoint);
Start := MousePosition();

// Further the distance the faster we move.
Expo := Power(Hypot(Start.X - Dest.X, Start.Y - Dest.Y), RandomRange(0.32, 0.35)) / 10;
Expo := Power(Hypot(Start.X - Dest.X, Start.Y - Dest.Y), RandomRange(0.32, 0.36)) / 10;

RandSpeed := RandomLeft(GetSpeed(), GetSpeed() * 1.5);
RandSpeed *= Expo;
Expand All @@ -347,7 +349,7 @@ procedure TSimbaInput.MouseMove(Dest: TPoint);
WindMouse(
Start.X, Start.Y, Dest.X, Dest.Y,
GetGravity(), GetWind(),
5 / RandSpeed, 10 / RandSpeed, 25 * RandSpeed, 20 * RandSpeed
5 / RandSpeed, 10 / RandSpeed, 20 * RandSpeed, 20 * RandSpeed
);
end;

Expand Down
27 changes: 21 additions & 6 deletions Source/targets/simba.target_eios.pas
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ implementation
uses
simba.script_pluginloader;

const
MouseButtonToEIOS: array[EMouseButton] of Int32 = (1, 3, 2, 4, 5);

function LoadEIOS(FileName, Args: String): TEIOSTarget;
begin
with Result do
Expand Down Expand Up @@ -191,7 +194,7 @@ function EIOSTarget_MousePressed(Target: Pointer; Button: EMouseButton): Boolean
with PEIOSTarget(Target)^ do
begin
if Assigned(IsMouseButtonHeld) then
Result := IsMouseButtonHeld(Target, Int32(Button))
Result := IsMouseButtonHeld(Target, MouseButtonToEIOS[Button])
else
Result := False;
end;
Expand Down Expand Up @@ -229,27 +232,39 @@ procedure EIOSTarget_MouseTeleport(Target: Pointer; P: TPoint);
end;

procedure EIOSTarget_MouseDown(Target: Pointer; Button: EMouseButton);
var
X,Y: Integer;
begin
with PEIOSTarget(Target)^, EIOSTarget_MousePosition(Target) do
with PEIOSTarget(Target)^ do
begin
if Assigned(GetMousePosition) then
GetMousePosition(Target, X, Y);
if Assigned(HoldMouse) then
HoldMouse(Target, X, Y, Int32(Button));
HoldMouse(Target, X, Y, MouseButtonToEIOS[Button]);
end;
end;

procedure EIOSTarget_MouseUp(Target: Pointer; Button: EMouseButton);
var
X, Y: Integer;
begin
with PEIOSTarget(Target)^, EIOSTarget_MousePosition(Target) do
with PEIOSTarget(Target)^ do
begin
if Assigned(GetMousePosition) then
GetMousePosition(Target, X, Y);
if Assigned(ReleaseMouse) then
ReleaseMouse(Target, X, Y, Int32(Button));
ReleaseMouse(Target, X, Y, MouseButtonToEIOS[Button]);
end;
end;

procedure EIOSTarget_MouseScroll(Target: Pointer; Scrolls: Integer);
var
X, Y: Integer;
begin
with PEIOSTarget(Target)^, EIOSTarget_MousePosition(Target) do
with PEIOSTarget(Target)^ do
begin
if Assigned(GetMousePosition) then
GetMousePosition(Target, X, Y);
if Assigned(ScrollMouse) then
ScrollMouse(Target, X, Y, Scrolls);
end;
Expand Down

0 comments on commit 92ebea7

Please sign in to comment.