# 02 — Tech stack & build environment

## 1. Ngôn ngữ & chuẩn

- **C++23** — sử dụng các tính năng mới phù hợp dự án:
  - `std::expected<T, E>` — kết quả đọc bộ nhớ / gửi input không dùng exception.
  - `std::print` / `std::format` — logging cấu trúc.
  - Deducing this (`explicit object parameter`) — gọn code behavior tree node.
  - `if consteval`, `constexpr` mở rộng — build-time bảng offsets validation.
  - `std::mdspan` — khi xử lý ma trận ảnh từ VisionModule.
  - `std::span`, `std::ranges` — mặc định cho mọi API nội bộ.

## 2. Compiler & toolchain

| Thành phần | Chọn | Ghi chú |
|-----------|------|---------|
| Compiler chính | **MSVC 19.38+** (VS 2022) | Hỗ trợ C++23 tốt nhất trên Windows, debug với game native |
| Compiler phụ | Clang 17+ (clang-cl) | Kiểm tra tương thích, dùng cho clang-tidy |
| Build system | **CMake ≥ 3.28** | Preset cho MSVC; Ninja backend |
| Package manager | **vcpkg** (manifest mode, `vcpkg.json`) | Reproducible builds |
| IDE | Visual Studio 2022 + VS Code | |

## 3. Thư viện lập kế hoạch

| Thư viện | Mục đích | Thay thế nếu cần |
|----------|----------|------------------|
| [spdlog](https://github.com/gabime/spdlog) | Logging hiệu năng cao | boost.log |
| [asio (standalone)](https://think-async.com/) | UDP/TCP tới KMBox Net | WinSock thuần |
| [nlohmann/json](https://github.com/nlohmann/json) | offsets.json, profile config | RapidJSON |
| [Catch2 v3](https://github.com/catchorg/Catch2) | Unit test | GoogleTest |
| [fmt](https://github.com/fmtlib/fmt) | Định dạng chuỗi (fallback khi std::print chưa full) | — |
| Desktop Duplication API (WinAPI) | Capture màn hình cho VisionModule | BitBlt |
| WinAPI trực tiếp | OpenProcess / ReadProcessMemory / Toolhelp32 | — |

> Nguyên tắc: **không thêm dependency lớn** (Qt, Boost toàn bộ) — dự án cần binary nhẹ, dễ chạy nền.

## 4. Cấu trúc repo dự kiến

```
ARES/
├── docs/                  # Tài liệu (thư mục này)
├── src/
│   ├── core/              # types (GameState, ActionCommand), thread, queue, log
│   ├── memory/            # MemoryReader, pointer-chain resolver, signature scanner
│   ├── vision/            # capture, OCR/template matching (dự phòng)
│   ├── decision/          # behavior tree, state machine, profiles từng class
│   ├── input/             # KMBox transport (UDP/serial), Humanizer
│   └── app/               # main, CLI, watchdog
├── configs/
│   ├── offsets.json       # offsets/pointer chains per game-version
│   └── profiles/          # per-class rotation, per-activity behavior
├── tests/                 # unit test (Catch2) + fake memory backend
└── tools/                 # script phụ trợ: sig-scanner, offsets diff sau patch
```

## 5. Build presets (bản nháp)

```bash
cmake --preset msvc-release        # build tối ưu
cmake --preset msvc-debug          # build debug với ASan
ctest --preset default             # chạy unit test
```

## 6. Kiểm thử

- **Unit test** mọi module với *fake backend*:
  - `FakeMemory` — process giả lập chứa GameState để test MemoryReader không cần game thật.
  - `FakeTransport` — bắt gói tin UDP KMBox thay vì gửi thật.
- **Integration test** chạy cùng client thật nhưng ở chế độ `--dry-run` (chỉ log hành động, không bấm phím).
- **Soak test** — chạy 4h, giám sát memory leak của chính bot (không phải game).
