fix invoke issues

This commit is contained in:
Mister_Nebula 2021-02-06 22:03:10 +00:00
parent 545cf27f8f
commit d4e9b372b8
7 changed files with 32 additions and 15 deletions

View File

@ -1,4 +1,5 @@
using QSB.Events;
using QSB.Utility;
using QuantumUNET;
using QuantumUNET.Components;
using QuantumUNET.Messages;
@ -59,13 +60,13 @@ namespace QSB.Messaging
private void OnClientReceiveMessageHandler(QNetworkMessage netMsg)
{
var message = netMsg.ReadMessage<T>();
OnClientReceiveMessage?.Invoke(message);
OnClientReceiveMessage?.SafeInvoke(message);
}
private void OnServerReceiveMessageHandler(QNetworkMessage netMsg)
{
var message = netMsg.ReadMessage<T>();
OnServerReceiveMessage?.Invoke(message);
OnServerReceiveMessage?.SafeInvoke(message);
}
}
}

View File

@ -15,11 +15,9 @@ using System.Linq;
namespace QSB.Patches
{
public delegate void PatchEvent(QSBPatchTypes type);
public static class QSBPatchManager
{
public static event PatchEvent OnPatchType;
public static event Action<QSBPatchTypes> OnPatchType;
private static List<QSBPatch> _patchList = new List<QSBPatch>();
@ -46,7 +44,7 @@ namespace QSB.Patches
public static void DoPatchType(QSBPatchTypes type)
{
OnPatchType?.Invoke(type);
OnPatchType?.SafeInvoke(type);
DebugLog.DebugWrite($"Patch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info);
foreach (var patch in _patchList.Where(x => x.Type == type))
{

View File

@ -185,7 +185,7 @@ namespace QSB
_lobby.CanEditName = false;
OnNetworkManagerReady?.Invoke();
OnNetworkManagerReady?.SafeInvoke();
IsReady = true;
QSBCore.Helper.Events.Unity.RunWhen(() => QSBEventManager.Ready && PlayerTransformSync.LocalInstance != null,

View File

@ -1,6 +1,7 @@
using OWML.Common;
using QSB.Utility;
using System;
using System.Linq;
namespace QSB
{
@ -11,7 +12,6 @@ namespace QSB
public static bool IsInUniverse => InUniverse(CurrentScene);
public static event Action<OWScene, bool> OnSceneLoaded;
public static event Action<OWScene> OnUniverseSceneLoaded;
static QSBSceneManager()
@ -24,10 +24,10 @@ namespace QSB
{
DebugLog.DebugWrite($"COMPLETE SCENE LOAD ({oldScene} -> {newScene})", MessageType.Info);
var universe = InUniverse(newScene);
OnSceneLoaded?.Invoke(newScene, universe);
OnSceneLoaded?.SafeInvoke(newScene, universe);
if (universe)
{
OnUniverseSceneLoaded?.Invoke(newScene);
OnUniverseSceneLoaded?.SafeInvoke(newScene, universe);
}
}

View File

@ -51,6 +51,7 @@ namespace QSB.TimeSync
if (QNetworkServer.active)
{
QSBCore.HasWokenUp = true;
RespawnOnDeath.Instance.Init();
}
}
@ -84,7 +85,6 @@ namespace QSB.TimeSync
if (IsServer)
{
SendServerTime();
RespawnOnDeath.Instance.Init();
}
else
{

View File

@ -1,6 +1,8 @@
using QSB.Player;
using OWML.Common;
using QSB.Player;
using QSB.TransformSync;
using QuantumUNET;
using System;
using UnityEngine;
namespace QSB.Utility
@ -24,7 +26,7 @@ namespace QSB.Utility
public static GameObject InstantiateInactive(this GameObject original)
{
original.SetActive(false);
var copy = Object.Instantiate(original);
var copy = UnityEngine.Object.Instantiate(original);
original.SetActive(true);
return copy;
}
@ -39,5 +41,21 @@ namespace QSB.Utility
var controller = go.GetComponent<PlayerTransformSync>();
return QSBPlayerManager.GetPlayer(controller.NetId.Value);
}
// C#
public static void SafeInvoke(this MulticastDelegate multicast, params object[] args)
{
foreach (var del in multicast.GetInvocationList())
{
try
{
del.DynamicInvoke(args);
}
catch
{
DebugLog.DebugWrite($"Error while invoking delegate {del.Method.DeclaringType.Name}.{del.Method.Name}", MessageType.Error);
}
}
}
}
}

View File

@ -26,11 +26,11 @@ namespace QSB.Utility
_wasEnabled = state;
if (state == ComponentState.Enabled)
{
OnEnableEvent?.Invoke();
OnEnableEvent?.SafeInvoke();
}
else
{
OnDisableEvent?.Invoke();
OnDisableEvent?.SafeInvoke();
}
}
}