Results 1 to 13 of 13

Thread: Can't find color while it is there

  1. #1
    Join Date
    Jul 2013
    Posts
    45
    Mentioned
    1 Post(s)
    Quoted
    16 Post(s)

    Default Can't find color while it is there

    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.
    Code:
    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' +
            'MHUrrM6BpQ1GxDwHAVYPZ3qJpsFaej29izpLwEa70gpiBgDsw33cl' +
            '4BNHx+g09H+z1BqLw31P8oUrL8CS8BGbOF0cb9Gx/U8sHQUBUCauR' +
            'Csfqz64wVp14L1tjVYGz0JLBxBK0QvLj/tp4IFYkMTQglEtzI1n3q' +
            'jBvRBUfI0WOpEj4RocAgssJ14aUfe6Aeos3fd5ihYUQ3s6bRRsOkg' +
            'gdrvX2vvLQr5XTYHVvQdEVRpcZFGX+O6R2+VOhfANV74iajYZXPSX' +
            '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:
    Code:
    if not (FindColorTolerance(X, Y, 15395563, 227, 234, 401, 256, 20)) then
    and another question. I have to add
    Code:
    Writeln('Found the login thing');
    between:
    Code:
    if FindBitmapToleranceIn(LogIn, X, Y, 197, 129, 424, 321, 5) then
    and
    Code:
    begin
    else it just terminates without doing anything, why is that?

  2. #2
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by xX4m4zingXx View Post
    (op)
    You're going about this the wrong way IMO. This bitmap you're using ( ) 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...

  3. #3
    Join Date
    Jul 2013
    Posts
    45
    Mentioned
    1 Post(s)
    Quoted
    16 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    You're going about this the wrong way IMO. This bitmap you're using ( ) 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.

  4. #4
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by xX4m4zingXx View Post
    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.

  5. #5
    Join Date
    Jul 2013
    Posts
    45
    Mentioned
    1 Post(s)
    Quoted
    16 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    Okay thanks, I'll check it out and write something in a bit.
    Oh Okay, Thank you very very much.

  6. #6
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by xX4m4zingXx View Post
    Oh Okay, Thank you very very much.
    Here is something super basic. Maybe I'll add more later.
    Simba Code:
    1. program new;
    2.  
    3. const
    4.   DEBUG = True;
    5.   USERNAME = 'asdf';
    6.   PASSWORD = '1234';
    7.  
    8.   MOUSE_MOVE = 3;
    9.   LOGIN_TEXT_YELLOW = 7456488;
    10.   USERNAME_BOX: TBOX = [288, 235, 498, 259];
    11.   PASSWORD_BOX: TBOX = [288, 288, 498, 312];
    12.  
    13. function CountColor(const Color: Int32; b: TBox): Int32; Overload;
    14. begin
    15.   Result := CountColor(Color, b.x1, b.y1, b.x2, b.y2);
    16. end;
    17.  
    18. function CountColor(const Color: Int32): Int32; Overload;
    19. var
    20.   w, h: Int32;
    21. begin
    22.   GetClientDimensions(w, h);
    23.   Result := CountColor(Color, 0, 0, w-1, h-1);
    24. end;
    25.  
    26. procedure Wait(w1, w2: Int32); Overload;
    27. begin
    28.   Wait(Random(w1, w2));
    29. end;
    30.  
    31. function WaitFunc(Func: function: Boolean; WaitTime, WaitInterval: Int32; Condition: Boolean = True): Boolean;
    32. var
    33.   t: UInt32;
    34. begin
    35.   Result := (not Condition);
    36.   t := GetTickCount() + WaitTime;
    37.   repeat
    38.     Result := Func();
    39.     if (Result = Condition) then Exit(True);
    40.     Wait(WaitInterval);
    41.   until (GetTickCount() > t);
    42. end;
    43.  
    44. procedure Mouse(p: TPoint; Button: Int32);
    45. begin
    46.   MoveMouse(p.x, p.y);
    47.   if (Button = MOUSE_MOVE) then Exit();
    48.   Wait(14, 24);
    49.   HoldMouse(p.x, p.y, Button);
    50.   Wait(69, 96);
    51.   ReleaseMouse(p.x, p.y, Button);
    52. end;
    53.  
    54. procedure MouseBox(B: TBox; Button: Int32);
    55. begin
    56.   Mouse(MiddleBox(B), Button);
    57. end;
    58.  
    59. function LoginScreen(): Boolean;
    60. begin
    61.   Result := InRange(CountColor(LOGIN_TEXT_YELLOW), 690, 710);
    62.   if DEBUG then WriteLn('LoginScreen: ', Result);
    63. end;
    64.  
    65. function UsernameFilledIn(): Boolean;
    66. begin
    67.   Result := (CountColor($FFFFFF, USERNAME_BOX) > 0);
    68.   if DEBUG then WriteLn('UsernameFilledIn: ', Result);
    69. end;
    70.  
    71. function PasswordFilledIn(): Boolean;
    72. begin
    73.   Result := (CountColor($FFFFFF, PASSWORD_BOX) > 0);
    74.   if DEBUG then WriteLn('PasswordFilledIn: ', Result);
    75. end;
    76.  
    77. function DoLogin(): Boolean;
    78. begin
    79.   if LoginScreen() then
    80.   begin
    81.     if ((not UsernameFilledIn()) and (not PasswordFilledIn())) then
    82.     begin
    83.       MouseBox(USERNAME_BOX, MOUSE_LEFT);
    84.       Wait(69);
    85.       SendKeys(USERNAME, 69, 22);
    86.       Wait(69);
    87.       PressKey(VK_TAB);
    88.       Wait(69);
    89.       SendKeys(PASSWORD, 69, 22);
    90.       PressKey(VK_RETURN);
    91.       Result := WaitFunc(@LoginScreen, 2345, 234, False);
    92.     end;
    93.   end;
    94. end;
    95.  
    96. begin
    97.   ClearDebug();
    98.   DoLogin();
    99. end.
    Last edited by Citrus; 11-09-2017 at 12:27 PM. Reason: updated script

  7. #7
    Join Date
    Jul 2013
    Posts
    45
    Mentioned
    1 Post(s)
    Quoted
    16 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    Here is something super basic. Maybe I'll add more later.
    Simba Code:
    1. program new;
    2.  
    3. const
    4.   USERNAME = 'asdf';
    5.   PASSWORD = '1234';
    6.  
    7.   MOUSE_MOVE = 3;
    8.   LOGIN_TEXT_YELLOW = 7456488;
    9.   USERNAME_BOX: TBOX = [288, 235, 498, 259];
    10.   PASSWORD_BOX: TBOX = [288, 288, 498, 312];
    11.  
    12. function CountColor(const Color: Int32; b: TBox): Int32; Overload;
    13. begin
    14.   Result := CountColor(Color, b.x1, b.y1, b.x2, b.y2);
    15. end;
    16.  
    17. function CountColor(const Color: Int32): Int32; Overload;
    18. var
    19.   w, h: Int32;
    20. begin
    21.   GetClientDimensions(w, h);
    22.   Result := CountColor(Color, 0, 0, w-1, h-1);
    23. end;
    24.  
    25. procedure Wait(w1, w2: Int32); Overload;
    26. begin
    27.   Wait(Random(w1, w2));
    28. end;
    29.  
    30. function WaitFunc(Func: function: Boolean; WaitTime, WaitInterval: Int32; Condition: Boolean = True): Boolean;
    31. var
    32.   t: UInt32;
    33. begin
    34.   Result := (not Condition);
    35.   t := GetTickCount() + WaitTime;
    36.   repeat
    37.     Result := Func();
    38.     if (Result = Condition) then Exit(True);
    39.     Wait(WaitInterval);
    40.   until (GetTickCount() > t);
    41. end;
    42.  
    43. procedure Mouse(p: TPoint; Button: Int32);
    44. begin
    45.   MoveMouse(p.x, p.y);
    46.   if (Button = MOUSE_MOVE) then Exit();
    47.   Wait(14, 24);
    48.   HoldMouse(p.x, p.y, Button);
    49.   Wait(69, 96);
    50.   ReleaseMouse(p.x, p.y, Button);
    51. end;
    52.  
    53. procedure MouseBox(B: TBox; Button: Int32);
    54. begin
    55.   Mouse(MiddleBox(B), Button);
    56. end;
    57.  
    58. function LoginScreen(): Boolean;
    59. begin
    60.   Result := InRange(CountColor(LOGIN_TEXT_YELLOW), 690, 710);
    61. end;
    62.  
    63. function UsernameFilledIn(): Boolean;
    64. begin
    65.   Result := (CountColor($FFFFFF, USERNAME_BOX) > 0);
    66. end;
    67.  
    68. function PasswordFilledIn(): Boolean;
    69. begin
    70.   Result := (CountColor($FFFFFF, PASSWORD_BOX) > 0);
    71. end;
    72.  
    73. procedure TypeString(const s: String; Enter: Boolean);
    74. begin
    75.   SendKeys(s, 69, 22);
    76.   if Enter then PressKey(VK_RETURN);
    77. end;
    78.  
    79. function DoLogin(): Boolean;
    80. begin
    81.   if LoginScreen() then
    82.   begin
    83.     if ((not UsernameFilledIn()) and (not PasswordFilledIn())) then
    84.     begin
    85.       MouseBox(USERNAME_BOX, MOUSE_LEFT);
    86.       Wait(69);
    87.       TypeString(USERNAME, False);
    88.       Wait(69);
    89.       PressKey(VK_TAB);
    90.       Wait(69);
    91.       TypeString(PASSWORD, True);
    92.       Result := WaitFunc(@LoginScreen, 2345, 234, False);
    93.     end;
    94.   end;
    95. end;
    96.  
    97. begin
    98.   ClearDebug();
    99.   DoLogin();
    100. end.
    Thank you very much, I'll try to read it and will do my best to understand all of it!

  8. #8
    Join Date
    Jul 2013
    Posts
    45
    Mentioned
    1 Post(s)
    Quoted
    16 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    Here is something super basic. Maybe I'll add more later.
    Simba Code:
    1. program new;
    2.  
    3. const
    4.   USERNAME = 'asdf';
    5.   PASSWORD = '1234';
    6.  
    7.   MOUSE_MOVE = 3;
    8.   LOGIN_TEXT_YELLOW = 7456488;
    9.   USERNAME_BOX: TBOX = [288, 235, 498, 259];
    10.   PASSWORD_BOX: TBOX = [288, 288, 498, 312];
    11.  
    12. function CountColor(const Color: Int32; b: TBox): Int32; Overload;
    13. begin
    14.   Result := CountColor(Color, b.x1, b.y1, b.x2, b.y2);
    15. end;
    16.  
    17. function CountColor(const Color: Int32): Int32; Overload;
    18. var
    19.   w, h: Int32;
    20. begin
    21.   GetClientDimensions(w, h);
    22.   Result := CountColor(Color, 0, 0, w-1, h-1);
    23. end;
    24.  
    25. procedure Wait(w1, w2: Int32); Overload;
    26. begin
    27.   Wait(Random(w1, w2));
    28. end;
    29.  
    30. function WaitFunc(Func: function: Boolean; WaitTime, WaitInterval: Int32; Condition: Boolean = True): Boolean;
    31. var
    32.   t: UInt32;
    33. begin
    34.   Result := (not Condition);
    35.   t := GetTickCount() + WaitTime;
    36.   repeat
    37.     Result := Func();
    38.     if (Result = Condition) then Exit(True);
    39.     Wait(WaitInterval);
    40.   until (GetTickCount() > t);
    41. end;
    42.  
    43. procedure Mouse(p: TPoint; Button: Int32);
    44. begin
    45.   MoveMouse(p.x, p.y);
    46.   if (Button = MOUSE_MOVE) then Exit();
    47.   Wait(14, 24);
    48.   HoldMouse(p.x, p.y, Button);
    49.   Wait(69, 96);
    50.   ReleaseMouse(p.x, p.y, Button);
    51. end;
    52.  
    53. procedure MouseBox(B: TBox; Button: Int32);
    54. begin
    55.   Mouse(MiddleBox(B), Button);
    56. end;
    57.  
    58. function LoginScreen(): Boolean;
    59. begin
    60.   Result := InRange(CountColor(LOGIN_TEXT_YELLOW), 690, 710);
    61. end;
    62.  
    63. function UsernameFilledIn(): Boolean;
    64. begin
    65.   Result := (CountColor($FFFFFF, USERNAME_BOX) > 0);
    66. end;
    67.  
    68. function PasswordFilledIn(): Boolean;
    69. begin
    70.   Result := (CountColor($FFFFFF, PASSWORD_BOX) > 0);
    71. end;
    72.  
    73. function DoLogin(): Boolean;
    74. begin
    75.   if LoginScreen() then
    76.   begin
    77.     if ((not UsernameFilledIn()) and (not PasswordFilledIn())) then
    78.     begin
    79.       MouseBox(USERNAME_BOX, MOUSE_LEFT);
    80.       Wait(69);
    81.       SendKeys(USERNAME, 69, 22);
    82.       Wait(69);
    83.       PressKey(VK_TAB);
    84.       Wait(69);
    85.       SendKeys(PASSWORD, 69, 22);
    86.       PressKey(VK_RETURN);
    87.       Result := WaitFunc(@LoginScreen, 2345, 234, False);
    88.     end;
    89.   end;
    90. end;
    91.  
    92. begin
    93.   ClearDebug();
    94.   DoLogin();
    95. 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();
    Code:
    New window: 6951286
    Compiled successfully in 500 ms.
    Successfully executed.
    It would be awesome if you could help me again

  9. #9
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by xX4m4zingXx View Post
    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();
    Code:
    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 and added some debug. You should be able to add some WriteLn's yourself though.

  10. #10
    Join Date
    Jul 2013
    Posts
    45
    Mentioned
    1 Post(s)
    Quoted
    16 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    Still works fine for me, but I edited my post 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?

  11. #11
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by xX4m4zingXx View Post
    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.

  12. #12
    Join Date
    Jul 2013
    Posts
    45
    Mentioned
    1 Post(s)
    Quoted
    16 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    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?

  13. #13
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by xX4m4zingXx View Post
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •