#include #include #Include #Include #include ;#include "FastFind.au3" #include #include #RequireAdmin ; ko thong bao khi thieu var co them quyen admin ghi vao bo x32 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "WinHttp.au3" #include "demem.au3" #include #include ;#include "VirtDsktLibrary01.au3" #include #include _WinAPI_SetErrorMode($SEM_FAILCRITICALERRORS Or $SEM_NOGPFAULTERRORBOX) $gamex01 = 720 ; 920 NOX $gamey01 = 530 ; 500 NOX $game_cap_x01 = 0 ; 5 $game_cap_y01 = 0 ; 35 $game_cap_x02 = $gamex01 $game_cap_y02 = $gamey01 $g_x = 0 $g_y = 0 $tab_all01 = 1 ; 1 tab = 0x2B0000 $vtmem_autoitX = _MemVirtualAlloc(0x0, 0x2B0000*$tab_all01, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) ; khoi tao 1 lan duy nhat khong se bi error memory $vtmem_autoit_screenX = _MemVirtualAlloc(0x0, 0x2B0000*$tab_all01, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) ; khoi tao 1 lan duy nhat khong se bi error memory $vtmem_autoit_screenXcrop = _MemVirtualAlloc(0x0, 0x2B0000*$tab_all01, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) ; khoi tao 1 lan duy nhat khong se bi error memory $tCodeBuffer = ASM64_opcode01vtmem() ; khoi tao 1 lan duy nhat khong se bi error memory ; Mở sẵn DLL tống vào RAM, không để AutoIt phải tốn thời gian tìm kiếm lại Global $g_hUser32_DLL = DllOpen("user32.dll") ; dùng cho WinCapture_cs01new Global $g_hGDI32_DLL = DllOpen("gdi32.dll") ; dùng cho WinCapture_cs01new ; 2. Lấy TỌA ĐỘ GPS (Địa chỉ RAM) của hàm PrintWindow cất vào biến $g_pPrintWindow ;Local $hModule = _WinAPI_GetModuleHandle("user32.dll") ; dùng cho WinCapture_cs01new ;Global $g_pPrintWindow = _WinAPI_GetProcAddress($hModule, "PrintWindow") ; dùng cho WinCapture_cs01new ; Kiểm tra xem lấy được địa chỉ RAM chưa (Chỉ dùng để test lúc đầu) ; ConsoleWrite("Địa chỉ RAM của PrintWindow: " & $g_pPrintWindow & @CRLF) Func ASM64_opcode01vtmem($bytes0="102400") Local $tCodeBuffer = _DllStructCreate64("byte ASM["&$bytes0&"]") Return $tCodeBuffer EndFunc Func _DllStructCreate64($struct) ;align auf 16-byte adresse Local $temp = DllStructCreate($struct) Local $tempsize = DllStructGetSize($temp) + 64 Local $ptr = DllStructGetPtr($struct) Local $a1 = Mod(Number($ptr), 64) Local $temp = 0 Local $mem = _MemVirtualAlloc($ptr + $a1, $tempsize, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) Local $a2 = Mod(Number($mem), 64) ;rest div 16 adresse = offset Local $sstruct = DllStructCreate($struct, (Number($mem) - $a2 + 64)) Return $sstruct ;auf 16 alingned pointer EndFunc ;==>_DllStructCreate64_2 $control01 = WinGetHandle("[REGEXPTITLE:\[#\] \["& "a" & "1"&"\] Diablo Immortal \[#\]]") ;$control01 = WinGetHandle("Master Bot Controller - 2 Accounts (a1 & a2)") If Not $control01 Then MsgBox(16, "Lỗi", "Không tìm thấy cửa sổ Game!") Exit EndIf ; 3. TẠO CỬA SỔ GUI ĐỂ HIỂN THỊ MAP PREVIEW Global $hGUI = GUICreate("Scaled Map 106x106", 720, 530) GUISetState(@SW_SHOW, $hGUI) ; 4. Bắt đầu GDI+ 1 lần duy nhất ở ngoài _GDIPlus_Startup() ; Khai báo biến đếm thời gian Local $hTimer, $iTimeCost $iTimeCost01add = 0 $iTimeCost02add = 0 ; 5. VÒNG LẶP CHÍNH CỦA TOOL While 1 ; Xử lý sự kiện GUI (tắt cửa sổ) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch ; Chạy hàm Capture và Vẽ ; ---> BẮT ĐẦU BẤM GIỜ <--- $hTimer01 = TimerInit() WinCapture_cs02new($control01, $vtmem_autoit_screenX, $hGUI, 1,$game_cap_x02,$game_cap_y02,$g_x,$g_y) ; $hGUI kiêm tra ten gui ton tai ;WinCapture_cs02new($control01, $vtmem_autoit_screenX, $hGUI, 1,$game_cap_x02,$game_cap_y02) ; $hGUI kiêm tra ten gui ton tai ;WinCapture_cs01new($control01, $vtmem_autoit_screenX, $hGUI, 1,$game_cap_x02,$game_cap_y02) ; $hGUI kiêm tra ten gui ton tai $iTimeCost01 = TimerDiff($hTimer01) $hTimer02 = TimerInit() ;WinCapture_ScaleAndWrite03($control01, $vtmem_autoit_screenX, $hGUI, 1,$game_cap_x02,$game_cap_y02) ;WinCapture_ScaleAndWrite02($control01, $vtmem_autoit_screenX, $hGUI, 1) $iTimeCost02 = TimerDiff($hTimer02) ;$iTimeCost01add += Round($iTimeCost01, 2) ;$iTimeCost02add += Round($iTimeCost02, 2) $iTimeCost01add = Round($iTimeCost01, 2) $iTimeCost02add = Round($iTimeCost02, 2) ; Cập nhật thời gian chạy lên thanh Title của GUI để dễ soi WinSetTitle($hGUI, "", "$iTimeCost01: " & $iTimeCost01add & " ms"&" $iTimeCost02: " & $iTimeCost02add & " ms") ; Nghỉ một chút nhường CPU Sleep(10) WEnd ; Dọn dẹp khi thoát _GDIPlus_Shutdown() _MemVirtualFree($vtmem_autoit_screenX, 0, $MEM_RELEASE) ;$WinCapture_cs01new_on = 0 ;WinCapture_cs02new($control01, $vtmem_autoit_screenX, $hGUI, 1,$gamex01,$gamey01) ; $hGUI kiêm tra ten gui ton tai ; ==================================================================================================== ; HÀM CAPTURE TỐI ƯU SIÊU TỐC - GDI THUẦN (GETDIBITS + STRETCHBLT SCALE ~1MS) ; ==================================================================================================== Func WinCapture_cs02new($hWnd, $vtmem_autoit_screenX, $g_hGUI = 0, $scale0 = 1,$iWidth0=720,$iHeigh0=530,$g_x = 0,$g_y = 0) Local $iWidth = $iWidth0 Local $iHeight = $iHeigh0 Local $nFlags = 3 $g_x0 = $g_x $g_y0 = $g_y ; Tính kích thước sau khi Scale Local $iIW = Int($iWidth / $scale0) Local $iIH = Int($iHeight / $scale0) ; 1. LẤY IMAGE GAME VÀO MEMORY Local $hDDC = _WinAPI_GetDC($hWnd) Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC) Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight) _WinAPI_SelectObject($hCDC, $hBMP) ; ---> [SỬA LỖI TẠI ĐÂY]: Không xóa $hBMP trước khi PrintWindow (Xóa ở đây sẽ bị màn hình đen) ; _WinAPI_DeleteObject($hBMP) ; Xóa ko hiển thị hình gui nhưng vẫn có trong memory ;DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "hwnd", $hCDC, "int", $nFlags) DllCall($g_hUser32_DLL, "int", "PrintWindow", "hwnd", $hWnd, "hwnd", $hCDC, "int", $nFlags) ;DllCallAddress("int", $g_pPrintWindow, "hwnd", $hWnd, "hwnd", $hCDC, "int", $nFlags) ; Mặc định target sẽ lấy từ DC gốc Local $hTargetDC = $hCDC Local $hTargetBMP = $hBMP ; 2. XỬ LÝ SCALE BẰNG STRETCHBLT (NẾU $scale0 <> 1) Local $hScaledDC = 0, $hScaledBMP = 0 If $scale0 <> 1 Then $hScaledDC = _WinAPI_CreateCompatibleDC($hDDC) $hScaledBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iIW, $iIH) _WinAPI_SelectObject($hScaledDC, $hScaledBMP) ; Mode 3 (COLORONCOLOR / STRETCH_DELETESCANS): Thu nhỏ cực nhanh bằng cách bỏ pixel thừa, tối ưu nhất cho AutoIt soi màu ;DllCall("gdi32.dll", "int", "SetStretchBltMode", "handle", $hScaledDC, "int", 3) DllCall($g_hGDI32_DLL, "int", "SetStretchBltMode", "handle", $hScaledDC, "int", 3) ; Co giãn ảnh từ $hCDC (720x530) sang $hScaledDC ($iIW x $iIH) _WinAPI_StretchBlt($hScaledDC, 0, 0, $iIW, $iIH, $hCDC, 0, 0, $iWidth, $iHeight, 0x00CC0020) ; 0x00CC0020 = $SRCCOPY ; Trỏ Target sang DC đã Scale $hTargetDC = $hScaledDC $hTargetBMP = $hScaledBMP EndIf ; 3. ĐỔ THẲNG PIXEL TỪ GDI VÀO BASE RAM ($vtmem_autoit_screenX) BẰNG GetDIBits If $vtmem_autoit_screenX <> 0 Then Local $tBMI = DllStructCreate("dword Size; long Width; long Height; word Planes; word BitCount; dword Compression; dword SizeImage; long XPelsPerMeter; long YPelsPerMeter; dword ClrUsed; dword ClrImportant") DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI)) DllStructSetData($tBMI, "Width", $iIW) DllStructSetData($tBMI, "Height", -$iIH) ; Dấu âm (-) ép GDI xuất kiểu Top-Down DllStructSetData($tBMI, "Planes", 1) DllStructSetData($tBMI, "BitCount", 32) DllStructSetData($tBMI, "Compression", 0) ; BI_RGB ; Lấy mảng byte từ $hTargetDC ghi thẳng trực tiếp vào con trỏ $vtmem_autoit_screenX ;DllCall("gdi32.dll", "int", "GetDIBits", "hwnd", $hTargetDC, "hwnd", $hTargetBMP, "uint", 0, "uint", $iIH, "ptr", $vtmem_autoit_screenX, "ptr", DllStructGetPtr($tBMI), "uint", 0) DllCall($g_hGDI32_DLL, "int", "GetDIBits", "hwnd", $hTargetDC, "hwnd", $hTargetBMP, "uint", 0, "uint", $iIH, "ptr", $vtmem_autoit_screenX, "ptr", DllStructGetPtr($tBMI), "uint", 0) EndIf ; 4. VẼ PREVIEW LÊN GUI (NẾU CÓ TRUYỀN $g_hGUI) If WinExists($g_hGUI) Then Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) Local $hBmpFromRAM = _GDIPlus_BitmapCreateFromScan0($iIW, $iIH, $GDIP_PXF32ARGB, $iIW * 4, $vtmem_autoit_screenX) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBmpFromRAM, 10, 10, $iIW, $iIH) _GDIPlus_BitmapDispose($hBmpFromRAM) _GDIPlus_GraphicsDispose($hGraphics) EndIf ; 5. CLEAN UP DC & BITMAP If $hScaledDC Then _WinAPI_DeleteDC($hScaledDC) _WinAPI_DeleteObject($hScaledBMP) EndIf ; ---> [SỬA LỖI TẠI ĐÂY]: Không xóa ở đây vì hàm WinCapture_ce01 sẽ gọi để xóa. Xóa 2 lần = Crash Bot. ; _WinAPI_DeleteDC($hCDC) ; _WinAPI_ReleaseDC($hWnd, $hDDC) ; ---> [SỬA LỖI TẠI ĐÂY]: Khai báo các biến bị thiếu để hàm trả về bộ form chuẩn 100% giống WinCapture_cs01 cũ Local $iScan0 = $vtmem_autoit_screenX ; Lấy RAM VTMEM làm Scan0 Local $tPixel = DllStructCreate("int[" & $iWidth * $iHeight & "];", $iScan0) ; Cấu trúc để bot đọc màu Local $BMP = 0, $tBitmapData = 0 ; Báo cho ce01 biết đây là GDI thuần ; ---> [SỬA LỖI TẠI ĐÂY]: Gỡ bỏ dấu ngoặc kép "" để trả về GIÁ TRỊ BIẾN thật sự. Local $stream_var[13] = [$hBMP, $iScan0, $tPixel, $BMP, $tBitmapData, $hWnd, $hDDC, $hCDC, $iWidth, $iHeight, $g_x0, $g_y0 &@CRLF& _ ""] ;$x01 = 555 ;$y01 = 394 ;$iRowOffset = $y01 * $iWidth+1 ; $iRowOffset = $iY * $iWidth + 1 ;$acolor01 = Hex(DllStructGetData($stream_var[2], 1, $iRowOffset + $x01),6) ;get pixel color ;MsgBox("","check","01 = "&$acolor01&" 02 = "&$acolor01,0) ; Local $stream_var[0] = $hBMP ; Local $stream_var[1] = $iScan0 ; Local $stream_var[2] = $tPixel ; Local $stream_var[3] = $BMP ; Local $stream_var[4] = $tBitmapData ; Local $stream_var[5] = $WinHandle ; Local $stream_var[6] = $hDDC ; Local $stream_var[7] = $hCDC ; Local $stream_var[8] = $iWidth ; Local $stream_var[9] = $iHeight ; Local $stream_var[10] = $g_x0 ; Local $stream_var[11] = $g_y0 Return $stream_var EndFunc ;WinCapture_cs01new($control01, $vtmem_autoit_screenX, $hGUI, 1,$gamex01,$gamey01) ; $hGUI kiêm tra ten gui ton tai ; ==================================================================================================== ; HÀM CAPTURE TỐI ƯU SIÊU TỐC - GDI THUẦN (GETDIBITS + STRETCHBLT SCALE ~1MS) ; ==================================================================================================== Func WinCapture_cs01new($hWnd, $vtmem_autoit_screenX, $g_hGUI = 0, $scale0 = 1,$iWidth0=720,$iHeigh0=530) Local $iWidth = $iWidth0 Local $iHeight = $iHeigh0 Local $nFlags = 3 ; Tính kích thước sau khi Scale Local $iIW = Int($iWidth / $scale0) Local $iIH = Int($iHeight / $scale0) ; 1. LẤY IMAGE GAME VÀO MEMORY Local $hDDC = _WinAPI_GetDC($hWnd) Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC) Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight) _WinAPI_SelectObject($hCDC, $hBMP) _WinAPI_DeleteObject($hBMP) ; Xóa ko hiển thị hình gui nhưng vẫn có trong memory DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "hwnd", $hCDC, "int", $nFlags) ;DllCall($g_hUser32_DLL, "int", "PrintWindow", "hwnd", $hWnd, "hwnd", $hCDC, "int", $nFlags) ;DllCallAddress("int", $g_pPrintWindow, "hwnd", $hWnd, "hwnd", $hCDC, "int", $nFlags) ; Mặc định target sẽ lấy từ DC gốc Local $hTargetDC = $hCDC Local $hTargetBMP = $hBMP ; 2. XỬ LÝ SCALE BẰNG STRETCHBLT (NẾU $scale0 <> 1) Local $hScaledDC = 0, $hScaledBMP = 0 If $scale0 <> 1 Then $hScaledDC = _WinAPI_CreateCompatibleDC($hDDC) $hScaledBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iIW, $iIH) _WinAPI_SelectObject($hScaledDC, $hScaledBMP) ; Mode 3 (COLORONCOLOR / STRETCH_DELETESCANS): Thu nhỏ cực nhanh bằng cách bỏ pixel thừa, tối ưu nhất cho AutoIt soi màu DllCall("gdi32.dll", "int", "SetStretchBltMode", "handle", $hScaledDC, "int", 3) ;DllCall($g_hGDI32_DLL, "int", "SetStretchBltMode", "handle", $hScaledDC, "int", 3) ; Co giãn ảnh từ $hCDC (720x530) sang $hScaledDC ($iIW x $iIH) _WinAPI_StretchBlt($hScaledDC, 0, 0, $iIW, $iIH, $hCDC, 0, 0, $iWidth, $iHeight, 0x00CC0020) ; 0x00CC0020 = $SRCCOPY ; Trỏ Target sang DC đã Scale $hTargetDC = $hScaledDC $hTargetBMP = $hScaledBMP EndIf ; 3. ĐỔ THẲNG PIXEL TỪ GDI VÀO BASE RAM ($vtmem_autoit_screenX) BẰNG GetDIBits If $vtmem_autoit_screenX <> 0 Then Local $tBMI = DllStructCreate("dword Size; long Width; long Height; word Planes; word BitCount; dword Compression; dword SizeImage; long XPelsPerMeter; long YPelsPerMeter; dword ClrUsed; dword ClrImportant") DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI)) DllStructSetData($tBMI, "Width", $iIW) DllStructSetData($tBMI, "Height", -$iIH) ; Dấu âm (-) ép GDI xuất kiểu Top-Down DllStructSetData($tBMI, "Planes", 1) DllStructSetData($tBMI, "BitCount", 32) DllStructSetData($tBMI, "Compression", 0) ; BI_RGB ; Lấy mảng byte từ $hTargetDC ghi thẳng trực tiếp vào con trỏ $vtmem_autoit_screenX DllCall("gdi32.dll", "int", "GetDIBits", "hwnd", $hTargetDC, "hwnd", $hTargetBMP, "uint", 0, "uint", $iIH, "ptr", $vtmem_autoit_screenX, "ptr", DllStructGetPtr($tBMI), "uint", 0) ;DllCall($g_hGDI32_DLL, "int", "GetDIBits", "hwnd", $hTargetDC, "hwnd", $hTargetBMP, "uint", 0, "uint", $iIH, "ptr", $vtmem_autoit_screenX, "ptr", DllStructGetPtr($tBMI), "uint", 0) EndIf ; 4. VẼ PREVIEW LÊN GUI (NẾU CÓ TRUYỀN $g_hGUI) If WinExists($g_hGUI) Then Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) Local $hBmpFromRAM = _GDIPlus_BitmapCreateFromScan0($iIW, $iIH, $GDIP_PXF32ARGB, $iIW * 4, $vtmem_autoit_screenX) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBmpFromRAM, 10, 10, $iIW, $iIH) _GDIPlus_BitmapDispose($hBmpFromRAM) _GDIPlus_GraphicsDispose($hGraphics) EndIf ; 5. CLEAN UP DC & BITMAP If $hScaledDC Then _WinAPI_DeleteDC($hScaledDC) _WinAPI_DeleteObject($hScaledBMP) EndIf _WinAPI_DeleteDC($hCDC) _WinAPI_ReleaseDC($hWnd, $hDDC) Local $stream_var[13] = ["$hBMP", "$iScan0", "$tPixel", "$BMP", "$tBitmapData", "$hWnd", "$hDDC", "$hCDC", $iWidth, $iHeight, "$g_x0", "$g_y0" &@CRLF& _ ""] ;$x01 = 555 ;$y01 = 394 ;$iRowOffset = $y01 * $iWidth+1 ; $iRowOffset = $iY * $iWidth + 1 ;$acolor01 = Hex(DllStructGetData($stream_var[2], 1, $iRowOffset + $x01),6) ;get pixel color ;MsgBox("","check","01 = "&$acolor01&" 02 = "&$acolor01,0) ; Local $stream_var[0] = $hBMP ; Local $stream_var[1] = $iScan0 ; Local $stream_var[2] = $tPixel ; Local $stream_var[3] = $BMP ; Local $stream_var[4] = $tBitmapData ; Local $stream_var[5] = $WinHandle ; Local $stream_var[6] = $hDDC ; Local $stream_var[7] = $hCDC ; Local $stream_var[8] = $iWidth ; Local $stream_var[9] = $iHeight ; Local $stream_var[10] = $g_x0 ; Local $stream_var[11] = $g_y0 Return $stream_var EndFunc ; ==================================================================================================== ; HÀM CAPTURE TỐI ƯU SIÊU TỐC - DÙNG GDI THUẦN (GETDIBITS) ; ==================================================================================================== Func WinCapture_ScaleAndWrite03($hWnd, $vtmem_autoit_screenX, $g_hGUI = 0, $scale0 = 1,$iWidth0=720,$iHeigh0=530) Local $iWidth = $iWidth0 Local $iHeight = $iHeigh0 Local $nFlags = 3 ; 1. LẤY IMAGE GAME VÀO MEMORY Local $hDDC = _WinAPI_GetDC($hWnd) Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC) Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight) _WinAPI_SelectObject($hCDC, $hBMP) _WinAPI_DeleteObject($hBMP) ; Xóa ko hiển thị hình gui nhưng vẫn có trong memory DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "hwnd", $hCDC, "int", $nFlags) ; 2. ĐỔ THẲNG PIXEL TỪ GDI VÀO BASE RAM ($vtmem_autoit_screenX) BẰNG GetDIBits If $vtmem_autoit_screenX <> 0 Then Local $tBMI = DllStructCreate("dword Size; long Width; long Height; word Planes; word BitCount; dword Compression; dword SizeImage; long XPelsPerMeter; long YPelsPerMeter; dword ClrUsed; dword ClrImportant") DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI)) DllStructSetData($tBMI, "Width", $iWidth) DllStructSetData($tBMI, "Height", -$iHeight) ; Dấu âm (-) ép GDI xuất kiểu Top-Down, ảnh không bị ngược DllStructSetData($tBMI, "Planes", 1) DllStructSetData($tBMI, "BitCount", 32) DllStructSetData($tBMI, "Compression", 0) ; BI_RGB ; Lấy mảng byte ghi thẳng trực tiếp vào con trỏ $vtmem_autoit_screenX DllCall("gdi32.dll", "int", "GetDIBits", "hwnd", $hCDC, "hwnd", $hBMP, "uint", 0, "uint", $iHeight, "ptr", $vtmem_autoit_screenX, "ptr", DllStructGetPtr($tBMI), "uint", 0) EndIf ; 3. VẼ PREVIEW LÊN GUI (NẾU CÓ TRUYỀN $g_hGUI) If WinExists($g_hGUI) Then Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) Local $hBmpFromRAM = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $GDIP_PXF32ARGB, $iWidth * 4, $vtmem_autoit_screenX) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBmpFromRAM, 10, 10, $iWidth, $iHeight) _GDIPlus_BitmapDispose($hBmpFromRAM) _GDIPlus_GraphicsDispose($hGraphics) EndIf ; 4. CLEAN UP DC & BITMAP _WinAPI_DeleteDC($hCDC) _WinAPI_ReleaseDC($hWnd, $hDDC) Return 1 EndFunc ; ==================================================================================================== ; HÀM CAPTURE & BỎ RESIZE (GIỮ NGUYÊN CÁC ĐOẠN KHÁC ACCORDING TO YOUR REQUEST) ; ==================================================================================================== Func WinCapture_ScaleAndWrite02($hWnd, $vtmem_autoit_screenX, $g_hGUI = 0, $scale0 = 1) ; không scale do bị chậm Local $iWidth = 720 Local $iHeight = 530 Local $nFlags = 3 ; Tính kích thước Scale giống y xì mã cũ của bạn Local $iIW = Int($iWidth / $scale0) Local $iIH = Int($iHeight / $scale0) Local $iTotalBytes = ($iIH * $iIW) * 4 ; 1. LẤY IMAGE GAME VÀO MEMORY (Giữ nguyên trò DeleteObject kinh điển của bạn) Local $hDDC = _WinAPI_GetDC($hWnd) Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC) Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight) _WinAPI_SelectObject($hCDC, $hBMP) _WinAPI_DeleteObject($hBMP) ; Xóa ko hiển thị hình gui nhưng vẫn có trong memory DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "hwnd", $hCDC, "int", $nFlags) ; Tạo GDI+ Bitmap từ hBMP đã chụp Local $BMP = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) ; Dọn dẹp DC _WinAPI_DeleteDC($hCDC) _WinAPI_ReleaseDC($hWnd, $hDDC) If Not $BMP Then Return 0 ; Gán trực tiếp $BMP cho $g_hBitmap02 thay vì gọi _GDIPlus_ImageResize Local $g_hBitmap02 = $BMP ; 3. LOCK BITS VÀ TẠO STRUCT PIXEL ĐỂ ĐẨY VÀO RAM Local $tBitmapData = _GDIPlus_BitmapLockBits($g_hBitmap02, 0, 0, $iIW, $iIH, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB) Local $Scan0 = DllStructGetData($tBitmapData, "Scan0") ; Create DLL structure for all pixels chuẩn bài của bạn Local $tPixel = DllStructCreate("byte[" & $iTotalBytes & "]", $Scan0) ; 4. MOVE MEMORY VÀO BASE RAM If $vtmem_autoit_screenX <> 0 Then _WinAPI_MoveMemory($vtmem_autoit_screenX, $tPixel, $iTotalBytes) EndIf ; 5. VẼ PREVIEW LÊN GUI TRỰC TIẾP TỪ BASE ADDRESS ($vtmem_autoit_screenX) If WinExists($g_hGUI) Then Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ; Tạo một Bitmap MỚI TINH đọc trực tiếp từ con trỏ Base Local $hBmpFromRAM = _GDIPlus_BitmapCreateFromScan0($iIW, $iIH, $GDIP_PXF32ARGB, $iIW * 4, $vtmem_autoit_screenX) ; Vẽ cái hình bốc từ RAM đó lên GUI _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBmpFromRAM, 10, 10, $iIW, $iIH) ; Vẽ xong thì giải phóng cái bitmap tạm này _GDIPlus_BitmapDispose($hBmpFromRAM) _GDIPlus_GraphicsDispose($hGraphics) EndIf ; ClipPut($vtmem_autoit_screenX) ; 6. CLEAN UP _GDIPlus_BitmapUnlockBits($g_hBitmap02, $tBitmapData) _GDIPlus_BitmapDispose($g_hBitmap02) Return 1 EndFunc ; ==================================================================================================== ; HÀM CAPTURE & TỰ ĐỘNG SCALE BẰNG _GDIPlus_ImageResize (CHUẨN LOGIC MÃ CŨ CỦA BẠN) ; ==================================================================================================== ; Thêm tham số $scale0 vào khai báo hàm (Mặc định = 1 là giữ nguyên kích cỡ gốc) Func WinCapture_ScaleAndWrite01($hWnd, $vtmem_autoit_screenX, $g_hGUI = 0, $scale0 = 1) Local $iWidth = 720 Local $iHeight = 530 Local $nFlags = 3 ; Tính kích thước Scale giống y xì mã cũ của bạn Local $iIW = Int($iWidth / $scale0) Local $iIH = Int($iHeight / $scale0) Local $iTotalBytes = ($iIH * $iIW) * 4 ; 1. LẤY IMAGE GAME VÀO MEMORY (Giữ nguyên trò DeleteObject kinh điển của bạn) Local $hDDC = _WinAPI_GetDC($hWnd) Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC) Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight) _WinAPI_SelectObject($hCDC, $hBMP) _WinAPI_DeleteObject($hBMP) ; Xóa ko hiển thị hình gui nhưng vẫn có trong memory DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "hwnd", $hCDC, "int", $nFlags) ; Tạo GDI+ Bitmap từ hBMP đã chụp Local $BMP = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) ; Dọn dẹp DC _WinAPI_DeleteDC($hCDC) _WinAPI_ReleaseDC($hWnd, $hDDC) If Not $BMP Then Return 0 ; 2. SCALE IMAGE BẰNG HÀM NATIVE CỦA AUTOIT ; Nếu $scale0 = 1 thì bản chất nó resize bằng đúng kích thước cũ Local $g_hBitmap02 = _GDIPlus_ImageResize($BMP, $iIW, $iIH) _GDIPlus_BitmapDispose($BMP) ; Xóa bản gốc 720x530 cho nhẹ RAM ; 3. LOCK BITS VÀ TẠO STRUCT PIXEL ĐỂ ĐẨY VÀO RAM Local $tBitmapData = _GDIPlus_BitmapLockBits($g_hBitmap02, 0, 0, $iIW, $iIH, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB) Local $Scan0 = DllStructGetData($tBitmapData, "Scan0") ; Create DLL structure for all pixels chuẩn bài của bạn Local $tPixel = DllStructCreate("byte[" & $iTotalBytes & "]", $Scan0) ; 4. MOVE MEMORY VÀO BASE RAM If $vtmem_autoit_screenX <> 0 Then _WinAPI_MoveMemory($vtmem_autoit_screenX, $tPixel, $iTotalBytes) EndIf ; 5. VẼ PREVIEW LÊN GUI TRỰC TIẾP TỪ BASE ADDRESS ($vtmem_autoit_screenX) If WinExists($g_hGUI) Then Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ; Tạo một Bitmap MỚI TINH đọc trực tiếp từ con trỏ Base Local $hBmpFromRAM = _GDIPlus_BitmapCreateFromScan0($iIW, $iIH, $GDIP_PXF32ARGB, $iIW * 4, $vtmem_autoit_screenX) ; Vẽ cái hình bốc từ RAM đó lên GUI _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBmpFromRAM, 10, 10, $iIW, $iIH) ; Vẽ xong thì giải phóng cái bitmap tạm này _GDIPlus_BitmapDispose($hBmpFromRAM) _GDIPlus_GraphicsDispose($hGraphics) EndIf ; ClipPut($vtmem_autoit_screenX) ; 6. CLEAN UP _GDIPlus_BitmapUnlockBits($g_hBitmap02, $tBitmapData) _GDIPlus_BitmapDispose($g_hBitmap02) Return 1 EndFunc