PotatoOfDoom / CyberFSR2

FidelityFx Super Resolution 2.0 for Cyberpunk
MIT License
620 stars 67 forks source link

My Red Dead Redemption 2 Port - Can't get D3D12_Init to call #4

Closed RealIndica closed 2 years ago

RealIndica commented 2 years ago

Hey! I absolutely love the idea behind this and I had something really similar in mind. However, I am not as good at writing in C++ as I am in C#. I am trying to port this over to Red Dead Redemption 2.

I've managed to find the viewport and applied some simple changes in hopes it would work.

struct CameraParams
{
    float FoV; //0x0
    float NearPlane; //0x4
    float FarPlane;  //0x8
};

//offset can be found by tinkering with in-game FOV slider.

auto mod = (uint64_t)GetModuleHandleW(L"RDR2.exe");
auto ptr1 = *((uintptr_t*)(mod + 0x3E806E0));
camParams = ((CameraParams*)(ptr1));

I am unable to get it to work correctly for some reason. The game refuses to load the DLL when named "nvngx.dll" but loads when named "d3d11.dll" but then the actual functionality of the DLL doesn't work with D3D12_Init not being called. (tested by using print with console in DLL_PROCESS_ATTACH).

Tested in Cyberpunk and works flawless.

Do you have any ideas how I could make this work? I am very desperate haha.

Thank you, again.

imniko commented 2 years ago

Maybe the registry value for RDR2 is different that cyberpunk? I know that you need game ready driver supporting the game to have dlss enabled in a particular game. I don't own an RTX gpu so I cant say it for sure.

RealIndica commented 2 years ago

Maybe the registry value for RDR2 is different that cyberpunk? I know that you need game ready driver supporting the game to have dlss enabled in a particular game. I don't own an RTX gpu so I cant say it for sure.

I don't think the registry values need to be changed as signature override should be a global thing. In my PC I have a 6700-xt and in my laptop a 3070. Might be worth re-downloading RDR2 on my laptop to see how nvngx might be loaded or if RDR2 does a check for an actual RTX GPU which would be quite stupid.

RealIndica commented 2 years ago

Would love to know how nvngx.dll gets loaded in the first place because maybe I could force RDR2 to load it the way it should.

PotatoOfDoom commented 2 years ago

Oh wow, it is awesome that you are already working on this. I don't own the game so I can't help you directly but rdr2 might have some weird signature checks in addition to the ones from nvidia. I've been told that rockstar games generally have a lot of anti-debug systems and this might be part of it. But yeah checking out how the real dlss works is always a idea. That's why me getting a rtx 3060 laptop helped a lot with troubleshooting the mod. If you still can't find any way to do it after debugging that part: Hooking LoadLibrary is always a last resort to this problem. I did the same in the beginning before I found out about the registry keys.

RealIndica commented 2 years ago

Yeah, Im started to feel that @imniko might be right about the registry keys being different. How did you find the registry keys anyway? Right now i got nvngx_dlss.dll open in IDA trying to find a string that might point me in the right direction.

PotatoOfDoom commented 2 years ago

The registry key part is in the game itself and part of the static library gamedevs get from nvidia (nvsdk_ngx_s.lib). I didn't know about the registry keys in the beginning but I ran the game in x64dbg, tried to investigate why my nvngx didn't load and stumbled over some weird RegOpenKeyExW calls. You can't find them directly in IDA because they are hidden via GetProcAddress + Loadlibrary stuff but the function call OutputDebugStringW(L"*** WARNING - PE SIGNATURE VERIFICATION FAILED !!!\n*** Filename: "); should lead you to the right function.

RealIndica commented 2 years ago

The registry key part is in the game itself and part of the static library gamedevs get from nvidia (nvsdk_ngx_s.lib). I didn't know about the registry keys in the beginning but I ran the game in x64dbg, tried to investigate why my nvngx didn't load and stumbled over some weird RegOpenKeyExW calls. You can't find them directly in IDA because they are hidden via GetProcAddress + Loadlibrary stuff but the function call OutputDebugStringW(L"*** WARNING - PE SIGNATURE VERIFICATION FAILED !!!\n*** Filename: "); should lead you to the right function.

You are referring to the GUID? Looks like {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}. That's what I'm currently trying to find, and RDR2 is very debug unfriendly. I have found the function you are on about in IDA (dumped the process with pe64), as well as in Cheat Engine and x64dbg. However, I can't find any obvious pointers to finding that GUID. I have tried hooking StringFromGUID2 but no luck, even manually calling the function that contains it.

imniko commented 2 years ago

Maybe games that have anti-tamper and anti-cheat DRM this DLL replacer method. wont work there. I have Horizon Zero Dawn, but have no knowledge on how to get the camera offset, also never worked with IDA or x64dbg or I would gave it a shot.

dumpsters commented 2 years ago

The latest scene release has this on the changelog

unpacked executable, it loads much faster than original

properly generated license in runtime that completely crushes their 4 stage license verification and anti-tamper scheme

perhaps debugging the cracked version would be easier and then you can apply your findings to the official one? Don't know how realistic that is though

RealIndica commented 2 years ago

Got it working! For some reason, the game seems to check if you have a supported GPU before going ahead and loading nvngx.dll, whereas cyberbug loads it pretty much without question and then unloads it if its not needed. Took a lot of debugging but will fork this repo and apply my edits. Thanks for the help dudes :)

Some performance stats (i7 8700k, 6700-xt, 32gb ram) : native : 95 balanced : 120 ultra performance : 140

RealIndica commented 2 years ago

https://github.com/RealIndica/RDRFSR2

JacekJagosz commented 2 years ago

I wonder if at one point other versions of this mod could get merged into the original one, with one file with configurations for different games. Do you think that could be possible, or you had to do changes in too many places?

nikviktorovich commented 2 years ago

https://github.com/RealIndica/RDRFSR2

Unfortunately, it does not work for me. I believe there can be different addresses for different versions of the game and between license/cracked vesions. Can you describe the way you found the view matrix and hardware support check addresses?

EDIT: The problem is that there is no DLSS option in settings. Enabling it in system.xml changes nothing either.

RealIndica commented 2 years ago

https://github.com/RealIndica/RDRFSR2

Unfortunately, it does not work for me. I believe there can be different addresses for different versions of the game and between license/cracked vesions. Can you describe the way you found the view matrix and hardware support check addresses?

EDIT: The problem is that there is no DLSS option in settings. Enabling it in system.xml changes nothing either.

I am using the legit version of rdr2. I will update to find the address by signature today so it shouldn't matter what version of rdr2 you have unless it's pre-dlss update.

edit : I won't be supporting cracked versions, sorry.

nikviktorovich commented 2 years ago

For those who want to try it in not a legit one, the relative address for game version 1436.28 is 0x2729774

rigopoui commented 2 years ago

For those who want to try it in not a legit one, the relative address for game version 1436.28 is 0x2729774

Does not work for me for that version. Are you sure this is the address? How could I find the correct value?

nikviktorovich commented 2 years ago

For those who want to try it in not a legit one, the relative address for game version 1436.28 is 0x2729774

Does not work for me for that version. Are you sure this is the address? How could I find the correct value?

Just to make suke, you're running D3D12 version and replaced the '_GPU_CHK' address in RealIndica's nvngxLoader and not the _SIG_VER (it's actually not used here)? Also, make sure you compiled it in Release x64 configuration and copied the compiled 'd3d11.dll' file into the game directory, right next to 'nvngx.dll'. If all above is correct and it's still not working, write your email address and I'll try to explain the way I found it (cause I can't write it here due to as someone pointed out - "decompiling is illegal in many parts of the world").

rigopoui commented 2 years ago

For those who want to try it in not a legit one, the relative address for game version 1436.28 is 0x2729774

Does not work for me for that version. Are you sure this is the address? How could I find the correct value?

