[PR #89] [CLOSED] runtime/shims: shim GetDateFormatEx and GetTimeFormatEx #141

Closed
opened 2026-11-26 20:16:55 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/89
Author: @Andretuta
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: old-pr/9819


📝 Commits (1)

  • cb6d910 runtime/shims: shim GetDateFormatEx and GetTimeFormatEx

📊 Changes

4 files changed (+394 additions, -2 deletions)

View changed files

📝 runtime/CMakeLists.txt (+14 -0)
➕ runtime/shims/datetime.cpp (+262 -0)
➕ runtime/test/datetime_test.cpp (+116 -0)
📝 scripts/build_runtime.ps1 (+2 -2)

📄 Description

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


🔄 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/89 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `old-pr/9819` --- ### 📝 Commits (1) - [`cb6d910`](https://github.com/ubiquitarianism/leonida/commit/cb6d91086ae1121660592f146540dec5a499a2f8) runtime/shims: shim GetDateFormatEx and GetTimeFormatEx ### 📊 Changes **4 files changed** (+394 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+14 -0) ➕ `runtime/shims/datetime.cpp` (+262 -0) ➕ `runtime/test/datetime_test.cpp` (+116 -0) 📝 `scripts/build_runtime.ps1` (+2 -2) </details> ### 📄 Description > 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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:16:55 +01:00
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#141
No description provided.