Advertisement
lazyy

Untitled

Oct 14th, 2020
8,029
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.49 KB | None | 0 0
  1. //
  2. // The compiler has to be configured a certain way in order to be loaded as a script.
  3. //
  4. // Disable security checks
  5. // Disable exceptions
  6. // Disable RTTI
  7. // Multi-threaded DLL
  8. // Ignore default libraries
  9. // Set entry point to DllMain
  10. //
  11. // You will not be able to use advanced C++ features like the file system.
  12. // All memory allocation, and other missing imports should be handled by our SDK.
  13. // This is done for security purposes.
  14. //
  15. #include <Windows.h>
  16.  
  17. #include "SDK.h"
  18.  
  19. #define STATE_INIT 4
  20. #define STATE_WALK_TREES 3
  21. #define STATE_TREES 0
  22. #define STATE_WALK_BANK 2
  23. #define STATE_OPEN_BANK 1
  24. #define STATE_BANK 5
  25.  
  26. extern "C" int _fltused = 0;
  27.  
  28. //
  29. // The scripting SDK.
  30. //
  31. static SDK s;
  32.  
  33. //
  34. // If the script is enabled/running.
  35. //
  36. static BOOLEAN Enabled = TRUE;
  37.  
  38. //
  39. // The begin runtime of this script.
  40. //
  41. static UINT64 BeginRuntime = 0ull;
  42.  
  43. //
  44. // The current state index.
  45. //
  46. static UINT64 State = STATE_WALK_TREES;
  47.  
  48. //
  49. // The current state message;
  50. //
  51. static PCSTR StateMessage = "Starting...";
  52.  
  53. //
  54. // The next loop time.
  55. //
  56. static UINT64 NextTime = 0ull;
  57.  
  58. //
  59. // The selected tree to chop.
  60. //
  61. static INT32 SelectedTree = 0;
  62.  
  63. //
  64. // The total trees banked.
  65. //
  66. static SIZE_T TreesChopped = 0;
  67.  
  68. //
  69. // The start mining experience.
  70. //
  71. static UINT32 StartExperience = 0;
  72.  
  73. //
  74. // A ground item cache.
  75. //
  76. static ScriptGroundItem GroundItems[256];
  77.  
  78. //
  79. // An tree object.
  80. //
  81. struct TREE_OBJECT
  82. {
  83. UINT32 ObjectId;
  84. UINT32 X;
  85. UINT32 Y;
  86. UINT32 ItemId;
  87. SIZE_T Price;
  88. };
  89.  
  90. //
  91. // All tree objects the user can select from.
  92. //
  93. static TREE_OBJECT TreeObjects[] =
  94. {
  95. // regular tree - west varrock
  96. { 38787, 3170, 3417, 1511, 492 },
  97. // oak - west varrock
  98. { 38731, 3167, 3420, 1521, 324 },
  99. };
  100.  
  101. //
  102. // Index of each tree.
  103. //
  104. enum TreeIndices
  105. {
  106. TREE_INDEX = 0,
  107. OAK_INDEX = 1,
  108. };
  109.  
  110. //
  111. // The name of each tree object.
  112. //
  113. static PCSTR TreeNames[] =
  114. {
  115. "Tree",
  116. "Oak",
  117. };
  118.  
  119. //
  120. // Determines if a position is within bounds.
  121. //
  122. __forceinline BOOLEAN IsInBounds(ScriptVec2i* Bounds, ScriptVec2i Pos)
  123. {
  124. return Pos.X >= Bounds[0].X && Pos.Y >= Bounds[0].Y && Pos.X <= Bounds[1].X && Pos.Y <= Bounds[1].Y;
  125. }
  126.  
  127.  
  128. static INT32 RunPlayButton(UINT64 Time, const ScriptPlayer& Self)
  129. {
  130. static UINT64 NextPlay = 0;
  131.  
  132. StateMessage = "Clicking play";
  133. if (Time > NextPlay)
  134. {
  135. s.FindFunction<MenuWidgetClick>("Menu", "ClickWidget")(0xfffffffful, WIDGET_ID_PLAY, 1);
  136. NextPlay = Time + 10000;
  137. }
  138.  
  139. return 700;
  140. }
  141.  
  142. static INT32 ChopTree(UINT64 Time, const ScriptPlayer& Self)
  143. {
  144. static UINT64 NextTree = 0;
  145.  
  146. if (s.FindFunction<InventoryIsFull>("Inventory", "IsFull")())
  147. {
  148. State = STATE_WALK_BANK;
  149. return 0;
  150. }
  151. else if (Time > NextTree || !Self.InAnimation)
  152. {
  153. if (SelectedTree == 0) {
  154. StateMessage = "Chopping regular tree";
  155. }
  156. else {
  157. StateMessage = "Chopping oak tree";
  158. }
  159.  
  160. NextTree = Time + 20000;
  161.  
  162. auto tree = TreeObjects[SelectedTree];
  163. s.FindFunction<MenuObjectClick>("Menu", "ClickObject")(tree.ObjectId, tree.X, tree.Y, 1);
  164. return 1000;
  165. }
  166.  
  167. return 100;
  168. }
  169.  
  170. static INT32 RunTreeWestVarrock(UINT64 Time, const ScriptPlayer& Self)
  171. {
  172. StateMessage = "Walking to trees";
  173.  
  174. ScriptVec2i Point = { 0xc61, 0xd56 };
  175. auto Location = Self.GlobalPosition;
  176. auto Distance = abs(Point.X - Location.X) + abs(Point.Y - Location.Y);
  177. if (Distance < 7)
  178. {
  179. State = STATE_TREES;
  180. }
  181. else if (!Self.IsMoving)
  182. {
  183. s.FindFunction<MovementWalk>("Movement", "Walk")(Point.X, Point.Y);
  184. return 1000;
  185. }
  186. return 100;
  187. }
  188.  
  189. static INT32 RunWalkBankWestVarrock(UINT64 Time, const ScriptPlayer& Self)
  190. {
  191. StateMessage = "Walking to bank";
  192.  
  193. ScriptVec2i Point = { 0xc61, 0xd56 };
  194. auto Location = Self.GlobalPosition;
  195. auto Distance = abs(Point.X - Location.X) + abs(Point.Y - Location.Y);
  196. if (Distance < 7)
  197. {
  198. State = STATE_OPEN_BANK;
  199. }
  200. else if (!Self.IsMoving)
  201. {
  202. s.FindFunction<MovementWalk>("Movement", "Walk")(Point.X, Point.Y);
  203. return 1000;
  204. }
  205. return 100;
  206. }
  207.  
  208. static INT32 RunOpenBankWestVarrock(UINT64 Time, const ScriptPlayer& Self)
  209. {
  210. StateMessage = "Opening bank";
  211.  
  212. s.FindFunction<MenuObjectClick>("Menu", "ClickObject")(0x30e, 0xc6d, 0xd6c, 2);
  213. if (s.FindFunction<BankIsOpen>("Bank", "IsOpen")())
  214. {
  215. State = STATE_BANK;
  216. return 1000;
  217. }
  218. else
  219. {
  220. return 100;
  221. }
  222. }
  223.  
  224.  
  225. static INT32 RunBank(UINT64 Time, const ScriptPlayer& Self)
  226. {
  227. StateMessage = "Banking";
  228.  
  229. ScriptItem FirstTree;
  230. if (s.FindFunction<InventoryGetFirstItem>("Inventory", "GetFirstItem")(TreeObjects[SelectedTree].ItemId, &FirstTree))
  231. {
  232. s.FindFunction<MenuWidgetItemClick>("Menu", "ClickWidgetItem")(7, FirstTree.Slot, 0x205000f);
  233. }
  234.  
  235. State = STATE_WALK_TREES;
  236. return 1000;
  237. }
  238.  
  239. //
  240. // Runs the script loop.
  241. //
  242. static INT32 Run(const ScriptPlayer& Self)
  243. {
  244. static UINT64 NextClickTime = 0;
  245. static UINT64 InvisCounter = 0;
  246.  
  247. auto Time = GetTickCount64();
  248. if (!Self.IsValid())
  249. {
  250. InvisCounter += 1;
  251. if (InvisCounter > 5)
  252. {
  253. InvisCounter = 0;
  254. return RunPlayButton(Time, Self);
  255. }
  256. return 800;
  257. }
  258. else
  259. {
  260. if (!StartExperience)
  261. {
  262. StartExperience = s.FindFunction<ClientGetStat>("Client", "GetStat")(STAT_WOODCUTTING).Xp;
  263. }
  264.  
  265. InvisCounter = 0;
  266. }
  267.  
  268. if (Time > NextClickTime)
  269. {
  270. StateMessage = "Moving mouse some";
  271.  
  272. s.FindFunction<InputRightClick>("Input", "RightClick")(30, 30);
  273. NextClickTime = (Time + 30000);
  274. return 700;
  275. }
  276.  
  277. if (State == STATE_WALK_TREES)
  278. {
  279. return RunTreeWestVarrock(Time, Self);
  280. }
  281. else if (State == STATE_WALK_BANK)
  282. {
  283. return RunWalkBankWestVarrock(Time, Self);
  284. }
  285. else if (State == STATE_OPEN_BANK)
  286. {
  287. return RunOpenBankWestVarrock(Time, Self);
  288. }
  289. else if (State == STATE_TREES)
  290. {
  291. return ChopTree(Time, Self);
  292. }
  293. else if (State == STATE_BANK)
  294. {
  295. return RunBank(Time, Self);
  296. }
  297.  
  298. StateMessage = "Unknown";
  299. return 10000;
  300. }
  301.  
  302. static UINT64 OnLoop()
  303. {
  304. if (!Enabled)
  305. {
  306. return 1000;
  307. }
  308.  
  309. return Run(s.FindFunction<PlayerGetSelf>("Players", "GetSelf")());
  310. }
  311.  
  312. static SIZE_T PerHour(UINT64 Total, UINT64 Runtime)
  313. {
  314. auto RuntimeSeconds = (DOUBLE)Runtime / 1000.0;
  315. if (!RuntimeSeconds)
  316. {
  317. return 0ull;
  318. }
  319.  
  320. auto XpPerSecond = ((DOUBLE)Total / (DOUBLE)RuntimeSeconds);
  321. return (SIZE_T)(XpPerSecond * 3600.0);
  322. }
  323.  
  324. static VOID OnPaint()
  325. {
  326. if (s.FindFunction<OverlayBegin>("Overlay", "Begin")("Varrock West Chopper 1.0"))
  327. {
  328. s.FindFunction<OverlayCheckbox>("Overlay", "Checkbox")("Enabled", &Enabled);
  329.  
  330. if (Enabled)
  331. {
  332. s.FindFunction<OverlayListBox>("Overlay", "ListBox")("Tree types", &SelectedTree, TreeNames, sizeof(TreeNames) / sizeof(TreeNames[0]));
  333.  
  334. auto MsInSecond = 1000ull;
  335. auto MsInMinute = MsInSecond * 60ull;
  336. auto MsInHour = MsInMinute * 60ull;
  337. auto MsInDay = MsInHour * 24ull;
  338.  
  339. auto Runtime = (GetTickCount64() - BeginRuntime);
  340. auto RuntimeAcc = Runtime;
  341.  
  342. auto Days = RuntimeAcc / MsInDay;
  343. RuntimeAcc -= (Days * MsInDay);
  344.  
  345. auto Hours = RuntimeAcc / MsInHour;
  346. RuntimeAcc -= (Hours * MsInHour);
  347.  
  348. auto Minutes = RuntimeAcc / MsInMinute;
  349. RuntimeAcc -= (Minutes * MsInMinute);
  350.  
  351. auto Seconds = RuntimeAcc / MsInSecond;
  352.  
  353. s.FindFunction<OverlayLabel>("Overlay", "Label")("Runtime", "%dd:%dh:%dm:%ds", 4, Days, Hours, Minutes, Seconds);
  354. s.FindFunction<OverlayLabel>("Overlay", "Label")("State", "%s", 1, StateMessage);
  355. s.FindFunction<OverlayLabel>("Overlay", "Label")("Trees", "%d (%d p/h)", 2, TreesChopped, PerHour(TreesChopped, Runtime));
  356.  
  357. auto XpGained = s.FindFunction<ClientGetStat>("Client", "GetStat")(STAT_MINING).Xp - StartExperience;
  358. s.FindFunction<OverlayLabel>("Overlay", "Label")("Xp", "%d (%d p/h)", 2, XpGained, PerHour(XpGained, Runtime));
  359.  
  360. auto ProfitGained = TreesChopped * TreeObjects[SelectedTree].Price;
  361. s.FindFunction<OverlayLabel>("Overlay", "Label")("Profits", "%d (%d p/h)", 2, ProfitGained, PerHour(ProfitGained, Runtime));
  362. }
  363.  
  364. s.FindFunction<OverlayEnd>("Overlay", "End")();
  365. }
  366. }
  367.  
  368. static VOID ScriptOnInventoryItemChanged(INT32 Slot, INT32 OldId, INT32 NewId)
  369. {
  370. if (NewId == TreeObjects[SelectedTree].ItemId)
  371. {
  372. TreesChopped += 1;
  373. }
  374. }
  375.  
  376. static VOID OnRegisterScript(ScriptContext* C)
  377. {
  378. //
  379. // TODO FIXME we fucked the CRT, so nothing is initialized!
  380. //
  381. BeginRuntime = GetTickCount64();
  382. StartExperience = 0;
  383.  
  384. ::s = C->ScriptSDK;
  385. C->OnLoop = OnLoop;
  386. C->OnPaint = OnPaint;
  387. C->OnInventoryItemChanged = ScriptOnInventoryItemChanged;
  388. }
  389.  
  390. BOOL APIENTRY DllMain(HMODULE Module, DWORD ReasonForCall, BotContext* C)
  391. {
  392. C->RegisterScript(OnRegisterScript);
  393. return TRUE;
  394. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement