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

Open
opened 2026-11-26 21:20:54 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2344
Author: @syfyra
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/lifecycle-ansi-subclass


📝 Commits (1)

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

📊 Changes

4 files changed (+107 additions, -7 deletions)

View changed files

📝 runtime/CMakeLists.txt (+18 -0)
📝 runtime/shims/lifecycle.cpp (+25 -6)
📝 runtime/test/lifecycle_test.cpp (+54 -1)
➕ runtime/test/utf8_codepage.manifest (+10 -0)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2344 **Author:** [@syfyra](https://github.com/syfyra) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/lifecycle-ansi-subclass` --- ### 📝 Commits (1) - [`9206032`](https://github.com/ubiquitarianism/leonida/commit/92060324fa3f5bf74fff6fad3434084e6d848b57) lifecycle: subclass the title window in its own character set (LIFECYCLE-ANSI-SUBCLASS) ### 📊 Changes **4 files changed** (+107 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+18 -0) 📝 `runtime/shims/lifecycle.cpp` (+25 -6) 📝 `runtime/test/lifecycle_test.cpp` (+54 -1) ➕ `runtime/test/utf8_codepage.manifest` (+10 -0) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2347
No description provided.