some fixes

- added log spam
- fixed typo
- fixed log texts
This commit is contained in:
w1naenator 2025-07-18 14:47:40 +03:00
parent 148a74c35b
commit e86afb1154
3 changed files with 56 additions and 42 deletions

View File

@ -18,9 +18,11 @@ static ImeUi g_ime_ui;
class ImeHandler { class ImeHandler {
public: public:
ImeHandler(const OrbisImeKeyboardParam* param) { ImeHandler(const OrbisImeKeyboardParam* param) {
LOG_INFO(Lib_Ime, "Creating ImeHandler for keyboard");
Init(param, false); Init(param, false);
} }
ImeHandler(const OrbisImeParam* param) { ImeHandler(const OrbisImeParam* param) {
LOG_INFO(Lib_Ime, "Creating ImeHandler for IME");
Init(param, true); Init(param, true);
} }
~ImeHandler() = default; ~ImeHandler() = default;
@ -38,8 +40,13 @@ public:
openEvent.id = (ime_mode ? OrbisImeEventId::Open : OrbisImeEventId::KeyboardOpen); openEvent.id = (ime_mode ? OrbisImeEventId::Open : OrbisImeEventId::KeyboardOpen);
if (ime_mode) { if (ime_mode) {
sceImeGetPanelSize(&m_param.ime, &openEvent.param.rect.width, LOG_INFO(Lib_Ime, "calling sceImeGetPanelSize");
&openEvent.param.rect.height); Error e = sceImeGetPanelSize(&m_param.ime, &openEvent.param.rect.width,
&openEvent.param.rect.height);
if (e != Error::OK) {
LOG_ERROR(Lib_Ime, "sceImeGetPanelSize returned 0x{:X}", static_cast<u32>(e));
}
openEvent.param.rect.x = m_param.ime.posx; openEvent.param.rect.x = m_param.ime.posx;
openEvent.param.rect.y = m_param.ime.posy; openEvent.param.rect.y = m_param.ime.posy;
} else { } else {
@ -223,24 +230,23 @@ int PS4_SYSV_ABI sceImeGetPanelPositionAndForm() {
} }
Error PS4_SYSV_ABI sceImeGetPanelSize(const OrbisImeParam* param, u32* width, u32* height) { Error PS4_SYSV_ABI sceImeGetPanelSize(const OrbisImeParam* param, u32* width, u32* height) {
LOG_INFO(Lib_Ime, "sceImeGetPanelSize called"); LOG_INFO(Lib_Ime, "called");
if (!param) { if (!param) {
LOG_ERROR(Lib_Ime, "sceImeGetPanelSize: param is NULL"); LOG_ERROR(Lib_Ime, "param is NULL");
return Error::INVALID_ADDRESS; return Error::INVALID_ADDRESS;
} }
if (!width) { if (!width) {
LOG_ERROR(Lib_Ime, "sceImeGetPanelSize: width pointer is NULL"); LOG_ERROR(Lib_Ime, "width pointer is NULL");
return Error::INVALID_ADDRESS; return Error::INVALID_ADDRESS;
} }
if (!height) { if (!height) {
LOG_ERROR(Lib_Ime, "sceImeGetPanelSize: height pointer is NULL"); LOG_ERROR(Lib_Ime, "height pointer is NULL");
return Error::INVALID_ADDRESS; return Error::INVALID_ADDRESS;
} }
if (static_cast<u32>(param->option) & ~0x7BFF) { // Basic check for invalid options if (static_cast<u32>(param->option) & ~0x7BFF) { // Basic check for invalid options
LOG_ERROR(Lib_Ime, "sceImeGetPanelSize: Invalid option 0x{:X}", LOG_ERROR(Lib_Ime, "Invalid option 0x{:X}", static_cast<u32>(param->option));
static_cast<u32>(param->option));
return Error::INVALID_OPTION; return Error::INVALID_OPTION;
} }
@ -248,35 +254,31 @@ Error PS4_SYSV_ABI sceImeGetPanelSize(const OrbisImeParam* param, u32* width, u3
case OrbisImeType::Default: case OrbisImeType::Default:
*width = 500; // dummy value *width = 500; // dummy value
*height = 100; // dummy value *height = 100; // dummy value
LOG_INFO(Lib_Ime, "sceImeGetPanelSize: IME type Default ({})", LOG_INFO(Lib_Ime, "IME type Default ({})", static_cast<u32>(param->type));
static_cast<u32>(param->type));
break; break;
case OrbisImeType::BasicLatin: case OrbisImeType::BasicLatin:
*width = 500; // dummy value *width = 500; // dummy value
*height = 100; // dummy value *height = 100; // dummy value
LOG_INFO(Lib_Ime, "sceImeGetPanelSize: IME type BasicLatin ({})", LOG_INFO(Lib_Ime, "IME type BasicLatin ({})", static_cast<u32>(param->type));
static_cast<u32>(param->type));
break; break;
case OrbisImeType::Url: case OrbisImeType::Url:
*width = 500; // dummy value *width = 500; // dummy value
*height = 100; // dummy value *height = 100; // dummy value
LOG_INFO(Lib_Ime, "sceImeGetPanelSize: IME type Url ({})", static_cast<u32>(param->type)); LOG_INFO(Lib_Ime, "IME type Url ({})", static_cast<u32>(param->type));
break; break;
case OrbisImeType::Mail: case OrbisImeType::Mail:
// We set our custom sizes, commented sizes are the original ones // We set our custom sizes, commented sizes are the original ones
*width = 500; // 793 *width = 500; // 793
*height = 100; // 408 *height = 100; // 408
LOG_INFO(Lib_Ime, "sceImeGetPanelSize: IME type Mail ({})", static_cast<u32>(param->type)); LOG_INFO(Lib_Ime, "IME type Mail ({})", static_cast<u32>(param->type));
break; break;
case OrbisImeType::Number: case OrbisImeType::Number:
*width = 370; *width = 370;
*height = 402; *height = 402;
LOG_INFO(Lib_Ime, "sceImeGetPanelSize: IME type Number ({})", LOG_INFO(Lib_Ime, "IME type Number ({})", static_cast<u32>(param->type));
static_cast<u32>(param->type));
break; break;
default: default:
LOG_ERROR(Lib_Ime, "sceImeGetPanelSize: Invalid IME type ({})", LOG_ERROR(Lib_Ime, "Invalid IME type ({})", static_cast<u32>(param->type));
static_cast<u32>(param->type));
return Error::INVALID_TYPE; return Error::INVALID_TYPE;
} }
@ -287,9 +289,11 @@ Error PS4_SYSV_ABI sceImeKeyboardClose(Libraries::UserService::OrbisUserServiceU
LOG_INFO(Lib_Ime, "called"); LOG_INFO(Lib_Ime, "called");
if (!g_keyboard_handler) { if (!g_keyboard_handler) {
LOG_ERROR(Lib_Ime, "No keyboard handler is open");
return Error::NOT_OPENED; return Error::NOT_OPENED;
} }
LOG_INFO(Lib_Ime, "Closing keyboard handler for user ID: {}", userId);
g_keyboard_handler.release(); g_keyboard_handler.release();
return Error::OK; return Error::OK;
} }
@ -308,23 +312,33 @@ Error PS4_SYSV_ABI sceImeKeyboardOpen(Libraries::UserService::OrbisUserServiceUs
const OrbisImeKeyboardParam* param) { const OrbisImeKeyboardParam* param) {
LOG_INFO(Lib_Ime, "called"); LOG_INFO(Lib_Ime, "called");
LOG_INFO(Lib_Ime, "kValidImeDialogExtOptionMask=0x{:X}", kValidImeDialogExtOptionMask); LOG_INFO(Lib_Ime, "kValidImeDialogExtOptionMask={:032b}", kValidImeDialogExtOptionMask);
if (!param) { if (!param) {
LOG_ERROR(Lib_Ime, "param is null");
return Error::INVALID_ADDRESS; return Error::INVALID_ADDRESS;
} }
if (!param->arg) { if (!param->arg) {
LOG_ERROR(Lib_Ime, "param->arg is null");
return Error::INVALID_ARG; return Error::INVALID_ARG;
} }
if (!param->handler) { if (!param->handler) {
LOG_ERROR(Lib_Ime, "param->handler is null");
return Error::INVALID_HANDLER; return Error::INVALID_HANDLER;
} }
if (g_keyboard_handler) { if (g_keyboard_handler) {
LOG_ERROR(Lib_Ime, "Keyboard handler is already open");
return Error::BUSY; return Error::BUSY;
} }
g_keyboard_handler = std::make_unique<ImeHandler>(param); g_keyboard_handler = std::make_unique<ImeHandler>(param);
if (!g_keyboard_handler) {
LOG_ERROR(Lib_Ime, "Failed to create keyboard handler");
return Error::NO_MEMORY;
} else {
LOG_INFO(Lib_Ime, "Keyboard handler created successfully for user ID: {}", userId);
}
return Error::OK; return Error::OK;
} }
@ -347,7 +361,7 @@ Error PS4_SYSV_ABI sceImeOpen(const OrbisImeParam* param, const OrbisImeParamExt
LOG_INFO(Lib_Ime, "called"); LOG_INFO(Lib_Ime, "called");
if (!param) { if (!param) {
LOG_ERROR(Lib_Ime, "sceImeOpen: param is null"); LOG_ERROR(Lib_Ime, "param is null");
return Error::INVALID_ADDRESS; return Error::INVALID_ADDRESS;
} else { } else {
// LOG_DEBUG values for debugging purposes // LOG_DEBUG values for debugging purposes
@ -374,7 +388,7 @@ Error PS4_SYSV_ABI sceImeOpen(const OrbisImeParam* param, const OrbisImeParamExt
} }
if (!extended) { if (!extended) {
LOG_INFO(Lib_Ime, "sceImeOpen: extended is null"); LOG_INFO(Lib_Ime, "extended is null");
} else { } else {
// LOG_DEBUG values for debugging purposes // LOG_DEBUG values for debugging purposes
LOG_DEBUG(Lib_Ime, "extended: option={:032b}", static_cast<u32>(extended->option)); LOG_DEBUG(Lib_Ime, "extended: option={:032b}", static_cast<u32>(extended->option));
@ -411,46 +425,46 @@ Error PS4_SYSV_ABI sceImeOpen(const OrbisImeParam* param, const OrbisImeParamExt
} }
if (param->user_id < 1 || param->user_id > 4) { if (param->user_id < 1 || param->user_id > 4) {
LOG_ERROR(Lib_Ime, "sceImeOpen: Invalid user_id ({})", static_cast<u32>(param->user_id)); LOG_ERROR(Lib_Ime, "Invalid user_id ({})", static_cast<u32>(param->user_id));
return Error::INVALID_USER_ID; return Error::INVALID_USER_ID;
} }
if (!magic_enum::enum_contains(param->type)) { if (!magic_enum::enum_contains(param->type)) {
LOG_ERROR(Lib_Ime, "sceImeOpen: Invalid type ({})", static_cast<u32>(param->type)); LOG_ERROR(Lib_Ime, "Invalid type ({})", static_cast<u32>(param->type));
return Error::INVALID_TYPE; return Error::INVALID_TYPE;
} }
if (static_cast<u64>(param->supported_languages) & ~kValidOrbisImeLanguageMask) { if (static_cast<u64>(param->supported_languages) & ~kValidOrbisImeLanguageMask) {
LOG_ERROR(Lib_Ime, "sceImeOpen: supported_languages has invalid bits (0x{:016X})", LOG_ERROR(Lib_Ime, "supported_languages has invalid bits (0x{:016X})",
static_cast<u64>(param->supported_languages)); static_cast<u64>(param->supported_languages));
return Error::INVALID_SUPPORTED_LANGUAGES; return Error::INVALID_SUPPORTED_LANGUAGES;
} }
if (!magic_enum::enum_contains(param->enter_label)) { if (!magic_enum::enum_contains(param->enter_label)) {
LOG_ERROR(Lib_Ime, "sceImeOpen: Invalid enter_label ({})", LOG_ERROR(Lib_Ime, "Invalid enter_label ({})",
static_cast<u32>(param->enter_label)); static_cast<u32>(param->enter_label));
return Error::INVALID_ENTER_LABEL; return Error::INVALID_ENTER_LABEL;
} }
if (!magic_enum::enum_contains(param->input_method)) { if (!magic_enum::enum_contains(param->input_method)) {
LOG_ERROR(Lib_Ime, "sceImeOpen: Invalid input_method ({})", LOG_ERROR(Lib_Ime, "Invalid input_method ({})",
static_cast<u32>(param->input_method)); static_cast<u32>(param->input_method));
return Error::INVALID_INPUT_METHOD; return Error::INVALID_INPUT_METHOD;
} }
if (static_cast<u32>(param->option) & ~kValidImeOptionMask) { if (static_cast<u32>(param->option) & ~kValidImeOptionMask) {
LOG_ERROR(Lib_Ime, "sceImeOpen: option has invalid bits set (0x{:X}), mask=(0x{:X})", LOG_ERROR(Lib_Ime, "option has invalid bits set (0x{:X}), mask=(0x{:X})",
static_cast<u32>(param->option), kValidImeOptionMask); static_cast<u32>(param->option), kValidImeOptionMask);
return Error::INVALID_OPTION; return Error::INVALID_OPTION;
} }
if (param->maxTextLength == 0 || param->maxTextLength > ORBIS_IME_DIALOG_MAX_TEXT_LENGTH) { if (param->maxTextLength == 0 || param->maxTextLength > ORBIS_IME_DIALOG_MAX_TEXT_LENGTH) {
LOG_ERROR(Lib_Ime, "sceImeOpen: maxTextLength invalid ({})", param->maxTextLength); LOG_ERROR(Lib_Ime, "maxTextLength invalid ({})", param->maxTextLength);
return Error::INVALID_MAX_TEXT_LENGTH; return Error::INVALID_MAX_TEXT_LENGTH;
} }
if (!param->inputTextBuffer) { if (!param->inputTextBuffer) {
LOG_ERROR(Lib_Ime, "sceImeOpen: inputTextBuffer is NULL"); LOG_ERROR(Lib_Ime, "inputTextBuffer is NULL");
return Error::INVALID_INPUT_TEXT_BUFFER; return Error::INVALID_INPUT_TEXT_BUFFER;
} }
@ -459,23 +473,23 @@ Error PS4_SYSV_ABI sceImeOpen(const OrbisImeParam* param, const OrbisImeParamExt
const float maxHeight = useHighRes ? 2160.0f : 1080.0f; const float maxHeight = useHighRes ? 2160.0f : 1080.0f;
if (param->posx < 0.0f || param->posx >= maxWidth) { if (param->posx < 0.0f || param->posx >= maxWidth) {
LOG_ERROR(Lib_Ime, "sceImeOpen: posx out of range (%.2f), max allowed %.0f", param->posx, LOG_ERROR(Lib_Ime, "posx out of range (%.2f), max allowed %.0f", param->posx,
maxWidth); maxWidth);
return Error::INVALID_POSX; return Error::INVALID_POSX;
} }
if (param->posy < 0.0f || param->posy >= maxHeight) { if (param->posy < 0.0f || param->posy >= maxHeight) {
LOG_ERROR(Lib_Ime, "sceImeOpen: posy out of range (%.2f), max allowed %.0f", param->posy, LOG_ERROR(Lib_Ime, "posy out of range (%.2f), max allowed %.0f", param->posy,
maxHeight); maxHeight);
return Error::INVALID_POSY; return Error::INVALID_POSY;
} }
if (!magic_enum::enum_contains(param->horizontal_alignment)) { if (!magic_enum::enum_contains(param->horizontal_alignment)) {
LOG_ERROR(Lib_Ime, "sceImeOpen: Invalid horizontal_alignment ({})", LOG_ERROR(Lib_Ime, "Invalid horizontal_alignment ({})",
static_cast<u32>(param->horizontal_alignment)); static_cast<u32>(param->horizontal_alignment));
return Error::INVALID_HORIZONTALIGNMENT; return Error::INVALID_HORIZONTALIGNMENT;
} }
if (!magic_enum::enum_contains(param->vertical_alignment)) { if (!magic_enum::enum_contains(param->vertical_alignment)) {
LOG_ERROR(Lib_Ime, "sceImeOpen: Invalid vertical_alignment ({})", LOG_ERROR(Lib_Ime, "Invalid vertical_alignment ({})",
static_cast<u32>(param->vertical_alignment)); static_cast<u32>(param->vertical_alignment));
return Error::INVALID_VERTICALALIGNMENT; return Error::INVALID_VERTICALALIGNMENT;
} }
@ -483,20 +497,20 @@ Error PS4_SYSV_ABI sceImeOpen(const OrbisImeParam* param, const OrbisImeParamExt
if (extended) { if (extended) {
u32 ext_option_value = static_cast<u32>(extended->option); u32 ext_option_value = static_cast<u32>(extended->option);
if (ext_option_value & ~kValidImeExtOptionMask) { if (ext_option_value & ~kValidImeExtOptionMask) {
LOG_ERROR(Lib_Ime, "sceImeOpen: extended->option has invalid bits set (0x{:X})", LOG_ERROR(Lib_Ime, "extended->option has invalid bits set (0x{:X})",
ext_option_value); ext_option_value);
return Error::INVALID_EXTENDED; return Error::INVALID_EXTENDED;
} }
} }
if (!param->work) { if (!param->work) {
LOG_ERROR(Lib_Ime, "sceImeOpen: work buffer is NULL"); LOG_ERROR(Lib_Ime, "work buffer is NULL");
return Error::INVALID_WORK; return Error::INVALID_WORK;
} }
for (unsigned i = 0; i < sizeof(param->reserved); ++i) { for (unsigned i = 0; i < sizeof(param->reserved); ++i) {
if (param->reserved[i] != 0) { if (param->reserved[i] != 0) {
LOG_ERROR(Lib_Ime, "sceImeOpen: reserved field must be zeroed"); LOG_ERROR(Lib_Ime, "reserved field must be zeroed");
return Error::INVALID_RESERVED; return Error::INVALID_RESERVED;
} }
} }
@ -504,12 +518,12 @@ Error PS4_SYSV_ABI sceImeOpen(const OrbisImeParam* param, const OrbisImeParamExt
// Todo: validate arg and handler // Todo: validate arg and handler
if (g_ime_handler) { if (g_ime_handler) {
LOG_ERROR(Lib_Ime, "sceImeOpen: Error BUSY"); LOG_ERROR(Lib_Ime, "Error BUSY");
return Error::BUSY; return Error::BUSY;
} }
g_ime_handler = std::make_unique<ImeHandler>(param); g_ime_handler = std::make_unique<ImeHandler>(param);
LOG_INFO(Lib_Ime, "sceImeOpen: OK"); LOG_INFO(Lib_Ime, "OK");
return Error::OK; return Error::OK;
} }
@ -519,7 +533,7 @@ int PS4_SYSV_ABI sceImeOpenInternal() {
} }
void PS4_SYSV_ABI sceImeParamInit(OrbisImeParam* param) { void PS4_SYSV_ABI sceImeParamInit(OrbisImeParam* param) {
LOG_INFO(Lib_Ime, "sceImeParamInit called"); LOG_INFO(Lib_Ime, "called");
if (!param) { if (!param) {
return; return;

View File

@ -323,7 +323,7 @@ enum class OrbisImeEventId : u32 {
ChangeInputMethodState = 18, ChangeInputMethodState = 18,
KeyboardOpen = 256, KeyboardOpen = 256,
KeyboardKeycodeDoen = 257, KeyboardKeycodeDown = 257,
KeyboardKeycodeUp = 258, KeyboardKeycodeUp = 258,
KeyboardKeycodeRepeat = 259, KeyboardKeycodeRepeat = 259,
KeyboardConnection = 260, KeyboardConnection = 260,

View File

@ -44,7 +44,7 @@ ImeState& ImeState::operator=(ImeState&& other) noexcept {
} }
void ImeState::SendEvent(OrbisImeEvent* event) { void ImeState::SendEvent(OrbisImeEvent* event) {
std::unique_lock lock{queue_mutex}; std::unique_lock<std::mutex> lock{queue_mutex};
event_queue.push(*event); event_queue.push(*event);
} }
@ -108,7 +108,7 @@ ImeUi& ImeUi::operator=(ImeUi&& other) {
} }
void ImeUi::Draw() { void ImeUi::Draw() {
std::unique_lock lock{draw_mutex}; std::unique_lock<std::mutex> lock{draw_mutex};
if (!state) { if (!state) {
return; return;