lifecycle: subclass the title window in its own character set (LIFECYCLE-ANSI-SUBCLASS) #2344

Open
github-bot wants to merge 1 commit from github-bot/gh-2344 into main AGit
Owner

@⁠syfyra on GitHub · 2026-11-26 14:18 UTC · original
syfyra:fix/lifecycle-ansi-subclass → main · +107 −7 · 4 files · 1 commits · draft

Claimed in the coordination issue as: LIFECYCLE-ANSI-SUBCLASS

What and why

runtime/shims/lifecycle.cpp subclasses the title's first top-level window so SC_CLOSE runs the suspend callbacks. It always did so with GetWindowLongPtrW/SetWindowLongPtrW. The retail title creates its window with CreateWindowExA (its import table names it from the -ansi- window set), which makes an ANSI window when the class was registered with the A function too; the title's class registration is not recorded in docs/, so whether the retail window is ANSI is not measured here. Setting a W procedure on an ANSI window turns it into a Unicode window: IsWindowUnicode becomes TRUE, and every text message the title posts and dispatches with the A functions is converted to Unicode for the hook. CallWindowProcW then converts it back for the title's ANSI procedure.

With a single-byte code page the round trip is lossless. With UTF-8 as the ANSI code page it is not. That is the code page of Windows' "Beta: Use Unicode UTF-8 for worldwide language support" option, or of a process whose manifest asks for it. Measured on Windows 11 with a small probe, an ANSI window with PostMessageA(WM_CHAR, byte) for each byte of "é€" (C3 A9 E2 82 AC), then DispatchMessageA:

window procedure chain the title's procedure receives
no hook c3 a9 e2 82 ac
hook set with SetWindowLongPtrW (main) 83 c3 a9 c2 a2 c3 80 e2 ac c2
hook set with SetWindowLongPtrA (this change) c3 a9 e2 82 ac

With code page 1252 all three receive the bytes unchanged. Only IsWindowUnicode differs there.

The hook now reads and sets the window procedure in the window's own character set (IsWindowUnicode), with an A and a W variant of the procedure that call the title's with CallWindowProcA/CallWindowProcW and fall back to DefWindowProcA/DefWindowProcW. A Unicode window is hooked as before.

Tested

Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo:

  • lifecycle_test gets a section 5. An ANSI class's window is created through the CreateWindowExA shim, and the test checks that it is hooked, that it stays an ANSI window, that the five WM_CHAR codes reach its procedure unchanged and in order, and that WM_SETTEXT/WM_GETTEXT still forward. A further check confirms a Unicode title window stays Unicode.
    • main: 1 of 35 checks fails (the window becomes Unicode).
    • this branch: 35 of 35 pass.
  • New lifecycle_utf8_test (MSVC only): the same source with test/utf8_codepage.manifest embedded (activeCodePage UTF-8), plus a check that GetACP() is 65001.
    • main: 2 of 36 checks fail; the title's procedure receives 83 c3 a9 c2 a2 c3 80 e2 ac c2.
    • this branch: 36 of 36 pass.
  • Full ctest -j 8 over the 170 CPU tests (no Vulkan SDK here): all pass.
  • Merges without new conflicts against every pull request that touches runtime/CMakeLists.txt, runtime/shims/lifecycle.cpp or runtime/test/lifecycle_test.cpp, including #2054.
  • scripts/check_no_game_data.py on the four files.

Not tested under Wine, where the manifest test may need Wine's own activeCodePage support.

GPUs tested: n/a (CPU tests)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

