Skip to main content
Glama

SiliconOKW — Hearts of Iron IV (1.19.5.0) Windows 原生 MCP 自动化工具集

IMPORTANT

项目说明

  • 本仓库大部分代码靠 vibe coding 完成。

  • 德国史实线已经过充分验证。

  • 如有发现工具 Bug 或特定游戏版本的内存偏移量错误,欢迎提交 Issue 与 PR,会尽量修复。


1. 项目简介

SiliconOKW 是一套面向 Windows Steam 版《钢铁雄心 IV》1.19.5.0(Operation Postern v1.19.5.0.7c6c) 的 MCP 自动化与内存调用工具集。

本项目通过 Win32 ReadProcessMemory 零停表纯只读采集 与 游戏原生 CCommandQueue 玩家命令队列发令,让大模型像真实玩家一样读取战局并发出合规指令:

  • 非作弊路径:所有操作均构造游戏原生 CCommand 并通过引擎自身的 CanExecute 校验,禁用控制台与键鼠画面点击注入。

  • 双模式 MCP 服务端:支持 Full 模式(179 个细粒度合规工具,hoi4_debug_* 默认关闭) 与 Compact 5 工具极简模式(Schema < 1k tokens,含 72 项 Plan DSL 动作与 28 项按需深查主题),零第三方 MCP SDK 依赖。

  • 可选 Rust 原生加速:内置 native/hoi4_fastmem(PyO3 + Rayon 多核 Win32 内存扫描与批量读取),缺失时自动无缝回落纯 Python/numpy 路径。


Related MCP server: witp-ae

2. 近期核心能力与待细化项

已覆盖的进阶能力

  • 战区空间态势“睁眼”(纯只读):多连通域战区切分(含盟友借道与隔海本土锚点)、跨帧红/黄/绿泡胜负趋势、铁路与补给瓶颈诊断、目标空域掩护与闲置联队转场建议、包围切口与空防港口雷达(hoi4_inspect(topic="front_topology"))及战前窗口提醒。

  • 陆 / 空 / 海装备变体设计器:基于 PE 1.19.5.0 原生变体命令(CCreate/Update/SetObsolete/RenameEquipmentVariantCommand),内置科技自适应降级预设与自由模块定制,支持 dry_run 预览与产线联动。

  • 三层作战职责分离 & 跨海突击状态机:单线程 frontd 统筹填线战斗计划与装甲矛头割包(set_army_role / set_spearhead_task),原生两栖登陆(naval_invasion)、空降与海狮联合突击状态机(arm_paradrop_assault / arm_coastal_assault,就绪同帧触发并强制停表),以及产线实时效率平滑换线与敌方装甲威胁预警。

  • 完整中后期机制:情报机构(建机构、升级、招特工、特工任务、行动)、实验设施与特别工程(设施、科学家派驻、启动/中止/奖励选择)以及 19 项通用多态外交动作(diplomatic_actions)。

仍待细化的边缘项(欢迎 PR)

  • 跨海海运增援高层封装(CTransportUnitCommand 偏移已定位,待补高层调用封装;当前夺港后可由前线订单自动海运)

  • 秘密行动名称到整型 token 的自动映射(create_operation 当前需传入整型 operation_id)

  • 军工组织(MIO)细粒度政策加点与部分 DLC 专属外交交互


3. 核心架构

┌──────────────────────────────────────────────────────────────────────┐
│  MCP Client (Claude Code / Claude Desktop / Cursor / Custom Agent)  │
└─────────────────────────────────┬────────────────────────────────────┘
                                  │ JSON-RPC 2.0 over stdio
┌─────────────────────────────────▼────────────────────────────────────┐
│  clausewitz.py / mcp/server.py                                       │
│    • Full 模式:179 个细粒度合规 hoi4_* 工具                          │
│    • Compact 模式:5 工具 + turnengine(72 动作 / 28 深查 / 门禁)    │
└──────────────────┬───────────────────────────────┬───────────────────┘
                   │ 纯只读观测                     │ 原生命令队列发令
┌──────────────────▼────────────────┐ ┌────────────▼───────────────────┐
│  calling/ (核心调用层)             │ │  calling/cmdwin.py & winject   │
│    • mem.py / fastmem.py (Rust)   │ │    • W^X 双页隔离 + 精确版本闸  │
│    • game.py / offsets_win.py     │ │    • 原生 ctor + CanExecute    │
│    • front_topology / doctrine    │ │    • fake_vtable 防跨堆释放     │
│    • designmeta / variant_win     │ │    • post_drained 回读核验      │
│    • armyops_win / airops_win     │ │                                │
│    • intel_win / projects_win     │ │                                │
│    • paradrop_sm / divreserve     │ │                                │
│    • macros / autopilot / reddots │ │                                │
└──────────────────┬────────────────┘ └────────────┬───────────────────┘
                   │ ReadProcessMemory              │ CCommandQueue::Post
┌──────────────────▼───────────────────────────────▼───────────────────┐
│  hoi4.exe  (Hearts of Iron IV 1.19.5.0 Windows x64 PE)              │
└──────────────────────────────────────────────────────────────────────┘

