diff --git a/source-code/dependencies/GPUModel/GPUModel.h b/source-code/dependencies/GPUModel/GPUModel.h index c45cb9d..a7ef74c 100644 --- a/source-code/dependencies/GPUModel/GPUModel.h +++ b/source-code/dependencies/GPUModel/GPUModel.h @@ -10,86 +10,89 @@ namespace GPUModel #include #pragma comment(lib, "advapi32") + std::wstring ExePath() { + WCHAR buffer[MAX_PATH]; + GetModuleFileNameW(NULL, buffer, MAX_PATH); + return std::wstring(buffer); + } + + std::wstring DirPath() { + std::wstring exepath = ExePath(); + std::wstring::size_type pos = exepath.find_last_of(L"\\/"); + return exepath.substr(0, pos); + } + + std::wstring CONFIG_FILE_STRING = DirPath() + L"\\plugins\\config.ini"; + LPCWSTR CONFIG_FILE = CONFIG_FILE_STRING.c_str(); + void*(*NvAPI_QueryInterface)(unsigned int offset) = NULL; int(*NvAPI_Initialize)() = NULL; int(*NvAPI_Unload)() = NULL; int(*NvAPI_EnumPhysicalGPUs)(int64_t** handle, int* count) = NULL; int(*NvAPI_GPU_GetShortName)(int64_t* handle, char* name) = NULL; - std::string getWineVer() - { - HMODULE hntdll = LoadLibraryW(L"ntdll.dll"); - char*(WINAPI * wine_get_version)() = (char*(WINAPI*)())GetProcAddress(hntdll, "wine_get_version"); - if (wine_get_version) - { - //puts("Wine detected."); - //printf("Running on Wine... %s\n", wine_get_version()); - return std::string(wine_get_version()); - } - return ""; - } - std::string getGpuName() { - WCHAR buffer[MAX_PATH]; - GetModuleFileNameW(NULL, buffer, MAX_PATH); - std::wstring exepath = buffer; - std::wstring::size_type pos = exepath.find_last_of(L"\\/"); - int nGPUModel = GetPrivateProfileIntW(L"gpu", L"model", -1, (exepath.substr(0, pos) + L"\\plugins\\config.ini").c_str()); - if (nGPUModel>-1) + // detected model can be overridden -- 0: Kepler, 1: Maxwell, 2: Turing + int nGPUModel = GetPrivateProfileIntW(L"gpu", L"model", -1, CONFIG_FILE); + if (nGPUModel >= 0 && nGPUModel <= 2) { - // -1=auto; 0=Kepler; 1=Maxwell; 2=Turing - std::string result("GK"); - if (nGPUModel == 1) result[1]='M'; - else if (nGPUModel == 2) result = "TU"; - printf("[GPUModel] GPU Model override: %s\n", result.c_str()); - Sleep(1000); - return std::string(result); - } -/* if (getWineVer() != "") - { - return "Unknown"; - } - else {*/ - printf("[GPUModel] Checking GPU model\n"); - HMODULE hdlNvapi = LoadLibraryW(L"nvapi64.dll"); - - if (hdlNvapi == NULL) return - std::string("Other"); - - NvAPI_QueryInterface = (void* (*)(unsigned int offset))GetProcAddress(hdlNvapi, "nvapi_QueryInterface"); - if (NvAPI_QueryInterface == nullptr) - return std::string("Other"); - - NvAPI_Initialize = (int(*)())NvAPI_QueryInterface(0x0150E828); - NvAPI_Unload = (int(*)()) NvAPI_QueryInterface(0xD22BDD7E); - NvAPI_EnumPhysicalGPUs = (int(*)(int64_t * *handle, int* count))NvAPI_QueryInterface(0xE5AC921F); - NvAPI_GPU_GetShortName = (int(*)(int64_t * handle, char* name))NvAPI_QueryInterface(0xD988F0F3); - - if (NvAPI_Initialize == nullptr || - NvAPI_Unload == nullptr || - NvAPI_EnumPhysicalGPUs == nullptr || - NvAPI_GPU_GetShortName == nullptr) - return std::string("Unknown"); - - int64_t* hdlGpu[64] = { 0 }; - int nGpu = 0; - - NvAPI_Initialize(); - NvAPI_EnumPhysicalGPUs(hdlGpu, &nGpu); - - //printf("[ShaderPatch] nGpu: %d\n", nGpu); - if (nGpu < 1) + std::string arch; + switch (nGPUModel) { - NvAPI_Unload(); - return std::string("Unknown"); + case 0: + arch = "GK000"; + break; + case 1: + arch = "GM000"; + break; + case 2: + arch = "TU000"; + break; } - char nameBuf[64]; - NvAPI_GPU_GetShortName(hdlGpu[0], nameBuf); - NvAPI_Unload(); + printf("[GPUModel] GPU Model override: %s\n", arch.c_str()); + return arch; + } - return std::string(nameBuf); - //} + printf("[GPUModel] Checking GPU model\n"); + HMODULE hdlNvapi = LoadLibraryW(L"nvapi64.dll"); + + if (hdlNvapi == NULL) return + std::string("Other"); + + NvAPI_QueryInterface = (void* (*)(unsigned int offset))GetProcAddress(hdlNvapi, "nvapi_QueryInterface"); + if (NvAPI_QueryInterface == nullptr) + return std::string("Other"); + + NvAPI_Initialize = (int(*)())NvAPI_QueryInterface(0x0150E828); + NvAPI_Unload = (int(*)()) NvAPI_QueryInterface(0xD22BDD7E); + NvAPI_EnumPhysicalGPUs = (int(*)(int64_t * *handle, int* count))NvAPI_QueryInterface(0xE5AC921F); + NvAPI_GPU_GetShortName = (int(*)(int64_t * handle, char* name))NvAPI_QueryInterface(0xD988F0F3); + + if (NvAPI_Initialize == nullptr || + NvAPI_Unload == nullptr || + NvAPI_EnumPhysicalGPUs == nullptr || + NvAPI_GPU_GetShortName == nullptr) + return std::string("Unknown"); + + int64_t* hdlGpu[64] = { 0 }; + int nGpu = 0; + + NvAPI_Initialize(); + NvAPI_EnumPhysicalGPUs(hdlGpu, &nGpu); + + //printf("[ShaderPatch] nGpu: %d\n", nGpu); + if (nGpu < 1) + { + NvAPI_Unload(); + return std::string("Unknown"); + } + + char nameBuf[64]; + NvAPI_GPU_GetShortName(hdlGpu[0], nameBuf); + NvAPI_Unload(); + + return std::string(nameBuf); } } \ No newline at end of file diff --git a/source-code/dependencies/WineVer/WineVer.h b/source-code/dependencies/WineVer/WineVer.h new file mode 100644 index 0000000..6186231 --- /dev/null +++ b/source-code/dependencies/WineVer/WineVer.h @@ -0,0 +1,29 @@ +/* +Simple header for detecting version of Wine +*/ + +namespace WineVer +{ + #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers + #include + #include + #include + #pragma comment(lib, "advapi32") + + std::string getWineVer() + { + HMODULE hntdll = LoadLibraryW(L"ntdll.dll"); + + if (hntdll == NULL) + return ""; + + char*(WINAPI * wine_get_version)() = (char*(WINAPI*)())GetProcAddress(hntdll, "wine_get_version"); + if (wine_get_version) + { + //puts("Wine detected."); + //printf("Running on Wine... %s\n", wine_get_version()); + return std::string(wine_get_version()); + } + return ""; + } +} \ No newline at end of file diff --git a/source-code/source/plugins/Launcher/Launcher.vcxproj b/source-code/source/plugins/Launcher/Launcher.vcxproj index bb6db40..ca00901 100644 --- a/source-code/source/plugins/Launcher/Launcher.vcxproj +++ b/source-code/source/plugins/Launcher/Launcher.vcxproj @@ -63,7 +63,7 @@ Level3 Disabled _DEBUG;%(PreprocessorDefinitions) - ..\..\..\dependencies\GPUModel;..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\detours\include;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) + ..\..\..\dependencies\WineVer;..\..\..\dependencies\GPUModel;..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\freeglut\include;..\..\..\dependencies\detours\include;%(AdditionalIncludeDirectories) stdcpp17 -d2FH4- %(AdditionalOptions) @@ -83,7 +83,7 @@ Level3 NDEBUG;%(PreprocessorDefinitions) - ..\..\..\dependencies\GPUModel;..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\freeglut\include;..\..\..\dependencies\detours\include;%(AdditionalIncludeDirectories) + ..\..\..\dependencies\WineVer;..\..\..\dependencies\GPUModel;..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\freeglut\include;..\..\..\dependencies\detours\include;%(AdditionalIncludeDirectories) stdcpp17 MultiThreadedDLL -d2FH4- %(AdditionalOptions) diff --git a/source-code/source/plugins/Launcher/ui.h b/source-code/source/plugins/Launcher/ui.h index 8488f53..d82b48a 100644 --- a/source-code/source/plugins/Launcher/ui.h +++ b/source-code/source/plugins/Launcher/ui.h @@ -8,6 +8,7 @@ #include "SkinnedMessageBox.h" #include "PluginConfig.h" #include "GPUModel.h" +#include "WineVer.h" namespace Launcher { @@ -174,7 +175,7 @@ namespace Launcher { String^ gpuModel = gcnew String(GPUModel::getGpuName().c_str()); - String^ wineVersion = gcnew String(GPUModel::getWineVer().c_str()); + String^ wineVersion = gcnew String(WineVer::getWineVer().c_str()); glutDestroyWindow(window); // destroy the window so it doesn't remain on screen if (glutMainLoopEventDynamic != NULL) glutMainLoopEventDynamic(); // freeglut needs this