From a84ea357ec34b62d8355d78a6671e3e6d9241250 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sun, 13 Jan 2019 03:40:00 -0500 Subject: [PATCH] give up on emulating non jp locale and launching in correct directory --- GUI/mainwindow.cpp | 54 +++++++++++++++++++++++----------------------- include/text.h | 1 + 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 8c54689..3171e2e 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -203,10 +204,9 @@ void MainWindow::AttachProcess() QStringList processList(allProcesses.uniqueKeys()); processList.sort(Qt::CaseInsensitive); - QString process = QInputDialog::getItem(this, SELECT_PROCESS, ATTACH_INFO, processList, 0, true, &ok, Qt::WindowCloseButtonHint); - if (!ok) return; - if (process.toInt(nullptr, 0)) Host::InjectProcess(process.toInt(nullptr, 0)); - else for (auto processId : allProcesses.values(process)) Host::InjectProcess(processId); + if (QString process = QInputDialog::getItem(this, SELECT_PROCESS, ATTACH_INFO, processList, 0, true, &ok, Qt::WindowCloseButtonHint); ok) + if (process.toInt(nullptr, 0)) Host::InjectProcess(process.toInt(nullptr, 0)); + else for (auto processId : allProcesses.values(process)) Host::InjectProcess(processId); } void MainWindow::LaunchProcess() @@ -219,30 +219,31 @@ void MainWindow::LaunchProcess() if (!ok) return; if (S(process) == SEARCH_GAME) process = S(QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, SELECT_PROCESS, "C:\\", PROCESSES))); if (process.empty()) return; - std::wstring path = std::wstring(process).erase(process.rfind(L'\\')); + PROCESS_INFORMATION info = {}; - if (HMODULE localeEmulator = LoadLibraryOnce(L"LoaderDll")) - { - // see https://github.com/xupefei/Locale-Emulator/blob/aa99dec3b25708e676c90acf5fed9beaac319160/LEProc/LoaderWrapper.cs#L252 - struct + if (QMessageBox::question(this, SELECT_PROCESS, USE_JP_LOCALE) == QMessageBox::Yes) + if (HMODULE localeEmulator = LoadLibraryOnce(L"LoaderDll")) { - ULONG AnsiCodePage = Host::defaultCodepage; - ULONG OemCodePage = Host::defaultCodepage; - ULONG LocaleID = LANG_JAPANESE; - ULONG DefaultCharset = DEFAULT_CHARSET; - ULONG HookUiLanguageApi = FALSE; - WCHAR DefaultFaceName[LF_FACESIZE] = {}; - TIME_ZONE_INFORMATION Timezone; - ULONG64 Unused = 0; - } LEB; - GetTimeZoneInformation(&LEB.Timezone); - ((LONG(__stdcall*)(decltype(&LEB), LPCWSTR appName, LPWSTR commandLine, LPCWSTR currentDir, void*, void*, PROCESS_INFORMATION*, void*, void*, void*, void*)) - GetProcAddress(localeEmulator, "LeCreateProcess"))(&LEB, process.c_str(), NULL, path.c_str(), NULL, NULL, &info, NULL, NULL, NULL, NULL); - } + // see https://github.com/xupefei/Locale-Emulator/blob/aa99dec3b25708e676c90acf5fed9beaac319160/LEProc/LoaderWrapper.cs#L252 + struct + { + ULONG AnsiCodePage = SHIFT_JIS; + ULONG OemCodePage = SHIFT_JIS; + ULONG LocaleID = LANG_JAPANESE; + ULONG DefaultCharset = SHIFTJIS_CHARSET; + ULONG HookUiLanguageApi = FALSE; + WCHAR DefaultFaceName[LF_FACESIZE] = {}; + TIME_ZONE_INFORMATION Timezone; + ULONG64 Unused = 0; + } LEB; + GetTimeZoneInformation(&LEB.Timezone); + ((LONG(__stdcall*)(decltype(&LEB), LPCWSTR appName, LPWSTR commandLine, LPCWSTR currentDir, void*, void*, PROCESS_INFORMATION*, void*, void*, void*, void*)) + GetProcAddress(localeEmulator, "LeCreateProcess"))(&LEB, process.c_str(), NULL, NULL, NULL, NULL, &info, NULL, NULL, NULL, NULL); + } if (info.hProcess == NULL) { STARTUPINFOW DUMMY = { sizeof(DUMMY) }; - CreateProcessW(process.c_str(), NULL, nullptr, nullptr, FALSE, 0, nullptr, path.c_str(), &DUMMY, &info); + CreateProcessW(process.c_str(), NULL, nullptr, nullptr, FALSE, 0, nullptr, NULL, &DUMMY, &info); } if (info.hProcess == NULL) return Host::AddConsoleOutput(LAUNCH_FAILED); Host::InjectProcess(info.dwProcessId); @@ -257,10 +258,9 @@ void MainWindow::DetachProcess() void MainWindow::AddHook() { - QString hookCode = QInputDialog::getText(this, ADD_HOOK, CODE_INFODUMP, QLineEdit::Normal, "", &ok, Qt::WindowCloseButtonHint); - if (!ok) return; - if (auto hp = ParseCode(hookCode)) Host::InsertHook(GetSelectedProcessId(), hp.value()); - else Host::AddConsoleOutput(INVALID_CODE); + if (QString hookCode = QInputDialog::getText(this, ADD_HOOK, CODE_INFODUMP, QLineEdit::Normal, "", &ok, Qt::WindowCloseButtonHint); ok) + if (auto hp = ParseCode(hookCode)) Host::InsertHook(GetSelectedProcessId(), hp.value()); + else Host::AddConsoleOutput(INVALID_CODE); } void MainWindow::SaveHooks() diff --git a/include/text.h b/include/text.h index 0fe95cb..8792c23 100644 --- a/include/text.h +++ b/include/text.h @@ -37,6 +37,7 @@ constexpr auto EXTEN_WINDOW_INSTRUCTIONS = u8R"(Drag and drop extension (.dll) f Drag and drop within the list to reorder Press delete with an extension selected to remove it)"; constexpr auto WINDOW = u8"Window"; +constexpr auto USE_JP_LOCALE = u8"Emulate japanese locale?"; constexpr auto DEFAULT_CODEPAGE = u8"Default Codepage"; constexpr auto FLUSH_DELAY = u8"Flush Delay"; constexpr auto MAX_BUFFER_SIZE = u8"Max Buffer Size";