diff --git a/CommonHelpers/AntiCheatSettings.cs b/CommonHelpers/AntiCheatSettings.cs
index 3d92429..7c0a9df 100644
--- a/CommonHelpers/AntiCheatSettings.cs
+++ b/CommonHelpers/AntiCheatSettings.cs
@@ -4,7 +4,7 @@ namespace CommonHelpers
{
public class AntiCheatSettings : BaseSettings
{
- public const String HelpURL = "https://steam-deck-tools.ayufan.dev/#anti-cheat-and-antivirus-software";
+ public const String HelpURL = "https://github.com/nicklavoie/steam-deck-tools";
public static readonly AntiCheatSettings Default = new AntiCheatSettings();
@@ -109,4 +109,4 @@ namespace CommonHelpers
return true;
}
}
-}
\ No newline at end of file
+}
diff --git a/CommonHelpers/CommonHelpers.csproj b/CommonHelpers/CommonHelpers.csproj
index 853887b..d4954d2 100644
--- a/CommonHelpers/CommonHelpers.csproj
+++ b/CommonHelpers/CommonHelpers.csproj
@@ -4,18 +4,16 @@
net6.0-windows
enable
true
+ true
enable
$(DefineConstants);$(ExtraDefineConstants)
-
-
-
diff --git a/CommonHelpers/Dependencies.cs b/CommonHelpers/Dependencies.cs
index 6923c14..244ae51 100644
--- a/CommonHelpers/Dependencies.cs
+++ b/CommonHelpers/Dependencies.cs
@@ -25,7 +25,7 @@ namespace CommonHelpers
"RTSSHooks64.dll"
};
- public static string SDTURL = "https://steam-deck-tools.ayufan.dev";
+ public static string SDTURL = "https://github.com/nicklavoie/steam-deck-tools";
public static string VCRuntimeURL = "https://aka.ms/vs/17/release/vc_redist.x64.exe";
public static string RTSSURL = "https://www.guru3d.com/files-details/rtss-rivatuner-statistics-server-download.html";
diff --git a/CommonHelpers/GlobalConfig.cs b/CommonHelpers/GlobalConfig.cs
index e315b77..0f01086 100644
--- a/CommonHelpers/GlobalConfig.cs
+++ b/CommonHelpers/GlobalConfig.cs
@@ -2,14 +2,6 @@
namespace CommonHelpers
{
- public enum FanMode : uint
- {
- Default = 17374,
- Silent,
- SteamOS,
- Max
- }
-
public enum KernelDriversLoaded : uint
{
Yes = 4363232,
@@ -32,19 +24,6 @@ namespace CommonHelpers
No
}
- public enum PowerControlVisible : uint
- {
- Yes = 371313,
- No
- }
-
- [StructLayout(LayoutKind.Sequential)]
- public struct FanModeSetting
- {
- public FanMode Current, Desired;
- public KernelDriversLoaded KernelDriversLoaded;
- }
-
[StructLayout(LayoutKind.Sequential)]
public struct OverlayModeSetting
{
@@ -53,23 +32,4 @@ namespace CommonHelpers
public KernelDriversLoaded KernelDriversLoaded;
public KernelDriversLoaded DesiredKernelDriversLoaded;
}
-
- [StructLayout(LayoutKind.Sequential)]
- public struct PowerControlSetting
- {
- public PowerControlVisible Current;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct SteamControllerSetting
- {
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public String CurrentProfile;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 2048)]
- public String SelectableProfiles;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public String DesiredProfile;
- }
}
diff --git a/CommonHelpers/GlobalUsings.cs b/CommonHelpers/GlobalUsings.cs
new file mode 100644
index 0000000..30f1415
--- /dev/null
+++ b/CommonHelpers/GlobalUsings.cs
@@ -0,0 +1 @@
+global using System.IO;
diff --git a/CommonHelpers/Instance.cs b/CommonHelpers/Instance.cs
index 8f7429a..de4ef29 100644
--- a/CommonHelpers/Instance.cs
+++ b/CommonHelpers/Instance.cs
@@ -1,6 +1,5 @@
using System.Security.Principal;
using System.Security.AccessControl;
-using Microsoft.Win32;
using System.Diagnostics;
using System.Reflection;
@@ -220,37 +219,6 @@ namespace CommonHelpers
return File.Exists(uninstallExe);
}
- private static System.Timers.Timer? updateTimer;
-
- public static void RunUpdater(string Title, bool user = false, int recheckIntervalHours = 24)
- {
- // Schedule updater in 24h
- if (updateTimer == null && !user && recheckIntervalHours > 0)
- {
- updateTimer = new System.Timers.Timer
- {
- Interval = recheckIntervalHours * 60 * 60 * 1000 // 24h
- };
- updateTimer.Elapsed += delegate { RunUpdater(Title, false); };
- updateTimer.Start();
- }
-
- try
- {
- Process.Start(new ProcessStartInfo()
- {
- FileName = "Updater.exe",
- ArgumentList = {
- user ? "-user" : "-first",
- "-app", ApplicationName,
- "-version", ProductVersion
- },
- UseShellExecute = false
- });
- }
- catch { }
- }
-
public static void Fatal(String? title, String message, bool capture = true)
{
if (capture)
diff --git a/DisableCheckForUpdates.txt b/DisableCheckForUpdates.txt
new file mode 100644
index 0000000..4f6c366
--- /dev/null
+++ b/DisableCheckForUpdates.txt
@@ -0,0 +1 @@
+Disabled by default in this fork.
diff --git a/DisableSentryTracking.txt b/DisableSentryTracking.txt
new file mode 100644
index 0000000..4f6c366
--- /dev/null
+++ b/DisableSentryTracking.txt
@@ -0,0 +1 @@
+Disabled by default in this fork.
diff --git a/FanControl/FanControl.csproj b/FanControl/FanControl.csproj
deleted file mode 100644
index f3dfb78..0000000
--- a/FanControl/FanControl.csproj
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-
- WinExe
- net6.0-windows
- enable
- enable
- True
- FanControl.Program
- app.manifest
- 0.1.0
- FanControl.ico
-
-
-
-
-
-
-
-
-
- True
- True
- Resources.resx
-
-
-
-
-
- ResXFileCodeGenerator
- Resources.Designer.cs
-
-
-
-
-
- PreserveNewest
-
-
-
-
diff --git a/FanControl/FanControl.ico b/FanControl/FanControl.ico
deleted file mode 100644
index a5aef5b..0000000
Binary files a/FanControl/FanControl.ico and /dev/null differ
diff --git a/FanControl/FanControlForm.Designer.cs b/FanControl/FanControlForm.Designer.cs
deleted file mode 100644
index 95bc48a..0000000
--- a/FanControl/FanControlForm.Designer.cs
+++ /dev/null
@@ -1,361 +0,0 @@
-namespace FanControl
-{
- partial class FanControlForm
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FanControlForm));
- this.fanLoopTimer = new System.Windows.Forms.Timer(this.components);
- this.notifyIcon = new System.Windows.Forms.NotifyIcon(this.components);
- this.contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
- this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem();
- this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
- this.toolStripSeparatorEndOfModes = new System.Windows.Forms.ToolStripSeparator();
- this.toolStripMenuItemStartupOnBootContext = new System.Windows.Forms.ToolStripMenuItem();
- this.toolStripMenuItemAlwaysOnTopContext = new System.Windows.Forms.ToolStripMenuItem();
- this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem();
- this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
- this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
- this.menuStrip1 = new System.Windows.Forms.MenuStrip();
- this.fanModeSelectMenu = new System.Windows.Forms.ToolStripComboBox();
- this.controlToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.toolStripMenuItemStartupOnBoot = new System.Windows.Forms.ToolStripMenuItem();
- this.toolStripMenuItemAlwaysOnTop = new System.Windows.Forms.ToolStripMenuItem();
- this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem();
- this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
- this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.propertyGridUpdateTimer = new System.Windows.Forms.Timer(this.components);
- this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
- this.label1 = new System.Windows.Forms.Label();
- this.helpLabel = new System.Windows.Forms.Label();
- this.sensorWarningLabel = new System.Windows.Forms.Label();
- this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
- this.toolStripMenuItem5 = new System.Windows.Forms.ToolStripMenuItem();
- this.contextMenu.SuspendLayout();
- this.menuStrip1.SuspendLayout();
- this.tableLayoutPanel1.SuspendLayout();
- this.SuspendLayout();
- //
- // fanLoopTimer
- //
- this.fanLoopTimer.Enabled = true;
- this.fanLoopTimer.Interval = 250;
- this.fanLoopTimer.Tick += new System.EventHandler(this.fanLoopTimer_Tick);
- //
- // notifyIcon
- //
- this.notifyIcon.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;
- this.notifyIcon.BalloonTipText = "Test";
- this.notifyIcon.ContextMenuStrip = this.contextMenu;
- this.notifyIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon.Icon")));
- this.notifyIcon.Text = "Steam Deck Fan Control";
- this.notifyIcon.DoubleClick += new System.EventHandler(this.formShow_Event);
- //
- // contextMenu
- //
- this.contextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.toolStripMenuItem2,
- this.toolStripSeparator3,
- this.toolStripSeparatorEndOfModes,
- this.toolStripMenuItemAlwaysOnTopContext,
- this.toolStripMenuItemStartupOnBootContext,
- this.toolStripMenuItem3,
- this.toolStripMenuItem5,
- this.toolStripSeparator1,
- this.toolStripMenuItem1});
- this.contextMenu.Name = "fanModeSelectMenu";
- this.contextMenu.Size = new System.Drawing.Size(211, 194);
- //
- // toolStripMenuItem2
- //
- this.toolStripMenuItem2.Name = "toolStripMenuItem2";
- this.toolStripMenuItem2.Size = new System.Drawing.Size(210, 24);
- this.toolStripMenuItem2.Text = "&Show";
- this.toolStripMenuItem2.Click += new System.EventHandler(this.formShow_Event);
- //
- // toolStripSeparator3
- //
- this.toolStripSeparator3.Name = "toolStripSeparator3";
- this.toolStripSeparator3.Size = new System.Drawing.Size(207, 6);
- //
- // toolStripSeparatorEndOfModes
- //
- this.toolStripSeparatorEndOfModes.Name = "toolStripSeparatorEndOfModes";
- this.toolStripSeparatorEndOfModes.Size = new System.Drawing.Size(207, 6); //
- // toolStripMenuItemAlwaysOnTopContext
- //
- this.toolStripMenuItemAlwaysOnTopContext.Name = "toolStripMenuItemAlwaysOnTopContext";
- this.toolStripMenuItemAlwaysOnTopContext.Size = new System.Drawing.Size(210, 24);
- this.toolStripMenuItemAlwaysOnTopContext.Text = "&Always on Top";
- this.toolStripMenuItemAlwaysOnTopContext.Click += new System.EventHandler(this.toolStripMenuItemAlwaysOnTop_Click);
- //
- // toolStripMenuItemStartupOnBootContext
- //
- this.toolStripMenuItemStartupOnBootContext.Name = "toolStripMenuItemStartupOnBootContext";
- this.toolStripMenuItemStartupOnBootContext.Size = new System.Drawing.Size(210, 24);
- this.toolStripMenuItemStartupOnBootContext.Text = "Run On &Startup";
- this.toolStripMenuItemStartupOnBootContext.Click += new System.EventHandler(this.toolStripMenuItemStartupOnBoot_Click);
- //
- // toolStripMenuItem3
- //
- this.toolStripMenuItem3.Name = "toolStripMenuItem3";
- this.toolStripMenuItem3.Size = new System.Drawing.Size(210, 24);
- this.toolStripMenuItem3.Text = "&Check for Updates";
- this.toolStripMenuItem3.Click += new System.EventHandler(this.checkForUpdates_Click);
- //
- // toolStripSeparator1
- //
- this.toolStripSeparator1.Name = "toolStripSeparator1";
- this.toolStripSeparator1.Size = new System.Drawing.Size(207, 6);
- //
- // toolStripMenuItem1
- //
- this.toolStripMenuItem1.Name = "toolStripMenuItem1";
- this.toolStripMenuItem1.Size = new System.Drawing.Size(210, 24);
- this.toolStripMenuItem1.Text = "&Exit";
- this.toolStripMenuItem1.Click += new System.EventHandler(this.formClose_Event);
- //
- // menuStrip1
- //
- this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.fanModeSelectMenu,
- this.controlToolStripMenuItem});
- this.menuStrip1.Location = new System.Drawing.Point(0, 0);
- this.menuStrip1.Name = "menuStrip1";
- this.menuStrip1.Padding = new System.Windows.Forms.Padding(4, 1, 0, 1);
- this.menuStrip1.Size = new System.Drawing.Size(438, 30);
- this.menuStrip1.TabIndex = 3;
- this.menuStrip1.Text = "menuStrip1";
- //
- // fanModeSelectMenu
- //
- this.fanModeSelectMenu.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
- this.fanModeSelectMenu.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.fanModeSelectMenu.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
- this.fanModeSelectMenu.Name = "fanModeSelectMenu";
- this.fanModeSelectMenu.Size = new System.Drawing.Size(155, 28);
- this.fanModeSelectMenu.SelectedIndexChanged += new System.EventHandler(this.fanModeSelectMenu_SelectedIndexChanged);
- //
- // controlToolStripMenuItem
- //
- this.controlToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.toolStripMenuItemAlwaysOnTop,
- this.toolStripMenuItemStartupOnBoot,
- this.toolStripMenuItem4,
- this.toolStripSeparator2,
- this.exitToolStripMenuItem});
- this.controlToolStripMenuItem.Name = "controlToolStripMenuItem";
- this.controlToolStripMenuItem.Size = new System.Drawing.Size(72, 28);
- this.controlToolStripMenuItem.Text = "&Control";
- //
- // toolStripMenuItemAlwaysOnTop
- //
- this.toolStripMenuItemAlwaysOnTop.Name = "toolStripMenuItemAlwaysOnTop";
- this.toolStripMenuItemAlwaysOnTop.Size = new System.Drawing.Size(192, 26);
- this.toolStripMenuItemAlwaysOnTop.Text = "&Always on Top";
- this.toolStripMenuItemAlwaysOnTop.Click += new System.EventHandler(this.toolStripMenuItemAlwaysOnTop_Click);
- //
- // toolStripMenuItemStartupOnBoot
- //
- this.toolStripMenuItemStartupOnBoot.Name = "toolStripMenuItemStartupOnBoot";
- this.toolStripMenuItemStartupOnBoot.Size = new System.Drawing.Size(192, 26);
- this.toolStripMenuItemStartupOnBoot.Text = "Run On &Startup";
- this.toolStripMenuItemStartupOnBoot.Click += new System.EventHandler(this.toolStripMenuItemStartupOnBoot_Click);
- //
- // toolStripMenuItem4
- //
- this.toolStripMenuItem4.Name = "toolStripMenuItem4";
- this.toolStripMenuItem4.Size = new System.Drawing.Size(192, 26);
- this.toolStripMenuItem4.Text = "Help";
- this.toolStripMenuItem4.Click += new System.EventHandler(this.help_DoubleClick);
- //
- // toolStripSeparator2
- //
- this.toolStripSeparator2.Name = "toolStripSeparator2";
- this.toolStripSeparator2.Size = new System.Drawing.Size(189, 6);
- //
- // exitToolStripMenuItem
- //
- this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
- this.exitToolStripMenuItem.Size = new System.Drawing.Size(192, 26);
- this.exitToolStripMenuItem.Text = "&Exit";
- this.exitToolStripMenuItem.Click += new System.EventHandler(this.formClose_Event);
- //
- // propertyGridUpdateTimer
- //
- this.propertyGridUpdateTimer.Enabled = true;
- this.propertyGridUpdateTimer.Interval = 1000;
- this.propertyGridUpdateTimer.Tick += new System.EventHandler(this.propertyGridUpdateTimer_Tick);
- //
- // tableLayoutPanel1
- //
- this.tableLayoutPanel1.ColumnCount = 1;
- this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
- this.tableLayoutPanel1.Controls.Add(this.label1, 0, 3);
- this.tableLayoutPanel1.Controls.Add(this.helpLabel, 0, 3);
- this.tableLayoutPanel1.Controls.Add(this.sensorWarningLabel, 0, 1);
- this.tableLayoutPanel1.Controls.Add(this.propertyGrid1, 0, 0);
- this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 30);
- this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(2, 1, 2, 1);
- this.tableLayoutPanel1.Name = "tableLayoutPanel1";
- this.tableLayoutPanel1.RowCount = 4;
- this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
- this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
- this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
- this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
- this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
- this.tableLayoutPanel1.Size = new System.Drawing.Size(438, 454);
- this.tableLayoutPanel1.TabIndex = 5;
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.label1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
- this.label1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
- this.label1.ForeColor = System.Drawing.Color.Red;
- this.label1.Location = new System.Drawing.Point(2, 394);
- this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(434, 40);
- this.label1.TabIndex = 9;
- this.label1.Text = "This application is highly experimental.\r\nUse at your own risk!";
- this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- //
- // helpLabel
- //
- this.helpLabel.AutoSize = true;
- this.helpLabel.Cursor = System.Windows.Forms.Cursors.Hand;
- this.helpLabel.Dock = System.Windows.Forms.DockStyle.Fill;
- this.helpLabel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
- this.helpLabel.Font = new System.Drawing.Font("Segoe UI", 9F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Underline))), System.Drawing.GraphicsUnit.Point);
- this.helpLabel.ForeColor = System.Drawing.SystemColors.HotTrack;
- this.helpLabel.Location = new System.Drawing.Point(2, 434);
- this.helpLabel.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
- this.helpLabel.Name = "helpLabel";
- this.helpLabel.Size = new System.Drawing.Size(434, 20);
- this.helpLabel.TabIndex = 8;
- this.helpLabel.Text = "https://steam-deck-tools.ayufan.dev";
- this.helpLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- this.helpLabel.DoubleClick += new System.EventHandler(this.help_DoubleClick);
- //
- // sensorWarningLabel
- //
- this.sensorWarningLabel.AutoSize = true;
- this.sensorWarningLabel.Dock = System.Windows.Forms.DockStyle.Fill;
- this.sensorWarningLabel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
- this.sensorWarningLabel.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
- this.sensorWarningLabel.ForeColor = System.Drawing.Color.Red;
- this.sensorWarningLabel.Location = new System.Drawing.Point(2, 334);
- this.sensorWarningLabel.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
- this.sensorWarningLabel.Name = "sensorWarningLabel";
- this.sensorWarningLabel.Size = new System.Drawing.Size(434, 60);
- this.sensorWarningLabel.TabIndex = 6;
- this.sensorWarningLabel.Text = "Some sensors are missing.\r\nThe fan behavior might be incorrect.\r\nWhich might resu" +
- "lt in device overheating.\r\n";
- this.sensorWarningLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- this.sensorWarningLabel.Visible = false;
- //
- // propertyGrid1
- //
- this.propertyGrid1.DisabledItemForeColor = System.Drawing.SystemColors.ControlText;
- this.propertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.propertyGrid1.HelpVisible = false;
- this.propertyGrid1.Location = new System.Drawing.Point(2, 1);
- this.propertyGrid1.Margin = new System.Windows.Forms.Padding(2, 1, 2, 1);
- this.propertyGrid1.Name = "propertyGrid1";
- this.propertyGrid1.Size = new System.Drawing.Size(434, 332);
- this.propertyGrid1.TabIndex = 1;
- this.propertyGrid1.ToolbarVisible = false;
- //
- // toolStripMenuItem5
- //
- this.toolStripMenuItem5.Name = "toolStripMenuItem5";
- this.toolStripMenuItem5.Size = new System.Drawing.Size(210, 24);
- this.toolStripMenuItem5.Text = "Help";
- //
- // FanControlForm
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.AutoSize = true;
- this.ClientSize = new System.Drawing.Size(438, 484);
- this.Controls.Add(this.tableLayoutPanel1);
- this.Controls.Add(this.menuStrip1);
- this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.MainMenuStrip = this.menuStrip1;
- this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.Name = "FanControlForm";
- this.ShowInTaskbar = false;
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "Steam Deck Fan Control";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FanControlForm_FormClosing);
- this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FanControlForm_FormClosed);
- this.contextMenu.ResumeLayout(false);
- this.menuStrip1.ResumeLayout(false);
- this.menuStrip1.PerformLayout();
- this.tableLayoutPanel1.ResumeLayout(false);
- this.tableLayoutPanel1.PerformLayout();
- this.ResumeLayout(false);
- this.PerformLayout();
-
- }
-
- #endregion
-
- private System.Windows.Forms.Timer fanLoopTimer;
- private NotifyIcon notifyIcon;
- private ContextMenuStrip contextMenu;
- private MenuStrip menuStrip1;
- private ToolStripSeparator toolStripSeparatorEndOfModes;
- private ToolStripMenuItem toolStripMenuItem1;
- private ToolStripComboBox fanModeSelectMenu;
- private ToolStripMenuItem controlToolStripMenuItem;
- private ToolStripMenuItem exitToolStripMenuItem;
- private System.Windows.Forms.Timer propertyGridUpdateTimer;
- private TableLayoutPanel tableLayoutPanel1;
- private Label sensorWarningLabel;
- private PropertyGrid propertyGrid1;
- private ToolStripMenuItem toolStripMenuItemStartupOnBoot;
- private ToolStripSeparator toolStripSeparator2;
- private Label label1;
- private Label helpLabel;
- private ToolStripMenuItem toolStripMenuItemAlwaysOnTop;
- private ToolStripMenuItem toolStripMenuItem2;
- private ToolStripSeparator toolStripSeparator3;
- private ToolStripMenuItem toolStripMenuItemStartupOnBootContext;
- private ToolStripMenuItem toolStripMenuItemAlwaysOnTopContext;
- private ToolStripMenuItem toolStripMenuItem3;
- private ToolStripSeparator toolStripSeparator1;
- private ToolStripMenuItem toolStripMenuItem4;
- private ToolStripMenuItem toolStripMenuItem5;
- }
-}
\ No newline at end of file
diff --git a/FanControl/FanControlForm.cs b/FanControl/FanControlForm.cs
deleted file mode 100644
index 585a72a..0000000
--- a/FanControl/FanControlForm.cs
+++ /dev/null
@@ -1,234 +0,0 @@
-using CommonHelpers;
-using ExternalHelpers;
-
-namespace FanControl
-{
- public partial class FanControlForm : Form
- {
- private FanController fanControl;
- private StartupManager startupManager = new StartupManager(
- "Steam Deck Fan Control",
- "Starts Steam Deck Fan Control on Windows startup."
- );
-
- private SharedData sharedData = SharedData.CreateNew();
-
- public FanControlForm()
- {
- Instance.OnUninstall(() =>
- {
- startupManager.Startup = false;
- });
-
- InitializeComponent();
-
- Text += " v" + Application.ProductVersion.ToString();
- Instance.Open(Text, true, "Global\\FanControlOnce");
- Instance.RunUpdater(Text);
-
- if (Instance.WantsRunOnStartup)
- startupManager.Startup = true;
-
- fanControl = new FanController();
- SharedData_Update();
-
- notifyIcon.Text = Text;
- notifyIcon.Visible = true;
- notifyIcon.Icon = WindowsDarkMode.IsDarkModeEnabled ? Resources.fan_white : Resources.fan;
-
- TopMost = Settings.Default.AlwaysOnTop;
- toolStripMenuItemAlwaysOnTop.Checked = TopMost;
- toolStripMenuItemAlwaysOnTopContext.Checked = TopMost;
-
- toolStripMenuItemStartupOnBoot.Visible = startupManager.IsAvailable;
- toolStripMenuItemStartupOnBoot.Checked = startupManager.Startup;
- toolStripMenuItemStartupOnBootContext.Visible = startupManager.IsAvailable;
- toolStripMenuItemStartupOnBootContext.Checked = startupManager.Startup;
-
- foreach (var item in Enum.GetValues(typeof(FanMode)))
- {
- var menuItem = new ToolStripMenuItem(item.ToString()) { Tag = item };
- menuItem.Click += FanMode_Click;
- int insertIndex = contextMenu.Items.IndexOf(toolStripSeparatorEndOfModes);
- contextMenu.Items.Insert(insertIndex, menuItem);
-
- fanModeSelectMenu.Items.Add(item);
- }
-
- propertyGrid1.SelectedObject = fanControl;
- propertyGrid1.ExpandAllGridItems();
-
- Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
-
- Opacity = 0;
- }
-
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- setFanMode(Settings.Default.FanMode, AntiCheatSettings.Default.NotYet);
- notifyIcon.ShowBalloonTip(3000, Text, "Fan Control Started", ToolTipIcon.Info);
- }
-
- protected override void OnShown(EventArgs e)
- {
- base.OnShown(e);
- Visible = false;
- Opacity = 100;
- }
-
- private bool AckAntiCheat()
- {
- return AntiCheatSettings.Default.AckAntiCheat(
- Text,
- "Usage of SteamOS or Max Fan Curve might trigger anti-cheat protection in some games.",
- "Ensure that you USE DEFAULT FAN when playing games with ANTI-CHEAT PROTECTION.");
- }
-
- private void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
- {
- // Restore fan mode on resume
- if (e.Mode == Microsoft.Win32.PowerModes.Resume)
- {
- Instance.HardwareComputer.Reset();
- fanControl.SetMode(fanControl.Mode);
- }
- }
-
- private void setFanMode(FanMode mode, bool requireAck = true)
- {
- if (mode != FanMode.Default && mode != fanControl.Mode)
- {
- if (requireAck && !AckAntiCheat())
- return;
- }
-
- fanControl.SetMode(mode);
- Settings.Default.FanMode = mode;
-
- foreach (ToolStripItem menuItem in contextMenu.Items)
- {
- if (menuItem is ToolStripMenuItem && menuItem.Tag is FanMode)
- ((ToolStripMenuItem)menuItem).Checked = ((FanMode)menuItem.Tag == mode);
- }
-
- fanModeSelectMenu.SelectedItem = mode;
- }
-
- private void FanMode_Click(object? sender, EventArgs e)
- {
- var menuItem = (ToolStripMenuItem)sender;
- setFanMode((FanMode)menuItem.Tag);
- }
-
- private void fanModeSelectMenu_SelectedIndexChanged(object sender, EventArgs e)
- {
- var menuItem = (ToolStripComboBox)sender;
- setFanMode((FanMode)menuItem.SelectedItem);
- }
-
- private void FanControlForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (e.CloseReason == CloseReason.UserClosing && Visible)
- {
- e.Cancel = true;
- Hide();
- }
- }
-
- private void formShow_Event(object sender, EventArgs e)
- {
- Show();
- Activate();
- propertyGrid1.Refresh();
- }
-
- private void formClose_Event(object sender, EventArgs e)
- {
- Hide();
- Close();
- }
-
- private void FanControlForm_FormClosed(object sender, FormClosedEventArgs e)
- {
- // Always revert to default on closing
- fanControl.SetMode(FanMode.Default);
- }
-
- private void SharedData_Update()
- {
- if (sharedData.GetValue(out var value) && Enum.IsDefined(value.Desired))
- {
- setFanMode((FanMode)value.Desired);
- }
-
- sharedData.SetValue(new FanModeSetting()
- {
- Current = fanControl.Mode,
- KernelDriversLoaded = Instance.UseKernelDrivers ? KernelDriversLoaded.Yes : KernelDriversLoaded.No
- });
- }
-
- private void fanLoopTimer_Tick(object sender, EventArgs e)
- {
- if (fanControl is null)
- return;
-
- try
- {
- fanLoopTimer.Enabled = false;
- SharedData_Update();
- }
- finally
- {
- fanLoopTimer.Enabled = true;
- }
-#if DEBUG
- fanControl.Update(Visible);
-#else
- fanControl.Update();
-#endif
- }
-
- private void propertyGridUpdateTimer_Tick(object sender, EventArgs e)
- {
- notifyIcon.Icon = WindowsDarkMode.IsDarkModeEnabled ? Resources.fan_white : Resources.fan;
-
- if (!Visible)
- return;
-
- propertyGrid1.Refresh();
- sensorWarningLabel.Visible = fanControl.IsAnyInvalid();
-
- if (fanControl.IsActive)
- notifyIcon.Text = String.Format("Fan: {0} RPM Mode: {1}", fanControl.CurrentRPM, fanControl.Mode);
- else
- notifyIcon.Text = String.Format("Mode: {0}", fanControl.Mode);
- }
-
- private void toolStripMenuItemStartupOnBoot_Click(object sender, EventArgs e)
- {
- startupManager.Startup = !startupManager.Startup;
- toolStripMenuItemStartupOnBoot.Checked = startupManager.Startup;
- toolStripMenuItemStartupOnBootContext.Checked = startupManager.Startup;
- }
-
- private void help_DoubleClick(object sender, EventArgs e)
- {
- Dependencies.OpenLink(Dependencies.SDTURL);
- }
-
- private void toolStripMenuItemAlwaysOnTop_Click(object sender, EventArgs e)
- {
- TopMost = !TopMost;
- toolStripMenuItemAlwaysOnTop.Checked = TopMost;
- toolStripMenuItemAlwaysOnTopContext.Checked = TopMost;
- Settings.Default.AlwaysOnTop = toolStripMenuItemAlwaysOnTop.Checked;
- }
-
- private void checkForUpdates_Click(object sender, EventArgs e)
- {
- Instance.RunUpdater(Text, true);
- }
- }
-}
diff --git a/FanControl/FanControlForm.resx b/FanControl/FanControlForm.resx
deleted file mode 100644
index 87f2860..0000000
--- a/FanControl/FanControlForm.resx
+++ /dev/null
@@ -1,158 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- 1188, 17
-
-
- 955, 18
-
-
- 8, 6
-
-
-
-
- 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
-
-
-
- 651, 17
-
-
- 1477, 16
-
-
-
- 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
-
-
-
\ No newline at end of file
diff --git a/FanControl/FanController.cs b/FanControl/FanController.cs
deleted file mode 100644
index d0778f5..0000000
--- a/FanControl/FanController.cs
+++ /dev/null
@@ -1,163 +0,0 @@
-using LibreHardwareMonitor.Hardware;
-using LibreHardwareMonitor.Hardware.CPU;
-using Microsoft.VisualBasic.Devices;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Diagnostics.Metrics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using CommonHelpers;
-
-namespace FanControl
-{
- [TypeConverter(typeof(ExpandableObjectConverter))]
- [RefreshProperties(RefreshProperties.Repaint)]
- internal partial class FanController : IDisposable
- {
- [CategoryAttribute("Fan")]
- public FanMode Mode { get; private set; } = FanMode.Default;
-
- [CategoryAttribute("Fan")]
- public bool KernelDriversLoaded
- {
- get => Instance.UseKernelDrivers;
- }
-
- [CategoryAttribute("Fan")]
- [NotifyParentProperty(true)]
-
- public ushort? CurrentRPM { get; private set; }
-
- [CategoryAttribute("Fan")]
- [NotifyParentProperty(true)]
-
- public ushort DesiredRPM { get; private set; }
-
- [CategoryAttribute("Board")]
- public String PDVersion { get; private set; } = Vlv0100.Instance.FirmwareVersion.ToString("X");
-
- public FanController()
- {
- }
-
- private void visitHardware(IHardware hardware)
- {
- Dictionary matched = new Dictionary();
-
- foreach (ISensor hwSensor in hardware.Sensors)
- {
- foreach (var sensor in allSensors.Values)
- {
- if (sensor.Matches(hwSensor))
- matched[sensor] = hwSensor;
- }
- }
-
- if (matched.Any())
- {
- hardware.Update();
- foreach (var sensor in matched)
- sensor.Key.Update(sensor.Value, Mode);
- }
-
- foreach (IHardware subhardware in hardware.SubHardware)
- {
- visitHardware(subhardware);
- }
- }
-
- private ushort getDesiredRPM()
- {
- ushort rpm = 0;
- foreach (var sensor in allSensors.Values)
- if (sensor.CalculatedRPM.HasValue)
- rpm = Math.Max(rpm, sensor.CalculatedRPM.Value);
- return rpm;
- }
-
- [Browsable(false)]
- public bool IsActive
- {
- get { return Vlv0100.Instance.IsOpen; }
- }
-
- public void Update(bool showForDefault = false)
- {
- var mutex = Instance.WaitGlobalMutex(200);
- if (mutex is null)
- {
- // If we cannot acquire mutex slightly increase FAN to compensate just in case
- Vlv0100.Instance.SetFanDesiredRPM((ushort)(Vlv0100.Instance.GetFanDesiredRPM() * 110 / 100));
- return;
- }
-
- try
- {
- if (AntiCheatSettings.Default.NotYet || Mode == FanMode.Default && !showForDefault)
- {
- Instance.UseKernelDrivers = false;
- CurrentRPM = null;
- DesiredRPM = 0;
- foreach (var sensor in allSensors.Values)
- sensor.Reset();
- return;
- }
- else if (!Vlv0100.Instance.IsOpen)
- {
- Instance.UseKernelDrivers = true;
- SetMode(Mode);
- }
-
- foreach (var sensor in allSensors.Values)
- sensor.Reset();
-
- foreach (var hardware in Instance.HardwareComputer.Hardware)
- visitHardware(hardware);
- }
- finally
- {
- mutex.ReleaseMutex();
- }
-
- allSensors["Batt"].Update("VLV0100", Vlv0100.Instance.GetBattTemperature(), Mode);
-
- Vlv0100.Instance.SetFanDesiredRPM(getDesiredRPM());
-
- CurrentRPM = Vlv0100.Instance.GetFanRPM();
- DesiredRPM = Vlv0100.Instance.GetFanDesiredRPM();
- }
-
- public void SetMode(FanMode mode)
- {
- switch (mode)
- {
- case FanMode.Default:
- Vlv0100.Instance.SetFanControl(false);
- break;
-
- default:
- Instance.UseKernelDrivers = true;
- Vlv0100.Instance.SetFanControl(true);
- break;
- }
-
- this.Mode = mode;
- }
-
- public bool IsAnyInvalid()
- {
- foreach (var sensor in allSensors.Values)
- {
- if (!sensor.IsValid(Mode))
- return true;
- }
- return false;
- }
-
- public void Dispose()
- {
- }
- }
-}
diff --git a/FanControl/FanControllerSensors.cs b/FanControl/FanControllerSensors.cs
deleted file mode 100644
index a585255..0000000
--- a/FanControl/FanControllerSensors.cs
+++ /dev/null
@@ -1,222 +0,0 @@
-using CommonHelpers;
-using LibreHardwareMonitor.Hardware;
-using System.ComponentModel;
-
-namespace FanControl
-{
- internal partial class FanController
- {
- private Dictionary allSensors = new Dictionary
- {
- {
- "APU", new FanSensor()
- {
- // TODO: Is this correct?
- HardwareNames = { "AMD Custom APU 0405", "AMD Custom APU 0932" },
- HardwareType = HardwareType.Cpu,
- SensorName = "Package",
- SensorType = SensorType.Power,
- ValueDeadZone = 0.1f,
- AvgSamples = 20,
- MaxValue = 25, // TODO: On resume a bogus value is returned
- Profiles = new Dictionary()
- {
- {
- FanMode.Max, new FanSensor.Profile()
- {
- Type = FanSensor.Profile.ProfileType.Constant,
- MinRPM = CommonHelpers.Vlv0100.MAX_FAN_RPM
- }
- },
- {
- FanMode.SteamOS, new FanSensor.Profile()
- {
- Type = FanSensor.Profile.ProfileType.Constant,
- MinRPM = 1500
- }
- },
- {
- FanMode.Silent, new FanSensor.Profile()
- {
- Type = FanSensor.Profile.ProfileType.Constant,
- MinRPM = 1500
- }
- },
- }
- }
- },
- {
- "CPU", new FanSensor()
- {
- HardwareNames = { "AMD Custom APU 0405", "AMD Custom APU 0932" },
- HardwareType = HardwareType.Cpu,
- SensorName = "Core (Tctl/Tdie)",
- SensorType = SensorType.Temperature,
- ValueDeadZone = 0.0f,
- AvgSamples = 20,
- Profiles = new Dictionary()
- {
- {
- FanMode.SteamOS, new FanSensor.Profile()
- {
- Type = FanSensor.Profile.ProfileType.Quadratic,
- MinInput = 55,
- MaxInput = 90,
- A = 2.286f,
- B = -188.6f,
- C = 5457.0f
- }
- },
- {
- FanMode.Silent, new FanSensor.Profile()
- {
- Type = FanSensor.Profile.ProfileType.Exponential,
- MinInput = 40,
- MaxInput = 95,
- A = 1.28f,
- B = Settings.Default.Silent4000RPMTemp - 28,
- C = 3000f
- }
- },
- }
- }
- },
- {
- "GPU", new FanSensor()
- {
- HardwareNames = { "AMD Custom GPU 0405", "AMD Custom GPU 0932" },
- HardwareType = HardwareType.GpuAmd,
- SensorName = "GPU Core",
- SensorType = SensorType.Temperature,
- ValueDeadZone = 0.0f,
- InvalidValue = 5.0f,
- AvgSamples = 20,
- Profiles = new Dictionary()
- {
- {
- FanMode.SteamOS, new FanSensor.Profile()
- {
- Type = FanSensor.Profile.ProfileType.Quadratic,
- MinInput = 55,
- MaxInput = 90,
- A = 2.286f,
- B = -188.6f,
- C = 5457.0f
- }
- },
- {
- FanMode.Silent, new FanSensor.Profile()
- {
- Type = FanSensor.Profile.ProfileType.Exponential,
- MinInput = 40,
- MaxInput = 95,
- A = 1.28f,
- B = Settings.Default.Silent4000RPMTemp - 28,
- C = 3000f
- }
- },
- }
- }
- },
- {
- "SSD", new FanSensor()
- {
- HardwareType = HardwareType.Storage,
- SensorName = "Temperature",
- SensorType = SensorType.Temperature,
- ValueDeadZone = 0.5f,
- Profiles = new Dictionary()
- {
- {
- FanMode.SteamOS, new FanSensor.Profile()
- {
- Type = FanSensor.Profile.ProfileType.Pid,
- MinInput = 30,
- MaxInput = 70,
- MaxRPM = 3000,
- PidSetPoint = 70,
- Kp = 0,
- Ki = -20,
- Kd = 0
- }
- },
- {
- FanMode.Silent, new FanSensor.Profile()
- {
- Type = FanSensor.Profile.ProfileType.Pid,
- MinInput = 30,
- MaxInput = 70,
- MaxRPM = 3000,
- PidSetPoint = 70,
- Kp = 0,
- Ki = -20,
- Kd = 0
- }
- }
- }
- }
- },
- {
- "Batt", new FanSensor()
- {
- HardwareType = HardwareType.Battery,
- SensorName = "Temperature",
- SensorType = SensorType.Temperature,
- ValueDeadZone = 0.0f,
- Profiles = new Dictionary()
- {
- {
- FanMode.SteamOS, new FanSensor.Profile()
- {
- // If battery goes over 40oC require 2kRPM
- Type = FanSensor.Profile.ProfileType.Constant,
- MinInput = 0,
- MaxInput = 40,
- MinRPM = 0,
- MaxRPM = 2000,
- }
- },
- {
- FanMode.Silent, new FanSensor.Profile()
- {
- // If battery goes over 40oC require 2kRPM
- Type = FanSensor.Profile.ProfileType.Constant,
- MinInput = 0,
- MaxInput = 40,
- MinRPM = 0,
- MaxRPM = 2000,
- }
- }
- }
- }
- }
- };
-
- #region Sensor Properties for Property Grid
- [CategoryAttribute("Sensor - APU"), DisplayName("Name")]
- public String? APUName { get { return allSensors["APU"].Name; } }
- [CategoryAttribute("Sensor - APU"), DisplayName("Power")]
- public String? APUPower { get { return allSensors["APU"].FormattedValue(); } }
-
- [CategoryAttribute("Sensor - CPU"), DisplayName("Name")]
- public String? CPUName { get { return allSensors["CPU"].Name; } }
- [CategoryAttribute("Sensor - CPU"), DisplayName("Temperature")]
- public String? CPUTemperature { get { return allSensors["CPU"].FormattedValue(); } }
-
- [CategoryAttribute("Sensor - GPU"), DisplayName("Name")]
- public String? GPUName { get { return allSensors["GPU"].Name; } }
- [CategoryAttribute("Sensor - GPU"), DisplayName("Temperature")]
- public String? GPUTemperature { get { return allSensors["GPU"].FormattedValue(); } }
-
- [CategoryAttribute("Sensor - SSD"), DisplayName("Name")]
- public String? SSDName { get { return allSensors["SSD"].Name; } }
- [CategoryAttribute("Sensor - SSD"), DisplayName("Temperature")]
- public String? SSDTemperature { get { return allSensors["SSD"].FormattedValue(); } }
- [CategoryAttribute("Sensor - Battery"), DisplayName("Name")]
- public String? BatteryName { get { return allSensors["Batt"].Name; } }
- [CategoryAttribute("Sensor - Battery"), DisplayName("Temperature")]
- public String? BatteryTemperature { get { return allSensors["Batt"].FormattedValue(); } }
-
- #endregion Sensor Properties for Property Grid
- }
-}
diff --git a/FanControl/FanSensor.cs b/FanControl/FanSensor.cs
deleted file mode 100644
index cdf5f40..0000000
--- a/FanControl/FanSensor.cs
+++ /dev/null
@@ -1,254 +0,0 @@
-using CommonHelpers;
-using LibreHardwareMonitor.Hardware;
-using System.ComponentModel;
-
-namespace FanControl
-{
- [TypeConverter(typeof(ExpandableObjectConverter))]
- internal class FanSensor
- {
- public string? Name { get; internal set; }
- public float? Value { get; internal set; }
- public ushort? CalculatedRPM { get; internal set; }
-
- public float ValueDeadZone { get; set; }
- public int AvgSamples { get; set; } = 5;
- public float InvalidValue { get; set; } = 0.0f;
- public float? MaxValue { get; set; }
-
- internal string HardwareName { get; set; } = "";
- internal IList HardwareNames { get; set; } = new List();
- internal HardwareType HardwareType { get; set; }
- internal string SensorName { get; set; } = "";
- internal SensorType SensorType { get; set; }
-
- private List AllSamples = new List();
-
- internal Dictionary Profiles { get; set; } = new Dictionary();
-
- internal class Profile
- {
- public enum ProfileType
- {
- Constant,
- Quadratic,
- Pid,
- Exponential
- }
-
- public ProfileType Type { get; set; }
- public float MinInput { get; set; }
- public float MaxInput { get; set; } = 90;
- public ushort MinRPM { get; set; }
- public ushort MaxRPM { get; set; } = ushort.MaxValue;
-
- public float A { get; set; }
- public float B { get; set; }
- public float C { get; set; }
-
- public float Kp { get; set; }
- public float Ki { get; set; }
- public float Kd { get; set; }
- public float PidSetPoint { get; set; }
-
- private float? pidLastInput { get; set; }
- private float pidLastError { get; set; }
- private DateTime pidLastTime { get; set; }
- private float pidP { get; set; }
- private float pidI { get; set; }
- private float pidD { get; set; }
-
- public ushort CalculateRPM(float input)
- {
- float rpm = 0;
-
- switch (Type)
- {
- case ProfileType.Constant:
- rpm = MinRPM;
- break;
-
- case ProfileType.Quadratic:
- rpm = calculateQuadraticRPM(input);
- break;
-
- case ProfileType.Pid:
- rpm = calculatePidRPM(input);
- break;
-
- case ProfileType.Exponential:
- rpm = calculateExponentialRPM(input);
- break;
- }
-
- if (input < MinInput)
- rpm = MinRPM;
- else if (input > MaxInput)
- rpm = MaxRPM;
-
- rpm = Math.Clamp(rpm, (float)MinRPM, (float)MaxRPM);
-
- return (ushort)rpm;
- }
-
- private float calculateQuadraticRPM(float input)
- {
- return A * input * input + B * input + C;
- }
-
- private float calculatePidRPM(float input)
- {
- if (!pidLastInput.HasValue)
- {
- pidLastInput = input;
- pidLastTime = DateTime.Now;
- return 0;
- }
-
- float error = PidSetPoint - input;
- float dInput = input - pidLastInput.Value;
- float dt = Math.Min((float)(DateTime.Now - pidLastTime).TotalSeconds, 1.0f);
-
- this.pidP = Kp * error;
- this.pidI += Ki * error * dt;
- this.pidI = Math.Min(this.pidI, this.MaxRPM);
- this.pidD -= Kd * dInput / dt;
-
- pidLastInput = input;
- pidLastError = error;
- pidLastTime = DateTime.Now;
-
- return pidP + pidI + pidD;
- }
-
- private float calculateExponentialRPM(float input)
- {
- return (float)(Math.Pow(A, input - B) + C);
- }
- }
-
- public void Reset()
- {
- Name = null;
- Value = null;
- CalculatedRPM = 0;
- }
-
- private bool MatchesHardwareName(string sensorHardwareName)
- {
- if (HardwareNames.Count > 0)
- {
- if (HardwareNames.Any(hardwareName => sensorHardwareName.StartsWith(hardwareName)))
- return true;
- }
-
- // Empty string matches always
- if (HardwareName.Length == 0)
- return true;
-
- if (sensorHardwareName.StartsWith(HardwareName))
- return true;
-
- return false;
- }
-
- public bool Matches(ISensor sensor)
- {
- return sensor != null &&
- sensor.Hardware.HardwareType == HardwareType &&
- MatchesHardwareName(sensor.Hardware.Name) &&
- sensor.SensorType == SensorType &&
- sensor.Name == SensorName;
- }
-
- public bool Update(ISensor hwSensor, FanMode mode)
- {
- if (!Matches(hwSensor))
- return false;
-
- System.Diagnostics.Trace.WriteLine(String.Format("{0}: {1} {2}, value: {3}, type: {4}",
- hwSensor.Identifier, hwSensor.Hardware.Name, hwSensor.Name, hwSensor.Value, hwSensor.SensorType));
-
- return Update(
- String.Format("{0} {1}", hwSensor.Hardware.Name, hwSensor.Name),
- hwSensor.Value, mode);
- }
-
- public bool Update(string name, float? newValue, FanMode mode)
- {
- if (!newValue.HasValue || newValue <= InvalidValue)
- return false;
-
- if (MaxValue.HasValue)
- newValue = Math.Min(newValue.Value, MaxValue.Value);
-
- if (AllSamples.Count == 0 || Math.Abs(AllSamples.Last() - newValue.Value) >= ValueDeadZone)
- {
- AllSamples.Add(newValue.Value);
- while (AllSamples.Count > AvgSamples)
- AllSamples.RemoveAt(0);
- }
-
- float avgValue = 0.0f;
- foreach (var value in AllSamples)
- avgValue += value;
-
- Name = name;
- Value = avgValue / AllSamples.Count;
- CalculatedRPM = CalculateRPM(mode);
- return true;
- }
-
- public bool IsValid(FanMode mode)
- {
- // If we have profile, but no sensor value to consume it
- // it is invalid
- if (Profiles.ContainsKey(mode) && !Value.HasValue)
- return false;
-
- return true;
- }
-
- private String Unit()
- {
- switch (SensorType)
- {
- case SensorType.Temperature:
- return "℃";
-
- case SensorType.Power:
- return "W";
-
- default:
- return "";
- }
- }
-
- public String FormattedValue()
- {
- if (!Value.HasValue)
- return "";
-
- String value = "";
-
- if (AllSamples.Count > 0)
- value += AllSamples.Last().ToString("F1") + Unit();
-
- value += " (avg: " + Value.Value.ToString("F1") + Unit() + ")";
-
- if (CalculatedRPM.HasValue)
- value += " (" + CalculatedRPM.ToString() + "RPM)";
-
- return value;
- }
-
- public ushort? CalculateRPM(FanMode mode)
- {
- if (!Profiles.ContainsKey(mode) || !Value.HasValue)
- return null;
-
- var profile = Profiles[mode];
- return profile.CalculateRPM(Value.Value);
- }
- }
-}
diff --git a/FanControl/Program.cs b/FanControl/Program.cs
deleted file mode 100644
index a447a9f..0000000
--- a/FanControl/Program.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using LibreHardwareMonitor.Hardware;
-using CommonHelpers;
-
-namespace FanControl
-{
- internal class Program
- {
- static void Main(string[] args)
- {
- Instance.WithSentry(() =>
- {
- ApplicationConfiguration.Initialize();
- Application.Run(new FanControlForm());
- });
- }
- }
-}
diff --git a/FanControl/Resources.Designer.cs b/FanControl/Resources.Designer.cs
deleted file mode 100644
index 91cfc18..0000000
--- a/FanControl/Resources.Designer.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// This code was generated by a tool.
-// Runtime Version:4.0.30319.42000
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-//
-//------------------------------------------------------------------------------
-
-namespace FanControl {
- using System;
-
-
- ///
- /// A strongly-typed resource class, for looking up localized strings, etc.
- ///
- // This class was auto-generated by the StronglyTypedResourceBuilder
- // class via a tool like ResGen or Visual Studio.
- // To add or remove a member, edit your .ResX file then rerun ResGen
- // with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class Resources {
-
- private static global::System.Resources.ResourceManager resourceMan;
-
- private static global::System.Globalization.CultureInfo resourceCulture;
-
- [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Resources() {
- }
-
- ///
- /// Returns the cached ResourceManager instance used by this class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager {
- get {
- if (object.ReferenceEquals(resourceMan, null)) {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FanControl.Resources", typeof(Resources).Assembly);
- resourceMan = temp;
- }
- return resourceMan;
- }
- }
-
- ///
- /// Overrides the current thread's CurrentUICulture property for all
- /// resource lookups using this strongly typed resource class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture {
- get {
- return resourceCulture;
- }
- set {
- resourceCulture = value;
- }
- }
-
- ///
- /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
- ///
- internal static System.Drawing.Icon fan {
- get {
- object obj = ResourceManager.GetObject("fan", resourceCulture);
- return ((System.Drawing.Icon)(obj));
- }
- }
-
- ///
- /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
- ///
- internal static System.Drawing.Icon fan_white {
- get {
- object obj = ResourceManager.GetObject("fan_white", resourceCulture);
- return ((System.Drawing.Icon)(obj));
- }
- }
- }
-}
diff --git a/FanControl/Resources.resx b/FanControl/Resources.resx
deleted file mode 100644
index 6cc159e..0000000
--- a/FanControl/Resources.resx
+++ /dev/null
@@ -1,127 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
-
- Resources\fan.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
-
-
- Resources\fan-white.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
-
-
\ No newline at end of file
diff --git a/FanControl/Resources/fan-white.ico b/FanControl/Resources/fan-white.ico
deleted file mode 100644
index 61c8cbb..0000000
Binary files a/FanControl/Resources/fan-white.ico and /dev/null differ
diff --git a/FanControl/Resources/fan.ico b/FanControl/Resources/fan.ico
deleted file mode 100644
index a5aef5b..0000000
Binary files a/FanControl/Resources/fan.ico and /dev/null differ
diff --git a/FanControl/Settings.cs b/FanControl/Settings.cs
deleted file mode 100644
index 82d769d..0000000
--- a/FanControl/Settings.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-using CommonHelpers;
-
-namespace FanControl
-{
- internal sealed class Settings : BaseSettings
- {
- public static readonly Settings Default = new Settings();
-
- public Settings() : base("Settings")
- {
- TouchSettings = true;
- }
-
- public FanMode FanMode
- {
- get { return Get("FanMode", CommonHelpers.FanMode.Default); }
- set { Set("FanMode", value); }
- }
-
- public bool AlwaysOnTop
- {
- get { return Get("AlwaysOnTop", true); }
- set { Set("AlwaysOnTop", value); }
- }
-
- public int Silent4000RPMTemp
- {
- get { return ClampSilent4000RPMTemp(Get("Silent4000RPMTemp", 85)); }
- set { Set("Silent4000RPMTemp", ClampSilent4000RPMTemp(value)); }
- }
-
- public bool EnableExperimentalFeatures
- {
- get { return Instance.IsDEBUG; }
- }
-
- private int ClampSilent4000RPMTemp(int value)
- {
- return Math.Clamp(value, 70, 90);
- }
- }
-}
diff --git a/FanControl/app.manifest b/FanControl/app.manifest
deleted file mode 100644
index 1c97d89..0000000
--- a/FanControl/app.manifest
+++ /dev/null
@@ -1,60 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- true
-
-
-
-
-
-
-
diff --git a/PerformanceOverlay/Controller.cs b/PerformanceOverlay/Controller.cs
index 6be3a81..0c52efc 100644
--- a/PerformanceOverlay/Controller.cs
+++ b/PerformanceOverlay/Controller.cs
@@ -40,7 +40,6 @@ namespace PerformanceOverlay
SharedData_Update();
Instance.Open(TitleWithVersion, Settings.Default.EnableKernelDrivers, "Global\\PerformanceOverlay");
- Instance.RunUpdater(TitleWithVersion);
if (Instance.WantsRunOnStartup)
startupManager.Startup = true;
@@ -261,13 +260,6 @@ namespace PerformanceOverlay
var osdMode = Settings.Default.OSDMode;
- // If Power Control is visible use temporarily full OSD
- if (Settings.Default.EnableFullOnPowerControl)
- {
- if (SharedData.GetExistingValue(out var value) && value.Current == PowerControlVisible.Yes)
- osdMode = OverlayMode.Full;
- }
-
var osdOverlay = Overlays.GetOSD(osdMode, sensors);
try
diff --git a/PerformanceOverlay/PerformanceOverlay.csproj b/PerformanceOverlay/PerformanceOverlay.csproj
index 260648e..8286234 100644
--- a/PerformanceOverlay/PerformanceOverlay.csproj
+++ b/PerformanceOverlay/PerformanceOverlay.csproj
@@ -49,4 +49,13 @@
-
\ No newline at end of file
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+
+
diff --git a/PerformanceOverlay/Settings.cs b/PerformanceOverlay/Settings.cs
index b573f2a..3b57dcc 100644
--- a/PerformanceOverlay/Settings.cs
+++ b/PerformanceOverlay/Settings.cs
@@ -35,12 +35,6 @@ namespace PerformanceOverlay
set { Set("ShowOSD", value); }
}
- public bool EnableFullOnPowerControl
- {
- get { return Get("EnableFullOnPowerControl", false); }
- set { Set("EnableFullOnPowerControl", value); }
- }
-
public bool EnableKernelDrivers
{
get { return Get("EnableKernelDrivers", false); }
diff --git a/PowerControl/Controller.cs b/PowerControl/Controller.cs
deleted file mode 100644
index 6f97b5b..0000000
--- a/PowerControl/Controller.cs
+++ /dev/null
@@ -1,488 +0,0 @@
-using CommonHelpers;
-using ExternalHelpers;
-using hidapi;
-using Microsoft.Win32;
-using PowerControl.External;
-using PowerControl.Helpers;
-using RTSSSharedMemoryNET;
-using System.ComponentModel;
-using System.Diagnostics;
-
-namespace PowerControl
-{
- internal class Controller : IDisposable
- {
- public const String Title = "Power Control";
- public static readonly String TitleWithVersion = Title + " v" + Application.ProductVersion.ToString();
- public const int KeyPressRepeatTime = 400;
- public const int KeyPressNextRepeatTime = 90;
-
- Container components = new Container();
- System.Windows.Forms.NotifyIcon notifyIcon;
- StartupManager startupManager = new StartupManager(Title);
-
- Menu.MenuRoot rootMenu = MenuStack.Root;
- OSD osd;
- System.Windows.Forms.Timer osdDismissTimer;
- bool isOSDToggled = false;
-
- bool wasInternalDisplayConnected;
-
- hidapi.HidDevice neptuneDevice = new hidapi.HidDevice(0x28de, 0x1205, 64);
- SDCInput neptuneDeviceState = new SDCInput();
- DateTime? neptuneDeviceNextKey;
- System.Windows.Forms.Timer neptuneTimer;
-
- ProfilesController? profilesController;
-
- SharedData sharedData = SharedData.CreateNew();
-
- static Controller()
- {
- //Dependencies.ValidateHidapi(TitleWithVersion);
- //Dependencies.ValidateRTSSSharedMemoryNET(TitleWithVersion);
- }
-
- public Controller()
- {
- Instance.OnUninstall(() =>
- {
- startupManager.Startup = false;
- });
-
- Log.CleanupLogFiles(DateTime.UtcNow.AddDays(-7));
- Log.LogToFile = true;
- Log.LogToFileDebug = true;
-
- Instance.RunOnce(TitleWithVersion, "Global\\PowerControl");
- Instance.RunUpdater(TitleWithVersion);
-
- if (Instance.WantsRunOnStartup)
- startupManager.Startup = true;
-
- var contextMenu = new System.Windows.Forms.ContextMenuStrip(components);
-
- var notRunningRTSSItem = contextMenu.Items.Add("&RTSS is not running");
- notRunningRTSSItem.Enabled = false;
- contextMenu.Opening += delegate { notRunningRTSSItem.Visible = Dependencies.EnsureRTSS(null) && !OSDHelpers.IsLoaded; };
-
- rootMenu.Init();
- rootMenu.Visible = false;
- rootMenu.Update();
- rootMenu.CreateMenu(contextMenu);
- rootMenu.VisibleChanged += delegate { updateOSD(); };
- contextMenu.Items.Add(new ToolStripSeparator());
-
- if (Settings.Default.EnableExperimentalFeatures)
- {
- var installEDIDItem = contextMenu.Items.Add("Install &Resolutions");
- installEDIDItem.Click += delegate { Helpers.AMD.EDID.SetEDID(Resources.CRU_SteamDeck); };
- var replaceEDIDItem = contextMenu.Items.Add("Replace &Resolutions");
- replaceEDIDItem.Click += delegate { Helpers.AMD.EDID.SetEDID(new byte[0]); Helpers.AMD.EDID.SetEDID(Resources.CRU_SteamDeck); };
- var uninstallEDIDItem = contextMenu.Items.Add("Revert &Resolutions");
- uninstallEDIDItem.Click += delegate { Helpers.AMD.EDID.SetEDID(new byte[0]); };
- contextMenu.Opening += delegate
- {
- if (ExternalHelpers.DisplayConfig.IsInternalConnected == true)
- {
- var edid = Helpers.AMD.EDID.GetEDID() ?? new byte[0];
- var edidInstalled = Resources.CRU_SteamDeck.SequenceEqual(edid);
- installEDIDItem.Visible = edid.Length <= 128;
- replaceEDIDItem.Visible = !edidInstalled && edid.Length > 128;
- uninstallEDIDItem.Visible = edid.Length > 128;
- }
- else
- {
- installEDIDItem.Visible = false;
- replaceEDIDItem.Visible = false;
- uninstallEDIDItem.Visible = false;
- }
- };
- contextMenu.Items.Add(new ToolStripSeparator());
- }
-
- if (startupManager.IsAvailable)
- {
- var startupItem = new ToolStripMenuItem("Run On Startup");
- startupItem.Checked = startupManager.Startup;
- startupItem.Click += delegate
- {
- startupManager.Startup = !startupManager.Startup;
- startupItem.Checked = startupManager.Startup;
- };
- contextMenu.Items.Add(startupItem);
- }
-
- var missingRTSSItem = contextMenu.Items.Add("&Install missing RTSS");
- missingRTSSItem.Click += delegate { Dependencies.OpenLink(Dependencies.RTSSURL); };
- contextMenu.Opening += delegate { missingRTSSItem.Visible = !Dependencies.EnsureRTSS(null); };
-
- var showGameProfilesItem = contextMenu.Items.Add("Show Game &Profiles");
- showGameProfilesItem.Click += delegate { Dependencies.OpenLink(Helper.ProfileSettings.UserProfilesPath); };
- contextMenu.Items.Add(new ToolStripSeparator());
-
- var checkForUpdatesItem = contextMenu.Items.Add("&Check for Updates");
- checkForUpdatesItem.Click += delegate { Instance.RunUpdater(TitleWithVersion, true); };
-
- var helpItem = contextMenu.Items.Add("&Help");
- helpItem.Click += delegate { Dependencies.OpenLink(Dependencies.SDTURL); };
- contextMenu.Items.Add(new ToolStripSeparator());
-
- var exitItem = contextMenu.Items.Add("&Exit");
- exitItem.Click += ExitItem_Click;
-
- notifyIcon = new System.Windows.Forms.NotifyIcon(components);
- notifyIcon.Icon = WindowsDarkMode.IsDarkModeEnabled ? Resources.traffic_light_outline_light : Resources.traffic_light_outline;
- notifyIcon.Text = TitleWithVersion;
- notifyIcon.Visible = true;
- notifyIcon.ContextMenuStrip = contextMenu;
-
- // Fix first time context menu position
- contextMenu.Show();
- contextMenu.Close();
-
- osdDismissTimer = new System.Windows.Forms.Timer(components);
- osdDismissTimer.Interval = 3000;
- osdDismissTimer.Tick += delegate (object? sender, EventArgs e)
- {
- if (!isOSDToggled)
- {
- hideOSD();
- }
- };
-
- var osdTimer = new System.Windows.Forms.Timer(components);
- osdTimer.Tick += OsdTimer_Tick;
- osdTimer.Interval = 250;
- osdTimer.Enabled = true;
-
- profilesController = new ProfilesController();
-
- GlobalHotKey.RegisterHotKey(Settings.Default.MenuUpKey, () =>
- {
- if (!OSDHelpers.IsOSDForeground())
- return;
- rootMenu.Next(-1);
- setDismissTimer();
- dismissNeptuneInput();
- }, true);
-
- GlobalHotKey.RegisterHotKey(Settings.Default.MenuDownKey, () =>
- {
- if (!OSDHelpers.IsOSDForeground())
- return;
- rootMenu.Next(1);
- setDismissTimer();
- dismissNeptuneInput();
- }, true);
-
- GlobalHotKey.RegisterHotKey(Settings.Default.MenuLeftKey, () =>
- {
- if (!OSDHelpers.IsOSDForeground())
- return;
- rootMenu.SelectNext(-1);
- setDismissTimer();
- dismissNeptuneInput();
- });
-
- GlobalHotKey.RegisterHotKey(Settings.Default.MenuRightKey, () =>
- {
- if (!OSDHelpers.IsOSDForeground())
- return;
- rootMenu.SelectNext(1);
- setDismissTimer();
- dismissNeptuneInput();
- });
-
- GlobalHotKey.RegisterHotKey(Settings.Default.MenuToggle, () =>
- {
- isOSDToggled = !rootMenu.Visible;
-
- if (!OSDHelpers.IsOSDForeground())
- return;
-
- if (isOSDToggled)
- {
- showOSD();
- }
- else
- {
- hideOSD();
- }
- }, true);
-
- if (Settings.Default.EnableNeptuneController)
- {
- neptuneTimer = new System.Windows.Forms.Timer(components);
- neptuneTimer.Interval = 1000 / 60;
- neptuneTimer.Tick += NeptuneTimer_Tick;
- neptuneTimer.Enabled = true;
-
- neptuneDevice.OnInputReceived += NeptuneDevice_OnInputReceived;
- neptuneDevice.OpenDevice();
- neptuneDevice.BeginRead();
- }
-
- if (Settings.Default.EnableVolumeControls)
- {
- GlobalHotKey.RegisterHotKey("VolumeUp", () =>
- {
- if (neptuneDeviceState.buttons5.HasFlag(SDCButton5.BTN_QUICK_ACCESS))
- rootMenu.Select("Brightness");
- else
- rootMenu.Select("Volume");
- rootMenu.SelectNext(1);
- setDismissTimer();
- dismissNeptuneInput();
- });
-
- GlobalHotKey.RegisterHotKey("VolumeDown", () =>
- {
- if (neptuneDeviceState.buttons5.HasFlag(SDCButton5.BTN_QUICK_ACCESS))
- rootMenu.Select("Brightness");
- else
- rootMenu.Select("Volume");
- rootMenu.SelectNext(-1);
- setDismissTimer();
- dismissNeptuneInput();
- });
- }
-
- wasInternalDisplayConnected = ExternalHelpers.DisplayConfig.IsInternalConnected.GetValueOrDefault(false);
- SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
- }
-
- private void OsdTimer_Tick(object? sender, EventArgs e)
- {
- try
- {
- notifyIcon.Text = TitleWithVersion + ". RTSS Version: " + OSD.Version;
- notifyIcon.Icon = WindowsDarkMode.IsDarkModeEnabled ? Resources.traffic_light_outline_light : Resources.traffic_light_outline;
- }
- catch
- {
- notifyIcon.Text = TitleWithVersion + ". RTSS Not Available.";
- notifyIcon.Icon = Resources.traffic_light_outline_red;
- }
-
- var watchedProfiles = profilesController?.WatchedProfiles ?? new string[0];
- if (watchedProfiles.Any())
- notifyIcon.Text += ". Profile: " + string.Join(", ", watchedProfiles);
-
- updateOSD();
- }
-
- private Task NeptuneDevice_OnInputReceived(hidapi.HidDeviceInputReceivedEventArgs e)
- {
- var input = SDCInput.FromBuffer(e.Buffer);
-
- var filteredInput = new SDCInput()
- {
- buttons0 = input.buttons0,
- buttons1 = input.buttons1,
- buttons2 = input.buttons2,
- buttons3 = input.buttons3,
- buttons4 = input.buttons4,
- buttons5 = input.buttons5
- };
-
- if (!neptuneDeviceState.Equals(filteredInput))
- {
- neptuneDeviceState = filteredInput;
- neptuneDeviceNextKey = null;
- }
-
- // Consume only some events to avoid under-running SWICD
- if (!neptuneDeviceState.buttons5.HasFlag(SDCButton5.BTN_QUICK_ACCESS))
- Thread.Sleep(50);
-
- return new Task(() => { });
- }
-
- private void dismissNeptuneInput()
- {
- neptuneDeviceNextKey = DateTime.UtcNow.AddDays(1);
- }
-
- private void NeptuneTimer_Tick(object? sender, EventArgs e)
- {
- var input = neptuneDeviceState;
-
- if (neptuneDeviceNextKey == null)
- neptuneDeviceNextKey = DateTime.UtcNow.AddMilliseconds(KeyPressRepeatTime);
- else if (neptuneDeviceNextKey < DateTime.UtcNow)
- neptuneDeviceNextKey = DateTime.UtcNow.AddMilliseconds(KeyPressNextRepeatTime);
- else
- return; // otherwise it did not yet trigger
-
- // Reset sequence: 3 dots + L4|R4|L5|R5
- if (input.buttons0 == SDCButton0.BTN_L5 &&
- input.buttons1 == SDCButton1.BTN_R5 &&
- input.buttons2 == 0 &&
- input.buttons3 == 0 &&
- input.buttons4 == (SDCButton4.BTN_L4 | SDCButton4.BTN_R4) &&
- input.buttons5 == SDCButton5.BTN_QUICK_ACCESS)
- {
- dismissNeptuneInput();
- rootMenu.Show();
- rootMenu.Reset();
- notifyIcon.ShowBalloonTip(3000, TitleWithVersion, "Settings were reset to default.", ToolTipIcon.Info);
- return;
- }
-
- // Display reset sequence
- if (input.buttons0 == (SDCButton0.BTN_L1 | SDCButton0.BTN_R1) &&
- input.buttons1 == 0 &&
- input.buttons2 == 0 &&
- input.buttons3 == 0 &&
- input.buttons4 == 0 &&
- input.buttons5 == SDCButton5.BTN_QUICK_ACCESS)
- {
- dismissNeptuneInput();
- DisplayResolutionController.ResetCurrentResolution();
- notifyIcon.ShowBalloonTip(3000, TitleWithVersion, "Resolution was reset.", ToolTipIcon.Info);
- return;
- }
-
- if (!neptuneDeviceState.buttons5.HasFlag(SDCButton5.BTN_QUICK_ACCESS) || !OSDHelpers.IsOSDForeground())
- {
- // schedule next repeat far in the future
- dismissNeptuneInput();
- hideOSD();
- return;
- }
-
- rootMenu.Show();
- setDismissTimer(false);
-
- if (input.buttons1 != 0 || input.buttons2 != 0 || input.buttons3 != 0 || input.buttons4 != 0)
- {
- return;
- }
- else if (input.buttons0 == SDCButton0.BTN_DPAD_LEFT)
- {
- rootMenu.SelectNext(-1);
- }
- else if (input.buttons0 == SDCButton0.BTN_DPAD_RIGHT)
- {
- rootMenu.SelectNext(1);
- }
- else if (input.buttons0 == SDCButton0.BTN_DPAD_UP)
- {
- rootMenu.Next(-1);
- }
- else if (input.buttons0 == SDCButton0.BTN_DPAD_DOWN)
- {
- rootMenu.Next(1);
- }
- }
-
- private void setDismissTimer(bool enabled = true)
- {
- osdDismissTimer.Stop();
- if (enabled)
- osdDismissTimer.Start();
- }
-
- private void hideOSD()
- {
- if (!rootMenu.Visible)
- return;
-
- Trace.WriteLine("Hide OSD");
- rootMenu.Visible = false;
- osdDismissTimer.Stop();
- updateOSD();
- }
-
- private void showOSD()
- {
- if (rootMenu.Visible)
- return;
-
- Trace.WriteLine("Show OSD");
- rootMenu.Update();
- rootMenu.Visible = true;
- updateOSD();
- }
-
- public void updateOSD()
- {
- sharedData.SetValue(new PowerControlSetting()
- {
- Current = rootMenu.Visible ? PowerControlVisible.Yes : PowerControlVisible.No
- });
-
- if (!rootMenu.Visible)
- {
- osdClose();
- return;
- }
-
- try
- {
- // recreate OSD if index 0
- if (OSDHelpers.OSDIndex("Power Control") == 0 && OSD.GetOSDCount() > 1)
- osdClose();
- if (osd == null)
- {
- osd = new OSD("Power Control");
- Trace.WriteLine("Show OSD");
- }
- osd.Update(rootMenu.Render(null));
- }
- catch (SystemException)
- {
- }
- }
-
- private void ExitItem_Click(object? sender, EventArgs e)
- {
- Application.Exit();
- }
-
- public void Dispose()
- {
- using (profilesController) { }
- components.Dispose();
- osdClose();
- }
-
- private void osdClose()
- {
- try
- {
- if (osd != null)
- {
- osd.Dispose();
- Trace.WriteLine("Close OSD");
- }
- osd = null;
- }
- catch (SystemException)
- {
- }
- }
-
- private void SystemEvents_DisplaySettingsChanged(object? sender, EventArgs e)
- {
- var isInternalDisplayConnected = ExternalHelpers.DisplayConfig.IsInternalConnected.GetValueOrDefault(false);
- if (wasInternalDisplayConnected == isInternalDisplayConnected)
- return;
-
- Log.TraceLine("SystemEvents_DisplaySettingsChanged: wasConnected={0}, isConnected={1}",
- wasInternalDisplayConnected, isInternalDisplayConnected);
-
- wasInternalDisplayConnected = isInternalDisplayConnected;
- System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(
- new Action(() =>
- {
- Options.RefreshRate.Instance?.Reset();
- Options.FPSLimit.Instance?.Reset();
-
- rootMenu.Update();
- })
- );
- }
- }
-}
diff --git a/PowerControl/Helpers/AMD/ADL.cs b/PowerControl/Helpers/AMD/ADL.cs
deleted file mode 100644
index 38f5db5..0000000
--- a/PowerControl/Helpers/AMD/ADL.cs
+++ /dev/null
@@ -1,328 +0,0 @@
-#region Copyright
-
-/*******************************************************************************
- Copyright(c) 2008 - 2022 Advanced Micro Devices, Inc. All Rights Reserved.
- Copyright (c) 2002 - 2006 ATI Technologies Inc. All Rights Reserved.
-
- THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
- ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDED BUT NOT LIMITED TO
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
- PARTICULAR PURPOSE.
-
- File: ADL.cs
-
- Purpose: Implements ADL interface
-
- Description: Implements some of the methods defined in ADL interface.
-
- ********************************************************************************/
-
-#endregion Copyright
-
-#region Using
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Runtime.InteropServices;
-using System.Diagnostics;
-using System.Threading;
-using FARPROC = System.IntPtr;
-using HMODULE = System.IntPtr;
-
-#endregion Using
-
-#region ATI.ADL
-
-namespace PowerControl.Helpers.AMD
-{
- #region Export Struct
-
- #region ADLAdapterInfo
- /// ADLAdapterInfo Structure
- [StructLayout(LayoutKind.Sequential)]
- internal struct ADLAdapterInfo
- {
- /// The size of the structure
- int Size;
- /// Adapter Index
- internal int AdapterIndex;
- /// Adapter UDID
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)ADL.ADL_MAX_PATH)]
- internal string UDID;
- /// Adapter Bus Number
- internal int BusNumber;
- /// Adapter Driver Number
- internal int DriverNumber;
- /// Adapter Function Number
- internal int FunctionNumber;
- /// Adapter Vendor ID
- internal int VendorID;
- /// Adapter Adapter name
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)ADL.ADL_MAX_PATH)]
- internal string AdapterName;
- /// Adapter Display name
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)ADL.ADL_MAX_PATH)]
- internal string DisplayName;
- /// Adapter Present status
- internal int Present;
- /// Adapter Exist status
- internal int Exist;
- /// Adapter Driver Path
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)ADL.ADL_MAX_PATH)]
- internal string DriverPath;
- /// Adapter Driver Ext Path
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)ADL.ADL_MAX_PATH)]
- internal string DriverPathExt;
- /// Adapter PNP String
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)ADL.ADL_MAX_PATH)]
- internal string PNPString;
- /// OS Display Index
- internal int OSDisplayIndex;
- }
-
-
- /// ADLAdapterInfo Array
- [StructLayout(LayoutKind.Sequential)]
- internal struct ADLAdapterInfoArray
- {
- /// ADLAdapterInfo Array
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)ADL.ADL_MAX_ADAPTERS)]
- internal ADLAdapterInfo[] ADLAdapterInfo;
- }
- #endregion ADLAdapterInfo
-
- #region ADLDisplayInfo
- /// ADLDisplayID Structure
- [StructLayout(LayoutKind.Sequential)]
- internal struct ADLDisplayID
- {
- /// Display Logical Index
- internal int DisplayLogicalIndex;
- /// Display Physical Index
- internal int DisplayPhysicalIndex;
- /// Adapter Logical Index
- internal int DisplayLogicalAdapterIndex;
- /// Adapter Physical Index
- internal int DisplayPhysicalAdapterIndex;
- }
-
- /// ADLDisplayInfo Structure
- [StructLayout(LayoutKind.Sequential)]
- internal struct ADLDisplayInfo
- {
- /// Display Index
- internal ADLDisplayID DisplayID;
- /// Display Controller Index
- internal int DisplayControllerIndex;
- /// Display Name
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)ADL.ADL_MAX_PATH)]
- internal string DisplayName;
- /// Display Manufacturer Name
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)ADL.ADL_MAX_PATH)]
- internal string DisplayManufacturerName;
- /// Display Type : < The Display type. CRT, TV,CV,DFP are some of display types,
- internal int DisplayType;
- /// Display output type
- internal int DisplayOutputType;
- /// Connector type
- internal int DisplayConnector;
- /// Indicating the display info bits' mask.
- internal int DisplayInfoMask;
- /// Indicating the display info value.
- internal int DisplayInfoValue;
- }
-
- /// ADLAdapterInfo Array
- [StructLayout(LayoutKind.Sequential)]
- internal class ADLDisplayInfoArray
- {
- /// ADLAdapterInfo Array
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)ADL.ADL_MAX_DISPLAYS)]
- internal ADLDisplayInfo[] ADLAdapterInfo;
- }
- #endregion ADLDisplayInfo
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct ADLDisplayEDIDData
- {
- internal int iSize;
- internal int iFlag;
- internal int iEDIDSize;
- internal int iBlockIndex;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)ADL.ADL_MAX_EDIDDATA_SIZE)]
- internal byte[] cEDIDData;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
- internal int[] iReserved;
- };
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct ADLDisplayEDIDDataX2
- {
- internal int iSize;
- internal int iFlag;
- internal int iEDIDSize;
- internal int iIgnored;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)2 * ADL.ADL_MAX_EDIDDATA_SIZE)]
- internal byte[] cEDIDData;
- };
-
- #region Radeon Image Sharpening
- [StructLayout(LayoutKind.Sequential)]
- internal struct ADL_RIS_SETTINGS
- {
- internal int GlobalEnable; //Global enable value
- internal int GlobalSharpeningDegree; //Global sharpening value
- internal int GlobalSharpeningDegree_MinLimit; //Gloabl sharpening slider min limit value
- internal int GlobalSharpeningDegree_MaxLimit; //Gloabl sharpening slider max limit value
- internal int GlobalSharpeningDegree_Step; //Gloabl sharpening step value
- };
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct ADL_RIS_NOTFICATION_REASON
- {
- internal int GlobalEnableChanged; //Set when Global enable value is changed
- internal int GlobalSharpeningDegreeChanged; //Set when Global sharpening Degree value is changed
- };
- #endregion ADLDisplayInfo
-
- #endregion Export Struct
-
- #region ADL Class
- /// ADL Class
- internal static class ADL
- {
- internal const int ADL_DEFAULT_ADAPTER = 0;
- internal const int ADL_DEFAULT_DISPLAY = 0;
-
- #region Internal Constant
- /// Define the maximum path
- internal const int ADL_MAX_PATH = 256;
- /// Define the maximum adapters
- internal const int ADL_MAX_ADAPTERS = 40 /* 150 */;
- /// Define the maximum displays
- internal const int ADL_MAX_DISPLAYS = 40 /* 150 */;
- /// Define the maximum device name length
- internal const int ADL_MAX_DEVICENAME = 32;
- /// Define the successful
- internal const int ADL_SUCCESS = 0;
- /// Define the failure
- internal const int ADL_FAIL = -1;
- /// Define the driver ok
- internal const int ADL_DRIVER_OK = 0;
- /// Maximum number of GL-Sync ports on the GL-Sync module
- internal const int ADL_MAX_GLSYNC_PORTS = 8;
- /// Maximum number of GL-Sync ports on the GL-Sync module
- internal const int ADL_MAX_GLSYNC_PORT_LEDS = 8;
- /// Maximum number of ADLMOdes for the adapter
- internal const int ADL_MAX_NUM_DISPLAYMODES = 1024;
- internal const int ADL_MAX_EDIDDATA_SIZE = 256;
- internal const int ADL_MAX_EDID_EXTENSION_BLOCKS = 3;
-
- internal const int ADL_DISPLAY_DISPLAYINFO_DISPLAYCONNECTED = 0x00000001;
-
- #endregion Internal Constant
-
- #region Internal Constant
- /// Atiadlxx_FileName
- internal const string Atiadlxx_FileName = "atiadlxx.dll";
- /// Kernel32_FileName
- internal const string Kernel32_FileName = "kernel32.dll";
- #endregion Internal Constant
-
- #region Export Delegates
- /// ADL Memory allocation function allows ADL to callback for memory allocation
- /// input size
- /// retrun ADL Error Code
- internal delegate IntPtr ADL_Main_Memory_Alloc(int size);
- #endregion
-
- #region DLLImport
- [DllImport(Kernel32_FileName)]
- internal static extern HMODULE GetModuleHandle(string moduleName);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_Main_Control_Create(ADL_Main_Memory_Alloc callback, int enumConnectedAdapters, out IntPtr context);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_Main_Control_Destroy(IntPtr context);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_Main_Control_IsFunctionValid(IntPtr context, HMODULE module, string procName);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_Adapter_NumberOfAdapters_Get(IntPtr context, out int numAdapters);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_Adapter_AdapterInfo_Get(IntPtr context, out ADLAdapterInfoArray info, int inputSize);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_Adapter_Active_Get(IntPtr context, int adapterIndex, out int status);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_Display_DisplayInfo_Get(IntPtr context, int adapterIndex, out int numDisplays, out IntPtr displayInfoArray, int forceDetect);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_DFP_GPUScalingEnable_Get(IntPtr context, int adapterIndex, int displayIndex, out int support, out int current, out int default_);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_DFP_GPUScalingEnable_Set(IntPtr context, int adapterIndex, int displayIndex, int current);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_Display_PreservedAspectRatio_Get(IntPtr context, int adapterIndex, int displayIndex, out int support, out int current, out int default_);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_Display_PreservedAspectRatio_Set(IntPtr context, int adapterIndex, int displayIndex, int current);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_Display_ImageExpansion_Get(IntPtr context, int adapterIndex, int displayIndex, out int support, out int current, out int default_);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_Display_ImageExpansion_Set(IntPtr context, int adapterIndex, int displayIndex, int current);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_Display_SCE_State_Get(IntPtr context, int adapterIndex, int displayIndex, out int current, out int support, out int default_);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_Display_SCE_State_Set(IntPtr context, int adapterIndex, int displayIndex, int current);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_RIS_Settings_Get(IntPtr context, int adapterIndex, out ADL_RIS_SETTINGS settings);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_RIS_Settings_Set(IntPtr context, int adapterIndex, ADL_RIS_SETTINGS settings, ADL_RIS_NOTFICATION_REASON reason);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_Display_EdidData_Get(IntPtr context, int adapterIndex, int displayIndex, ref ADLDisplayEDIDData edidData);
-
- [DllImport(Atiadlxx_FileName)]
- internal static extern int ADL2_Display_EdidData_Set(IntPtr context, int adapterIndex, int displayIndex, ref ADLDisplayEDIDDataX2 edidData);
- #endregion DLLImport
-
- #region ADL_Main_Memory_Alloc
- /// Build in memory allocation function
- /// input size
- /// return the memory buffer
- internal static IntPtr ADL_Main_Memory_Alloc_(int size)
- {
- IntPtr result = Marshal.AllocCoTaskMem(size);
- return result;
- }
- #endregion ADL_Main_Memory_Alloc
-
- #region ADL_Main_Memory_Free
- /// Build in memory free function
- /// input buffer
- internal static void ADL_Main_Memory_Free(IntPtr buffer)
- {
- if (IntPtr.Zero != buffer)
- {
- Marshal.FreeCoTaskMem(buffer);
- }
- }
- #endregion ADL_Main_Memory_Free
- }
- #endregion ADL Class
-}
-
-#endregion ATI.ADL
\ No newline at end of file
diff --git a/PowerControl/Helpers/AMD/ADLContext.cs b/PowerControl/Helpers/AMD/ADLContext.cs
deleted file mode 100644
index f6cf9c4..0000000
--- a/PowerControl/Helpers/AMD/ADLContext.cs
+++ /dev/null
@@ -1,146 +0,0 @@
-using System.Runtime.InteropServices;
-using CommonHelpers;
-
-namespace PowerControl.Helpers.AMD
-{
- internal class ADLContext : IDisposable
- {
- public IntPtr Context { get; private set; }
-
- public ADLContext()
- {
- IntPtr context = IntPtr.Zero;
- WithSafe(() => ADL.ADL2_Main_Control_Create(ADL.ADL_Main_Memory_Alloc_, 1, out context), true);
- Context = context;
- }
-
- public bool IsValid
- {
- get { return Context != IntPtr.Zero; }
- }
-
- public ADLAdapterInfo[]? AdapterInfos
- {
- get
- {
- int res = ADL.ADL2_Adapter_NumberOfAdapters_Get(Context, out var numAdapters);
- if (res != 0)
- return null;
-
- res = ADL.ADL2_Adapter_AdapterInfo_Get(Context,
- out var adapters,
- Marshal.SizeOf());
- if (res != 0)
- return null;
-
- return adapters.ADLAdapterInfo.Take(numAdapters).ToArray();
- }
- }
-
- public IEnumerable DisplayInfos
- {
- get
- {
- foreach (var adapter in AdapterInfos)
- {
- if (adapter.Present == 0)
- continue;
-
- foreach (var display in GetDisplayInfos(adapter.AdapterIndex))
- {
- if ((display.DisplayInfoValue & ADL.ADL_DISPLAY_DISPLAYINFO_DISPLAYCONNECTED) != ADL.ADL_DISPLAY_DISPLAYINFO_DISPLAYCONNECTED)
- continue;
-
- yield return display;
- }
- }
- }
- }
-
- public IEnumerable GetDisplayInfos(int adapterIndex)
- {
- int res = ADL.ADL2_Display_DisplayInfo_Get(Context, adapterIndex, out var numDisplays, out var displays, 0);
- if (res != 0)
- yield break;
-
- try
- {
- int sizeOf = Marshal.SizeOf();
-
- for (int i = 0; i < numDisplays; i++)
- {
- var display = Marshal.PtrToStructure(IntPtr.Add(displays, i * sizeOf));
- // TODO: why even though we pass adapterIndex?
- if (display.DisplayID.DisplayLogicalAdapterIndex != adapterIndex)
- continue;
- yield return display;
- }
- }
- finally
- {
- ADL.ADL_Main_Memory_Free(displays);
- }
- }
-
- ~ADLContext()
- {
- Dispose();
- }
-
- public void Dispose()
- {
- GC.SuppressFinalize(this);
- if (Context != IntPtr.Zero)
- {
- WithSafe(() => ADL.ADL2_Main_Control_Destroy(Context));
- Context = IntPtr.Zero;
- }
- }
-
- private static ADLContext? instance;
- private static readonly Mutex mutex = new Mutex();
-
- public static T? WithSafe(Func func, bool useInstance = false)
- {
- if (useInstance)
- {
- if (!mutex.WaitOne(200))
- return default;
-
- try
- {
- if (instance == null)
- instance = new ADLContext();
- return instance.WithSafe(() => func(instance));
- }
- finally
- {
- mutex.ReleaseMutex();
- }
- }
- else
- {
- using (var context = new ADLContext())
- {
- return context.WithSafe(() => func(context));
- }
- }
- }
-
- public T? WithSafe(Func func, bool force = false)
- {
- if (!IsValid && !force)
- return default;
-
- try
- {
- return func();
- }
- catch (DllNotFoundException e) { Log.TraceException("ADL: Method not found", e); }
- catch (EntryPointNotFoundException e) { Log.TraceException("ADL: Entry point not found", e); }
- catch (Exception e) { Log.TraceException("ADL: Generic Exception", e); }
-
- return default;
- }
- }
-}
diff --git a/PowerControl/Helpers/AMD/DCE.cs b/PowerControl/Helpers/AMD/DCE.cs
deleted file mode 100644
index 7b88c48..0000000
--- a/PowerControl/Helpers/AMD/DCE.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-using Microsoft.Win32;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PowerControl.Helpers.AMD
-{
- internal class DCE
- {
- internal enum Mode
- {
- Normal = 1,
- Vivid
- }
-
- internal static Mode? Current
- {
- get
- {
- return ADLContext.WithSafe((context) =>
- {
- int res = ADL.ADL2_Display_SCE_State_Get(
- context.Context,
- ADL.ADL_DEFAULT_ADAPTER,
- ADL.ADL_DEFAULT_DISPLAY,
- out var current, out var support, out _);
-
- if (res == 0 && support == 1)
- return current == 2 ? Mode.Vivid : Mode.Normal;
-
- return (DCE.Mode?)null;
- });
- }
- set
- {
- ADLContext.WithSafe((context) =>
- {
- if (value is null)
- return false;
-
- ADL.ADL2_Display_SCE_State_Set(
- context.Context,
- ADL.ADL_DEFAULT_ADAPTER,
- ADL.ADL_DEFAULT_DISPLAY,
- (int)value
- );
-
- return true;
- });
- }
- }
- }
-}
diff --git a/PowerControl/Helpers/AMD/EDID.cs b/PowerControl/Helpers/AMD/EDID.cs
deleted file mode 100644
index 095684a..0000000
--- a/PowerControl/Helpers/AMD/EDID.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-using System.Linq;
-using System.Runtime.InteropServices;
-
-namespace PowerControl.Helpers.AMD
-{
- internal class EDID
- {
- internal static byte[]? GetEDID(int displayIndex = ADL.ADL_DEFAULT_DISPLAY)
- {
- return ADLContext.WithSafe((context) =>
- {
- byte[] edid = new byte[0];
-
- for (int block = 0; block < ADL.ADL_MAX_EDID_EXTENSION_BLOCKS; ++block)
- {
- ADLDisplayEDIDData displayEdidData = new ADLDisplayEDIDData()
- {
- iSize = Marshal.SizeOf(),
- iBlockIndex = block,
- };
-
- int res = ADL.ADL2_Display_EdidData_Get(context.Context, ADL.ADL_DEFAULT_ADAPTER, ADL.ADL_DEFAULT_DISPLAY, ref displayEdidData);
- if (res != 0)
- break;
-
- var blockBytes = displayEdidData.cEDIDData.Take(displayEdidData.iEDIDSize);
- edid = edid.Concat(blockBytes).ToArray();
- }
-
- return edid;
- });
- }
-
- internal static bool? SetEDID(byte[] value, int displayIndex = ADL.ADL_DEFAULT_DISPLAY)
- {
- return ADLContext.WithSafe((context) =>
- {
- var bytes = new byte[ADL.ADL_MAX_EDIDDATA_SIZE * 2];
- value.CopyTo(bytes, 0);
-
- var blockData = new ADLDisplayEDIDDataX2()
- {
- // TODO: Hack to send a full EDID at once
- iSize = Marshal.SizeOf(),
- cEDIDData = bytes,
- iEDIDSize = value.Length,
- };
-
- int res = ADL.ADL2_Display_EdidData_Set(context.Context,
- ADL.ADL_DEFAULT_ADAPTER, ADL.ADL_DEFAULT_DISPLAY,
- ref blockData);
-
- return res == 0;
- });
- }
- }
-}
diff --git a/PowerControl/Helpers/AMD/GPUScaling.cs b/PowerControl/Helpers/AMD/GPUScaling.cs
deleted file mode 100644
index b288c71..0000000
--- a/PowerControl/Helpers/AMD/GPUScaling.cs
+++ /dev/null
@@ -1,184 +0,0 @@
-using Microsoft.Win32;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PowerControl.Helpers.AMD
-{
- internal class GPUScaling
- {
- public enum ScalingMode
- {
- AspectRatio,
- FullPanel,
- Centered
- }
-
- internal static bool SafeResolutionChange
- {
- get { return Enabled; }
- }
-
- internal static bool IsSupported
- {
- get
- {
- return ADLContext.WithSafe((context) =>
- {
- int res = ADL.ADL2_DFP_GPUScalingEnable_Get(
- context.Context,
- ADL.ADL_DEFAULT_ADAPTER,
- ADL.ADL_DEFAULT_DISPLAY,
- out var support, out _, out _);
-
- if (res == 0 && support == 1)
- return true;
-
- return false;
- });
- }
- }
-
- internal static bool Enabled
- {
- get
- {
- return ADLContext.WithSafe((context) =>
- {
- int res = ADL.ADL2_DFP_GPUScalingEnable_Get(
- context.Context,
- ADL.ADL_DEFAULT_ADAPTER,
- ADL.ADL_DEFAULT_DISPLAY,
- out var support, out var current, out _);
- if (res == 0 && support == 1 && current == 1)
- return true;
-
- return false;
- });
- }
- set
- {
- ADLContext.WithSafe((context) =>
- {
- ADL.ADL2_DFP_GPUScalingEnable_Get(
- context.Context,
- ADL.ADL_DEFAULT_ADAPTER,
- ADL.ADL_DEFAULT_DISPLAY,
- out var _, out var current, out _);
- if (current == (value ? 1 : 0))
- return true;
-
- ADL.ADL2_DFP_GPUScalingEnable_Set(
- context.Context,
- ADL.ADL_DEFAULT_ADAPTER,
- ADL.ADL_DEFAULT_DISPLAY,
- value ? 1 : 0
- );
-
- return true;
- });
- }
- }
-
- internal static ScalingMode? Mode
- {
- get
- {
- return ADLContext.WithSafe((context) =>
- {
- int resAR = ADL.ADL2_Display_PreservedAspectRatio_Get(
- context.Context,
- ADL.ADL_DEFAULT_ADAPTER,
- ADL.ADL_DEFAULT_DISPLAY,
- out var supportAR, out var ar, out _);
- int resIE = ADL.ADL2_Display_ImageExpansion_Get(
- context.Context,
- ADL.ADL_DEFAULT_ADAPTER,
- ADL.ADL_DEFAULT_DISPLAY,
- out var supportIE, out var ie, out _);
-
- if (resAR != 0 || resIE != 0)
- return default(ScalingMode?);
-
- TraceLine("GPUScaling: ar={0}, ie={1}",
- supportAR > 0 ? ar : -1, supportIE > 0 ? ie : -1);
-
- if (ar == 1)
- return ScalingMode.AspectRatio;
- else if (ie == 1)
- return ScalingMode.FullPanel;
- else if (ie == 0 && supportIE == 1)
- return ScalingMode.Centered;
-
- return default(ScalingMode?);
- });
- }
- set
- {
- ADLContext.WithSafe((context) =>
- {
- int resGS = ADL.ADL2_DFP_GPUScalingEnable_Get(
- context.Context,
- ADL.ADL_DEFAULT_ADAPTER,
- ADL.ADL_DEFAULT_DISPLAY,
- out var _, out var current, out _);
- if (current == 0)
- {
- resGS = ADL.ADL2_DFP_GPUScalingEnable_Set(
- context.Context,
- ADL.ADL_DEFAULT_ADAPTER,
- ADL.ADL_DEFAULT_DISPLAY,
- 1
- );
- }
-
- int resAR = -1;
- int resIE = -1;
-
- switch (value)
- {
- case ScalingMode.FullPanel:
- resIE = ADL.ADL2_Display_ImageExpansion_Set(
- context.Context,
- ADL.ADL_DEFAULT_ADAPTER,
- ADL.ADL_DEFAULT_DISPLAY,
- 1
- );
- break;
-
- case ScalingMode.AspectRatio:
- resAR = ADL.ADL2_Display_PreservedAspectRatio_Set(
- context.Context,
- ADL.ADL_DEFAULT_ADAPTER,
- ADL.ADL_DEFAULT_DISPLAY,
- 1
- );
- break;
-
- case ScalingMode.Centered:
- resIE = ADL.ADL2_Display_ImageExpansion_Set(
- context.Context,
- ADL.ADL_DEFAULT_ADAPTER,
- ADL.ADL_DEFAULT_DISPLAY,
- 0
- );
- break;
- }
-
- TraceLine("GPUScaling: mode={0} => resAR={1}, resIE={2}, resGS={3}",
- value, resAR, resIE, resGS);
-
- return true;
- });
- }
- }
-
- private static void TraceLine(string format, params object?[]? arg)
- {
- Trace.WriteLine(string.Format(format, arg));
- }
- }
-}
diff --git a/PowerControl/Helpers/AMD/ImageSharpening.cs b/PowerControl/Helpers/AMD/ImageSharpening.cs
deleted file mode 100644
index f6882fb..0000000
--- a/PowerControl/Helpers/AMD/ImageSharpening.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-using Microsoft.Win32;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PowerControl.Helpers.AMD
-{
- internal class ImageSharpening
- {
- internal static bool? Enabled
- {
- get
- {
- return GetSettings(out var settings) ? settings.GlobalEnable != 0 : null;
- }
- set
- {
- if (!GetSettings(out var settings))
- return;
-
- var enabled = value.GetValueOrDefault(false) ? 1 : 0;
- if (settings.GlobalEnable == enabled)
- return;
-
- settings.GlobalEnable = enabled;
- SetSettings(settings, new ADL_RIS_NOTFICATION_REASON() { GlobalEnableChanged = 1 });
- }
- }
-
- private static bool GetSettings(out ADL_RIS_SETTINGS settings)
- {
- ADL_RIS_SETTINGS settings2 = default;
-
- var result = ADLContext.WithSafe((context) =>
- {
- int res = ADL.ADL2_RIS_Settings_Get(
- context.Context,
- ADL.ADL_DEFAULT_ADAPTER,
- out settings2);
- return res == 0;
- });
-
- settings = settings2;
- return result;
- }
-
- private static bool SetSettings(ADL_RIS_SETTINGS settings, ADL_RIS_NOTFICATION_REASON reason)
- {
- return ADLContext.WithSafe((context) =>
- {
- int res = ADL.ADL2_RIS_Settings_Set(
- context.Context,
- ADL.ADL_DEFAULT_ADAPTER,
- settings, reason);
- return res == 0;
- });
- }
- }
-}
diff --git a/PowerControl/Helpers/AMD/RadeonSoftware.cs b/PowerControl/Helpers/AMD/RadeonSoftware.cs
deleted file mode 100644
index 189e09d..0000000
--- a/PowerControl/Helpers/AMD/RadeonSoftware.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PowerControl.Helpers.AMD
-{
- public class RadeonSoftware
- {
- public static void Kill()
- {
- foreach (var process in Process.GetProcessesByName("RadeonSoftware.exe"))
- {
- try { process.Kill(); }
- catch { }
- }
- }
- }
-}
diff --git a/PowerControl/Helpers/AMD/RyzenSMU.cs b/PowerControl/Helpers/AMD/RyzenSMU.cs
deleted file mode 100644
index 2000318..0000000
--- a/PowerControl/Helpers/AMD/RyzenSMU.cs
+++ /dev/null
@@ -1,207 +0,0 @@
-using CommonHelpers;
-using System.Runtime.InteropServices;
-
-namespace PowerControl.Helpers.AMD
-{
- public class RyzenSMU : IDisposable
- {
- public IntPtr MMIO_ADDR;
- public uint MMIO_SIZE;
- public uint RES_ADDR, MSG_ADDR, PARAM_ADDR;
- public uint INDEX_ADDR, DATA_ADDR;
-
- IntPtr mappedAddress;
- IntPtr physicalHandle;
- InpOut? inpOut;
-
- public RyzenSMU()
- {
- }
-
- ~RyzenSMU()
- {
- Dispose();
- }
-
- public bool Opened
- {
- get { return physicalHandle != IntPtr.Zero && mappedAddress != IntPtr.Zero; }
- }
-
- public bool Open()
- {
- if (physicalHandle != IntPtr.Zero)
- return true;
- if (MMIO_ADDR == IntPtr.Zero || MMIO_SIZE == 0)
- return false;
-
- try
- {
- inpOut = new InpOut();
- mappedAddress = inpOut.MapPhysToLin(MMIO_ADDR, MMIO_SIZE, out physicalHandle);
- }
- catch (Exception e)
- {
- Log.TraceException("RyzenSMU", e);
- return false;
- }
-
- return Opened;
- }
-
- public void Dispose()
- {
- if (physicalHandle == IntPtr.Zero)
- return;
-
- GC.SuppressFinalize(this);
- inpOut?.UnmapPhysicalMemory(physicalHandle, mappedAddress);
- mappedAddress = IntPtr.Zero;
- physicalHandle = IntPtr.Zero;
- using (inpOut) { }
- inpOut = null;
- }
-
- private uint RregRaw(uint reg)
- {
- return (uint)Marshal.ReadInt32(mappedAddress, (int)reg);
- }
-
- private void WregRaw(uint reg, uint value)
- {
- Marshal.WriteInt32(mappedAddress, (int)reg, (int)value);
- }
-
- private bool WregCheckedRaw(uint reg, uint value)
- {
- WregRaw(reg, value);
- return RregRaw(reg) == value;
- }
-
- private bool Wreg(uint reg, uint value)
- {
- if (!Opened)
- return false;
-
- bool success = false;
-
- try
- {
- if (reg < MMIO_SIZE)
- {
- return success = WregCheckedRaw(reg, value);
- }
- else
- {
- if (!WregCheckedRaw(INDEX_ADDR, reg))
- return false;
- if (!WregCheckedRaw(DATA_ADDR, value))
- return false;
- }
-
- return success = true;
- }
- finally
- {
- Log.TraceLine("Wreg: reg={0:X}, value={1:X} => success={2}",
- reg, value, success);
- }
- }
-
- private bool Rreg(uint reg, out uint value)
- {
- value = default;
-
- if (!Opened)
- return false;
-
- bool success = false;
-
- try
- {
- if (reg < MMIO_SIZE)
- {
- value = RregRaw(reg);
- }
- else
- {
- if (!WregCheckedRaw(INDEX_ADDR, reg))
- return false;
- value = RregRaw(DATA_ADDR);
- }
-
- return success = true;
- }
- finally
- {
- Log.TraceLine("Rreg: reg={0:X} => read={1}/{1:X}, success={2}",
- reg, value, success);
- }
- }
-
- private uint WaitForResponse()
- {
- const int timeout = 20;
- for (int i = 0; i < timeout; i++)
- {
- uint value;
- if (!Rreg(RES_ADDR, out value))
- return 0;
- if (value != 0)
- return value;
- Thread.SpinWait(100);
- }
- return 0;
- }
-
- public bool SendMsg(ushort msg, uint param)
- {
- return SendMsg(msg, param, out _);
- }
-
- public bool SendMsg(ushort msg, uint param, out uint arg)
- {
- bool success = false;
-
- arg = 0;
-
- try
- {
- var res = WaitForResponse();
- if (res != 0x1)
- {
- // Reset SMU state
- if (res != 0)
- Wreg(RES_ADDR, 1);
- return false;
- }
-
- Wreg(RES_ADDR, 0);
- Wreg(PARAM_ADDR, param);
- Wreg(MSG_ADDR, msg);
-
- res = WaitForResponse();
- if (res != 0x1)
- return false;
-
- success = Rreg(PARAM_ADDR, out arg);
- return success;
- }
- finally
- {
- Log.TraceLine(">> SendMsg: msg={0:X}, param={1:X} => arg={2}/{2:X}, success={3}",
- msg, param, arg, success);
- }
- }
-
- public bool SendMsg(T msg, uint param)
- {
- return SendMsg((ushort)(object)msg, param, out _);
- }
-
- public bool SendMsg(T msg, uint param, out uint arg) where T : unmanaged
- {
- return SendMsg((ushort)(object)msg, param, out arg);
- }
- }
-}
diff --git a/PowerControl/Helpers/AMD/VangoghGPU.cs b/PowerControl/Helpers/AMD/VangoghGPU.cs
deleted file mode 100644
index e6909fb..0000000
--- a/PowerControl/Helpers/AMD/VangoghGPU.cs
+++ /dev/null
@@ -1,474 +0,0 @@
-using CommonHelpers;
-using System.Diagnostics;
-using static CommonHelpers.Log;
-using Device = System.Tuple;
-
-namespace PowerControl.Helpers.AMD
-{
- internal class VangoghGPU : IDisposable
- {
- public static readonly Device[] SupportedDevices =
- {
- // SteamDeck LCD
- // F7A0131 = 0x063F0F00
- new Device("AMD Custom GPU 0405", 0x80300000, 0x8037ffff, new uint[] { 0x43F3900, 0x43F3C05, 0x43F3E00, 0x063F0F00 }),
-
- // SteamDeck OLED
- // BIOS 105
- // new Device("AMD Custom GPU 0932", 0x80600000, 0x8067ffff, new uint[] { 0x063F0E00 }),
- // BIOS 107
- new Device("AMD Custom GPU 0932", 0x80500000, 0x8057ffff, new uint[] { 0x063F0F00 }),
-
- // SteamDeck unofficial APU drivers
- // https://sourceforge.net/projects/amernimezone/files/Release%20Polaris-Vega-Navi/AMD%20SOC%20Driver%20Variant/
- new Device("AMD Radeon 670M", 0x80300000, 0x8037ffff, new uint[] { 0x43F3900, 0x43F3C05, 0x43F3E00, 0x063F0F00 }),
- new Device("AMD Radeon RX 670 Graphics", 0x80300000, 0x8037ffff, new uint[] { 0x43F3900, 0x43F3C05, 0x43F3E00, 0x063F0F00 }),
- };
-
- private static Device? DetectedDevice;
-
- public static bool IsSupported
- {
- get { return DetectedDevice != null; }
- }
-
- public static VangoghGPU? Open()
- {
- if (DetectedDevice is null)
- return null;
-
- return Open(DetectedDevice);
- }
-
- public static VangoghGPU? Open(Device device)
- {
- if (device is null)
- return null;
-
- return OpenMMIO(new IntPtr((long)device.Item2), (uint)(device.Item3 - device.Item2 + 1));
- }
-
- public enum DetectionStatus
- {
- Detected,
- Retryable,
- NotDetected
- }
-
- public static DetectionStatus Detect()
- {
- var discoveredDevices = new Dictionary();
-
- foreach (var pnp in DeviceManager.GetDevices(DeviceManager.GUID_DISPLAY) ?? new string[0])
- {
- // Properly support many devices with the same name (pick the first one)
- var name = DeviceManager.GetDeviceDesc(pnp);
- if (name is not null && !discoveredDevices.ContainsKey(name))
- discoveredDevices[name] = pnp;
- }
-
- foreach (var device in SupportedDevices)
- {
- var deviceName = device.Item1;
-
- if (!discoveredDevices.ContainsKey(deviceName))
- {
- TraceLine("GPU: {0}: Not matched.", deviceName);
- continue;
- }
-
- var devicePNP = discoveredDevices[deviceName];
- var ranges = DeviceManager.GetDeviceMemResources(devicePNP);
- if (ranges is null)
- {
- TraceError("GPU: {0}: {1}: No memory ranges", deviceName, devicePNP);
- continue;
- }
- var expectedRange = new Tuple(new UIntPtr(device.Item2), new UIntPtr(device.Item3));
- if (!ranges.Contains(expectedRange))
- {
- TraceError("GPU: {0}: {1}: Memory range not found: {2}",
- deviceName,
- devicePNP,
- String.Join(",", ranges.Select((item) => item.ToString()))
- );
- continue;
- }
-
- using (var gpu = Open(device))
- {
- if (gpu is null)
- {
- TraceError("GPU: {0}: {1}: Failed to open.", deviceName, devicePNP);
- continue;
- }
-
- var smuVersion = gpu.SMUVersion;
- if (!device.Item4.Contains(smuVersion))
- {
- // Silence SMU_Version = 0 since it happens fairly often
- if (smuVersion != 0)
- {
- TraceError("GPU: {0}: {1}: SMU not supported: {2:X8} (IO: {3})", deviceName, devicePNP, smuVersion, expectedRange);
- }
- return DetectionStatus.Retryable;
- }
-
- TraceLine("GPU: {0}: Matched!", deviceName);
- DetectedDevice = device;
- return DetectionStatus.Detected;
- }
- }
- DetectedDevice = null;
- return DetectionStatus.Detected;
- }
-
- // Addresses:
- // drivers/gpu/drm/amd/include/vangogh_ip_offset.h => MP1_BASE => 0x00016000
- // drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c => mmMP1_SMN_C2PMSG_* => 0x0282/0x0292/0x029a
- // drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_7_4_offset.h => mmPCIE_INDEX2/mmPCIE_DATA2 => 0x000e/0x000f
- //
- // Messages:
- // drivers/gpu/drm/amd/pm/inc/smu_v11_5_ppsmc.h
-
- private RyzenSMU smu;
-
- ~VangoghGPU()
- {
- Dispose();
- }
-
- public void Dispose()
- {
- GC.SuppressFinalize(this);
- if (smu != null)
- smu.Dispose();
- }
-
- private static VangoghGPU? OpenMMIO(IntPtr mmioAddress, uint mmioSize)
- {
- var gpu = new VangoghGPU
- {
- smu = new RyzenSMU()
- {
- MMIO_ADDR = mmioAddress,
- MMIO_SIZE = mmioSize,
- RES_ADDR = 0x0001629A * 4,
- MSG_ADDR = 0x00016282 * 4,
- PARAM_ADDR = 0x00016292 * 4,
- INDEX_ADDR = 0xE * 4,
- DATA_ADDR = 0xF * 4
- }
- };
-
- if (!gpu.smu.Open())
- return null;
-
- return gpu;
- }
-
- public UInt32 SMUVersion
- {
- get { return getValue(Message.PPSMC_MSG_GetSmuVersion); }
- }
-
- public UInt32 IfVersion
- {
- get { return getValue(Message.PPSMC_MSG_GetDriverIfVersion); }
- }
-
- public Features SmuFeatures
- {
- get
- {
- UInt64 low = getValue(Message.PPSMC_MSG_GetEnabledSmuFeatures, 0);
- UInt64 high = getValue(Message.PPSMC_MSG_GetEnabledSmuFeatures, 1);
- return (Features)((high << 32) | low);
- }
- }
-
- const uint MIN_TDP = 3000;
- const uint MAX_TDP = 21000;
-
- public uint SlowTDP
- {
- get { return getValue(Message.PPSMC_MSG_GetSlowPPTLimit); }
- set { setValue(Message.PPSMC_MSG_SetSlowPPTLimit, value, MIN_TDP, MAX_TDP); }
- }
-
- public uint FastTDP
- {
- get { return getValue(Message.PPSMC_MSG_GetFastPPTLimit); }
- set { setValue(Message.PPSMC_MSG_SetFastPPTLimit, value, MIN_TDP, MAX_TDP); }
- }
-
- public uint GfxClock
- {
- get { return getValue(Message.PPSMC_MSG_GetGfxclkFrequency); }
- }
-
- public uint FClock
- {
- get { return getValue(Message.PPSMC_MSG_GetFclkFrequency); }
- }
-
- const uint MIN_CPU_CLOCK = 1400;
- const uint MAX_CPU_CLOCK = 4000;
-
- public uint MinCPUClock
- {
- set { setCPUValue(Message.PPSMC_MSG_SetSoftMinCclk, value, MIN_CPU_CLOCK, MAX_CPU_CLOCK); }
- }
-
- public uint MaxCPUClock
- {
- set { setCPUValue(Message.PPSMC_MSG_SetSoftMaxCclk, value, MIN_CPU_CLOCK, MAX_CPU_CLOCK); }
- }
-
- const uint MIN_GFX_CLOCK = 200;
- const uint MAX_GFX_CLOCK = 1900;
-
- public uint HardMinGfxClock
- {
- set { setValue(Message.PPSMC_MSG_SetHardMinGfxClk, value, MIN_GFX_CLOCK, MAX_GFX_CLOCK); }
- }
-
- public uint SoftMinGfxClock
- {
- set { setValue(Message.PPSMC_MSG_SetSoftMinGfxclk, value, MIN_GFX_CLOCK, MAX_GFX_CLOCK); }
- }
-
- public uint SoftMaxGfxClock
- {
- set { setValue(Message.PPSMC_MSG_SetSoftMaxGfxClk, value, MIN_GFX_CLOCK, MAX_GFX_CLOCK); }
- }
-
- public Dictionary All
- {
- get
- {
- var dict = new Dictionary();
-
- foreach (var key in ValuesGetters)
- {
- if (!this.smu.SendMsg(key, 0, out var value))
- continue;
-
- var keyString = key.ToString().Replace("PPSMC_MSG_Get", "");
- dict[keyString] = value;
- }
-
- return dict;
- }
- }
-
- private void setCPUValue(Message msg, uint value, uint min = UInt32.MinValue, uint max = UInt32.MaxValue)
- {
- // TODO: Hardcode CPUs
- for (uint i = 0; i < 4; i++)
- {
- setValue(msg, value | (i << 20), min, max, (1 << 20) - 1);
- }
- }
-
- private uint getValue(Message msg, UInt32 param = 0)
- {
- this.smu.SendMsg(msg, param, out var value);
- return value;
- }
-
- private void setValue(Message msg, uint value, uint min = UInt32.MinValue, uint max = UInt32.MaxValue, uint clampMask = uint.MaxValue)
- {
- this.smu.SendMsg(msg, Math.Clamp(value & clampMask, min, max) | (value & ~clampMask));
- }
-
- private readonly Message[] ValuesGetters = new Message[]
- {
- Message.PPSMC_MSG_GetGfxclkFrequency,
- Message.PPSMC_MSG_GetFclkFrequency,
- Message.PPSMC_MSG_GetPptLimit,
- Message.PPSMC_MSG_GetThermalLimit,
- Message.PPSMC_MSG_GetFastPPTLimit,
- Message.PPSMC_MSG_GetSlowPPTLimit,
-
- // Those values return PPSMC_Result_CmdRejectedPrereq
- Message.PPSMC_MSG_GetCurrentTemperature,
- Message.PPSMC_MSG_GetCurrentPower,
- Message.PPSMC_MSG_GetCurrentCurrent,
- Message.PPSMC_MSG_GetCurrentFreq,
- Message.PPSMC_MSG_GetCurrentVoltage,
- Message.PPSMC_MSG_GetAverageCpuActivity,
- Message.PPSMC_MSG_GetAverageGfxActivity,
- Message.PPSMC_MSG_GetAveragePower,
- Message.PPSMC_MSG_GetAverageTemperature
- };
-
- enum Result : byte
- {
- PPSMC_Result_OK = 0x1,
- PPSMC_Result_Failed = 0xFF,
- PPSMC_Result_UnknownCmd = 0xFE,
- PPSMC_Result_CmdRejectedPrereq = 0xFD,
- PPSMC_Result_CmdRejectedBusy = 0xFC
- }
-
- enum Tables : byte
- {
- TABLE_BIOS_IF = 0, // Called by BIOS
- TABLE_WATERMARKS = 1, // Called by DAL through VBIOS
- TABLE_CUSTOM_DPM = 2, // Called by Driver
- TABLE_SPARE1 = 3,
- TABLE_DPMCLOCKS = 4, // Called by Driver
- TABLE_SPARE2 = 5, // Called by Tools
- TABLE_MODERN_STDBY = 6, // Called by Tools for Modern Standby Log
- TABLE_SMU_METRICS = 7, // Called by Driver
- TABLE_COUNT = 8
- }
-
- enum Message : ushort
- {
- PPSMC_MSG_TestMessage = 0x1,
- PPSMC_MSG_GetSmuVersion = 0x2,
- PPSMC_MSG_GetDriverIfVersion = 0x3,
- PPSMC_MSG_EnableGfxOff = 0x4,
- PPSMC_MSG_DisableGfxOff = 0x5,
- PPSMC_MSG_PowerDownIspByTile = 0x6, // ISP is power gated by default
- PPSMC_MSG_PowerUpIspByTile = 0x7,
- PPSMC_MSG_PowerDownVcn = 0x8, // VCN is power gated by default
- PPSMC_MSG_PowerUpVcn = 0x9,
- PPSMC_MSG_RlcPowerNotify = 0xA,
- PPSMC_MSG_SetHardMinVcn = 0xB, // For wireless display
- PPSMC_MSG_SetSoftMinGfxclk = 0xC, //Sets SoftMin for GFXCLK. Arg is in MHz
- PPSMC_MSG_ActiveProcessNotify = 0xD,
- PPSMC_MSG_SetHardMinIspiclkByFreq = 0xE,
- PPSMC_MSG_SetHardMinIspxclkByFreq = 0xF,
- PPSMC_MSG_SetDriverDramAddrHigh = 0x10,
- PPSMC_MSG_SetDriverDramAddrLow = 0x11,
- PPSMC_MSG_TransferTableSmu2Dram = 0x12,
- PPSMC_MSG_TransferTableDram2Smu = 0x13,
- PPSMC_MSG_GfxDeviceDriverReset = 0x14, //mode 2 reset during TDR
- PPSMC_MSG_GetEnabledSmuFeatures = 0x15,
- PPSMC_MSG_spare1 = 0x16,
- PPSMC_MSG_SetHardMinSocclkByFreq = 0x17,
- PPSMC_MSG_SetSoftMinFclk = 0x18, //Used to be PPSMC_MSG_SetMinVideoFclkFreq
- PPSMC_MSG_SetSoftMinVcn = 0x19,
- PPSMC_MSG_EnablePostCode = 0x1A,
- PPSMC_MSG_GetGfxclkFrequency = 0x1B,
- PPSMC_MSG_GetFclkFrequency = 0x1C,
- PPSMC_MSG_AllowGfxOff = 0x1D,
- PPSMC_MSG_DisallowGfxOff = 0x1E,
- PPSMC_MSG_SetSoftMaxGfxClk = 0x1F,
- PPSMC_MSG_SetHardMinGfxClk = 0x20,
- PPSMC_MSG_SetSoftMaxSocclkByFreq = 0x21,
- PPSMC_MSG_SetSoftMaxFclkByFreq = 0x22,
- PPSMC_MSG_SetSoftMaxVcn = 0x23,
- PPSMC_MSG_spare2 = 0x24,
- PPSMC_MSG_SetPowerLimitPercentage = 0x25,
- PPSMC_MSG_PowerDownJpeg = 0x26,
- PPSMC_MSG_PowerUpJpeg = 0x27,
- PPSMC_MSG_SetHardMinFclkByFreq = 0x28,
- PPSMC_MSG_SetSoftMinSocclkByFreq = 0x29,
- PPSMC_MSG_PowerUpCvip = 0x2A,
- PPSMC_MSG_PowerDownCvip = 0x2B,
- PPSMC_MSG_GetPptLimit = 0x2C,
- PPSMC_MSG_GetThermalLimit = 0x2D,
- PPSMC_MSG_GetCurrentTemperature = 0x2E,
- PPSMC_MSG_GetCurrentPower = 0x2F,
- PPSMC_MSG_GetCurrentVoltage = 0x30,
- PPSMC_MSG_GetCurrentCurrent = 0x31,
- PPSMC_MSG_GetAverageCpuActivity = 0x32,
- PPSMC_MSG_GetAverageGfxActivity = 0x33,
- PPSMC_MSG_GetAveragePower = 0x34,
- PPSMC_MSG_GetAverageTemperature = 0x35,
- PPSMC_MSG_SetAveragePowerTimeConstant = 0x36,
- PPSMC_MSG_SetAverageActivityTimeConstant = 0x37,
- PPSMC_MSG_SetAverageTemperatureTimeConstant = 0x38,
- PPSMC_MSG_SetMitigationEndHysteresis = 0x39,
- PPSMC_MSG_GetCurrentFreq = 0x3A,
- PPSMC_MSG_SetReducedPptLimit = 0x3B,
- PPSMC_MSG_SetReducedThermalLimit = 0x3C,
- PPSMC_MSG_DramLogSetDramAddr = 0x3D,
- PPSMC_MSG_StartDramLogging = 0x3E,
- PPSMC_MSG_StopDramLogging = 0x3F,
- PPSMC_MSG_SetSoftMinCclk = 0x40,
- PPSMC_MSG_SetSoftMaxCclk = 0x41,
- PPSMC_MSG_SetDfPstateActiveLevel = 0x42,
- PPSMC_MSG_SetDfPstateSoftMinLevel = 0x43,
- PPSMC_MSG_SetCclkPolicy = 0x44,
- PPSMC_MSG_DramLogSetDramAddrHigh = 0x45,
- PPSMC_MSG_DramLogSetDramBufferSize = 0x46,
- PPSMC_MSG_RequestActiveWgp = 0x47,
- PPSMC_MSG_QueryActiveWgp = 0x48,
- PPSMC_MSG_SetFastPPTLimit = 0x49,
- PPSMC_MSG_SetSlowPPTLimit = 0x4A,
- PPSMC_MSG_GetFastPPTLimit = 0x4B,
- PPSMC_MSG_GetSlowPPTLimit = 0x4C,
- PPSMC_Message_Count = 0x4D,
- }
-
- [Flags]
- public enum Features : UInt64
- {
- CCLK_DPM_BIT = 0,
- FAN_CONTROLLER_BIT = 1,
- DATA_CALCULATION_BIT = 2,
- PPT_BIT = 3,
- TDC_BIT = 4,
- THERMAL_BIT = 5,
- FIT_BIT = 6,
- EDC_BIT = 7,
- PLL_POWER_DOWN_BIT = 8,
- ULV_BIT = 9,
- VDDOFF_BIT = 10,
- VCN_DPM_BIT = 11,
- CSTATE_BOOST_BIT = 12,
- FCLK_DPM_BIT = 13,
- SOCCLK_DPM_BIT = 14,
- MP0CLK_DPM_BIT = 15,
- LCLK_DPM_BIT = 16,
- SHUBCLK_DPM_BIT = 17,
- DCFCLK_DPM_BIT = 18,
- GFX_DPM_BIT = 19,
- DS_GFXCLK_BIT = 20,
- DS_SOCCLK_BIT = 21,
- DS_LCLK_BIT = 22,
- DS_DCFCLK_BIT = 23,
- DS_SHUBCLK_BIT = 24,
- GFX_TEMP_VMIN_BIT = 25,
- S0I2_BIT = 26,
- WHISPER_MODE_BIT = 27,
- DS_FCLK_BIT = 28,
- DS_SMNCLK_BIT = 29,
- DS_MP1CLK_BIT = 30,
- DS_MP0CLK_BIT = 31,
- SMU_LOW_POWER_BIT = 32,
- FUSE_PG_BIT = 33,
- GFX_DEM_BIT = 34,
- PSI_BIT = 35,
- PROCHOT_BIT = 36,
- CPUOFF_BIT = 37,
- STAPM_BIT = 38,
- S0I3_BIT = 39,
- DF_CSTATES_BIT = 40,
- PERF_LIMIT_BIT = 41,
- CORE_DLDO_BIT = 42,
- RSMU_LOW_POWER_BIT = 43,
- SMN_LOW_POWER_BIT = 44,
- THM_LOW_POWER_BIT = 45,
- SMUIO_LOW_POWER_BIT = 46,
- MP1_LOW_POWER_BIT = 47,
- DS_VCN_BIT = 48,
- CPPC_BIT = 49,
- OS_CSTATES_BIT = 50,
- ISP_DPM_BIT = 51,
- A55_DPM_BIT = 52,
- CVIP_DSP_DPM_BIT = 53,
- MSMU_LOW_POWER_BIT = 54,
- SOC_VOLTAGE_MON_BIT = 55,
- ATHUB_PG_BIT = 56,
- ECO_DEEPCSTATE_BIT = 57,
- CC6_BIT = 58,
- GFX_EDC_BIT = 59
- }
- }
-}
diff --git a/PowerControl/Helpers/DeviceManager.cs b/PowerControl/Helpers/DeviceManager.cs
deleted file mode 100644
index d1b22b6..0000000
--- a/PowerControl/Helpers/DeviceManager.cs
+++ /dev/null
@@ -1,214 +0,0 @@
-using PowerControl.External;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PowerControl.Helpers
-{
- internal class DeviceManager
- {
- public static string[]? GetDevices(Guid? classGuid)
- {
- string? filter = null;
- int flags = CM_GETIDLIST_FILTER_PRESENT;
-
- if (classGuid is not null)
- {
- filter = classGuid?.ToString("B").ToUpper();
- flags |= CM_GETIDLIST_FILTER_CLASS;
- }
-
- var res = CM_Get_Device_ID_List_Size(out var size, filter, flags);
- if (res != CR_SUCCESS)
- return null;
-
- char[] data = new char[size];
- res = CM_Get_Device_ID_List(filter, data, size, flags);
- if (res != CR_SUCCESS)
- return null;
-
- var result = new string(data);
- var devices = result.Split('\0', StringSplitOptions.RemoveEmptyEntries);
- return devices.ToArray();
- }
-
- public static string? GetDeviceDesc(String PNPString)
- {
- if (CM_Locate_DevNode(out var devInst, PNPString, 0) != 0)
- return null;
-
- if (!CM_Get_DevNode_Property(devInst, DEVPKEY_Device_DeviceDesc, out var deviceDesc, 0))
- return null;
-
- return deviceDesc;
- }
-
- public static IList>? GetDeviceMemResources(string PNPString)
- {
- int res = CM_Locate_DevNode(out var devInst, PNPString, 0);
- if (res != CR_SUCCESS)
- return null;
-
- res = CM_Get_First_Log_Conf(out var logConf, devInst, ALLOC_LOG_CONF);
- if (res != CR_SUCCESS)
- res = CM_Get_First_Log_Conf(out logConf, devInst, BOOT_LOG_CONF);
- if (res != CR_SUCCESS)
- return null;
-
- var ranges = new List>();
-
- while (CM_Get_Next_Res_Des(out var newResDes, logConf, ResType_Mem, out _, 0) == 0)
- {
- CM_Free_Res_Des_Handle(logConf);
- logConf = newResDes;
-
- if (!CM_Get_Res_Des_Data(logConf, out var memResource, 0))
- continue;
-
- ranges.Add(new Tuple(
- memResource.MEM_Header.MD_Alloc_Base, memResource.MEM_Header.MD_Alloc_End));
- }
-
- CM_Free_Res_Des_Handle(logConf);
- return ranges;
- }
-
- static bool CM_Get_DevNode_Property(IntPtr devInst, DEVPROPKEY propertyKey, out string result, int flags)
- {
- result = default;
-
- // int length = 0;
- // int res = CM_Get_DevNode_Property(devInst, ref propertyKey, out var propertyType, null, ref length, flags);
- // if (res != CR_SUCCESS && res != CR_BUFFER_TOO_SMALL)
- // return false;
-
- char[] buffer = new char[2048];
- int length = buffer.Length;
- int res = CM_Get_DevNode_Property(devInst, ref propertyKey, out var propertyType, buffer, ref length, flags);
- if (res != CR_SUCCESS)
- return false;
- if (propertyType != DEVPROP_TYPE_STRING)
- return false;
-
- result = new String(buffer, 0, length).Split('\0').First();
- return true;
- }
-
- static bool CM_Get_Res_Des_Data(IntPtr rdResDes, out T buffer, int ulFlags) where T : struct
- {
- buffer = default;
-
- int res = CM_Get_Res_Des_Data_Size(out var size, rdResDes, ulFlags);
- if (res != CR_SUCCESS)
- return false;
-
- int sizeOf = Marshal.SizeOf();
- if (sizeOf < size)
- return false;
-
- var addr = Marshal.AllocHGlobal(sizeOf);
- try
- {
- res = CM_Get_Res_Des_Data(rdResDes, addr, size, 0);
- if (res != CR_SUCCESS)
- return false;
-
- buffer = Marshal.PtrToStructure(addr);
- return true;
- }
- finally
- {
- Marshal.FreeHGlobal(addr);
- }
- }
-
- [DllImport("setupapi.dll", CharSet = CharSet.Auto)]
- static extern int CM_Locate_DevNode(out IntPtr pdnDevInst, string pDeviceID, int ulFlags);
-
- [DllImport("setupapi.dll", CharSet = CharSet.Unicode)]
- static extern int CM_Get_Device_ID_List_Size(out int idListlen, string? filter, int ulFlags);
-
- [DllImport("setupapi.dll", CharSet = CharSet.Unicode)]
- static extern int CM_Get_Device_ID_List(string? filter, char[] bffr, int bffrLen, int ulFlags);
-
- [DllImport("CfgMgr32.dll", CharSet = CharSet.Unicode)]
- static extern int CM_Get_DevNode_Property(IntPtr devInst, ref DEVPROPKEY propertyKey, out int propertyType, char[]? bffr, ref int bffrLen, int flags);
-
- [DllImport("setupapi.dll")]
- static extern int CM_Free_Res_Des_Handle(IntPtr rdResDes);
-
- [DllImport("setupapi.dll")]
- static extern int CM_Get_First_Log_Conf(out IntPtr rdResDes, IntPtr pdnDevInst, int ulFlags);
-
- [DllImport("setupapi.dll")]
- static extern int CM_Get_Next_Res_Des(out IntPtr newResDes, IntPtr rdResDes, int resType, out int resourceID, int ulFlags);
-
- [DllImport("setupapi.dll")]
- static extern int CM_Get_Res_Des_Data_Size(out int size, IntPtr rdResDes, int ulFlags);
-
- [DllImport("setupapi.dll")]
- static extern int CM_Get_Res_Des_Data(IntPtr rdResDes, IntPtr buffer, int size, int ulFlags);
-
- [StructLayout(LayoutKind.Sequential)]
- struct MEM_DES
- {
- internal uint MD_Count;
- internal uint MD_Type;
- internal UIntPtr MD_Alloc_Base;
- internal UIntPtr MD_Alloc_End;
- internal uint MD_Flags;
- internal uint MD_Reserved;
- };
-
- [StructLayout(LayoutKind.Sequential, Pack = 4)]
- struct MEM_RANGE
- {
- internal UIntPtr MR_Align; // specifies mask for base alignment
- internal uint MR_nBytes; // specifies number of bytes required
- internal UIntPtr MR_Min; // specifies minimum address of the range
- internal UIntPtr MR_Max; // specifies maximum address of the range
- internal uint MR_Flags; // specifies flags describing range (fMD flags)
- internal uint MR_Reserved;
- };
-
- [StructLayout(LayoutKind.Sequential)]
- struct MEM_RESOURCE
- {
- internal MEM_DES MEM_Header;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
- internal MEM_RANGE[] MEM_Data;
- };
-
- [StructLayout(LayoutKind.Sequential)]
- struct DEVPROPKEY
- {
- public Guid Guid;
- public uint Pid;
-
- public DEVPROPKEY(String guid, uint pid)
- {
- this.Guid = new Guid(guid);
- this.Pid = pid;
- }
- };
-
- const int ALLOC_LOG_CONF = 0x00000002; // Specifies the Alloc Element.
- const int BOOT_LOG_CONF = 0x00000003; // Specifies the RM Alloc Element.
- const int ResType_Mem = (0x00000001); // Physical address resource
-
- const int CM_GETIDLIST_FILTER_PRESENT = 0x00000100;
- const int CM_GETIDLIST_FILTER_CLASS = 0x00000200;
- const int CR_SUCCESS = 0x0;
- const int CR_BUFFER_TOO_SMALL = 0x1A;
-
- const int DEVPROP_TYPE_STRING = 0x00000012;
-
- static readonly DEVPROPKEY DEVPKEY_Device_DeviceDesc = new DEVPROPKEY("a45c254e-df1c-4efd-8020-67d146a850e0", 2);
-
- internal static readonly Guid GUID_DISPLAY = new Guid("{4d36e968-e325-11ce-bfc1-08002be10318}");
- }
-}
diff --git a/PowerControl/Helpers/DisplayResolutionController.cs b/PowerControl/Helpers/DisplayResolutionController.cs
deleted file mode 100644
index 4c193a1..0000000
--- a/PowerControl/Helpers/DisplayResolutionController.cs
+++ /dev/null
@@ -1,377 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.Immutable;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Linq;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
-using CommonHelpers;
-using static PowerControl.Helpers.PhysicalMonitorBrightnessController;
-
-namespace PowerControl.Helpers
-{
- internal class DisplayResolutionController
- {
- public struct DisplayResolution : IComparable
- {
- public int Width { get; set; }
- public int Height { get; set; }
-
- public DisplayResolution() { Width = 0; Height = 0; }
-
- public DisplayResolution(int width, int height) { Width = width; Height = height; }
-
- public DisplayResolution(String text)
- {
- var options = text.Split("x", 2);
- Width = int.Parse(options[0]);
- Height = int.Parse(options[1]);
- }
-
- public static bool operator ==(DisplayResolution sz1, DisplayResolution sz2) => sz1.Width == sz2.Width && sz1.Height == sz2.Height;
-
- public static bool operator !=(DisplayResolution sz1, DisplayResolution sz2) => !(sz1 == sz2);
-
- public override readonly bool Equals([NotNullWhen(true)] object? obj) => obj is DisplayResolution && Equals((DisplayResolution)obj);
- public readonly bool Equals(DisplayResolution other) => this == other;
-
- public override readonly int GetHashCode() => HashCode.Combine(Width, Height);
-
- public int CompareTo(DisplayResolution other)
- {
- var index = Width.CompareTo(other.Width);
- if (index == 0) index = Height.CompareTo(other.Height);
- return index;
- }
-
- public override string ToString()
- {
- return String.Format("{0}x{1}", Width, Height);
- }
- }
-
- private static IEnumerable FindAllDisplaySettings()
- {
- DEVMODE dm = new DEVMODE();
- for (int i = 0; EnumDisplaySettings(null, i, ref dm); i++)
- {
- if (dm.dmFields.HasFlag(DM.PelsWidth) && dm.dmFields.HasFlag(DM.PelsHeight) && dm.dmFields.HasFlag(DM.PelsHeight))
- yield return dm;
-
- dm = new DEVMODE();
- }
- }
-
- internal static DEVMODE? CurrentDisplaySettings()
- {
- DEVMODE dm = new DEVMODE();
- if (EnumDisplaySettings(null, ENUM_CURRENT_SETTINGS, ref dm))
- return dm;
- return null;
- }
-
- private static bool SetDisplaySettings(String type, DEVMODE? best)
- {
- if (best == null)
- return false;
-
- DEVMODE oldDm = new DEVMODE();
- if (!EnumDisplaySettings(null, ENUM_CURRENT_SETTINGS, ref oldDm))
- return false;
-
- Log.TraceObject("SetDisplaySettings:" + type + ":IN", oldDm);
-
- DEVMODE dm = best.Value;
-
- if (dm.dmPelsWidth == oldDm.dmPelsWidth &&
- dm.dmPelsHeight == oldDm.dmPelsHeight &&
- dm.dmDisplayFrequency == oldDm.dmDisplayFrequency)
- {
- Log.TraceLine(
- "DispChange: {0}, already set: {1}x{2}@{3}",
- type,
- oldDm.dmPelsWidth, oldDm.dmPelsHeight, oldDm.dmDisplayFrequency);
- return true;
- }
-
- var testChange = ChangeDisplaySettingsEx(
- null, ref dm, IntPtr.Zero,
- ChangeDisplaySettingsFlags.CDS_TEST, IntPtr.Zero);
- var applyChange = DISP_CHANGE.NotUpdated;
- Log.TraceObject("SetDisplaySettings:" + type + ":REQ", dm);
-
- if (testChange == DISP_CHANGE.Successful)
- {
- applyChange = ChangeDisplaySettingsEx(
- null, ref dm, IntPtr.Zero,
- ChangeDisplaySettingsFlags.CDS_RESET, IntPtr.Zero);
- }
-
- DEVMODE newDm = new DEVMODE();
- if (!EnumDisplaySettings(null, ENUM_CURRENT_SETTINGS, ref newDm))
- return false;
-
- Log.TraceObject("SetDisplaySettings:" + type + ":OUT", newDm);
-
- Log.TraceLine(
- "DispChange: {0}, Test: {1}, Set: {8}, from: {2}x{3}@{4}, to: {5}x{6}@{7}",
- type, testChange,
- oldDm.dmPelsWidth, oldDm.dmPelsHeight, oldDm.dmDisplayFrequency,
- newDm.dmPelsWidth, newDm.dmPelsHeight, newDm.dmDisplayFrequency,
- applyChange
- );
-
- return applyChange == DISP_CHANGE.Successful;
- }
-
- public static bool SetDisplaySettings(DisplayResolution size, int hz, String type = "DisplaySettings")
- {
- DEVMODE? best = FindAllDisplaySettings()
- .Where((dm) => dm.dmPelsWidth == size.Width && dm.dmPelsHeight == size.Height)
- .Where((dm) => dm.dmDisplayFrequency == hz)
- .First();
-
- if (best is null)
- return false;
-
- return SetDisplaySettings(type, best);
- }
-
- public static bool ResetCurrentResolution()
- {
- try
- {
- var dm = CurrentDisplaySettings();
-
- // Reset to best default
- var bestResolution = GetAllResolutions().Last();
- var bestRefreshRate = GetRefreshRates(bestResolution).Max();
- SetDisplaySettings(bestResolution, bestRefreshRate, "ResetToDefault");
-
- return SetDisplaySettings("Reset", dm);
- }
- catch (Exception e)
- {
- Log.TraceException("ResetResolution", e);
- return false;
- }
- }
-
- public static DisplayResolution[] GetAllResolutions()
- {
- return FindAllDisplaySettings()
- .Select((dm) => new DisplayResolution(dm.dmPelsWidth, dm.dmPelsHeight))
- .ToImmutableSortedSet()
- .ToArray();
- }
-
- public static DisplayResolution? GetResolution()
- {
- var dm = CurrentDisplaySettings();
- if (dm is not null)
- return new DisplayResolution(dm.Value.dmPelsWidth, dm.Value.dmPelsHeight);
-
- return null;
- }
-
- public static bool SetResolution(DisplayResolution size)
- {
- DEVMODE? best = FindAllDisplaySettings()
- .Where((dm) => dm.dmPelsWidth == size.Width && dm.dmPelsHeight == size.Height)
- .MaxBy((dm) => dm.dmDisplayFrequency);
-
- if (best == null)
- return false;
-
- return SetDisplaySettings("Resolution", best);
- }
-
- public static int[] GetRefreshRates(DisplayResolution? size = null)
- {
- if (size is null)
- size = GetResolution();
- if (size is null)
- return new int[0];
-
- return FindAllDisplaySettings()
- .Where((dm) => dm.dmPelsWidth == size?.Width && dm.dmPelsHeight == size?.Height)
- .Select((dm) => dm.dmDisplayFrequency)
- .ToHashSet()
- .ToArray();
- }
-
- public static int GetRefreshRate()
- {
- var dm = CurrentDisplaySettings();
-
- if (dm is not null)
- return dm.Value.dmDisplayFrequency;
-
- return -1;
- }
-
- public static bool SetRefreshRate(int hz)
- {
- var current = GetResolution();
- if (current is null)
- return false;
-
- return SetDisplaySettings(current.Value, hz, "SetRefreshRate");
- }
-
-
- enum DISP_CHANGE : int
- {
- Successful = 0,
- Restart = 1,
- Failed = -1,
- BadMode = -2,
- NotUpdated = -3,
- BadFlags = -4,
- BadParam = -5,
- BadDualView = -6
- }
-
- [Flags()]
- internal enum DM : int
- {
- Orientation = 0x1,
- PaperSize = 0x2,
- PaperLength = 0x4,
- PaperWidth = 0x8,
- Scale = 0x10,
- Position = 0x20,
- NUP = 0x40,
- DisplayOrientation = 0x80,
- Copies = 0x100,
- DefaultSource = 0x200,
- PrintQuality = 0x400,
- Color = 0x800,
- Duplex = 0x1000,
- YResolution = 0x2000,
- TTOption = 0x4000,
- Collate = 0x8000,
- FormName = 0x10000,
- LogPixels = 0x20000,
- BitsPerPixel = 0x40000,
- PelsWidth = 0x80000,
- PelsHeight = 0x100000,
- DisplayFlags = 0x200000,
- DisplayFrequency = 0x400000,
- ICMMethod = 0x800000,
- ICMIntent = 0x1000000,
- MeduaType = 0x2000000,
- DitherType = 0x4000000,
- PanningWidth = 0x8000000,
- PanningHeight = 0x10000000,
- DisplayFixedOutput = 0x20000000
- }
-
- internal struct POINTL
- {
- public Int32 x;
- public Int32 y;
- };
-
- [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
- internal struct DEVMODE
- {
- public const int CCHDEVICENAME = 32;
- public const int CCHFORMNAME = 32;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME)]
- [System.Runtime.InteropServices.FieldOffset(0)]
- public string dmDeviceName;
- [System.Runtime.InteropServices.FieldOffset(32)]
- public Int16 dmSpecVersion;
- [System.Runtime.InteropServices.FieldOffset(34)]
- public Int16 dmDriverVersion;
- [System.Runtime.InteropServices.FieldOffset(36)]
- public Int16 dmSize;
- [System.Runtime.InteropServices.FieldOffset(38)]
- public Int16 dmDriverExtra;
- [System.Runtime.InteropServices.FieldOffset(40)]
- public DM dmFields;
-
- [System.Runtime.InteropServices.FieldOffset(44)]
- Int16 dmOrientation;
- [System.Runtime.InteropServices.FieldOffset(46)]
- Int16 dmPaperSize;
- [System.Runtime.InteropServices.FieldOffset(48)]
- Int16 dmPaperLength;
- [System.Runtime.InteropServices.FieldOffset(50)]
- Int16 dmPaperWidth;
- [System.Runtime.InteropServices.FieldOffset(52)]
- Int16 dmScale;
- [System.Runtime.InteropServices.FieldOffset(54)]
- Int16 dmCopies;
- [System.Runtime.InteropServices.FieldOffset(56)]
- Int16 dmDefaultSource;
- [System.Runtime.InteropServices.FieldOffset(58)]
- Int16 dmPrintQuality;
-
- [System.Runtime.InteropServices.FieldOffset(44)]
- public POINTL dmPosition;
- [System.Runtime.InteropServices.FieldOffset(52)]
- public Int32 dmDisplayOrientation;
- [System.Runtime.InteropServices.FieldOffset(56)]
- public Int32 dmDisplayFixedOutput;
-
- [System.Runtime.InteropServices.FieldOffset(60)]
- public short dmColor; // See note below!
- [System.Runtime.InteropServices.FieldOffset(62)]
- public short dmDuplex; // See note below!
- [System.Runtime.InteropServices.FieldOffset(64)]
- public short dmYResolution;
- [System.Runtime.InteropServices.FieldOffset(66)]
- public short dmTTOption;
- [System.Runtime.InteropServices.FieldOffset(68)]
- public short dmCollate; // See note below!
- //[System.Runtime.InteropServices.FieldOffset(70)]
- //[MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHFORMNAME)]
- //public string dmFormName;
- [System.Runtime.InteropServices.FieldOffset(102)]
- public Int16 dmLogPixels;
- [System.Runtime.InteropServices.FieldOffset(104)]
- public Int32 dmBitsPerPel;
- [System.Runtime.InteropServices.FieldOffset(108)]
- public Int32 dmPelsWidth;
- [System.Runtime.InteropServices.FieldOffset(112)]
- public Int32 dmPelsHeight;
- [System.Runtime.InteropServices.FieldOffset(116)]
- public Int32 dmDisplayFlags;
- [System.Runtime.InteropServices.FieldOffset(116)]
- public Int32 dmNup;
- [System.Runtime.InteropServices.FieldOffset(120)]
- public Int32 dmDisplayFrequency;
- }
-
- [Flags()]
- public enum ChangeDisplaySettingsFlags : uint
- {
- CDS_NONE = 0,
- CDS_UPDATEREGISTRY = 0x00000001,
- CDS_TEST = 0x00000002,
- CDS_FULLSCREEN = 0x00000004,
- CDS_GLOBAL = 0x00000008,
- CDS_SET_PRIMARY = 0x00000010,
- CDS_VIDEOPARAMETERS = 0x00000020,
- CDS_ENABLE_UNSAFE_MODES = 0x00000100,
- CDS_DISABLE_UNSAFE_MODES = 0x00000200,
- CDS_RESET = 0x40000000,
- CDS_RESET_EX = 0x20000000,
- CDS_NORESET = 0x10000000
- }
-
- const int ENUM_CURRENT_SETTINGS = -1;
- const int ENUM_REGISTRY_SETTINGS = -2;
-
- [DllImport("user32.dll")]
- static extern bool EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE devMode);
-
- [DllImport("user32.dll")]
- static extern DISP_CHANGE ChangeDisplaySettingsEx(string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd, ChangeDisplaySettingsFlags dwflags, IntPtr lParam);
- }
-}
diff --git a/PowerControl/Helpers/ProcessorCores.cs b/PowerControl/Helpers/ProcessorCores.cs
deleted file mode 100644
index dc782b8..0000000
--- a/PowerControl/Helpers/ProcessorCores.cs
+++ /dev/null
@@ -1,190 +0,0 @@
-using PowerControl.External;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PowerControl.Helpers
-{
- internal class ProcessorCores
- {
- public static int GetProcessorCoreCount()
- {
- return GetProcessorCores().Count();
- }
-
- public static IntPtr GetProcessorMask(bool firstThreadOnly = false)
- {
- Int64 mask = 0;
-
- foreach (var process in GetProcessorCores())
- {
- // This works only up-to 63 CPUs
- Int64 processorMask = (Int64)process.ProcessorMask.ToUInt64();
-
- if (firstThreadOnly)
- processorMask = LSB(processorMask);
-
- mask |= processorMask;
- }
-
- return new IntPtr(mask);
- }
-
- public static bool HasSMTThreads()
- {
- foreach (var processorMask in GetProcessorMasks())
- {
- if (processorMask != LSB(processorMask))
- return true;
- }
-
- return false;
- }
-
- public static bool IsUsingSMT(int processId)
- {
- try
- {
- var p = Process.GetProcessById(processId);
- UInt64 mask = (UInt64)p.ProcessorAffinity.ToInt64();
-
- foreach (var processorMask in GetProcessorMasks())
- {
- // look for CPU that has more than 1 thread
- // and has both assigned to process
- var filtered = mask & processorMask;
- if (filtered != LSB(filtered))
- return true;
- }
-
- return false;
- }
- catch(ArgumentException)
- {
- return false;
- }
- }
-
- public static bool SetProcessSMT(int processId, bool allThreads)
- {
- try
- {
- var p = Process.GetProcessById(processId);
- UInt64 mask = (UInt64)p.ProcessorAffinity.ToInt64();
-
- foreach (var processorMask in GetProcessorMasks())
- {
- var selectedMask = mask & processorMask;
-
- if (selectedMask == 0)
- continue; // ignore not assigned processors
- else if (allThreads)
- mask |= processorMask; // assign all threads
- else
- mask = LSB(selectedMask) | (mask & ~processorMask); // assign only first thread
- }
-
- p.ProcessorAffinity = new IntPtr((Int64)mask);
- return true;
- }
- catch (ArgumentException)
- {
- return false;
- }
- }
-
- private static UInt64 LSB(UInt64 value)
- {
- return (UInt64)LSB((Int64)value);
- }
-
- private static Int64 LSB(Int64 value)
- {
- return (value & -value);
- }
-
- static IEnumerable GetProcessorMasks()
- {
- return GetProcessorCores().Select((p) => p.ProcessorMask.ToUInt64());
- }
-
- static IEnumerable GetProcessorCores()
- {
- return GetLogicalProcessorInformation().Where((p) => p.Relationship == LOGICAL_PROCESSOR_RELATIONSHIP.RelationProcessorCore);
- }
-
- static SYSTEM_LOGICAL_PROCESSOR_INFORMATION[] GetLogicalProcessorInformation()
- {
- int bufferSize = 0;
- GetLogicalProcessorInformation(IntPtr.Zero, ref bufferSize);
- if (bufferSize == 0)
- return new SYSTEM_LOGICAL_PROCESSOR_INFORMATION[0];
-
- int sizeOfEntry = Marshal.SizeOf();
- int numEntries = bufferSize / sizeOfEntry;
- var processors = new SYSTEM_LOGICAL_PROCESSOR_INFORMATION[numEntries];
-
- var handle = Marshal.AllocHGlobal(bufferSize);
- try
- {
- if (!GetLogicalProcessorInformation(handle, ref bufferSize))
- return new SYSTEM_LOGICAL_PROCESSOR_INFORMATION[0];
-
- for (int i = 0; i < processors.Length; i++)
- processors[i] = Marshal.PtrToStructure(IntPtr.Add(handle, sizeOfEntry * i));
-
- return processors;
- }
- finally
- {
- Marshal.FreeHGlobal(handle);
- }
- }
-
- // Taken from: https://stackoverflow.com/a/63744912
- [StructLayout(LayoutKind.Sequential)]
- struct CACHE_DESCRIPTOR
- {
- public byte Level;
- public byte Associativity;
- public ushort LineSize;
- public uint Size;
- public uint Type;
- };
-
- [StructLayout(LayoutKind.Explicit)]
- struct SYSTEM_LOGICAL_PROCESSOR_INFORMATION_UNION
- {
- [FieldOffset(0)] public byte ProcessorCore;
- [FieldOffset(0)] public uint NumaNode;
- [FieldOffset(0)] public CACHE_DESCRIPTOR Cache;
- [FieldOffset(0)] private UInt64 Reserved1;
- [FieldOffset(8)] private UInt64 Reserved2;
- };
-
- public enum LOGICAL_PROCESSOR_RELATIONSHIP
- {
- RelationProcessorCore,
- RelationNumaNode,
- RelationCache,
- RelationProcessorPackage,
- RelationGroup,
- RelationAll = 0xffff
- }
-
- [StructLayout(LayoutKind.Sequential)]
- struct SYSTEM_LOGICAL_PROCESSOR_INFORMATION
- {
- public UIntPtr ProcessorMask;
- public LOGICAL_PROCESSOR_RELATIONSHIP Relationship;
- public SYSTEM_LOGICAL_PROCESSOR_INFORMATION_UNION ProcessorInformation;
- }
-
- [DllImport("kernel32.dll")]
- static extern bool GetLogicalProcessorInformation(IntPtr buffer, ref int bufferSize);
- }
-}
diff --git a/PowerControl/Helpers/ProfileSettings.cs b/PowerControl/Helpers/ProfileSettings.cs
deleted file mode 100644
index 98b821e..0000000
--- a/PowerControl/Helpers/ProfileSettings.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Xml.Linq;
-using CommonHelpers;
-
-namespace PowerControl.Helper
-{
- public class ProfileSettings : BaseSettings
- {
- public static String UserProfilesPath
- {
- get
- {
- var exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
- var exeFolder = Path.GetDirectoryName(exePath) ?? Directory.GetCurrentDirectory();
- var exeGameProfiles = Path.Combine(exeFolder, "GameProfiles");
- if (!Directory.Exists(exeGameProfiles))
- Directory.CreateDirectory(exeGameProfiles);
- return exeGameProfiles;
- }
- }
-
- public String ProfileName { get; }
-
- public ProfileSettings(string profileName) : base("PersistentSettings")
- {
- this.ProfileName = profileName;
- this.ConfigFile = Path.Combine(UserProfilesPath, String.Format("PowerControl.Process.{0}.ini", profileName));
-
- this.SettingChanging += delegate { };
- this.SettingChanged += delegate { };
- }
-
- public String? GetValue(string key)
- {
- var result = base.Get(key, String.Empty);
- if (result == String.Empty)
- return null;
- return result;
- }
-
- public int GetInt(string key, int defaultValue)
- {
- return base.Get(key, defaultValue);
- }
-
- public void SetValue(string key, string value)
- {
- base.Set(key, value);
- }
- }
-}
diff --git a/PowerControl/Menu/MenuItem.cs b/PowerControl/Menu/MenuItem.cs
deleted file mode 100644
index cffeb2b..0000000
--- a/PowerControl/Menu/MenuItem.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-namespace PowerControl.Menu
-{
- public abstract class MenuItem
- {
- public static readonly String[] OSDHelpers =
- {
- "",
- "",
- };
-
- public enum Colors : int
- {
- Green,
- Blue,
- Redish,
- Red,
- White
- }
-
- public String Name { get; set; } = "";
- public bool Visible { get; set; } = true;
- public bool Selectable { get; set; }
-
- protected string Color(String text, Colors index)
- {
- return String.Format("{0}", text, (int)index);
- }
-
- public abstract string Render(MenuItem? selected);
-
- public abstract void CreateMenu(System.Windows.Forms.ContextMenuStrip contextMenu);
- public abstract void Update();
- public abstract void Reset();
-
- public abstract void SelectNext(int change);
- }
-}
diff --git a/PowerControl/Menu/MenuItemWithOptions.cs b/PowerControl/Menu/MenuItemWithOptions.cs
deleted file mode 100644
index 5a8485a..0000000
--- a/PowerControl/Menu/MenuItemWithOptions.cs
+++ /dev/null
@@ -1,268 +0,0 @@
-namespace PowerControl.Menu
-{
- public class MenuItemWithOptions : MenuItem
- {
- public IList Options { get; set; } = new List();
- public string? SelectedOption { get; private set; }
- public string? ActiveOption { get; set; }
- public string? ProfileOption { get; set; }
- public int ApplyDelay { get; set; }
- public bool CycleOptions { get; set; } = true;
- public string? PersistentKey { get; set; }
- public bool PersistOnCreate { get; set; } = true;
-
- public IList Impacts { get; set; } = new List();
-
- public Func? CurrentValue { get; set; }
- public Func? OptionsValues { get; set; }
- public Func? ApplyValue { get; set; }
- public Action? ImpactedBy { get; set; }
- public Action? AfterApply { get; set; }
- public Func? ResetValue { get; set; }
-
- public event Action ValueChanged;
-
- private System.Windows.Forms.Timer delayTimer = new System.Windows.Forms.Timer();
- private ToolStripMenuItem toolStripItem = new ToolStripMenuItem();
- private bool runAfterApply = false;
-
- public MenuItemWithOptions()
- {
- this.Selectable = true;
-
- ValueChanged += delegate { };
-
- delayTimer.Tick += delegate (object? sender, EventArgs e)
- {
- if (delayTimer != null)
- delayTimer.Stop();
-
- FinalizeSet();
- };
- }
-
- public override void Reset()
- {
- if (ResetValue == null)
- return;
-
- var resetOption = ResetValue();
- if (resetOption == null || resetOption == ActiveOption)
- return;
-
- Set(resetOption, true, false);
- }
-
- public override void Update()
- {
- if (CurrentValue != null)
- {
- var result = CurrentValue();
- if (result != null)
- {
- ActiveOption = result;
- Visible = true;
- }
- else
- {
- Visible = false;
- }
- }
-
- if (OptionsValues != null)
- {
- var result = OptionsValues();
- if (result != null)
- Options = result.ToList();
- else
- Visible = false;
- }
-
- if (ActiveOption == null && Options.Count > 0)
- ActiveOption = Options.First();
- }
-
- public void Set(String value, bool immediate, bool refresh)
- {
- if (delayTimer != null)
- delayTimer.Stop();
-
- SelectedOption = value;
- runAfterApply = refresh;
-
- if (ApplyDelay == 0 || immediate)
- {
- FinalizeSet();
- return;
- }
-
- delayTimer.Interval = ApplyDelay > 0 ? ApplyDelay : 1;
- delayTimer.Enabled = true;
- }
-
- private void FinalizeSet()
- {
- var wasOption = ActiveOption;
-
- if (ApplyValue != null && SelectedOption != null)
- {
- try
- {
- ActiveOption = ApplyValue(SelectedOption);
- }
- catch (Exception e)
- {
- CommonHelpers.Log.TraceException("FinalizeSet", Name, e);
- Update();
- }
- }
- else
- ActiveOption = SelectedOption;
-
- SelectedOption = null;
-
- if (wasOption != ActiveOption && ActiveOption != null)
- {
- if (AfterApply != null)
- AfterApply();
-
- foreach (var impact in Impacts)
- {
- if (impact.ImpactedBy is not null)
- impact.ImpactedBy(this, wasOption, ActiveOption);
- impact.Update();
- }
-
- ValueChanged(this, wasOption, ActiveOption);
- }
- }
-
- public override void CreateMenu(System.Windows.Forms.ContextMenuStrip contextMenu)
- {
- toolStripItem.Text = Name;
- contextMenu.Items.Add(toolStripItem);
- contextMenu.Opening += delegate
- {
- Update();
-
- toolStripItem.DropDownItems.Clear();
-
- foreach (var option in Options)
- {
- var item = new ToolStripMenuItem(option);
- item.Checked = option == (SelectedOption ?? ActiveOption);
- item.Click += delegate { Set(option, true, true); };
- toolStripItem.DropDownItems.Add(item);
- }
-
- toolStripItem.Visible = Visible && Options.Count > 0;
- };
- }
-
- private void SelectIndex(int index)
- {
- if (Options.Count == 0)
- return;
-
- Set(Options[Math.Clamp(index, 0, Options.Count - 1)], false, true);
- }
-
- public override void SelectNext(int change)
- {
- int index = Options.IndexOf(SelectedOption ?? ActiveOption ?? "");
- if (index < 0)
- {
- if (change > 0)
- SelectIndex(0); // select first
- else
- SelectIndex(Options.Count); // select last
- return;
- }
-
- if (CycleOptions)
- SelectIndex((index + change + Options.Count) % Options.Count);
- else
- SelectIndex(index + change);
- }
-
- public override string Render(MenuItem? selected)
- {
- string output = "";
-
- if (selected == this)
- output += Color(Name + ":", Colors.White).PadRight(30);
- else
- output += Color(Name + ":", Colors.Blue).PadRight(30);
-
- output += optionText(SelectedOption ?? ActiveOption);
-
- if (SelectedOption != null && ActiveOption != SelectedOption)
- output += " (active: " + optionText(ActiveOption) + ")";
-
- if (ProfileOption != null)
- {
- if (ProfileOption != ActiveOption && ProfileOption != SelectedOption)
- output += " (profile: " + optionText(ProfileOption) + ")";
- else
- output += " [P]";
- }
-
- return output;
- }
-
- private String optionText(String? option)
- {
- String text;
-
- if (option is null)
- text = Color("?", Colors.White);
- else if (option == (SelectedOption ?? ActiveOption))
- text = Color(option, Colors.Red);
- else if (option == ActiveOption)
- text = Color(option, Colors.White);
- else
- text = Color(option, Colors.Green);
-
- return text;
- }
-
- public static IEnumerable Order(IEnumerable items)
- {
- HashSet processed = new HashSet();
-
- // Try to run iteratively up to 10 times
- for (int i = 0; i < 10; i++)
- {
- List leftItems = new List();
-
- foreach (var item in items)
- {
- bool valid = item.Impacts.All((impactsItem) => processed.Contains(impactsItem));
-
- if (valid)
- {
- processed.Add(item);
- yield return item;
- }
- else
- {
- leftItems.Add(item);
- }
- }
-
- if (leftItems.Count() == 0)
- yield break;
-
- items = leftItems;
- }
-
- CommonHelpers.Log.TraceLine("PowerControl: Failed to order items: {0}",
- string.Join(", ", items.Select((item) => item.Name)));
-
- foreach (var item in items)
- {
- yield return item;
- }
- }
- }
-}
diff --git a/PowerControl/Menu/MenuRoot.cs b/PowerControl/Menu/MenuRoot.cs
deleted file mode 100644
index df2d0ac..0000000
--- a/PowerControl/Menu/MenuRoot.cs
+++ /dev/null
@@ -1,156 +0,0 @@
-using System.Text;
-
-namespace PowerControl.Menu
-{
- public class MenuRoot : MenuItem
- {
- public IList