0

The cheat protection of the game I play ensures that the following codes do not work. When I use different screen capture methods, I encounter a black screen and I tried many alternatives, but I could not get a result. Do you have any solution or alternative solution for this error?

This Error output:
enter image description here

import cv2
import numpy as np
import win32gui, win32ui, win32con

class WindowCapture:
    w = 0
    h = 0
    hwnd = None
    cropped_x = 0
    cropped_y = 0
    offset_x = 0
    offset_y = 0
    def __init__(self, window_name):
        self.hwnd = win32gui.FindWindow(None, window_name)
        if not self.hwnd:
            raise Exception('Window not found: {}'.format(window_name))
        window_rect = win32gui.GetWindowRect(self.hwnd)
        self.w = window_rect[2] - window_rect[0]
        self.h = window_rect[3] - window_rect[1]

        border_pixels = 1  # <-- Change this
        titlebar_pixels = 10  # <-- Change this
        self.w = self.w - border_pixels  # <-- Change this
        self.h = self.h - titlebar_pixels - border_pixels
        self.cropped_x = border_pixels
        self.cropped_y = titlebar_pixels
    def get_screenshot(self):
        wDC = win32gui.GetWindowDC(self.hwnd)
        dcObj = win32ui.CreateDCFromHandle(wDC)
        cDC = dcObj.CreateCompatibleDC()
        dataBitMap = win32ui.CreateBitmap()
        dataBitMap.CreateCompatibleBitmap(dcObj, self.w, self.h)
        cDC.SelectObject(dataBitMap)
        cDC.BitBlt((0, 0), (self.w, self.h), dcObj, (self.cropped_x, self.cropped_y), win32con.SRCCOPY)
        signedIntsArray = dataBitMap.GetBitmapBits(True)
        img = np.fromstring(signedIntsArray, dtype='uint8')
        img.shape = (self.h, self.w, 4)

        dcObj.DeleteDC()
        cDC.DeleteDC()
        win32gui.ReleaseDC(self.hwnd, wDC)
        win32gui.DeleteObject(dataBitMap.GetHandle())

        img = img[...,:3]

        img = np.ascontiguousarray(img)

        return img

    def list_window_names(self):
        def winEnumHandler(hwnd, ctx):
            if win32gui.IsWindowVisible(hwnd):
                print(hex(hwnd), win32gui.GetWindowText(hwnd))
        win32gui.EnumWindows(winEnumHandler, None)

    def get_screen_position(self, pos):
        return (pos[0] + self.offset_x, pos[1] + self.offset_y)

wincap = WindowCapture("Window Name")
screen = wincap.get_screenshot()
cv2.imshow("", screen)
cv2.waitKey(0)
blackraven
  • 5,284
  • 7
  • 19
  • 45
CrotaL
  • 19
  • 5
  • But you are trying to cheat the cheat protection! Why should we give you any help? – fmw42 Oct 13 '22 at 22:21
  • The windows screenshot tool is not working including it this is now a "protection tool" other than the anti-cheating understanding that interferes with personal freedoms. – CrotaL Oct 13 '22 at 22:25
  • not an OpenCV issue. I've removed the tag. use tags responsibly. tags are a promise of relevancy to the people that watch those tags. – Christoph Rackwitz Oct 14 '22 at 10:00

0 Answers0