Skip to content

Commit 5466a7f

Browse files
committed
新增本机信息,包括传感器温度和主板产品号等。
1 parent e6ee11a commit 5466a7f

9 files changed

Lines changed: 373 additions & 42 deletions

HelpForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public HelpForm() {
4545
Dock = DockStyle.Fill,
4646
Text = "版本号:" + version +
4747
"\n更新说明:\n" +
48-
"(1)功能:新增CPU监控开关,若CPU、GPU监控均关闭将关闭Libre硬件监控库,可能对解决反作弊问题有用\n" +
48+
"(1)功能:新增本机信息,包括IR、南桥、环境传感器温度和主板产品号等\n" +
4949
"(2)功能:新增刷新频率和温度显示方式菜单;\n" +
5050
"(3)修复:启动时Tpp设置失效的异常;\n" +
5151
"(4)修复:增强温度过高时自动切换模式的稳定性。\n\n" +

OmenHardware.cs

Lines changed: 131 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ public static byte[] GetSystemDesignData() {
5050
return SendOmenBiosWmi(0x28, new byte[] { 0x00, 0x00, 0x00, 0x00 }, 128);
5151
}
5252

53+
// 提取适配器功率
54+
public static int GetAdapterPower() {
55+
byte[] data = GetSystemDesignData();
56+
if (data == null || data.Length < 2) {
57+
return -1;
58+
}
59+
return data[0] | (data[1] << 8);
60+
}
61+
5362
// 解析并输出 SystemDesignData (128字节) 的关键比特位含义
5463
public static void PrintSystemDesignData() {
5564
byte[] data = GetSystemDesignData();
@@ -134,7 +143,7 @@ public static void PrintSystemDesignData() {
134143
Console.WriteLine($" DefaultLoadLine (高4位) : {defaultLoadLine}");
135144
Console.WriteLine();
136145

137-
// --- 字节 [10]: 传感器能力 ---
146+
// --- 字节 [10]: 传感器能力,但是为0也可能能获取传感器值 ---
138147
byte b10 = data[10];
139148
Console.WriteLine($"[10] 传感器能力 = 0x{b10:X2} ({Convert.ToString(b10, 2).PadLeft(8, '0')})");
140149
Console.WriteLine($" Bit 0 (IR_Sensor) : {(b10 & 0x01) != 0}");
@@ -147,7 +156,7 @@ public static void PrintSystemDesignData() {
147156
Console.WriteLine($" Bit 7 : {(b10 & 0x80) != 0}");
148157
Console.WriteLine($" => IR 传感器 (Bit0) : {((b10 & 0x01) != 0 ? "是" : "否")}");
149158
Console.WriteLine($" => 环境传感器 (Bit1) : {((b10 & 0x02) != 0 ? "是" : "否")}");
150-
Console.WriteLine($" => PCH 过热支持 (Bit2) : {((b10 & 0x04) != 0 ? "是" : "否")}");
159+
Console.WriteLine($" => PCH 传感器 (Bit2) : {((b10 & 0x04) != 0 ? "是" : "否")}");
151160
Console.WriteLine($" => VR 传感器 (Bit3) : {((b10 & 0x08) != 0 ? "是" : "否")}");
152161
Console.WriteLine();
153162

@@ -176,6 +185,100 @@ public static void PrintSystemDesignData() {
176185
Console.WriteLine("=============================================");
177186
}
178187

188+
public enum GraphicsMode {
189+
Hybrid = 0, // 混合模式
190+
Discrete = 1, // 独显直连
191+
Optimus = 2, // Optimus
192+
UMA = 3 // 仅核显
193+
}
194+
195+
/// <summary>
196+
/// 获取当前显卡模式(读取时返回的是当前生效的模式,可能需要重启后才会变化)
197+
/// </summary>
198+
public static GraphicsMode GetGfxMode() {
199+
byte[] result = SendOmenBiosWmi(82, new byte[4] { 0, 0, 0, 0 }, 4, 1);
200+
if (result != null && result.Length > 0) {
201+
int modeValue = result[0] & 0x7F; // 忽略最高位(可能是状态位)
202+
if (modeValue >= 0 && modeValue <= 3)
203+
return (GraphicsMode)modeValue;
204+
}
205+
return GraphicsMode.Hybrid; // 默认返回混合模式
206+
}
207+
208+
/// <summary>
209+
/// 检查支持的模式(若需要)
210+
/// 优先从系统设计数据字节[7]获取,失败时回退到旧版检测
211+
/// </summary>
212+
public static byte GetSupportedGfxModes() {
213+
// 尝试从系统设计数据获取
214+
byte[] designData = GetSystemDesignData();
215+
if (designData != null && designData.Length > 7 && designData[7] != 0)
216+
return designData[7];
217+
218+
// 回退到旧版检测:读取命令1, 82的返回码
219+
byte[] result = SendOmenBiosWmi(82, null, 4, 1);
220+
if (result != null && result.Length > 0) {
221+
int code = result[0];
222+
if (code != 3 && code != 4) // 3=无效命令, 4=无效命令类型
223+
return 6; // 6 = 支持 legacy 模式
224+
}
225+
return 0; // 不支持
226+
}
227+
228+
public static void PrintSupportedGfxModes(byte supported) {
229+
Console.WriteLine($"支持的模式标志:0x{supported:X2}");
230+
231+
if (supported == 0) {
232+
Console.WriteLine(" → 不支持任何显卡切换模式");
233+
return;
234+
}
235+
236+
var modes = new List<string>();
237+
if ((supported & 1) != 0) modes.Add("UMA(仅集显)");
238+
if ((supported & 2) != 0) modes.Add("Hybrid(混合输出/Optimus)");
239+
if ((supported & 4) != 0) modes.Add("Discrete(独显直连)");
240+
if ((supported & 8) != 0) modes.Add("DDS(动态切换/Advanced Optimus)");
241+
242+
Console.WriteLine(" → 支持的模式:");
243+
foreach (var m in modes)
244+
Console.WriteLine($" - {m}");
245+
246+
// 用传统 switch 语句替代 switch 表达式
247+
string constantName = null;
248+
switch (supported) {
249+
case 0:
250+
constantName = "SupportMode_None";
251+
break;
252+
case 1:
253+
constantName = "SupportMode_UMA";
254+
break;
255+
case 2:
256+
constantName = "SupportMode_Hybrid";
257+
break;
258+
case 3:
259+
constantName = "SupportMode_HybridUMA";
260+
break;
261+
case 4:
262+
constantName = "SupportMode_Discrete";
263+
break;
264+
case 5:
265+
constantName = "SupportMode_DiscrerteUMA";
266+
break;
267+
case 6:
268+
constantName = "SupportMode_Legacy";
269+
break;
270+
case 8:
271+
constantName = "SupportMode_DDS";
272+
break;
273+
// 其他组合没有对应常量,保持 null
274+
}
275+
276+
if (constantName != null)
277+
Console.WriteLine($" → 对应常量:{constantName}");
278+
else
279+
Console.WriteLine(" (此为组合模式,无对应单一常量)");
280+
}
281+
179282
public static bool IsLoadLineSupported() {
180283
byte[] data = GetSystemDesignData();
181284
if (data == null || data.Length < 10)
@@ -218,16 +321,38 @@ public static int GetLoadLine() {
218321
}
219322

220323
// 通过 WMI 设置 IccMax(CPU 电流限制,单位安培)
221-
public static bool SetIccMaxByWmi(decimal iccMaxAmpere) {
324+
public static void SetIccMaxByWmi(decimal iccMaxAmpere) {
222325
byte[] inputData = new byte[128];
223326
inputData[0] = 0;
224327
inputData[1] = 15; // 子命令:IccMax 操作
225328
inputData[2] = (byte)((int)iccMaxAmpere & 0xFF);
226329
inputData[3] = (byte)(((int)iccMaxAmpere >> 8) & 0xFF);
227-
// 写操作,outputSize=0 表示不关心返回数据(官方亦如此)
228330
SendOmenBiosWmi(0x37, inputData, 0);
229-
// 官方通过 BiosWmiCmd_SetSync 的返回值判断,此处简化处理,认为无异常即成功
230-
return true;
331+
}
332+
333+
/// <summary>
334+
/// 根据传感器索引获取温度(摄氏度)
335+
/// </summary>
336+
/// <param name="sensorIndex">
337+
/// 传感器索引:
338+
/// 0 - IR 传感器(主板/系统内部温度,部分新机型会映射为环境传感器)
339+
/// 1 - 环境传感器(机箱内空气温度)
340+
/// 2 - PCH 芯片温度
341+
/// 3 - VR(电压调节模块)温度
342+
/// </param>
343+
/// <returns>温度值(℃),失败或传感器无效时返回 -1</returns>
344+
public static int GetSensorTemperature(byte sensorIndex) {
345+
byte[] input = new byte[4];
346+
input[0] = sensorIndex; // 其余字节自动为 0
347+
348+
// commandType = 35 (0x23), 返回 4 字节
349+
byte[] result = SendOmenBiosWmi(0x23, input, 4);
350+
351+
if (result != null && result.Length > 0) {
352+
return result[0];
353+
}
354+
355+
return -1;
231356
}
232357

233358
/// <param name="ocp">输出:是否触发过流保护 (Bit 0)</param>

OmenSuperHub.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,18 @@
350350
<EmbeddedResource Include="Resources\HP.Omen.Core.Common.dll" />
351351
<EmbeddedResource Include="Resources\HP.Omen.Core.Model.Device.dll" />
352352
</ItemGroup>
353+
<ItemGroup>
354+
<EmbeddedResource Include="Resources\NvidiaApi.dll" />
355+
</ItemGroup>
356+
<ItemGroup>
357+
<EmbeddedResource Include="Resources\HP.Omen.Core.Logger.dll" />
358+
</ItemGroup>
359+
<ItemGroup>
360+
<EmbeddedResource Include="Resources\HP.Omen.Logger.dll" />
361+
</ItemGroup>
362+
<ItemGroup>
363+
<EmbeddedResource Include="Resources\HP.Omen.Logger.APIs.dll" />
364+
</ItemGroup>
353365
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
354366
<ProjectExtensions>
355367
<VisualStudio AllowExistingFolder="true" />

0 commit comments

Comments
 (0)