Skip to content

Commit

Permalink
Rays layer fix
Browse files Browse the repository at this point in the history
Desktop tracking scale fix
More notifications
  • Loading branch information
SDraw committed Jan 29, 2023
1 parent fbad3fd commit 6bc448d
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Merged set of MelonLoader mods for ChilloutVR.
| Avatar Motion Tweaker | ml_amt | 1.2.2 | Yes | Working |
| Desktop Head Tracking | ml_dht | 1.1.1 | Yes | Working |
| Desktop Reticle Switch | ml_drs | 1.0.0 | Yes | Working |
| Extended Game Notifications | ml_egn | 1.0.0 | Yes | Working
| Extended Game Notifications | ml_egn | 1.0.1 | Yes, update review | Working
| Four Point Tracking | ml_fpt | 1.0.9 | Retired | Deprecated | In-game feature since 2022r170 update
| Leap Motion Extension | ml_lme | 1.3.0 | Yes, update review | Working |
| Pickup Arm Movement | ml_pam | 1.0.0 | Yes | Working |
Expand Down
57 changes: 57 additions & 0 deletions ml_egn/Main.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ABI_RC.Core.EventSystem;
using ABI_RC.Core.InteractionSystem;
using ABI_RC.Core.IO;
using ABI_RC.Core.Networking;
using ABI_RC.Core.Util;
using DarkRift.Client;
Expand Down Expand Up @@ -28,6 +29,24 @@ public override void OnInitializeMelon()
null,
new HarmonyLib.HarmonyMethod(typeof(ExtendedGameNotifications).GetMethod(nameof(OnGameNetworkConnectionClosed), BindingFlags.NonPublic | BindingFlags.Static))
);

HarmonyInstance.Patch(
typeof(CVRCamImageSaver).GetMethod(nameof(CVRCamImageSaver.SavePicture), BindingFlags.Public | BindingFlags.Static),
null,
new HarmonyLib.HarmonyMethod(typeof(ExtendedGameNotifications).GetMethod(nameof(OnPictureSave), BindingFlags.NonPublic | BindingFlags.Static))
);

HarmonyInstance.Patch(
typeof(CVRSyncHelper).GetMethod(nameof(CVRSyncHelper.DeleteAllProps), BindingFlags.Public | BindingFlags.Static),
null,
new HarmonyLib.HarmonyMethod(typeof(ExtendedGameNotifications).GetMethod(nameof(OnAllPropsDelete), BindingFlags.NonPublic | BindingFlags.Static))
);

HarmonyInstance.Patch(
typeof(CVRSyncHelper).GetMethod(nameof(CVRSyncHelper.DeleteMyProps), BindingFlags.Public | BindingFlags.Static),
null,
new HarmonyLib.HarmonyMethod(typeof(ExtendedGameNotifications).GetMethod(nameof(OnOwnPropsDelete), BindingFlags.NonPublic | BindingFlags.Static))
);
}

static void OnLocalAvatarLoad()
Expand Down Expand Up @@ -82,5 +101,43 @@ static void OnGameNetworkConnectionClosed(DisconnectedEventArgs __1)
MelonLoader.MelonLogger.Error(e);
}
}

static void OnPictureSave()
{
try
{
Utils.ShowHUDNotification("(Local) Client", "Screenshot saved");
}
catch(System.Exception e)
{
MelonLoader.MelonLogger.Error(e);
}
}

static void OnAllPropsDelete()
{
try
{
if(Utils.IsMenuOpened())
Utils.ShowMenuNotification("Props are removed");
}
catch(System.Exception e)
{
MelonLoader.MelonLogger.Error(e);
}
}

static void OnOwnPropsDelete()
{
try
{
if(Utils.IsMenuOpened())
Utils.ShowMenuNotification("Own props are removed");
}
catch(System.Exception e)
{
MelonLoader.MelonLogger.Error(e);
}
}
}
}
6 changes: 3 additions & 3 deletions ml_egn/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Reflection;

