Fix background Unity input and shop boundaries; record login failure
This commit is contained in:
+73
-5
@@ -79,6 +79,19 @@ class AalcEngine(Engine):
|
|||||||
self.images_root = os.path.join(root, 'assets', 'images')
|
self.images_root = os.path.join(root, 'assets', 'images')
|
||||||
|
|
||||||
# ---- 看 ----
|
# ---- 看 ----
|
||||||
|
def show_game_background(self):
|
||||||
|
if self.cfg.simulator:
|
||||||
|
raise RuntimeError('后台恢复窗口仅支持 Windows 游戏客户端')
|
||||||
|
hwnd = self.screen.handle.hwnd
|
||||||
|
if not hwnd:
|
||||||
|
raise RuntimeError('未找到游戏窗口,未修改其他窗口')
|
||||||
|
import win32con
|
||||||
|
import win32gui
|
||||||
|
foreground = win32gui.GetForegroundWindow()
|
||||||
|
win32gui.ShowWindow(hwnd, win32con.SW_SHOWNOACTIVATE)
|
||||||
|
return {'visible': bool(win32gui.IsWindowVisible(hwnd)),
|
||||||
|
'foreground_changed': win32gui.GetForegroundWindow() != foreground}
|
||||||
|
|
||||||
def _grab(self, gray):
|
def _grab(self, gray):
|
||||||
if not self.cfg.simulator and not self.screen.handle.hwnd:
|
if not self.cfg.simulator and not self.screen.handle.hwnd:
|
||||||
raise RuntimeError('未找到游戏窗口 %r: 先启动游戏(run_task 会自动启动)' % self.cfg.game_title_name)
|
raise RuntimeError('未找到游戏窗口 %r: 先启动游戏(run_task 会自动启动)' % self.cfg.game_title_name)
|
||||||
@@ -198,19 +211,45 @@ class AalcEngine(Engine):
|
|||||||
if not handle.isActive:
|
if not handle.isActive:
|
||||||
raise RuntimeError('无法激活游戏窗口,未发送输入')
|
raise RuntimeError('无法激活游戏窗口,未发送输入')
|
||||||
|
|
||||||
|
def _background_mouse(self, message, x, y, held=False):
|
||||||
|
"""Deliver client coordinates without moving the user's system pointer."""
|
||||||
|
import win32api
|
||||||
|
import win32con
|
||||||
|
hwnd = self.screen.handle.hwnd
|
||||||
|
if not hwnd:
|
||||||
|
raise RuntimeError('未找到游戏窗口,未发送鼠标消息')
|
||||||
|
win32api.PostMessage(hwnd, message, win32con.MK_LBUTTON if held else 0,
|
||||||
|
win32api.MAKELONG(int(x), int(y)))
|
||||||
|
|
||||||
|
def _restore_background_position(self, position):
|
||||||
|
import win32con
|
||||||
|
import win32gui
|
||||||
|
win32gui.SetWindowPos(self.screen.handle.hwnd, 0, *position, 0, 0,
|
||||||
|
win32con.SWP_NOSIZE | win32con.SWP_NOZORDER |
|
||||||
|
win32con.SWP_NOACTIVATE)
|
||||||
|
|
||||||
def click(self, x, y, times=1):
|
def click(self, x, y, times=1):
|
||||||
self._prepare_input()
|
self._prepare_input()
|
||||||
if not self.cfg.simulator and self.cfg.win_input_type == 'background':
|
if not self.cfg.simulator and self.cfg.win_input_type in ('background', 'window_move'):
|
||||||
|
import win32con
|
||||||
handler = self.auto.input_handler
|
handler = self.auto.input_handler
|
||||||
self.auto.wait_pause()
|
self.auto.wait_pause()
|
||||||
for _ in range(int(times)):
|
for _ in range(int(times)):
|
||||||
handler.set_mouse_pos(int(x), int(y))
|
position = None
|
||||||
|
if self.cfg.win_input_type == 'window_move':
|
||||||
|
self.screen.handle.set_window_transparent(True)
|
||||||
|
position = handler._set_window_pos(int(x), int(y))
|
||||||
handler.set_active()
|
handler.set_active()
|
||||||
handler.mouse_down(int(x), int(y))
|
self._background_mouse(win32con.WM_MOUSEMOVE, x, y)
|
||||||
|
time.sleep(0.12)
|
||||||
|
self._background_mouse(win32con.WM_LBUTTONDOWN, x, y, held=True)
|
||||||
try:
|
try:
|
||||||
time.sleep(0.12)
|
time.sleep(0.12)
|
||||||
finally:
|
finally:
|
||||||
handler.mouse_up(int(x), int(y))
|
self._background_mouse(win32con.WM_LBUTTONUP, x, y)
|
||||||
|
if position is not None:
|
||||||
|
time.sleep(0.12)
|
||||||
|
self._restore_background_position(position)
|
||||||
# Let Unity consume the release before another target is selected.
|
# Let Unity consume the release before another target is selected.
|
||||||
time.sleep(0.12)
|
time.sleep(0.12)
|
||||||
elif not self.cfg.simulator and self.cfg.win_input_type == 'foreground':
|
elif not self.cfg.simulator and self.cfg.win_input_type == 'foreground':
|
||||||
@@ -236,7 +275,7 @@ class AalcEngine(Engine):
|
|||||||
if k not in self.key_names:
|
if k not in self.key_names:
|
||||||
raise ValueError('AALC 不支持按键 %r, 可用: %s' % (key, ' '.join(self.key_names)))
|
raise ValueError('AALC 不支持按键 %r, 可用: %s' % (key, ' '.join(self.key_names)))
|
||||||
self._prepare_input()
|
self._prepare_input()
|
||||||
if not self.cfg.simulator and self.cfg.win_input_type == 'background':
|
if not self.cfg.simulator and self.cfg.win_input_type in ('background', 'window_move'):
|
||||||
# Unity 可能在同一帧收到 down/up,导致快捷键被吞掉。
|
# Unity 可能在同一帧收到 down/up,导致快捷键被吞掉。
|
||||||
handler = self.auto.input_handler
|
handler = self.auto.input_handler
|
||||||
self.auto.wait_pause()
|
self.auto.wait_pause()
|
||||||
@@ -262,6 +301,35 @@ class AalcEngine(Engine):
|
|||||||
if not (0 <= x < img.width and 0 <= y < img.height):
|
if not (0 <= x < img.width and 0 <= y < img.height):
|
||||||
raise ValueError('拖动坐标超出游戏客户区 %sx%s' % (img.width, img.height))
|
raise ValueError('拖动坐标超出游戏客户区 %sx%s' % (img.width, img.height))
|
||||||
self._prepare_input()
|
self._prepare_input()
|
||||||
|
if not self.cfg.simulator and self.cfg.win_input_type in ('background', 'window_move'):
|
||||||
|
import win32con
|
||||||
|
self.auto.wait_pause()
|
||||||
|
position = None
|
||||||
|
if self.cfg.win_input_type == 'window_move':
|
||||||
|
self.screen.handle.set_window_transparent(True)
|
||||||
|
position = self.auto.input_handler._set_window_pos(int(from_x), int(from_y))
|
||||||
|
self.auto.input_handler.set_active()
|
||||||
|
self._background_mouse(win32con.WM_MOUSEMOVE, from_x, from_y)
|
||||||
|
time.sleep(0.12)
|
||||||
|
self._background_mouse(win32con.WM_LBUTTONDOWN, from_x, from_y, held=True)
|
||||||
|
last_x, last_y = from_x, from_y
|
||||||
|
try:
|
||||||
|
time.sleep(0.12)
|
||||||
|
steps = max(1, int(float(duration) / 0.02))
|
||||||
|
for step in range(1, steps + 1):
|
||||||
|
last_x = round(from_x + (to_x - from_x) * step / steps)
|
||||||
|
last_y = round(from_y + (to_y - from_y) * step / steps)
|
||||||
|
if position is not None:
|
||||||
|
self.auto.input_handler._set_window_pos(last_x, last_y)
|
||||||
|
self._background_mouse(win32con.WM_MOUSEMOVE, last_x, last_y, held=True)
|
||||||
|
time.sleep(float(duration) / steps)
|
||||||
|
time.sleep(0.12)
|
||||||
|
finally:
|
||||||
|
self._background_mouse(win32con.WM_LBUTTONUP, last_x, last_y)
|
||||||
|
if position is not None:
|
||||||
|
time.sleep(0.12)
|
||||||
|
self._restore_background_position(position)
|
||||||
|
return
|
||||||
if not self.cfg.simulator and self.cfg.win_input_type == 'foreground':
|
if not self.cfg.simulator and self.cfg.win_input_type == 'foreground':
|
||||||
import pyautogui
|
import pyautogui
|
||||||
start = self.auto.input_handler.pos_offset(int(from_x), int(from_y))
|
start = self.auto.input_handler.pos_offset(int(from_x), int(from_y))
|
||||||
|
|||||||
Reference in New Issue
Block a user