88 lines
12 KiB
Markdown
88 lines
12 KiB
Markdown
# Development rules
|
||
|
||
<a id="zh-cn"></a>
|
||
|
||
简体中文 · [English](#english) · [返回 Dev Docs](README.md#zh-cn)
|
||
|
||
## 实现位置
|
||
|
||
- 开工前明确玩家会看到什么变化和准备改的范围。涉及玩法或架构取舍,先和维护者对齐。先查目标版本的游戏文件、原版界面脚本和官方公开源码,记录版本、文件或函数以及支持结论的事实。把推测标为推测。需要读写游戏格式时,先评估已有工具的许可、维护情况和版本适用性。[DagorEngine 源码](https://github.com/GaijinEntertainment/DagorEngine)
|
||
- 客户端沿用原有流程,由本地服务器按协议回应。先看服务器或游戏自带配置能否解决。确实需要改客户端时,注明对应功能、原有行为和更小的改动为什么不够。界面脚本进 `patches/gui/`,数据包配置改动归 `packages/patcher/`,其他补丁按[补丁指南](patches.md#zh-cn)登记。
|
||
- 服务端按领域分模块。协议层处理请求和应答格式,规则层处理游戏规则,存档层负责持久化,数据层只提取游戏文件中的事实。修改档案的动作写盘成功后再回复。无法识别账号、缺必填参数或余额不足时,明确拒绝。初期开发用新存档验收,无需增加旧存档迁移。
|
||
- 应用通过参数把配置和路径交给共享库。按职责拆文件、函数和类,复用现有逻辑和常量。文件接近 300 行或函数接近 50 行就检查是否该拆分。商城与交易所的 HTML、CSS、JS 使用独立文件并复用[网页模块](../apps/server/src/web-ui)。
|
||
|
||
## 数值和数据来源
|
||
|
||
| 数值类别 | 做法 |
|
||
| --- | --- |
|
||
| 协议规定的值,如包头长度和消息类型 | 保留在代码中,注明版本和出处。 |
|
||
| 游戏文件已有的值,如车价、改装件价格 | 启动时从玩家的游戏文件读取。缺少必需值时报告具体字段并停止,避免悄悄代入编造的默认值。 |
|
||
| 离线版决定的值,如奖励、价格、权重、倍率、等级门槛、数量上限 | 写进对应模块的 `tuning/`。服务端默认值位于 [apps/server/tuning](../apps/server/tuning),启动时校验类型、范围和必填字段。 |
|
||
|
||
经济数值先查游戏数据和官方资料。商城以官方美元价作为 GJN 标价依据。官方资料缺项时,沿用已有出处的参考数据,或说明它属于离线设计。配置注释或 PR 记录出处、单位和取值规则,具体数值以配置为准。展示给玩家的数字也从同一数据来源生成。
|
||
|
||
本地服务器每次启动加载数值配置。数据目录下的同名 `tuning/*.jsonc` 可逐键覆盖默认对象。数字、字符串和列表整体替换。
|
||
|
||
## 常见实现陷阱与工程红线(含 AI 辅助开发对照)
|
||
|
||
欢迎借助 AI 助手阅读反汇编、排查日志和定位根因。实际提交改动时,请按下列正反对照逐条收口实现,确保补丁在后续小版本更新与长期维护中依然健壮:
|
||
|
||
| 维度 | 推荐做法 | 避免做法 |
|
||
| --- | --- | --- |
|
||
| 定位与偏移 | exe 补丁与 native 模块一律通过 `patches/exe/`、`patches/native/` 的 `signature`、`string_ref`、`within` 动态捕获地址、跳转目标和结构体偏移 | 在 C/TS 代码中硬编码 RVA、结构体偏移、函数地址或 `_ReturnAddress` |
|
||
| 改动分层 | 先核对服务端协议、任务根字段与原版配置能否解决;协议层、规则层、存档层、数据层职责分离,修改档案先写盘再回复 | 用客户端硬补丁绕开本该由本地服务器解决的问题,或在协议处理器里堆砌业务规则、先回成功再写盘 |
|
||
| 静态数据与数值 | 游戏文件已有的载具、任务、奖励、出生点等一律通过缓存 `datasets/` 从玩家原版文件读取;离线自定参数进 `apps/server/tuning/*.jsonc` 并做启动校验 | 在代码里手抄原版数值、写死兜底坐标或散落魔法数字 |
|
||
| 复用与粒度 | 复用 `local_mp_core` 等公共站点与现有模块;共享库 `packages/*` 通过参数收配置;文件接近 300 行、函数接近 50 行时拆分职责 | 重复挂钩同一原生函数、让 `packages/*` 反向读取 `apps/*`、把多类职责塞进单个大文件或大函数 |
|
||
| 编译器与运行环境 | Native C 代码严格兼容 MSVC(`native/wto-net/build.ps1` 0 警告);TS 代码兼容 Node 24 原生类型剥离(`erasableSyntaxOnly`) | 引入 GCC 专属扩展或未在 MSVC 编译核对的 C 语法 |
|
||
| 校验与验收 | 按改动执行对应的 `typecheck`、`check-patches`、完整 `check-gui`(Quirrel 字节码检查)与临时副本构建,如实记录未实机项 | 只靠单测或静态推演就宣称已验证通过;跳过 `check-gui`;在未实机验收前提交 `patches/versions/*.jsonc` |
|
||
| 范围与协作规范 | 一笔 PR 专注单一目标,使用英文约定式提交与英文代码注释,只保留实际人类协作者的 `Co-authored-by` | 夹带无关格式化/重构、写入个人本机路径或把 AI 助手署名为 `Co-authored-by` |
|
||
|
||
## 本地开发与材料
|
||
|
||
- 游戏只在专用副本和隔离环境里启动。启动前验证断网限制、本地服务、Steam 和账号身份,以及文件、注册表、机器标识、反作弊和崩溃上报的隔离。需要观察启动行为时,在一次性环境里核对前后变化。原版来源只读,通过离线副本启动并使用本地账号。
|
||
- 商城和交易所通过游戏内置浏览器访问本地服务。改动时核对该客户端内置浏览器支持的语法,沿用游戏语言和游戏文件中的本地化文字。包括浏览器子进程在内都要检查网络和缓存位置。
|
||
- 提交材料使用自己的代码和最小改动片段。游戏文件、解包产物和玩家数据留在本机。PR 使用可公开复核的出处和已清理的日志节选。
|
||
|
||
<a id="english"></a>
|
||
|
||
[简体中文](#zh-cn) · English · [Dev Docs](README.md#english)
|
||
|
||
## Where changes belong
|
||
|
||
- State the player-visible result and the intended scope before starting. Discuss gameplay or architectural changes with maintainers. Check the target build, stock UI scripts, and official public source. Record the version, file or symbol, and the evidence for the behavior. Mark any inference as such. For game formats, look for existing tools and review their licensing, maintenance, and version support. [DagorEngine source](https://github.com/GaijinEntertainment/DagorEngine)
|
||
- Keep the client's normal flow by responding from the local server. Check the server and stock configuration first. When a client change is necessary, document the feature, the stock behavior, and why a lighter change is insufficient. Put UI edits in `patches/gui/` and archive configuration edits in `packages/patcher/`. See the [patch guide](patches.md#english) for the other patch types.
|
||
- Keep protocol encoding, game rules, persistence, and game data extraction in their own layers. Persist a save change before returning success. Reject unknown accounts, missing required inputs, and insufficient balances. During early development, use fresh saves for acceptance and omit legacy migrations.
|
||
- Pass configuration and paths from applications into shared packages. Reuse existing logic and constants. Review files near 300 lines or functions near 50 lines for responsibilities that can be split. Store shop and marketplace HTML, CSS, and JavaScript in separate files and reuse the [web UI module](../apps/server/src/web-ui).
|
||
|
||
## Data and tuning
|
||
|
||
| Kind of value | Where it belongs |
|
||
| --- | --- |
|
||
| Protocol constants such as header sizes and message types | Keep them in code with the source and relevant version. |
|
||
| Values already in the game files such as vehicle and modification prices | Read them from the player's game files at startup. Report the field and stop if a required value is missing. |
|
||
| Offline defaults such as rewards, prices, weights, multipliers, rank thresholds, and limits | Put them in the module's `tuning/` directory. Server defaults are in [apps/server/tuning](../apps/server/tuning) and are validated at startup. |
|
||
|
||
Use game data and official material as the first sources for economic defaults. The local store uses official USD prices as the basis for GJN prices. For gaps, use reference data with a recorded source or document the offline design choice. Put the source, unit, and reasoning in a comment or the PR. Read the exact values and any player-facing numbers from the configuration.
|
||
|
||
At startup, the server can load a same-named `tuning/*.jsonc` file from the data directory. Object keys merge. Numbers, strings, and arrays are replaced as a whole.
|
||
|
||
## Common implementation pitfalls (especially with AI-assisted PRs)
|
||
|
||
Using AI tools to inspect binaries, trace logs, and pinpoint root causes is welcome. Before opening a PR, verify the implementation itself against these engineering guardrails so changes stay maintainable across game updates:
|
||
|
||
| Area | Preferred practice | Avoid |
|
||
| --- | --- | --- |
|
||
| Locating & offsets | Resolve addresses, jump targets, and struct offsets dynamically via `signature`, `string_ref`, or `within` captures in `patches/exe/` and `patches/native/` | Hardcoding RVAs, struct offsets, raw function pointers, or `_ReturnAddress` checks in C or TypeScript |
|
||
| Layering | Solve in the local server or stock config first; separate protocol, rules, persistence, and datasets, and write saves to disk before returning success | Adding client workarounds for server-solvable issues, mixing game rules into protocol handlers, or replying before persistence |
|
||
| Static data & tuning | Extract stock vehicle, mission, reward, and spawn data from player archives via cached `datasets/`; put offline defaults in `apps/server/tuning/*.jsonc` with startup validation | Copying stock numbers into source code, hardcoding fallback coordinates, or scattering magic constants |
|
||
| Reuse & modularity | Reuse shared native sites (`local_mp_core`) and existing helpers; pass paths/config into `packages/*`; split files near 300 lines or functions near 50 lines | Registering duplicate hooks for the same symbol, reading `apps/*` from `packages/*`, or growing monolithic handlers |
|
||
| Toolchains | Keep native C code cleanly buildable with MSVC (`native/wto-net/build.ps1`, zero warnings) and TS compatible with Node 24 erasable syntax | Relying on GCC-only extensions or submitting C changes without an MSVC build |
|
||
| Verification | Run the matching `typecheck`, `check-patches`, full `check-gui` (Quirrel bytecode check), and temporary copy build; clearly mark pending in-game checks | Relying on mock/unit tests as proof of in-game correctness, skipping `check-gui`, or committing `patches/versions/*.jsonc` before live acceptance |
|
||
| Scope & hygiene | Keep each PR focused on one change, use English conventional commits and English comments, and reserve `Co-authored-by` for human collaborators | Mixing unrelated refactors, leaking local paths, or attributing AI tools in `Co-authored-by` |
|
||
|
||
## Local development and contributions
|
||
|
||
- Launch the game in a dedicated copy and isolated environment. Before launch, verify the network restrictions, local service, and isolation of Steam identity, accounts, files, registry, machine identifiers, anti-cheat, and crash reporting. Observe before and after effects in a disposable environment when needed. Use a read-only stock source and a local account, and launch from the offline copy.
|
||
- The store and marketplace use the game's embedded browser and the local service. Check the browser features supported by the target build and reuse the game's language and localized data. Include the browser subprocess when checking network access and cache paths.
|
||
- Submit your own code and the smallest fragments needed for a patch. Keep game files, extracted assets, and player data local. Use sources that reviewers can access and redact any log excerpts.
|