Skip to content

ImeDialog: change wchar_t to uint16_t#199

Open
sleirsgoevy wants to merge 1 commit intoOpenOrbis:masterfrom
sleirsgoevy:wchar
Open

ImeDialog: change wchar_t to uint16_t#199
sleirsgoevy wants to merge 1 commit intoOpenOrbis:masterfrom
sleirsgoevy:wchar

Conversation

@sleirsgoevy
Copy link
Contributor

musl's wchar_t is 32-bit, but the PS4 expects 16-bit strings

musl's wchar_t is 32-bit, but the PS4 expects 16-bit strings
@Backporter
Copy link
Contributor

can confirm, implemented IME into my module and it shows up broken however swapping from wchat_t* to uint16_t* fixes it.

@Backporter
Copy link
Contributor

as someone else pointed out, shouldn't the compiler flag of -fshort-wchar also do exactly that?, this works for me that is.

@kiwidoggie
Copy link
Contributor

After digging way more into this, this will have to be a global change across all projects and build configurations to remain consistent. Pending talking with spec to figure out the best course, and if we should just onboard all of this to cmake while we are at it.

@cy33hc
Copy link

cy33hc commented Dec 14, 2022

Hi. I wanted to check to see if this is the cause of my issue in the ImeDialog. The problem is the ImeDialog only displaying the first character of the inputText and Title that I set into the param. The inputText should be the IP address. Also the "X" and "O" buttons are swapped. Btw, I'm creating an FTP client app for the PS4 and the ImeDialog is the last thing to do.

Here is the code that init the dialog and the screenshot of the result.

  int initImeDialog(const char *Title, const char *initialTextBuffer, int max_text_length, OrbisImeType type)
  {
    if (ime_dialog_running)
      return IME_DIALOG_ALREADY_RUNNING;

    wchar_t title[384];

    if (initialTextBuffer && strlen(initialTextBuffer) > 255)
    {
      ime_dialog_running = 0;
      return -1;
    }

    memset(&inputTextBuffer[0], 0, sizeof(inputTextBuffer));
    memset(&storebuffer[0], 0, sizeof(storebuffer));
    memset(&initial_ime_text[0], 0, sizeof(initial_ime_text));

    if (initialTextBuffer)
    {
      snprintf(storebuffer, 255, "%s", initialTextBuffer);
      snprintf(initial_ime_text, 255, "%s", initialTextBuffer);
    }

    // converts the multibyte string src to a wide-character string starting at dest.
    mbstowcs(inputTextBuffer, storebuffer, strlen(storebuffer) + 1);
    mbstowcs(title, Title, strlen(Title) + 1);

    OrbisImeDialogSetting param;
    memset(&param, 0, sizeof(OrbisImeDialogSetting));

    param.maxTextLength = max_text_length;
    param.inputTextBuffer = inputTextBuffer;
    param.title = title;
    param.userId = 0xFE;
    param.type = type;
    param.enterLabel = ORBIS_BUTTON_LABEL_DEFAULT;

    int res = sceImeDialogInit(&param, NULL);
    if (res >= 0)
    {
      ime_dialog_running = 1;
    }

ezFTP_20221213192226

@Backporter
Copy link
Contributor

yes, this is the reason why your IME is broken, you need to use uint16_t and not wchar_t, you also need to import mbstowcs from the system as it will no longer work if you pass in uint16_t, and cast it to wchar_t.

@cy33hc
Copy link

cy33hc commented Dec 14, 2022

Thx very much. Any examples on how to import mbstowcs from system. Hope this can help with any others seeking this info too.

Here's my shot at it.

## declare the function
int (*__mbstowcs)(wchar_t*, const char *, size_t) = NULL;

int libcInternal = sceKernelLoadStartModule("/system/common/lib/libSceLibcInternal.sprx", 0, NULL, 0, 0, 0);
int ret = sceKernelDlsym(libcInternal, "__whatever_symbol_string__", (void**)&__mbstowcs);

@Backporter
Copy link
Contributor

Backporter commented Dec 14, 2022

@kiwidoggie kiwidoggie linked an issue Jul 7, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Future

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix compiler semantics

4 participants