def highLight(self): """高亮此区域 """ hwnd = win32gui.GetDesktopWindow() hDesktopDC = win32gui.GetWindowDC(hwnd) oldRop2 = ctypes.windll.gdi32.SetROP2(hDesktopDC, win32con.R2_NOTXORPEN) newPen = win32gui.CreatePen(win32con.PS_SOLID, 3, 0) oldPen = win32gui.SelectObject(hDesktopDC, newPen) #在指示窗口周围显示闪烁矩形 for i in range(2): win32gui.Rectangle(hDesktopDC, self._rect[0], self._rect[1], self._rect[2], self._rect[3]) time.sleep(0.2) win32gui.Rectangle(hDesktopDC, self._rect[0], self._rect[1], self._rect[2], self._rect[3]) time.sleep(0.3) ctypes.windll.gdi32.SetROP2(hDesktopDC, oldRop2) win32gui.SelectObject(hDesktopDC, oldPen) win32gui.DeleteObject(newPen) win32gui.ReleaseDC(hwnd,hDesktopDC)
def highlightWindow(self, hwnd): if hwnd is not None: left, top, right, bottom = win32gui.GetWindowRect(hwnd) windowDc = win32gui.GetWindowDC(hwnd) if windowDc: prevPen = win32gui.SelectObject(windowDc, self.rectanglePen) prevBrush = win32gui.SelectObject( windowDc, win32gui.GetStockObject(win32con.HOLLOW_BRUSH)) win32gui.Rectangle(windowDc, 0, 0, right - left, bottom - top) win32gui.SelectObject(windowDc, prevPen) win32gui.SelectObject(windowDc, prevBrush) win32gui.ReleaseDC(hwnd, windowDc)
def _on_mouse_move(self, hwnd, message, wparam, lparam): """Mouse moving event""" # get current mouse coordinates x, y = win32api.GetCursorPos() if self._drag: hdc = win32gui.CreateDC("DISPLAY", None, None) pycdc = win32ui.CreateDCFromHandle(hdc) pycdc.SetROP2(win32con.R2_NOTXORPEN) # erase old rectangle if self._draw: win32gui.Rectangle(hdc, self._start[0], self._start[1], self._end[0], self._end[1]) # draw new rectangle self._draw = True win32gui.Rectangle(hdc, self._start[0], self._start[1], x, y) self._end = (x, y)
def hightligt_window(handle): left, top, right, bottom = win32gui.GetWindowRect(handle) rectanglePen = win32gui.CreatePen(win32con.PS_SOLID, 3, win32api.RGB(255, 0, 0)) windowDc = win32gui.GetWindowDC(handle) if windowDc: prevPen = win32gui.SelectObject(windowDc, rectanglePen) prevBrush = win32gui.SelectObject( windowDc, win32gui.GetStockObject(win32con.HOLLOW_BRUSH)) win32gui.Rectangle(windowDc, 0, 0, right - left, bottom - top) win32gui.SelectObject(windowDc, prevPen) win32gui.SelectObject(windowDc, prevBrush) win32gui.ReleaseDC(handle, windowDc)
def draw_pixel(): hwin = win32gui.GetDesktopWindow() hdc = win32gui.GetDC(hwin) # 점찍기 red = win32api.RGB(255, 0, 0) win32gui.SetPixel(hdc, 0, 0, red) win32gui.SetPixel(hdc, 0, 1, red) win32gui.SetPixel(hdc, 0, 2, red) win32gui.SetPixel(hdc, 0, 3, red) # 사각형그리기 pen = win32gui.CreatePen(win32con.PS_SOLID, 5, win32api.RGB(0, 0, 255)) oldPen = win32gui.SelectObject(hdc, pen) win32gui.Rectangle(hdc, 50, 50, 100, 100) win32gui.SelectObject(hdc, oldPen) win32gui.DeleteObject(pen)
def OnPaint(hwnd, msg, wp, lp): """Windows needs repainting""" dc, ps = win32gui.BeginPaint(hwnd) #Draw red circle br = win32gui.CreateSolidBrush(win32api.RGB(255, 0, 0)) win32gui.SelectObject(dc, br) win32gui.Ellipse(dc, 20, 20, 120, 120) #Draw green rectangle br = win32gui.CreateSolidBrush(win32api.RGB(0, 255, 0)) win32gui.SelectObject(dc, br) win32gui.Rectangle(dc, 150, 20, 300, 120) #Draw blue triangle br = win32gui.CreateSolidBrush(win32api.RGB(0, 0, 255)) win32gui.SelectObject(dc, br) win32gui.Polygon(dc, [(400, 20), (350, 120), (450, 120)]) win32gui.EndPaint(hwnd, ps) return 0
def on_paint(self, hwnd, message, wparam, lparam): """Draw current selection rectangle.""" hdc, paint = win32gui.BeginPaint(hwnd) # Selection not started yet if self._selection is None: win32gui.EndPaint(hwnd, paint) return 0 brush = win32gui.GetStockObject(win32con.NULL_BRUSH) pen = win32gui.CreatePen(win32con.PS_SOLID, self.REGION_WIDTH, self.REGION_COLOR) brush_default = win32gui.SelectObject(hdc, brush) pen_default = win32gui.SelectObject(hdc, pen) win32gui.Rectangle(hdc, *self._selection) win32gui.SelectObject(hdc, pen_default) win32gui.SelectObject(hdc, brush_default) win32gui.EndPaint(hwnd, paint) return 0
def _on_mouse_up(self, hwnd, message, wparam, lparam): """Mouse up event""" if self._draw: # cleanup rectangle on desktop self._drag = False self._draw = False hdc = win32gui.CreateDC("DISPLAY", None, None) pycdc = win32ui.CreateDCFromHandle(hdc) pycdc.SetROP2(win32con.R2_NOTXORPEN) win32gui.Rectangle(hdc, self._start[0], self._start[1], self._end[0], self._end[1]) # save bitmap capture_screen(self._filename, self._start[0], self._start[1], self._end[0], self._end[1]) self.close() if self._shot_callback: self._shot_callback()
def _thread_function(x, y, w, h, delay): [x, y, w, h] = map(int, [x, y, w, h]) delay = float(delay) # Получим контекст всех дисплев или всего рабочего стола: #scr_hdc = win32gui.GetDC(0) scr_hdc = win32gui.CreateDC('DISPLAY', None, None) mem_hdc = win32gui.CreateCompatibleDC( scr_hdc ) # New context of memory device. This one is compatible with 'scr_hdc' new_bitmap_h = win32gui.CreateCompatibleBitmap(scr_hdc, w + 2, h + 2) win32gui.SelectObject( mem_hdc, new_bitmap_h ) # Returns 'old_bitmap_h'. It will be deleted automatically. # Сохраняем рамочку в 1 пиксель (она вокруг области (x,y,w,h)): _cp_boundary(mem_hdc, 0, 0, scr_hdc, x - 1, y - 1, w + 2, h + 2) # Рисуем подсветку области: # brush = win32gui.CreateSolidBrush(win32api.RGB(255,0,0)) win32gui.SelectObject(scr_hdc, win32gui.GetStockObject(win32con.NULL_BRUSH)) pen = win32gui.CreatePen(win32con.PS_DOT, 1, win32api.RGB(148, 0, 0)) win32gui.SelectObject(scr_hdc, pen) for i in range(2): win32gui.Rectangle(scr_hdc, x - 1, y - 1, x + w + 1, y + h + 1) # Восстаналиваема рамочку: time.sleep(delay) _cp_boundary(scr_hdc, x - 1, y - 1, mem_hdc, 0, 0, w + 2, h + 2) #win32gui.ReleaseDC(scr_hdc, 0) win32gui.DeleteDC(scr_hdc) win32gui.DeleteDC(mem_hdc) win32gui.DeleteObject(new_bitmap_h)
def drawRect(pos, pred, colors): hwnd = win32gui.GetDesktopWindow() # 定义框颜色 hPen = win32gui.CreatePen(win32con.PS_SOLID, 3, win32api.RGB(colors[pred][0], colors[pred][1], colors[pred][2])) win32gui.InvalidateRect(hwnd, None, True) win32gui.UpdateWindow(hwnd) win32gui.RedrawWindow(hwnd, None, None, win32con.RDW_FRAME | win32con.RDW_INVALIDATE | win32con.RDW_UPDATENOW | win32con.RDW_ALLCHILDREN) # 根据窗口句柄获取窗口的设备上下文DC(Divice Context) hwndDC = win32gui.GetDC(hwnd) win32gui.SelectObject(hwndDC, hPen) # 定义透明画刷,这个很重要! hbrush = win32gui.GetStockObject(win32con.NULL_BRUSH) prebrush = win32gui.SelectObject(hwndDC, hbrush) # 左上到右下的坐标 win32gui.Rectangle(hwndDC, pos[0] - 240, pos[1] - 135, pos[0] + 240, pos[1] + 135) win32gui.SaveDC(hwndDC) win32gui.SelectObject(hwndDC, prebrush) # 回收资源 win32gui.DeleteObject(hPen) win32gui.DeleteObject(hbrush) win32gui.DeleteObject(prebrush) win32gui.ReleaseDC(hwnd, hwndDC)
def draw_rectangle(cls, region: Region, color: RGB = None) -> None: """Draws a colour bordered transparent rectangle around given region Args: region (Region): [description] color (RGB, optional): [description]. Defaults to None. """ if not color: color = RGB(0, 255, 0) dc = win32gui.GetDC(0) pen = win32gui.CreatePen(win32con.PS_SOLID, 2, color.to_color_ref()) brush = win32gui.CreateBrushIndirect({ 'Style': win32con.BS_NULL, 'Color': -1, 'Hatch': win32con.HS_DIAGCROSS }) win32gui.SelectObject(dc, pen) win32gui.SelectObject(dc, brush) win32gui.Rectangle(dc, *region.to_tuple()) win32gui.DeleteObject(pen) win32gui.DeleteObject(brush) win32gui.DeleteDC(dc)
def mouse_pro(nCode, wParam, lParam): print('mouse_pro') """ 函数功能:鼠标钩子函数,当有鼠标事件,此函数被回调 """ if nCode == win32con.HC_ACTION: MSLLHOOKSTRUCT_p = POINTER(MSLLHOOKSTRUCT) param = cast(lParam, MSLLHOOKSTRUCT_p) # 鼠标左键点击 if wParam == win32con.WM_LBUTTONDOWN: hForeWnd = win32gui.GetForegroundWindow() dwSelfThreadId = win32api.GetCurrentThreadId() print(dwSelfThreadId) dwForeThreadId = win32process.GetWindowThreadProcessId(hForeWnd) print(dwForeThreadId) win32process.AttachThreadInput(dwForeThreadId[1], dwSelfThreadId, True) hw = win32api.GetFocus() win32process.AttachThreadInput(dwForeThreadId[1], dwSelfThreadId, False) # hw = win32gui.WindowFromPoint(win32api.GetCursorPos()) print("%s#######################%s" % (hw, mouse_hd)) print(win32gui.GetClassName(hw)) left, top, right, bottom = win32gui.GetWindowRect(hw) print(left, top, right, bottom) windowDc = win32gui.GetWindowDC(hw) if windowDc: prevPen = win32gui.SelectObject(windowDc, rectanglePen) prevBrush = win32gui.SelectObject(windowDc, win32gui.GetStockObject(win32con.HOLLOW_BRUSH)) win32gui.Rectangle(windowDc, 0, 0, right - left, bottom - top) win32gui.SelectObject(windowDc, prevPen) win32gui.SelectObject(windowDc, prevBrush) win32gui.ReleaseDC(hw, windowDc) # hw = win32gui.WindowFromPoint((int(param.contents.pt.x),int(param.contents.pt.y))) # print("%s#######################%s" % (hw, mouse_hd)) # print(win32gui.GetClassName(hw)) # left, top, right, bottom = win32gui.GetWindowRect(hw) # print(left, top, right, bottom) # print("左键点击,坐标:x:%d,y:%d" % (param.contents.pt.x,param.contents.pt.y)) # hwndChildList = get_child_windows(hw) # for hwndChild in hwndChildList: # hw = hwndChild # print("%s#######################%s" % (hw, mouse_hd)) # print(win32gui.GetClassName(hw)) # left, top, right, bottom = win32gui.GetWindowRect(hw) # print(left, top, right, bottom) # windowDc = win32gui.GetWindowDC(hw) # if windowDc: # prevPen = win32gui.SelectObject(windowDc, rectanglePen) # prevBrush = win32gui.SelectObject(windowDc, win32gui.GetStockObject(win32con.HOLLOW_BRUSH)) # # win32gui.Rectangle(windowDc, 0, 0, right - left, bottom - top) # win32gui.SelectObject(windowDc, prevPen) # win32gui.SelectObject(windowDc, prevBrush) # win32gui.ReleaseDC(hw, windowDc) # elif wParam == win32con.WM_LBUTTONUP: # print("左键抬起,坐标:x:%d,y:%d" % (param.contents.pt.x, param.contents.pt.y)) # elif wParam == win32con.WM_MOUSEMOVE: # hw = win32gui.WindowFromPoint(win32api.GetCursorPos()) # print("%s#######################%s" % (hw, mouse_hd)) # print(win32gui.GetClassName(hw)) # left, top, right, bottom = win32gui.GetWindowRect(hw) # print(left, top, right, bottom) # windowDc = win32gui.GetWindowDC(hw) # if windowDc: # prevPen = win32gui.SelectObject(windowDc, rectanglePen) # prevBrush = win32gui.SelectObject(windowDc, win32gui.GetStockObject(win32con.HOLLOW_BRUSH)) # # win32gui.Rectangle(windowDc, 0, 0, right - left, bottom - top) # win32gui.SelectObject(windowDc, prevPen) # win32gui.SelectObject(windowDc, prevBrush) # win32gui.ReleaseDC(hw, windowDc) # # # hw = win32gui.WindowFromPoint((int(param.contents.pt.x),int(param.contents.pt.y))) # # print("%s#######################%s" % (hw, mouse_hd)) # # print(win32gui.GetClassName(hw)) # # left, top, right, bottom = win32gui.GetWindowRect(hw) # # print(left, top, right, bottom) # # print("鼠标移动,坐标:x:%d,y:%d" % (param.contents.pt.x, param.contents.pt.y)) # elif wParam == win32con.WM_RBUTTONDOWN: # print("右键点击,坐标:x:%d,y:%d" % (param.contents.pt.x, param.contents.pt.y)) # elif wParam == win32con.WM_RBUTTONUP: # print("右键抬起,坐标:x:%d,y:%d" % (param.contents.pt.x, param.contents.pt.y)) return CallNextHookEx(mouse_hd, nCode, wParam, lParam)
hWnd = win32gui.GetDesktopWindow() # Retrieves a handle to the desktop window. The desktop window covers the entire screen. # The desktop window is the area on top of which other windows are painted. hdc = win32gui.GetDC(hWnd) #win32gui.GetDC(None) # A handle to the window whose DC is to be retrieved. If this value is NULL, GetDC # retrieves the DC for the entire screen. red = win32api.RGB(255, 0, 0) win32gui.SetPixel(hdc, 0, 0, red) # (0, 0)에 빨간 점 그리기 MyPen = win32gui.CreatePen(win32con.PS_SOLID, 5, win32api.RGB(0,0,255)); OldPen = win32gui.SelectObject(hdc, MyPen); win32gui.Rectangle(hdc, 50, 50, 100, 100) # (50, 50, 100, 100)에 파란 선으로 사각형 그리기 win32gui.SelectObject(hdc, OldPen); win32gui.DeleteObject(MyPen); # 폰트 만들기 font_spec = {'name':'Arial', 'height':42, 'weight':30} font = win32ui.CreateFont(font_spec) #lf = win32gui.LOGFONT() #lf.lfFaceName = "Times New Roman" #lf.lfHeight = 100 #lf.lfWeight = win32con.FW_NORMAL #hf = win32gui.CreateFontIndirect(lf) oldfont = win32gui.SelectObject(hdc, font.GetSafeHandle())
def drawRect(self, x, y, w, h): win32gui.FlashWindow(self.hwnd, 0) self.prebrush = win32gui.SelectObject(self.hwndDC, self.hbrush) win32gui.Rectangle(self.hwndDC, x - 1, y - 1, x + w + 2, y + h + 2) # 左上到右下的坐标
def drawPolygon(maxWidth, maxHeight): win32gui.Rectangle(dc, 100, 100, maxWidth - 100, maxHeight - 100)
def wnd_proc(h_wnd, message, w_param, l_param): """Displays a transparent window with some graphic elements Displays a transparent window with some graphic elements :param h_wnd: an input argument :returns: nothing """ if message == win32con.WM_QUIT: # print("Closing the window overlay") win32gui.PostQuitMessage(0) return 0 if message == win32con.WM_PAINT: hdc, paint_struct = win32gui.BeginPaint(h_wnd) win32gui.SetGraphicsMode(hdc, win32con.GM_ADVANCED) win32gui.BringWindowToTop(h_wnd) for r in self.graphical_elements: if 'geometry' in r: geometry = r['geometry'] else: geometry = None if 'x' in r: x = r['x'] - self.x_min else: x = 0 if 'y' in r: y = r['y'] - self.y_min else: y = 0 if 'width' in r: width = r['width'] else: width = 100 if 'height' in r: height = r['height'] else: height = 100 if 'xyrgb_array' in r: xyrgb_array = r['xyrgb_array'] else: xyrgb_array = ((15, 15, 255, 0, 0), (15, 45, 0, 255, 0), (45, 30, 0, 0, 255)) if 'color' in r: color_r = r['color'][0] color_g = r['color'][1] color_b = r['color'][2] else: color_r = 255 color_g = 0 color_b = 0 if 'thickness' in r: thickness = r['thickness'] else: thickness = 0 if 'angle' in r: angle = r['angle'] else: angle = 0 if 'geometry' in r and r['geometry'] is Shape.triangle: vertices = () for xyrgb in xyrgb_array: vertices = vertices + ( { 'x': int(round(xyrgb[0])) - self.x_min, 'y': int(round(xyrgb[1])) - self.y_min, 'Red': xyrgb[2] * 256, 'Green': xyrgb[3] * 256, 'Blue': xyrgb[4] * 256, 'Alpha': 0 }, ) mesh = ((0, 1, 2), ) win32gui.GradientFill(hdc, vertices, mesh, win32con.GRADIENT_FILL_TRIANGLE) if 'brush_color' in r: brush_color_r = r['brush_color'][0] brush_color_g = r['brush_color'][1] brush_color_b = r['brush_color'][2] else: brush_color_r = 255 brush_color_g = 255 brush_color_b = 255 if thickness == 0: color_r = brush_color_r color_g = brush_color_g color_b = brush_color_b if 'font_size' in r: font_size = r['font_size'] else: font_size = 18 if 'font_name' in r: font_name = r['font_name'] else: font_name = "Arial" my_brush = None if 'brush' in r and width > 1 and height > 1: brush = r['brush'] brush_color = win32api.RGB(brush_color_r, brush_color_g, brush_color_b) if brush is Brush.solid: my_brush = win32gui.CreateSolidBrush(brush_color) elif brush is Brush.b_diagonal: my_brush = win32gui.CreateHatchBrush( win32con.HS_BDIAGONAL, brush_color) elif brush is Brush.cross: my_brush = win32gui.CreateHatchBrush( win32con.HS_CROSS, brush_color) elif brush is Brush.diag_cross: my_brush = win32gui.CreateHatchBrush( win32con.HS_DIAGCROSS, brush_color) elif brush is Brush.f_diagonal: my_brush = win32gui.CreateHatchBrush( win32con.HS_FDIAGONAL, brush_color) elif brush is Brush.horizontal: my_brush = win32gui.CreateHatchBrush( win32con.HS_HORIZONTAL, brush_color) elif brush is Brush.vertical: my_brush = win32gui.CreateHatchBrush( win32con.HS_VERTICAL, brush_color) old_brush = win32gui.SelectObject(hdc, my_brush) pen = win32gui.CreatePen( win32con.PS_GEOMETRIC, thickness, win32api.RGB(color_r, color_g, color_b)) old_pen = win32gui.SelectObject(hdc, pen) if 'center_of_rotation' in r: center_of_rotation_x = r['center_of_rotation'][0] center_of_rotation_y = r['center_of_rotation'][1] else: center_of_rotation_x = 0 center_of_rotation_y = 0 if angle != 0: r_angle = angle * (math.pi / 180) Py_XFORM = win32gui.GetWorldTransform(hdc) win32gui.SetWorldTransform( hdc, { 'M11': math.cos(r_angle), 'M12': math.sin(r_angle), 'M21': math.sin(r_angle) * -1, 'M22': math.cos(r_angle), 'Dx': x, 'Dy': y }) x, y = -center_of_rotation_x, -center_of_rotation_y if 'text_format' in r: text_format = eval(r['text_format']) else: text_format = win32con.DT_CENTER | win32con.DT_SINGLELINE | win32con.DT_VCENTER if 'geometry' in r: if r['geometry'] is Shape.rectangle: win32gui.Rectangle(hdc, int(round(x)), int(round(y)), int(round(x + width)), int(round(y + height))) elif r['geometry'] is Shape.ellipse: win32gui.Ellipse(hdc, int(round(x)), int(round(y)), int(round(x + width)), int(round(y + height))) elif r['geometry'] is Shape.arrow: a = thickness t = ((x - int(a * 1.4), y), (x - a * 4, y + a * 3), (x, y), (x - a * 4, y - a * 3), (x - int(a * 1.4), y), (x - a * 9, y)) win32gui.Polyline(hdc, t) elif r['geometry'] is Shape.image: hicon = r['hicon'] win32gui.DrawIconEx(hdc, x, y, hicon, 0, 0, 0, None, 0x0003) elif r['geometry'] is Shape.triangle and thickness > 0: t = () for xyrgb in xyrgb_array: t = t + ((int(round( xyrgb[0])), +int(round(xyrgb[1]))), ) t = t + ((int(round(xyrgb_array[0][0])), int(round(xyrgb_array[0][1]))), ) win32gui.Polyline(hdc, t) if angle != 0: win32gui.SetWorldTransform(hdc, Py_XFORM) win32gui.SelectObject(hdc, old_pen) if 'brush' in r and width > 1 and height > 1: win32gui.SelectObject(hdc, old_brush) if 'text' in r: text = r['text'] lf = win32gui.LOGFONT() lf.lfFaceName = font_name lf.lfHeight = font_size lf.lfWeight = win32con.FW_NORMAL lf.lfQuality = win32con.ANTIALIASED_QUALITY hf = win32gui.CreateFontIndirect(lf) old_font = win32gui.SelectObject(hdc, hf) if 'text_color' in r: text_color_r = r['text_color'][0] text_color_g = r['text_color'][1] text_color_b = r['text_color'][2] else: text_color_r = 0 text_color_g = 0 text_color_b = 0 win32gui.SetTextColor( hdc, win32api.RGB(text_color_r, text_color_g, text_color_b)) if 'text_bg_color' in r: text_bg_color_r = r['text_bg_color'][0] text_bg_color_g = r['text_bg_color'][1] text_bg_color_b = r['text_bg_color'][2] else: text_bg_color_r = brush_color_r text_bg_color_g = brush_color_g text_bg_color_b = brush_color_b win32gui.SetBkMode(hdc, win32con.TRANSPARENT) win32gui.SetBkColor( hdc, win32api.RGB(text_bg_color_r, text_bg_color_g, text_bg_color_b)) tuple_r = tuple([ int(round(x)), int(round(y)), int(round(x + width)), int(round(y + height)) ]) win32gui.DrawTextW(hdc, text, -1, tuple_r, text_format) win32gui.SelectObject(hdc, old_font) win32gui.EndPaint(h_wnd, paint_struct) return 0 else: return win32gui.DefWindowProc(h_wnd, message, w_param, l_param)
def drawSoldiers(hDc, dataContainer, globalLock): # ============== initialize the minimap =============== centerX, centerY = 230, 530 boundaryX, boundaryY = 230, 230 top, bottom = centerY - boundaryY, centerY + boundaryY left, right = centerX - boundaryX, centerX + boundaryX hPen = win32gui.CreatePen(win32con.PS_SOLID, 2, COLOR_BLUE) win32gui.SelectObject(hDc, hPen) win32gui.Rectangle(hDc, left, top, right, bottom) drawCrossHair(hDc, centerX, centerY, size=230, lineWidth=2, color=COLOR_BLUE) # ===================================================== # ============== initialize the offview esp ================ sizeX, sizeY = 230, 135 hPenESP = win32gui.CreatePen(win32con.PS_SOLID, 1, COLOR_RED) hPenRect = win32gui.CreatePen(win32con.PS_SOLID, 2, COLOR_BLUE) win32gui.SelectObject(hDc, hPenRect) win32gui.Rectangle(hDc, 0, 0, 460, 270) drawCrossHair(hDc, 230, 135, size=5, lineWidth=2, color=COLOR_BLUE) # ========================================================== if dataContainer.isInGame != 0x4000: return # get the view properties globalLock.acquire() viewOrigin = dataContainer.viewOrigin.copy() viewAxisX = dataContainer.viewAxisX.copy() viewAxisY = dataContainer.viewAxisY.copy() viewAxisZ = dataContainer.viewAxisZ.copy() fovX = dataContainer.fovX fovY = dataContainer.fovY globalLock.release() win32gui.SelectObject(hDc, hPenESP) for i in range(dataContainer.soldiers.qsize()): soldier = dataContainer.soldiers.get() if not soldier.isValid(): continue headPos = soldier.posVec4.copy() headPos.z += 60.0 distance = (headPos - viewOrigin).length()/10 feetCoords = worldToScreen(fovX, fovY, sizeX, sizeY, viewAxisX, viewAxisY, viewAxisZ, viewOrigin, soldier.posVec4) if not feetCoords: continue headCoords = worldToScreen(fovX, fovY, sizeX, sizeY, viewAxisX, viewAxisY, viewAxisZ, viewOrigin, headPos) if not headCoords: continue feetX, feetY, miniX, miniY = feetCoords headX, headY, _p, _q = headCoords height = headY - feetY width = height / 3 # esp win32gui.Rectangle(hDc, headX-width/2, headY, feetX+width/2, feetY) # mini map dx = miniX + centerX dy = miniY + centerY if dx < left: dx = left if dx > right:dx = right if dy < top : dy = top if dy > bottom:dy = bottom win32gui.Rectangle(hDc, dx, dy, dx+4, dy+4)
def drawSoldiers(hDc, dataContainer, globalLock, cX, cY, lineWidth=1): """ win32gui.Rectangle(hDc, left, top, right, bottom) draw the box esp and the minimap """ globalLock.acquire() viewTransform = dataContainer.viewMatrix viewOrigin = dataContainer.viewOrigin viewForwardVec = dataContainer.viewForwardVec fovY = dataContainer.fovY fovX = dataContainer.fovX # i'm using the old bf3 worldToScreen calculation, so do not need the aspect ratio any more #aspect = dataContainer.aspectRatio globalLock.release() projM = getProjectionMatrixBF3(0.06, 10000.0, fovX, fovY) # ============== initialize the minimap ================ centerX, centerY = 200, 200 boundaryX, boundaryY = 160, 160 top, bottom = centerY - boundaryY, centerY + boundaryY left, right = centerX - boundaryX, centerX + boundaryX hPen = win32gui.CreatePen(win32con.PS_SOLID, 2, COLOR_BLUE) win32gui.SelectObject(hDc, hPen) win32gui.Rectangle(hDc, left, top, right, bottom) drawCrossHair(hDc, centerX, centerY, size=159, lineWidth=2, color=COLOR_BLUE) # ====================================================== # the consumer starts up - consuming n soldier objects at a time # n equals to the approximate size of the queue at that point for i in range(dataContainer.soldiers.qsize()): soldier = dataContainer.soldiers.get() # strictly speaking the soldier object can not be invalid (due to the producer-consumer # model), but just to be on the safe side... if not soldier.isValid(): continue distanceToViewOrigin = viewOrigin.distanceTo(soldier.posVec4) # visible enemy footman: Green color = COLOR_RED if soldier.occluded else COLOR_GREEN if soldier.isVehicle: hPen = win32gui.CreatePen(win32con.PS_SOLID, 2, COLOR_YELLOW) else: hPen = win32gui.CreatePen(win32con.PS_SOLID, lineWidth, color) win32gui.SelectObject(hDc, hPen) # here is the same logic as in BF3, applies to other MVP transformation as well posV = soldier.posVec4.multToMat(viewTransform) posVP = posV.multToMat(projM) if abs(posVP.w) > 0.001 and posVP.z <= 0: # ============== draw soldier box esp =============== # important! this is different from BF3 (d3d)!! scrX = int(cX * (1 + posVP.x / posVP.w)) scrY = int(cY * (1 - posVP.y / posVP.w)) # draw text text = "%d(%d)" % (int(distanceToViewOrigin), int(soldier.health)) win32gui.DrawText(hDc, text, len(text), (scrX, scrY, scrX + 68, scrY + 14), win32con.DT_TOP | win32con.DT_LEFT) # calculate the esp box size! # the reason I don't use the calculation is the scope will disturb the esp box if soldier.isVehicle: w, h = 6, 6 win32gui.Rectangle(hDc, scrX - w / 2, scrY - h, scrX + w / 2, scrY) else: w, h = 4, 4 #getWidthHeight(distanceToViewOrigin, soldier.stance) win32gui.Rectangle(hDc, scrX - w / 2, scrY - h, scrX + w / 2, scrY) # =================================================== if posV.w > 0.001: # =========== draw soldier minimap spot =========== # calculate the planar coord while compensate for the viewing angle dx = posV.x / posV.w cosA = viewForwardVec.dotProduct( vector.Vector4(viewForwardVec.x, 0.0, viewForwardVec.z, 0.0).normalize()) dy = posV.z / posV.w / abs(cosA) # limit the drawing to the defined minimap region dx = int(dx / 1.0 + centerX) dy = int(dy / 1.0 + centerY) if dx < left: dx = left if dx > right: dx = right if dy < top: dy = top if dy > bottom: dy = bottom # draw spot pColor = COLOR_RED if soldier.occluded else COLOR_GREEN hPen = win32gui.CreatePen(win32con.PS_SOLID, 2, pColor) win32gui.SelectObject(hDc, hPen) win32gui.Rectangle(hDc, dx, dy, dx + 2, dy + 2)