Get game framerate

Discussion in 'Rivatuner Statistics Server (RTSS) Forum' started by Shayne Hartford, Jul 22, 2018.

  1. Shayne Hartford

    Shayne Hartford New Member

    Messages:
    1
    Likes Received:
    2
    GPU:
    MSI GTX 1050 OC 2GB
    I am new to C++, but I'm trying to read the currently selected game's framerate with the RTSS SDK.
    I have the lib(s) included, but need help with getting framerate from the SDK.

    Project: I'm trying to use RTSS and Logitech LED Lib to change the color of keys on my keyboard depending on the framerate of the detected game in RTSS (and in the future temperature too) But I'm hoping by getting a framerate example I can figure out how to do temperature.

    EDIT: I figured out how to get the framerate of every process running, now I just need to know how to only get the currently selected process

    EDIT2: I figured it out! Yay for doing things yourself
    Heres the code if anyone wants it, I know it's probably really bad but it's functional
    Code:
    #include <thread>
    #include <iostream>
    #include <Windows.h>
    #include "LogitechLEDLib.h"
    #include "EncoderPluginTypes.h"
    #include "RTSSHooksTypes.h"
    #include "RTSSSharedMemory.h"
    
    using namespace std;
    
    DWORD pid;
    HWND hwnd;
    int FPS;
    
    void loop() {
        cout << "Thread 1" << endl;
    
        HANDLE hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, "RTSSSharedMemoryV2");
        LPVOID pMapAddr = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
        LPRTSS_SHARED_MEMORY pMem = (LPRTSS_SHARED_MEMORY)pMapAddr;
        while (true) {
            hwnd = GetForegroundWindow();
            GetWindowThreadProcessId(hwnd, &pid);
    
            for (DWORD dwEntry = 0; dwEntry < pMem->dwAppArrSize; dwEntry++) {
                RTSS_SHARED_MEMORY::LPRTSS_SHARED_MEMORY_APP_ENTRY pEntry = (RTSS_SHARED_MEMORY::LPRTSS_SHARED_MEMORY_APP_ENTRY)((LPBYTE)pMem + pMem->dwAppArrOffset + dwEntry * pMem->dwAppEntrySize);
    
                if (pEntry->dwProcessID == pid) FPS = pEntry->dwStatFrameTimeBufFramerate / 10.0f;
            }
        }
    }
    
    int main() {
        cout << "Thread 0" << endl;
    
        thread t1(loop);
    
        while(true) cout << FPS << endl;
    
        t1.join();
    
        return 0;
    }
     
    Last edited: Jul 23, 2018
    CaptaPraelium and Unwinder like this.

Share This Page