Mod runtime API
Last updated:
- Published on
vs Panel Registry
与面板注册的区别
| Mod Runtime API | Panel Registry | |
|---|---|---|
| Purpose | Utility — mod metadata and timing hooks | UI — add tabs to the DevMode rail |
| Has UI | No | Yes |
| Typical use | Logging, save metadata, mod filters | In-game developer panels |
| Available | Any time after mods load | Only when DevMode rail is attached |
Use ModRuntime when you need mod metadata or a safe post-init timing point, regardless of whether you also register a panel.
| Mod 运行时 API | 面板注册 | |
|---|---|---|
| 用途 | 工具层 — mod 元数据与时机钩子 | UI 层 — 向 DevMode 轨道添加标签页 |
| 是否涉及 UI | 否 | 是 |
| 典型场景 | 日志、存档元数据、mod 过滤 | 游戏内开发者面板 |
| 可用时机 | mod 加载完成后任意时刻 | 仅当 DevMode 轨道已附着时 |
需要 mod 元数据或安全的初始化后时机时,使用 ModRuntime,与是否同时注册面板无关。
DevMode.Modding.ModRuntime
Public hooks for other mods:
| Member | Purpose |
|---|---|
ModRuntime.Catalog (IModCatalog) | Snapshot of loaded mods (GetSnapshot, GetIdSet) backed by ModManager.LoadedMods. |
ModRuntime.RegisterAfterAllModsLoaded(Action) | Same queue and timing as DevPanelRegistry.RegisterPanelWhenReady. |
DevModeModInfo exposes Id, DisplayName, and Version from each manifest.
Use this instead of re-implementing scans over ModManager when you need a consistent view (e.g. logging, save metadata, or UI filters).
面向其他 mod 的公开钩子:
| 成员 | 作用 |
|---|---|
ModRuntime.Catalog (IModCatalog) | 已加载 mod 的快照 (GetSnapshot、GetIdSet),数据来自 ModManager.LoadedMods。 |
ModRuntime.RegisterAfterAllModsLoaded(Action) | 与 DevPanelRegistry.RegisterPanelWhenReady 相同的队列与时机。 |
DevModeModInfo 暴露各清单中的 Id、DisplayName、Version。
在需要一致视图(例如日志、存档元数据、UI 过滤)时,使用本 API,而不是自行反复扫描 ModManager。
Dependencies
依赖
The same hard / soft dependency rules from Dev panel registry apply here: if you reference ModRuntime types unconditionally at startup and DevMode is absent, the CLR throws at load time.
- Hard dependency (
"dependencies": ["DevMode"]): suitable when mod catalog or timing hooks are core to your mod’s functionality. - Soft dependency (conditional compilation / runtime assembly check): suitable when
ModRuntimeusage is an optional enhancement. Guard all references behind#if YOUR_MOD_DEVMODEor an equivalent runtime check.
与开发者面板注册中描述的硬依赖 / 软依赖规则相同:若在启动时无条件引用 ModRuntime 类型而 DevMode 未安装,CLR 会在加载阶段抛出异常。
- 硬依赖(
"dependencies": ["DevMode"]):适合将 mod 目录或时机钩子作为核心功能的情况。 - 软依赖(条件编译 / 运行时程序集检测):适合将
ModRuntime用作可选增强的情况。所有引用需置于#if YOUR_MOD_DEVMODE或等效的运行时检测之后。