Skip to content

Commit 8614021

Browse files
updates for linux and windows
1 parent 98878e4 commit 8614021

File tree

7 files changed

+480
-34
lines changed

7 files changed

+480
-34
lines changed

.github/copilot-instructions.md

Lines changed: 107 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,138 @@
11
# Copilot instructions for arrastools
22

3-
Purpose: Help AI coding agents work productively in this repo of desktop automation tools and a PPO-based Arras AI. Scripts control keyboard/mouse, read pixels, and automate gameplay/UI flows on macOS.
3+
Purpose: Help AI coding agents work productively in this repo of desktop automation tools and a PPO-based Arras AI. Scripts control keyboard/mouse, read pixels, and automate gameplay/UI flows across macOS, Linux, and Windows.
44

55
## Architecture and key files
66
- This is a collection of standalone Python scripts (no package/pytest). Common patterns repeat across files.
77
- Screen + input automation:
88
- `arrastools.py` — hotkey-driven macros using pynput. Listeners run at module end and spawn daemon threads via `start_*` helpers.
9+
- `arrastools2.py` — alternative version with similar functionality and cross-platform support.
910
- `arrasbot.py` — a watchdog that samples screen pixels with `mss`, reacts to state (disconnected/died/banned), and logs/screenshots.
11+
- `arrascopypasta.py` — copypasta automation with platform-agnostic file path handling using pathlib.
1012
- PPO AI prototype:
1113
- `arrasai.py` — defines PPO agent (PolicyNetwork, PPOMemory, ArrasAI) and training/exec loops over screen observations sampled in a polygon (`GAME_REGION`). Models saved to `arras_models/` (e.g., `arras_model.pt_best`).
1214
- Assets/data: `arras_models/`, `logs/`, `copypastas/`.
1315

14-
## Runtime assumptions and permissions (macOS)
15-
- Requires Accessibility (keyboard/mouse control) and Screen Recording permissions for Terminal/VS Code (pynput + mss).
16-
- Coordinates are absolute screen pixels for a specific UI layout. Retina scaling handled manually:
17-
- `arrasbot.py`: `MONITOR_INDEX` (default 1) and `SCALE` (2 on Retina, 1 on non-Retina). Convert global to local with these.
18-
- If your resolution/layout differs, update `GAME_REGION` and bounds used by `arrastools.py` and `arrasai.py` (e.g., mouse x in [2,1693], y in [128,1094]).
16+
## Cross-platform support and runtime assumptions
1917

