Skip to content

Commit 48dc345

Browse files
committed
feat: read notes
- removed simpleocr in favour of the built-in pixelocr. Nothing was tested. -
1 parent 5090f6a commit 48dc345

File tree

16 files changed

+179
-139
lines changed

16 files changed

+179
-139
lines changed

.github/workflows/version.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ on:
88

99
jobs:
1010
version:
11-
if: >
12-
${{ github.event.workflow_run.conclusion == 'success' &&
13-
github.event.workflow_run.event == 'push' }} # Only run if Tests succeeded and was triggered by a push
11+
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' }}
1412
runs-on: ubuntu-latest
1513

1614
steps:

osrs/interfaces/chat/chat.simba

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ begin
9898
b.X2 := b.X1 + Self.InputLine.Width div 4;
9999
b.Y2 := Self.InputLine.Y2;
100100

101-
Result := OCR.RecognizeStatic(b, TOCRColorFilter.Create([$FFFFFF, $000000]), RSFonts.PLAIN_12);
101+
Result := OCR.RecognizeStatic(b, OCR.PLAIN_12, [$FFFFFF, $000000], 0);
102102

103103
if ':' in Result then
104104
Result := Result.Before(':');
@@ -170,17 +170,13 @@ end;
170170

171171

172172
function TRSChat.GetQuery(): String;
173-
const
174-
FILTER: TOCRColorFilter := TOCRColorFilter.Create([$000000]);
175173
begin
176-
Result := OCR.Recognize(Self.Bounds, FILTER, RSFonts.BOLD_12);
174+
Result := OCR.Recognize(Self.Bounds, OCR.BOLD, [$0], 0);
177175
end;
178176

179177
function TRSChat.GetQueryAnswer(): String;
180-
var
181-
FILTER: TOCRColorFilter := TOCRColorFilter.Create([8388608]);
182178
begin
183-
Result := OCR.Recognize(Self.Bounds, FILTER, RSFonts.BOLD_12);
179+
Result := OCR.Recognize(Self.Bounds, OCR.BOLD, [$800000], 0);
184180
end;
185181

186182
function TRSChat.FindQuery(query: String; caseSensitive: Boolean = False): Boolean;
@@ -232,7 +228,7 @@ begin
232228
tpa += Target.FindColor(colors[i], 0, Self.Bounds);
233229

234230
b := tpa.Bounds();
235-
strings := OCR.RecognizeLines(b, TOCRColorFilter.Create(colors), RSFonts.QUILL_8);
231+
strings := OCR.RecognizeLines(b, OCR.QUILL_8, colors, 0);
236232

237233
boxes := b.Partition(strings.Length, 1);
238234

osrs/interfaces/chooseoption.simba

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Core record responsible with interacting with the choose option context menu.
3636
*)
3737
TRSChooseOption = record
3838
Bounds: TBox;
39-
OCRFilter: TOCRInvertColorFilter;
4039
const TitleImg: TImage = ImageFromString('IMG:AQAAAGYAAAASAAAAAAAAAP21aQABAAAAIKprAAEAAADI5D8BAAAAAM0CAQABAAAAOIe7BgAAAAAApLsGAAAAADQBAACYAQAAOIe7BgAAAAABAAAAZgAAABIAAAAYAAAAAAAAAAAAAAAAAAAAAwAAABgIEAgICAAAAAEAAAIAAAAAAAAAAAAAAAAAAAAAiVBORw0KGgoAAAANSUhEUgAAAGYAAAASCAIAAAAmDjziAAAAzUlEQVR4nO2U0Q2AMAhE3c4F/HX/NYzxo9oWvAO0mkBqoqTA9Qmd1mXORa1pf9IoS2S0JTLaWmRlaK+ed3X1rdU2RkT1eXjOysarvMoA9TwlG+mmLyAzNH4iC0AWcxAcWfce8fjb0sqRdGSenEpUP5BCVu3xvEs4wE63lcOjtEuTHUwnJuXH4hpspf3iSxZJVkglPCcyRGZJkeKlpFGYPMMohRjwRYpvXdTgSN2hDODtfgUfG1s5EfEWZL8zsEkj671X7BlLZLQNQJaLWhvxdfuwwsTSHQAAAABJRU5ErkJggg==');
4140
end;
4241

@@ -108,19 +107,6 @@ begin
108107
Result := Self.WaitOpen(600);
109108
end;
110109

111-
(*
112-
## ChooseOption.Setup
113-
```pascal
114-
procedure TRSChooseOption.Setup();
115-
```
116-
TRSChooseOption setup method.
117-
This is responsible for loading the needed bitmaps into memory and is automatically called for you when a script is ran so you
118-
don't have to call it.
119-
*)
120-
procedure TRSChooseOption.Setup();
121-
begin
122-
Self.OCRFilter := TOCRInvertColorFilter.Create([4674653, 0]);
123-
end;
124110

125111
(*
126112
## ChooseOption.GetOptions
@@ -149,7 +135,7 @@ begin
149135
b.Y2 := b.Y1 + 15;
150136
if b.Y2 > Self.Bounds.Y2 then Exit;
151137

152-
Result[i].Text := OCR.RecognizeStatic(b, Self.OCRFilter, RSFonts.BOLD_12_SHADOW);
138+
Result[i].Text := OCR.RecognizeStatic(b, OCR.BOLD_SHADOW, [$47545D, $0], 0);
153139
Result[i].Bounds := b;
154140
end;
155141
end;
@@ -221,7 +207,7 @@ begin
221207
option.Bounds.Y2 := option.Bounds.Y1 + 15;
222208
if option.Bounds.Y2 > Self.Bounds.Y2 then Exit;
223209

224-
option.Text := OCR.RecognizeStatic(option.Bounds, Self.OCRFilter, RSFonts.BOLD_12_SHADOW);
210+
option.Text := OCR.RecognizeStatic(option.Bounds, OCR.BOLD_SHADOW, [$47545D, $0], 0);
225211

226212
if option.Text.ContainsAny(text, caseSensitive) then
227213
Exit(True);
@@ -321,6 +307,3 @@ var
321307
Global TRSChooseOption variable.
322308
*)
323309
ChooseOption: TRSChooseOption;
324-
begin
325-
ChooseOption.Setup();
326-
end;

osrs/interfaces/gametabs/stats.simba

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,13 @@ end;
4343
(*
4444
(TRSStats)=
4545
## type TRSStats
46-
```pascal
47-
TRSStats = record
48-
Levels: array [ERSSkill] of Integer;
49-
Skills: TBoxArray;
50-
StatsOCR, InfoOCR: TOCRColorFilter;
51-
end;
52-
```
46+
Main record used to interact with the stats gametab.
5347
*)
5448
TRSStats = record
5549
Levels: array [ERSSkill] of Integer;
5650
Skills: TBoxArray;
57-
StatsOCR, InfoOCR: TOCRColorFilter;
5851
end;
5952

