Merge pull request #24 from ryumiyax/Refactor

[Experimental] auto_ime enhanced | graphic enhanced | build without requirement of msvcp140.dll
This commit is contained in:
RyuMiyaX
2025-01-13 19:08:47 +08:00
committed by GitHub
21 changed files with 501 additions and 457 deletions
+76 -7
View File
@@ -24,13 +24,17 @@ char accessCode2[21] = "00000000000000000002";
char chipId1[33] = "00000000000000000000000000000001";
char chipId2[33] = "00000000000000000000000000000002";
bool windowed = false;
bool autoIme = false;
bool autoIme = true;
bool jpLayout = false;
bool cursor = true;
bool emulateUsio = true;
bool emulateCardReader = true;
bool emulateQr = true;
bool acceptInvalidCards = false;
HKL currentLayout = nullptr;
i32 xRes = 1920;
i32 yRes = 1080;
bool vsync = false;
std::string logLevelStr = "INFO";
bool logToFile = true;
@@ -39,6 +43,22 @@ std::string logPath = "TaikoArcadeLoader.log";
HWND hGameWnd;
FAST_HOOK (i32, ShowMouse, PROC_ADDRESS ("user32.dll", "ShowCursor"), bool) { return originalShowMouse.stdcall<i32> (true); }
FAST_HOOK (i32, ExitWindows, PROC_ADDRESS ("user32.dll", "ExitWindowsEx")) { ExitProcess (0); }
// FAST_HOOK (ATOM, HookRegisterClassA, PROC_ADDRESS ("winuser.h", "RegisterClassA"), WNDCLASSA *lpWndClass) {
// LogMessage (LogLevel::DEBUG, "RegisterClassA name={}", lpWndClass->lpszClassName);
// return originalHookRegisterClassA.call<ATOM> (lpWndClass);
// }
// FAST_HOOK (ATOM, HookRegisterClassW, PROC_ADDRESS ("winuser.h", "RegisterClassW"), WNDCLASSW *lpWndClass) {
// LogMessage (LogLevel::DEBUG, L"RegisterClassW name={}", lpWndClass->lpszClassName);
// return originalHookRegisterClassW.call<ATOM> (lpWndClass);
// }
// FAST_HOOK (ATOM, HookRegisterClassExA, PROC_ADDRESS ("winuser.h", "RegisterClassExA"), WNDCLASSEXA *lpWndClass) {
// LogMessage (LogLevel::DEBUG, "RegisterClassExA name={}", lpWndClass->lpszClassName);
// return originalHookRegisterClassExA.call<ATOM> (lpWndClass);
// }
// FAST_HOOK (ATOM, HookRegisterClassExW, PROC_ADDRESS ("winuser.h", "RegisterClassExW"), WNDCLASSEXW *lpWndClass) {
// LogMessage (LogLevel::DEBUG, L"RegisterClassExW name={}", lpWndClass->lpszClassName);
// return originalHookRegisterClassExW.call<ATOM> (lpWndClass);
// }
FAST_HOOK (HWND, CreateWindow, PROC_ADDRESS ("user32.dll", "CreateWindowExW"), DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle,
i32 X, i32 Y, i32 nWidth, i32 nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) {
if (lpWindowName != nullptr) {
@@ -152,10 +172,6 @@ DllMain (HMODULE module, const DWORD reason, LPVOID reserved) {
InitializeLogger (GetLogLevel (logLevelStr), logToFile, logPath);
patches::Timer::Init ();
// #ifdef ASYNC_IO
// InitializeKeyboard ();
// #endif
LogMessage (LogLevel::INFO, "Loading config...");
std::string version = "auto";
@@ -190,6 +206,11 @@ DllMain (HMODULE module, const DWORD reason, LPVOID reserved) {
if (const auto graphics = openConfigSection (config, "graphics")) {
windowed = readConfigBool (graphics, "windowed", windowed);
cursor = readConfigBool (graphics, "cursor", cursor);
if (auto res = openConfigSection (graphics, "res")) {
xRes = static_cast<i32> (readConfigInt (res, "x", xRes));
yRes = static_cast<i32> (readConfigInt (res, "y", yRes));
}
vsync = readConfigBool (graphics, "vsync", vsync);
}
if (const auto keyboard = openConfigSection (config, "keyboard")) {
autoIme = readConfigBool (keyboard, "auto_ime", autoIme);
@@ -203,6 +224,49 @@ DllMain (HMODULE module, const DWORD reason, LPVOID reserved) {
}
}
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE);
auto activeWindow = GetActiveWindow();
HMONITOR monitor = MonitorFromWindow(activeWindow, MONITOR_DEFAULTTONEAREST);
// Get the logical width and height of the monitor
MONITORINFOEX monitorInfoEx;
monitorInfoEx.cbSize = sizeof(monitorInfoEx);
GetMonitorInfo(monitor, &monitorInfoEx);
auto cxLogical = monitorInfoEx.rcMonitor.right - monitorInfoEx.rcMonitor.left;
auto cyLogical = monitorInfoEx.rcMonitor.bottom - monitorInfoEx.rcMonitor.top;
// Get the physical width and height of the monitor
DEVMODE devMode;
devMode.dmSize = sizeof(devMode);
devMode.dmDriverExtra = 0;
EnumDisplaySettings(monitorInfoEx.szDevice, ENUM_CURRENT_SETTINGS, &devMode);
auto cxPhysical = devMode.dmPelsWidth;
auto cyPhysical = devMode.dmPelsHeight;
// Calculate the scaling factor
auto horizontalScale = (static_cast<double> (cxPhysical) / static_cast<double> (cxLogical));
auto verticalScale = (static_cast<double> (cyPhysical) / static_cast<double> (cyLogical));
if (windowed) {
// Game will automatically adjust scale
xRes = (int)(xRes / horizontalScale);
yRes = (int)(yRes / verticalScale);
} else {
xRes = cxLogical;
yRes = cyLogical;
if (yRes * 16 > xRes * 9) yRes = (int)(xRes * 9.0 / 16.0);
else if (yRes * 16 < xRes * 9) xRes = (int)(yRes * 16.0 / 9.0);
}
LogMessage (LogLevel::INFO, "Scale Rate: x={} y={}", horizontalScale, verticalScale);
LogMessage (LogLevel::INFO, "Boot with {} mode ({}x{})", windowed ? "window" : "fullscreen", xRes, yRes);
if (autoIme) {
currentLayout = GetKeyboardLayout (0);
auto engLayout = LoadKeyboardLayout (TEXT ("00000409"), KLF_ACTIVATE);
ActivateKeyboardLayout (engLayout, KLF_SETFORPROCESS);
LogMessage (LogLevel::DEBUG, "Initial change KeyboardLayout {}", LOWORD(engLayout));
}
// Update the logger with the level read from config file.
InitializeLogger (GetLogLevel (logLevelStr), logToFile, logPath);
LogMessage (LogLevel::INFO, "Application started.");
@@ -235,9 +299,13 @@ DllMain (HMODULE module, const DWORD reason, LPVOID reserved) {
LogMessage (LogLevel::INFO, "==== Loading patches, please wait...");
if (cursor) INSTALL_FAST_HOOK (ShowMouse);
if (windowed && cursor) INSTALL_FAST_HOOK (ShowMouse);
INSTALL_FAST_HOOK (ExitWindows);
INSTALL_FAST_HOOK (CreateWindow);
// INSTALL_FAST_HOOK (HookRegisterClassA);
// INSTALL_FAST_HOOK (HookRegisterClassW);
// INSTALL_FAST_HOOK (HookRegisterClassExA);
// INSTALL_FAST_HOOK (HookRegisterClassExW);
INSTALL_FAST_HOOK (SetWindowPosition);
INSTALL_FAST_HOOK (ExitProcessHook);
@@ -266,11 +334,12 @@ DllMain (HMODULE module, const DWORD reason, LPVOID reserved) {
patches::Scanner::Init ();
patches::Audio::Init ();
patches::Dxgi::Init ();
// patches::Dxgi::Init ();
patches::AmAuth::Init ();
patches::Language::Init ();
patches::TestMode::Init ();
patches::LayeredFs::Init ();
// patches::UnlimitSong::Init ();
std::chrono::duration<double> duration = std::chrono::high_resolution_clock::now() - start;
LogMessage (LogLevel::INFO, "==== Finished Loading patches! using: {:.2f}ms", duration.count () * 1000);