Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- using System.Threading;
- namespace MinimapSpotter
- {
- class Program
- {
- struct OFFSETS
- {
- public const Int64 ClientGameContext = 0x1424A0C00;
- public const Int64 ClientPlayerManager = 0x60;
- public const Int64 ClientLocalPlayer = 0x540;
- public const Int64 ClientPlayerArray = 0x548;
- public const Int64 teamID = 0x13CC;
- public const Int64 ClientSoldierEntity = 0x14D0;
- public const Int64 ClientSpottingTargetComponent = 0xBF0;
- public const Int64 activeSpotType = 0x50;
- }
- const int spotType = 1;
- static IntPtr processHandle;
- [DllImport("kernel32.dll")]
- static extern IntPtr OpenProcess(Int64 dwDesiredAccess, bool bInheritHandle, Int64 dwProcessId);
- [DllImport("kernel32.dll")]
- static extern bool CloseHandle(IntPtr handle);
- [DllImport("kernel32.dll")]
- static extern bool ReadProcessMemory(IntPtr hProcess, Int64 lpBaseAddress, byte[] lpBuffer, Int64 dwSize, out Int64 lpNumberOfBytesRead);
- [DllImport("kernel32.dll")]
- static extern bool WriteProcessMemory(IntPtr hProcess, Int64 lpBaseAddress, byte[] lpBuffer, Int64 dwSize, out Int64 lpNumberOfBytesWritten);
- static bool IsValid(Int64 address)
- {
- return (address >= 0x10000 && address < 0x000F000000000000);
- }
- static void Main(string[] args)
- {
- Int64 pClientGameContext;
- Int64 pClientPlayerManager;
- Int64 pClientLocalPlayer;
- Int64 pClientPlayerArray;
- int teamID;
- Int64 pClientEnemyPlayer;
- Int64 pClientSoldierEntity;
- Int64 pClientSpottingTargetComponent;
- Console.WriteLine("Waiting for BF4 process and module (x64)....");
- Process process;
- ProcessModule processModule;
- while (true)
- {
- if (GetProcessByName("bf4", out process))
- {
- if (GetModuleByProcess(process, "bf4.exe", out processModule))
- {
- processHandle = OpenProcess(0x0008 | 0x0010 | 0x0020, false, process.Id);
- pClientGameContext = ReadInt64(OFFSETS.ClientGameContext);
- if (IsValid(pClientGameContext))
- {
- break;
- }
- CloseHandle(processHandle);
- }
- }
- Thread.Sleep(100);
- }
- Thread.Sleep(100);
- Console.WriteLine("BF4 process and module found");
- Console.WriteLine("Ready and GO!");
- while (true)
- {
- pClientPlayerManager = ReadInt64(pClientGameContext + OFFSETS.ClientPlayerManager);
- if (!IsValid(pClientPlayerManager))
- {
- continue;
- }
- pClientLocalPlayer = ReadInt64(pClientPlayerManager + OFFSETS.ClientLocalPlayer);
- if (!IsValid(pClientLocalPlayer))
- {
- continue;
- }
- teamID = ReadInt32(pClientLocalPlayer + OFFSETS.teamID);
- pClientPlayerArray = ReadInt64(pClientPlayerManager + OFFSETS.ClientPlayerArray);
- if (!IsValid(pClientPlayerArray))
- {
- continue;
- }
- for (int i = 0; i < 70; i++)
- {
- pClientEnemyPlayer = ReadInt64(pClientPlayerArray + i * 0x8);
- if (!IsValid(pClientEnemyPlayer))
- {
- continue;
- }
- if (teamID == ReadInt32(pClientEnemyPlayer + OFFSETS.teamID))
- {
- continue;
- }
- pClientSoldierEntity = ReadInt64(pClientEnemyPlayer + OFFSETS.ClientSoldierEntity);
- if (!IsValid(pClientSoldierEntity))
- {
- continue;
- }
- pClientSpottingTargetComponent = ReadInt64(pClientSoldierEntity + OFFSETS.ClientSpottingTargetComponent);
- if (!IsValid(pClientSpottingTargetComponent))
- {
- continue;
- }
- if (ReadInt32(pClientSpottingTargetComponent + OFFSETS.activeSpotType) != spotType)
- {
- WriteInt32(pClientSpottingTargetComponent + OFFSETS.activeSpotType, spotType);
- }
- }
- }
- }
- static bool GetProcessByName(string processName, out Process process)
- {
- Process[] processList = Process.GetProcessesByName(processName);
- if (processList.Length > 0)
- {
- process = processList[0];
- return true;
- }
- process = null;
- return false;
- }
- static bool GetModuleByProcess(Process process, string moduleName, out ProcessModule processModule)
- {
- foreach (ProcessModule module in process.Modules)
- {
- if (module.ModuleName == moduleName)
- {
- processModule = module;
- return true;
- }
- }
- processModule = null;
- return false;
- }
- static bool WriteInt32(Int64 _lpBaseAddress, int value)
- {
- byte[] buffer = BitConverter.GetBytes(value);
- Int64 bytesRead = 0;
- return WriteProcessMemory(processHandle, _lpBaseAddress, buffer, buffer.Length, out bytesRead);
- }
- static Int64 ReadInt64(Int64 _lpBaseAddress)
- {
- byte[] buffer = new byte[sizeof(Int64)];
- Int64 bytesRead = 0;
- ReadProcessMemory(processHandle, _lpBaseAddress, buffer, buffer.Length, out bytesRead);
- return BitConverter.ToInt64(buffer, 0);
- }
- static Int32 ReadInt32(Int64 _lpBaseAddress)
- {
- byte[] buffer = new byte[sizeof(Int32)];
- Int64 bytesRead = 0;
- ReadProcessMemory(processHandle, _lpBaseAddress, buffer, buffer.Length, out bytesRead);
- return BitConverter.ToInt32(buffer, 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement