-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMenu.simba
238 lines (209 loc) · 4.93 KB
/
Menu.simba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
{$include_once Internal/Reflection.simba}
{$include_once Mouse.simba}
{$include_once Timing.simba}
{*
R_MenuItems
~~~~~~~~~~~~~~~~~~~~~~
Returns an array of available menu actions.
Example:
Writeln(R_MenuItems);
*}
Function R_MenuItems: Array of String;
var
I, Count: Int32;
Menu: RSMenu;
Actions: Array of String;
Options: Array of String;
Action, Option: String;
begin
Menu := RSClient.Menu;
if Menu.ref = nil then
begin
Exit;
end;
Count := Menu.Count;
if Count > 0 then
begin
Actions := Menu.Actions;
Options := Menu.Options;
Count := Min(Count, Length(Actions));
Count := Min(Count, Length(Options));
if Count > 0 then
begin
for I := Count - 1 downto 0 do
begin
Action := StripHTML(Actions[I]);
Option := StripHTML(Options[I]);
if (Length(Action) = 0) and (Length(Option) = 0) then
break;
Result += Trim(Action + ' ' + Option);
end;
end;
end;
Menu.Free;
end;
{*
R_IsMenuOpen
~~~~~~~~~~~~~~~~~~~~~~
Returns true if the menu is open.
Example:
if R_IsMenuOpen then
...
*}
Function R_IsMenuOpen: Boolean;
begin
Result := RSClient.IsMenuOpen;
end;
{*
R_ChooseOptions
~~~~~~~~~~~~~~~~~~~~~~
Returns true if the menu is open and the specified options were selected.
Example:
if R_ChooseOptions(['Take bones'], True) then
...
*}
Function R_ChooseOptions(options: Array of String; caseSensitive: Boolean = True): Boolean;
var
T: Int64;
I, J, Offset: Int32;
X, Y: Int32;
Menu: RSMenu;
Items: Array of String;
Bounds, OptionBounds: TBox;
begin
T := GetTickCount();
while(not R_IsMenuOpen) do
begin
if GetTickCount() - T > 500 then
Exit(False);
Wait(50 + RandomRange(0, 100));
end;
Menu := RSClient.Menu;
if Menu.ref = nil then
begin
Exit;
end;
Items := R_MenuItems;
Bounds := Menu.Bounds;
Menu.Free;
For I := 0 To high(Items) do
begin
For J := 0 To high(Options) do
begin
If (caseSensitive and (Pos(Options[J], Items[I]) > 0)) or (not caseSensitive and (Pos(LowerCase(Options[J]), Lowercase(Items[I])) > 0)) then
begin
//The menu title is 21 in height.
//Each Item is 16 in height.
//The font of each item is 12 in height.
Offset := 21 + (I * 16); // + RandomRange(2, 10);
//Small characters are 4 pixels wide with a 4px offset from the left
OptionBounds := Box(Bounds.X1 + 4, Bounds.Y1 + Offset, Bounds.X1 + 4 + ((Length(Items[I]) * 4) - 4), Bounds.Y1 + Offset + 7);
Mouse.Move(OptionBounds);
GetMousePos(X, Y);
if PointInBox(Point(X, Y), OptionBounds) then
begin
Mouse.Click(MOUSE_LEFT);
Exit(True);
end;
end;
end;
end;
Result := False;
end;
{*
R_WaitChooseOptions
~~~~~~~~~~~~~~~~~~~~~~
Returns true if the menu is open and the specified options were selected within
the specified amount of time.
Example:
if R_WaitChooseOptions(['Take bones'], True, 240) then
...
*}
Function R_WaitChooseOptions(options: Array of String; caseSensitive: Boolean = True; timeout: UInt32): Boolean;
var
timer: Timer;
begin
timer.Start;
while (not R_ChooseOptions(options, caseSensitive)) do
begin
if timer.ElapsedTime >= timeout then
Exit(False);
Wait(50 + Random(50));
end;
Result := True;
end;
{*
R_Uptext
~~~~~~~~~~~~~~~~~~~~~~
Returns a string of the current uptext.
Example:
if (R_Uptext in UptextToClick) then
...
*}
Function R_Uptext: String;
var
Count: Int32;
Items: Array of String;
begin
Items := R_MenuItems;
if Length(Items) > 0 then
begin
Result := Items[0];
Count := Length(Items);
if (Count > 2) and (Result <> '') then
begin
Result += ' / ' + ToStr(Count - 2) + ' more options';
end;
end;
end;
{*
R_IsUptext
~~~~~~~~~~~~~~~~~~~~~~
Returns true if the uptext matches the specified options.
Example:
if R_IsUptext(['Take bones']) then
...
*}
Function R_IsUptext(options: Array of String; caseSensitive: Boolean = True): Boolean;
var
I: Int32;
T: Int64;
Uptext: String;
begin
T := GetTickCount();
while((Uptext := R_Uptext) = '') do
begin
If GetTickCount() - T > 1000 then
Exit(False);
Wait(50 + RandomRange(0, 100));
end;
For I := 0 to high(Options) do
begin
if (caseSensitive and (Pos(Options[I], Uptext) > 0)) or (not caseSensitive and (Pos(Lowercase(Options[I]), Lowercase(Uptext)) > 0)) then
begin
Exit(True);
end;
end;
end;
{*
R_WaitUptext
~~~~~~~~~~~~~~~~~~~~~~
Returns true if the uptext matches the specified options within the given
amount of time.
Example:
if R_WaitUptext(['Take bones'], False, 450) then
...
*}
Function R_WaitUptext(options: Array of String; caseSensitive: Boolean = True; timeout: UInt32): Boolean;
var
timer: Timer;
begin
timer.Start;
while (not R_IsUptext(options, caseSensitive)) do
begin
if timer.ElapsedTime >= timeout then
Exit(False);
Wait(50 + Random(50));
end;
Result := True;
end;