mcpField
S
se-dev-game-code

se-dev-game-code

github.com/cometworks开发10126 次安装4 天前更新
代码仓库

关于 se-dev-game-code

se-dev-game-code 是用于搜索 Space Engineers version 1 反编译 C# 源码和文本内容的技能,适合 Mod、插件及脚本开发者查询 API、实现细节和版本差异。

主要功能

  1. 01准备反编译游戏源码
  2. 02搜索 C# 类和方法
  3. 03检查类继承层级
  4. 04搜索游戏文本内容
  5. 05通过本地 Git 历史追踪版本
  6. 06记录并验证游戏文件哈希

适用场景

  1. 01编写插件前查找 API
  2. 02补丁开发前检查方法实现
  3. 03比较不同游戏版本的源码
  4. 04查找代码引用的定义文件

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/cometworks/skills --skill se-dev-game-code

安装后在 Claude Code 中输入/se-dev-game-code确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

.python-version
Advanced.md
check_index.py
check_version.py
Clean.bat
clean.sh
CodeSearch.md
CommandExecution.md
CommandExecutionDetails.md
common-posix.sh
ContentTypes.md
copy_content.py
Decompile.sh
DecompileDll.sh
DetectGameRoot.bat
fix_case_collisions.py
GameFileHashes.md
hash_game_files.py
hierarchy_tree.py
HierarchySearch.md
Implementation.md
index_code.py
index_content.py
Prepare.bat
Prepare.md
prepare.sh
actions/
bash.md
prepare.md
search.md
test.md

详细介绍

SE Dev Game Code 技能

可读取 Space Engineers version 1 的反编译 C# 代码。

⚠️ 重要:命令在 UNIX shell 中运行。请使用 bash 语法。在 Windows 上使用 BusyBox;在 Linux 上使用原生 shell。

示例:

  • ✅ test -f file.txt && echo exists
  • ✅ ls -la | head -10
  • ❌ if exist file.txt (echo exists) - 这不会生效

操作:

  • prepare:运行一次性准备操作(Windows 上运行 Prepare.bat,Linux 上运行 prepare.sh)
  • bash:运行 UNIX shell 命令(Windows 上使用 busybox,Linux 上使用原生 shell)
  • search:使用 search_game_code.py 搜索代码
  • test:在 Windows 上运行 test_search_game_code.bat,或在 Linux 上运行 test_search_game_code.sh 来测试此技能

路由决策

按以下顺序检查这些模式——以第一个匹配项为准:

优先级模式示例路由
1空调用或不带参数的调用se-dev-game-code显示此帮助信息
2准备关键词se-dev-game-code prepare、se-dev-game-code setup、se-dev-game-code initprepare
3Bash/shell 关键词se-dev-game-code bash、se-dev-game-code grep、se-dev-game-code catbash
4搜索关键词se-dev-game-code search、se-dev-game-code find class、se-dev-game-code lookupsearch
5测试关键词se-dev-game-code test、se-dev-game-code verify、se-dev-game-code checktest

要求

主机系统的 PATH 中必须包含:

  • Python 3.11 或更高版本
  • git 命令行客户端(用于为每个反编译游戏版本建立版本记录)
  • dotnet SDK(用于安装 ilspycmd)

入门

⚠️ 重要:运行任何命令之前,请先阅读 CommandExecution.md,以避免导致命令失败的常见错误。

如果此文件夹中缺少 Prepare.DONE 文件,则必须先运行一次性准备步骤。请参阅 prepare 操作。

文件夹布局

准备完成后,技能文件夹中会包含一个 Data junction/symlink。实际数据存储在技能文件夹之外,因此在执行 Clean.bat / Prepare.bat / prepare.sh 时会保留下来。

skills/se-dev-game-code/
├── Data/                 (junction/symlink → per-user persistent game-code data)
│   ├── .git/             local Git repository tracking decompiled sources
│   ├── .gitignore        ignores CodeIndex/, graphify-out/, __pycache__, *.py[cod], *.bak, *.log
│   ├── game_version.txt  recorded SE_VERSION / CLIENT_BUILD_NUMBER / SERVER_BUILD_NUMBER
│   ├── game_files.json   SHA256 of every original game file (committed - diffable)
│   ├── Decompiled/       decompiled C# sources only, organised per assembly (committed)
│   ├── Content/          textual game content (committed - definition changes reviewable)
│   ├── CodeIndex/        CSV indexes (NOT committed - regenerated)
│   └── graphify-out/     Graphify graph of Decompiled/ (NOT committed - regenerated)
├── Bin64/                (junction/symlink → game's Bin64, removed after preparation)
└── ...                   skill scripts and documentation

Data 文件夹是指向每用户持久化游戏代码数据目录的 junction/symlink(Windows 上为 %USERPROFILE%\.se-dev\game-code,Linux 上为 ~/.se-dev/game-code)。请像以往一样处理 Data/Decompiled、Data/Content 和 Data/CodeIndex。

Graphify 图

准备过程会为 Data/Decompiled 下的反编译游戏代码构建一个独立的 Graphify 图(也可使用 SE_DEV_GAME_CODE_GRAPH_ROOT 指定)。该图会写入图化树旁的 Data/graphify-out(也可使用 SE_DEV_GAME_CODE_GRAPH_OUT 指定),因此 Data/Decompiled 中只包含反编译后的 C# 代码。Prepare 会在 Python 3.12 上安装 Graphify,并启用快速的原生 Rust Leiden 聚类后端;如果该后端可用(需要 uv),就会在约 1–2 分钟内自动构建图。无法配置快速后端时,则会退回到较慢的单核聚类(约 10–30 分钟),且默认选择加入,需先征求用户同意;设置 SE_DEV_GRAPHIFY=0 可禁用。仅在需要时阅读以下文档——常规搜索时可跳过:

健康检查和查询测试(仅在图构建完成后才有意义):

bash ../se-dev/graphify-check.sh Data --deep   # is the graph usable?
./test_graphify_game_code.sh                # run a few graph queries

反编译源代码的本地版本管理

Data 文件夹是一个本地 Git 仓库。每次成功准备都会为反编译后的 C# 源代码创建一个提交,提交信息使用游戏版本标签,例如 1.208.015 b4。

这意味着:

  • 所有以前反编译的游戏版本都会保留在本地 Git 历史记录中。你可以在 Data/ 中对任意过去的提交执行 git checkout,以检查旧版本或与旧版本进行比较。
  • **通过比较二进制文件中嵌入的版本常量与 Data/game_version.txt,自动检测游戏更新。**如果两者不同(或文件不存在),则会清空 Decompiled/、Content/、CodeIndex/、graphify-out/ 和 game_files.json,并重新进行反编译。
  • 这样便于更新插件、模组和脚本,以兼容新发布的游戏版本:在 Data/ 中比较两个提交之间相关源代码的差异,即可准确查看发生了哪些变化。

仓库使用内部作者/邮箱(se-dev-skills@localhost),因此即使机器未配置全局 Git 身份信息,也能正常提交。

原始游戏文件哈希值

准备过程还会记录 Space Engineers 安装目录中每个文件的 SHA256 值,并保存到 Data/game_files.json 中(相对于安装根目录的路径 → 小写十六进制摘要, 按字母顺序排序,每行一对),并以版本标签作为提交信息提交。 比较两个版本提交之间的差异,即可准确查看游戏更新修改了哪些二进制文件——包括既不是程序集也不是文本的资源,因此它们不会出现在 Data/Decompiled 或 Data/Content 中。

使用 ./verify_game_files.sh(Linux)或 .\VerifyGameFiles.bat(Windows)对照记录的摘要验证安装内容。有关文件格式、 差异比较方法和验证输出,请参阅 GameFileHashes.md。

必备文档

  • CommandExecution.md - ⚠️ 请先阅读 - Windows 命令执行详情;在 Linux 上请保留 bash 语法并使用 prepare.sh

代码搜索文档

快速搜索示例

# Find class declarations
uv run search_game_code.py class declaration MyCubeBlock

# Find method signatures
uv run search_game_code.py method signature UpdateBeforeSimulation

# Find class hierarchy
uv run search_game_code.py class children MyTerminalBlock

# Count results before viewing (useful for large result sets)
uv run search_game_code.py class usage MyEntity --count

# Limit number of results
uv run search_game_code.py class usage MyEntity --limit 10

# Paginate through results
uv run search_game_code.py class usage MyEntity --limit 10 --offset 0
uv run search_game_code.py class usage MyEntity --limit 10 --offset 20

需要精确 API、方法体或 IL(也就是你即将调用或修补的代码)时,请检查游戏代码。若要了解整个系统的工作原理,如果已安装 se-dev-game-book 手册,请先阅读;它比搜索更快。如果没有手册,本技能也可作为这方面的参考。

自定义脚本

若要构建自己的实用脚本来处理索引和反编译代码:

  • ScriptingGuide.md - 如何编写 Python 脚本、使用 BusyBox、处理 Windows 路径

游戏内容数据

游戏 Content 中的文本部分会复制到 Data/Content 文件夹,供全文搜索:

  • 语言翻译,包括字符串 ID
  • 方块和其他实体定义
  • 默认蓝图和场景
  • 内容类型完整列表请参阅 ContentTypes.md
内容索引

Data/CodeIndex/content_index.csv 将每个文本内容文件映射到引用它的反编译 C# 源文件。列包括:rel_path(相对于 Data/Content/ 的路径) 和 usage(引用该文件的 Data/Decompiled/ 中 C# 源文件的路径)。每个内容 文件会针对每处引用分别出现一行,因此你可以按 rel_path 筛选和分页,以查看 加载或引用指定内容文件的所有 C# 代码。没有已知引用的文件只有一行,且 usage 列为空。

通用规则

  • 通常只在 Data/Decompiled 文件夹中的 C# 源文件(.cs)里搜索。如果你要处理转译器或预加载器补丁,则也要在 IL 代码(.il)文件中搜索(如果准备过程中生成了这些文件;默认关闭,参见 DecompileDll.sh)。
  • 在 Data/Content 文件夹中搜索与任务相关的文件。类型列表请参见 ContentTypes.md。
  • 不要在 Data/Decompiled 文件夹之外搜索反编译的游戏代码。如果准备成功,反编译后的游戏源码树应位于该文件夹中。
  • 不要在 Data/Content 文件夹之外搜索游戏内容数据。如果准备成功,复制的游戏内容应位于该文件夹中。

操作参考

请按照以下详细说明操作:

备注

此技能的原始来源:https://github.com/CometWorks/skills

评论

支持 Markdown