加载流程与时机Load pipeline & timing
Mod 全部在启动加载画面中处理。高亮的步骤是你的代码被调用的时机;“能访问什么”取决于你处在哪一步。 All mod work happens on the startup loading screen. Highlighted steps are where your code is called; what you can access depends on the step.
阶段一:安装 ModPhase 1: install mods
ViewPreLoad → ModPluginManager.initModPlugin
- 读取启用列表
mod.datRead the enabled list frommod.dat - 扫描 Mod:先 Steam 创意工坊,再本地
mods/;清单无效的文件夹被跳过并记录日志Scan mods: Steam Workshop first, then localmods/; invalid manifests are skipped and logged - 按启用顺序逐个安装:选择版本目录;手机上的 DLL Mod 提示后跳过Install each enabled mod in order: pick the version folder; DLL mods on mobile are skipped with a notice
- 加载程序:Lua 执行入口脚本并调用
onLoad;DLL 加载lib→main并调用launcher()Load the program: Lua runs the entry script and callsonLoad; DLL loadslib→mainand callslauncher()此时游戏配置表为空Game definitions are empty here - 解析
def.xml与role-customize.xml(只解析,尚未写入表)Parsedef.xmlandrole-customize.xml(parsed, not yet applied)
Mod 之间互不拖累:版本目录不匹配的 Mod 只记录错误并跳过;其他安装失败会停在该 Mod 并弹出提示——选“继续”跳过它并接着安装后面的 Mod,选“清除所有MOD并重启”则清空启用列表并重启游戏。失败的 Mod 不会进入已安装列表,它的数据与回调都不会生效。Mods fail independently: a mod with no matching version folder is logged and skipped; any other install failure pauses at that mod with a prompt — “Continue” skips it and installs the rest, “Clear all mods and restart” empties the enabled list and restarts the game. A failed mod never joins the installed list, so neither its data nor its callbacks take effect.
阶段二:加载配置表Phase 2: load definitions
CategoryManager.loadDefinitions
- 清空所有表Clear every table
- 读取全部原版
.fwr表Read all built-in.fwrtables - 把每个 Mod 的 XML/fwr 行追加到对应表(按 Mod 顺序;
DependID在这里从原版行复制模板)Append each mod's XML/fwr rows to their tables (in mod order;DependIDtemplates are copied here) - 按 Mod 顺序调用
onDefLoaded(Lua)/initModDef()(DLL)CallonDefLoaded(Lua) /initModDef()(DLL) in mod order 可用:ImplDef<T>.beans(全部行)。不可用:beansDict、getDataIDUsable:ImplDef<T>.beans(all rows). Not yet:beansDict,getDataID - 初始化每一行(
initRow,计算全局 ID 等)并建立按 ID 的索引Initialise every row (initRow, global IDs…) and build the ID index - 读取战舰贴图覆盖
ShipTextures.xmlRead warship overrides fromShipTextures.xml - 把所有
RawIcon打包成图集Pack everyRawIconinto an atlas
阶段三:收尾与运行Phase 3: finish and run
- 合并角色外观与武器(
role-customize.xml),应用语言设置,显示封面Merge character skins and weapons (role-customize.xml), apply language, show the title screen - 之后每帧调用 Lua
onUpdate(ctx, dt),此时可以用getDataIDEvery frame afterwards, LuaonUpdate(ctx, dt);getDataIDworks now - 退出游戏时调用 Lua
onUnloadOn quit, LuaonUnload
对照表At a glance
| 时机Hook | Lua | DLL | 适合做什么Good for |
|---|---|---|---|
| 安装Install | onLoad | launcher() | 订阅事件、替换 defLoader、初始化自己的状态Subscribe to events, replace defLoader, set up your own state |
| 配置表就绪Definitions ready | onDefLoaded | initModDef() | 修改原版行、用代码新增行Edit built-in rows, add rows from code |
| 每帧Per frame | onUpdate | 自行创建 MonoBehaviourCreate your own MonoBehaviour | 轻量的周期逻辑Light periodic logic |
| 退出Quit | onUnload | — | 撤销订阅Undo subscriptions |