11using Newtonsoft . Json . Linq ;
2+ using System ;
23using System . Collections . Generic ;
34using System . IO ;
45using System . Text . Json ;
@@ -15,18 +16,71 @@ public class FastFlagManager : JsonManager<Dictionary<string, object>>
1516 public Dictionary < string , object ? > Changes = new ( ) ;
1617
1718 // only one missing here is Metal because lol
18- public static IReadOnlyDictionary < string , string > RenderingModes { get ; set ; } = new Dictionary < string , string > ( )
19+ public static IReadOnlyDictionary < string , string > RenderingModes => new Dictionary < string , string >
1920 {
2021 { "Automatic" , "" } ,
2122 { "Direct3D 11" , "FFlagDebugGraphicsPreferD3D11" } ,
2223 { "OpenGL" , "FFlagDebugGraphicsPreferOpenGL" } ,
2324 { "Vulkan" , "FFlagDebugGraphicsPreferVulkan" }
2425 } ;
2526
27+ // this is one hell of a variable definition lmao
28+ public static IReadOnlyDictionary < string , Dictionary < string , string ? > > IGMenuVersions => new Dictionary < string , Dictionary < string , string ? > >
29+ {
30+ {
31+ "Default" ,
32+ new Dictionary < string , string ? >
33+ {
34+ { "FFlagDisableNewIGMinDUA" , null } ,
35+ { "FFlagEnableInGameMenuV3" , null }
36+ }
37+ } ,
38+
39+ {
40+ "Version 1 (2015)" ,
41+ new Dictionary < string , string ? >
42+ {
43+ { "FFlagDisableNewIGMinDUA" , "True" } ,
44+ { "FFlagEnableInGameMenuV3" , "False" }
45+ }
46+ } ,
47+
48+ {
49+ "Version 2 (2020)" ,
50+ new Dictionary < string , string ? >
51+ {
52+ { "FFlagDisableNewIGMinDUA" , "False" } ,
53+ { "FFlagEnableInGameMenuV3" , "False" }
54+ }
55+ } ,
56+
57+ {
58+ "Version 3 (2021)" ,
59+ new Dictionary < string , string ? >
60+ {
61+ { "FFlagDisableNewIGMinDUA" , "False" } ,
62+ { "FFlagEnableInGameMenuV3" , "True" }
63+ }
64+ }
65+ } ;
66+
67+ // all fflags are stored as strings
68+ // to delete a flag, set the value as null
69+ public void SetValue ( string key , object ? value )
70+ {
71+ if ( value is null )
72+ {
73+ Changes [ key ] = null ;
74+ App . Logger . WriteLine ( $ "[FastFlagManager::SetValue] Deletion of '{ key } ' is pending") ;
75+ }
76+ else
77+ {
78+ Changes [ key ] = value . ToString ( ) ;
79+ App . Logger . WriteLine ( $ "[FastFlagManager::SetValue] Value change for '{ key } ' to '{ value } ' is pending") ;
80+ }
81+ }
82+
2683 // this returns null if the fflag doesn't exist
27- // this also returns as a string because deserializing an object doesn't
28- // deserialize back into the original object type, it instead deserializes
29- // as a "JsonElement" which is annoying
3084 public string ? GetValue ( string key )
3185 {
3286 // check if we have an updated change for it pushed first
@@ -44,26 +98,39 @@ public void SetRenderingMode(string value)
4498 foreach ( var mode in RenderingModes )
4599 {
46100 if ( mode . Key != "Automatic" )
47- App . FastFlags . Changes [ mode . Value ] = null ;
101+ SetValue ( mode . Value , null ) ;
48102 }
49103
50104 if ( value != "Automatic" )
51- App . FastFlags . Changes [ RenderingModes [ value ] ] = true ;
105+ SetValue ( RenderingModes [ value ] , "True" ) ;
106+ }
107+
108+ public override void Load ( )
109+ {
110+ base . Load ( ) ;
111+
112+ // set to 9999 by default if it doesnt already exist
113+ if ( GetValue ( "DFIntTaskSchedulerTargetFps" ) is null )
114+ SetValue ( "DFIntTaskSchedulerTargetFps" , 9999 ) ;
115+
116+ // reshade / exclusive fullscreen requires direct3d 11 to work
117+ if ( GetValue ( RenderingModes [ "Direct3D 11" ] ) != "True" && ( App . Settings . Prop . UseReShade || App . FastFlags . GetValue ( "FFlagHandleAltEnterFullscreenManually" ) == "False" ) )
118+ SetRenderingMode ( "Direct3D 11" ) ;
52119 }
53120
54121 public override void Save ( )
55122 {
56123 App . Logger . WriteLine ( $ "[FastFlagManager::Save] Attempting to save JSON to { FileLocation } ...") ;
57124
125+ // reload for any changes made while the menu was open
126+ Load ( ) ;
127+
58128 if ( Changes . Count == 0 )
59129 {
60130 App . Logger . WriteLine ( $ "[FastFlagManager::Save] No changes to apply, aborting.") ;
61131 return ;
62132 }
63133
64- // reload for any changes made while the menu was open
65- Load ( ) ;
66-
67134 foreach ( var change in Changes )
68135 {
69136 if ( change . Value is null )
@@ -73,7 +140,7 @@ public override void Save()
73140 continue ;
74141 }
75142
76- App . Logger . WriteLine ( $ "[FastFlagManager::Save] Setting '{ change . Key } ' to { change . Value } ") ;
143+ App . Logger . WriteLine ( $ "[FastFlagManager::Save] Setting '{ change . Key } ' to ' { change . Value } ' ") ;
77144 Prop [ change . Key ] = change . Value ;
78145 }
79146
0 commit comments