Skip to main content

Crate maa_framework

Crate maa_framework 

Source
Expand description

§MaaFramework Rust Bindings

High-performance, safe Rust bindings for MaaFramework, a game automation framework based on image recognition.

§Quick Start

use maa_framework::toolkit::Toolkit;
use maa_framework::controller::Controller;
use maa_framework::resource::Resource;
use maa_framework::tasker::Tasker;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 1. Find devices
    let devices = Toolkit::find_adb_devices()?;
    let device = devices.first().expect("No device found");

    // 2. Create controller
    let controller = Controller::new_adb(
        device.adb_path.to_str().unwrap(),
        &device.address,
        "{}",
        None,
    )?;

    // 3. Create resource and tasker
    let resource = Resource::new()?;
    let tasker = Tasker::new()?;

    // 4. Bind and run
    tasker.bind(&resource, &controller)?;
    let job = tasker.post_task("StartTask", "{}")?;
    job.wait();

    Ok(())
}

§Core Modules

ModuleDescription
taskerTask execution and pipeline management
resourceResource loading (images, models, pipelines)
controllerDevice control (ADB, Win32, PlayCover)
contextTask execution context for custom components
toolkitDevice discovery utilities
pipelinePipeline configuration types
jobAsynchronous job management
event_sinkEvent sink system for typed callbacks
bufferSafe data buffers for FFI
customCustom recognizer and action traits
custom_controllerCustom controller implementation
notificationStructured event notification parsing
commonCommon types and data structures
errorError types and handling
utilMiscellaneous utility functions
agent_clientRemote custom component client
agent_serverRemote custom component server

§Feature Flags

  • adb - ADB controller support (default)
  • win32 - Win32 controller support (Windows only)
  • custom - Custom recognizer/action/controller support
  • toolkit - Device discovery utilities
  • image - Integration with the image crate

Re-exports§

pub use common::ControllerFeature;
pub use common::MaaStatus;
pub use error::MaaError;
pub use error::MaaResult;

Modules§

agent_client
Agent client for connecting to AgentServer.
agent_server
Agent server for hosting custom components.
buffer
Safe buffer types for FFI data exchange.
callback
Internal callback infrastructure for FFI event handling.
common
Common types and data structures used throughout the SDK.
context
Task execution context for pipeline runtime operations.
controller
Device controller for input, screen capture, and app management.
custom
Custom recognizer and action components.
custom_controller
Custom controller implementation for user-defined device control.
error
Error types and result aliases for the MAA framework.
event_sink
Event sink system for typed callback notifications.
job
Asynchronous job management for tracking operation status and results.
notification
Structured notification parsing for event callbacks.
pipeline
Pipeline configuration types for recognition and action definitions.
resource
Resource management for pipelines, models, and images.
sys
Raw FFI bindings to the C API (auto-generated).
tasker
Task execution and pipeline management.
toolkit
Device discovery and configuration utilities.
util
Miscellaneous utility functions.

Functions§

configure_logging
Configure the log output directory.
load_plugin
Load a plugin from the specified path.
maa_version
Get the MaaFramework version string.
set_debug_mode
Enable or disable debug mode.
set_draw_quality
Set JPEG quality for saved draw images (0-100, default 85).
set_global_option
Set a global framework option.
set_reco_image_cache_limit
Set the recognition image cache limit (default 4096).
set_save_draw
Enable/disable saving recognition visualizations to log directory.
set_save_on_error
Enable/disable saving screenshots on error.
set_stdout_level
Set the log level for stdout output.