Quantcast
Channel: OwnedCore - World of Warcraft Exploits, Hacks, Bots and Guides.
Viewing all articles
Browse latest Browse all 280060

Limit FPS with injected clr app

$
0
0
First of all: Yes nowdays you can use CVar maxfpsbk to limit the framerate in WoW however Im not really interested in capping the FPS for a purpose but rather want to find out the best technique to do it.

Right now I got an injected clr executable running in WoW.
Obviously one EndScene call means one frame. So FPS depends on how often EndScene can get executed in a second.
If we want to cap at 60 FPS:
1000/60 = 16,66666666666667 => Time between each rendered frame should be around 16666666ns

Logic is easy:
If the time passing by between the last rendered frame and the current frame takes less than 16 ms we sleep til we reach 16 ms.
Now I redirected EndScene to a c# function which will do the logic:

Code:

private static int LastFrameTick = 0;
private static int TimeBetweenFrame = 0;
private static int WaitTilNextFrame = 0;

private static int EndSceneHook(IntPtr parDevice)
{
        int ret = (int)_endSceneHook.CallOriginal(parDevice);
        if (LastFrameTick != 0)
        {
                TimeBetweenFrame = (Environment.TickCount - LastFrameTick);
                if (TimeBetweenFrame < 15)
                {
                        WaitTilNextFrame = Environment.TickCount + (15 - TimeBetweenFrame);
                        while (Environment.TickCount < WaitTilNextFrame) ;
                }
        }
        LastFrameTick = Environment.TickCount;
        return ret;
}

Well I am pretty happy with the result but I am wondering if there are ways to be more accurate. Since .net cant work with ns (atleast I read it cant) we cant really work with 16,66666666666667 so we have to decide between 16ms (62.5 fps) and 17ms (58.8 fps) not accounting that the detour itself also affects the outcome.

Can someone recommend a better way to be more accurate?

Viewing all articles
Browse latest Browse all 280060

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>