Skip to content

Commit

Permalink
Updated packages and frameworks, added DirectJoinServer option
Browse files Browse the repository at this point in the history
  • Loading branch information
SinoAHpx committed Jun 27, 2024
1 parent 919f025 commit 68f0955
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 89 deletions.
2 changes: 1 addition & 1 deletion ModuleLauncher.NET.Runtime/LauncherChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class LauncherChecker
public static async Task CheckAsync(string? defaultVersion = null, string? defaultWorkingDirectory = null)
{
var resolver = new MinecraftResolver(@"C:\Users\ahpx\AppData\Roaming\.minecraft");
var launcher = new Launcher(resolver, new LauncherConfig
var launcher = new Launcher.Launcher(resolver, new LauncherConfig
{
Authentication = "ahpx",
Fullscreen = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

<ItemGroup>
<PackageReference Include="Downloader" Version="2.3.5" />
<PackageReference Include="Flurl.Http" Version="4.0.0-pre2" />
<PackageReference Include="morelinq" Version="3.3.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta1" />
<PackageReference Include="Polly" Version="7.2.3" />
Expand Down
18 changes: 11 additions & 7 deletions ModuleLauncher.NET.Runtime/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
using ModuleLauncher.NET.Resources;
using ModuleLauncher.NET.Utilities;
using System.Runtime.CompilerServices;
using Manganese.Process;
using Tommy;

const string MinecraftRoot = @"C:\Users\ahpx\AppData\Roaming\.minecraft";
var resolver = new MinecraftResolver(MinecraftRoot);

var mc = resolver.GetMinecraft("1.20.4");
var mc = resolver.GetMinecraft("fabric-loader-0.15.11-1.21");

await mc.WithAuthentication("AHpx")
.WithJava(@"C:\Users\ahpx\AppData\Local\Packages\Microsoft.4297127D64EC6_8wekyb3d8bbwe\LocalCache\Local\runtime\java-runtime-gamma\windows-x64\java-runtime-gamma\bin\javaw.exe")
var process = await mc.WithAuthentication("AHpx")
.WithJava(@"C:\Program Files\Eclipse Adoptium\jre-21.0.3.9-hotspot\bin\javaw.exe")
.WithLauncherName("Latest Version")
.LaunchAsync(pipeTarget: CliWrap.PipeTarget.ToDelegate(s =>
{
Console.WriteLine(s);
}));
.WithDirectServer("hypixel.net")
.LaunchAsync();

while (!process.HasExited)
{
process.ReadOutputLine().Print();
}

static class RuntimeUtils
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Diagnostics;
using CliWrap;
using CliWrap.Buffered;
using Manganese.Data;
using Manganese.IO;
using Manganese.Text;
Expand All @@ -11,7 +9,7 @@
using ModuleLauncher.NET.Utilities;
using Newtonsoft.Json.Linq;

namespace ModuleLauncher.NET;
namespace ModuleLauncher.NET.Launcher;

public class Launcher
{
Expand Down Expand Up @@ -67,49 +65,15 @@ public async Task<Process> LaunchAsync(string id)

return await LaunchAsync(minecraftEntry);
}

/// <summary>
/// Launch minecraft
/// </summary>
/// <param name="minecraftEntry"></param>
/// <param name="pipeTarget">How do you want to grab your output lines. No idea how to use it? Simply pass a null is allowed</param>
/// <returns></returns>
public async Task<CommandResult> LaunchAsync(MinecraftEntry minecraftEntry, PipeTarget? pipeTarget)
{
#region Precheck

await WriteLauncherProfileAsync(minecraftEntry);

#endregion

var java = GetJava(minecraftEntry)?.Executable
.ThrowIfNull(new InvalidJavaExecutableException("No java executable file was specified"));

var arguments = GetLaunchArguments(minecraftEntry);
var result = await Cli.Wrap(java
.ThrowIfNull(new InvalidJavaExecutableException("No java executable file was specified"))
.FullName)
.WithArguments(arguments)
.WithWorkingDirectory(minecraftEntry.Tree.WorkingDirectory.FullName)
.WithValidation(CommandResultValidation.None)
.WithStandardOutputPipe(pipeTarget ?? PipeTarget.Null)
.ExecuteAsync();

await minecraftEntry.ExtractNativesAsync();
await minecraftEntry.MapAssetsAsync();

return result;
}

[Obsolete("This method will be soon abandoned")]
public async Task<Process> LaunchAsync(MinecraftEntry minecraftEntry)
{
#region Precheck

await WriteLauncherProfileAsync(minecraftEntry);

#endregion

var java = GetJava(minecraftEntry)?.Executable
.ThrowIfNull(new InvalidJavaExecutableException("No java executable file was specified"));

Expand All @@ -134,12 +98,12 @@ public async Task<Process> LaunchAsync(MinecraftEntry minecraftEntry)
await minecraftEntry.MapAssetsAsync();

process.Start();

return process;
}



public string GetLaunchArguments(MinecraftEntry minecraftEntry)
{
var preset = GetJvmArguments(minecraftEntry);
Expand Down Expand Up @@ -204,7 +168,7 @@ private string GetMinecraftArguments(MinecraftEntry minecraftEntry)
var options = new List<string>();

var boilerplate = GetMinecraftArgumentBoilerplate(minecraftEntry);

//filling the boilerplate
boilerplate = boilerplate.Replace("${auth_player_name}", $"\"{LauncherConfig.Authentication.Name}\"")
.Replace("${version_name}", $"\"{LauncherConfig.LauncherName}\"")
Expand All @@ -231,6 +195,9 @@ private string GetMinecraftArguments(MinecraftEntry minecraftEntry)
if (LauncherConfig.WindowWidth != null)
options.Add($"--width {LauncherConfig.WindowWidth}");

if (LauncherConfig.DirectlyJoinServer != null)
options.Add($"--server {LauncherConfig.DirectlyJoinServer}");

return options.JoinToString(" ");
}

Expand Down Expand Up @@ -261,11 +228,11 @@ private string GetMinecraftArgumentBoilerplate(MinecraftEntry minecraftEntry)

return boilerplate;
}

private string GetJvmArguments(MinecraftEntry minecraftEntry)
{
var libraries = minecraftEntry.GetLibraries();

var rawArgs = new List<string>
{
// "-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump",
Expand All @@ -277,7 +244,7 @@ private string GetJvmArguments(MinecraftEntry minecraftEntry)
"-XX:G1HeapRegionSize=32M",
$"-Xmx{LauncherConfig.MaxMemorySize}M"
};

if (LauncherConfig.MinMemorySize != null)
rawArgs.Add($"-Xmn{LauncherConfig.MinMemorySize}M");

Expand All @@ -302,7 +269,7 @@ private string GetJvmArguments(MinecraftEntry minecraftEntry)

rawArgs.Add(forgeArgs.JoinToString(" "));
}

var args = rawArgs.JoinToString(" ");

return args;
Expand Down
5 changes: 5 additions & 0 deletions ModuleLauncher.NET/Models/Launcher/LauncherConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public class LauncherConfig
/// </summary>
public int? MinMemorySize { get; set; }

/// <summary>
/// The example pattern(server:port): 127.0.0.1:8080. Invalid pattern will occur an error.
/// </summary>
public string? DirectlyJoinServer { get; set; }

/// <summary>
/// AuthenticateResult object, could be implicitly convert via string
/// </summary>
Expand Down
9 changes: 4 additions & 5 deletions ModuleLauncher.NET/ModuleLauncher.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<Nullable>enable</Nullable>
<LangVersion>latestmajor</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>4.0.8</PackageVersion>
<PackageVersion>4.0.9</PackageVersion>
<Title>ModuleLauncher.NET</Title>
<Description>Your on-the-fly Minecraft launcher core.</Description>
<Copyright>Copyright 2023 AHpx all rights reserved.</Copyright>
<Copyright>Copyright 2024 AHpx all rights reserved.</Copyright>
<PackageProjectUrl>https://github.com/SinoAHpx/ModuleLauncher.Re</PackageProjectUrl>
<PackageIcon>ML-logo.png</PackageIcon>
<RepositoryUrl>https://github.com/SinoAHpx/ModuleLauncher.Re</RepositoryUrl>
Expand All @@ -20,9 +20,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CliWrap" Version="3.6.0" />
<PackageReference Include="Flurl.Http" Version="4.0.0-pre2" />
<PackageReference Include="Manganese" Version="1.2.8" />
<PackageReference Include="Flurl.Http" Version="4.0.2" />
<PackageReference Include="Manganese" Version="1.2.9" />
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>$(MSBuildProjectName).Tests</_Parameter1>
</AssemblyAttribute>
Expand Down
39 changes: 11 additions & 28 deletions ModuleLauncher.NET/Utilities/LauncherUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics;
using CliWrap;
using Manganese.Text;
using ModuleLauncher.NET.Models.Authentication;
using ModuleLauncher.NET.Models.Launcher;
Expand Down Expand Up @@ -415,51 +414,35 @@ public static LauncherConfigBuilder WithJavas(this LauncherConfigBuilder builder
return builder;
}

public static Launcher? Launcher;

/// <summary>
/// Launch minecraft from internal config, should be the last item of the method chain
/// </summary>
/// <param name="minecraftEntry"></param>
/// <param name="config"></param>
/// <returns></returns>
[Obsolete("This method will be soon abandoned")]
public static async Task<Process> LaunchAsync(this MinecraftEntry minecraftEntry, LauncherConfig config)
public static LauncherConfigBuilder WithDirectServer(this LauncherConfigBuilder builder, string? server)
{
Launcher = new Launcher
if (server is not null)
{
MinecraftResolver = MinecraftResolver.Of(minecraftEntry),
LauncherConfig = config
};
builder.LauncherConfig.DirectlyJoinServer = server;
}

return await Launcher.LaunchAsync(minecraftEntry);
return builder;
}

public static Launcher.Launcher? Launcher;

/// <summary>
/// Launch minecraft from internal config, should be the last item of the method chain
/// </summary>
/// <param name="minecraftEntry"></param>
/// <param name="config"></param>
/// <returns></returns>
//todo: make the parameter optional
public static async Task<CommandResult> LaunchAsync(this MinecraftEntry minecraftEntry, LauncherConfig config, PipeTarget? pipeTarget)
public static async Task<Process> LaunchAsync(this MinecraftEntry minecraftEntry, LauncherConfig config)
{
Launcher = new Launcher
Launcher = new Launcher.Launcher
{
MinecraftResolver = MinecraftResolver.Of(minecraftEntry),
LauncherConfig = config
};

return await Launcher.LaunchAsync(minecraftEntry, pipeTarget);
}

//todo: make the parameter optional
public static async Task<CommandResult> LaunchAsync(this LauncherConfigBuilder builder, PipeTarget? pipeTarget)
{
return await builder.MinecraftEntry.LaunchAsync(builder.LauncherConfig, pipeTarget);
return await Launcher.LaunchAsync(minecraftEntry);
}

[Obsolete("This method will be soon abandoned")]

public static async Task<Process> LaunchAsync(this LauncherConfigBuilder builder)
{
return await builder.MinecraftEntry.LaunchAsync(builder.LauncherConfig);
Expand Down

0 comments on commit 68f0955

Please sign in to comment.