Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.35 KB | None | 0 0
  1. program Universal_Miner_V021;
  2. {$DEFINE SMART}
  3. {$I SRL/OSR.simba}
  4. {$I RSWalker/Walker.simba}
  5. {$H-}{$R+}{$X+}
  6. {==============================================================================]
  7. | Universal Miner ™
  8. |
  9. | Steps to use:
  10. | 1. For longer runs you need to declare login details bellow
  11. | 2. Start the script at your mining site, and run setup.
  12. [==============================================================================}
  13. type EDropStyle = (dsRegular, dsIntense, dsAdaptive);
  14. {$DEFINE SMARTDEBUG}
  15. const
  16. LOGIN_NAME = 'scom';
  17. LOGIN_PASS = ''ac';
  18. RS_WORLD = 335; // preferred world
  19. SHIFT_DROP = True; // use shift to drop
  20. INTENSE_DROP = dsRegular; // dsIntense, and dsAdaptive = mine some drop some (Often higher XP)
  21.  
  22. CONFIG_PATH = IncludePath+'Universal_Miner/';
  23. CONFIG_FILE = 'config.cfg';
  24. CONFIG_MAP = 'map.png';
  25.  
  26. type
  27. TClickHistory = record
  28. Data: TRectArray;
  29. end;
  30.  
  31. TStatistics = record
  32. Trips: Int32;
  33. StartInfo: TSkillInfo;
  34. CurrLvl: Int32;
  35. Count: Int32;
  36. PrcToNextLvl: Int32;
  37. Gains,Rem,CurrXP:Double;
  38. XPPerOre: Int32;
  39. DismissedRandoms: Int32;
  40. Isset_XPPerOre: Boolean;
  41. end;
  42.  
  43. TBreakTimer = record
  44. Name: String;
  45. Interval: Double;
  46. Length: Double;
  47. Prev: Double;
  48. LogoutChance: Int32;
  49. end;
  50.  
  51. TAntibanTask = record
  52. BaseInterval: Double;
  53. NextAtTime: Double;
  54. Method: procedure of object;
  55. end;
  56.  
  57. TAntiban = record
  58. ActiveSkill: Int32;
  59. Tasks: array of TAntibanTask;
  60. end;
  61.  
  62. TMiner = record
  63. PlayerBox: TBox;
  64. ConfigPath: String;
  65.  
  66. StartTime: Int64;
  67. EnergyLevel: Double;
  68. QuickDeposit: Boolean;
  69. BotStats: TStatistics;
  70. StatsDebugTick: Int64;
  71.  
  72. RockSpots, BankSpots: TPointArray;
  73. RockColors, BankColors: array of TCTS2Color;
  74. BankPath: TPointArray;
  75.  
  76. ClickOrder: TClickHistory;
  77. ProggyArea: TBox;
  78. BufferImage: TMufasaBitmap;
  79.  
  80. Breaks: array of TBreakTimer;
  81. Antiban: TAntiban;
  82.  
  83. Notes: TStringArray;
  84.  
  85. __RndCalls: Int32;
  86. end;
  87.  
  88.  
  89. const
  90. ONE_SECOND = 1000;
  91. ONE_MINUTE = ONE_SECOND * 60;
  92. ONE_HOUR = ONE_MINUTE * 60;
  93. ONE_DAY = ONE_HOUR * 24;
  94.  
  95. var
  96. INTENSITY_LEVEL: Double;
  97. CHANCE_OF_MISS = 1;
  98.  
  99. var
  100. Bot: TMiner;
  101. RSW: TRSWalker;
  102.  
  103.  
  104. // -----------------------------------------------------------------------------
  105. // -----------------------------------------------------------------------------
  106. // WIN API stuff
  107.  
  108. const WINAPI_CC = {$IFDEF CPU386}' stdcall'{$ELSE}' win64'{$ENDIF};
  109. const ffi_winapi = {$IFDEF CPU386}ffi_stdcall{$ELSE}ffi_win64{$ENDIF};
  110.  
  111. type
  112. _EnumWindowsProc = function(wnd:DWORD; Param:Pointer): LongBool;
  113. TEnumWindowsProc = native(_EnumWindowsProc, ffi_winapi);
  114.  
  115. function GetAsyncKeyState(vKey: Int32): Int16; external 'GetAsyncKeyState@user32.dll' + WINAPI_CC;
  116. function GetForegroundWindow(): PtrUInt; external 'GetForegroundWindow@user32.dll' + WINAPI_CC;
  117. function GetWindowThreadProcessId(wnd: PtrUInt; out dwProcessId: DWORD): DWORD; external 'GetWindowThreadProcessId@user32.dll' + WINAPI_CC;
  118. function EnumChildWindows(hWndParent: DWORD; func: TEnumWindowsProc; Param: Pointer): LongBool; external 'EnumChildWindows@user32.dll' + WINAPI_CC;
  119.  
  120. function GetKeyDown(): Char;
  121. var
  122. key: Word;
  123. keys: array of Word;
  124. begin
  125. keys := [VK_A..VK_Z];
  126. keys += [VK_0..VK_9];
  127. keys += [VK_OEM_PERIOD, VK_OEM_MINUS];
  128. for Key in keys do
  129. if GetAsyncKeyState(key) and $8000 <> 0 then
  130. begin
  131. while GetAsyncKeyState(key) and $8000 <> 0 do Wait(10);
  132. if key = VK_OEM_PERIOD then key := Ord('.');
  133. if key = VK_OEM_MINUS then key := Ord('-');
  134. Exit(Char(key));
  135. end;
  136. end;
  137.  
  138. function IsKeyDown2(vKey: Word): Boolean;
  139. begin
  140. Result := GetAsyncKeyState(vKey) and $8000 <> 0;
  141. end;
  142.  
  143. function HasFocus(PID: PtrUInt): Boolean;
  144. var tmp: DWORD;
  145. begin
  146. GetWindowThreadProcessId(GetForegroundWindow(), tmp);
  147. Result := tmp = PID;
  148. end;
  149.  
  150. function GetRSAppletWnd(PID: DWORD): DWORD;
  151. function GetLastChild(Handle: DWORD; Param: Pointer): LongBool; static;
  152. begin
  153. DWORD(Param^) := handle;
  154. Result := True;
  155. end;
  156. var
  157. p: TSysProc;
  158. client: DWORD;
  159. begin
  160. for p in GetProcesses() do
  161. if p.Pid = PID then
  162. Break;
  163. EnumChildWindows(p.Handle, @GetLastChild, @Result);
  164. end;
  165.  
  166.  
  167. // -----------------------------------------------------------------------------
  168. // -----------------------------------------------------------------------------
  169. // UTILITY FUNCTIONS
  170.  
  171. function StrToTPA(s:String): TPointArray;
  172. var
  173. i: Int32;
  174. Arr: TExtArray;
  175. begin
  176. Arr := s.ExtractNumbers();
  177. SetLength(Result, Length(Arr) div 2);
  178. for i:=0 to High(Result) do
  179. begin
  180. Result[i].x := Trunc(Arr[i*2]);
  181. Result[i].y := Trunc(Arr[i*2+1]);
  182. end;
  183. end;
  184.  
  185. function StrToCTS2(s:String): array of TCTS2Color;
  186. var
  187. i: Int32;
  188. Arr: TExtArray;
  189. begin
  190. Arr := s.ExtractNumbers();
  191. SetLength(Result, Length(Arr) div 4);
  192. for i:=0 to High(Result) do
  193. begin
  194. Result[i].Color := Trunc(Arr[i*4]);
  195. Result[i].Tolerance := Trunc(Arr[i*4+1]);
  196. Result[i].HueMod := Arr[i*4+2];
  197. Result[i].SatMod := Arr[i*4+3];
  198. end;
  199. end;
  200.  
  201. procedure TMouse.Move(P: TPoint); override;
  202. var
  203. dist: Double;
  204. q: TPoint;
  205. maxSpeed := Random(20,22);
  206. minSpeed := Random(4,6);
  207. begin
  208. q := Self.GetPosition;
  209. dist := Hypot(q.x-p.x, q.y-p.y);
  210. self.Speed := Trunc(minSpeed + (maxSpeed-minSpeed) * Power(dist / 1000, 1/2));
  211. inherited;
  212. end;
  213.  
  214. procedure DebugNote(s: String);
  215. begin
  216. Bot.Notes += '['+FormatDateTime('hh:mm:ss', Now())+']' + s;
  217. WriteLn(Bot.Notes[High(Bot.Notes)]);
  218. end;
  219.  
  220.  
  221. // -----------------------------------------------------------------------------
  222. // -----------------------------------------------------------------------------
  223. // MISC BOT FUNCTIONS
  224.  
  225. function WorldToMSTile(Me, ObjLoc: TPoint; Height:Double=0; Offx,Offy:Double=0): TRectangle;
  226. var
  227. Angle: Double;
  228. begin
  229. ObjLoc := Point(MM2MS.MMCX, MM2MS.MMCY) + (ObjLoc - Me);
  230. Angle := Minimap.GetCompassAngle(False);
  231. ObjLoc := ObjLoc.Rotate(Angle, Point(MM2MS.MMCX, MM2MS.MMCY));
  232. Result := Minimap.VecToMSRect(Vec3(ObjLoc.x - offx, ObjLoc.y - offy, Height), Angle);
  233. end;
  234.  
  235. procedure TClickHistory.Push(x: TRectangle);
  236. begin
  237. Insert(x, Self.Data, 0);
  238. end;
  239.  
  240. function TClickHistory.Pop(): TRectangle;
  241. begin
  242. if Length(Self.Data) < Length(Bot.RockSpots) then
  243. Exit(Self.Data[High(Self.Data)]);
  244. Result := Self.Data[High(Self.Data)];
  245. SetLength(Self.Data, High(Self.Data));
  246. end;
  247.  
  248.  
  249. // -----------------------------------------------------------------------------
  250. // -----------------------------------------------------------------------------
  251. // OVERRIDES AND METHODS FOR FATIGUE
  252.  
  253. procedure WaitFatigue(t: Double; Exp: Double=0.2);
  254. begin
  255. System.Wait(Trunc(2*t * (1-Power(System.Max(0.0001, Bot.EnergyLevel/100),Exp))));
  256. end;
  257.  
  258. procedure Wait(min, max:Double; weight:EWaitDir=wdMean); override;
  259. var t:Double;
  260. begin
  261. t := PerformanceTimer();
  262. inherited(min, max, weight);
  263. WaitFatigue(PerformanceTimer()-t,0.2);
  264. end;
  265.  
  266. procedure WaitEx(mean, dev:Double); override;
  267. var t:Double;
  268. begin
  269. t := PerformanceTimer();
  270. inherited(mean, dev);
  271. WaitFatigue(PerformanceTimer()-t, 0.2);
  272. end;
  273.  
  274.  
  275. // -----------------------------------------------------------------------------
  276. // -----------------------------------------------------------------------------
  277. // DRAWING UTILITIES
  278.  
  279. function NewFont(name:String; size:Int32; fs:TFontStyles; fq:TFontQuality): TFont;
  280. begin
  281. Result.Init();
  282. Result.SetName(name);
  283. Result.SetSize(size);
  284. Result.SetStyle(fs);
  285. Result.SetQuality(fq);
  286. Result.SetColor($FFFFFF);
  287. end;
  288.  
  289. var
  290. ProggyFont := NewFont('Tahoma', 7, [fsBold], fqCleartype);
  291. PercentBarFont := NewFont('Tahoma', 7, [fsBold], fqCleartype);
  292.  
  293.  
  294. procedure TMufasaBitmap.ClearAllBut(Area: TBox);
  295. var
  296. CLB: TBox;
  297. begin
  298. CLB := srl.DefaultClientBounds;
  299. Area.Expand(1);
  300. Area.LimitTo(CLB);
  301.  
  302. Smart.Image.ClearArea(Box(CLB.X1,CLB.Y1,Area.x1,Area.y1)); //left T
  303. Smart.Image.ClearArea(Box(CLB.X1,Area.y1,Area.x1,Area.y2)); //.. M
  304. Smart.Image.ClearArea(Box(CLB.X1,Area.y1,Area.x1,CLB.y2)); //.. B
  305. Smart.Image.ClearArea(Box(Area.x1,CLB.Y1,Area.x2,Area.y1)); //mid T
  306. Smart.Image.ClearArea(Box(Area.x1,Area.y2,Area.x2,CLB.y2)); //.. B
  307. Smart.Image.ClearArea(Box(Area.x2,CLB.Y1,CLB.x2,Area.y1)); //right T
  308. Smart.Image.ClearArea(Box(Area.x2,Area.y1,CLB.x2,Area.y2)); //.. M
  309. Smart.Image.ClearArea(Box(Area.x2,Area.y1,CLB.x2,CLB.y2)); //.. B
  310. end;
  311.  
  312. procedure TMufasaBitmap.DrawText(txt:String; pt:TPoint; font:TFont;
  313. color:Int32; align:Int32=0; shadow:Boolean=False; shadowDir:Byte=0); overload;
  314. var
  315. bit:TBitmap;
  316. muf:TMufasaBitmap;
  317. W,H:Int32;
  318. begin
  319. bit.Init();
  320. bit.GetCanvas().SetFont(font);
  321. bit.GetCanvas().GetBrush().SetStyle(bsClear);
  322.  
  323. W := bit.GetCanvas().TextWidth(txt);
  324. H := bit.GetCanvas().TextHeight(txt);
  325. bit.SetWidth(W+1);
  326. bit.SetHeight(H+1);
  327.  
  328. if align then
  329. pt := Point(pt.x-W, pt.y);
  330.  
  331. muf := self.Copy(pt.x,pt.y,pt.x+W,pt.y+H);
  332. muf.DrawToCanvas(0,0,bit.getCanvas());
  333.  
  334. if Shadow then
  335. begin
  336. bit.getCanvas().getFont().setColor(1);
  337. case ShadowDir of
  338. 0:bit.GetCanvas().TextOut(0,0,txt);
  339. 1:bit.GetCanvas().TextOut(1,0,txt);
  340. 2:bit.GetCanvas().TextOut(2,0,txt);
  341. 3:bit.GetCanvas().TextOut(2,1,txt);
  342. 4:bit.GetCanvas().TextOut(2,2,txt);
  343. 5:bit.GetCanvas().TextOut(1,2,txt);
  344. 6:bit.GetCanvas().TextOut(0,2,txt);
  345. 7:bit.GetCanvas().TextOut(0,1,txt);
  346. end;
  347. bit.GetCanvas().GetFont().SetColor(color);
  348. bit.GetCanvas().TextOut(1,1,txt);
  349. end else
  350. begin
  351. bit.GetCanvas().GetFont().SetColor(color);
  352. bit.GetCanvas().TextOut(0,0,txt);
  353. end;
  354. muf.LoadFromTBitmap(bit);
  355. muf.DrawTransparent(pt.x,pt.y,self);
  356.  
  357. muf.Free();
  358. bit.Free();
  359. end;
  360.  
  361. procedure TMufasaBitmap.DrawTextNL(txt:TStringArray; pos:TPoint; font:TFont;
  362. color:Int32; align:Int32=0; shadow:Boolean=False; shadowDir:Byte=0);
  363. var
  364. i,hei:Int32;
  365. begin
  366. hei := Round(1.2 * abs(font.GetHeight()));
  367. for i:=0 to High(txt) do
  368. begin
  369. Self.DrawText(txt[i],pos,font,color,align,shadow,shadowDir);
  370. inc(pos.y,hei);
  371. end;
  372. end;
  373.  
  374. procedure TMufasaBitmap.DrawPrecentBar(pt:TPoint; w,h,percent:Int32; BgColor:Int32=986895; BarColor:Int32=1474364; lText:String=''; rText:String='');
  375. var
  376. B:TBox;
  377. tx,ty:Int32;
  378. begin
  379. B := [pt.x,pt.y,pt.x+w-1,pt.y+h-1];
  380. Self.DrawTPA(TPAFromBox(B), BgColor);
  381. B.Expand(-2);
  382. B.x2 := B.x1 + round(B.Width() * (percent*0.01));
  383. Self.DrawTPA(TPAFromBox(B), BarColor);
  384.  
  385. tx := B.x1 + (W div 2) - 8;
  386. ty := B.y1 + (H div 2) - Abs(PercentBarFont.GetHeight()) + 1;
  387. Self.DrawText(ToStr(percent)+'%',Point(tx,ty),PercentBarFont,$FFFFFF);
  388. Self.DrawText(lText,Point(b.x1+4,ty), PercentBarFont,$FFFFFF,0,True,4);
  389. Self.DrawText(rText,Point(pt.x+w-5,ty),PercentBarFont,$FFFFFF,1,True,4);
  390. end;
  391.  
  392.  
  393. // -----------------------------------------------------------------------------
  394. // -----------------------------------------------------------------------------
  395. // ANTIBAN
  396.  
  397. procedure TAntiban.LoseFocus();
  398. begin
  399. DebugNote('[RND] Losing focus');
  400. srl.MouseOffClient();
  401. WaitEx(25000,2000);
  402. Players.GetCurrent()^.Login();
  403. if Random(4)=0 then Stats.HoverSkill(Self.ActiveSkill, srl.GaussRand(3000,400));
  404. end;
  405.  
  406. procedure TAntiban.HoverPlayers();
  407. begin
  408. DebugNote('[RND] Hovering players');
  409. srl.HoverRandomPlayer(20);
  410. end;
  411.  
  412. procedure TAntiban.CheckSkill();
  413. begin
  414. DebugNote('[RND] Check Skill Stats');
  415. Stats.HoverSkill(Self.ActiveSkill, srl.GaussRand(3000,400), Random(5) > 1);
  416. end;
  417.  
  418. procedure TAntiban.RandomCompass();
  419. begin
  420. DebugNote('[RND] Rotate Compass');
  421. Minimap.RandomCompass(-180,180, Random(5)=0);
  422. end;
  423.  
  424. procedure TAntiban.CheckStats();
  425. begin
  426. DebugNote('[RND] Look at Stats');
  427. Stats.Open();
  428. WaitEx(5000,400);
  429. if Random(2) = 0 then Inventory.Open();
  430. end;
  431.  
  432. procedure TAntiban.OpenRandomTab();
  433. begin
  434. DebugNote('[RND] Open Random Tab');
  435. Gametabs.Open(EGametab(Random(High(Gametabs.Tabs))));
  436. WaitEx(1600,100);
  437. if Random(4) = 0 then Inventory.Open()
  438. else if Random(4) = 0 then Stats.Open();
  439. end;
  440.  
  441. procedure TAntiban.VeryShortBreak();
  442. begin
  443. DebugNote('[RND] Taking a breather');
  444. if(Random(2)=0) then srl.MouseOffClient;
  445. WaitEx(50000,5000);
  446. Players.GetCurrent()^.Login();
  447. Wait(60,600, wdLeft);
  448. Stats.HoverSkill(Self.ActiveSkill, srl.GaussRand(3000,400));
  449. end;
  450.  
  451. procedure TAntiban.DoMiscStuff();
  452. begin
  453. DebugNote('[RND] Doing misc stuff');
  454. for 0 to Random(2) do
  455. begin
  456. if Random(3) = 0 then
  457. Gametabs.Open(EGametab(Random(High(Gametabs.Tabs))));
  458.  
  459. WaitEx(1500,200);
  460. if(Random(8) = 0) then
  461. begin
  462. if(Random(2) = 0) then srl.MouseOffClient();
  463. WaitEx(40000,4500);
  464. end;
  465.  
  466. if(Random(4) > 1) then
  467. begin
  468. Stats.HoverSkill(Self.ActiveSkill, srl.GaussRand(3000,400), Random(5) > 1);
  469. WaitEx(2500,300);
  470. end;
  471. end;
  472. end;
  473.  
  474.  
  475. //
  476.  
  477. function TAntiban.Init(): Boolean;
  478. var
  479. i: Int32;
  480. begin
  481. Self.ActiveSkill := SKILL_MINING;
  482. Self.Tasks := [
  483. TAntibanTask([ONE_MINUTE*7, 0, @Self.LoseFocus]),
  484. TAntibanTask([ONE_MINUTE*10, 0, @Self.HoverPlayers]),
  485. TAntibanTask([ONE_MINUTE*11, 0, @Self.CheckSkill]),
  486. TAntibanTask([ONE_MINUTE*13, 0, @Self.CheckStats]),
  487. TAntibanTask([ONE_MINUTE*16, 0, @Self.OpenRandomTab]),
  488. TAntibanTask([ONE_MINUTE*35, 0, @Self.VeryShortBreak]),
  489. TAntibanTask([ONE_MINUTE*35, 0, @Self.RandomCompass]),
  490. TAntibanTask([ONE_MINUTE*45, 0, @Self.DoMiscStuff])
  491. ];
  492.  
  493. for i:=0 to High(Self.Tasks) do
  494. begin
  495. Self.Tasks[i].BaseInterval := srl.GaussRand(Self.Tasks[i].BaseInterval, Self.Tasks[i].BaseInterval*0.1);
  496. Self.Tasks[i].NextAtTime := GetTimeRunning() + Random() * Self.Tasks[i].BaseInterval;
  497. end;
  498. end;
  499.  
  500. function TAntiban.DoAntiban(): Boolean;
  501. var
  502. i,j,PauseLen: Int32;
  503. begin
  504. for i:=0 to High(Self.Tasks) do
  505. if GetTimeRunning() > Self.Tasks[i].NextAtTime then
  506. begin
  507. Self.Tasks[i].Method();
  508. Self.Tasks[i].NextAtTime := GetTimeRunning() + srl.GaussRand(Self.Tasks[i].BaseInterval, Self.Tasks[i].BaseInterval*0.125);
  509. Result := True;
  510. end;
  511. end;
  512.  
  513.  
  514. // -----------------------------------------------------------------------------
  515. // -----------------------------------------------------------------------------
  516. // MINER
  517.  
  518. function TMiner.GetTimeRunning(): Int64;
  519. begin
  520. if Self.StartTime = 0 then Exit(0);
  521. Result := GetTickCount() - Self.StartTime;
  522. end;
  523.  
  524. function TMiner.TimeSinceBreak(): UInt64;
  525. var i: UInt64;
  526. begin
  527. Result := Self.GetTimeRunning();
  528. for i:=0 to High(Self.Breaks) do
  529. if(GetTimeRunning()-Self.Breaks[i].Prev < Result) then
  530. Result := GetTimeRunning()-Round(Self.Breaks[i].Prev);
  531. end;
  532.  
  533. function TMiner.BreakPower(): Double;
  534. var
  535. i,last: Int32;
  536. lastTime, perfect: Double;
  537. lastBreak: TBreakTimer;
  538. begin
  539. perfect := Self.Breaks[High(Self.Breaks)].Length;
  540. for i:=1 to High(Self.Breaks) do
  541. if Self.Breaks[i].Prev <= Self.Breaks[last].Prev then
  542. last := i;
  543.  
  544. lastBreak := Self.Breaks[last];
  545. Result := Power(lastBreak.Length / perfect, 1/2);
  546. end;
  547.  
  548. procedure TMiner.ReseedRandom(UpTo: Int32);
  549. var
  550. TimeRunning: Int64;
  551. begin
  552. TimeRunning := Self.GetTimeRunning();
  553. if UpTo >= 0 then Self.Breaks[0] := ['STUFF', ONE_HOUR*srl.GaussRand(1,0.1), ONE_MINUTE*srl.GaussRand(4,0.1), TimeRunning, 10];
  554. if UpTo >= 1 then Self.Breaks[1] := ['EAT', ONE_HOUR*srl.GaussRand(3,0.3), ONE_MINUTE*srl.GaussRand(20,5.0), TimeRunning, 80];
  555. if UpTo >= 2 then Self.Breaks[2] := ['SLEEP', ONE_HOUR*srl.GaussRand(9,1.0), ONE_HOUR*srl.GaussRand(14,1.0), TimeRunning, 90];
  556.  
  557. INTENSITY_LEVEL := Random(50,80);
  558. Self.EnergyLevel := 100 * BreakPower();
  559. end;
  560.  
  561. procedure TMiner.DrawProggy();
  562. var
  563. l: Int32;
  564. runtime: UInt32;
  565. str: TStringArray;
  566. statusText: TPointArray;
  567. begin
  568. if (ProggyArea = []) then ProggyArea := [290,9,510,62];
  569.  
  570. try
  571. runtime := GetTimeRunning();
  572.  
  573. BufferImage.DrawBox(Box(290,9,510,62), True, 5389366);
  574. BufferImage.DrawTPA([[290,9],[510,9],[290,62],[510,62]], 0);
  575.  
  576. BufferImage.DrawPrecentBar(
  577. [295,14], 210, 20, BotStats.PrcToNextLvl, //pos, w,h, percent
  578. 2628890,7880503, //colors
  579. 'Lvl: '+ToString(BotStats.CurrLvl), //left-text
  580. 'Lvl: '+ToString(BotStats.CurrLvl+1) //right-text
  581. );
  582.  
  583. str := ['Uptime: ' + srl.MsToTime(runtime, Time_Bare),
  584. 'Exp Gained: '+ srl.FormatNumber(BotStats.Gains,1)];
  585. BufferImage.DrawTextNL(str, Point(295,36), ProggyFont, $FFFFFF, 0, True, 4);
  586.  
  587. str := ['Exp/Hour: ' + srl.FormatNumber(BotStats.Gains / (runtime / ONE_HOUR),1) ,
  588. 'Mined: ' + ToStr(BotStats.Count) + ' ores'];
  589. BufferImage.DrawTextNL(str, Point(406,36), ProggyFont, $FFFFFF, 0, True, 4);
  590.  
  591. BufferImage.DrawTransparent(0,0, Smart.Image);
  592. except
  593. WriteLn('Error: Something went wrong');
  594. end;
  595. end;
  596.  
  597.  
  598. procedure TMiner.DeclarePlayers();
  599. begin
  600. with Players.New()^ do
  601. begin
  602. LoginName := LOGIN_NAME;
  603. Password := LOGIN_PASS;
  604. IsActive := True;
  605. IsMember := False;
  606. World := RS_WORLD;
  607. end;
  608. Players.SetCurrent(0);
  609. end;
  610.  
  611.  
  612. function TMiner.HasBanking(): Boolean;
  613. begin
  614. Result := (Self.BankColors <> []) and (Self.BankPath <> []) and (Self.BankSpots <> []);
  615. end;
  616.  
  617. function TMiner.DoBreak(ForceNearest: Boolean): Boolean;
  618. var
  619. i,j,PauseLen: Int32;
  620. begin
  621. for i:=0 to High(Breaks) do
  622. if GetTimeRunning() > Breaks[i].Prev + Breaks[i].Interval then
  623. begin
  624. PauseLen := Trunc(Max(ONE_MINUTE, srl.GaussRand(Breaks[i].Length, Breaks[i].Length*0.15)));
  625. DebugNote('[RND] Pausing for '+ ToStr(SRL.MsToTime(PauseLen, Time_Formal)) + ' ('+Breaks[i].Name+')');
  626.  
  627. if (Random(100) < Breaks[i].LogoutChance) then
  628. begin
  629. Logout.Open(); WaitEx(700,90);
  630. Logout.ClickLogout(); WaitEx(700,90);
  631. SRL.MouseOffClient();
  632. end;
  633.  
  634. repeat
  635. Wait(Min(PauseLen, ONE_MINUTE));
  636. PauseLen -= ONE_MINUTE;
  637. DebugNote('[RND] '+ ToStr(SRL.MsToTime(PauseLen, Time_Formal)) + ' left of the break');
  638. until PauseLen < 0;
  639.  
  640. Self.ReseedRandom(i);
  641. Exit(True);
  642. end;
  643. end;
  644.  
  645. procedure TMiner.DoAntiban();
  646. begin
  647. if Self.Antiban.DoAntiban() then
  648. begin
  649. Players.GetCurrent()^.Login(); // if we got logged out
  650. end;
  651.  
  652. if Self.DoBreak(False) then
  653. begin
  654. if Random(3) = 0 then
  655. begin
  656. Stats.HoverSkill(SKILL_MINING, srl.GaussRand(3000,400), Random(5) > 1);
  657. WaitEx(2500,500);
  658. end;
  659. Players.GetCurrent()^.Login(); // if we got logged out
  660. end;
  661. end;
  662.  
  663.  
  664. procedure TMiner.PostAction(CheckAntiban: Boolean = True);
  665. begin
  666. WaitEx(500,70);
  667. if CheckAntiban then Self.DoAntiban;
  668. end;
  669.  
  670.  
  671. procedure TMiner.ProcessWhileWaiting();
  672. var
  673. n,atNextLvl,atCurrLvl:Int32;
  674. begin
  675. BotStats.Gains := BotStats.count * BotStats.XPPerOre;
  676. BotStats.CurrXP := BotStats.StartInfo.XP + BotStats.Gains;
  677. BotStats.CurrLvl := srl.GetLevelAtXP(Ceil(BotStats.CurrXP));
  678. atNextLvl := srl.GetXPAtLevel(BotStats.CurrLvl+1);
  679. atCurrLvl := srl.GetXPAtLevel(BotStats.CurrLvl);
  680. BotStats.Rem := atNextLvl - BotStats.CurrXP;
  681. BotStats.PrcToNextLvl := 100 - Round((BotStats.Rem / (atNextLvl - atCurrLvl)) * 100);
  682.  
  683. if GetTickCount() - StatsDebugTick > 2000 then
  684. begin
  685. ClearDebug();
  686. WriteLn('+---| STATS |----------------------------------------');
  687. WriteLn('|- Trips / Drops : ', BotStats.Trips);
  688. WriteLn('|- Ores Mined : ', BotStats.Count);
  689. WriteLn('|- Experience Gained : ', BotStats.Gains);
  690. WriteLn('|- Experience Per Hour : ', Round(BotStats.Gains / (GetTimeRunning()/1000/60/60)) );
  691. WriteLn('|- Dismissed Randoms : ', BotStats.DismissedRandoms);
  692. WriteLn('|- Time Since Break : ', SRL.MsToTime(Self.TimeSinceBreak, Time_Short));
  693. WriteLn('|- Energy Level : ', Self.EnergyLevel);
  694. WriteLn('|- Script Runtime : ', SRL.MsToTime(GetTimeRunning, Time_Short));
  695. WriteLn('+----------------------------------------------------');
  696.  
  697. {$IFDEF SMARTDEBUG}
  698. Self.DrawProggy();
  699. {$ENDIF}
  700.  
  701. StatsDebugTick := GetTickCount();
  702. end;
  703. Self.DoAntiban;
  704. end;
  705.  
  706.  
  707. function TMiner.Contains(R: TRectangle; Colors: array of TCTS2Color): Boolean;
  708. var
  709. TPA: TPointArray;
  710. i, count: Int32;
  711. begin
  712. for i:=0 to High(Colors) do
  713. begin
  714. count += srl.FindColors(TPA, Colors[i], R.Bounds);
  715. if count > 150 then //XXXXXXXXXXXX
  716. Exit(True);
  717. end;
  718. end;
  719.  
  720.  
  721. function TMiner.Find(Locations: TPointArray): TRectArray;
  722. var
  723. i: Int32;
  724. me: TPoint;
  725. rect: TRectangle;
  726. begin
  727. me := RSW.GetMyPos();
  728. for i:=0 to High(Locations) do
  729. begin
  730. rect := WorldToMSTile(me, Locations[i], 0,0,0).Expand(-2);
  731. if MainScreen.GetBounds.Contains(rect.Bounds) then
  732. Result += rect;
  733. end;
  734.  
  735. if Length(Result) = 0 then
  736. TerminateScript('Not close enough to objects: ('+ ToStr(me.x) +','+ToStr(me.y)+') -> '+ ToStr(locations));
  737. end;
  738.  
  739.  
  740. function TMiner.DoWork(): Boolean;
  741. var
  742. i,next: Int32;
  743. T: TCountDown;
  744. TRA: TRectArray;
  745. tmpCurrXP, invCount: Int32;
  746.  
  747. function MaybeMiss(): Boolean;
  748. var
  749. R: TRectangle;
  750. begin
  751. Result := True;
  752. if Random()*100 <= CHANCE_OF_MISS then
  753. begin
  754. R := Minimap.PointToMsRect(Point(MM2MS.MMCX+Random(-6,6), MM2MS.MMCY+Random(-6,6)));
  755. Mouse.Move(R.Mean, Trunc(R.Radius), True);
  756. WaitEx(65,10);
  757. if MainScreen.IsUpText(['Walk here', 'Mine', 'Rocks']) then
  758. Exit();
  759. Result := False;
  760. end;
  761. end;
  762.  
  763. function ClickRock(rect: TRectangle): Int8;
  764. begin
  765. mouse.Move(TRA[i].Mean, Trunc(TRA[i].Radius), Random(10) = 0);
  766. WaitEx(65,10);
  767. if not Mainscreen.IsUpText(['Mine', 'Rocks']) then
  768. Exit(1);
  769.  
  770. if (not MaybeMiss()) then
  771. Exit(0);
  772.  
  773. if (not ((Random()*100 <= 5) and ChooseOption.Select('Mine Rocks'))) and
  774. (not Mouse.Click(ctRed)) then
  775. begin
  776. Wait(500,6000,wdLeft);
  777. Self.DoAntiban;
  778. WaitFatigue(Random(1000,4500), 0.6);
  779. Exit(0);
  780. end;
  781.  
  782. for 6 to Round(srl.TruncatedGauss(0,12)) do
  783. begin
  784. Mouse.Click(mouse_Left);
  785. WaitEx(70,10);
  786. end;
  787.  
  788. WaitEx(500,70);
  789. ClickOrder.Push(TRA[i]);
  790. Result := 2;
  791. end;
  792.  
  793. begin
  794. invCount := Inventory.Count;
  795. TRA := Find(self.RockSpots);
  796.  
  797. if (Self.BotStats.StartInfo = []) and (Self.BotStats.XPPerOre = 0) then
  798. begin
  799. Self.BotStats.StartInfo := Stats.GetSkillInfo(SKILL_MINING);
  800. Self.BotStats.XPPerOre := BotStats.StartInfo.XP;
  801. end;
  802.  
  803. for i:=0 to High(TRA) do
  804. begin
  805. if not Contains(TRA[i], Self.RockColors) then
  806. Continue;
  807.  
  808. WaitFatigue(Random(700,1200), 0.1);
  809. case ClickRock(TRA[i]) of
  810. 0: Exit;
  811. 1: Continue;
  812. 2: Minimap.WaitPlayerMoving(False);
  813. end;
  814.  
  815. TRA := Find(self.RockSpots); // update the TRA in case we moved
  816.  
  817. if (Self.EnergyLevel > INTENSITY_LEVEL) or (Random() < 0.05) then
  818. begin
  819. if(Random() < Self.BreakPower) then
  820. begin
  821. with ClickOrder.Pop() do
  822. Mouse.Move(Mean, Trunc(Radius))
  823. end
  824. else if(Random() < 0.05) then
  825. Mouse.Move(srl.DefaultClientBounds, True, rndRandom);
  826. end;
  827.  
  828. T.Init(srl.NormalRange(20000,25000)); //XXXXXXXXXXXX
  829. while (not T.IsFinished) and Contains(TRA[i], Self.RockColors) do
  830. begin
  831. if(Chatbox.GotLevelUp()) then
  832. if(Random(9) = 0) then
  833. Chatbox.HandleLevelUp()
  834. else
  835. Break;
  836.  
  837. if 'inventory is too full' in Chatbox.GetNotification() then
  838. Break;
  839.  
  840. Self.ProcessWhileWaiting();
  841. WaitEx(30,5);
  842. end;
  843.  
  844. if (Inventory.Count > invCount) then
  845. begin
  846. Inc(Self.BotStats.Count);
  847.  
  848. if (not Self.BotStats.Isset_XPPerOre) then //XXXXXXXXXXXX
  849. begin
  850. Self.BotStats.XPPerOre := Stats.GetSkillInfo(SKILL_MINING).XP - Self.BotStats.XPPerOre;
  851. Self.BotStats.Isset_XPPerOre := Self.BotStats.XPPerOre <> 0;
  852. end;
  853. end;
  854.  
  855. Exit(True);
  856. end;
  857. end;
  858.  
  859.  
  860. procedure TMiner.DoBanking();
  861. function OpenBank(): Boolean;
  862. var Rect: TRectangle;
  863. begin
  864. for 0 to 3 do
  865. begin
  866. for Rect in Find(self.BankSpots) do
  867. if Contains(Rect, Self.BankColors) and BankScreen.OpenAt(srl.RandomPoint(Rect.Mean, Trunc(Rect.Radius))) then
  868. Exit(True);
  869. Wait(800,1300);
  870. end;
  871. end;
  872.  
  873. function BankInventory(): Boolean;
  874. var
  875. slots: TIntArray;
  876. t: TCountDown;
  877. begin
  878. if Self.QuickDeposit then
  879. Exit(BankScreen.DepositAll);
  880.  
  881. slots := Inventory.GetUsedSlots();
  882. slots.Remove(0); //reserved
  883. while Length(slots) > 0 do
  884. begin
  885. Inventory.MouseSlot(slots[0]);
  886. ChooseOption.Select('Deposit-All');
  887. t.Init(2000);
  888. while Inventory.IsSlotUsed(slots[0]) and (not t.IsFinished) do WaitEx(90,10);
  889. slots := Inventory.GetUsedSlots();
  890. slots.Remove(0);
  891. end;
  892. Wait(1, 1200, wdLeft);
  893. Result := not Inventory.IsFull();
  894.  
  895. if Inventory.Count = 0 then
  896. Self.QuickDeposit := True;
  897. end;
  898.  
  899. function Walk(path: TPointArray): Boolean;
  900. begin
  901. for 0 to 2 do
  902. if RSW.WalkPath(Path) then
  903. Exit(True)
  904. else
  905. Wait(800, 3200, wdRight);
  906. end;
  907.  
  908. begin
  909. if(not Walk(self.BankPath)) then
  910. TerminateScript('Failed to walk path [1]');
  911. Self.DoAntiban;
  912.  
  913. if(not OpenBank()) then
  914. TerminateScript('Failed to open bank');
  915. PostAction(False);
  916.  
  917. if(not BankInventory()) then
  918. TerminateScript('Failed to deposit items');
  919. PostAction;
  920.  
  921. if(not Walk(self.BankPath.Reversed)) then
  922. TerminateScript('Failed to walk path [2]');
  923. Self.DoAntiban;
  924. end;
  925.  
  926.  
  927. procedure TMiner.IntenseDrop(Test: function: Boolean of Object);
  928. var
  929. p: TPoint;
  930. Slots: TIntArray;
  931. n: Int32 = 3;
  932. begin
  933. if Test() then Exit;
  934.  
  935. if Random(5) = 0 then
  936. n := Random(2,4);
  937.  
  938. p := Mouse.GetPosition();
  939. Slots := Inventory.GetUsedSlots();
  940. if (Length(Slots) >= 3)then
  941. begin
  942. if(not Self.QuickDeposit) then Slots.Remove(0);
  943.  
  944. SetLength(Slots, Min(Length(Slots), n));
  945. Inventory.DropItems(Inventory.ErrorPattern(Slots,2));
  946. Mouse.Move(p,20);
  947. end;
  948. end;
  949.  
  950. procedure TMiner.DropInventory();
  951. begin
  952. if Self.QuickDeposit then
  953. Inventory.DropItems(Inventory.ErrorPattern(DROP_PATTERN_SNAKE))
  954. else
  955. Inventory.DropItemsExcept([0], Inventory.ErrorPattern(DROP_PATTERN_SNAKE));
  956. end;
  957.  
  958.  
  959. procedure TMiner.Run();
  960. var
  961. loc: TPoint;
  962. tick: UInt64;
  963.  
  964. procedure TryDropWhileMining();
  965. begin
  966. if (not HasBanking) and (INTENSE_DROP in [dsIntense,dsAdaptive]) then
  967. begin
  968. if (INTENSE_DROP = dsIntense) then
  969. Self.IntenseDrop(@Self.DoWork)
  970. else if (INTENSE_DROP = dsAdaptive) and (Self.EnergyLevel > INTENSITY_LEVEL) then
  971. begin
  972. Self.IntenseDrop(@Self.DoWork);
  973. Self.EnergyLevel -= 0.05;
  974. Self.EnergyLevel := Max(1,Self.EnergyLevel);
  975. end;
  976. end;
  977. end;
  978.  
  979. begin
  980. Self.StartTime := GetTickCount();
  981. Self.Antiban.Init();
  982. if Inventory.Count = 0 then
  983. Self.QuickDeposit := True;
  984.  
  985. if Self.HasBanking() then
  986. begin
  987. loc := RSW.GetMyPos();
  988. if (Distance(loc, self.BankPath[high(self.BankPath)]) < Distance(loc, self.BankPath[0])) and
  989. (not RSW.WalkPath(self.BankPath.Reversed)) then
  990. TerminateScript('Failed to walk from bank on startup');
  991. end;
  992.  
  993. repeat
  994. if (Random(5000) <> 0) and Inventory.IsFull() then
  995. begin
  996. if HasBanking then Self.DoBanking()
  997. else Self.DropInventory();
  998. Inc(BotStats.Trips);
  999. end;
  1000.  
  1001. if Self.DoWork() then
  1002. begin
  1003. TryDropWhileMining();
  1004. Self.DoAntiban;
  1005. end else
  1006. Players.GetCurrent()^.Login();
  1007.  
  1008. if Self.GetTimeRunning() > tick then
  1009. begin
  1010. Self.EnergyLevel -= 1;
  1011. Self.EnergyLevel := Max(1,Self.EnergyLevel);
  1012. tick := Self.GetTimeRunning() + Random(ONE_MINUTE div 2, ONE_MINUTE + ONE_MINUTE div 2);
  1013. end;
  1014. Wait(1);
  1015. until False;
  1016. end;
  1017.  
  1018.  
  1019. procedure TMiner.Init();
  1020. var
  1021. W, H: Integer;
  1022. begin
  1023. GetClientDimensions(W, H);
  1024.  
  1025. self.PlayerBox := Minimap.VecToMsRect(Vec3(MM2MS.MMCX,MM2MS.MMCY,2)).Expand(7).Bounds;
  1026. self.DeclarePlayers();
  1027.  
  1028. Mouse.Speed := 10;
  1029. Players.GetCurrent()^.Login();
  1030. mainscreen.SetAngle(True);
  1031.  
  1032. BufferImage.Init(client.GetMBitmaps);
  1033. BufferImage.SetSize(Smart.Image.GetWidth, Smart.Image.GetHeight);
  1034.  
  1035. SetLength(Self.Breaks, 3);
  1036. Self.ReseedRandom(99);
  1037.  
  1038. Self.EnergyLevel := 100;
  1039. Inventory.ShiftDrop := SHIFT_DROP;
  1040. end;
  1041.  
  1042.  
  1043.  
  1044. // -----------------------------------------------------------------------------
  1045. // -----------------------------------------------------------------------------
  1046. // Crazy config generation
  1047.  
  1048. procedure TMiner.Setup();
  1049. var
  1050. r: String;
  1051. DefaultBox: TBox = [75,40, 425,140];
  1052. client2: TClient;
  1053.  
  1054. type
  1055. TButtonBox = record
  1056. TextTPA: TPointArray;
  1057. Bounds: TBox;
  1058. end;
  1059.  
  1060. function SlowMSToMM(MS: TPoint): TPoint;
  1061. var
  1062. x,y: Int32;
  1063. best,test: TPoint;
  1064. begin
  1065. for x:=MM2MS.MMCX-52 to MM2MS.MMCX+52 do
  1066. for y:=MM2MS.MMCY-52 to MM2MS.MMCY+52 do
  1067. begin
  1068. test := Minimap.PointToMs([x,y],0);
  1069. if Distance(test, MS) < Distance(best, MS) then
  1070. begin
  1071. best := test;
  1072. Result := Point(x,y);
  1073. end;
  1074. end;
  1075. end;
  1076.  
  1077. procedure WaitReleaseKey();
  1078. begin
  1079. while client2.GetIOManager.IsMouseButtonDown(0) do Wait(10);
  1080. end;
  1081.  
  1082. function GetClick(out p: TPoint): Boolean;
  1083. begin
  1084. if not HasFocus(smart.PID) then Exit();
  1085. if client2.GetIOManager.IsMouseButtonDown(0) then
  1086. begin
  1087. client2.GetIOManager.GetMousePos(p.x,p.y);
  1088. Result := p.InBox(GetClientBounds);
  1089. WaitReleaseKey();
  1090. end;
  1091. end;
  1092.  
  1093. function GetButton(txt: String): TButtonBox;
  1094. begin
  1095. Result.TextTPA := TPAFromText(txt, StatChars07);
  1096. Result.Bounds := GetTPABounds(Result.TextTPA).ExpandFunc(8);
  1097. end;
  1098.  
  1099. function DrawButton(p: TPoint; var Button: TButtonBox): TButtonBox;
  1100. begin
  1101. Button.TextTPA.Offset(p);
  1102. Button.Bounds.Offset(p);
  1103. smart.Image.DrawBox(Button.Bounds, True, 2502198);
  1104. smart.Image.DrawBox(Button.Bounds.ExpandFunc(-1), True, 4607315);
  1105. smart.Image.DrawTPA(Button.TextTPA, $FFFFFF);
  1106. end;
  1107.  
  1108. function MessageBox(Text: String; Area:TBox=[]): string;
  1109. var
  1110. xstart: Int32;
  1111. TPA: TPointArray;
  1112. box: TBox;
  1113. begin
  1114. if (Area.x1 = Area.x2) then Area := chatbox.GetBounds;
  1115. smart.Image.DrawBox(Area.ExpandFunc(-0), False, $1F2F33);
  1116. smart.Image.DrawBox(Area.ExpandFunc(-1), False, $3F4A5A);
  1117. smart.Image.DrawBox(Area.ExpandFunc(-2), False, $1F2F33);
  1118. smart.Image.DrawBox(Area.ExpandFunc(-3), True, $171D20);
  1119.  
  1120. TPA := TPAFromText(Text, SmallChars07);
  1121. box := GetTPABounds(TPA);
  1122. xstart := (box.Width + Area.Width) div 2 - box.Width;
  1123. OffsetTPA(TPA, Point(Area.x1+xstart, Area.y1+20));
  1124. smart.Image.DrawTPA(TPA, $FFFFFF);
  1125. end;
  1126.  
  1127. function Query(Text: String; Alts:TStringArray; Area:TBox=[]): string;
  1128. var
  1129. i,xstart,CurrWidth: Int32;
  1130. p: TPoint;
  1131. Buttons: array of TButtonBox;
  1132. xOffset: TIntArray;
  1133. begin
  1134. if (Area.x1 = Area.x2) then Area := chatbox.GetBounds;
  1135.  
  1136. // query
  1137. MessageBox(Text, Area);
  1138.  
  1139. // buttons
  1140. for i:=0 to High(Alts) do
  1141. begin
  1142. Buttons += GetButton(Alts[i]);
  1143. xOffset += CurrWidth;
  1144. CurrWidth += Buttons[i].Bounds.X2+20;
  1145. end;
  1146. CurrWidth -= 20;
  1147.  
  1148. xstart := (CurrWidth + Area.Width) div 2 - CurrWidth;
  1149. for i:=0 to High(Buttons) do
  1150. DrawButton(Point(Area.x1+xstart+xOffset[i], Area.y1+50), Buttons[i]);
  1151.  
  1152. // handling
  1153. while True do
  1154. begin
  1155. if GetClick(p) then
  1156. for i:=0 to High(Buttons) do
  1157. if PointInBox(p, Buttons[i].Bounds) then
  1158. begin
  1159. smart.Image.DrawBox(Area, True, 0);
  1160. Exit(Alts[i]);
  1161. end;
  1162. Wait(1);
  1163. end;
  1164. end;
  1165.  
  1166. function QueryStr(Text: String; Area:TBox=[]): string;
  1167. var
  1168. i: Int32;
  1169. pt, p: TPoint;
  1170. chr: Char;
  1171. B: TBox;
  1172. TPA: TPointArray;
  1173. Button: TButtonBox;
  1174. begin
  1175. if (Area.x1 = Area.x2) then
  1176. Area := chatbox.GetBounds;
  1177.  
  1178. // query
  1179. smart.Image.DrawBox(Area.ExpandFunc(-0), False, $1F2F33);
  1180. smart.Image.DrawBox(Area.ExpandFunc(-1), False, $3F4A5A);
  1181. smart.Image.DrawBox(Area.ExpandFunc(-2), False, $1F2F33);
  1182. smart.Image.DrawBox(Area.ExpandFunc(-3), True, $171D20);
  1183.  
  1184. TPA := TPAFromText(Text, SmallChars07);
  1185. OffsetTPA(TPA, Point(Area.x1+40, Area.y1+20));
  1186. smart.Image.DrawTPA(TPA, $FFFFFF);
  1187. B := GetTPABounds(TPA);
  1188.  
  1189. // button
  1190. Button := GetButton('OK');
  1191. DrawButton(Point(Area.x1+48, Area.y1+50), Button);
  1192.  
  1193. // handling
  1194. pt.x := B.x2+5;
  1195. pt.y := Area.y1+20;
  1196. repeat
  1197. while not HasFocus(smart.PID) do Wait(10);
  1198.  
  1199. if GetClick(p) then
  1200. if PointInBox(p, Button.Bounds) then
  1201. begin
  1202. smart.Image.DrawBox(Area, True, 0);
  1203. Exit(Result);
  1204. end;
  1205.  
  1206. chr := GetKeyDown();
  1207. if chr <> #0 then
  1208. begin
  1209. Result += Lowercase(chr);
  1210. Keyboard.PressKey(VK_BACK);
  1211. smart.Image.DrawText(Result,'SmallChars07', pt, False, $FFCCAA);
  1212. end;
  1213.  
  1214. if IsKeyDown2(VK_BACK) and (Result <> '') then
  1215. begin
  1216. TPA := TPAFromText(Result, 'SmallChars07');
  1217. TPA.Offset(pt);
  1218. smart.Image.DrawBox(GetTPABounds(TPA), True, $171D20);
  1219. while IsKeyDown2(VK_BACK) do Wait(50);
  1220. SetLength(Result, Length(Result)-1);
  1221. smart.Image.DrawText(Result, 'SmallChars07', pt, False, $FFCCAA);
  1222. end;
  1223. until False;
  1224. end;
  1225.  
  1226. function SetupLocations(): TPointArray;
  1227. var
  1228. p, me, worldPt: TPoint;
  1229. rect: TRectangle;
  1230. begin
  1231. me := RSW.GetMyPos();
  1232.  
  1233. while True do
  1234. begin
  1235. if GetClick(p) then
  1236. begin
  1237. worldPt := (SlowMSToMM(p) - Point(MM2MS.MMCX, MM2MS.MMCY)) + me;
  1238.  
  1239. rect := WorldToMSTile(me, worldPt);
  1240. if Mainscreen.GetBounds.Contains(rect.Bounds) then
  1241. begin
  1242. smart.Image.DrawTPA(rect.ToTPA.Connect, $FFFF);
  1243. case Query('Are you happy?', ['Add more', 'Retry', 'Yes']) of
  1244. 'Retry': smart.Image.DrawTPA(rect.ToTPA.Connect, 0);
  1245. 'Add more': Result += worldPt;
  1246. 'Yes': begin Result += worldPt; Break; end;
  1247. end;
  1248. end;
  1249. end;
  1250. Wait(1);
  1251. end;
  1252. smart.Image.Clear();
  1253. end;
  1254.  
  1255. function SetupColors(Locations: TPointArray): array of TCTS2Color;
  1256. var
  1257. i: Int32;
  1258. p,me: TPoint;
  1259. IsValid: Boolean;
  1260. R: array of TRectangle;
  1261. Color: TCTS2Color;
  1262. TPA: TPointArray;
  1263.  
  1264. function MarkColors(Colors: array of TCTS2Color): TPointArray;
  1265. var
  1266. i,j: Int32;
  1267. TPA: TPointArray;
  1268. begin
  1269. for i:=0 to High(Colors) do
  1270. for j:=0 to High(R) do
  1271. if srl.FindColors(TPA, Colors[i], R[j].Bounds.ExpandFunc(-1)) then
  1272. begin
  1273. TPA := R[j].Filter(TPA);
  1274. smart.Image.DrawTPA(TPA, $FF);
  1275. Result += TPA;
  1276. end;
  1277. end;
  1278. begin
  1279. me := RSW.GetMyPos();
  1280. SetLength(R, Length(Locations));
  1281. for i:=0 to High(Locations) do
  1282. begin
  1283. R[i] := WorldToMSTile(Me, Locations[i]);
  1284. smart.Image.DrawTPA(R[i].ToTPA.Connect, $00FF00);
  1285. end;
  1286.  
  1287. while True do
  1288. begin
  1289. if GetClick(p) then
  1290. begin
  1291. Color := CTS2(GetColor(p), 13);
  1292. for i:=0 to High(R) do
  1293. if R[i].Contains(p) then
  1294. begin
  1295. IsValid := True;
  1296. break;
  1297. end;
  1298. if(not IsValid) then
  1299. continue;
  1300.  
  1301. TPA := MarkColors(Result + Color);
  1302. case Query('Are you happy?', ['Add more', 'Retry', 'Reset', 'Yes']) of
  1303. 'Retry': smart.Image.DrawTPA(TPA, 0);
  1304. 'Add more': Result += Color;
  1305. 'Yes': begin Result += Color; Break; end;
  1306. 'Reset': begin smart.Image.DrawTPA(TPA, 0); Result := []; end;
  1307. end;
  1308. end;
  1309. Wait(1);
  1310. end;
  1311. smart.Image.Clear();
  1312. end;
  1313.  
  1314. function RecordPath(): TPointArray;
  1315. var
  1316. worldPt,p: TPoint;
  1317. t: UInt64;
  1318. begin
  1319. t := GetTickCount()+8000;
  1320. while True do
  1321. begin
  1322. if GetClick(p) then
  1323. begin
  1324. t := GetTickCount()+2500;
  1325. worldPt := RSW.GetMyPos();
  1326. Mouse.Click(p, mouse_Left);
  1327.  
  1328. Result += worldPt;
  1329. end;
  1330.  
  1331. if (GetTickCount() > t) and (not Minimap.isPlayerMoving()) then
  1332. case Query('Are we there yet?', ['No', 'Yes']) of
  1333. 'Yes': Exit(Result+RSW.GetMyPos());
  1334. 'No' : t := GetTickCount()+2500;
  1335. end;
  1336. Wait(1);
  1337. end;
  1338. end;
  1339.  
  1340. procedure GenerateMap(MapPath:String; Pad:Int32=160);
  1341. var
  1342. pt,sz: TPoint;
  1343. map,slice: TMufasaBitmap;
  1344. TPA: TPointArray;
  1345. B: TBox;
  1346. begin
  1347. TPA := Self.BankPath + Self.RockSpots + Self.BankSpots;
  1348.  
  1349. sz := Point(High(RSW.worldMap[0]),High(RSW.worldMap));
  1350. B := TPA.Bounds.ExpandFunc(Pad);
  1351. B.LimitTo(Box(0,0,sz.x,sz.y));
  1352.  
  1353. map.Init(client.GetMBitmaps);
  1354. map.SetSize(B.Width, B.Height);
  1355. for pt in TPA do
  1356. begin
  1357. slice.Init(client.GetMBitmaps);
  1358. slice.DrawMatrix(w_GetArea(RSW.worldMap, Max(0,pt.x-Pad), Max(0,pt.y-Pad), Min(sz.x,pt.x+Pad), Min(sz.y,pt.y+Pad)));
  1359. slice.DrawTransparent(pt.x-B.x1-Pad,pt.y-B.y1-Pad, map);
  1360. slice.Free();
  1361. end;
  1362. map.SaveToFile(MapPath);
  1363. map.Free();
  1364.  
  1365. Self.BankPath.Offset ([-B.x1,-B.y1]);
  1366. Self.RockSpots.Offset([-B.x1,-B.y1]);
  1367. Self.BankSpots.Offset([-B.x1,-B.y1]);
  1368. end;
  1369.  
  1370. function LoadConfig(): Boolean;
  1371. begin
  1372. if not FileExists(ConfigPath+CONFIG_FILE) then
  1373. Exit(False);
  1374.  
  1375. BankPath := StrToTPA (ReadINI('settings', 'BankPath', ConfigPath+CONFIG_FILE));
  1376. RockSpots := StrToTPA (ReadINI('settings', 'RockSpots', ConfigPath+CONFIG_FILE));
  1377. RockColors := StrToCTS2(ReadINI('settings', 'RockColors', ConfigPath+CONFIG_FILE));
  1378. BankSpots := StrToTPA (ReadINI('settings', 'BankSpots', ConfigPath+CONFIG_FILE));
  1379. BankColors := StrToCTS2(ReadINI('settings', 'BankColors', ConfigPath+CONFIG_FILE));
  1380. Result := True;
  1381. end;
  1382.  
  1383. procedure SaveConfig();
  1384. var
  1385. f: PtrInt;
  1386. begin
  1387. CreateDirectory(CONFIG_PATH);
  1388. CreateDirectory(ConfigPath);
  1389.  
  1390. GenerateMap(ConfigPath+CONFIG_MAP);
  1391. CloseFile(CreateFile(ConfigPath+CONFIG_FILE));
  1392.  
  1393. f := RewriteFile(Self.ConfigPath+CONFIG_FILE, True);
  1394. WriteFileString(f, '[settings]' + #13#10);
  1395. WriteFileString(f, 'BankPath = '+ToStr(BankPath) + #13#10);
  1396. WriteFileString(f, 'RockSpots = '+ToStr(RockSpots) + #13#10);
  1397. WriteFileString(f, 'RockColors = '+ToStr(RockColors)+ #13#10);
  1398. WriteFileString(f, 'BankSpots = '+ToStr(BankSpots) + #13#10);
  1399. WriteFileString(f, 'BankColors = '+ToStr(BankColors)+ #13#10);
  1400. CloseFile(f);
  1401. end;
  1402.  
  1403. label
  1404. START, QUERY_CONFIG;
  1405.  
  1406. begin
  1407. client2.Init(PluginPath);
  1408. client2.GetIOManager.SetTarget2(GetRSAppletWnd(SMART.PID));
  1409.  
  1410. START:
  1411. r := Query('Do you wish to run setup?', ['Yes','No'], DefaultBox);
  1412. if r = 'No' then
  1413. begin QUERY_CONFIG:
  1414. Self.ConfigPath := CONFIG_PATH + QueryStr('Name of config: ', DefaultBox) + '/';
  1415.  
  1416. if not LoadConfig() then
  1417. case Query('Failed to load config, try again?', ['Yes','No'], DefaultBox) of
  1418. 'Yes': goto QUERY_CONFIG;
  1419. 'No' : goto START;
  1420. end;
  1421.  
  1422. client2.Free();
  1423. Exit();
  1424. end;
  1425.  
  1426. r := MessageBox('Preparing, please stand by...', DefaultBox);
  1427. minimap.SetCompassAngle(0);
  1428. RSW.Init('world.png');
  1429.  
  1430. Query('Click the rocks you wish to mine...', ['OK'], DefaultBox);
  1431. RockSpots := SetupLocations();
  1432.  
  1433. Query('Click some colors for us to use...', ['OK'], DefaultBox);
  1434. RockColors := SetupColors(RockSpots);
  1435.  
  1436. if('Banking' = Query('Select style:', ['Banking','Powermining'], DefaultBox)) then
  1437. begin
  1438. Query('Please walk to your bank', ['OK'], DefaultBox);
  1439. BankPath := RSWUtils.BuildPath(RecordPath(), 8);
  1440.  
  1441. Query('Click valid bankers, or booths...', ['OK'], DefaultBox);
  1442. BankSpots := SetupLocations();
  1443.  
  1444. Query('Click some colors for us to use...', ['OK'], DefaultBox);
  1445. BankColors := SetupColors(BankSpots);
  1446. end;
  1447.  
  1448. Self.ConfigPath := CONFIG_PATH + QueryStr('Save config as: ', DefaultBox) + '/';
  1449. SaveConfig();
  1450.  
  1451. RSW.Free();
  1452. client2.Free();
  1453. end;
  1454.  
  1455.  
  1456. begin
  1457. smart.EnableDrawing := True;
  1458. srl.Setup([]);
  1459. AddOnTerminate(@smart.Free);
  1460.  
  1461. Bot.Init();
  1462. Bot.Setup();
  1463.  
  1464. RSW.Init(Bot.ConfigPath+CONFIG_MAP);
  1465. RSW.skipClose := 25;
  1466. RSW.walkStyle := wsSPS;
  1467. RSW.minRunEnergy := 35;
  1468. AddOnTerminate(@RSW.Free);
  1469.  
  1470. Bot.Run();
  1471. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement