From 7864570a56f702db9a6f475396660d80202b5b26 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Mon, 14 Feb 2022 04:56:27 +0100 Subject: [PATCH] fix: allow null in CallGateChannel args --- .../Ipc/Exceptions/IpcValueNullError.cs | 21 +++++++++++++++++++ .../Plugin/Ipc/Internal/CallGateChannel.cs | 10 ++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 Dalamud/Plugin/Ipc/Exceptions/IpcValueNullError.cs diff --git a/Dalamud/Plugin/Ipc/Exceptions/IpcValueNullError.cs b/Dalamud/Plugin/Ipc/Exceptions/IpcValueNullError.cs new file mode 100644 index 000000000..04d5550a9 --- /dev/null +++ b/Dalamud/Plugin/Ipc/Exceptions/IpcValueNullError.cs @@ -0,0 +1,21 @@ +using System; + +namespace Dalamud.Plugin.Ipc.Exceptions; + +/// +/// This exception is thrown when a null value is passed to an IPC requiring a value type. +/// +public class IpcValueNullError : IpcError +{ + /// + /// Initializes a new instance of the class. + /// + /// Name of the IPC. + /// The type expected. + /// Index of the failing argument. + public IpcValueNullError(string name, Type expectedType, int index) + : base($"IPC {name} expects a value type({expectedType.FullName}) at index {index}, null given.") + { + // ignored + } +} diff --git a/Dalamud/Plugin/Ipc/Internal/CallGateChannel.cs b/Dalamud/Plugin/Ipc/Internal/CallGateChannel.cs index 7dbda203e..c933b4cd1 100644 --- a/Dalamud/Plugin/Ipc/Internal/CallGateChannel.cs +++ b/Dalamud/Plugin/Ipc/Internal/CallGateChannel.cs @@ -105,7 +105,7 @@ namespace Dalamud.Plugin.Ipc.Internal var paramTypes = methodInfo.GetParameters() .Select(pi => pi.ParameterType).ToArray(); - if (args.Length != paramTypes.Length) + if (args?.Length != paramTypes.Length) throw new IpcLengthMismatchError(this.Name, args.Length, paramTypes.Length); for (var i = 0; i < args.Length; i++) @@ -113,6 +113,14 @@ namespace Dalamud.Plugin.Ipc.Internal var arg = args[i]; var paramType = paramTypes[i]; + if (arg == null) + { + if (paramType.IsValueType) + throw new IpcValueNullError(this.Name, paramType, i); + + continue; + } + var argType = arg.GetType(); if (argType != paramType) {