Skip to content

Commit

Permalink
Merge pull request #730 from HAHOOS/master
Browse files Browse the repository at this point in the history
Add External Command Line Arguments
  • Loading branch information
HerpDerpinstine authored Sep 4, 2024
2 parents 62567fd + d03b475 commit 95a8f70
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions MelonLoader/MelonLaunchOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace MelonLoader
{
Expand All @@ -8,6 +9,14 @@ public static class MelonLaunchOptions
private static Dictionary<string, Action> WithoutArg = new Dictionary<string, Action>();
private static Dictionary<string, Action<string>> WithArg = new Dictionary<string, Action<string>>();

/// <summary>
/// Dictionary of all Arguments with value (if found) that were not used by MelonLoader
/// <para>
/// <b>Key</b> is the argument, <b>Value</b> is the value for the argument, <c>null</c> if not found
/// </para>
/// </summary>
public static Dictionary<string, string> ExternalArguments { get; private set; } = new Dictionary<string, string>();

static MelonLaunchOptions()
{
Core.Setup();
Expand Down Expand Up @@ -52,6 +61,28 @@ internal static void Load()
foundOptions.Add($"{fullcmd} = {cmdArg}");
withArgFunc(cmdArg);
}
if (foundOptions.Where(x => x.StartsWith(fullcmd)).Count() <= 0)
{
if (!argEnumerator.MoveNext())
{
ExternalArguments.Add(cmd, null);
continue;
}

string cmdArg = argEnumerator.Current;
if (string.IsNullOrEmpty(cmdArg))
{
ExternalArguments.Add(cmd, null);
continue;
}

if (cmdArg.StartsWith("--"))
{
ExternalArguments.Add(cmd, null);
continue;
}
ExternalArguments.Add(cmd, cmdArg);
}
}
}

Expand All @@ -65,6 +96,7 @@ public enum LoadModeEnum
DEV,
BOTH
}

public static LoadModeEnum LoadMode_Plugins { get; internal set; }
public static LoadModeEnum LoadMode_Mods { get; internal set; }
public static bool QuitFix { get; internal set; }
Expand Down Expand Up @@ -103,6 +135,7 @@ public enum DisplayMode
RANDOMRAINBOW,
LEMON
};

public static DisplayMode Mode { get; internal set; }
public static bool CleanUnityLogs { get; internal set; } = true;
public static bool ShouldSetTitle { get; internal set; } = true;
Expand Down Expand Up @@ -180,6 +213,6 @@ internal static void Setup()
}
}

#endregion
#endregion Args
}
}
}

0 comments on commit 95a8f70

Please sign in to comment.