PDA

View Full Version : Can't find color while it is there



xX4m4zingXx
11-08-2017, 11:28 AM
So I got back at making a bot again.
I tried making it so that the bot can login, but it can't find a color to check if the fields are already filled in.

program RuneCrafting;
{$I srl-6/srl.simba}

var
LogIn:Integer;

const
USERNAME = '';
PASSWORD = '';


Procedure LogInOnAccount;
var X, Y:Integer;
begin
if FindBitmapToleranceIn(LogIn, X, Y, 197, 129, 424, 321, 5) then
Writeln('Found the login thing');
begin
Writeln('Found the login thing');
if not (FindColorTolerance(X, Y, 15395563, 227, 234, 401, 256, 20)) then
begin
Writeln('Not filled in');
MouseSpeed := 15;
Mouse(302, 200);
wait(250);
ClickMouse(302, 200, mouse_Left);
wait(1000);
SendKeys(USERNAME, 100, 10);
Mouse(308, 246);
wait(250);
ClickMouse(308, 246, mouse_Left);
wait(1000);
SendKeys(PASSWORD, 100, 10);
end;
Writeln('Logging in');
Mouse(321, 279);
wait(250);
ClickMouse(321, 279, mouse_Left);
end;
end;

Procedure CallThings;
Begin
LogIn := BitmapFromString(115, 23, 'meJztltENwjAMRP8yWCfglzFYk' +
'lkYAwmkypzP5yRNVT6M7it2nPOr07Ld7lupVCqVTtbj+QJFoT +xd5' +
'WTCbXWds/t8/MhWL/W3lVOJmSd05Bd9/ND52ofreNTJ+xFrqIjhqz' +
'aRVFnCVg7OTYEQ0V3fVcm2KZgYZ6jriEN7oI/C1oThx4EC2kitH2u' +
'MHUrrM6BpQ1GxDwHAVYPZ3qJpsFaej29izpLwEa70gpiBgDsw 33cl' +
'4BNHx+g09H+z1BqLw31P8oUrL8CS8BGbOF0cb9Gx/U8sHQUBUCauR' +
'Csfqz64wVp14L1tjVYGz0JLBxBK0QvLj/tp4IFYkMTQglEtzI1n3q' +
'jBvRBUfI0WOpEj4RocAgssJ14aUfe6Aeos3fd5ihYUQ3s6bRR sOkg' +
'gdrvX2vvLQr5XTYHVvQdEVRpcZFGX+O6R2+VOhfANV74iajYZ XPSX' +
'aOWeryJsiJTm6d1OsGWSqVSqfSfegMktTJ6');
End;

Procedure FreeThings;
Begin
FreeBitMap(LogIn);
End;

begin
CallThings;
AddOnTerminate('FreeThings');
LogInOnAccount();
end.

When the login fields are filled in then it should find some white pixels in the password field, but for some reason it never finds these.
It's about this line of code:

if not (FindColorTolerance(X, Y, 15395563, 227, 234, 401, 256, 20)) then
and another question. I have to add
Writeln('Found the login thing'); between:

if FindBitmapToleranceIn(LogIn, X, Y, 197, 129, 424, 321, 5) then
and

begin
else it just terminates without doing anything, why is that?

Citrus
11-08-2017, 11:53 AM
(op)

