runtime/shims: shim GetDateFormatEx and GetTimeFormatEx #89

Closed
Andretuta wants to merge 1 commit from upstream-pr/89 into main
Andretuta commented 2026-11-24 02:15:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:15:52Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5464803391 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/89). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T02:15:52Z. --- > 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
aslan2142 commented 2026-11-24 19:19:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-24T19:19:00Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7141917407 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/89#issuecomment-7141917407). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-24T19:19:00Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!89
No description provided.