Advertisement
zamaro

World Tracker v2

Jul 11th, 2014
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.52 KB | None | 0 0
  1. program worldtracker;
  2.  
  3. const
  4. ManualRefresh = false;
  5. Sleep_Intervals = 500;
  6. MinCount = 3;
  7. MsgBoxe = true;
  8. WarnCount = 6;
  9. XDistance = 70;
  10. Ydistance = 19;
  11.  
  12. type
  13. TWorld = record
  14. World, Players: Integer;
  15. end;
  16.  
  17. TDisplay = record
  18. Surface: Integer;
  19. Width, Height: Integer;
  20. end;
  21. TWorldArray = array of TWorld;
  22.  
  23. function World(__World, __Players: Integer): TWorld;
  24. begin
  25. Result.World := __World;
  26. Result.Players := __Players;
  27. end;
  28.  
  29. var
  30. MSGBoXES: boolean;
  31.  
  32. function SortWorlds(Worlds: TWorldArray): TWorldArray;
  33. var
  34. I, J, K: Integer;
  35. begin
  36. K := 301;
  37. repeat
  38. for I := 0 to High(Worlds) do
  39. begin
  40. if (Worlds[I].World = K) then
  41. begin
  42. Inc(J);
  43. SetLength(Result, J);
  44. Result[J - 1] := Worlds[I];
  45. end;
  46. end;
  47. Inc(K);
  48. until (Length(Result) = Length(Worlds));
  49. end;
  50.  
  51. function CalculateDifference(LC, CC: TWorldArray): TWorldArray;
  52. var
  53. I: Integer;
  54. begin
  55. SetLength(Result, Length(LC));
  56. for I := 0 to High(LC) do
  57. begin
  58. Result[I] := World(LC[I].World, CC[I].Players - LC[I].Players);
  59. end;
  60. end;
  61.  
  62. function GetData: string;
  63. var
  64. HTTPClient: Integer;
  65. begin
  66. HTTPClient := InitializeHTTPClient(False);
  67. Result := GetHTTPPage(HTTPClient, 'http://oldschool.runescape.com/c=sn10L0LBNoo/slu');
  68. FreeHTTPClient(HTTPClient);
  69. end;
  70.  
  71. function GetWorldData: TWorldArray;
  72. var
  73. Pieces, WorldPieces: TStringArray;
  74. I, J: Integer;
  75. begin
  76. Pieces := MultiBetween(GetData, 'e(', '");');
  77. for I := 0 to High(Pieces) do
  78. begin
  79. if (Pos('oldschool', Pieces[I]) > 0) then
  80. begin
  81. WorldPieces := Explode(',', Pieces[I]);
  82. Inc(J);
  83. SetLength(Result, J);
  84. Result[J - 1] := World(StrToInt(WorldPieces[0]), StrToInt(WorldPieces[4]));
  85. end;
  86. end;
  87. end;
  88.  
  89. function Display(Width, Height: Integer): TDisplay;
  90. begin
  91. Result.Surface := CreateBitmap(Width, Height);
  92. Result.Width := Width;
  93. Result.Height := Height;
  94. DisplayDebugImgWindow(Result.Width, Result.Height);
  95. end;
  96.  
  97. procedure ClearDisplay(__Display: TDisplay);
  98. begin
  99. FastDrawClear(__Display.Surface, clBlack);
  100. end;
  101.  
  102. procedure FlushDisplay(__Display: TDisplay);
  103. begin
  104. DrawBitmapDebugImg(__Display.Surface);
  105. end;
  106.  
  107. procedure FreeDisplay(__Display: TDisplay);
  108. begin
  109. FreeBitmap(__Display.Surface);
  110. end;
  111.  
  112. procedure DisplayDrawText(__Display: TDisplay; Text, Font: string; X, Y, Color: Integer);
  113. var
  114. TPA: TPointArray;
  115. W, H: Integer;
  116. begin
  117. TPA := TPAFromText(Text, Font, W, H);
  118. OffsetTPA(TPA, Point(X, Y));
  119. DrawTPABitmap(__Display.Surface, TPA, Color);
  120. end;
  121.  
  122. procedure AnsweredNo;
  123. begin
  124. Writeln('Disabling MsgBox for world Tracking...');
  125. MSGBoXES := false;
  126. end;
  127.  
  128. procedure DisplayDrawWorldInfo(__Display: TDisplay; World, Players, X, Y: Integer);
  129. var
  130. TPA: TPointArray;
  131. WorldInfos, C, W, W2, H, H2: Integer;
  132. begin
  133. if (Players < 0) then
  134. C := 255;
  135. if (Players = 0) or ((Players < MinCount) and (Players > 0)) then
  136. c := 16777215;
  137. if (Players >= MinCount) then
  138. C := 65280;
  139. TPA := TPAFromText(ToStr(World) + ':', 'SmallChars', W, H);
  140. OffsetTPA(TPA, Point(X, Y));
  141. DrawTPABitmap(__Display.Surface, TPA, clYellow);
  142. TPA := TPAFromText(ToStr(Players), 'SmallChars', W2, H2);
  143. OffsetTPA(TPA, Point(X + W + 2, Y));
  144. DrawTPABitmap(__Display.Surface, TPA, C);
  145. DisplayDrawText(__Display, 'Refresh', 'SmallChars', 120, 365, 16744192);
  146. if (Players >= WarnCount) and (MSGBoXES = true) and (World <> 301) and (world < 381) then
  147. begin
  148. WorldInfos := MessageBox('World: ' + IntToSTr(World) + ' Just went up by: ' + IntToStr(Players) + ' + Players', 'World Notice', 1);
  149. writeln(ToStr(WorldInfos));
  150. case (WorldInfos) of
  151. 1: Exit;
  152. 2: AnsweredNo;
  153. end;
  154. end;
  155. if (Players <= - WarnCount) and (MSGBoXES = true) and (World <> 301) and (world < 381) then
  156. begin
  157. WorldInfos := MessageBox('World: ' + IntToSTr(World) + ' Just went DOWN by: ' + IntToStr(Players) + ' - Players', 'World Notice', 1);
  158. writeln(ToStr(WorldInfos));
  159. case (WorldInfos) of
  160. 1: Exit;
  161. 2: AnsweredNo;
  162. end;
  163. end;
  164. end;
  165.  
  166. procedure DrawWorldData(__Display: TDisplay; Worlds: TWorldArray);
  167. var
  168. I, XOffset, YOffset, X, Y: Integer;
  169. begin
  170. ClearDisplay(__Display);
  171. XOffset := XDistance;
  172. YOffset := YDistance;
  173. DisplayDrawText(__Display, ' OSRS World Tracker - By Frement', 'SmallChars', 30, 10, 16744192);
  174. for I := 0 to High(Worlds) do
  175. begin
  176. DisplayDrawWorldInfo(__Display, Worlds[I].World, Worlds[I].Players, 20 + (XOffset * X), 40 + (YOffset * Y));
  177. Inc(Y);
  178. if (Y > 16) then
  179. begin
  180. Y := 0;
  181. Inc(X);
  182. end;
  183. end;
  184. FlushDisplay(__Display);
  185. end;
  186.  
  187. var
  188. LastCount, CurrentCount, Diff: TWorldArray;
  189. __Display: TDisplay;
  190. Box1: Tbox;
  191.  
  192. function FindAndSetTarget(TitlePrefix: string; SetAsTarget: Boolean): Boolean;
  193. var
  194. T: TSysProcArr;
  195. I: Integer;
  196. begin
  197. T := GetProcesses;
  198. for I := High(T) downto 0 do
  199. if Pos(TitlePrefix, T[I].Title) <> 0 then
  200. begin
  201. Result := True;
  202. if SetAsTarget then
  203. SetTarget(T[I]);
  204. Exit;
  205. end;
  206. end;
  207.  
  208. procedure GetRealMousePos(var X, Y: Integer);
  209. var
  210. KMTarget, ITarget: Integer;
  211. begin
  212. {$IFDEF LAPE}
  213. writeln('GetRealMousePos not implemented yet in SRL-5 Lape!');
  214. TerminateScript;
  215. {$ELSE}
  216. KMTarget := GetKeyMouseTarget;
  217. ITarget := GetImageTarget;
  218. FindAndSetTarget('DebugImgForm', True);
  219. GetTClient.IOManager.GetMousePos(X, Y);
  220. FreeTarget(GetImageTarget);
  221. SetKeyMouseTarget(KMTarget);
  222. SetImageTarget(ITarget);
  223. {$ENDIF}
  224. end;
  225.  
  226. function IsRealMouseInBox(B: TBox): Boolean;
  227. var
  228. P: TPoint;
  229. begin
  230. GetRealMousePos(P.X, P.Y);
  231. if PointInBox(P, B) then
  232. begin
  233. if ismouseButtonDown(Mouse_left) then
  234. result := true;
  235. end;
  236. end;
  237.  
  238. procedure OnTerminate;
  239. begin
  240. FreeDisplay(__Display);
  241. end;
  242.  
  243. procedure refresh;
  244. begin
  245. cleardebug;
  246. LastCount := SortWorlds(GetWorldData);
  247. Sleep(Sleep_Intervals);
  248. CurrentCount := SortWorlds(GetWorldData);
  249. Diff := CalculateDifference(LastCount, CurrentCount);
  250. DrawWorldData(__Display, Diff);
  251. SetTargetBitmap(__Display.Surface);
  252. end;
  253.  
  254. begin
  255. __Display := Display(300, 395);
  256. AddOnTerminate('OnTerminate');
  257. FindAndSetTarget('DebugImgForm', true);
  258. box1 := IntToBox(120, 380, 403, 350);
  259. MSGBoXES := MsgBoxe;
  260. repeat
  261. if (ManualRefresh = true) then
  262. begin
  263. if IsRealMouseInBox(box1) then
  264. refresh
  265. end
  266. else
  267. refresh;
  268. if IsRealMouseInBox(box1) then
  269. MSGBoXES := true;
  270. until (False);
  271. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement