加载流程与时机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

  1. 读取启用列表 mod.datRead the enabled list from mod.dat
  2. 扫描 Mod:先 Steam 创意工坊,再本地 mods/;清单无效的文件夹被跳过并记录日志Scan mods: Steam Workshop first, then local mods/; invalid manifests are skipped and logged
  3. 按启用顺序逐个安装:选择版本目录;手机上的 DLL Mod 提示后跳过Install each enabled mod in order: pick the version folder; DLL mods on mobile are skipped with a notice
  4. 加载程序:Lua 执行入口脚本并调用 onLoad;DLL 加载 lib → main 并调用 launcher()Load the program: Lua runs the entry script and calls onLoad; DLL loads lib → main and calls launcher() 此时游戏配置表为空Game definitions are empty here
  5. 解析 def.xml 与 role-customize.xml(只解析,尚未写入表)Parse def.xml and role-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

  1. 清空所有表Clear every table
  2. 读取全部原版 .fwr 表Read all built-in .fwr tables
  3. 把每个 Mod 的 XML/fwr 行追加到对应表(按 Mod 顺序;DependID 在这里从原版行复制模板)Append each mod's XML/fwr rows to their tables (in mod order; DependID templates are copied here)
  4. 按 Mod 顺序调用 onDefLoaded(Lua)/ initModDef()(DLL)Call onDefLoaded (Lua) / initModDef() (DLL) in mod order 可用:ImplDef<T>.beans(全部行)。不可用:beansDict、getDataIDUsable: ImplDef<T>.beans (all rows). Not yet: beansDict, getDataID
  5. 初始化每一行(initRow,计算全局 ID 等)并建立按 ID 的索引Initialise every row (initRow, global IDs…) and build the ID index
  6. 读取战舰贴图覆盖 ShipTextures.xmlRead warship overrides from ShipTextures.xml
  7. 把所有 RawIcon 打包成图集Pack every RawIcon into an atlas

阶段三:收尾与运行Phase 3: finish and run

  1. 合并角色外观与武器(role-customize.xml),应用语言设置,显示封面Merge character skins and weapons (role-customize.xml), apply language, show the title screen
  2. 之后每帧调用 Lua onUpdate(ctx, dt),此时可以用 getDataIDEvery frame afterwards, Lua onUpdate(ctx, dt); getDataID works now
  3. 退出游戏时调用 Lua onUnloadOn quit, Lua onUnload

对照表At a glance

时机HookLuaDLL适合做什么Good for
安装InstallonLoadlauncher()订阅事件、替换 defLoader、初始化自己的状态Subscribe to events, replace defLoader, set up your own state
配置表就绪Definitions readyonDefLoadedinitModDef()修改原版行、用代码新增行Edit built-in rows, add rows from code
每帧Per frameonUpdate自行创建 MonoBehaviourCreate your own MonoBehaviour轻量的周期逻辑Light periodic logic
退出QuitonUnload—撤销订阅Undo subscriptions
在 Mod 管理界面修改启用列表后,变更在下次启动时生效;运行中不会热加载或卸载 Mod。 Changes in the mod manager take effect on the next launch; mods are never hot-loaded or unloaded while running.