├── sample ├── resource │ ├── image │ │ └── .gitkeep │ └── pipeline │ │ ├── custom_demo.json │ │ ├── sample.json │ │ └── common.json ├── python │ └── requirements.txt ├── csharp │ ├── README.md │ ├── .config │ │ └── dotnet-tools.json │ ├── QuickStart.ps1 │ ├── QuickStart.sh │ ├── 2.pi_cli.csx │ └── 3.AgentChild.csx ├── cpp │ ├── modules │ │ ├── main.cpp │ │ └── CMakeLists.txt │ ├── CMakeLists.txt │ └── MaaAgent │ │ └── CMakeLists.txt ├── interface_zh.json ├── interface_en.json └── nodejs │ └── server.ts ├── tools ├── ImageCropper │ ├── dst │ │ └── .gitkeep │ ├── src │ │ └── .gitkeep │ ├── .gitignore │ ├── requirements.txt │ ├── install.bat │ ├── start.bat │ ├── README.md │ └── roimage.py ├── Doxygen │ └── CNAME ├── pip_pack │ ├── .gitignore │ ├── requirements.txt │ └── pyproject.toml ├── nupkgs │ ├── Tail.nuspec │ ├── Maa.Framework.Runtime.osx-x64.nuspec │ ├── Maa.Framework.Runtime.win-x64.nuspec │ ├── Maa.Framework.Runtime.linux-x64.nuspec │ ├── Maa.Framework.Runtime.win-arm64.nuspec │ ├── Maa.Framework.Runtime.osx-arm64.nuspec │ ├── Maa.Framework.Runtime.android-x64.nuspec │ ├── Maa.Framework.Runtime.linux-arm64.nuspec │ ├── Maa.Framework.Runtime.android-arm64.nuspec │ ├── Maa.Framework.Runtimes.nuspec │ ├── Head.nuspec │ └── pack.sh ├── custom.action.schema.json ├── custom.recognition.schema.json ├── maadeps-download.py ├── collect-mac-debug.sh ├── NodeTest │ └── CMakeLists.txt ├── CMakeLists.txt └── split-linux-debug.sh ├── source ├── binding │ ├── NodeJS │ │ ├── release │ │ │ ├── maa-node │ │ │ │ ├── agent │ │ │ │ │ └── .gitkeep │ │ │ │ ├── .npmignore │ │ │ │ ├── package.json │ │ │ │ └── src │ │ │ │ │ ├── index-client.js │ │ │ │ │ └── index-server.js │ │ │ ├── maa-node-linux-x64 │ │ │ │ └── package.json │ │ │ ├── maa-node-win32-x64 │ │ │ │ └── package.json │ │ │ ├── maa-node-darwin-x64 │ │ │ │ └── package.json │ │ │ ├── maa-node-linux-arm64 │ │ │ │ └── package.json │ │ │ ├── maa-node-win32-arm64 │ │ │ │ └── package.json │ │ │ └── maa-node-darwin-arm64 │ │ │ │ └── package.json │ │ ├── tsconfig.json │ │ ├── src │ │ │ ├── utils │ │ │ │ └── library.h │ │ │ ├── tsconfig.json │ │ │ ├── foundation │ │ │ │ ├── spec │ │ │ │ │ ├── async.h │ │ │ │ │ ├── class.h │ │ │ │ │ ├── callback.h │ │ │ │ │ ├── quickjs │ │ │ │ │ │ └── types.h │ │ │ │ │ ├── nodejs │ │ │ │ │ │ ├── types.h │ │ │ │ │ │ └── async.h │ │ │ │ │ ├── types.h │ │ │ │ │ ├── instric.h │ │ │ │ │ └── tools.h │ │ │ │ └── spec.h │ │ │ ├── sys.d.ts │ │ │ ├── apis │ │ │ │ ├── index-client.d.ts │ │ │ │ ├── index-server.d.ts │ │ │ │ ├── plugin.d.ts │ │ │ │ ├── global.d.ts │ │ │ │ ├── client.d.ts │ │ │ │ ├── convert.h │ │ │ │ ├── job.h │ │ │ │ ├── job.d.ts │ │ │ │ ├── server.d.ts │ │ │ │ ├── loader.h │ │ │ │ ├── client.h │ │ │ │ └── context.d.ts │ │ │ └── plugin │ │ │ │ └── runtime.h │ │ ├── README.md │ │ ├── .prettierrc │ │ ├── .gitignore │ │ └── package.json │ ├── .editorconfig │ ├── Python │ │ ├── README.md │ │ ├── maa │ │ │ ├── __init__.py │ │ │ └── agent │ │ │ │ └── __init__.py │ │ └── pyproject.toml │ └── CMakeLists.txt ├── MaaWin32ControlUnit │ ├── Screencap │ │ ├── SafeDXGI.hpp │ │ ├── GdiScreencap.h │ │ ├── ScreenDCScreencap.h │ │ ├── PrintWindowScreencap.h │ │ ├── DesktopDupWindowScreencap.h │ │ └── DesktopDupScreencap.h │ ├── API │ │ └── Win32ControlUnitAPI.cpp │ ├── CMakeLists.txt │ ├── Base │ │ └── UnitBase.h │ └── Input │ │ ├── LegacyEventInput.h │ │ ├── PostThreadMessageInput.h │ │ └── SeizeInput.h ├── MaaToolkit │ ├── AdbDevice │ │ ├── AdbDeviceLinuxFinder.cpp │ │ ├── AdbDeviceLinuxFinder.h │ │ ├── AdbDeviceMacOSFinder.h │ │ ├── AdbDeviceWin32Finder.h │ │ └── AdbDeviceMacOSFinder.cpp │ ├── DesktopWindow │ │ ├── DesktopWindowLinuxFinder.cpp │ │ ├── DesktopWindowMacOSFinder.cpp │ │ ├── DesktopWindowFinder.h │ │ ├── DesktopWindowLinuxFinder.h │ │ ├── DesktopWindowMacOSFinder.h │ │ ├── DesktopWindowWin32Finder.h │ │ ├── DesktopWindowWin32Finder.cpp │ │ └── DesktopWindowBuffer.hpp │ ├── API │ │ ├── MaaToolkitBufferTypes.hpp │ │ └── MaaToolkitConfig.cpp │ ├── CMakeLists.txt │ └── Config │ │ └── GlobalOptionConfig.h ├── Common │ └── MaaUtility.cpp ├── include │ ├── ProjectInterface │ │ ├── Runner.h │ │ ├── Parser.h │ │ └── Configurator.h │ ├── ControlUnit │ │ ├── PlayCoverControlUnitAPI.h │ │ ├── DbgControlUnitAPI.h │ │ ├── CustomControlUnitAPI.h │ │ ├── Win32ControlUnitAPI.h │ │ └── AdbControlUnitAPI.h │ ├── LibraryHolder │ │ └── AgentClient.h │ └── Common │ │ └── TaskResultTypes.h ├── MaaDbgControlUnit │ ├── ReplayRecording │ │ ├── ReplayRecordingMgr.h │ │ ├── ReplayRecordingMgr.cpp │ │ ├── RecordParser.h │ │ └── ReplayRecording.h │ ├── CMakeLists.txt │ └── API │ │ └── DbgControlUnitAPI.cpp ├── MaaFramework │ ├── Resource │ │ ├── PipelineDumper.h │ │ ├── MLProvider.h │ │ ├── PipelineChecker.h │ │ ├── TemplateResMgr.h │ │ └── ONNXResMgr.h │ ├── Task │ │ ├── EmptyTask.h │ │ ├── RecognitionTask.h │ │ ├── Component │ │ │ ├── CustomAction.h │ │ │ ├── CustomRecognition.h │ │ │ ├── CustomAction.cpp │ │ │ └── CommandAction.h │ │ ├── ActionTask.h │ │ └── PipelineTask.h │ ├── Vision │ │ ├── TemplateComparator.h │ │ ├── ColorMatcher.h │ │ ├── TemplateMatcher.h │ │ ├── NeuralNetworkClassifier.h │ │ └── NeuralNetworkDetector.h │ └── Global │ │ └── PluginMgr.h ├── modules │ ├── MaaAgentServer.cppm │ ├── MaaAgentClient.cppm │ └── CMakeLists.txt ├── MaaAdbControlUnit │ ├── Screencap │ │ ├── Minicap │ │ │ ├── MinicapDirect.h │ │ │ ├── MinicapDef.h │ │ │ ├── MinicapDirect.cpp │ │ │ ├── MinicapStream.h │ │ │ └── MinicapBase.h │ │ ├── Encode.h │ │ ├── RawWithGzip.h │ │ ├── EncodeToFile.h │ │ ├── Encode.cpp │ │ ├── RawWithGzip.cpp │ │ ├── RawByNetcat.h │ │ └── ScreencapHelper.h │ ├── General │ │ ├── DeviceList.h │ │ ├── AdbCommand.h │ │ ├── Activity.h │ │ ├── DeviceInfo.h │ │ ├── Connection.h │ │ ├── AdbCommand.cpp │ │ └── DeviceList.cpp │ ├── Base │ │ ├── ProcessArgvGenerator.h │ │ └── ProcessArgvGenerator.cpp │ ├── CMakeLists.txt │ ├── Invoke │ │ └── InvokeApp.h │ ├── Input │ │ └── AdbShellInput.h │ ├── Manager │ │ └── ScreencapAgent.h │ └── EmulatorExtras │ │ └── LDPlayerExtras.h ├── CMakeLists.txt ├── MaaPiCli │ └── CMakeLists.txt ├── MaaPlayCoverControlUnit │ ├── CMakeLists.txt │ ├── API │ │ └── PlayCoverControlUnitAPI.cpp │ └── Client │ │ └── PlayToolsClient.h ├── MaaCustomControlUnit │ ├── API │ │ └── CustomControlUnitAPI.cpp │ └── CMakeLists.txt ├── LibraryHolder │ ├── CMakeLists.txt │ └── AgentClient │ │ └── AgentClient.cpp └── MaaAgentClient │ └── CMakeLists.txt ├── test ├── nodejs │ ├── inject-client.js │ ├── empty.png │ ├── inject-server.js │ ├── maa-client.ts │ ├── tsconfig.json │ ├── .prettierrc │ ├── package.json │ ├── maa-server.ts │ ├── server.ts │ └── recording │ │ ├── maa_recording_2024.11.24-16.12.43.8029970.txt │ │ └── maa_recording_2024.11.24-16.13.21.8133449.txt ├── pipeline │ ├── module │ │ ├── PipelineSmoking.h │ │ ├── RunWithoutFile.h │ │ └── PipelineSmoking.cpp │ ├── CMakeLists.txt │ └── main.cpp ├── win32_test │ ├── CMakeLists.txt │ └── dpi_test.exe.manifest └── dlopen │ └── CMakeLists.txt ├── 3rdparty ├── include │ ├── gzip │ │ ├── config.hpp │ │ ├── version.hpp │ │ └── utils.hpp │ └── MaaPlugin │ │ ├── MaaPluginAPI.h │ │ └── MaaPluginPort.h └── CMakeLists.txt ├── .cursorignore ├── include ├── MaaAgentServer │ ├── MaaAgentServerDef.h │ └── MaaAgentServerAPI.h ├── MaaAgentClient │ └── MaaAgentClientDef.h ├── MaaToolkit │ ├── MaaToolkitAPI.h │ ├── MaaToolkitDef.h │ ├── Config │ │ └── MaaToolkitConfig.h │ ├── DesktopWindow │ │ └── MaaToolkitDesktopWindow.h │ └── AdbDevice │ │ └── MaaToolkitAdbDevice.h └── MaaFramework │ ├── Utility │ └── MaaUtility.h │ ├── MaaAPI.h │ └── Global │ └── MaaGlobal.h ├── Config.cmake.in ├── .devcontainer ├── devcontainer.json ├── ninja-build.sh ├── Dockerfile ├── gcc-13_and_g++-13.sh └── cmake.sh ├── .editorconfig ├── docs ├── zh_cn │ ├── 3.2-ProjectInterface协议.md │ ├── NodeJS │ │ └── J1.3-打包.md │ ├── 1.2-术语解释.md │ └── 4.1-构建指南.md └── en_us │ ├── 3.2-ProjectInterface.md │ └── NodeJS │ └── J1.3-Packaging.md ├── .vscode ├── tasks.json └── launch.json ├── .github └── workflows │ ├── deploy-website.yml │ ├── mirrorchyan_release_note.yml │ ├── mirrorchyan.yml │ ├── format.yml │ └── deploy-manual.yml └── .gitmodules /sample/resource/image/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/ImageCropper/dst/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/ImageCropper/src/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/Doxygen/CNAME: -------------------------------------------------------------------------------- 1 | man.maafw.xyz 2 | -------------------------------------------------------------------------------- /sample/python/requirements.txt: -------------------------------------------------------------------------------- 1 | maafw 2 | -------------------------------------------------------------------------------- /tools/pip_pack/.gitignore: -------------------------------------------------------------------------------- 1 | .venv/ 2 | *.lock 3 | -------------------------------------------------------------------------------- /source/binding/NodeJS/release/maa-node/agent/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/pip_pack/requirements.txt: -------------------------------------------------------------------------------- 1 | tomlkit 2 | build 3 | wheel -------------------------------------------------------------------------------- /source/binding/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.py] 2 | 3 | end_of_line = lf -------------------------------------------------------------------------------- /tools/ImageCropper/.gitignore: -------------------------------------------------------------------------------- 1 | venv/ 2 | dst/ 3 | src/ 4 | !.gitkeep 5 | -------------------------------------------------------------------------------- /tools/ImageCropper/requirements.txt: -------------------------------------------------------------------------------- 1 | MaaFw~=4.0 2 | opencv_python~=4.10 3 | -------------------------------------------------------------------------------- /test/nodejs/inject-client.js: -------------------------------------------------------------------------------- 1 | globalThis.maa = require('../../install/bin/MaaNode.node') 2 | -------------------------------------------------------------------------------- /test/nodejs/empty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaaXYZ/MaaFramework/HEAD/test/nodejs/empty.png -------------------------------------------------------------------------------- /test/nodejs/inject-server.js: -------------------------------------------------------------------------------- 1 | globalThis.maa = require('../../install/bin/MaaNodeServer.node') 2 | -------------------------------------------------------------------------------- /sample/csharp/README.md: -------------------------------------------------------------------------------- 1 | Link: https://github.com/MaaXYZ/MaaFramework.Binding.CSharp/tree/main/sample -------------------------------------------------------------------------------- /3rdparty/include/gzip/config.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef ZLIB_CONST 4 | #define ZLIB_CONST 5 | #endif 6 | -------------------------------------------------------------------------------- /.cursorignore: -------------------------------------------------------------------------------- 1 | build/ 2 | install/ 3 | 3rdparty/quickjs/ 4 | source/MaaUtils/MaaDeps/vcpkg/ 5 | test/TestingDataSet/ 6 | -------------------------------------------------------------------------------- /include/MaaAgentServer/MaaAgentServerDef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MaaFramework/MaaDef.h" // IWYU pragma: export 4 | -------------------------------------------------------------------------------- /source/binding/Python/README.md: -------------------------------------------------------------------------------- 1 | # MaaFW Python binding 2 | 3 | ## Install 4 | 5 | ```bash 6 | python -m pip install maafw 7 | ``` 8 | -------------------------------------------------------------------------------- /source/binding/NodeJS/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@tsconfig/node20/tsconfig.json", 3 | "include": ["scripts/**/*.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /test/nodejs/maa-client.ts: -------------------------------------------------------------------------------- 1 | import './inject-client' 2 | 3 | export * from '../../source/binding/NodeJS/release/maa-node/dist/index-client' 4 | -------------------------------------------------------------------------------- /Config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/MaaFramework.cmake") 4 | 5 | check_required_components(MaaFramework) 6 | -------------------------------------------------------------------------------- /tools/ImageCropper/install.bat: -------------------------------------------------------------------------------- 1 | python -m venv venv 2 | call venv\Scripts\activate.bat 3 | python -m pip install -r requirements.txt 4 | pause 5 | -------------------------------------------------------------------------------- /tools/ImageCropper/start.bat: -------------------------------------------------------------------------------- 1 | IF EXIST "venv\Scripts\activate.bat" ( 2 | call venv\Scripts\activate.bat 3 | ) 4 | python main.py 5 | pause 6 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MaaFramework-Ubuntu22.04", 3 | "build": { 4 | "dockerfile": "Dockerfile" 5 | } 6 | } -------------------------------------------------------------------------------- /source/binding/NodeJS/src/utils/library.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | std::filesystem::path get_library_path(void* addr); 6 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": [] 4 | }, 5 | "include": ["**/*.d.ts", "*.mts"] 6 | } 7 | -------------------------------------------------------------------------------- /test/nodejs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@tsconfig/node20/tsconfig.json", 3 | "include": ["*.ts", "inject-server.js", "inject-client.js"] 4 | } 5 | -------------------------------------------------------------------------------- /tools/nupkgs/Tail.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | insert_final_newline = true 6 | charset = utf-8 7 | end_of_line = lf 8 | indent_size = 4 9 | -------------------------------------------------------------------------------- /source/binding/NodeJS/release/maa-node/.npmignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | *.md 3 | LICENSE 4 | .gitkeep 5 | /src 6 | /scripts 7 | /tsconfig.json 8 | /pnpm-lock.yaml 9 | -------------------------------------------------------------------------------- /test/nodejs/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true, 4 | "trailingComma": "none", 5 | "arrowParens": "avoid", 6 | "printWidth": 100 7 | } -------------------------------------------------------------------------------- /test/pipeline/module/PipelineSmoking.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | bool pipeline_smoking(const std::filesystem::path& testset_dir); 6 | -------------------------------------------------------------------------------- /test/pipeline/module/RunWithoutFile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | bool run_without_file(const std::filesystem::path& testset_dir); 6 | -------------------------------------------------------------------------------- /source/MaaWin32ControlUnit/Screencap/SafeDXGI.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MaaUtils/SafeWindows.hpp" 4 | 5 | #include 6 | #include 7 | -------------------------------------------------------------------------------- /.devcontainer/ninja-build.sh: -------------------------------------------------------------------------------- 1 | dpkg -l | grep 'ninja-build' > /dev/null 2>&1 2 | 3 | if [ $? -ne 0 ]; then 4 | echo 'install ninja' 5 | apt install ninja-build -y 6 | fi -------------------------------------------------------------------------------- /source/binding/NodeJS/README.md: -------------------------------------------------------------------------------- 1 | # MaaFW NodeJS 2 | 3 | [文档](../../../docs/zh_cn/NodeJS/J1.1-快速开始.md) 4 | 5 | [Document](../../../docs/en_us/NodeJS/J1.1-QuickStarted.md) 6 | -------------------------------------------------------------------------------- /include/MaaAgentClient/MaaAgentClientDef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MaaFramework/MaaDef.h" // IWYU pragma: export 4 | 5 | typedef struct MaaAgentClient MaaAgentClient; 6 | -------------------------------------------------------------------------------- /test/nodejs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "@tsconfig/node20": "^20.1.4", 4 | "@types/node": "^20.17.22", 5 | "tsx": "^4.19.3" 6 | } 7 | } -------------------------------------------------------------------------------- /source/binding/NodeJS/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true, 4 | "trailingComma": "all", 5 | "arrowParens": "avoid", 6 | "printWidth": 100 7 | } 8 | -------------------------------------------------------------------------------- /docs/zh_cn/3.2-ProjectInterface协议.md: -------------------------------------------------------------------------------- 1 | # Project Interface 协议 2 | 3 | > [!NOTE] 4 | > 当前文档为 Project Interface v1 版本协议,已被废弃。 5 | > v5.x 版本新引入了 [V2 协议](3.3-ProjectInterfaceV2协议.md), 欢迎各位大佬集成适配! 6 | -------------------------------------------------------------------------------- /source/binding/NodeJS/.gitignore: -------------------------------------------------------------------------------- 1 | .cache 2 | build 3 | /install 4 | /maa 5 | node_modules 6 | /dist/binary 7 | .DS_Store 8 | *.png 9 | dist 10 | debug 11 | maa_option.json 12 | !release 13 | -------------------------------------------------------------------------------- /sample/cpp/modules/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | import maa.core; 4 | import maa.toolkit; 5 | import maa.agent.client; 6 | 7 | int main() 8 | { 9 | std::cout << MaaVersion(); 10 | } 11 | -------------------------------------------------------------------------------- /source/MaaToolkit/AdbDevice/AdbDeviceLinuxFinder.cpp: -------------------------------------------------------------------------------- 1 | #if defined(__linux__) 2 | 3 | #include "AdbDeviceLinuxFinder.h" 4 | 5 | MAA_TOOLKIT_NS_BEGIN 6 | 7 | MAA_TOOLKIT_NS_END 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /source/binding/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(WITH_NODEJS_BINDING OR WITH_QUICKJS_BINDING) 2 | add_subdirectory(NodeJS) 3 | endif() 4 | 5 | # install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Python" DESTINATION binding) 6 | -------------------------------------------------------------------------------- /tools/custom.action.schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json-schema.org/draft/2020-12/schema", 3 | "type": "object", 4 | "properties": { 5 | "custom_action": {}, 6 | "custom_action_param": {} 7 | } 8 | } -------------------------------------------------------------------------------- /test/nodejs/maa-server.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import './inject-server.js' 4 | 5 | export * from '../../source/binding/NodeJS/release/maa-node/dist/index-server' 6 | -------------------------------------------------------------------------------- /tools/custom.recognition.schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json-schema.org/draft/2020-12/schema", 3 | "type": "object", 4 | "properties": { 5 | "custom_recognition": {}, 6 | "custom_recognition_param": {} 7 | } 8 | } -------------------------------------------------------------------------------- /include/MaaToolkit/MaaToolkitAPI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MaaToolkitDef.h" // IWYU pragma: export 4 | 5 | #include "AdbDevice/MaaToolkitAdbDevice.h" 6 | #include "Config/MaaToolkitConfig.h" 7 | #include "DesktopWindow/MaaToolkitDesktopWindow.h" 8 | -------------------------------------------------------------------------------- /source/Common/MaaUtility.cpp: -------------------------------------------------------------------------------- 1 | #include "MaaFramework/MaaAPI.h" 2 | 3 | #include "MaaUtils/Logger.h" 4 | 5 | const char* MaaVersion() 6 | { 7 | #pragma message("MaaFramework MAA_VERSION: " MAA_VERSION) 8 | 9 | return MAA_VERSION; 10 | } 11 | -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/devcontainers/cpp:1-ubuntu-22.04 2 | 3 | COPY cmake.sh /tmp 4 | COPY ninja-build.sh /tmp 5 | COPY gcc-13_and_g++-13.sh /tmp 6 | 7 | RUN sudo sh /tmp/cmake.sh && sudo sh /tmp/ninja-build.sh && sudo sh /tmp/gcc-13_and_g++-13.sh -------------------------------------------------------------------------------- /source/binding/NodeJS/src/foundation/spec/async.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef MAA_JS_IMPL_IS_NODEJS 4 | #include "nodejs/async.h" // IWYU pragma: export 5 | #endif 6 | 7 | #ifdef MAA_JS_IMPL_IS_QUICKJS 8 | #include "quickjs/async.h" // IWYU pragma: export 9 | #endif 10 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/foundation/spec/class.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef MAA_JS_IMPL_IS_NODEJS 4 | #include "nodejs/class.h" // IWYU pragma: export 5 | #endif 6 | 7 | #ifdef MAA_JS_IMPL_IS_QUICKJS 8 | #include "quickjs/class.h" // IWYU pragma: export 9 | #endif 10 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/sys.d.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | const print: (msg: unknown) => void 3 | const readFile: (path: string) => ArrayBuffer 4 | const writeFile: (path: string, file: ArrayBuffer) => void 5 | const exit: (ret: string) => void 6 | } 7 | 8 | export {} 9 | -------------------------------------------------------------------------------- /sample/csharp/.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "dotnet-script": { 6 | "version": "1.6.0", 7 | "commands": [ 8 | "dotnet-script" 9 | ], 10 | "rollForward": false 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /source/binding/NodeJS/src/foundation/spec/callback.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef MAA_JS_IMPL_IS_NODEJS 4 | #include "nodejs/callback.h" // IWYU pragma: export 5 | #endif 6 | 7 | #ifdef MAA_JS_IMPL_IS_QUICKJS 8 | #include "quickjs/callback.h" // IWYU pragma: export 9 | #endif 10 | -------------------------------------------------------------------------------- /test/nodejs/server.ts: -------------------------------------------------------------------------------- 1 | import './maa-server' 2 | 3 | async function main() { 4 | console.log('MaaFw Version:', maa.Global) 5 | // console.log('MaaFw Role', maa.AgentRole) 6 | 7 | console.log('AgentServer', maa.Server) 8 | 9 | process.exit(0) 10 | } 11 | 12 | main() 13 | -------------------------------------------------------------------------------- /docs/en_us/3.2-ProjectInterface.md: -------------------------------------------------------------------------------- 1 | # Project Interface 2 | 3 | > [!NOTE] 4 | > The current document is Project Interface v1 protocol, which has been deprecated. 5 | > The v5.x release introduces the [V2 Protocol](3.3-ProjectInterfaceV2.md). We welcome all developers to integrate and adapt it! 6 | -------------------------------------------------------------------------------- /source/include/ProjectInterface/Runner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #include "Common/Conf.h" 6 | 7 | MAA_PROJECT_INTERFACE_NS_BEGIN 8 | 9 | class Runner 10 | { 11 | public: 12 | static bool run(const RuntimeParam& param); 13 | }; 14 | 15 | MAA_PROJECT_INTERFACE_NS_END 16 | -------------------------------------------------------------------------------- /source/MaaDbgControlUnit/ReplayRecording/ReplayRecordingMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ReplayRecording/ReplayRecording.h" 4 | 5 | #include "Common/Conf.h" 6 | 7 | MAA_CTRL_UNIT_NS_BEGIN 8 | 9 | ReplayRecording* create_replay_recording(const std::filesystem::path& path); 10 | 11 | MAA_CTRL_UNIT_NS_END 12 | -------------------------------------------------------------------------------- /source/binding/Python/maa/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pathlib import Path 3 | 4 | from .library import Library 5 | 6 | env_path = os.environ.get("MAAFW_BINARY_PATH") 7 | if env_path: 8 | __PATH = Path(env_path) 9 | else: 10 | __PATH = Path(Path(__file__).parent, "bin") 11 | 12 | Library.open(__PATH, agent_server=False) 13 | -------------------------------------------------------------------------------- /source/binding/Python/maa/agent/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pathlib import Path 3 | 4 | from ..library import Library 5 | 6 | env_path = os.environ.get("MAAFW_BINARY_PATH") 7 | if env_path: 8 | __PATH = Path(env_path) 9 | else: 10 | __PATH = Path(Path(__file__).parent.parent, "bin") 11 | 12 | Library.open(__PATH, agent_server=True) 13 | -------------------------------------------------------------------------------- /tools/pip_pack/pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "MaaPipPack" 3 | version = "0" 4 | requires-python = ">=3.9" 5 | authors = [{ name = "MaaXYZ" }] 6 | dependencies = ["tomlkit", "build", "wheel"] 7 | 8 | [build-system] 9 | requires = ["hatchling"] 10 | build-backend = "hatchling.build" 11 | 12 | [tool.uv] 13 | managed = true 14 | package = false 15 | -------------------------------------------------------------------------------- /source/MaaFramework/Resource/PipelineDumper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Common/Conf.h" 6 | #include "PipelineTypes.h" 7 | 8 | MAA_RES_NS_BEGIN 9 | 10 | class PipelineDumper 11 | { 12 | public: 13 | PipelineDumper() = delete; 14 | 15 | static json::object dump(const PipelineData& pp); 16 | }; 17 | 18 | MAA_RES_NS_END 19 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "build_picli", 8 | "type": "shell", 9 | "command": "cmake --build build --preset 'NinjaMulti - Debug' -j 16" 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /test/nodejs/recording/maa_recording_2024.11.24-16.12.43.8029970.txt: -------------------------------------------------------------------------------- 1 | {"cost":1,"success":true,"time":755909008338600,"type":"connect","uuid":"12345678","version":"de7080efc9758e04a52d777fede858764528c7c5"} 2 | {"cost":0,"package":"custom_aaa","success":true,"time":755909012118300,"type":"start_app"} 3 | {"cost":0,"package":"custom_bbb","success":true,"time":755909015074200,"type":"stop_app"} 4 | -------------------------------------------------------------------------------- /test/nodejs/recording/maa_recording_2024.11.24-16.13.21.8133449.txt: -------------------------------------------------------------------------------- 1 | {"cost":2,"success":true,"time":755947018832700,"type":"connect","uuid":"12345678","version":"de7080efc9758e04a52d777fede858764528c7c5"} 2 | {"cost":0,"package":"custom_aaa","success":true,"time":755947023949200,"type":"start_app"} 3 | {"cost":1,"package":"custom_bbb","success":true,"time":755947026545100,"type":"stop_app"} 4 | -------------------------------------------------------------------------------- /include/MaaToolkit/MaaToolkitDef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MaaFramework/MaaDef.h" // IWYU pragma: export 4 | 5 | typedef struct MaaToolkitAdbDevice MaaToolkitAdbDevice; 6 | typedef struct MaaToolkitAdbDeviceList MaaToolkitAdbDeviceList; 7 | 8 | typedef struct MaaToolkitDesktopWindow MaaToolkitDesktopWindow; 9 | typedef struct MaaToolkitDesktopWindowList MaaToolkitDesktopWindowList; 10 | -------------------------------------------------------------------------------- /sample/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(sample main.cpp) 2 | 3 | if(MSVC) 4 | target_compile_options(sample PRIVATE "/WX-") 5 | else() 6 | target_compile_options(sample PRIVATE -Wno-error -Wno-unused-parameter -Wno-unused-variable) 7 | endif() 8 | 9 | target_link_libraries(sample MaaFramework MaaToolkit) 10 | 11 | if(WITH_MAA_AGENT) 12 | add_subdirectory(MaaAgent) 13 | endif() 14 | -------------------------------------------------------------------------------- /source/MaaToolkit/DesktopWindow/DesktopWindowLinuxFinder.cpp: -------------------------------------------------------------------------------- 1 | #ifdef __linux__ 2 | 3 | #include "DesktopWindowLinuxFinder.h" 4 | 5 | #include "MaaUtils/Logger.h" 6 | 7 | MAA_TOOLKIT_NS_BEGIN 8 | 9 | std::vector DesktopWindowLinuxFinder::find_all() const 10 | { 11 | LogError << "Not implemented"; 12 | return {}; 13 | } 14 | 15 | MAA_TOOLKIT_NS_END 16 | 17 | #endif // __linux__ 18 | -------------------------------------------------------------------------------- /source/MaaToolkit/DesktopWindow/DesktopWindowMacOSFinder.cpp: -------------------------------------------------------------------------------- 1 | #ifdef __APPLE__ 2 | 3 | #include "DesktopWindowMacOSFinder.h" 4 | 5 | #include "MaaUtils/Logger.h" 6 | 7 | MAA_TOOLKIT_NS_BEGIN 8 | 9 | std::vector DesktopWindowMacOSFinder::find_all() const 10 | { 11 | LogError << "Not implemented"; 12 | return {}; 13 | } 14 | 15 | MAA_TOOLKIT_NS_END 16 | 17 | #endif // __APPLE__ 18 | -------------------------------------------------------------------------------- /source/MaaToolkit/DesktopWindow/DesktopWindowFinder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "DesktopWindowBuffer.hpp" 4 | #include "MaaUtils/Platform.h" 5 | 6 | #include "Common/Conf.h" 7 | 8 | MAA_TOOLKIT_NS_BEGIN 9 | 10 | class DesktopWindowFinder 11 | { 12 | public: 13 | virtual ~DesktopWindowFinder() = default; 14 | 15 | virtual std::vector find_all() const = 0; 16 | }; 17 | 18 | MAA_TOOLKIT_NS_END 19 | -------------------------------------------------------------------------------- /.github/workflows/deploy-website.yml: -------------------------------------------------------------------------------- 1 | name: deploy-maafw.xyz 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v*" 7 | 8 | workflow_dispatch: 9 | 10 | jobs: 11 | deploy: 12 | runs-on: ubuntu-latest 13 | env: 14 | GH_TOKEN: ${{ secrets.MaaFwDocsDeploy }} 15 | steps: 16 | - run: | 17 | gh workflow --repo MaaXYZ/MaaFrameworkWebsite run deploy.yml 18 | -------------------------------------------------------------------------------- /source/MaaFramework/Resource/MLProvider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if __has_include() 4 | #pragma message("MAA_WITH_DML") 5 | #define MAA_WITH_DML 6 | #include 7 | #endif 8 | 9 | #if __has_include() 10 | #pragma message("MAA_WITH_COREML") 11 | #define MAA_WITH_COREML 12 | #include 13 | #endif 14 | -------------------------------------------------------------------------------- /tools/nupkgs/Maa.Framework.Runtime.osx-x64.nuspec: -------------------------------------------------------------------------------- 1 | Maa.Framework.Runtime.osx-x64 2 | MaaFramework Runtime for osx-x64 3 | Native binaries of MaaFramework Embedded for osx-x64. 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /tools/nupkgs/Maa.Framework.Runtime.win-x64.nuspec: -------------------------------------------------------------------------------- 1 | Maa.Framework.Runtime.win-x64 2 | MaaFramework Runtime for win-x64 3 | Native binaries of MaaFramework Embedded for win-x64. 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /source/binding/NodeJS/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "binary": { 3 | "napi_versions": [ 4 | 8 5 | ] 6 | }, 7 | "devDependencies": { 8 | "@tsconfig/node20": "^20.1.6", 9 | "@types/node": "^20.19.9", 10 | "cmake-js": "^7.3.1", 11 | "node-addon-api": "^8.5.0", 12 | "node-api-headers": "^1.5.0", 13 | "tsx": "^4.20.3", 14 | "typescript": "^5.9.3" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /source/MaaFramework/Task/EmptyTask.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "TaskBase.h" 4 | 5 | MAA_TASK_NS_BEGIN 6 | 7 | // for MaaTaskerPostStop, as a stop mark 8 | class EmptyTask : public TaskBase 9 | { 10 | public: 11 | using TaskBase::TaskBase; 12 | 13 | virtual ~EmptyTask() override = default; 14 | 15 | virtual bool run() override { return true; } 16 | 17 | virtual void post_stop() override {} 18 | }; 19 | 20 | MAA_TASK_NS_END 21 | -------------------------------------------------------------------------------- /tools/nupkgs/Maa.Framework.Runtime.linux-x64.nuspec: -------------------------------------------------------------------------------- 1 | Maa.Framework.Runtime.linux-x64 2 | MaaFramework Runtime for linux-x64 3 | Native binaries of MaaFramework Embedded for linux-x64. 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /tools/nupkgs/Maa.Framework.Runtime.win-arm64.nuspec: -------------------------------------------------------------------------------- 1 | Maa.Framework.Runtime.win-arm64 2 | MaaFramework Runtime for win-arm64 3 | Native binaries of MaaFramework Embedded for win-arm64. 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /test/win32_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # DPI 截图问题测试程序(仅 Windows) 2 | add_executable(dpi_test dpi_test.cpp) 3 | 4 | if(MSVC) 5 | target_compile_options(dpi_test PRIVATE "/WX-") 6 | 7 | # 禁用 MSVC 默认的 Per-Monitor DPI Aware 设置,强制 DPI Unaware 以复现问题 8 | target_link_options(dpi_test PRIVATE "/MANIFEST:EMBED" "/MANIFESTINPUT:${CMAKE_CURRENT_SOURCE_DIR}/dpi_test.exe.manifest") 9 | endif() 10 | 11 | target_link_libraries(dpi_test MaaFramework MaaToolkit) 12 | -------------------------------------------------------------------------------- /tools/nupkgs/Maa.Framework.Runtime.osx-arm64.nuspec: -------------------------------------------------------------------------------- 1 | Maa.Framework.Runtime.osx-arm64 2 | MaaFramework Runtime for osx-arm64 3 | Native binaries of MaaFramework Embedded for osx-arm64. 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /tools/nupkgs/Maa.Framework.Runtime.android-x64.nuspec: -------------------------------------------------------------------------------- 1 | Maa.Framework.Runtime.android-x64 2 | MaaFramework Runtime for android-x64 3 | Native binaries of MaaFramework Embedded for android-x64. 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /tools/nupkgs/Maa.Framework.Runtime.linux-arm64.nuspec: -------------------------------------------------------------------------------- 1 | Maa.Framework.Runtime.linux-arm64 2 | MaaFramework Runtime for linux-arm64 3 | Native binaries of MaaFramework Embedded for linux-arm64. 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.devcontainer/gcc-13_and_g++-13.sh: -------------------------------------------------------------------------------- 1 | dpkg -l | grep 'gcc-13' > /dev/null 2>&1 2 | 3 | if [ $? -ne 0 ]; then 4 | echo 'install gcc-13 && g++-13' 5 | apt install software-properties-common -y 6 | add-apt-repository ppa:ubuntu-toolchain-r/test -y 7 | apt update 8 | apt install gcc-13 g++-13 -y 9 | rm /usr/bin/gcc 10 | rm /usr/bin/g++ 11 | ln -s /usr/bin/gcc-13 /usr/bin/gcc 12 | ln -s /usr/bin/g++-13 /usr/bin/g++ 13 | fi 14 | 15 | 16 | -------------------------------------------------------------------------------- /tools/nupkgs/Maa.Framework.Runtime.android-arm64.nuspec: -------------------------------------------------------------------------------- 1 | Maa.Framework.Runtime.android-arm64 2 | MaaFramework Runtime for android-arm64 3 | Native binaries of MaaFramework Embedded for android-arm64. 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sample/cpp/modules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.28) 2 | project(test) 3 | 4 | list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/../../../install/share/cmake") 5 | 6 | find_package(MaaFramework CONFIG REQUIRED) 7 | 8 | add_executable(test main.cpp) 9 | target_link_libraries(test 10 | MaaFramework::MaaFramework 11 | MaaFramework::MaaToolkit 12 | MaaFramework::MaaAgentClient 13 | MaaFramework::MaaFrameworkModule # for cpp modules 14 | ) 15 | -------------------------------------------------------------------------------- /source/modules/MaaAgentServer.cppm: -------------------------------------------------------------------------------- 1 | module; 2 | 3 | #include 4 | 5 | export module maa.agent.server; 6 | 7 | import maa.core; 8 | 9 | // MaaAgentServerAPI.h 10 | 11 | export using ::MaaAgentServerRegisterCustomRecognition; 12 | export using ::MaaAgentServerRegisterCustomAction; 13 | export using ::MaaAgentServerStartUp; 14 | export using ::MaaAgentServerShutDown; 15 | export using ::MaaAgentServerJoin; 16 | export using ::MaaAgentServerDetach; 17 | -------------------------------------------------------------------------------- /3rdparty/include/gzip/version.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /// The major version number 4 | #define GZIP_VERSION_MAJOR 1 5 | 6 | /// The minor version number 7 | #define GZIP_VERSION_MINOR 0 8 | 9 | /// The patch number 10 | #define GZIP_VERSION_PATCH 0 11 | 12 | /// The complete version number 13 | #define GZIP_VERSION_CODE \ 14 | (GZIP_VERSION_MAJOR * 10000 + GZIP_VERSION_MINOR * 100 + GZIP_VERSION_PATCH) 15 | 16 | /// Version number as string 17 | #define GZIP_VERSION_STRING "1.0.0" 18 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/apis/index-client.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | /// 8 | /// 9 | /// 10 | /// 11 | 12 | export {} 13 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/apis/index-server.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | /// 8 | /// 9 | /// 10 | /// 11 | 12 | export {} 13 | -------------------------------------------------------------------------------- /source/binding/NodeJS/release/maa-node-linux-x64/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@maaxyz/maa-node-linux-x64", 3 | "main": "./MaaNode.node", 4 | "exports": { 5 | ".": "./MaaNode.node", 6 | "./server": "./MaaNodeServer.node" 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "git://github.com/MaaXYZ/MaaFramework.git" 11 | }, 12 | "scripts": {}, 13 | "os": [ 14 | "linux" 15 | ], 16 | "cpu": [ 17 | "x64" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /source/binding/NodeJS/release/maa-node-win32-x64/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@maaxyz/maa-node-win32-x64", 3 | "main": "./MaaNode.node", 4 | "exports": { 5 | ".": "./MaaNode.node", 6 | "./server": "./MaaNodeServer.node" 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "git://github.com/MaaXYZ/MaaFramework.git" 11 | }, 12 | "scripts": {}, 13 | "os": [ 14 | "win32" 15 | ], 16 | "cpu": [ 17 | "x64" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /source/binding/NodeJS/release/maa-node-darwin-x64/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@maaxyz/maa-node-darwin-x64", 3 | "main": "./MaaNode.node", 4 | "exports": { 5 | ".": "./MaaNode.node", 6 | "./server": "./MaaNodeServer.node" 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "git://github.com/MaaXYZ/MaaFramework.git" 11 | }, 12 | "scripts": {}, 13 | "os": [ 14 | "darwin" 15 | ], 16 | "cpu": [ 17 | "x64" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /source/binding/NodeJS/release/maa-node-linux-arm64/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@maaxyz/maa-node-linux-arm64", 3 | "main": "./MaaNode.node", 4 | "exports": { 5 | ".": "./MaaNode.node", 6 | "./server": "./MaaNodeServer.node" 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "git://github.com/MaaXYZ/MaaFramework.git" 11 | }, 12 | "scripts": {}, 13 | "os": [ 14 | "linux" 15 | ], 16 | "cpu": [ 17 | "arm64" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /source/binding/NodeJS/release/maa-node-win32-arm64/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@maaxyz/maa-node-win32-arm64", 3 | "main": "./MaaNode.node", 4 | "exports": { 5 | ".": "./MaaNode.node", 6 | "./server": "./MaaNodeServer.node" 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "git://github.com/MaaXYZ/MaaFramework.git" 11 | }, 12 | "scripts": {}, 13 | "os": [ 14 | "win32" 15 | ], 16 | "cpu": [ 17 | "arm64" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Screencap/Minicap/MinicapDirect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MinicapBase.h" 4 | 5 | #include "Common/Conf.h" 6 | 7 | MAA_CTRL_UNIT_NS_BEGIN 8 | 9 | class MinicapDirect : public MinicapBase 10 | { 11 | public: 12 | using MinicapBase::MinicapBase; 13 | 14 | virtual ~MinicapDirect() override; 15 | 16 | public: // from ScreencapBase 17 | virtual bool init() override; 18 | 19 | virtual std::optional screencap() override; 20 | }; 21 | 22 | MAA_CTRL_UNIT_NS_END 23 | -------------------------------------------------------------------------------- /source/binding/NodeJS/release/maa-node-darwin-arm64/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@maaxyz/maa-node-darwin-arm64", 3 | "main": "./MaaNode.node", 4 | "exports": { 5 | ".": "./MaaNode.node", 6 | "./server": "./MaaNodeServer.node" 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "git://github.com/MaaXYZ/MaaFramework.git" 11 | }, 12 | "scripts": {}, 13 | "os": [ 14 | "darwin" 15 | ], 16 | "cpu": [ 17 | "arm64" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /include/MaaFramework/Utility/MaaUtility.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file MaaUtility.h 3 | * @author 4 | * @brief Provide global functions for the framework. 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | // IWYU pragma: private, include 11 | 12 | #pragma once 13 | 14 | #include "../MaaDef.h" 15 | #include "../MaaPort.h" 16 | 17 | #ifdef __cplusplus 18 | extern "C" 19 | { 20 | #endif 21 | 22 | MAA_FRAMEWORK_API const char* MaaVersion(); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | -------------------------------------------------------------------------------- /sample/resource/pipeline/custom_demo.json: -------------------------------------------------------------------------------- 1 | { 2 | "MyTask": { 3 | "next": [ 4 | "MyCustomRecTask" 5 | ] 6 | }, 7 | "MyCustomRecTask": { 8 | "recognition": "Custom", 9 | "custom_recognition": "MyRec", 10 | "custom_recognition_param": { 11 | "my_rec_key": "my_rec_value" 12 | }, 13 | "action": "Custom", 14 | "custom_action": "MyAct", 15 | "custom_action_param": { 16 | "my_act_key": "my_act_value" 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /source/modules/MaaAgentClient.cppm: -------------------------------------------------------------------------------- 1 | module; 2 | 3 | #include 4 | 5 | export module maa.agent.client; 6 | 7 | import maa.core; 8 | 9 | // MaaAgentClientDef.h 10 | 11 | export using ::MaaAgentClient; 12 | 13 | // MaaAgentClientAPI.h 14 | 15 | export using ::MaaAgentClientCreate; 16 | export using ::MaaAgentClientDestroy; 17 | export using ::MaaAgentClientBindResource; 18 | export using ::MaaAgentClientCreateSocket; 19 | export using ::MaaAgentClientConnect; 20 | export using ::MaaAgentClientDisconnect; 21 | -------------------------------------------------------------------------------- /source/binding/Python/pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "MaaFw" 3 | version = "0" 4 | requires-python = ">=3.9" 5 | authors = [{ name = "MaaXYZ" }] 6 | description = "An automation black-box testing framework based on image recognition" 7 | readme = "README.md" 8 | urls = { Homepage = "https://github.com/MaaXYZ/MaaFramework" } 9 | dependencies = ["numpy", "strenum", "MaaAgentBinary"] 10 | 11 | [build-system] 12 | requires = ["hatchling"] 13 | build-backend = "hatchling.build" 14 | 15 | [tool.hatch.build.targets.wheel] 16 | packages = ["maa"] 17 | -------------------------------------------------------------------------------- /include/MaaToolkit/Config/MaaToolkitConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file MaaToolkitConfig.h 3 | * @author 4 | * @brief Init and uninit the toolkit. 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | // IWYU pragma: private, include 11 | 12 | #pragma once 13 | 14 | #include "../MaaToolkitDef.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" 18 | { 19 | #endif 20 | 21 | MAA_TOOLKIT_API MaaBool MaaToolkitConfigInitOption(const char* user_path, const char* default_json); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /sample/csharp/QuickStart.ps1: -------------------------------------------------------------------------------- 1 | $n = [int](Read-Host "(1) Main`n(2) PI`n(3) Agent`n(4) CSBinding README Example`nSelect") 2 | $path = @('1.main.csx', '2.pi_cli.csx', '3.AgentMain.csx', "4.CSBinding README Example.csx")[$n - 1] 3 | if ($n -lt 1 -or $n -gt 4) { 4 | Write-Error "Invalid selection." 5 | exit 1 6 | } 7 | 8 | cd "$PSScriptRoot" 9 | $ENV:DOTNET_SCRIPT_CACHE_LOCATION = "$PSScriptRoot\.cache" 10 | 11 | dotnet tool restore 12 | dotnet script "$path" --sources https://api.nuget.org/v3/index.json --sources https://maaxyz.github.io/pkg/nuget/index.json -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/General/DeviceList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Base/UnitBase.h" 4 | 5 | #include "Common/Conf.h" 6 | 7 | MAA_CTRL_UNIT_NS_BEGIN 8 | 9 | class DeviceList : public UnitBase 10 | { 11 | public: 12 | virtual ~DeviceList() override = default; 13 | 14 | public: // from UnitBase 15 | virtual bool parse(const json::value& config) override; 16 | 17 | public: 18 | std::optional> request_devices(); 19 | 20 | private: 21 | ProcessArgvGenerator devices_argv_; 22 | }; 23 | 24 | MAA_CTRL_UNIT_NS_END 25 | -------------------------------------------------------------------------------- /source/include/ControlUnit/PlayCoverControlUnitAPI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ControlUnit/ControlUnitAPI.h" 4 | #include "MaaFramework/MaaDef.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" 8 | { 9 | #endif 10 | 11 | MAA_CONTROL_UNIT_API const char* MaaPlayCoverControlUnitGetVersion(); 12 | 13 | MAA_CONTROL_UNIT_API MaaControlUnitHandle MaaPlayCoverControlUnitCreate(const char* address, const char* uuid); 14 | 15 | MAA_CONTROL_UNIT_API void MaaPlayCoverControlUnitDestroy(MaaControlUnitHandle handle); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | -------------------------------------------------------------------------------- /.devcontainer/cmake.sh: -------------------------------------------------------------------------------- 1 | dpkg -l | grep cmake > /dev/null 2>&1 2 | 3 | if [ $? -eq 0 ]; then 4 | echo 'remove cmake' 5 | apt -y remove --purge --auto-remove cmake 6 | fi 7 | 8 | apt update && \ 9 | apt install -y software-properties-common lsb-release && \ 10 | apt clean all 11 | 12 | wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null 13 | 14 | apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" -y 15 | 16 | apt install cmake -y 17 | 18 | 19 | -------------------------------------------------------------------------------- /source/MaaDbgControlUnit/ReplayRecording/ReplayRecordingMgr.cpp: -------------------------------------------------------------------------------- 1 | #include "ReplayRecordingMgr.h" 2 | 3 | #include "MaaUtils/Logger.h" 4 | #include "ReplayRecording/RecordParser.h" 5 | 6 | MAA_CTRL_UNIT_NS_BEGIN 7 | 8 | ReplayRecording* create_replay_recording(const std::filesystem::path& path) 9 | { 10 | auto record_opt = RecordParser::parse(path); 11 | if (!record_opt) { 12 | LogError << "Failed to parse record file:" << path; 13 | return nullptr; 14 | } 15 | return new ReplayRecording(std::move(*record_opt)); 16 | } 17 | 18 | MAA_CTRL_UNIT_NS_END 19 | -------------------------------------------------------------------------------- /source/MaaFramework/Task/RecognitionTask.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "TaskBase.h" 4 | 5 | #include "Common/Conf.h" 6 | 7 | MAA_TASK_NS_BEGIN 8 | 9 | class RecognitionTask : public TaskBase 10 | { 11 | public: 12 | RecognitionTask(const cv::Mat& image, std::string entry, Tasker* tasker, std::shared_ptr context = nullptr); 13 | 14 | virtual ~RecognitionTask() override = default; 15 | 16 | public: 17 | virtual bool run() override; 18 | 19 | public: 20 | MaaRecoId run_impl(); 21 | 22 | private: 23 | cv::Mat image_; 24 | }; 25 | 26 | MAA_TASK_NS_END 27 | -------------------------------------------------------------------------------- /test/pipeline/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file( 2 | GLOB_RECURSE 3 | pipeline_testing_src 4 | *.cpp 5 | *.h 6 | *.hpp) 7 | 8 | add_executable(PipelineTesting ${pipeline_testing_src}) 9 | 10 | target_link_libraries(PipelineTesting MaaFramework) 11 | 12 | add_dependencies(PipelineTesting MaaFramework PipelineSmokingResource) 13 | set_target_properties(PipelineTesting PROPERTIES FOLDER Testing) 14 | 15 | install(TARGETS PipelineTesting RUNTIME DESTINATION bin) 16 | 17 | if(WIN32) 18 | install(FILES $ DESTINATION symbol OPTIONAL) 19 | endif() 20 | -------------------------------------------------------------------------------- /tools/maadeps-download.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import sys 3 | from pathlib import Path 4 | 5 | sub_path = Path(__file__).parent.parent / "source" / "MaaUtils" / "tools" 6 | sys.path.append(str(sub_path)) 7 | 8 | from maadeps_download import main as download_main, detect_host_triplet 9 | 10 | REPO = "MaaXYZ/MaaDeps" 11 | VERSION = "v2.10.0-beta.1" 12 | 13 | if __name__ == "__main__": 14 | if len(sys.argv) == 2: 15 | target_triplet = sys.argv[1] 16 | else: 17 | target_triplet = detect_host_triplet() 18 | 19 | download_main(target_triplet, REPO, VERSION) 20 | -------------------------------------------------------------------------------- /source/include/ControlUnit/DbgControlUnitAPI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "ControlUnitAPI.h" 7 | #include "MaaFramework/MaaDef.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | MAA_CONTROL_UNIT_API const char* MaaDbgControlUnitGetVersion(); 15 | 16 | MAA_CONTROL_UNIT_API MaaControlUnitHandle MaaDbgControlUnitCreate(MaaDbgControllerType type, const char* read_path); 17 | 18 | MAA_CONTROL_UNIT_API void MaaDbgControlUnitDestroy(MaaControlUnitHandle handle); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /source/MaaWin32ControlUnit/Screencap/GdiScreencap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Base/UnitBase.h" 4 | #include "MaaUtils/SafeWindows.hpp" 5 | 6 | #include "Common/Conf.h" 7 | 8 | MAA_CTRL_UNIT_NS_BEGIN 9 | 10 | class GdiScreencap : public ScreencapBase 11 | { 12 | public: 13 | explicit GdiScreencap(HWND hwnd) 14 | : hwnd_(hwnd) 15 | { 16 | } 17 | 18 | virtual ~GdiScreencap() override = default; 19 | 20 | public: // from ScreencapBase 21 | virtual std::optional screencap() override; 22 | 23 | private: 24 | HWND hwnd_ = nullptr; 25 | }; 26 | 27 | MAA_CTRL_UNIT_NS_END 28 | -------------------------------------------------------------------------------- /source/MaaToolkit/DesktopWindow/DesktopWindowLinuxFinder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__linux__) 4 | 5 | #include "DesktopWindowFinder.h" 6 | #include "MaaUtils/SingletonHolder.hpp" 7 | 8 | #include "Common/Conf.h" 9 | 10 | MAA_TOOLKIT_NS_BEGIN 11 | 12 | class DesktopWindowLinuxFinder 13 | : public DesktopWindowFinder 14 | , public SingletonHolder 15 | { 16 | public: 17 | virtual ~DesktopWindowLinuxFinder() override = default; 18 | 19 | virtual std::vector find_all() const override; 20 | }; 21 | 22 | MAA_TOOLKIT_NS_END 23 | 24 | #endif // __linux__ 25 | -------------------------------------------------------------------------------- /source/MaaToolkit/DesktopWindow/DesktopWindowMacOSFinder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__APPLE__) 4 | 5 | #include "DesktopWindowFinder.h" 6 | #include "MaaUtils/SingletonHolder.hpp" 7 | 8 | #include "Common/Conf.h" 9 | 10 | MAA_TOOLKIT_NS_BEGIN 11 | 12 | class DesktopWindowMacOSFinder 13 | : public DesktopWindowFinder 14 | , public SingletonHolder 15 | { 16 | public: 17 | virtual ~DesktopWindowMacOSFinder() override = default; 18 | 19 | virtual std::vector find_all() const override; 20 | }; 21 | 22 | MAA_TOOLKIT_NS_END 23 | 24 | #endif // __APPLE__ 25 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "3rdparty/MaaAgentBinary"] 2 | path = 3rdparty/MaaAgentBinary 3 | url = https://github.com/MaaXYZ/MaaAgentBinary 4 | [submodule "test/TestingDataSet"] 5 | path = test/TestingDataSet 6 | url = https://github.com/MaaXYZ/MaaFrameworkTesting.git 7 | [submodule "3rdparty/EmulatorExtras"] 8 | path = 3rdparty/EmulatorExtras 9 | url = https://github.com/MaaXYZ/EmulatorExtras.git 10 | [submodule "3rdparty/quickjs"] 11 | path = 3rdparty/quickjs 12 | url = https://github.com/quickjs-ng/quickjs 13 | [submodule "source/MaaUtils"] 14 | path = source/MaaUtils 15 | url = https://github.com/MaaXYZ/MaaUtils.git 16 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/General/AdbCommand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Base/UnitBase.h" 4 | 5 | #include "Common/Conf.h" 6 | 7 | MAA_CTRL_UNIT_NS_BEGIN 8 | 9 | class AdbCommand : public UnitBase 10 | { 11 | public: 12 | virtual ~AdbCommand() override = default; 13 | 14 | public: // from UnitBase 15 | virtual bool parse(const json::value& config) override; 16 | 17 | public: 18 | std::optional shell(const std::string& cmd, std::chrono::milliseconds timeout = std::chrono::milliseconds(20000)); 19 | 20 | private: 21 | ProcessArgvGenerator shell_argv; 22 | }; 23 | 24 | MAA_CTRL_UNIT_NS_END 25 | -------------------------------------------------------------------------------- /source/MaaFramework/Resource/PipelineChecker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Common/Conf.h" 4 | #include "PipelineTypes.h" 5 | 6 | MAA_RES_NS_BEGIN 7 | 8 | class PipelineChecker 9 | { 10 | public: 11 | PipelineChecker() = delete; 12 | 13 | static bool check_all_validity(const PipelineDataMap& data_map); 14 | 15 | private: 16 | static bool check_all_next_list(const PipelineDataMap& data_map); 17 | static bool check_all_regex(const PipelineDataMap& data_map); 18 | 19 | static bool check_next_list(const std::vector& next_list, const PipelineDataMap& data_map); 20 | }; 21 | 22 | MAA_RES_NS_END 23 | -------------------------------------------------------------------------------- /source/MaaToolkit/AdbDevice/AdbDeviceLinuxFinder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__linux__) 4 | 5 | #include "AdbDeviceFinder.h" 6 | #include "Common/Conf.h" 7 | #include "MaaUtils/SingletonHolder.hpp" 8 | 9 | MAA_TOOLKIT_NS_BEGIN 10 | 11 | class AdbDeviceLinuxFinder 12 | : public SingletonHolder 13 | , public AdbDeviceFinder 14 | { 15 | friend class SingletonHolder; 16 | 17 | public: 18 | virtual ~AdbDeviceLinuxFinder() override = default; 19 | 20 | private: 21 | AdbDeviceLinuxFinder() = default; 22 | }; 23 | 24 | MAA_TOOLKIT_NS_END 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /tools/collect-mac-debug.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | INSTALL_PREFIX=$1 4 | 5 | if ! [[ -d "$INSTALL_PREFIX" ]]; then 6 | echo "Usage: $0 [install prefix]" 7 | exit 1 8 | fi 9 | 10 | INSTALL_PREFIX=`realpath "$INSTALL_PREFIX"` 11 | 12 | cd `dirname "$0"/..` 13 | 14 | mkdir -p "$INSTALL_PREFIX/symbols" 15 | find $INSTALL_PREFIX/bin -type f | while read BINARY; do 16 | echo "Process $BINARY" 17 | FILE=`basename "$BINARY"` 18 | DEBUG_FILE="$INSTALL_PREFIX/symbols/$FILE.dSYM" 19 | 20 | cd `dirname "$BINARY"` 21 | 22 | dsymutil "$BINARY" 23 | mv "$BINARY.dSYM" "$DEBUG_FILE" 24 | 25 | cd - > /dev/null 26 | done 27 | -------------------------------------------------------------------------------- /source/MaaFramework/Task/Component/CustomAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Common/Conf.h" 4 | 5 | #include "Common/MaaTypes.h" 6 | #include "MaaFramework/MaaDef.h" 7 | #include "Resource/ResourceMgr.h" 8 | #include "Task/Context.h" 9 | 10 | MAA_TASK_NS_BEGIN 11 | 12 | class CustomAction 13 | { 14 | public: 15 | static bool 16 | run(Context& context, 17 | std::string node_name, 18 | MAA_RES_NS::CustomActionSession session, 19 | const MAA_RES_NS::Action::CustomParam& param, 20 | MaaRecoId reco_id, 21 | const cv::Rect& rect); 22 | }; 23 | 24 | MAA_TASK_NS_END 25 | -------------------------------------------------------------------------------- /source/MaaWin32ControlUnit/Screencap/ScreenDCScreencap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Base/UnitBase.h" 4 | #include "MaaUtils/SafeWindows.hpp" 5 | 6 | #include "Common/Conf.h" 7 | 8 | MAA_CTRL_UNIT_NS_BEGIN 9 | 10 | class ScreenDCScreencap : public ScreencapBase 11 | { 12 | public: 13 | explicit ScreenDCScreencap(HWND hwnd) 14 | : hwnd_(hwnd) 15 | { 16 | } 17 | 18 | virtual ~ScreenDCScreencap() override = default; 19 | 20 | public: // from ScreencapBase 21 | virtual std::optional screencap() override; 22 | 23 | private: 24 | HWND hwnd_ = nullptr; 25 | }; 26 | 27 | MAA_CTRL_UNIT_NS_END 28 | 29 | -------------------------------------------------------------------------------- /sample/csharp/QuickStart.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo -e "(1) Main\n(2) PI\n(3) Agent\n(4) CSBinding README Example\nSelect: " 4 | read -r n 5 | case $n in 6 | 1) path="1.main.csx" ;; 7 | 2) path="2.pi_cli.csx" ;; 8 | 3) path="3.Agent/AgentMain.cs" ;; 9 | 4) path="4.CSBinding README Example.csx" ;; 10 | *) echo "Invalid selection."; exit 1 ;; 11 | esac 12 | 13 | ScriptRoot=$(dirname "$0") 14 | cd "$ScriptRoot" 15 | export DOTNET_SCRIPT_CACHE_LOCATION="$ScriptRoot/.cache" 16 | 17 | dotnet tool restore 18 | dotnet script "$path" --sources https://api.nuget.org/v3/index.json --sources https://maaxyz.github.io/pkg/nuget/index.json -------------------------------------------------------------------------------- /source/MaaToolkit/DesktopWindow/DesktopWindowWin32Finder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(_WIN32) 4 | 5 | #include "DesktopWindowFinder.h" 6 | #include "MaaUtils/Platform.h" 7 | #include "MaaUtils/SingletonHolder.hpp" 8 | 9 | #include "Common/Conf.h" 10 | 11 | MAA_TOOLKIT_NS_BEGIN 12 | 13 | class DesktopWindowWin32Finder 14 | : public DesktopWindowFinder 15 | , public SingletonHolder 16 | { 17 | public: 18 | virtual ~DesktopWindowWin32Finder() override = default; 19 | 20 | virtual std::vector find_all() const override; 21 | }; 22 | 23 | MAA_TOOLKIT_NS_END 24 | 25 | #endif // _WIN32 26 | -------------------------------------------------------------------------------- /source/MaaWin32ControlUnit/Screencap/PrintWindowScreencap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Base/UnitBase.h" 4 | #include "MaaUtils/SafeWindows.hpp" 5 | 6 | #include "Common/Conf.h" 7 | 8 | MAA_CTRL_UNIT_NS_BEGIN 9 | 10 | class PrintWindowScreencap : public ScreencapBase 11 | { 12 | public: 13 | explicit PrintWindowScreencap(HWND hwnd) 14 | : hwnd_(hwnd) 15 | { 16 | } 17 | 18 | virtual ~PrintWindowScreencap() override = default; 19 | 20 | public: // from ScreencapBase 21 | virtual std::optional screencap() override; 22 | 23 | private: 24 | HWND hwnd_ = nullptr; 25 | }; 26 | 27 | MAA_CTRL_UNIT_NS_END 28 | 29 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/apis/plugin.d.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | namespace maa { 3 | const Plugin: { 4 | add_resource_sink(cb: (res: Resource, msg: ResourceNotify) => MaybePromise): void 5 | add_controller_sink( 6 | cb: (ctrl: Controller, msg: ControllerNotify) => MaybePromise, 7 | ): void 8 | add_tasker_sink(cb: (tsk: Tasker, msg: TaskerNotify) => MaybePromise): void 9 | add_context_sink( 10 | cb: (ctx: Context, msg: TaskerContextNotify) => MaybePromise, 11 | ): void 12 | } 13 | } 14 | } 15 | 16 | export {} 17 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/General/Activity.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Base/UnitBase.h" 4 | 5 | #include "Common/Conf.h" 6 | 7 | MAA_CTRL_UNIT_NS_BEGIN 8 | 9 | class Activity : public UnitBase 10 | { 11 | public: 12 | virtual ~Activity() override = default; 13 | 14 | public: // from UnitBase 15 | virtual bool parse(const json::value& config) override; 16 | 17 | public: 18 | bool start_app(const std::string& intent); 19 | bool stop_app(const std::string& intent); 20 | 21 | private: 22 | ProcessArgvGenerator start_app_argv_; 23 | ProcessArgvGenerator start_activity_argv_; 24 | ProcessArgvGenerator stop_app_argv_; 25 | }; 26 | 27 | MAA_CTRL_UNIT_NS_END 28 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Screencap/Encode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Base/UnitBase.h" 4 | 5 | #include "ScreencapHelper.h" 6 | 7 | #include "Common/Conf.h" 8 | 9 | MAA_CTRL_UNIT_NS_BEGIN 10 | 11 | class ScreencapEncode : public ScreencapBase 12 | { 13 | public: 14 | virtual ~ScreencapEncode() override = default; 15 | 16 | public: // from UnitBase 17 | virtual bool parse(const json::value& config) override; 18 | 19 | public: // from ScreencapBase 20 | virtual bool init() override { return true; } 21 | 22 | virtual std::optional screencap() override; 23 | 24 | private: 25 | ProcessArgvGenerator screencap_encode_argv_; 26 | }; 27 | 28 | MAA_CTRL_UNIT_NS_END 29 | -------------------------------------------------------------------------------- /tools/NodeTest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file( 2 | GLOB_RECURSE 3 | node_test_src 4 | *.cpp 5 | *.h 6 | *.hpp) 7 | 8 | add_executable(NodeTest ${node_test_src}) 9 | 10 | if(MSVC) 11 | target_compile_options(NodeTest PRIVATE "/WX-") 12 | else() 13 | target_compile_options(NodeTest PRIVATE "-Wno-error") 14 | endif() 15 | 16 | target_link_libraries(NodeTest MaaFramework MaaToolkit ${OpenCV_LIBS}) 17 | 18 | add_dependencies(NodeTest MaaFramework) 19 | set_target_properties(NodeTest PROPERTIES FOLDER Testing) 20 | 21 | install(TARGETS NodeTest RUNTIME DESTINATION bin) 22 | 23 | if(WIN32) 24 | install(FILES $ DESTINATION symbol OPTIONAL) 25 | endif() 26 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Screencap/Minicap/MinicapDef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Common/Conf.h" 6 | 7 | MAA_CTRL_UNIT_NS_BEGIN 8 | 9 | #pragma pack(push, 1) 10 | 11 | struct MinicapHeader 12 | { 13 | enum 14 | { 15 | DUMB = 1 << 0, 16 | ALWAYS_UPRIGHT = 1 << 1, 17 | TEAR = 1 << 2 18 | }; 19 | 20 | uint8_t version = 0; 21 | uint8_t size = 0; 22 | uint32_t pid = 0; 23 | uint32_t real_width = 0; 24 | uint32_t real_height = 0; 25 | uint32_t virt_width = 0; 26 | uint32_t virt_height = 0; 27 | uint8_t orientation = 0; 28 | uint8_t flags = 0; 29 | }; 30 | 31 | #pragma pack(pop) 32 | 33 | MAA_CTRL_UNIT_NS_END 34 | -------------------------------------------------------------------------------- /test/win32_test/dpi_test.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | false 11 | unaware 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Screencap/RawWithGzip.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Base/UnitBase.h" 4 | 5 | #include "ScreencapHelper.h" 6 | 7 | #include "Common/Conf.h" 8 | 9 | MAA_CTRL_UNIT_NS_BEGIN 10 | 11 | class ScreencapRawWithGzip : public ScreencapBase 12 | { 13 | public: 14 | virtual ~ScreencapRawWithGzip() override = default; 15 | 16 | public: // from UnitBase 17 | virtual bool parse(const json::value& config) override; 18 | 19 | public: // from ScreencapBase 20 | virtual bool init() override { return true; } 21 | 22 | virtual std::optional screencap() override; 23 | 24 | private: 25 | ProcessArgvGenerator screencap_raw_with_gzip_argv_; 26 | }; 27 | 28 | MAA_CTRL_UNIT_NS_END 29 | -------------------------------------------------------------------------------- /source/include/ControlUnit/CustomControlUnitAPI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "ControlUnit/ControlUnitAPI.h" 7 | #include "MaaFramework/Instance/MaaCustomController.h" 8 | #include "MaaFramework/MaaDef.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" 12 | { 13 | #endif 14 | 15 | MAA_CONTROL_UNIT_API const char* MaaCustomControlUnitGetVersion(); 16 | 17 | MAA_CONTROL_UNIT_API MaaCustomControlUnitHandle 18 | MaaCustomControlUnitCreate(MaaCustomControllerCallbacks* controller, void* controller_arg); 19 | 20 | MAA_CONTROL_UNIT_API void MaaCustomControlUnitDestroy(MaaCustomControlUnitHandle handle); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/foundation/spec/quickjs/types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "wrapper.h" // IWYU pragma: export 4 | 5 | namespace maajs 6 | { 7 | 8 | using EnvType = QjsEnv; 9 | using ValueType = QjsValue; 10 | using ObjectType = QjsObject; 11 | using BooleanType = QjsBoolean; 12 | using StringType = QjsString; 13 | using NumberType = QjsNumber; 14 | using FunctionType = QjsFunction; 15 | using ArrayType = QjsArray; 16 | using PromiseType = QjsPromise; 17 | using ArrayBufferType = QjsArrayBuffer; 18 | 19 | using ObjectRefType = QjsRef; 20 | using FunctionRefType = QjsRef; 21 | using WeakObjectRefType = QjsWeakRef; 22 | 23 | using CallbackInfo = QjsCallbackInfo; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /source/MaaFramework/Task/ActionTask.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MaaFramework/MaaDef.h" 4 | #include "TaskBase.h" 5 | 6 | #include "Common/Conf.h" 7 | 8 | MAA_TASK_NS_BEGIN 9 | 10 | class ActionTask : public TaskBase 11 | { 12 | public: 13 | ActionTask( 14 | const cv::Rect& box, 15 | const std::string& reco_detail, 16 | std::string entry, 17 | Tasker* tasker, 18 | std::shared_ptr context = nullptr); 19 | 20 | virtual ~ActionTask() override = default; 21 | 22 | public: 23 | virtual bool run() override; 24 | 25 | public: 26 | MaaActId run_impl(); 27 | 28 | private: 29 | cv::Rect box_; 30 | json::value reco_detail_; 31 | }; 32 | 33 | MAA_TASK_NS_END 34 | -------------------------------------------------------------------------------- /source/MaaToolkit/AdbDevice/AdbDeviceMacOSFinder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__APPLE__) 4 | 5 | #include "AdbDeviceFinder.h" 6 | #include "Common/Conf.h" 7 | #include "MaaUtils/SingletonHolder.hpp" 8 | 9 | MAA_TOOLKIT_NS_BEGIN 10 | 11 | class AdbDeviceMacOSFinder 12 | : public SingletonHolder 13 | , public AdbDeviceFinder 14 | { 15 | friend class SingletonHolder; 16 | 17 | public: 18 | virtual ~AdbDeviceMacOSFinder() override = default; 19 | 20 | protected: 21 | virtual const EmulatorConstDataMap& get_emulator_const_data() const override; 22 | 23 | private: 24 | AdbDeviceMacOSFinder() = default; 25 | }; 26 | 27 | MAA_TOOLKIT_NS_END 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /source/include/LibraryHolder/AgentClient.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "MaaUtils/LibraryHolder.h" 6 | #include "MaaUtils/Platform.h" 7 | 8 | #include "Common/Conf.h" 9 | 10 | struct MaaAgentClient; 11 | 12 | MAA_NS_BEGIN 13 | 14 | class AgentClientLibraryHolder : public LibraryHolder 15 | { 16 | public: 17 | static std::shared_ptr create_agent_client(); 18 | 19 | private: 20 | inline static const std::filesystem::path libname_ = MAA_NS::path("MaaAgentClient"); 21 | inline static const std::string create_func_name_ = "MaaAgentClientCreateV2"; 22 | inline static const std::string destroy_func_name_ = "MaaAgentClientDestroy"; 23 | }; 24 | 25 | MAA_NS_END 26 | -------------------------------------------------------------------------------- /sample/cpp/MaaAgent/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(agent_child agent_child.cpp) 2 | 3 | target_link_libraries(agent_child MaaAgentServer) 4 | 5 | add_executable(agent_main agent_main.cpp) 6 | target_link_libraries(agent_main MaaFramework MaaToolkit MaaAgentClient) 7 | 8 | add_dependencies(agent_main agent_child MaaAgentClient) 9 | add_dependencies(agent_child MaaAgentServer) 10 | 11 | if(MSVC) 12 | target_compile_options(agent_child PRIVATE "/WX-") 13 | target_compile_options(agent_main PRIVATE "/WX-") 14 | else() 15 | target_compile_options(agent_child PRIVATE -Wno-error -Wno-unused-parameter -Wno-unused-variable) 16 | target_compile_options(agent_main PRIVATE -Wno-error -Wno-unused-parameter -Wno-unused-variable) 17 | endif() 18 | -------------------------------------------------------------------------------- /source/include/ControlUnit/Win32ControlUnitAPI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "ControlUnit/ControlUnitAPI.h" 7 | #include "MaaFramework/MaaDef.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | MAA_CONTROL_UNIT_API const char* MaaWin32ControlUnitGetVersion(); 15 | 16 | MAA_CONTROL_UNIT_API MaaWin32ControlUnitHandle MaaWin32ControlUnitCreate( 17 | void* hWnd, 18 | MaaWin32ScreencapMethod screencap_method, 19 | MaaWin32InputMethod mouse_method, 20 | MaaWin32InputMethod keyboard_method); 21 | 22 | MAA_CONTROL_UNIT_API void MaaWin32ControlUnitDestroy(MaaWin32ControlUnitHandle handle); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/foundation/spec/nodejs/types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include // IWYU pragma: export 4 | 5 | namespace maajs 6 | { 7 | 8 | using EnvType = Napi::Env; 9 | using ValueType = Napi::Value; 10 | using ObjectType = Napi::Object; 11 | using BooleanType = Napi::Boolean; 12 | using StringType = Napi::String; 13 | using NumberType = Napi::Number; 14 | using FunctionType = Napi::Function; 15 | using ArrayType = Napi::Array; 16 | using PromiseType = Napi::Promise; 17 | using ArrayBufferType = Napi::ArrayBuffer; 18 | 19 | using ObjectRefType = Napi::ObjectReference; 20 | using FunctionRefType = Napi::FunctionReference; 21 | using WeakObjectRefType = Napi::ObjectReference; 22 | 23 | using CallbackInfo = Napi::CallbackInfo; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_custom_target(tools ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}) 2 | # set_property( TARGET tools APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${CMAKE_CURRENT_SOURCE_DIR}) 3 | set_target_properties(tools PROPERTIES FOLDER Assets) 4 | install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ImageCropper DESTINATION tools) 5 | install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pipeline.schema.json DESTINATION tools) 6 | install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/custom.action.schema.json DESTINATION tools) 7 | install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/custom.recognition.schema.json DESTINATION tools) 8 | install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/interface.schema.json DESTINATION tools) 9 | install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/interface_config.schema.json DESTINATION tools) 10 | -------------------------------------------------------------------------------- /source/MaaFramework/Task/PipelineTask.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "TaskBase.h" 4 | 5 | #include "Common/Conf.h" 6 | 7 | MAA_RES_NS_BEGIN 8 | struct NodeAttr; 9 | MAA_RES_NS_END 10 | 11 | MAA_TASK_NS_BEGIN 12 | 13 | class PipelineTask : public TaskBase 14 | { 15 | public: 16 | using TaskBase::TaskBase; 17 | 18 | virtual ~PipelineTask() override = default; 19 | 20 | virtual bool run() override; 21 | virtual void post_stop() override; 22 | 23 | private: 24 | NodeDetail run_next(const std::vector& next, const PipelineData& pretask); 25 | RecoResult recognize_list(const cv::Mat& image, const std::vector& list); 26 | void save_on_error(const std::string& node_name); 27 | }; 28 | 29 | MAA_TASK_NS_END 30 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/apis/global.d.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | namespace maa { 3 | const Global: { 4 | get version_from_macro(): string 5 | get version(): string 6 | set log_dir(value: string) 7 | set save_draw(value: boolean) 8 | set save_on_error(value: boolean) 9 | set stdout_level( 10 | value: 'Off' | 'Fatal' | 'Error' | 'Warn' | 'Info' | 'Debug' | 'Trace' | 'All', 11 | ) 12 | set debug_mode(value: boolean) 13 | set draw_quality(value: number) 14 | set reco_image_cache_limit(value: number) 15 | config_init_option(user_path: string, default_json?: string): void 16 | } 17 | } 18 | } 19 | 20 | export {} 21 | -------------------------------------------------------------------------------- /sample/resource/pipeline/sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "StartUpAndClickButton": { 3 | "next": [ 4 | "Click_Button", 5 | "Flag_NoButton", 6 | "[JumpBack]Sub_StartUp" 7 | ] 8 | }, 9 | "Sub_StartUp": { 10 | "next": [ 11 | "Flag_InApp", 12 | "[JumpBack]Sub_StartUp" 13 | ] 14 | }, 15 | "Sub_StartApp": { 16 | "action": "StartApp" 17 | }, 18 | "Flag_InApp": { 19 | "recognition": "TemplateMatch", 20 | "template": "App.png" 21 | }, 22 | "Flag_NoButton": { 23 | "recognition": "OCR", 24 | "expected": "NoButton" 25 | }, 26 | "Click_Button": { 27 | "recognition": "OCR", 28 | "expected": "Button", 29 | "action": "Click" 30 | } 31 | } -------------------------------------------------------------------------------- /source/MaaWin32ControlUnit/Screencap/DesktopDupWindowScreencap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Common/Conf.h" 4 | #include "MaaUtils/SafeWindows.hpp" 5 | 6 | #include "Base/UnitBase.h" 7 | #include "DesktopDupScreencap.h" 8 | 9 | MAA_CTRL_UNIT_NS_BEGIN 10 | 11 | class DesktopDupWindowScreencap : public DesktopDupScreencap 12 | { 13 | public: 14 | explicit DesktopDupWindowScreencap(HWND hwnd) 15 | : DesktopDupScreencap(hwnd) 16 | { 17 | } 18 | 19 | virtual ~DesktopDupWindowScreencap() override = default; 20 | 21 | public: // from ScreencapBase 22 | virtual std::optional screencap() override; 23 | 24 | private: 25 | RECT get_window_client_rect_screen() const; 26 | RECT get_output_desktop_coordinates() const; 27 | }; 28 | 29 | MAA_CTRL_UNIT_NS_END 30 | 31 | -------------------------------------------------------------------------------- /source/include/ControlUnit/AdbControlUnitAPI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "ControlUnit/ControlUnitAPI.h" 7 | #include "MaaFramework/MaaDef.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | MAA_CONTROL_UNIT_API const char* MaaAdbControlUnitGetVersion(); 15 | 16 | MAA_CONTROL_UNIT_API MaaAdbControlUnitHandle MaaAdbControlUnitCreate( 17 | const char* adb_path, 18 | const char* adb_serial, 19 | MaaAdbScreencapMethod screencap_methods, 20 | MaaAdbInputMethod input_methods, 21 | const char* config, 22 | const char* agent_path); 23 | 24 | MAA_CONTROL_UNIT_API void MaaAdbControlUnitDestroy(MaaAdbControlUnitHandle handle); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Screencap/EncodeToFile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Base/UnitBase.h" 4 | 5 | #include "ScreencapHelper.h" 6 | 7 | #include "Common/Conf.h" 8 | 9 | MAA_CTRL_UNIT_NS_BEGIN 10 | 11 | class ScreencapEncodeToFileAndPull : public ScreencapBase 12 | { 13 | public: 14 | virtual ~ScreencapEncodeToFileAndPull() override = default; 15 | 16 | public: // from UnitBase 17 | virtual bool parse(const json::value& config) override; 18 | 19 | public: // from ScreencapBase 20 | virtual bool init() override; 21 | 22 | virtual std::optional screencap() override; 23 | 24 | private: 25 | ProcessArgvGenerator screencap_encode_to_file_argv_; 26 | ProcessArgvGenerator pull_file_argv_; 27 | 28 | std::string tempname_; 29 | }; 30 | 31 | MAA_CTRL_UNIT_NS_END 32 | -------------------------------------------------------------------------------- /tools/split-linux-debug.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | INSTALL_PREFIX=$1 4 | 5 | if ! [[ -d "$INSTALL_PREFIX" ]]; then 6 | echo "Usage: $0 [install prefix]" 7 | exit 1 8 | fi 9 | 10 | INSTALL_PREFIX=`realpath "$INSTALL_PREFIX"` 11 | 12 | cd `dirname "$0"/..` 13 | PATH="`pwd`/source/MaaUtils/MaaDeps/x-tools/llvm/bin:$PATH" 14 | 15 | mkdir -p "$INSTALL_PREFIX/symbols" 16 | find $INSTALL_PREFIX/bin -type f | while read BINARY; do 17 | echo "Process $BINARY" 18 | FILE=`basename "$BINARY"` 19 | DEBUG_FILE="$INSTALL_PREFIX/symbols/$FILE.debug" 20 | 21 | cd `dirname "$BINARY"` 22 | 23 | llvm-objcopy --only-keep-debug "$BINARY" "$BINARY.debug" 24 | llvm-objcopy --add-gnu-debuglink=$FILE.debug --strip-unneeded "$BINARY" 25 | mv "$BINARY.debug" "$DEBUG_FILE" 26 | 27 | cd - > /dev/null 28 | done 29 | -------------------------------------------------------------------------------- /docs/zh_cn/NodeJS/J1.3-打包.md: -------------------------------------------------------------------------------- 1 | # 打包 2 | 3 | > 注意: 本文档是关于如何使用 NodeJS 进行集成 4 | 5 | 本项目中包含二进制. `@maaxyz/maa-node`包会从`@maaxyz/maa-node-${platform}-${arch}`包中获取对应`MaaNode.node`. 同时, 由于被加载的`MaaNode.node`动态链接了`MaaFramework`库, 且`Adb`控制器依赖`AgentBinary`, 建议直接将`@maaxyz/maa-node`作为外部依赖不参与打包. 6 | 7 | 如果你确实想要打包, 需要注意以下要点: 8 | 9 | * 通常打包工具只能发现`MaaNode.node`, 但不会意识到它的依赖. `MaaNode.node`旁边的所有`dll/so/dylib`应当一并放置在`MaaNode.node`同目录中. 10 | * `Adb`控制器会使用**库脚本**所在目录的`../agent`目录来搜索MaaAgentBinary. 也可以手动在代码中配置. 11 | 12 | ## maa-node-template 13 | 14 | 可以参考 [maa-node-template](https://github.com/neko-para/maa-node-template). 该模板提供了简易的electron打包方案. 15 | 16 | ```shell 17 | npm run build # 使用esbuild构建项目, 参考scripts/build.mjs 18 | npm run watch # 使用esbuild和vite热重载, 参考scripts/watch.mjs 19 | npm run package # 使用electron-forge进行打包 20 | ``` 21 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Screencap/Minicap/MinicapDirect.cpp: -------------------------------------------------------------------------------- 1 | #include "MinicapDirect.h" 2 | 3 | #include 4 | 5 | #include "MaaUtils/Logger.h" 6 | #include "MaaUtils/NoWarningCV.hpp" 7 | 8 | MAA_CTRL_UNIT_NS_BEGIN 9 | 10 | MinicapDirect::~MinicapDirect() 11 | { 12 | deinit_binary(); 13 | } 14 | 15 | bool MinicapDirect::init() 16 | { 17 | return init_binary(); 18 | } 19 | 20 | std::optional MinicapDirect::screencap() 21 | { 22 | auto res = binary_->invoke_bin_and_read_pipe( 23 | std::format("-P {}x{}@{}x{}/{} -s", display_width_, display_height_, display_width_, display_height_, 0)); 24 | 25 | if (!res) { 26 | return std::nullopt; 27 | } 28 | 29 | return screencap_helper_.process_data(*res, ScreencapHelper::trunc_decode_jpg); 30 | } 31 | 32 | MAA_CTRL_UNIT_NS_END 33 | -------------------------------------------------------------------------------- /tools/nupkgs/Maa.Framework.Runtimes.nuspec: -------------------------------------------------------------------------------- 1 | Maa.Framework.Runtimes 2 | MaaFramework Runtimes 3 | An automation black-box testing framework based on image recognition. 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.github/workflows/mirrorchyan_release_note.yml: -------------------------------------------------------------------------------- 1 | name: mirrorchyan_release_note 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | tag: 7 | default: '' 8 | required: false 9 | release: 10 | types: [edited] 11 | 12 | jobs: 13 | mirrorchyan: 14 | if: ${{ github.repository_owner == 'MaaXYZ' }} 15 | runs-on: macos-latest 16 | 17 | steps: 18 | - id: uploading 19 | uses: MirrorChyan/release-note-action@v1 20 | with: 21 | mirrorchyan_rid: MaaFramework 22 | version_name: ${{ inputs.tag }} 23 | 24 | owner: MaaXYZ 25 | repo: MaaFramework 26 | upload_token: ${{ secrets.MirrorChyanUploadToken }} 27 | github_token: ${{ secrets.GITHUB_TOKEN }} 28 | -------------------------------------------------------------------------------- /3rdparty/include/MaaPlugin/MaaPluginAPI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "MaaPluginPort.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" 9 | { 10 | #endif 11 | 12 | MAA_PLUGIN_API const char* GetPluginVersion(void); 13 | 14 | MAA_PLUGIN_API uint32_t GetApiVersion(void); 15 | 16 | MAA_PLUGIN_API void OnResourceEvent(void* handle, const char* message, const char* details_json, void* trans_arg); 17 | MAA_PLUGIN_API void OnControllerEvent(void* handle, const char* message, const char* details_json, void* trans_arg); 18 | MAA_PLUGIN_API void OnTaskerEvent(void* handle, const char* message, const char* details_json, void* trans_arg); 19 | MAA_PLUGIN_API void OnContextEvent(void* handle, const char* message, const char* details_json, void* trans_arg); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /include/MaaFramework/MaaAPI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MaaDef.h" // IWYU pragma: export 4 | 5 | #include "Global/MaaGlobal.h" 6 | 7 | #include "Instance/MaaContext.h" 8 | #include "Instance/MaaController.h" 9 | #include "Instance/MaaCustomController.h" 10 | #include "Instance/MaaResource.h" 11 | #include "Instance/MaaTasker.h" 12 | 13 | #include "Utility/MaaBuffer.h" 14 | #include "Utility/MaaUtility.h" 15 | 16 | /** 17 | * @mainpage MaaFramework API Reference 18 | * 19 | * @section intro_sec Introduction 20 | * 21 | * MaaFramework is a toolset used to create automated tests under various environments such as 22 | * Windows and Android emulators. 23 | * 24 | * For starter, take a look at the following pages: 25 | * 26 | * - MaaTasker.h 27 | * - MaaController.h 28 | * - MaaResource.h 29 | * - MaaContext.h 30 | * 31 | */ 32 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/foundation/spec.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // #define MAA_JS_IMPL_IS_NODEJS 4 | // #define MAA_JS_IMPL_IS_QUICKJS 5 | 6 | #if !defined(MAA_JS_IMPL_IS_NODEJS) && !defined(MAA_JS_IMPL_IS_QUICKJS) 7 | #define MAA_JS_IMPL_IS_NODEJS 8 | // #define MAA_JS_IMPL_IS_QUICKJS 9 | #endif 10 | 11 | #include "spec/async.h" // IWYU pragma: export 12 | #include "spec/callback.h" // IWYU pragma: export 13 | #include "spec/class.h" // IWYU pragma: export 14 | #include "spec/convert.h" // IWYU pragma: export 15 | #include "spec/instric.h" // IWYU pragma: export 16 | #include "spec/utils.h" // IWYU pragma: export 17 | #include "spec/wrapper.h" // IWYU pragma: export 18 | 19 | #ifdef MAA_JS_IMPL_IS_QUICKJS 20 | #include "spec/quickjs/bridge.h" // IWYU pragma: export 21 | #endif 22 | 23 | #include "jsutils.h" // IWYU pragma: export 24 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/apis/client.d.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | namespace maa { 3 | class Client { 4 | constructor(identifier?: string) 5 | 6 | destroy(): void 7 | get identifier(): string 8 | bind_resource(resource: Resource): void 9 | register_resource_sink(resource: Resource): void 10 | register_controller_sink(controller: Controller): void 11 | register_tasker_sink(tasker: Tasker): void 12 | connect(): Promise 13 | disconnect(): void 14 | get connected(): boolean 15 | get alive(): boolean 16 | set timeout(ms: Uint64) 17 | get custom_recognition_list(): string[] | null 18 | get custom_action_list(): string[] | null 19 | } 20 | } 21 | } 22 | 23 | export {} 24 | -------------------------------------------------------------------------------- /sample/interface_zh.json: -------------------------------------------------------------------------------- 1 | { 2 | "MyDemo3": "示例程序3", 3 | "demo3-png": "./assets/demo-zh.png", 4 | "安卓端": "安卓设备", 5 | "电脑端": "Windows 桌面应用", 6 | "官服资源": "官方服务器资源包", 7 | "B站资源": "Bilibili 服务器资源包", 8 | "收取荒原": "收取荒原资源", 9 | "每日心相": "每日心相(意志解析)", 10 | "常规作战": "常规作战任务", 11 | "活动任务": "活动:绿湖噩梦 17 艰难", 12 | "领取奖励": "领取每日奖励", 13 | "选择作战关卡": "请选择要刷的关卡", 14 | "3-9厄险": "3-9 厄险(百灵百验鸟)", 15 | "4-20厄险": "4-20 厄险(双头形骨架)", 16 | "章节号": "章节号", 17 | "难度": "关卡难度", 18 | "超时时间": "等待超时时间(毫秒)", 19 | "1次": "复现 1 次", 20 | "2次": "复现 2 次", 21 | "3次": "复现 3 次", 22 | "4次": "复现 4 次", 23 | "是": "是", 24 | "否": "否", 25 | "刷完全部体力": "是否刷完全部体力", 26 | "使用理智药": "是否使用理智药", 27 | "使用": "使用", 28 | "不使用": "不使用", 29 | "刷完后操作": "刷完关卡后的操作", 30 | "返回主界面": "返回主界面", 31 | "继续战斗": "继续战斗", 32 | "退出游戏": "退出游戏" 33 | } -------------------------------------------------------------------------------- /tools/nupkgs/Head.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $version$ 5 | MAA Team 6 | false 7 | LGPL-3.0-only 8 | maa-logo_128x128.png 9 | Release notes are at https://github.com/MaaXYZ/MaaFramework/releases. 10 | Copyright © 2021-$year$ MAA Team and Contributers. All rights reserved. 11 | MAA native runtimes C++ computer-vision black-box-testing 12 | https://maafw.xyz/ 13 | 14 | README.md -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/General/DeviceInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Base/UnitBase.h" 4 | 5 | #include "Common/Conf.h" 6 | 7 | MAA_CTRL_UNIT_NS_BEGIN 8 | 9 | class DeviceInfo : public UnitBase 10 | { 11 | public: 12 | struct DisplayInfo 13 | { 14 | int w = 0; 15 | int h = 0; 16 | int r = 0; 17 | }; 18 | 19 | public: 20 | virtual ~DeviceInfo() override = default; 21 | 22 | public: // from UnitBase 23 | virtual bool parse(const json::value& config) override; 24 | 25 | public: 26 | std::optional request_uuid(); 27 | std::optional request_resolution(); 28 | std::optional request_orientation(); 29 | 30 | private: 31 | ProcessArgvGenerator uuid_argv_; 32 | ProcessArgvGenerator resolution_argv_; 33 | ProcessArgvGenerator orientation_argv_; 34 | }; 35 | 36 | MAA_CTRL_UNIT_NS_END 37 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/foundation/spec/types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef MAA_JS_IMPL_IS_NODEJS 6 | #include "nodejs/types.h" // IWYU pragma: export 7 | #endif 8 | 9 | #ifdef MAA_JS_IMPL_IS_QUICKJS 10 | #include "quickjs/types.h" // IWYU pragma: export 11 | #endif 12 | 13 | namespace maajs 14 | { 15 | 16 | using RawCallback = std::function; 17 | 18 | using NativeMarkerFunc = std::function; 19 | 20 | struct NativeClassBase 21 | { 22 | EnvType env { nullptr }; 23 | 24 | NativeClassBase() = default; 25 | virtual ~NativeClassBase() = default; 26 | 27 | virtual void init_bind([[maybe_unused]] ObjectType self) {} 28 | 29 | virtual void gc_mark([[maybe_unused]] NativeMarkerFunc marker) {} 30 | 31 | virtual std::string to_string() { return ""; } 32 | }; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /3rdparty/include/gzip/utils.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace gzip 4 | { 5 | 6 | // These live in gzip.hpp because it doesnt need to use deps. 7 | // Otherwise, they would need to live in impl files if these methods used 8 | // zlib structures or functions like inflate/deflate) 9 | inline bool is_compressed(const char* data, std::size_t size) 10 | { 11 | return size > 2 12 | && ( 13 | // zlib 14 | (static_cast(data[0]) == 0x78 15 | && (static_cast(data[1]) == 0x9C || static_cast(data[1]) == 0x01 16 | || static_cast(data[1]) == 0xDA 17 | || static_cast(data[1]) == 0x5E)) 18 | || 19 | // gzip 20 | (static_cast(data[0]) == 0x1F && static_cast(data[1]) == 0x8B)); 21 | } 22 | } // namespace gzip 23 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/General/Connection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Base/UnitBase.h" 6 | 7 | #include "Common/Conf.h" 8 | 9 | MAA_CTRL_UNIT_NS_BEGIN 10 | 11 | class Connection : public UnitBase 12 | { 13 | public: 14 | Connection(std::filesystem::path adb_path, std::string adb_serial); 15 | virtual ~Connection() override = default; 16 | 17 | public: // from UnitBase 18 | virtual bool parse(const json::value& config) override; 19 | 20 | public: 21 | bool connect(); 22 | bool kill_server(); 23 | bool test_connection(); 24 | 25 | private: 26 | bool connect_remote(); 27 | 28 | std::filesystem::path adb_path_; 29 | std::string adb_serial_; 30 | 31 | ProcessArgvGenerator connect_argv_; 32 | ProcessArgvGenerator kill_server_argv_; 33 | ProcessArgvGenerator test_connection_argv_; 34 | }; 35 | 36 | MAA_CTRL_UNIT_NS_END 37 | -------------------------------------------------------------------------------- /3rdparty/include/MaaPlugin/MaaPluginPort.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // The function exported symbols 4 | #if defined _WIN32 || defined __CYGWIN__ 5 | #define MAA_PLUGIN_DLL_IMPORT __declspec(dllimport) 6 | #define MAA_PLUGIN_DLL_EXPORT __declspec(dllexport) 7 | #define MAA_PLUGIN_DLL_LOCAL 8 | #else 9 | #if __GNUC__ >= 4 10 | #define MAA_PLUGIN_DLL_IMPORT __attribute__((visibility("default"))) 11 | #define MAA_PLUGIN_DLL_EXPORT __attribute__((visibility("default"))) 12 | #define MAA_PLUGIN_DLL_LOCAL __attribute__((visibility("hidden"))) 13 | #else 14 | #define MAA_PLUGIN_DLL_IMPORT 15 | #define MAA_PLUGIN_DLL_EXPORT 16 | #define MAA_PLUGIN_DLL_LOCAL 17 | #endif 18 | #endif 19 | 20 | #ifdef MAA_PLUGIN_EXPORTS // defined if we are building the DLL (instead of using it) 21 | #define MAA_PLUGIN_API MAA_PLUGIN_DLL_EXPORT 22 | #else 23 | #define MAA_PLUGIN_API MAA_PLUGIN_DLL_IMPORT 24 | #endif // MAA_PLUGIN_EXPORTS 25 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/foundation/spec/instric.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "instric.forward.h" // IWYU pragma: export 4 | 5 | #ifdef MAA_JS_IMPL_IS_NODEJS 6 | #include "nodejs/instric.impl.h" // IWYU pragma: export 7 | #endif 8 | 9 | #ifdef MAA_JS_IMPL_IS_QUICKJS 10 | #include "quickjs/instric.impl.h" // IWYU pragma: export 11 | #endif 12 | 13 | namespace maajs 14 | { 15 | 16 | inline FunctionType MakeFunction(EnvType env, const char* name, int argc, RawCallback func, std::shared_ptr capture) 17 | { 18 | return MakeFunction(env, name, argc, func, [capture](auto marker) { marker(capture->Value()); }); 19 | } 20 | 21 | inline FunctionType MakeFunction(EnvType env, const char* name, int argc, RawCallback func, std::shared_ptr capture) 22 | { 23 | return MakeFunction(env, name, argc, func, [capture](auto marker) { marker(capture->Value()); }); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /source/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(WITH_ADB_CONTROLLER) 2 | add_subdirectory(MaaAdbControlUnit) 3 | endif() 4 | 5 | if(WITH_WIN32_CONTROLLER) 6 | add_subdirectory(MaaWin32ControlUnit) 7 | endif() 8 | 9 | if(WITH_DBG_CONTROLLER) 10 | add_subdirectory(MaaDbgControlUnit) 11 | endif() 12 | 13 | if(WITH_CUSTOM_CONTROLLER) 14 | add_subdirectory(MaaCustomControlUnit) 15 | endif() 16 | 17 | if(WITH_PLAYCOVER_CONTROLLER) 18 | add_subdirectory(MaaPlayCoverControlUnit) 19 | endif() 20 | 21 | add_subdirectory(LibraryHolder) 22 | add_subdirectory(MaaFramework) 23 | add_subdirectory(MaaToolkit) 24 | 25 | if(BUILD_PICLI) 26 | add_subdirectory(MaaPiCli) 27 | endif() 28 | 29 | if(WITH_MAA_AGENT) 30 | add_subdirectory(MaaAgentClient) 31 | add_subdirectory(MaaAgentServer) 32 | endif() 33 | 34 | add_subdirectory(binding) 35 | 36 | # if(ENABLE_CPP20_MODULES) 37 | # add_subdirectory(modules) 38 | # endif() 39 | -------------------------------------------------------------------------------- /source/MaaToolkit/API/MaaToolkitBufferTypes.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | struct MaaToolkitAdbDevice 9 | { 10 | public: 11 | virtual ~MaaToolkitAdbDevice() = default; 12 | 13 | virtual const std::string& name() const = 0; 14 | virtual const std::string& adb_path() const = 0; 15 | virtual const std::string& address() const = 0; 16 | virtual MaaAdbScreencapMethod screencap_methods() const = 0; 17 | virtual MaaAdbInputMethod input_methods() const = 0; 18 | virtual const std::string& config() const = 0; 19 | }; 20 | 21 | struct MaaToolkitDesktopWindow 22 | { 23 | public: 24 | virtual ~MaaToolkitDesktopWindow() = default; 25 | 26 | virtual void* handle() const = 0; 27 | virtual const std::string& class_name() const = 0; 28 | virtual const std::string& window_name() const = 0; 29 | }; 30 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/plugin/runtime.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | struct QuickJSRuntimeData; 8 | 9 | class QuickJSRuntime 10 | { 11 | public: 12 | QuickJSRuntime(); 13 | ~QuickJSRuntime(); 14 | 15 | void eval_file(std::string file); 16 | void eval_script(std::string script); 17 | void exec_loop(bool auto_quit = true); 18 | std::string get_result(); 19 | 20 | void dispatch_resource_sink(MaaResource* handle, const char* message, const char* details_json); 21 | void dispatch_controller_sink(MaaController* handle, const char* message, const char* details_json); 22 | void dispatch_tasker_sink(MaaTasker* handle, const char* message, const char* details_json); 23 | void dispatch_context_sink(MaaContext* handle, const char* message, const char* details_json); 24 | 25 | private: 26 | QuickJSRuntimeData* d_; 27 | }; 28 | -------------------------------------------------------------------------------- /source/include/ProjectInterface/Parser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "Types.h" 9 | 10 | #include "Common/Conf.h" 11 | 12 | MAA_PROJECT_INTERFACE_NS_BEGIN 13 | 14 | class Parser 15 | { 16 | public: 17 | static std::optional parse_interface(const std::filesystem::path& path); 18 | static std::optional parse_interface(const json::value& json); 19 | static std::optional parse_config(const std::filesystem::path& path); 20 | static std::optional parse_config(const json::value& json); 21 | 22 | static bool check_configuration(const InterfaceData& data, Configuration& config); 23 | 24 | private: 25 | static bool check_task(const InterfaceData& data, Configuration::Task& config_task); 26 | }; 27 | 28 | MAA_PROJECT_INTERFACE_NS_END 29 | -------------------------------------------------------------------------------- /source/MaaFramework/Resource/TemplateResMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "Common/Conf.h" 7 | #include "MaaUtils/NoWarningCVMat.hpp" 8 | #include "MaaUtils/NonCopyable.hpp" 9 | 10 | MAA_RES_NS_BEGIN 11 | 12 | class TemplateResMgr : public NonCopyable 13 | { 14 | public: 15 | bool lazy_load(const std::filesystem::path& path); 16 | bool load_file(const std::filesystem::path& path); 17 | 18 | void clear(); 19 | 20 | public: 21 | std::vector get_image(const std::string& name); 22 | void set_image(const std::string& name, const cv::Mat& image); 23 | 24 | private: 25 | std::vector load(const std::string& name); 26 | 27 | std::vector roots_ = { "" }; // for filepath without prefix 28 | 29 | std::unordered_map> image_cache_; 30 | }; 31 | 32 | MAA_RES_NS_END 33 | -------------------------------------------------------------------------------- /source/modules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MODULE_PREFIX "share/MaaFramework/modules") 2 | 3 | add_library(MaaFrameworkModule) 4 | target_sources(MaaFrameworkModule PUBLIC FILE_SET cppms TYPE CXX_MODULES FILES 5 | $ 6 | $ 7 | $ 8 | $ 9 | $ 10 | $ 11 | $ 12 | $ 13 | ) 14 | target_compile_features(MaaFrameworkModule INTERFACE cxx_std_20) 15 | target_link_libraries(MaaFrameworkModule PRIVATE MaaInterface) 16 | 17 | install( 18 | TARGETS MaaFrameworkModule 19 | EXPORT MaaFrameworkTargets 20 | FILE_SET cppms DESTINATION ${MODULE_PREFIX}) 21 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/General/AdbCommand.cpp: -------------------------------------------------------------------------------- 1 | #include "AdbCommand.h" 2 | 3 | #include 4 | 5 | #include "MaaUtils/Logger.h" 6 | #include "MaaUtils/StringMisc.hpp" 7 | 8 | MAA_CTRL_UNIT_NS_BEGIN 9 | 10 | bool AdbCommand::parse(const json::value& config) 11 | { 12 | static const json::array kDefaultShellArgv = { 13 | "{ADB}", "-s", "{ADB_SERIAL}", "shell", "{CMD}", 14 | }; 15 | 16 | return parse_command("Shell", config, kDefaultShellArgv, shell_argv); 17 | } 18 | 19 | std::optional AdbCommand::shell(const std::string& cmd, std::chrono::milliseconds timeout) 20 | { 21 | LogFunc << VAR(cmd) << VAR(timeout); 22 | 23 | merge_replacement({ { "{CMD}", cmd } }); 24 | 25 | auto argv_opt = shell_argv.gen(argv_replace_); 26 | if (!argv_opt) { 27 | return std::nullopt; 28 | } 29 | 30 | return startup_and_read_pipe(*argv_opt, timeout); 31 | } 32 | 33 | MAA_CTRL_UNIT_NS_END 34 | -------------------------------------------------------------------------------- /source/MaaPiCli/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB_RECURSE maa_pi_cli_src *.h *.hpp *.cpp) 2 | file(GLOB_RECURSE maa_pi_cli_header ${MAA_PRIVATE_INC}/MaaPiCli/*) 3 | 4 | add_executable(MaaPiCli ${maa_pi_cli_src} ${maa_pi_cli_header}) 5 | 6 | target_include_directories(MaaPiCli 7 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${MAA_PRIVATE_INC} ${MAA_PUBLIC_INC}) 8 | 9 | target_link_libraries(MaaPiCli PRIVATE MaaUtils MaaFramework MaaToolkit MaaAgentClient Boost::system ${OpenCV_LIBS}) 10 | 11 | if(LINUX) 12 | target_link_libraries(MaaPiCli PRIVATE pthread dl) 13 | endif() 14 | 15 | add_dependencies(MaaPiCli MaaUtils MaaFramework MaaToolkit MaaAgentClient) 16 | 17 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${maa_pi_cli_src}) 18 | 19 | install(TARGETS MaaPiCli 20 | RUNTIME DESTINATION bin 21 | LIBRARY DESTINATION bin 22 | ) 23 | 24 | if(WIN32) 25 | install(FILES $ DESTINATION symbol OPTIONAL) 26 | endif() -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Screencap/Encode.cpp: -------------------------------------------------------------------------------- 1 | #include "Encode.h" 2 | 3 | #include "MaaUtils/Logger.h" 4 | 5 | MAA_CTRL_UNIT_NS_BEGIN 6 | 7 | bool ScreencapEncode::parse(const json::value& config) 8 | { 9 | static const json::array kDefaultScreencapEncodeArgv = { 10 | "{ADB}", "-s", "{ADB_SERIAL}", "exec-out", "screencap -p", 11 | }; 12 | 13 | return parse_command("ScreencapEncode", config, kDefaultScreencapEncodeArgv, screencap_encode_argv_); 14 | } 15 | 16 | std::optional ScreencapEncode::screencap() 17 | { 18 | auto argv_opt = screencap_encode_argv_.gen(argv_replace_); 19 | if (!argv_opt) { 20 | return std::nullopt; 21 | } 22 | 23 | auto output_opt = startup_and_read_pipe(*argv_opt); 24 | if (!output_opt) { 25 | return std::nullopt; 26 | } 27 | 28 | return screencap_helper_.process_data(*output_opt, ScreencapHelper::decode_png); 29 | } 30 | 31 | MAA_CTRL_UNIT_NS_END 32 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/apis/convert.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../foundation/spec.h" 6 | 7 | namespace maajs 8 | { 9 | 10 | template <> 11 | struct JSConvert 12 | { 13 | static std::string name() { return "array"; }; 14 | 15 | static MaaRect from_value(ValueType val) 16 | { 17 | auto arr = JSConvert>::from_value(val); 18 | return { 19 | .x = arr[0], 20 | .y = arr[1], 21 | .width = arr[2], 22 | .height = arr[3], 23 | }; 24 | } 25 | 26 | static ValueType to_value(EnvType env, const MaaRect& val) 27 | { 28 | return JSConvert>::to_value( 29 | env, 30 | { 31 | val.x, 32 | val.y, 33 | val.width, 34 | val.height, 35 | }); 36 | } 37 | }; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Screencap/RawWithGzip.cpp: -------------------------------------------------------------------------------- 1 | #include "RawWithGzip.h" 2 | 3 | #include "MaaUtils/Logger.h" 4 | 5 | MAA_CTRL_UNIT_NS_BEGIN 6 | 7 | bool ScreencapRawWithGzip::parse(const json::value& config) 8 | { 9 | static const json::array kDefaultScreencapRawWithGzipArgv = { 10 | "{ADB}", "-s", "{ADB_SERIAL}", "exec-out", "screencap | gzip -1", 11 | }; 12 | 13 | return parse_command("ScreencapRawWithGzip", config, kDefaultScreencapRawWithGzipArgv, screencap_raw_with_gzip_argv_); 14 | } 15 | 16 | std::optional ScreencapRawWithGzip::screencap() 17 | { 18 | auto argv_opt = screencap_raw_with_gzip_argv_.gen(argv_replace_); 19 | if (!argv_opt) { 20 | return std::nullopt; 21 | } 22 | 23 | auto output_opt = startup_and_read_pipe(*argv_opt); 24 | if (!output_opt) { 25 | return std::nullopt; 26 | } 27 | 28 | return screencap_helper_.process_data(*output_opt, ScreencapHelper::decode_gzip); 29 | } 30 | 31 | MAA_CTRL_UNIT_NS_END 32 | -------------------------------------------------------------------------------- /source/MaaToolkit/API/MaaToolkitConfig.cpp: -------------------------------------------------------------------------------- 1 | #include "MaaToolkit/Config/MaaToolkitConfig.h" 2 | 3 | #include 4 | 5 | #include "Config/GlobalOptionConfig.h" 6 | #include "MaaUtils/Logger.h" 7 | #include "MaaUtils/Platform.h" 8 | #include "MaaUtils/Runtime.h" 9 | 10 | MaaBool MaaToolkitConfigInitOption(const char* user_path, const char* default_json) 11 | { 12 | LogInfo << VAR(user_path) << VAR(default_json); 13 | 14 | if (!user_path) { 15 | LogError << "user_path is null"; 16 | return false; 17 | } 18 | 19 | if (!default_json) { 20 | LogError << "default_json is null"; 21 | return false; 22 | } 23 | 24 | auto json_opt = json::parse(default_json); 25 | if (!json_opt) { 26 | LogError << "failed to parse json" << default_json; 27 | return false; 28 | } 29 | 30 | auto& config = MAA_TOOLKIT_NS::GlobalOptionConfig::get_instance(); 31 | return config.init(MAA_NS::path(user_path), *json_opt); 32 | } 33 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/apis/job.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "../foundation/spec.h" 8 | 9 | struct JobImpl : public maajs::NativeClassBase 10 | { 11 | maajs::ObjectRefType source; 12 | MaaId id; 13 | std::optional status; 14 | 15 | maajs::ValueType get_source(); 16 | MaaId get_id(); 17 | MaaStatus get_status(); 18 | maajs::PromiseType wait(maajs::ValueType self, maajs::EnvType env); 19 | virtual maajs::ValueType get(); 20 | bool get_done(); 21 | bool get_succeeded(); 22 | bool get_failed(); 23 | bool get_running(); 24 | bool get_pending(); 25 | 26 | std::string to_string() override; 27 | 28 | constexpr static char name[] = "Job"; 29 | 30 | static JobImpl* ctor(const maajs::CallbackInfo& info); 31 | static void init_proto(maajs::ObjectType proto, maajs::FunctionType); 32 | void gc_mark(maajs::NativeMarkerFunc marker) override; 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /source/binding/NodeJS/release/maa-node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@maaxyz/maa-node", 3 | "author": "nekosu", 4 | "main": "./dist/index-client.js", 5 | "types": "./dist/index-client.d.ts", 6 | "exports": { 7 | ".": { 8 | "default": "./dist/index-client.js", 9 | "types": "./dist/index-client.d.ts" 10 | }, 11 | "./server": { 12 | "default": "./dist/index-server.js", 13 | "types": "./dist/index-server.d.ts" 14 | } 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git://github.com/MaaXYZ/MaaFramework.git" 19 | }, 20 | "engines": { 21 | "node": ">= 20.0.0" 22 | }, 23 | "devDependencies": { 24 | "@trivago/prettier-plugin-sort-imports": "^4.3.0", 25 | "@tsconfig/node20": "^20.1.4", 26 | "@types/node": "^20.17.22", 27 | "esbuild": "^0.25.0", 28 | "prettier": "^3.5.2", 29 | "typescript": "^5.8.2" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /source/MaaPlayCoverControlUnit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB_RECURSE maa_playcover_control_unit_src *.h *.hpp *.cpp) 2 | file(GLOB_RECURSE maa_playcover_control_unit_header ${MAA_PRIVATE_INC}/ControlUnit/PlayCoverControlUnitAPI.h ${MAA_PRIVATE_INC}/ControlUnit/ControlUnitAPI.h) 3 | 4 | add_library(MaaPlayCoverControlUnit SHARED ${maa_playcover_control_unit_src} ${maa_playcover_control_unit_header}) 5 | 6 | target_include_directories(MaaPlayCoverControlUnit 7 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${MAA_PRIVATE_INC} ${MAA_PUBLIC_INC}) 8 | 9 | target_link_libraries(MaaPlayCoverControlUnit PRIVATE MaaUtils ${OpenCV_LIBS} Boost::system) 10 | 11 | target_compile_definitions(MaaPlayCoverControlUnit PRIVATE MAA_CONTROL_UNIT_EXPORTS) 12 | 13 | add_dependencies(MaaPlayCoverControlUnit MaaUtils) 14 | 15 | install( 16 | TARGETS MaaPlayCoverControlUnit 17 | RUNTIME DESTINATION bin 18 | LIBRARY DESTINATION bin 19 | ) 20 | 21 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${maa_playcover_control_unit_src}) 22 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/apis/job.d.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | namespace maa { 3 | interface JobSource { 4 | status(id: Id): Status 5 | wait(id: Id): Promise 6 | } 7 | 8 | class Job, Result = void> { 9 | constructor(source: Source, id: Id) 10 | 11 | get source(): Source 12 | get id(): Id 13 | get status(): Status 14 | wait(): Promise & { 15 | status: Promise 16 | done: Promise 17 | succeeded: Promise 18 | failed: Promise 19 | get(): Promise 20 | } 21 | get(): Result 22 | get done(): boolean 23 | get succeeded(): boolean 24 | get failed(): boolean 25 | get running(): boolean 26 | get pending(): boolean 27 | } 28 | } 29 | } 30 | 31 | export {} 32 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/apis/server.d.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | namespace maa { 3 | const Server: { 4 | register_custom_recognition(name: string, func: CustomRecognitionCallback): void 5 | register_custom_action(name: string, func: CustomActionCallback): void 6 | 7 | add_resource_sink(cb: (res: Resource, msg: ResourceNotify) => MaybePromise): void 8 | add_controller_sink( 9 | cb: (ctrl: Controller, msg: ControllerNotify) => MaybePromise, 10 | ): void 11 | add_tasker_sink(cb: (tsk: Tasker, msg: TaskerNotify) => MaybePromise): void 12 | add_context_sink( 13 | cb: (ctx: Context, msg: TaskerContextNotify) => MaybePromise, 14 | ): void 15 | 16 | start_up(identifier: string): Promise 17 | shut_down(): Promise 18 | join(): Promise 19 | detach(): void 20 | } 21 | } 22 | } 23 | 24 | export {} 25 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Python Binding Test", 9 | "type": "debugpy", 10 | "request": "launch", 11 | "program": "${workspaceFolder}/test/python/binding_test.py", 12 | "console": "integratedTerminal", 13 | "args": [ 14 | "source/binding/Python", 15 | "install", 16 | ] 17 | }, 18 | { 19 | "type": "lldb", 20 | "request": "launch", 21 | "name": "MaaPiCli - Debug", 22 | "program": "${workspaceFolder}/build/bin/Debug/MaaPiCli", 23 | "args": [], 24 | "cwd": "${workspaceFolder}", 25 | "preLaunchTask": "build_picli" 26 | } 27 | ] 28 | } -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Base/ProcessArgvGenerator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "MaaUtils/StringMisc.hpp" 10 | 11 | #include "Common/Conf.h" 12 | 13 | MAA_CTRL_UNIT_NS_BEGIN 14 | 15 | class ProcessArgvGenerator 16 | { 17 | public: 18 | using Replacement = std::unordered_map; 19 | 20 | struct ProcessArgv 21 | { 22 | std::filesystem::path exec; 23 | std::vector args; 24 | }; 25 | 26 | public: 27 | static std::optional create(const json::array& arr); 28 | 29 | ProcessArgvGenerator() = default; 30 | 31 | explicit ProcessArgvGenerator(std::vector raw) 32 | : raw_(std::move(raw)) 33 | { 34 | } 35 | 36 | std::optional gen(const Replacement& replacement) const; 37 | 38 | private: 39 | std::vector raw_; 40 | }; 41 | 42 | MAA_CTRL_UNIT_NS_END 43 | -------------------------------------------------------------------------------- /source/binding/NodeJS/release/maa-node/src/index-client.js: -------------------------------------------------------------------------------- 1 | if (!globalThis.maa) { 2 | switch (`${process.platform}-${process.arch}`) { 3 | case 'win32-x64': 4 | globalThis.maa = require('@maaxyz/maa-node-win32-x64') 5 | break 6 | case 'win32-arm64': 7 | globalThis.maa = require('@maaxyz/maa-node-win32-arm64') 8 | break 9 | case 'linux-x64': 10 | globalThis.maa = require('@maaxyz/maa-node-linux-x64') 11 | break 12 | case 'linux-arm64': 13 | globalThis.maa = require('@maaxyz/maa-node-linux-arm64') 14 | break 15 | case 'darwin-x64': 16 | globalThis.maa = require('@maaxyz/maa-node-darwin-x64') 17 | break 18 | case 'darwin-arm64': 19 | globalThis.maa = require('@maaxyz/maa-node-darwin-arm64') 20 | break 21 | default: 22 | globalThis.maa = {} 23 | break 24 | } 25 | } 26 | 27 | module.exports = globalThis.maa 28 | -------------------------------------------------------------------------------- /test/pipeline/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "module/PipelineSmoking.h" 4 | #include "module/RunWithoutFile.h" 5 | 6 | #include "MaaFramework/MaaAPI.h" 7 | 8 | int main([[maybe_unused]] int argc, char** argv) 9 | { 10 | auto cur_dir = std::filesystem::path(argv[0]).parent_path(); 11 | auto testset_dir = cur_dir.parent_path() / "test"; 12 | if (argc == 2) { 13 | testset_dir = argv[1]; 14 | } 15 | 16 | std::string logging_dir = (cur_dir / "debug").string(); 17 | MaaGlobalSetOption(MaaGlobalOption_LogDir, static_cast(logging_dir.data()), logging_dir.size()); 18 | bool on = true; 19 | MaaGlobalSetOption(MaaGlobalOption_SaveDraw, &on, sizeof(on)); 20 | MaaLoggingLevel lv = MaaLoggingLevel_Info; 21 | MaaGlobalSetOption(MaaGlobalOption_StdoutLevel, &lv, sizeof(lv)); 22 | 23 | if (!run_without_file(testset_dir)) { 24 | return -1; 25 | } 26 | if (!pipeline_smoking(testset_dir)) { 27 | return -1; 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Screencap/RawByNetcat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Base/UnitBase.h" 4 | 5 | #include "MaaUtils/IOStream/SockIOStream.h" 6 | #include "ScreencapHelper.h" 7 | 8 | #include "Common/Conf.h" 9 | 10 | MAA_CTRL_UNIT_NS_BEGIN 11 | 12 | class ScreencapRawByNetcat : public ScreencapBase 13 | { 14 | public: 15 | virtual ~ScreencapRawByNetcat() override = default; 16 | 17 | public: // from UnitBase 18 | virtual bool parse(const json::value& config) override; 19 | 20 | public: // from ScreencapBase 21 | virtual bool init() override; 22 | 23 | virtual std::optional screencap() override; 24 | 25 | private: 26 | std::optional request_netcat_address(); 27 | 28 | ProcessArgvGenerator screencap_raw_by_netcat_argv_; 29 | ProcessArgvGenerator netcat_address_argv_; 30 | 31 | std::string netcat_address_; 32 | 33 | std::shared_ptr io_factory_ = nullptr; 34 | std::shared_ptr sock_io_ = nullptr; 35 | }; 36 | 37 | MAA_CTRL_UNIT_NS_END 38 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/foundation/spec/nodejs/async.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../utils.h" 6 | 7 | namespace maajs 8 | { 9 | template 10 | struct AsyncWork : public Napi::AsyncWorker 11 | { 12 | AsyncWork(EnvType env, std::function exec) 13 | : Napi::AsyncWorker(env) 14 | , exec(exec) 15 | , deferred(env) 16 | { 17 | } 18 | 19 | void Execute() override { result = exec(); } 20 | 21 | void OnOK() override 22 | { 23 | try { 24 | deferred.Resolve(JSConvert::to_value(Env(), result)); 25 | } 26 | catch (const MaaError& exc) { 27 | deferred.Reject(Napi::String::New(Env(), exc.what())); 28 | } 29 | } 30 | 31 | void OnError(const Napi::Error& err) override { deferred.Reject(err.Value()); } 32 | 33 | PromiseType Promise() { return deferred.Promise(); } 34 | 35 | std::function exec; 36 | Ret result; 37 | Napi::Promise::Deferred deferred; 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /source/MaaToolkit/AdbDevice/AdbDeviceWin32Finder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(_WIN32) 4 | 5 | #include 6 | #include 7 | 8 | #include "AdbDeviceFinder.h" 9 | #include "Common/Conf.h" 10 | #include "MaaUtils/SingletonHolder.hpp" 11 | 12 | MAA_TOOLKIT_NS_BEGIN 13 | 14 | class AdbDeviceWin32Finder 15 | : public SingletonHolder 16 | , public AdbDeviceFinder 17 | { 18 | friend class SingletonHolder; 19 | 20 | public: 21 | virtual ~AdbDeviceWin32Finder() override = default; 22 | 23 | protected: 24 | virtual const EmulatorConstDataMap& get_emulator_const_data() const override; 25 | virtual std::vector find_by_emulator_tool(const Emulator& emulator) const override; 26 | 27 | private: 28 | AdbDeviceWin32Finder() = default; 29 | 30 | std::vector find_mumu_devices(const Emulator& emulator) const; 31 | std::vector find_ld_devices(const Emulator& emulator) const; 32 | }; 33 | 34 | MAA_TOOLKIT_NS_END 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /source/MaaPlayCoverControlUnit/API/PlayCoverControlUnitAPI.cpp: -------------------------------------------------------------------------------- 1 | #include "ControlUnit/PlayCoverControlUnitAPI.h" 2 | 3 | #include "MaaUtils/Logger.h" 4 | #include "Manager/PlayCoverControlUnitMgr.h" 5 | 6 | const char* MaaPlayCoverControlUnitGetVersion() 7 | { 8 | #pragma message("MaaPlayCoverControlUnit MAA_VERSION: " MAA_VERSION) 9 | 10 | return MAA_VERSION; 11 | } 12 | 13 | MaaControlUnitHandle MaaPlayCoverControlUnitCreate(const char* address, const char* uuid) 14 | { 15 | using namespace MAA_CTRL_UNIT_NS; 16 | 17 | LogFunc << VAR(address) << VAR(uuid); 18 | 19 | if (!address || !uuid || !address[0] || !uuid[0]) { 20 | LogError << "address or uuid is null or empty"; 21 | return nullptr; 22 | } 23 | 24 | auto unit_mgr = std::make_unique(address, uuid); 25 | return unit_mgr.release(); 26 | } 27 | 28 | void MaaPlayCoverControlUnitDestroy(MaaControlUnitHandle handle) 29 | { 30 | LogFunc << VAR_VOIDP(handle); 31 | 32 | if (handle) { 33 | delete handle; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /source/MaaCustomControlUnit/API/CustomControlUnitAPI.cpp: -------------------------------------------------------------------------------- 1 | #include "ControlUnit/CustomControlUnitAPI.h" 2 | 3 | #include "MaaUtils/Logger.h" 4 | #include "Manager/CustomControlUnitMgr.h" 5 | 6 | const char* MaaCustomControlUnitGetVersion() 7 | { 8 | #pragma message("MaaCustomControlUnit MAA_VERSION: " MAA_VERSION) 9 | 10 | return MAA_VERSION; 11 | } 12 | 13 | MaaCustomControlUnitHandle MaaCustomControlUnitCreate(MaaCustomControllerCallbacks* controller, void* controller_arg) 14 | { 15 | using namespace MAA_CTRL_UNIT_NS; 16 | 17 | LogFunc << VAR_VOIDP(controller) << VAR_VOIDP(controller_arg); 18 | 19 | if (!controller) { 20 | LogError << "Controller is null"; 21 | return nullptr; 22 | } 23 | 24 | auto unit_mgr = std::make_unique(controller, controller_arg); 25 | 26 | return unit_mgr.release(); 27 | } 28 | 29 | void MaaCustomControlUnitDestroy(MaaCustomControlUnitHandle handle) 30 | { 31 | LogFunc << VAR_VOIDP(handle); 32 | 33 | if (handle) { 34 | delete handle; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /source/binding/NodeJS/release/maa-node/src/index-server.js: -------------------------------------------------------------------------------- 1 | if (!globalThis.maa) { 2 | switch (`${process.platform}-${process.arch}`) { 3 | case 'win32-x64': 4 | globalThis.maa = require('@maaxyz/maa-node-win32-x64/server') 5 | break 6 | case 'win32-arm64': 7 | globalThis.maa = require('@maaxyz/maa-node-win32-arm64/server') 8 | break 9 | case 'linux-x64': 10 | globalThis.maa = require('@maaxyz/maa-node-linux-x64/server') 11 | break 12 | case 'linux-arm64': 13 | globalThis.maa = require('@maaxyz/maa-node-linux-arm64/server') 14 | break 15 | case 'darwin-x64': 16 | globalThis.maa = require('@maaxyz/maa-node-darwin-x64/server') 17 | break 18 | case 'darwin-arm64': 19 | globalThis.maa = require('@maaxyz/maa-node-darwin-arm64/server') 20 | break 21 | default: 22 | globalThis.maa = {} 23 | break 24 | } 25 | } 26 | 27 | module.exports = globalThis.maa 28 | -------------------------------------------------------------------------------- /source/MaaDbgControlUnit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB_RECURSE maa_dbg_control_unit_src *.h *.hpp *.cpp) 2 | file(GLOB_RECURSE maa_dbg_control_unit_header ${MAA_PRIVATE_INC}/ControlUnit/DbgControlUnitAPI.h ${MAA_PRIVATE_INC}/ControlUnit/ControlUnitAPI.h) 3 | 4 | add_library(MaaDbgControlUnit SHARED ${maa_dbg_control_unit_src} ${maa_dbg_control_unit_header}) 5 | 6 | target_include_directories(MaaDbgControlUnit 7 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${MAA_PRIVATE_INC} ${MAA_PUBLIC_INC}) 8 | 9 | target_link_libraries(MaaDbgControlUnit MaaUtils ${OpenCV_LIBS}) 10 | 11 | target_compile_definitions(MaaDbgControlUnit PRIVATE MAA_CONTROL_UNIT_EXPORTS) 12 | 13 | add_dependencies(MaaDbgControlUnit MaaUtils) 14 | 15 | install( 16 | TARGETS MaaDbgControlUnit 17 | RUNTIME DESTINATION bin 18 | LIBRARY DESTINATION bin 19 | 20 | # ARCHIVE DESTINATION lib 21 | ) 22 | 23 | if(WIN32) 24 | install(FILES $ DESTINATION symbol OPTIONAL) 25 | endif() 26 | 27 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${maa_dbg_control_unit_src}) 28 | -------------------------------------------------------------------------------- /source/MaaFramework/Vision/TemplateComparator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MaaUtils/JsonExt.hpp" 4 | #include "VisionBase.h" 5 | #include "VisionTypes.h" 6 | 7 | #include "Common/Conf.h" 8 | 9 | MAA_VISION_NS_BEGIN 10 | 11 | struct TemplateComparatorResult 12 | { 13 | cv::Rect box {}; 14 | double score = 0.0; 15 | 16 | MEO_JSONIZATION(box, score); 17 | }; 18 | 19 | class TemplateComparator 20 | : public VisionBase 21 | , public RecoResultAPI 22 | { 23 | public: 24 | TemplateComparator(cv::Mat lhs, cv::Mat rhs, cv::Rect roi, TemplateComparatorParam param, std::string name = ""); 25 | 26 | private: 27 | void analyze(); 28 | 29 | void add_results(ResultsVec results, double threshold); 30 | void cherry_pick(); 31 | 32 | double comp(const cv::Mat& lhs, const cv::Mat& rhs, int method); 33 | bool comp_score(double s1, double s2) const; 34 | 35 | private: 36 | const cv::Mat rhs_image_ = {}; 37 | const TemplateComparatorParam param_; 38 | const bool low_score_better_ = false; 39 | }; 40 | 41 | MAA_VISION_NS_END 42 | -------------------------------------------------------------------------------- /tools/nupkgs/pack.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | 5 | version="$1" 6 | 7 | curl -fsSL -O https://raw.githubusercontent.com/MaaAssistantArknights/design/main/logo/maa-logo_128x128.png 8 | for nuspec in Maa.Framework.Runtime*.nuspec; do 9 | # extract RID from filename: 10 | # Maa.Framework.Runtime..nuspec -> Maa.Framework.Runtime. 11 | # Maa.Framework.Runtimes.nuspec -> Maa.Framework.Runtimes 12 | pid="${nuspec%.nuspec}" 13 | rid="${pid#Maa.Framework.Runtime.}" 14 | if [ "${pid}" != "Maa.Framework.Runtimes" ]; then 15 | sed "s/__PID__/${pid}/g; s/__RID__/${rid}/g" "buildTransitive/template.targets" > "buildTransitive/${pid}.targets" 16 | fi 17 | 18 | # Prepend Head.nuspec and append Tail.nuspec 19 | cat Head.nuspec "${nuspec}" Tail.nuspec > temp && mv temp "${nuspec}" 20 | 21 | nuget pack "${nuspec}" \ 22 | -Verbosity detailed \ 23 | -Properties "version=${version//-post/};year=$(date +%Y);branch=$(git rev-parse --abbrev-ref HEAD);commit=$(git rev-parse HEAD);root_path=..\.." 24 | done -------------------------------------------------------------------------------- /source/LibraryHolder/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB_RECURSE library_holder_src *.h *.hpp *.cpp) 2 | file(GLOB_RECURSE library_holder_header ${MAA_PRIVATE_INC}/LibraryHolder/*) 3 | 4 | add_library(LibraryHolder STATIC ${library_holder_src} ${library_holder_header}) 5 | set_target_properties(LibraryHolder PROPERTIES POSITION_INDEPENDENT_CODE ON) 6 | 7 | target_include_directories(LibraryHolder 8 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${MAA_PRIVATE_INC} ${MAA_PUBLIC_INC}) 9 | 10 | target_link_libraries(LibraryHolder MaaUtils Boost::system ${OpenCV_LIBS}) 11 | 12 | add_dependencies(LibraryHolder MaaUtils) 13 | 14 | if(WITH_ADB_CONTROLLER) 15 | add_dependencies(LibraryHolder MaaAdbControlUnit) 16 | endif() 17 | 18 | if(WITH_WIN32_CONTROLLER) 19 | add_dependencies(LibraryHolder MaaWin32ControlUnit) 20 | endif() 21 | 22 | if(WITH_DBG_CONTROLLER) 23 | add_dependencies(LibraryHolder MaaDbgControlUnit) 24 | endif() 25 | 26 | if(WITH_CUSTOM_CONTROLLER) 27 | add_dependencies(LibraryHolder MaaCustomControlUnit) 28 | endif() 29 | 30 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${library_holder_src}) 31 | -------------------------------------------------------------------------------- /source/MaaCustomControlUnit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB_RECURSE maa_custom_control_unit_src *.h *.hpp *.cpp) 2 | file(GLOB_RECURSE maa_custom_control_unit_header ${MAA_PRIVATE_INC}/ControlUnit/CustomControlUnitAPI.h ${MAA_PRIVATE_INC}/ControlUnit/ControlUnitAPI.h) 3 | 4 | add_library(MaaCustomControlUnit SHARED ${maa_custom_control_unit_src} ${maa_custom_control_unit_header}) 5 | 6 | target_include_directories(MaaCustomControlUnit 7 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${MAA_PRIVATE_INC} ${MAA_PUBLIC_INC}) 8 | 9 | target_link_libraries(MaaCustomControlUnit MaaUtils ${OpenCV_LIBS}) 10 | 11 | target_compile_definitions(MaaCustomControlUnit PRIVATE MAA_CONTROL_UNIT_EXPORTS) 12 | 13 | add_dependencies(MaaCustomControlUnit MaaUtils) 14 | 15 | install( 16 | TARGETS MaaCustomControlUnit 17 | RUNTIME DESTINATION bin 18 | LIBRARY DESTINATION bin 19 | 20 | # ARCHIVE DESTINATION lib 21 | ) 22 | 23 | if(WIN32) 24 | install(FILES $ DESTINATION symbol OPTIONAL) 25 | endif() 26 | 27 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${maa_custom_control_unit_src}) 28 | -------------------------------------------------------------------------------- /include/MaaFramework/Global/MaaGlobal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file MaaUtility.h 3 | * @author 4 | * @brief Provide global functions for the framework. 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | // IWYU pragma: private, include 11 | 12 | #pragma once 13 | 14 | #include "../MaaDef.h" 15 | #include "../MaaPort.h" 16 | 17 | #ifdef __cplusplus 18 | extern "C" 19 | { 20 | #endif 21 | 22 | /** 23 | * @param[in] value 24 | */ 25 | MAA_FRAMEWORK_API MaaBool 26 | MaaGlobalSetOption(MaaGlobalOption key, MaaOptionValue value /**< byte array, int*, char*, bool* */, MaaOptionValueSize val_size); 27 | 28 | /// load a plugin with full path or name only, name only will search in system directory and current directory 29 | /// or 30 | /// load plugins with recursive search in the directory 31 | MAA_FRAMEWORK_API MaaBool MaaGlobalLoadPlugin(const char* library_path); 32 | 33 | MAA_DEPRECATED MAA_FRAMEWORK_API MaaBool 34 | MaaSetGlobalOption(MaaGlobalOption key, MaaOptionValue value /**< byte array, int*, char*, bool* */, MaaOptionValueSize val_size); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | -------------------------------------------------------------------------------- /source/MaaFramework/Task/Component/CustomRecognition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Common/MaaTypes.h" 6 | #include "MaaFramework/MaaDef.h" 7 | #include "Resource/ResourceMgr.h" 8 | #include "Task/Context.h" 9 | #include "Vision/VisionBase.h" 10 | 11 | #include "Common/Conf.h" 12 | 13 | MAA_TASK_NS_BEGIN 14 | 15 | struct CustomRecognitionResult 16 | { 17 | cv::Rect box {}; 18 | json::value detail; 19 | 20 | MEO_JSONIZATION(box, detail); 21 | }; 22 | 23 | class CustomRecognition 24 | : public MAA_VISION_NS::VisionBase 25 | , public MAA_VISION_NS::RecoResultAPI 26 | { 27 | public: 28 | CustomRecognition( 29 | const cv::Mat& image, 30 | const cv::Rect& roi, 31 | const MAA_VISION_NS::CustomRecognitionParam& param, 32 | MAA_RES_NS::CustomRecognitionSession session, 33 | Context& context, 34 | std::string name); 35 | 36 | private: 37 | void analyze(); 38 | 39 | private: 40 | const MAA_VISION_NS::CustomRecognitionParam& param_; 41 | MAA_RES_NS::CustomRecognitionSession session_; 42 | Context& context_; 43 | }; 44 | 45 | MAA_TASK_NS_END 46 | -------------------------------------------------------------------------------- /include/MaaToolkit/DesktopWindow/MaaToolkitDesktopWindow.h: -------------------------------------------------------------------------------- 1 | // IWYU pragma: private, include 2 | 3 | #pragma once 4 | 5 | #include "../MaaToolkitDef.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" 9 | { 10 | #endif 11 | 12 | MAA_TOOLKIT_API MaaToolkitDesktopWindowList* MaaToolkitDesktopWindowListCreate(); 13 | MAA_TOOLKIT_API void MaaToolkitDesktopWindowListDestroy(MaaToolkitDesktopWindowList* handle); 14 | 15 | MAA_TOOLKIT_API MaaBool MaaToolkitDesktopWindowFindAll(/*out*/ MaaToolkitDesktopWindowList* buffer); 16 | 17 | MAA_TOOLKIT_API MaaSize MaaToolkitDesktopWindowListSize(const MaaToolkitDesktopWindowList* list); 18 | MAA_TOOLKIT_API const MaaToolkitDesktopWindow* MaaToolkitDesktopWindowListAt(const MaaToolkitDesktopWindowList* list, MaaSize index); 19 | 20 | MAA_TOOLKIT_API void* MaaToolkitDesktopWindowGetHandle(const MaaToolkitDesktopWindow* window); 21 | MAA_TOOLKIT_API const char* MaaToolkitDesktopWindowGetClassName(const MaaToolkitDesktopWindow* window); 22 | MAA_TOOLKIT_API const char* MaaToolkitDesktopWindowGetWindowName(const MaaToolkitDesktopWindow* window); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | -------------------------------------------------------------------------------- /.github/workflows/mirrorchyan.yml: -------------------------------------------------------------------------------- 1 | name: mirrorchyan 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | tag: 7 | default: '' 8 | required: false 9 | # release: 10 | # types: [released] 11 | 12 | jobs: 13 | mirrorchyan: 14 | runs-on: macos-latest 15 | if: ${{ github.repository_owner == 'MaaXYZ' }} 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | os: [win, macos, linux] 20 | arch: [aarch64, x86_64] 21 | 22 | steps: 23 | - id: uploading 24 | uses: MirrorChyan/uploading-action@v1 25 | with: 26 | filetype: latest-release 27 | filename: "MAA-${{ matrix.os }}-${{ matrix.arch }}-*.zip" 28 | mirrorchyan_rid: MaaFramework 29 | tag: ${{ inputs.tag }} 30 | 31 | owner: MaaXYZ 32 | repo: MaaFramework 33 | github_token: ${{ secrets.GITHUB_TOKEN }} 34 | upload_token: ${{ secrets.MirrorChyanUploadToken }} 35 | os: ${{ matrix.os }} 36 | arch: ${{ matrix.arch }} 37 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB_RECURSE maa_adb_control_unit_src *.h *.hpp *.cpp) 2 | file(GLOB_RECURSE maa_adb_control_unit_header ${MAA_PRIVATE_INC}/ControlUnit/AdbControlUnitAPI.h ${MAA_PRIVATE_INC}/ControlUnit/ControlUnitAPI.h) 3 | 4 | add_library(MaaAdbControlUnit SHARED ${maa_adb_control_unit_src} ${maa_adb_control_unit_header}) 5 | 6 | target_include_directories(MaaAdbControlUnit 7 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${MAA_PRIVATE_INC} ${MAA_PUBLIC_INC}) 8 | 9 | target_link_libraries(MaaAdbControlUnit MaaUtils HeaderOnlyLibraries ${OpenCV_LIBS} ZLIB::ZLIB EmulatorExtras) 10 | 11 | if(WIN32) 12 | target_link_libraries(MaaAdbControlUnit ws2_32) 13 | endif() 14 | 15 | target_compile_definitions(MaaAdbControlUnit PRIVATE MAA_CONTROL_UNIT_EXPORTS) 16 | 17 | add_dependencies(MaaAdbControlUnit MaaUtils) 18 | 19 | install( 20 | TARGETS MaaAdbControlUnit 21 | RUNTIME DESTINATION bin 22 | LIBRARY DESTINATION bin 23 | 24 | # ARCHIVE DESTINATION lib 25 | ) 26 | 27 | if(WIN32) 28 | install(FILES $ DESTINATION symbol OPTIONAL) 29 | endif() 30 | 31 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${maa_adb_control_unit_src}) 32 | -------------------------------------------------------------------------------- /include/MaaAgentServer/MaaAgentServerAPI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MaaAgentServerDef.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" 7 | { 8 | #endif 9 | 10 | MAA_AGENT_SERVER_API 11 | MaaBool MaaAgentServerRegisterCustomRecognition(const char* name, MaaCustomRecognitionCallback recognition, void* trans_arg); 12 | 13 | MAA_AGENT_SERVER_API MaaBool MaaAgentServerRegisterCustomAction(const char* name, MaaCustomActionCallback action, void* trans_arg); 14 | 15 | MAA_AGENT_SERVER_API MaaSinkId MaaAgentServerAddResourceSink(MaaEventCallback sink, void* trans_arg); 16 | MAA_AGENT_SERVER_API MaaSinkId MaaAgentServerAddControllerSink(MaaEventCallback sink, void* trans_arg); 17 | MAA_AGENT_SERVER_API MaaSinkId MaaAgentServerAddTaskerSink(MaaEventCallback sink, void* trans_arg); 18 | MAA_AGENT_SERVER_API MaaSinkId MaaAgentServerAddContextSink(MaaEventCallback sink, void* trans_arg); 19 | 20 | MAA_AGENT_SERVER_API MaaBool MaaAgentServerStartUp(const char* identifier); 21 | MAA_AGENT_SERVER_API void MaaAgentServerShutDown(); 22 | MAA_AGENT_SERVER_API void MaaAgentServerJoin(); 23 | MAA_AGENT_SERVER_API void MaaAgentServerDetach(); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /source/MaaWin32ControlUnit/API/Win32ControlUnitAPI.cpp: -------------------------------------------------------------------------------- 1 | #include "ControlUnit/Win32ControlUnitAPI.h" 2 | 3 | #include "Base/UnitBase.h" 4 | #include "MaaUtils/Logger.h" 5 | #include "MaaUtils/SafeWindows.hpp" 6 | #include "Manager/Win32ControlUnitMgr.h" 7 | 8 | const char* MaaWin32ControlUnitGetVersion() 9 | { 10 | #pragma message("MaaWin32ControlUnit MAA_VERSION: " MAA_VERSION) 11 | 12 | return MAA_VERSION; 13 | } 14 | 15 | MaaWin32ControlUnitHandle MaaWin32ControlUnitCreate( 16 | void* hWnd, 17 | MaaWin32ScreencapMethod screencap_method, 18 | MaaWin32InputMethod mouse_method, 19 | MaaWin32InputMethod keyboard_method) 20 | { 21 | using namespace MAA_CTRL_UNIT_NS; 22 | 23 | LogFunc << VAR_VOIDP(hWnd) << VAR(screencap_method) << VAR(mouse_method) << VAR(keyboard_method); 24 | 25 | HWND h_wnd = reinterpret_cast(hWnd); 26 | 27 | auto unit_mgr = std::make_unique(h_wnd, screencap_method, mouse_method, keyboard_method); 28 | return unit_mgr.release(); 29 | } 30 | 31 | void MaaWin32ControlUnitDestroy(MaaWin32ControlUnitHandle handle) 32 | { 33 | LogFunc << VAR_VOIDP(handle); 34 | 35 | if (handle) { 36 | delete handle; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /source/MaaWin32ControlUnit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB_RECURSE maa_win32_control_unit_src *.h *.hpp *.cpp) 2 | file(GLOB_RECURSE maa_win32_control_unit_header ${MAA_PRIVATE_INC}/ControlUnit/Win32ControlUnitAPI.h ${MAA_PRIVATE_INC}/ControlUnit/ControlUnitAPI.h) 3 | 4 | add_library(MaaWin32ControlUnit SHARED ${maa_win32_control_unit_src} ${maa_win32_control_unit_header}) 5 | 6 | target_include_directories(MaaWin32ControlUnit 7 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${MAA_PRIVATE_INC} ${MAA_PUBLIC_INC}) 8 | 9 | target_link_libraries(MaaWin32ControlUnit PRIVATE MaaUtils ${OpenCV_LIBS} ZLIB::ZLIB Boost::system) 10 | target_link_libraries(MaaWin32ControlUnit PRIVATE d3d11 dxgi runtimeobject) 11 | 12 | target_compile_definitions(MaaWin32ControlUnit PRIVATE MAA_CONTROL_UNIT_EXPORTS) 13 | 14 | add_dependencies(MaaWin32ControlUnit MaaUtils) 15 | 16 | install( 17 | TARGETS MaaWin32ControlUnit 18 | RUNTIME DESTINATION bin 19 | LIBRARY DESTINATION bin 20 | 21 | # ARCHIVE DESTINATION lib 22 | ) 23 | 24 | if(WIN32) 25 | install(FILES $ DESTINATION symbol OPTIONAL) 26 | endif() 27 | 28 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${maa_win32_control_unit_src}) 29 | -------------------------------------------------------------------------------- /sample/interface_en.json: -------------------------------------------------------------------------------- 1 | { 2 | "MyDemo3": "Demo Program 3", 3 | "demo3-png": "./assets/demo-en.png", 4 | "安卓端": "Android Device", 5 | "电脑端": "Windows Desktop App", 6 | "官服资源": "Official Server Resource Pack", 7 | "B站资源": "Bilibili Server Resource Pack", 8 | "收取荒原": "Collect Wilderness Resources", 9 | "每日心相": "Daily Psychube (Wilderness Analysis)", 10 | "常规作战": "Regular Combat Mission", 11 | "活动任务": "Event: A Nightmare At Green Lake 17 Dire", 12 | "领取奖励": "Claim Daily Rewards", 13 | "选择作战关卡": "Please select the stage to farm", 14 | "3-9厄险": "3-9 Dire (Lark)", 15 | "4-20厄险": "4-20 Dire (Two-Headed Skeleton)", 16 | "章节号": "Chapter Number", 17 | "难度": "Stage Difficulty", 18 | "超时时间": "Timeout Duration (milliseconds)", 19 | "1次": "Replay 1 time", 20 | "2次": "Replay 2 times", 21 | "3次": "Replay 3 times", 22 | "4次": "Replay 4 times", 23 | "是": "Yes", 24 | "否": "No", 25 | "刷完全部体力": "Use all stamina", 26 | "使用理智药": "Use sanity potion", 27 | "使用": "Use", 28 | "不使用": "Don't use", 29 | "刷完后操作": "Action after farming", 30 | "返回主界面": "Return to main menu", 31 | "继续战斗": "Continue battle", 32 | "退出游戏": "Exit game" 33 | } -------------------------------------------------------------------------------- /source/MaaWin32ControlUnit/Base/UnitBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "MaaFramework/MaaDef.h" 6 | #include "MaaUtils/NoWarningCVMat.hpp" 7 | 8 | #include "Common/Conf.h" 9 | 10 | MAA_CTRL_UNIT_NS_BEGIN 11 | 12 | class ScreencapBase 13 | { 14 | public: 15 | virtual ~ScreencapBase() = default; 16 | 17 | public: 18 | virtual std::optional screencap() = 0; 19 | 20 | protected: 21 | }; 22 | 23 | class InputBase 24 | { 25 | public: 26 | virtual ~InputBase() = default; 27 | 28 | public: 29 | virtual MaaControllerFeature get_features() const = 0; 30 | 31 | virtual bool click(int x, int y) = 0; 32 | virtual bool swipe(int x1, int y1, int x2, int y2, int duration) = 0; 33 | 34 | virtual bool touch_down(int contact, int x, int y, int pressure) = 0; 35 | virtual bool touch_move(int contact, int x, int y, int pressure) = 0; 36 | virtual bool touch_up(int contact) = 0; 37 | 38 | virtual bool click_key(int key) = 0; 39 | virtual bool input_text(const std::string& text) = 0; 40 | 41 | virtual bool key_down(int key) = 0; 42 | virtual bool key_up(int key) = 0; 43 | 44 | virtual bool scroll(int dx, int dy) = 0; 45 | }; 46 | 47 | MAA_CTRL_UNIT_NS_END 48 | -------------------------------------------------------------------------------- /source/MaaFramework/Vision/ColorMatcher.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MaaUtils/JsonExt.hpp" 4 | #include "VisionBase.h" 5 | #include "VisionTypes.h" 6 | 7 | #include "Common/Conf.h" 8 | 9 | MAA_VISION_NS_BEGIN 10 | 11 | struct ColorMatcherResult 12 | { 13 | cv::Rect box {}; 14 | int count = 0; 15 | 16 | MEO_JSONIZATION(box, count); 17 | }; 18 | 19 | class ColorMatcher 20 | : public VisionBase 21 | , public RecoResultAPI 22 | { 23 | public: 24 | ColorMatcher(cv::Mat image, cv::Rect roi, ColorMatcherParam param, std::string name = ""); 25 | 26 | private: 27 | void analyze(); 28 | ResultsVec color_match(const ColorMatcherParam::Range& range) const; 29 | 30 | void add_results(ResultsVec results, int count); 31 | void cherry_pick(); 32 | 33 | private: 34 | ResultsVec count_non_zero(const cv::Mat& bin, const cv::Point& tl) const; 35 | ResultsVec count_non_zero_with_connected(const cv::Mat& bin, const cv::Point& tl) const; 36 | cv::Mat draw_result(const cv::Mat& color, const cv::Mat& bin, const ResultsVec& results) const; 37 | 38 | void sort_(ResultsVec& results) const; 39 | 40 | private: 41 | const ColorMatcherParam param_; 42 | }; 43 | 44 | MAA_VISION_NS_END 45 | -------------------------------------------------------------------------------- /.github/workflows/format.yml: -------------------------------------------------------------------------------- 1 | name: format code 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: "0 23 * * *" # UTC 7 | 8 | jobs: 9 | format: 10 | runs-on: macos-latest 11 | steps: 12 | - name: Checkout repository 13 | uses: actions/checkout@v4 14 | with: 15 | token: ${{ secrets.GITHUB_TOKEN }} 16 | fetch-depth: 0 17 | submodules: false 18 | 19 | - name: Install clang-format 20 | run: | 21 | brew install clang-format 22 | clang-format --version 23 | 24 | - name: Format C++ files 25 | run: | 26 | python3 tools/FormatCode/format_cpp.py --verbose 27 | 28 | - name: Commit and push changes 29 | uses: actions-js/push@master 30 | with: 31 | rebase: true 32 | branch: ${{ github.ref }} 33 | message: "styles: Format C++ files 34 | 35 | https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} 36 | 37 | [skip changelog]" 38 | github_token: ${{ secrets.GITHUB_TOKEN }} 39 | -------------------------------------------------------------------------------- /test/dlopen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file( 2 | GLOB_RECURSE 3 | dlopen_testing_src 4 | *.cpp 5 | *.h 6 | *.hpp) 7 | 8 | add_executable(DlopenTesting ${dlopen_testing_src}) 9 | 10 | target_include_directories(DlopenTesting 11 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${MAA_PUBLIC_INC} ${MAA_PRIVATE_INC}) 12 | 13 | target_link_libraries(DlopenTesting LibraryHolder) 14 | 15 | if(LINUX) 16 | target_link_libraries(DlopenTesting dl) 17 | endif() 18 | 19 | if(WITH_ADB_CONTROLLER) 20 | target_compile_definitions(DlopenTesting PRIVATE WITH_ADB_CONTROLLER) 21 | endif() 22 | 23 | if(WITH_WIN32_CONTROLLER) 24 | target_compile_definitions(DlopenTesting PRIVATE WITH_WIN32_CONTROLLER) 25 | endif() 26 | 27 | if(WITH_DBG_CONTROLLER) 28 | target_compile_definitions(DlopenTesting PRIVATE WITH_DBG_CONTROLLER) 29 | endif() 30 | 31 | if(WITH_CUSTOM_CONTROLLER) 32 | target_compile_definitions(DlopenTesting PRIVATE WITH_CUSTOM_CONTROLLER) 33 | endif() 34 | 35 | add_dependencies(DlopenTesting LibraryHolder) 36 | 37 | set_target_properties(DlopenTesting PROPERTIES FOLDER Testing) 38 | 39 | install(TARGETS DlopenTesting RUNTIME DESTINATION bin) 40 | 41 | if(WIN32) 42 | install(FILES $ DESTINATION symbol OPTIONAL) 43 | endif() 44 | -------------------------------------------------------------------------------- /sample/csharp/2.pi_cli.csx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env dotnet-script 2 | #nullable enable 3 | 4 | #r "nuget: Maa.Framework, 4.2.0" 5 | 6 | using MaaFramework.Binding; 7 | using MaaFramework.Binding.Buffers; 8 | using MaaFramework.Binding.Custom; 9 | 10 | MaaUtility.Shared.SetOption_StdoutLevel(LoggingLevel.Info); 11 | // Register custom action 12 | MaaToolkit.Shared.PI.Register(new MyAction()); 13 | // Run MaaPiCli 14 | MaaToolkit.Shared.PI.RunCli("../resource", ".cache", false); 15 | 16 | 17 | internal sealed class MyAction : IMaaCustomAction 18 | { 19 | public string Name { get; set; } = "MyAct"; 20 | 21 | public bool Run(in IMaaContext context, in RunArgs args, in RunResults results) 22 | { 23 | Console.WriteLine($"on MyAction.run, context: {context}, args: {args}"); 24 | 25 | context.OverrideNext(args.NodeName, ["TaskA", "TaskB"]); 26 | 27 | using var image = new MaaImageBuffer(); 28 | context.Tasker.Controller.GetCachedImage(image); 29 | context.Tasker.Controller.Click(100, 100).Wait(); 30 | 31 | var RecognitionDetail = context.RunRecognition("Cat", image, 32 | """{"Cat": {"recognition": "OCR", "expected": "喵喵喵"}}"""); 33 | // if RecognitionDetail xxxx 34 | 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /source/MaaToolkit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB_RECURSE maa_toolkit_src *.h *.hpp *.cpp) 2 | file(GLOB_RECURSE maa_toolkit_header ${MAA_PUBLIC_INC}/MaaToolkit/*) 3 | 4 | add_library(MaaToolkit SHARED ${maa_toolkit_src} ${maa_toolkit_header}) 5 | 6 | target_include_directories( 7 | MaaToolkit 8 | PUBLIC $ $ 9 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${MAA_PRIVATE_INC} ${MAA_PUBLIC_INC}) 10 | 11 | target_compile_definitions(MaaToolkit PRIVATE MAA_TOOLKIT_EXPORTS) 12 | 13 | target_link_libraries( 14 | MaaToolkit PRIVATE MaaUtils MaaFramework LibraryHolder Boost::system ${OpenCV_LIBS}) 15 | 16 | if(LINUX) 17 | target_link_libraries(MaaToolkit PRIVATE pthread dl) 18 | endif() 19 | 20 | add_dependencies(MaaToolkit MaaUtils MaaFramework LibraryHolder) 21 | 22 | install( 23 | TARGETS MaaToolkit 24 | EXPORT MaaFrameworkTargets 25 | RUNTIME DESTINATION bin 26 | LIBRARY DESTINATION bin 27 | ARCHIVE DESTINATION lib) 28 | 29 | if(WIN32) 30 | install(FILES $ DESTINATION symbol OPTIONAL) 31 | endif() 32 | 33 | install(DIRECTORY "${MAA_PUBLIC_INC}/MaaToolkit" DESTINATION "include") 34 | 35 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${maa_toolkit_src}) 36 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Screencap/ScreencapHelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Common/Conf.h" 8 | #include "MaaUtils/NoWarningCVMat.hpp" 9 | 10 | MAA_CTRL_UNIT_NS_BEGIN 11 | 12 | class ScreencapHelper 13 | { 14 | public: 15 | std::optional process_data(std::string& buffer, std::function(const std::string& buffer)> decoder); 16 | 17 | static std::optional decode_raw(const std::string& buffer); 18 | static std::optional decode_gzip(const std::string& buffer); 19 | static std::optional decode_png(const std::string& buffer); 20 | static std::optional trunc_decode_jpg(const std::string& buffer); 21 | static std::optional decode_jpg(const std::string& buffer); 22 | static std::optional decode(const std::string& buffer); 23 | 24 | private: 25 | static bool clean_cr(std::string& buffer); 26 | static bool check_head_tail(std::string_view input, std::string_view head, std::string_view tail); 27 | 28 | enum class EndOfLine 29 | { 30 | UnknownYet, 31 | CRLF, 32 | LF, 33 | CR 34 | } end_of_line_ = EndOfLine::UnknownYet; 35 | }; 36 | 37 | MAA_CTRL_UNIT_NS_END 38 | -------------------------------------------------------------------------------- /tools/ImageCropper/README.md: -------------------------------------------------------------------------------- 1 | # 截图工具 2 | 3 | 本工具可以对 **预先准备好的截图** 或 **通过 ADB 连接设备**,进行 ROI 区域的截取、保存、取色操作。 4 | 5 | ## 环境 6 | 7 | > 如果虚拟环境路径 venv/ 存在,start.bat 优先使用虚拟环境。 8 | 9 | 需要 `python` 环境,推荐版本为 `3.11` ,最低版本为 `3.9` 以上。 10 | 11 | ## 依赖 12 | 13 | > [!TIP] 14 | > windows 用户推荐直接运行 install.bat 和 start.bat 15 | 16 | ```shell 17 | python -m pip install -r requirements.txt 18 | ``` 19 | 20 | ## 使用 21 | 22 | 0. (非必要) 根据 `set_screenshot_target_long/short_side` 的使用情况,调整脚本中的 `截图参数` 和 `初始窗口大小` 23 | 1. 如果有预先准备好的截图,需保存到 `./src/` 路径下 24 | 2. 运行 `start.bat` 或 `python main.py [device serial]` ,设备地址为可选 25 | - 根据提示 `Please select the device (ENTER to pass):` ,选择 adb 已连接设备(按 ENTER 跳过选择) 26 | - 如果没有该提示,请使用 `python main.py [device serial]` 连接设备 27 | 3. 在弹窗中左键选择目标区域,滚轮缩放图片,右键移动图片 28 | 4. 使用快捷键操作: 29 | - 按 S ENTER 保存目标区域 30 | - 按 F 保存全屏标准化截图 31 | - 按 R 不保存,只输出 ROI 范围 32 | - 按 C 不保存,输出 ROI 范围和 ColorMatch 的所需字段,大写将使用 connected 字段 33 | - 按 Z DELETE BACKSPACE 撤销 34 | - 按 0 ~ 9 缩放窗口 35 | - 按 Q ESC 退出 36 | - 按 任意键 跳过 / 刷新当前截图 37 | 38 | 5. 目标区域截图保存在 `./dst/` 路径下,文件名为 `src` 中的文件名 / 截图的时间 + ROI + 放大后的 ROI 39 | -------------------------------------------------------------------------------- /source/MaaFramework/Vision/TemplateMatcher.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "MaaUtils/JsonExt.hpp" 7 | #include "VisionBase.h" 8 | #include "VisionTypes.h" 9 | 10 | #include "Common/Conf.h" 11 | 12 | MAA_VISION_NS_BEGIN 13 | 14 | struct TemplateMatcherResult 15 | { 16 | cv::Rect box {}; 17 | double score = 0.0; 18 | 19 | MEO_JSONIZATION(box, score); 20 | }; 21 | 22 | class TemplateMatcher 23 | : public VisionBase 24 | , public RecoResultAPI 25 | { 26 | public: 27 | TemplateMatcher(cv::Mat image, cv::Rect roi, TemplateMatcherParam param, std::vector templates, std::string name = ""); 28 | 29 | private: 30 | void analyze(); 31 | ResultsVec template_match(const cv::Mat& templ) const; 32 | 33 | void add_results(ResultsVec results, double threshold); 34 | void cherry_pick(); 35 | 36 | private: 37 | cv::Mat draw_result(const cv::Mat& templ, const ResultsVec& results) const; 38 | 39 | void sort_(ResultsVec& results) const; 40 | 41 | bool comp_score(double s1, double s2) const; 42 | 43 | private: 44 | const TemplateMatcherParam param_; 45 | const bool low_score_better_ = false; 46 | const std::vector templates_; 47 | }; 48 | 49 | MAA_VISION_NS_END 50 | -------------------------------------------------------------------------------- /source/MaaToolkit/DesktopWindow/DesktopWindowWin32Finder.cpp: -------------------------------------------------------------------------------- 1 | #ifdef _WIN32 2 | 3 | #include "DesktopWindowWin32Finder.h" 4 | 5 | #include "MaaUtils/Encoding.h" 6 | #include "MaaUtils/Logger.h" 7 | #include "MaaUtils/Platform.h" 8 | 9 | MAA_TOOLKIT_NS_BEGIN 10 | 11 | std::vector DesktopWindowWin32Finder::find_all() const 12 | { 13 | LogFunc; 14 | 15 | std::vector windows; 16 | 17 | for (HWND hwnd = GetTopWindow(NULL); hwnd != NULL; hwnd = GetNextWindow(hwnd, GW_HWNDNEXT)) { 18 | if (!IsWindowVisible(hwnd)) { 19 | continue; 20 | } 21 | 22 | std::wstring class_name(256, '\0'); 23 | GetClassNameW(hwnd, class_name.data(), static_cast(class_name.size())); 24 | 25 | std::wstring window_name(256, '\0'); 26 | GetWindowTextW(hwnd, window_name.data(), static_cast(window_name.size())); 27 | 28 | windows.emplace_back( 29 | DesktopWindow { 30 | .hwnd = hwnd, 31 | .class_name = class_name, 32 | .window_name = window_name, 33 | }); 34 | } 35 | 36 | #ifdef MAA_DEBUG 37 | LogInfo << "Window list:" << windows; 38 | #endif 39 | 40 | return windows; 41 | } 42 | 43 | MAA_TOOLKIT_NS_END 44 | 45 | #endif // _WIN32 46 | -------------------------------------------------------------------------------- /source/LibraryHolder/AgentClient/AgentClient.cpp: -------------------------------------------------------------------------------- 1 | #include "LibraryHolder/AgentClient.h" 2 | 3 | #include "MaaAgentClient/MaaAgentClientAPI.h" 4 | 5 | #include 6 | 7 | #include "MaaUtils/Logger.h" 8 | #include "MaaUtils/Runtime.h" 9 | 10 | MAA_NS_BEGIN 11 | 12 | std::shared_ptr AgentClientLibraryHolder::create_agent_client() 13 | { 14 | if (!load_library(library_dir() / libname_)) { 15 | LogError << "Failed to load library" << VAR(library_dir()) << VAR(libname_); 16 | return nullptr; 17 | } 18 | 19 | auto create_func = get_function(create_func_name_); 20 | if (!create_func) { 21 | LogError << "Failed to get function create_func" << VAR(create_func_name_); 22 | return nullptr; 23 | } 24 | 25 | auto destroy_func = get_function(destroy_func_name_); 26 | if (!destroy_func) { 27 | LogError << "Failed to get function destroy_func" << VAR(destroy_func_name_); 28 | return nullptr; 29 | } 30 | 31 | auto handle = create_func(nullptr); 32 | if (!handle) { 33 | LogError << "Failed to create handle"; 34 | return nullptr; 35 | } 36 | 37 | return std::shared_ptr(handle, destroy_func); 38 | } 39 | 40 | MAA_NS_END 41 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Screencap/Minicap/MinicapStream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MinicapBase.h" 4 | 5 | #include 6 | #include 7 | 8 | #include "MaaUtils/IOStream/ChildPipeIOStream.h" 9 | #include "MaaUtils/IOStream/SockIOStream.h" 10 | 11 | #include "Common/Conf.h" 12 | 13 | MAA_CTRL_UNIT_NS_BEGIN 14 | 15 | class MinicapStream : public MinicapBase 16 | { 17 | public: 18 | using MinicapBase::MinicapBase; 19 | 20 | virtual ~MinicapStream() override; 21 | 22 | public: // from UnitBase 23 | virtual bool parse(const json::value& config) override; 24 | 25 | public: // from ScreencapBase 26 | virtual bool init() override; 27 | virtual std::optional screencap() override; 28 | 29 | private: 30 | std::optional read(size_t count); 31 | void create_thread(); 32 | void release_thread(); 33 | bool connect_and_check(); 34 | 35 | void pulling(); 36 | 37 | ProcessArgvGenerator forward_argv_; 38 | int port_ = 0; 39 | 40 | bool quit_ = true; 41 | std::mutex mutex_; 42 | cv::Mat image_; 43 | std::condition_variable cond_; 44 | std::thread pull_thread_; 45 | 46 | std::shared_ptr pipe_ios_ = nullptr; 47 | std::shared_ptr sock_ios_ = nullptr; 48 | }; 49 | 50 | MAA_CTRL_UNIT_NS_END 51 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/foundation/spec/tools.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace maajs 8 | { 9 | 10 | struct MaaError : public std::exception 11 | { 12 | std::string error; 13 | 14 | MaaError(const std::string& err) 15 | : error(err) 16 | { 17 | } 18 | 19 | MaaError(std::string&& err) 20 | : error(err) 21 | { 22 | } 23 | 24 | virtual const char* what() const noexcept override { return error.c_str(); } 25 | }; 26 | 27 | template 28 | struct StringHolder 29 | { 30 | char data[N]; 31 | 32 | constexpr StringHolder(const char (&str)[N]) { std::copy(str, str + N, data); } 33 | 34 | template 35 | constexpr auto operator+(const char (&str)[M]) 36 | { 37 | StringHolder ret; 38 | std::copy(data, data + N - 1, ret.data); 39 | std::copy(str.data, str.data + M, ret.data + N - 1); 40 | return ret; 41 | } 42 | }; 43 | 44 | inline std::string JoinString(std::vector parts, std::string sep) 45 | { 46 | std::string result = ""; 47 | bool first = true; 48 | for (const auto& name : parts) { 49 | result += first ? name : sep + name; 50 | first = false; 51 | } 52 | return result; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/apis/loader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "../foundation/spec.h" 7 | 8 | maajs::ObjectType load_global(maajs::EnvType env); 9 | 10 | maajs::ValueType load_job(maajs::EnvType env); 11 | 12 | maajs::ValueType load_resource(maajs::EnvType env); 13 | 14 | maajs::ValueType load_image_job(maajs::EnvType env); 15 | maajs::ValueType load_controller(maajs::EnvType env); 16 | maajs::ValueType load_adb_controller(maajs::EnvType env); 17 | maajs::ValueType load_win32_controller(maajs::EnvType env); 18 | #ifdef __APPLE__ 19 | maajs::ValueType load_playcover_controller(maajs::EnvType env); 20 | #endif 21 | maajs::ValueType load_dbg_controller(maajs::EnvType env); 22 | maajs::ValueType load_custom_controller(maajs::EnvType env); 23 | 24 | maajs::ValueType load_task_job(maajs::EnvType env); 25 | maajs::ValueType load_tasker(maajs::EnvType env); 26 | 27 | maajs::ValueType load_context(maajs::EnvType env); 28 | 29 | maajs::ValueType load_client(maajs::EnvType env); 30 | maajs::ValueType load_server(maajs::EnvType env); 31 | maajs::ValueType load_plugin(maajs::EnvType env); 32 | 33 | std::map load_constant(maajs::EnvType env); 34 | 35 | #ifdef MAA_JS_IMPL_IS_QUICKJS 36 | void init_module_maa(JSContext* ctx); 37 | void init_module_sys(JSContext* ctx); 38 | #endif 39 | -------------------------------------------------------------------------------- /docs/en_us/NodeJS/J1.3-Packaging.md: -------------------------------------------------------------------------------- 1 | # Packaging 2 | 3 | > Note: This document is about integrating with NodeJS 4 | 5 | This project contains binary. `@maaxyz/maa-node` package will require corresponding `MaaNode.node` from `@maaxyz/maa-node-${platform}-${arch}`. Meanwhile, as loaded `MaaNode.node` dynamic links `MaaFramework` library, and `Adb` controller relies on `AgentBinary`, it is strongly recommended to mark `@maaxyz/maa-node` as external dependencies and do not participate packaging. 6 | 7 | If you do want to package it, the following should be take cared: 8 | 9 | * Usually, packaging tool can only discover `MaaNode.node`, but won't aware its dependencies. All `dll/so/dylib` besides `MaaNode.node` should be placed the same directory to `MaaNode.node`. 10 | * `Adb` controller will use `../agent` applying on the directory of **the library script** to search for MaaAgentBinary. It is also possible to manually configure it in code. 11 | 12 | ## maa-node-template 13 | 14 | Refer to [maa-node-template](https://github.com/neko-para/maa-node-template). This template provides a simplified packaging solution with electron. 15 | 16 | ```shell 17 | npm run build # use esbuild to build project, refer to scripts/build.mjs 18 | npm run watch # use esbuild and vite to hot reload, refer to scripts/watch.mjs 19 | npm run package # use electron-forge to package 20 | ``` 21 | -------------------------------------------------------------------------------- /source/MaaDbgControlUnit/ReplayRecording/RecordParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "Record.h" 8 | 9 | #include "Common/Conf.h" 10 | 11 | MAA_CTRL_UNIT_NS_BEGIN 12 | 13 | class RecordParser 14 | { 15 | public: 16 | static std::optional parse(const std::filesystem::path& path); 17 | 18 | private: 19 | static std::optional parse_record(const json::value& record_json, const std::filesystem::path& dir); 20 | static std::optional parse_connect(const json::value& record_json); 21 | static std::optional parse_click(const json::value& record_json); 22 | static std::optional parse_swipe(const json::value& record_json); 23 | static std::optional parse_multi_swipe(const json::value& record_json); 24 | static std::optional parse_touch(const json::value& record_json); 25 | static std::optional parse_click_key(const json::value& record_json); 26 | static std::optional parse_input_text(const json::value& record_json); 27 | static std::optional parse_screencap(const json::value& record_json, const std::filesystem::path& dir); 28 | static std::optional parse_app(const json::value& record_json); 29 | }; 30 | 31 | MAA_CTRL_UNIT_NS_END 32 | -------------------------------------------------------------------------------- /source/MaaFramework/Task/Component/CustomAction.cpp: -------------------------------------------------------------------------------- 1 | #include "CustomAction.h" 2 | 3 | #include "MaaUtils/Logger.h" 4 | 5 | MAA_TASK_NS_BEGIN 6 | 7 | bool CustomAction::run( 8 | Context& context, 9 | std::string node_name, 10 | MAA_RES_NS::CustomActionSession session, 11 | const MAA_RES_NS::Action::CustomParam& param, 12 | MaaRecoId reco_id, 13 | const cv::Rect& rect) 14 | { 15 | LogFunc << VAR(context.task_id()) << VAR(node_name) << VAR_VOIDP(session.action) << VAR_VOIDP(session.trans_arg) << VAR(param.name) 16 | << VAR(param.custom_param) << VAR(reco_id) << VAR(rect); 17 | 18 | if (!session.action) { 19 | LogError << "Action is null" << VAR(node_name) << VAR(param.name); 20 | return false; 21 | } 22 | 23 | std::string custom_param_string = param.custom_param.to_string(); 24 | MaaRect crect { .x = rect.x, .y = rect.y, .width = rect.width, .height = rect.height }; 25 | 26 | bool ret = session.action( 27 | &context, 28 | context.task_id(), 29 | node_name.c_str(), 30 | param.name.c_str(), 31 | custom_param_string.c_str(), 32 | reco_id, 33 | &crect, 34 | session.trans_arg); 35 | 36 | LogDebug << VAR(node_name) << VAR(param.name) << VAR_VOIDP(session.action) << VAR(session.trans_arg) << VAR(ret); 37 | 38 | return ret; 39 | } 40 | 41 | MAA_TASK_NS_END 42 | -------------------------------------------------------------------------------- /docs/zh_cn/1.2-术语解释.md: -------------------------------------------------------------------------------- 1 | # 术语 2 | 3 | ## MaaFW 专有术语 4 | 5 | - **Node** | **节点** 6 | 7 | 符合 [任务流水线(Pipeline)协议](3.1-任务流水线协议.md) 的一个完整的 Json Object。 8 | 9 | - **Task** | **任务** 10 | 11 | 若干 **Node** 按一定次序相连的逻辑顺序结构,表示从头到尾的整个过程。 12 | 13 | - **Entry** | **入口** 14 | 15 | 一个 **Task** 中的第一个 **Node**。 16 | 17 | - **Pipeline** | **流水线** 18 | 19 | 一个 `pipeline` 文件夹中包含的 **Node** 全体。 20 | 21 | - **Bundle** | *暂无翻译* 22 | 23 | 一个按标准资源结构存储的文件夹,包含 `pipeline`、`model`、`image` 等文件夹。 24 | 25 | - **Resource** | **资源** 26 | 27 | 多个 **Bundle** 按一定次序加载的资源结构。 28 | 29 | - **PI** | **项目接口** 30 | 31 | `ProjectInterface`, 符合 [ProjectInterface 定义](3.2-ProjectInterface协议.md) 的标准化项目结构声明。 32 | 33 | - **Agent** | **执行代理** 34 | 35 | 💡 MaaFW v4.x 版本亮点功能。可将 MaaFW 本体与 `CustomRecognition` / `CustomAction` 分离至独立的两个进程中。 36 | 例如本体运行在 C# 编写的通用 GUI 中,同时在 Python 代码中运行编写自己的 Custom 逻辑,打破语言壁垒。 37 | 38 | ## 通用术语 39 | 40 | - **Binding** | **语言绑定** 41 | 42 | 提供将 MaaFW 的 C 语言接口转换为其他编程语言或操作系统服务的胶水代码。 43 | 参考 [WIKI](https://en.wikipedia.org/wiki/Language_binding)。 44 | 45 | - **ROI** | **感兴趣区域** 46 | 47 | 定义图像识别边界,仅在该区域内进行相关图像处理。 48 | 参考 [WIKI](https://en.wikipedia.org/wiki/Region_of_interest)。 49 | 50 | - **OCR** | **文字识别** 51 | 52 | 对包含文本内容的图像进行处理和识别,并提取其中所包含的文字及排版信息。 53 | 参考 [WIKI](https://zh.wikipedia.org/wiki/%E5%85%89%E5%AD%A6%E5%AD%97%E7%AC%A6%E8%AF%86%E5%88%AB)。 54 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Invoke/InvokeApp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Base/UnitBase.h" 6 | #include "MaaUtils/IOStream/ChildPipeIOStream.h" 7 | 8 | #include "Common/Conf.h" 9 | 10 | MAA_CTRL_UNIT_NS_BEGIN 11 | 12 | class InvokeApp : public UnitBase 13 | { 14 | public: 15 | virtual ~InvokeApp() override; 16 | 17 | public: // from UnitBase 18 | virtual bool parse(const json::value& config) override; 19 | 20 | public: 21 | bool init(const std::string& force_temp = ""); 22 | 23 | std::optional> abilist(); 24 | std::optional sdk(); 25 | bool push(const std::filesystem::path& path); 26 | bool chmod(); 27 | bool remove(); 28 | 29 | std::optional invoke_bin_and_read_pipe(const std::string& extra); 30 | std::shared_ptr invoke_bin(const std::string& extra); 31 | std::shared_ptr invoke_app(const std::string& package); 32 | 33 | private: 34 | ProcessArgvGenerator abilist_argv_; 35 | ProcessArgvGenerator sdk_argv_; 36 | ProcessArgvGenerator push_bin_argv_; 37 | ProcessArgvGenerator chmod_bin_argv_; 38 | ProcessArgvGenerator invoke_bin_argv_; 39 | ProcessArgvGenerator invoke_app_argv_; 40 | ProcessArgvGenerator remove_file_argv_; 41 | 42 | std::string tempname_; 43 | bool pushed_ = false; 44 | }; 45 | 46 | MAA_CTRL_UNIT_NS_END 47 | -------------------------------------------------------------------------------- /source/MaaDbgControlUnit/API/DbgControlUnitAPI.cpp: -------------------------------------------------------------------------------- 1 | #include "ControlUnit/DbgControlUnitAPI.h" 2 | 3 | #include "CarouselImage/CarouselImage.h" 4 | #include "MaaUtils/Logger.h" 5 | #include "MaaUtils/Platform.h" 6 | #include "ReplayRecording/ReplayRecordingMgr.h" 7 | 8 | const char* MaaDbgControlUnitGetVersion() 9 | { 10 | #pragma message("MaaDbgControlUnit MAA_VERSION: " MAA_VERSION) 11 | 12 | return MAA_VERSION; 13 | } 14 | 15 | MaaControlUnitHandle MaaDbgControlUnitCreate(MaaDbgControllerType type, const char* read_path) 16 | { 17 | LogFunc << VAR(type) << VAR(read_path); 18 | 19 | if (!read_path) { 20 | LogError << "read_path is null"; 21 | return nullptr; 22 | } 23 | 24 | auto read_stdpath = MAA_NS::path(read_path); 25 | 26 | MaaControlUnitHandle handle = nullptr; 27 | 28 | switch (type) { 29 | case MaaDbgControllerType_CarouselImage: 30 | handle = new MAA_CTRL_UNIT_NS::CarouselImage(read_stdpath); 31 | break; 32 | 33 | case MaaDbgControllerType_ReplayRecording: 34 | handle = MAA_CTRL_UNIT_NS::create_replay_recording(read_stdpath); 35 | break; 36 | } 37 | 38 | LogDebug << VAR_VOIDP(handle); 39 | 40 | return handle; 41 | } 42 | 43 | void MaaDbgControlUnitDestroy(MaaControlUnitHandle handle) 44 | { 45 | LogFunc << VAR_VOIDP(handle); 46 | 47 | if (handle) { 48 | delete handle; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /source/MaaPlayCoverControlUnit/Client/PlayToolsClient.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include "Common/Conf.h" 12 | 13 | MAA_CTRL_UNIT_NS_BEGIN 14 | 15 | class PlayToolsClient 16 | { 17 | public: 18 | enum class TouchPhase : uint8_t 19 | { 20 | Began = 0, 21 | Moved = 1, 22 | Ended = 3, 23 | }; 24 | 25 | PlayToolsClient(); 26 | ~PlayToolsClient(); 27 | 28 | PlayToolsClient(const PlayToolsClient&) = delete; 29 | PlayToolsClient& operator=(const PlayToolsClient&) = delete; 30 | 31 | bool connect(const std::string& address); 32 | void close(); 33 | bool is_connected() const; 34 | 35 | bool screencap(std::vector& buffer, int& width, int& height); 36 | bool touch(TouchPhase phase, int x, int y); 37 | bool terminate(); 38 | 39 | std::pair screen_size() const; 40 | 41 | private: 42 | bool open(); 43 | bool check_version(); 44 | bool fetch_screen_size(int& width, int& height); 45 | 46 | static constexpr int MinimalVersion = 2; 47 | 48 | boost::asio::io_context context_; 49 | boost::asio::ip::tcp::socket socket_; 50 | std::string address_; 51 | std::pair screen_size_ { 0, 0 }; 52 | }; 53 | 54 | MAA_CTRL_UNIT_NS_END 55 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Input/AdbShellInput.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Base/UnitBase.h" 4 | 5 | #include "Common/Conf.h" 6 | 7 | MAA_CTRL_UNIT_NS_BEGIN 8 | 9 | class AdbShellInput : public InputBase 10 | { 11 | public: 12 | virtual ~AdbShellInput() override = default; 13 | 14 | public: // from UnitBase 15 | virtual bool parse(const json::value& config) override; 16 | 17 | public: // from InputBase 18 | virtual bool init() override { return true; } 19 | 20 | virtual MaaControllerFeature get_features() const override; 21 | 22 | virtual bool click(int x, int y) override; 23 | virtual bool swipe(int x1, int y1, int x2, int y2, int duration) override; 24 | 25 | virtual bool touch_down(int contact, int x, int y, int pressure) override; 26 | virtual bool touch_move(int contact, int x, int y, int pressure) override; 27 | virtual bool touch_up(int contact) override; 28 | 29 | virtual bool click_key(int key) override; 30 | virtual bool input_text(const std::string& text) override; 31 | 32 | virtual bool key_down(int key) override; 33 | virtual bool key_up(int key) override; 34 | 35 | virtual bool scroll(int dx, int dy) override; 36 | 37 | private: 38 | ProcessArgvGenerator click_argv_; 39 | ProcessArgvGenerator swipe_argv_; 40 | 41 | ProcessArgvGenerator click_key_argv_; 42 | ProcessArgvGenerator input_text_argv_; 43 | }; 44 | 45 | MAA_CTRL_UNIT_NS_END 46 | -------------------------------------------------------------------------------- /sample/nodejs/server.ts: -------------------------------------------------------------------------------- 1 | import '../../test/nodejs/maa-server' 2 | // import '@maaxyz/maa-node/server' 3 | 4 | console.log(maa.Global.version) 5 | 6 | const my_reco: maa.CustomRecognitionCallback = async self => { 7 | let reco_detail = await self.context.run_recognition('MyCustomOCR', self.image, { 8 | MyCustomOCR: { 9 | roi: [100, 100, 200, 300] 10 | } 11 | }) 12 | 13 | self.context.override_pipeline({ 14 | MyCustomOCR: { 15 | roi: [1, 1, 114, 514] 16 | } 17 | }) 18 | 19 | const new_context = self.context.clone() 20 | new_context.override_pipeline({ 21 | MyCustomOCR: { 22 | roi: [100, 200, 300, 400] 23 | } 24 | }) 25 | 26 | reco_detail = await new_context.run_recognition('MyCustomOCR', self.image) 27 | 28 | const click_job = self.context.tasker.controller!.post_click(10, 20) 29 | await click_job.wait() 30 | 31 | self.context.override_next(self.task, ['TaskA', 'TaskB']) 32 | 33 | return [[0, 0, 100, 100], 'Hello World!'] 34 | } 35 | 36 | async function main() { 37 | maa.Global.config_init_option('./') 38 | 39 | const socket_id = process.argv[process.argv.length - 1] 40 | 41 | maa.AgentServer.start_up(socket_id) 42 | 43 | maa.AgentServer.register_custom_recognizer('MyRecongition', my_reco) 44 | 45 | await maa.AgentServer.join() 46 | maa.AgentServer.shut_down() 47 | } 48 | 49 | main() 50 | -------------------------------------------------------------------------------- /source/MaaFramework/Task/Component/CommandAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Common/Conf.h" 8 | #include "MaaUtils/Platform.h" 9 | #include "MaaUtils/SingletonHolder.hpp" 10 | #include "Resource/PipelineTypes.h" 11 | 12 | MAA_TASK_NS_BEGIN 13 | 14 | class TempFileHolder : public SingletonHolder 15 | { 16 | public: 17 | virtual ~TempFileHolder() override; 18 | 19 | void emplace(const std::filesystem::path& p); 20 | 21 | private: 22 | std::vector files_; 23 | }; 24 | 25 | class CommandAction 26 | { 27 | public: 28 | struct Runtime 29 | { 30 | std::vector resource_paths; 31 | 32 | std::string entry; 33 | std::string node; 34 | cv::Mat image; 35 | cv::Rect box {}; 36 | }; 37 | 38 | public: 39 | bool run(const MAA_RES_NS::Action::CommandParam& command, const Runtime& runtime); 40 | 41 | private: 42 | std::string get_entry_name(const Runtime& runtime); 43 | std::string get_node_name(const Runtime& runtime); 44 | std::string get_image_path(const Runtime& runtime); 45 | std::string get_box(const Runtime& runtime); 46 | std::string get_library_dir(const Runtime& runtime); 47 | std::string get_resource_dir(const Runtime& runtime); 48 | 49 | private: 50 | std::string image_path_; 51 | }; 52 | 53 | MAA_TASK_NS_END 54 | -------------------------------------------------------------------------------- /source/MaaAgentClient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB_RECURSE maa_agent_client_src *.h *.hpp *.cpp) 2 | file(GLOB_RECURSE maa_agent_common_src ../AgentCommon/*.h ../AgentCommon/*.hpp ../AgentCommon/*.cpp) 3 | file(GLOB_RECURSE maa_agent_client_header ${MAA_PUBLIC_INC}/MaaAgentClient/*) 4 | 5 | add_library(MaaAgentClient SHARED ${maa_agent_common_src} ${maa_agent_client_src} ${maa_agent_client_header}) 6 | 7 | target_include_directories( 8 | MaaAgentClient 9 | PUBLIC $ $ 10 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${MAA_PRIVATE_INC} ${MAA_PUBLIC_INC}) 11 | 12 | target_compile_definitions(MaaAgentClient PRIVATE MAA_AGENT_CLIENT_EXPORTS) 13 | 14 | target_link_libraries(MaaAgentClient PRIVATE cppzmq-static ${OpenCV_LIBS} MaaUtils MaaFramework) 15 | 16 | add_dependencies(MaaAgentClient MaaUtils MaaFramework) 17 | 18 | install( 19 | TARGETS MaaAgentClient 20 | EXPORT MaaFrameworkTargets 21 | RUNTIME DESTINATION bin 22 | LIBRARY DESTINATION bin 23 | ARCHIVE DESTINATION lib) 24 | 25 | if(WIN32) 26 | install(FILES $ DESTINATION symbol OPTIONAL) 27 | endif() 28 | 29 | install(DIRECTORY "${MAA_PUBLIC_INC}/MaaAgentClient" DESTINATION "include") 30 | 31 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${maa_agent_client_src}) 32 | source_group(PREFIX "AgentCommon" TREE ${CMAKE_CURRENT_SOURCE_DIR}/../AgentCommon FILES ${maa_agent_common_src}) 33 | -------------------------------------------------------------------------------- /source/MaaWin32ControlUnit/Input/LegacyEventInput.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ControlUnit/ControlUnitAPI.h" 4 | 5 | #include "Base/UnitBase.h" 6 | #include "MaaUtils/SafeWindows.hpp" 7 | 8 | #include "Common/Conf.h" 9 | 10 | MAA_CTRL_UNIT_NS_BEGIN 11 | 12 | class LegacyEventInput : public InputBase 13 | { 14 | public: 15 | LegacyEventInput(HWND hwnd, bool block_input = false) 16 | : hwnd_(hwnd) 17 | , block_input_(block_input) 18 | { 19 | } 20 | 21 | virtual ~LegacyEventInput() override; 22 | 23 | public: // from InputBase 24 | virtual MaaControllerFeature get_features() const override; 25 | 26 | virtual bool click(int x, int y) override; 27 | virtual bool swipe(int x1, int y1, int x2, int y2, int duration) override; 28 | 29 | virtual bool touch_down(int contact, int x, int y, int pressure) override; 30 | virtual bool touch_move(int contact, int x, int y, int pressure) override; 31 | virtual bool touch_up(int contact) override; 32 | 33 | virtual bool click_key(int key) override; 34 | 35 | virtual bool input_text(const std::string& text) override; 36 | 37 | virtual bool key_down(int key) override; 38 | virtual bool key_up(int key) override; 39 | 40 | virtual bool scroll(int dx, int dy) override; 41 | 42 | private: 43 | void ensure_foreground(); 44 | 45 | HWND hwnd_ = nullptr; 46 | const bool block_input_ = false; 47 | }; 48 | 49 | MAA_CTRL_UNIT_NS_END 50 | 51 | -------------------------------------------------------------------------------- /.github/workflows/deploy-manual.yml: -------------------------------------------------------------------------------- 1 | name: deploy-manual 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v*" 7 | 8 | workflow_dispatch: 9 | 10 | jobs: 11 | meta: 12 | uses: ./.github/workflows/meta.yml 13 | 14 | build: 15 | needs: meta 16 | runs-on: ubuntu-latest 17 | env: 18 | MAN_VERSION: ${{ format('({0}) {1}', needs.meta.outputs.tag == github.ref_name && 'main' || github.ref_name, needs.meta.outputs.tag) }} 19 | permissions: 20 | contents: write 21 | steps: 22 | - uses: actions/checkout@v4 23 | with: 24 | fetch-depth: 0 25 | 26 | - name: Build Doxygen 27 | uses: mattnotmitt/doxygen-action@v1.9 28 | with: 29 | doxyfile-path: tools/Doxygen/Doxyfile 30 | 31 | - name: Build index.json 32 | uses: MaaXYZ/MaaApiConverter@v2 33 | with: 34 | version: ${{ env.MAN_VERSION }} 35 | xml: ./docs-gen/html/xml 36 | output: ./docs-gen/html 37 | 38 | - name: Deploy to GitHub Pages 39 | uses: peaceiris/actions-gh-pages@v4 40 | with: 41 | github_token: ${{ secrets.GITHUB_TOKEN }} 42 | publish_dir: ./docs-gen/html 43 | publish_branch: gh-pages 44 | commit_message: ${{ env.MAN_VERSION }} 45 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Screencap/Minicap/MinicapBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../ScreencapHelper.h" 6 | #include "Base/UnitBase.h" 7 | #include "General/DeviceInfo.h" 8 | #include "Invoke/InvokeApp.h" 9 | 10 | #include "Common/Conf.h" 11 | 12 | MAA_CTRL_UNIT_NS_BEGIN 13 | 14 | class MinicapBase : public ScreencapBase 15 | { 16 | public: 17 | explicit MinicapBase(std::filesystem::path agent_path) 18 | : agent_path_(std::move(agent_path)) 19 | { 20 | children_.emplace_back(binary_); 21 | children_.emplace_back(library_); 22 | children_.emplace_back(device_info_); 23 | } 24 | 25 | virtual ~MinicapBase() override = default; 26 | 27 | public: // from UnitBase 28 | virtual bool parse(const json::value& config) override; 29 | 30 | public: // from ScreencapBase 31 | virtual std::optional screencap() override = 0; 32 | 33 | protected: 34 | bool init_binary(); 35 | void deinit_binary(); 36 | 37 | std::shared_ptr binary_ = std::make_shared(); 38 | std::shared_ptr library_ = std::make_shared(); 39 | 40 | int display_width_ = 0; 41 | int display_height_ = 0; 42 | 43 | private: 44 | std::filesystem::path agent_path_; 45 | std::vector arch_list_; 46 | std::vector sdk_list_; 47 | 48 | std::shared_ptr device_info_ = std::make_shared(); 49 | }; 50 | 51 | MAA_CTRL_UNIT_NS_END 52 | -------------------------------------------------------------------------------- /source/MaaToolkit/DesktopWindow/DesktopWindowBuffer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "API/MaaToolkitBufferTypes.hpp" 6 | #include "Common/Conf.h" 7 | #include "MaaUtils/Buffer/ListBuffer.hpp" 8 | #include "MaaUtils/Encoding.h" 9 | #include "MaaUtils/Logger.h" 10 | 11 | MAA_TOOLKIT_NS_BEGIN 12 | 13 | struct DesktopWindow 14 | { 15 | void* hwnd = nullptr; 16 | std::wstring class_name; 17 | std::wstring window_name; 18 | 19 | MEO_TOJSON(hwnd, class_name, window_name); 20 | }; 21 | 22 | class DesktopWindowBuffer : public MaaToolkitDesktopWindow 23 | { 24 | public: 25 | DesktopWindowBuffer(const DesktopWindow& window) 26 | : hwnd_(window.hwnd) 27 | , class_name_(from_u16(window.class_name)) 28 | , window_name_(from_u16(window.window_name)) 29 | { 30 | } 31 | 32 | virtual ~DesktopWindowBuffer() override = default; 33 | 34 | virtual void* handle() const override { return hwnd_; } 35 | 36 | virtual const std::string& class_name() const override { return class_name_; } 37 | 38 | virtual const std::string& window_name() const override { return window_name_; } 39 | 40 | private: 41 | void* hwnd_ = nullptr; 42 | std::string class_name_; 43 | std::string window_name_; 44 | }; 45 | 46 | MAA_TOOLKIT_NS_END 47 | 48 | struct MaaToolkitDesktopWindowList : public MAA_NS::ListBuffer 49 | { 50 | virtual ~MaaToolkitDesktopWindowList() override = default; 51 | }; 52 | -------------------------------------------------------------------------------- /source/MaaFramework/Resource/ONNXResMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "Common/Conf.h" 10 | #include "MaaUtils/NonCopyable.hpp" 11 | 12 | MAA_RES_NS_BEGIN 13 | 14 | class ONNXResMgr : public NonCopyable 15 | { 16 | public: 17 | ONNXResMgr(); 18 | 19 | public: 20 | void use_cpu(); 21 | void use_cuda(int device_id); 22 | void use_directml(int device_id); 23 | void use_coreml(uint32_t coreml_flag); 24 | 25 | bool lazy_load_classifier(const std::filesystem::path& path); 26 | bool lazy_load_detector(const std::filesystem::path& path); 27 | void clear(); 28 | 29 | public: 30 | std::shared_ptr classifier(const std::string& name); 31 | std::shared_ptr detector(const std::string& name); 32 | const Ort::MemoryInfo& memory_info() const; 33 | 34 | private: 35 | std::shared_ptr load(const std::string& name, const std::vector& roots); 36 | 37 | std::vector classifier_roots_; 38 | std::vector detector_roots_; 39 | 40 | Ort::Env env_; 41 | Ort::SessionOptions options_; 42 | Ort::MemoryInfo memory_info_; 43 | 44 | std::unordered_map> classifiers_; 45 | std::unordered_map> detectors_; 46 | }; 47 | 48 | MAA_RES_NS_END 49 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Manager/ScreencapAgent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Base/UnitBase.h" 6 | 7 | #include "Common/Conf.h" 8 | 9 | MAA_CTRL_UNIT_NS_BEGIN 10 | 11 | class ScreencapAgent : public ScreencapBase 12 | { 13 | public: 14 | enum class Method 15 | { 16 | UnknownYet, 17 | EncodeToFileAndPull, 18 | Encode, 19 | RawWithGzip, 20 | RawByNetcat, 21 | MinicapDirect, 22 | MinicapStream, 23 | MuMuPlayerExtras, 24 | LDPlayerExtras, 25 | }; 26 | 27 | public: 28 | ScreencapAgent(MaaAdbScreencapMethod methods, const std::filesystem::path& agent_path); 29 | virtual ~ScreencapAgent() override = default; 30 | 31 | public: // from UnitBase 32 | virtual bool parse(const json::value& config) override; 33 | 34 | public: // from ScreencapBase 35 | virtual bool init() override; 36 | 37 | virtual std::optional screencap() override; 38 | 39 | public: // from ControlUnitSink 40 | virtual void on_image_resolution_changed(const std::pair& pre, const std::pair& cur) override; 41 | virtual void on_app_started(const std::string& intent) override; 42 | virtual void on_app_stopped(const std::string& intent) override; 43 | 44 | private: 45 | std::shared_ptr speed_test(); 46 | 47 | std::unordered_map> units_; 48 | std::shared_ptr active_unit_; 49 | }; 50 | 51 | MAA_CTRL_UNIT_NS_END 52 | -------------------------------------------------------------------------------- /source/MaaToolkit/Config/GlobalOptionConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include "Common/Conf.h" 12 | #include "MaaFramework/MaaDef.h" 13 | #include "MaaUtils/SingletonHolder.hpp" 14 | 15 | MAA_TOOLKIT_NS_BEGIN 16 | 17 | class GlobalOptionConfig : public SingletonHolder 18 | { 19 | friend class SingletonHolder; 20 | 21 | public: 22 | inline static const std::filesystem::path kConfigPath = "config/maa_option.json"; 23 | inline static const std::filesystem::path kDebugDir = "debug"; 24 | 25 | public: 26 | struct Option 27 | { 28 | bool logging = true; 29 | bool save_draw = false; 30 | bool save_on_error = true; 31 | int32_t stdout_level = MaaLoggingLevel_Error; 32 | int draw_quality = 85; 33 | 34 | MEO_JSONIZATION(MEO_OPT logging, MEO_OPT save_draw, MEO_OPT save_on_error, MEO_OPT stdout_level, MEO_OPT draw_quality); 35 | }; 36 | 37 | public: 38 | bool init(const std::filesystem::path& user_path, const json::value& default_config); 39 | 40 | private: 41 | GlobalOptionConfig() = default; 42 | 43 | bool load(); 44 | bool apply_option(); 45 | 46 | bool save() const; 47 | 48 | private: 49 | std::filesystem::path config_path_; 50 | std::filesystem::path debug_dir_; 51 | 52 | private: 53 | Option option_; 54 | }; 55 | 56 | MAA_TOOLKIT_NS_END 57 | -------------------------------------------------------------------------------- /source/MaaWin32ControlUnit/Input/PostThreadMessageInput.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ControlUnit/ControlUnitAPI.h" 4 | 5 | #include "Base/UnitBase.h" 6 | #include "MaaUtils/SafeWindows.hpp" 7 | 8 | #include "Common/Conf.h" 9 | 10 | MAA_CTRL_UNIT_NS_BEGIN 11 | 12 | class PostThreadMessageInput : public InputBase 13 | { 14 | public: 15 | PostThreadMessageInput(HWND hwnd); 16 | virtual ~PostThreadMessageInput() override = default; 17 | 18 | public: // from InputBase 19 | virtual MaaControllerFeature get_features() const override; 20 | 21 | virtual bool click(int x, int y) override; 22 | virtual bool swipe(int x1, int y1, int x2, int y2, int duration) override; 23 | 24 | virtual bool touch_down(int contact, int x, int y, int pressure) override; 25 | virtual bool touch_move(int contact, int x, int y, int pressure) override; 26 | virtual bool touch_up(int contact) override; 27 | 28 | virtual bool click_key(int key) override; 29 | 30 | virtual bool input_text(const std::string& text) override; 31 | 32 | virtual bool key_down(int key) override; 33 | virtual bool key_up(int key) override; 34 | 35 | virtual bool scroll(int dx, int dy) override; 36 | 37 | private: 38 | void ensure_foreground(); 39 | // 获取 last_pos_,若未设置则返回窗口客户区中心坐标 40 | std::pair get_target_pos() const; 41 | 42 | HWND hwnd_ = nullptr; 43 | DWORD thread_id_ = 0; 44 | std::pair last_pos_; 45 | bool last_pos_set_ = false; 46 | }; 47 | 48 | MAA_CTRL_UNIT_NS_END 49 | 50 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/apis/client.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include "../foundation/spec.h" 13 | #include "controller.h" 14 | #include "resource.h" 15 | #include "tasker.h" 16 | 17 | struct ClientImpl : public maajs::NativeClassBase 18 | { 19 | MaaAgentClient* client {}; 20 | 21 | ClientImpl() = default; 22 | ClientImpl(std::string identifier); 23 | ~ClientImpl(); 24 | void destroy(); 25 | std::string get_identifier(); 26 | void bind_resource(maajs::NativeObject resource); 27 | void register_resource_sink(maajs::NativeObject resource); 28 | void register_controller_sink(maajs::NativeObject controller); 29 | void register_tasker_sink(maajs::NativeObject); 30 | maajs::PromiseType connect(); 31 | void disconnect(); 32 | bool get_connected(); 33 | bool get_alive(); 34 | void set_timeout(uint64_t ms); 35 | std::optional> get_custom_recognition_list(); 36 | std::optional> get_custom_action_list(); 37 | 38 | std::string to_string() override; 39 | 40 | constexpr static char name[] = "Client"; 41 | 42 | static ClientImpl* ctor(const maajs::CallbackInfo& info); 43 | static void init_proto(maajs::ObjectType proto, maajs::FunctionType ctor); 44 | }; 45 | 46 | -------------------------------------------------------------------------------- /source/MaaWin32ControlUnit/Screencap/DesktopDupScreencap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Base/UnitBase.h" 4 | #include "SafeDXGI.hpp" 5 | 6 | #include "Common/Conf.h" 7 | 8 | MAA_CTRL_UNIT_NS_BEGIN 9 | 10 | class DesktopDupScreencap : public ScreencapBase 11 | { 12 | public: 13 | explicit DesktopDupScreencap(HWND hwnd = nullptr) 14 | : hwnd_(hwnd) 15 | { 16 | } 17 | 18 | virtual ~DesktopDupScreencap() override; 19 | 20 | public: // from ScreencapBase 21 | virtual std::optional screencap() override; 22 | 23 | protected: 24 | bool init(); 25 | bool init_texture(ID3D11Texture2D* raw_texture); 26 | void uninit(); 27 | std::optional screencap_impl(); 28 | 29 | ID3D11Device* d3d_device_ = nullptr; 30 | ID3D11DeviceContext* d3d_context_ = nullptr; 31 | IDXGIFactory* dxgi_factory_ = nullptr; 32 | IDXGIAdapter* dxgi_adapter_ = nullptr; 33 | IDXGIOutput1* dxgi_output_ = nullptr; 34 | IDXGIOutputDuplication* dxgi_dup_ = nullptr; 35 | 36 | ID3D11Texture2D* readable_texture_ = nullptr; 37 | D3D11_TEXTURE2D_DESC texture_desc_ { 0 }; 38 | 39 | HWND hwnd_ = nullptr; 40 | HMONITOR current_monitor_ = nullptr; 41 | bool output_just_initialized_ = false; 42 | 43 | private: 44 | bool init_d3d_device(); 45 | bool init_dxgi_factory(); 46 | bool find_output_by_monitor(HMONITOR monitor); 47 | bool init_primary_output(); 48 | bool init_output_duplication(); 49 | bool ensure_output_for_monitor(); 50 | }; 51 | 52 | MAA_CTRL_UNIT_NS_END 53 | -------------------------------------------------------------------------------- /source/include/Common/TaskResultTypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "MaaFramework/MaaDef.h" 6 | #include "MaaUtils/JsonExt.hpp" 7 | #include "MaaUtils/NoWarningCVMat.hpp" 8 | 9 | #include "Common/Conf.h" 10 | 11 | MAA_TASK_NS_BEGIN 12 | 13 | using ImageEncodedBuffer = std::vector; 14 | 15 | struct RecoResult 16 | { 17 | MaaRecoId reco_id = MaaInvalidId; 18 | std::string name; 19 | std::string algorithm; 20 | std::optional box = std::nullopt; 21 | json::value detail; 22 | ImageEncodedBuffer raw; 23 | std::vector draws; 24 | 25 | MEO_TOJSON(reco_id, name, algorithm, box, detail); 26 | }; 27 | 28 | struct ActionResult 29 | { 30 | MaaActId action_id = MaaInvalidId; 31 | std::string name; 32 | std::string action; 33 | cv::Rect box {}; 34 | bool success = false; 35 | json::value detail; 36 | 37 | MEO_TOJSON(action_id, name, action, box, success, detail); 38 | }; 39 | 40 | struct NodeDetail 41 | { 42 | MaaNodeId node_id = MaaInvalidId; 43 | std::string name; 44 | MaaRecoId reco_id = MaaInvalidId; 45 | MaaActId action_id = MaaInvalidId; 46 | bool completed = false; 47 | 48 | MEO_TOJSON(node_id, name, reco_id, action_id, completed); 49 | }; 50 | 51 | struct TaskDetail 52 | { 53 | MaaTaskId task_id = MaaInvalidId; 54 | std::string entry; 55 | std::vector node_ids; 56 | MaaStatus status = MaaStatus_Invalid; 57 | 58 | MEO_TOJSON(task_id, entry, node_ids, status); 59 | }; 60 | 61 | MAA_TASK_NS_END 62 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/Base/ProcessArgvGenerator.cpp: -------------------------------------------------------------------------------- 1 | #include "ProcessArgvGenerator.h" 2 | 3 | #include "MaaUtils/IOStream/BoostIO.hpp" 4 | #include "MaaUtils/Logger.h" 5 | #include "MaaUtils/Platform.h" 6 | 7 | MAA_CTRL_UNIT_NS_BEGIN 8 | 9 | std::optional ProcessArgvGenerator::create(const json::array& arr) 10 | { 11 | if (!arr.all()) { 12 | LogError << "array not all string" << VAR(arr); 13 | return std::nullopt; 14 | } 15 | 16 | auto raw = arr.as>(); 17 | if (raw.empty()) { 18 | LogError << "array is empty"; 19 | return std::nullopt; 20 | } 21 | 22 | return ProcessArgvGenerator(std::move(raw)); 23 | } 24 | 25 | std::optional ProcessArgvGenerator::gen(const Replacement& replacement) const 26 | { 27 | if (raw_.empty()) { 28 | LogError << "raw is empty"; 29 | return std::nullopt; 30 | } 31 | 32 | auto res = raw_; 33 | for (auto& s : res) { 34 | string_replace_all_(s, replacement); 35 | } 36 | 37 | std::filesystem::path exec = boost::process::search_path(path(res.front())); 38 | if (!std::filesystem::exists(exec)) { 39 | LogError << "exec path not exists" << VAR(res.front()) << VAR(exec); 40 | return std::nullopt; 41 | } 42 | 43 | auto args = std::vector(std::make_move_iterator(res.begin() + 1), std::make_move_iterator(res.end())); 44 | 45 | return ProcessArgv { .exec = std::move(exec), .args = std::move(args) }; 46 | } 47 | 48 | MAA_CTRL_UNIT_NS_END 49 | -------------------------------------------------------------------------------- /source/MaaWin32ControlUnit/Input/SeizeInput.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ControlUnit/ControlUnitAPI.h" 4 | 5 | #include "Base/UnitBase.h" 6 | #include "MaaUtils/SafeWindows.hpp" 7 | 8 | #include "Common/Conf.h" 9 | 10 | MAA_CTRL_UNIT_NS_BEGIN 11 | 12 | class SeizeInput : public InputBase 13 | { 14 | public: 15 | SeizeInput(HWND hwnd, bool block_input = false) 16 | : hwnd_(hwnd) 17 | , block_input_(block_input) 18 | { 19 | } 20 | 21 | virtual ~SeizeInput() override; 22 | 23 | public: // from InputBase 24 | virtual MaaControllerFeature get_features() const override; 25 | 26 | virtual bool click(int x, int y) override; 27 | virtual bool swipe(int x1, int y1, int x2, int y2, int duration) override; 28 | 29 | virtual bool touch_down(int contact, int x, int y, int pressure) override; 30 | virtual bool touch_move(int contact, int x, int y, int pressure) override; 31 | virtual bool touch_up(int contact) override; 32 | 33 | virtual bool click_key(int key) override; 34 | virtual bool input_text(const std::string& text) override; 35 | 36 | virtual bool key_down(int key) override; 37 | virtual bool key_up(int key) override; 38 | 39 | virtual bool scroll(int dx, int dy) override; 40 | 41 | private: 42 | void ensure_foreground(); 43 | // 获取 last_pos_,若未设置则返回窗口客户区中心坐标 44 | std::pair get_target_pos() const; 45 | 46 | HWND hwnd_ = nullptr; 47 | const bool block_input_ = false; 48 | 49 | std::pair last_pos_; 50 | bool last_pos_set_ = false; 51 | }; 52 | 53 | MAA_CTRL_UNIT_NS_END 54 | -------------------------------------------------------------------------------- /source/MaaFramework/Vision/NeuralNetworkClassifier.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "MaaUtils/JsonExt.hpp" 10 | #include "VisionBase.h" 11 | #include "VisionTypes.h" 12 | 13 | #include "Common/Conf.h" 14 | 15 | MAA_VISION_NS_BEGIN 16 | 17 | struct NeuralNetworkClassifierResult 18 | { 19 | size_t cls_index = SIZE_MAX; 20 | std::string label; 21 | cv::Rect box {}; 22 | double score = 0.0; 23 | std::vector raw; 24 | std::vector probs; 25 | 26 | MEO_JSONIZATION(cls_index, label, box, score); 27 | }; 28 | 29 | class NeuralNetworkClassifier 30 | : public VisionBase 31 | , public RecoResultAPI 32 | { 33 | public: 34 | NeuralNetworkClassifier( 35 | cv::Mat image, 36 | cv::Rect roi, 37 | NeuralNetworkClassifierParam param, 38 | std::shared_ptr session, 39 | const Ort::MemoryInfo& memory_info, 40 | std::string name = ""); 41 | 42 | private: 43 | void analyze(); 44 | 45 | Result classify() const; 46 | 47 | void add_results(ResultsVec results, const std::vector& expected); 48 | void cherry_pick(); 49 | 50 | private: 51 | cv::Mat draw_result(const Result& res) const; 52 | void sort_(ResultsVec& results) const; 53 | 54 | private: 55 | const NeuralNetworkClassifierParam param_; 56 | std::shared_ptr session_ = nullptr; 57 | const Ort::MemoryInfo& memory_info_; 58 | }; 59 | 60 | MAA_VISION_NS_END 61 | -------------------------------------------------------------------------------- /source/MaaFramework/Global/PluginMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define BOOST_DLL_USE_STD_FS 1 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include "Common/Conf.h" 12 | #include "MaaFramework/MaaDef.h" 13 | #include "MaaPlugin/MaaPluginAPI.h" 14 | #include "MaaUtils/LibraryHolder.h" 15 | #include "MaaUtils/SingletonHolder.hpp" 16 | 17 | MAA_GLOBAL_NS_BEGIN 18 | 19 | class PluginMgr : public SingletonHolder 20 | { 21 | public: 22 | using Sink = void (*)(void* handle, const char* message, const char* details_json, void* trans_arg); 23 | 24 | struct Plugin 25 | { 26 | boost::dll::shared_library library; 27 | Sink on_res_event = nullptr; 28 | Sink on_ctrl_event = nullptr; 29 | Sink on_tasker_event = nullptr; 30 | Sink on_ctx_event = nullptr; 31 | }; 32 | 33 | public: 34 | friend class SingletonHolder; 35 | 36 | public: 37 | bool load(const std::filesystem::path& library_path); 38 | 39 | std::vector get_names() const; 40 | std::vector get_res_sinks() const; 41 | std::vector get_ctrl_sinks() const; 42 | std::vector get_tasker_sinks() const; 43 | std::vector get_ctx_sinks() const; 44 | 45 | private: 46 | std::optional load_dll(const std::filesystem::path& library_path); 47 | bool load_and_parse(const std::filesystem::path& library_path); 48 | 49 | private: 50 | std::unordered_map plugins_; 51 | }; 52 | 53 | MAA_GLOBAL_NS_END 54 | -------------------------------------------------------------------------------- /source/MaaToolkit/AdbDevice/AdbDeviceMacOSFinder.cpp: -------------------------------------------------------------------------------- 1 | #if defined(__APPLE__) 2 | 3 | #include "AdbDeviceMacOSFinder.h" 4 | 5 | #include 6 | 7 | MAA_TOOLKIT_NS_BEGIN 8 | 9 | using namespace path_literals; 10 | 11 | const AdbDeviceFinder::EmulatorConstDataMap& AdbDeviceMacOSFinder::get_emulator_const_data() const 12 | { 13 | static const EmulatorConstDataMap kConstData { 14 | { "Nox", 15 | { .keyword = "Nox", .adb_candidate_paths = { "adb"_path }, .adb_common_serials = { "127.0.0.1:62001", "127.0.0.1:59865" } } }, 16 | 17 | { "MuMuPlayerPro", 18 | { .keyword = "MuMuEmulator", 19 | .adb_candidate_paths = { "tools/adb"_path }, 20 | .adb_common_serials = { "127.0.0.1:16384", "127.0.0.1:16416" } } }, 21 | 22 | { "AVD", 23 | { .keyword = "qemu-system", 24 | .adb_candidate_paths = { "../../../platform-tools/adb"_path }, 25 | .adb_common_serials = { "emulator-5554", "127.0.0.1:5555" } } }, 26 | 27 | { "Genymotion", 28 | { .keyword = "genymotion", 29 | .adb_candidate_paths = { "player.app/Contents/MacOS/tools/adb"_path }, 30 | .adb_common_serials = { "127.0.0.1:6555" } } }, 31 | 32 | { "BlueStacks", 33 | { .keyword = "BlueStacks", 34 | .adb_candidate_paths = { "hd-adb"_path, "BlueStacks.app/Contents/MacOS/hd-adb"_path }, 35 | .adb_common_serials = { "127.0.0.1:5555", "127.0.0.1:5556", "127.0.0.1:5565", "127.0.0.1:5575" } } }, 36 | }; 37 | 38 | return kConstData; 39 | } 40 | 41 | MAA_TOOLKIT_NS_END 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/General/DeviceList.cpp: -------------------------------------------------------------------------------- 1 | #include "DeviceList.h" 2 | 3 | #include 4 | 5 | #include "MaaUtils/Logger.h" 6 | #include "MaaUtils/StringMisc.hpp" 7 | 8 | MAA_CTRL_UNIT_NS_BEGIN 9 | 10 | bool DeviceList::parse(const json::value& config) 11 | { 12 | static const json::array kDefaultDevicesArgv = { 13 | "{ADB}", 14 | "devices", 15 | }; 16 | 17 | return parse_command("Devices", config, kDefaultDevicesArgv, devices_argv_); 18 | } 19 | 20 | std::optional> DeviceList::request_devices() 21 | { 22 | LogFunc; 23 | 24 | auto argv_opt = devices_argv_.gen(argv_replace_); 25 | if (!argv_opt) { 26 | return std::nullopt; 27 | } 28 | 29 | auto output_opt = startup_and_read_pipe(*argv_opt); 30 | if (!output_opt) { 31 | return std::nullopt; 32 | } 33 | 34 | // like: 35 | // List of devices attached 36 | // 127.0.0.1:16384 offline 37 | // 127.0.0.1:16416 device 38 | auto devices_str = std::move(output_opt).value(); 39 | auto lines = string_split(devices_str, '\n'); 40 | if (lines.empty()) { 41 | return {}; 42 | } 43 | lines.erase(lines.begin()); // remove "List of devices attached" 44 | 45 | std::vector devices; 46 | for (auto&& line : lines) { 47 | if (line.find("device") == std::string::npos) { 48 | continue; 49 | } 50 | string_trim_(line); 51 | devices.emplace_back(string_split(line, '\t')[0]); 52 | } 53 | LogInfo << VAR(devices); 54 | 55 | return devices; 56 | } 57 | 58 | MAA_CTRL_UNIT_NS_END 59 | -------------------------------------------------------------------------------- /test/pipeline/module/PipelineSmoking.cpp: -------------------------------------------------------------------------------- 1 | #include "PipelineSmoking.h" 2 | 3 | #include "MaaFramework/MaaAPI.h" 4 | 5 | bool pipeline_smoking(const std::filesystem::path& testset_dir) 6 | { 7 | auto testing_path = testset_dir / "PipelineSmoking" / "MaaRecording.txt"; 8 | auto result_path = testset_dir / "debug"; 9 | 10 | auto controller_handle = 11 | MaaDbgControllerCreate(testing_path.string().c_str(), result_path.string().c_str(), MaaDbgControllerType_ReplayRecording, "{}"); 12 | 13 | auto ctrl_id = MaaControllerPostConnection(controller_handle); 14 | 15 | auto resource_handle = MaaResourceCreate(); 16 | auto resource_dir = testset_dir / "PipelineSmoking" / "resource"; 17 | auto res_id = MaaResourcePostBundle(resource_handle, resource_dir.string().c_str()); 18 | 19 | MaaControllerWait(controller_handle, ctrl_id); 20 | MaaResourceWait(resource_handle, res_id); 21 | 22 | auto tasker_handle = MaaTaskerCreate(); 23 | MaaTaskerBindResource(tasker_handle, resource_handle); 24 | MaaTaskerBindController(tasker_handle, controller_handle); 25 | 26 | auto destroy = [&]() { 27 | MaaTaskerDestroy(tasker_handle); 28 | MaaResourceDestroy(resource_handle); 29 | MaaControllerDestroy(controller_handle); 30 | }; 31 | 32 | if (!MaaTaskerInited(tasker_handle)) { 33 | destroy(); 34 | return false; 35 | } 36 | 37 | auto task_id = MaaTaskerPostTask(tasker_handle, "Wilderness", "{}"); 38 | auto status = MaaTaskerWait(tasker_handle, task_id); 39 | 40 | destroy(); 41 | 42 | return status == MaaStatus_Succeeded; 43 | } 44 | -------------------------------------------------------------------------------- /source/include/ProjectInterface/Configurator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "Types.h" 7 | 8 | #include "Common/Conf.h" 9 | 10 | MAA_PROJECT_INTERFACE_NS_BEGIN 11 | 12 | class Configurator 13 | { 14 | static constexpr std::string_view kInterfaceFilename = "interface.json"; 15 | static constexpr std::string_view kConfigPath = "config/maa_pi_config.json"; 16 | 17 | public: 18 | bool load(const std::filesystem::path& project_dir, const std::filesystem::path& user_dir); 19 | bool check_configuration(); 20 | void save(const std::filesystem::path& user_dir); 21 | 22 | std::optional generate_runtime() const; 23 | 24 | const auto& interface_data() const { return data_; } 25 | 26 | const auto& configuration() const { return config_; } 27 | 28 | auto& configuration() { return config_; } 29 | 30 | bool is_first_time_use() const { return first_time_use_; } 31 | 32 | const auto& resource_dir() const { return resource_dir_; } 33 | 34 | // 国际化文本翻译:如果文本以 $ 开头,则从翻译表中查找 35 | std::string translate(const std::string& text) const; 36 | 37 | private: 38 | std::optional generate_runtime_task(const Configuration::Task& config_task) const; 39 | void load_translations(); 40 | std::string detect_system_language() const; 41 | 42 | std::filesystem::path resource_dir_; 43 | 44 | InterfaceData data_; 45 | bool first_time_use_ = false; 46 | Configuration config_; 47 | std::unordered_map translations_; // 翻译表 48 | }; 49 | 50 | MAA_PROJECT_INTERFACE_NS_END 51 | -------------------------------------------------------------------------------- /source/MaaAdbControlUnit/EmulatorExtras/LDPlayerExtras.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _WIN32 4 | 5 | #include "Base/UnitBase.h" 6 | #include "General/DeviceInfo.h" 7 | #include "MaaUtils/LibraryHolder.h" 8 | 9 | #include "MaaUtils/SafeWindows.hpp" // for dnopengl 10 | 11 | #include "Common/Conf.h" 12 | 13 | namespace dnopengl 14 | { 15 | #include "LD/dnopengl/dnopengl.h" 16 | } 17 | 18 | MAA_CTRL_UNIT_NS_BEGIN 19 | 20 | class LDPlayerExtras 21 | : public LibraryHolder 22 | , public ScreencapBase 23 | { 24 | public: 25 | LDPlayerExtras() { children_.emplace_back(device_info_); } 26 | 27 | virtual ~LDPlayerExtras() override; 28 | 29 | public: // from UnitBase 30 | virtual bool parse(const json::value& config) override; 31 | 32 | public: // from ScreencapBase 33 | virtual bool init() override; 34 | 35 | virtual std::optional screencap() override; 36 | 37 | private: 38 | bool load_ld_library(); 39 | bool create_ld_instance(); 40 | void release_ld_instance(); 41 | 42 | private: 43 | std::filesystem::path lib_path_; 44 | 45 | unsigned int ld_index_ = 0; 46 | unsigned int ld_pid_ = 0; 47 | dnopengl::IScreenShotClass* ld_handle_ = nullptr; 48 | 49 | std::shared_ptr device_info_ = std::make_shared(); 50 | 51 | int display_width_ = 0; 52 | int display_height_ = 0; 53 | 54 | private: 55 | inline static const std::string kCreateInstanceFuncName = "CreateScreenShotInstance"; 56 | boost::function create_instance_func_; 57 | }; 58 | 59 | MAA_CTRL_UNIT_NS_END 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /docs/zh_cn/4.1-构建指南.md: -------------------------------------------------------------------------------- 1 | # 构建指南 2 | 3 | > [!TIP] 4 | > _仅当您准备开发 MaaFramework 本身时,才需要阅读本章节内容。若您仅希望基于 MaaFramework 开发自己的应用,则请参考 [快速开始](1.1-快速开始.md)。_ 5 | 6 | 开始前,请确保已安装 Git、Python 3、CMake 3.24+,以及对应平台的编译链(Windows: MSVC 2022;Linux/macOS: Ninja + g++/clang)。 7 | 8 | ## 本地开发 9 | 10 | 1. 完整克隆本仓库及子模块(推荐一次性同步) 11 | 12 | 子模块包含第三方依赖,构建前必须初始化,可重复执行以保证同步。 13 | 14 | ```sh 15 | git clone --recurse-submodules https://github.com/MaaXYZ/MaaFramework.git 16 | ``` 17 | 18 | 或 19 | 20 | ```sh 21 | git clone https://github.com/MaaXYZ/MaaFramework.git 22 | cd MaaFramework 23 | git submodule update --init --recursive 24 | ``` 25 | 26 | 2. 下载 MaaDeps prebuilt 27 | 28 | ```sh 29 | python3 tools/maadeps-download.py 30 | ``` 31 | 32 | 脚本会自动下载并校验预编译依赖,如遇网络问题可重复执行。 33 | 34 | 3. 配置 CMake 预设 35 | 36 | - Windows 37 | 38 | ```bash 39 | cmake --preset "MSVC 2022" 40 | ``` 41 | 42 | - Linux / macOS 43 | 44 | ```bash 45 | cmake --preset "NinjaMulti" 46 | ``` 47 | 48 | 4. 构建并安装 49 | 50 | ```bash 51 | cmake --build build --config Release 52 | cmake --install build --prefix install 53 | ``` 54 | 55 | 根据需要可将 `--config` 切换为 `Debug`/`RelWithDebInfo`。生成的二进制及相关文件默认位于 `install` 目录。 56 | 57 | 详情请参考 [Build CI](https://github.com/MaaXYZ/MaaFramework/blob/main/.github/workflows/build.yml) 。 58 | 59 | ## 在线开发 60 | 61 | 使用 Codespaces (Dev Container) 一键配置基础开发环境 (Ninja、Cmake、g++-13): 62 | 63 | [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=master&repo=632024122) 64 | 65 | 随后按照 [本地开发](#本地开发) 流程进行配置。 66 | -------------------------------------------------------------------------------- /3rdparty/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(HeaderOnlyLibraries INTERFACE) 2 | target_include_directories(HeaderOnlyLibraries INTERFACE include) 3 | 4 | add_library(EmulatorExtras INTERFACE) 5 | target_include_directories(EmulatorExtras INTERFACE EmulatorExtras) 6 | 7 | if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/MaaAgentBinary/README.md) 8 | add_custom_target(AgentBinary ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/MaaAgentBinary) 9 | 10 | # set_property( TARGET AgentBinary APPEND PROPERTY ADDITIONAL_CLEAN_FILES 11 | # ${CMAKE_CURRENT_SOURCE_DIR}/MaaAgentBinary) 12 | set_target_properties(AgentBinary PROPERTIES FOLDER Assets) 13 | install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/MaaAgentBinary DESTINATION share) 14 | else() 15 | message(STATUS "MaaAgentBinary not found, skipping") 16 | endif() 17 | 18 | if(WITH_QUICKJS_BINDING) 19 | add_subdirectory(quickjs EXCLUDE_FROM_ALL) 20 | add_library(qjs_headers INTERFACE) 21 | target_include_directories(qjs_headers INTERFACE quickjs) 22 | 23 | if(MSVC) 24 | target_compile_options( 25 | qjs 26 | PRIVATE /wd4146 27 | /wd4668 28 | /wd4132 29 | /wd4334 30 | /wd4702 31 | /wd4701 32 | /wd4746 33 | /wd4244) 34 | elseif(LINUX) 35 | target_compile_options(qjs PRIVATE -Wno-error=unused-command-line-argument) 36 | endif() 37 | endif() 38 | 39 | add_custom_target(MaaPlugin ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/include/MaaPlugin) 40 | set_target_properties(MaaPlugin PROPERTIES FOLDER Assets) 41 | install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/MaaPlugin DESTINATION share) 42 | -------------------------------------------------------------------------------- /source/MaaFramework/Vision/NeuralNetworkDetector.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "MaaUtils/JsonExt.hpp" 7 | #include "VisionBase.h" 8 | #include "VisionTypes.h" 9 | 10 | #include 11 | 12 | #include "Common/Conf.h" 13 | 14 | MAA_VISION_NS_BEGIN 15 | 16 | struct NeuralNetworkDetectorResult 17 | { 18 | size_t cls_index = SIZE_MAX; 19 | std::string label; 20 | cv::Rect box {}; 21 | double score = 0.0; 22 | 23 | MEO_JSONIZATION(cls_index, label, box, score); 24 | }; 25 | 26 | class NeuralNetworkDetector 27 | : public VisionBase 28 | , public RecoResultAPI 29 | { 30 | public: 31 | NeuralNetworkDetector( 32 | cv::Mat image, 33 | cv::Rect roi, 34 | NeuralNetworkDetectorParam param, 35 | std::shared_ptr session, 36 | const Ort::MemoryInfo& memory_info, 37 | std::string name = ""); 38 | 39 | private: 40 | void analyze(); 41 | 42 | ResultsVec detect(const std::vector& labels) const; 43 | 44 | void add_results(ResultsVec results, const std::vector& expected, const std::vector& thresholds); 45 | void cherry_pick(); 46 | 47 | private: 48 | cv::Mat draw_result(const ResultsVec& results) const; 49 | void sort_(ResultsVec& results) const; 50 | 51 | private: 52 | std::vector parse_labels_from_metadata() const; 53 | 54 | private: 55 | const NeuralNetworkDetectorParam param_; 56 | std::shared_ptr session_ = nullptr; 57 | const Ort::MemoryInfo& memory_info_; 58 | }; 59 | 60 | MAA_VISION_NS_END 61 | -------------------------------------------------------------------------------- /tools/ImageCropper/roimage.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | from numpy import ndarray 4 | from roi import Roi 5 | import cv2 6 | 7 | class Roimage(Roi): 8 | def __init__(self, width: float, height: float, x: float = 0 , y: float = 0, parent: Roimage = None, zoom: float = 1) -> None: 9 | Roi.__init__(self, width, height, x, y, parent, zoom) 10 | self.__image: ndarray = None 11 | self.zoom_image_cache = {} 12 | 13 | @property 14 | def image(self): 15 | ''' 16 | 获取当前 Roi 的图片,如果没有则从父 Roi 裁剪 17 | 18 | 或设置当前 Roi 的图片 19 | ''' 20 | if self.__image is not None: 21 | return self.__image 22 | 23 | if self.zoom == 1: 24 | img = self.parent.image 25 | else: 26 | parent_img: ndarray = self.parent.image 27 | cache = self.parent.zoom_image_cache 28 | # 缓存过期 29 | if (parent_img != cache.get(self.parent.size)).any(): 30 | cache.clear() 31 | cache[self.parent.size] = parent_img.copy() 32 | # 命中缓存 33 | size = (int(self.parent.width * self.zoom), int(self.parent.height * self.zoom)) 34 | img = cache.get(size) 35 | # 没命中 36 | if img is None: 37 | img = cache.setdefault( 38 | size, 39 | cv2.resize(parent_img, size, interpolation=cv2.INTER_AREA)) 40 | return img[ 41 | int(self.y): int(self.y + self.height), 42 | int(self.x): int(self.x + self.width) 43 | ] 44 | 45 | @image.setter 46 | def image(self, value): 47 | self.__image = value 48 | -------------------------------------------------------------------------------- /sample/resource/pipeline/common.json: -------------------------------------------------------------------------------- 1 | { 2 | "Pinch": { 3 | "action": "MultiSwipe", 4 | "swipes": [ 5 | { 6 | "begin": [ 7 | 100, 8 | 100, 9 | 0, 10 | 0 11 | ], 12 | "end": [ 13 | 500, 14 | 300, 15 | 0, 16 | 0 17 | ] 18 | }, 19 | { 20 | "begin": [ 21 | 1000, 22 | 600, 23 | 0, 24 | 0 25 | ], 26 | "end": [ 27 | 700, 28 | 400, 29 | 0, 30 | 0 31 | ] 32 | }] 33 | }, 34 | "Unpinch": { 35 | "action": "MultiSwipe", 36 | "swipes": [ 37 | { 38 | "begin": [ 39 | 500, 40 | 300, 41 | 0, 42 | 0 43 | ], 44 | "end": [ 45 | 100, 46 | 100, 47 | 0, 48 | 0 49 | ] 50 | }, 51 | { 52 | "begin": [ 53 | 700, 54 | 400, 55 | 0, 56 | 0 57 | ], 58 | "end": [ 59 | 1000, 60 | 600, 61 | 0, 62 | 0 63 | ] 64 | } 65 | ] 66 | } 67 | } -------------------------------------------------------------------------------- /source/MaaDbgControlUnit/ReplayRecording/ReplayRecording.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "ControlUnit/ControlUnitAPI.h" 8 | #include "Record.h" 9 | 10 | #include "Common/Conf.h" 11 | 12 | MAA_CTRL_UNIT_NS_BEGIN 13 | 14 | class ReplayRecording : public ControlUnitAPI 15 | { 16 | public: 17 | explicit ReplayRecording(Recording recording); 18 | 19 | virtual ~ReplayRecording() override; 20 | 21 | public: // from ControlUnitAPI 22 | virtual bool connect() override; 23 | 24 | virtual bool request_uuid(/*out*/ std::string& uuid) override; 25 | virtual MaaControllerFeature get_features() const override; 26 | 27 | virtual bool start_app(const std::string& intent) override; 28 | virtual bool stop_app(const std::string& intent) override; 29 | 30 | virtual bool screencap(/*out*/ cv::Mat& image) override; 31 | 32 | virtual bool click(int x, int y) override; 33 | virtual bool swipe(int x1, int y1, int x2, int y2, int duration) override; 34 | 35 | virtual bool touch_down(int contact, int x, int y, int pressure) override; 36 | virtual bool touch_move(int contact, int x, int y, int pressure) override; 37 | virtual bool touch_up(int contact) override; 38 | 39 | virtual bool click_key(int key) override; 40 | virtual bool input_text(const std::string& text) override; 41 | 42 | virtual bool key_down(int key) override; 43 | virtual bool key_up(int key) override; 44 | 45 | virtual bool scroll(int dx, int dy) override; 46 | 47 | private: 48 | void sleep(int ms); 49 | 50 | private: 51 | Recording recording_; 52 | size_t record_index_ = 0; 53 | }; 54 | 55 | MAA_CTRL_UNIT_NS_END 56 | -------------------------------------------------------------------------------- /sample/csharp/3.AgentChild.csx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env dotnet-script 2 | #nullable enable 3 | 4 | #r "nuget: Maa.Framework.Binding.Native, 4.2.0" 5 | 6 | using MaaFramework.Binding; 7 | using MaaFramework.Binding.Custom; 8 | 9 | var commandLineArgs = Environment.GetCommandLineArgs(); 10 | if (commandLineArgs.Length < 4) 11 | { 12 | Console.WriteLine("Call AgentMain.cs instead of this file."); 13 | return 1; 14 | } 15 | 16 | var socketId = commandLineArgs[^1]; 17 | var userPath = commandLineArgs[^2]; 18 | var dllPath = commandLineArgs[^3]; 19 | 20 | MaaAgentServer.Current 21 | .WithIdentifier(socketId) 22 | .WithNativeLibrary(dllPath) 23 | .WithToolkitConfig_InitOption(userPath) 24 | .Register(new MyRec()) 25 | .Register(new MyAct()) 26 | .StartUp() 27 | .Join() 28 | .ShutDown(); 29 | 30 | internal sealed class MyRec : IMaaCustomRecognition 31 | { 32 | public string Name { get; set; } = "TestRecognition"; 33 | 34 | public bool Analyze(in IMaaContext context, in AnalyzeArgs args, in AnalyzeResults results) 35 | { 36 | Console.WriteLine("{0} Called", Name); 37 | 38 | return results.Box.TrySetValues(0, 0, 100, 100) 39 | && results.Detail.TrySetValue("Hello Client!"); 40 | } 41 | } 42 | 43 | internal sealed class MyAct : IMaaCustomAction 44 | { 45 | public string Name { get; set; } = "TestAction"; 46 | 47 | public bool Run(in IMaaContext context, in RunArgs args, in RunResults results) 48 | { 49 | Console.WriteLine("{0} Called", Name); 50 | Console.WriteLine("recognition detail: {0}", args.RecognitionDetail); 51 | Console.WriteLine("custom action param: {0}", args.ActionParam); 52 | 53 | return true; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /source/binding/NodeJS/src/apis/context.d.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | namespace maa { 3 | class Context { 4 | constructor(handle?: string) 5 | 6 | run_task( 7 | entry: string, 8 | pipeline_override?: Record | Record[], 9 | ): Promise 10 | run_recognition( 11 | entry: string, 12 | image: ImageData | Buffer, 13 | pipeline_override?: Record | Record[], 14 | ): Promise 15 | run_action( 16 | entry: string, 17 | box: Rect, 18 | reco_detail: string, 19 | pipeline_override?: Record | Record[], 20 | ): Promise 21 | override_pipeline( 22 | pipeline_override: Record | Record[], 23 | ): void 24 | override_next(node_name: string, next: string[]): void 25 | override_image(image_name: string, image: ImageData | Buffer): void 26 | get_node_data(node_name: string): string | null 27 | get_node_data_parsed(node_name: string): DumpTask | null 28 | get task_id(): TaskId 29 | get tasker(): Tasker 30 | clone(): Context 31 | set_anchor(anchor_name: string, node_name: string): void 32 | get_anchor(anchor_name: string): string | null 33 | get_hit_count(node_name: string): number 34 | clear_hit_count(node_name: string): void 35 | } 36 | } 37 | } 38 | 39 | export {} 40 | -------------------------------------------------------------------------------- /include/MaaToolkit/AdbDevice/MaaToolkitAdbDevice.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file MaaToolkitDevice.h 3 | * @author 4 | * @brief Toolkits for working with ADB controller. 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | // IWYU pragma: private, include 11 | 12 | #pragma once 13 | 14 | #include "../MaaToolkitDef.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" 18 | { 19 | #endif 20 | 21 | MAA_TOOLKIT_API MaaToolkitAdbDeviceList* MaaToolkitAdbDeviceListCreate(); 22 | MAA_TOOLKIT_API void MaaToolkitAdbDeviceListDestroy(MaaToolkitAdbDeviceList* handle); 23 | 24 | MAA_TOOLKIT_API MaaBool MaaToolkitAdbDeviceFind(/* out */ MaaToolkitAdbDeviceList* buffer); 25 | MAA_TOOLKIT_API MaaBool MaaToolkitAdbDeviceFindSpecified(const char* adb_path, /* out */ MaaToolkitAdbDeviceList* buffer); 26 | 27 | MAA_TOOLKIT_API MaaSize MaaToolkitAdbDeviceListSize(const MaaToolkitAdbDeviceList* list); 28 | MAA_TOOLKIT_API const MaaToolkitAdbDevice* MaaToolkitAdbDeviceListAt(const MaaToolkitAdbDeviceList* list, MaaSize index); 29 | 30 | MAA_TOOLKIT_API const char* MaaToolkitAdbDeviceGetName(const MaaToolkitAdbDevice* device); 31 | MAA_TOOLKIT_API const char* MaaToolkitAdbDeviceGetAdbPath(const MaaToolkitAdbDevice* device); 32 | MAA_TOOLKIT_API const char* MaaToolkitAdbDeviceGetAddress(const MaaToolkitAdbDevice* device); 33 | MAA_TOOLKIT_API MaaAdbScreencapMethod MaaToolkitAdbDeviceGetScreencapMethods(const MaaToolkitAdbDevice* device); 34 | MAA_TOOLKIT_API MaaAdbInputMethod MaaToolkitAdbDeviceGetInputMethods(const MaaToolkitAdbDevice* device); 35 | MAA_TOOLKIT_API const char* MaaToolkitAdbDeviceGetConfig(const MaaToolkitAdbDevice* device); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | --------------------------------------------------------------------------------