Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Magic;
- using System.Diagnostics;
- using System.Windows.Forms;
- namespace Bot{
- public class Game {
- private int ticks = 0;
- public static Process Process;
- private bool processReady = false;
- public static BlackMagic Magic = new BlackMagic();
- public static uint BaseAddress;
- private uint ObjectManager, FirstObject;
- public Object LocalPlayer, LocalTarget;
- public Game(int procID) {
- try {
- attachProcess(procID);
- prepareReader();
- } catch (Exception ex) {
- MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
- }
- }
- public void tick() {
- ticks++;
- }
- private void attachProcess(int pid) {
- setStatus("Attaching to " + pid + " ...");
- log("Attaching to process with ID '" + pid + "' ...");
- try {
- Process p = Process.GetProcessById(pid);
- Magic.OpenProcessAndThread(pid);
- BaseAddress = (uint)Magic.MainModule.BaseAddress;
- } catch (Exception ex) {
- setStatus("Exception while attaching to process!");
- log("Exception while attaching to process (" + pid + "): \r\n" + ex.Message + "\r\n" + ex.StackTrace);
- return;
- }
- setStatus("Attached to " + pid);
- log("Successfully attached to process with ID " + pid);
- log("Preparing to read from memory ...");
- }
- private void prepareReader() {
- setStatus("Preparing reader ...");
- log("Preparing reader ...");
- try {
- ObjectManager = Magic.ReadUInt((uint)(Magic.ReadUInt((uint)(BaseAddress + (uint)Pointers.ObjectManager.CurMgrPointer)) + (uint)Pointers.ObjectManager.CurMgrOffset));
- FirstObject = Magic.ReadUInt((uint)(ObjectManager + (uint)Pointers.ObjectManager.FirstObject));
- } catch (Exception ex) {
- setStatus("Exception while finding the first object");
- log("Exception while finding 'FirstObject': (BaseAddress=" + BaseAddress + ") (ObjectManager=" + ObjectManager + ") (FirstObject=" + FirstObject + ") \r\n\r\n" + ex.StackTrace);
- }
- LocalPlayer = new Object();
- LocalPlayer.GUID = Magic.ReadUInt64(BaseAddress + (uint)Pointers.StaticPointers.LocalPlayerGUID);
- LocalTarget = new Object();
- LocalTarget.GUID = Magic.ReadUInt64(BaseAddress + (uint)Pointers.StaticPointers.CurrentTargetGUID);
- if (LocalPlayer.GUID == 0) {
- setStatus("Error finding LocalPlayer.GUID");
- log("There was an error finding the LocalPlayer.GUID - It's zero!");
- processReady = false;
- return;
- } else {
- log("Found LocalPlayer.GUID: " + LocalPlayer.GUID);
- processReady = true;
- }
- setStatus("Ready reader!");
- log("The Reader is ready! First Object: " + FirstObject);
- }
- public Object getPlayer() {
- return null;
- }
- public bool isReady() {
- return processReady;
- }
- private void setStatus(string msg) {
- frmMain.Status = msg;
- }
- private void log(string msg) {
- VanUtil.Debug.log("[Game]: " + msg);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment