Results 1 to 3 of 3

Thread: [RS3] Reading UpText

  1. #1
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default [RS3] Reading UpText

    Since Jagex added classic top-left corner text ("UpText") in a recent update, I decided to try to write some functions that would read it.

    Mouse-over text can be annoying because the mouse-over box covers a lot of the screen. Sometimes this is a minor or nonexistent annoyance, such as when clicking objects on the mainScreen. Other times it's very frustrating, when doing activities that require precision, such as alching.

    Credits to go @slacky; for posting an example of SimpleOCR's usage (and SimpleOCR in general ). I used his filter.
    And also to @Brandon; for his tutorial on regex. Informative stuff.
    And also to @Coh3n;, the structure of my isUpText() function was modeled loosely after his isMouseOverText() function, which is already in SRL-6.

    The video (watch in 720p fullscreen! And don't worry about the account, it's a throwaway):



    The code:

    You can copy this into Simba and run it as-is. It will use your existing SRL-6 include and has the new functions built-in. Make sure you have UpText enabled!
    Alternatively, you can clone my fork of SRL-6, include it, and write something yourself.

    There's also a pull request on GitHub which might contain updated code.

    Simba Code:
    program UpTextTest;
    {$define smart}
    {$loadlib SimpleOCR}
    {$i srl-6/srl.simba}

    (*
    getUpText
    ~~~~~~~~~~~~~~~~

    .. code-block:: pascal

        function getUpText(): string;

    Returns the current UpText (the text in the top-left corner of the screen).

    .. note::

        - by slacky & KeepBotting
        - Last Modified: 27 February 2016 by KeepBotting

    Example:

    .. code-block:: pascal

        writeln(getUpText());
    *)

    function getUpText(): string;
    var
      ocr: TSimpleOCR;
      box: TBox := intToBox(4, 5, 500, 25);
      filter: TCompareRules := [-1, 85, true, 55];
    begin
      ocr.init(FontPath + 'UpCharsEx');
      ocr.clientID := exportImageTarget();
      exit(replaceRegExpr('[^a-zA-Z\d\s]', ocr.recognize(box, filter), '', true));
    end;

    (*
    isUpText
    ~~~~~~~~~~~~~~~

    .. code-block:: pascal

        function isUpText(txt: string; waitTime: integer = 100): boolean;

    Returns true if the string 'txt' is found in the current UpText.
    Will wait up to 'waitTime' to find the text before exiting the function.

    .. note::

        - by KeepBotting
        - Last Modified: 27 February 2016 by KeepBotting

    Example:

    .. code-block:: pascal

        if isUpText('Banker') then writeLn('Found the bank!');
    *)

    function isUpText(txt: string; waitTime: integer = 100): boolean;
    var
      t: TTimeMarker;
    begin
      t.start();

      repeat
        if (pos(txt, getUpText()) > 0) then exit(true);
        wait(20);
      until (t.getTime() > waitTime);
    end;

    (*
    isUpText
    ~~~~~~~~~~~~~~~

    .. code-block:: pascal

        function isUpText(txt: TStringArray; waitTime: integer = 100): boolean; overload;

    Overloaded function. Takes a TStringArray instead of a string.

    Returns true if any one of the indicies in 'txt' is found in the current UpText.
    Will wait up to 'waitTime' to find the text before exiting the function.

    .. note::

        - by KeepBotting
        - Last Modified: 27 February 2016 by KeepBotting

    Example:

    .. code-block:: pascal

        if isUpText(['Bank', 'Banker', 'Booth']) then writeLn('Found the bank!');
    *)

    function isUpText(txt: TStringArray; waitTime: integer = 100): boolean; overload;
    var
      i: integer;
      t: TTimeMarker;
    begin
      t.start();

      repeat
        for i := 0 to high(txt) do
          if (pos(txt[i], getUpText()) > 0) then exit(true);
        wait(20);
      until (t.getTime() > waitTime);
    end;

    begin
      smartShowConsole := false;

      setupSRL();

      while (true) do
      begin
        wait(1000);
        writeLn(getUpText());
      end;
    end.

    Right now, the function strips all non-alphanumeric characters. That's what causes some of the weird results you see in the video, like "Customisekeybind" ("Customise-keybind") and "openclose" ("open/close").

    I know how to exempt characters from being matched by the regex, but I personally don't see a need for it as long as the function returns a predictable result. The only non-alphanumeric characters I guess people might want are "-" and "/" which would be easy to add.

    As you can see from the video the function is a little unpredictable when reading players' UpText. But you could still match it with enough foresight and proper parameters, e.g. using an array of many possible strings instead of one giant string.

    I rotate the camera a lot so you can see how the function performs reading text from many different backgrounds.
    Last edited by KeepBotting; 02-28-2016 at 04:47 AM.
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Badâ„¢ before everyone gets laser pistols

  2. #2
    Join Date
    Dec 2011
    Posts
    2,147
    Mentioned
    221 Post(s)
    Quoted
    1068 Post(s)

  3. #3
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Quote Originally Posted by Clarity View Post
    Sweet, great addition to the include. Glad they added this back in - the hover text would always cause some issues blocking stuff on the mainscreen.
    Yeah! The hugest problem I had with it was when alching. The mouse-over box would cover a lot of the inventory and could throw off DTM recognition, counting item amounts, counting inventory items, any number of things...
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Badâ„¢ before everyone gets laser pistols

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
  •