Skip to content

Commit 498e1eb

Browse files
Fixed several MelonLaunchOptions related issues
Implemented `Peek` Method for LemonEnumerator Fixed an issue with MelonLaunchOptions failing to parse arguments if an `=` sign is used instead of a space Fixed an issue with MelonLaunchOptions failing to parse options if a `-` prefix is used instead of `--` Fixed an issue with Command Line Arguments not being logged
1 parent 95a8f70 commit 498e1eb

File tree

4 files changed

+96
-52
lines changed

4 files changed

+96
-52
lines changed

CHANGELOG.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,30 @@
4545
4. Updated AsmResolver to 6.0.0-beta.1
4646
5. Updated AssetRipper.VersionUtilities to 1.5.0
4747
6. Updated AssetsTools.NET to 3.0.0
48-
7. Implemented `--cpp2il.callanalyzer` launch option to enable Cpp2IL's CallAnalyzer processor
49-
8. Implemented `--cpp2il.nativemethoddetector` launch option to enable Cpp2IL's NativeMethodDetector processor
50-
9. Implemented several fixes for Il2CppInterop related issues
51-
10. Implemented Cpp2IL's StrippedCodeRegSupport plugin
52-
11. Fixed an accidental regression with LemonSHA256
53-
12. Fixed an issue with Native logs using the wrong Colors
54-
13. Fixed an issue with Preload module not replacing Mono libraries on Older Mono Games
55-
14. Fixed an issue with MonoMod DetourContext Disposal not working properly
56-
15. Fixed an issue with Debugger Launch Option causing crashes
57-
16. Fixed an issue with Console not having the Game Name and Version in the title
58-
17. Fixed an issue with Sharing Violation during Log Initialization
48+
7. Updated UnityEngine.Il2CppAssetBundleManager for latest compatibility
49+
8. Updated UnityEngine.Il2CppImageConversionManager for latest compatibility
50+
9. Implemented `--cpp2il.callanalyzer` launch option to enable Cpp2IL's CallAnalyzer processor
51+
10. Implemented `--cpp2il.nativemethoddetector` launch option to enable Cpp2IL's NativeMethodDetector processor
52+
11. Implemented several fixes for Il2CppInterop related issues
53+
12. Implemented Cpp2IL's StrippedCodeRegSupport plugin
54+
13. Implemented `ExternalArguments` Dictionary for MelonLaunchOptions (Credits to [HAHOOS](https://github.com/HAHOOS) :P)
55+
14. Implemented `Peek` Method for LemonEnumerator
56+
15. Fixed an accidental regression with LemonSHA256
57+
16. Fixed an issue with Native logs using the wrong Colors
58+
17. Fixed an issue with Preload module not replacing Mono libraries on Older Mono Games
59+
18. Fixed an issue with MonoMod DetourContext Disposal not working properly
60+
19. Fixed an issue with Debugger Launch Option causing crashes
61+
20. Fixed an issue with Console not having the Game Name and Version in the title
62+
21. Fixed an issue with Sharing Violation during Log Initialization
63+
22. Fixed an issue with `--melonloader.basedir` launch option always expecting an `=` sign before the path
64+
23. Fixed an issue with Il2CppInteropFixes not being properly error handled
65+
24. Fixed an issue with Il2CppInteropFixes using `il2cpp_type_get_class_or_element_class` instead of `il2cpp_class_from_type`
66+
25. Fixed an issue with EOS Support Module not being properly error handled
67+
26. Fixed an issue with NativeStackWalk not unregistering addresses
68+
27. Fixed an issue with Errors being Spammed if `UnityEngine.Transform::SetAsLastSibling` fails to resolve
69+
28. Fixed an issue with MelonLaunchOptions failing to parse arguments if an `=` sign is used instead of a space
70+
29. Fixed an issue with MelonLaunchOptions failing to parse options if a `-` prefix is used instead of `--`
71+
30. Fixed an issue with Command Line Arguments not being logged
5972

6073
---
6174

MelonLoader/Core.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.IO;
99
using bHapticsLib;
1010
using System.Threading;
11+
using System.Linq;
1112
#pragma warning disable IDE0051 // Prevent the IDE from complaining about private unreferenced methods
1213

1314
namespace MelonLoader
@@ -172,6 +173,9 @@ internal static void WelcomeMessage()
172173
var archString = MelonUtils.IsGame32Bit() ? "x86" : "x64";
173174
MelonLogger.MsgDirect($"Game Arch: {archString}");
174175
MelonLogger.MsgDirect("------------------------------");
176+
MelonLogger.MsgDirect($"CommandLine: {string.Join(" ", MelonLaunchOptions.CommandLineArgs)}");
177+
MelonLogger.MsgDirect("------------------------------");
178+
175179

176180
MelonEnvironment.PrintEnvironment();
177181
}

MelonLoader/Lemons/LemonEnumerator.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ public LemonEnumerator(IList<T> lemons)
2525
object IEnumerator.Current => Current;
2626
public T Current { get; private set; }
2727

28+
public bool Peek(out T next)
29+
{
30+
if ((LemonPatch == null)
31+
|| (LemonPatch.Length <= 0)
32+
|| (NextLemon >= LemonPatch.Length))
33+
{
34+
next = Current;
35+
return false;
36+
}
37+
38+
next = LemonPatch[NextLemon];
39+
return true;
40+
}
41+
2842
bool IEnumerator.MoveNext() => MoveNext();
2943
public bool MoveNext()
3044
{

MelonLoader/MelonLaunchOptions.cs

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43

54
namespace MelonLoader
65
{
76
public static class MelonLaunchOptions
87
{
98
private static Dictionary<string, Action> WithoutArg = new Dictionary<string, Action>();
109
private static Dictionary<string, Action<string>> WithArg = new Dictionary<string, Action<string>>();
10+
private static string[] _cmd;
1111

1212
/// <summary>
1313
/// Dictionary of all Arguments with value (if found) that were not used by MelonLoader
@@ -17,6 +17,19 @@ public static class MelonLaunchOptions
1717
/// </summary>
1818
public static Dictionary<string, string> ExternalArguments { get; private set; } = new Dictionary<string, string>();
1919

20+
/// <summary>
21+
/// Array of All Command Line Arguments
22+
/// </summary>
23+
public static string[] CommandLineArgs
24+
{
25+
get
26+
{
27+
if (_cmd == null)
28+
_cmd = Environment.GetCommandLineArgs();
29+
return _cmd;
30+
}
31+
}
32+
2033
static MelonLaunchOptions()
2134
{
2235
Core.Setup();
@@ -28,61 +41,61 @@ static MelonLaunchOptions()
2841

2942
internal static void Load()
3043
{
31-
List<string> foundOptions = new List<string>();
32-
LemonEnumerator<string> argEnumerator = new LemonEnumerator<string>(Environment.GetCommandLineArgs());
44+
LemonEnumerator<string> argEnumerator = new LemonEnumerator<string>(CommandLineArgs);
3345
while (argEnumerator.MoveNext())
3446
{
3547
string fullcmd = argEnumerator.Current;
3648
if (string.IsNullOrEmpty(fullcmd))
3749
continue;
3850

39-
if (!fullcmd.StartsWith("--"))
51+
// Parse Prefix
52+
string noPrefixCmd = fullcmd;
53+
if (noPrefixCmd.StartsWith("--"))
54+
noPrefixCmd = noPrefixCmd.Remove(0, 2);
55+
else if (noPrefixCmd.StartsWith("-"))
56+
noPrefixCmd = noPrefixCmd.Remove(0, 1);
57+
else
58+
{
59+
// Unknown Command, Add it to Dictionary
60+
ExternalArguments.Add(noPrefixCmd, null);
4061
continue;
62+
}
4163

42-
string cmd = fullcmd.Remove(0, 2);
43-
44-
if (WithoutArg.TryGetValue(cmd, out Action withoutArgFunc))
64+
// Parse Argumentless Commands
65+
if (WithoutArg.TryGetValue(noPrefixCmd, out Action withoutArgFunc))
4566
{
46-
foundOptions.Add(fullcmd);
4767
withoutArgFunc();
68+
continue;
4869
}
49-
else if (WithArg.TryGetValue(cmd, out Action<string> withArgFunc))
50-
{
51-
if (!argEnumerator.MoveNext())
52-
continue;
53-
54-
string cmdArg = argEnumerator.Current;
55-
if (string.IsNullOrEmpty(cmdArg))
56-
continue;
5770

58-
if (cmdArg.StartsWith("--"))
59-
continue;
60-
61-
foundOptions.Add($"{fullcmd} = {cmdArg}");
62-
withArgFunc(cmdArg);
71+
// Parse Argument
72+
string cmdArg = null;
73+
if (noPrefixCmd.Contains("="))
74+
{
75+
string[] split = noPrefixCmd.Split('=');
76+
noPrefixCmd = split[0];
77+
cmdArg = split[1];
78+
}
79+
if ((string.IsNullOrEmpty(cmdArg)
80+
&& !argEnumerator.Peek(out cmdArg))
81+
|| string.IsNullOrEmpty(cmdArg)
82+
|| !cmdArg.StartsWith("--")
83+
|| !cmdArg.StartsWith("-"))
84+
{
85+
// Unknown Command, Add it to Dictionary
86+
ExternalArguments.Add(noPrefixCmd, null);
87+
continue;
6388
}
64-
if (foundOptions.Where(x => x.StartsWith(fullcmd)).Count() <= 0)
89+
90+
// Parse Argument Commands
91+
if (WithArg.TryGetValue(noPrefixCmd, out Action<string> withArgFunc))
6592
{
66-
if (!argEnumerator.MoveNext())
67-
{
68-
ExternalArguments.Add(cmd, null);
69-
continue;
70-
}
71-
72-
string cmdArg = argEnumerator.Current;
73-
if (string.IsNullOrEmpty(cmdArg))
74-
{
75-
ExternalArguments.Add(cmd, null);
76-
continue;
77-
}
78-
79-
if (cmdArg.StartsWith("--"))
80-
{
81-
ExternalArguments.Add(cmd, null);
82-
continue;
83-
}
84-
ExternalArguments.Add(cmd, cmdArg);
93+
withArgFunc(cmdArg);
94+
continue;
8595
}
96+
97+
// Unknown Command with Argument, Add it to Dictionary
98+
ExternalArguments.Add(noPrefixCmd, cmdArg);
8699
}
87100
}
88101

0 commit comments

Comments
 (0)