/// <summary> /// NOTE: Not original! von mir estellt /// </summary> public static byte[] MemoryRead(IntPtr iv_Address, IntPtr ah_Handle, byte[] v_Buffer) { int numberBytesRead = 0; ReadProcessMemory(ah_Handle, iv_Address, v_Buffer, AutoItApi.DllStructGetSize(v_Buffer), out numberBytesRead); return(v_Buffer); }
public static void MemoryWrite(IntPtr iv_Address, IntPtr ah_Handle, byte[] v_Data, string sv_Type = "dword") { var v_Buffer = AutoItApi.DllStructCreate(sv_Type); AutoItApi.DllStructSetData(v_Buffer, 1, v_Data); IntPtr lpNumberOfBytesWritten; WriteProcessMemory(ah_Handle, iv_Address, v_Buffer, v_Buffer.Length, out lpNumberOfBytesWritten); }
/** * Description: Reads the value located in the memory address specified. * * Parameter(s): iv_Address - The memory address you want to read from. It must be in hex * format (0x00000000). * ah_Handle - An array containing the Dll handle and the handle of the open * process as returned by _MemoryOpen(). * sv_Type - (optional) The "Type" of value you intend to read. This is set to * 'dword'(32bit(4byte) signed integer) by default. See the help file * for DllStructCreate for all types. * An example: If you want to read a word that is 15 characters in * length, you would use 'char[16]'. * Requirement(s): The ah_Handle returned from _MemoryOpen. * Return Value(s): On Success - Returns the value located at the specified address. * On Failure - Returns 0 */ public static int MemoryRead(IntPtr iv_Address, IntPtr ah_Handle, string sv_Type = "dword") { var v_Buffer = AutoItApi.DllStructCreate(sv_Type); int numberBytesRead = 0; ReadProcessMemory(ah_Handle, iv_Address, v_Buffer, AutoItApi.DllStructGetSize(v_Buffer), out numberBytesRead); var v_Value = AutoItApi.DllStructGetData(v_Buffer, 1, sv_Type); return(v_Value); }
/** * @brief Reads a chain of pointers and returns an array containing the destination * address and the data at the address. * Parameter(s): iv_Address - The static memory address you want to start at. It must be in * hex format (0x00000000). * ah_Handle - An array containing the Dll handle and the handle of the open * process as returned by _MemoryOpen(). * av_Offset - An array of offsets for the pointers. Each pointer must have an * offset. If there is no offset for a pointer, enter 0 for that * array dimension. * sv_Type - (optional) The "Type" of data you intend to read at the destination * address. This is set to 'dword'(32bit(4byte) signed integer) by * default. See the help file for DllStructCreate for all types. * Requirement(s): The ah_Handle returned from _MemoryOpen. * Return Value(s): On Success - Returns an array containing the destination address and the value * located at the address. * On Failure - Returns 0 * Note(s): Values returned are in Decimal format, unless a 'char' type is selected. * Set av_Offset like this: * av_Offset[0] = NULL (not used) * av_Offset[1] = Offset for pointer 1 (all offsets must be in Decimal) * av_Offset[2] = Offset for pointer 2 * etc... * (The number of array dimensions determines the number of pointers) */ public static IntPtr MemoryPointerRead(IntPtr iv_Address, IntPtr ah_Handle, int[] av_Offset, string sv_Type = "dword") { var iv_PointerCount = av_Offset.Length - 1; IntPtr[] iv_Data = new IntPtr[2]; var v_Buffer = AutoItApi.DllStructCreate("dword"); int numberBytesRead = 0; for (int i = 0; i <= iv_PointerCount; i++) { if (i == iv_PointerCount) { // Last Pointer v_Buffer = AutoItApi.DllStructCreate(sv_Type); iv_Address = iv_Data[1] + av_Offset[i]; ReadProcessMemory(ah_Handle, iv_Address, v_Buffer, AutoItApi.DllStructGetSize(v_Buffer), out numberBytesRead); iv_Data[1] = (IntPtr)AutoItApi.DllStructGetData(v_Buffer, 1, sv_Type); } else if (i == 0) { // First Pointer ReadProcessMemory(ah_Handle, iv_Address, v_Buffer, AutoItApi.DllStructGetSize(v_Buffer), out numberBytesRead); // Pointer always dword iv_Data[1] = (IntPtr)AutoItApi.DllStructGetData(v_Buffer, 1, "dword"); } else { iv_Address = iv_Data[1] + av_Offset[i]; ReadProcessMemory(ah_Handle, iv_Address, v_Buffer, AutoItApi.DllStructGetSize(v_Buffer), out numberBytesRead); // Pointer always dword iv_Data[1] = (IntPtr)AutoItApi.DllStructGetData(v_Buffer, 1, "dword"); } } iv_Data[0] = iv_Address; return(iv_Data[1]); }
public void UpdateHandle(IntPtr hWnd) { var iPID = AutoItApi.WinGetProcess(hWnd); //if (iPID == -1) { return _CloseHandle(); } if (iPID == g_iD2pid) { // Already initialized return; } _CloseHandle(); g_iUpdateFailCounter += 1; g_ahD2Handle = OpenProcess((int)iPID); if (g_ahD2Handle == IntPtr.Zero) { // https://docs.microsoft.com/en-au/windows/win32/debug/system-error-codes var lastWin32Error = Marshal.GetLastWin32Error(); throw new Exception($"UpdateHandle: Couldn't open Diablo II memory handle. No Admin rights? lastWin32Error: {lastWin32Error}"); } if (!UpdateDllHandles()) { _CloseHandle(); logger.Debug("UpdateHandle: Couldn't update dll handles."); //throw new Exception("UpdateHandle: Couldn't update dll handles."); } if (InjectFunctions() == false) { _CloseHandle(); throw new Exception("UpdateHandle: Couldn't inject functions."); } g_iUpdateFailCounter = 0; g_iD2pid = iPID; g_pD2sgpt = (IntPtr)MemoryRead(g_hD2Common + 0x99E1C, g_ahD2Handle); }
public void Main() { //AutoItApi._HotKey_Disable(HK_FLAG_D2STATS); //var hTimerUpdateDelay = AutoItApi.TimerInit(); int timer = 0; bool bIsIngame = false; while (true) { timer++; var hWnd = AutoItApi.WinGetHandle("Diablo II"); if (hWnd == (IntPtr)0) { Thread.Sleep(500); ErrorMsg = "Couldn't find Diablo II window"; continue; } try { UpdateHandle(hWnd); ErrorMsg = ""; } catch (Exception ex) { ErrorMsg = ex.Message; } if (IsIngame()) { if (!bIsIngame) { // Reset the notify-cache Notifier.ItemCache = null; } InjectFunctions(); mouseFix.Do(); showItems.Do(); noPickup.Do(bIsIngame); configAlwaysRun.Do(); if (timer % 5 == 0) { // Throttle update. This is only a workaround to get the load on the cpu from ~3% to ~1% // Maybe implemente a proper wpf-implementation for the stats to fix that completle statsControl.UpdateStats(); } if (Settings.Default.notifyEnabled) { notifier.Do(); // The following implementation is not pretty but it should work good enough for now NotifierLinesClearError(); foreach (var errorLineNumber in notifier.MatchErrorLines) { NotifierLineAsError(errorLineNumber); } } bIsIngame = true; } else { if (bIsIngame) { //AutoItApi.GUICtrlSetState(g_idnotifyTest, GUI_DISABLE); } bIsIngame = false; g_hTimerCopyName = 0; } //if (g_hTimerCopyName && AutoItApi.TimerDiff(g_hTimerCopyName) > 10000) { // g_hTimerCopyName = 0; // if (bIsIngame) { PrintString("Item name multi-copy expired."); } //} Thread.Sleep(200); } }