runtime/shims: shim GetDateFormatEx and GetTimeFormatEx #89

Closed
github-bot wants to merge 1 commit from gh-pr/89/head into gh-pr/89/base
Owner

@⁠Andretuta on GitHub · 2026-11-24 02:15 UTC · original
ubiquitarianism:old-pr/9819 → main · +394 −2 · 4 files · 1 commits · closed without merging

Carried over from old PR 9819 by piyonchu in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9819, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
This branch conflicts with the current main and needs a rebase.
piyonchu: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Clean-room shim for api-ms-win-core-datetime-l1-1-1.dll, kernel32.dll, and kernelbase.dll exporting GetDateFormatEx and GetTimeFormatEx.

Why

Static analysis of game_scarlett_master.exe (local inspection only — zero game bytes/RVAs included) shows 4 direct call sites passing L"" (LOCALE_NAME_USER_DEFAULT) and explicit date/time format pictures; any 0 return immediately throws a C++ exception.

Changes

  • Added runtime/shims/datetime.cpp:
    • Honors LEONIDA_LOCALE when lpLocaleName is null or empty (matching GetUserDefaultLocaleName).
    • Delegates to host GetDateFormatEx / GetTimeFormatEx first; preserves ERROR_INVALID_PARAMETER and ERROR_INSUFFICIENT_BUFFER contracts cleanly.
    • When a host/sandbox lacks locale tables or rejects a locale name, retries LOCALE_NAME_INVARIANT and falls back to a built-in Gregorian date/time picture formatter instead of returning 0.
    • Uses no function-local static initialization guards (0 _Init_thread_header symbols verified via dumpbin /symbols).
  • Added runtime/test/datetime_test.cpp covering DLL/registry key resolution, RFC/ISO date & 24h time format pictures, buffer size query (cch == 0), ERROR_INSUFFICIENT_BUFFER, invalid date/time fields (ERROR_INVALID_PARAMETER), unknown-locale recovery, and null SYSTEMTIME local-clock formatting.
  • Wired shims/datetime.cpp and datetime_test into runtime/CMakeLists.txt and scripts/build_runtime.ps1.

Verification

  • ctest -R '^datetime$': PASS (1/1) (datetime_test: PASS (0 failures)).
  • dumpbin /symbols on datetime.obj: 0 _Init_thread_header symbols.
  • gta6rt.exe --dry-run game_scarlett_master.exe: resolves both GetDateFormatEx and GetTimeFormatEx via shim.
  • python scripts/check_no_game_data.py, python tests/test_ctest_registration.py (4/4 OK), git diff --check.
  • Claimed on #9677 (https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7116632010).

AI-assisted: yes

**@⁠Andretuta** on GitHub · 2026-11-24 02:15 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/89) `ubiquitarianism:old-pr/9819` → `main` · +394 −2 · 4 files · 1 commits · closed without merging > Carried over from **old PR 9819** by `piyonchu` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9819`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > This branch conflicts with the current `main` and needs a rebase. > `piyonchu`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Clean-room shim for `api-ms-win-core-datetime-l1-1-1.dll`, `kernel32.dll`, and `kernelbase.dll` exporting `GetDateFormatEx` and `GetTimeFormatEx`. ### Why Static analysis of `game_scarlett_master.exe` (local inspection only — zero game bytes/RVAs included) shows 4 direct call sites passing `L""` (`LOCALE_NAME_USER_DEFAULT`) and explicit date/time format pictures; any `0` return immediately throws a C++ exception. ### Changes - Added [`runtime/shims/datetime.cpp`](runtime/shims/datetime.cpp): - Honors `LEONIDA_LOCALE` when `lpLocaleName` is null or empty (matching `GetUserDefaultLocaleName`). - Delegates to host `GetDateFormatEx` / `GetTimeFormatEx` first; preserves `ERROR_INVALID_PARAMETER` and `ERROR_INSUFFICIENT_BUFFER` contracts cleanly. - When a host/sandbox lacks locale tables or rejects a locale name, retries `LOCALE_NAME_INVARIANT` and falls back to a built-in Gregorian date/time picture formatter instead of returning `0`. - Uses no function-local static initialization guards (`0` `_Init_thread_header` symbols verified via `dumpbin /symbols`). - Added [`runtime/test/datetime_test.cpp`](runtime/test/datetime_test.cpp) covering DLL/registry key resolution, RFC/ISO date & 24h time format pictures, buffer size query (`cch == 0`), `ERROR_INSUFFICIENT_BUFFER`, invalid date/time fields (`ERROR_INVALID_PARAMETER`), unknown-locale recovery, and null `SYSTEMTIME` local-clock formatting. - Wired `shims/datetime.cpp` and `datetime_test` into `runtime/CMakeLists.txt` and `scripts/build_runtime.ps1`. ### Verification - `ctest -R '^datetime$'`: `PASS (1/1)` (`datetime_test: PASS (0 failures)`). - `dumpbin /symbols` on `datetime.obj`: `0` `_Init_thread_header` symbols. - `gta6rt.exe --dry-run game_scarlett_master.exe`: resolves both `GetDateFormatEx` and `GetTimeFormatEx` via `shim`. - `python scripts/check_no_game_data.py`, `python tests/test_ctest_registration.py` (`4/4` OK), `git diff --check`. - Claimed on `#9677` (`https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7116632010`). AI-assisted: yes
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:43:57 +00:00
github-bot closed this pull request 2026-11-26 08:43:57 +00:00
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-24 19:19 UTC · original

This carry-over of old upstream PR 9819 has been taken over in #1105, so I'm closing this draft as #17 describes. The branch old-pr/9819 stays.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-24 19:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/89#issuecomment-7141917407) This carry-over of old upstream PR 9819 has been taken over in #1105, so I'm closing this draft as #17 describes. The branch `old-pr/9819` stays. AI-assisted (Claude Code, Claude Opus 5.5).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.