diff --git a/GlosSITarget/HidHide.cpp b/GlosSITarget/HidHide.cpp index a9697ba..ef31fac 100644 --- a/GlosSITarget/HidHide.cpp +++ b/GlosSITarget/HidHide.cpp @@ -186,8 +186,12 @@ void HidHide::UnPatchHook(const std::string& name, HMODULE module) if (!address) { spdlog::error("failed to unpatch \"{}\"", name); } - - auto bytes = ORIGINAL_BYTES.at(name); + std::string bytes; + if (Settings::isWin10 && ORIGINAL_BYTES_WIN10.contains(name)) { + bytes = ORIGINAL_BYTES_WIN10.at(name); + } else { + bytes = ORIGINAL_BYTES.at(name); + } DWORD dw_old_protect, dw_bkup; const auto len = bytes.size(); VirtualProtect(address, len, PAGE_EXECUTE_READWRITE, &dw_old_protect); // Change permissions of memory.. diff --git a/GlosSITarget/HidHide.h b/GlosSITarget/HidHide.h index 2e9ceb3..0f398bd 100644 --- a/GlosSITarget/HidHide.h +++ b/GlosSITarget/HidHide.h @@ -85,6 +85,11 @@ class HidHide { {"HidP_GetButtonCaps", "\x48\x83\xEC\x48\x49"}, }; + static inline const std::map ORIGINAL_BYTES_WIN10 = { + {"SetupDiEnumDeviceInfo", "\x40\x53\x56\x57\x41\x54\x41\x55"}, + {"SetupDiGetClassDevsW", "\x48\x8B\xC4\x48\x89\x58\x08"}, + }; + static inline const std::vector JUMP_INSTR_OPCODES = { 0xE9, 0xE8, diff --git a/GlosSITarget/Settings.h b/GlosSITarget/Settings.h index e341348..bac7034 100644 --- a/GlosSITarget/Settings.h +++ b/GlosSITarget/Settings.h @@ -23,6 +23,12 @@ limitations under the License. #include #include +#ifdef WIN32 +#define NOMINMAX +#include +#endif + + namespace Settings { inline struct Launch { @@ -56,6 +62,7 @@ inline bool extendedLogging = false; inline std::filesystem::path settings_path_ = ""; + inline bool checkIsUwp(const std::wstring& launch_path) { if (launch_path.find(L"://") != std::wstring::npos) { @@ -68,6 +75,45 @@ inline bool checkIsUwp(const std::wstring& launch_path) return false; } +#ifdef WIN32 +inline bool isWin10 = false; + + typedef LONG NTSTATUS, *PNTSTATUS; +#define STATUS_SUCCESS (0x00000000) + +typedef NTSTATUS(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); + +inline RTL_OSVERSIONINFOW GetRealOSVersion() +{ + HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll"); + if (hMod) { + RtlGetVersionPtr fxPtr = (RtlGetVersionPtr)::GetProcAddress(hMod, "RtlGetVersion"); + if (fxPtr != nullptr) { + RTL_OSVERSIONINFOW rovi = {0}; + rovi.dwOSVersionInfoSize = sizeof(rovi); + if (STATUS_SUCCESS == fxPtr(&rovi)) { + return rovi; + } + } + } + RTL_OSVERSIONINFOW rovi = {0}; + return rovi; +} + +inline void checkWinVer() +{ + auto VN = GetRealOSVersion(); + isWin10 = VN.dwBuildNumber < 22000; + + if (isWin10) { + spdlog::info("Running on Windows 10"); + } else { + spdlog::info("Running on Windows 11"); + } + +} +#endif + inline void Parse(std::wstring arg1) { if (!arg1.ends_with(L".json")) { diff --git a/GlosSITarget/main.cpp b/GlosSITarget/main.cpp index ec6ee4e..238c5d7 100644 --- a/GlosSITarget/main.cpp +++ b/GlosSITarget/main.cpp @@ -158,6 +158,7 @@ int main(int argc, char* argv[]) argsv += i == 1 ? args[i] : std::wstring(L" ") + args[i]; } Settings::Parse(argsv); + Settings::checkWinVer(); SteamTarget target; #else // Code below is broken now due to parse requiring std::wstring instead of std:string. Sorry. std::string argsv = "";