diff --git a/ml_amt/GameEvents.cs b/ml_amt/GameEvents.cs index fcb5bcd..00cb0f8 100644 --- a/ml_amt/GameEvents.cs +++ b/ml_amt/GameEvents.cs @@ -25,13 +25,13 @@ namespace ml_amt try { p_instance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar)), + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar), BindingFlags.Instance | BindingFlags.Public), null, - new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnAvatarClear_Postfix), BindingFlags.NonPublic | BindingFlags.Static)) + new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnAvatarClear_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); p_instance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar)), + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar), BindingFlags.Instance | BindingFlags.Public), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnSetupAvatar_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); @@ -43,7 +43,7 @@ namespace ml_amt ); p_instance.Patch( - typeof(PlayerSetup).GetMethod("SetPlaySpaceScale", BindingFlags.NonPublic | BindingFlags.Instance), + typeof(PlayerSetup).GetMethod("SetPlaySpaceScale", BindingFlags.Instance | BindingFlags.NonPublic), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnPlayspaceScale_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); diff --git a/ml_amt/Properties/AssemblyInfo.cs b/ml_amt/Properties/AssemblyInfo.cs index e1a8580..8b4257e 100644 --- a/ml_amt/Properties/AssemblyInfo.cs +++ b/ml_amt/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.4.2", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] +[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.5.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_amt/ResourcesHandler.cs b/ml_amt/ResourcesHandler.cs index d929fc4..214cead 100644 --- a/ml_amt/ResourcesHandler.cs +++ b/ml_amt/ResourcesHandler.cs @@ -19,7 +19,10 @@ namespace ml_amt StreamReader l_streadReader = new StreamReader(l_libraryStream); l_result = l_streadReader.ReadToEnd(); } - catch(Exception) { } + catch(Exception e) + { + MelonLoader.MelonLogger.Error(e); + } return l_result; } diff --git a/ml_amt/Utils.cs b/ml_amt/Utils.cs index 0b86b15..79b1130 100644 --- a/ml_amt/Utils.cs +++ b/ml_amt/Utils.cs @@ -11,14 +11,14 @@ namespace ml_amt { static class Utils { - static readonly FieldInfo ms_hasToes = typeof(IKSolverVR).GetField("hasToes", BindingFlags.NonPublic | BindingFlags.Instance); - static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.NonPublic | BindingFlags.Instance); + static readonly FieldInfo ms_hasToes = typeof(IKSolverVR).GetField("hasToes", BindingFlags.Instance | BindingFlags.NonPublic); + static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.Instance | BindingFlags.NonPublic); public static bool IsInVR() => ((MetaPort.Instance != null) && MetaPort.Instance.isUsingVr); - public static bool HasToes(this IKSolverVR p_instance) => (bool)ms_hasToes.GetValue(p_instance); + public static bool HasToes(this IKSolverVR p_instance) => (bool)ms_hasToes?.GetValue(p_instance); - public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => ((cohtml.Net.View)ms_view.GetValue(p_instance)).ExecuteScript(p_script); + public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => (ms_view?.GetValue(p_instance) as cohtml.Net.View)?.ExecuteScript(p_script); public static void SetAvatarTPose() { diff --git a/ml_asl/Main.cs b/ml_asl/Main.cs index 9b6dc98..4ff6362 100644 --- a/ml_asl/Main.cs +++ b/ml_asl/Main.cs @@ -13,9 +13,9 @@ namespace ml_asl Settings.Init(); HarmonyInstance.Patch( - typeof(PlayerSetup).GetMethod("UpdatePlayerAvatarMovementData", BindingFlags.NonPublic | BindingFlags.Instance), + typeof(PlayerSetup).GetMethod("UpdatePlayerAvatarMovementData", BindingFlags.Instance | BindingFlags.NonPublic ), null, - new HarmonyLib.HarmonyMethod(typeof(AvatarSyncedLook).GetMethod(nameof(OnPlayerAvatarMovementDataUpdate_Postfix), BindingFlags.NonPublic | BindingFlags.Static)) + new HarmonyLib.HarmonyMethod(typeof(AvatarSyncedLook).GetMethod(nameof(OnPlayerAvatarMovementDataUpdate_Postfix), BindingFlags.Static | BindingFlags.NonPublic )) ); } diff --git a/ml_asl/ResourcesHandler.cs b/ml_asl/ResourcesHandler.cs index 03fba8c..e73c290 100644 --- a/ml_asl/ResourcesHandler.cs +++ b/ml_asl/ResourcesHandler.cs @@ -19,7 +19,10 @@ namespace ml_asl StreamReader l_streadReader = new StreamReader(l_libraryStream); l_result = l_streadReader.ReadToEnd(); } - catch(Exception) { } + catch(Exception e) + { + MelonLoader.MelonLogger.Error(e); + } return l_result; } diff --git a/ml_asl/Utils.cs b/ml_asl/Utils.cs index 7b7bcdd..f858218 100644 --- a/ml_asl/Utils.cs +++ b/ml_asl/Utils.cs @@ -6,9 +6,9 @@ namespace ml_asl { static class Utils { - static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.NonPublic | BindingFlags.Instance); + static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.Instance | BindingFlags.NonPublic); - public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => ((cohtml.Net.View)ms_view.GetValue(p_instance)).ExecuteScript(p_script); + public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => (ms_view?.GetValue(p_instance) as cohtml.Net.View)?.ExecuteScript(p_script); // Extensions public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false) diff --git a/ml_bft/GameEvents.cs b/ml_bft/GameEvents.cs index 9a5c342..58ea46a 100644 --- a/ml_bft/GameEvents.cs +++ b/ml_bft/GameEvents.cs @@ -35,13 +35,13 @@ namespace ml_bft try { p_instance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar)), + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar), BindingFlags.Instance | BindingFlags.Public), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnSetupAvatar_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); p_instance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar)), + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar), BindingFlags.Instance | BindingFlags.Public), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnAvatarClear_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); @@ -53,15 +53,15 @@ namespace ml_bft ); p_instance.Patch( - typeof(CVRInputManager).GetMethod("UpdateInput", BindingFlags.NonPublic | BindingFlags.Instance), + typeof(CVRInputManager).GetMethod("UpdateInput", BindingFlags.Instance | BindingFlags.NonPublic), null, - new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnInputUpdate_Postfix), BindingFlags.NonPublic | BindingFlags.Static)) + new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnInputUpdate_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); p_instance.Patch( - typeof(IKSystem).GetMethod("LateUpdate", BindingFlags.NonPublic | BindingFlags.Instance), + typeof(IKSystem).GetMethod("LateUpdate", BindingFlags.Instance | BindingFlags.NonPublic), null, - new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnIKSystemLateUpdate_Postfix), BindingFlags.NonPublic | BindingFlags.Static)) + new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnIKSystemLateUpdate_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); } catch(Exception e) diff --git a/ml_bft/HandHandlerVR.cs b/ml_bft/HandHandlerVR.cs index 055f30b..ec01650 100644 --- a/ml_bft/HandHandlerVR.cs +++ b/ml_bft/HandHandlerVR.cs @@ -9,7 +9,7 @@ namespace ml_bft // 31 bones in each hand, get index at Valve.VR.SteamVR_Skeleton_JointIndexes or SteamVR_Skeleton_JointIndexEnum const int c_fingerBonesCount = (int)SteamVR_Skeleton_JointIndexEnum.pinkyAux + 1; - bool m_left = false; + readonly bool m_left = false; readonly List m_bones = null; readonly List m_localRotations = null; Transform m_prefabRoot = null; diff --git a/ml_bft/ResourcesHandler.cs b/ml_bft/ResourcesHandler.cs index 210bb71..82c08c2 100644 --- a/ml_bft/ResourcesHandler.cs +++ b/ml_bft/ResourcesHandler.cs @@ -19,7 +19,10 @@ namespace ml_bft StreamReader l_streadReader = new StreamReader(l_libraryStream); l_result = l_streadReader.ReadToEnd(); } - catch(Exception) { } + catch(Exception e) + { + MelonLoader.MelonLogger.Error(e); + } return l_result; } diff --git a/ml_bft/Utils.cs b/ml_bft/Utils.cs index c913803..688febf 100644 --- a/ml_bft/Utils.cs +++ b/ml_bft/Utils.cs @@ -10,9 +10,9 @@ namespace ml_bft { static class Utils { - static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.NonPublic | BindingFlags.Instance); + static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.Instance | BindingFlags.NonPublic); - public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => ((cohtml.Net.View)ms_view.GetValue(p_instance)).ExecuteScript(p_script); + public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => (ms_view?.GetValue(p_instance) as cohtml.Net.View)?.ExecuteScript(p_script); public static bool IsInVR() => ((MetaPort.Instance != null) && MetaPort.Instance.isUsingVr); diff --git a/ml_dht/GameEvents.cs b/ml_dht/GameEvents.cs index d5a469b..56e8043 100644 --- a/ml_dht/GameEvents.cs +++ b/ml_dht/GameEvents.cs @@ -48,13 +48,13 @@ namespace ml_dht try { p_instance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar)), + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar), BindingFlags.Instance | BindingFlags.Public), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnAvatarClear_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); p_instance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar)), + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar), BindingFlags.Instance | BindingFlags.Public), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnSetupAvatar_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); diff --git a/ml_dht/HeadTracked.cs b/ml_dht/HeadTracked.cs index 03d25b1..0f6cf0f 100644 --- a/ml_dht/HeadTracked.cs +++ b/ml_dht/HeadTracked.cs @@ -52,9 +52,9 @@ namespace ml_dht return; } - DontDestroyOnLoad(this); - ms_instance = this; + DontDestroyOnLoad(this); + m_dataParser = new DataParser(); } diff --git a/ml_dht/MemoryMapReader.cs b/ml_dht/MemoryMapReader.cs index eb5f71c..7949072 100644 --- a/ml_dht/MemoryMapReader.cs +++ b/ml_dht/MemoryMapReader.cs @@ -32,7 +32,10 @@ namespace ml_dht m_stream.Read(p_data, 0, (p_data.Length > m_dataSize) ? m_dataSize : p_data.Length); l_result = true; } - catch(System.Exception) { } + catch(System.Exception e) + { + MelonLoader.MelonLogger.Error(e); + } } return l_result; } diff --git a/ml_dht/ResourcesHandler.cs b/ml_dht/ResourcesHandler.cs index d0d22ac..3c9b578 100644 --- a/ml_dht/ResourcesHandler.cs +++ b/ml_dht/ResourcesHandler.cs @@ -19,7 +19,10 @@ namespace ml_dht StreamReader l_streadReader = new StreamReader(l_libraryStream); l_result = l_streadReader.ReadToEnd(); } - catch(Exception) { } + catch(Exception e) + { + MelonLoader.MelonLogger.Error(e); + } return l_result; } diff --git a/ml_dht/Utils.cs b/ml_dht/Utils.cs index e561038..ec35c6c 100644 --- a/ml_dht/Utils.cs +++ b/ml_dht/Utils.cs @@ -11,12 +11,12 @@ namespace ml_dht static class Utils { static readonly object[] ms_emptyArray = new object[0]; - static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.NonPublic | BindingFlags.Instance); - static readonly MethodInfo ms_updateShapesLocal = typeof(CVRFaceTracking).GetMethod("UpdateShapesLocal", BindingFlags.NonPublic | BindingFlags.Instance); + static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.Instance | BindingFlags.NonPublic); + static readonly MethodInfo ms_updateShapesLocal = typeof(CVRFaceTracking).GetMethod("UpdateShapesLocal", BindingFlags.Instance | BindingFlags.NonPublic); public static bool IsInVR() => ((MetaPort.Instance != null) && MetaPort.Instance.isUsingVr); - public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => ((cohtml.Net.View)ms_view.GetValue(p_instance)).ExecuteScript(p_script); + public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => (ms_view?.GetValue(p_instance) as cohtml.Net.View)?.ExecuteScript(p_script); public static void UpdateShapesLocal_Private(this CVRFaceTracking p_instance) => ms_updateShapesLocal?.Invoke(p_instance, ms_emptyArray); diff --git a/ml_lme/GameEvents.cs b/ml_lme/GameEvents.cs index bb2a6e8..91237e3 100644 --- a/ml_lme/GameEvents.cs +++ b/ml_lme/GameEvents.cs @@ -35,13 +35,13 @@ namespace ml_lme try { p_instance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar)), + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar), BindingFlags.Instance | BindingFlags.Public), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnAvatarClear_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); p_instance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar)), + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar), BindingFlags.Instance | BindingFlags.Public), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnSetupAvatar_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); @@ -53,19 +53,19 @@ namespace ml_lme ); p_instance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetControllerRayScale)), + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetControllerRayScale), BindingFlags.Instance | BindingFlags.Public), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnRayScale_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); p_instance.Patch( - typeof(PlayerSetup).GetMethod("SetPlaySpaceScale", BindingFlags.NonPublic | BindingFlags.Instance), + typeof(PlayerSetup).GetMethod("SetPlaySpaceScale", BindingFlags.Instance | BindingFlags.NonPublic), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnPlayspaceScale_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); p_instance.Patch( - typeof(CVRPickupObject).GetMethod(nameof(CVRPickupObject.Grab), BindingFlags.Public | BindingFlags.Instance), + typeof(CVRPickupObject).GetMethod(nameof(CVRPickupObject.Grab), BindingFlags.Instance | BindingFlags.Public), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnPickupGrab_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); diff --git a/ml_lme/Main.cs b/ml_lme/Main.cs index c4eeebc..44ad503 100644 --- a/ml_lme/Main.cs +++ b/ml_lme/Main.cs @@ -18,13 +18,6 @@ namespace ml_lme MelonLoader.MelonCoroutines.Start(WaitForRootLogic()); } - public override void OnDeinitializeMelon() - { - if(m_leapManager != null) - Object.Destroy(m_leapManager); - m_leapManager = null; - } - IEnumerator WaitForRootLogic() { while(ABI_RC.Core.RootLogic.Instance == null) @@ -32,5 +25,12 @@ namespace ml_lme m_leapManager = new GameObject("[LeapMotionExtension]").AddComponent(); } + + public override void OnDeinitializeMelon() + { + if(m_leapManager != null) + Object.Destroy(m_leapManager); + m_leapManager = null; + } } } diff --git a/ml_lme/ResourcesHandler.cs b/ml_lme/ResourcesHandler.cs index 1804d96..ad24e11 100644 --- a/ml_lme/ResourcesHandler.cs +++ b/ml_lme/ResourcesHandler.cs @@ -19,7 +19,10 @@ namespace ml_lme StreamReader l_streadReader = new StreamReader(l_libraryStream); l_result = l_streadReader.ReadToEnd(); } - catch(Exception) { } + catch(Exception e) + { + MelonLoader.MelonLogger.Error(e); + } return l_result; } diff --git a/ml_lme/Utils.cs b/ml_lme/Utils.cs index f920f88..55b0b8b 100644 --- a/ml_lme/Utils.cs +++ b/ml_lme/Utils.cs @@ -12,9 +12,9 @@ namespace ml_lme { static class Utils { - static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.NonPublic | BindingFlags.Instance); - static readonly FieldInfo ms_vrActive = typeof(ControllerRay).GetField("vrActive", BindingFlags.NonPublic | BindingFlags.Instance); - static readonly FieldInfo ms_inputModules = typeof(CVRInputManager).GetField("_inputModules", BindingFlags.NonPublic | BindingFlags.Instance); + static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.Instance | BindingFlags.NonPublic); + static readonly FieldInfo ms_vrActive = typeof(ControllerRay).GetField("vrActive", BindingFlags.Instance | BindingFlags.NonPublic); + static readonly FieldInfo ms_inputModules = typeof(CVRInputManager).GetField("_inputModules", BindingFlags.Instance | BindingFlags.NonPublic); public static bool IsInVR() => ((MetaPort.Instance != null) && MetaPort.Instance.isUsingVr); public static bool AreKnucklesInUse() => ((CVRInputManager.Instance._leftController == ABI_RC.Systems.InputManagement.XR.eXRControllerType.Index) || (CVRInputManager.Instance._rightController == ABI_RC.Systems.InputManagement.XR.eXRControllerType.Index)); @@ -41,17 +41,20 @@ namespace ml_lme public static void SetModuleAsLast(this CVRInputManager p_instance, CVRInputModule p_module) { - List l_modules = ms_inputModules.GetValue(p_instance) as List; - int l_lastIndex = l_modules.Count - 1; - int l_index = l_modules.FindIndex(p => p == p_module); - if((l_index != -1) && (l_index != l_lastIndex)) + List l_modules = ms_inputModules?.GetValue(p_instance) as List; + if(l_modules != null) { - l_modules[l_index] = l_modules[l_lastIndex]; - l_modules[l_lastIndex] = p_module; + int l_lastIndex = l_modules.Count - 1; + int l_index = l_modules.FindIndex(p => p == p_module); + if((l_index != -1) && (l_index != l_lastIndex)) + { + l_modules[l_index] = l_modules[l_lastIndex]; + l_modules[l_lastIndex] = p_module; + } } } - public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => ((cohtml.Net.View)ms_view.GetValue(p_instance)).ExecuteScript(p_script); + public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => (ms_view?.GetValue(p_instance) as cohtml.Net.View)?.ExecuteScript(p_script); public static void SetAvatarTPose() { @@ -69,7 +72,7 @@ namespace ml_lme public static float InverseLerpUnclamped(float a, float b, float value) { - if(a != b) + if(!Mathf.Approximately(a, b)) return (value - a) / (b - a); return 0f; } diff --git a/ml_pam/GameEvents.cs b/ml_pam/GameEvents.cs index 8d53289..6e77919 100644 --- a/ml_pam/GameEvents.cs +++ b/ml_pam/GameEvents.cs @@ -43,13 +43,13 @@ namespace ml_pam try { p_instance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar)), + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar), BindingFlags.Instance | BindingFlags.Public), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnAvatarClear_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); p_instance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar)), + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar), BindingFlags.Instance | BindingFlags.Public), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnSetupAvatar_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); @@ -61,7 +61,7 @@ namespace ml_pam ); p_instance.Patch( - typeof(PlayerSetup).GetMethod("SetupIKScaling", BindingFlags.NonPublic | BindingFlags.Instance), + typeof(PlayerSetup).GetMethod("SetupIKScaling", BindingFlags.Instance | BindingFlags.NonPublic), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnSetupIKScaling_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); diff --git a/ml_pam/ResourcesHandler.cs b/ml_pam/ResourcesHandler.cs index ce6d86f..874c49f 100644 --- a/ml_pam/ResourcesHandler.cs +++ b/ml_pam/ResourcesHandler.cs @@ -19,7 +19,10 @@ namespace ml_pam StreamReader l_streadReader = new StreamReader(l_libraryStream); l_result = l_streadReader.ReadToEnd(); } - catch(Exception) { } + catch(Exception e) + { + MelonLoader.MelonLogger.Error(e); + } return l_result; } diff --git a/ml_pam/Utils.cs b/ml_pam/Utils.cs index 39b9b3c..a01906b 100644 --- a/ml_pam/Utils.cs +++ b/ml_pam/Utils.cs @@ -9,11 +9,11 @@ namespace ml_pam { static class Utils { - static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.NonPublic | BindingFlags.Instance); + static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.Instance | BindingFlags.NonPublic); public static bool IsInVR() => ((MetaPort.Instance != null) && MetaPort.Instance.isUsingVr); - public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => ((cohtml.Net.View)ms_view.GetValue(p_instance)).ExecuteScript(p_script); + public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => (ms_view?.GetValue(p_instance) as cohtml.Net.View)?.ExecuteScript(p_script); public static void SetAvatarTPose() { diff --git a/ml_pin/Main.cs b/ml_pin/Main.cs index 26d93ba..c4c0462 100644 --- a/ml_pin/Main.cs +++ b/ml_pin/Main.cs @@ -20,14 +20,6 @@ namespace ml_pin MelonLoader.MelonCoroutines.Start(WaitForInstances()); } - public override void OnDeinitializeMelon() - { - m_soundManager = null; - - CVRGameEventSystem.Player.OnJoinEntity.RemoveListener(OnPlayerJoin); - CVRGameEventSystem.Player.OnLeaveEntity.RemoveListener(OnPlayerLeave); - } - IEnumerator WaitForInstances() { if(InterfaceAudio.Instance == null) @@ -40,6 +32,14 @@ namespace ml_pin CVRGameEventSystem.Player.OnLeaveEntity.AddListener(OnPlayerLeave); } + public override void OnDeinitializeMelon() + { + m_soundManager = null; + + CVRGameEventSystem.Player.OnJoinEntity.RemoveListener(OnPlayerJoin); + CVRGameEventSystem.Player.OnLeaveEntity.RemoveListener(OnPlayerLeave); + } + void OnPlayerJoin(CVRPlayerEntity p_player) { try diff --git a/ml_pin/ResourcesHandler.cs b/ml_pin/ResourcesHandler.cs index 5865e11..f095e80 100644 --- a/ml_pin/ResourcesHandler.cs +++ b/ml_pin/ResourcesHandler.cs @@ -73,7 +73,10 @@ namespace ml_pin StreamReader l_streadReader = new StreamReader(l_libraryStream); l_result = l_streadReader.ReadToEnd(); } - catch(Exception) { } + catch(Exception e) + { + MelonLoader.MelonLogger.Error(e); + } return l_result; } diff --git a/ml_pin/Utils.cs b/ml_pin/Utils.cs index f2e993b..de1f4f7 100644 --- a/ml_pin/Utils.cs +++ b/ml_pin/Utils.cs @@ -5,8 +5,8 @@ namespace ml_pin { static class Utils { - static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.NonPublic | BindingFlags.Instance); + static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.Instance | BindingFlags.NonPublic); - public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => ((cohtml.Net.View)ms_view.GetValue(p_instance)).ExecuteScript(p_script); + public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => (ms_view?.GetValue(p_instance) as cohtml.Net.View)?.ExecuteScript(p_script); } } diff --git a/ml_pmc/GameEvents.cs b/ml_pmc/GameEvents.cs index 02dd1ae..389065b 100644 --- a/ml_pmc/GameEvents.cs +++ b/ml_pmc/GameEvents.cs @@ -25,13 +25,13 @@ namespace ml_pmc try { p_instance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar)), + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar), BindingFlags.Instance | BindingFlags.Public), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnAvatarClear_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); p_instance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar)), + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar), BindingFlags.Instance | BindingFlags.Public), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnSetupAvatar_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); diff --git a/ml_pmc/Main.cs b/ml_pmc/Main.cs index bd10ea6..bdf5faa 100644 --- a/ml_pmc/Main.cs +++ b/ml_pmc/Main.cs @@ -16,13 +16,6 @@ namespace ml_pmc MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer()); } - public override void OnDeinitializeMelon() - { - if(m_poseCopycat != null) - Object.Destroy(m_poseCopycat.gameObject); - m_poseCopycat = null; - } - System.Collections.IEnumerator WaitForLocalPlayer() { while(PlayerSetup.Instance == null) @@ -30,5 +23,12 @@ namespace ml_pmc m_poseCopycat = new GameObject("[PlayerMovementCopycat]").AddComponent(); } + + public override void OnDeinitializeMelon() + { + if(m_poseCopycat != null) + Object.Destroy(m_poseCopycat.gameObject); + m_poseCopycat = null; + } } } diff --git a/ml_pmc/Utils.cs b/ml_pmc/Utils.cs index 34558c2..da2a10d 100644 --- a/ml_pmc/Utils.cs +++ b/ml_pmc/Utils.cs @@ -90,7 +90,7 @@ namespace ml_pmc l_hits.RemoveAll(hit => hit.collider.gameObject.layer == LayerMask.NameToLayer("PlayerLocal")); l_hits.RemoveAll(hit => hit.collider.gameObject.layer == LayerMask.NameToLayer("PlayerClone")); l_hits.Sort((a, b) => ((a.distance < b.distance) ? -1 : 1)); - l_result = (l_hits.First().collider.gameObject.transform.root == p_target.transform.root); + l_result = (l_hits[0].collider.gameObject.transform.root == p_target.transform.root); } } return l_result; diff --git a/ml_prm/GameEvents.cs b/ml_prm/GameEvents.cs index 7fa87f2..4e48819 100644 --- a/ml_prm/GameEvents.cs +++ b/ml_prm/GameEvents.cs @@ -51,13 +51,13 @@ namespace ml_prm try { p_instance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar)), + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar), BindingFlags.Instance | BindingFlags.Public), null, - new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnAvatarClear_Postfix), BindingFlags.NonPublic | BindingFlags.Static)) + new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnAvatarClear_Postfix), BindingFlags.Static |BindingFlags.NonPublic)) ); p_instance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar)), + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar), BindingFlags.Instance | BindingFlags.Public), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnSetupAvatar_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); @@ -69,25 +69,25 @@ namespace ml_prm ); p_instance.Patch( - typeof(PlayerSetup).GetMethod("SetupIKScaling", BindingFlags.NonPublic | BindingFlags.Instance), + typeof(PlayerSetup).GetMethod("SetupIKScaling", BindingFlags.Instance |BindingFlags.NonPublic), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnSetupIKScaling_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); p_instance.Patch( - typeof(CVRSeat).GetMethod(nameof(CVRSeat.SitDown)), + typeof(CVRSeat).GetMethod(nameof(CVRSeat.SitDown), BindingFlags.Instance | BindingFlags.Public), new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnCVRSeatSitDown_Prefix), BindingFlags.Static | BindingFlags.NonPublic)), null ); p_instance.Patch( - typeof(BodySystem).GetMethod(nameof(BodySystem.StartCalibration)), + typeof(BodySystem).GetMethod(nameof(BodySystem.StartCalibration), BindingFlags.Instance | BindingFlags.Public), new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnStartCalibration_Prefix), BindingFlags.Static | BindingFlags.NonPublic)), null ); p_instance.Patch( - typeof(RootLogic).GetMethod(nameof(RootLogic.SpawnOnWorldInstance)), + typeof(RootLogic).GetMethod(nameof(RootLogic.SpawnOnWorldInstance),BindingFlags.Instance | BindingFlags.Public), new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnWorldSpawn_Prefix), BindingFlags.Static | BindingFlags.NonPublic)), null ); @@ -99,7 +99,7 @@ namespace ml_prm ); p_instance.Patch( - typeof(BetterBetterCharacterController).GetMethod(nameof(BetterBetterCharacterController.ChangeFlight)), + typeof(BetterBetterCharacterController).GetMethod(nameof(BetterBetterCharacterController.ChangeFlight), BindingFlags.Instance | BindingFlags.Public), null, new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnChangeFlight_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); diff --git a/ml_prm/Main.cs b/ml_prm/Main.cs index 47bcc6d..fa9fd2a 100644 --- a/ml_prm/Main.cs +++ b/ml_prm/Main.cs @@ -21,15 +21,6 @@ namespace ml_prm MelonLoader.MelonCoroutines.Start(WaitForWhitelist()); } - public override void OnDeinitializeMelon() - { - WorldManager.DeInit(); - - if(m_controller != null) - UnityEngine.Object.Destroy(m_controller.gameObject); - m_controller = null; - } - System.Collections.IEnumerator WaitForRootLogic() { while(ABI_RC.Core.RootLogic.Instance == null) @@ -46,5 +37,14 @@ namespace ml_prm yield return null; SharedFilter.LocalComponentWhitelist.Add(typeof(RagdollToggle)); } + + public override void OnDeinitializeMelon() + { + WorldManager.DeInit(); + + if(m_controller != null) + UnityEngine.Object.Destroy(m_controller.gameObject); + m_controller = null; + } } } diff --git a/ml_prm/ModUi.cs b/ml_prm/ModUi.cs index 6e0f9c3..b393a97 100644 --- a/ml_prm/ModUi.cs +++ b/ml_prm/ModUi.cs @@ -342,12 +342,7 @@ namespace ml_prm ms_hotkeyToggle.ToggleTooltip = string.Format(c_ragdollKeyTooltip, p_keyCode); } - static Stream GetIconStream(string p_name) - { - Assembly l_assembly = Assembly.GetExecutingAssembly(); - string l_assemblyName = l_assembly.GetName().Name; - return l_assembly.GetManifestResourceStream(ms_namespace + ".resources." + p_name); - } + static Stream GetIconStream(string p_name) => Assembly.GetExecutingAssembly().GetManifestResourceStream(ms_namespace + ".resources." + p_name); static float GetDropHeight(float p_speed, float p_gravity = 9.8f) { diff --git a/ml_prm/RagdollBodypartHandler.cs b/ml_prm/RagdollBodypartHandler.cs index f3c9367..4da1439 100644 --- a/ml_prm/RagdollBodypartHandler.cs +++ b/ml_prm/RagdollBodypartHandler.cs @@ -206,28 +206,25 @@ namespace ml_prm { bool l_result = false; - if(!m_attached && (collider != null)) + if(!m_attached && (collider != null) && (Vector3.Distance(p_pos, collider.ClosestPoint(p_pos)) <= Settings.GrabDistance)) { - if(Vector3.Distance(p_pos, collider.ClosestPoint(p_pos)) <= Settings.GrabDistance) - { - GameObject l_attachPoint = new GameObject("[AttachPoint]"); - m_attachTransform = l_attachPoint.transform; - m_attachTransform.parent = p_hand; - m_attachTransform.position = p_pos; + GameObject l_attachPoint = new GameObject("[AttachPoint]"); + m_attachTransform = l_attachPoint.transform; + m_attachTransform.parent = p_hand; + m_attachTransform.position = p_pos; - Rigidbody l_body = l_attachPoint.AddComponent(); - l_body.isKinematic = true; - l_body.detectCollisions = false; + Rigidbody l_body = l_attachPoint.AddComponent(); + l_body.isKinematic = true; + l_body.detectCollisions = false; - m_attachJoint = this.gameObject.AddComponent(); - m_attachJoint.connectedBody = l_body; - m_attachJoint.breakForce = Mathf.Infinity; - m_attachJoint.breakTorque = Mathf.Infinity; + m_attachJoint = this.gameObject.AddComponent(); + m_attachJoint.connectedBody = l_body; + m_attachJoint.breakForce = Mathf.Infinity; + m_attachJoint.breakTorque = Mathf.Infinity; - m_attached = true; - m_attachedHand = p_hand; - l_result = true; - } + m_attached = true; + m_attachedHand = p_hand; + l_result = true; } return l_result; } @@ -253,11 +250,8 @@ namespace ml_prm // CVRTriggerVolume public void TriggerEnter(CVRPointer pointer) { - if(Settings.PointersReaction && (RagdollController.Instance != null)) - { - if((pointer != null) && (pointer.type == c_ragdollPointerType) && pointer.enabled && !IsIgnored(pointer.transform) && !RagdollController.Instance.IsRagdolled()) - RagdollController.Instance.SwitchRagdoll(); - } + if(Settings.PointersReaction && (pointer != null) && pointer.enabled && (pointer.type == c_ragdollPointerType) && !IsIgnored(pointer.transform) && (RagdollController.Instance != null) && !RagdollController.Instance.IsRagdolled()) + RagdollController.Instance.Ragdoll(); } public void TriggerExit(CVRPointer pointer) { diff --git a/ml_prm/RagdollController.cs b/ml_prm/RagdollController.cs index 9f5fcf7..61cf9f3 100644 --- a/ml_prm/RagdollController.cs +++ b/ml_prm/RagdollController.cs @@ -57,6 +57,7 @@ namespace ml_prm m_ragdollBodyHandlers = new List(); m_boneLinks = new List>(); m_jointAnchors = new List>(); + m_playerPlane = new Plane(); } // Unity events @@ -237,8 +238,7 @@ namespace ml_prm // Project on plane and fix our position if we under previous plane if(m_playerPlane.GetDistanceToPoint(m_lastRagdollPosition) < 0f) m_playerPlane.Flip(); - float l_distance = m_playerPlane.GetDistanceToPoint(PlayerSetup.Instance.transform.position); - if(l_distance < 0f) + if(m_playerPlane.GetDistanceToPoint(PlayerSetup.Instance.transform.position) < 0f) PlayerSetup.Instance.transform.position = m_playerPlane.ClosestPointOnPlane(PlayerSetup.Instance.transform.position); } } @@ -692,8 +692,8 @@ namespace ml_prm foreach(RagdollBodypartHandler l_handler in m_ragdollBodyHandlers) l_handler.SetAsKinematic(false); - m_puppet.gameObject.SetActive(false); // - m_puppet.gameObject.SetActive(true); // Resets rigidbodies and joints inner physics states + m_puppet.gameObject.SetActive(false); // Resets rigidbodies and joints inner physics states + m_puppet.gameObject.SetActive(true); foreach(RagdollBodypartHandler l_handler in m_ragdollBodyHandlers) { diff --git a/ml_prm/Utils.cs b/ml_prm/Utils.cs index c4fe775..095f418 100644 --- a/ml_prm/Utils.cs +++ b/ml_prm/Utils.cs @@ -14,13 +14,13 @@ namespace ml_prm { static class Utils { - static readonly FieldInfo ms_touchingVolumes = typeof(BetterBetterCharacterController).GetField("_currentlyTouchingFluidVolumes", BindingFlags.NonPublic | BindingFlags.Instance); - static readonly FieldInfo ms_referencePoints = typeof(PhysicsInfluencer).GetField("_referencePoints", BindingFlags.NonPublic | BindingFlags.Instance); - static readonly FieldInfo ms_influencerTouchingVolumes = typeof(PhysicsInfluencer).GetField("_touchingVolumes", BindingFlags.NonPublic | BindingFlags.Instance); - static readonly FieldInfo ms_influencerSubmergedColliders = typeof(PhysicsInfluencer).GetField("_submergedColliders", BindingFlags.NonPublic | BindingFlags.Instance); - static readonly FieldInfo ms_lastCVRSeat = typeof(BetterBetterCharacterController).GetField("_lastCvrSeat", BindingFlags.NonPublic | BindingFlags.Instance); + static readonly FieldInfo ms_touchingVolumes = typeof(BetterBetterCharacterController).GetField("_currentlyTouchingFluidVolumes", BindingFlags.Instance | BindingFlags.NonPublic); + static readonly FieldInfo ms_referencePoints = typeof(PhysicsInfluencer).GetField("_referencePoints", BindingFlags.Instance | BindingFlags.NonPublic); + static readonly FieldInfo ms_influencerTouchingVolumes = typeof(PhysicsInfluencer).GetField("_touchingVolumes", BindingFlags.Instance | BindingFlags.NonPublic); + static readonly FieldInfo ms_influencerSubmergedColliders = typeof(PhysicsInfluencer).GetField("_submergedColliders", BindingFlags.Instance | BindingFlags.NonPublic); + static readonly FieldInfo ms_lastCVRSeat = typeof(BetterBetterCharacterController).GetField("_lastCvrSeat", BindingFlags.Instance | BindingFlags.NonPublic); - public static void ClearFluidVolumes(this BetterBetterCharacterController p_instance) => (ms_touchingVolumes.GetValue(p_instance) as List)?.Clear(); + public static void ClearFluidVolumes(this BetterBetterCharacterController p_instance) => (ms_touchingVolumes?.GetValue(p_instance) as List)?.Clear(); public static void CopyGlobal(this Transform p_source, Transform p_target) { diff --git a/ml_prm/WorldManager.cs b/ml_prm/WorldManager.cs index 7de13d9..87ce672 100644 --- a/ml_prm/WorldManager.cs +++ b/ml_prm/WorldManager.cs @@ -29,7 +29,7 @@ namespace ml_prm ms_movementLimit = 1f; GameObject l_restrictObj = GameObject.Find("[RagdollRestriction]"); - ms_restrictedWorld = ((l_restrictObj == null) ? false : (l_restrictObj.scene.name != "DontDestroyOnLoad")); + ms_restrictedWorld = ((l_restrictObj != null) && (l_restrictObj.scene.name != "DontDestroyOnLoad")); if(CVRWorld.Instance != null) { diff --git a/ml_vei/Main.cs b/ml_vei/Main.cs index dcf0cb3..fdce8f1 100644 --- a/ml_vei/Main.cs +++ b/ml_vei/Main.cs @@ -12,7 +12,7 @@ namespace ml_vei Settings.Init(); HarmonyInstance.Patch( - typeof(CVRXRModule).GetMethod("Update_Gestures_Vive", BindingFlags.NonPublic | BindingFlags.Instance), + typeof(CVRXRModule).GetMethod("Update_Gestures_Vive", BindingFlags.Instance | BindingFlags.NonPublic), null, new HarmonyLib.HarmonyMethod(typeof(ViveExtendedInput).GetMethod(nameof(OnViveGesturesUpdate_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); diff --git a/ml_vei/ResourcesHandler.cs b/ml_vei/ResourcesHandler.cs index f7b0e08..59cfbc2 100644 --- a/ml_vei/ResourcesHandler.cs +++ b/ml_vei/ResourcesHandler.cs @@ -19,7 +19,10 @@ namespace ml_vei StreamReader l_streadReader = new StreamReader(l_libraryStream); l_result = l_streadReader.ReadToEnd(); } - catch(Exception) { } + catch(Exception e) + { + MelonLoader.MelonLogger.Error(e); + } return l_result; } diff --git a/ml_vei/Utils.cs b/ml_vei/Utils.cs index 5da1fd9..8e32f9b 100644 --- a/ml_vei/Utils.cs +++ b/ml_vei/Utils.cs @@ -5,8 +5,8 @@ namespace ml_vei { static class Utils { - static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.NonPublic | BindingFlags.Instance); + static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.Instance | BindingFlags.NonPublic); - public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => ((cohtml.Net.View)ms_view.GetValue(p_instance)).ExecuteScript(p_script); + public static void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => (ms_view?.GetValue(p_instance) as cohtml.Net.View)?.ExecuteScript(p_script); } }