You're going about this the wrong way IMO. This bitmap you're using ( https://i.imgur.com/IqbtzXg.png ) is solid colors... why use a bitmap at all?
Something like CountColor would work just fine.

Why does nobody ever say which private server they're using when asking for help here...

xX4m4zingXx
11-08-2017, 12:03 PM
You're going about this the wrong way IMO. This bitmap you're using ( https://i.imgur.com/IqbtzXg.png ) is solid colors... why use a bitmap at all?
Something like CountColor would work just fine.

Why does nobody ever say which private server they're using when asking for help here...

Ah okay, thank you for the advice!
The server I am using is ArandarPS, it's not really known.

Citrus
11-08-2017, 12:16 PM
Ah okay, thank you for the advice!
The server I am using is ArandarPS, it's not really known.

Okay thanks, I'll check it out and write something in a bit.

xX4m4zingXx
11-08-2017, 12:21 PM
Okay thanks, I'll check it out and write something in a bit.

Oh Okay, Thank you very very much.

Citrus
11-08-2017, 12:46 PM
Oh Okay, Thank you very very much.
Here is something super basic. Maybe I'll add more later.

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.

xX4m4zingXx
11-08-2017, 01:02 PM
Here is something super basic. Maybe I'll add more later.

program new;

const
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);
end;

function UsernameFilledIn(): Boolean;
begin
Result := (CountColor($FFFFFF, USERNAME_BOX) > 0);
end;

function PasswordFilledIn(): Boolean;
begin
Result := (CountColor($FFFFFF, PASSWORD_BOX) > 0);
end;

procedure TypeString(const s: String; Enter: Boolean);
begin
SendKeys(s, 69, 22);
if Enter then PressKey(VK_RETURN);
end;

function DoLogin(): Boolean;
begin
if LoginScreen() then
begin
if ((not UsernameFilledIn()) and (not PasswordFilledIn())) then
begin
MouseBox(USERNAME_BOX, MOUSE_LEFT);
Wait(69);
TypeString(USERNAME, False);
Wait(69);
PressKey(VK_TAB);
Wait(69);
TypeString(PASSWORD, True);
Result := WaitFunc(@LoginScreen, 2345, 234, False);
end;
end;
end;

begin
ClearDebug();
DoLogin();
end.


Thank you very much, I'll try to read it and will do my best to understand all of it!

xX4m4zingXx
11-09-2017, 11:46 AM
Here is something super basic. Maybe I'll add more later.

program new;

const
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);
end;

function UsernameFilledIn(): Boolean;
begin
Result := (CountColor($FFFFFF, USERNAME_BOX) > 0);
end;

function PasswordFilledIn(): Boolean;
begin
Result := (CountColor($FFFFFF, PASSWORD_BOX) > 0);
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.


Today I tried using this script, but for some reason it doesn't do anything. it's just saying executed sucessfully.
This is all what is says after I comment out clearDebug();

New window: 6951286
Compiled successfully in 500 ms.
Successfully executed.
It would be awesome if you could help me again

Citrus
11-09-2017, 12:28 PM
Today I tried using this script, but for some reason it doesn't do anything. it's just saying executed sucessfully.
This is all what is says after I comment out clearDebug();

New window: 6951286
Compiled successfully in 500 ms.
Successfully executed.
It would be awesome if you could help me again

Still works fine for me, but I edited my post (https://villavu.com/forum/showthread.php?t=117937&p=1389612#post1389612) and added some debug. You should be able to add some WriteLn's yourself though.

xX4m4zingXx
11-09-2017, 12:38 PM
Still works fine for me, but I edited my post (https://villavu.com/forum/showthread.php?t=117937&p=1389612#post1389612) and added some debug. You should be able to add some WriteLn's yourself though.

Ah, yeah I should've done that myself to be honest. In the debug it said that the username was filled in when it wasn't, so I supposed that it saw the white pixels of the "username" text. I changed the tbox coordinates and it worked! Thank you once again! btw did you fix the problem with seeing the type cursor by adjusting the tbox of the username/password to be next to the type cursor?

Citrus
11-09-2017, 12:43 PM
Ah, yeah I should've done that myself to be honest. In the debug it said that the username was filled in when it wasn't, so I supposed that it saw the white pixels of the "username" text. I changed the tbox coordinates and it worked! Thank you once again! btw did you fix the problem with seeing the type cursor by adjusting the tbox of the username/password to be next to the type cursor?

Ahh okay. Your window must be a different size than mine. Ideally the boxes wouldn't be hard-coded, but this is just a quick and dirty script.

xX4m4zingXx
11-09-2017, 12:45 PM
Ahh okay. Your window must be a different size than mine. Ideally the boxes wouldn't be hard-coded, but this is just a quick and dirty script.

Ah okay, how should it be done? Can you give just a real simple answer without any code, So I can find it out myself?

Citrus
11-09-2017, 12:54 PM
Ah okay, how should it be done? Can you give just a real simple answer without any code, So I can find it out myself?

There are tons of ways to do it. The next step up from hard-coding might be to edit/offset boxes based on other features of the login screen. e.g. the yellow 'USER LOGIN' text, the white 'Username' and 'Password' text, the solid brown background of the login box... there are plenty of unique colors on that screen.