Skip to content

Commit

Permalink
Menu integration
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed Aug 7, 2022
1 parent a417b41 commit b1c3c7f
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 12 deletions.
26 changes: 22 additions & 4 deletions ml_fpt/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down
5 changes: 2 additions & 3 deletions ml_fpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 26 additions & 0 deletions ml_fpt/Scripts.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
6 changes: 6 additions & 0 deletions ml_fpt/menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var l_block = document.createElement("fpt_block");
l_block.innerHTML = `
<h2>4-Point Tracking</h2>
<div class="action-btn" onclick="engine.trigger('MelonMod_Action_FPT_Calibrate');"><img src=\"gfx/recalibrate.svg\">Calibrate</div>
`;
document.getElementById('settings-implementation').appendChild(l_block);
4 changes: 4 additions & 0 deletions ml_fpt/ml_fpt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Scripts.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="menu.js" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
Expand Down
19 changes: 18 additions & 1 deletion ml_lme/Main.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions ml_lme/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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)]
1 change: 0 additions & 1 deletion ml_lme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<GameFolder>\ChilloutVR_Data\StreamingAssets\Cohtml\UIResources\CVRTest\index.html` after `row-wrapper` div for `InteractionViveFaceTrackingStrength` menu item (near line 1183)

# Usage
## Settings
Expand Down
26 changes: 26 additions & 0 deletions ml_lme/Scripts.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
106 changes: 106 additions & 0 deletions ml_lme/menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
var l_block = document.createElement("lme_block");
l_block.innerHTML = `
<h2>Leap Motion tracking</h2>
<div class ="row-wrapper">
<div class ="option-caption">Enable tracking: </div>
<div class ="option-input">
<div id="InteractionLeapMotionTracking" class ="inp_toggle" data-current="false" data-saveOnChange="true"></div>
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">Tracking mode: </div>
<div class ="option-input">
<div id="InteractionLeapMotionTrackingMode" class ="inp_dropdown" data-options="0:Screentop,1:Desktop,2:HMD" data-current="1" data-saveOnChange="true"></div>
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">Desktop offset X: </div>
<div class ="option-input">
<div id="InteractionLeapMotionTrackingDesktopX" class ="inp_slider" data-min="-100" data-max="100" data-current="0" data-saveOnChange="true" data-continuousUpdate="true"></div>
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">Desktop offset Y: </div>
<div class ="option-input">
<div id="InteractionLeapMotionTrackingDesktopY" class ="inp_slider" data-min="-100" data-max="100" data-current="-45" data-saveOnChange="true" data-continuousUpdate="true"></div>
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">Desktop offset Z: </div>
<div class ="option-input">
<div id="InteractionLeapMotionTrackingDesktopZ" class ="inp_slider" data-min="-100" data-max="100" data-current="30" data-saveOnChange="true" data-continuousUpdate="true"></div>
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">Attach to head: </div>
<div class ="option-input">
<div id="InteractionLeapMotionTrackingHead" class ="inp_toggle" data-current="false" data-saveOnChange="true"></div>
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">Head offset X: </div>
<div class ="option-input">
<div id="InteractionLeapMotionTrackingHeadX" class ="inp_slider" data-min="-100" data-max="100" data-current="0" data-saveOnChange="true" data-continuousUpdate="true"></div>
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">Head offset Y: </div>
<div class ="option-input">
<div id="InteractionLeapMotionTrackingHeadY" class ="inp_slider" data-min="-100" data-max="100" data-current="-30" data-saveOnChange="true" data-continuousUpdate="true"></div>
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">Head offset Z: </div>
<div class ="option-input">
<div id="InteractionLeapMotionTrackingHeadZ" class ="inp_slider" data-min="-100" data-max="100" data-current="15" data-saveOnChange="true" data-continuousUpdate="true"></div>
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">Offset angle: </div>
<div class ="option-input">
<div id="InteractionLeapMotionTrackingAngle" class ="inp_slider" data-min="-180" data-max="180" data-current="0" data-saveOnChange="true" data-continuousUpdate="true"></div>
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">Fingers tracking only: </div>
<div class ="option-input">
<div id="InteractionLeapMotionTrackingFingersOnly" class ="inp_toggle" data-current="false" data-saveOnChange="true"></div>
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">Model visibility: </div>
<div class ="option-input">
<div id="InteractionLeapMotionTrackingModel" class ="inp_toggle" data-current="false" data-saveOnChange="true"></div>
</div>
</div>
`;
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]);
}
10 changes: 10 additions & 0 deletions ml_lme/ml_lme.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
<HintPath>C:\Games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="cohtml.Net">
<Private>False</Private>
</Reference>
<Reference Include="Cohtml.Runtime">
<Private>False</Private>
</Reference>
<Reference Include="MelonLoader">
<HintPath>C:\Games\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -82,6 +88,7 @@
<Compile Include="LeapTracked.cs" />
<Compile Include="Main.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Scripts.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Utils.cs" />
<Compile Include="vendor\LeapCSharp\Arm.cs" />
Expand Down Expand Up @@ -125,6 +132,9 @@
<ItemGroup>
<EmbeddedResource Include="resources\leapmotion_controller.asset" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="menu.js" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /y "$(TargetPath)" "C:\Games\Steam\common\ChilloutVR\Mods\</PostBuildEvent>
Expand Down

0 comments on commit b1c3c7f

Please sign in to comment.