From fc0cf98c66574224e2dad91a4161629efbfc1540 Mon Sep 17 00:00:00 2001 From: Xilophor Date: Sat, 15 Jun 2024 17:41:46 -0400 Subject: [PATCH] Fix NRE in catch statement... --- LethalNetworkAPI/LethalNetwork.cs | 34 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/LethalNetworkAPI/LethalNetwork.cs b/LethalNetworkAPI/LethalNetwork.cs index 64c3bb4..2073911 100644 --- a/LethalNetworkAPI/LethalNetwork.cs +++ b/LethalNetworkAPI/LethalNetwork.cs @@ -20,7 +20,7 @@ public abstract class LethalNetwork internal readonly string Identifier = null!; private readonly string _networkType = null!; - + protected LethalNetwork(string identifier, string networkType, int frameIndex = 3) { try @@ -28,27 +28,27 @@ protected LethalNetwork(string identifier, string networkType, int frameIndex = var m = new StackTrace().GetFrame(frameIndex).GetMethod(); var assembly = m.ReflectedType!.Assembly; var pluginType = AccessTools.GetTypesFromAssembly(assembly).First(type => type.GetCustomAttributes(typeof(BepInPlugin), false).Any()); - + Identifier = $"{MetadataHelper.GetMetadata(pluginType).GUID}.{identifier}"; _networkType = networkType; - + #if DEBUG LethalNetworkAPIPlugin.Logger.LogDebug($"LethalNetwork {_networkType} with identifier \"{Identifier}\" has been created."); #endif } catch (Exception e) { - LethalNetworkAPIPlugin.Logger.LogError(string.Format(TextDefinitions.UnableToFindGuid, _networkType.ToLower(), Identifier, e)); + LethalNetworkAPIPlugin.Logger.LogError(string.Format(TextDefinitions.UnableToFindGuid, (_networkType ?? "").ToLower(), Identifier ?? "", e)); } } #region Error Checks - + /// true if it is null protected bool IsNetworkHandlerNull(bool log = true) { if (NetworkHandler.Instance != null) return false; - + if (log) LethalNetworkAPIPlugin.Logger.LogError(string.Format( TextDefinitions.NotInLobbyEvent, _networkType.ToLower(), Identifier)); return true; @@ -59,10 +59,10 @@ protected bool IsHostOrServer(bool log = true) { if (NetworkManager.Singleton == null) return false; if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer) return true; - + if (log) LethalNetworkAPIPlugin.Logger.LogError(string.Format( TextDefinitions.NotServerInfo, NetworkManager.Singleton.LocalClientId, _networkType, Identifier)); - + return false; } @@ -70,23 +70,23 @@ protected bool IsHostOrServer(bool log = true) private bool DoClientsExist(IEnumerable clientIds, bool log = true) { if (clientIds.Any()) return true; - + if (log) LethalNetworkAPIPlugin.Logger.LogError(string.Format( TextDefinitions.TargetClientsNotConnected, clientIds, _networkType, Identifier)); - + return false; } #endregion #region ClientRpcParams - + private ClientRpcParams GenerateClientParams(IEnumerable clientIds, bool allExcept) { NativeArray allowedClientIds; var enumerable = clientIds as ulong[] ?? clientIds.ToArray(); - + if (!enumerable.Any() && allExcept) allowedClientIds = new NativeArray(NetworkManager.Singleton.ConnectedClientsIds .Where(i => i != NetworkManager.ServerClientId).ToArray(), Allocator.Persistent); @@ -98,7 +98,7 @@ private ClientRpcParams GenerateClientParams(IEnumerable clientIds, bool .Where(i => NetworkManager.Singleton.ConnectedClientsIds.Contains(i)).ToArray(), Allocator.Persistent); if (!DoClientsExist(allowedClientIds)) return new ClientRpcParams(); - + return new ClientRpcParams { Send = new ClientRpcSendParams @@ -107,14 +107,14 @@ private ClientRpcParams GenerateClientParams(IEnumerable clientIds, bool } }; } - + protected ClientRpcParams GenerateClientParams(IEnumerable clientIds) => GenerateClientParams(clientIds, false); protected ClientRpcParams GenerateClientParams(ulong clientId) => GenerateClientParams([clientId], false); - + protected ClientRpcParams GenerateClientParamsExcept(IEnumerable clientIds) => GenerateClientParams(clientIds, true); protected ClientRpcParams GenerateClientParamsExcept(ulong clientId) => GenerateClientParams([clientId], true); - + protected ClientRpcParams GenerateClientParamsExceptHost() => GenerateClientParams([], true); #endregion -} \ No newline at end of file +}