Code:
program soilScreener;
{$I SRL-6/SRL.simba} // To load the SRL include files
{$I SPS/lib/SPS-RS3.Simba}
{$loadlib libMufasaLayer}
type
thing = record
col: Integer;
tol: Integer;
cts: TColorSettings;
box: TBox;
end;
var
Layer, proggyLayer: TMufasaLayer;
itemAmount : integer;
lastBagSlot : thing;
bankChest : thing;
mapBankIcon :thing;
mesh : thing;
pntCenter := point(482, 549);
//Utilities
//Main process
procedure init(); forward;
procedure walkToMesh(); forward;
function login(): boolean; forward;
procedure SetupLayer; forward;
//
procedure setThing(var t : thing; col : integer; tol :integer; box : TBox; cts : TColorSettings); overload;
begin
t.box := box;
t.col := col;
t.tol := tol;
t.cts := cts;
end
procedure setThing(var t : thing; col : integer; tol :integer; box : TBox); overload;
begin
t.box := box;
t.col := col;
t.tol := tol;
end
procedure init()
begin
writeln('Initializing variables', lastBagSlot);
setThing(lastBagSlot, 2629131, 7, intToBox(836, 905, 870, 935));
setThing(bankChest, 7963601, 13, intToBox(290, 385, 704, 718), colorSetting(2, 0.05, 1.74));
setThing(mapBankIcon, 2203600, 9, intToBox(439, 98, 482, 141), colorSetting(2, 0.14, 0.92));
setThing(mesh, 12570338, 1, intToBox(90, 295, 737, 768), colorSetting(2, 0.48, 2.22));
itemAmount := 999;
SetupLayer;
end
function ras_countColor(t : thing) : integer
begin
result := CountColorTolerance(t.col, t.box, t.tol);
end
function ras_findColors(t : thing) : TPointArray;
var
TPA : TPointArray;
ATPA: T2DPointArray;
p := pntCenter;
begin
if (findColorsSpiralTolerance(pntCenter.X, pntCenter.Y, TPA, t.col , t.box , t.tol , t.cts )) then
begin
Layer.Bitmap.clearArea(intToBox(405,394,774,698));
Writeln('--Found total points : ', Length(TPA));
ATPA := TPA.Cluster(5);
ATPA.filterBetween(0, 100);
ATPA.sortFromMidPoint(pntCenter);
//ATPA.sortBySize();
Layer.Bitmap.debugATPA(ATPA);
Writeln('--Found clusters : ', Length(ATPA));
if (Length(ATPA)) > 0 then
begin
TPA := ATPA[0];
//TPA.fill();
Writeln('--Found object points : ', Length(TPA));
Layer.Bitmap.debugTPA(TPA, true);
end;
result := TPA;
end
end
function isBagFull() : boolean
var
s := ras_countColor(lastBagSlot);
begin
writeln('Found bag last slot colors: ', s);
result := s < 700;
end
function isNearBank() : boolean
begin
result := Length(ras_findColors(bankChest)) > 300;
end
procedure walkToBank()
var
TPA : TPointArray;
p : TPoint;
begin
if not isNearBank() then
begin
TPA := ras_findColors(mapBankIcon);
writeln('--Possible map bank points: ',Length(TPA));
if (Length(TPA) > 10) then
begin
p := TPA.getMiddle();
writeln('Trying to click: ', p);
mouseCircle(p.X, p.Y + 10, 3, MOUSE_LEFT);
mouseOffClient(OFF_CLIENT_LEFT, randomRange(1000, 2000));
waitFunc(@isNearBank, 300, 5000);
wait(1500);
end;
end;
end
function isBankOpen() : boolean
var
str : string;
begin
str := Tesseract_GetText(intToBox(415,225,466,245), TESS_FILTER_SMALL_CHARS);
writeln('Found bank text: ', str);
if containsMatch('BANK', str) > 0.70 then
begin
writeln('Bank is open: ', str);
result := true;
end
end
function isMeshOpen() : boolean
var
str : string;
begin
str := Tesseract_GetText(intToBox(257,377,343,395), TESS_FILTER_SMALL_CHARS);
writeln('Found mesh text: ', str);
if containsMatch('SCREENING', str) > 0.70 then
begin
writeln('Mesh is open: ', str);
result := true;
end
end
function openBank() : boolean
var
TPA : TPointArray;
p : TPoint;
begin
TPA := ras_findColors(bankChest);
writeln('--Possible bank points: ',Length(TPA));
if (Length(TPA) > 200) then
begin
Layer.Bitmap.debugTPA(TPA);
p := TPA.getMiddle();
writeln('Trying to click: ', p);
mouseCircle(p.X, p.Y, 5, MOUSE_LEFT);
end;
result := waitFunc(@isBankOpen,200,3000);
end
procedure reloadBag()
var
x, y: integer;
begin
itemAmount := getItemAmount(intToBox(153,298,189,333));
writeln('Found soils: ', itemAmount);
if (itemAmount > 0) then
begin
writeln('Reloading bag.');
mouse(649, 304, 7, 7, MOUSE_RIGHT);
getMousePos(x, y);
mouse(x, y + 44, 100, 4, MOUSE_LEFT);
Writeln('Filling Soil Box.');
mouse(773, 753, 7, 7, MOUSE_LEFT);
//typeByte(VK_F5);
Writeln('Loaded Soil.');
if(waitFunc(@isBankOpen,300,2000,false)) then
walkToMesh();
end
end
function doBanking() : boolean
begin
if openBank() then
begin
reloadBag();
end;
end;
function isNearMesh() : boolean
begin
result := (Length(ras_findColors(mesh)) > 100) and (not isNearBank());
end
procedure bank()
begin
writeln('Banking routine..');
login();
walkToBank();
if not isNearMesh() then
begin
doBanking();
end
end;
procedure walkToMesh()
begin
if (not isNearMesh()) then
begin
writeln('Walking to Mesh');
mouse(580, 223, 5, 5, MOUSE_LEFT);
waitFunc(@isNearMesh,300,12000);
end
end
function isScreening() : boolean
var
str : string;
begin
str := Tesseract_GetText(intToBox(419,407,507,426), TESS_FILTER_SMALL_CHARS);
writeln('Found mesh text: ', str);
if containsMatch('SCREENING', str) > 0.70 then
begin
writeln('Mesh is open: ', str);
result := true;
end
end
function isWalking() : boolean;
var
s : integer;
begin
s := getPixelShiftAverage(intToBox(513,160,545,191), 50, 300);
writeln('Walking pixel shift: ',s);
result:= s > 300;
end;
function getMeshPoint() : TPoint
var
TPA : TPointArray;
p : TPoint;
begin
TPA := ras_findColors(mesh);
writeln('--Possible mesh points: ',Length(TPA));
if (Length(TPA) > 50) then
begin
Layer.Bitmap.debugTPA(TPA);
p := TPA.getMiddle();
writeln('Found point: ', p);
result := p;
end;
end
function startScreen() : boolean
var
p : TPoint;
t : TTimeMarker;
begin
if isNearMesh() then
begin
writeln('Near mesh!');
if isWalking() then
begin
mouse(getMeshPoint(), MOUSE_MOVE, MOUSE_HUMAN);
wait(1000);
end;
t.reset();
t.start();
repeat
writeln('Trying to click..');
p := getMeshPoint();
mouse(p.X - 70, p.Y, 5, 5, MOUSE_LEFT);
until didClick(true, 500) or (t.getTime() > 3000) ;
if waitFunc(@isMeshOpen,200,4000) then
begin
mouse(595, 674, 80, 5, MOUSE_LEFT);
mouseOffClient(OFF_CLIENT_LEFT, randomRange(2000, 5000));
repeat
wait(200);
until not isScreening();
end else
begin
startScreen();
end;
end;
end
function screen() : boolean
begin
writeln('Screening routine..');
login();
if not isBagFull() then
begin
walkToMesh();
startScreen();
end else
begin
writeln('Bag is full..');
end;
end
procedure FreeLayer;
begin
Layer.Bitmap.Free;
Layer.Free;
end;
procedure SetupLayer;
var
W, H: Integer;
begin
GetClientDimensions(W, H);
Layer.Init(GetNativeWindow, True, PluginPath);
Layer.Bitmap.Init(Client.getMBitmaps());
Layer.Bitmap.SetPersistentMemory(PtrUInt(Layer.GetBitmapPtr(W, H)), W, H);
AddOnTerminate('FreeLayer');
end;
procedure proggy()
begin
Layer.Bitmap.drawText('Soils left: ' + intToStr(itemAmount), point(103, 732), upchars, false, clRed);
end;
function isReady() : boolean
var
str : string;
begin
str := Tesseract_GetText(intToBox(785,666,867,681), TESS_FILTER_SMALL_CHARS);
writeln('Found backpack text', str);
if containsMatch('BACKPACK', str) > 0.15 then
begin
writeln('Script ready: ', str);
result := true;
end
end
function lobbyPressPlay() : boolean
var
str : string;
begin
str := Tesseract_GetText(intToBox(230,533,277,577), TESS_FILTER_SMALL_CHARS);
writeln('Found lobby text: ', str);
if containsMatch('World', str) > 0.15 then
begin
writeln('Lobby is open: ', str);
mouse(484,562,70,6,MOUSE_LEFT);
result := waitFunc(@isReady,1000,20000);
end
end
procedure setupScreen()
begin
ActivateClient;
KeyDown(VK_UP);
wait(RandomRange(2000, 3000));
KeyUp(VK_UP);
end
function login() : boolean
begin
if lobbyPressPlay() then
begin
setupScreen();
end;
end
begin
init();
login();
setupScreen();
repeat
Layer.Bitmap.DrawClear(0);
proggy();
bank();
screen();
until itemAmount < 100;
end.