diff --git a/DDrawCompat/Config/Config.cpp b/DDrawCompat/Config/Config.cpp index 48c2943..c0ddc91 100644 --- a/DDrawCompat/Config/Config.cpp +++ b/DDrawCompat/Config/Config.cpp @@ -23,4 +23,5 @@ namespace Config Settings::TextureFilter textureFilter; Settings::ThreadPriorityBoost threadPriorityBoost; Settings::VSync vSync; + Settings::WinVersionLie winVersionLie; } diff --git a/DDrawCompat/Config/Config.h b/DDrawCompat/Config/Config.h index a29e4ef..cd58a71 100644 --- a/DDrawCompat/Config/Config.h +++ b/DDrawCompat/Config/Config.h @@ -21,6 +21,7 @@ #include #include #include +#include namespace Config { @@ -45,4 +46,5 @@ namespace Config extern Settings::TextureFilter textureFilter; extern Settings::ThreadPriorityBoost threadPriorityBoost; extern Settings::VSync vSync; + extern Settings::WinVersionLie winVersionLie; } diff --git a/DDrawCompat/Config/Settings/WinVersionLie.cpp b/DDrawCompat/Config/Settings/WinVersionLie.cpp new file mode 100644 index 0000000..eaac0c8 --- /dev/null +++ b/DDrawCompat/Config/Settings/WinVersionLie.cpp @@ -0,0 +1,35 @@ +#include + +namespace Config +{ + namespace Settings + { + bool VersionInfo::operator==(const VersionInfo& other) const + { + return version == other.version && + build == other.build && + platform == other.platform; + } + + WinVersionLie::WinVersionLie() + : MappedSetting("WinVersionLie", "off", { + {"off", {}}, + {"95", {0xC3B60004, 0x3B6, 1}}, + {"nt4", {0x5650004, 0x565, 2}}, + {"98", {0xC0000A04, 0x40A08AE, 1}}, + {"2000", {0x8930005, 0x893, 2}}, + {"xp", {0xA280105, 0xA28, 2}} + }) + { + } + + Setting::ParamInfo WinVersionLie::getParamInfo() const + { + if (0 != m_value.version) + { + return { "SP", 0, 5, 0, m_param }; + } + return {}; + } + } +} diff --git a/DDrawCompat/Config/Settings/WinVersionLie.h b/DDrawCompat/Config/Settings/WinVersionLie.h new file mode 100644 index 0000000..85fe8b3 --- /dev/null +++ b/DDrawCompat/Config/Settings/WinVersionLie.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +namespace Config +{ + namespace Settings + { + struct VersionInfo + { + DWORD version; + DWORD build; + DWORD platform; + + bool operator==(const VersionInfo& other) const; + }; + + class WinVersionLie : public MappedSetting + { + public: + WinVersionLie(); + + virtual ParamInfo getParamInfo() const override; + }; + } +} diff --git a/DDrawCompat/DDrawCompat.vcxproj b/DDrawCompat/DDrawCompat.vcxproj index 157b539..de884f0 100644 --- a/DDrawCompat/DDrawCompat.vcxproj +++ b/DDrawCompat/DDrawCompat.vcxproj @@ -238,6 +238,7 @@ + @@ -342,6 +343,7 @@ + @@ -366,6 +368,7 @@ + @@ -450,6 +453,7 @@ + diff --git a/DDrawCompat/DDrawCompat.vcxproj.filters b/DDrawCompat/DDrawCompat.vcxproj.filters index 2103f1b..1bc12cf 100644 --- a/DDrawCompat/DDrawCompat.vcxproj.filters +++ b/DDrawCompat/DDrawCompat.vcxproj.filters @@ -555,6 +555,12 @@ Header Files\Config\Settings + + Header Files\Config\Settings + + + Header Files\Win32 + @@ -875,6 +881,12 @@ Source Files\DDraw\Surfaces + + Source Files\Config\Settings + + + Source Files\Win32 + diff --git a/DDrawCompat/Dll/DllMain.cpp b/DDrawCompat/Dll/DllMain.cpp index 67cfd9a..2b4376f 100644 --- a/DDrawCompat/Dll/DllMain.cpp +++ b/DDrawCompat/Dll/DllMain.cpp @@ -25,6 +25,7 @@ #include #include #include +#include HRESULT WINAPI SetAppCompatData(DWORD, DWORD); @@ -231,6 +232,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) Input::installHooks(); Win32::MemoryManagement::installHooks(); Win32::Thread::installHooks(); + Win32::Version::installHooks(); Compat::closeDbgEng(); timeBeginPeriod(1); diff --git a/DDrawCompat/Win32/Log.cpp b/DDrawCompat/Win32/Log.cpp index 2b27a50..c1299cb 100644 --- a/DDrawCompat/Win32/Log.cpp +++ b/DDrawCompat/Win32/Log.cpp @@ -71,6 +71,31 @@ namespace << Compat::hex(mcs.style) << Compat::hex(mcs.lParam); } + + template + std::ostream& logOsVersionInfoEx(std::ostream& os, const OsVersionInfoEx& vi) + { + return Compat::LogStruct(os) + << vi.dwOSVersionInfoSize + << vi.dwMajorVersion + << vi.dwMinorVersion + << vi.dwBuildNumber + << vi.dwPlatformId + << Compat::out(vi.szCSDVersion) + << vi.wServicePackMajor + << vi.wServicePackMinor + << Compat::hex(vi.wSuiteMask) + << static_cast(vi.wProductType) + << static_cast(vi.wReserved); + } + + template + std::ostream& logOsVersionInfo(std::ostream& os, const OsVersionInfo& vi) + { + OsVersionInfoEx viEx = {}; + memcpy(&viEx, &vi, min(sizeof(viEx), vi.dwOSVersionInfoSize)); + return logOsVersionInfoEx(os, viEx); + } } std::ostream& operator<<(std::ostream& os, const COMPAREITEMSTRUCT& cis) @@ -349,6 +374,26 @@ std::ostream& operator<<(std::ostream& os, const NMHDR& nm) << Compat::hex(nm.code); } +std::ostream& operator<<(std::ostream& os, const OSVERSIONINFOA& vi) +{ + return logOsVersionInfo(os, vi); +} + +std::ostream& operator<<(std::ostream& os, const OSVERSIONINFOW& vi) +{ + return logOsVersionInfo(os, vi); +} + +std::ostream& operator<<(std::ostream& os, const OSVERSIONINFOEXA& vi) +{ + return logOsVersionInfoEx(os, vi); +} + +std::ostream& operator<<(std::ostream& os, const OSVERSIONINFOEXW& vi) +{ + return logOsVersionInfoEx(os, vi); +} + std::ostream& operator<<(std::ostream& os, const POINT& p) { return Compat::LogStruct(os) diff --git a/DDrawCompat/Win32/Log.h b/DDrawCompat/Win32/Log.h index 0f2b9ec..177c00d 100644 --- a/DDrawCompat/Win32/Log.h +++ b/DDrawCompat/Win32/Log.h @@ -31,6 +31,10 @@ std::ostream& operator<<(std::ostream& os, const MINMAXINFO& mmi); std::ostream& operator<<(std::ostream& os, const MSG& msg); std::ostream& operator<<(std::ostream& os, const NCCALCSIZE_PARAMS& nccs); std::ostream& operator<<(std::ostream& os, const NMHDR& nm); +std::ostream& operator<<(std::ostream& os, const OSVERSIONINFOA& vi); +std::ostream& operator<<(std::ostream& os, const OSVERSIONINFOW& vi); +std::ostream& operator<<(std::ostream& os, const OSVERSIONINFOEXA& vi); +std::ostream& operator<<(std::ostream& os, const OSVERSIONINFOEXW& vi); std::ostream& operator<<(std::ostream& os, const POINT& p); std::ostream& operator<<(std::ostream& os, const POINTS& p); std::ostream& operator<<(std::ostream& os, const RECT& rect); diff --git a/DDrawCompat/Win32/Version.cpp b/DDrawCompat/Win32/Version.cpp new file mode 100644 index 0000000..13c918d --- /dev/null +++ b/DDrawCompat/Win32/Version.cpp @@ -0,0 +1,80 @@ +#include + +#include +#include +#include + +#include + +#pragma warning(disable : 4996) + +namespace +{ + DWORD WINAPI getVersion() + { + LOG_FUNC("GetVersion"); + auto vi = Config::winVersionLie.get(); + if (0 != vi.version) + { + return LOG_RESULT(vi.version); + } + return LOG_RESULT(CALL_ORIG_FUNC(GetVersion)()); + } + + template + BOOL getVersionInfo(OsVersionInfo* osVersionInfo, BOOL(WINAPI* origGetVersionInfo)(OsVersionInfo*), + [[maybe_unused]] const char* funcName) + { + LOG_FUNC(funcName, osVersionInfo); + BOOL result = origGetVersionInfo(osVersionInfo); + auto vi = Config::winVersionLie.get(); + if (result && 0 != vi.version) + { + osVersionInfo->dwMajorVersion = vi.version & 0xFF; + osVersionInfo->dwMinorVersion = (vi.version & 0xFF00) >> 8; + osVersionInfo->dwBuildNumber = vi.build; + osVersionInfo->dwPlatformId = vi.platform; + + auto sp = Config::winVersionLie.getParam(); + if (0 != sp) + { + typedef std::remove_reference_tszCSDVersion[0])> Char; + std::basic_ostringstream oss; + oss << "Service Pack " << sp; + memset(osVersionInfo->szCSDVersion, 0, sizeof(osVersionInfo->szCSDVersion)); + memcpy(osVersionInfo->szCSDVersion, oss.str().c_str(), oss.str().length() * sizeof(Char)); + + if (osVersionInfo->dwOSVersionInfoSize >= sizeof(OsVersionInfoEx)) + { + auto osVersionInfoEx = reinterpret_cast(osVersionInfo); + osVersionInfoEx->wServicePackMajor = static_cast(sp); + osVersionInfoEx->wServicePackMinor = 0; + } + } + } + return result; + } + + BOOL WINAPI getVersionExA(LPOSVERSIONINFOA lpVersionInformation) + { + return getVersionInfo(lpVersionInformation, CALL_ORIG_FUNC(GetVersionExA), "GetVersionExA"); + } + + BOOL WINAPI getVersionExW(LPOSVERSIONINFOW lpVersionInformation) + { + return getVersionInfo(lpVersionInformation, CALL_ORIG_FUNC(GetVersionExW), "GetVersionExW"); + } +} + +namespace Win32 +{ + namespace Version + { + void installHooks() + { + HOOK_FUNCTION(kernel32, GetVersion, getVersion); + HOOK_FUNCTION(kernel32, GetVersionExA, getVersionExA); + HOOK_FUNCTION(kernel32, GetVersionExW, getVersionExW); + } + } +} diff --git a/DDrawCompat/Win32/Version.h b/DDrawCompat/Win32/Version.h new file mode 100644 index 0000000..a93c61f --- /dev/null +++ b/DDrawCompat/Win32/Version.h @@ -0,0 +1,9 @@ +#pragma once + +namespace Win32 +{ + namespace Version + { + void installHooks(); + } +}