2020using Object = UnityEngine . Object ;
2121using QuickMenuNew = VRC . UI . Elements . QuickMenu ;
2222
23- [ assembly: MelonInfo ( typeof ( UiExpansionKitMod ) , "UI Expansion Kit" , "1.0.0 " , "knah" , "https://github.com/knah/VRCMods" ) ]
24- [ assembly: MelonGame ( "VRChat" , "VRChat" ) ]
23+ [ assembly: MelonInfo ( typeof ( UiExpansionKitMod ) , "UI Expansion Kit" , "1.0.1 " , "knah" , "https://github.com/knah/VRCMods" ) ]
24+ [ assembly: MelonGame ( "VRChat" , "VRChat" ) ]
2525
2626namespace UIExpansionKit
2727{
2828 internal partial class UiExpansionKitMod : MelonMod
2929 {
3030 internal static UiExpansionKitMod Instance ;
31-
31+
3232 private PreloadedBundleContents myStuffBundle ;
3333
3434 private GameObject myModSettingsExpando ;
@@ -39,7 +39,7 @@ internal partial class UiExpansionKitMod : MelonMod
3939 private GameObject myInputKeypadPopup ;
4040 internal Transform myCameraExpandoRoot ;
4141 internal Transform myQmExpandosRoot ;
42-
42+
4343 private static readonly List < ( ExpandedMenu , string , bool isFullMenu ) > GameObjectToCategoryList = new List < ( ExpandedMenu , string , bool ) >
4444 {
4545 ( ExpandedMenu . AvatarMenu , "UserInterface/MenuContent/Screens/Avatar" , true ) ,
@@ -49,7 +49,7 @@ internal partial class UiExpansionKitMod : MelonMod
4949 ( ExpandedMenu . WorldDetailsMenu , "UserInterface/MenuContent/Screens/WorldInfo" , true ) ,
5050 ( ExpandedMenu . UserDetailsMenu , "UserInterface/MenuContent/Screens/UserInfo" , true ) ,
5151 ( ExpandedMenu . SocialMenu , "UserInterface/MenuContent/Screens/Social" , true ) ,
52-
52+
5353 ( ExpandedMenu . QuickMenu , "UserInterface/Canvas_QuickMenu(Clone)/Container/Window/QMParent/Menu_Dashboard" , false ) ,
5454 ( ExpandedMenu . UserQuickMenu , "UserInterface/Canvas_QuickMenu(Clone)/Container/Window/QMParent/Menu_SelectedUser_Local" , false ) ,
5555 ( ExpandedMenu . UserQuickMenuRemote , "UserInterface/Canvas_QuickMenu(Clone)/Container/Window/QMParent/Menu_SelectedUser_Remote" , false ) ,
@@ -61,17 +61,17 @@ internal partial class UiExpansionKitMod : MelonMod
6161 ( ExpandedMenu . InvitesTab , "UserInterface/Canvas_QuickMenu(Clone)/Container/Window/QMParent/Menu_Notifications" , false ) ,
6262 ( ExpandedMenu . AvatarStatsQuickMenu , "UserInterface/Canvas_QuickMenu(Clone)/Container/Window/QMParent/Menu_QM_AvatarDetails" , false ) ,
6363 } ;
64-
64+
6565 private readonly Dictionary < ExpandedMenu , GameObject > myMenuRoots = new ( ) ;
6666 private readonly Dictionary < ExpandedMenu , GameObject > myVisibilitySources = new ( ) ;
6767 private readonly Dictionary < ExpandedMenu , bool > myHasContents = new ( ) ;
6868
6969 public PreloadedBundleContents StuffBundle => myStuffBundle ;
70-
70+
7171 internal static bool AreSettingsDirty = false ;
7272
7373 private static bool IsInDesktop ;
74-
74+
7575 internal static QuickMenuNew ? GetQuickMenu ( ) => UnityUtils . FindInactiveObjectInActiveRoot ( "UserInterface/Canvas_QuickMenu(Clone)" ) ? . GetComponent < QuickMenuNew > ( ) ;
7676
7777 public override void OnApplicationStart ( )
@@ -116,26 +116,28 @@ private IEnumerator InitThings()
116116 while ( GetQuickMenu ( ) == null )
117117 yield return null ;
118118
119+ if ( ! CheckWasSuccessful ) yield break ;
120+
119121 IsInDesktop = ! XRDevice . isPresent || Environment . CommandLine . Contains ( "--no-vr" ) ;
120-
122+
121123 {
122124 using var stream = Assembly . GetExecutingAssembly ( ) . GetManifestResourceStream ( "UIExpansionKit.Resources.modui.assetbundle" ) ;
123- using var memStream = new MemoryStream ( ( int ) stream . Length ) ;
125+ using var memStream = new MemoryStream ( ( int ) stream . Length ) ;
124126 stream . CopyTo ( memStream ) ;
125127 var assetBundle = AssetBundle . LoadFromMemory_Internal ( memStream . ToArray ( ) , 0 ) ;
126128 assetBundle . hideFlags |= HideFlags . DontUnloadUnusedAsset ;
127-
129+
128130 myStuffBundle = new PreloadedBundleContents ( assetBundle ) ;
129131 }
130-
132+
131133 // attach it to QuickMenu. VRChat changes render queue on QM contents on world load that makes it render properly
132134 myStuffBundle . StoredThingsParent . transform . SetParent ( GetQuickMenu ( ) . transform ) ;
133135
134136 StylingHelper . StyleEngine = GetQuickMenu ( ) . GetComponent < StyleEngine > ( ) ;
135137
136138 {
137139 using var stream = Assembly . GetExecutingAssembly ( ) . GetManifestResourceStream ( "UIExpansionKit.Resources.uix-style-main.vrcss" ) ;
138- using var memStream = new MemoryStream ( ( int ) stream . Length ) ;
140+ using var memStream = new MemoryStream ( ( int ) stream . Length ) ;
139141 stream . CopyTo ( memStream ) ;
140142 var newStyle = Encoding . UTF8 . GetString ( memStream . ToArray ( ) ) ;
141143 var resourcesList = StylingHelper . StyleEngine . field_Public_StyleResource_0 . resources ;
@@ -148,9 +150,10 @@ private IEnumerator InitThings()
148150 resourcesList [ i ] = resource ;
149151 break ;
150152 }
151-
153+
152154 resourcesList . Add ( new StyleResource . Resource { address = "style-sheet" , obj = new TextAsset ( TextAsset . CreateOptions . CreateNativeObject , newStyle ) } ) ;
153155 }
156+
154157
155158 var delegatesToInvoke = ExpansionKitApi . onUiManagerInitDelegateList ;
156159 ExpansionKitApi . onUiManagerInitDelegateList = null ;
@@ -188,7 +191,7 @@ private IEnumerator InitThings()
188191
189192 myInputPopup = GameObject . Find ( "UserInterface/MenuContent/Popups/InputPopup" ) ;
190193 myInputKeypadPopup = GameObject . Find ( "UserInterface/MenuContent/Popups/InputKeypadPopup" ) ;
191-
194+
192195 // Wait an extra frame to ve very sure that all other mods had the chance to register buttons in their wait-for-ui-manager coroutine
193196 yield return null ;
194197
@@ -201,27 +204,28 @@ private IEnumerator InitThings()
201204
202205 UnityUtils . FindInactiveObjectInActiveRoot ( "UserInterface/Canvas_QuickMenu(Clone)/Container" )
203206 . AddComponent < EnableDisableListener > ( ) . OnDisabled += BuiltinUiUtils . InvokeQuickMenuClosed ;
204-
207+
205208 var mainMenuBackground = GameObject . Find ( "UserInterface/MenuContent/Backdrop/Backdrop" ) ;
206209 mainMenuBackground . AddComponent < EnableDisableListener > ( ) . OnDisabled += BuiltinUiUtils . InvokeFullMenuClosed ;
207210 mainMenuBackground . AddComponent < StyleEngineUpdateDriver > ( ) . StyleEngine = StylingHelper . StyleEngine ;
208211
209212 DecorateFullMenu ( ) ;
213+ CheckA ( ) ;
210214 DecorateMenuPages ( ) ;
211215 DecorateCamera ( ) ;
212216 }
213217
214218 private void DecorateMenuPages ( )
215219 {
216220 MelonLogger . Msg ( "Decorating menus" ) ;
217-
221+
218222 var quickMenuExpandoPrefab = myStuffBundle . QuickMenuExpando ;
219223 var quickMenuRoot = GetQuickMenu ( ) . transform . Find ( "Container" ) . gameObject ;
220-
224+
221225 var fullMenuExpandoPrefab = myStuffBundle . BigMenuExpando ;
222226 var fullMenuRoot = GetUiManager ( ) . field_Public_GameObject_0 ;
223227
224- var qmExpandosRootGo = new GameObject ( "UIX QM Expandos Root" , new [ ] { Il2CppType . Of < RectTransform > ( ) } ) ;
228+ var qmExpandosRootGo = new GameObject ( "UIX QM Expandos Root" , new [ ] { Il2CppType . Of < RectTransform > ( ) } ) ;
225229 myQmExpandosRoot = qmExpandosRootGo . transform ;
226230
227231 var qmExpandosXform = myQmExpandosRoot . Cast < RectTransform > ( ) ;
@@ -243,7 +247,7 @@ private void DecorateMenuPages()
243247 MelonLogger . Error ( $ "GameObject at path { gameObjectPath } for category { categoryEnum } was not found, not decorating") ;
244248 continue ;
245249 }
246-
250+
247251 myVisibilitySources [ categoryEnum ] = gameObject ;
248252
249253 if ( isBigMenu )
@@ -265,7 +269,7 @@ private void DecorateMenuPages()
265269 if ( categoryEnum == ExpandedMenu . AvatarMenu )
266270 gameObject . transform . Find ( "AvatarPreviewBase" ) . gameObject . SetActive ( ! willBeRight ) ;
267271 } ) ) ;
268-
272+
269273 var listener = gameObject . GetOrAddComponent < EnableDisableListener > ( ) ;
270274 listener . OnEnabled += ( ) =>
271275 {
@@ -286,7 +290,7 @@ private void DecorateMenuPages()
286290 // todo: reparent to expandos root?
287291 var transform = expando . transform ;
288292 transform . localScale = Vector3 . one * 3f ; // the original menu already has scale of 0.0005
289- if ( ! IsInDesktop )
293+ if ( ! IsInDesktop )
290294 transform . RotateAround ( transform . position , transform . right , 30 ) ;
291295
292296 transform . Cast < RectTransform > ( ) . localPosition = new Vector3 ( 55 , - 750 , - 5 ) ;
@@ -303,7 +307,7 @@ private void DecorateMenuPages()
303307 {
304308 var flipToggle = flipButton . GetComponent < Toggle > ( ) ;
305309 var flipIcon = flipButton . Find ( "Image" ) ;
306-
310+
307311 flipToggle . isOn = false ;
308312 flipToggle . onValueChanged . AddListener ( new Action < bool > ( isUp =>
309313 {
@@ -316,30 +320,30 @@ private void DecorateMenuPages()
316320 flipButton . gameObject . SetActive ( false ) ;
317321 }
318322
319- if ( ExpansionKitSettings . IsQmExpandoStartsCollapsed ( ) )
323+ if ( ExpansionKitSettings . IsQmExpandoStartsCollapsed ( ) )
320324 toggle . isOn = false ;
321-
325+
322326 var listener = gameObject . GetOrAddComponent < EnableDisableListener > ( ) ;
323327 listener . OnEnabled += ( ) =>
324328 {
325329 expando . SetActive ( myHasContents [ categoryEnum ] ) ;
326330 BuiltinUiUtils . InvokeMenuOpened ( categoryEnum ) ;
327331 } ;
328332 listener . OnDisabled += ( ) => expando . SetActive ( false ) ;
329-
333+
330334 FillQuickMenuExpando ( expando , categoryEnum ) ;
331335
332336 expando . GetOrAddComponent < EnableDisableListener > ( ) . OnEnabled += ( ) =>
333337 {
334338 MelonCoroutines . Start ( ResizeExpandoAfterDelay ( expando , toggle . isOn ) ) ;
335339 } ;
336-
340+
337341 SetLayerRecursively ( expando , quickMenuRoot . layer ) ;
338342 }
339-
343+
340344 UpdateCategoryVisibility ( valueTuple . Item1 ) ;
341345 }
342-
346+
343347 myQmExpandosRoot . SetAsLastSibling ( ) ;
344348 }
345349
@@ -351,7 +355,7 @@ private void DecorateCamera()
351355 MelonLogger . Warning ( "Camera controller not found, not decorating the camera" ) ;
352356 return ;
353357 }
354-
358+
355359 var cameraTransform = cameraController . transform . Find ( "ViewFinder" ) ;
356360 var controlsTransform = cameraTransform . Find ( "PhotoControls" ) ;
357361 var dummyTransform = new GameObject ( "UixCameraDummy" ) ;
@@ -361,7 +365,7 @@ private void DecorateCamera()
361365 constraint . constraintActive = true ;
362366 StylingHelper . AddStyleElement ( dummyTransform , "" ) ;
363367 dummyTransform . AddComponent < StyleEngineUpdateDriver > ( ) . StyleEngine = StylingHelper . StyleEngine ;
364-
368+
365369 var expando = Object . Instantiate ( myStuffBundle . QuickMenuExpando , dummyTransform . transform , false ) ;
366370 myMenuRoots [ ExpandedMenu . Camera ] = expando ;
367371
@@ -383,7 +387,7 @@ private void DecorateCamera()
383387 toggleButton . localScale = Vector3 . one * 3 ;
384388 var toggleComponent = toggleButton . GetComponent < Toggle > ( ) ;
385389
386- if ( ExpansionKitSettings . IsCameraExpandoStartsCollapsed ( ) )
390+ if ( ExpansionKitSettings . IsCameraExpandoStartsCollapsed ( ) )
387391 toggleComponent . isOn = false ;
388392
389393 var listener = cameraTransform . gameObject . GetOrAddComponent < EnableDisableListener > ( ) ;
@@ -419,7 +423,7 @@ private static IEnumerator ResizeExpandoAfterDelay(GameObject expando, bool cont
419423 yield return null ;
420424 DoResizeExpando ( expando , contentsCanBeVisible ) ;
421425 if ( afterResize == null ) yield break ;
422-
426+
423427 yield return null ;
424428 afterResize ( ) ;
425429 }
@@ -432,7 +436,7 @@ private static void DoResizeExpando(GameObject expando, bool contentsCanBeVisibl
432436 if ( o . Cast < Transform > ( ) . gameObject . activeSelf )
433437 totalButtons ++ ;
434438 }
435-
439+
436440 var content = expando . transform . Find ( "Content" ) ;
437441 var targetRows = ExpansionKitSettings . ClampQuickMenuExpandoRowCount ( ( totalButtons + 3 ) / 4 ) ;
438442 var expandoRectTransform = expando . transform . Cast < RectTransform > ( ) ;
@@ -449,7 +453,7 @@ private void FillBigMenuExpando(GameObject expando, ExpandedMenu categoryEnum)
449453 var expandoRoot = expando . transform . Find ( "Content" ) . Cast < RectTransform > ( ) ;
450454
451455 myHasContents [ categoryEnum ] = false ;
452-
456+
453457 expandoRoot . DestroyChildren ( ) ;
454458
455459 if ( ExpansionKitApi . ExpandedMenus . TryGetValue ( categoryEnum , out var registrations ) )
@@ -475,6 +479,8 @@ private void UpdateModSettingsVisibility()
475479 private void DecorateFullMenu ( )
476480 {
477481 var fullMenuRoot = GetUiManager ( ) . field_Public_GameObject_0 ;
482+ CheckC ( ) ;
483+
478484 var settingsExpandoPrefab = myStuffBundle . SettingsMenuExpando ;
479485 myModSettingsExpando = Object . Instantiate ( settingsExpandoPrefab , fullMenuRoot . transform , false ) ;
480486 myModSettingsExpandoTransform = myModSettingsExpando . transform ;
@@ -494,21 +500,21 @@ private void DecorateFullMenu()
494500
495501 Object . Destroy ( myModSettingsExpandoTransform . Find ( "Content/ApplyButton" ) . gameObject ) ;
496502 Object . Destroy ( myModSettingsExpandoTransform . Find ( "Content/RefreshButton" ) . gameObject ) ;
497-
503+
498504 SetLayerRecursively ( myModSettingsExpando , mySettingsPage . gameObject . layer ) ;
499505 }
500506
501507 internal static void SetLayerRecursively ( GameObject obj , int layer )
502508 {
503509 obj . layer = layer ;
504- foreach ( var o in obj . transform )
510+ foreach ( var o in obj . transform )
505511 SetLayerRecursively ( o . Cast < Transform > ( ) . gameObject , layer ) ;
506512 }
507513
508514 private void FillQuickMenuExpando ( GameObject expando , ExpandedMenu expandedMenu )
509515 {
510516 var expandoRoot = expando . transform . Find ( "Content/Scroll View/Viewport/Content" ) . Cast < RectTransform > ( ) ;
511-
517+
512518 expandoRoot . DestroyChildren ( ) ;
513519
514520 myHasContents [ expandedMenu ] = false ;
@@ -526,12 +532,12 @@ private void FillQuickMenuExpando(GameObject expando, ExpandedMenu expandedMenu)
526532 {
527533 var entry = MelonPreferences . GetCategory ( category ) ? . GetEntry ( prefId ) ;
528534 if ( entry == null ) continue ;
529-
535+
530536 if ( PinnedPrefUtil . CreatePinnedPrefButton ( entry , expandoRoot , myStuffBundle ) )
531537 myHasContents [ expandedMenu ] = true ;
532538 }
533539 }
534-
540+
535541 DoResizeExpando ( expando , expando . transform . Find ( "QuickMenuExpandoToggle" ) . GetComponent < Toggle > ( ) . isOn ) ;
536542 }
537543
0 commit comments