20-
## Dependencies used across scripts
21-
- Core: `pynput`, `mss`, `numpy`.
22-
- Bot: `ping3`, `Pillow`, `mss.tools`.
23-
- AI: `torch`, `shapely`, `pytesseract` (requires system Tesseract), `Pillow`.
24-
- Example install (Python 3.10+): pynput, mss, numpy, ping3, pillow, torch, shapely, pytesseract.
18+
### Platform detection
19+
All main scripts now include platform detection using `platform.system().lower()`:
20+
- Returns: `'darwin'` (macOS), `'linux'`, `'windows'`
21+
- Scripts print platform on startup and warn if unsupported
22+
23+
### Platform-specific behaviors
24+
- **macOS (primary development platform)**:
25+
- Requires Accessibility + Screen Recording permissions (System Settings > Privacy & Security)
26+
- Retina displays: Set `SCALE=2` in `arrasbot.py`
27+
- Modifier keys: `Option+Arrow` for 1px mouse nudges
28+
- Coordinate system: May differ from Linux/Windows due to Retina scaling
29+
30+
- **Linux (Arch, Debian, Ubuntu)**:
31+
- Install dependencies via package manager: `sudo apt install python3-tk tesseract-ocr` (Debian/Ubuntu) or `sudo pacman -S tk tesseract` (Arch)
32+
- Accessibility permissions may vary by DE/WM (check pynput documentation)
33+
- Standard displays: Set `SCALE=1` in `arrasbot.py`
34+
- Modifier keys: `Alt+Arrow` for 1px mouse nudges
35+
- Wayland vs X11: pynput works best on X11; Wayland may have limitations
36+
37+
- **Windows**:
38+
- Install Tesseract OCR separately: Download from https://github.com/UB-Mannheim/tesseract/wiki
39+
- May require running as Administrator for input automation
40+
- Standard displays: Set `SCALE=1` in `arrasbot.py`
41+
- Modifier keys: `Alt+Arrow` for 1px mouse nudges
42+
- Path separators: Now handled automatically via pathlib
43+
44+
- **Android**:
45+
- Limited/experimental support
46+
- pynput may not work on all devices
47+
- Consider using Termux with X11 server for best compatibility
48+
49+
### Display scaling and coordinates
50+
- Coordinates are absolute screen pixels for a specific UI layout
51+
- **Critical**: Adjust based on YOUR display resolution:
52+
- `arrasbot.py`: `MONITOR_INDEX` (default 1) and `SCALE` (2 on Retina, 1 on standard displays)
53+
- `arrasai.py`: Update `GAME_REGION` polygon coordinates to match your game window
54+
- `arrastools.py`: Update mouse bounds in `on_press()` and click positions in `conq_quickstart()`
55+
- Use `arrasbot.py` CLI command `probe` to sample pixel colors and positions on your setup
56+
- Retina/HiDPI displays require coordinate conversion: multiply or divide by `SCALE` as needed
57+
58+
## Dependencies and installation
59+
60+
### Python requirements
61+
- **Python version**: 3.10+ recommended
62+
- **Core libraries**: `pynput`, `mss`, `numpy`, `pathlib` (built-in)
63+
- **Bot utilities**: `ping3`, `Pillow`, `mss.tools`
64+
- **AI/ML**: `torch`, `shapely`, `pytesseract`, `Pillow`
65+
66+
### System dependencies (platform-specific)
67+
- **macOS**: Tesseract via Homebrew: `brew install tesseract`
68+
- **Linux**: `sudo apt install python3-tk tesseract-ocr` (Debian/Ubuntu) or equivalent
69+
- **Windows**: Download Tesseract installer from GitHub, add to PATH
70+
- **All platforms**: Ensure Python tkinter is installed (usually bundled)
71+
72+
### Quick setup
73+
```bash
74+
# Create virtual environment (recommended)
75+
python3 -m venv .venv
76+
source .venv/bin/activate # Linux/macOS
77+
# OR
78+
.venv\Scripts\activate # Windows
79+
80+
# Install dependencies
81+
pip install pynput mss numpy ping3 pillow torch shapely pytesseract
82+
83+
# Platform-specific system packages
84+
# macOS: brew install tesseract
85+
# Linux: sudo apt install tesseract-ocr python3-tk
86+
# Windows: Install Tesseract from GitHub releases
87+
```
2588

