11using BepInEx ;
22using HarmonyLib ;
3- using KSP . UI . Binding ;
43using SpaceWarp ;
5- using SpaceWarp . API . Assets ;
64using SpaceWarp . API . Mods ;
7- using SpaceWarp . API . Game ;
8- using SpaceWarp . API . Game . Extensions ;
9- using SpaceWarp . API . UI ;
10- using SpaceWarp . API . UI . Appbar ;
11- using UnityEngine ;
125using KSP . Game ;
136using KSP . Game . Flow ;
14- using static GUIUtil ;
15- using UnityEngine . UIElements . UIR ;
16- using BepInEx . Logging ;
17- using KSP . Game . StartupFlow ;
187
198namespace SkipSplashScreen ;
209
2110[ BepInPlugin ( MyPluginInfo . PLUGIN_GUID , MyPluginInfo . PLUGIN_NAME , MyPluginInfo . PLUGIN_VERSION ) ]
2211[ BepInDependency ( SpaceWarpPlugin . ModGuid , SpaceWarpPlugin . ModVer ) ]
12+ [ HarmonyPatch ( typeof ( SequentialFlow ) ) ]
2313public class SkipSplashScreenPlugin : BaseSpaceWarpPlugin
2414{
2515 // These are useful in case some other mod wants to add a dependency to this one
2616 public const string ModGuid = MyPluginInfo . PLUGIN_GUID ;
2717 public const string ModName = MyPluginInfo . PLUGIN_NAME ;
2818 public const string ModVer = MyPluginInfo . PLUGIN_VERSION ;
29-
30- private bool _isWindowOpen ;
31- private Rect _windowRect ;
32-
33- private const string ToolbarFlightButtonID = "BTN-SkipSplashScreenFlight" ;
34- private const string ToolbarOABButtonID = "BTN-SkipSplashScreenOAB" ;
3519
36- public static SkipSplashScreenPlugin Instance { get ; set ; }
37-
38- /// <summary>
39- /// Runs when the mod is first initialized.
40- /// </summary>
41- public override void OnInitialized ( )
20+ public void Start ( )
4221 {
43- base . OnInitialized ( ) ;
44-
45- Instance = this ;
46-
47- // Register Flight AppBar button
48- Appbar . RegisterAppButton (
49- "SkipSplashScreen" ,
50- ToolbarFlightButtonID ,
51- AssetManager . GetAsset < Texture2D > ( $ "{ SpaceWarpMetadata . ModID } /images/icon.png") ,
52- isOpen =>
53- {
54- _isWindowOpen = isOpen ;
55- GameObject . Find ( ToolbarFlightButtonID ) ? . GetComponent < UIValue_WriteBool_Toggle > ( ) ? . SetValue ( isOpen ) ;
56- }
57- ) ;
58-
59- // Register OAB AppBar Button
60- Appbar . RegisterOABAppButton (
61- "SkipSplashScreen" ,
62- ToolbarOABButtonID ,
63- AssetManager . GetAsset < Texture2D > ( $ "{ SpaceWarpMetadata . ModID } /images/icon.png") ,
64- isOpen =>
65- {
66- _isWindowOpen = isOpen ;
67- GameObject . Find ( ToolbarOABButtonID ) ? . GetComponent < UIValue_WriteBool_Toggle > ( ) ? . SetValue ( isOpen ) ;
68- }
69- ) ;
70-
71- // Fetch a configuration value or create a default one if it does not exist
72- var defaultValue = "my_value" ;
73- var configValue = Config . Bind < string > ( "Settings section" , "Option 1" , defaultValue , "Option description" ) ;
74-
75- // Log the config value into <KSP2 Root>/BepInEx/LogOutput.log
76- Logger . LogInfo ( $ "Option 1: { configValue . Value } ") ;
77-
78- //Harmony.CreateAndPatchAll(typeof(SkipSplashScreenPlugin).Assembly);
22+ Harmony . CreateAndPatchAll ( typeof ( SkipSplashScreenPlugin ) . Assembly ) ;
7923 }
8024
8125 public void Update ( )
8226 {
83- if ( GameManager . Instance . Game . GlobalGameState . GetState ( ) == GameState . MainMenu )
84- Destroy ( this ) ;
85- }
86-
87- private static FlowAction lastFlowAction = null ;
88- private static List < FlowAction > flowActions = new List < FlowAction > ( ) ;
89-
90- /// <summary>
91- /// Defines the content of the UI window drawn in the <code>OnGui</code> method.
92- /// </summary>
93- /// <param name="windowID"></param>
94- private static void FillWindow ( int windowID )
95- {
96- GUILayout . BeginHorizontal ( ) ;
97- GUILayout . Label ( "GameManager.Instance: " ) ;
98- GUILayout . FlexibleSpace ( ) ;
99- GUILayout . Label ( $ "{ GameManager . Instance } ") ;
100- GUILayout . EndHorizontal ( ) ;
27+ var gameState = GameManager . Instance ? . Game . GlobalGameState ? . GetState ( ) ;
10128
102- GUILayout . BeginHorizontal ( ) ;
103- GUILayout . Label ( "GameManager.Instance.Game.GlobalGameState: " ) ;
104- GUILayout . FlexibleSpace ( ) ;
105- GUILayout . Label ( $ "{ GameManager . Instance . Game . GlobalGameState } ") ;
106- GUILayout . EndHorizontal ( ) ;
107-
108- GUILayout . BeginHorizontal ( ) ;
109- GUILayout . Label ( "GameManager.Instance.Game.GlobalGameState.GetState: " ) ;
110- GUILayout . FlexibleSpace ( ) ;
111- GUILayout . Label ( $ "{ GameManager . Instance . Game . GlobalGameState . GetState ( ) } ") ;
112- GUILayout . EndHorizontal ( ) ;
113-
114- //GUILayout.Label($"{}");
115-
116-
117- GameManager instance = GameManager . Instance ;
118- FlowAction flowAction ;
119- if ( instance == null )
120- {
121- flowAction = null ;
122- }
123- else
124- {
125- SequentialFlow loadingFlow = instance . LoadingFlow ;
126- flowAction = loadingFlow ? . GetCurrentAction ( ) ;
127-
128- if ( flowAction != lastFlowAction )
129- {
130- GUILayout . Label ( "Flow changed" ) ;
131- lastFlowAction = flowAction ;
132- flowActions . Add ( lastFlowAction ) ;
133- }
134-
135- GUILayout . BeginHorizontal ( ) ;
136- GUILayout . Label ( "FlowAction name: " ) ;
137- GUILayout . FlexibleSpace ( ) ;
138- GUILayout . Label ( $ "{ flowAction . Name } ") ;
139- GUILayout . EndHorizontal ( ) ;
140-
141- GUILayout . BeginHorizontal ( ) ;
142- GUILayout . Label ( "FlowAction Timeout: " ) ;
143- GUILayout . FlexibleSpace ( ) ;
144- GUILayout . Label ( $ "{ flowAction . Timeout } ") ;
145- GUILayout . EndHorizontal ( ) ;
146-
147- GUILayout . BeginHorizontal ( ) ;
148- GUILayout . Label ( "FlowAction Description: " ) ;
149- GUILayout . FlexibleSpace ( ) ;
150- GUILayout . Label ( $ "{ flowAction . Description } ") ;
151- GUILayout . EndHorizontal ( ) ;
152-
153- }
154- if ( flowAction == null || flowAction . Name != "Creating Splash Screens Prefab" )
155- {
29+ if ( gameState == null )
15630 return ;
157- }
158- flowAction . Timeout = 0 ;
159- //this.showNotice = true;
160-
161- //GameObject.Find(ToolbarOABButtonID)?.GetComponent<UIValue_WriteBool_Toggle>()?.SetValue(isOpen);
162- var splashScreenManager = GameObject . FindObjectOfType ( typeof ( SplashScreensManager ) ) ; // .Find(ToolbarOABButtonID)?.GetComponent<UIValue_WriteBool_Toggle>()?.SetValue(isOpen);
163- SplashScreensManager man = new SplashScreensManager ( ) ;
164-
165-
166-
167-
168-
169- GUI . DragWindow ( new Rect ( 0 , 0 , Screen . width , Screen . height ) ) ;
170- }
171-
172- public void Start ( )
173- {
174- Harmony . CreateAndPatchAll ( typeof ( SkipSplashScreenPlugin ) . Assembly ) ;
175- }
176- }
177-
178- [ HarmonyPatch ( typeof ( SplashScreensManager ) ) ]
179- [ HarmonyPatch ( "StartAnimations" ) ]
180- public class SplashScreensManagerPatch
181- {
182- private static ManualLogSource Logger = BepInEx . Logging . Logger . CreateLogSource ( "SkipSplashScreenPlugin.SplashScreensManagerPatch" ) ;
18331
184- private static void Prefix ( SplashScreensManager __instance )
185- {
186- Logger . LogInfo ( "StartAnimations harmony patch hit" ) ;
187- //__instance.ResolveSplashScreens();
188- }
189- }
190-
191- [ HarmonyPatch ( typeof ( SequentialFlow ) ) ]
192- public class SplashScreensManagerPatch2
193- {
194- private static ManualLogSource Logger = BepInEx . Logging . Logger . CreateLogSource ( "SkipSplashScreenPlugin.SplashScreensManagerPatch2" ) ;
32+ if ( GameManager . Instance . Game . GlobalGameState . GetState ( ) == GameState . MainMenu )
33+ Destroy ( this ) ;
34+ }
19535
19636 [ HarmonyPatch ( "AddAction" ) ]
19737 [ HarmonyPrefix ]
198- private static bool AddActionPrefix ( FlowAction action )
38+ private static bool SequentialFlow_AddAction ( FlowAction action )
19939 {
200- Logger . LogInfo ( $ "SequentialFlow harmony patch hit. Action name: { action . Name } ") ;
201- if ( action . Name == "Creating Splash Screens Prefab" || action . Name == "Parsing Loading Screens" || action . Name == "Set Loading Optimizations" )
40+ if ( action . Name == "Creating Splash Screens Prefab" )
20241 {
20342 GameManager . Instance . HasPhotosensitivityWarningBeenShown = true ;
20443 return false ;
20544 }
206-
20745 else
20846 return true ;
209- //__instance.ResolveSplashScreens();
210- }
211- }
212-
213- [ HarmonyPatch ( typeof ( LandingHUD ) ) ]
214- public class SplashScreensManagerPatch3
215- {
216- private static ManualLogSource Logger = BepInEx . Logging . Logger . CreateLogSource ( "SkipSplashScreenPlugin.LandingHUD" ) ;
217-
218- [ HarmonyPatch ( "Start" ) ]
219- [ HarmonyPrefix ]
220- private static bool StartPrefix ( LandingHUD __instance )
221- {
222- Logger . LogInfo ( $ "LandingHUD harmony patch hit.") ;
223-
224- //GameManager.Instance.HasPhotosensitivityWarningBeenShown = true;
225-
226- return true ;
227- //__instance.ResolveSplashScreens();
22847 }
229- }
48+ }
0 commit comments