[assembly: AssemblyTitle("ExtendedGameNotifications")]
[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyVersion("1.0.1")]
[assembly: AssemblyFileVersion("1.0.1")]

[assembly: MelonLoader.MelonInfo(typeof(ml_egn.ExtendedGameNotifications), "ExtendedGameNotifications", "1.0.0", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
[assembly: MelonLoader.MelonInfo(typeof(ml_egn.ExtendedGameNotifications), "ExtendedGameNotifications", "1.0.1", "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)]
6 changes: 5 additions & 1 deletion ml_egn/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Extended Game Notifications
This mod shows main menu notifications and HUD popups upon avatar changing, prop spawning and server connection loss.
This mod shows main menu notifications and HUD popups upon:
* Avatar changing
* Prop spawning/deletion
* Server connection loss
* Screenshot saving
Basically, merged previous `Avatar Change Info` and `Server Connection Info` mods in one.

# Installation
Expand Down
4 changes: 3 additions & 1 deletion ml_lme/LeapInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LeapInput : CVRInputModule
base.Start();

m_inputManager = CVRInputManager.Instance; // _inputManager is stripped out, cool beans
m_steamVrModule = this.GetComponent<InputModuleSteamVR>();
m_steamVrModule = m_inputManager.GetComponent<InputModuleSteamVR>();
m_inVR = Utils.IsInVR();

m_handRayLeft = LeapTracking.GetInstance().GetLeftHand().gameObject.AddComponent<ControllerRay>();
Expand Down Expand Up @@ -91,7 +91,9 @@ IEnumerator WaitForMaterial()
yield return null;

m_lineLeft.material = PlayerSetup.Instance.leftRay.lineRenderer.material;
m_lineLeft.gameObject.layer = PlayerSetup.Instance.leftRay.gameObject.layer;
m_lineRight.material = PlayerSetup.Instance.leftRay.lineRenderer.material;
m_lineRight.gameObject.layer = PlayerSetup.Instance.leftRay.gameObject.layer;
}

void OnDestroy()
Expand Down
8 changes: 8 additions & 0 deletions ml_lme/LeapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ void OnTrackingModeChange(Settings.LeapTrackingMode p_mode)
// Game events
internal void OnAvatarClear()
{
if(m_leapTracking != null)
m_leapTracking.OnAvatarClear();
if(m_leapTracked != null)
m_leapTracked.OnAvatarClear();
}
Expand All @@ -184,6 +186,12 @@ internal void OnRayScale(float p_scale)
m_leapInput.OnRayScale(p_scale);
}

internal void OnPlayspaceScale(float p_relation)
{
if(m_leapTracking != null)
m_leapTracking.OnPlayspaceScale(p_relation);
}

// Arbitrary
void UpdateDeviceTrackingMode()
{
Expand Down
61 changes: 22 additions & 39 deletions ml_lme/LeapTracking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class LeapTracking : MonoBehaviour
GameObject m_leapElbowRight = null;
GameObject m_leapControllerModel = null;

float m_scaleRelation = 1f;

public static LeapTracking GetInstance() => ms_instance;

void Start()
Expand Down Expand Up @@ -75,9 +77,7 @@ IEnumerator WaitForLocalPlayer()
while(PlayerSetup.Instance == null)
yield return null;

OnDesktopOffsetChange(Settings.DesktopOffset);
OnHeadAttachChange(Settings.HeadAttach);
OnHeadOffsetChange(Settings.HeadOffset);
}

void OnDestroy()
Expand Down Expand Up @@ -130,12 +130,7 @@ void Update()
void OnDesktopOffsetChange(Vector3 p_offset)
{
if(!Settings.HeadAttach)
{
if(!m_inVR)
this.transform.localPosition = p_offset * PlayerSetup.Instance.vrCameraRig.transform.localScale.x;
else
this.transform.localPosition = p_offset;
}
this.transform.localPosition = p_offset * (!m_inVR ? m_scaleRelation : 1f);
}

void OnModelVisibilityChange(bool p_state)
Expand Down Expand Up @@ -166,56 +161,44 @@ void OnRootAngleChange(Vector3 p_angle)

void OnHeadAttachChange(bool p_state)
{
if(p_state)
if(!m_inVR)
{
if(!m_inVR)
{
this.transform.parent = PlayerSetup.Instance.desktopCamera.transform;
this.transform.localPosition = Settings.HeadOffset * PlayerSetup.Instance.vrCameraRig.transform.localScale.x;
this.transform.localScale = PlayerSetup.Instance.vrCameraRig.transform.localScale;
}
else
{
this.transform.parent = PlayerSetup.Instance.vrCamera.transform;
this.transform.localPosition = Settings.HeadOffset;
this.transform.localScale = Vector3.one;
}
this.transform.parent = (p_state ? PlayerSetup.Instance.desktopCamera.transform : PlayerSetup.Instance.desktopCameraRig.transform);
this.transform.localPosition = (p_state ? Settings.HeadOffset : Settings.DesktopOffset) * m_scaleRelation;
}
else
{
if(!m_inVR)
{
this.transform.parent = PlayerSetup.Instance.desktopCameraRig.transform;
this.transform.localPosition = Settings.DesktopOffset * PlayerSetup.Instance.vrCameraRig.transform.localScale.x;
this.transform.localScale = PlayerSetup.Instance.vrCameraRig.transform.localScale;
}
else
{
this.transform.parent = PlayerSetup.Instance.vrCameraRig.transform;
this.transform.localPosition = Settings.DesktopOffset;
this.transform.localScale = Vector3.one;
}
this.transform.parent = (p_state ? PlayerSetup.Instance.vrCamera.transform : PlayerSetup.Instance.vrCameraRig.transform);
this.transform.localPosition = (p_state ? Settings.HeadOffset : Settings.DesktopOffset);
}

this.transform.localScale = Vector3.one * (!m_inVR ? m_scaleRelation : 1f);
this.transform.localRotation = Quaternion.Euler(Settings.RootAngle);
}

void OnHeadOffsetChange(Vector3 p_offset)
{
if(Settings.HeadAttach)
{
if(!m_inVR)
this.transform.localPosition = p_offset * PlayerSetup.Instance.vrCameraRig.transform.localScale.x;
else
this.transform.localPosition = p_offset;
}
this.transform.localPosition = p_offset * (!m_inVR ? m_scaleRelation : 1f);
}

// Game events
internal void OnAvatarClear()
{
m_scaleRelation = 1f;
OnHeadAttachChange(Settings.HeadAttach);
}

internal void OnAvatarSetup()
{
m_inVR = Utils.IsInVR();
OnHeadAttachChange(Settings.HeadAttach);
}

internal void OnPlayspaceScale(float p_relation)
{
m_scaleRelation = p_relation;
OnHeadAttachChange(Settings.HeadAttach);
}
}
}
19 changes: 19 additions & 0 deletions ml_lme/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public override void OnInitializeMelon()
null,
new HarmonyLib.HarmonyMethod(typeof(LeapMotionExtension).GetMethod(nameof(OnRayScale_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
);
HarmonyInstance.Patch(
typeof(PlayerSetup).GetMethod("SetPlaySpaceScale", BindingFlags.NonPublic | BindingFlags.Instance),
null,
new HarmonyLib.HarmonyMethod(typeof(LeapMotionExtension).GetMethod(nameof(OnPlayspaceScale_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
);

MelonLoader.MelonCoroutines.Start(WaitForRootLogic());
}
Expand Down Expand Up @@ -117,5 +122,19 @@ void OnRayScale(float p_scale)
MelonLoader.MelonLogger.Error(e);
}
}

static void OnPlayspaceScale_Postfix(float ____avatarScaleRelation) => ms_instance?.OnPlayspaceScale(____avatarScaleRelation);
void OnPlayspaceScale(float p_relation)
{
try
{
if(m_leapManager != null)
m_leapManager.OnPlayspaceScale(p_relation);
}
catch(System.Exception e)
{
MelonLoader.MelonLogger.Error(e);
}
}
}
}

0 comments on commit 6bc448d

Please sign in to comment.