Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 31.20 KB | None | 0 0
  1. {$I srl-6/srl.simba}
  2. /by rjj ~2016
  3. const
  4.  
  5.   USERNAME = '';
  6.   CLIENTNAME = 'Runique';
  7.   CLIENTWIDTH = 765;
  8.   CLIENTHEIGHT = 525;
  9.   EAT_AT = 650;
  10.   DRINK_PRAYER_AT = 450;
  11.   lootItems = ['Dragon bones', 'Draconic visage',
  12.   'Dragon platelegs', 'Dragon plateskirt', 'Runique chest key'];
  13.  
  14.  
  15.   antiFireSTRING = 'mQwAAAHicY2ZgYDjMxMCwF4hPAnE6IwNDFBDHAHGZ8AygLCMUIwAjqigA6U8EmQ==';
  16.   prayerSTRING = 'mQwAAAHicY2ZgYHBlYmDwAmJ7IHZmZGAwA2JzIHa/vAgoywjFCMCIKgoAlPADTA==';
  17.   attackSTRING = 'mQwAAAHicY2ZgYDjCxMCwF4hPAHE3IwNDPRTbO10CyjJCMQIwoooCAAQ5BTc=';
  18.   strengthSTRING = 'mQwAAAHicY2ZgYHBlYmDwBmJ7IF7PyMCwBIgXA/GFc+eAsoxgzMqAAIxIGAgA7AkFSA==';
  19.   sharkSTRING = 'mWAAAAHicY2FgYChgYmDIB+IkIK4CYnNGBgZtILYEYjMgnteUDVTFCMesQBIZM6JhEAAAEHUEQw==';
  20.   vialSTRING = 'mWAAAAHicY2FgYDjMxMBwAoj3AvEhIBZnZGAQgmI5IE5LzwSqYgTjmpoaBlYgCxkzomEQAACBAgY4';
  21.  
  22. type
  23.  
  24.   TLOCATION = (SWBANK, NEWSPOT, DUNGEON, LOST);
  25.  
  26.   TDIRECTION = (NORTH, EAST, SOUTH, WEST);
  27.  
  28.   fnct_actionOptions = (ClickRight, ClickLeft, ClickMiddle, Move, Nothing);
  29.  
  30.   TOptions = record
  31.     Str: string;
  32.     Bounds, BigBox: TBox;
  33.   end;
  34.  
  35.   TPOTIONTIMER = record
  36.     potionDTM, lastSip, interval:integer;
  37.     name:string;
  38.   end;
  39.  
  40.   TRSInventory =  record
  41.     bounds:tbox;
  42.     slots:TBoxArray;
  43.   end;
  44.  
  45. var
  46.   antiFireDTM, prayerDTM, attackDTM, strengthDTM:integer;
  47.   sharkDTM, vialDTM, lastPotion:integer;
  48.   rsClient:TSysProc;
  49.   inventory:TRSInventory;
  50.  
  51. 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;
  52.  
  53. 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;
  54.  
  55. function isText(Text, theText: TStringArray): Boolean;
  56. var
  57.   i, k: Integer;
  58. begin
  59.   for i := 0 to High(Text) do
  60.     for k := 0 to high(theText) do
  61.       if (Pos(Text[i], TheText[k]) > 0) then
  62.         exit(true);
  63. end;
  64.  
  65. procedure clickMouse2(button:integer);
  66. begin
  67.   holdMouse(0, 0, button);
  68.   wait(50);
  69.   releaseMouse(0, 0, button);
  70.   wait(10);
  71. end;
  72.  
  73. procedure Mouse(T:TPoint)override;
  74. begin
  75.   moveMouse(T);
  76.   wait(100);
  77.   clickMouse2(1);
  78. end;
  79.  
  80. function getOptions(): Array of TOptions;
  81. var
  82.    B, BB: TBox;
  83.    TPA, restpa, blacktpa, newtpa, merged: TPointArray;
  84.    ATPA, tempatpa, blackatpa, newatpa: T2DPointArray;
  85.    I, L, target, bmp, w, h: Integer;
  86.    BoxColors: TIntegerArray;
  87. begin
  88.   target := GetImageTarget;
  89.   GetClientDimensions(B.X2, B.Y2);
  90.   B := IntToBox(0, 0, B.X2-1, B.Y2-1);
  91.   BoxColors := [4674653];
  92.   SetLength(ATPA, Length(BoxColors));
  93.   FindColors(tpa, 4674653, b);
  94.   If Length(tpa) < 100 Then
  95.     exit;
  96.   atpa := clusterTpa(tpa, 3);
  97.   for i := 0 to High(ATPA) do
  98.   begin
  99.     B := GetTPABounds(ATPA[i]);
  100.     if ((B.x2-B.x1) > 95) and ((B.y2-B.y1) > 18) then
  101.       Break
  102.     else
  103.       B := IntToBox(0, 0, 0, 0);
  104.   end;
  105.   If (B.x2 = 0) then
  106.     exit;
  107.   findcolors(blacktpa, 0, b);
  108.   if (length(blacktpa) < 1) then
  109.     exit;
  110.   blackatpa := clustertpa(blacktpa, 1);
  111.   for i := 0 to high(blackatpa) do
  112.   begin
  113.     b := gettpaBounds(blackatpa[i]);
  114.      if ((B.x2-B.x1) > 95) and ((B.y2-B.y1) > 16) then
  115.        break
  116.     else
  117.       b := inttobox(0, 0, 0, 0);
  118.   end;
  119.   findcolors(newtpa, 4674653, b);
  120.   if (length(newtpa) < 0) then
  121.     exit;
  122.   newatpa := clustertpa(newtpa, 1);
  123.   b := gettpaBounds(newatpa[0]);
  124.   findcolors(blacktpa, 0, b);
  125.   merged := mergeAtpa([blacktpa, newtpa]);
  126.   ReturnPointsNotInTPAWrap(merged, b, resTPA);
  127.   bmp := CreateBitmap(b.X2-B.X1+2, b.Y2-b.Y1+2);
  128.   OffsetTPA(restpa, Point(-B.X1, -B.Y1));
  129.   FastDrawClear(bmp, 0);
  130.   DrawTPABitmap(bmp, restpa, clRed);//Text
  131.   GetbitmapSize(bmp, w, h);
  132.   settargetbitmap(bmp);
  133.   SetLength(newatpa, H div 16);
  134.   for i := 0 to High(newatpa) do
  135.     FindColorsTolerance(newatpa[i], 255, 0, 2+i*15,  W-1, 15+i*15, 0);
  136.   L := High(newatpa);
  137.   SortATPAFromFirstPointY(newatpa, Point(w div 2,0));
  138.   SetArrayLength(Result, Length(newatpa));
  139.   Result[0].BigBox := b;
  140.   for i := 0 to high(newatpa) do
  141.   begin
  142.     TPA := newatpa[i];
  143.     tempatpa := SplitTPAEx(TPA, 1, 10);
  144.     SortATPAFromFirstPointX(tempatpa, Point(0, 0));
  145.     Result[i].Str := GetTextATPA(tempatpa, 4, 'UpChars07'); //Writeln(Result[i].Str);
  146.     BB := GetTPABounds(newatpa[i]);
  147.     Result[i].Bounds := IntToBox(BB.X1+B.X1, BB.Y1+B.Y1, BB.X2+B.X1, BB.Y2+B.Y1);
  148.     setlength(tempatpa,0);
  149.     setlength(TPA,0);
  150.   end;
  151.   SetImageTarget(target);
  152.   FreeBitmap(bmp);
  153. end;
  154.  
  155. function ArrInStr(arrS: TStringArray; str: string): Boolean;
  156. var
  157.   I, L, H: Integer;
  158. begin
  159.   Result := True;
  160.   L := Low(arrS);    H := High(arrS);
  161.   for I := L to H do
  162.     if Pos(arrS[I], Str) > 0 then
  163.       Exit;
  164.   Result := False;
  165. end;
  166.  
  167. function chooseOptionMulti(Texts: TStringArray; TextType: String; Action: fnct_ActionOptions): Boolean;
  168. var
  169.    B: TBox;
  170.    i, H, x, R: Integer;
  171.    T: TPoint;
  172.    Options: array of TOptions;
  173. begin
  174.   Result := False;
  175.   Options := getOptions();
  176.   if (Length(Options) < 1) then
  177.     Exit;
  178.   H := High(Options);
  179.   for i := 0 To H do
  180.   begin
  181.     if ArrInStr(Texts, Options[i].Str) then
  182.     begin
  183.       Result := True;
  184.       B := Options[i].Bounds;
  185.       GetMousePos(T.x, T.y);
  186.  
  187.       R:= Min(((B.X2 - B.X1) shr 1), 5);
  188.       case Action of
  189.         ClickLeft:
  190.           if PointInBox(T, B) then
  191.             ClickMouse2(mouse_left)
  192.           else
  193.             Mouse(intToBox(B.x1 + R, B.Y1, B.x2 - R, B.Y1 + 5).getMiddle(), mouse_Left);
  194.  
  195.         Move:
  196.           if not PointInBox(T, B) then
  197.             Mouse(intToBox(B.x1 + R, B.Y1, B.x2 - R, B.Y1 + 5).getMiddle(), mouse_move);
  198.  
  199.         Nothing:
  200.           begin
  201.           end;
  202.  
  203.         else
  204.           writeLn('ChooseOptionMultiEx ', ' ClickRight not a valid click for RS menus!');
  205.       end;
  206.       Exit;
  207.     end;
  208.   end;
  209.   B := Options[0].BigBox;
  210.   if Action <> Nothing then
  211.   begin
  212.     x := Max(B.X1 - 52, 0);
  213.     if x = 0 then
  214.       x := B.X2+10;
  215.     MoveMouse(0, 0);
  216.     Wait(200 + Random(100));
  217.   end;
  218. end;
  219.  
  220. function chooseOptionMulti(Txt: TStringArray): Boolean; overload;
  221. begin
  222.   Result := chooseOptionMulti(Txt, 'All', ClickLeft);
  223. end;
  224.  
  225. function chooseOption2(Txt, TextType: string): Boolean;
  226. begin
  227.   Result := chooseOptionMulti([Txt], TextType, ClickLeft);
  228. end;
  229.  
  230. function chooseOption2(Txt: String): Boolean; overload;
  231. begin
  232.   Result := chooseOptionMulti([Txt], 'All', ClickLeft);
  233. end;
  234.  
  235. function waitOptionMulti(S: TStringArray; TextType: string; Action: fnct_ActionOptions; Time: Integer): Boolean;
  236. var
  237.   T: Integer;
  238. begin
  239.   Result := False;
  240.   T := GetSystemTime + Time;
  241.   while (GetSystemTime < T) do
  242.   begin
  243.     if (chooseOptionMulti(S, TextType, Action)) then
  244.       exit(true);
  245.     Wait(20 + Random(10));
  246.   end;
  247. end;
  248.  
  249. function waitOptionMulti(S: TStringArray; Time: Integer): Boolean; overload;
  250. begin
  251.   Result := waitOptionMulti(S, 'all', ClickLeft, Time);
  252. end;
  253.  
  254. function waitOption(S: string; Time: Integer): Boolean; overload;
  255. begin
  256.   Result := waitOptionMulti([s], 'all', ClickLeft, Time);
  257. end;
  258.  
  259. procedure markTime(var t:Integer);
  260. begin
  261.   t := getSystemTime;
  262. end;
  263.  
  264. function timeFromMark(i:Integer):Integer;
  265. begin
  266.   result := i - getSystemTime;
  267. end;
  268.  
  269. procedure DebugBitmap2(Bmp: Integer);
  270. var
  271.   W, H: Integer;
  272. begin
  273.   try
  274.     GetBitmapSize(Bmp, W, H);
  275.     DisplayDebugImgWindow(W, H);
  276.     DrawBitmapDebugImg(Bmp);
  277.   except
  278.     writeLn('DebugBitmap Error in DebugBitmap');
  279.   end;
  280. end;
  281.  
  282. (*
  283.   Auther: Wizzup?
  284.   Description: Shows an image of the Debug screen, plotting colors over the points
  285.   stored in Points TPA. If a name is specified, an image will be saved to that path..
  286. *)
  287.  
  288. function DebugTPA2(Points: TPointArray; BmpName: string): Boolean;
  289. var
  290.   Bmp: integer;
  291.   Box : TBox;
  292.   TempTPA : TPointArray;
  293. begin
  294.   Box := GetTPABounds(Points);
  295.   Bmp := BitmapFromClient(Box.x1,Box.y1,Box.x2,Box.y2);
  296.   TempTPA := CopyTPA(Points);
  297.   OffsetTPA(TempTPA,Point(-box.x1,-box.y1));
  298.   DrawTPABitmap(Bmp,TempTPA,clRed);
  299.   DisplayDebugImgWindow(box.x2-Box.x1 + 1, box.y2-box.y1 + 1);
  300.   DrawBitmapDebugImg(Bmp);
  301.   if bmpname <> '' then
  302.     SaveBitmap(Bmp, ScriptPath + BmpName + '.bmp');
  303.   FreeBitmap(Bmp);
  304.   Result := True;
  305. end;
  306.  
  307. (*
  308.   Auther: Wizzup?
  309.   Description: Shows an image of the client, plotting each TPA of the 2D point
  310.   array aPoints. Each TPA is a different color. If a name is specified, an image
  311.   will be saved.
  312. *)
  313.  
  314. function DebugATPA2(aPoints: T2DPointArray; BmpName: string): Boolean;
  315. var
  316.    Width, Height, ClientBMP: Integer;
  317.    ATPA : T2DPointArray;Box : TBox;
  318. begin
  319.   result := false;
  320.   if length(aPoints) = 0 then
  321.     exit;
  322.   Box := GetATPABounds(aPoints);
  323.   Width := box.x2 - box.x1 + 1;
  324.   Height := box.y2 - box.y1 + 1;
  325.   DisplayDebugImgWindow(Width, Height);
  326.   ClientBMP := BitmapFromClient(box.x1,box.y1,box.x2,box.y2);
  327.   ATPA := CopyATPA(aPoints);
  328.   OffsetATPA(ATPA,point(-box.x1,-box.y1));
  329.   DrawATPABitmap(ClientBMP,ATPA);
  330.   DrawBitmapDebugImg(ClientBMP);
  331.   if BmpName <> '' then
  332.     SaveBitmap(ClientBMP, ScriptPath + BmpName + '.bmp');
  333.   FreeBitmap(ClientBMP);
  334.   Result := True;
  335. end;
  336.  
  337. (*
  338.   Auther: Wizzup?, lordsaturn, & caused
  339.   Description: Shows an image of the client, plotting each TPA's bounds as a box
  340.   of different colour per TPA. If a name is specified, an image will be saved.
  341. *)
  342.  
  343. procedure DebugATPABounds2(aPoints: array Of TPointArray);
  344. var
  345.   Width, Height, ClientBMP, I: Integer;
  346.   B, Box: TBox;
  347.   BoxColors : TIntegerArray;
  348.   SelColor: Integer;
  349.   x,y : integer;
  350.   BMP : Integer;
  351. begin
  352.   Box := GetATPABounds(aPoints);
  353.   Width := Box.X2 + 5;
  354.   Height := Box.Y2 + 5;
  355.   DisplayDebugImgWindow(Width, Height);
  356.   BoxColors := [clRed, clBlue, clBlack, clGreen, clYellow];
  357.   ClientBMP := BitmapFromClient(0,0,width-1,height-1);
  358.   for i:= 0 to high(aPoints) do
  359.   begin
  360.     SelColor := BoxColors[Random(length(Boxcolors))];
  361.  
  362.     B := getTPABounds(aPoints[i]);
  363.     for x := B.x1 to B.x2 do
  364.     begin
  365.       FastSetPixel(ClientBMP, x, b.y1, selColor);
  366.       FastSetPixel(ClientBMP, x, B.y2, selColor);
  367.     end;
  368.     for y := B.y1 to B.y2 do
  369.     begin
  370.       FastSetPixel(ClientBMP, B.x1, y, selColor);
  371.       FastSetPixel(ClientBMP, B.x2, y, selColor);
  372.     end;
  373.  
  374.     BMP := BitmapFromText(inttostr(i),StatChars);
  375.     FastReplaceColor(bmp,clblack,clyellow);
  376.     FastReplaceColor(bmp,clwhite,clblack);
  377.     SetTransparentColor(bmp,clYellow);
  378.     FastDrawTransparent(B.x1 + 2, b.y1 + 2, bmp,clientbmp);
  379.     FreeBitmap(BMP);
  380.   end;
  381.   DrawBitmapDebugImg(clientBMP);
  382.   FreeBitmap(ClientBmp);
  383. end;
  384.  
  385. procedure state(s:string);
  386. begin
  387.   clearDebug();
  388.   writeln('=======================================');
  389.   writeln('Dragons killed: 0| Per hour: 0');
  390.   writeln('XP Gained: 0| Per hour: 0');
  391.   writeln('State:', s);
  392.   writeln('=======================================');
  393. end;
  394.  
  395. procedure initInv();
  396. begin
  397.   inventory.slots := explodeBox(inventory.bounds, 7, 4);
  398. end;
  399.  
  400. function TRSInventory.getSlot(slot:integer):Tbox;
  401. begin
  402.   result := self.slots[slot];
  403. end;
  404.  
  405. function TRSInventory.slotFull(s:Integer):Boolean;
  406. var
  407.   xee, yee:integer;
  408. begin
  409.   result := FindColor(xee, yee, 65536, self.slots[s]);
  410. end;
  411.  
  412. function TRSInventory.count:Integer;
  413. var
  414.   i:Integer;
  415. begin
  416.   for i := 0 to high(self.slots) do
  417.     if self.slotFull(i) then
  418.       result := result + 1;
  419. end;
  420.  
  421. function TRSInventory.full:Boolean;
  422. begin
  423.   result := false;
  424.   exit(self.count = 28);
  425. end;
  426.  
  427. function getSimpleText(Colors:TIntegerArray;x1, y1, x2, y2:integer;font:string):String;
  428. var
  429.   textTPA:TPointArray;
  430.   textATPA, textATPAS:T2DPointArray;
  431.   i:integer;
  432.   textStr:string;
  433. begin
  434.   setLength(textATPAS, length(colors));
  435.   for i := 0 to high(colors) do
  436.     findColors(textATPAS[i], Colors[i], x1, y1, x2, y2);
  437.   textTPA := mergeATPA(textATPAS);
  438.   textATPA := SplitTPAEx(textTPA, 1, 10);
  439.   filtertpasbetween(textatpa, 0, 1);
  440.   SortATPAFromFirstPointX(textATPA, Point(0, 0));
  441.   result := getTextATPA(textATPA, 3, font);
  442. end;
  443.  
  444. function getFightingMonster():string;
  445. begin
  446.   result := getSimpleText([16777215], 33, 78, 142, 103, 'UpChars07');
  447. end;
  448.  
  449. function inCombat(monster:string):boolean;
  450. begin
  451.   result := getFightingMonster() = monster;
  452. end;
  453.  
  454. function inCombat():boolean;overload;
  455. begin
  456.   result := inCombat('Steel dragon');
  457. end;
  458.  
  459. function getHealth():integer;
  460. begin;
  461.   try
  462.     result := strToInt(getSimpleText([65280, 65535, 501500, 855541], 724, 72, 750, 90, 'statchars07'));
  463.   except
  464.     result := 0;
  465.   end;
  466. end;
  467.  
  468. function getPrayer():integer;
  469. begin;
  470.   try
  471.     result := strToInt(getSimpleText([65280, 65535, 501500, 855541], 739, 112, 764, 130, 'statchars07'));
  472.   except
  473.     result := 0;
  474.   end;
  475. end;
  476.  
  477. function getXpBarTPA():TPointArray;
  478. begin
  479.   findColors(result, 16777215, 424, 101, 519, 118);
  480. end;
  481.  
  482. function getXpBarText():string;
  483. var
  484.   textTPA:TPointArray;
  485.   textATPA:T2DPointArray;
  486. begin
  487.   textTPA := getXpBarTPA();
  488.   textATPA := splittpaex(textTPA, 1, 10);
  489.   filtertpasbetween(textatpa, 0, 1);
  490.   SortATPAFromFirstPointX(textATPA, Point(0, 0));
  491.   result := getTextATPA(textatpa, 3, 'smallchars07');
  492. end;
  493.  
  494. function xpBarOpen():boolean;
  495. begin
  496.   result := getXPBarText().contains('XP:');
  497. end;
  498.  
  499. function getXpBarTotal():integer;
  500. var
  501.   BARstring:string;
  502. begin
  503.   BARstring := getXpBarText();
  504.   BARstring := replace(BARstring, '''', '', [rfReplaceAll]);
  505.   BARstring := replace(BARstring, 'XP:', '', [rfReplaceAll]);
  506.   BARstring := replace(BARstring, ' ', '', [rfReplaceAll]);
  507.   result := strtoInt(barString);
  508. end;
  509.  
  510. function getLocation():TLOCATION;
  511. begin
  512.   if (not isLoggedIn()) then
  513.     exit
  514.   else if (countColorTolerance(2678011, intToBox(550, 51, 717, 214), 1, colorSetting(2, 0.00, 0.00)) > 200) then
  515.     result := SWBANK
  516.   else if (countColorTolerance(0, intToBox(550, 51, 717, 214), 1, colorSetting(2, 0.00, 0.00)) > 500) and
  517.     (countColorTolerance(2840425, intToBox(550, 51, 717, 214), 4, colorSetting(2, 0.24, 1.42)) > 600) then
  518.       result := DUNGEON
  519.   else
  520.     result := LOST;
  521. end;
  522.  
  523. procedure withdrawItems();
  524. begin
  525.   wait(50);
  526.   mouse(Point(189, 146), 1);
  527.   wait(500);
  528.   mouse(Point(232, 146), 1);
  529.   wait(500);
  530.   mouse(Point(277, 146), 1);
  531.   wait(500);
  532.   mouse(Point(321, 146), 1);
  533.   wait(150);
  534.   mouse(Point(321, 146), 1);
  535.   wait(500);
  536.   mouse(Point(366, 146), 1);
  537.   wait(150);
  538.   mouse(Point(366, 146), 1);
  539.   wait(500);
  540. end;
  541.  
  542. function bankOpen():boolean;
  543. begin
  544.   result := getSimpleText([2070783], 180, 65, 312, 84, 'UpChars07') = 'The Bank of Runique';
  545. end;
  546.  
  547. procedure bankAll();
  548. begin
  549.   if bankOpen() then
  550.     mouse(Point(356, 348), 1);
  551. end;
  552.  
  553. procedure closeBank();
  554. begin
  555.   if bankOpen() then
  556.     mouse(Point(491, 75), 1);
  557. end;
  558.  
  559. function findBank():boolean;
  560. var
  561.   brownTPA, silverTPA:TPointArray;
  562.   brownATPA, silverATPA:T2DPointArray;
  563.   P:TPoint;
  564.   i:integer;
  565. begin
  566.   if findColorstolerancE(brownTPA, 6057341, intToBox(4, 47, 520, 384), 16, colorSetting(2, 0.05, 0.70)) then
  567.   begin
  568.     brownATPA := clusterTPA(brownTPA, 10);
  569.     filterTPAsbetween(brownATPA, 0, 500);
  570.     for i := 0 to high(brownATPA) do
  571.       if findColorsTolerance(silverTPA, 11250613, brownATPA[i].getBounds(), 14, colorSetting(2, 0.15, 0.11)) then
  572.       begin
  573.         silverATPA := clusterTPA(silverTPA, 10);
  574.         for i := 0 to high(silverATPA) do
  575.         begin
  576.           p := silverATPA[i].getBounds().getMiddle();
  577.           mouse(p, 0);
  578.           if waitOption('Use', 1000) then
  579.             if waitFunc(@bankOpen, 40, 4000) then
  580.               exit(true)
  581.           else
  582.           begin
  583.             mouse(Point(0, 0), 0);
  584.             wait(100);
  585.           end;
  586.         end;
  587.         //debugATPABounds2(silverATPA);
  588.       end;
  589.   end;
  590.  
  591. end;
  592.  
  593. function teleportTo(place:TLOCATION):boolean;
  594. var
  595.   t:integer;
  596. begin
  597.   wait(50);
  598.   mouse(Point(504, 512));
  599.  
  600.   wait(500);
  601.   case place of
  602.     SWBANK : sendKeys('MS', 75, 75);
  603.     DUNGEON: sendKeys('DB', 75, 75);
  604.   end;
  605.  
  606.   markTime(t);
  607.   repeat
  608.     wait(100)
  609.   until (getLocation() = place) or timeFromMark(t) > 3500;
  610.   wait(1700);
  611. end;
  612.  
  613. procedure makeCompassHigh;
  614. begin
  615.   keyDown(vk_up);
  616.   wait(2000);
  617.   keyUp(vk_up);
  618. end;
  619.  
  620. function tileToCoords(Location, Tile:TPoint):TPoint;
  621. begin
  622.   if (Tile.x - Location.x > 17) or (Location.y - Tile.y > 17) then
  623.   begin
  624.     Result := Point(-1, -1);
  625.     exit;
  626.   end;
  627.   result.x := ((Tile.x - Location.x) * 4) + 630;
  628.   result.y := ((Location.y - Tile.y) * 4) + 132;
  629. end;
  630.  
  631. function getTile():TPoint;
  632. var
  633.   s:string;
  634. begin
  635.   sendKeys('::mypos', 30, 300);
  636.   pressKey(vk_enter);
  637.   wait(700);
  638.   s := getSimpleText([0], 13, 491, 105, 506, 'smallchars07');
  639.   if s.contains('[') then
  640.   begin
  641.     try
  642.       result.x := strToInt(between('[', '''', s));
  643.       result.y := strtoInt(between(''' ','''',s));
  644.     except
  645.       result := Point(-1, -1);
  646.     end;
  647.   end;
  648.   state('Tile has been read at ' + toStr(result));
  649. end;
  650.  
  651. function walkTile(p:TPoint):boolean;
  652. var
  653.   T:TPoint;
  654. begin
  655.   T := tileToCoords(getTile(), p);
  656.   if (T.X <> -1) then
  657.   begin
  658.     mouse(T, 1);
  659.     wait(3000);
  660.     result := true;
  661.   end;
  662. end;
  663.  
  664. function seeDragon(var p:TPoint):boolean;
  665. var
  666.   dragonTPA:TPointArray;
  667.   dragonATPA:T2DPointArray;
  668.   i:integer;
  669. begin
  670.   findColorstolerance(dragonTPA, 8620443, intToBox(7, 49, 517, 383), 14, colorSetting(2, 0.32, 0.53));
  671.   dragonATPA := clusterTPA(dragonTPA, 8);
  672.   filterTPAsbetween(dragonATPA, 0, 350);
  673.   sortATPAFrom(dragonATPA, Point(336, 309));
  674.   for i := 0 to high(dragonATPA) do
  675.     if ((dragonATPA[i].getBounds().getWidth() > 90) and (dragonATPA[i].getBounds().getHeight() > 90)) then
  676.     begin
  677.       p := dragonATPA[i].getBounds().getMiddle();
  678.       result := true;
  679.     end;
  680. end;
  681.  
  682. function seeDragon():boolean; overload;
  683. var
  684.   p:TPoint;
  685. begin
  686.   result := seeDragon(p);
  687. end;
  688.  
  689. procedure walkToSpot;
  690. begin
  691.   walkTile(Point(2704, 9459));
  692.   waitFunc(@seeDragon, 40, 4000);
  693. end;
  694.  
  695. function findDragon():boolean;
  696. var
  697.   T:TPoint;
  698. begin
  699.   if seeDragon(T) then
  700.   begin
  701.     result := true;
  702.     mouse(t);
  703.   end;
  704. end;
  705.  
  706. function string.contains(s: string): Boolean;
  707. begin
  708.   if ((self <> '') and (s <> '')) then
  709.     result := (pos(s, self) > 0)
  710.   else
  711.     result := False;
  712. end;
  713.  
  714. function getOptionsString():TStringArray;
  715. var
  716.   t:array of Toptions;
  717.   i:integer;
  718. begin
  719.   t := getOptions();
  720.   setLength(result, length(t));
  721.   for i := 0 to high(t) do
  722.     result[i] := t[i].str;
  723. end;
  724.  
  725. function validDropMenu():boolean;
  726. var
  727.   i:integer;
  728.   t:TStringArray;
  729. begin
  730.   t := getOptionsString();
  731.   for i := 0 to high(t) do
  732.     if lowercase(t[i]).contains('take dragon bones') then
  733.       exit(true);
  734. end;
  735.  
  736. function getDropCount():integer;
  737. var
  738.   i, k:integer;
  739.   t:tStringArray;
  740. begin
  741.   t := getOptionsString();
  742.   for i := 0 to high(lootItems) do
  743.     for k := 0 to high(t) do
  744.       if lowercase(t[k]).contains(lowercase('Take ' + lootItems[i])) then
  745.         result := result + 1;
  746. end;
  747.  
  748. procedure pickUpItems();
  749. var
  750.   redDotsTPA, groundTPA, objectsTPA:TPointArray;
  751.   redDotsATPA, groundATPA, objectsATPA:T2DPointArray;
  752.   itemsOnGround:TStringArray;
  753.   nearestDirection, nearestDrop, me:TPoint;
  754.   i, dx, dy, dropCount:integer;
  755. begin
  756.   me := Point(630, 132);
  757.   findColorsTolerance(redDotsTPA, 1776620, 630 - 30, 132 - 30, 630 + 30, 132 + 30, 43);
  758.   redDotsATPA := clusterTPA(redDotsTPA, 1);
  759.   filterTPAsBetween(redDotsATPA, 25, 200);
  760.   sortATPAFrom(redDotsATPA, Point(630, 132));
  761.   if (length(redDotsATPA) > 0) then
  762.   begin
  763.     nearestDrop := redDotsATPA[0].getBounds().getMiddle();
  764.     findColorsTolerance(groundTPA, 2312279, intToBox(7, 49, 517, 383), 6, colorSetting(2, 0.18, 1.06));
  765.     groundATPA := clusterTPA(groundTPA, 3);
  766.     filterTPAsbetween(groundATPA, 0, 700);
  767.     objectsTPA := returnPointsNotInTPA(mergeATPA(groundATPA), intToBox(7, 49, 517, 383));
  768.     objectsATPA := clusterTPA(objectsTPA, 2);
  769.     filterTPAsbetween(objectsATPA, 400, 50000);
  770.     dx := me.x - nearestDrop.x;
  771.     dy := me.y - nearestDrop.y;
  772.     if abs(dx) > abs(dy) then
  773.     begin
  774.       if (dx < 0) then
  775.         nearestDirection := Point(me.x + 15,me.y)
  776.       else nearestDirection := Point(me.x - 15,me.y);
  777.     end else
  778.     if abs(dx) < abs(dy) then
  779.     begin
  780.       if (dy < 0) then
  781.         nearestDirection := Point(me.x ,me.y + 15)
  782.       else
  783.         nearestDirection := Point(me.x ,me.y - 15)
  784.     end else
  785.       nearestDirection := me;
  786.     sortATPAFromFirstPoint(objectsATPA, nearestDirection);
  787.     for i := 0 to high(objectsATPA) do
  788.     begin
  789.       mouse(objectsATPA[i].getBounds().getMiddle(), 0);
  790.       wait(250);
  791.       if (validDropMenu()) then
  792.       begin
  793.         dropCount := getDropCount();
  794.         if waitOptionMulti(lootItems, 1000) then
  795.         begin
  796.           dropCount := dropCount - 1;
  797.           state('Drop count:' + toStr(dropCount));
  798.           for i := 0 to dropCount do
  799.           begin
  800.             mouse(Point(265, 230), 0);
  801.             if waitOptionMulti(lootItems, 1000) then
  802.               wait(750);
  803.           end;
  804.         end;
  805.         exit();
  806.       end else
  807.       begin
  808.         moveMouse(0, 0);
  809.         wait(150);
  810.       end;
  811.     end;
  812.   end;
  813. end;
  814.  
  815. function activateRsClient(firstTime:boolean):boolean;
  816. var
  817.   processes: TSysProcArr;
  818.   i: integer;
  819. begin
  820.   result := false;
  821.   processes := GetProcesses();
  822.   if (firstTime) then
  823.     writeln('Scanning for ' , CLIENTNAME , 'Client..');
  824.   for i := 0 to high(processes) do
  825.     if (processes[i].title.contains(CLIENTNAME)) and (processes[i].width = CLIENTWIDTH) and (processes[i].height = CLIENTHEIGHT) then
  826.     begin
  827.       if (firstTime) then
  828.       begin
  829.         writeln('Found client');
  830.         writeln('Target set to: ' , toStr(processes[i]));
  831.       end;
  832.       rsClient := processes[i];
  833.       setTarget(processes[i]);
  834.       ActivateClient();
  835.       exit(true);
  836.     end;
  837. end;
  838.  
  839. function getClientName():string;
  840. begin
  841.   activateRsClient(false);
  842.   result := rsClient.title;
  843. end;
  844.  
  845. function isLoggedIn():boolean; override;
  846. begin
  847.   if (USERNAME = '') then
  848.   begin
  849.     writeln('Please enter a username at the top of the script');
  850.     terminateScript();
  851.   end else
  852.     result := getClientName().contains(USERNAME);
  853. end;
  854.  
  855. function loginPlayer():boolean;
  856. begin
  857.   writeln('logging in player');
  858. end;
  859.  
  860. procedure TRSInventory.interactItem(const slot, Button:Integer);
  861. begin
  862.   if (self.slotFull(slot)) then
  863.     mouse(boxCenter(self.slots[slot]).x, boxCenter(self.slots[slot]).y, 0, 0, BUTTON);
  864. end;
  865.  
  866. function TRSInventory.DTMExists(const DTM, slot:integer):boolean;
  867. var
  868.   x, y:integer;
  869. begin
  870.   result := findDTM(DTM, x, y, self.slots[slot].X1, self.slots[slot].y1, self.slots[slot].x2, self.slots[slot].y2);
  871. end;
  872.  
  873. function TRSInventory.countDTM(const DTMSearch:Integer):Integer;
  874. var
  875.   i:Integer;
  876. begin
  877.   for i := 0 to high(self.slots) do
  878.     if (self.DTMExists(dtmSearch, i)) then
  879.       result := result + 1;
  880. end;
  881.  
  882. function TRSInventory.countDTM(const DTMSearch:TIntegerArray):integer; overload;
  883. var
  884.   i:integer;
  885. begin
  886.   for i := 0 to high(DTMSearch) do
  887.     result := result + self.countDTM(DTMsearch[i]);
  888. end;
  889.  
  890. function TRSInventory.searchDTM(const DTMSearch:Integer;click, cont:Boolean;button:Integer):Boolean;
  891. var
  892.   i:Integer;
  893. begin
  894.   for i := 0 to high(self.slots) do
  895.   begin
  896.     if self.DTMExists(dtmSearch, i) then
  897.     begin
  898.       result := true;
  899.       if click then
  900.         self.interactItem(i, button);
  901.       if not cont then
  902.         exit;
  903.     end;
  904.   end;
  905. end;
  906.  
  907. function TRSInventory.searchDTM(const DTMSearch:Integer;cont:Boolean;button:Integer):Boolean; overload;
  908. var
  909.   I:Integer;
  910. begin
  911.   result := false;
  912.   for i := 0 to high(self.slots) do
  913.   begin
  914.   if self.DTMExists(dtmSearch, i) then
  915.     begin
  916.       result := true;
  917.       self.interactItem(i, button);
  918.       if not cont then
  919.         exit;
  920.     end;
  921.   end;
  922. end;
  923.  
  924. function TRSInventory.searchDTM(const DTMSearch:Integer;button:Integer):Boolean; overload;
  925. var
  926.   I, x, y:Integer;
  927. begin
  928.   result := false;
  929.   for i := 0 to high(self.slots) do
  930.   begin
  931.     if self.DTMExists(dtmSearch, i) then
  932.     begin
  933.       self.interactItem(i, button);
  934.       exit(true);
  935.     end;
  936.   end;
  937. end;
  938.  
  939. function TRSInventory.searchDTM(const DTMSearch:TIntegerarray;button:Integer):boolean; overload;
  940. var
  941.   i:integer;
  942. begin
  943.   for i := 0 to high(DTMSearch) do
  944.     if inventory.searchDTM(DTMSearch[i], true, false, 1) then
  945.       exit(true);
  946. end;
  947.  
  948. function inventoryReady():boolean;
  949. var
  950.   i:integer;
  951.   prayPotCount:integer;
  952. begin
  953.   result := inventory.countDTM([antiFireDTM, prayerDTM, attackDTM, strengthDTM, sharkDTM, vialDTM]) = 7;
  954. end;
  955.  
  956. function needEatOrPray():boolean;
  957. begin
  958.   if (getHealth < EAT_AT) or (getPrayer < DRINK_PRAYER_AT) then
  959.     result := true;
  960. end;
  961.  
  962. function checkHealthPray():boolean;
  963. begin
  964.   if (getHealth < EAT_AT) then
  965.   begin
  966.     inventory.searchDTM(sharkDTM, 1);
  967.     result := true;
  968.     wait(500);
  969.   end;
  970.   if (getPrayer < DRINK_PRAYER_AT) then
  971.   begin
  972.     result := true;
  973.     inventory.searchDTM(prayerDTM, 1);
  974.   end;
  975.   if (timeFromMark(lastPotion) > 300000) then
  976.   begin
  977.     markTime(lastPotion);
  978.     inventory.searchDTM(attackDTM, 1);
  979.     wait(1000);
  980.     inventory.searchDTM(strengthDTM, 1);
  981.     wait(1200);
  982.     inventory.searchDTM(antiFireDTM, 1);
  983.     wait(350);
  984.   end;
  985. end;
  986.  
  987. function prayOn():boolean;
  988. var
  989.   x, y:integer;
  990. begin
  991.   result := findColorTolerance(x, y, 13956822, 720, 108, 733, 125, 2);
  992. end;
  993.  
  994. procedure togglePrayer();
  995. begin
  996.   mouse(Point(728, 116));
  997. end;
  998.  
  999. procedure initDTMz();
  1000. begin
  1001.   antiFireDTM := DTMFromString(antiFireSTRING);
  1002.   prayerDTM := DTMFromString(prayerSTRING);
  1003.   attackDTM := DTMFromString(attackSTRING);
  1004.   strengthDTM := DTMFromString(strengthSTRING);
  1005.   sharkDTM := DTMFromString(sharkSTRING);
  1006.   vialDTM := DTMFromString(vialSTRING);
  1007. end;
  1008.  
  1009. procedure freememory;
  1010. begin
  1011.   freeDTM(antiFireDTM);
  1012.   freeDTM(prayerDTM);
  1013.   freeDTM(attackDTM);
  1014.   freeDTM(strengthDTM);
  1015.   freeDTM(sharkDTM);
  1016.   freeDTM(vialDTM);
  1017. end;
  1018.  
  1019. function checkHealthPray2():boolean;
  1020. begin
  1021.   if (getPrayer < DRINK_PRAYER_AT) then
  1022.   begin
  1023.     inventory.searchDTM(prayerDTM, 1);
  1024.     wait(3000);
  1025.   end;
  1026. end;
  1027.  
  1028. procedure loop();
  1029. var
  1030.   t, d, sharkAmount, i:integer;
  1031. begin
  1032.     if (not isLoggedIn()) then
  1033.       exit;
  1034.     case getLocation() of
  1035.       SWBANK:
  1036.       begin
  1037.         if prayOn() then
  1038.           togglePrayer();
  1039.         closeBank();
  1040.         if needEatOrPray() then
  1041.         begin
  1042.           if findBank() then
  1043.           begin
  1044.             bankAll();
  1045.             state('Healing');
  1046.             sharkAmount := round((900 - getHealth())/200);
  1047.             for i := 0 to sharkAmount do
  1048.             begin
  1049.               mouse(Point(364, 139), 1);
  1050.               wait(250);
  1051.             end;
  1052.             mouse(Point(320, 147), 1);
  1053.             wait(400);
  1054.             closeBank();
  1055.             markTime(t);
  1056.             repeat
  1057.               if (getPrayer() < 600) then
  1058.                 inventory.searchDTM(prayerDTM, 1)
  1059.               else if (getHealth() < 800) then
  1060.                 inventory.searchDTM(sharkDTM, 1)
  1061.               else begin
  1062.                 state('Finished healing');
  1063.                 break;
  1064.               end;
  1065.             until timeFromMark(t) > 10000;
  1066.             wait(750);
  1067.             inventory.searchDTM(prayerDTM, 1);
  1068.             wait(500);
  1069.           end;
  1070.         end;
  1071.         if (inventory.count() > 7) or (not inventoryReady()) then
  1072.         begin
  1073.           if findBank() then
  1074.           begin
  1075.             state('Banking items');
  1076.             bankAll();
  1077.             withdrawItems();
  1078.             closeBank();
  1079.           end;
  1080.         end else if inventoryReady() then
  1081.         begin
  1082.           state('Teleporting to dungeon');
  1083.           teleportTo(DUNGEON);
  1084.           walkToSpot;
  1085.         end;
  1086.         begin
  1087.           state('Inventory not ready');
  1088.           if findBank() then
  1089.           begin
  1090.             state('Banking all items');
  1091.             bankAll();
  1092.             withdrawItems();
  1093.             closeBank();
  1094.           end;
  1095.         end;
  1096.       end;
  1097.       DUNGEON:
  1098.       begin
  1099.         if (not prayOn()) then
  1100.           togglePrayer();
  1101.         if (getHealth() < 200) or (getPrayer() < 100) then
  1102.         begin
  1103.           state('Low health teleporting to bank');
  1104.           teleportTo(SWBANK);
  1105.         end
  1106.         else if (inventory.count() > 15) then
  1107.           teleportTo(SWBANK)
  1108.         else if seeDragon() then
  1109.         begin
  1110.           markTime(d);
  1111.           repeat
  1112.             if findDragon() then
  1113.             begin
  1114.               state('Found dragon');
  1115.               waitFunc(@inCombat, 150, 3500);
  1116.               if getFightingMonster() = 'Steel dragon' then
  1117.               begin
  1118.                 state('We are fighting the dragon');
  1119.                 markTime(t);
  1120.                 while inCombat() do
  1121.                 begin
  1122.                   state('We will just check if health is low');
  1123.                   checkHealthPray;
  1124.                   if (timeFromMark(t) > 75000) then
  1125.                   begin
  1126.                     state('Woah took too long to kill dragon');
  1127.                     exit;
  1128.                   end;
  1129.                 end;
  1130.                 inventory.searchDTM(vialDTM, 0);
  1131.                 waitOption('rop', 800);
  1132.                 if (inventory.Full() or inventory.count = 27) then
  1133.                 begin
  1134.                   inventory.searchDTM([antiFireDTM, prayerDTM, attackDTM, strengthDTM, sharkDTM, vialDTM], 1);
  1135.                   waitOption('rop', 800);
  1136.                   wait(350);
  1137.                   inventory.searchDTM([antiFireDTM, prayerDTM, attackDTM, strengthDTM, sharkDTM, vialDTM], 1);
  1138.                   waitOption('rop', 800);
  1139.                 end;
  1140.                 pickUpItems();
  1141.                 waitOption('rop', 800);
  1142.                 writeln('waiting for dragon to spawn');
  1143.                 waitFunc(@seeDragon, 40, 15000);
  1144.               end;
  1145.             end else
  1146.             begin
  1147.               state('Can not find dragon');
  1148.               wait(200);
  1149.             end;
  1150.           Until (inventory.full()) or (timeFromMark(d) > 10000000);
  1151.         end else
  1152.         begin
  1153.           teleportTo(DUNGEON);
  1154.           walkToSpot;
  1155.         end;
  1156.       end;
  1157.       LOST:
  1158.       begin
  1159.         state('Lost, teleporting to soulwars bank');
  1160.         teleportTo(SWBANK);
  1161.         wait(3500);
  1162.       end;
  1163.     end;
  1164. end;
  1165.  
  1166. begin
  1167.   initDTMz();
  1168.   addOnTerminate('freememory');
  1169.   activateRsClient(true);
  1170.   wait(1500);
  1171.   inventory.bounds := IntTobox(567, 259, 722, 506);
  1172.   initInv();
  1173.   repeat
  1174.     checkHealthPray2();
  1175.     wait(2000);
  1176.   until false;
  1177.   lastPotion := -1000000;
  1178.   repeat
  1179.     wait(100);
  1180.     loop;
  1181.   until isKeyDown(113);
  1182. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement