Networked client on the existing Godot 4.7 + libgr2 renderer:
- net: m2dev wire protocol (libsodium KX + XChaCha20), auth/select/game
phases, EntityStore world model, ~all GC/CG headers. char create/delete,
private shop / mall / cube, SHOP_GC_START_EX, guild, party (+ CG_PARTY_SET_STATE),
quests, dragon soul, refine, safebox, exchange.
- UI: in-game windows migrated 1:1 from the reference uiscript/root .py —
char status (/stat), inventory+equipment, select-item ([SELECT_ITEM] quest
token), system-option + game-option + ESC system menu, private-shop 39-grid,
party info board, shop tabs, atlas, minimap, quickbar, chat, …
- EterGrnLib polish: GR2 material blend/two-sided, LOD crossfade, motion-event
dispatch, contact shadow, ray-AABB picking, weapon grip pre-transform.
Portable asset IO (A1) — all extension/libgr2/formats/mtproto reads routed
through godot::FileAccess (res:// PCK works on iOS/Android); standalone-lib
*_path() kept for the non-Godot CTests. AssetResolver + PropertyRegistry
switched to a baked index (bake_asset_index.gd) instead of std::filesystem.
Mobile builds: build-{android,ios}.sh, export-android.sh, pack-assets.sh,
gen-debug-keystore.sh. Assets ship as a zip mounted at runtime by
project/asset_pack.gd (adb push now; HTTP download is a drop-in later).
ctest 10/10, 34 GDScript suites, macOS/iOS/Android all build.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013EJxkHiNKS4kybHS3XKyAJ
43 lines
2.9 KiB
Markdown
43 lines
2.9 KiB
Markdown
# libgr2
|
||
|
||
自研 gr2 v6/v7 **只读**读取器。零第三方依赖。施工文档 [`../docs/steps/M0-gr2-reader.md`](../docs/steps/M0-gr2-reader.md)。
|
||
|
||
## 能做什么
|
||
|
||
- 容器:magic / header / section / pointer-fixup(懒解引用,不物化 32 位指针)
|
||
- section 解压:Oodle1(`oodle1.c`)
|
||
- 自描述类型树遍历(不硬编码 struct 布局)
|
||
- `FileInfo`:skeletons / meshes / materials / textures / models / animations
|
||
- 骨架 + `granny_transform` → 4x4 组合(`BuildCompositeTransform4x4` 语义)
|
||
- 蒙皮网格:顶点(按顶点格式自描述解)/ 索引 / 三角组 / BoneBindings(多 skeleton 取最优匹配)
|
||
- 材质:`granny_material` 链(直接 `.Texture` 或递归 `.Maps[].Map`)→ `granny_texture.FromFileName`;
|
||
`Mesh.material_textures` 与 `MaterialBindings` 平行,`tri_group.material_index` 索引它
|
||
- 动画曲线(`OldCurveType` B 样条,degree 0/1/2)解码 + `gr2::sample_pose`(跨文件按骨骼名 retarget)
|
||
|
||
## 验证
|
||
|
||
- 全量 9166 个 Metin2 `.gr2`:**0 崩溃、0 非退化谓词失败**(`tools/gr2fuzz`)
|
||
- **对拍真 Granny 2.9.12**:骨骼世界矩阵 ≤ 4.6e-5、蒙皮顶点 ≤ 6.5e-5(`tools/oracle_diff`,`test/m2-numeric.json`,23 用例含 v7 / 双 root / 刚体 / 多动画帧)
|
||
- 坏输入(空 / 错 magic / 截断 / 越界索引)一律干净报错,不崩
|
||
|
||
## 明确不做(Metin2 语料里 0 出现;要「任意 gr2」才需要)
|
||
|
||
| 缺口 | 现状 | 补的成本 |
|
||
|---|---|---|
|
||
| **writer** | 无(设计上只读)| 大,PoC 不需要 |
|
||
| Oodle0 解压(`Format==1`)| `decompress_status=1`,不崩 | 中,同族算法变体 |
|
||
| BitKnit 解压(`Format==4`)| `decompress_status=4`,不崩 | 大,无公开实现;退路:Windows 侧离线转未压缩 |
|
||
| 压缩曲线(`curve2` / `CurveData*` 变体)| `classify_curve` 标 `Identity`/`Unknown`,`read_old_curve` 跳过 | 中,`granny_curve.cpp` 各 `Da*` 分支 |
|
||
| B 样条 degree ≥ 3 | `eval` 退化到 degree 2 | 小,加 `CubicCoefficients` |
|
||
| 64 位 / big-endian gr2 | `load` 直接拒(`only 32-bit little-endian`)| 中 |
|
||
| 多 skeleton 文件里刚体挂件的 skeleton 归属 | mesh binding 取「悬空最少」的 skeleton;`oracle_diff` 对这种 mesh 会误判(不是 libgr2 的问题)| 需要 FileInfo 暴露 per-model skeleton 索引 |
|
||
|
||
## ⚠ 许可
|
||
|
||
`src/oodle1.c` 是从泄露的 Granny SDK **直接端口**的解码路径(约 450 行)。
|
||
|
||
- **内部研究 / 不发布 / 非商用**:可用(和「拿泄露 SDK 当字节级规格」同一风险类别,全项目都这么做)。
|
||
- **任何对外发布 / 商用**:必须 clean-room 重写(照公开的「granny2 Oodle1」算法描述从零写,不看这份端口)。
|
||
|
||
其余代码(容器 / 类型树 / 骨架 / 网格 / 曲线 / 姿势)是照泄露 SDK **头文件的 struct 定义和公式注释**自己写的,不是复制实现。
|