# pine-client

[![crates.io](https://img.shields.io/crates/v/pine-client?logo=rust)](https://crates.io/crates/pine-client)

`pine-client` is an async Rust library for the PCSX2 Pine IPC protocol. It provides a small, type-safe API for reading and writing emulator memory, querying game metadata, checking runtime state, and loading or saving save states from Tokio applications.

## Features

- Async client built on Tokio I/O.
- Type-safe wrappers for memory addresses, save-state slots, and endpoint selection.
- Default endpoint resolution for PCSX2 on Windows, macOS, and Linux.
- Lazy connection management with automatic reconnect after connection-invalidating failures.

## Installation

```toml
[dependencies]
pine-client = "0.1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
```

## Quick start

```rust
use pine_client::{MemoryAddress, PineClient, PineError};

async fn example() -> Result<(), PineError> {
    let client = PineClient::new()?;
    let health = client.read_u32(MemoryAddress::new(0x0034_7D34)).await?;
    println!("health = {health}");
    Ok(())
}
```

## Custom endpoints

```rust
use std::time::Duration;

use pine_client::{PineClient, PineEndpoint, PineError, PineOptions};

fn build_client() -> Result<PineClient, PineError> {
    PineClient::with_endpoint_and_options(
        PineEndpoint::Tcp {
            host: "127.0.0.1".to_string(),
            port: 28_011,
        },
        PineOptions {
            connect_timeout: Duration::from_secs(1),
            io_timeout: Duration::from_secs(1),
        },
    )
}
```

## Platform defaults

- **Windows:** `tcp://127.0.0.1:28011`
- **macOS / Linux:** `unix://<runtime-dir>/pcsx2.sock`
- Non-default slots follow PCSX2 naming: TCP uses the slot as the port, and Unix sockets use `pcsx2.sock.<slot>`.

## Supported operations

- Read and write `u8`, `u16`, `u32`, and `u64` values.
- Read and write arbitrary byte buffers.
- Query emulator version, title, serial, UUID/CRC, and game version.
- Read emulator status.
- Load and save save states.

## License

Licensed under the MIT license.
