@@ -12,7 +12,7 @@ public class MLaunch
12
12
private const int DefaultServerPort = 25565 ;
13
13
14
14
public static readonly string SupportVersion = "1.17.1" ;
15
- public readonly static string [ ] DefaultJavaParameter =
15
+ public readonly static string [ ] DefaultJavaParameter =
16
16
{
17
17
"-XX:+UnlockExperimentalVMOptions" ,
18
18
"-XX:+UseG1GC" ,
@@ -33,12 +33,12 @@ public MLaunch(MLaunchOption option)
33
33
34
34
private readonly MinecraftPath minecraftPath ;
35
35
private readonly MLaunchOption launchOption ;
36
-
36
+
37
37
public Process GetProcess ( )
38
38
{
39
39
string arg = string . Join ( " " , CreateArg ( ) ) ;
40
40
Process mc = new Process ( ) ;
41
- mc . StartInfo . FileName =
41
+ mc . StartInfo . FileName =
42
42
useNotNull ( launchOption . GetStartVersion ( ) . JavaBinaryPath , launchOption . GetJavaPath ( ) ) ?? "" ;
43
43
mc . StartInfo . Arguments = arg ;
44
44
mc . StartInfo . WorkingDirectory = minecraftPath . BasePath ;
@@ -48,20 +48,29 @@ public Process GetProcess()
48
48
49
49
private string createClassPath ( MVersion version )
50
50
{
51
- var classpath = new List < string > ( version . Libraries ? . Length ?? 1 ) ;
52
-
53
- if ( version . Libraries != null )
51
+ IEnumerable < string > getLibraryPaths ( )
54
52
{
55
- var libraries = version . Libraries
56
- . Where ( lib => lib . IsRequire && ! lib . IsNative && ! string . IsNullOrEmpty ( lib . Path ) )
57
- . Select ( lib => Path . GetFullPath ( Path . Combine ( minecraftPath . Library , lib . Path ! ) ) ) ;
58
- classpath . AddRange ( libraries ) ;
59
- }
53
+ var set = new HashSet < string > ( ) ;
60
54
61
- if ( ! string . IsNullOrEmpty ( version . Jar ) )
62
- classpath . Add ( minecraftPath . GetVersionJarPath ( version . Jar ) ) ;
55
+ if ( version . Libraries != null )
56
+ {
57
+ var libraries = version . Libraries
58
+ . Where ( lib => lib . IsRequire && ! lib . IsNative && ! string . IsNullOrEmpty ( lib . Path ) )
59
+ . Select ( lib => Path . GetFullPath ( Path . Combine ( minecraftPath . Library , lib . Path ! ) ) )
60
+ . Where ( lib => set . Add ( lib ) ) ;
61
+ foreach ( var lib in libraries )
62
+ yield return lib ;
63
+ }
64
+
65
+ if ( ! string . IsNullOrEmpty ( version . Jar ) )
66
+ {
67
+ var jar = minecraftPath . GetVersionJarPath ( version . Jar ) ;
68
+ if ( set . Add ( jar ) )
69
+ yield return jar ;
70
+ }
71
+ }
63
72
64
- var classpathStr = IOUtil . CombinePath ( classpath . ToArray ( ) ) ;
73
+ var classpathStr = IOUtil . CombinePath ( getLibraryPaths ( ) ) ;
65
74
return classpathStr ;
66
75
}
67
76
@@ -78,11 +87,11 @@ public string[] CreateArg()
78
87
{
79
88
MVersion version = launchOption . GetStartVersion ( ) ;
80
89
var args = new List < string > ( ) ;
81
-
90
+
82
91
var classpath = createClassPath ( version ) ;
83
92
var nativePath = createNativePath ( version ) ;
84
93
var session = launchOption . GetSession ( ) ;
85
-
94
+
86
95
var argDict = new Dictionary < string , string ? >
87
96
{
88
97
{ "library_directory" , minecraftPath . Library } ,
@@ -91,7 +100,7 @@ public string[] CreateArg()
91
100
{ "launcher_version" , useNotNull ( launchOption . GameLauncherVersion , "2" ) } ,
92
101
{ "classpath_separator" , Path . PathSeparator . ToString ( ) } ,
93
102
{ "classpath" , classpath } ,
94
-
103
+
95
104
{ "auth_player_name" , session . Username } ,
96
105
{ "version_name" , version . Id } ,
97
106
{ "game_directory" , minecraftPath . BasePath } ,
@@ -109,11 +118,11 @@ public string[] CreateArg()
109
118
} ;
110
119
111
120
// JVM argument
112
-
121
+
113
122
// version-specific jvm arguments
114
123
if ( version . JvmArguments != null )
115
124
args . AddRange ( Mapper . MapInterpolation ( version . JvmArguments , argDict ) ) ;
116
-
125
+
117
126
// default jvm arguments
118
127
if ( launchOption . JVMArguments != null )
119
128
args . AddRange ( launchOption . JVMArguments ) ;
@@ -124,7 +133,7 @@ public string[] CreateArg()
124
133
125
134
if ( launchOption . MinimumRamMb > 0 )
126
135
args . Add ( "-Xms" + launchOption . MinimumRamMb + "m" ) ;
127
-
136
+
128
137
args . AddRange ( DefaultJavaParameter ) ;
129
138
}
130
139
@@ -196,7 +205,7 @@ public string[] CreateArg()
196
205
{
197
206
if ( input == null )
198
207
return null ;
199
-
208
+
200
209
if ( input . Contains ( " " ) )
201
210
return "\" " + input + "\" " ;
202
211
else
0 commit comments