Skip to content

Commit

Permalink
Handle alternate entrypoint signatures for .NET launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
bbepis committed Aug 23, 2021
1 parent 6650c4d commit ed18974
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion BepInEx.NetLauncher/NetPreloader.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -10,6 +11,7 @@
using BepInEx.Preloader.Core;
using BepInEx.Preloader.Core.Logging;
using BepInEx.Preloader.Core.Patching;
using HarmonyLib;
using MonoMod.Utils;

namespace BepInEx.NetLauncher
Expand Down Expand Up @@ -121,7 +123,28 @@ public static void Start(string[] args)

try
{
entrypointAssembly.EntryPoint.Invoke(null, new[] { args });
var argList = new List<object>();

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<int>
// 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)
{
Expand Down

0 comments on commit ed18974

Please sign in to comment.