From c8ba395e4fa85e6274326dfa1765f7d24745dcaa Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Thu, 3 Dec 2026 06:13:23 +0800 Subject: [PATCH] docs(dev-docs): add common implementation pitfalls and PR self-check --- dev-docs/contributing.md | 2 ++ dev-docs/development-rules.md | 28 ++++++++++++++++++++++++++++ dev-docs/templates/pull-request.md | 8 ++++++++ 3 files changed, 38 insertions(+) diff --git a/dev-docs/contributing.md b/dev-docs/contributing.md index dad2b01..f868b73 100644 --- a/dev-docs/contributing.md +++ b/dev-docs/contributing.md @@ -9,6 +9,7 @@ - 改动只解决一个目标。实现、配置、补丁说明和相关开发文档一致。提交标题用英文 `type(scope): description`,scope 用小写模块名,仓库级改动用 `repo`。破坏兼容时用 `type(scope)!: description`,并在 `BREAKING CHANGE:` 脚注说明影响和处理方式。正文交代原因、依据和验证结果,代码注释也用英文。联署留给实际协作的开发者。 - 游戏行为的判断有目标版本和一手出处。新动作写清客户端怎样发请求、怎样读取应答。客户端改动登记到对应补丁或构建模块,并说明为何需要。涉及新数值时,按[三类数值规则](development-rules.md#数值和数据来源)检查来源、配置和校验。 - 检查模块职责、依赖方向和重复逻辑。涉及账号、余额和档案时,检查错误输入、写盘顺序,以及多个账号之间的数据隔离。选择奖品或其他数据项时,按明确规则排序和筛选。 +- 若借助 AI 助手编写代码,提交前请人工逐行对照 [常见实现陷阱与工程红线](development-rules.md#常见实现陷阱与工程红线含-ai-辅助开发对照):确认没有硬编码偏移/地址、没有写死原版数据或魔法数字、没有越层修改或夹带无关改动,并且每一条写进 PR 的检查命令都在本机真实运行过。 - 只做类型、补丁、构建和可运行检查。功能验收由人使用隔离副本在游戏里做。注明实际执行过的命令、对应版本和结果。还要实机核对时写出入口、操作和预期现象。商城或交易所改动覆盖内置浏览器打开、相关操作和关窗后的档案刷新。 - 提交前看一遍差异,确认来源、路径、记录和玩家数据可以分享。用 [PR 模板](templates/pull-request.md) 提供复核所需的信息。 @@ -21,6 +22,7 @@ - Keep one purpose per change. Update the affected implementation, configuration, patch notes, and developer docs together. Use English `type(scope): description` commit subjects with a lowercase module scope or `repo` for repository-wide changes. For a breaking change, use `type(scope)!: description` and a `BREAKING CHANGE:` footer that explains the impact and what to do. Explain the reason, evidence, and verification in the commit body. Use English comments and reserve co-author credits for developers who actually collaborated. - Cite the target build and primary evidence for game behavior. For new actions, explain how the client sends the request and consumes the reply. Register client edits in their patch or build module and explain why they are needed. For new values, check the source, tuning, and validation using the [three kinds of values](development-rules.md#data-and-tuning). - Check module responsibilities, dependency direction, and reuse. For accounts, currency, and saves, check bad inputs, when updates reach disk, and separation between accounts. Use explicit ordering and selection rules for prize pools and other lists. +- When using AI tools to draft code, review the diff line by line against [common implementation pitfalls](development-rules.md#common-implementation-pitfalls-especially-with-ai-assisted-prs): confirm there are no hardcoded addresses/offsets, no copied stock numbers or magic constants, no layer violations or unrelated edits, and that every check reported in the PR was actually executed. - Limit automated checks to type, patch, build, and startup checks. Functional acceptance is performed by a person in an isolated game copy. Report the commands actually run, the client builds, and the results. For pending in-game checks, give the entry point, action, and expected result. Store and marketplace changes cover opening the embedded browser, the affected action, and the profile refresh on close. - Review the diff for shareable sources, paths, records, and player data. Use the [PR template](templates/pull-request.md) to provide enough detail for review. diff --git a/dev-docs/development-rules.md b/dev-docs/development-rules.md index 34888d9..3934847 100644 --- a/dev-docs/development-rules.md +++ b/dev-docs/development-rules.md @@ -23,6 +23,20 @@ 本地服务器每次启动加载数值配置。数据目录下的同名 `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 和账号身份,以及文件、注册表、机器标识、反作弊和崩溃上报的隔离。需要观察启动行为时,在一次性环境里核对前后变化。原版来源只读,通过离线副本启动并使用本地账号。 @@ -52,6 +66,20 @@ Use game data and official material as the first sources for economic defaults. 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. diff --git a/dev-docs/templates/pull-request.md b/dev-docs/templates/pull-request.md index c564b92..5e9fba1 100644 --- a/dev-docs/templates/pull-request.md +++ b/dev-docs/templates/pull-request.md @@ -12,6 +12,14 @@ +## Self-check + +- [ ] No hardcoded addresses, RVAs, struct offsets, or `_ReturnAddress` checks (dynamic `patches/` captures used instead) +- [ ] No hardcoded stock game numbers or magic defaults (read from stock archives via `datasets/` or placed in `tuning/*.jsonc`) +- [ ] Layer boundaries preserved (protocol / rules / persistence / datasets; `packages/*` does not read `apps/*`) +- [ ] Scope is focused on one goal, code comments and commit messages are in English, and no unrelated files were modified +- [ ] Every command listed in **Checks run** was actually executed (including `check-gui` for `patches/gui/` and MSVC `build.ps1` for `native/`) + ## Checks run | Command or check | Client build if relevant | Result |