Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // The compiler has to be configured a certain way in order to be loaded as a script.
- //
- // Disable security checks
- // Disable exceptions
- // Disable RTTI
- // Multi-threaded DLL
- // Ignore default libraries
- // Set entry point to DllMain
- //
- // You will not be able to use advanced C++ features like the file system.
- // All memory allocation, and other missing imports should be handled by our SDK.
- // This is done for security purposes.
- //
- #include <Windows.h>
- #include "SDK.h"
- #define STATE_INIT 4
- #define STATE_WALK_TREES 3
- #define STATE_TREES 0
- #define STATE_WALK_BANK 2
- #define STATE_OPEN_BANK 1
- #define STATE_BANK 5
- extern "C" int _fltused = 0;
- //
- // The scripting SDK.
- //
- static SDK s;
- //
- // If the script is enabled/running.
- //
- static BOOLEAN Enabled = TRUE;
- //
- // The begin runtime of this script.
- //
- static UINT64 BeginRuntime = 0ull;
- //
- // The current state index.
- //
- static UINT64 State = STATE_WALK_TREES;
- //
- // The current state message;
- //
- static PCSTR StateMessage = "Starting...";
- //
- // The next loop time.
- //
- static UINT64 NextTime = 0ull;
- //
- // The selected tree to chop.
- //
- static INT32 SelectedTree = 0;
- //
- // The total trees banked.
- //
- static SIZE_T TreesChopped = 0;
- //
- // The start mining experience.
- //
- static UINT32 StartExperience = 0;
- //
- // A ground item cache.
- //
- static ScriptGroundItem GroundItems[256];
- //
- // An tree object.
- //
- struct TREE_OBJECT
- {
- UINT32 ObjectId;
- UINT32 X;
- UINT32 Y;
- UINT32 ItemId;
- SIZE_T Price;
- };
- //
- // All tree objects the user can select from.
- //
- static TREE_OBJECT TreeObjects[] =
- {
- // regular tree - west varrock
- { 38787, 3170, 3417, 1511, 492 },
- // oak - west varrock
- { 38731, 3167, 3420, 1521, 324 },
- };
- //
- // Index of each tree.
- //
- enum TreeIndices
- {
- TREE_INDEX = 0,
- OAK_INDEX = 1,
- };
- //
- // The name of each tree object.
- //
- static PCSTR TreeNames[] =
- {
- "Tree",
- "Oak",
- };
- //
- // Determines if a position is within bounds.
- //
- __forceinline BOOLEAN IsInBounds(ScriptVec2i* Bounds, ScriptVec2i Pos)
- {
- return Pos.X >= Bounds[0].X && Pos.Y >= Bounds[0].Y && Pos.X <= Bounds[1].X && Pos.Y <= Bounds[1].Y;
- }
- static INT32 RunPlayButton(UINT64 Time, const ScriptPlayer& Self)
- {
- static UINT64 NextPlay = 0;
- StateMessage = "Clicking play";
- if (Time > NextPlay)
- {
- s.FindFunction<MenuWidgetClick>("Menu", "ClickWidget")(0xfffffffful, WIDGET_ID_PLAY, 1);
- NextPlay = Time + 10000;
- }
- return 700;
- }
- static INT32 ChopTree(UINT64 Time, const ScriptPlayer& Self)
- {
- static UINT64 NextTree = 0;
- if (s.FindFunction<InventoryIsFull>("Inventory", "IsFull")())
- {
- State = STATE_WALK_BANK;
- return 0;
- }
- else if (Time > NextTree || !Self.InAnimation)
- {
- if (SelectedTree == 0) {
- StateMessage = "Chopping regular tree";
- }
- else {
- StateMessage = "Chopping oak tree";
- }
- NextTree = Time + 20000;
- auto tree = TreeObjects[SelectedTree];
- s.FindFunction<MenuObjectClick>("Menu", "ClickObject")(tree.ObjectId, tree.X, tree.Y, 1);
- return 1000;
- }
- return 100;
- }
- static INT32 RunTreeWestVarrock(UINT64 Time, const ScriptPlayer& Self)
- {
- StateMessage = "Walking to trees";
- ScriptVec2i Point = { 0xc61, 0xd56 };
- auto Location = Self.GlobalPosition;
- auto Distance = abs(Point.X - Location.X) + abs(Point.Y - Location.Y);
- if (Distance < 7)
- {
- State = STATE_TREES;
- }
- else if (!Self.IsMoving)
- {
- s.FindFunction<MovementWalk>("Movement", "Walk")(Point.X, Point.Y);
- return 1000;
- }
- return 100;
- }
- static INT32 RunWalkBankWestVarrock(UINT64 Time, const ScriptPlayer& Self)
- {
- StateMessage = "Walking to bank";
- ScriptVec2i Point = { 0xc61, 0xd56 };
- auto Location = Self.GlobalPosition;
- auto Distance = abs(Point.X - Location.X) + abs(Point.Y - Location.Y);
- if (Distance < 7)
- {
- State = STATE_OPEN_BANK;
- }
- else if (!Self.IsMoving)
- {
- s.FindFunction<MovementWalk>("Movement", "Walk")(Point.X, Point.Y);
- return 1000;
- }
- return 100;
- }
- static INT32 RunOpenBankWestVarrock(UINT64 Time, const ScriptPlayer& Self)
- {
- StateMessage = "Opening bank";
- s.FindFunction<MenuObjectClick>("Menu", "ClickObject")(0x30e, 0xc6d, 0xd6c, 2);
- if (s.FindFunction<BankIsOpen>("Bank", "IsOpen")())
- {
- State = STATE_BANK;
- return 1000;
- }
- else
- {
- return 100;
- }
- }
- static INT32 RunBank(UINT64 Time, const ScriptPlayer& Self)
- {
- StateMessage = "Banking";
- ScriptItem FirstTree;
- if (s.FindFunction<InventoryGetFirstItem>("Inventory", "GetFirstItem")(TreeObjects[SelectedTree].ItemId, &FirstTree))
- {
- s.FindFunction<MenuWidgetItemClick>("Menu", "ClickWidgetItem")(7, FirstTree.Slot, 0x205000f);
- }
- State = STATE_WALK_TREES;
- return 1000;
- }
- //
- // Runs the script loop.
- //
- static INT32 Run(const ScriptPlayer& Self)
- {
- static UINT64 NextClickTime = 0;
- static UINT64 InvisCounter = 0;
- auto Time = GetTickCount64();
- if (!Self.IsValid())
- {
- InvisCounter += 1;
- if (InvisCounter > 5)
- {
- InvisCounter = 0;
- return RunPlayButton(Time, Self);
- }
- return 800;
- }
- else
- {
- if (!StartExperience)
- {
- StartExperience = s.FindFunction<ClientGetStat>("Client", "GetStat")(STAT_WOODCUTTING).Xp;
- }
- InvisCounter = 0;
- }
- if (Time > NextClickTime)
- {
- StateMessage = "Moving mouse some";
- s.FindFunction<InputRightClick>("Input", "RightClick")(30, 30);
- NextClickTime = (Time + 30000);
- return 700;
- }
- if (State == STATE_WALK_TREES)
- {
- return RunTreeWestVarrock(Time, Self);
- }
- else if (State == STATE_WALK_BANK)
- {
- return RunWalkBankWestVarrock(Time, Self);
- }
- else if (State == STATE_OPEN_BANK)
- {
- return RunOpenBankWestVarrock(Time, Self);
- }
- else if (State == STATE_TREES)
- {
- return ChopTree(Time, Self);
- }
- else if (State == STATE_BANK)
- {
- return RunBank(Time, Self);
- }
- StateMessage = "Unknown";
- return 10000;
- }
- static UINT64 OnLoop()
- {
- if (!Enabled)
- {
- return 1000;
- }
- return Run(s.FindFunction<PlayerGetSelf>("Players", "GetSelf")());
- }
- static SIZE_T PerHour(UINT64 Total, UINT64 Runtime)
- {
- auto RuntimeSeconds = (DOUBLE)Runtime / 1000.0;
- if (!RuntimeSeconds)
- {
- return 0ull;
- }
- auto XpPerSecond = ((DOUBLE)Total / (DOUBLE)RuntimeSeconds);
- return (SIZE_T)(XpPerSecond * 3600.0);
- }
- static VOID OnPaint()
- {
- if (s.FindFunction<OverlayBegin>("Overlay", "Begin")("Varrock West Chopper 1.0"))
- {
- s.FindFunction<OverlayCheckbox>("Overlay", "Checkbox")("Enabled", &Enabled);
- if (Enabled)
- {
- s.FindFunction<OverlayListBox>("Overlay", "ListBox")("Tree types", &SelectedTree, TreeNames, sizeof(TreeNames) / sizeof(TreeNames[0]));
- auto MsInSecond = 1000ull;
- auto MsInMinute = MsInSecond * 60ull;
- auto MsInHour = MsInMinute * 60ull;
- auto MsInDay = MsInHour * 24ull;
- auto Runtime = (GetTickCount64() - BeginRuntime);
- auto RuntimeAcc = Runtime;
- auto Days = RuntimeAcc / MsInDay;
- RuntimeAcc -= (Days * MsInDay);
- auto Hours = RuntimeAcc / MsInHour;
- RuntimeAcc -= (Hours * MsInHour);
- auto Minutes = RuntimeAcc / MsInMinute;
- RuntimeAcc -= (Minutes * MsInMinute);
- auto Seconds = RuntimeAcc / MsInSecond;
- s.FindFunction<OverlayLabel>("Overlay", "Label")("Runtime", "%dd:%dh:%dm:%ds", 4, Days, Hours, Minutes, Seconds);
- s.FindFunction<OverlayLabel>("Overlay", "Label")("State", "%s", 1, StateMessage);
- s.FindFunction<OverlayLabel>("Overlay", "Label")("Trees", "%d (%d p/h)", 2, TreesChopped, PerHour(TreesChopped, Runtime));
- auto XpGained = s.FindFunction<ClientGetStat>("Client", "GetStat")(STAT_MINING).Xp - StartExperience;
- s.FindFunction<OverlayLabel>("Overlay", "Label")("Xp", "%d (%d p/h)", 2, XpGained, PerHour(XpGained, Runtime));
- auto ProfitGained = TreesChopped * TreeObjects[SelectedTree].Price;
- s.FindFunction<OverlayLabel>("Overlay", "Label")("Profits", "%d (%d p/h)", 2, ProfitGained, PerHour(ProfitGained, Runtime));
- }
- s.FindFunction<OverlayEnd>("Overlay", "End")();
- }
- }
- static VOID ScriptOnInventoryItemChanged(INT32 Slot, INT32 OldId, INT32 NewId)
- {
- if (NewId == TreeObjects[SelectedTree].ItemId)
- {
- TreesChopped += 1;
- }
- }
- static VOID OnRegisterScript(ScriptContext* C)
- {
- //
- // TODO FIXME we fucked the CRT, so nothing is initialized!
- //
- BeginRuntime = GetTickCount64();
- StartExperience = 0;
- ::s = C->ScriptSDK;
- C->OnLoop = OnLoop;
- C->OnPaint = OnPaint;
- C->OnInventoryItemChanged = ScriptOnInventoryItemChanged;
- }
- BOOL APIENTRY DllMain(HMODULE Module, DWORD ReasonForCall, BotContext* C)
- {
- C->RegisterScript(OnRegisterScript);
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement