FakeMichau / fakenvapi

NVAPI library for spoofing an Nvidia GPU. With support for AntiLag 2 and LatencyFlex
MIT License
29 stars 0 forks source link

Anti-Lag 2 injection using Rivatuner Statistics Server #3

Open Dendari92 opened 1 month ago

Dendari92 commented 1 month ago

Hello, thanks for your work on the mod! I've used it with OptiScaler on some games and can definitely feel the difference.

I noticed in the release notes it's mentioned that "RTSS can inject it to many games that don't support Reflex out of the box as well", is it actually possible? Any tips on how to do it, for example does it need OptiScaler to be installed? Does the game need to have DLSS support?

FakeMichau commented 1 month ago

Yes it needs optiscaler for spoofing the gpu and loading nvapi from the game folder but the game doesn't need to support DLSS. It's abusing optiscaler in a sense.

RTSS is a double edge sword, it injects latency markers by default in newer RTSS versions but this also causes issues in games that already support Reflex. If you launch RTSS' gui, press Setup on the bottom and scroll down, you should see Reflex injection settings. I don't know if RTSS let's you choose that setting per-game but I would advise having that option disabled by default and only enabling it for games that don't support Reflex by themselves. It's not perfect but from my tests in Palworld (both dx11 and dx12) it can make a difference.

I'm also looking at SpecialK support as it can also inject Reflex but SpecialK + Optiscaler combination has issues by itself.

So in short, install opti, install fakenvapi and launch RTSS. It might work, it might not.

Dendari92 commented 1 month ago

Thanks for your reply and information!

I've been doing some testing (probably I should've done it before asking) and I was able to get AL2 injection working through RTSS standalone. So far I've tested just a couple of games so nothing conclusive, but I guess it's still something. To get it to work was actually pretty simple, what I've tried:

  1. Copying fakenvapi's nvapi64.dll into my Windows\System32 folder. Seems to work, but will it trigger anti-cheat systems?

  2. Copying fakenvapi's nvapi64.dll into the game directory. Again seems to work but I had some inconsistencies and need more testing.

One thing I'm wondering now is if RTSS is injecting the Reflex markers by default wouldn't it trigger the anti-cheat systems? Isn't it similar to what AMD tried to do with Anti-Lag+ (iirc that got people banned in CS2 and some other games)?

P.S. when I say "AL2 seems to work" I'm mostly referring to the Radeon Anti-Lag overlay working, unfortunately with my limited testing I've not tried latency sensitive games, so in terms of "feeling" more responsive I couldn't tell.

FakeMichau commented 1 month ago

You can use FLM for testing latency or FrameView for displaying PC Latency on an overlay which is usually more accurate than AL2's overlay.

Seems to work, but will it trigger anti-cheat systems?

In the past I've seen War Thunder fail to load when a modified nvapi was in system32. Most games don't load nvapi when dxgi reports an AMD GPU so usually it's not an issue. No guarantees of course.

One thing I'm wondering now is if RTSS is injecting the Reflex markers by default wouldn't it trigger the anti-cheat systems?

To be honest I have no idea. To my knowledge RTSS is already doing some questionable hooking and injection. There were even some online games that blocked all the overlays like this. But I imagine anti cheat devs just whitelist RTSS otherwise they would be banning a lot of innocent people.

Dendari92 commented 1 month ago

Hello, it's been a while. I've been doing quite a bit of testing since last time I posted, and I wanted to share my findings here.

First about RTSS standalone injection: I've found that copying fakenvapi's nvapi64.dll into the game directory only works for Xbox Game Pass games, and to be precise it only works when the file is copied into the root game folder. I wasn't able to replicate this behavior with other games and in these cases the only way was to copy fakenvapi's nvapi64.dll into my Windows\System32 folder or use OptiScaler/DLSS-Enabler (when it works).

About RTSS through OptiScaler/DLSS-Enabler injection: I had some problems, especially crashes on games with non-native Reflex support. This might be vary based on the game and I'm not sure if these crashes were caused by fakenvapi, OptiScaler/DLSS-Enabler or the game being sensitive.

About native Reflex to Anti-Lag 2 conversion: in the few games I could test the result seemed flawless. Latencies were almost always halved compared to not having AL2 active. Definitely gonna use the mod whenever possible.

About the latencies: for measuring latencies I used Nvidia FrameView PCL stat, AMD Frame Latency Meter and also the AMD Radeon Anti-Lag Indicator. From my finding they report almost the same values when testing the native conversion (usually within 1ms each other). While testing RTSS injection only NFV and AFLM were close while ARALI seemed to report always the best possible latency (as if it was native). I've also noticed that the latencies when using RTSS injection are on par with driver level Anti-Lag (as reported by NFV and AFLM), so I'm wondering if this is also true on a Nvidia GPU (RTSS reflex vs driver level NULL) because at the moment I'd say it's not worth the hassle if the results are accurate.

About anti-cheat: I can confirm Easy Anti-Cheat will block nvapi64.dll with a message saying Untrusted system file or something similar.

Overall I'm happy the mod exists as currently native Anti-Lag 2 support is pretty much non-existent, so I'm gonna use it for the native conversion whenever possible. Kinda disappointed in the RTSS injection, I was hoping it'd be much closer to the "native" experience but it seems too much hassle for not much to gain (especially if it's similar to driver level AL).

Anyway thanks again for your work!

FakeMichau commented 1 month ago

My default assumption is for this mod to be used in combination with OptiScaler / DLSS Enabler. Most games need to have spoofed vendorid in dxgi descriptors to even load nvapi. Honestly didn't know that gamepass just loads nvapi from the game folder.

We've been messing around with getting SpecialK to work to inject Reflex with it instead of RTSS. If you look at the latest version of OptiScaler, it has a setting for loading SpecialK. You could try messing with it in games that don't work all that well with RTSS' injection.

Also, what games were crashing when you tried to use fakenvapi+Opti? Nitec, the creator of Optiscaler, usually fixes issues like this quite quickly when they show up.

Dendari92 commented 1 month ago

My default assumption is for this mod to be used in combination with OptiScaler / DLSS Enabler. Most games need to have spoofed vendorid in dxgi descriptors to even load nvapi.

I admit when I first noticed your mod I thought it was gonna work only with native Reflex implementation, but then I read the release notes mentioning RTSS injection and I was even more excited to try it out.

Honestly didn't know that gamepass just loads nvapi from the game folder.

Yeah, Xbox Game Pass games are a very weird case, from my testing the mod actually only works if nvapi64.dll is in that root folder (besides the gamelaunchhelper.exe file, dunno if it is related) and launch the game using Xbox shortcuts (app, desktop, start menu). If I launch the game using the main executable it won't work, copying in almost every other folder won't work. Only in that specific case RTSS will inject fakenvapi, I can't say why is that but it's definitely interesting.

We've been messing around with getting SpecialK to work to inject Reflex with it instead of RTSS. If you look at the latest version of OptiScaler, it has a setting for loading SpecialK. You could try messing with it in games that don't work all that well with RTSS' injection.

Thanks for letting me know, I'll check it out (also noticed someone asked official AL2 integration into SpecialK).

EDIT: did a quick test and the latency is pretty much on par with the native Reflex implementation.

Also, what games were crashing when you tried to use fakenvapi+Opti? Nitec, the creator of Optiscaler, usually fixes issues like this quite quickly when they show up.

I had issues with Watch Dogs 2 and Watch Dogs Legion. In all honesty I don't think they're really the type of games to benefit much from AL2 (being third person). I just had them installed and wanted to see if it'd work.

cdozdil commented 1 month ago

Hi there,

I have a few questions/requests from you if it's not going to be too much.

  1. Are these two Watchdogs games are Gamepass versions?
  2. Are there any error messages from game or eventlog info? If there is could you share these?
  3. If you were using latest pre-release version of Opti there should be Optiscaler.log file in game folder. Could you share it too?
Dendari92 commented 4 weeks ago

Hi, it's me again.

Hi there,

I have a few questions/requests from you if it's not going to be too much.

  1. Are these two Watchdogs games are Gamepass versions?
  2. Are there any error messages from game or eventlog info? If there is could you share these?
  3. If you were using latest pre-release version of Opti there should be Optiscaler.log file in game folder. Could you share it too?

Sorry for not replying earlier. I was playing those games on the Ubisoft Launcher while subscribed to Ubisoft+. Unfortunately it has expired so I can't access those games anymore and I don't have the logs. In the future if anything similar happen I'll definitely share with you any issue.

Anyway I wanted to share an update on my experience with fakenvapi and its Reflex injection, as I've been playing/testing many games in the last few weeks.

In games with native Reflex implementation I can confirm fakenvapi seems to perform as expected while using both Anti-Lag 2 and even LatencyFlex. So far I haven't noticed any evident issues with this method, apart from the obvious ones like anti-cheat detecting the injection.

On the other hand RTSS or SpecialK Reflex Latency Markers injection, I think neither AL2 nor LFX are working as intended at all.

From my initial testing it seemed that SpecialK was working better than RTSS but I later noticed I wasn't setting it correctly. What happened was that in native Reflex games SpecialK will let you choose to override the native implementation, but only after clicking on a checkbox (I was an idiot and didn't notice it at first...), without clicking that checkbox it'll use the native Reflex.

Anyway after more testing and double checking the settings both RTSS and SpecialK perform the same, and that means AL2 latency reduction will be on par with driver-level Anti-Lag, while LFX doesn't seem to work at all. I've also tried different settings, like when or where the injection is supposed to happen (I think both offer similar options, like before or after the frame), but at end still same results. My (completely ignorant) assumption is that some kind of information is missing and probably AL2 is somewhat of falling back to AL1, I'd imagine in case of a botched implementation it'll still give the user some latency reduction.

I know fakenvapi was only intended for native Reflex games (and it's working correctly as far I can tell), while RTSS/SpecialK were kind of a side effect. Anyway I just wanted to report my findings, as useful they might be.

AlexUnwinder commented 2 weeks ago

RTSS is a double edge sword, it injects latency markers by default in newer RTSS versions but this also causes issues in games that already support Reflex.

Wrong. It shuts down latency markers injection in games that already support Reflex with original NVAPI. But this functionality depends on NvAPI_D3D_GetLatency, which is not implemented in your wrapper. RTSS uses the following hookless approach to detect games with native Reflex support and stop injecting latency markers and NVAPI_D3D_Sleep() calls in such case:

FakeMichau commented 2 weeks ago

Thanks for your insight! Will try to add that. It was kinda a pain not knowing how rtss' detection was working.

AlexUnwinder commented 2 weeks ago

To my knowledge RTSS is already doing some questionable hooking and in

Any non-MPO overlay does exactly the same "questionable" hooking. Discord does that. EGS overlay does that. Steam overlay does that. OBS that.

FakeMichau commented 2 weeks ago
  • RTSS is constantly monitoring latency markers, reported back to application from NVAPI side via NvAPI_D3D_GetLatency. Once it sees at least one marker, containing no embedded 'RTSS' watermark, it means that the marker came from application side so RTSS completely stops injecting latency markers and sleep calls for this application runtime session.

Adding get latency stopped RTSS from injecting markers as well while allowing RTSS to graph some of the values that I have access to. RTSS' reflex graph might be especially useful for troubleshooting.

Thanks again for the explanation (and helping to get rid of at least some of the ugly code).

AlexUnwinder commented 2 weeks ago

Excellent!

Dendari92 commented 2 weeks ago

Hi again. @FakeMichau, I was wondering would this new development help the fakenvapi latency reduction through RTSS? Or is it unrelated? Thanks