Если автор позволит, я выложу тут свою наработку, что бы не создавать новый трэд.
Использую глобал хук, что бы отдалять и приближать карту - намного удобнее в таком режиме.
Но я по прежнему не приложу ума как пропатчить туман и как найти нужный адрес, буду признателен за любые наводки
Использую глобал хук, что бы отдалять и приближать карту - намного удобнее в таком режиме.
Но я по прежнему не приложу ума как пропатчить туман и как найти нужный адрес, буду признателен за любые наводки
Код:
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
internal class Program
{
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int dwSize, out int lpNumberOfBytesRead);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int nSize, out int lpNumberOfBytesWritten);
const int PROCESS_WM_READ = 0x0010;
const int PROCESS_VM_WRITE = 0x0020;
const int PROCESS_VM_OPERATION = 0x0008;
private static IntPtr processHandle;
private static IntPtr chosenAddress;
private static IntPtr hookID = IntPtr.Zero;
private delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam);
private static LowLevelMouseProc proc = HookCallback;
public static void Main(string[] args)
{
var processId = GetProcessIdByName("dota2");
if (processId == -1)
{
Console.WriteLine("Process dota2.exe not found.");
return;
}
processHandle = OpenProcess(PROCESS_WM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION, false, processId);
if (processHandle == IntPtr.Zero)
{
Console.WriteLine("Problem with process opening.");
return;
}
var (baseAddress, moduleSize) = GetModuleBaseAndSize(processId, "client.dll");
if (baseAddress == IntPtr.Zero)
{
Console.WriteLine("Module client.dll not found.");
return;
}
Console.WriteLine($"Base address client.dll: 0x{baseAddress.ToString("X")}, ModuleSize: {moduleSize}");
string patternStr = "00 00 ?? 44 00 00 8C 42"; // Example pattern
var (pattern, skipIndexes) = ParsePatternString(patternStr);
byte[] buffer = new byte[moduleSize];
int bytesRead;
if (!ReadProcessMemory(processHandle, baseAddress, buffer, buffer.Length, out bytesRead))
{
Console.WriteLine("Failed to read process memory.");
return;
}
AppDomain.CurrentDomain.ProcessExit += (sender, e) =>
{
Console.WriteLine("Process is exiting...");
ResetValueAtAddress();
};
Application.ApplicationExit += (sender, e) =>
{
Console.WriteLine("Application is exiting...");
ResetValueAtAddress();
};
Console.CancelKeyPress += (sender, e) =>
{
Console.WriteLine("CTRL+C pressed. Exiting...");
e.Cancel = true; // Cancel the cancellation to invoke ProcessExit.
ResetValueAtAddress();
Environment.Exit(0); // Forcefully exits the application after cleanup
};
try
{
var addresses = FindPatternAddresses(processHandle, baseAddress, buffer, bytesRead, pattern, skipIndexes, IntPtr.Zero);
if (addresses.Count < 2)
{
Console.WriteLine("Less than two addresses found. Cannot proceed.");
return;
}
// Always use the second found address:
chosenAddress = addresses[1];
Console.WriteLine($"Using address: 0x{chosenAddress.ToString("X")}");
// Set up mouse hook and start monitoring
hookID = SetHook(proc);
Application.Run(); // Using a form to handle closing gracefully
ResetValueAtAddress();
}
catch (Exception ex)
{
Console.WriteLine($"An exception occurred: {ex.Message}");
ResetValueAtAddress();
}
}
private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
{
Console.WriteLine("Application domain exiting...");
ResetValueAtAddress();
}
private static void Application_ApplicationExit(object sender, EventArgs e)
{
Console.WriteLine("Application exiting...");
ResetValueAtAddress();
}
static void ResetValueAtAddress()
{
if (processHandle != IntPtr.Zero && chosenAddress != IntPtr.Zero)
{
UnhookWindowsHookEx(hookID);
float resetValue = 1200f;
byte[] bytesToWrite = BitConverter.GetBytes(resetValue);
if (WriteProcessMemory(processHandle, chosenAddress, bytesToWrite, bytesToWrite.Length, out int bytesWritten))
{
Console.WriteLine("Value reset to 1200 successfully.");
}
else
{
Console.WriteLine("Failed to reset value.");
}
}
}
static (IntPtr baseAddress, int moduleSize) GetModuleBaseAndSize(int processId, string moduleName)
{
var process = Process.GetProcessById(processId);
foreach (ProcessModule module in process.Modules)
{
if (module.ModuleName.Equals(moduleName, StringComparison.OrdinalIgnoreCase))
{
return (module.BaseAddress, module.ModuleMemorySize);
}
}
return (IntPtr.Zero, 0);
}
static (List<byte?> pattern, List<int> skipIndexes) ParsePatternString(string patternStr)
{
var bytes = new List<byte?>();
var skips = new List<int>();
string[] parts = patternStr.Split(' ');
for (int i = 0; i < parts.Length; i++)
{
if (parts[i] == "??")
{
bytes.Add(null);
skips.Add(i);
}
else
{
bytes.Add(Convert.ToByte(parts[i], 16));
}
}
return (bytes, skips);
}
static List<IntPtr> FindPatternAddresses(IntPtr hProcess, IntPtr baseAddress, byte[] buffer, int bytesRead, List<byte?> pattern, List<int> skipIndexes, IntPtr startAddress)
{
List<IntPtr> addresses = new List<IntPtr>();
int patternLength = pattern.Count;
for (int i = 0; i <= bytesRead - patternLength; i++)
{
bool match = true;
for (int j = 0; j < patternLength; j++)
{
if (skipIndexes.Contains(j) || pattern[j] == null || buffer[i + j] == pattern[j])
{
continue;
}
match = false;
break;
}
if (match)
{
addresses.Add(IntPtr.Add(baseAddress, i));
}
}
return addresses;
}
static int GetProcessIdByName(string processName)
{
foreach (var process in Process.GetProcesses())
{
if (process.ProcessName.StartsWith(processName, StringComparison.OrdinalIgnoreCase))
{
return process.Id;
}
}
return -1;
}
private static IntPtr SetHook(LowLevelMouseProc proc)
{
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
IntPtr hook = SetWindowsHookEx(14, proc, GetModuleHandle(curModule.ModuleName), 0);
if (hook == IntPtr.Zero)
{
Console.WriteLine("Failed to install hook.");
}
else
{
Console.WriteLine("Hook installed successfully.");
}
return hook;
}
}
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && (MouseMessages)wParam == MouseMessages.WM_MOUSEWHEEL)
{
MSLLHOOKSTRUCT mouseInfo = Marshal.PtrToStructure<MSLLHOOKSTRUCT>(lParam);
int wheelDelta = (int)mouseInfo.mouseData >> 16;
Console.WriteLine($"Mouse wheel moved, delta: {wheelDelta}");
AdjustGameValue(wheelDelta);
}
return CallNextHookEx(hookID, nCode, wParam, lParam);
}
private static void AdjustGameValue(int wheelDelta)
{
// Calculate increment based on wheel direction
float increment = wheelDelta > 0 ? -100.0f : 100.0f;
byte[] buffer = new byte[4];
// Read current value from the process memory
if (ReadProcessMemory(processHandle, chosenAddress, buffer, buffer.Length, out int bytesRead) && bytesRead == 4)
{
float currentValue = BitConverter.ToSingle(buffer, 0);
float newValue = currentValue + increment;
// Enforce minimum value of 1200
if (newValue < 1200.0f)
{
newValue = 1200.0f;
}
// Write the new value back to the memory
byte[] bytesToWrite = BitConverter.GetBytes(newValue);
if (WriteProcessMemory(processHandle, chosenAddress, bytesToWrite, bytesToWrite.Length, out int bytesWritten) && bytesWritten == 4)
{
Console.WriteLine($"Value updated to {newValue} at address {chosenAddress.ToString("X")}");
}
else
{
Console.WriteLine("Failed to write the updated value.");
}
}
else
{
Console.WriteLine("Failed to read the current value.");
}
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool UnhookWindowsHookEx(IntPtr hhk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);
enum MouseMessages
{
WM_MOUSEWHEEL = 0x020A
}
[StructLayout(LayoutKind.Sequential)]
private struct MSLLHOOKSTRUCT
{
public POINT pt;
public int mouseData;
public int flags;
public int time;
public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
private struct POINT
{
public int x;
public int y;
}
}