forked from acceleration3/cloudgamestream
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed resolution getting stuck after playing games
- Loading branch information
1 parent
6ad2f80
commit 41066bd
Showing
13 changed files
with
215 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.vscode | ||
ResFix_src/nvapi/* | ||
!ResFix_src/nvapi/nvapi_info.txt | ||
ResFix_src/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ResFix.exe set-edid 0 0 edid.txt > log.txt |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
00 FF FF FF FF FF FF 00 3A C4 00 00 00 00 00 00 0F 19 01 04 A5 3E 22 64 06 92 B1 A3 54 4C 99 26 0F 50 54 00 00 00 95 00 81 00 D1 00 D1 C0 81 C0 B3 00 6C 40 00 00 4D D0 00 A0 F0 70 3E 80 30 20 35 00 6D 55 21 00 00 1A 39 1C 58 A0 50 00 16 30 30 20 3A 00 6D 55 21 00 00 1A 00 00 00 FD 00 1E 46 1E 8C 36 01 0A 20 20 20 20 20 20 00 00 00 FC 00 4E 56 49 44 49 41 20 56 47 58 20 0A 20 00 73 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") | ||
|
||
project(ResFix) | ||
|
||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | ||
|
||
find_package(NVAPI) | ||
|
||
if (NOT NVAPI_FOUND) | ||
message(FATAL_ERROR "NVAPI was not found. Read the file nvapi_info.txt inside the nvapi folder for more information.") | ||
endif() | ||
|
||
add_executable(ResFix main.cpp) | ||
target_include_directories(ResFix PRIVATE ${NVAPI_INCLUDE_DIR}) | ||
target_link_libraries(ResFix ${NVAPI_LIBRARY}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@echo off | ||
cmake --build build --config Release --target ResFix | ||
mv build/Release/ResFix.exe ../Bin/ResFix/ResFix.exe | ||
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@echo off | ||
rmdir /q /s build | ||
mkdir build | ||
cd build | ||
cmake -G "Visual Studio 16 2019" -A win32 .. | ||
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
set(NVAPI_FOUND 0) | ||
|
||
if(WIN32) | ||
find_path(NVAPI_INCLUDE_DIR | ||
NAMES nvapi.h | ||
PATHS ${CMAKE_SOURCE_DIR}/nvapi | ||
) | ||
|
||
if("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) | ||
message("Trying to find AMD64 NVAPI library...") | ||
set(NVAPI_ARCH_DIR amd64) | ||
set(NVAPI_LIBRARY_NAME nvapi64) | ||
else() | ||
message("Trying to find x86 NVAPI library...") | ||
set(NVAPI_ARCH_DIR x86) | ||
set(NVAPI_LIBRARY_NAME nvapi) | ||
endif() | ||
|
||
set(NVAPI_POSSIBLE_LIBRARY_PATHS | ||
${NVAPI_INCLUDE_DIR}/${NVAPI_ARCH_DIR} | ||
) | ||
|
||
find_library(NVAPI_LIBRARY | ||
NAMES ${NVAPI_LIBRARY_NAME} | ||
HINTS ${NVAPI_POSSIBLE_LIBRARY_PATHS} | ||
) | ||
|
||
message("NVAPI_INCLUDE_DIR: ${NVAPI_INCLUDE_DIR}") | ||
message("NVAPI_LIBRARY: ${NVAPI_LIBRARY}") | ||
|
||
if(NVAPI_INCLUDE_DIR AND NVAPI_LIBRARY) | ||
message("Found NVAPI.") | ||
set(NVAPI_FOUND 1) | ||
endif() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#include <windows.h> | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <string_view> | ||
#include <vector> | ||
#include <map> | ||
#include <fstream> | ||
#include <sstream> | ||
#include <filesystem> | ||
|
||
#include "nvapi.h" | ||
|
||
#define NVAPI_EXIT_IF_ERROR(func, msg) \ | ||
{ \ | ||
NvAPI_Status status; \ | ||
NvAPI_ShortString string; \ | ||
if ((status = func) != NVAPI_OK) { \ | ||
NvAPI_GetErrorMessage(status, string); \ | ||
std::cout << msg << " Error: " << string << std::endl; \ | ||
NvAPI_Unload(); \ | ||
return false; \ | ||
} \ | ||
} | ||
|
||
bool nv_set_edid(const std::uint32_t gpu_index, const std::uint32_t display_index, const std::string_view edid_file) | ||
{ | ||
std::fstream edid_stream(edid_file); | ||
if (!edid_stream.good()) { | ||
std::cout << "ERROR: Failed to open EDID file." << std::endl; | ||
return false; | ||
} | ||
|
||
std::vector<std::uint8_t> edid_data; | ||
std::uint32_t byte; | ||
while(!edid_stream.eof()) { | ||
edid_stream >> std::hex >> byte; | ||
edid_data.push_back(byte); | ||
} | ||
if (edid_data.size() != 256) { | ||
std::cout << "ERROR: Invalid EDID data (size != 256 bytes). The data is either malformed or not in the NVIDIA format." << std::endl; | ||
return false; | ||
} | ||
|
||
NVAPI_EXIT_IF_ERROR(NvAPI_Initialize(), "ERROR: Failed to initialize NVAPI."); | ||
|
||
NvU32 gpu_count = 0; | ||
NvPhysicalGpuHandle physical_gpus[NVAPI_MAX_PHYSICAL_GPUS]; | ||
NVAPI_EXIT_IF_ERROR(NvAPI_EnumPhysicalGPUs(physical_gpus, &gpu_count), "ERROR: NvAPI_EnumPhysicalGPUs failed to get GPU info."); | ||
if (gpu_count <= 0) { | ||
std::cout << "ERROR: Invalid GPU count: " << gpu_count << std::endl; | ||
return false; | ||
} | ||
|
||
NvU32 display_count = 0; | ||
NVAPI_EXIT_IF_ERROR(NvAPI_GPU_GetAllDisplayIds(physical_gpus[0], NULL, &display_count), "ERROR: NvAPI_GPU_GetAllDisplayIds failed to get available display count."); | ||
|
||
NV_GPU_DISPLAYIDS displays[NVAPI_MAX_DISPLAYS]; | ||
displays[0].version = NV_GPU_DISPLAYIDS_VER; | ||
NVAPI_EXIT_IF_ERROR(NvAPI_GPU_GetAllDisplayIds(physical_gpus[0], displays, &display_count), "ERROR: NvAPI_GPU_GetAllDisplayIds failed to get display info."); | ||
|
||
if (gpu_index >= gpu_count) { | ||
std::cout << "ERROR: Invalid GPU index: count=" << gpu_count << ", index=" << gpu_index << std::endl; | ||
return false; | ||
} | ||
if (display_index >= display_count) { | ||
std::cout << "ERROR: Invalid display index: count=" << display_count << ", index=" << display_index << std::endl; | ||
return false; | ||
} | ||
|
||
NV_EDID edid{}; | ||
edid.version = NV_EDID_VER; | ||
std::copy(edid_data.begin(), edid_data.end(), edid.EDID_Data); | ||
edid.sizeofEDID = edid_data.size(); | ||
NVAPI_EXIT_IF_ERROR(NvAPI_GPU_SetEDID(physical_gpus[gpu_index], displays[display_index].displayId, &edid), "ERROR: NvAPI_GPU_SetEDID failed to set EDID."); | ||
|
||
NvAPI_Unload(); | ||
return true; | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
std::vector<std::string> args; | ||
for (int i = 0; i < argc; i++) { | ||
args.push_back(std::string(argv[i])); | ||
} | ||
|
||
for (auto arg = args.begin(); arg != args.end(); arg++) { | ||
if (*arg == "set-edid") { | ||
auto gpu_index_arg = std::next(arg); | ||
if(gpu_index_arg == args.end()) { | ||
std::cout << "ERROR: set-edid command missing GPU index argument." << std::endl; | ||
return -1; | ||
} | ||
|
||
auto display_index_arg = std::next(gpu_index_arg); | ||
if(display_index_arg == args.end()) { | ||
std::cout << "ERROR: set-edid command missing display index argument." << std::endl; | ||
return -1; | ||
} | ||
|
||
auto edid_file_arg = std::next(display_index_arg); | ||
if(edid_file_arg == args.end()) { | ||
std::cout << "ERROR: set-edid command missing EDID file argument." << std::endl; | ||
return -1; | ||
} | ||
|
||
std::string edid_file = *edid_file_arg; | ||
if (!std::filesystem::exists(edid_file)) { | ||
std::cout << "ERROR: EDID file \"" << edid_file << "\" does not exist." << std::endl; | ||
return -1; | ||
} | ||
|
||
std::uint32_t gpu_index = std::atoi(gpu_index_arg->c_str()); | ||
std::uint32_t display_index = std::atoi(display_index_arg->c_str()); | ||
if (!nv_set_edid(gpu_index, display_index, edid_file)) { | ||
return -1; | ||
} | ||
std::cout << "Success: Set EDID file sucessfully." << std::endl; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Due to the NVAPI SDK's license, distribution of copies of the source code is not allowed. To build this, you need to download the NVAPI SDK and extract it here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters