mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Added AutoTDP feature with RTSS source and Intel + ASUS power limiters
This commit is contained in:
136
app/AutoTDP/FramerateSource/RTSSFramerateSource.cs
Normal file
136
app/AutoTDP/FramerateSource/RTSSFramerateSource.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RTSSSharedMemoryNET;
|
||||
|
||||
namespace GHelper.AutoTDP.FramerateSource
|
||||
{
|
||||
internal class RTSSFramerateSource : IFramerateSource
|
||||
{
|
||||
private static Process? rtssInstance;
|
||||
|
||||
private static OSD? osd;
|
||||
|
||||
public static string RTSSPath { get; set; }
|
||||
|
||||
|
||||
public static bool IsRunning => Process.GetProcessesByName("RTSS").Length != 0;
|
||||
|
||||
|
||||
static RTSSFramerateSource()
|
||||
{
|
||||
RTSSPath = @"C:\Program Files (x86)\RivaTuner Statistics Server\RTSS.exe";
|
||||
}
|
||||
|
||||
public static bool IsAvailable()
|
||||
{
|
||||
return File.Exists(RTSSPath);
|
||||
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
if ((rtssInstance == null || rtssInstance.HasExited) && !IsRunning && File.Exists(RTSSPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
rtssInstance = Process.Start(RTSSPath);
|
||||
Thread.Sleep(2000); // If it works, don't touch it
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.WriteLine("Could not start RTSS Service" + exc.Message);
|
||||
}
|
||||
|
||||
RunOSD();
|
||||
}
|
||||
else
|
||||
{
|
||||
RunOSD();
|
||||
}
|
||||
}
|
||||
|
||||
public List<GameInstance> GetRunningGames()
|
||||
{
|
||||
if (!IsRunning)
|
||||
{
|
||||
return new List<GameInstance>();
|
||||
}
|
||||
|
||||
List<GameInstance> giL = new List<GameInstance>();
|
||||
|
||||
foreach (AppEntry appEntry in OSD.GetAppEntries())
|
||||
{
|
||||
GameInstance i = new GameInstance();
|
||||
i.ProcessID = appEntry.ProcessId;
|
||||
i.ProcessName = appEntry.Name;
|
||||
|
||||
giL.Add(i);
|
||||
}
|
||||
|
||||
return giL;
|
||||
}
|
||||
|
||||
public double GetFramerate(string processName)
|
||||
{
|
||||
if (!IsRunning)
|
||||
{
|
||||
return -1.0d;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var appE = OSD.GetAppEntries()
|
||||
.Where(x => (x.Flags & AppFlags.MASK) != AppFlags.None).FirstOrDefault(a => a.Name.EndsWith(processName));
|
||||
if (appE is null)
|
||||
return -1.0d;
|
||||
|
||||
return (double)appE.StatFrameTimeBufFramerate / 10;
|
||||
}
|
||||
catch (InvalidDataException)
|
||||
{
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
}
|
||||
|
||||
return -1.0d;
|
||||
}
|
||||
|
||||
public static void RunOSD()
|
||||
{
|
||||
if (osd == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
osd = new OSD("GHELPER");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.WriteLine("Could not start OSD" + exc.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
if (rtssInstance != null && !rtssInstance.HasExited)
|
||||
{
|
||||
try
|
||||
{
|
||||
rtssInstance.Kill();
|
||||
rtssInstance = null;
|
||||
var proc = Process.GetProcessesByName("RTSSHooksLoader64");
|
||||
proc[0].Kill();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user