diff --git a/src/spice2x/.gitignore b/src/spice2x/.gitignore index fa14a9b..5f29de8 100644 --- a/src/spice2x/.gitignore +++ b/src/spice2x/.gitignore @@ -18,4 +18,9 @@ dist/* external/cv2pdb/* -.ccache/* \ No newline at end of file +.ccache/* + +# Visual Studio +.vs +out +CMakeSettings.json diff --git a/src/spice2x/games/pc/pc.cpp b/src/spice2x/games/pc/pc.cpp index 405bf2a..23b2716 100644 --- a/src/spice2x/games/pc/pc.cpp +++ b/src/spice2x/games/pc/pc.cpp @@ -21,6 +21,8 @@ namespace games::pc { static std::wstring portName = L"COM1"; static decltype(RegisterRawInputDevices) *RegisterRawInputDevices_orig = nullptr; + static decltype(EnumDisplaySettingsW) *EnumDisplaySettingsW_orig = nullptr; + static decltype(QueryDisplayConfig) *QueryDisplayConfig_orig = nullptr; static BOOL WINAPI RegisterRawInputDevices_hook(PCRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize) { @@ -38,6 +40,27 @@ namespace games::pc { return FALSE; } + static BOOL WINAPI EnumDisplaySettingsW_hook(LPCWSTR lpszDeviceName, DWORD iModeNum, DEVMODEW* lpDevMode) { + auto result = EnumDisplaySettingsW_orig(lpszDeviceName, iModeNum, lpDevMode); + + // https://docs.unity3d.com/2022.3/Documentation/ScriptReference/Screen-currentResolution.html + // "If the player is running in windowed mode, this returns the current dimensions of the game window in pixels and the display refresh rate." + // Override it to 1920x1080 to avoid broken UI under Windowed mode + if (result && iModeNum == ENUM_CURRENT_SETTINGS) { + // Actually make it returns size of the game window, Can I? + lpDevMode->dmPelsWidth = 1920; + lpDevMode->dmPelsHeight = 1080; + } + + return result; + } + + LONG WINAPI QueryDisplayConfig_hook(UINT32, UINT32*, DISPLAYCONFIG_PATH_INFO*, UINT32*, DISPLAYCONFIG_MODE_INFO*, DISPLAYCONFIG_TOPOLOGY_ID*) { + // make unity fallback to EnumDisplaySettingsW as I don't + // want to deal with this api which is way more complex + return ERROR_NOT_SUPPORTED; + } + void PCGame::attach() { Game::attach(); @@ -63,7 +86,10 @@ namespace games::pc { const auto user32Dll = "user32.dll"; detour::trampoline_try(user32Dll, "RegisterRawInputDevices", RegisterRawInputDevices_hook, &RegisterRawInputDevices_orig); - + detour::trampoline_try(user32Dll, "QueryDisplayConfig", + QueryDisplayConfig_hook, &QueryDisplayConfig_orig); + detour::trampoline_try(user32Dll, "EnumDisplaySettingsW", + EnumDisplaySettingsW_hook, &EnumDisplaySettingsW_orig); if (GRAPHICS_SHOW_CURSOR) { unity_utils::force_show_cursor(true); diff --git a/src/spice2x/overlay/windows/patch_manager.cpp b/src/spice2x/overlay/windows/patch_manager.cpp index 091976c..0b8fc51 100644 --- a/src/spice2x/overlay/windows/patch_manager.cpp +++ b/src/spice2x/overlay/windows/patch_manager.cpp @@ -230,7 +230,13 @@ namespace overlay::windows { auto const register_fn = reinterpret_cast (GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "LdrRegisterDllNotification")); - auto callback = [] CALLBACK (ULONG reason, PCLDR_DLL_NOTIFICATION_DATA data, PVOID ctx) { + auto callback = +#ifdef _MSC_VER + static_cast([] +#else + [] CALLBACK +#endif + (ULONG reason, PCLDR_DLL_NOTIFICATION_DATA data, PVOID ctx) { if (reason == LDR_DLL_NOTIFICATION_REASON_LOADED) { auto const dll = strtolower(std::filesystem::path({ data->Loaded.FullDllName->Buffer, @@ -241,7 +247,11 @@ namespace overlay::windows { static_cast(ctx)->reload_local_patches(true); } } - }; + } +#ifdef _MSC_VER + ) +#endif + ; if (register_fn && NT_SUCCESS(register_fn(0, callback, this, &ldr_notify_cookie))) { log_info("patchmanager", "registered for DLL load notifications"); diff --git a/src/spice2x/util/peb.cpp b/src/spice2x/util/peb.cpp index 6fc3153..bcf7747 100644 --- a/src/spice2x/util/peb.cpp +++ b/src/spice2x/util/peb.cpp @@ -77,7 +77,7 @@ std::string peb::entry_name(const LDR_DATA_TABLE_ENTRY* entry) { } const PEB* peb::peb_get() { -#ifdef SPICE64 +#ifdef _WIN64 return reinterpret_cast(__readgsqword(0x60)); #else return reinterpret_cast(__readfsdword(0x30));