Compare commits

..

77 Commits

Author SHA1 Message Date
seerge
24014dd20f Fix 2023-03-05 23:26:39 +01:00
seerge
321bc2623d Added support for animated GIF in animatrix 2023-03-05 23:14:48 +01:00
seerge
52b07843a2 UI Fixes 2023-03-05 19:59:07 +01:00
seerge
5038ff2315 Merge branch 'main' of https://github.com/seerge/g14-helper 2023-03-05 18:23:40 +01:00
seerge
c8f4c4b0d4 Added more actions for m3/m4, fixed scaling 2023-03-05 18:23:38 +01:00
seerge
319401af5d Update README.md 2023-03-04 13:34:27 +01:00
seerge
aa30f472ad Update README.md 2023-03-04 12:57:41 +01:00
seerge
b40eb50e90 Readme 2023-03-04 00:23:04 +01:00
seerge
1f47b031f6 Screenshot 2023-03-04 00:22:48 +01:00
seerge
84a3f01267 Readme 2023-03-04 00:13:30 +01:00
seerge
f9488fbf2f Merge branch 'main' of https://github.com/seerge/g14-helper 2023-03-04 00:12:02 +01:00
seerge
43d2ed656a Added animatrix control thanks to https://github.com/vddCore/Starlight 2023-03-04 00:11:59 +01:00
seerge
e9fa181d4e Fixed missing fan curve 2023-03-03 14:17:09 +01:00
seerge
58aa838e51 Update README.md 2023-03-03 12:50:28 +01:00
seerge
96c85f69fe Show performance notifications only when mode changes 2023-03-03 12:41:53 +01:00
seerge
8f215dafab Minor fixes 2023-03-03 01:00:47 +01:00
seerge
b3636fd447 Remember performance mode for plugged / battery 2023-03-02 21:05:02 +01:00
seerge
ed579f25d6 PPT for 2021 model 2023-03-02 19:17:10 +01:00
seerge
6a71a64c96 Removed GSharphelper task removal 2023-03-02 14:07:12 +01:00
seerge
ac69f1317e New screenshot 2023-03-02 13:01:06 +01:00
seerge
4b38d380b5 Fan label calibration 2023-03-02 12:51:56 +01:00
seerge
9a2f9afe5b Minor fixes, fan RPM display 2023-03-02 12:22:52 +01:00
seerge
ce9ec1b6df Merge branch 'main' of https://github.com/seerge/g14-helper 2023-03-02 00:07:15 +01:00
seerge
e68282050b Fan curve auto apply 2023-03-02 00:07:07 +01:00
seerge
6b8f61fab4 Update README.md 2023-03-01 18:36:53 +01:00
seerge
f59070cb96 Minor fixes 2023-03-01 11:45:43 +01:00
seerge
f47a00fde2 Update README.md 2023-02-28 19:42:30 +01:00
seerge
b15c15974e New screenshot 2023-02-28 19:25:04 +01:00
seerge
b5c47de3f2 Added power limits 2023-02-28 19:17:16 +01:00
seerge
6b88fe67d3 Fix for possible missing fans curve on G15 2023-02-28 17:32:47 +01:00
seerge
3ff2a5f946 New screenshot 2023-02-27 18:43:48 +01:00
seerge
c73c05c24a Project settings 2023-02-27 18:40:47 +01:00
seerge
1131035254 Basic key bindings, second keyboard color, minor fixes 2023-02-27 18:16:05 +01:00
seerge
1c23f8aad4 Merge branch 'main' of https://github.com/seerge/g14-helper 2023-02-25 13:24:34 +01:00
seerge
28aeeb7d57 Fixed GPU fan sensor 2023-02-25 13:24:31 +01:00
seerge
202cb84d12 Update README.md 2023-02-25 12:01:01 +01:00
seerge
0b4da0a66a Update README.md 2023-02-25 01:52:32 +01:00
seerge
bfa0a08cbc Merge branch 'main' of https://github.com/seerge/g14-helper 2023-02-25 01:43:18 +01:00
seerge
1417593413 Fixed bug with battery discharge sensor 2023-02-25 01:43:12 +01:00
seerge
5d4a08e1e2 Update README.md 2023-02-24 21:08:04 +01:00
seerge
8cc558e750 Update README.md 2023-02-24 21:07:42 +01:00
seerge
e0fe292358 Update README.md 2023-02-24 21:06:57 +01:00
seerge
a0bafa8843 Extra screenshot 2023-02-24 21:06:14 +01:00
seerge
b0a6163a1c Update README.md 2023-02-24 21:03:29 +01:00
seerge
f5805871d3 Update README.md 2023-02-24 21:02:58 +01:00
seerge
c811d940b1 Merge branch 'main' of https://github.com/seerge/g14-helper 2023-02-24 19:06:41 +01:00
seerge
a777929070 Resolution change fix attempt 2023-02-24 19:06:38 +01:00
seerge
9f72ba3486 Update README.md 2023-02-24 18:01:22 +01:00
seerge
d02703cf1c Wrap in case something goes wrong 2023-02-24 17:26:53 +01:00
seerge
4630fee687 Merge branch 'main' of https://github.com/seerge/g14-helper 2023-02-24 17:17:16 +01:00
seerge
e5890648b9 Added OSD notifications 2023-02-24 17:17:12 +01:00
seerge
c292226fa2 Update README.md 2023-02-23 19:56:22 +01:00
seerge
1c17c705de Charge limit will be applied every time powe mode changes (incl hibernate) 2023-02-23 19:50:06 +01:00
seerge
27f5ed50d5 Fixed possible crash 2023-02-23 16:05:31 +01:00
seerge
02ae48092b Minor fixes, Factory default profiles will apply immediately on click 2023-02-23 14:14:11 +01:00
seerge
41d92d76cc Readme and new screenshot 2023-02-23 00:41:57 +01:00
seerge
44c3d9f3c7 Custom fan profiles with editor 2023-02-23 00:25:41 +01:00
seerge
146150b1e7 Cleanup 2023-02-22 19:30:58 +01:00
seerge
ccf4ae5126 Temporarily removed notifications, as they require extra 20mb lib 2023-02-22 19:24:04 +01:00
seerge
249fef0bb1 Merge branch 'main' of https://github.com/seerge/g14-helper 2023-02-22 19:20:14 +01:00
seerge
2ee9110016 Rewrite of core ASUSWmi module, now app doesn't need admin permissions 2023-02-22 19:14:31 +01:00
seerge
bc1f3ab530 Merge pull request #14 from Albert24GG/notification-feature
Send notification on performance mode cycling
2023-02-21 23:13:49 +01:00
seerge
3cd62bc9e1 Merge branch 'main' into notification-feature 2023-02-21 23:12:55 +01:00
seerge
16f6f3f934 Merge branch 'main' of https://github.com/seerge/g14-helper 2023-02-21 21:54:16 +01:00
seerge
1f4afedc1d Sensor refresh timers 2023-02-21 21:54:13 +01:00
Albert24GG
c705ce2b5b Send notification on performance mode cycling 2023-02-21 22:51:52 +02:00
seerge
75942ebdb2 Update README.md 2023-02-21 20:07:49 +01:00
seerge
6d142213c8 Minor fix 2023-02-21 19:40:16 +01:00
seerge
bfcb97b158 Update README.md 2023-02-21 19:35:18 +01:00
seerge
f97765c5c2 Performance fix 2023-02-21 19:24:43 +01:00
seerge
19a8b0dc22 Update README.md 2023-02-21 19:15:43 +01:00
seerge
f209f211b5 Added CPU / GPU temps monitoring and Charge/discharge rates in Watts 2023-02-21 19:11:50 +01:00
seerge
81a0019b42 Assure gpu mode and refresh rate are set at startup 2023-02-20 17:24:24 +01:00
seerge
3778c255bc Merge branch 'main' of https://github.com/seerge/g14-helper 2023-02-20 16:51:51 +01:00
seerge
a6b597affe Text adjustments 2023-02-20 16:51:49 +01:00
seerge
4aaba5cee7 Update README.md 2023-02-19 22:40:27 +01:00
seerge
cbbe944c2b New screenshot 2023-02-19 22:21:16 +01:00
36 changed files with 4105 additions and 1102 deletions

212
ASUSWmi.cs Normal file
View File

@@ -0,0 +1,212 @@
using System.Diagnostics;
using System.Management;
using System.Runtime.InteropServices;
public class ASUSWmi
{
const string FILE_NAME = @"\\.\\ATKACPI";
const uint CONTROL_CODE = 0x0022240C;
const uint DSTS = 0x53545344;
const uint DEVS = 0x53564544;
public const uint CPU_Fan = 0x00110013;
public const uint GPU_Fan = 0x00110014;
public const uint PerformanceMode = 0x00120075; // Thermal Control
public const uint GPUEco = 0x00090020;
public const uint GPUMux = 0x00090016;
public const uint BatteryLimit = 0x00120057;
public const uint ScreenOverdrive = 0x00050019;
public const uint DevsCPUFanCurve = 0x00110024;
public const uint DevsGPUFanCurve = 0x00110025;
public const int PPT_TotalA0 = 0x001200A0;
public const int PPT_TotalA1 = 0x001200A1;
public const int PPT_CPUB0 = 0x001200B0;
public const int PPT_CPUB1 = 0x001200B1;
public const int PPT_CPUA2 = 0x001200A2;
public const int PerformanceBalanced = 0;
public const int PerformanceTurbo = 1;
public const int PerformanceSilent = 2;
public const int GPUModeEco = 0;
public const int GPUModeStandard = 1;
public const int GPUModeUltimate = 2;
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern IntPtr CreateFile(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile
);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool DeviceIoControl(
IntPtr hDevice,
uint dwIoControlCode,
byte[] lpInBuffer,
uint nInBufferSize,
byte[] lpOutBuffer,
uint nOutBufferSize,
ref uint lpBytesReturned,
IntPtr lpOverlapped
);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool CloseHandle(IntPtr hObject);
private const uint GENERIC_READ = 0x80000000;
private const uint GENERIC_WRITE = 0x40000000;
private const uint OPEN_EXISTING = 3;
private const uint FILE_ATTRIBUTE_NORMAL = 0x80;
private const uint FILE_SHARE_READ = 1;
private const uint FILE_SHARE_WRITE = 2;
private IntPtr handle;
public ASUSWmi()
{
handle = CreateFile(
FILE_NAME,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
IntPtr.Zero,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
IntPtr.Zero
);
if (handle == new IntPtr(-1))
{
throw new Exception("Can't connect to ACPI");
}
}
public void Control(uint dwIoControlCode, byte[] lpInBuffer, byte[] lpOutBuffer)
{
uint lpBytesReturned = 0;
bool result = DeviceIoControl(
handle,
dwIoControlCode,
lpInBuffer,
(uint)lpInBuffer.Length,
lpOutBuffer,
(uint)lpOutBuffer.Length,
ref lpBytesReturned,
IntPtr.Zero
);
}
public void Close()
{
CloseHandle(handle);
}
protected byte[] CallMethod(uint MethodID, byte[] args)
{
byte[] acpiBuf = new byte[8 + args.Length];
byte[] outBuffer = new byte[20];
BitConverter.GetBytes((uint)MethodID).CopyTo(acpiBuf, 0);
BitConverter.GetBytes((uint)args.Length).CopyTo(acpiBuf, 4);
Array.Copy(args, 0, acpiBuf, 8, args.Length);
// if (MethodID == DEVS) Debug.WriteLine(BitConverter.ToString(acpiBuf, 0, acpiBuf.Length));
Control(CONTROL_CODE, acpiBuf, outBuffer);
return outBuffer;
}
public void DeviceSet(uint DeviceID, int Status)
{
byte[] args = new byte[8];
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
BitConverter.GetBytes((uint)Status).CopyTo(args, 4);
CallMethod(DEVS, args);
}
public void DeviceSet(uint DeviceID, byte[] Params)
{
byte[] args = new byte[4 + Params.Length];
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
Params.CopyTo(args, 4);
CallMethod(DEVS, args);
}
public int DeviceGet(uint DeviceID)
{
byte[] args = new byte[8];
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
byte[] status = CallMethod(DSTS, args);
return BitConverter.ToInt32(status, 0) - 65536;
}
public byte[] DeviceGetBuffer(uint DeviceID, uint Status = 0)
{
byte[] args = new byte[8];
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
BitConverter.GetBytes((uint)Status).CopyTo(args, 4);
return CallMethod(DSTS, args);
}
public void SetFanCurve(int device, byte[] curve)
{
if (curve.Length != 16) return;
if (curve.All(singleByte => singleByte == 0)) return;
Debug.WriteLine(BitConverter.ToString(curve));
if (device == 1)
DeviceSet(DevsGPUFanCurve, curve);
else
DeviceSet(DevsCPUFanCurve, curve);
}
public byte[] GetFanCurve(int device, int mode = 0)
{
uint fan_mode;
// because it's asus, and modes are swapped here
switch (mode)
{
case 1: fan_mode = 2; break;
case 2: fan_mode = 1; break;
default: fan_mode = 0; break;
}
if (device == 1)
return DeviceGetBuffer(DevsGPUFanCurve, fan_mode);
else
return DeviceGetBuffer(DevsCPUFanCurve, fan_mode);
}
public void SubscribeToEvents(Action<object, EventArrivedEventArgs> EventHandler)
{
ManagementEventWatcher watcher = new ManagementEventWatcher();
watcher.EventArrived += new EventArrivedEventHandler(EventHandler);
watcher.Scope = new ManagementScope("root\\wmi");
watcher.Query = new WqlEventQuery("SELECT * FROM AsusAtkWmiEvent");
watcher.Start();
}
}

View File

@@ -0,0 +1,291 @@
// Source thanks to https://github.com/vddCore/Starlight :)
using System.Diagnostics;
using System.Text;
using Starlight.Communication;
namespace Starlight.AnimeMatrix
{
public class BuiltInAnimation
{
public enum Startup
{
GlitchConstruction,
StaticEmergence
}
public enum Shutdown
{
GlitchOut,
SeeYa
}
public enum Sleeping
{
BannerSwipe,
Starfield
}
public enum Running
{
BinaryBannerScroll,
RogLogoGlitch
}
public byte AsByte { get; }
public BuiltInAnimation(
Running running,
Sleeping sleeping,
Shutdown shutdown,
Startup startup
)
{
AsByte |= (byte)(((int)running & 0x01) << 0);
AsByte |= (byte)(((int)sleeping & 0x01) << 1);
AsByte |= (byte)(((int)shutdown & 0x01) << 2);
AsByte |= (byte)(((int)startup & 0x01) << 3);
}
}
internal class AnimeMatrixPacket : Packet
{
public AnimeMatrixPacket(byte[] command)
: base(0x5E, 640, command)
{
}
}
public enum BrightnessMode : byte
{
Off = 0,
Dim = 1,
Medium = 2,
Full = 3
}
public class AnimeMatrixDevice : Device
{
private const int UpdatePageLength = 0x0278;
public int LedCount => 1450;
public int Rows => 61;
private byte[] _displayBuffer = new byte[UpdatePageLength * 3];
private List<byte[]> frames = new List<byte[]>();
private int frameIndex = 0;
public AnimeMatrixDevice()
: base(0x0B05, 0x193B, 640)
{
}
public byte[] GetBuffer()
{
return _displayBuffer;
}
public void PresentNextFrame()
{
if (frameIndex >= frames.Count) frameIndex = 0;
_displayBuffer = frames[frameIndex];
Present();
frameIndex++;
}
public void ClearFrames()
{
frames.Clear();
frameIndex = 0;
}
public void AddFrame()
{
frames.Add(_displayBuffer.ToArray());
}
public void SendRaw(params byte[] data)
{
Set(Packet<AnimeMatrixPacket>(data));
}
public int EmptyColumns(int row)
{
return (int)Math.Ceiling(Math.Max(0, row - 11) / 2.0);
}
public int Columns(int row)
{
EnsureRowInRange(row);
return 34 - EmptyColumns(row);
}
public int RowToLinearAddress(int row)
{
EnsureRowInRange(row);
var ret = 0;
if (row > 0)
{
for (var i = 0; i < row; i++)
ret += Columns(i);
}
return ret;
}
public void WakeUp()
{
Set(Packet<AnimeMatrixPacket>(Encoding.ASCII.GetBytes("ASUS Tech.Inc.")));
}
public void SetLedLinear(int address, byte value)
{
EnsureAddressableLed(address);
_displayBuffer[address] = value;
}
public void SetLedLinearImmediate(int address, byte value)
{
EnsureAddressableLed(address);
_displayBuffer[address] = value;
Set(Packet<AnimeMatrixPacket>(0xC0, 0x02)
.AppendData(BitConverter.GetBytes((ushort)(address + 1)))
.AppendData(BitConverter.GetBytes((ushort)0x0001))
.AppendData(value)
);
Set(Packet<AnimeMatrixPacket>(0xC0, 0x03));
}
public void SetLedPlanar(int x, int y, byte value)
{
EnsureRowInRange(y);
var start = RowToLinearAddress(y) - EmptyColumns(y);
if (x > EmptyColumns(y))
SetLedLinear(start + x, value);
}
public void Clear(bool present = false)
{
for (var i = 0; i < _displayBuffer.Length; i++)
_displayBuffer[i] = 0;
if (present)
Present();
}
public void Present()
{
Set(Packet<AnimeMatrixPacket>(0xC0, 0x02)
.AppendData(BitConverter.GetBytes((ushort)(UpdatePageLength * 0 + 1)))
.AppendData(BitConverter.GetBytes((ushort)UpdatePageLength))
.AppendData(_displayBuffer[(UpdatePageLength * 0)..(UpdatePageLength * 1)])
);
Set(Packet<AnimeMatrixPacket>(0xC0, 0x02)
.AppendData(BitConverter.GetBytes((ushort)(UpdatePageLength * 1 + 1)))
.AppendData(BitConverter.GetBytes((ushort)UpdatePageLength))
.AppendData(_displayBuffer[(UpdatePageLength * 1)..(UpdatePageLength * 2)])
);
Set(Packet<AnimeMatrixPacket>(0xC0, 0x02)
.AppendData(BitConverter.GetBytes((ushort)(UpdatePageLength * 2 + 1)))
.AppendData(BitConverter.GetBytes((ushort)(LedCount - UpdatePageLength * 2)))
.AppendData(
_displayBuffer[(UpdatePageLength * 2)..(UpdatePageLength * 2 + (LedCount - UpdatePageLength * 2))])
);
Set(Packet<AnimeMatrixPacket>(0xC0, 0x03));
}
public void SetDisplayState(bool enable)
{
if (enable)
{
Set(Packet<AnimeMatrixPacket>(0xC3, 0x01)
.AppendData(0x00));
}
else
{
Set(Packet<AnimeMatrixPacket>(0xC3, 0x01)
.AppendData(0x80));
}
}
public void SetBrightness(BrightnessMode mode)
{
Set(Packet<AnimeMatrixPacket>(0xC0, 0x04)
.AppendData((byte)mode)
);
}
public void SetBuiltInAnimation(bool enable)
{
var enabled = enable ? (byte)0x00 : (byte)0x80;
Set(Packet<AnimeMatrixPacket>(0xC4, 0x01, enabled));
}
public void SetBuiltInAnimation(bool enable, BuiltInAnimation animation)
{
SetBuiltInAnimation(enable);
Set(Packet<AnimeMatrixPacket>(0xC5, animation.AsByte));
}
public void GenerateFrame(Image image)
{
int width = 34 * 3;
int height = 61;
float scale;
Bitmap canvas = new Bitmap(width, height);
scale = Math.Min((float)width / (float)image.Width, (float)height / (float)image.Height);
var graph = Graphics.FromImage(canvas);
var scaleWidth = (int)(image.Width * scale);
var scaleHeight = (int)(image.Height * scale);
graph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
graph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
graph.DrawImage(image, ((int)width - scaleWidth), ((int)height - scaleHeight) / 2, scaleWidth, scaleHeight);
Bitmap bmp = new Bitmap(canvas, 34, 61);
for (int y = 0; y < bmp.Height; y++)
{
for (int x = 0; x < bmp.Width; x++)
{
var pixel = bmp.GetPixel(x, y);
byte color = (byte)((pixel.R + pixel.G + pixel.B) / 3);
SetLedPlanar(x, y, color);
}
}
}
private void EnsureRowInRange(int row)
{
if (row < 0 || row >= Rows)
{
throw new IndexOutOfRangeException($"Y-coordinate should fall in range of [0, {Rows - 1}].");
}
}
private void EnsureAddressableLed(int address)
{
if (address < 0 || address >= LedCount)
{
throw new IndexOutOfRangeException($"Linear LED address must be in range of [0, {LedCount - 1}].");
}
}
}
}

143
AppConfig.cs Normal file
View File

@@ -0,0 +1,143 @@
using System.Text.Json;
public class AppConfig
{
public string appPath;
string configFile;
public Dictionary<string, object> config = new Dictionary<string, object>();
public AppConfig()
{
appPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\GHelper";
configFile = appPath + "\\config.json";
if (!System.IO.Directory.Exists(appPath))
System.IO.Directory.CreateDirectory(appPath);
if (File.Exists(configFile))
{
string text = File.ReadAllText(configFile);
try
{
config = JsonSerializer.Deserialize<Dictionary<string, object>>(text);
}
catch
{
initConfig();
}
}
else
{
initConfig();
}
}
private void initConfig()
{
config = new Dictionary<string, object>();
config["performance_mode"] = 0;
string jsonString = JsonSerializer.Serialize(config);
File.WriteAllText(configFile, jsonString);
}
public int getConfig(string name)
{
if (config.ContainsKey(name))
return int.Parse(config[name].ToString());
else return -1;
}
public string getConfigString(string name)
{
if (config.ContainsKey(name))
return config[name].ToString();
else return null;
}
public void setConfig(string name, int value)
{
config[name] = value;
string jsonString = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(configFile, jsonString);
}
public void setConfig(string name, string value)
{
config[name] = value;
string jsonString = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(configFile, jsonString);
}
public string getParamName(int device, string paramName = "fan_profile")
{
int mode = getConfig("performance_mode");
string name;
if (device == 1)
name = "gpu";
else
name = "cpu";
return paramName + "_" + name + "_" + mode;
}
public byte[] getFanConfig(int device)
{
string curveString = getConfigString(getParamName(device));
byte[] curve = { };
if (curveString is not null)
curve = StringToBytes(curveString);
return curve;
}
public void setFanConfig(int device, byte[] curve)
{
string bitCurve = BitConverter.ToString(curve);
setConfig(getParamName(device), bitCurve);
}
public static byte[] StringToBytes(string str)
{
String[] arr = str.Split('-');
byte[] array = new byte[arr.Length];
for (int i = 0; i < arr.Length; i++) array[i] = Convert.ToByte(arr[i], 16);
return array;
}
public byte[] getDefaultCurve(int device)
{
int mode = getConfig("performance_mode");
byte[] curve;
switch (mode)
{
case 1:
if (device == 1)
curve = StringToBytes("14-3F-44-48-4C-50-54-62-16-1F-26-2D-39-47-55-5F");
else
curve = StringToBytes("14-3F-44-48-4C-50-54-62-11-1A-22-29-34-43-51-5A");
break;
case 2:
if (device == 1)
curve = StringToBytes("3C-41-42-46-47-4B-4C-62-08-11-11-1D-1D-26-26-2D");
else
curve = StringToBytes("3C-41-42-46-47-4B-4C-62-03-0C-0C-16-16-22-22-29");
break;
default:
if (device == 1)
curve = StringToBytes("3A-3D-40-44-48-4D-51-62-0C-16-1D-1F-26-2D-34-4A");
else
curve = StringToBytes("3A-3D-40-44-48-4D-51-62-08-11-16-1A-22-29-30-45");
break;
}
return curve;
}
}

82
Aura.cs Normal file
View File

@@ -0,0 +1,82 @@
using HidLibrary;
public class Aura
{
static byte[] MESSAGE_SET = { 0x5d, 0xb5, 0,0,0 };
static byte[] MESSAGE_APPLY = { 0x5d, 0xb4};
public const int Static = 0;
public const int Breathe = 1;
public const int Strobe = 2;
public const int Rainbow = 3;
public const int Dingding = 4;
public const int SpeedSlow = 0xe1;
public const int SpeedMedium = 0xeb;
public const int SpeedHigh = 0xf5;
public static int Mode = Static;
public static Color Color1 = Color.White;
public static Color Color2 = Color.Black;
public static int Speed = SpeedSlow;
public static byte[] AuraMessage(int mode, Color color, Color color2, int speed)
{
byte[] msg = new byte[17];
msg[0] = 0x5d;
msg[1] = 0xb3;
msg[2] = 0x00; // Zone
msg[3] = (byte)mode; // Aura Mode
msg[4] = (byte)(color.R); // R
msg[5] = (byte)(color.G); // G
msg[6] = (byte)(color.B); // B
msg[7] = (byte)speed; // aura.speed as u8;
msg[8] = 0; // aura.direction as u8;
msg[10] = (byte)(color2.R); // R
msg[11] = (byte)(color2.G); // G
msg[12] = (byte)(color2.B); // B
return msg;
}
public static void ApplyAura()
{
HidDevice[] HidDeviceList;
int[] deviceIds = { 0x1854, 0x1869, 0x1866, 0x19b6 };
HidDeviceList = HidDevices.Enumerate(0x0b05, deviceIds).ToArray();
if (Mode == Dingding)
{
Mode = 10;
Speed = SpeedMedium;
}
else if (Mode == Rainbow)
{
Speed = SpeedMedium;
}
else
{
Speed = SpeedSlow;
}
foreach (HidDevice device in HidDeviceList)
{
if (device.IsConnected)
{
if (device.Description.IndexOf("HID") >= 0)
{
device.OpenDevice();
byte[] msg = AuraMessage(Mode, Color1, Color2, Speed);
device.Write(msg);
device.Write(MESSAGE_SET);
device.Write(MESSAGE_APPLY);
device.CloseDevice();
}
}
}
}
}

32
Communication/Device.cs Normal file
View File

@@ -0,0 +1,32 @@
// Source thanks to https://github.com/vddCore/Starlight :)
using Starlight.Communication.Platform;
namespace Starlight.Communication
{
public abstract class Device : IDisposable
{
private static UsbProvider _usbProvider;
protected Device(ushort vendorId, ushort productId, int maxFeatureReportLength)
{
_usbProvider = new WindowsUsbProvider(vendorId, productId, maxFeatureReportLength);
}
protected T Packet<T>(params byte[] command) where T : Packet
{
return (T)Activator.CreateInstance(typeof(T), command)!;
}
public void Set(Packet packet)
=> _usbProvider?.Set(packet.Data);
public byte[] Get(Packet packet)
=> _usbProvider?.Get(packet.Data);
public void Dispose()
{
_usbProvider?.Dispose();
}
}
}

58
Communication/Packet.cs Normal file
View File

@@ -0,0 +1,58 @@
// Source thanks to https://github.com/vddCore/Starlight :)
namespace Starlight.Communication
{
public abstract class Packet
{
private int _currentDataIndex = 1;
public byte[] Data { get; }
internal Packet(byte reportId, int packetLength, params byte[] data)
{
if (packetLength < 1)
{
throw new ArgumentOutOfRangeException(
nameof(packetLength),
"Packet length must be at least 1."
);
}
Data = new byte[packetLength];
Data[0] = reportId;
if (data.Length > 0)
{
if (_currentDataIndex >= Data.Length)
{
throw new ArgumentOutOfRangeException(
nameof(data),
"Your packet length does not allow for initial data to be appended."
);
}
AppendData(data);
}
}
public Packet AppendData(params byte[] data)
=> AppendData(out _, data);
public Packet AppendData(out int bytesWritten, params byte[] data)
{
bytesWritten = 0;
for (var i = 0;
i < data.Length && _currentDataIndex < Data.Length - 1;
i++, bytesWritten++, _currentDataIndex++)
{
if (_currentDataIndex > Data.Length - 1)
break;
Data[_currentDataIndex] = data[i];
}
return this;
}
}
}

View File

@@ -0,0 +1,19 @@
namespace Starlight.Communication.Platform
{
internal abstract class UsbProvider : IDisposable
{
protected ushort VendorID { get; }
protected ushort ProductID { get; }
protected UsbProvider(ushort vendorId, ushort productId)
{
VendorID = vendorId;
ProductID = productId;
}
public abstract void Set(byte[] data);
public abstract byte[] Get(byte[] data);
public abstract void Dispose();
}
}

View File

@@ -0,0 +1,79 @@
using System.ComponentModel;
using HidSharp;
namespace Starlight.Communication.Platform
{
internal class WindowsUsbProvider : UsbProvider
{
protected HidDevice HidDevice { get; }
protected HidStream HidStream { get; }
public WindowsUsbProvider(ushort vendorId, ushort productId, int maxFeatureReportLength)
: base(vendorId, productId)
{
try
{
HidDevice = DeviceList.Local
.GetHidDevices(vendorId, productId)
.First(x => x.GetMaxFeatureReportLength() == maxFeatureReportLength);
}
catch
{
throw new IOException("AniMe Matrix control device was not found on your machine.");
}
var config = new OpenConfiguration();
config.SetOption(OpenOption.Interruptible, true);
config.SetOption(OpenOption.Exclusive, false);
config.SetOption(OpenOption.Priority, 10);
HidStream = HidDevice.Open(config);
}
public override void Set(byte[] data)
{
WrapException(() =>
{
HidStream.SetFeature(data);
HidStream.Flush();
});
}
public override byte[] Get(byte[] data)
{
var outData = new byte[data.Length];
Array.Copy(data, outData, data.Length);
WrapException(() =>
{
HidStream.GetFeature(outData);
HidStream.Flush();
});
return data;
}
public override void Dispose()
{
HidStream.Dispose();
}
private void WrapException(Action action)
{
try
{
action();
}
catch (IOException e)
{
if (e.InnerException is Win32Exception w32e)
{
if (w32e.NativeErrorCode != 0)
{
throw;
}
}
}
}
}
}

300
Fans.Designer.cs generated Normal file
View File

@@ -0,0 +1,300 @@
namespace GHelper
{
partial class Fans
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
chartCPU = new System.Windows.Forms.DataVisualization.Charting.Chart();
buttonApply = new Button();
buttonReset = new Button();
chartGPU = new System.Windows.Forms.DataVisualization.Charting.Chart();
groupBox1 = new GroupBox();
labelApplied = new Label();
pictureFine = new PictureBox();
labelInfo = new Label();
labelCPU = new Label();
labelTotal = new Label();
label2 = new Label();
label1 = new Label();
trackCPU = new TrackBar();
trackTotal = new TrackBar();
buttonApplyPower = new Button();
checkAuto = new CheckBox();
((System.ComponentModel.ISupportInitialize)chartCPU).BeginInit();
((System.ComponentModel.ISupportInitialize)chartGPU).BeginInit();
groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureFine).BeginInit();
((System.ComponentModel.ISupportInitialize)trackCPU).BeginInit();
((System.ComponentModel.ISupportInitialize)trackTotal).BeginInit();
SuspendLayout();
//
// chartCPU
//
chartArea1.Name = "ChartArea1";
chartCPU.ChartAreas.Add(chartArea1);
chartCPU.Location = new Point(195, 14);
chartCPU.Margin = new Padding(2, 1, 2, 1);
chartCPU.Name = "chartCPU";
chartCPU.Size = new Size(416, 218);
chartCPU.TabIndex = 0;
chartCPU.Text = "chartCPU";
//
// buttonApply
//
buttonApply.Location = new Point(473, 476);
buttonApply.Margin = new Padding(2, 1, 2, 1);
buttonApply.Name = "buttonApply";
buttonApply.Size = new Size(137, 22);
buttonApply.TabIndex = 1;
buttonApply.Text = "Apply Fan Curve";
buttonApply.UseVisualStyleBackColor = true;
//
// buttonReset
//
buttonReset.Location = new Point(195, 476);
buttonReset.Margin = new Padding(2, 1, 2, 1);
buttonReset.Name = "buttonReset";
buttonReset.Size = new Size(137, 22);
buttonReset.TabIndex = 2;
buttonReset.Text = "Factory Defaults";
buttonReset.UseVisualStyleBackColor = true;
//
// chartGPU
//
chartArea2.Name = "ChartArea1";
chartGPU.ChartAreas.Add(chartArea2);
chartGPU.Location = new Point(195, 240);
chartGPU.Margin = new Padding(2, 1, 2, 1);
chartGPU.Name = "chartGPU";
chartGPU.Size = new Size(416, 225);
chartGPU.TabIndex = 3;
chartGPU.Text = "chart1";
//
// groupBox1
//
groupBox1.Controls.Add(labelApplied);
groupBox1.Controls.Add(pictureFine);
groupBox1.Controls.Add(labelInfo);
groupBox1.Controls.Add(labelCPU);
groupBox1.Controls.Add(labelTotal);
groupBox1.Controls.Add(label2);
groupBox1.Controls.Add(label1);
groupBox1.Controls.Add(trackCPU);
groupBox1.Controls.Add(trackTotal);
groupBox1.Location = new Point(6, 6);
groupBox1.Margin = new Padding(2, 1, 2, 1);
groupBox1.Name = "groupBox1";
groupBox1.Padding = new Padding(3, 2, 3, 2);
groupBox1.Size = new Size(178, 459);
groupBox1.TabIndex = 4;
groupBox1.TabStop = false;
groupBox1.Text = "Power Limits (PPT)";
//
// labelApplied
//
labelApplied.AutoSize = true;
labelApplied.ForeColor = Color.Tomato;
labelApplied.Location = new Point(8, 18);
labelApplied.Margin = new Padding(2, 0, 2, 0);
labelApplied.Name = "labelApplied";
labelApplied.Size = new Size(71, 15);
labelApplied.TabIndex = 13;
labelApplied.Text = "Not Applied";
//
// pictureFine
//
pictureFine.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
pictureFine.BackgroundImage = Properties.Resources.everything_is_fine_itsfine;
pictureFine.BackgroundImageLayout = ImageLayout.Zoom;
pictureFine.Location = new Point(5, 343);
pictureFine.Margin = new Padding(2, 1, 2, 1);
pictureFine.Name = "pictureFine";
pictureFine.Size = new Size(167, 112);
pictureFine.TabIndex = 12;
pictureFine.TabStop = false;
pictureFine.Visible = false;
//
// labelInfo
//
labelInfo.AutoSize = true;
labelInfo.Dock = DockStyle.Bottom;
labelInfo.Location = new Point(3, 442);
labelInfo.Margin = new Padding(2, 0, 2, 0);
labelInfo.Name = "labelInfo";
labelInfo.Size = new Size(32, 15);
labelInfo.TabIndex = 11;
labelInfo.Text = "label";
//
// labelCPU
//
labelCPU.AutoSize = true;
labelCPU.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
labelCPU.Location = new Point(106, 59);
labelCPU.Margin = new Padding(2, 0, 2, 0);
labelCPU.Name = "labelCPU";
labelCPU.Size = new Size(30, 15);
labelCPU.TabIndex = 10;
labelCPU.Text = "CPU";
labelCPU.TextAlign = ContentAlignment.MiddleCenter;
//
// labelTotal
//
labelTotal.AutoSize = true;
labelTotal.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
labelTotal.Location = new Point(21, 59);
labelTotal.Margin = new Padding(2, 0, 2, 0);
labelTotal.Name = "labelTotal";
labelTotal.Size = new Size(34, 15);
labelTotal.TabIndex = 9;
labelTotal.Text = "Total";
labelTotal.TextAlign = ContentAlignment.MiddleCenter;
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(108, 43);
label2.Margin = new Padding(2, 0, 2, 0);
label2.Name = "label2";
label2.Size = new Size(30, 15);
label2.TabIndex = 8;
label2.Text = "CPU";
label2.TextAlign = ContentAlignment.MiddleCenter;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(22, 43);
label1.Margin = new Padding(2, 0, 2, 0);
label1.Name = "label1";
label1.Size = new Size(32, 15);
label1.TabIndex = 7;
label1.Text = "Total";
label1.TextAlign = ContentAlignment.MiddleCenter;
//
// trackCPU
//
trackCPU.Location = new Point(109, 83);
trackCPU.Margin = new Padding(2, 1, 2, 1);
trackCPU.Maximum = 85;
trackCPU.Minimum = 15;
trackCPU.Name = "trackCPU";
trackCPU.Orientation = Orientation.Vertical;
trackCPU.Size = new Size(45, 208);
trackCPU.TabIndex = 6;
trackCPU.TickFrequency = 5;
trackCPU.Value = 80;
//
// trackTotal
//
trackTotal.Location = new Point(23, 83);
trackTotal.Margin = new Padding(2, 1, 2, 1);
trackTotal.Maximum = 150;
trackTotal.Minimum = 15;
trackTotal.Name = "trackTotal";
trackTotal.Orientation = Orientation.Vertical;
trackTotal.Size = new Size(45, 208);
trackTotal.TabIndex = 5;
trackTotal.TickFrequency = 5;
trackTotal.TickStyle = TickStyle.TopLeft;
trackTotal.Value = 125;
//
// buttonApplyPower
//
buttonApplyPower.Location = new Point(8, 476);
buttonApplyPower.Margin = new Padding(2, 1, 2, 1);
buttonApplyPower.Name = "buttonApplyPower";
buttonApplyPower.Size = new Size(176, 22);
buttonApplyPower.TabIndex = 11;
buttonApplyPower.Text = "Apply Power Limits";
buttonApplyPower.UseVisualStyleBackColor = true;
//
// checkAuto
//
checkAuto.AutoSize = true;
checkAuto.Location = new Point(381, 479);
checkAuto.Margin = new Padding(2, 1, 2, 1);
checkAuto.Name = "checkAuto";
checkAuto.Size = new Size(86, 19);
checkAuto.TabIndex = 12;
checkAuto.Text = "Auto Apply";
checkAuto.UseVisualStyleBackColor = true;
//
// Fans
//
AutoScaleDimensions = new SizeF(96F, 96F);
AutoScaleMode = AutoScaleMode.Dpi;
AutoSize = true;
ClientSize = new Size(621, 510);
Controls.Add(checkAuto);
Controls.Add(buttonApplyPower);
Controls.Add(groupBox1);
Controls.Add(chartGPU);
Controls.Add(buttonReset);
Controls.Add(buttonApply);
Controls.Add(chartCPU);
Margin = new Padding(2, 1, 2, 1);
MaximizeBox = false;
MdiChildrenMinimizedAnchorBottom = false;
MinimizeBox = false;
Name = "Fans";
ShowIcon = false;
ShowInTaskbar = false;
StartPosition = FormStartPosition.CenterScreen;
Text = "Fans and Power";
((System.ComponentModel.ISupportInitialize)chartCPU).EndInit();
((System.ComponentModel.ISupportInitialize)chartGPU).EndInit();
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureFine).EndInit();
((System.ComponentModel.ISupportInitialize)trackCPU).EndInit();
((System.ComponentModel.ISupportInitialize)trackTotal).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private System.Windows.Forms.DataVisualization.Charting.Chart chartCPU;
private Button buttonApply;
private Button buttonReset;
private System.Windows.Forms.DataVisualization.Charting.Chart chartGPU;
private GroupBox groupBox1;
private Label labelCPU;
private Label labelTotal;
private Label label2;
private Label label1;
private TrackBar trackCPU;
private TrackBar trackTotal;
private Button buttonApplyPower;
private Label labelInfo;
private PictureBox pictureFine;
private Label labelApplied;
private CheckBox checkAuto;
}
}

346
Fans.cs Normal file
View File

@@ -0,0 +1,346 @@
using System;
using System.Diagnostics;
using System.Windows.Forms.DataVisualization.Charting;
namespace GHelper
{
public partial class Fans : Form
{
DataPoint curPoint = null;
Series seriesCPU;
Series seriesGPU;
const int MaxTotal = 150;
const int MinTotal = 15;
const int DefaultTotal = 125;
const int MaxCPU = 90;
const int MinCPU = 15;
const int DefaultCPU = 80;
void SetChart(Chart chart, int device)
{
string title;
if (device == 1)
title = "GPU Fan Profile";
else
title = "CPU Fan Profile";
if (Program.settingsForm.perfName.Length > 0)
title += ": " + Program.settingsForm.perfName;
if (chart.Titles.Count > 0)
chart.Titles[0].Text = title;
else
chart.Titles.Add(title);
chart.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.LightGray;
chart.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.LightGray;
chart.ChartAreas[0].AxisX.Minimum = 10;
chart.ChartAreas[0].AxisX.Maximum = 100;
chart.ChartAreas[0].AxisX.Interval = 10;
chart.ChartAreas[0].AxisY.Minimum = 0;
chart.ChartAreas[0].AxisY.Maximum = 100;
chart.ChartAreas[0].AxisY.LabelStyle.Font = new Font("Arial", 7F);
chart.ChartAreas[0].AxisY.CustomLabels.Add(-2, 2, "OFF");
for (int i = 1; i <= 9; i++)
chart.ChartAreas[0].AxisY.CustomLabels.Add(i * 10 - 2, i * 10 + 2, (1800 + 400 * i).ToString());
chart.ChartAreas[0].AxisY.CustomLabels.Add(98, 102, "RPM");
chart.ChartAreas[0].AxisY.Interval = 10;
if (chart.Legends.Count > 0)
chart.Legends[0].Enabled = false;
}
private void Fans_Shown(object? sender, EventArgs e)
{
Top = Program.settingsForm.Top;
Left = Program.settingsForm.Left - Width - 5;
}
public Fans()
{
InitializeComponent();
FormClosing += Fans_FormClosing;
seriesCPU = chartCPU.Series.Add("CPU");
seriesGPU = chartGPU.Series.Add("GPU");
seriesCPU.Color = Color.Blue;
seriesGPU.Color = Color.Red;
chartCPU.MouseMove += ChartCPU_MouseMove;
chartCPU.MouseUp += ChartCPU_MouseUp;
chartGPU.MouseMove += ChartCPU_MouseMove;
chartGPU.MouseUp += ChartCPU_MouseUp;
buttonReset.Click += ButtonReset_Click;
buttonApply.Click += ButtonApply_Click;
trackTotal.Maximum = MaxTotal;
trackTotal.Minimum = MinTotal;
trackCPU.Maximum = MaxCPU;
trackCPU.Minimum = MinCPU;
trackCPU.Scroll += TrackCPU_Scroll;
trackTotal.Scroll += TrackTotal_Scroll;
buttonApplyPower.Click += ButtonApplyPower_Click;
checkAuto.Click += CheckAuto_Click;
//labelInfo.MaximumSize = new Size(280, 0);
labelInfo.Text = "Power Limits (PPT) is\nexperimental feature.\n\nValues will be applied\nonly after you click 'Apply'\nand reset after performance\nmode changes.\n\nUse carefully and\non your own risk!";
LoadFans();
VisualisePower(true);
Shown += Fans_Shown;
}
private void CheckAuto_Click(object? sender, EventArgs e)
{
if (sender is null)
return;
CheckBox chk = (CheckBox)sender;
Program.config.setConfig("auto_apply_" + Program.config.getConfig("performance_mode"), chk.Checked ? 1 : 0);
}
private void Fans_FormClosing(object? sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
Hide();
}
}
private void ButtonApplyPower_Click(object? sender, EventArgs e)
{
int limit_total = trackTotal.Value;
int limit_cpu = trackCPU.Value;
Program.config.setConfig("limit_total", limit_total);
Program.config.setConfig("limit_cpu", limit_cpu);
Program.wmi.DeviceSet(ASUSWmi.PPT_TotalA0, limit_total);
Program.wmi.DeviceSet(ASUSWmi.PPT_TotalA1, limit_total);
Program.wmi.DeviceSet(ASUSWmi.PPT_CPUB0, limit_cpu);
Program.wmi.DeviceSet(ASUSWmi.PPT_CPUA2, limit_cpu);
labelApplied.ForeColor = Color.Blue;
labelApplied.Text = "Applied";
}
public void VisualisePower(bool init = false)
{
int limit_total;
int limit_cpu;
if (init)
{
limit_total = Program.config.getConfig("limit_total");
limit_cpu = Program.config.getConfig("limit_cpu");
}
else
{
limit_total = trackTotal.Value;
limit_cpu = trackCPU.Value;
}
if (limit_total < 0) limit_total = DefaultTotal;
if (limit_total > MaxTotal) limit_total = MaxTotal;
if (limit_total < MinTotal) limit_total = MinTotal;
if (limit_cpu < 0) limit_cpu = DefaultCPU;
if (limit_cpu > MaxCPU) limit_cpu = MaxCPU;
if (limit_cpu < MinCPU) limit_cpu = MinCPU;
if (limit_cpu > limit_total) limit_cpu = limit_total;
trackTotal.Value = limit_total;
trackCPU.Value = limit_cpu;
labelTotal.Text = trackTotal.Value.ToString() + "W";
labelCPU.Text = trackCPU.Value.ToString() + "W";
pictureFine.Visible = (limit_cpu > 85 || limit_total > 145);
}
private void TrackTotal_Scroll(object? sender, EventArgs e)
{
VisualisePower();
}
private void TrackCPU_Scroll(object? sender, EventArgs e)
{
VisualisePower();
}
public void ResetApplyLabel()
{
labelApplied.ForeColor = Color.Red;
labelApplied.Text = "Not Applied";
}
public void LoadFans()
{
SetChart(chartCPU, 0);
SetChart(chartGPU, 1);
LoadProfile(seriesCPU, 0);
LoadProfile(seriesGPU, 1);
int auto_apply = Program.config.getConfig("auto_apply_" + Program.config.getConfig("performance_mode"));
checkAuto.Checked = (auto_apply == 1);
}
void LoadProfile(Series series, int device, int def = 0)
{
series.ChartType = SeriesChartType.Line;
series.MarkerSize = 10;
series.MarkerStyle = MarkerStyle.Circle;
series.Points.Clear();
int mode = Program.config.getConfig("performance_mode");
byte[] curve = Program.config.getFanConfig(device);
if (def == 1 || curve.Length != 16)
curve = Program.wmi.GetFanCurve(device, mode);
if (curve.Length != 16 || curve.All(singleByte => singleByte == 0))
curve = Program.config.getDefaultCurve(device);
//Debug.WriteLine(BitConverter.ToString(curve));
byte old = 0;
for (int i = 0; i < 8; i++)
{
if (curve[i] == old) curve[i]++; // preventing 2 points in same spot from default asus profiles
series.Points.AddXY(curve[i], curve[i + 8]);
old = curve[i];
}
}
void ApplyProfile(Series series, int device)
{
byte[] curve = new byte[16];
int i = 0;
foreach (DataPoint point in series.Points)
{
curve[i] = (byte)point.XValue;
curve[i + 8] = (byte)point.YValues.First();
i++;
}
Program.config.setFanConfig(device, curve);
Program.wmi.SetFanCurve(device, curve);
}
private void ButtonApply_Click(object? sender, EventArgs e)
{
ApplyProfile(seriesCPU, 0);
ApplyProfile(seriesGPU, 1);
}
private void ButtonReset_Click(object? sender, EventArgs e)
{
LoadProfile(seriesCPU, 0, 1);
LoadProfile(seriesGPU, 1, 1);
checkAuto.Checked = false;
Program.config.setConfig("auto_apply_" + Program.config.getConfig("performance_mode"), 0);
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, Program.config.getConfig("performance_mode"));
ResetApplyLabel();
}
private void ChartCPU_MouseUp(object? sender, MouseEventArgs e)
{
curPoint = null;
}
private void ChartCPU_MouseMove(object? sender, MouseEventArgs e)
{
if (sender is null) return;
Chart chart = (Chart)sender;
if (e.Button.HasFlag(MouseButtons.Left))
{
ChartArea ca = chart.ChartAreas[0];
Axis ax = ca.AxisX;
Axis ay = ca.AxisY;
HitTestResult hit = chart.HitTest(e.X, e.Y);
if (hit.Series is not null && hit.PointIndex >= 0)
curPoint = hit.Series.Points[hit.PointIndex];
if (curPoint != null)
{
Series s = hit.Series;
double dx, dy, dymin;
try
{
dx = ax.PixelPositionToValue(e.X);
dy = ay.PixelPositionToValue(e.Y);
if (dx < 20) dx = 20;
if (dx > 100) dx = 100;
if (dy < 0) dy = 0;
if (dy > 100) dy = 100;
dymin = (dx - 60) * 1.2;
if (dy < dymin) dy = dymin;
curPoint.XValue = dx;
curPoint.YValues[0] = dy;
}
catch
{
Debug.WriteLine(e.Y);
}
}
}
}
}
}

60
Fans.resx Normal file
View File

@@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -2,14 +2,21 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net7.0-windows8.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>True</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<IsPublishable>True</IsPublishable>
<ApplicationManifest>app.manifest</ApplicationManifest>
<StartupObject>GHelper.Program</StartupObject>
<ApplicationIcon>Resources\standard.ico</ApplicationIcon>
<ApplicationIcon>favicon.ico</ApplicationIcon>
<Platforms>AnyCPU;x64</Platforms>
<SupportedOSPlatformVersion>8.0</SupportedOSPlatformVersion>
<AssemblyName>GHelper</AssemblyName>
<PlatformTarget>x64</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AssemblyVersion>0.16</AssemblyVersion>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
@@ -24,15 +31,17 @@
<ItemGroup>
<Content Include="Resources\standard.ico">
<Content Include="favicon.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="hidlibrary" Version="3.3.40" />
<PackageReference Include="HidSharpCore" Version="1.2.1.1" />
<PackageReference Include="System.Management" Version="7.0.0" />
<PackageReference Include="TaskScheduler" Version="2.10.1" />
<PackageReference Include="WinForms.DataVisualization" Version="1.7.0" />
</ItemGroup>
<ItemGroup>
@@ -46,22 +55,22 @@
<ItemGroup>
<Content Include="Resources\eco.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
<Content Include="Resources\icons8-charging-battery-48.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
<Content Include="Resources\icons8-laptop-48.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
<Content Include="Resources\icons8-speed-48.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
<Content Include="Resources\icons8-video-card-48.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
<Content Include="Resources\ultimate.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
</ItemGroup>
@@ -92,4 +101,8 @@
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="screenshots\" />
</ItemGroup>
</Project>

View File

@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33403.182
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GHelper", "GHelper.csproj", "{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GHelper", "GHelper.csproj", "{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B6E44CC6-5D28-4CB9-8EE2-BE9D6238E2D6}"
ProjectSection(SolutionItems) = preProject
@@ -13,13 +13,19 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Release|Any CPU.Build.0 = Release|Any CPU
{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Debug|Any CPU.ActiveCfg = Debug|x64
{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Debug|Any CPU.Build.0 = Debug|x64
{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Debug|x64.ActiveCfg = Release|x64
{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Debug|x64.Build.0 = Release|x64
{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Release|Any CPU.ActiveCfg = Release|x64
{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Release|Any CPU.Build.0 = Release|x64
{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Release|x64.ActiveCfg = Release|x64
{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

173
Keyboard.Designer.cs generated Normal file
View File

@@ -0,0 +1,173 @@
namespace GHelper
{
partial class Keyboard
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
groupBox1 = new GroupBox();
textM4 = new TextBox();
textM3 = new TextBox();
comboM4 = new ComboBox();
labelM4 = new Label();
comboM3 = new ComboBox();
labelM3 = new Label();
textFNF4 = new TextBox();
comboFNF4 = new ComboBox();
labelFNF4 = new Label();
groupBox1.SuspendLayout();
SuspendLayout();
//
// groupBox1
//
groupBox1.Controls.Add(textFNF4);
groupBox1.Controls.Add(comboFNF4);
groupBox1.Controls.Add(labelFNF4);
groupBox1.Controls.Add(textM4);
groupBox1.Controls.Add(textM3);
groupBox1.Controls.Add(comboM4);
groupBox1.Controls.Add(labelM4);
groupBox1.Controls.Add(comboM3);
groupBox1.Controls.Add(labelM3);
groupBox1.Dock = DockStyle.Top;
groupBox1.Location = new Point(10, 10);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(751, 242);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Key Bindings";
//
// textM4
//
textM4.Location = new Point(411, 113);
textM4.Name = "textM4";
textM4.PlaceholderText = "action";
textM4.Size = new Size(320, 39);
textM4.TabIndex = 5;
//
// textM3
//
textM3.Location = new Point(411, 54);
textM3.Name = "textM3";
textM3.PlaceholderText = "notepad /p \"file.txt\"";
textM3.Size = new Size(320, 39);
textM3.TabIndex = 4;
//
// comboM4
//
comboM4.FormattingEnabled = true;
comboM4.Items.AddRange(new object[] { "Performance Mode", "Open G-Helper window", "Custom" });
comboM4.Location = new Point(93, 112);
comboM4.Name = "comboM4";
comboM4.Size = new Size(312, 40);
comboM4.TabIndex = 3;
//
// labelM4
//
labelM4.AutoSize = true;
labelM4.Location = new Point(25, 116);
labelM4.Name = "labelM4";
labelM4.Size = new Size(54, 32);
labelM4.TabIndex = 2;
labelM4.Text = "M4:";
//
// comboM3
//
comboM3.FormattingEnabled = true;
comboM3.Items.AddRange(new object[] { "Default", "Volume Mute", "Play / Pause", "PrintScreen", "Toggle Aura", "Custom" });
comboM3.Location = new Point(93, 54);
comboM3.Name = "comboM3";
comboM3.Size = new Size(312, 40);
comboM3.TabIndex = 1;
//
// labelM3
//
labelM3.AutoSize = true;
labelM3.Location = new Point(25, 58);
labelM3.Name = "labelM3";
labelM3.Size = new Size(54, 32);
labelM3.TabIndex = 0;
labelM3.Text = "M3:";
//
// textFNF4
//
textFNF4.Location = new Point(411, 176);
textFNF4.Name = "textFNF4";
textFNF4.PlaceholderText = "action";
textFNF4.Size = new Size(320, 39);
textFNF4.TabIndex = 8;
//
// comboFNF4
//
comboFNF4.FormattingEnabled = true;
comboFNF4.Location = new Point(93, 175);
comboFNF4.Name = "comboFNF4";
comboFNF4.Size = new Size(312, 40);
comboFNF4.TabIndex = 7;
//
// labelFNF4
//
labelFNF4.AutoSize = true;
labelFNF4.Location = new Point(2, 178);
labelFNF4.Name = "labelFNF4";
labelFNF4.Size = new Size(90, 32);
labelFNF4.TabIndex = 6;
labelFNF4.Text = "FN+F4:";
//
// Keyboard
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(771, 858);
Controls.Add(groupBox1);
FormBorderStyle = FormBorderStyle.FixedSingle;
MaximizeBox = false;
MdiChildrenMinimizedAnchorBottom = false;
MinimizeBox = false;
Name = "Keyboard";
Padding = new Padding(10);
ShowIcon = false;
ShowInTaskbar = false;
Text = "Keyboard";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private Label labelM3;
private ComboBox comboM3;
private ComboBox comboM4;
private Label labelM4;
private TextBox textM4;
private TextBox textM3;
private TextBox textFNF4;
private ComboBox comboFNF4;
private Label labelFNF4;
}
}

69
Keyboard.cs Normal file
View File

@@ -0,0 +1,69 @@
namespace GHelper
{
public partial class Keyboard : Form
{
Dictionary<string, string> customActions = new Dictionary<string, string>
{
{"","--------------" },
{"mute", "Volume Mute"},
{"screenshot", "Screenshot"},
{"play", "Play/Pause"},
{"aura", "Aura"},
{"ghelper", "Open GHelper"},
{"custom", "Custom"}
};
private void SetKeyCombo(ComboBox combo, TextBox txbox, string name)
{
if (name == "m4")
customActions[""] = "Performance";
if (name == "fnf4")
{
customActions[""] = "Aura";
customActions.Remove("aura");
}
combo.DropDownStyle = ComboBoxStyle.DropDownList;
combo.DataSource = new BindingSource(customActions, null);
combo.DisplayMember = "Value";
combo.ValueMember = "Key";
string action = Program.config.getConfigString(name);
combo.SelectedValue = (action is not null) ? action : "";
if (combo.SelectedValue is null) combo.SelectedValue = "";
combo.SelectedValueChanged += delegate
{
if (combo.SelectedValue is not null)
Program.config.setConfig(name, combo.SelectedValue.ToString());
};
txbox.Text = Program.config.getConfigString(name + "_custom");
txbox.TextChanged += delegate
{
Program.config.setConfig(name + "_custom", txbox.Text);
};
}
public Keyboard()
{
InitializeComponent();
SetKeyCombo(comboM3, textM3, "m3");
SetKeyCombo(comboM4, textM4, "m4");
SetKeyCombo(comboFNF4, textFNF4, "fnf4");
Shown += Keyboard_Shown;
}
private void Keyboard_Shown(object? sender, EventArgs e)
{
Top = Program.settingsForm.Top;
Left = Program.settingsForm.Left - Width - 5;
}
}
}

60
Keyboard.resx Normal file
View File

@@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

277
NativeMethods.cs Normal file
View File

@@ -0,0 +1,277 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
public class NativeMethods
{
public const int KEYEVENTF_EXTENDEDKEY = 1;
public const int KEYEVENTF_KEYUP = 2;
public const int VK_MEDIA_NEXT_TRACK = 0xB0;
public const int VK_MEDIA_PLAY_PAUSE = 0xB3;
public const int VK_MEDIA_PREV_TRACK = 0xB1;
public const int VK_VOLUME_MUTE = 0xAD;
public const int VK_SNAPSHOT = 0x2C;
[DllImport("user32.dll", SetLastError = true)]
public static extern void keybd_event(byte virtualKey, byte scanCode, uint flags, IntPtr extraInfo);
public static void KeyPress(int key = VK_MEDIA_PLAY_PAUSE)
{
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
}
[DllImport("user32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
public const int SW_RESTORE = 9;
public static bool SwitchToCurrent()
{
IntPtr hWnd = IntPtr.Zero;
Process process = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(process.ProcessName);
foreach (Process _process in processes)
{
if (_process.Id != process.Id)
{
if (_process.MainWindowHandle != IntPtr.Zero)
{
Debug.WriteLine(_process.Id);
Debug.WriteLine(process.Id);
hWnd = _process.MainWindowHandle;
ShowWindowAsync(hWnd, SW_RESTORE);
}
return true;
break;
}
}
return false;
}
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerWriteDCValueIndex(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid,
int AcValueIndex);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerWriteACValueIndex(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid,
int AcValueIndex);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerReadACValueIndex(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid,
out IntPtr AcValueIndex
);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerReadDCValueIndex(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid,
out IntPtr AcValueIndex
);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerSetActiveScheme(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerGetActiveScheme(IntPtr UserPowerKey, out IntPtr ActivePolicyGuid);
static readonly Guid GUID_CPU = new Guid("54533251-82be-4824-96c1-47b60b740d00");
static readonly Guid GUID_BOOST = new Guid("be337238-0d82-4146-a960-4f3749d470c7");
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct DEVMODE
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string dmDeviceName;
public short dmSpecVersion;
public short dmDriverVersion;
public short dmSize;
public short dmDriverExtra;
public int dmFields;
public int dmPositionX;
public int dmPositionY;
public int dmDisplayOrientation;
public int dmDisplayFixedOutput;
public short dmColor;
public short dmDuplex;
public short dmYResolution;
public short dmTTOption;
public short dmCollate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string dmFormName;
public short dmLogPixels;
public short dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
public int dmICMMethod;
public int dmICMIntent;
public int dmMediaType;
public int dmDitherType;
public int dmReserved1;
public int dmReserved2;
public int dmPanningWidth;
public int dmPanningHeight;
};
[Flags()]
public enum DisplaySettingsFlags : int
{
CDS_UPDATEREGISTRY = 1,
CDS_TEST = 2,
CDS_FULLSCREEN = 4,
CDS_GLOBAL = 8,
CDS_SET_PRIMARY = 0x10,
CDS_RESET = 0x40000000,
CDS_NORESET = 0x10000000
}
// PInvoke declaration for EnumDisplaySettings Win32 API
[DllImport("user32.dll")]
public static extern int EnumDisplaySettingsEx(
string lpszDeviceName,
int iModeNum,
ref DEVMODE lpDevMode);
// PInvoke declaration for ChangeDisplaySettings Win32 API
[DllImport("user32.dll")]
public static extern int ChangeDisplaySettingsEx(
string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd,
DisplaySettingsFlags dwflags, IntPtr lParam);
public const int ENUM_CURRENT_SETTINGS = -1;
public const string laptopScreenName = "\\\\.\\DISPLAY1";
public static DEVMODE CreateDevmode()
{
DEVMODE dm = new DEVMODE();
dm.dmDeviceName = new String(new char[32]);
dm.dmFormName = new String(new char[32]);
dm.dmSize = (short)Marshal.SizeOf(dm);
return dm;
}
public static Screen FindLaptopScreen()
{
var screens = Screen.AllScreens;
Screen laptopScreen = null;
foreach (var screen in screens)
{
if (screen.DeviceName == laptopScreenName)
{
laptopScreen = screen;
}
}
if (laptopScreen is null) return null;
else return laptopScreen;
}
public static int GetRefreshRate()
{
DEVMODE dm = CreateDevmode();
Screen laptopScreen = FindLaptopScreen();
int frequency = -1;
if (laptopScreen is null)
return -1;
if (0 != NativeMethods.EnumDisplaySettingsEx(laptopScreen.DeviceName, NativeMethods.ENUM_CURRENT_SETTINGS, ref dm))
{
frequency = dm.dmDisplayFrequency;
}
return frequency;
}
public static int SetRefreshRate(int frequency = 120)
{
DEVMODE dm = CreateDevmode();
Screen laptopScreen = FindLaptopScreen();
if (laptopScreen is null)
return -1;
if (0 != NativeMethods.EnumDisplaySettingsEx(laptopScreen.DeviceName, NativeMethods.ENUM_CURRENT_SETTINGS, ref dm))
{
dm.dmDisplayFrequency = frequency;
int iRet = NativeMethods.ChangeDisplaySettingsEx(laptopScreen.DeviceName, ref dm, IntPtr.Zero, DisplaySettingsFlags.CDS_UPDATEREGISTRY, IntPtr.Zero);
return iRet;
}
return 0;
}
static Guid GetActiveScheme()
{
IntPtr pActiveSchemeGuid;
var hr = PowerGetActiveScheme(IntPtr.Zero, out pActiveSchemeGuid);
Guid activeSchemeGuid = (Guid)Marshal.PtrToStructure(pActiveSchemeGuid, typeof(Guid));
return activeSchemeGuid;
}
public static int GetCPUBoost()
{
IntPtr AcValueIndex;
Guid activeSchemeGuid = GetActiveScheme();
UInt32 value = PowerReadACValueIndex(IntPtr.Zero,
activeSchemeGuid,
GUID_CPU,
GUID_BOOST, out AcValueIndex);
return AcValueIndex.ToInt32();
}
public static void SetCPUBoost(int boost = 0)
{
Guid activeSchemeGuid = GetActiveScheme();
var hrAC = PowerWriteACValueIndex(
IntPtr.Zero,
activeSchemeGuid,
GUID_CPU,
GUID_BOOST,
boost);
PowerSetActiveScheme(IntPtr.Zero, activeSchemeGuid);
var hrDC = PowerWriteDCValueIndex(
IntPtr.Zero,
activeSchemeGuid,
GUID_CPU,
GUID_BOOST,
boost);
PowerSetActiveScheme(IntPtr.Zero, activeSchemeGuid);
}
}

463
OSDBase.cs Normal file
View File

@@ -0,0 +1,463 @@
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
namespace OSD
{
class OSDNativeForm : NativeWindow, IDisposable
{
private bool _disposed = false;
private byte _alpha = 250;
private Size _size = new Size(350, 50);
private Point _location = new Point(50, 50);
protected virtual void PerformPaint(PaintEventArgs e)
{
}
protected internal void Invalidate()
{
this.UpdateLayeredWindow();
}
private void UpdateLayeredWindow()
{
Bitmap bitmap1 = new Bitmap(this.Size.Width, this.Size.Height, PixelFormat.Format32bppArgb);
using (Graphics graphics1 = Graphics.FromImage(bitmap1))
{
Rectangle rectangle1;
SIZE size1;
POINT point1;
POINT point2;
BLENDFUNCTION blendfunction1;
rectangle1 = new Rectangle(0, 0, this.Size.Width, this.Size.Height);
PerformPaint(new PaintEventArgs(graphics1, rectangle1));
IntPtr ptr1 = User32.GetDC(IntPtr.Zero);
IntPtr ptr2 = Gdi32.CreateCompatibleDC(ptr1);
IntPtr ptr3 = bitmap1.GetHbitmap(Color.FromArgb(0));
IntPtr ptr4 = Gdi32.SelectObject(ptr2, ptr3);
size1.cx = this.Size.Width;
size1.cy = this.Size.Height;
point1.x = this.Location.X;
point1.x = this.Location.X;
point1.y = this.Location.Y;
point2.x = 0;
point2.y = 0;
blendfunction1 = new BLENDFUNCTION();
blendfunction1.BlendOp = 0;
blendfunction1.BlendFlags = 0;
blendfunction1.SourceConstantAlpha = this._alpha;
blendfunction1.AlphaFormat = 1;
User32.UpdateLayeredWindow(base.Handle, ptr1, ref point1, ref size1, ptr2, ref point2, 0, ref blendfunction1, 2); //2=ULW_ALPHA
Gdi32.SelectObject(ptr2, ptr4);
User32.ReleaseDC(IntPtr.Zero, ptr1);
Gdi32.DeleteObject(ptr3);
Gdi32.DeleteDC(ptr2);
}
}
public virtual void Show()
{
if (base.Handle == IntPtr.Zero) //if handle don't equal to zero - window was created and just hided
this.CreateWindowOnly();
User32.ShowWindow(base.Handle, User32.SW_SHOWNOACTIVATE);
}
public virtual void Hide()
{
if (base.Handle == IntPtr.Zero)
return;
User32.ShowWindow(base.Handle, User32.SW_HIDE);
this.DestroyHandle();
}
public virtual void Close()
{
this.Hide();
this.Dispose();
}
private void CreateWindowOnly()
{
CreateParams params1 = new CreateParams();
params1.Caption = "FloatingNativeWindow";
int nX = this._location.X;
int nY = this._location.Y;
Screen screen1 = Screen.FromHandle(base.Handle);
if ((nX + this._size.Width) > screen1.Bounds.Width)
{
nX = screen1.Bounds.Width - this._size.Width;
}
if ((nY + this._size.Height) > screen1.Bounds.Height)
{
nY = screen1.Bounds.Height - this._size.Height;
}
this._location = new Point(nX, nY);
Size size1 = this._size;
Point point1 = this._location;
params1.X = nX;
params1.Y = nY;
params1.Height = size1.Height;
params1.Width = size1.Width;
params1.Parent = IntPtr.Zero;
uint ui = User32.WS_POPUP;
params1.Style = (int)ui;
params1.ExStyle = User32.WS_EX_TOPMOST | User32.WS_EX_TOOLWINDOW | User32.WS_EX_LAYERED | User32.WS_EX_NOACTIVATE | User32.WS_EX_TRANSPARENT;
this.CreateHandle(params1);
this.UpdateLayeredWindow();
}
protected virtual void SetBoundsCore(int x, int y, int width, int height)
{
if (((this.X != x) || (this.Y != y)) || ((this.Width != width) || (this.Height != height)))
{
if (base.Handle != IntPtr.Zero)
{
int num1 = 20;
if ((this.X == x) && (this.Y == y))
{
num1 |= 2;
}
if ((this.Width == width) && (this.Height == height))
{
num1 |= 1;
}
User32.SetWindowPos(base.Handle, IntPtr.Zero, x, y, width, height, (uint)num1);
}
else
{
this.Location = new Point(x, y);
this.Size = new Size(width, height);
}
}
}
#region # Properties #
/// <summary>
/// Get or set position of top-left corner of floating native window in screen coordinates
/// </summary>
public virtual Point Location
{
get { return this._location; }
set
{
if (base.Handle != IntPtr.Zero)
{
this.SetBoundsCore(value.X, value.Y, this._size.Width, this._size.Height);
RECT rect = new RECT();
User32.GetWindowRect(base.Handle, ref rect);
this._location = new Point(rect.left, rect.top);
this.UpdateLayeredWindow();
}
else
{
this._location = value;
}
}
}
/// <summary>
/// Get or set size of client area of floating native window
/// </summary>
public virtual Size Size
{
get { return this._size; }
set
{
if (base.Handle != IntPtr.Zero)
{
this.SetBoundsCore(this._location.X, this._location.Y, value.Width, value.Height);
RECT rect = new RECT();
User32.GetWindowRect(base.Handle, ref rect);
this._size = new Size(rect.right - rect.left, rect.bottom - rect.top);
this.UpdateLayeredWindow();
}
else
{
this._size = value;
}
}
}
/// <summary>
/// Gets or sets the height of the floating native window
/// </summary>
public int Height
{
get { return this._size.Height; }
set
{
this._size = new Size(this._size.Width, value);
}
}
/// <summary>
/// Gets or sets the width of the floating native window
/// </summary>
public int Width
{
get { return this._size.Width; }
set
{
this._size = new Size(value, this._size.Height);
}
}
/// <summary>
/// Get or set x-coordinate of top-left corner of floating native window in screen coordinates
/// </summary>
public int X
{
get { return this._location.X; }
set
{
this.Location = new Point(value, this.Location.Y);
}
}
/// <summary>
/// Get or set y-coordinate of top-left corner of floating native window in screen coordinates
/// </summary>
public int Y
{
get { return this._location.Y; }
set
{
this.Location = new Point(this.Location.X, value);
}
}
/// <summary>
/// Get rectangle represented client area of floating native window in client coordinates(top-left corner always has coord. 0,0)
/// </summary>
public Rectangle Bound
{
get
{
return new Rectangle(new Point(0, 0), this._size);
}
}
/// <summary>
/// Get or set full opacity(255) or full transparency(0) or any intermediate state for floating native window transparency
/// </summary>
public byte Alpha
{
get { return this._alpha; }
set
{
if (this._alpha == value) return;
this._alpha = value;
this.UpdateLayeredWindow();
}
}
#endregion
#region IDisposable Members
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!this._disposed)
{
this.DestroyHandle();
this._disposed = true;
}
}
#endregion
}
#region # Win32 #
[StructLayout(LayoutKind.Sequential)]
internal struct POINT
{
public int x;
public int y;
}
[StructLayout(LayoutKind.Sequential)]
internal struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[StructLayout(LayoutKind.Sequential)]
internal struct SIZE
{
public int cx;
public int cy;
}
[StructLayout(LayoutKind.Sequential)]
internal struct TRACKMOUSEEVENTS
{
public uint cbSize;
public uint dwFlags;
public IntPtr hWnd;
public uint dwHoverTime;
}
[StructLayout(LayoutKind.Sequential)]
internal struct MSG
{
public IntPtr hwnd;
public int message;
public IntPtr wParam;
public IntPtr lParam;
public int time;
public int pt_x;
public int pt_y;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct BLENDFUNCTION
{
public byte BlendOp;
public byte BlendFlags;
public byte SourceConstantAlpha;
public byte AlphaFormat;
}
internal class User32
{
public const uint WS_POPUP = 0x80000000;
public const int WS_EX_TOPMOST = 0x8;
public const int WS_EX_TOOLWINDOW = 0x80;
public const int WS_EX_LAYERED = 0x80000;
public const int WS_EX_TRANSPARENT = 0x20;
public const int WS_EX_NOACTIVATE = 0x08000000;
public const int SW_SHOWNOACTIVATE = 4;
public const int SW_HIDE = 0;
public const uint AW_HOR_POSITIVE = 0x1;
public const uint AW_HOR_NEGATIVE = 0x2;
public const uint AW_VER_POSITIVE = 0x4;
public const uint AW_VER_NEGATIVE = 0x8;
public const uint AW_CENTER = 0x10;
public const uint AW_HIDE = 0x10000;
public const uint AW_ACTIVATE = 0x20000;
public const uint AW_SLIDE = 0x40000;
public const uint AW_BLEND = 0x80000;
// Methods
private User32()
{
}
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool AnimateWindow(IntPtr hWnd, uint dwTime, uint dwFlags);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool ClientToScreen(IntPtr hWnd, ref POINT pt);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool DispatchMessage(ref MSG msg);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool DrawFocusRect(IntPtr hWnd, ref RECT rect);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr GetFocus();
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern ushort GetKeyState(int virtKey);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool GetMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool GetClientRect(IntPtr hWnd, [In, Out] ref RECT rect);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr GetWindow(IntPtr hWnd, int cmd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool HideCaret(IntPtr hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool InvalidateRect(IntPtr hWnd, ref RECT rect, bool erase);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr LoadCursor(IntPtr hInstance, uint cursor);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, [In, Out] ref RECT rect, int cPoints);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool PeekMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax, uint wFlag);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool PostMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool ReleaseCapture();
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool ScreenToClient(IntPtr hWnd, ref POINT pt);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern uint SendMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr SetCursor(IntPtr hCursor);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr SetFocus(IntPtr hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int newLong);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndAfter, int X, int Y, int Width, int Height, uint flags);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool ShowCaret(IntPtr hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool SetCapture(IntPtr hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern int ShowWindow(IntPtr hWnd, short cmdShow);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref int bRetValue, uint fWinINI);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool TrackMouseEvent(ref TRACKMOUSEEVENTS tme);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool TranslateMessage(ref MSG msg);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize, IntPtr hdcSrc, ref POINT pprSrc, int crKey, ref BLENDFUNCTION pblend, int dwFlags);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool UpdateWindow(IntPtr hwnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool WaitMessage();
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool AdjustWindowRectEx(ref RECT lpRect, int dwStyle, bool bMenu, int dwExStyle);
}
internal class Gdi32
{
// Methods
private Gdi32()
{
}
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern int CombineRgn(IntPtr dest, IntPtr src1, IntPtr src2, int flags);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr CreateBrushIndirect(ref LOGBRUSH brush);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr CreateCompatibleDC(IntPtr hDC);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr CreateRectRgnIndirect(ref RECT rect);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern bool DeleteDC(IntPtr hDC);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr DeleteObject(IntPtr hObject);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern int GetClipBox(IntPtr hDC, ref RECT rectBox);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern bool PatBlt(IntPtr hDC, int x, int y, int width, int height, uint flags);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern int SelectClipRgn(IntPtr hDC, IntPtr hRgn);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
}
[StructLayout(LayoutKind.Sequential)]
public struct LOGBRUSH
{
public uint lbStyle;
public uint lbColor;
public uint lbHatch;
}
#endregion
}

View File

@@ -1,543 +1,175 @@
using Microsoft.Win32.TaskScheduler;
using Microsoft.Win32;
using System.Diagnostics;
using System.Management;
using System.Runtime.InteropServices;
using HidLibrary;
using System.Text.Json;
using Starlight.AnimeMatrix;
public class ASUSWmi
public class HardwareMonitor
{
private ManagementObject mo;
private ManagementClass classInstance;
public const int CPU_Fan = 0x00110013;
public const int GPU_Fan = 0x00110014;
public static float? cpuTemp = -1;
public static float? batteryDischarge = -1;
public const int PerformanceMode = 0x00120075;
public const int GPUEco = 0x00090020;
public const int GPUMux = 0x00090016;
public const int BatteryLimit = 0x00120057;
public const int ScreenOverdrive = 0x00050019;
public const int PerformanceBalanced = 0;
public const int PerformanceTurbo = 1;
public const int PerformanceSilent = 2;
public const int GPUModeEco = 0;
public const int GPUModeStandard = 1;
public const int GPUModeUltimate = 2;
public ASUSWmi()
public static void ReadSensors()
{
this.classInstance = new ManagementClass(new ManagementScope("root\\wmi"), new ManagementPath("AsusAtkWmi_WMNB"), null);
foreach (ManagementObject mo in this.classInstance.GetInstances())
cpuTemp = -1;
batteryDischarge = -1;
try
{
this.mo = mo;
}
}
var ct = new PerformanceCounter("Thermal Zone Information", "Temperature", @"\_TZ.THRM", true);
cpuTemp = ct.NextValue() - 273;
ct.Dispose();
private int WMICall(string MethodName, int Device_Id, int Control_status = -1)
{
ManagementBaseObject inParams = this.classInstance.Methods[MethodName].InParameters;
inParams["Device_ID"] = Device_Id;
if (Control_status != -1)
var cb = new PerformanceCounter("Power Meter", "Power", "Power Meter (0)", true);
batteryDischarge = cb.NextValue() / 1000;
cb.Dispose();
}
catch
{
inParams["Control_status"] = Control_status;
Debug.WriteLine("Failed reading sensors");
}
ManagementBaseObject outParams = this.mo.InvokeMethod(MethodName, inParams, null);
foreach (PropertyData property in outParams.Properties)
{
if (property.Name == "device_status")
{
int status;
try
{
status = int.Parse(property.Value.ToString());
status -= 65536;
return status;
}
catch
{
return -1;
}
}
if (property.Name == "result")
{
try
{
return int.Parse(property.Value.ToString());
}
catch
{
return -1;
}
}
}
return -1;
}
public int DeviceGet(int Device_Id)
{
return this.WMICall("DSTS", Device_Id);
}
public int DeviceSet(int Device_Id, int Control_status)
{
return this.WMICall("DEVS", Device_Id, Control_status);
}
public void SubscribeToEvents(Action<object, EventArrivedEventArgs> EventHandler)
{
ManagementEventWatcher watcher = new ManagementEventWatcher();
watcher.EventArrived += new EventArrivedEventHandler(EventHandler);
watcher.Scope = new ManagementScope("root\\wmi");
watcher.Query = new WqlEventQuery("SELECT * FROM AsusAtkWmiEvent");
watcher.Start();
}
}
public class Startup
{
static string taskName = "GSharpHelper";
public Startup()
{
}
public bool IsScheduled()
{
TaskService taskService = new TaskService();
return (taskService.RootFolder.AllTasks.Any(t => t.Name == taskName));
}
public void Schedule()
{
TaskService taskService = new TaskService();
string strExeFilePath = Application.ExecutablePath;
if (strExeFilePath is null) return;
Debug.WriteLine(strExeFilePath);
TaskDefinition td = TaskService.Instance.NewTask();
td.RegistrationInfo.Description = "GSharpHelper Auto Start";
LogonTrigger lt = new LogonTrigger();
td.Triggers.Add(lt);
td.Actions.Add(strExeFilePath);
td.Principal.RunLevel = TaskRunLevel.Highest;
td.Settings.StopIfGoingOnBatteries = false;
td.Settings.DisallowStartIfOnBatteries = false;
TaskService.Instance.RootFolder.RegisterTaskDefinition(taskName, td);
}
public void UnSchedule()
{
TaskService taskService = new TaskService();
taskService.RootFolder.DeleteTask(taskName);
}
}
public class AppConfig
{
string appPath;
string configFile;
public Dictionary<string, object> config = new Dictionary<string, object>();
public AppConfig()
{
appPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\GHelper";
configFile = appPath + "\\config.json";
if (!System.IO.Directory.Exists(appPath))
System.IO.Directory.CreateDirectory(appPath);
if (File.Exists(configFile))
{
string text = File.ReadAllText(configFile);
try
{
config = JsonSerializer.Deserialize<Dictionary<string, object>>(text);
}
catch
{
initConfig();
}
}
else
{
initConfig();
}
}
private void initConfig()
{
config = new Dictionary<string, object>();
config["performance_mode"] = 0;
string jsonString = JsonSerializer.Serialize(config);
File.WriteAllText(configFile, jsonString);
}
public int getConfig(string name)
{
if (config.ContainsKey(name))
return int.Parse(config[name].ToString());
else return -1;
}
public void setConfig(string name, int value)
{
config[name] = value;
string jsonString = JsonSerializer.Serialize(config);
File.WriteAllText(configFile, jsonString);
}
}
public class NativeMethods
{
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerWriteDCValueIndex(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid,
int AcValueIndex);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerReadACValueIndex(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid,
out IntPtr AcValueIndex
);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerWriteACValueIndex(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid,
int AcValueIndex);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerSetActiveScheme(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerGetActiveScheme(IntPtr UserPowerKey, out IntPtr ActivePolicyGuid);
static readonly Guid GUID_CPU = new Guid("54533251-82be-4824-96c1-47b60b740d00");
static readonly Guid GUID_BOOST = new Guid("be337238-0d82-4146-a960-4f3749d470c7");
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct DEVMODE
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string dmDeviceName;
public short dmSpecVersion;
public short dmDriverVersion;
public short dmSize;
public short dmDriverExtra;
public int dmFields;
public int dmPositionX;
public int dmPositionY;
public int dmDisplayOrientation;
public int dmDisplayFixedOutput;
public short dmColor;
public short dmDuplex;
public short dmYResolution;
public short dmTTOption;
public short dmCollate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string dmFormName;
public short dmLogPixels;
public short dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
public int dmICMMethod;
public int dmICMIntent;
public int dmMediaType;
public int dmDitherType;
public int dmReserved1;
public int dmReserved2;
public int dmPanningWidth;
public int dmPanningHeight;
};
[Flags()]
public enum DisplaySettingsFlags : int
{
CDS_UPDATEREGISTRY = 1,
CDS_TEST = 2,
CDS_FULLSCREEN = 4,
CDS_GLOBAL = 8,
CDS_SET_PRIMARY = 0x10,
CDS_RESET = 0x40000000,
CDS_NORESET = 0x10000000
}
// PInvoke declaration for EnumDisplaySettings Win32 API
[DllImport("user32.dll")]
public static extern int EnumDisplaySettingsEx(
string lpszDeviceName,
int iModeNum,
ref DEVMODE lpDevMode);
// PInvoke declaration for ChangeDisplaySettings Win32 API
[DllImport("user32.dll")]
public static extern int ChangeDisplaySettingsEx(
string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd,
DisplaySettingsFlags dwflags, IntPtr lParam);
public const int ENUM_CURRENT_SETTINGS = -1;
public const string laptopScreenName = "\\\\.\\DISPLAY1";
public static DEVMODE CreateDevmode()
{
DEVMODE dm = new DEVMODE();
dm.dmDeviceName = new String(new char[32]);
dm.dmFormName = new String(new char[32]);
dm.dmSize = (short)Marshal.SizeOf(dm);
return dm;
}
public static Screen FindLaptopScreen()
{
var screens = Screen.AllScreens;
Screen laptopScreen = null;
foreach (var screen in screens)
{
if (screen.DeviceName == laptopScreenName)
{
laptopScreen = screen;
}
}
if (laptopScreen is null) return null;
else return laptopScreen;
}
public static int GetRefreshRate()
{
DEVMODE dm = CreateDevmode();
Screen laptopScreen = FindLaptopScreen();
int frequency = -1;
if (laptopScreen is null)
return -1;
if (0 != NativeMethods.EnumDisplaySettingsEx(laptopScreen.DeviceName, NativeMethods.ENUM_CURRENT_SETTINGS, ref dm))
{
frequency = dm.dmDisplayFrequency;
}
return frequency;
}
public static int SetRefreshRate(int frequency = 120)
{
DEVMODE dm = CreateDevmode();
Screen laptopScreen = FindLaptopScreen();
if (laptopScreen is null)
return -1;
if (0 != NativeMethods.EnumDisplaySettingsEx(laptopScreen.DeviceName, NativeMethods.ENUM_CURRENT_SETTINGS, ref dm))
{
dm.dmDisplayFrequency = frequency;
int iRet = NativeMethods.ChangeDisplaySettingsEx(laptopScreen.DeviceName, ref dm, IntPtr.Zero, DisplaySettingsFlags.CDS_UPDATEREGISTRY, IntPtr.Zero);
return iRet;
}
return 0;
}
static Guid GetActiveScheme()
{
IntPtr pActiveSchemeGuid;
var hr = PowerGetActiveScheme(IntPtr.Zero, out pActiveSchemeGuid);
Guid activeSchemeGuid = (Guid)Marshal.PtrToStructure(pActiveSchemeGuid, typeof(Guid));
return activeSchemeGuid;
}
public static int GetCPUBoost()
{
IntPtr AcValueIndex;
Guid activeSchemeGuid = GetActiveScheme();
UInt32 value = PowerReadACValueIndex(IntPtr.Zero,
activeSchemeGuid,
GUID_CPU,
GUID_BOOST, out AcValueIndex);
return AcValueIndex.ToInt32();
}
public static void SetCPUBoost(int boost = 0)
{
Guid activeSchemeGuid = GetActiveScheme();
var hr = PowerWriteACValueIndex(
IntPtr.Zero,
activeSchemeGuid,
GUID_CPU,
GUID_BOOST,
boost);
PowerSetActiveScheme(IntPtr.Zero, activeSchemeGuid);
}
}
public class Aura
{
static byte[] MESSAGE_SET = { 0x5d, 0xb5 };
static byte[] MESSAGE_APPLY = { 0x5d, 0xb4 };
public const int Static = 0;
public const int Breathe = 1;
public const int Strobe = 2;
public const int Rainbow = 3;
public const int SpeedSlow = 0;
public const int SpeedMedium = 1;
public const int SpeedHigh = 2;
public static int Mode = Static;
public static Color Color1 = Color.White;
public static Color Color2 = Color.Black;
public static int Speed = SpeedSlow;
public static byte[] AuraMessage(int mode, Color color, Color color2, int speed)
{
byte[] msg = new byte[17];
msg[0] = 0x5d;
msg[1] = 0xb3;
msg[2] = 0x00; // Zone
msg[3] = (byte)mode; // Aura Mode
msg[4] = (byte)(color.R); // R
msg[5] = (byte)(color.G); // G
msg[6] = (byte)(color.B); // B
msg[7] = (byte)speed; // aura.speed as u8;
msg[8] = 0; // aura.direction as u8;
msg[10] = (byte)(color2.R); // R
msg[11] = (byte)(color2.G); // G
msg[12] = (byte)(color2.B); // B
return msg;
}
public static void ApplyAura()
{
HidDevice[] HidDeviceList;
int[] deviceIds = { 0x1854, 0x1869, 0x1866, 0x19b6 };
HidDeviceList = HidDevices.Enumerate(0x0b05, deviceIds).ToArray();
foreach (HidDevice device in HidDeviceList)
{
if (device.IsConnected)
{
if (device.Description.IndexOf("HID") >= 0)
{
device.OpenDevice();
byte[] msg = AuraMessage(Mode, Color1, Color2, Speed);
device.Write(msg);
device.Write(MESSAGE_SET);
device.Write(MESSAGE_APPLY);
device.CloseDevice();
}
}
}
}
}
namespace GHelper
{
static class Program
{
public static NotifyIcon trayIcon;
public static NotifyIcon trayIcon = new NotifyIcon
{
Text = "G-Helper",
Icon = Properties.Resources.standard,
Visible = true
};
public static ASUSWmi wmi;
public static AppConfig config;
public static ASUSWmi wmi = new ASUSWmi();
public static AppConfig config = new AppConfig();
public static SettingsForm settingsForm;
public static Startup scheduler;
public static SettingsForm settingsForm = new SettingsForm();
public static ToastForm toast = new ToastForm();
// The main entry point for the application
public static void Main()
{
trayIcon = new NotifyIcon
{
Text = "G14 Helper",
Icon = GHelper.Properties.Resources.standard,
Visible = true
};
trayIcon.MouseClick += TrayIcon_MouseClick; ;
config = new AppConfig();
wmi = new ASUSWmi();
wmi.SubscribeToEvents(WatcherEventArrived);
scheduler = new Startup();
settingsForm = new SettingsForm();
settingsForm.InitGPUMode();
settingsForm.InitBoost();
settingsForm.InitAura();
settingsForm.SetPerformanceMode(config.getConfig("performance_mode"));
settingsForm.SetBatteryChargeLimit(config.getConfig("charge_limit"));
settingsForm.VisualiseGPUAuto(config.getConfig("gpu_auto"));
settingsForm.VisualiseScreenAuto(config.getConfig("screen_auto"));
settingsForm.SetStartupCheck(Startup.IsScheduled());
settingsForm.SetStartupCheck(scheduler.IsScheduled());
SetAutoModes();
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
IntPtr ds = settingsForm.Handle;
Application.Run();
}
private static void SetAutoModes()
{
PowerLineStatus isPlugged = SystemInformation.PowerStatus.PowerLineStatus;
settingsForm.AutoGPUMode(isPlugged);
settingsForm.AutoScreen(isPlugged);
settingsForm.AutoPerformance(isPlugged);
settingsForm.SetBatteryChargeLimit(config.getConfig("charge_limit"));
}
private static void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
SetAutoModes();
}
static void LaunchProcess(string fileName = "")
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = fileName;
start.WindowStyle = ProcessWindowStyle.Hidden;
start.CreateNoWindow = true;
try
{
Process proc = Process.Start(start);
}
catch
{
Debug.WriteLine("Failed to run " + fileName);
}
}
static void CustomKey(string configKey = "m3")
{
string command = config.getConfigString(configKey + "_custom");
int intKey;
try
{
intKey = Convert.ToInt32(command, 16);
} catch
{
intKey = -1;
}
if (intKey > 0)
NativeMethods.KeyPress(intKey);
else
LaunchProcess(command);
}
static void KeyProcess(string name = "m3")
{
string action = config.getConfigString(name);
if (action is null || action.Length <= 1)
{
if (name == "m4")
action = "performance";
if (name == "fnf4")
action = "aura";
}
switch (action)
{
case "mute":
NativeMethods.KeyPress(NativeMethods.VK_VOLUME_MUTE);
break;
case "play":
NativeMethods.KeyPress(NativeMethods.VK_MEDIA_PLAY_PAUSE);
break;
case "screenshot":
NativeMethods.KeyPress(NativeMethods.VK_SNAPSHOT);
break;
case "aura":
settingsForm.BeginInvoke(settingsForm.CycleAuraMode);
break;
case "performance":
settingsForm.BeginInvoke(settingsForm.CyclePerformanceMode);
break;
case "ghelper":
settingsForm.BeginInvoke(SettingsToggle);
break;
case "custom":
CustomKey(name);
break;
default:
break;
}
}
static void WatcherEventArrived(object sender, EventArrivedEventArgs e)
{
@@ -551,53 +183,42 @@ namespace GHelper
switch (EventID)
{
case 56: // Rog button
case 124: // M3
KeyProcess("m3");
return;
case 56: // M4 / Rog button
KeyProcess("m4");
return;
case 174: // FN+F5
settingsForm.BeginInvoke(delegate
{
settingsForm.CyclePerformanceMode();
});
settingsForm.BeginInvoke(settingsForm.CyclePerformanceMode);
return;
case 179: // FN+F4
settingsForm.BeginInvoke(delegate
{
settingsForm.CycleAuraMode();
});
KeyProcess("fnf4");
return;
case 87: // Battery
settingsForm.BeginInvoke(delegate
{
settingsForm.AutoGPUMode(0);
settingsForm.AutoScreen(0);
});
return;
case 88: // Plugged
settingsForm.SetBatteryChargeLimit(config.getConfig("charge_limit"));
settingsForm.BeginInvoke(delegate
{
settingsForm.AutoGPUMode(1);
settingsForm.AutoScreen(1);
});
return;
}
}
static void SettingsToggle()
{
if (settingsForm.Visible)
settingsForm.Hide();
else
{
settingsForm.Show();
settingsForm.Activate();
}
settingsForm.VisualiseGPUMode();
}
static void TrayIcon_MouseClick(object? sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
{
if (settingsForm.Visible)
settingsForm.Hide();
else
{
settingsForm.Show();
settingsForm.Activate();
}
trayIcon.Icon = trayIcon.Icon; // refreshing icon as it get's blurred when screen resolution changes
SettingsToggle();
}
}

View File

@@ -70,6 +70,16 @@ namespace GHelper.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap everything_is_fine_itsfine {
get {
object obj = ResourceManager.GetObject("everything-is-fine-itsfine", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
@@ -80,6 +90,16 @@ namespace GHelper.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap icons8_fan_head_96 {
get {
object obj = ResourceManager.GetObject("icons8-fan-head-96", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
@@ -100,6 +120,16 @@ namespace GHelper.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap icons8_matrix_desktop_48 {
get {
object obj = ResourceManager.GetObject("icons8-matrix-desktop-48", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
@@ -110,6 +140,16 @@ namespace GHelper.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap icons8_speed_96 {
get {
object obj = ResourceManager.GetObject("icons8-speed-96", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>

View File

@@ -133,13 +133,25 @@
<data name="icons8-speed-48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-speed-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="everything-is-fine-itsfine" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\everything-is-fine-itsfine.gif;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-speed-96" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-speed-96.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-video-card-48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-video-card-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-fan-head-96" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-fan-head-96.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-charging-battery-48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-charging-battery-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-laptop-48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-laptop-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-matrix-desktop-48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-matrix-desktop-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@@ -1,54 +1,68 @@
# G14-Helper
# G-Helper (For Asus ROG Zephyrus G14, G15, Flow X13, Flow X16, and others)
A tiny system tray utility that allows you set performance and GPU profiles for your laptop. Same as ASUS Armory Crate does but without it completely!.
A small utility that allows you do almost everyting you could do with Armory Crate but without extra bloat and unnecessary services.
Designed for Asus Zephyrus G14 2022 (with AMD Radeon iGPU and dGPU). But could and should potentially work for G14 of 2021 and 2020, G15, X FLOW, and other ROG models.
## NEW (and experimental) features
![Screenshot](https://github.com/seerge/g14-helper/blob/main/screenshot.png)
1. Set Power limits (PPT) for Total (APU + dGPU) and CPU.
2. Anime matrix control thanks to https://github.com/vddCore/Starlight
## Main features
1. Switch between built-in system **Performance modes** Silent / Balanced / Turbo and apply default fan curves
2. Switch between Eco / Standard or Ultimate **GPU modes**
3. Change laptop screen refresh rate - 60hz or your maximum (120hz, 144hz, etc depending on the model) with display overdrive (OD)
4. View default fan profiles for every mode and **auto apply** custom ones
5. Control keyboard backlit animation and colors
6. Set battery charge limit to preserve battery health
7. Monitor CPU temperature, fan speeds and battery discharge rate
8. **Automatically switch to Eco(iGPU)/60hz on battery** and back to Standard(GPU)/120hz modes when plugged
9. Support for FN+F5 to cycle through performance modes (with OSD notification) and FN+F4 to cycle through keeyboard animation modes
10. Basic keybindings for M3 and M4 keys
11. Turn cpu turbo boost on/off with one checkbox to keep temps cooler
Designed and developed for Asus Zephyrus G14 2022 (with AMD Radeon iGPU and dGPU). But could and should potentially work for G14 of 2021 and 2020, G15, X FLOW, and other ROG models for relevant and supported features.
To keep autoswitching and hotkeys work app needs to stay in running in tray. It doesn't consume any resources.
I recommend to keep "Asus Optimization Service" running, as it keeps basic laptop hotkeys such as screen or keyboard brightness adjustment working. If you have (or had) MyASUS app installed, that service is most probably still up an running even after MyASUS uninstall. It's part of [Asus System Controll Interface](https://www.asus.com/support/FAQ/1047338/). You can install it, and later disable / remove unnecesarily services by running [this bat file](https://raw.githubusercontent.com/seerge/g-helper/main/stop-asus-sv.bat ) as admin.
### [Download latest release](https://github.com/seerge/g-helper/releases)
![Screenshot](https://github.com/seerge/g-helper/blob/main/screenshot.png)
## Performance Profile switching
Profiles are **same** as in Armory Crate, including default fan curves
Profiles are **same** as in Armory Crate (as they are stored in bios), including default fan curves
1. Silent (minimal or no fans, 45W PPT to CPU)
2. Balanced (balanced fans, up to 45W PPT to CPU)
1. Silent (minimal or no fans, 70W PPT total, up to 45W PPT to CPU)
2. Balanced (balanced fans, 100W PPT total, up to 45W PPT to CPU)
3. Turbo (intense fans, 125W PPT total, up to 80W PPT to CPU)
## GPU Mode switching
PPTs are shown for G14 2022, for other models PPTs will be different as they are set in bios.
1. Eco mode : only low power iGPU (Radeon 680u) enabled, iGPU drives built in display
2. Standard mode (Windows Hybrid) : iGPU and dGPU (Radeon 6700s/6800s) enabled, iGPU drives built in display
3. Ultimate mode: iGPU and dGPU enabled, but dGPU drives built in display
## GPU Modes
## Extras
1. Keyboard backlight control (basic aura modes and colors)
2. **Maximum battery charge rate** limit (60% / 80% / 100%) to preserve your battery
3. CPU and GPU relative fan speed monitoring
4. Automatic switching of Standard/Eco GPU modes when laptop is plugged / unplugged!
5. FN+F5 an M4 (Rog) keys cycle through Performance modes
6. Screen resolution and display overdrive switching
7. Run on startup (optional)
## Things still missing
1. Custom fan profiles
2. Anime matrix control
1. Eco mode : only low power integrated GPU enabled, iGPU drives built in display
2. Standard mode (Windows Hybrid) : iGPU and dGPU enabled, iGPU drives built in display
3. Ultimate mode: iGPU and dGPU enabled, but dGPU drives built in display (supported only on G14 2022 model)
## How to install
1. Download latest release from https://github.com/seerge/g14-helper/releases
1. Download latest release from https://github.com/seerge/g-helper/releases
2. Unzip to a folder of your choice
3. Run **GHelper.exe**
Note: Uses low level ASUS WMI commands to do switching and doens't require Armory Crate to be isntalled at all.
Therefore requires Administrator priveledges on Windows to run.
Note: Uses low level ASUS ACPI commands and doens't require Armory Crate to be installed at all! Doesn't need administrator privileges to run!
I don`t have Microsoft certificate to sign app yet, so if you set a warning from Windows Defender on launch (Windows Protected your PC), click More Info -> Run anyway.
I don`t have Microsoft certificate to sign app yet, so if you get a warning from Windows Defender on launch (Windows Protected your PC), click More Info -> Run anyway. Alternatively you can compile and run project by yourself using Visual Studio :)
Alternatively you can comile and run project by yourself :)
Settings file is storer at %AppData%\GHelper
Settings file is stored at %AppData%\GHelper
P.S.: It's not recommended to use app in combination with Armory Crate, cause they adjust same settings.
Please keep in mind, that if you also run MyASUS app periodically it will also try to adjust same battery charge settings
------------------
Debloating helps to save your battery and keep laptop a bit cooler
![Helps to save your battery](https://raw.githubusercontent.com/seerge/g-helper/main/screenshots/screen-5w.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

1025
Settings.Designer.cs generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,12 @@
using Microsoft.VisualBasic.ApplicationServices;
using Starlight.AnimeMatrix;
using System.Diagnostics;
using System.Management;
using System.Drawing.Imaging;
using System.Reflection;
using System.Timers;
using System.Windows.Forms;
namespace GHelper
{
public partial class SettingsForm : Form
{
@@ -17,6 +18,14 @@ namespace GHelper
static int buttonActive = 5;
static System.Timers.Timer aTimer = default!;
static System.Timers.Timer matrixTimer = new System.Timers.Timer(100);
public string perfName = "Balanced";
Fans fans;
Keyboard keyb;
AnimeMatrixDevice mat = new AnimeMatrixDevice();
public SettingsForm()
{
@@ -56,27 +65,248 @@ namespace GHelper
comboKeyboard.DropDownStyle = ComboBoxStyle.DropDownList;
comboKeyboard.SelectedIndex = 0;
comboKeyboard.SelectedValueChanged += ComboKeyboard_SelectedValueChanged;
buttonKeyboardColor.Click += ButtonKeyboardColor_Click;
buttonFans.Click += ButtonFans_Click;
buttonKeyboard.Click += ButtonKeyboard_Click;
pictureColor.Click += PictureColor_Click;
pictureColor2.Click += PictureColor2_Click;
labelVersion.Text = "Version " + Assembly.GetExecutingAssembly().GetName().Version.ToString();
labelVersion.Click += LabelVersion_Click;
labelCPUFan.Click += LabelCPUFan_Click;
labelGPUFan.Click += LabelCPUFan_Click;
InitMatrix();
comboMatrix.DropDownStyle = ComboBoxStyle.DropDownList;
comboMatrixRunning.DropDownStyle = ComboBoxStyle.DropDownList;
comboMatrix.SelectedValueChanged += ComboMatrix_SelectedValueChanged;
comboMatrixRunning.SelectedValueChanged += ComboMatrixRunning_SelectedValueChanged;
buttonMatrix.Click += ButtonMatrix_Click;
matrixTimer.Enabled = false;
matrixTimer.Elapsed += MatrixTimer_Elapsed;
SetTimer();
}
private void MatrixTimer_Elapsed(object? sender, ElapsedEventArgs e)
{
mat.PresentNextFrame();
}
void SetMatrixPicture(string fileName)
{
Image image;
try
{
using (var fs = new FileStream(fileName, FileMode.Open))
{
var ms = new MemoryStream();
fs.CopyTo(ms);
ms.Position = 0;
image = Image.FromStream(ms);
}
}
catch
{
Debug.WriteLine("Error loading picture");
return;
}
mat.SetBuiltInAnimation(false);
mat.ClearFrames();
FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]);
int frameCount = image.GetFrameCount(dimension);
if (frameCount > 1)
{
for (int i = 0; i < frameCount; i++)
{
image.SelectActiveFrame(dimension, i);
mat.GenerateFrame(image);
mat.AddFrame();
}
matrixTimer.Enabled = true;
}
else
{
matrixTimer.Enabled = false;
mat.GenerateFrame(image);
mat.Present();
}
}
private void ButtonMatrix_Click(object? sender, EventArgs e)
{
Thread t = new Thread((ThreadStart)(() =>
{
OpenFileDialog of = new OpenFileDialog();
of.Filter = "Image Files (*.bmp;*.jpg;*.jpeg,*.png,*.gif)|*.BMP;*.JPG;*.JPEG;*.PNG;*.GIF";
if (of.ShowDialog() == DialogResult.OK)
{
Program.config.setConfig("matrix_picture", of.FileName);
SetMatrixPicture(of.FileName);
BeginInvoke(delegate
{
comboMatrixRunning.SelectedIndex = 2;
});
}
return;
}));
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
}
private void ComboMatrixRunning_SelectedValueChanged(object? sender, EventArgs e)
{
SetAnimeMatrix();
}
private void ComboMatrix_SelectedValueChanged(object? sender, EventArgs e)
{
SetAnimeMatrix();
}
private void SetAnimeMatrix()
{
int brightness = comboMatrix.SelectedIndex;
int running = comboMatrixRunning.SelectedIndex;
//var mat = new AnimeMatrixDevice();
BuiltInAnimation animation = new BuiltInAnimation(
(BuiltInAnimation.Running)running,
BuiltInAnimation.Sleeping.Starfield,
BuiltInAnimation.Shutdown.SeeYa,
BuiltInAnimation.Startup.StaticEmergence
);
if (brightness == 0)
{
mat.SetDisplayState(false);
}
else
{
mat.SetDisplayState(true);
mat.SetBrightness((BrightnessMode)brightness);
if (running == 2)
{
string fileName = Program.config.getConfigString("matrix_picture");
SetMatrixPicture(fileName);
}
else
{
mat.SetBuiltInAnimation(true, animation);
}
}
//mat.Dispose();
Program.config.setConfig("matrix_brightness", comboMatrix.SelectedIndex);
Program.config.setConfig("matrix_running", comboMatrixRunning.SelectedIndex);
}
private void LabelCPUFan_Click(object? sender, EventArgs e)
{
Program.config.setConfig("fan_rpm", (Program.config.getConfig("fan_rpm") == 1) ? 0 : 1);
RefreshSensors();
}
private void LabelVersion_Click(object? sender, EventArgs e)
{
Process.Start(new ProcessStartInfo("http://github.com/seerge/g-helper/releases") { UseShellExecute = true });
}
private void PictureColor2_Click(object? sender, EventArgs e)
{
ColorDialog colorDlg = new ColorDialog();
colorDlg.AllowFullOpen = false;
colorDlg.Color = pictureColor2.BackColor;
if (colorDlg.ShowDialog() == DialogResult.OK)
{
SetAuraColor(color2: colorDlg.Color);
}
}
private void PictureColor_Click(object? sender, EventArgs e)
{
buttonKeyboardColor.PerformClick();
}
private void ButtonKeyboard_Click(object? sender, EventArgs e)
{
if (keyb == null || keyb.Text == "")
{
keyb = new Keyboard();
keyb.Show();
}
else
{
keyb.Close();
}
}
private void ButtonFans_Click(object? sender, EventArgs e)
{
if (fans == null || fans.Text == "")
{
fans = new Fans();
Debug.WriteLine("Starting fans");
}
if (fans.Visible)
{
fans.Hide();
}
else
{
fans.Show();
}
}
private void ButtonKeyboardColor_Click(object? sender, EventArgs e)
{
if (sender is null)
return;
Button but = (Button)sender;
ColorDialog colorDlg = new ColorDialog();
colorDlg.AllowFullOpen = false;
colorDlg.Color = but.FlatAppearance.BorderColor;
colorDlg.Color = pictureColor.BackColor;
if (colorDlg.ShowDialog() == DialogResult.OK)
{
SetAuraColor(colorDlg.Color);
SetAuraColor(color1: colorDlg.Color);
}
}
@@ -84,59 +314,95 @@ namespace GHelper
{
int mode = Program.config.getConfig("aura_mode");
int colorCode = Program.config.getConfig("aura_color");
int colorCode2 = Program.config.getConfig("aura_color2");
int speed = Program.config.getConfig("aura_speed");
Color color = Color.FromArgb(255, 255, 255);
Color color2 = Color.FromArgb(0, 0, 0);
if (mode == -1)
if (mode == -1)
mode = 0;
if (colorCode != -1)
color = Color.FromArgb(colorCode);
if (colorCode2 != -1)
color2 = Color.FromArgb(colorCode2);
SetAuraColor(color, false);
SetAuraColor(color, color2, false);
SetAuraMode(mode, false);
Aura.Mode = mode;
}
public void SetAuraColor(Color color, bool apply = true)
public void InitMatrix()
{
Aura.Color1 = color;
Program.config.setConfig("aura_color", color.ToArgb());
int brightness = Program.config.getConfig("matrix_brightness");
int running = Program.config.getConfig("matrix_running");
comboMatrix.SelectedIndex = (brightness != -1) ? brightness : 0;
comboMatrixRunning.SelectedIndex = (running != -1) ? running : 0;
}
public void SetAuraColor(Color? color1 = null, Color? color2 = null, bool apply = true)
{
if (color1 is not null)
{
Aura.Color1 = (Color)color1;
Program.config.setConfig("aura_color", Aura.Color1.ToArgb());
}
if (color2 is not null)
{
Aura.Color2 = (Color)color2;
Program.config.setConfig("aura_color2", Aura.Color2.ToArgb());
}
if (apply)
Aura.ApplyAura();
buttonKeyboardColor.FlatAppearance.BorderColor = color;
pictureColor.BackColor = Aura.Color1;
pictureColor2.BackColor = Aura.Color2;
}
public void SetAuraMode (int mode = 0, bool apply = true)
public void SetAuraMode(int mode = 0, bool apply = true)
{
if (mode > 3) mode = 0;
//Debug.WriteLine(mode);
if (mode > 4) mode = 0;
pictureColor2.Visible = (mode == Aura.Breathe);
if (Aura.Mode == mode) return; // same mode
Aura.Mode = mode;
Program.config.setConfig("aura_mode", mode);
comboKeyboard.SelectedValueChanged -= ComboKeyboard_SelectedValueChanged;
comboKeyboard.SelectedIndex = mode;
comboKeyboard.SelectedValueChanged += ComboKeyboard_SelectedValueChanged;
if (apply)
Aura.ApplyAura();
else
comboKeyboard.SelectedIndex = mode;
}
public void CycleAuraMode ()
public void CycleAuraMode()
{
SetAuraMode(Program.config.getConfig("aura_mode") + 1);
}
private void ComboKeyboard_SelectedValueChanged(object? sender, EventArgs e)
{
if (sender is null)
return;
ComboBox cmb = (ComboBox)sender;
SetAuraMode(cmb.SelectedIndex);
}
@@ -144,9 +410,12 @@ namespace GHelper
private void CheckBoost_Click(object? sender, EventArgs e)
{
if (sender is null)
return;
CheckBox chk = (CheckBox)sender;
if (chk.Checked)
NativeMethods.SetCPUBoost(3);
NativeMethods.SetCPUBoost(2);
else
NativeMethods.SetCPUBoost(0);
}
@@ -179,8 +448,16 @@ namespace GHelper
if (frequency > 0)
NativeMethods.SetRefreshRate(frequency);
if (overdrive > 0)
Program.wmi.DeviceSet(ASUSWmi.ScreenOverdrive, overdrive);
try
{
if (overdrive > 0)
Program.wmi.DeviceSet(ASUSWmi.ScreenOverdrive, overdrive);
}
catch
{
Debug.WriteLine("Screen Overdrive not supported");
}
InitScreen();
}
@@ -215,7 +492,15 @@ namespace GHelper
labelSreen.Text = "Laptop Screen";
}
int overdrive = Program.wmi.DeviceGet(ASUSWmi.ScreenOverdrive);
int overdrive = 0;
try
{
overdrive = Program.wmi.DeviceGet(ASUSWmi.ScreenOverdrive);
}
catch
{
Debug.WriteLine("Screen Overdrive not supported");
}
button60Hz.FlatAppearance.BorderSize = buttonInactive;
button120Hz.FlatAppearance.BorderSize = buttonInactive;
@@ -275,22 +560,51 @@ namespace GHelper
private static void SetTimer()
{
aTimer = new System.Timers.Timer(1000);
aTimer = new System.Timers.Timer(500);
aTimer.Elapsed += OnTimedEvent;
aTimer.AutoReset = true;
aTimer.Enabled = false;
}
private static void OnTimedEvent(Object source, ElapsedEventArgs e)
private static string FormatFan(int fan)
{
var cpuFan = Math.Round(Program.wmi.DeviceGet(ASUSWmi.CPU_Fan) / 0.6);
var gpuFan = Math.Round(Program.wmi.DeviceGet(ASUSWmi.GPU_Fan) / 0.6);
if (Program.config.getConfig("fan_rpm") == 1)
return " Fan: " + (fan * 100).ToString() + "RPM";
else
return " Fan: " + Math.Min(Math.Round(fan / 0.6), 100).ToString() + "%"; // relatively to 6000 rpm
}
private static void RefreshSensors()
{
string cpuFan = FormatFan(Program.wmi.DeviceGet(ASUSWmi.CPU_Fan));
string gpuFan = FormatFan(Program.wmi.DeviceGet(ASUSWmi.GPU_Fan));
string cpuTemp = "";
string gpuTemp = "";
string battery = "";
HardwareMonitor.ReadSensors();
if (HardwareMonitor.cpuTemp > 0)
cpuTemp = ": " + Math.Round((decimal)HardwareMonitor.cpuTemp).ToString() + "°C - ";
if (HardwareMonitor.batteryDischarge > 0)
battery = "Discharging: " + Math.Round((decimal)HardwareMonitor.batteryDischarge, 1).ToString() + "W";
Program.settingsForm.BeginInvoke(delegate
{
Program.settingsForm.labelCPUFan.Text = "CPU Fan: " + cpuFan.ToString() + "%";
Program.settingsForm.labelGPUFan.Text = "GPU Fan: " + gpuFan.ToString() + "%";
Program.settingsForm.labelCPUFan.Text = "CPU" + cpuTemp + cpuFan;
Program.settingsForm.labelGPUFan.Text = "GPU" + gpuTemp + gpuFan;
Program.settingsForm.labelBattery.Text = battery;
});
}
private static void OnTimedEvent(Object? source, ElapsedEventArgs? e)
{
RefreshSensors();
aTimer.Interval = 2000;
}
private void SettingsForm_VisibleChanged(object? sender, EventArgs e)
@@ -299,10 +613,13 @@ namespace GHelper
{
InitScreen();
this.Left = Screen.FromControl(this).Bounds.Width - 10 - this.Width;
this.Left = Screen.FromControl(this).WorkingArea.Width - 10 - this.Width;
this.Top = Screen.FromControl(this).WorkingArea.Height - 10 - this.Height;
this.Activate();
aTimer.Interval = 300;
aTimer.Enabled = true;
}
else
{
@@ -310,7 +627,7 @@ namespace GHelper
}
}
public void SetPerformanceMode(int PerformanceMode = ASUSWmi.PerformanceBalanced)
public void SetPerformanceMode(int PerformanceMode = ASUSWmi.PerformanceBalanced, bool notify = false)
{
buttonSilent.FlatAppearance.BorderSize = buttonInactive;
@@ -321,27 +638,47 @@ namespace GHelper
{
case ASUSWmi.PerformanceSilent:
buttonSilent.FlatAppearance.BorderSize = buttonActive;
labelPerf.Text = "Performance Mode: Silent";
perfName = "Silent";
break;
case ASUSWmi.PerformanceTurbo:
buttonTurbo.FlatAppearance.BorderSize = buttonActive;
labelPerf.Text = "Performance Mode: Turbo";
perfName = "Turbo";
break;
default:
buttonBalanced.FlatAppearance.BorderSize = buttonActive;
labelPerf.Text = "Performance Mode: Balanced";
PerformanceMode = ASUSWmi.PerformanceBalanced;
perfName = "Balanced";
break;
}
int oldMode = Program.config.getConfig("performance_mode");
Program.config.setConfig("performance_" + (int)SystemInformation.PowerStatus.PowerLineStatus, PerformanceMode);
Program.config.setConfig("performance_mode", PerformanceMode);
try
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode);
if (Program.config.getConfig("auto_apply_" + PerformanceMode) == 1)
{
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode);
} catch
Program.wmi.SetFanCurve(0, Program.config.getFanConfig(0));
Program.wmi.SetFanCurve(1, Program.config.getFanConfig(1));
}
if (fans != null && fans.Text != "")
{
labelPerf.Text = "Performance Mode: not supported";
fans.LoadFans();
fans.ResetApplyLabel();
}
if (notify && (oldMode != PerformanceMode))
{
try
{
Program.toast.RunToast(perfName);
}
catch
{
Debug.WriteLine("Toast error");
}
}
}
@@ -349,22 +686,34 @@ namespace GHelper
public void CyclePerformanceMode()
{
SetPerformanceMode(Program.config.getConfig("performance_mode") + 1);
SetPerformanceMode(Program.config.getConfig("performance_mode") + 1, true);
}
public void AutoScreen(int Plugged = 1)
public void AutoPerformance(PowerLineStatus Plugged = PowerLineStatus.Online)
{
int mode = Program.config.getConfig("performance_" + (int)Plugged);
if (mode != -1)
SetPerformanceMode(mode, true);
else
SetPerformanceMode(Program.config.getConfig("performance_mode"));
}
public void AutoScreen(PowerLineStatus Plugged = PowerLineStatus.Online)
{
int ScreenAuto = Program.config.getConfig("screen_auto");
if (ScreenAuto != 1) return;
if (Plugged == 1)
if (Plugged == PowerLineStatus.Online)
SetScreen(1000, 1);
else
SetScreen(60, 0);
InitScreen();
}
public void AutoGPUMode(int Plugged = 1)
public void AutoGPUMode(PowerLineStatus Plugged = PowerLineStatus.Online)
{
int GpuAuto = Program.config.getConfig("gpu_auto");
@@ -373,27 +722,20 @@ namespace GHelper
int eco = Program.wmi.DeviceGet(ASUSWmi.GPUEco);
int mux = Program.wmi.DeviceGet(ASUSWmi.GPUMux);
int GPUMode;
if (mux == 0) // GPU in Ultimate, ignore
return;
else
{
if (eco == 1 && Plugged == 1) // Eco going Standard on plugged
if (eco == 1 && Plugged == PowerLineStatus.Online) // Eco going Standard on plugged
{
Program.wmi.DeviceSet(ASUSWmi.GPUEco, 0);
GPUMode = ASUSWmi.GPUModeStandard;
VisualiseGPUMode(GPUMode);
Program.config.setConfig("gpu_mode", GPUMode);
InitGPUMode();
}
else if (eco == 0 && Plugged == 0) // Standard going Eco on plugged
else if (eco == 0 && Plugged != PowerLineStatus.Online) // Standard going Eco on plugged
{
Program.wmi.DeviceSet(ASUSWmi.GPUEco, 1);
GPUMode = ASUSWmi.GPUModeEco;
VisualiseGPUMode(GPUMode);
Program.config.setConfig("gpu_mode", GPUMode);
InitGPUMode();
}
}
@@ -494,9 +836,14 @@ namespace GHelper
checkScreen.Checked = (ScreenAuto == 1);
}
public void VisualiseGPUMode(int GPUMode)
public void VisualiseGPUMode(int GPUMode = -1)
{
if (GPUMode == -1)
{
GPUMode = Program.config.getConfig("gpu_mode");
}
buttonEco.FlatAppearance.BorderSize = buttonInactive;
buttonStandard.FlatAppearance.BorderSize = buttonInactive;
buttonUltimate.FlatAppearance.BorderSize = buttonInactive;
@@ -557,40 +904,41 @@ namespace GHelper
CheckBox chk = (CheckBox)sender;
if (chk.Checked)
{
Program.scheduler.Schedule();
Startup.Schedule();
}
else
{
Program.scheduler.UnSchedule();
Startup.UnSchedule();
}
}
public void SetBatteryChargeLimit(int limit = 100)
{
if (limit < 50 || limit > 100) limit = 100;
if (limit < 40 || limit > 100) return;
labelBatteryLimit.Text = limit.ToString() + "%";
labelBatteryTitle.Text = "Battery Charge Limit: " + limit.ToString() + "%";
trackBattery.Value = limit;
try
{
Program.wmi.DeviceSet(ASUSWmi.BatteryLimit, limit);
} catch
{
Debug.WriteLine("Can't set battery charge limit");
}
Program.wmi.DeviceSet(ASUSWmi.BatteryLimit, limit);
Program.config.setConfig("charge_limit", limit);
}
private void trackBatteryChange(object sender, EventArgs e)
private void trackBatteryChange(object? sender, EventArgs e)
{
if (sender is null)
return;
TrackBar bar = (TrackBar)sender;
SetBatteryChargeLimit(bar.Value);
}
private void checkGPU_CheckedChanged(object sender, EventArgs e)
private void checkGPU_CheckedChanged(object? sender, EventArgs e)
{
if (sender is null)
return;
CheckBox chk = (CheckBox)sender;
if (chk.Checked)
Program.config.setConfig("gpu_auto", 1);
@@ -599,8 +947,12 @@ namespace GHelper
}
private void checkScreen_CheckedChanged(object sender, EventArgs e)
private void checkScreen_CheckedChanged(object? sender, EventArgs e)
{
if (sender is null)
return;
CheckBox chk = (CheckBox)sender;
if (chk.Checked)
Program.config.setConfig("screen_auto", 1);

42
Startup.cs Normal file
View File

@@ -0,0 +1,42 @@
using Microsoft.Win32.TaskScheduler;
using System.Diagnostics;
using System.Security.Principal;
public class Startup
{
static string taskName = "GHelper";
public static bool IsScheduled()
{
TaskService taskService = new TaskService();
return (taskService.RootFolder.AllTasks.Any(t => t.Name == taskName));
}
public static void Schedule()
{
string strExeFilePath = Application.ExecutablePath;
if (strExeFilePath is null) return;
var userId = WindowsIdentity.GetCurrent().Name;
//Debug.WriteLine(strExeFilePath);
TaskDefinition td = TaskService.Instance.NewTask();
td.RegistrationInfo.Description = "GHelper Auto Start";
td.Triggers.Add(new LogonTrigger { UserId = userId, });
td.Actions.Add(strExeFilePath);
td.Settings.StopIfGoingOnBatteries = false;
td.Settings.DisallowStartIfOnBatteries = false;
TaskService.Instance.RootFolder.RegisterTaskDefinition(taskName, td);
}
public static void UnSchedule()
{
TaskService taskService = new TaskService();
taskService.RootFolder.DeleteTask(taskName);
}
}

94
ToastForm.cs Normal file
View File

@@ -0,0 +1,94 @@
using System.Drawing.Drawing2D;
using OSD;
namespace GHelper
{
static class Drawing
{
public static GraphicsPath RoundedRect(Rectangle bounds, int radius)
{
int diameter = radius * 2;
Size size = new Size(diameter, diameter);
Rectangle arc = new Rectangle(bounds.Location, size);
GraphicsPath path = new GraphicsPath();
if (radius == 0)
{
path.AddRectangle(bounds);
return path;
}
path.AddArc(arc, 180, 90);
arc.X = bounds.Right - diameter;
path.AddArc(arc, 270, 90);
arc.Y = bounds.Bottom - diameter;
path.AddArc(arc, 0, 90);
arc.X = bounds.Left;
path.AddArc(arc, 90, 90);
path.CloseFigure();
return path;
}
public static void FillRoundedRectangle(this Graphics graphics, Brush brush, Rectangle bounds, int cornerRadius)
{
using (GraphicsPath path = RoundedRect(bounds, cornerRadius))
{
graphics.FillPath(brush, path);
}
}
}
class ToastForm : OSDNativeForm
{
protected static string toastText = "Balanced";
protected static System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
protected override void PerformPaint(PaintEventArgs e)
{
Brush brush = new SolidBrush(Color.FromArgb(150,Color.Black));
Drawing.FillRoundedRectangle(e.Graphics, brush, this.Bound, 10);
StringFormat format = new StringFormat();
format.LineAlignment = StringAlignment.Center;
format.Alignment = StringAlignment.Center;
e.Graphics.DrawString(toastText,
new Font("Segoe UI", 16f, FontStyle.Bold),
new SolidBrush(Color.White),
new PointF(this.Bound.Width/2, this.Bound.Height / 2),
format);
}
public void RunToast(string text)
{
toastText = text;
Screen screen1 = Screen.FromHandle(base.Handle);
Width = 300;
Height = 100;
X = (screen1.Bounds.Width - this.Width)/2;
Y = screen1.Bounds.Height - 300 - this.Height;
Show();
timer.Stop();
timer.Tick -= timer_Tick;
timer.Tick += timer_Tick;
timer.Enabled = true;
timer.Interval = 2000;
timer.Start();
}
private void timer_Tick(object? sender, EventArgs e)
{
timer.Stop();
Hide();
}
}
}

View File

@@ -16,7 +16,6 @@
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
@@ -53,13 +52,15 @@
Makes the application long-path aware. See https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
<windowsSettings>
<!--<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitor/dpiAwareness>-->
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor, System</dpiAwareness>
</windowsSettings>
</application>
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<dependency>
<dependentAssembly>
<assemblyIdentity

BIN
favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

BIN
null

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 813 KiB

After

Width:  |  Height:  |  Size: 2.3 MiB

BIN
screenshots/screen-5w.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 955 KiB

15
stop-asus-sv.bat Normal file
View File

@@ -0,0 +1,15 @@
sc STOP AsusAppService
sc STOP ASUSLinkNear
sc STOP ASUSLinkRemote
sc STOP ASUSSoftwareManager
sc STOP ASUSSwitch
sc STOP ASUSSystemAnalysis
sc STOP ASUSSystemDiagnosis
sc DELETE AsusAppService
sc DELETE ASUSLinkNear
sc DELETE ASUSLinkRemote
sc DELETE ASUSSoftwareManager
sc DELETE ASUSSwitch
sc DELETE ASUSSystemAnalysis
sc DELETE ASUSSystemDiagnosis