Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2015
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.06 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Runtime.InteropServices;
  4. using System.Threading;
  5.  
  6. namespace MinimapSpotter
  7. {
  8.     class Program
  9.     {
  10.         struct OFFSETS
  11.         {
  12.             public const Int64 ClientGameContext = 0x1424A0C00;
  13.             public const Int64 ClientPlayerManager = 0x60;
  14.             public const Int64 ClientLocalPlayer = 0x540;
  15.             public const Int64 ClientPlayerArray = 0x548;
  16.             public const Int64 teamID = 0x13CC;
  17.             public const Int64 ClientSoldierEntity = 0x14D0;
  18.             public const Int64 ClientSpottingTargetComponent = 0xBF0;
  19.             public const Int64 activeSpotType = 0x50;
  20.         }
  21.  
  22.         const int spotType = 1;
  23.  
  24.         static IntPtr processHandle;
  25.  
  26.         [DllImport("kernel32.dll")]
  27.         static extern IntPtr OpenProcess(Int64 dwDesiredAccess, bool bInheritHandle, Int64 dwProcessId);
  28.  
  29.         [DllImport("kernel32.dll")]
  30.         static extern bool CloseHandle(IntPtr handle);
  31.  
  32.         [DllImport("kernel32.dll")]
  33.         static extern bool ReadProcessMemory(IntPtr hProcess, Int64 lpBaseAddress, byte[] lpBuffer, Int64 dwSize, out Int64 lpNumberOfBytesRead);
  34.  
  35.         [DllImport("kernel32.dll")]
  36.         static extern bool WriteProcessMemory(IntPtr hProcess, Int64 lpBaseAddress, byte[] lpBuffer, Int64 dwSize, out Int64 lpNumberOfBytesWritten);
  37.  
  38.         static bool IsValid(Int64 address)
  39.         {
  40.             return (address >= 0x10000 && address < 0x000F000000000000);
  41.         }
  42.  
  43.         static void Main(string[] args)
  44.         {
  45.             Int64 pClientGameContext;
  46.             Int64 pClientPlayerManager;
  47.             Int64 pClientLocalPlayer;
  48.             Int64 pClientPlayerArray;
  49.             int teamID;
  50.             Int64 pClientEnemyPlayer;
  51.             Int64 pClientSoldierEntity;
  52.             Int64 pClientSpottingTargetComponent;
  53.  
  54.             Console.WriteLine("Waiting for BF4 process and module (x64)....");
  55.  
  56.             Process process;
  57.             ProcessModule processModule;
  58.  
  59.             while (true)
  60.             {
  61.                 if (GetProcessByName("bf4", out process))
  62.                 {
  63.                     if (GetModuleByProcess(process, "bf4.exe", out processModule))
  64.                     {
  65.                         processHandle = OpenProcess(0x0008 | 0x0010 | 0x0020, false, process.Id);
  66.  
  67.                         pClientGameContext = ReadInt64(OFFSETS.ClientGameContext);
  68.                         if (IsValid(pClientGameContext))
  69.                         {
  70.                             break;
  71.                         }
  72.  
  73.                         CloseHandle(processHandle);
  74.                     }
  75.                 }
  76.  
  77.                 Thread.Sleep(100);
  78.             }
  79.  
  80.             Thread.Sleep(100);
  81.  
  82.             Console.WriteLine("BF4 process and module found");
  83.             Console.WriteLine("Ready and GO!");
  84.  
  85.             while (true)
  86.             {
  87.                 pClientPlayerManager = ReadInt64(pClientGameContext + OFFSETS.ClientPlayerManager);
  88.                 if (!IsValid(pClientPlayerManager))
  89.                 {
  90.                     continue;
  91.                 }
  92.  
  93.                 pClientLocalPlayer = ReadInt64(pClientPlayerManager + OFFSETS.ClientLocalPlayer);
  94.                 if (!IsValid(pClientLocalPlayer))
  95.                 {
  96.                     continue;
  97.                 }
  98.  
  99.                 teamID = ReadInt32(pClientLocalPlayer + OFFSETS.teamID);
  100.  
  101.                 pClientPlayerArray = ReadInt64(pClientPlayerManager + OFFSETS.ClientPlayerArray);
  102.                 if (!IsValid(pClientPlayerArray))
  103.                 {
  104.                     continue;
  105.                 }
  106.  
  107.                 for (int i = 0; i < 70; i++)
  108.                 {
  109.                     pClientEnemyPlayer = ReadInt64(pClientPlayerArray + i * 0x8);
  110.                     if (!IsValid(pClientEnemyPlayer))
  111.                     {
  112.                         continue;
  113.                     }
  114.  
  115.                     if (teamID == ReadInt32(pClientEnemyPlayer + OFFSETS.teamID))
  116.                     {
  117.                         continue;
  118.                     }
  119.  
  120.                     pClientSoldierEntity = ReadInt64(pClientEnemyPlayer + OFFSETS.ClientSoldierEntity);
  121.                     if (!IsValid(pClientSoldierEntity))
  122.                     {
  123.                         continue;
  124.                     }
  125.  
  126.                     pClientSpottingTargetComponent = ReadInt64(pClientSoldierEntity + OFFSETS.ClientSpottingTargetComponent);
  127.                     if (!IsValid(pClientSpottingTargetComponent))
  128.                     {
  129.                         continue;
  130.                     }
  131.  
  132.                     if (ReadInt32(pClientSpottingTargetComponent + OFFSETS.activeSpotType) != spotType)
  133.                     {
  134.                         WriteInt32(pClientSpottingTargetComponent + OFFSETS.activeSpotType, spotType);
  135.                     }
  136.                 }
  137.             }
  138.         }
  139.  
  140.         static bool GetProcessByName(string processName, out Process process)
  141.         {
  142.             Process[] processList = Process.GetProcessesByName(processName);
  143.             if (processList.Length > 0)
  144.             {
  145.                 process = processList[0];
  146.                 return true;
  147.             }
  148.  
  149.             process = null;
  150.             return false;
  151.         }
  152.  
  153.         static bool GetModuleByProcess(Process process, string moduleName, out ProcessModule processModule)
  154.         {
  155.             foreach (ProcessModule module in process.Modules)
  156.             {
  157.                 if (module.ModuleName == moduleName)
  158.                 {
  159.                     processModule = module;
  160.                     return true;
  161.                 }
  162.             }
  163.  
  164.             processModule = null;
  165.             return false;
  166.         }
  167.  
  168.  
  169.         static bool WriteInt32(Int64 _lpBaseAddress, int value)
  170.         {
  171.             byte[] buffer = BitConverter.GetBytes(value);
  172.  
  173.             Int64 bytesRead = 0;
  174.             return WriteProcessMemory(processHandle, _lpBaseAddress, buffer, buffer.Length, out bytesRead);
  175.         }
  176.  
  177.         static Int64 ReadInt64(Int64 _lpBaseAddress)
  178.         {
  179.             byte[] buffer = new byte[sizeof(Int64)];
  180.  
  181.             Int64 bytesRead = 0;
  182.             ReadProcessMemory(processHandle, _lpBaseAddress, buffer, buffer.Length, out bytesRead);
  183.  
  184.             return BitConverter.ToInt64(buffer, 0);
  185.         }
  186.  
  187.         static Int32 ReadInt32(Int64 _lpBaseAddress)
  188.         {
  189.             byte[] buffer = new byte[sizeof(Int32)];
  190.  
  191.             Int64 bytesRead = 0;
  192.             ReadProcessMemory(processHandle, _lpBaseAddress, buffer, buffer.Length, out bytesRead);
  193.  
  194.             return BitConverter.ToInt32(buffer, 0);
  195.         }
  196.     }
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement