program SpawnPKThiever;
//for best results, face camera south and zoom in a bit
const
STOP_KEY = 130; //choose a key to stop the script
MOUSE_MOVE = 3;
MSX1 = 8;
MSY1 = 33;
MSX2 = 518;
MSY2 = 366;
MSBOX: TBox = [MSX1, MSY1, MSX2, MSY2];
MSCX = (MSX2 - MSX1) div 2;
MSCY = (MSY2 - MSY1) div 2;
MSCP: TPoint = [MSCX, MSCY];
var
_w, _h, Level: Int32;
CashTimer: UInt32;
function FindColors(var TPA: TPointArray; Color: Int32; b: TBox): Boolean; Overload;
begin
Result := FindColors(TPA, Color, b.x1, b.y1, b.x2, b.y2);
end;
function FindColors(var TPA: TPointArray; Color: Int32): Boolean; Overload;
var
w, h: Int32;
begin
GetClientDimensions(w, h);
Result := FindColors(TPA, Color, 0, 0, w-1, h-1);
end;
procedure Wait(w1, w2: Int32); Overload;
begin
Wait(Random(w1, w2));
end;
procedure FastClick(Button: Byte);
var
x, y: integer;
begin
GetMousePos(x, y);
HoldMouse(x, y, Button);
Wait(80, 100);
ReleaseMouse(x, y, Button);
end;
procedure Mouse(P: TPoint; Button: Byte);
begin
MoveMouse(P.X, P.Y);
if (Button = MOUSE_MOVE) then Exit;
Wait(20, 30);
FastClick(Button);
end;
procedure Mouse(X, Y: Int32; Button: Byte); Overload;
begin
Mouse(Point(X, Y), Button);
end;
procedure MouseBox(const B: TBox; Button: Byte);
begin
Mouse(Point(B.X1 + Random(B.X2 - B.X1), B.Y1 + Random(B.Y2 - B.Y1)), Button);
end;
procedure Setup();
var
i: Int32;
PP: TSysProcArr;
begin
PP := GetProcesses();
for i := 0 to High(PP) do
begin
if (Pos('SpawnPK', PP[i].Title) > 0) then
begin
if (Pos('Simba', PP[i].Title) > 0) then Continue;
SetTarget(PP[i]);
GetClientDimensions(_w, _h);
if (_w > 800) then
begin
Mouse(750, 44, MOUSE_LEFT);
Wait(234);
GetClientDimensions(_w, _h);
if (_w > 800) then
begin
WriteLn('Please minimize the side panel.');
TerminateScript();
end else Exit;
end else Exit;
end;
end;
WriteLn('Error: Didn''t setup client.');
TerminateScript();
end;
//https://github.com/SRL/SRL/blob/master/shared/text.simba#L18
function FindTextIn(var Matches: TPointArray; const Text, Font: String; const Color: Int32; const B: TBox): Boolean;
var
w, h: Int32;
TPA, TextTPA: TPointArray;
begin
if FindColors(TPA, Color, B.X1, B.Y1, B.X2, B.Y2) then
begin
SetLength(Matches, 0);
TextTPA := TPAFromText(Text, Font, w, h);
Result := FindTextTPAinTPA(h-1, TextTPA, TPA, Matches);
end;
end;
function WaitFunc(Func: function: Boolean; WaitTime, WaitInterval: Int32; Condition: Boolean = True): Boolean;
var
t: UInt32;
begin
t := GetTickCount() + WaitTime;
repeat
Result := Func();
if (Result = Condition) then Exit(True);
Wait(WaitInterval);
until (GetTickCount() > t);
Result := False;
end;
function IsWalking(): boolean;
var
BMPA, BMPB, w, h: Int32;
begin
try
BMPA := BitmapFromClient(MSX1, MSY1, MSX2, MSY2);
Wait(69);
BMPB := BitmapFromClient(MSX1, MSY1, MSX2, MSY2);
GetBitmapSize(BMPA, w, h);
Result := (CalculatePixelShift(BMPA, BMPB, [0, 0, w-1, h-1]) > 50000);
finally
if BitmapExists(BMPA) then FreeBitmap(BMPA);
if BitmapExists(BMPB) then FreeBitmap(BMPB);
end;
end;
function GetUpText(): String;
const
COL = $006699;
var
BMP, w, h, OldT, NewT: Int32;
B: TBox;
TPA: TPointArray;
begin
if FindColors(TPA, 16777215, 12, 34, 500, 54) then
begin
OldT := GetImageTarget();
B := GetTPABounds(TPA);
BMP := BitmapFromClient(B.X1, B.Y1, B.X2+1, B.Y2+1);
FastReplaceColor(BMP, $FFFFFF, COL); //white
FastReplaceColor(BMP, $FFFF00, COL); //cyan
FastReplaceColor(BMP, $00FF00, COL); //green
GetBitmapSize(BMP, w, h);
try
SetTargetBitmap(BMP);
Result := GetTextAtEx(0, 0, w-1, h-1, 0, 4, 4, COL, 0, 'UpChars07');
finally
NewT := GetImageTarget();
SetImageTarget(OldT);
FreeTarget(NewT);
if BitmapExists(BMP) then FreeBitmap(BMP);
end;
end;
end;
function IsUpText(const S: String): Boolean;
begin
Result := (Pos(S, GetUpText()) > 0);
end;
function IsUpText(const SS: TStringArray): Boolean; Overload;
begin
Result := IsArrInStr(SS, GetUpText());
end;
function WaitUpText(const S: String; const WaitTime: UInt32): Boolean;
var
t: UInt32;
begin
t := GetTickCount() + WaitTime;
repeat
Result := IsUpText(S);
if Result then Exit;
Wait(44);
until (GetTickCount() > t);
end;
function WaitUpText(const SS: TStringArray; const WaitTime: UInt32): Boolean; Overload;
var
t: UInt32;
begin
t := GetTickCount() + WaitTime;
repeat
Result := IsUpText(SS);
if Result then Exit;
Wait(44);
until (GetTickCount() > t);
end;
function GetTabBox(const Tab: Int32): TBox;
begin
if (not InRange(Tab, 1, 7)) then Exit;
Result.X1 := 499 + (Tab * 33);
Result.X2 := Result.X1 + 32;
Result.Y1 := 196;
Result.Y2 := 232;
end;
function IsTabActive(const Tab: Int32): Boolean;
const
COLOR = 1515095;
TOL = 30;
var
B: TBox;
begin
if (not InRange(Tab, 1, 7)) then Exit;
B := GetTabBox(Tab);
Result := (CountColorTolerance(COLOR, B.X1, B.Y1, B.X2, B.Y2, TOL) > 200);
end;
function ClickTab(const Tab: Int32): Boolean;
var
t: UInt32;
begin
if IsTabActive(Tab) then Exit(True);
MouseBox(GetTabBox(Tab), MOUSE_LEFT);
t := GetTickCount() + 100;
repeat
Result := IsTabActive(Tab);
if Result then Exit;
Wait(20);
until (GetTickCount() > t);
end;
function IsMoneyMakingScreen(): Boolean;
var
TPA: TPointArray;
begin
Result := FindTextIn(TPA, 'Money Making', 'UpChars07', 45311, MSBOX);
end;
function ClickThieving(): Boolean;
var
c: Int32;
TPA: TPointArray;
begin
repeat
if FindTextIn(TPA, 'Thieving', 'StatChars07', $FFFFFF, MSBOX) then Exit(True);
if FindTextIn(TPA, 'Thieving', 'StatChars07', 2070783, MSBOX) then
begin
OffsetTPA(TPA, Point(4, 4));
Mouse(TPA[0], MOUSE_LEFT);
Wait(234);
end;
until (Inc(c) > 4);
end;
function ClickTeleport(): Boolean;
var
TPA: TPointArray;
begin
if FindTextIn(TPA, 'Teleport', 'StatChars07', 39935, MSBOX) then
begin
OffsetTPA(TPA, Point(4, 4));
Mouse(TPA[0], MOUSE_LEFT);
Result := WaitFunc(@IsMoneyMakingScreen, 2345, 234, False);
end;
end;
function Teleport(): Boolean;
const
B: TBox = [591, 273, 610, 292];
begin
if IsMoneyMakingScreen() then
begin
if ClickTeleport() then
begin
Wait(4567, 5678);
Exit(True);
end;
end;
if ClickTab(7) then
begin
Wait(121, 212);
MouseBox(B, MOUSE_LEFT);
if WaitFunc(@IsMoneyMakingScreen, 3456, 234, True) then
begin
if ClickThieving() then
begin
if ClickTeleport() then
begin
Wait(4567, 5678);
Result := True;
end;
end;
end;
end;
end;
function GetThievingLevel(): Int32;
const
B: TBox = [630, 350, 655, 365];
var
TPA: TPointArray;
begin
if ClickTab(2) then
if FindColors(TPA, $00FFFF, B.X1, B.Y1, B.X2, B.Y2) then
Result := StrToIntDef(GetTextATPA(ClusterTPA(TPA, 1), 5, 'StatChars07'), -1);
end;
function GetStallNumber(const TL: Int32): Int32;
begin
case TL of
01..24: Result := 1;
25..49: Result := 2;
50..74: Result := 3;
75..98: Result := 4;
99: Result := 5;
end;
end;
function GetStallText(const Stall: Int32): String;
begin
case Stall of
1: Result := '250';
2: Result := '350';
3: Result := '450';
4: Result := '650';
5: Result := '850';
end;
end;
function Thieve(): Boolean;
const
TABLE_COLOR = 2708852;
TABLE_TOL = 2;
var
i, Stall: Int32;
B: TBox;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
if (Level <> 99) then Level := GetThievingLevel();
Stall := GetStallNumber(Level);
if (not IsUpText(GetStallText(Stall))) then
begin
if FindColorsTolerance(TPA, TABLE_COLOR, MSX1, MSY1, MSX2, MSY2, TABLE_TOL) then
begin
ATPA := ClusterTPA(TPA, 1);
FilterTPAsBetween(ATPA, 0, 100);
FilterTPAsBetween(ATPA, 1000, 1000000);
if (Length(ATPA) < 1) then Exit;
if (Level < 50) then
SortATPAFromMidPoint(ATPA, Point(200, MSY1)) else
SortATPAFromMidPoint(ATPA, Point(200, MSY2));
for i := 0 to High(ATPA) do
begin
Mouse(MedianTPA(ATPA[i]), MOUSE_MOVE);
if WaitUpText(GetStallText(Stall), 300) then Break;
end;
if (i = Length(ATPA)) then Exit;
end else Exit;
end;
FastClick(MOUSE_LEFT);
Wait(2450, 2500);
Result := True;
end;
function FindChooseOption(out B: TBox): Boolean;
const
COLOR = 4674653;
var
TPA: TPointArray;
ATPA: T2DPointArray;
begin
if FindColors(TPA, COLOR) then
begin
ATPA := ClusterTPA(TPA, 4);
SortATPASize(ATPA, True);
B := GetTPABounds(ATPA[0]);
Result := True;
end;
end;
function ChooseOption(const S: String): Boolean;
var
B: TBox;
TPA: TPointArray;
begin
if FindChooseOption(B) then
begin
if FindTextIn(TPA, S, 'UpChars07', $FFFFFF, B) then
begin
OffsetTPA(TPA, [9, 4]);
Mouse(MedianTPA(TPA), MOUSE_LEFT);
Result := True;
end;
end;
end;
function CashBags(): Boolean;
const
B: TBox = [553, 238, 738, 488];
GREEN_CASH = $80FF00;
var
x, y: Int32;
TPA: TPointArray;
begin
if (GetTickCount() < CashTimer) then Exit;
CashTimer := GetTickCount() + 1000000;
if ClickTab(4) then
begin
Wait(121);
if FindColor(x, y, GREEN_CASH, B.X1, B.Y1, B.X2, B.Y2) then
begin
Mouse(x + 9, y + 9, MOUSE_RIGHT);
Wait(121);
Result := ChooseOption('exchange');
end;
end;
end;
procedure Mainloop();
begin
if IsKeyDown(STOP_KEY) then TerminateScript();
CashBags();
if (not Thieve()) then
begin
if WaitFunc(@IsWalking, 2345, 345, True) then
begin
while IsWalking() do Wait(444);
end else
begin
Teleport();
end;
end;
end;
begin
ClearDebug();
Setup();
ActivateClient();
CashTimer := GetTickCount() + 1000000;
while True do Mainloop();
end.