Files
mtgodot-poc/libgr2
shenleiandClaude Opus 5.5 ff0983d3c8 2V3-a: walk with the keyboard through the ported player chain
PythonPlayer, PythonPlayerInput{,Keyboard,Mouse}, PythonPlayerEventHandler,
PythonPlayerSkill, PythonPlayerModule and GameType are verbatim copies; the
`player` stub module and the pending PythonPlayer/GameType stand-ins are gone.
Unported callees (CPythonSkill, CItemData, CItemManager, CPythonItem, ...) are
pending stubs. 64-bit fixes: emotion icon handles use Py_BuildPointer, and
PyDict_Next takes Py_ssize_t.

The actor did not move because GrannyUpdateModelMatrix passed the model matrix
through. Walk/run motions use constant root-motion extraction
(AccumulationFlags=AccumulationExtracted, LoopTranslation e.g. (0,-300,0) for
the warrior run, same as the .msa Accumulation). libgr2 now reads both fields
from TrackGroups[0], and the runtime moves by LoopTranslation over each
control's local-clock span, blended by control weight. VDA extraction is not
implemented.

port.login_flow presses DIK_UP; the actor walks more than 100 cm, and the fake
server parses CG packets and sees CG_MOVE FUNC_MOVE, then FUNC_WAIT at the new
position. port.login_live against the real server walked 132 cm.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 23:41:31 +09:00
..
2026-09-07 14:53:36 +08:00

libgr2

自研 gr2 v6/v7 只读读取器。零第三方依赖。施工文档 ../docs/reference/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 定义和公式注释自己写的,不是复制实现。