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:
    2
    Likes Received:
    2
    GPU:
    N/A
    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.
  2. Shayne Hartford

    Shayne Hartford New Member

    Messages:
    2
    Likes Received:
    2
    GPU:
    N/A
    This is probably bumping and will get closed but I recently found my post while trying to remake this, here's updated code if it helps anyone, make sure to add "C:\Program Files (x86)\RivaTuner Statistics Server\SDK\Include" to your additional includes in project settings.
    Code:
    #include <iostream>
    #include <Windows.h>
    #include <RTSSSharedMemory.h>
    
    int main()
    {
        HANDLE hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"RTSSSharedMemoryV2");
        LPVOID pMapAddr = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
        LPRTSS_SHARED_MEMORY pMem = (LPRTSS_SHARED_MEMORY)pMapAddr;
    
        while (true)
        {
            HWND hWnd = GetForegroundWindow();
            DWORD threadId, pid;
            threadId = 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)
                {
                    float framerate = pEntry->dwStatFrameTimeBufFramerate / 10.0f;
                    std::cout << framerate << std::endl;
                };
            }
        }
    
        return 0;
    }
     

Share This Page