Skip to content

hypoxic127/FH6-AFK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

133 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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

๐ŸŒ Language: English | ไธญๆ–‡

CI Release Python 3.10+ Platform License

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

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
๐Ÿ”„ Auto-Update GitHub Releases auto-update with multi-mirror download, one-click update via Web UI or --update flag
๐Ÿ›ก๏ธ Self-Healing Capture BitBlt failure auto-recovery with MSS reset + window re-foreground
๐ŸŽฐ Super Wheelspin Counter Automatically tracks upgrade macro executions
๐Ÿ“ฆ One-Click Build PyInstaller single-file .exe, no Python required
๐Ÿงช 93 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 Check "Add to PATH" during install
Tesseract OCR 5.x Download Check "Add to PATH" during install
ViGEmBus Latest Download Reboot required after install

๐Ÿ“ฅ Installation

# 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)

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
  • ๐Ÿ†• Auto-Update โ€” Version badge + check for updates button + one-click update with progress bar

๐Ÿ”„ Auto-Update

The bot automatically checks for new releases on startup and notifies you:

# Manual update via CLI
FH6AutoBot.exe --update

# Skip update check (e.g. for autostart scenarios)
FH6AutoBot.exe --skip-update --web

In Web UI: click the ๐Ÿ”„ button in the header, or use the โฌ‡๏ธ Update Now button when a new version banner appears.

๐Ÿ’ป Terminal Mode

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

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
โ”‚   โ”œโ”€โ”€ version.py              #    Single source of truth for app version
โ”‚   โ”œโ”€โ”€ updater.py              #    GitHub Releases auto-update engine
โ”‚   โ”œโ”€โ”€ i18n.py                 #    Bilingual string table (en/zh)
โ”‚   โ””โ”€โ”€ 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 (93 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

# 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 93 test cases (ubuntu-latest)
Release v* tag PyInstaller build โ†’ GitHub Release (auto-sync version)

๐Ÿ” 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 ~50MB 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

๐Ÿ”„ Auto-Update System

  • Integer Tuple Version Comparison โ€” (1,5,10) > (1,5,9), no string comparison bugs
  • Transactional File Replacement โ€” Rollback on failure (never bricks the installation)
  • Multi-Mirror Download โ€” Direct GitHub โ†’ ghproxy fallback chain (3 mirrors)
  • Infinite Restart Prevention โ€” Filters --update from sys.argv before restarting
  • Rate Limit Protection โ€” 1-hour API cache, respects GitHub's 60 req/hr limit
  • Global Update Lock โ€” Prevents concurrent downloads from Web UI + CLI

๐Ÿ›ก๏ธ Self-Healing Screenshot

  • BitBlt Failure Recovery โ€” Auto-resets MSS instance when GDI device context is corrupted
  • Window Re-Foreground โ€” Pulls game window back to front after capture failure
  • Web UI Stop/Start Safe โ€” MSS reset on bot stop prevents stale handle leaks

๐Ÿค 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 (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

About

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

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors