libCes CP932 fix for Windows/macOS, fix SaveDataDialog lockups #878

Manually merged
github merged 5 commits from gh-pr/878/head into gh-pr/878/base 2026-11-26 09:35:53 +00:00
Owner

@⁠EmK530 on GitHub · 2026-09-27 22:53 UTC · original
EmK530:fix/neptunia-saves → main · +409 −16 · 6 files · 5 commits · merged 2026-09-28 14:42 UTC

Commits

  • caf66f4: Fix libCes ConvertMbcsToUtf8 failing on a CP932 codepage on Windows/macOS.

ConvertMbcsToUtf8 would previously crash in Neptunia ReVerse on save from the assertion: EXIT_IF(converter == reinterpret_cast<SDL_iconv_t>(-1));. On Windows and macOS, SDL_iconv_open is compiled using SDL3's own minimal implementation, so the converters it creates only support ASCII/Latin-1/UTF/UCS leading to a failure on the CP932 codepage.

This commit replaces the usage of SDL_iconv_open with a platform-specific layer.
Windows: Handles CP932 conversion with Win32 APIs.
macOS: macOS builds edited to link iconv, CesIconvOpen will directly call POSIX iconv which supports CP932.
Linux: Untouched, directly maps to SDL_iconv_open as it is compiled to support CP932 on Linux.

  • ecf21a4: Report SaveDataDialog as running for one check before reporting as finished.

Observed: After the CP932 crash was solved by commit caf66f4, Neptunia ReVerse would get stuck trying to save and repeatedly called SaveDataDialogOpen. It did not expect an immediate FINISHED status to be given by SaveDataDialogUpdateStatus right after a dialog open and would endlessly attempt to re-open the save data dialog.
This commit changes the SaveDataDialogOpen function to set the global status to RUNNING, and the status is later set to FINISHED on UpdateStatus when the guest has read the running status once.

Testing

I have only been able to verify the libCes solution as functioning for Windows. Linux is untouched but I do not have a macOS environment to test games against.

AI usage

AI was involved in the process of investigating issues and was responsible for implementing changes. I have studied the changes in post and wrote this PR myself.

**@⁠EmK530** on GitHub · 2026-09-27 22:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/878) `EmK530:fix/neptunia-saves` → `main` · +409 −16 · 6 files · 5 commits · merged 2026-09-28 14:42 UTC # Commits - caf66f4: **Fix libCes `ConvertMbcsToUtf8` failing on a CP932 codepage on Windows/macOS.** `ConvertMbcsToUtf8` would previously crash in Neptunia ReVerse on save from the assertion: `EXIT_IF(converter == reinterpret_cast<SDL_iconv_t>(-1));`. On Windows and macOS, `SDL_iconv_open` is compiled using SDL3's own minimal implementation, so the converters it creates only support ASCII/Latin-1/UTF/UCS leading to a failure on the CP932 codepage. This commit replaces the usage of `SDL_iconv_open` with a platform-specific layer. **Windows**: Handles CP932 conversion with Win32 APIs. **macOS**: macOS builds edited to link `iconv`, `CesIconvOpen` will directly call POSIX iconv which supports CP932. **Linux**: Untouched, directly maps to `SDL_iconv_open` as it is compiled to support CP932 on Linux. - ecf21a4: **Report SaveDataDialog as running for one check before reporting as finished.** Observed: After the CP932 crash was solved by commit caf66f4, Neptunia ReVerse would get stuck trying to save and repeatedly called `SaveDataDialogOpen`. It did not expect an immediate FINISHED status to be given by `SaveDataDialogUpdateStatus` right after a dialog open and would endlessly attempt to re-open the save data dialog. This commit changes the `SaveDataDialogOpen` function to set the global status to RUNNING, and the status is later set to FINISHED on UpdateStatus when the guest has read the running status once. # Testing I have only been able to verify the libCes solution as functioning for Windows. Linux is untouched but I do not have a macOS environment to test games against. ## AI usage AI was involved in the process of investigating issues and was responsible for implementing changes. I have studied the changes in post and wrote this PR myself.
SDL3's SDL_SYSTEM_ICONV build option defaults off on Windows and macOS,
so SDL falls back to its own bundled iconv there, which only implements
ASCII/Latin-1/UTF/UCS. SDL_iconv_open("UTF-8", "CP932") always failed as
a result, crashing games that convert Shift-JIS strings via
sceCesMbcsStrToUtf8Str (e.g. save-data dialogs).

Add a small CesIconv shim selected at compile time: Windows converts one
character at a time via the Win32 codepage-932 APIs, replicating
SDL_iconv's chunked semantics and error codes; macOS calls real POSIX
iconv directly, since libiconv is always present there and does support
CP932, unlike SDL's fallback. Linux is untouched, since SDL already
links real system iconv by default there.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
SaveDataDialogOpen() jumped straight from SAVE_STATUS_INITIALIZED (1) to
SAVE_STATUS_FINISHED (3), skipping SAVE_STATUS_RUNNING (2) entirely. At
least one title's save-write dialog stage only accepts a FINISHED status
after observing a RUNNING poll first; without it, the title assumed the
Open() request never took effect and re-issued it forever, hanging the
save flow (this only became visible once the CP932 crash above stopped
masking it).

Open() now starts the dialog as RUNNING. UpdateStatus() advances the
state machine, reporting RUNNING once before flipping to FINISHED for
subsequent polls; GetStatus() is untouched, staying a pure peek with no
side effects, matching the real SDK's pump-vs-peek split between the two
calls.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:35:53 +00:00
github manually merged commit 54d88ce21f into gh-pr/878/base 2026-11-26 09:35:53 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-27 22:59 UTC · original · edited 2026-09-27 23:24 UTC

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

The save-data dialog now reports RUNNING on its first status poll, then reports FINISHED on later polls. MBCS-to-UTF-8 conversion now uses a platform-specific converter behind a shared iconv-compatible interface. Windows uses Win32 CP932 conversion, macOS uses POSIX iconv, and other platforms use SDL iconv wrappers. The full-emulator test target helper and kyty_emulator target now link against iconv on Apple platforms.

Suggested reviewers: nmzik

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: 🟡 Moderate · up to 9f898

Windows CP932 conversion remains unusable for valid input and should be corrected before merging.

Architecture Summary

Architecture risk: 🔵 Low · up to 9f898

The change affects 2 systems.

Changed systems: src, CMakeLists.txt

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 2 changed files map to changed impact.
  • observed — CMakeLists.txt (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/libs/dialog.cpp: Added the SAVE_STATUS_RUNNING constant with value 2.
  • observed — Modified behavior in src/libs/dialog.cpp: SaveDataDialogUpdateStatus now snapshots and returns the current status before changing RUNNING to FINISHED; previously it returned the stored status without advancing it.
  • observed — Modified behavior in src/libs/dialog.cpp: SaveDataDialogOpen now sets the dialog status to RUNNING instead of immediately setting it to FINISHED.
  • observed — Modified behavior in src/libs/libCes.cpp: Adds platform-specific headers: Windows API declarations on Windows and errno.h/iconv.h on macOS.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 2 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes both main changes: the CP932 conversion fix for Windows and macOS and the SaveDataDialog lockup fix.
Description check ✅ Passed The description directly explains the CP932 conversion issue, the platform-specific implementation, the SaveDataDialog status change, and the available testing results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 2 files. (1 skipped: 1 unsupported.)


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-27 22:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/878#issuecomment-5860628733) · edited 2026-09-27 23:24 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/878"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> Navigate logical layers of code changes, visualize relationships, and explore their blast radius. <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough The save-data dialog now reports RUNNING on its first status poll, then reports FINISHED on later polls. MBCS-to-UTF-8 conversion now uses a platform-specific converter behind a shared iconv-compatible interface. Windows uses Win32 CP932 conversion, macOS uses POSIX iconv, and other platforms use SDL iconv wrappers. The full-emulator test target helper and `kyty_emulator` target now link against `iconv` on Apple platforms. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"9f8984ca9b6858ea884d15157b8b296409c3f166" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _🟡 Moderate_ · up to `9f898` <!-- final_review_risk_coverage:{"sourceCommitId":"9f8984ca9b6858ea884d15157b8b296409c3f166","coveredCommitId":"9f8984ca9b6858ea884d15157b8b296409c3f166","kind":"reviewed"} --> Windows CP932 conversion remains unusable for valid input and should be corrected before merging. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Architecture Summary **Architecture risk:** _🔵 Low_ · up to `9f898` The change affects 2 systems. **Changed systems:** `src`, `CMakeLists.txt` **Architecture concerns** No architecture-level concerns identified. <details> <summary>Review details</summary> **Systems and components** - _observed_ — src (service) was modified; 2 changed files map to changed impact. - _observed_ — CMakeLists.txt (service) was modified; 1 changed file maps to changed impact. **Before / after behavior** - _observed_ — Modified behavior in src/libs/dialog.cpp: Added the `SAVE_STATUS_RUNNING` constant with value `2`. - _observed_ — Modified behavior in src/libs/dialog.cpp: `SaveDataDialogUpdateStatus` now snapshots and returns the current status before changing `RUNNING` to `FINISHED`; previously it returned the stored status without advancing it. - _observed_ — Modified behavior in src/libs/dialog.cpp: `SaveDataDialogOpen` now sets the dialog status to `RUNNING` instead of immediately setting it to `FINISHED`. - _observed_ — Modified behavior in src/libs/libCes.cpp: Adds platform-specific headers: Windows API declarations on Windows and `errno.h`/`iconv.h` on macOS. </details> <!-- architecture_review_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 2 files. (1 skipped: … | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly and concisely summarizes both main changes: the CP932 conversion fix for Windows and macOS and the SaveDataDialog lockup fix. | | Description check | ✅ Passed | The description directly explains the CP932 conversion issue, the platform-specific implementation, the SaveDataDialog status change, and the available testing results. | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | </details> <details> <summary>Full details: Docstring Coverage</summary> **Explanation** Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 2 files. (1 skipped: 1 unsupported.) </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=878)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠EmK530 on GitHub · 2026-09-27 23:18 UTC · original

Correction: libiconv is not always shipped. CMakeLists.txt is now changed to add the link library iconv on macOS builds for this implementation.

**@⁠EmK530** on GitHub · 2026-09-27 23:18 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/878#issuecomment-5860758500) Correction: libiconv is not always shipped. CMakeLists.txt is now changed to add the link library `iconv` on macOS builds for this implementation.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-27 23:23 UTC · original · reviewed

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 Major · Use zero flags for CP932 and preserve invalid-sequence validation separately. · libCes.cpp:263-268

src/libs/libCes.cpp:263-268
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use zero flags for CP932 and preserve invalid-sequence validation separately.

The Windows branch passes unsupported MB_ERR_INVALID_CHARS to MultiByteToWideChar with code page 932. The API fails before conversion for every non-empty input character. ConvertMbcsToUtf8 then returns CES_ERROR_INVALID_ENCODE for valid single-byte input or CES_ERROR_UNASSIGNED_CODE for valid two-byte input. Both public CP932 conversion functions are affected.

Changing the flags to 0 allows valid conversion, but it removes strict invalid-sequence handling. Add explicit CP932 validation before using the zero-flag conversion. Do not apply the flag replacement alone.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 6b6101c0-7c1e-4ae9-beb7-8164a077cbb7

📥 Commits

Reviewing files that changed from the base of the PR and between b59677901a and 9f8984ca9b.

📒 Files selected for processing (1)
  • CMakeLists.txt

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-27 23:23 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/878#pullrequestreview-5332641903) · **reviewed** > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (1)** > > <details> > <summary><em>🟠 Major</em> · Use zero flags for CP932 and preserve invalid-sequence validation separately. · <code>libCes.cpp:263-268</code></summary><blockquote> > > `src/libs/libCes.cpp:263-268` > _🎯 Functional Correctness_ | _🟠 Major_ | _⚡ Quick win_ > > **Use zero flags for CP932 and preserve invalid-sequence validation separately.** > > The Windows branch passes unsupported `MB_ERR_INVALID_CHARS` to `MultiByteToWideChar` with code page 932. The API fails before conversion for every non-empty input character. `ConvertMbcsToUtf8` then returns `CES_ERROR_INVALID_ENCODE` for valid single-byte input or `CES_ERROR_UNASSIGNED_CODE` for valid two-byte input. Both public CP932 conversion functions are affected. > > Changing the flags to `0` allows valid conversion, but it removes strict invalid-sequence handling. Add explicit CP932 validation before using the zero-flag conversion. Do not apply the flag replacement alone. > > <!-- cr-comment:v1:0fcca9ab2dae0f90fb2e725e --> > > </blockquote></details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `6b6101c0-7c1e-4ae9-beb7-8164a077cbb7` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between b59677901a0ec1b945150cf78c49890bdf5fff07 and 9f8984ca9b6858ea884d15157b8b296409c3f166. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `CMakeLists.txt` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
This discussion has been locked. Commenting is limited to contributors.
No description provided.