program new;
const
DEBUG = True;
USERNAME = 'asdf';
PASSWORD = '1234';
MOUSE_MOVE = 3;
LOGIN_TEXT_YELLOW = 7456488;
USERNAME_BOX: TBOX = [288, 235, 498, 259];
PASSWORD_BOX: TBOX = [288, 288, 498, 312];
function CountColor(const Color: Int32; b: TBox): Int32; Overload;
begin
Result := CountColor(Color, b.x1, b.y1, b.x2, b.y2);
end;
function CountColor(const Color: Int32): Int32; Overload;
var
w, h: Int32;
begin
GetClientDimensions(w, h);
Result := CountColor(Color, 0, 0, w-1, h-1);
end;
procedure Wait(w1, w2: Int32); Overload;
begin
Wait(Random(w1, w2));
end;
function WaitFunc(Func: function: Boolean; WaitTime, WaitInterval: Int32; Condition: Boolean = True): Boolean;
var
t: UInt32;
begin
Result := (not Condition);
t := GetTickCount() + WaitTime;
repeat
Result := Func();
if (Result = Condition) then Exit(True);
Wait(WaitInterval);
until (GetTickCount() > t);
end;
procedure Mouse(p: TPoint; Button: Int32);
begin
MoveMouse(p.x, p.y);
if (Button = MOUSE_MOVE) then Exit();
Wait(14, 24);
HoldMouse(p.x, p.y, Button);
Wait(69, 96);
ReleaseMouse(p.x, p.y, Button);
end;
procedure MouseBox(B: TBox; Button: Int32);
begin
Mouse(MiddleBox(B), Button);
end;
function LoginScreen(): Boolean;
begin
Result := InRange(CountColor(LOGIN_TEXT_YELLOW), 690, 710);
if DEBUG then WriteLn('LoginScreen: ', Result);
end;
function UsernameFilledIn(): Boolean;
begin
Result := (CountColor($FFFFFF, USERNAME_BOX) > 0);
if DEBUG then WriteLn('UsernameFilledIn: ', Result);
end;
function PasswordFilledIn(): Boolean;
begin
Result := (CountColor($FFFFFF, PASSWORD_BOX) > 0);
if DEBUG then WriteLn('PasswordFilledIn: ', Result);
end;
function DoLogin(): Boolean;
begin
if LoginScreen() then
begin
if ((not UsernameFilledIn()) and (not PasswordFilledIn())) then
begin
MouseBox(USERNAME_BOX, MOUSE_LEFT);
Wait(69);
SendKeys(USERNAME, 69, 22);
Wait(69);
PressKey(VK_TAB);
Wait(69);
SendKeys(PASSWORD, 69, 22);
PressKey(VK_RETURN);
Result := WaitFunc(@LoginScreen, 2345, 234, False);
end;
end;
end;
begin
ClearDebug();
DoLogin();
end.