44using System . IO ;
55using System . Linq ;
66using System . Threading ;
7+ using HP . Omen . Core . Common . NVidiaApi ;
78using Microsoft . Win32 ;
89using Microsoft . Win32 . TaskScheduler ;
9- using Newtonsoft . Json . Linq ;
1010using static OmenSuperHub . GpuAppManager ;
1111using static OmenSuperHub . OmenHardware ;
1212
1313namespace OmenSuperHub {
1414 static partial class Program {
15+ private static List < int > frameRateMap = new List < int > ( ) ;
16+
17+ private static void InitFrameRateMap ( ) {
18+ frameRateMap . Clear ( ) ;
19+
20+ frameRateMap . Add ( 0 ) ; // index 0 = 0
21+
22+ for ( int v = 1 ; v <= 5 ; v += 1 )
23+ frameRateMap . Add ( v ) ;
24+
25+ for ( int v = 5 ; v <= 60 ; v += 5 )
26+ frameRateMap . Add ( v ) ;
27+
28+ for ( int v = 60 ; v <= 240 ; v += 10 )
29+ frameRateMap . Add ( v ) ;
30+
31+ for ( int v = 240 ; v <= 1000 ; v += 20 )
32+ frameRateMap . Add ( v ) ;
33+ }
34+
35+ private static int IndexToFrameRate ( int index ) {
36+ if ( index < 0 ) return 0 ;
37+ if ( index >= frameRateMap . Count ) return frameRateMap [ frameRateMap . Count - 1 ] ;
38+ return frameRateMap [ index ] ;
39+ }
40+
41+ private static int FrameRateToIndex ( int value ) {
42+ int bestIndex = 0 ;
43+ int bestDiff = int . MaxValue ;
44+
45+ for ( int i = 0 ; i < frameRateMap . Count ; i ++ ) {
46+ int diff = Math . Abs ( frameRateMap [ i ] - value ) ;
47+ if ( diff < bestDiff ) {
48+ bestDiff = diff ;
49+ bestIndex = i ;
50+ }
51+ }
52+
53+ return bestIndex ;
54+ }
55+
1556 /// <summary>
1657 /// 获取当前系统 UI 语言对应的语言代码(zh-CN / zh-TW / en)
1758 /// 若无法匹配,返回 "en"
@@ -520,6 +561,7 @@ static void SaveConfig(string configName = null) {
520561 key . SetValue ( "DState" , dState ) ;
521562 if ( hasNVIDIAGpu ) {
522563 key . SetValue ( "GpuClock" , gpuClock ) ;
564+ key . SetValue ( "MaxFrameRate" , maxFrameRate ) ;
523565 key . SetValue ( "DBVersion" , DBVersion ) ;
524566 }
525567 key . SetValue ( "AutoStart" , autoStart ) ;
@@ -581,6 +623,9 @@ static void SaveConfig(string configName = null) {
581623 case "GpuClock" :
582624 key . SetValue ( "GpuClock" , gpuClock ) ;
583625 break ;
626+ case "MaxFrameRate" :
627+ key . SetValue ( "MaxFrameRate" , maxFrameRate ) ;
628+ break ;
584629 case "DBVersion" :
585630 key . SetValue ( "DBVersion" , DBVersion ) ;
586631 break ;
@@ -645,7 +690,7 @@ static void SaveConfig(string configName = null) {
645690 key . SetValue ( "AutoFanProtect" , autoFanProtect ) ;
646691 break ;
647692 }
648- if ( configName == "FanTable" || configName == "FanControl" || configName == "TempSensitivity" || configName == "CpuPower" || configName == "TgpPower" || configName == "PpabPower" || configName == "DState" || configName == "GpuClock" || configName == "TppPower" || configName == "IccMax" || configName == "AcLoadLine" ||
693+ if ( configName == "FanTable" || configName == "FanControl" || configName == "TempSensitivity" || configName == "CpuPower" || configName == "TgpPower" || configName == "PpabPower" || configName == "DState" || configName == "GpuClock" || configName == "MaxFrameRate" || configName == " TppPower" || configName == "IccMax" || configName == "AcLoadLine" ||
649694 configName == "MonitorCPU" || configName == "MonitorGPU" || configName == "MonitorFan" || configName == "MonitorRefreshRate" || configName == "TempDisplayMode" ) {
650695 SavePresetToRegistry ( currentPreset ) ;
651696 }
@@ -670,6 +715,7 @@ static void SavePresetToRegistry(string presetKey) {
670715 key . SetValue ( "PpabPower" , ppabPower ) ;
671716 key . SetValue ( "DState" , dState ) ;
672717 key . SetValue ( "GpuClock" , gpuClock ) ;
718+ key . SetValue ( "MaxFrameRate" , maxFrameRate ) ;
673719 key . SetValue ( "TppPower" , tppPower ) ;
674720 key . SetValue ( "IccMax" , iccMax ) ;
675721 key . SetValue ( "AcLoadLine" , acLoadline ) ;
@@ -697,6 +743,7 @@ static void LoadPresetFromRegistry(string presetKey) {
697743 ppabPower = ( string ) key . GetValue ( "PpabPower" , ppabPower ) ;
698744 dState = ( string ) key . GetValue ( "DState" , dState ) ;
699745 gpuClock = ( int ) key . GetValue ( "GpuClock" , gpuClock ) ;
746+ maxFrameRate = ( int ) key . GetValue ( "MaxFrameRate" , maxFrameRate ) ;
700747 tppPower = ( string ) key . GetValue ( "TppPower" , tppPower ) ;
701748 iccMax = ( string ) key . GetValue ( "IccMax" , iccMax ) ;
702749 acLoadline = ( string ) key . GetValue ( "AcLoadLine" , acLoadline ) ;
@@ -751,6 +798,7 @@ static void RestoreConfig(bool isPreset = false) {
751798 ppabPower = ( string ) key . GetValue ( "PpabPower" , "on" ) ;
752799 dState = ( string ) key . GetValue ( "DState" , "normal" ) ;
753800 gpuClock = ( int ) key . GetValue ( "GpuClock" , 0 ) ;
801+ maxFrameRate = ( int ) key . GetValue ( "MaxFrameRate" , - 1 ) ;
754802 tppPower = ( string ) key . GetValue ( "TppPower" , "null" ) ;
755803 iccMax = ( string ) key . GetValue ( "IccMax" , "null" ) ;
756804 acLoadline = ( string ) key . GetValue ( "AcLoadLine" , "null" ) ;
@@ -893,15 +941,32 @@ static void RestoreConfig(bool isPreset = false) {
893941 UpdateCheckedState ( "dStateGroup" , dState == "normal" ? Strings . Normal : Strings . LowPower ) ;
894942
895943 if ( hasNVIDIAGpu ) {
896- if ( SetGPUClockLimit ( gpuClock ) ) {
897- if ( gpuClock > 0 && gpuClockTrackBar != null ) {
898- gpuClockTrackBar . Value = gpuClock / 10 ;
899- UpdateCheckedState ( "gpuClockGroup" , Strings . SetGpuClockSlider ) ;
900- } else if ( gpuClock == 0 ) {
901- UpdateCheckedState ( "gpuClockGroup" , Strings . Restore ) ;
944+ if ( gpuClockTrackBar != null ) {
945+ if ( SetGPUClockLimit ( gpuClock ) ) {
946+ if ( gpuClock > 0 ) {
947+ gpuClockTrackBar . Value = gpuClock / 10 ;
948+ UpdateCheckedState ( "gpuClockGroup" , Strings . SetGpuClockSlider ) ;
949+ } else if ( gpuClock == 0 ) {
950+ UpdateCheckedState ( "gpuClockGroup" , Strings . Unlimited ) ;
951+ }
952+ } else {
953+ UpdateCheckedState ( "gpuClockGroup" , Strings . Unlimited ) ;
954+ }
955+ }
956+
957+ if ( maxFrameRateTrackBar != null ) {
958+ if ( maxFrameRate > 0 ) {
959+ NvApiWrapper . NVAPI_SetMaxFrameRate ( maxFrameRate ) ;
960+ maxFrameRateTrackBar . Value = FrameRateToIndex ( maxFrameRate ) ;
961+ UpdateCheckedState ( "maxFrameRateGroup" , Strings . SetMaxFrameRateSlider ) ;
962+ } else if ( maxFrameRate == 0 ) {
963+ NvApiWrapper . NVAPI_SetMaxFrameRate ( 0 ) ;
964+ maxFrameRateTrackBar . Value = FrameRateToIndex ( NvApiWrapper . NVAPI_GetMaxFrameRate ( ) ) ;
965+ UpdateCheckedState ( "maxFrameRateGroup" , Strings . Unlimited ) ;
966+ } else {
967+ maxFrameRateTrackBar . Value = FrameRateToIndex ( NvApiWrapper . NVAPI_GetMaxFrameRate ( ) ) ;
968+ UpdateCheckedState ( "maxFrameRateGroup" , Strings . NotSet ) ;
902969 }
903- } else {
904- UpdateCheckedState ( "gpuClockGroup" , Strings . Restore ) ;
905970 }
906971
907972 if ( DBMenu . Enabled && ! isPreset ) {
@@ -1137,16 +1202,19 @@ static void applyPresetLogic(string targetPreset) {
11371202 if ( targetPreset == "PresetExtreme" ) {
11381203 cpuPower = $ "{ targetPL1Perf } W";
11391204 tppPower = $ "{ targetPL1Perf } W";
1205+ maxFrameRate = 0 ;
11401206 } else if ( targetPreset == "PresetGpuPriority" ) {
11411207 cpuPower = $ "{ targetPL1Default } W";
11421208 tppPower = $ "{ targetPL1Perf } W";
1209+ maxFrameRate = 0 ;
11431210 } else if ( targetPreset == "PresetLightUse" ) {
11441211 fanTable = "silent" ;
11451212 cpuPower = $ "{ ( int ) ( targetPL1Default * 0.6 ) } W";
11461213 if ( currentPreset == "PresetLightUse" && platformSettings ? . NbPL1UpperBoundDefault == null ) cpuPower = "30 W" ;
11471214 tppPower = "null" ;
11481215 tgpPower = "off" ;
11491216 ppabPower = "off" ;
1217+ maxFrameRate = 60 ;
11501218 }
11511219 } else {
11521220 LoadPresetFromRegistry ( targetPreset ) ;
0 commit comments