feat(libSceCesCs): convert EUC-JP (CP51932) strings through a profile context #5515

Merged
ps54all merged 1 commit from upstream-pr/5515 into main 2026-10-14 14:03:36 +00:00
ps54all commented 2026-10-13 22:00:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-13T22:00:04Z.


What

EUC-JP (CP51932) string conversion through a profile context, which Metal Gear Solid 4's game executable imports (it fails to load on sceCesUtf8StrToMbcsStr without it).

  • sceCesUcsProfileInitEucJpCp51932 marks the caller's sheet and returns it as the profile.
  • sceCesMbcsUcsContextInit now keeps the profile pointer in the context (it wrote nothing before).
  • New: sceCesUtf8StrToMbcsStr, sceCesUcs2StrToMbcsStr, sceCesMbcsStrToUtf8Str, sceCesMbcsStrToUcs2Str, the four Get*Len forms, and sceCesEucJpToUcs2. For the EUC-JP profile they convert ASCII and JIS X 0201 half-width katakana (0x8E + 0xA1-0xDF ↔ U+FF61-U+FF9F). For the existing CP1252/CP1251 profiles they convert every character through the existing tables.
  • Two-byte JIS X 0208 and three-byte JIS X 0212 characters throw (NotImplemented): the mapping table is not present. A follow-up can add it; this keeps the change small and every unsupported input loud.
  • Signatures follow orbital's type database. The string forms stop at the source limit or at a zero code unit, which is neither converted nor counted. That and the context layout are assumptions recorded in the debt file.

Independent of #5425, which builds libSceCesCs-module from these sources (MGS4 loads the module under that name).

Tested

Windows 11, RTX 3080, WinLibs GCC 15.2.0 r7, Release.

  • guest_ces gains checks: UTF-8 ↔ EUC-JP with half-width katakana, both length queries, UCS-2 ↔ EUC-JP, sceCesEucJpToUcs2, and CP1251 through a context. It also checks the errors: destination too small, null context, truncated SS2, invalid SS2 trail, and a non-BMP code point giving UNASSIGNED_CODE. Passes; without the change it does not link.
  • check_conventions.py --base origin/main passes.
  • Metal Gear Solid 4: Guns of the Patriots, Master Collection Version (PPSA18194): with this, #5411, #5425, #5514 and an Opus change, the game executable loads, plays its intro and reaches gameplay (about 3 fps). No JIS X 0208 character reached these calls in that run (Italian language).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA18194
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code); the runs are on my machine.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4850027537 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5515). Originally posted by [ps54all](https://github.com/ps54all) on 2026-10-13T22:00:04Z. --- ### What EUC-JP (CP51932) string conversion through a profile context, which Metal Gear Solid 4's game executable imports (it fails to load on `sceCesUtf8StrToMbcsStr` without it). - `sceCesUcsProfileInitEucJpCp51932` marks the caller's sheet and returns it as the profile. - `sceCesMbcsUcsContextInit` now keeps the profile pointer in the context (it wrote nothing before). - New: `sceCesUtf8StrToMbcsStr`, `sceCesUcs2StrToMbcsStr`, `sceCesMbcsStrToUtf8Str`, `sceCesMbcsStrToUcs2Str`, the four `Get*Len` forms, and `sceCesEucJpToUcs2`. For the EUC-JP profile they convert ASCII and JIS X 0201 half-width katakana (`0x8E` + `0xA1`-`0xDF` ↔ U+FF61-U+FF9F). For the existing CP1252/CP1251 profiles they convert every character through the existing tables. - Two-byte JIS X 0208 and three-byte JIS X 0212 characters throw (`NotImplemented`): the mapping table is not present. A follow-up can add it; this keeps the change small and every unsupported input loud. - Signatures follow [orbital's type database](https://github.com/AlexAltea/orbital/blob/master/tools/ida/db_types.json). The string forms stop at the source limit or at a zero code unit, which is neither converted nor counted. That and the context layout are assumptions recorded in the debt file. Independent of #5425, which builds `libSceCesCs-module` from these sources (MGS4 loads the module under that name). ### Tested Windows 11, RTX 3080, WinLibs GCC 15.2.0 r7, Release. - `guest_ces` gains checks: UTF-8 ↔ EUC-JP with half-width katakana, both length queries, UCS-2 ↔ EUC-JP, `sceCesEucJpToUcs2`, and CP1251 through a context. It also checks the errors: destination too small, null context, truncated SS2, invalid SS2 trail, and a non-BMP code point giving `UNASSIGNED_CODE`. Passes; without the change it does not link. - `check_conventions.py --base origin/main` passes. - Metal Gear Solid 4: Guns of the Patriots, Master Collection Version (PPSA18194): with this, #5411, #5425, #5514 and an Opus change, the game executable loads, plays its intro and reaches gameplay (about 3 fps). No JIS X 0208 character reached these calls in that run (Italian language). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA18194 - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code); the runs are on my machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-13 22:00:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T22:00:49Z.


Progress report (9a3e2ac → 61e10ef)

📈 System libraries: 88.34% (+0.01%, +9 implemented, +1 declared functions)

✅ 9 implemented
Library Name
libSceCesCs sceCesMbcsStrGetUcs2Len
libSceCesCs sceCesMbcsStrGetUtf8Len
libSceCesCs sceCesMbcsStrToUcs2Str
libSceCesCs sceCesMbcsStrToUtf8Str
libSceCesCs sceCesUcs2StrGetMbcsLen
libSceCesCs sceCesUcs2StrToMbcsStr
libSceCesCs sceCesUcsProfileInitEucJpCp51932
libSceCesCs sceCesUtf8StrGetMbcsLen
libSceCesCs sceCesUtf8StrToMbcsStr
🆕 1 declared as stubs
Library Name
libSceCesCs sceCesEucJpToUcs2
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6156103811 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5515#issuecomment-6156103811). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T22:00:49Z. --- <!-- progress-report --> ### Progress report (9a3e2ac → 61e10ef) 📈 **System libraries**: 88.34% (+0.01%, +9 implemented, +1 declared functions) <details> <summary>✅ 9 implemented</summary> | Library | Name | | - | - | | libSceCesCs | `sceCesMbcsStrGetUcs2Len` | | libSceCesCs | `sceCesMbcsStrGetUtf8Len` | | libSceCesCs | `sceCesMbcsStrToUcs2Str` | | libSceCesCs | `sceCesMbcsStrToUtf8Str` | | libSceCesCs | `sceCesUcs2StrGetMbcsLen` | | libSceCesCs | `sceCesUcs2StrToMbcsStr` | | libSceCesCs | `sceCesUcsProfileInitEucJpCp51932` | | libSceCesCs | `sceCesUtf8StrGetMbcsLen` | | libSceCesCs | `sceCesUtf8StrToMbcsStr` | </details> <details> <summary>🆕 1 declared as stubs</summary> | Library | Name | | - | - | | libSceCesCs | `sceCesEucJpToUcs2` | </details>
adriadam10 commented 2026-10-14 11:53:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:53:37Z.


Checked the build, guest_ces (passes with the change; without it the test does not link) and the buffer/limit handling of the new conversions; merging after the rebase.

Added on your branch:

  • Rebased onto current main.
  • docs/dev/debt/libSceCesCs.md: the merge left the old sceCesMbcsUcsContextInit text ("nothing is stored", "no conversion through an initialized context exists") appended to the new EUC-JP entry, contradicting it. Removed the stale part, kept the signature source and the CP1251 note.

Unverified without hardware: the context layout, stopping at a zero code unit without counting it, and the error codes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6167728827 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5515#issuecomment-6167728827). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T11:53:37Z. --- Checked the build, `guest_ces` (passes with the change; without it the test does not link) and the buffer/limit handling of the new conversions; merging after the rebase. Added on your branch: - Rebased onto current `main`. - `docs/dev/debt/libSceCesCs.md`: the merge left the old `sceCesMbcsUcsContextInit` text ("nothing is stored", "no conversion through an initialized context exists") appended to the new EUC-JP entry, contradicting it. Removed the stale part, kept the signature source and the CP1251 note. Unverified without hardware: the context layout, stopping at a zero code unit without counting it, and the error codes.
adriadam10 commented 2026-10-14 12:35:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T12:35:28Z.


Checked the build, guest_ces (passes with the change; without it the test does not link) and the buffer/limit handling of the new conversions; merging after the rebase.

Added on your branch:

  • Rebased onto current main (conflict in docs/dev/debt/libSceCesCs.md with the CP1250 entry; both kept).
  • docs/dev/debt/libSceCesCs.md: removed the old sceCesMbcsUcsContextInit text ("nothing is stored", "no conversion through an initialized context exists") that contradicted the new EUC-JP entry; kept the signature source and the CP1251 note.

Unverified without hardware: the context layout, stopping at a zero code unit without counting it, and the error codes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6168471265 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5515#issuecomment-6168471265). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T12:35:28Z. --- Checked the build, `guest_ces` (passes with the change; without it the test does not link) and the buffer/limit handling of the new conversions; merging after the rebase. Added on your branch: - Rebased onto current `main` (conflict in `docs/dev/debt/libSceCesCs.md` with the CP1250 entry; both kept). - `docs/dev/debt/libSceCesCs.md`: removed the old `sceCesMbcsUcsContextInit` text ("nothing is stored", "no conversion through an initialized context exists") that contradicted the new EUC-JP entry; kept the signature source and the CP1251 note. Unverified without hardware: the context layout, stopping at a zero code unit without counting it, and the error codes.
ps54all commented 2026-10-14 16:08:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-14T16:08:13Z.


Thanks @adriadam10 for the rebase and for cleaning up the old sceCesMbcsUcsContextInit text. Agreed on the unverified points: the context layout, the stop at a zero code unit and the error codes come from the call sites in Metal Gear Solid 4 (PPSA18194), not from hardware. MGS4 runs through these conversions into gameplay here (discussion #5518).

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6172740074 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5515#issuecomment-6172740074). Originally posted by [ps54all](https://github.com/ps54all) on 2026-10-14T16:08:13Z. --- Thanks @adriadam10 for the rebase and for cleaning up the old `sceCesMbcsUcsContextInit` text. Agreed on the unverified points: the context layout, the stop at a zero code unit and the error codes come from the call sites in Metal Gear Solid 4 (PPSA18194), not from hardware. MGS4 runs through these conversions into gameplay here (discussion #5518). AI-assisted (Claude Code).
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
boykopovar/AnyPS5!5515
No description provided.