|
| 1 | +# Project Guidelines |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +Cheat Engine MCP Server — a C# plugin that exposes Cheat Engine functionality as MCP tools over SSE (Server-Sent Events) using the official [Model Context Protocol C# SDK](https://github.com/modelcontextprotocol/csharp-sdk). |
| 6 | + |
| 7 | +## Build and Test |
| 8 | + |
| 9 | +```bash |
| 10 | +# Initialize submodule (first time) |
| 11 | +git submodule update --init --recursive |
| 12 | + |
| 13 | +# Build |
| 14 | +dotnet build |
| 15 | + |
| 16 | +# Build Release |
| 17 | +dotnet build -c Release |
| 18 | +``` |
| 19 | + |
| 20 | +Deploy: copy `ce-mcp.dll` from `bin/` to Cheat Engine plugins directory, enable in CE, use "MCP" menu. |
| 21 | + |
| 22 | +## Architecture |
| 23 | + |
| 24 | +### Core Components |
| 25 | + |
| 26 | +- **Plugin.cs** — Main CE plugin entry point (`CESDKPluginClass`). Manages MCP server lifecycle, registers Lua functions for CE menu integration, provides WPF config UI. |
| 27 | +- **McpServer.cs** — MCP SSE server using `ModelContextProtocol.AspNetCore`. Registers all tools via `WithTools<T>()` and maps endpoints with `MapMcp()`. |
| 28 | +- **ServerConfig.cs** — Configuration management (host/port/name). Loads from `%APPDATA%\CeMCP\config.json` with env var overrides (`MCP_HOST`, `MCP_PORT`). |
| 29 | + |
| 30 | +### Tools (`src/Tools/`) |
| 31 | + |
| 32 | +All tools use `[McpServerToolType]` on the class and `[McpServerTool]` + `[Description]` on methods. Tools are static classes with static methods. Each returns anonymous objects with `success` boolean and either result data or `error` message. |
| 33 | + |
| 34 | +- **ProcessTool** — List processes, open by ID/name, get current process |
| 35 | +- **LuaExecutionTool** — Execute Lua scripts in CE with stack management |
| 36 | +- **MemoryReadTool** — Read memory (bytes, int32, int64, float, string) |
| 37 | +- **MemoryWriteTool** — Write memory values |
| 38 | +- **AOBScanTool** — Array of Bytes pattern scanning |
| 39 | +- **DisassembleTool** — Disassemble instructions at address |
| 40 | +- **AddressTool** — Resolve address expressions |
| 41 | +- **ConversionTool** — String format conversion (MD5, ANSI/UTF8) |
| 42 | +- **ThreadListTool** — List process threads |
| 43 | +- **MemScanTool** — Memory value scanning with first/next scan pattern |
| 44 | +- **AddressListTool** — Cheat table CRUD operations |
| 45 | + |
| 46 | +### SDK Layer (`CESDK/`) |
| 47 | + |
| 48 | +Git submodule — C# wrapper around Cheat Engine's Lua API. Key classes: `LuaEngine`, `MemoryAccess`, `Process`, `AOBScanner`, `Disassembler`, `MemScan`, `AddressList`. |
| 49 | + |
| 50 | +### Views (`src/Views/`) |
| 51 | + |
| 52 | +- **ConfigWindow.cs** — WPF config window (code-only, no XAML). Supports dark/light theme via `ThemeHelper`. |
| 53 | + |
| 54 | +## Adding New Tools |
| 55 | + |
| 56 | +1. Create a new file in `src/Tools/` with `[McpServerToolType]` class attribute |
| 57 | +2. Add static methods with `[McpServerTool(Name = "tool_name")]` and `[Description("...")]` |
| 58 | +3. Use `[Description]` on parameters for schema generation |
| 59 | +4. Return anonymous objects: `new { success = true, ... }` or `new { success = false, error = "..." }` |
| 60 | +5. Register in `McpServer.cs` via `.WithTools<Tools.YourTool>()` |
| 61 | + |
| 62 | +Example: |
| 63 | +```csharp |
| 64 | +[McpServerToolType] |
| 65 | +public static class MyTool |
| 66 | +{ |
| 67 | + [McpServerTool(Name = "my_action"), Description("Does something useful")] |
| 68 | + public static object MyAction([Description("Input param")] string input) |
| 69 | + { |
| 70 | + try { |
| 71 | + // ... CE SDK calls ... |
| 72 | + return new { success = true, result = "done" }; |
| 73 | + } catch (Exception ex) { |
| 74 | + return new { success = false, error = ex.Message }; |
| 75 | + } |
| 76 | + } |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +## Code Style |
| 81 | + |
| 82 | +- C# with nullable reference types enabled, `TreatWarningsAsErrors` |
| 83 | +- Target: `net9.0-windows`, WPF enabled, x64 platform |
| 84 | +- Tools use static classes/methods, not instance-based |
| 85 | +- Wrap CE SDK calls in try-catch, always return structured response objects |
| 86 | +- Use proper Lua stack management (`GetTop`, `Pop`) when interacting with Lua |
| 87 | + |
| 88 | +## Important Notes |
| 89 | + |
| 90 | +- **Lua stack**: Always clean up with `lua.Pop()` calls after reading values |
| 91 | +- **CE thread safety**: Use `CESDK.CESDK.Synchronize()` for operations that must run on CE's main thread (e.g., AddressList operations) |
| 92 | +- **Memory scanning**: Requires scan → `WaitTillDone()` → `foundList.Initialize()` sequence |
| 93 | +- **Dark mode**: UI adapts via Windows registry check (`ThemeHelper.IsInDarkMode()`) |
| 94 | +- Default server: `http://127.0.0.1:6300` with MCP SSE at `/sse` |
| 95 | + |
| 96 | +## CESDK Submodule |
| 97 | + |
| 98 | +The `CESDK/` directory is a git submodule providing the Cheat Engine SDK wrapper library: |
| 99 | + |
| 100 | +- **Core**: `CESDK.cs`, `CheatEnginePlugin.cs`, `PluginContext.cs` |
| 101 | +- **Lua**: `LuaEngine.cs` (high-level), `LuaNative.cs` (low-level C API) |
| 102 | +- **Memory**: `MemoryScanner.cs`, `ScanConfiguration.cs`, `ScanResults.cs` |
| 103 | +- **System**: `SystemInfo.cs`, `CEInterop.cs` |
| 104 | + |
| 105 | +Plugin pattern: inherit `CheatEnginePlugin`, implement `Name`/`OnEnable()`/`OnDisable()`, access Lua via `PluginContext.Lua`. |
0 commit comments