From b1c3c7f4104eb7117851cf6ec373a26d869071b6 Mon Sep 17 00:00:00 2001 From: SDraw Date: Sun, 7 Aug 2022 17:57:49 +0300 Subject: [PATCH] Menu integration --- ml_fpt/Main.cs | 26 ++++++-- ml_fpt/README.md | 5 +- ml_fpt/Scripts.cs | 26 ++++++++ ml_fpt/menu.js | 6 ++ ml_fpt/ml_fpt.csproj | 4 ++ ml_lme/Main.cs | 19 +++++- ml_lme/Properties/AssemblyInfo.cs | 6 +- ml_lme/README.md | 1 - ml_lme/Scripts.cs | 26 ++++++++ ml_lme/menu.js | 106 ++++++++++++++++++++++++++++++ ml_lme/ml_lme.csproj | 10 +++ 11 files changed, 223 insertions(+), 12 deletions(-) create mode 100644 ml_fpt/Scripts.cs create mode 100644 ml_fpt/menu.js create mode 100644 ml_lme/Scripts.cs create mode 100644 ml_lme/menu.js diff --git a/ml_fpt/Main.cs b/ml_fpt/Main.cs index c449fc6..584ac0b 100644 --- a/ml_fpt/Main.cs +++ b/ml_fpt/Main.cs @@ -31,14 +31,12 @@ public override void OnApplicationStart() new HarmonyLib.HarmonyMethod(typeof(FourPointTracking).GetMethod(nameof(OnAvatarClear_Postfix), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)) ); + MelonLoader.MelonCoroutines.Start(WaitForMainMenuView()); MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer()); } public override void OnUpdate() { - if(Input.GetKeyDown(KeyCode.T) && Input.GetKey(KeyCode.LeftControl) && !m_inCalibration) - PrepareCalibration(); - if(m_playerReady && m_inCalibration && (m_hipsTrackerIndex != -1)) { if(m_origVrIk != null) @@ -83,6 +81,26 @@ public override void OnUpdate() } } + System.Collections.IEnumerator WaitForMainMenuView() + { + while(ViewManager.Instance == null) + yield return null; + while(ViewManager.Instance.gameMenuView == null) + yield return null; + while(ViewManager.Instance.gameMenuView.Listener == null) + yield return null; + + ViewManager.Instance.gameMenuView.Listener.ReadyForBindings += () => + { + ViewManager.Instance.gameMenuView.View.RegisterForEvent("MelonMod_Action_FPT_Calibrate", new System.Action(this.StartCalibration)); + }; + + ViewManager.Instance.gameMenuView.Listener.FinishLoad += (_) => + { + ViewManager.Instance.gameMenuView.View.ExecuteScript(Scripts.GetEmbeddedScript("menu.js")); + }; + } + System.Collections.IEnumerator WaitForLocalPlayer() { while(PlayerSetup.Instance == null) @@ -94,7 +112,7 @@ System.Collections.IEnumerator WaitForLocalPlayer() m_playerReady = true; } - void PrepareCalibration() + void StartCalibration() { if(m_playerReady && !m_inCalibration && PlayerSetup.Instance._inVr && !PlayerSetup.Instance.fullBodyActive && PlayerSetup.Instance._animator.isHuman && !m_ikCalibrator.inFullbodyCalibration && m_indexIk.calibrated) { diff --git a/ml_fpt/README.md b/ml_fpt/README.md index cfa9edf..a2c65b0 100644 --- a/ml_fpt/README.md +++ b/ml_fpt/README.md @@ -9,13 +9,12 @@ This mod adds ability to use 4-point tracking. # Usage * Be sure that your tracker role is set to `Hips` in SteamVR * Adjust your avatar at forward direction -* Press `LCtrl-T` keyboard combination to calibrate +* Go to `Settings - Implementation - 4-Point Tracking` and press `Calibrate` button * Adjust your tracker in a similar way as in FBT calibration -* Press trigger on both hands controllers +* Press trigger on both controllers # Notes * You have to recalibrate each time you change avatar # Planned * No need for recalibration upon avatar change -* Main menu button for calibration diff --git a/ml_fpt/Scripts.cs b/ml_fpt/Scripts.cs new file mode 100644 index 0000000..fa63c6e --- /dev/null +++ b/ml_fpt/Scripts.cs @@ -0,0 +1,26 @@ +using System; +using System.IO; +using System.Reflection; + +namespace ml_fpt +{ + static class Scripts + { + public static string GetEmbeddedScript(string p_name) + { + string l_result = ""; + Assembly l_assembly = Assembly.GetExecutingAssembly(); + string l_assemblyName = l_assembly.GetName().Name; + + try + { + Stream l_libraryStream = l_assembly.GetManifestResourceStream(l_assemblyName + "." + p_name); + StreamReader l_streadReader = new StreamReader(l_libraryStream); + l_result = l_streadReader.ReadToEnd(); + } + catch(Exception) { } + + return l_result; + } + } +} diff --git a/ml_fpt/menu.js b/ml_fpt/menu.js new file mode 100644 index 0000000..7381cc1 --- /dev/null +++ b/ml_fpt/menu.js @@ -0,0 +1,6 @@ +var l_block = document.createElement("fpt_block"); +l_block.innerHTML = ` +

4-Point Tracking

+
Calibrate
+`; +document.getElementById('settings-implementation').appendChild(l_block); diff --git a/ml_fpt/ml_fpt.csproj b/ml_fpt/ml_fpt.csproj index fb0e475..c8d3c3d 100644 --- a/ml_fpt/ml_fpt.csproj +++ b/ml_fpt/ml_fpt.csproj @@ -81,6 +81,10 @@ + + + + diff --git a/ml_lme/Main.cs b/ml_lme/Main.cs index 66b4580..5474cac 100644 --- a/ml_lme/Main.cs +++ b/ml_lme/Main.cs @@ -1,4 +1,5 @@ -using ABI_RC.Core.Player; +using ABI_RC.Core.InteractionSystem; +using ABI_RC.Core.Player; using ABI_RC.Core.UI; using UnityEngine; @@ -59,6 +60,7 @@ public override void OnApplicationStart() new HarmonyLib.HarmonyMethod(typeof(LeapMotionExtension).GetMethod(nameof(OnAvatarClear_Postfix), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)) ); + MelonLoader.MelonCoroutines.Start(WaitForMainMenuView()); MelonLoader.MelonCoroutines.Start(CreateTrackingObjects()); } @@ -105,6 +107,21 @@ System.Collections.IEnumerator CreateTrackingObjects() OnSettingsHeadAttachChange(); // Includes offsets and parenting } + System.Collections.IEnumerator WaitForMainMenuView() + { + while(ViewManager.Instance == null) + yield return null; + while(ViewManager.Instance.gameMenuView == null) + yield return null; + while(ViewManager.Instance.gameMenuView.Listener == null) + yield return null; + + ViewManager.Instance.gameMenuView.Listener.FinishLoad += (_) => + { + ViewManager.Instance.gameMenuView.View.ExecuteScript(Scripts.GetEmbeddedScript("menu.js")); + }; + } + public override void OnUpdate() { if(Settings.Enabled) diff --git a/ml_lme/Properties/AssemblyInfo.cs b/ml_lme/Properties/AssemblyInfo.cs index 93960f1..277fb39 100644 --- a/ml_lme/Properties/AssemblyInfo.cs +++ b/ml_lme/Properties/AssemblyInfo.cs @@ -1,10 +1,10 @@ using System.Reflection; [assembly: AssemblyTitle("LeapMotionExtension")] -[assembly: AssemblyVersion("1.0.8")] -[assembly: AssemblyFileVersion("1.0.8")] +[assembly: AssemblyVersion("1.1.0")] +[assembly: AssemblyFileVersion("1.1.0")] -[assembly: MelonLoader.MelonInfo(typeof(ml_lme.LeapMotionExtension), "LeapMotionExtension", "1.0.8", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] +[assembly: MelonLoader.MelonInfo(typeof(ml_lme.LeapMotionExtension), "LeapMotionExtension", "1.1.0", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] [assembly: MelonLoader.MelonGame(null, "ChilloutVR")] [assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] [assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)] diff --git a/ml_lme/README.md b/ml_lme/README.md index 0809b8e..652700e 100644 --- a/ml_lme/README.md +++ b/ml_lme/README.md @@ -8,7 +8,6 @@ This mod allows you to use your Leap Motion controller for hands and fingers vis * Install [latest MelonLoader](https://github.com/LavaGang/MelonLoader) * Get [latest release DLL](../../../releases/latest): * Put `ml_lme.dll` in `Mods` folder of game -* Add code from [this gist](https://gist.github.com/SDraw/543825b39cdabc3bc4fda358bc70247a) to `\ChilloutVR_Data\StreamingAssets\Cohtml\UIResources\CVRTest\index.html` after `row-wrapper` div for `InteractionViveFaceTrackingStrength` menu item (near line 1183) # Usage ## Settings diff --git a/ml_lme/Scripts.cs b/ml_lme/Scripts.cs new file mode 100644 index 0000000..76e5314 --- /dev/null +++ b/ml_lme/Scripts.cs @@ -0,0 +1,26 @@ +using System; +using System.IO; +using System.Reflection; + +namespace ml_lme +{ + static class Scripts + { + public static string GetEmbeddedScript(string p_name) + { + string l_result = ""; + Assembly l_assembly = Assembly.GetExecutingAssembly(); + string l_assemblyName = l_assembly.GetName().Name; + + try + { + Stream l_libraryStream = l_assembly.GetManifestResourceStream(l_assemblyName + "." + p_name); + StreamReader l_streadReader = new StreamReader(l_libraryStream); + l_result = l_streadReader.ReadToEnd(); + } + catch(Exception) { } + + return l_result; + } + } +} diff --git a/ml_lme/menu.js b/ml_lme/menu.js new file mode 100644 index 0000000..32e09b4 --- /dev/null +++ b/ml_lme/menu.js @@ -0,0 +1,106 @@ +var l_block = document.createElement("lme_block"); +l_block.innerHTML = ` +

Leap Motion tracking

+
+
Enable tracking:
+
+
+
+
+ +
+
Tracking mode:
+
+
+
+
+ +
+
Desktop offset X:
+
+
+
+
+ +
+
Desktop offset Y:
+
+
+
+
+ +
+
Desktop offset Z:
+
+
+
+
+ +
+
Attach to head:
+
+
+
+
+ +
+
Head offset X:
+
+
+
+
+ +
+
Head offset Y:
+
+
+
+
+ +
+
Head offset Z:
+
+
+
+
+ +
+
Offset angle:
+
+
+
+
+ +
+
Fingers tracking only:
+
+
+
+
+ +
+
Model visibility:
+
+
+
+
+`; +document.getElementById('settings-implementation').appendChild(l_block); + +// Update toggles in new menu block +var l_toggles = l_block.querySelectorAll('.inp_toggle'); +for (var i = 0; i < l_toggles.length; i++) { + settings[settings.length] = new inp_toggle(l_toggles[i]); +} + +//Update dropdowns in new menu block +var l_dropdowns = l_block.querySelectorAll('.inp_dropdown'); +for (var i = 0; i < l_dropdowns.length; i++) { + settings[settings.length] = new inp_dropdown(l_dropdowns[i]); +} + +// Update sliders in new menu block +var l_sliders = l_block.querySelectorAll('.inp_slider'); +for (var i = 0; i < l_sliders.length; i++) { + settings[settings.length] = new inp_slider(l_sliders[i]); +} diff --git a/ml_lme/ml_lme.csproj b/ml_lme/ml_lme.csproj index 8a5724b..7ee97b2 100644 --- a/ml_lme/ml_lme.csproj +++ b/ml_lme/ml_lme.csproj @@ -45,6 +45,12 @@ C:\Games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll False + + False + + + False + C:\Games\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll False @@ -82,6 +88,7 @@ + @@ -125,6 +132,9 @@ + + + copy /y "$(TargetPath)" "C:\Games\Steam\common\ChilloutVR\Mods\