PotatoOfDoom / CyberFSR2

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

Need some help making this work on Horizon Zero Dawn #10

Open imniko opened 2 years ago

imniko commented 2 years ago

I just wanted to see if I could get the dll loaded in HZD, I installed IDA and tried to find relevant string, but I am still not sure if I am on right direction or how to get the reg value. It does have the following part though, but I am unable to figure out what to do next.

Edit: I think the game checks for some nvidia driver/registry because I am unable to get the dll loaded in the game as I have AMD gpu, another user (nvidia GPU) confirmed that the DLL loads on their PC, so its probably checks for nvidia stuffs or something

Xontaro commented 2 years ago

Just a word of caution, decompiling is illegal in many parts of the world. And you sadly aren't on the right path, take a look at the ViewMatrixHook, you need to patch it in order to work with Horizon Zero Dawn.

imniko commented 2 years ago

Oh, I thought as the DLL was not loaded by the game at all, it had to do with some check. Thanks anyway, I am closing it for now and editing original post to remove some stuffs.

imniko commented 2 years ago

@Xontaro why do you think your solution is hacky? Didn't you just patched ViewMatrixHook?

Xontaro commented 2 years ago

@imniko Oh, I thought I deleted my original post for good, but you got a hold of it. So yeah I patched the ViewMatrixHook, sadly I only found the location of the FOV and not the Near and FarPlane. As @mnxn wrote in another issue, approximating their values is usually close enough, so I did that. But there are several issues with it ingame:

Hacky is indeed probably not the right word for it, more like unfinished and unwilling to develop it further. I just don't see much value in what I've done.

imniko commented 2 years ago

Yah, this mod is good as proof of concept, but unless ghosting and transparent objects are handled it wont be worth it if you can do away without it. Or absolutely cant run the game otherwise.

imniko commented 2 years ago

I think the game checks for nvidia driver or something, the game does not load the dll for me at all maybe because I have AMD GPU.

imniko commented 2 years ago

Finally I managed to find the check which was disabling DLSS for AMD GPU, for reference the address value is 00007FF64D28ADC4, I had to edit the JNE/JNZ to JE/JZ (which wont work in nvidia btw) I also don't know how to patch exe's using DLLmain, so I wont be creating a fork.

Now, how FSR 2.0 looks? some stuffs looks really good, but some stuffs that normally needs a reactive mask (e.g. hair/beard, fur on cloths, smoke, rain etc) has horrible aliasing, because those are rendered in lower resolution and aren't upscaled by FSR 2.0, these are also affecting the surrounding objects. Foliage also looks like mush due to ghosting and snow flakes also has ghosting.

Anyway, I was more curious as to why some were saying that this mod loads on HZD, but I couldn't make it work on my PC, its because of a different check, I don't exactly know what it checks but patching that line was the key for me. I will keep this issue opened for now, if mod improves (I hope it does) and someone decides to add support for this game.

Xontaro commented 2 years ago

@imniko Sorry that I mislead you with my initial comment, but I simply wasn't aware of that, since I'm using a Nvidia GPU.

imniko commented 2 years ago

@imniko Sorry that I mislead you with my initial comment, but I simply wasn't aware of that, since I'm using a Nvidia GPU.

Its okay, I don't think getting the camera reference will make it any better (don't know how to get that reference anyway) as I compiled the repo supporting external config and changing FOV, far/near clip had almost no effect.

RealIndica commented 2 years ago

Finally I managed to find the check which was disabling DLSS for AMD GPU, for reference the address value is 00007FF64D28ADC4, I had to edit the JNE/JNZ to JE/JZ (which wont work in nvidia btw) I also don't know how to patch exe's using DLLmain, so I wont be creating a fork.

Now, how FSR 2.0 looks? some stuffs looks really good, but some stuffs that normally needs a reactive mask (e.g. hair/beard, fur on cloths, smoke, rain etc) has horrible aliasing, because those are rendered in lower resolution and aren't upscaled by FSR 2.0, these are also affecting the surrounding objects. Foliage also looks like mush due to ghosting and snow flakes also has ghosting.

Anyway, I was more curious as to why some were saying that this mod loads on HZD, but I couldn't make it work on my PC, its because of a different check, I don't exactly know what it checks but patching that line was the key for me. I will keep this issue opened for now, if mod improves (I hope it does) and someone decides to add support for this game.

You can nop the 6 bytes responsible for making the decision to load nvngx instead of switching the jz to a jnz then it will work on all drivers/gpus.

imniko commented 2 years ago

Yep, that's the way to go once support is need to be added for that game, but right now FSR 2.0 has major issues in this game.

nikviktorovich commented 2 years ago

Finally I managed to find the check which was disabling DLSS for AMD GPU, for reference the address value is 00007FF64D28ADC4, I had to edit the JNE/JNZ to JE/JZ (which wont work in nvidia btw) I also don't know how to patch exe's using DLLmain, so I wont be creating a fork.

Now, how FSR 2.0 looks? some stuffs looks really good, but some stuffs that normally needs a reactive mask (e.g. hair/beard, fur on cloths, smoke, rain etc) has horrible aliasing, because those are rendered in lower resolution and aren't upscaled by FSR 2.0, these are also affecting the surrounding objects. Foliage also looks like mush due to ghosting and snow flakes also has ghosting.

Anyway, I was more curious as to why some were saying that this mod loads on HZD, but I couldn't make it work on my PC, its because of a different check, I don't exactly know what it checks but patching that line was the key for me. I will keep this issue opened for now, if mod improves (I hope it does) and someone decides to add support for this game.

Looks like the given address is absolute and can be different every time (in my case it was 0x7FF6FF6BADC4). So for those who want to try it - the relative address (to the base) is 0x1FADC4. Just fill it with 6 'nop's like the RealIndica pointed out (to do this you can use nvngxLoader from his fork).

TheRazerMD commented 2 years ago

@lnfecteDru @imniko I've been trying to follow these instructions, but not really into IDA so it's more like hitting my head on the wall atm. I followed the relative address, but can't figure out which 6 are the ones you have to "nop" out. Any way you could show me or something?

nikviktorovich commented 2 years ago

@lnfecteDru @imniko I've been trying to follow these instructions, but not really into IDA so it's more like hitting my head on the wall atm. I followed the relative address, but can't figure out which 6 are the ones you have to "nop" out. Any way you could show me or something?

Hello! There are 2 bytes defining the instruction (JNZ/JNE) and 4 bytes of address. In IDA it is probably shown as a single command (something like JNE XX XX XX XX), which you just have to fill with NOPs (it's opcode is 0x90 so the sequence will look like '90 90 90 90 90 90').

EDIT: But the easiest approach is still using RealIndica's nvngxLoader. Just clone his RDRFSR2 repository, then in nvngxLoader/dllmain.cpp remove everything related to _SIG_VER (lines 9 and 22) and change the value of _GPU_CHK (line 8) to 0x1FADC4 and compile the nvngxLoader project (you don't need to compile the CyberFSR project). Then copy the compiled 'd3d11.dll' file to your game directory (right next to 'nvngx.dll').

EDIT2: Also, if you still want to do this manually, notice, that the game checks ability to use DLSS before the game window even appear so you have to start the game right in IDA so it will activate the breakpoint before the check.

TheRazerMD commented 2 years ago

@lnfecteDru Thanks for the guide! Ended up using the nvngxLoader method you mentioned. Seems to have worked out fine as DLSS option was exposed and available. The Steam Overlay was not working (neither in RDR2, but I was expecting that), only problem was neither did RTSS overlay for some reason (which does in RDR2), so that was weird. And as was previously mentioned, guessing the transparency mask regarding Aloy's hair, fur and particles isn't working/being upscaled, resulting in the distorted outer lines.

Btw, for future reference regarding your EDIT2 - IDA has Debugger with Run and Attach options. So the order should be Debugger - Run - Local Windows Debugger - game exe to catch the checks? Terminating the process/detaching the debugger also gives save memory snapshot with all segments or loaded only.

Also sorry if I'm bothering you!

nikviktorovich commented 2 years ago

only problem was neither did RTSS overlay for some reason (which does in RDR2)

From my experience, RTSS overlay works in RDR2 under Vulkan but not D3D12. Probably, RTSS uses 'd3d11.dll' as injected dll name too for D3D games but not for Vulkan ones.

Btw, for future reference regarding your EDIT2 - IDA has Debugger with Run and Attach options. So the order should be Debugger - Run - Local Windows Debugger - game exe to catch the checks?

Not sure about this one since I'm using x64dbg

Also sorry if I'm bothering you!

Feel free to ask, this is what github issues exist for!

TheRazerMD commented 2 years ago

From my experience, RTSS overlay works in RDR2 under Vulkan but not D3D12. Probably, RTSS uses 'd3d11.dll' as injected dll name too for D3D games but not for Vulkan ones.

Interesting, works fine for me on DX12 with FSR2 mod. Didn't try Vulkan so can't comment on that.

Not sure about this one since I'm using x64dbg

Also have x64dbg, so that works too. Open file then Debugger - Run?

spajdrEX commented 2 years ago

Come to discord guys! and let discuss it there. https://discord.gg/2JDHx6kcXB (PotatoOfDoom created it recently)

nikviktorovich commented 2 years ago

Also have x64dbg, so that works too. Open file then Debugger - Run?

Yes, File -> Open. You also may need to enable checkbox 'Entry breakpoint' under 'Events' section in Options -> Preferences

MOVZX commented 2 years ago

Before: image

After: image

You can do that to almost every games which has the checks like SotTR, F1 22, and so on.

Railgun-wiki commented 1 year ago

May be you can use this mod to load FSR2 https://www.nexusmods.com/horizonzerodawn/mods/133

But Anoy's hair , grass and trees are really strange

t0mtee commented 1 year ago

only problem was neither did RTSS overlay for some reason (which does in RDR2)

From my experience, RTSS overlay works in RDR2 under Vulkan but not D3D12. Probably, RTSS uses 'd3d11.dll' as injected dll name too for D3D games but not for Vulkan ones.

I got RTSS working by adding making a new profile for RDR2.exe, opening the .cfg file for the profile, finding [RendererDirect3D12] and adding D3D11on12=0 under it

Boulotaur2024 commented 1 year ago

May be you can use this mod to load FSR2 https://www.nexusmods.com/horizonzerodawn/mods/133

But Anoy's hair , grass and trees are really strange

I wonder what could be done to improve that... Direct access to the game camera matrix, I guess ? near & far plane don't do much as someone said in this thread (Well I know nothing about FSR 2.0 but I'm just gathering info)

EDIT : bit of info here https://github.com/ValveSoftware/Proton/issues/5937#issuecomment-1182951631