Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ChenYFan/a129519697ba32ce0260fb53b7271fed to your computer and use it in GitHub Desktop.
Save ChenYFan/a129519697ba32ce0260fb53b7271fed to your computer and use it in GitHub Desktop.
从SecretFlasherManaka游戏中获取振动器和活塞机状态并输出的脚本(郊狼待开发)
import win32gui
import win32ui
import win32con
import win32api
from ctypes import windll
import numpy as np
import cv2
import psutil
def GetHWNDbyProcessName(process_name):
target_hwnd = None
for proc in psutil.process_iter(['pid', 'name']):
if proc.info['name'].lower() == f"{process_name.lower()}.exe":
pid = proc.info['pid']
def enum_windows_callback(hwnd, hwnds):
if win32gui.IsWindowVisible(hwnd) and win32gui.GetWindowText(hwnd):
_, found_pid = win32process.GetWindowThreadProcessId(hwnd)
if found_pid == pid:
hwnds.append(hwnd)
return True
hwnds = []
win32gui.EnumWindows(enum_windows_callback, hwnds)
if hwnds:
target_hwnd = hwnds[0]
break
if not target_hwnd:
print(f"未找到进程 {process_name} 的窗口")
return None
return target_hwnd
def GetStatusFromSFM(target_hwnd):
try:
cleft, ctop, cright, cbottom = win32gui.GetClientRect(target_hwnd)
wleft, wtop, wright, wbottom = win32gui.GetWindowRect(target_hwnd)
width = wright - wleft
height = wbottom - wtop
offset = (width - (cright - cleft))//2
hwndDC = win32gui.GetWindowDC(target_hwnd)
mfcDC = win32ui.CreateDCFromHandle(hwndDC)
saveDC = mfcDC.CreateCompatibleDC()
saveBitMap = win32ui.CreateBitmap()
saveBitMap.CreateCompatibleBitmap(mfcDC, width, height)
saveDC.SelectObject(saveBitMap)
windll.user32.PrintWindow(target_hwnd, saveDC.GetSafeHdc(), 2)
bmpinfo = saveBitMap.GetInfo()
bmpstr = saveBitMap.GetBitmapBits(True)
img = np.frombuffer(bmpstr, dtype=np.uint8)
img = img.reshape((bmpinfo['bmHeight'], bmpinfo['bmWidth'], 4))
img = img[offset:-offset, offset:-offset, :]
img = cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
img_height, img_width = img.shape[:2]
pixel_values = (img[img_height-3:img_height, 0:9])[1]
def getStrength(RGB):
if RGB[2]>250:
return 3
elif RGB[1]>250:
return 2
elif RGB[0]>250:
return 1
else:
return 0
data = {
"vibrator": getStrenth(pixel_values[0]),
"piston": getStrenth(pixel_values[-1]),
}
win32gui.DeleteObject(saveBitMap.GetHandle())
saveDC.DeleteDC()
mfcDC.DeleteDC()
win32gui.ReleaseDC(target_hwnd, hwndDC)
return data
except Exception as e:
print(f"截图失败: {e}")
return None
if __name__ == "__main__":
import win32process
import time
process_name = "SecretFlasherManaka"
while True:
data=GetStatusFromSFM(GetHWNDbyProcessName(process_name))
print(data)
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment