# WebRadarCPP — CS2 External Web Radar

A **C++ external** web-based radar overlay for **Counter-Strike 2**. Reads game memory externally (no DLL injection) and streams real-time game state to a browser frontend via WebSocket.

## Features

### 🎯 Web Radar
- Real-time player positions on interactive 2D minimap
- Player names, health, armor, team colors
- Active weapon display with icons
- Player flags: Scoped, Flashed, Ducking, Defusing
- Follow-mode: lock camera to any player
- Rotate-minimap support
- Zoom slider (1.5×–8×)
- PiP (Picture-in-Picture) window support
- Killfeed display
- Scoreboard overlay
- Auto-reconnect on disconnect
- Works on any device with a browser (PC, tablet, phone)

### 💣 Bomb Tracker
- Carried bomb indicator
- Planted bomb timer with visual countdown
- Bomb site indicator (A / B)
- Defuse status and countdown

### 🧨 Grenade Tracking
- Smoke grenade — position, duration, effect area
- HE Grenade — trajectory and landing position
- Flashbang — trajectory prediction
- Decoy — trajectory tracking
- Molotov / Incendiary — fire spread positions and duration
- Inferno — fire area tracking

### 🔫 Dropped Weapon ESP
- Weapon icons on radar for dropped weapons
- Supports all weapons (rifles, pistols, SMGs, shotguns, snipers, equipment)
- Utility items tracking

### 🗺️ Map Support
- Automatic map detection
- All competitive maps supported

### 🔧 Technical Features
- External memory reading (no driver, no injection)
- Multi-threaded game state scanning
- Rate-limited entity updates for performance
- WebSocket-based data streaming (port 22006)
- React SPA frontend with TailwindCSS
- Node.js relay server for static file serving + WebSocket

## Architecture

```
┌──────────────┐    WebSocket (22006)    ┌──────────────────┐
│  C++ Engine  │ ──────────────────────▶ │  Node.js Relay   │
│  (game_data) │                        │  Server (ws/)     │
└──────────────┘                        └────────┬─────────┘
                                                 │
                                     HTTP/WebSocket (22006)
                                                 │
                                        ┌────────▼─────────┐
                                        │  React Web App    │
                                        │  (webapp/)        │
                                        └───────────────────┘
```

### Components

| Component | Tech | Description |
|-----------|------|-------------|
| **C++ Engine** | C++20, Win32 API | External memory reading, entity management, feature extraction |
| **WebSocket Relay** | Node.js + `ws` | Serves static frontend + relays game state to browser clients |
| **React Frontend** | React 18 + Vite + TailwindCSS | Interactive radar UI, bomb timer, grenade display |

## Build Requirements

### C++ Backend
- **Visual Studio 2022** with Desktop development with C++
- **vcpkg** (installed and integrated with MSBuild)
- Dependencies (auto-installed by vcpkg):
  - `nlohmann-json` — JSON serialization
  - `ixwebsocket` — WebSocket client library
  - `curl` — HTTP requests

### Web Frontend
- **Node.js** 18+ (for the relay server)
- **npm** (for frontend build)

## Build & Run

### 1. Build C++ Backend
```bat
build_cpp.bat
```

### 2. Build Web Frontend
```bat
build_webradar.bat
```

### 3. Run
```bat
webradar_cpp.exe
```

The radar will be available at:
- **UI**: http://localhost:22006
- **WebSocket**: ws://localhost:22006/ws

### Configuration

Edit `webradar.config.json`:
```json
{
  "Web_Asset_Root": "webapp/dist",
  "WebSocket_Port": 22006,
  "WebSocket_Path": "/ws"
}
```

### Optional: WebSocket Relay Server

A standalone Node.js Single-Executable Application (SEA) relay server is also included:
```bat
webradar_relay_server.exe
```

## Project Structure

```
WebRadarCPP/
├── src/                     # C++ source files
│   ├── main.cpp             # Entry point
│   ├── features.cpp         # Feature orchestration
│   ├── players.cpp          # Player data extraction
│   ├── bomb.cpp             # Bomb state tracking
│   ├── grenades.cpp         # Grenade tracking
│   ├── dropped_weapons.cpp  # Dropped weapon detection
│   ├── entity.cpp           # Entity management
│   ├── roundinfo.cpp        # Round info extraction
│   ├── memory.cpp           # Memory read/write primitives
│   ├── schema.cpp           # Schema system interface
│   ├── sdk.cpp              # SDK helper functions
│   ├── interfaces.cpp       # Engine interface resolution
│   └── address.cpp          # Address resolution
├── include/                 # C++ headers
│   ├── core/                # Core: memory, offsets, schema, types
│   ├── features/            # Feature declarations
│   ├── game/                # Game: entity, player, bomb, grenade data
│   ├── sdk/                 # SDK: vectors, entities, interfaces
│   ├── server/              # WebSocket server + config
│   └── utils/               # Utility functions
├── webapp/                  # React frontend
│   ├── src/                 # React source
│   │   ├── components/      # UI components (radar, bomb, player, etc.)
│   │   ├── hooks/           # React hooks (PiP, autozoom, POV lock)
│   │   └── utilities/       # Helper utilities
│   └── dist/                # Built frontend assets
├── ws/                      # Node.js WebSocket relay server
│   └── server.js            # Relay server (HTTP + WebSocket)
├── vcpkg.json               # vcpkg dependencies
├── webradar.config.json     # Runtime configuration
├── webradar_cpp.vcxproj     # MSBuild project file
└── build_cpp.bat            # Build script
```

## Data Flow

1. **C++ Engine** reads CS2 game memory externally every frame
2. Data is serialized to JSON and sent via WebSocket (ixwebsocket)
3. **Node.js Relay Server** receives the data and broadcasts to all connected browser clients
4. **React Frontend** renders the radar, bomb timer, grenades, and player information

## Supported Game State

- ✅ Player positions, health, armor, team, weapon
- ✅ Bomb (carried, planted, defusing)
- ✅ All grenade types (smoke, HE, flash, decoy, molotov, inferno)
- ✅ Dropped weapons with type detection
- ✅ Round timer and scores
- ✅ Map name auto-detection
- ✅ Player flags (scoped, flashed, shifting, ducking)

## Disclaimer

This software is for **educational purposes only**. Use at your own risk in accordance with CS2's Terms of Service.