2689
## How to run and control
27-
- `arrastools.py` hotkeys (hold Ctrl):
90+
- `arrastools.py` / `arrastools2.py` hotkeys (hold Ctrl):
2891
- `Ctrl+1` one/two/three presses within 2s: `$arena size` automation type 1/2/3 (`start_arena_automation`).
29-
- `Ctrl+y` begin “Controlled Nuke”: click 2 points in 10s to spray `k` within rectangle (uses global mouse listener).
92+
- `Ctrl+y` begin "Controlled Nuke": click 2 points in 10s to spray `k` within rectangle (uses global mouse listener).
93+
- `Alt+Arrow` (Option+Arrow on macOS): Move mouse 1 pixel in arrow direction (for precise positioning).
3094
- Safety: `Esc` stops activities; `Ctrl+Esc` immediate exit.
3195
- Other examples: `Ctrl+6` double-press within 5s triggers `ballcrash()`; `Ctrl+9` runs `nuke()`; `Ctrl+m` benchmarks ball spam.
3296
- `arrasbot.py` CLI commands (typed in terminal while running): `stop`, `setscale <1|2>`, `setmon <index>`, `dbgmon`, `screenshot`, `status`, `ping`, `probe`, `forcedisconnect`, `forcedeath`, `forcereconnect`.
33-
- Logs: `logs/abss_*.log`; screenshots: `~/Desktop/abss/<session>/`. Uses `color_close()` for tolerant RGB checks.
97+
- Logs: `logs/abss_*.log`; screenshots: `~/Desktop/abss/<session>/` (Linux/macOS) or `C:\Users\<user>\Desktop\abss\<session>\` (Windows).
98+
- Uses `color_close()` for tolerant RGB checks (accounts for antialiasing).
3499
- `arrasai.py` training:
35100
- Hotkeys while running: `Esc` force-stop (hard exit), `p` pause/resume, `r` simulate death.
36101
- Samples RGB at `OBSERVATION_POINTS = sample_points_in_polygon(GAME_REGION, step=10)` using `mss`; outputs: action (W/A/S/D/Space), mouse target, Sum42 head, and upgrade path.
37102
- Models saved in `arras_models/` with suffixes `_best`, `_final`, `_interrupted` based on training flow.
103+
- `arrascopypasta.py`: Reads `.txt` files from `copypastas/` directory (uses pathlib for cross-platform compatibility).
38104

39105
## Conventions and patterns to follow
40-
- Threading: Use `threading.Thread(..., daemon=True)` for background actions; toggle with global flags (e.g., `slowballs`, `randomwalld`). Provide `start_*` helpers to avoid duplicate threads.
41-
- Input synthesis: Use a single `KeyboardController`/`MouseController` per module; batch keystrokes within backtick-quoted console in-game by `controller.press("`")``controller.release("`")`.
42-
- Color detection: Prefer `color_close(tupleRGB, tupleRGB, tol=6)` rather than strict equality to account for antialiasing/transparency.
43-
- File outputs: Prefer timestamped paths from `timestamp()`; keep bot logs under `logs/` and images under `~/Desktop/abss/<session>/`.
106+
- **Threading**: Use `threading.Thread(..., daemon=True)` for background actions; toggle with global flags (e.g., `slowballs`, `randomwalld`). Provide `start_*` helpers to avoid duplicate threads.
107+
- **Input synthesis**: Use a single `KeyboardController`/`MouseController` per module; batch keystrokes within backtick-quoted console in-game by `controller.press("`")``controller.release("`")`.
108+
- **Color detection**: Prefer `color_close(tupleRGB, tupleRGB, tol=6)` rather than strict equality to account for antialiasing/transparency.
109+
- **File paths**: Use `pathlib.Path` for cross-platform compatibility (see `arrascopypasta.py` for example). Avoid hardcoded `/` or `\`.
110+
- **File outputs**: Prefer timestamped paths from `timestamp()`; keep bot logs under `logs/` and images under `~/Desktop/abss/<session>/`.
111+
- **Modifier key detection**: Use helper functions `is_ctrl()`, `is_alt()`, `is_modifier_for_arrow_nudge()` to handle cross-platform modifier key variants (Key.ctrl vs Key.ctrl_l vs Key.ctrl_r).
44112

45113
## When extending
46114
- For new macros, mirror `arrastools.py` style: add a function, a `start_*` wrapper if it loops, and wire a Ctrl+<key> branch in `on_press()` with debouncing if needed.
47115
- For new detectors, add small, monitor-relative probes (`probe` in `arrasbot.py`) and gate user-visible actions with tolerant checks + cooldowns.
48116
- If changing layout/resolution, update `GAME_REGION`, bounds and any hard-coded click points in `arrastools.py` (e.g., `conq_quickstart()` positions).
117+
- **Platform testing**: Test on target platforms before committing. Use virtual machines or containers for cross-platform validation.
118+
- Add platform detection at script start: `PLATFORM = platform.system().lower()` with appropriate warnings.
119+
120+
## Troubleshooting
121+
122+
### Permission issues
123+
- **macOS**: Grant Accessibility + Screen Recording in System Settings > Privacy & Security
124+
- **Linux**: Check X11 vs Wayland; pynput may need additional configuration for Wayland
125+
- **Windows**: Run Terminal/IDE as Administrator if input automation fails
126+
127+
### Coordinate/scaling issues
128+
- Use `arrasbot.py` command `dbgmon` to list all monitors and their properties
129+
- Use `probe` command to check pixel colors at cursor position
130+
- Adjust `SCALE` variable to match your display (2 for Retina/HiDPI, 1 for standard)
131+
- Re-map `GAME_REGION` coordinates for your screen resolution
132+
133+
### Dependency issues
134+
- Ensure Tesseract OCR is installed system-wide and in PATH
135+
- Virtual environment recommended to isolate Python packages
136+
- Check pynput documentation for platform-specific requirements
49137

50-
References: `arrastools.py`, `arrasbot.py`, `arrasai.py`, `arras_models/`, `logs/`, `copypastas/`. Keep changes minimal and aligned with existing patterns.
138+
References: `arrastools.py`, `arrastools2.py`, `arrasbot.py`, `arrasai.py`, `arrascopypasta.py`, `arras_models/`, `logs/`, `copypastas/`. Keep changes minimal and aligned with existing patterns.

README.md

Lines changed: 214 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,214 @@
1-
# arrastools
1+
# arrastools
2+
3+
Desktop automation tools and a PPO-based AI for Arras.io gameplay. Cross-platform support for macOS, Linux, and Windows.
4+
5+
## Features
6+
7+
- **Hotkey-driven automation** (`arrastools.py`, `arrastools2.py`): Control gameplay with keyboard shortcuts
8+
- **Game state monitoring** (`arrasbot.py`): Automatic detection of disconnection, death, and bans with logging
9+
- **PPO Reinforcement Learning AI** (`arrasai.py`): Train an AI agent to play Arras.io
10+
- **Copypasta automation** (`arrascopypasta.py`): Send text automatically with timing control
11+
- **Cross-platform**: Works on macOS, Linux (Arch/Debian/Ubuntu), and Windows
12+
13+
## Platform Support
14+
15+
### macOS
16+
**Primary development platform** - Fully tested
17+
18+
**Requirements:**
19+
- macOS 10.14 or later
20+
- Accessibility + Screen Recording permissions (System Settings > Privacy & Security)
21+
- Homebrew (recommended): `brew install tesseract`
22+
23+
### Linux
24+
**Tested on Arch, Debian, Ubuntu**
25+
26+
**Requirements:**
27+
```bash
28+
# Debian/Ubuntu
29+
sudo apt install python3-tk tesseract-ocr
30+
31+
# Arch
32+
sudo pacman -S tk tesseract
33+
```
34+
35+
**Notes:**
36+
- Works best on X11; Wayland may have limitations with pynput
37+
- Accessibility permissions may vary by desktop environment
38+
- Use `SCALE=1` for standard displays
39+
40+
### Windows
41+
**Tested on Windows 10/11**
42+
43+
**Requirements:**
44+
- [Tesseract OCR](https://github.com/UB-Mannheim/tesseract/wiki) (install separately, add to PATH)
45+
- May require running Terminal as Administrator for input automation
46+
- Use `SCALE=1` for standard displays
47+
48+
### Android
49+
⚠️ **Experimental** - Limited support
50+
- pynput may not work on all devices
51+
- Consider using Termux with X11 server
52+
53+
## Installation
54+
55+
### 1. Clone the repository
56+
```bash
57+
git clone https://github.com/maple-underscore/arrastools.git
58+
cd arrastools
59+
```
60+
61+
### 2. Create a virtual environment (recommended)
62+
```bash
63+
# Linux/macOS
64+
python3 -m venv .venv
65+
source .venv/bin/activate
66+
67+
# Windows
68+
python -m venv .venv
69+
.venv\Scripts\activate
70+
```
71+
72+
### 3. Install Python dependencies
73+
```bash
74+
pip install pynput mss numpy ping3 pillow torch shapely pytesseract
75+
```
76+
77+
### 4. Install system dependencies
78+
79+
**macOS:**
80+
```bash
81+
brew install tesseract
82+
```
83+
84+
**Linux (Debian/Ubuntu):**
85+
```bash
86+
sudo apt install python3-tk tesseract-ocr
87+
```
88+
89+
**Windows:**
90+
- Download and install [Tesseract OCR](https://github.com/UB-Mannheim/tesseract/wiki)
91+
- Add Tesseract to your system PATH
92+
93+
## Quick Start
94+
95+
### Automation Tools
96+
```bash
97+
python arrastools.py
98+
```
99+
100+
**Key shortcuts (hold Ctrl):**
101+
- `Ctrl+1` (press 1-3 times): Arena size automation
102+
- `Ctrl+y`: Controlled nuke (click two points)
103+
- `Alt+Arrow` (`Option+Arrow` on macOS): 1-pixel mouse movement
104+
- `Ctrl+9`: Nuke
105+
- `Ctrl+m`: Benchmark balls
106+
- `Esc`: Stop current activity
107+
- `Ctrl+Esc`: Emergency exit
108+
109+
### Bot Monitor
110+
```bash
111+
python arrasbot.py
112+
```
113+
114+
**CLI commands:**
115+
- `status`: Check bot state
116+
- `screenshot`: Take manual screenshot
117+
- `probe`: Sample pixel color at mouse position
118+
- `dbgmon`: List all monitors
119+
- `setscale <1|2>`: Set display scaling
120+
- `ping`: Check connection to arras.io
121+
122+
### AI Training
123+
```bash
124+
python arrasai.py
125+
```
126+
127+
**Hotkeys while training:**
128+
- `Esc`: Force stop
129+
- `p`: Pause/resume
130+
- `r`: Simulate death
131+
132+
## Configuration
133+
134+
### Display Scaling
135+
Adjust `SCALE` in `arrasbot.py` based on your display:
136+
- **Retina/HiDPI displays (macOS)**: `SCALE = 2`
137+
- **Standard displays (Windows/Linux)**: `SCALE = 1`
138+
139+
### Game Region
140+
Update `GAME_REGION` coordinates in `arrasai.py` to match your screen resolution:
141+
```python
142+
GAME_REGION = Polygon([
143+
(x1, y1), (x2, y2), ... # Your screen coordinates
144+
])
145+
```
146+
147+
Use `arrasbot.py` with the `probe` command to find your coordinates.
148+
149+
### Click Positions
150+
Hard-coded positions in `arrastools.py` (e.g., `conq_quickstart()`) may need adjustment for different resolutions.
151+
152+
## Project Structure
153+
154+
```
155+
arrastools/
156+
├── arrastools.py # Main automation script
157+
├── arrastools2.py # Alternative automation script
158+
├── arrasbot.py # Game state monitor
159+
├── arrasai.py # PPO AI trainer
160+
├── arrascopypasta.py # Text automation
161+
├── copypastas/ # Text files for copypasta
162+
├── arras_models/ # Saved AI models
163+
├── logs/ # Bot logs
164+
└── .github/
165+
└── copilot-instructions.md # AI coding agent guidance
166+
```
167+
168+
## Troubleshooting
169+
170+
### Permission Issues
171+
172+
**macOS:**
173+
- Go to System Settings > Privacy & Security
174+
- Enable Accessibility for your Terminal/IDE
175+
- Enable Screen Recording for your Terminal/IDE
176+
177+
**Linux:**
178+
- Check if running on X11 (pynput works better than Wayland)
179+
- Accessibility permissions vary by desktop environment
180+
181+
**Windows:**
182+
- Run Terminal as Administrator if automation fails
183+
- Ensure Tesseract is in your system PATH
184+
185+
### Coordinate/Scaling Issues
186+
1. Use `arrasbot.py` command `dbgmon` to list monitor properties
187+
2. Use `probe` command to check pixel colors at cursor position
188+
3. Adjust `SCALE` variable (2 for HiDPI, 1 for standard)
189+
4. Re-map coordinates for your resolution
190+
191+
### Dependency Issues
192+
- Ensure Tesseract OCR is installed system-wide
193+
- Use virtual environment to isolate Python packages
194+
- Check pynput documentation for platform-specific issues
195+
196+
## Development
197+
198+
See [.github/copilot-instructions.md](.github/copilot-instructions.md) for detailed development guidelines, conventions, and architecture notes.
199+
200+
## License
201+
202+
MIT License - See LICENSE file for details
203+
204+
## Contributing
205+
206+
Contributions welcome! Please:
207+
1. Test on your target platform (macOS/Linux/Windows)
208+
2. Use `pathlib` for file paths (cross-platform)
209+
3. Follow existing patterns (see copilot-instructions.md)
210+
4. Add platform detection for new scripts
211+
212+
## Disclaimer
213+
214+
This tool is for educational purposes. Use responsibly and in accordance with game terms of service.

0 commit comments

Comments
 (0)