2022-12-19 22:47:10 +01:00
|
|
|
using System.Diagnostics;
|
2023-01-12 22:58:40 +01:00
|
|
|
using CommonHelpers;
|
2022-12-19 22:47:10 +01:00
|
|
|
using PowerControl.Helpers.AMD;
|
|
|
|
|
|
|
|
|
|
namespace PowerControl.Options
|
|
|
|
|
{
|
|
|
|
|
public static class TDP
|
|
|
|
|
{
|
2023-02-08 14:09:19 +01:00
|
|
|
public const string SlowTDP = "SlowTDP";
|
|
|
|
|
public const string FastTDP = "FastTDP";
|
|
|
|
|
|
|
|
|
|
public const int DefaultSlowTDP = 15000;
|
|
|
|
|
public const int DefaultFastTDP = 15000;
|
|
|
|
|
|
|
|
|
|
public static PersistedOptions UserOptions()
|
|
|
|
|
{
|
|
|
|
|
var options = new PersistedOptions("TDP");
|
|
|
|
|
|
|
|
|
|
if (options.GetOptions().Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
options.SetOptions(new PersistedOptions.Option[]
|
|
|
|
|
{
|
|
|
|
|
options.ForOption("3W").Set(SlowTDP, 3000).Set(FastTDP, 3000),
|
|
|
|
|
options.ForOption("4W").Set(SlowTDP, 4000).Set(FastTDP, 4000),
|
|
|
|
|
options.ForOption("5W").Set(SlowTDP, 5000).Set(FastTDP, 5000),
|
|
|
|
|
options.ForOption("6W").Set(SlowTDP, 6000).Set(FastTDP, 6000),
|
|
|
|
|
options.ForOption("7W").Set(SlowTDP, 7000).Set(FastTDP, 7000),
|
|
|
|
|
options.ForOption("8W").Set(SlowTDP, 8000).Set(FastTDP, 8000),
|
|
|
|
|
options.ForOption("9W").Set(SlowTDP, 9000).Set(FastTDP, 9000),
|
|
|
|
|
options.ForOption("10W").Set(SlowTDP, 10000).Set(FastTDP, 10000),
|
|
|
|
|
options.ForOption("12W").Set(SlowTDP, 12000).Set(FastTDP, 12000),
|
|
|
|
|
options.ForOption("15W").Set(SlowTDP, 15000).Set(FastTDP, 15000),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return options;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-19 22:47:10 +01:00
|
|
|
public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions()
|
|
|
|
|
{
|
|
|
|
|
Name = "TDP",
|
2023-01-10 11:12:31 +01:00
|
|
|
PersistentKey = "TDP",
|
|
|
|
|
PersistOnCreate = false,
|
2023-02-08 14:09:19 +01:00
|
|
|
OptionsValues = () => { return UserOptions().GetOptions(); },
|
2022-12-19 22:47:10 +01:00
|
|
|
ApplyDelay = 1000,
|
2023-12-14 19:07:21 +01:00
|
|
|
Visible = VangoghGPU.IsSupported,
|
2022-12-19 22:47:10 +01:00
|
|
|
ResetValue = () => { return "15W"; },
|
|
|
|
|
ActiveOption = "?",
|
2022-12-19 23:36:22 +01:00
|
|
|
ApplyValue = (selected) =>
|
2022-12-19 22:47:10 +01:00
|
|
|
{
|
2023-01-12 22:58:40 +01:00
|
|
|
if (!AntiCheatSettings.Default.AckAntiCheat(
|
2022-12-19 22:47:10 +01:00
|
|
|
Controller.TitleWithVersion,
|
2023-01-12 22:58:40 +01:00
|
|
|
"Changing TDP requires kernel access for a short period.",
|
|
|
|
|
"Leave the game if it uses anti-cheat protection."))
|
2022-12-19 22:47:10 +01:00
|
|
|
return null;
|
|
|
|
|
|
2023-02-08 14:09:19 +01:00
|
|
|
var selectedOption = UserOptions().ForOption(selected);
|
|
|
|
|
if (!selectedOption.Exist)
|
|
|
|
|
return null;
|
2023-01-12 23:01:01 +01:00
|
|
|
|
2023-02-08 14:09:19 +01:00
|
|
|
var slowTDP = selectedOption.Get(SlowTDP, DefaultSlowTDP);
|
|
|
|
|
var fastTDP = selectedOption.Get(FastTDP, DefaultFastTDP);
|
2022-12-19 22:47:10 +01:00
|
|
|
|
2023-12-14 19:07:21 +01:00
|
|
|
return CommonHelpers.Instance.WithGlobalMutex<string>(200, () =>
|
2022-12-19 22:47:10 +01:00
|
|
|
{
|
2023-12-14 19:07:21 +01:00
|
|
|
using (var sd = VangoghGPU.Open())
|
2022-12-19 22:47:10 +01:00
|
|
|
{
|
2023-12-14 19:07:21 +01:00
|
|
|
if (sd is null)
|
|
|
|
|
return null;
|
2022-12-19 22:47:10 +01:00
|
|
|
|
2023-12-14 19:07:21 +01:00
|
|
|
sd.SlowTDP = (uint)slowTDP;
|
|
|
|
|
sd.FastTDP = (uint)fastTDP;
|
|
|
|
|
}
|
2022-12-19 22:47:10 +01:00
|
|
|
|
|
|
|
|
return selected;
|
2023-12-14 19:07:21 +01:00
|
|
|
});
|
2022-12-19 22:47:10 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|