This commit is contained in:
Aaro Varis
2025-03-23 20:46:20 +02:00
parent ff52da9542
commit b004b725f0
2 changed files with 32 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
@@ -12,13 +13,25 @@ namespace BoneSync.Data
{ {
internal static class SyncLogger 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) public static void Msg(string message, ConsoleColor color = ConsoleColor.White, int frame = 1)
{ {
StackTrace stackTrace = new StackTrace(); StackTrace stackTrace = new StackTrace();
StackFrame stackFrame = stackTrace.GetFrame(frame); StackFrame stackFrame = stackTrace.GetFrame(frame);
string methodName = stackFrame.GetMethod().Name; MethodBase methodBase = stackFrame.GetMethod();
string className = stackFrame.GetMethod().DeclaringType.Name;
MelonLogger.Msg(color, $"[{className}.{methodName}] {message}"); 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) public static void Warning(string message)

View File

@@ -83,7 +83,21 @@ namespace BoneSync.Sync.Components
public bool isStale => Time.realtimeSinceStartup - _lastSyncTime > 5f; public bool isStale => Time.realtimeSinceStartup - _lastSyncTime > 5f;
public bool isOwner => _ownerId == BoneSync.lobby.GetLocalId(); 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) public void SetInHolster(bool val)
{ {
@@ -131,6 +145,7 @@ namespace BoneSync.Sync.Components
public bool IsStatic() => rigidbodies.Length == 0; public bool IsStatic() => rigidbodies.Length == 0;
private void CheckAutoSync() private void CheckAutoSync()
{ {
if (!isValid) return;
FindAndUpdateComponents(); FindAndUpdateComponents();
bool shouldAutoSync = ShouldAutoSync(); bool shouldAutoSync = ShouldAutoSync();
if (shouldAutoSync && (BoneSync.lobby.IsHost || ClientSpawningAllowed())) if (shouldAutoSync && (BoneSync.lobby.IsHost || ClientSpawningAllowed()))