diff --git a/BoneSync/Data/Debugger.cs b/BoneSync/Data/Debugger.cs index 2ae046f..f8631ab 100644 --- a/BoneSync/Data/Debugger.cs +++ b/BoneSync/Data/Debugger.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using UnityEngine; @@ -12,13 +13,25 @@ namespace BoneSync.Data { internal static class SyncLogger { + private static string GetCleanCaller(string className, string methodName) + { + if (className.Contains("BoneSync")) + className = className.Replace("BoneSync.", ""); + if (methodName.Contains("BoneSync")) + methodName = methodName.Replace("BoneSync.", ""); + return $"{className}.{methodName}"; + } public static void Msg(string message, ConsoleColor color = ConsoleColor.White, int frame = 1) { StackTrace stackTrace = new StackTrace(); StackFrame stackFrame = stackTrace.GetFrame(frame); - string methodName = stackFrame.GetMethod().Name; - string className = stackFrame.GetMethod().DeclaringType.Name; - MelonLogger.Msg(color, $"[{className}.{methodName}] {message}"); + MethodBase methodBase = stackFrame.GetMethod(); + + string methodName = methodBase.Name; + string className = methodBase.DeclaringType.Name; + string cleanCaller = GetCleanCaller(className, methodName); + + MelonLogger.Msg(color, $"[{cleanCaller}] {message}"); } public static void Warning(string message) diff --git a/BoneSync/Sync/Components/SyncableBase.cs b/BoneSync/Sync/Components/SyncableBase.cs index 8c44ddc..fdfe67a 100644 --- a/BoneSync/Sync/Components/SyncableBase.cs +++ b/BoneSync/Sync/Components/SyncableBase.cs @@ -83,7 +83,21 @@ namespace BoneSync.Sync.Components public bool isStale => Time.realtimeSinceStartup - _lastSyncTime > 5f; public bool isOwner => _ownerId == BoneSync.lobby.GetLocalId(); - public bool isValid => this != null; + public bool isValid => _GetIsValid(); + + private bool _GetIsValid() + { + try + { + if (this == null) return false; + if (gameObject == null) return false; + return true; + + } catch + { + return false; + } + } public void SetInHolster(bool val) { @@ -131,6 +145,7 @@ namespace BoneSync.Sync.Components public bool IsStatic() => rigidbodies.Length == 0; private void CheckAutoSync() { + if (!isValid) return; FindAndUpdateComponents(); bool shouldAutoSync = ShouldAutoSync(); if (shouldAutoSync && (BoneSync.lobby.IsHost || ClientSpawningAllowed()))