fix: correct CJK tooltip layout and center option titles

This commit is contained in:
DragonHD
2026-09-20 11:25:04 +08:00
parent ca5748821c
commit 253cc47bc5
6 changed files with 450 additions and 1 deletions
+43
View File
@@ -100,6 +100,49 @@ Shrift_gb_Germany.TGA 2048 x 1024, 32bpp TGA (type 2, bottom-up, desc 0x08, 26
## Tools
### Option-title centering
Four original title sites push reference x=620 and directly draw text. The
panel/Bind button center is reference x=640 (`0x4D8646`). Patch the title
anchors to x=640 and redirect their draw calls to `.cjk+0x180500`:
| Page | Anchor instruction | Draw call |
|---|---|---|
| Audio | `0x4D748C` | `0x4D74A6` |
| Game | `0x4D9A1C` | `0x4D9A36` |
| Video | `0x4DDAB4` | `0x4DDACE` |
| Controls | `0x4DE8C8` | `0x4DE8E2` |
The wrapper preserves registers, measures the supplied font/text using
`0x4E7FD0`, subtracts half the measured width from the already transformed
screen point, and tail-jumps to `0x4EAB70`. Ordinary option rows and unrelated
draw calls retain their existing placement. Input opcodes are checked before
these title edits. `tools/test_cjk_titles.py` tests the actual call-site code,
coordinate transformation, measurement, and resulting draw positions.
### Wrapped-text layout correction
`0x4ED380` wraps/aligns tooltip paragraphs separately from the plain draw and
measure loops. Its one-byte temporary string must be extended to a full GB2312
character, otherwise a Chinese-only line has zero measured glyph height.
New hooks (all addresses apply to the documented Steam executable):
| Hook | Cave offset in .cjk | Purpose |
|---|---|---|
| `0x4ED430` | `0x180200` | Prepare a NUL-terminated one/two-byte character; preserve control-code flags |
| `0x4ED50E` | `0x180300` | Append complete character, advance byte index, retain width/height at CJK break |
| `0x4ED4E9` | `0x180400` | Preserve an overwide first CJK glyph instead of consuming only its lead byte |
Layout locals: `esp+0x18..0x1A` character plus NUL, `+0x1B` byte length,
`+0x14` source byte index, `+0x24` output byte count, `+0x1C` last wrap
checkpoint. Empty output initializes the checkpoint to `source_index-1`.
The caves use spare space after the metric table; UVs and atlas pixels are
unchanged. `tools/test_cjk_layout.py` runs the original layout and measurement
machine code in Unicorn and captures line bytes and coordinates at the draw
call boundary. This checks layout behavior without replacing it with a Python
reimplementation.
- `tools/add_section.py` — append an executable PE section.
- `tools/apply_cjk.py` — assemble the caves (keystone), add `.cjk`, write hooks and tables.
- `tools/build_cjk.py` — build the atlas TGA + `cjk_glyph`/`cjk_metric` from a charset.