Skip to content

Commit 1b9fbed

Browse files
committed
feat: add a proof of concept tooltip reader
- it's bugged in java clients due to an OCR bug
1 parent 79d1d67 commit 1b9fbed

2 files changed

Lines changed: 49 additions & 10 deletions

File tree

osrs/rsclient.simba

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ begin
7474
ITEM_SHADOW := $323232;
7575
ITEM_SHADOW_GRAY := $323232;
7676
ITEM_BORDER := $000000;
77+
TEXT_SHADOW := $010000;
7778
ITEM_BORDER_WHITE := $FEFEFE;
7879
Exit(ERSClient.OFFICIAL);
7980
end;
@@ -325,6 +326,46 @@ begin
325326
Result := SleepUntil(Self.IsLoggedIn(), interval, time);
326327
end;
327328

329+
330+
(*
331+
## RSClient.ReadTooltip
332+
```pascal
333+
function TRSClient.ReadTooltip(): String;
334+
```
335+
Attempts to read the client tooltip if it's present.
336+
337+
Example:
338+
```pascal
339+
WriteLn RSClient.ReadTooltip();
340+
```
341+
*)
342+
function TRSClient.ReadTooltip(): String;
343+
var
344+
pt: TPoint;
345+
b: TBox;
346+
tpa: TPointArray;
347+
begin
348+
pt := Target.MouseXY;
349+
with Self._Bounds() do
350+
begin
351+
if not Contains(pt) then
352+
Exit;
353+
b := [Max(X1, pt.X)+4, Max(Y1, pt.Y+24)+5, X2, Min(Y2, pt.Y + 45)];
354+
end;
355+
356+
tpa := Target.FindColor(TEXT_SHADOW, 0, b);
357+
if tpa = [] then
358+
Exit;
359+
360+
tpa := tpa.Cluster(6,4).SortFromFirstPointX(pt).First;
361+
b.X2 := tpa.Bounds().X2;
362+
case RSClient.Client of
363+
ERSClient.OFFICIAL: Result := OCR.RecognizeShadow(b, RSFonts.PLAIN_12, 0);
364+
ERSClient.RUNELITE, ERSClient.LEGACY: Result := OCR.RecognizeShadow(b, RSFonts.PLAIN_11, 0);
365+
end;
366+
end;
367+
368+
328369
var
329370
(*
330371
## RSClient variable

utils/ocr.simba

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ This page is about WaspLib's OCR.
66
{$DEFINE WL_OCR_INCLUDED}
77
{$INCLUDE_ONCE WaspLib/utils.simba}
88

9+
var
10+
TEXT_SHADOW: TColor = $000000;
11+
912
type
1013
(*
1114
## TOCR
@@ -93,7 +96,7 @@ var
9396
colors: TColorArray;
9497
begin
9598
img := Target.GetImage(bounds);
96-
shadows := img.FindColor($0, 2.5, [1, 1, img.Width - 1, img.Height - 1]);
99+
shadows := img.FindColor(TEXT_SHADOW, 0, [1, 1, img.Width - 1, img.Height - 1]);
97100
shadows := shadows.Offset([-1,-1]).ExcludePoints(shadows);
98101

99102
colors := img.GetColors(shadows).Unique();
@@ -145,15 +148,10 @@ type
145148
Record containing pre-loaded RuneScape fonts and common text colors.
146149
*)
147150
TRSFonts = record
148-
PLAIN_11: TPixelFont;
149-
PLAIN_12: TPixelFont;
150-
BOLD: TPixelFont;
151-
BOLD_SHADOW: TPixelFont;
152-
QUILL_8: TPixelFont;
153-
QUILL: TPixelFont;
154-
VERDANA_13: TPixelFont;
155-
VERDANA_13_Bold:TPixelFont;
156-
VERDANA_15: TPixelFont;
151+
PLAIN_11, PLAIN_12,
152+
BOLD, BOLD_SHADOW,
153+
QUILL_8, QUILL,
154+
VERDANA_13, VERDANA_13_BOLD, VERDANA_15: TPixelFont;
157155
Unzipping: Boolean;
158156
Timeout: TCountDown;
159157

0 commit comments

Comments
 (0)