Skip to content

Commit

Permalink
Merge pull request #10 from LIV/toggle-body-visibility
Browse files Browse the repository at this point in the history
Add option to toggle gorilla body visibility
  • Loading branch information
Raicuparta authored May 18, 2022
2 parents 1722812 + 193dded commit 3448c2a
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 9 deletions.
11 changes: 10 additions & 1 deletion GorillaTagLIV.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CProgram_0020Files_0020_0028x86_0029_005CSteam_005Csteamapps_005Ccommon_005CGorilla_0020Tag_005CBepInEx_005Cplugins_005CBepinject_002DAuros_005CBepinject_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CProgram_0020Files_0020_0028x86_0029_005CSteam_005Csteamapps_005Ccommon_005CGorilla_0020Tag_005CBepInEx_005Cplugins_005CComputerInterface_005CComputerInterface_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CProgram_0020Files_0020_0028x86_0029_005CSteam_005Csteamapps_005Ccommon_005CGorilla_0020Tag_005CBepInEx_005Cplugins_005CExtenject_005CZenject_002Dusage_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CProgram_0020Files_0020_0028x86_0029_005CSteam_005Csteamapps_005Ccommon_005CGorilla_0020Tag_005CBepInEx_005Cplugins_005CExtenject_005CZenject_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CUsers_005Crai_005CRepos_005CGorillaTagLIV_005CGorillaTagLIVUnity_005CAssets_005CLIV_005CPlugins_005Cx64_005CLIV_005FBridge_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CUsers_005Crai_005CRepos_005CGorillaTagLIV_005CGorillaTagLIVUnity_005CBuild_005CGorillaTagLIVUnity_005FData_005CManaged_005CLIV_002Edll/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CUsers_005Crai_005CRepos_005CGorillaTagLIV_005CGorillaTagLIVUnity_005CBuild_005CGorillaTagLIVUnity_005FData_005CManaged_005CLIV_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;&#xD;
&lt;Assembly Path="C:\Program Files (x86)\Steam\steamapps\common\Gorilla Tag\BepInEx\plugins\Extenject\Zenject-usage.dll" /&gt;&#xD;
&lt;Assembly Path="C:\Program Files (x86)\Steam\steamapps\common\Gorilla Tag\BepInEx\plugins\Extenject\Zenject.dll" /&gt;&#xD;
&lt;Assembly Path="C:\Program Files (x86)\Steam\steamapps\common\Gorilla Tag\BepInEx\plugins\ComputerInterface\ComputerInterface.dll" /&gt;&#xD;
&lt;/AssemblyExplorer&gt;</s:String></wpf:ResourceDictionary>
16 changes: 16 additions & 0 deletions GorillaTagLIV/GorillaTagLIV.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<HintPath>$(BepInExAssemblyPath)\BepInEx.Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Bepinject">
<HintPath>$(GamePath)\BepInEx\plugins\Bepinject-Auros\Bepinject.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Cinemachine">
<HintPath>$(GameAssemblyPath)\Cinemachine.dll</HintPath>
<Private>False</Private>
Expand All @@ -44,6 +48,10 @@
<HintPath>$(GameAssemblyPath)\clipper_library.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ComputerInterface">
<HintPath>$(GamePath)\BepInEx\plugins\ComputerInterface\ComputerInterface.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="LIV, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\GorillaTagLIVUnity\Build\GorillaTagLIVUnity_Data\Managed\LIV.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -387,6 +395,14 @@
<HintPath>$(GameAssemblyPath)\websocket-sharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Zenject">
<HintPath>$(GamePath)\BepInEx\plugins\Extenject\Zenject.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Zenject-usage">
<HintPath>$(GamePath)\BepInEx\plugins\Extenject\Zenject-usage.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>

<ItemGroup>
Expand Down
89 changes: 89 additions & 0 deletions GorillaTagLIV/LivComputerView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using Bepinject;
using ComputerInterface;
using ComputerInterface.Interfaces;
using ComputerInterface.ViewLib;
using UnityEngine;
using Zenject;

namespace GorillaTagLIV
{
public class LivComputerView : ComputerView
{
private const string highlightColor = "52fc03";
private readonly UISelectionHandler selectionHandler;

public LivComputerView()
{
selectionHandler = new UISelectionHandler(EKeyboardKey.Up, EKeyboardKey.Down, EKeyboardKey.Enter);
selectionHandler.MaxIdx = 3;
selectionHandler.OnSelected += OnEntrySelected;
selectionHandler.ConfigureSelectionIndicator($"<color=#{highlightColor}>></color> ", "", " ", "");
}

private void OnEntrySelected(int index)
{
if (index == 0)
{
Plugin.Instance.ShowGorillaBody.Value = !Plugin.Instance.ShowGorillaBody.Value;
}
UpdateScreen();
}
public override void OnShow(object[] args)
{
base.OnShow(args);
UpdateScreen();
}

public override void OnKeyPressed(EKeyboardKey key)
{
if (selectionHandler.HandleKeypress(key))
{
UpdateScreen();
return;
}

switch (key)
{
case EKeyboardKey.Back:
ReturnToMainMenu();
break;
}
}

private void UpdateScreen()
{
SetText(str =>
{
str.BeginCenter();
str.MakeBar('-', SCREEN_WIDTH, 0, "ffffff10");
str.AppendClr("LIV", highlightColor).EndColor().AppendLine();
str.MakeBar('-', SCREEN_WIDTH, 0, "ffffff10");
str.EndAlign().AppendLines(1);
str.AppendLine(selectionHandler.GetIndicatedText(0, $"Show Gorilla Body: <color={(Plugin.Instance.ShowGorillaBody.Value ? $"#{highlightColor}>Yes" : "white>No")}</color>"));
str.AppendLines(2);
str.AppendClr("Press ENTER to toggle setting", "ffffff10").EndColor().AppendLine();
});
}
}

public class LivModComputerEntry : IComputerModEntry
{
public string EntryName => "LIV";

public Type EntryViewType => typeof(LivComputerView);
}

internal class LivModComputerInstaller : Installer
{
public override void InstallBindings()
{
Container.Bind<IComputerModEntry>().To<LivModComputerEntry>().AsSingle();
}

public static void Install()
{
Zenjector.Install<LivModComputerInstaller>().OnProject();
}
}
}
44 changes: 36 additions & 8 deletions GorillaTagLIV/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using BepInEx;
using BepInEx.Configuration;
using Cinemachine;
using UnityEngine;
using Utilla;
Expand All @@ -13,23 +14,41 @@ namespace GorillaTagLIV
[BepInPlugin(PluginInfo.GUID, PluginInfo.Name, PluginInfo.Version)]
public class Plugin : BaseUnityPlugin
{
public static Plugin Instance;
public ConfigEntry<bool> ShowGorillaBody;

private const string assetsDir = "/BepInEx/plugins/GorillaTagLIV/Assets/";
private Camera thirdPersonCamera;

private LIV.SDK.Unity.LIV liv;

private void Awake()
{
Instance = this;
ShowGorillaBody = Config.Bind("Settings", "ShowGorillaBody", false);
}

private void OnEnable() {
HarmonyPatches.ApplyHarmonyPatches();
Events.GameInitialized += OnGameInitialized;

var shaderBundle = LoadBundle("liv-shaders");
SDKShaders.LoadFromAssetBundle(shaderBundle);

LivModComputerInstaller.Install();

Config.SettingChanged += OnSettingChanged;
}

private void OnSettingChanged(object sender, SettingChangedEventArgs e)
{
SetUpLivLayerMask();
}

private void OnDisable() {
DestroyExistingLiv();
HarmonyPatches.RemoveHarmonyPatches();
}
Config.SettingChanged -= OnSettingChanged;
}

private void OnGameInitialized(object sender, EventArgs e)
{
Expand All @@ -56,9 +75,8 @@ private static AssetBundle LoadBundle(string assetName)
private void SetUpLiv(Camera camera, Transform parent)
{
if (!enabled) return;


Debug.Log(string.Format("Setting up LIV with camera {0}", camera.name));
Debug.Log($"Setting up LIV with camera {camera.name}");

DestroyExistingLiv();

Expand All @@ -70,15 +88,25 @@ private void SetUpLiv(Camera camera, Transform parent)
liv.stage = parent;
liv.HMDCamera = camera;
liv.fixPostEffectsAlpha = true;
liv.spectatorLayerMask = camera.cullingMask;

liv.spectatorLayerMask &= ~(1 << (int) CustomLayers.HideFromLiv);

Debug.Log(string.Format("LIV created successfully with stage {0}", parent.name));
liv.onActivate += SetUpLivLayerMask;

Debug.Log($"LIV created successfully with stage {parent.name}");

livObject.gameObject.SetActive(true);
}

private void SetUpLivLayerMask()
{
if (!liv || !liv.isActive) return;

liv.spectatorLayerMask = liv.HMDCamera.cullingMask;
if (!ShowGorillaBody.Value)
{
liv.spectatorLayerMask &= ~(1 << (int) CustomLayers.HideFromLiv);
}
}

private void SetUpThridPersonCamera()
{
var cinemachineBrain = FindObjectOfType<CinemachineBrain>();
Expand Down

0 comments on commit 3448c2a

Please sign in to comment.