22using System . Collections . Generic ;
33using System . ComponentModel ;
44using System . IO ;
5+ using System . Linq ;
56using System . Reflection ;
67using System . Windows . Forms ;
78
89namespace DLSSTweaks . ConfigTool
910{
1011 public partial class Main : Form
1112 {
13+ public static string FirstCharToUpper ( string input )
14+ {
15+ switch ( input )
16+ {
17+ case null : throw new ArgumentNullException ( nameof ( input ) ) ;
18+ case "" : throw new ArgumentException ( $ "{ nameof ( input ) } cannot be empty", nameof ( input ) ) ;
19+ default : return input [ 0 ] . ToString ( ) . ToUpper ( ) + input . Substring ( 1 ) ;
20+ }
21+ }
22+
1223 Dictionary < string , string > dllOverrides = new Dictionary < string , string > ( ) ;
1324
1425 string DefaultFormTitle = "DLSSTweaks" ; // will be updated to actual text after InitializeComponent
1526
1627 static string IniFilename = "dlsstweaks.ini" ;
1728
1829 static string DefaultDescText = "Welcome to DLSSTweaks ConfigTool!\r \n \r \n Select any setting to view a description of it here, or click on the value for the setting to edit it.\r \n \r \n If you just want to force DLAA, simply edit the ForceDLAA value above and then save the file." ;
19-
30+ static string UltraQualityText = "UltraQuality: allows setting the ratio for the 'UltraQuality' level. \r \n \r \n Not every game allows using this level, some may only expose it as an option once this has been set to non-zero. \r \n A very small number might also already show an UltraQuality level, which this setting should be able to customize. \r \n (the number of games that work with this is very small unfortunately) \r \n \r \n Set to 0 to leave this as DLSS default." ;
2031 static string HoverLoadText = "Reload the DLSSTweaks.ini from the same folder as ConfigTool." ;
2132 static string HoverSaveText = "Writes out the changed settings to DLSSTweaks.ini." ;
2233 static string HoverAddDLLOverrideText = "DLL override: allows overriding the path that a game will load a DLL from, simply pick the new DLL you wish to override with.\r \n \r \n This can be useful if you're prevented from editing the game files for some reason.\r \n \r \n eg. with Rockstar Game Launcher, you can't easily update nvngx_dlss.dll without RGL reverting it, but by using this you can make the game load DLSS from a completely different path which RGL can't override." ;
2334
35+ static string [ ] BooleanKeys = new [ ] { "ForceDLAA" , "DisableDevWatermark" , "VerboseLogging" , "Enable" , "DisableIniMonitoring" , "OverrideAppId" } ;
36+ static string [ ] OverrideKeys = new [ ] { "OverrideAutoExposure" , "OverrideDlssHud" } ;
37+ static string [ ] OverrideValues = new [ ] { "Force disable" , "Default" , "Force enable" } ; // -1, 0, 1
38+
2439 public void IniRead ( )
2540 {
2641 lvSettings . Items . Clear ( ) ;
2742 lvSettings . Groups . Clear ( ) ;
43+ lvSettings . ClearEditCells ( ) ;
2844
2945 string [ ] lines = null ;
3046
@@ -49,6 +65,60 @@ public void IniRead()
4965
5066 var groups = new Dictionary < string , ListViewGroup > ( ) ;
5167
68+ bool isUltraQualityAdded = false ;
69+
70+ void AddSetting ( string section , string key , string value , string comment )
71+ {
72+ ListViewGroup group = null ;
73+ if ( ! groups . TryGetValue ( section , out group ) )
74+ {
75+ group = new ListViewGroup ( section ) ;
76+ groups . Add ( section , group ) ;
77+ lvSettings . Groups . Add ( group ) ;
78+ }
79+
80+ bool isBooleanKey = BooleanKeys . Contains ( key ) ;
81+ bool isOverrideKey = OverrideKeys . Contains ( key ) ;
82+ if ( isBooleanKey )
83+ value = FirstCharToUpper ( value ) ;
84+ else
85+ {
86+ if ( isOverrideKey )
87+ {
88+ if ( value == "-1" )
89+ value = OverrideValues [ 0 ] ;
90+ else if ( value == "0" )
91+ value = OverrideValues [ 1 ] ;
92+ else
93+ value = OverrideValues [ 2 ] ;
94+ }
95+ }
96+
97+ var listViewItem = new ListViewItem ( ) ;
98+ listViewItem . Text = key ;
99+ listViewItem . Tag = comment ;
100+ listViewItem . Group = group ;
101+ listViewItem . SubItems . Add ( value ) ;
102+ lvSettings . Items . Add ( listViewItem ) ;
103+
104+ var row = lvSettings . Items . Count - 1 ;
105+
106+ if ( isBooleanKey )
107+ lvSettings . AddComboBoxCell ( row , 1 , new string [ ] { "False" , "True" } ) ;
108+ else
109+ {
110+ if ( isOverrideKey )
111+ lvSettings . AddComboBoxCell ( row , 1 , OverrideValues ) ;
112+ else
113+ {
114+ if ( section == "DLSSPresets" )
115+ lvSettings . AddComboBoxCell ( row , 1 , new string [ ] { "Default" , "A" , "B" , "C" , "D" , "F" } ) ;
116+ else
117+ lvSettings . AddEditableCell ( row , 1 ) ;
118+ }
119+ }
120+ }
121+
52122 foreach ( var line in lines )
53123 {
54124 var trimmed = line . TrimStart ( ' ' ) . TrimEnd ( ' ' ) . TrimStart ( '\t ' ) . TrimEnd ( '\t ' ) ;
@@ -66,6 +136,13 @@ public void IniRead()
66136 if ( trimmed . StartsWith ( "[" ) && trimmed . EndsWith ( "]" ) )
67137 {
68138 state_comment = "" ;
139+
140+ // If we're changing from DLSSQualityLevels section to new section, and haven't added UltraQuality...
141+ if ( state_section == "DLSSQualityLevels" && ! isUltraQualityAdded )
142+ {
143+ AddSetting ( "DLSSQualityLevels" , "UltraQuality" , "0" , UltraQualityText ) ;
144+ }
145+
69146 state_section = trimmed . Substring ( 1 , trimmed . Length - 2 ) ;
70147 continue ;
71148 }
@@ -76,18 +153,6 @@ public void IniRead()
76153 var key = trimmed . Substring ( 0 , seperator ) . TrimStart ( ' ' ) . TrimEnd ( ' ' ) . TrimStart ( '\t ' ) . TrimEnd ( '\t ' ) ;
77154 var value = trimmed . Substring ( seperator + 1 ) . TrimStart ( ' ' ) . TrimEnd ( ' ' ) . TrimStart ( '\t ' ) . TrimEnd ( '\t ' ) ;
78155
79- bool isBooleanValue = value . ToLower ( ) == "true" || value . ToLower ( ) == "false" ;
80- if ( isBooleanValue )
81- value = value . ToLower ( ) ;
82-
83- ListViewGroup group = null ;
84- if ( ! groups . TryGetValue ( state_section , out group ) )
85- {
86- group = new ListViewGroup ( state_section ) ;
87- groups . Add ( state_section , group ) ;
88- lvSettings . Groups . Add ( group ) ;
89- }
90-
91156 if ( state_section == "DLLPathOverrides" )
92157 state_comment = "DLLPathOverrides: allows overriding the path that a DLL will be loaded from based on the filename of it\r \n \r \n Delete/clear the path to remove this override." ;
93158
@@ -97,6 +162,9 @@ public void IniRead()
97162 comment_DLSSQualityLevels = state_comment ;
98163 else
99164 state_comment = comment_DLSSQualityLevels ;
165+
166+ if ( key == "UltraQuality" )
167+ state_comment = UltraQualityText ;
100168 }
101169
102170 if ( state_section == "DLSSPresets" )
@@ -107,24 +175,10 @@ public void IniRead()
107175 state_comment = comment_DLSSPresets ;
108176 }
109177
110- var listViewItem = new ListViewItem ( ) ;
111- listViewItem . Text = key ;
112- listViewItem . Tag = state_comment ;
113- listViewItem . Group = group ;
114- listViewItem . SubItems . Add ( value ) ;
115- lvSettings . Items . Add ( listViewItem ) ;
178+ AddSetting ( state_section , key , value , state_comment ) ;
116179
117- var row = lvSettings . Items . Count - 1 ;
118-
119- if ( isBooleanValue )
120- lvSettings . AddComboBoxCell ( row , 1 , new string [ ] { "true" , "false" } ) ;
121- else
122- {
123- if ( state_section == "DLSSPresets" )
124- lvSettings . AddComboBoxCell ( row , 1 , new string [ ] { "Default" , "A" , "B" , "C" , "D" , "F" } ) ;
125- else
126- lvSettings . AddEditableCell ( row , 1 ) ;
127- }
180+ if ( state_section == "DLSSQualityLevels" && key == "UltraQuality" )
181+ isUltraQualityAdded = true ;
128182
129183 state_comment = "" ;
130184 }
@@ -141,6 +195,18 @@ void IniWrite()
141195 var key = item . Text ;
142196 var value = item . SubItems [ 1 ] . Text ;
143197
198+ if ( OverrideKeys . Contains ( key ) )
199+ {
200+ if ( value == OverrideValues [ 0 ] )
201+ value = "-1" ;
202+ else if ( value == OverrideValues [ 1 ] )
203+ value = "0" ;
204+ else
205+ value = "1" ;
206+ }
207+ else if ( BooleanKeys . Contains ( key ) )
208+ value = value . ToLower ( ) ;
209+
144210 file [ section ] [ key ] = value ;
145211 }
146212
@@ -158,6 +224,7 @@ void IniWrite()
158224 public Main ( )
159225 {
160226 InitializeComponent ( ) ;
227+ AutoScaleMode = AutoScaleMode . Dpi ;
161228 lvSettings . ValueChanged += lvSettings_ValueChanged ;
162229
163230 this . Text += $ " v{ Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version } ";
@@ -196,16 +263,19 @@ private void lvSettings_SelectedIndexChanged(object sender, EventArgs e)
196263
197264 private void saveToolStripMenuItem_Click ( object sender , EventArgs e )
198265 {
266+ lvSettings . Unfocus ( ) ;
199267 IniWrite ( ) ;
200268 }
201269
202270 private void loadToolStripMenuItem_Click ( object sender , EventArgs e )
203271 {
272+ lvSettings . Unfocus ( ) ;
204273 IniRead ( ) ;
205274 }
206275
207276 private void addDLLOverrideToolStripMenuItem_Click ( object sender , EventArgs e )
208277 {
278+ lvSettings . Unfocus ( ) ;
209279 var ofd = new OpenFileDialog ( ) ;
210280 ofd . Title = "Select the new DLL that you want to override with" ;
211281 ofd . Filter = "DLL Files (*.dll)|*.dll|All Files (*.*)|*.*" ;
0 commit comments