Skip to content

Commit

Permalink
Release candidate for beta UI update
Browse files Browse the repository at this point in the history
  • Loading branch information
benaclejames committed Nov 12, 2021
1 parent f4cb57c commit cfed61e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 55 deletions.
56 changes: 12 additions & 44 deletions VRCFaceTracking/MainMod.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using VRCFaceTracking;
using MelonLoader;
using UnityEngine;
using VRCFaceTracking.QuickMenu;

[assembly: MelonInfo(typeof(MainMod), "VRCFaceTracking", "2.4.1", "benaclejames",
[assembly: MelonInfo(typeof(MainMod), "VRCFaceTracking", "2.5.0", "benaclejames",
"https://github.com/benaclejames/VRCFaceTracking")]
[assembly: MelonGame("VRChat", "VRChat")]

Expand All @@ -17,10 +16,8 @@ namespace VRCFaceTracking
public class MainMod : MelonMod
{
// Detect when UIManager has finished initializing
private Assembly _assemblyCSharp;
private Type _uiManager;
private MethodInfo _uiManagerInstance;
private bool _shouldCheckUiManager;

// Mostly used for UI management, allows calling of main-thread methods directly from a tracking worker thread
public static readonly List<Action> MainThreadExecutionQueue = new List<Action>();
Expand All @@ -30,36 +27,32 @@ public override void OnApplicationStart()
// Load all unmanaged DLLs as soon as we can
DependencyManager.Init();

// Prepare to watch for UIManager initialization
_assemblyCSharp = AppDomain.CurrentDomain.GetAssemblies()
.FirstOrDefault(assembly => assembly.GetName().Name == "Assembly-CSharp");
_shouldCheckUiManager = typeof(MelonMod).GetMethod("VRChat_OnUiManagerInit") == null;

QuickModeMenu.LoadBundle();
MelonCoroutines.Start(CheckUiManager());
}

public override void OnApplicationQuit() => UnifiedLibManager.Teardown();

private static void UiManagerInit()
{
MelonLogger.Msg("Manager init");
UnifiedLibManager.Initialize();
Hooking.SetupHooking();
MelonCoroutines.Start(WaitForMenu());
}

public override void OnSceneWasLoaded(int level, string levelName)
{
//if (level == -1)
//QuickModeMenu.CheckIfShouldInit();

UnifiedTrackingData.LatestEyeData.ResetThresholds();
// Just waits for the user to open their quickmenu, easier than trying to work around the uninitialized cloned gameobjects
private static IEnumerator WaitForMenu()
{
var qmCanvas = GameObject.Find("UserInterface").transform.FindChild("Canvas_QuickMenu(Clone)");
yield return new WaitUntil((Func<bool>) (() => qmCanvas.gameObject.active));
QuickModeMenu.CheckIfShouldInit();
}

public override void OnSceneWasLoaded(int level, string levelName) =>
UnifiedTrackingData.LatestEyeData.ResetThresholds();

public override void OnUpdate()
{
if (Input.GetKeyDown(KeyCode.F6))
MelonCoroutines.Start(UnifiedLibManager.CheckRuntimeSanity());

if (!UnifiedLibManager.ShouldThread)
UnifiedLibManager.Update();

Expand All @@ -78,32 +71,7 @@ private IEnumerator CheckUiManager()
{
yield return new WaitUntil((Func<bool>) (() =>
VRCPlayer.field_Internal_Static_VRCPlayer_0 != null));
/*
MelonLogger.Msg("checkui");
if (_assemblyCSharp == null) return;
if (_uiManager == null)
_uiManager = _assemblyCSharp.GetType("VRCUiManager");
if (_uiManager == null) {
MelonLogger.Msg("UImanagerNull");
_shouldCheckUiManager = false;
return;
}
if (_uiManagerInstance == null)
_uiManagerInstance = _uiManager.GetMethods().First(x => x.ReturnType == _uiManager);
if (_uiManagerInstance == null)
{
MelonLogger.Msg("uinull");
_shouldCheckUiManager = false;
return;
}
if (_uiManagerInstance.Invoke(null, Array.Empty<object>()) == null)
return;

_shouldCheckUiManager = false;*/
_shouldCheckUiManager = false;
UiManagerInit();

}
Expand Down
9 changes: 5 additions & 4 deletions VRCFaceTracking/QuickMenu/QuickModeMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public static class QuickModeMenu

public static bool IsMenuShown => _menuStateController.field_Private_UIPage_0 == MainMenu.MainMenuPage;
public static MainMenu MainMenu;
private static AssetBundle _assetBundle;

public static void LoadBundle() => _assetBundle = AssetBundle.LoadFromMemory(ExtractAb());

public static void CheckIfShouldInit()
{
if (_hasInitMenu) return;
Expand All @@ -27,8 +30,6 @@ public static void CheckIfShouldInit()

private static void CreateNotificationTab()
{
var bundle = AssetBundle.LoadFromMemory(ExtractAb());

var baseParent = GameObject.Find(
"UserInterface").transform
.FindChild("Canvas_QuickMenu(Clone)/Container/Window/Page_Buttons_QM/HorizontalLayoutGroup");
Expand All @@ -41,7 +42,7 @@ private static void CreateNotificationTab()
var iconImage = _menuTab.FindChild("Icon").GetComponent<Image>();
GameObject.Destroy(_menuTab.GetComponent<NotificationTab>());
GameObject.Destroy(_menuTab.GetComponent<StyleElement>());
iconImage.sprite = LoadQmSprite(bundle);
iconImage.sprite = LoadQmSprite(_assetBundle);
iconImage.m_Color = new Color(0.4157f, 0.8902f, 0.9765f, 1);

// Main Window
Expand All @@ -52,7 +53,7 @@ private static void CreateNotificationTab()
var mainWindowParent = GameObject.Find("UserInterface").transform
.FindChild("Canvas_QuickMenu(Clone)/Container/Window/QMParent");

MainMenu = new MainMenu(mainWindowParent, bundle, _menuStateController);
MainMenu = new MainMenu(mainWindowParent, _assetBundle, _menuStateController);

// Add Streamer Mode Hide
_menuTab.gameObject.SetActive(
Expand Down
14 changes: 7 additions & 7 deletions VRCFaceTracking/UnifiedTrackingData.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MelonLoader;
using ParamLib;
using UnityEngine;
using ViveSR.anipal.Eye;
using ViveSR.anipal.Lip;
Expand Down Expand Up @@ -123,18 +121,20 @@ public struct UnifiedTrackingData
// Resets the currently used params list and regenerates it with the latest found parameters
public static void RefreshParameterList()
{
// Yeet the existing params back to zero
foreach (var current in _currentlyUsedParams)
{
current.ZeroParam();
current.ResetParam();
}

// Find the new params we actually need
_currentlyUsedParams = FindParams(ParamLib.ParamLib.GetLocalParams().Select(p => p.name).Distinct());

// Reset em to find their values
foreach (var current in _currentlyUsedParams)
current.ResetParam();
}


// Returns a list of all parameters given by name in the searchParams parameter
public static List<IParameter> FindParams(IEnumerable<string> searchParams)
private static List<IParameter> FindParams(IEnumerable<string> searchParams)
{
var eyeParams = EyeTrackingParams.ParameterList.Where(p => p.GetName().Any(searchParams.Contains));

Expand Down

0 comments on commit cfed61e

Please sign in to comment.