**@⁠syfyra** on GitHub · 2026-11-26 14:18 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2344) `syfyra:fix/lifecycle-ansi-subclass` → `main` · +107 −7 · 4 files · 1 commits · draft Claimed in the coordination issue as: LIFECYCLE-ANSI-SUBCLASS ### What and why `runtime/shims/lifecycle.cpp` subclasses the title's first top-level window so `SC_CLOSE` runs the suspend callbacks. It always did so with `GetWindowLongPtrW`/`SetWindowLongPtrW`. The retail title creates its window with `CreateWindowExA` (its import table names it from the `-ansi-` window set), which makes an ANSI window when the class was registered with the A function too; the title's class registration is not recorded in `docs/`, so whether the retail window is ANSI is not measured here. Setting a W procedure on an ANSI window turns it into a Unicode window: `IsWindowUnicode` becomes `TRUE`, and every text message the title posts and dispatches with the A functions is converted to Unicode for the hook. `CallWindowProcW` then converts it back for the title's ANSI procedure. With a single-byte code page the round trip is lossless. With UTF-8 as the ANSI code page it is not. That is the code page of Windows' "Beta: Use Unicode UTF-8 for worldwide language support" option, or of a process whose manifest asks for it. Measured on Windows 11 with a small probe, an ANSI window with `PostMessageA(WM_CHAR, byte)` for each byte of "é€" (`C3 A9 E2 82 AC`), then `DispatchMessageA`: | window procedure chain | the title's procedure receives | |---|---| | no hook | `c3 a9 e2 82 ac` | | hook set with `SetWindowLongPtrW` (`main`) | `83 c3 a9 c2 a2 c3 80 e2 ac c2` | | hook set with `SetWindowLongPtrA` (this change) | `c3 a9 e2 82 ac` | With code page 1252 all three receive the bytes unchanged. Only `IsWindowUnicode` differs there. The hook now reads and sets the window procedure in the window's own character set (`IsWindowUnicode`), with an A and a W variant of the procedure that call the title's with `CallWindowProcA`/`CallWindowProcW` and fall back to `DefWindowProcA`/`DefWindowProcW`. A Unicode window is hooked as before. ### Tested Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo: - `lifecycle_test` gets a section 5. An ANSI class's window is created through the `CreateWindowExA` shim, and the test checks that it is hooked, that it stays an ANSI window, that the five `WM_CHAR` codes reach its procedure unchanged and in order, and that `WM_SETTEXT`/`WM_GETTEXT` still forward. A further check confirms a Unicode title window stays Unicode. - `main`: 1 of 35 checks fails (the window becomes Unicode). - this branch: 35 of 35 pass. - New `lifecycle_utf8_test` (MSVC only): the same source with `test/utf8_codepage.manifest` embedded (`activeCodePage` UTF-8), plus a check that `GetACP()` is 65001. - `main`: 2 of 36 checks fail; the title's procedure receives `83 c3 a9 c2 a2 c3 80 e2 ac c2`. - this branch: 36 of 36 pass. - Full `ctest -j 8` over the 170 CPU tests (no Vulkan SDK here): all pass. - Merges without new conflicts against every pull request that touches `runtime/CMakeLists.txt`, `runtime/shims/lifecycle.cpp` or `runtime/test/lifecycle_test.cpp`, including #2054. - `scripts/check_no_game_data.py` on the four files. Not tested under Wine, where the manifest test may need Wine's own `activeCodePage` support. GPUs tested: n/a (CPU tests) AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The SC_CLOSE hook was always set with SetWindowLongPtrW. The retail
title creates its window with CreateWindowExA, and a W procedure on an
ANSI window makes it a Unicode window: IsWindowUnicode turns TRUE, and
every text message the title posts and dispatches with the A functions
goes through Unicode on its way to the title's procedure. Under a UTF-8
code page that breaks WM_CHAR: the UTF-8 bytes C3 A9 E2 82 AC arrived as
83 C3 A9 C2 A2 C3 80 E2 AC C2.

The hook now reads and sets the procedure with the window's own
character set and has an A and a W variant. lifecycle_test checks that
an ANSI title window stays ANSI and gets its WM_CHAR codes unchanged;
the new lifecycle_utf8_test (MSVC, activeCodePage manifest) runs the
same checks with UTF-8 as the ANSI code page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:23:44 +00:00
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 15:37 UTC · original · reviewed

Built lifecycle_test with MSVC on Windows 11. The CTest run passed and exercised both ANSI and Unicode windows. The hooked ANSI window stayed ANSI, received the original WM_CHAR values in order and forwarded WM_SETTEXT/WM_GETTEXT. No findings.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-26 15:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2344#pullrequestreview-6076879482) · **reviewed** Built `lifecycle_test` with MSVC on Windows 11. The CTest run passed and exercised both ANSI and Unicode windows. The hooked ANSI window stayed ANSI, received the original WM_CHAR values in order and forwarded WM_SETTEXT/WM_GETTEXT. No findings. AI-assisted.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2344/head:github-bot/gh-2344'
git switch 'github-bot/gh-2344'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2344'
git switch 'github-bot/gh-2344'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2344'
git switch 'github-bot/gh-2344'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2344'
git switch 'main'
git merge --squash 'github-bot/gh-2344'
git switch 'main'
git merge --ff-only 'github-bot/gh-2344'
git switch 'main'
git merge 'github-bot/gh-2344'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.