Simba Code:
{$I srl-6/srl.simba}
const
TASK = 'mix'; //clean or mix
USERNAME = '';
CLIENTNAME = 'Runique';
CLIENTWIDTH = 765;
CLIENTHEIGHT = 525;
dirtyHerbDTM = 'mQwAAAHicY2ZgYMgE4hQgTgbiXiDuBOI+IHa3kGQIcZZjcPDlZEAGjEgYCADVNgS+';
cleanHerbDTM = 'mbQAAAHicY2VgYHBnYmBwAmIvIPaBskUYGRj4oRjEFgNiz3BuBkUNVqAORgYHX04Gn2huBmyAEQsGAwAnYAQZ';
ingr_1DTM = 'mbQAAAHicY2VgYHBnYmBwAmIvIPaBskUYGRj4oRjEFgNiz3BuBkUNVqAORgYHX04Gn2huBmyAEQsGAwAnYAQZ';
ingr_2DTM = 'mQwAAAHicY2ZgYOgH4slA3A3E04B4IhT3T97BkJo9lWHn7tMMyIARCQMBAG3ECOo=';
finished_productDTM = 'mWAAAAHicY2FgYHBlYmDwBGJnIPYBYklGBgZxIBYFYgkgXtpszVAaq8WwuNEaqBoogAYY0TAIAAAj2AVO';
dialogColor = 128;
dialogCount = 473;
dialogTolerance = 0.05;
{
}
type
fnct_actionOptions = (ClickRight, ClickLeft, ClickMiddle, Move, Nothing);
TOptions = record
Str: string;
Bounds, BigBox: TBox;
end;
var
slots:TBoxArray;
bounds:Tbox;
rsClient:TSysProc;
dirtyHerb, cleanHerb, ingr_1, ingr_2, finished_product:integer;
procedure clickMouse2(button:integer);
begin
holdMouse(0, 0, button);
wait(50);
releaseMouse(0, 0, button);
wait(10);
end;
function boxCenter(bx: TBox): TPoint; begin if ((bx.X1 > bx.X2) or (bx.Y1 > bx.Y2)) then begin if(bx.X1 > bx.X2) then Swap(bx.X1, bx.X2); if (bx.Y1 > bx.Y2) then Swap(bx.Y1, bx.Y2); end; Result := Point(Round(bx.X1 + ((bx.X2 - bx.X1) div 2)), Round(bx.Y1 + ((bx.Y2 - bx.Y1) div 2))); end;
function explodeBox(bx: TBox; rows, columns: integer): TBoxArray; var r, c, w, h, ew, eh, ow, oh, i, x, y: integer; begin if ((rows > 0) and (columns > 0) and(bx.X1 <= bx.X2) and (bx.Y1 <= bx.Y2)) then begin w := ((bx.X2 - bx.X1) + 1); h := ((bx.Y2 - bx.Y1) + 1); if (rows < 1) then rows := 1 else if (rows > h) then rows := h; if (columns < 1) then columns := 1 else if (columns > w) then columns := w; w := (w div columns); h := (h div rows); ew := (((bx.X2 - bx.X1) + 1) - (w * columns)); eh := (((bx.Y2 - bx.Y1) + 1) - (h * rows)); SetLength(result, (rows * columns)); y :=bx.Y1;for r := 0 to (rows - 1) do begin x := bx.X1; if ((eh > 0) and (r < eh)) then oh := 1 else oh := 0; for c := 0 to (columns - 1) do begin if ((ew > 0) and (c < ew)) then ow := 1 else ow := 0; i := ((r * columns) + c); result[i].X1 := x; result[i].X2 := (x + (w - 1) + ow); result[i].Y1 := y; result[i].Y2 := (y + (h - 1) + oh); x := (Result[i].X2 + 1); end;y := (result[i].Y2 + 1); end; end else SetLength(result, 0); end;
function isText(Text, theText: TStringArray): Boolean;
var
i, k: Integer;
begin
for i := 0 to High(Text) do
for k := 0 to high(theText) do
if (Pos(Text[i], TheText[k]) > 0) then
exit(true);
end;
function getOptions(): Array of TOptions;
var
B, BB: TBox;
TPA, restpa, blacktpa, newtpa, merged: TPointArray;
ATPA, tempatpa, blackatpa, newatpa: T2DPointArray;
I, L, target, bmp, w, h: Integer;
BoxColors: TIntegerArray;
begin
target := GetImageTarget;
GetClientDimensions(B.X2, B.Y2);
B := IntToBox(0, 0, B.X2-1, B.Y2-1);
BoxColors := [4674653];
SetLength(ATPA, Length(BoxColors));
FindColors(tpa, 4674653, b);
If Length(tpa) < 100 Then
exit;
atpa := clusterTpa(tpa, 3);
for i := 0 to High(ATPA) do
begin
B := GetTPABounds(ATPA[i]);
if ((B.x2-B.x1) > 95) and ((B.y2-B.y1) > 18) then
Break
else
B := IntToBox(0, 0, 0, 0);
end;
If (B.x2 = 0) then
exit;
findcolors(blacktpa, 0, b);
if (length(blacktpa) < 1) then
exit;
blackatpa := clustertpa(blacktpa, 1);
for i := 0 to high(blackatpa) do
begin
b := gettpaBounds(blackatpa[i]);
if ((B.x2-B.x1) > 95) and ((B.y2-B.y1) > 16) then
break
else
b := inttobox(0, 0, 0, 0);
end;
findcolors(newtpa, 4674653, b);
if (length(newtpa) < 0) then
exit;
newatpa := clustertpa(newtpa, 1);
b := gettpaBounds(newatpa[0]);
findcolors(blacktpa, 0, b);
merged := mergeAtpa([blacktpa, newtpa]);
ReturnPointsNotInTPAWrap(merged, b, resTPA);
bmp := CreateBitmap(b.X2-B.X1+2, b.Y2-b.Y1+2);
OffsetTPA(restpa, Point(-B.X1, -B.Y1));
FastDrawClear(bmp, 0);
DrawTPABitmap(bmp, restpa, clRed);//Text
GetbitmapSize(bmp, w, h);
settargetbitmap(bmp);
SetLength(newatpa, H div 16);
for i := 0 to High(newatpa) do
FindColorsTolerance(newatpa[i], 255, 0, 2+i*15, W-1, 15+i*15, 0);
L := High(newatpa);
SortATPAFromFirstPointY(newatpa, Point(w div 2,0));
SetArrayLength(Result, Length(newatpa));
Result[0].BigBox := b;
for i := 0 to high(newatpa) do
begin
TPA := newatpa[i];
tempatpa := SplitTPAEx(TPA, 1, 10);
SortATPAFromFirstPointX(tempatpa, Point(0, 0));
Result[i].Str := GetTextATPA(tempatpa, 4, 'UpChars07'); //Writeln(Result[i].Str);
BB := GetTPABounds(newatpa[i]);
Result[i].Bounds := IntToBox(BB.X1+B.X1, BB.Y1+B.Y1, BB.X2+B.X1, BB.Y2+B.Y1);
setlength(tempatpa,0);
setlength(TPA,0);
end;
SetImageTarget(target);
FreeBitmap(bmp);
end;
function ArrInStr(arrS: TStringArray; str: string): Boolean;
var
I, L, H: Integer;
begin
Result := True;
L := Low(arrS); H := High(arrS);
for I := L to H do
if Pos(arrS[I], Str) > 0 then
Exit;
Result := False;
end;
function chooseOptionMulti(Texts: TStringArray; TextType: String; Action: fnct_ActionOptions): Boolean;
var
B: TBox;
i, H, x, R: Integer;
T: TPoint;
Options: array of TOptions;
begin
Result := False;
Options := getOptions();
if (Length(Options) < 1) then
Exit;
H := High(Options);
for i := 0 To H do
begin
if ArrInStr(Texts, Options[i].Str) then
begin
Result := True;
B := Options[i].Bounds;
GetMousePos(T.x, T.y);
R:= Min(((B.X2 - B.X1) shr 1), 5);
case Action of
ClickLeft:
if PointInBox(T, B) then
ClickMouse2(mouse_left)
else
Mouse(intToBox(B.x1 + R, B.Y1, B.x2 - R, B.Y1 + 5).getMiddle(), mouse_Left);
Move:
if not PointInBox(T, B) then
Mouse(intToBox(B.x1 + R, B.Y1, B.x2 - R, B.Y1 + 5).getMiddle(), mouse_move);
Nothing:
begin
end;
else
writeLn('ChooseOptionMultiEx ', ' ClickRight not a valid click for RS menus!');
end;
Exit;
end;
end;
B := Options[0].BigBox;
if Action <> Nothing then
begin
x := Max(B.X1 - 52, 0);
if x = 0 then
x := B.X2+10;
MoveMouse(0, 0);
Wait(200 + Random(100));
end;
end;
function chooseOptionMulti(Txt: TStringArray): Boolean; overload;
begin
Result := chooseOptionMulti(Txt, 'All', ClickLeft);
end;
function chooseOption2(Txt, TextType: string): Boolean;
begin
Result := chooseOptionMulti([Txt], TextType, ClickLeft);
end;
function chooseOption2(Txt: String): Boolean; overload;
begin
Result := chooseOptionMulti([Txt], 'All', ClickLeft);
end;
function waitOptionMulti(S: TStringArray; TextType: string; Action: fnct_ActionOptions; Time: Integer): Boolean;
var
T: Integer;
begin
Result := False;
T := GetSystemTime + Time;
while (GetSystemTime < T) do
begin
if (chooseOptionMulti(S, TextType, Action)) then
exit(true);
Wait(20 + Random(10));
end;
end;
function waitOptionMulti(S: TStringArray; Time: Integer): Boolean; overload;
begin
Result := waitOptionMulti(S, 'all', ClickLeft, Time);
end;
function waitOption(S: string; Time: Integer): Boolean; overload;
begin
Result := waitOptionMulti([s], 'all', ClickLeft, Time);
end;
procedure initInv();
begin
slots := explodeBox(bounds, 7, 4);
end;
function getSlot(slot:integer):Tbox;
begin
result := slots[slot];
end;
function slotFull(s:Integer):Boolean;
var
xee, yee:integer;
begin
result := FindColor(xee, yee, 65536, slots[s]);
end;
function Inventorycount:Integer;
var
i:Integer;
begin
for i := 0 to high(slots) do
if slotFull(i) then
result := result + 1;
end;
function Inventoryfull:Boolean;
begin
result := false;
exit(inventorycount = 28);
end;
procedure interactItem(constref slot, Button:Integer);
begin
if (slotFull(slot)) then
mouse(boxCenter(slots[slot]).x, boxCenter(slots[slot]).y, 0, 0, BUTTON);
end;
function InventoryDTMExists2(const DTM, slot:integer):boolean;
var
x, y:integer;
begin
try
result := findDTM(DTM, x, y, slots[slot].X1, slots[slot].y1, slots[slot].x2, slots[slot].y2);
except
writeln('[ERROR] function InventoryDTMExists(const DTM, slot:integer):boolean;');
writeln('Slots length:', length(slots));
// writeln('Current slot:', self.slots[slot]);
writeln('DTM:',DTM);
terminateScript();
//printexception;
end;
end;
function InventorycountDTM(const DTMSearch:Integer):Integer;
var
i:Integer;
begin
for i := 0 to high(slots) do
if (InventoryDTMExists2(dtmSearch, i)) then
result := result + 1;
end;
function InventorycountDTM(const DTMSearch:TIntegerArray):integer; overload;
var
i:integer;
begin
for i := 0 to high(DTMSearch) do
result := result + InventorycountDTM(DTMsearch[i]);
end;
function InventorysearchDTM(const DTMSearch:Integer;click, cont:Boolean;button:Integer):Boolean;
var
i:Integer;
begin
for i := 0 to high(slots) do
begin
if InventoryDTMExists2(dtmSearch, i) then
begin
result := true;
if click then
interactItem(i, button);
if not cont then
exit;
end;
end;
end;
function InventorysearchDTM(const DTMSearch:Integer;cont:Boolean;button:Integer):Boolean; overload;
var
I:Integer;
begin
result := false;
for i := 0 to high(slots) do
begin
if InventoryDTMExists2(dtmSearch, i) then
begin
result := true;
interactItem(i, button);
if not cont then
exit;
end;
end;
end;
function InventorysearchDTM(const DTMSearch:Integer;button:Integer):Boolean; overload;
var
I, x, y:Integer;
begin
result := false;
for i := 0 to high(slots) do
begin
if InventoryDTMExists2(dtmSearch, i) then
begin
interactItem(i, button);
exit(true);
end;
end;
end;
function InventorysearchDTM(const DTMSearch:TIntegerarray;button:Integer):boolean; overload;
var
i:integer;
begin
for i := 0 to high(DTMSearch) do
if InventorysearchDTM(DTMSearch[i], true, false, 1) then
exit(true);
end;
function string.contains(s: string): Boolean;
begin
if ((self <> '') and (s <> '')) then
result := (pos(s, self) > 0)
else
result := False;
end;
function activateRsClient(firstTime:boolean):boolean;
var
processes: TSysProcArr;
i: integer;
begin
result := false;
processes := GetProcesses();
if (firstTime) then
writeln('Scanning for ' , CLIENTNAME , 'Client..');
for i := 0 to high(processes) do
if (processes[i].title.contains(CLIENTNAME)) and (processes[i].width = CLIENTWIDTH) and (processes[i].height = CLIENTHEIGHT) then
begin
if (firstTime) then
begin
writeln('Found client');
writeln('Target set to: ' , toStr(processes[i]));
end;
rsClient := processes[i];
setTarget(processes[i]);
ActivateClient();
exit(true);
end;
end;
function getClientName():string;
begin
activateRsClient(false);
result := rsClient.title;
end;
function isLoggedIn():boolean; override;
begin
if (USERNAME = '') then
begin
writeln('Please enter a username at the top of the script');
terminateScript();
end else
result := getClientName().contains(USERNAME);
end;
function loginPlayer():boolean;
begin
writeln('logging in player');
end;
function dialogOpen():boolean;
var
textColorCount:integer;
begin
textColorCount := countColorTolerance(dialogColor, intToBox(152, 404, 376, 425), 0, colorSetting(1, 0.00, 0.00));
result := inRange(textColorCount, textColorCount * (1.00 - dialogTolerance), textColorCount * (1.00 + dialogTolerance));
end;
function getSimpleText(Colors:TIntegerArray;x1, y1, x2, y2:integer;font:string):String;
var
textTPA:TPointArray;
textATPA, textATPAS:T2DPointArray;
i:integer;
textStr:string;
begin
setLength(textATPAS, length(colors));
for i := 0 to high(colors) do
findColors(textATPAS[i], Colors[i], x1, y1, x2, y2);
textTPA := mergeATPA(textATPAS);
textATPA := SplitTPAEx(textTPA, 1, 10);
filtertpasbetween(textatpa, 0, 1);
SortATPAFromFirstPointX(textATPA, Point(0, 0));
result := getTextATPA(textATPA, 3, font);
end;
function bankOpen():boolean;
var
getStr:string;
begin
getStr := getSimpleText([2070783], 180, 65, 312, 84, 'UpChars07');
result := getStr.contains('Runique') or getStr.contains('Bank of');
end;
procedure bankAll();
begin
if bankOpen() then
mouse(Point(356, 348), 1);
end;
procedure closeBank();
begin
if bankOpen() then
mouse(Point(491, 75), 1);
end;
function findBank():boolean;
var
brownTPA, silverTPA:TPointArray;
brownATPA, silverATPA:T2DPointArray;
P:TPoint;
i:integer;
begin
if findColorstolerancE(brownTPA, 6057341, intToBox(4, 47, 520, 384), 16, colorSetting(2, 0.05, 0.70)) then
begin
brownATPA := clusterTPA(brownTPA, 10);
filterTPAsbetween(brownATPA, 0, 500);
for i := 0 to high(brownATPA) do
if findColorsTolerance(silverTPA, 11250613, brownATPA[i].getBounds(), 14, colorSetting(2, 0.15, 0.11)) then
begin
silverATPA := clusterTPA(silverTPA, 10);
for i := 0 to high(silverATPA) do
begin
p := silverATPA[i].getBounds().getMiddle();
mouse(p, 0);
if waitOption('Use', 1000) then
if waitFunc(@bankOpen, 40, 1500) then
exit(true)
else
begin
mouse(Point(0, 0), 0);
wait(100);
end;
end;
//debugATPABounds2(silverATPA);
end;
end;
end;
procedure cleanHerbs;
var
T:TTimeMarker;
begin
T.start();
repeat
inventorysearchDTM(dirtyHerb, true, mouse_left);
wait(random(100));
if (not isLoggedIn()) then
exit;
Until (T.getTotalTime() > 60000) or (inventorycountDTM(dirtyHerb) = 0);
end;
procedure mixPotions;
var
T:TTimeMarker;
begin
closeBank();
T.start();
if inventorysearchDTM(ingr_1, false, mouse_left) then
if inventorysearchDTM(ingr_2, false, mouse_left) then
if waitFunc(@dialogOpen, 40, 2500) then
begin
mouse(Point(267, 456), mouse_right);
if waitOption('ake All', 600) then
repeat
wait(50);
if (not isLoggedIn()) then
exit;
Until ((inventorycountDTM(ingr_1) = 0) or (inventorycountDTM(ingr_2) = 0) or (inventorycountDTM(finished_product) = 14) or (T.getTotalTime() > 200000));
end;
end;
function findBankDTM(searchFor:integer):boolean;
var
fx, fy:integer;
begin
if (not bankOpen()) then
exit(false)
else begin
if findDTM(searchFor, fx, fy, 34, 123, 470, 160) then
begin
moveMouse(fx + random(3), fy + random(3));
wait(200);
clickMouse2(mouse_right);
wait(200);
exit(true);
end;
end;
end;
procedure teleport(toWhere:string);
begin
end;
procedure withDraw();
var
mx, my:integer;
begin
if (inventorycount() > 0) then
bankAll();
wait(150);
if (TASK = 'clean') then
begin
if findBankDTM(dirtyHerb) then
begin
waitOption('draw All', 850);
wait(200);
end;
end else if (TASK = 'mix') then
begin
if findBankDTM(ingr_1) then
if (not waitOption('draw 14', 850)) then
begin
wait(350);
if findBankDTM(ingr_1) then
begin
if (not waitOption('draw X', 850)) then
exit
else
wait(1000);
typeSend('14');
wait(500);
end;
end;
if findBankDTM(ingr_2) then
begin
waitOption('draw 14', 750);
wait(500);
end;
end;
end;
procedure loadDTMs;
begin
dirtyHerb := DTMFromString(dirtyHerbDTM);
cleanHerb := DTMFromString(cleanHerbDTM);
ingr_1 := DTMFromString(ingr_1DTM);
ingr_2 := DTMFromString(ingr_2DTM);
finished_product := DTMFromString(finished_productDTM);
end;
procedure free;
begin
freeDTM(dirtyHerb);
freeDTM(cleanHerb);
freeDTM(ingr_1);
freeDTM(ingr_2);
freeDTM(finished_product);
end;
begin
loadDTMs;
addOnTerminate('free');
activateRsClient(true);
bounds := IntTobox(567, 259, 722, 506);
initInv();
repeat
wait(100);
if (not isLoggedIn) then
if (not loginPlayer()) then
begin
writeln('Did not login player waiting . . . ');
wait(4000);
end;
closeBank();
case TASK of
'clean':
begin
if (inventorycountDTM(dirtyHerb) = 28) then
cleanHerbs
else begin
if findBank() then
withDraw()
else
telePort('');
end;
end;
'mix':
begin
if (inventorycountDTM(ingr_1) + inventorycountDTM(ingr_2) <> 28) then
begin
if findBank() then
withDraw()
else
telePort('');
end else
mixPotions;
end;
end;
Until (isKeydown(113));
end.
@