60-
(*
61-
## Stats.Setup()
62-
```pascal
63-
procedure TRSStats.Setup(); override;
64-
```
65-
Internal method responsible for setting up Stats.
66-
It's automatically called for you when the file is included.
67-
*)
68-
procedure TRSStats.Setup();
69-
begin
70-
Self.StatsOCR := TOCRColorFilter.Create([65535]);
71-
Self.InfoOCR := TOCRColorFilter.Create([0]);
72-
end;
73-
74-
7553
(*
7654
## Stats.SetupInterface
7755
```pascal
@@ -161,7 +139,7 @@ begin
161139
if lines = [] then Exit;
162140

163141
for i := 0 to High(lines) do
164-
lines[i] := OCR.Recognize([b.X1, b.Y1 + (i * 12), b.X2, b.Y1 + ((i+1) * 12) + 3], Self.InfoOCR, RSFonts.PLAIN_12);
142+
lines[i] := OCR.Recognize([b.X1, b.Y1 + (i * 12), b.X2, b.Y1 + ((i+1) * 12) + 3], OCR.PLAIN_12, [0], 0);
165143

166144
if not (ToStr(skill).Capitalize() in lines[0]) then Exit;
167145

@@ -220,7 +198,7 @@ begin
220198
if not Self.Open() then Exit(-1);
221199

222200
with Self.Skills[skill] do
223-
Result := OCR.RecognizeNumber([X1, Y2 - (Height div 2), X2, Y2], Self.StatsOCR, RSFonts.PLAIN_11);
201+
Result := OCR.RecognizeNumber([X1, Y2 - (Height div 2), X2, Y2], OCR.PLAIN_11, [RSColors.STACK_YELLOW], 0);
224202

225203
if Result > 0 then
226204
Self.Levels[skill] := Result;
@@ -268,7 +246,3 @@ var
268246
Global TRSStats variable.
269247
*)
270248
Stats: TRSStats;
271-
272-
begin
273-
Stats.Setup();
274-
end;

osrs/interfaces/interface.simba

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ end;
4343
type
4444
TRSInterfaceTitle = record
4545
Bounds, CloseButton: TBox;
46-
TitleOCR: TOCRInvertColorFilter;
4746
end;
4847

4948
procedure TRSInterfaceTitle.Setup(const bounds: TBox);
@@ -57,8 +56,6 @@ begin
5756
Self.CloseButton.Y1 := bounds.Y1+8;
5857
Self.CloseButton.X2 := bounds.X2-7;
5958
Self.CloseButton.Y2 := bounds.Y1+28;
60-
61-
Self.TitleOCR := TOCRInvertColorFilter.Create([3358536, 0], [5, 0]) ;
6259
end;
6360

6461

@@ -76,12 +73,12 @@ end;
7673

7774
function TRSInterfaceTitle.GetTitle(): String;
7875
begin
79-
Result := OCR.Recognize(Self.Bounds, Self.TitleOCR, RSFonts.BOLD_12);
76+
Result := OCR.Recognize(Self.Bounds, OCR.BOLD, [RSColors.TEXT_ORANGE, $0], 0);
8077
end;
8178

8279
function TRSInterfaceTitle.IsTitle(const text: String; const similarity: Single = 0.8): Boolean;
8380
begin
84-
Result := OCR.Locate(Self.Bounds, text, RSFonts.BOLD_12, Self.TitleOCR) >= similarity;
81+
Result := OCR.LocateInvert(Self.Bounds, text, [$344049,0], 2, OCR.BOLD) >= similarity;
8582
end;
8683

8784
function TRSInterfaceTitle.WaitTitle(const text: String; const similarity: Single = 0.8; const time: Integer = 600; interval: Integer = -1): Boolean; overload;

osrs/interfaces/login.simba

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
type
77
TRSLoginLobby = record
88
Bounds, Button: TBox;
9-
OCRFilter: TOCRColorFilter;
109
end;
1110

1211
procedure TRSLoginLobby.Setup();
1312
begin
14-
Self.OCRFilter := TOCRColorFilter.Create([$FFFFFF]);
15-
1613
Self.Bounds.X1 := Target.Bounds.Width div 2 - 382;
1714
Self.Bounds.X2 := Target.Bounds.Width div 2 + 382;
1815
Self.Bounds.Y1 := Target.Bounds.Y1;
@@ -30,7 +27,7 @@ end;
3027

3128
function TRSLoginLobby.IsOpen(): Boolean;
3229
begin
33-
Result := 1 = OCR.Locate(Self.Button, 'CLICK HERE TO PLAY', RSFonts.BOLD_12_SHADOW,Self.OCRFilter);
30+
Result := OCR.Locate(Self.Button, 'CLICK HERE TO PLAY', [$FFFFFF], 0, OCR.BOLD_SHADOW) > 0.999;
3431
end;
3532

3633
function TRSLoginLobby.WaitOpen(const time: Integer = 600; interval: Integer = -1): Boolean;
@@ -67,7 +64,6 @@ type
6764
TRSLoginWorldSwitcher = record
6865
Bounds: TBox;
6966
OpenButton, CancelButton: TBox;
70-
CurrentOCRFilter, WorldOCRFilter: TOCRColorFilter;
7167
CurrentWorld: Integer;
7268
WorldBoxes: TBoxArray;
7369

@@ -76,9 +72,6 @@ type
7672

7773
procedure TRSLoginWorldSwitcher.Setup();
7874
begin
79-
Self.CurrentOCRFilter := TOCRColorFilter.Create([$FFFFFF]);
80-
Self.WorldOCRFilter := TOCRColorFilter.Create([$000000, $0000FF]);
81-
8275
Self.Bounds.X1 := Target.Bounds.Width div 2 - 382;
8376
Self.Bounds.X2 := Target.Bounds.Width div 2 + 382;
8477
Self.Bounds.Y1 := Target.Bounds.Y1;
@@ -142,7 +135,7 @@ end;
142135

143136
function TRSLoginWorldSwitcher.Read(index: Integer): Integer;
144137
begin
145-
Result := OCR.RecognizeNumber(Self.WorldBoxes[index], Self.WorldOCRFilter, RSFonts.BOLD_12);
138+
Result := OCR.RecognizeNumber(Self.WorldBoxes[index], OCR.BOLD, [$000000, $0000FF], 0);
146139
end;
147140

148141

@@ -172,7 +165,7 @@ end;
172165
function TRSLoginWorldSwitcher.GetCurrent(): Integer;
173166
begin
174167
if not Self.Close() then Exit;
175-
Result := OCR.RecognizeNumber(Self.OpenButton, Self.CurrentOCRFilter, RSFonts.BOLD_12_SHADOW);
168+
Result := OCR.RecognizeNumber(Self.OpenButton, OCR.BOLD_SHADOW, [$FFFFFF], 0);
176169
if InRange(Self.CurrentWorld, 301, 580) then Self.CurrentWorld := Result;
177170
end;
178171

@@ -181,7 +174,7 @@ function TRSLoginWorldSwitcher.Find(world: Integer; out index: Integer): Boolean
181174
begin
182175
repeat
183176
for index := 0 to High(Self.WorldBoxes) do
184-
if OCR.RecognizeNumber(Self.WorldBoxes[index], Self.WorldOCRFilter, RSFonts.BOLD_12) = world then
177+
if OCR.RecognizeNumber(Self.WorldBoxes[index], OCR.BOLD, [$000000, $0000FF], 0) = world then
185178
Exit(True);
186179
until not Self.NextPage();
187180

@@ -249,9 +242,7 @@ type
249242
TRSLogin = record
250243
Lobby: TRSLoginLobby;
251244
WorldSwitcher: TRSLoginWorldSwitcher;
252-
253245
Bounds: TBox;
254-
WhiteOCR, YellowOCR: TOCRColorFilter;
255246

256247
Inputs: array [ERSLoginInput] of TBox;
257248
Buttons: array [ERSLoginButton] of record
@@ -270,9 +261,6 @@ begin
270261
Self.WorldSwitcher.Setup();
271262
Self.Lobby.Setup();
272263

273-
Self.WhiteOCR := TOCRColorFilter.Create([$FFFFFF]);
274-
Self.YellowOCR := TOCRColorFilter.Create([$00FFFF]);
275-
276264
Self.Bounds.X1 := Target.Bounds.Width div 2 - 176;
277265
Self.Bounds.Y1 := Target.Bounds.Y1 + 172;
278266
Self.Bounds.X2 := Target.Bounds.Width div 2 + 176;
@@ -354,9 +342,9 @@ begin
354342
end;
355343

356344
if Self.Buttons[button].Bold then
357-
Result := Self.Buttons[button].Text = OCR.Recognize(Self.Buttons[button].Bounds, Self.WhiteOCR, RSFonts.BOLD_12_SHADOW)
358-
else
359-
Result := Self.Buttons[button].Text = OCR.Recognize(Self.Buttons[button].Bounds, Self.WhiteOCR, RSFonts.PLAIN_12);
345+
Exit(Self.Buttons[button].Text = OCR.Recognize(Self.Buttons[button].Bounds, OCR.BOLD_SHADOW, [$FFFFFF], 0));
346+
347+
Result := Self.Buttons[button].Text = OCR.Recognize(Self.Buttons[button].Bounds, OCR.PLAIN_12, [$FFFFFF], 0);
360348
end;
361349

362350
function TRSLogin.ClickButton(button: ERSLoginButton): Boolean;
@@ -410,9 +398,9 @@ function TRSLogin.GetMessage(): ERSLoginMessage;
410398
var
411399
dialog: String;
412400
begin
413-
dialog := OCR.RecognizeLines(Self.Bounds, Self.YellowOCR, RSFonts.BOLD_12_SHADOW).Join(' ');
401+
dialog := OCR.RecognizeLines(Self.Bounds, OCR.BOLD_SHADOW, [$00FFFF], 0).Join(' ');
414402
if dialog = '' then
415-
dialog := OCR.RecognizeLines(Self.Bounds, Self.WhiteOCR, RSFonts.BOLD_12_SHADOW).Join(' ');
403+
dialog := OCR.RecognizeLines(Self.Bounds, OCR.BOLD_SHADOW, [$FFFFFF], 0).Join(' ');
416404
if dialog = '' then Exit;
417405

418406
for Result := ERSLoginMessage.WELCOME to High(ERSLoginMessage)-1 do

osrs/interfaces/mainscreen/mainscreen.simba

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ type
1717
TopLeft, TopRight, BottomRight, BottomLeft: TPoint;
1818

1919
UpTextImageBuffer: TImage;
20-
UpTextBox: TBox;
21-
UpTextFilter: TOCRFilter;
20+
UptextBounds: TBox;
21+
UptextOCR: TPixelOCR;
2222

2323
HighestPitch: Boolean;
2424
end;
2525

2626
procedure TRSMainScreen.Setup();
2727
begin
28-
Self.UptextFilter := TOCRAnyColorFilter.Create(85, 60);
29-
Self.UptextFilter.Blacklist := ',.'+#39+#34;
28+
Self.UptextOCR.Tolerance := 25;
29+
Self.UptextOCR.ShadowTolerance := 65;
30+
Self.UptextOCR.Whitelist := ['a'..'z', 'A'..'Z', '0'..'9', '-', '>', '(', ')', '/'];
3031
end;
3132

3233
procedure TRSMainScreen.SetupInterface();
@@ -44,20 +45,20 @@ begin
4445
Self.BottomRight := Self.Bounds.BottomRight;
4546
Self.BottomLeft := Self.Bounds.BottomLeft;
4647

47-
Self.UpTextBox.X1 := Self.Bounds.X1 + 3;
48-
Self.UpTextBox.Y1 := Self.Bounds.Y1 + 3;
49-
Self.UpTextBox.X2 := Self.Bounds.X1 + 500;
50-
Self.UpTextBox.Y2 := Self.Bounds.Y1 + 21;
48+
Self.UptextBounds.X1 := Self.Bounds.X1 + 3;
49+
Self.UptextBounds.Y1 := Self.Bounds.Y1 + 3;
50+
Self.UptextBounds.X2 := Self.Bounds.X1 + 500;
51+
Self.UptextBounds.Y2 := Self.Bounds.Y1 + 21;
5152
end;
5253

5354

5455
function TRSMainScreen.GetUpText(): String;
56+
var
57+
img: TImage;
5558
begin
56-
if RSClient.Mode = ERSClientMode.FIXED then
57-
Result := OCR.RecognizeStatic(Self.UpTextBox, Self.UptextFilter, RSFonts.BOLD_12_SHADOW)
58-
else
59-
Result := OCR.RecognizeStatic(Self.UpTextBox, Self.UptextFilter, RSFonts.BOLD_12_SHADOW);
60-
59+
img := TImage.CreateFromTarget(Self.UptextBounds);
60+
Result := Self.UptextOCR.Recognize(img, OCR.BOLD_SHADOW, [0,0]);
61+
img.Free();
6162
{$IFDEF DEBUG_UPTEXT}
6263
WriteLn GetDebugLn('MainScreen', 'UpText: ' + Result);
6364
{$ENDIF}

osrs/interfaces/minimap.simba

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ type
2121
Center: TPoint;
2222
Polygon: TPolygon;
2323

24-
OrbOCR: TOCRShadowFilter;
25-
2624
Compass: record
2725
PreviousRadians: Single;
2826
Circle: TCircle;
@@ -270,7 +268,6 @@ begin
270268
until GetTickCount() > timeout;
271269

272270
WriteLn GetDebugLn('Minimap', 'SetCompassAngle timed out.', EErrorLevel.WARN);
273-
274271
//TODO:
275272
//if not RSClient.IsLoggedIn() then
276273
// Login.LoginPlayer()
@@ -306,7 +303,9 @@ WriteLn Minimap.GetLevel(ERSMinimapOrb.PRAYER);
306303
*)
307304
function TRSMinimap.GetLevel(orb: ERSMinimapOrb): Integer;
308305
begin
309-
Result := OCR.RecognizeNumber([Self.Orbs[orb].X-35, Self.Orbs[orb].Y-1, Self.Orbs[orb].X-15, Self.Orbs[orb].Y+9], Self.OrbOCR, RSFonts.PLAIN_11);
306+
raise GetDebugLn('Minimap.GetLevel' , 'TODO');
307+
//TODO:
308+
//Result := OCR.RecognizeNumber([Self.Orbs[orb].X-35, Self.Orbs[orb].Y-1, Self.Orbs[orb].X-15, Self.Orbs[orb].Y+9], Self.OrbOCR, RSFonts.PLAIN_11);
310309
end;
311310

312311

@@ -750,7 +749,3 @@ var
750749
Global TRSMinimap variable.
751750
*)
752751
Minimap: TRSMinimap;
753-
754-
begin
755-
Minimap.OrbOCR := TOCRShadowFilter.Create();
756-
end;

0 commit comments

Comments
 (0)