From 203717212052e17e004f8cc3ceabb4844dc33666 Mon Sep 17 00:00:00 2001 From: weinibuliu Date: Mon, 1 Dec 2025 12:35:42 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E5=85=81=E8=AE=B8=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=87=E4=BB=B6=E4=BD=9C=E4=B8=BA=E5=BE=85=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaDebugger/maafw/__init__.py | 47 +++++++++++++++++-- .../webpage/index_page/master_control.py | 21 +++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/MaaDebugger/maafw/__init__.py b/src/MaaDebugger/maafw/__init__.py index 77e0cec..bb32664 100644 --- a/src/MaaDebugger/maafw/__init__.py +++ b/src/MaaDebugger/maafw/__init__.py @@ -1,10 +1,11 @@ import re +import io from pathlib import Path from typing import Callable, List, Optional, Tuple, Union from asyncify import asyncify from PIL import Image -from maa.controller import AdbController, Win32Controller +from maa.controller import AdbController, Win32Controller, CustomController from maa.context import Context, ContextEventSink from maa.tasker import Tasker, RecognitionDetail from maa.resource import Resource, ResourceEventSink @@ -12,14 +13,32 @@ from maa.agent_client import AgentClient from maa.library import Library from maa.event_sink import NotificationType +import numpy as np from ..utils import cvmat_to_image +class MyCustomController(CustomController): + def __init__(self, img_bytes: bytes): + super().__init__() + + img = Image.open(io.BytesIO(img_bytes)) + self.ndarray = np.array(img) + + def connect(self) -> bool: + return True + + def request_uuid(self) -> str: + return "0" + + def screencap(self) -> np.ndarray: + return self.ndarray + + class MaaFW: resource: Optional[Resource] - controller: Union[AdbController, Win32Controller, None] + controller: Union[AdbController, Win32Controller, CustomController, None] tasker: Optional[Tasker] agent: Optional[AgentClient] context_event_sink: Optional[ContextEventSink] @@ -89,6 +108,12 @@ def connect_win32hwnd( return True, None + def connect_custom_controller(self, img_bytes) -> Tuple[bool, Optional[str]]: + self.controller = MyCustomController(img_bytes) + self.controller.post_connection().wait() + + return True, None + @asyncify def load_resource(self, dir: List[Path]) -> Tuple[bool, Optional[str]]: if not self.resource: @@ -149,7 +174,20 @@ def run_task( if not AgentClient().register_sink(self.resource, self.controller, self.tasker): return False, "Failed to register Agent sink." - return self.tasker.post_task(entry, pipeline_override).wait().succeeded, None + if isinstance(self.controller, CustomController): + # disable action + pipeline_override.update( + {entry: {"action": {"type": "DoNothing"}, "next": []}} + ) + return ( + self.tasker.post_task(entry, pipeline_override).wait().succeeded, + None, + ) + else: + return ( + self.tasker.post_task(entry, pipeline_override).wait().succeeded, + None, + ) @asyncify def stop_task(self) -> None: @@ -176,6 +214,9 @@ def click(self, x, y) -> bool: if not self.controller: return False + if isinstance(self.controller, CustomController): + return False + return self.controller.post_click(x, y).wait().succeeded @asyncify diff --git a/src/MaaDebugger/webpage/index_page/master_control.py b/src/MaaDebugger/webpage/index_page/master_control.py index 0dcfb3f..f6dde93 100644 --- a/src/MaaDebugger/webpage/index_page/master_control.py +++ b/src/MaaDebugger/webpage/index_page/master_control.py @@ -39,6 +39,7 @@ def connect_control(): with ui.tabs() as tabs: adb = ui.tab("Adb") win32 = ui.tab("Win32") + custom = ui.tab("Custom") tab_panels = ui.tab_panels(tabs, value="Adb").bind_value(STORAGE, "controller_type") with tab_panels: @@ -49,6 +50,10 @@ def connect_control(): with ui.row(align_items="center").classes("w-full"): connect_win32_control() + with ui.tab_panel(custom): + with ui.row(align_items="center").classes("w-full"): + connect_custom_control() + os_type = system.get_os_type() if os_type != system.OSTypeEnum.Windows: win32.disable() @@ -301,6 +306,22 @@ def on_change_hwnd_select(value: Optional[str]): hwnd_input.value = value +def connect_custom_control(): + def on_upload(e): + GlobalStatus.ctrl_connecting = Status.RUNNING + try: + maafw.connect_custom_controller(e.content.read()) + except: + GlobalStatus.ctrl_connecting = Status.FAILED + ui.notify("Failed to load image.", position="bottom-right", type="negative") + return + + GlobalStatus.ctrl_connecting = Status.SUCCEEDED + + StatusIndicator(GlobalStatus, "ctrl_connecting") + ui.upload(auto_upload=True, on_upload=lambda e: on_upload(e)) + + def screenshot_control(): with ( ui.row() From d5633d5a2663a79e27410d8eb52c5c54666da9c5 Mon Sep 17 00:00:00 2001 From: weinibuliu Date: Mon, 1 Dec 2025 13:26:14 +0800 Subject: [PATCH 2/5] fix: RGB -> RBG --- src/MaaDebugger/maafw/__init__.py | 10 ++++++++-- src/MaaDebugger/utils/{__init__.py => img_tools.py} | 0 src/MaaDebugger/webpage/reco_page/__init__.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) rename src/MaaDebugger/utils/{__init__.py => img_tools.py} (100%) diff --git a/src/MaaDebugger/maafw/__init__.py b/src/MaaDebugger/maafw/__init__.py index bb32664..9f49cef 100644 --- a/src/MaaDebugger/maafw/__init__.py +++ b/src/MaaDebugger/maafw/__init__.py @@ -15,7 +15,7 @@ from maa.event_sink import NotificationType import numpy as np -from ..utils import cvmat_to_image +from ..utils.img_tools import cvmat_to_image class MyCustomController(CustomController): @@ -23,7 +23,13 @@ def __init__(self, img_bytes: bytes): super().__init__() img = Image.open(io.BytesIO(img_bytes)) - self.ndarray = np.array(img) + arr = np.array(img) + + # RGB -> BGR 转换 + if arr.ndim == 3 and arr.shape[2] >= 3: + self.ndarray = arr[:, :, ::-1].copy() + else: + self.ndarray = arr def connect(self) -> bool: return True diff --git a/src/MaaDebugger/utils/__init__.py b/src/MaaDebugger/utils/img_tools.py similarity index 100% rename from src/MaaDebugger/utils/__init__.py rename to src/MaaDebugger/utils/img_tools.py diff --git a/src/MaaDebugger/webpage/reco_page/__init__.py b/src/MaaDebugger/webpage/reco_page/__init__.py index 3645be8..4c58875 100644 --- a/src/MaaDebugger/webpage/reco_page/__init__.py +++ b/src/MaaDebugger/webpage/reco_page/__init__.py @@ -2,7 +2,7 @@ from nicegui import ui -from ...utils import cvmat_to_image +from ...utils.img_tools import cvmat_to_image from ...maafw import maafw, RecognitionDetail From 088146975e80b2114a58cc4ce5b03f6ac72f70a2 Mon Sep 17 00:00:00 2001 From: weinibuliu Date: Tue, 2 Dec 2025 14:05:05 +0800 Subject: [PATCH 3/5] =?UTF-8?q?rft:=20=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaDebugger/maafw/__init__.py | 10 ++-------- src/MaaDebugger/utils/img_tools.py | 8 ++++++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/MaaDebugger/maafw/__init__.py b/src/MaaDebugger/maafw/__init__.py index 9f49cef..fa3f523 100644 --- a/src/MaaDebugger/maafw/__init__.py +++ b/src/MaaDebugger/maafw/__init__.py @@ -15,7 +15,7 @@ from maa.event_sink import NotificationType import numpy as np -from ..utils.img_tools import cvmat_to_image +from ..utils.img_tools import cvmat_to_image, rgb_to_rbg class MyCustomController(CustomController): @@ -23,13 +23,7 @@ def __init__(self, img_bytes: bytes): super().__init__() img = Image.open(io.BytesIO(img_bytes)) - arr = np.array(img) - - # RGB -> BGR 转换 - if arr.ndim == 3 and arr.shape[2] >= 3: - self.ndarray = arr[:, :, ::-1].copy() - else: - self.ndarray = arr + self.ndarray = rgb_to_rbg(np.array(img)) def connect(self) -> bool: return True diff --git a/src/MaaDebugger/utils/img_tools.py b/src/MaaDebugger/utils/img_tools.py index 4ff55bf..9db7433 100644 --- a/src/MaaDebugger/utils/img_tools.py +++ b/src/MaaDebugger/utils/img_tools.py @@ -6,3 +6,11 @@ def cvmat_to_image(cvmat: ndarray) -> Image.Image: pil = Image.fromarray(cvmat) b, g, r = pil.split() return Image.merge("RGB", (r, g, b)) + + +def rgb_to_rbg(arr: ndarray) -> ndarray: + """RGB -> BGR 转换""" + if arr.ndim == 3 and arr.shape[2] >= 3: + return arr[:, :, ::-1].copy() + else: + return arr From 5fcb88ffd8f0b7a578ffaae2b0a88ac4b23f6cdf Mon Sep 17 00:00:00 2001 From: weinibuliu Date: Tue, 2 Dec 2025 14:06:06 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=E5=87=BD=E6=95=B0=E5=90=8D=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaDebugger/maafw/__init__.py | 4 ++-- src/MaaDebugger/utils/img_tools.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MaaDebugger/maafw/__init__.py b/src/MaaDebugger/maafw/__init__.py index fa3f523..1ad4cd7 100644 --- a/src/MaaDebugger/maafw/__init__.py +++ b/src/MaaDebugger/maafw/__init__.py @@ -15,7 +15,7 @@ from maa.event_sink import NotificationType import numpy as np -from ..utils.img_tools import cvmat_to_image, rgb_to_rbg +from ..utils.img_tools import cvmat_to_image, rgb_to_bgr class MyCustomController(CustomController): @@ -23,7 +23,7 @@ def __init__(self, img_bytes: bytes): super().__init__() img = Image.open(io.BytesIO(img_bytes)) - self.ndarray = rgb_to_rbg(np.array(img)) + self.ndarray = rgb_to_bgr(np.array(img)) def connect(self) -> bool: return True diff --git a/src/MaaDebugger/utils/img_tools.py b/src/MaaDebugger/utils/img_tools.py index 9db7433..5d237dd 100644 --- a/src/MaaDebugger/utils/img_tools.py +++ b/src/MaaDebugger/utils/img_tools.py @@ -8,7 +8,7 @@ def cvmat_to_image(cvmat: ndarray) -> Image.Image: return Image.merge("RGB", (r, g, b)) -def rgb_to_rbg(arr: ndarray) -> ndarray: +def rgb_to_bgr(arr: ndarray) -> ndarray: """RGB -> BGR 转换""" if arr.ndim == 3 and arr.shape[2] >= 3: return arr[:, :, ::-1].copy() From 30a77ecf549731a7c775c7529a14643cb91add0c Mon Sep 17 00:00:00 2001 From: weinibuliu Date: Thu, 4 Dec 2025 19:59:57 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaDebugger/webpage/index_page/master_control.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/MaaDebugger/webpage/index_page/master_control.py b/src/MaaDebugger/webpage/index_page/master_control.py index f6dde93..ce7ef15 100644 --- a/src/MaaDebugger/webpage/index_page/master_control.py +++ b/src/MaaDebugger/webpage/index_page/master_control.py @@ -311,9 +311,11 @@ def on_upload(e): GlobalStatus.ctrl_connecting = Status.RUNNING try: maafw.connect_custom_controller(e.content.read()) - except: + except Exception as e: GlobalStatus.ctrl_connecting = Status.FAILED - ui.notify("Failed to load image.", position="bottom-right", type="negative") + ui.notify( + f"Failed to load image. {e}", position="bottom-right", type="negative" + ) return GlobalStatus.ctrl_connecting = Status.SUCCEEDED