Guest User

Game.cs

a guest
Jan 28th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Magic;
  6. using System.Diagnostics;
  7. using System.Windows.Forms;
  8.  
  9. namespace Bot{
  10.     public class Game {
  11.         private int ticks = 0;
  12.         public static Process Process;
  13.         private bool processReady = false;
  14.  
  15.         public static BlackMagic Magic = new BlackMagic();
  16.         public static uint BaseAddress;
  17.  
  18.         private uint ObjectManager, FirstObject;
  19.  
  20.         public Object LocalPlayer, LocalTarget;
  21.  
  22.         public Game(int procID) {
  23.             try {
  24.                 attachProcess(procID);
  25.                 prepareReader();
  26.             } catch (Exception ex) {
  27.                 MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
  28.             }
  29.         }
  30.  
  31.         public void tick() {
  32.             ticks++;
  33.         }
  34.  
  35.         private void attachProcess(int pid) {
  36.             setStatus("Attaching to " + pid + " ...");
  37.             log("Attaching to process with ID '" + pid + "' ...");
  38.  
  39.             try {
  40.                 Process p = Process.GetProcessById(pid);
  41.                 Magic.OpenProcessAndThread(pid);
  42.                 BaseAddress = (uint)Magic.MainModule.BaseAddress;
  43.             } catch (Exception ex) {
  44.                 setStatus("Exception while attaching to process!");
  45.                 log("Exception while attaching to process (" + pid + "): \r\n" + ex.Message + "\r\n" + ex.StackTrace);
  46.                 return;
  47.             }
  48.  
  49.             setStatus("Attached to " + pid);
  50.             log("Successfully attached to process with ID " + pid);
  51.             log("Preparing to read from memory ...");
  52.         }
  53.  
  54.         private void prepareReader() {
  55.             setStatus("Preparing reader ...");
  56.             log("Preparing reader ...");
  57.  
  58.             try {
  59.                 ObjectManager = Magic.ReadUInt((uint)(Magic.ReadUInt((uint)(BaseAddress + (uint)Pointers.ObjectManager.CurMgrPointer)) + (uint)Pointers.ObjectManager.CurMgrOffset));
  60.                 FirstObject = Magic.ReadUInt((uint)(ObjectManager + (uint)Pointers.ObjectManager.FirstObject));
  61.             } catch (Exception ex) {
  62.                 setStatus("Exception while finding the first object");
  63.                 log("Exception while finding 'FirstObject': (BaseAddress=" + BaseAddress + ") (ObjectManager=" + ObjectManager + ") (FirstObject=" + FirstObject + ") \r\n\r\n" + ex.StackTrace);
  64.             }
  65.  
  66.             LocalPlayer = new Object();
  67.             LocalPlayer.GUID = Magic.ReadUInt64(BaseAddress + (uint)Pointers.StaticPointers.LocalPlayerGUID);
  68.  
  69.             LocalTarget = new Object();
  70.             LocalTarget.GUID = Magic.ReadUInt64(BaseAddress + (uint)Pointers.StaticPointers.CurrentTargetGUID);
  71.  
  72.             if (LocalPlayer.GUID == 0) {
  73.                 setStatus("Error finding LocalPlayer.GUID");
  74.                 log("There was an error finding the LocalPlayer.GUID - It's zero!");
  75.                 processReady = false;
  76.                 return;
  77.             } else {
  78.                 log("Found LocalPlayer.GUID: " + LocalPlayer.GUID);
  79.                 processReady = true;
  80.             }
  81.  
  82.             setStatus("Ready reader!");
  83.             log("The Reader is ready! First Object: " + FirstObject);
  84.         }
  85.  
  86.         public Object getPlayer() {
  87.             return null;
  88.         }
  89.  
  90.         public bool isReady() {
  91.             return processReady;
  92.         }
  93.  
  94.         private void setStatus(string msg) {
  95.             frmMain.Status = msg;
  96.         }
  97.  
  98.         private void log(string msg) {
  99.             VanUtil.Debug.log("[Game]: " + msg);
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment