From 5641e06a19f30e2fa8a4a6593e2a83fd3c3797d8 Mon Sep 17 00:00:00 2001 From: bicarus-dev <202771338+bicarus-dev@users.noreply.github.com> Date: Mon, 10 Nov 2025 11:35:46 -0800 Subject: [PATCH] iidx: fix kana input broken in subscreen when system language is not Japanese (#421) ## Link to GitHub Issue, if one exists user-reported ## Description of change When the system non-Unicode language is not set to Japanese, TDJ subscreen katakana keyboard was broken (weird behavior with characters not erasing, ending with corrupt characters, etc) To fix this, add a hook for `IsDBCSLeadByte`. `IsDBCSLeadByte` assumes system ACP (which may not be SHIFT_JIS). Instead, redirect bm2dx.dll to use `IsDBCSLeadByteEx` instead with SHIFT_JIS explicitly specified as a parameter. Presumably the game was using IsDBCSLeadByte to manage the keyboard typing logic.... which is weird because SDVX doesn't do the same. ## Testing Tested iidx 31 and tried to do searches. --- src/spice2x/hooks/lang.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/spice2x/hooks/lang.cpp b/src/spice2x/hooks/lang.cpp index a247822..b10d36d 100644 --- a/src/spice2x/hooks/lang.cpp +++ b/src/spice2x/hooks/lang.cpp @@ -8,6 +8,7 @@ #include #include "avs/game.h" +#include "games/iidx/iidx.h" #include "util/detour.h" #include "util/logging.h" #include "util/utils.h" @@ -22,6 +23,7 @@ static decltype(GetLocaleInfoEx) *GetLocaleInfoEx_orig = nullptr; #ifdef SPICE64 static decltype(GetSystemDefaultLCID) *GetSystemDefaultLCID_orig = nullptr; +static decltype(IsDBCSLeadByte) *IsDBCSLeadByte_orig = nullptr; #endif static NTSTATUS NTAPI RtlMultiByteToUnicodeN_hook( @@ -162,6 +164,17 @@ static int WINAPI GetLocaleInfoEx_hook ( return GetLocaleInfoEx_orig(lpLocaleName, LCType, lpLCData, cchData); } +#ifdef SPICE64 + +static BOOL WINAPI IsDBCSLeadByte_hook ( + BYTE TestChar + ) +{ + return IsDBCSLeadByteEx(CODEPAGE_SHIFT_JIS, TestChar); +} + +#endif + void hooks::lang::early_init() { log_info("hooks::lang", "early initialization"); @@ -189,6 +202,19 @@ void hooks::lang::early_init() { GetLocaleInfoEx_hook, &GetLocaleInfoEx_orig); } + +#ifdef SPICE64 + // for TDJ subscreen search keyboard + if (avs::game::is_model("LDJ") && games::iidx::TDJ_MODE) { + log_info("hooks::lang", "hooking IsDBCSLeadByte"); + detour::trampoline_try( + "kernel32.dll", + "IsDBCSLeadByte", + IsDBCSLeadByte_hook, + &IsDBCSLeadByte_orig); + } +#endif + } void hooks::lang::init() {