An open API service indexing awesome lists of open source software.

https://github.com/hypoxic127/fh6-afk

๐ŸŽ๏ธ Fully automated super wheel farming bot for Forza Horizon 6, powered by Computer Vision & Virtual Gamepad
https://github.com/hypoxic127/fh6-afk

afk-farming automation bot computer-vision forza-horizon-6 opencv python

Last synced: 23 days ago
JSON representation

๐ŸŽ๏ธ Fully automated super wheel farming bot for Forza Horizon 6, powered by Computer Vision & Virtual Gamepad

Awesome Lists containing this project

README

          

# ๐ŸŽ๏ธ FH6 AutoBot โ€” A Never-Ending AFK Farming Machine

**๐ŸŒ Language: English | [ไธญๆ–‡](README_zh-CN.md)**

[![CI](https://github.com/hypoxic127/FH6-AFK/actions/workflows/ci.yml/badge.svg)](https://github.com/hypoxic127/FH6-AFK/actions/workflows/ci.yml)
[![Release](https://github.com/hypoxic127/FH6-AFK/actions/workflows/release.yml/badge.svg)](https://github.com/hypoxic127/FH6-AFK/actions/workflows/release.yml)
![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-3776ab?logo=python&logoColor=white)
![Platform](https://img.shields.io/badge/platform-Windows-0078d4?logo=windows&logoColor=white)
![License](https://img.shields.io/badge/license-Personal%20Use-f5c542)

> A fully automated, infinite-loop Skill Points farming system for **Forza Horizon 6**.
> Powered by **Computer Vision (OpenCV + Tesseract OCR)** and **Virtual Gamepad (ViGEmBus)**, achieving **zero human intervention** closed-loop farming.
> Comes with a **Cyberpunk-styled Web UI** dashboard for remote monitoring and one-click control.

---

## ๐Ÿ“‹ Table of Contents

- [โœจ Features](#-features)
- [๐Ÿ”„ Workflow](#-workflow)
- [๐Ÿ› ๏ธ Tech Stack](#๏ธ-tech-stack)
- [๐Ÿš€ Getting Started](#-getting-started)
- [๐Ÿ“– Usage](#-usage)
- [๐Ÿ“ Project Structure](#-project-structure)
- [๐Ÿงช Testing & CI](#-testing--ci)
- [๐Ÿ” Technical Details](#-technical-details)
- [๐Ÿค Contributing](#-contributing)
- [๐Ÿ“ License](#-license)

---

## โœจ Features

| Feature | Description |
|:--------|:------------|
| ๐Ÿ” **4-Stage Auto Loop** | Farm โ†’ Buy โ†’ Upgrade โ†’ Sell, infinite loop, sleep & farm |
| ๐Ÿ‘๏ธ **Computer Vision State Machine** | Color histogram + OCR hybrid detection, identifies 10+ game UI states |
| ๐ŸŽฎ **Virtual Gamepad** | ViGEmBus simulates Xbox 360 controller, native-level input |
| ๐Ÿ–ฅ๏ธ **Web UI Dashboard** | Glassmorphism UI + real-time logs + QR code mobile monitoring |
| โน๏ธ **Instant Stop** | Thread injection technology, bot stops immediately on button click |
| ๐ŸŽฐ **Super Wheelspin Counter** | Automatically tracks upgrade macro executions |
| ๐Ÿ“ฆ **One-Click Build** | PyInstaller single-file `.exe`, no Python required |
| ๐Ÿงช **95 Test Cases** | Ruff linting + Pytest coverage, GitHub Actions CI |

---

## ๐Ÿ”„ Workflow

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ๐ŸŽ๏ธ Farm โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚ ๐Ÿ›’ Buy โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚ โšก Upgrade โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚ ๐Ÿ—‘๏ธ Sell โ”‚
โ”‚ Skill Pointsโ”‚ โ”‚ Cars โ”‚ โ”‚ Cars โ”‚ โ”‚ Cars โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚ โ”‚
โ”‚ โ™ป๏ธ Infinite Loop โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

| Stage | State Constant | Description |
|:-----:|:---------------|:------------|
| 1๏ธโƒฃ | `STATE_FARM_POINTS` | OCR scans skill points โ†’ auto-enters EventLab to farm up to 999 |
| 2๏ธโƒฃ | `STATE_BUY_CARS` | Five-step visual navigation โ†’ batch-purchase 33 Subaru Impreza 22B-STIs |
| 3๏ธโƒฃ | `STATE_UPGRADE_CARS` | Select each car with NEW tag โ†’ spend skill points on skill tree |
| 4๏ธโƒฃ | `STATE_TRASH_CARS` | Batch-remove upgraded Imprezas (keeping S2 main car) |

---

## ๐Ÿ› ๏ธ Tech Stack

| Category | Technology | Purpose |
|:---------|:-----------|:--------|
| **Vision Engine** | OpenCV, Tesseract OCR | Image processing, text recognition, color detection |
| **Numerics** | NumPy | Histogram comparison, image matrix operations |
| **Screen Capture** | MSS | High-performance cross-platform screenshots |
| **Gamepad** | VGamepad + ViGEmBus | Virtual Xbox 360 controller input |
| **Web Server** | Flask + Flask-SocketIO | Real-time Web UI control panel |
| **Frontend** | Vanilla JS + CSS3 | Glassmorphism dashboard, WebSocket live logs |
| **Testing** | Pytest + Ruff | Unit testing + code quality checks |
| **Packaging** | PyInstaller | One-click single-file executable build |
| **CI/CD** | GitHub Actions | Automated testing + Release publishing |

---

## ๐Ÿš€ Getting Started

### ๐Ÿ“‹ Prerequisites

> โš ๏ธ The following software must be installed before running

| Software | Version | Download | Notes |
|:---------|:--------|:---------|:------|
| **Python** | 3.10+ | [python.org](https://www.python.org/downloads/) | Check "Add to PATH" during install |
| **Tesseract OCR** | 5.x | [Download](https://github.com/UB-Mannheim/tesseract/releases) | Check "Add to PATH" during install |
| **ViGEmBus** | Latest | [Download](https://github.com/ViGEm/ViGEmBus/releases) | **Reboot required** after install |

### ๐Ÿ“ฅ Installation

```bash
# 1. Clone the repository
git clone https://github.com/hypoxic127/FH6-AFK.git
cd FH6-AFK

# 2. One-click install (auto-creates venv + installs dependencies)
python setup.py

# 3. Launch (Web UI mode)
python main_bot.py --web
```

### ๐ŸŽฎ In-Game Preparation

Before starting the bot, ensure the following:

1. **Game language must be set to English** โ€” OCR depends on English text
2. **Windowed mode** โ€” Windowed or Borderless Windowed (recommended: 2560ร—1440)
3. **Purchase main car** โ€” `1998 Subaru Impreza 22B-STI Version`
4. **Install S2 tune** โ€” Any S2-class tune (PI badge = blue)
5. **Favorite the EventLab blueprint** โ€” Share code `890169683`
6. **Enable Auto-Steering** โ€” Go to `Settings โ†’ Difficulty โ†’ Auto-Steering: ON`. The bot relies on auto-steering for autonomous driving in EventLab

> **โš ๏ธ Important:** The S2 **blue PI badge** on the main car is the sole indicator the program uses to distinguish "keep" vs "deletable" cars. Make sure your main car has an S2 tune applied.

---

## ๐Ÿ“– Usage

### ๐ŸŒ Web UI Mode (Recommended)

```bash
python main_bot.py --web # Default port 6800
python main_bot.py --web --port 8080 # Custom port
```

Open `http://localhost:6800` in your browser to access the control panel:

- ๐ŸŽฏ **Live Status** โ€” Current stage, loop count, runtime, super wheelspin count
- ๐Ÿ”„ **Progress Bar** โ€” Visual 4-stage progress indicator
- โš™๏ธ **Stage Selector** โ€” Start from any stage via dropdown
- ๐Ÿ“œ **Live Log Terminal** โ€” Syntax-highlighted real-time log stream
- ๐Ÿ“ฑ **QR Remote Monitoring** โ€” Scan QR code to monitor from your phone

### ๐Ÿ’ป Terminal Mode

```bash
python main_bot.py
```

| Option | Function | When to Use |
|:------:|:---------|:------------|
| `[0]` | ๐Ÿ”„ Auto loop (full cycle) | Main menu โ€” full 4-stage infinite loop |
| `[1]` | ๐ŸŽ๏ธ Farm Skill Points | Main menu โ€” enter EventLab |
| `[2]` | ๐Ÿ›’ Buy Cars | Main menu โ€” batch purchase Imprezas |
| `[3]` | โšก Upgrade Cars | Main menu โ€” spend skill points |
| `[4]` | ๐Ÿ—‘๏ธ Sell Cars | In garage, Subaru brand selected |
| `[5]` | โญ๏ธ Skip Buy loop | When garage already has un-upgraded cars |

### ๐Ÿ“ฆ Build Executable

```bash
python packaging/build.py
```

Produces `dist/FH6AutoBot.exe` โ€” portable, no Python needed (Tesseract & ViGEmBus still required).

> **๐Ÿ’ก Tip:** Push a git tag (e.g. `git tag v1.2.0 && git push --tags`) to auto-trigger GitHub Actions build and publish to the Releases page.

---

## ๐Ÿ“ Project Structure

```
FH6_AutoBot/
โ”‚
โ”œโ”€โ”€ main_bot.py # ๐Ÿš€ Entry point (Terminal / Web UI)
โ”‚
โ”œโ”€โ”€ engine/ # ๐Ÿง  Perception Engine
โ”‚ โ”œโ”€โ”€ ocr.py # Computer vision (OCR + color detection)
โ”‚ โ”œโ”€โ”€ state_detect.py # Game state detector (histogram + OCR hybrid)
โ”‚ โ”œโ”€โ”€ event_bus.py # Event bus (log/state push to Web UI)
โ”‚ โ”œโ”€โ”€ runtime.py # PyInstaller runtime path resolution
โ”‚ โ””โ”€โ”€ utils.py # Logging / window ops / gamepad / MSS capture
โ”‚
โ”œโ”€โ”€ macro/ # ๐ŸŽฎ Macro Operations
โ”‚ โ”œโ”€โ”€ master_loop.py # Master state machine (4-stage loop engine)
โ”‚ โ”œโ”€โ”€ core.py # Infrastructure: screenshots, logging, constants
โ”‚ โ”œโ”€โ”€ navigation.py # Menu navigation / visual braking / return-to-garage
โ”‚ โ”œโ”€โ”€ purchase.py # 5-step Impreza purchase navigation
โ”‚ โ”œโ”€โ”€ garage.py # Garage grid: select / delete / main car nav
โ”‚ โ””โ”€โ”€ upgrade.py # Upgrade macro (Cannot Afford detection)
โ”‚
โ”œโ”€โ”€ farm/ # ๐Ÿ EventLab Farming
โ”‚ โ””โ”€โ”€ skills.py # Visual state machine (auto-drive + finish detection)
โ”‚
โ”œโ”€โ”€ web/ # ๐ŸŒ Web UI Control Panel
โ”‚ โ”œโ”€โ”€ server.py # Flask + SocketIO server
โ”‚ โ”œโ”€โ”€ state_manager.py # Global state manager
โ”‚ โ””โ”€โ”€ static/ # Frontend assets
โ”‚ โ”œโ”€โ”€ index.html # Dashboard page
โ”‚ โ”œโ”€โ”€ style.css # Cyberpunk theme styles
โ”‚ โ””โ”€โ”€ app.js # WebSocket client logic
โ”‚
โ”œโ”€โ”€ packaging/ # ๐Ÿ“ฆ Build & Packaging
โ”‚ โ”œโ”€โ”€ build.py # One-click PyInstaller build script
โ”‚ โ”œโ”€โ”€ FH6AutoBot.spec # PyInstaller spec (--onefile)
โ”‚ โ””โ”€โ”€ hook_utf8.py # Runtime hook (Windows UTF-8 fix)
โ”‚
โ”œโ”€โ”€ tests/ # ๐Ÿงช Unit Tests (95 cases)
โ”œโ”€โ”€ tools/ # ๐Ÿ”ง Dev utilities (not packaged)
โ”‚
โ”œโ”€โ”€ .github/workflows/
โ”‚ โ”œโ”€โ”€ ci.yml # CI (Ruff check + Pytest)
โ”‚ โ””โ”€โ”€ release.yml # Release (PyInstaller โ†’ GitHub Release)
โ”‚
โ”œโ”€โ”€ setup.py # โš™๏ธ One-click environment setup
โ”œโ”€โ”€ requirements.txt # ๐Ÿ“‹ Python dependencies
โ”œโ”€โ”€ ruff.toml # ๐Ÿ” Ruff linter config
โ””โ”€โ”€ pytest.ini # ๐Ÿงช Pytest config
```

---

## ๐Ÿงช Testing & CI

```bash
# Run all tests
python -m pytest

# Lint check
python -m ruff check .

# Format check
python -m ruff format --check .
```

| CI Job | Trigger | Description |
|:-------|:--------|:------------|
| **Lint** | Push / PR | Ruff lint + format validation |
| **Test** | Push / PR | 95 test cases (ubuntu-latest) |
| **Release** | `v*` tag | PyInstaller build โ†’ GitHub Release |

---

## ๐Ÿ” Technical Details

### ๐Ÿ‘๏ธ Visual State Detection

- **Histogram + OCR Hybrid** โ€” `StateDetector` uses color distribution features for fast candidate screening, then OCR for precise verification
- **PI Badge Color Detection** โ€” HSV color space analysis: blue = S2 main car (keep), orange = deletable

### ๐Ÿ”ค OCR Strategy

- **Dual PSM Mode** โ€” Uses PSM 8 (single word) + PSM 7 (single line), picks the result with most digits
- **OTSU Adaptive Thresholding** โ€” Prevents single-digit zero-padding errors
- **Zero Skill Points Fallback** โ€” Detects "No Skill Points Available" text

### ๐ŸŽฏ Garage Grid Navigation

- **Typewriter Traversal** โ€” Column by column, top to bottom (3ร—N grid)
- **Triple Verification** โ€” OCR keywords (2/3 match) + NEW yellow tag + LEGENDARY orange rarity
- **Cannot Afford Detection** โ€” Auto-dismisses popup, stops purchasing

### ๐Ÿ“ฆ Build & Packaging

- **PyInstaller --onefile** โ€” Single ~44MB executable
- **Runtime Path Layer** โ€” `engine/runtime.py` unified path resolution (dev/packaged dual-mode)
- **UTF-8 Console Fix** โ€” `hook_utf8.py` resolves Chinese log garbling on Windows

---

## ๐Ÿค Contributing

Contributions are welcome! Please follow this workflow:

1. **Fork** this repository
2. Create a feature branch (`git checkout -b feat/amazing-feature`)
3. Commit your changes (`git commit -m 'feat: add amazing feature'`)
4. Push to the branch (`git push origin feat/amazing-feature`)
5. Open a **Pull Request**

### Development Standards

- ๐Ÿ Code style: PEP 8 (enforced by Ruff)
- ๐Ÿท๏ธ Commit format: [Conventional Commits](https://www.conventionalcommits.org/) (`feat` / `fix` / `docs` / `refactor` / `chore`)
- โœ… All PRs must pass CI checks (Lint + Test)

---

## ๐Ÿ“ License

This project is for **learning and personal use** only.

---

**If this project helps you, please give it a โญ Star!**

Made with โค๏ธ by [hypoxic127](https://github.com/hypoxic127)