From ed18974f5c5efa684573223b2678c0917401037c Mon Sep 17 00:00:00 2001 From: Bepis <36346617+bbepis@users.noreply.github.com> Date: Mon, 23 Aug 2021 20:56:37 +1000 Subject: [PATCH] Handle alternate entrypoint signatures for .NET launcher --- BepInEx.NetLauncher/NetPreloader.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/BepInEx.NetLauncher/NetPreloader.cs b/BepInEx.NetLauncher/NetPreloader.cs index 72bfb9e..00cb53b 100644 --- a/BepInEx.NetLauncher/NetPreloader.cs +++ b/BepInEx.NetLauncher/NetPreloader.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; @@ -10,6 +11,7 @@ using BepInEx.NetLauncher.RuntimeFixes; using BepInEx.Preloader.Core; using BepInEx.Preloader.Core.Logging; using BepInEx.Preloader.Core.Patching; +using HarmonyLib; using MonoMod.Utils; namespace BepInEx.NetLauncher @@ -121,7 +123,28 @@ namespace BepInEx.NetLauncher try { - entrypointAssembly.EntryPoint.Invoke(null, new[] { args }); + var argList = new List(); + + var paramTypes = entrypointAssembly.EntryPoint.GetParameters(); + + if (paramTypes.Length == 1 && paramTypes[0].ParameterType == typeof(string[])) + { + argList.Add(args); + } + else if (paramTypes.Length == 1 && paramTypes[0].ParameterType == typeof(string)) + { + argList.Add(string.Join(" ", args)); + } + else if (paramTypes.Length != 0) + { + // Only other entrypoint signatures I can think of that .NET supports is Task / Task + // async entrypoints. That's a can of worms for another time though + + Log.LogFatal($"Could not figure out how to handle entrypoint method with this signature: {entrypointAssembly.EntryPoint.FullDescription()}"); + return; + } + + entrypointAssembly.EntryPoint.Invoke(null, argList.ToArray()); } catch (Exception ex) {