已实现的兜底与工程护栏

  • 代码级运营兜底:内置红点门禁(reddots,含和会强阻塞)、Standing Orders v1 自动驾驶阶段机(autopilot)、housekeep 常规管家、rebalance_production 产能配平与实时效率平滑换线、upgrade_template_preset 换编挪厂联动与 strategic_health 战略体检,防止模型空转或摆烂。

  • 战斗计划与安全防崩:支持原生 CompletePlan / COrderNewFrontCommand(0xD57D90 敌对连通区匹配)、单条/整军转守(hoi4_execute_plan(executing=false))、按敌国与集团军角色隔离前线、hoi4_move_divisions(spread=true) 自动分散撤军、0 师空订单清理(防 0xB2E62E 崩溃)、winject 双页 W^X 隔离与跨堆释放防护(fake_vtable)。


4. 快速开始

详细安装与排障请参见 INSTALL.md。

1) 环境要求

  • Windows 10 / 11 x64

  • Python 3.11+

  • Steam 版 Hearts of Iron IV 1.19.5.0(进程名 hoi4.exe)

  • 与游戏运行在同一 Windows 用户权限级别(同级无需管理员)

2) 安装依赖与自检

python -m pip install -r requirements.txt

# 游戏未安装在默认 Steam 目录时指定环境变量
$env:HOI4_PATH = "D:\SteamLibrary\steamapps\common\Hearts of Iron IV"

# 环境自检
python clausewitz.py doctor

# 游戏读档后纯只读查看当前战局
python clausewitz.py status

3) 挂载到 MCP 客户端

  • Compact 5 工具极简模式(推荐用于长局运营):

    claude mcp add hoi4 -- python "D:\path\to\SiliconOKW\clausewitz.py" serve --compact
  • Full 179 工具全量模式(全部 hoi4_debug_* 调试/作弊工具默认禁用且隐藏;仅限本地逆向调试时可设 HOI4_MCP_ALLOW_DEBUG=1,而 hoi4_debug_eval 需同时显式设置 HOI4_MCP_ALLOW_EVAL=1):

    claude mcp add hoi4 -- python "D:\path\to\SiliconOKW\clausewitz.py" serve
  • 更多 JSON 配置模板见 mcp/config/。

4) 可选:构建 Rust 内存扫描加速扩展

powershell -File native/hoi4_fastmem/build_win.ps1

不编译也能运行,calling/fastmem.py 会自动回落到纯 Python/numpy 路径。

5) 使用前一定要看

  1. 保持游戏窗口未最小化:HOI4 最小化后模拟时钟会冻结,且 D3D 线程挂起恢复存在风险;发令前可先读取窗口状态。

  2. 读档后先清理空订单:读档后、解暂停前执行 hoi4_purge_orders,消除历史遗留的 0 师订单(防 0xB2E62E 崩溃)。

  3. 写命令串行发送并回读核验:遇 -32001 超时不代表失败,先用纯只读工具核验状态再决定是否重试。

  4. 切档/重开前先停后台微操:先调用 hoi4_clear_front_directive(),确认 frontd 处于 idle 状态。


5. 目录结构

路径

说明

clausewitz.py

统一入口:serve(--compact)、doctor、status、brief、tools、tables、shell

calling/

核心内存读写、游戏对象模型、PE 1.19.5.0 偏移表 offsets_win.py、命令表与运营兜底模块

mcp/

零依赖 stdio MCP 服务端 server.py 与 Windows 客户端配置模板

native/

hoi4_fastmem(Rust Win32 扫描扩展)与 hoi4_recalc(PE 偏移校验工具)

research/

PE 1.19.5.0 反汇编参考笔记 WINDOWS_1.19.5.md、离线反汇编工具链与回归测试 research/windows/test_*.py

docs/

策略参考提示词 STRATEGY_PROMPT.md 与定点数/动态变量说明

tools/

独立分发压缩包构建脚本 build_bundle.py


6. 离线回归测试

在 Windows 环境下无需启动游戏即可运行全量离线回归与偏移单一真源校验(提交 PR 前建议先跑一遍):

python tests/run_hermetic.py --with-legacy -q
python research/windows/test_offsets_single_source.py

7. 许可协议与免责声明

  • 本项目采用 MIT License 开源。欢迎通过 Issue 反馈 Bug 或特定版本偏移问题,欢迎 PR 补全尚未实现的功能模块。

  • 安全说明:MCP 服务端默认关闭全部 hoi4_debug_* 调试工具(hoi4_debug_eval 需显式双重环境变量解锁);仓库中不含任何 .pkl 文件,离线索引均以纯 JSON / JSON.GZ 形式存储(支持 HOI4_NO_PICKLE=1 全局禁 pickle)。

  • 免责声明:本项目仅用于单机模式下的 AI 自动化研究与技术交流,不包含《钢铁雄心 IV》游戏本体、DLC 解锁工具或任何受版权保护的游戏原始资源;严禁用于多人联机作弊或任何违反游戏服务条款的用途。使用本项目涉及进程内存读写,请提前备份存档并自行承担相应风险。

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to interact with Hearts of Iron IV by reading live game memory and sending commands through the game's own command queue for real-time gameplay and strategic decisions.
      28
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to read and control War in the Pacific: Admiral's Edition game state through memory and save-file tools, issue fleet and airgroup orders, advance turns, forecast victory and weather, and support autonomous staff inference.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to inspect and instrument live Windows x64 processes through memory manipulation, AOB scanning, function detours, thread hijacking, C-to-shellcode compilation, window discovery, and screenshots, without DLL injection.
      104
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables Claude to play Europa Universalis IV by reading game state, issuing the same orders as the GUI (armies, economy, diplomacy, events), and advancing time through an injected game hook. Also supports a watch page, play log, and auxiliary agents for observing and narrating a campaign.
      1
      -