Just to make suke, you're running D3D12 version and replaced the '_GPU_CHK' address in RealIndica's nvngxLoader and not the _SIG_VER (it's actually not used here)? Also, make sure you compiled it in Release x64 configuration and copied the compiled 'd3d11.dll' file into the game directory, right next to 'nvngx.dll'. If all above is correct and it's still not working, write your email address and I'll try to explain the way I found it (cause I can't write it here due to as someone pointed out - "decompiling is illegal in many parts of the world").

Ah cheers I was in vulkan mode, gonna give this a try. Thanks a lot!

Edit: it didn't work. I guess I'm probably not replacing the right variable with this address in the code? Or maybe there are more than one addresses that have changed.

nikviktorovich commented 2 years ago

For those who want to try it in not a legit one, the relative address for game version 1436.28 is 0x2729774

Does not work for me for that version. Are you sure this is the address? How could I find the correct value?

Just to make suke, you're running D3D12 version and replaced the '_GPU_CHK' address in RealIndica's nvngxLoader and not the _SIG_VER (it's actually not used here)? Also, make sure you compiled it in Release x64 configuration and copied the compiled 'd3d11.dll' file into the game directory, right next to 'nvngx.dll'. If all above is correct and it's still not working, write your email address and I'll try to explain the way I found it (cause I can't write it here due to as someone pointed out - "decompiling is illegal in many parts of the world").

Ah cheers I was in vulkan mode, gonna give this a try. Thanks a lot!

Edit: it didn't work. I guess I'm probably not replacing the right variable with this address in the code? Or maybe there are more than one addresses that have changed.

Also, can you, please, describe - by not working you mean that there is no DLSS option in game settings or it is there but it just scales rendering resolution and doing nothing more? Cause in the second case you need to change value of 'Method' (under [View] section of ini-file) to 'config' (without quotation marks), otherwise it just gets wrong values for FarPlane, NearPlane and Fov. Also, I just checked - it should work for both Vulkan and D3D12.

rigopoui commented 2 years ago

Yeah sorry, no DLSS option, looks like it never gets loaded. Could you put up a fork with your edited files? Or share the diff with me? I guess I'm doing something wrong since I have no idea what I'm doing :smiling_face_with_tear:

nikviktorovich commented 2 years ago

Yeah sorry, no DLSS option, looks like it never gets loaded. Could you put up a fork with your edited files? Or share the diff with me? I guess I'm doing something wrong since I have no idea what I'm doing 🥲

Sure. Download 'Release.zip' from here https://github.com/lnfecteDru/RDRFSR2/releases/tag/v1.3 and extract it into your game directory. Let me know if this worked for you.

rigopoui commented 2 years ago

Still didn't load, although your diff was quite different from mine (I had only changed _GPU_CHK, and had no deletions). I'm on version 1436.28

nikviktorovich commented 2 years ago

Still didn't load, although your diff was quite different from mine (I had only changed _GPU_CHK, and had no deletions). I'm on version 1436.28

I forgot to put 'EnableSignatureOverride.reg' and 'DisableSignatureOverride.reg' to release zip-file. Can you download 'EnableSignatureOverride.reg' from the repository and run it? It allows to bypass DLSS signature check.

rigopoui commented 2 years ago

Still didn't load, although your diff was quite different from mine (I had only changed _GPU_CHK, and had no deletions). I'm on version 1436.28

I forgot to put 'EnableSignatureOverride.reg' and 'DisableSignatureOverride.reg' to release zip-file. Can you download 'EnableSignatureOverride.reg' from the repository and run it? It allows to bypass DLSS signature check.

That got it working! nice. Weird because the reg edit wasn't needed for me for the legit version.

nikviktorovich commented 2 years ago

Still didn't load, although your diff was quite different from mine (I had only changed _GPU_CHK, and had no deletions). I'm on version 1436.28

I forgot to put 'EnableSignatureOverride.reg' and 'DisableSignatureOverride.reg' to release zip-file. Can you download 'EnableSignatureOverride.reg' from the repository and run it? It allows to bypass DLSS signature check.

That got it working! nice. Weird because the reg edit wasn't needed for me for the legit version.

AFAICT he's patching result of signature verification so it returns success in any case (the address stored in _SIG_VER).