From 631f5c9126072c8caa987dcd49a9c7583393959e Mon Sep 17 00:00:00 2001 From: Timerix Date: Fri, 27 Dec 2024 22:12:20 +0500 Subject: [PATCH] forge support --- Mlaumcherb.Client.Avalonia/Config.cs | 6 +-- Mlaumcherb.Client.Avalonia/GameVersion.cs | 38 ++++++++++++++++--- .../зримое/LauncherApp.axaml.cs | 6 +++ .../зримое/MainWindow.axaml | 3 ++ .../зримое/MainWindow.axaml.cs | 11 ++++++ .../классы/Буржуазия/GameVersionDescriptor.cs | 1 + .../классы/Пролетариат/Libraries.cs | 22 ++++++----- .../TaskFactories/LibrariesDownloadTaskFactory.cs | 20 +++------- 8 files changed, 76 insertions(+), 31 deletions(-) diff --git a/Mlaumcherb.Client.Avalonia/Config.cs b/Mlaumcherb.Client.Avalonia/Config.cs index 9ac5748..d512078 100644 --- a/Mlaumcherb.Client.Avalonia/Config.cs +++ b/Mlaumcherb.Client.Avalonia/Config.cs @@ -17,16 +17,16 @@ public record Config public int max_memory { get; set; } = 4096; public string minecraft_dir { get; set; } = "."; public bool download_java { get; set; } = true; + public bool redirect_game_output { get; set; } = false; public string? last_launched_version { get; set; } public int max_parallel_downloads { get; set; } = 16; - - public VersionCatalogProps[] version_catalogs { get; set; } = [ new() { Name = "Mojang", Url = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json" } ]; + - [JsonIgnore] static IOPath _filePath = "config.json"; + [JsonIgnore] private static IOPath _filePath = "config.json"; public static Config LoadFromFile() { diff --git a/Mlaumcherb.Client.Avalonia/GameVersion.cs b/Mlaumcherb.Client.Avalonia/GameVersion.cs index f1faacb..1ba1184 100644 --- a/Mlaumcherb.Client.Avalonia/GameVersion.cs +++ b/Mlaumcherb.Client.Avalonia/GameVersion.cs @@ -7,6 +7,7 @@ using Mlaumcherb.Client.Avalonia.классы; using Mlaumcherb.Client.Avalonia.сеть; using Mlaumcherb.Client.Avalonia.сеть.TaskFactories; using Mlaumcherb.Client.Avalonia.холопы; +using Newtonsoft.Json.Linq; using static Mlaumcherb.Client.Avalonia.холопы.PathHelper; namespace Mlaumcherb.Client.Avalonia; @@ -62,9 +63,32 @@ public class GameVersion private GameVersion(GameVersionProps props) { _props = props; + string descriptorText = File.ReadAllText(props.LocalDescriptorPath); - _descriptor = JsonConvert.DeserializeObject(descriptorText) - ?? throw new Exception($"can't parse descriptor file '{props.LocalDescriptorPath}'"); + JObject descriptorRaw = JObject.Parse(descriptorText); + + // Descriptors can inherit from other descriptors. + // For example, 1.12.2-forge-14.23.5.2860 inherits from 1.12.2 + if (descriptorRaw.TryGetValue("inheritsFrom", out var v)) + { + string parentDescriptorId = v.Value() + ?? throw new Exception("inheritsFrom is null"); + LauncherApp.Logger.LogInfo(Name, $"merging descriptor '{parentDescriptorId}' with '{Name}'"); + IOPath parentDescriptorPath = GetVersionDescriptorPath(parentDescriptorId); + if (!File.Exists(parentDescriptorPath)) + throw new Exception($"Версия '{Name} требует установить версию '{parentDescriptorId}'"); + string parentDescriptorText = File.ReadAllText(parentDescriptorPath); + JObject parentDescriptorRaw = JObject.Parse(parentDescriptorText); + parentDescriptorRaw.Merge(descriptorRaw, + new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Concat }); + descriptorRaw = parentDescriptorRaw; + // removing dependency + descriptorRaw.Remove("inheritsFrom"); + File.WriteAllText(props.LocalDescriptorPath, descriptorRaw.ToString()); + } + + _descriptor = descriptorRaw.ToObject() + ?? throw new Exception($"can't parse descriptor file '{props.LocalDescriptorPath}'"); _javaArgs = new JavaArguments(_descriptor); _gameArgs = new GameArguments(_descriptor); _libraries = new Libraries(_descriptor); @@ -82,7 +106,7 @@ public class GameVersion new LibrariesDownloadTaskFactory(_descriptor, _libraries), new VersionFileDownloadTaskFactory(_descriptor), ]; - if(LauncherApp.Config.download_java) + if (LauncherApp.Config.download_java) { taskFactories.Add(new JavaDownloadTaskFactory(_descriptor)); } @@ -190,9 +214,13 @@ public class GameVersion var command = Cli.Wrap(JavaExecutableFilePath.ToString()) .WithWorkingDirectory(WorkingDirectory.ToString()) .WithArguments(argsList) - .WithStandardOutputPipe(PipeTarget.ToDelegate(LogGameOut)) - .WithStandardErrorPipe(PipeTarget.ToDelegate(LogGameError)) .WithValidation(CommandResultValidation.None); + if (LauncherApp.Config.redirect_game_output) + { + command = command + .WithStandardOutputPipe(PipeTarget.ToDelegate(LogGameOut)) + .WithStandardErrorPipe(PipeTarget.ToDelegate(LogGameError)); + } LauncherApp.Logger.LogInfo(Name, "launching the game"); LauncherApp.Logger.LogDebug(Name, "java: " + command.TargetFilePath); LauncherApp.Logger.LogDebug(Name, "working_dir: " + command.WorkingDirPath); diff --git a/Mlaumcherb.Client.Avalonia/зримое/LauncherApp.axaml.cs b/Mlaumcherb.Client.Avalonia/зримое/LauncherApp.axaml.cs index e1c8e48..9404307 100644 --- a/Mlaumcherb.Client.Avalonia/зримое/LauncherApp.axaml.cs +++ b/Mlaumcherb.Client.Avalonia/зримое/LauncherApp.axaml.cs @@ -15,6 +15,12 @@ public class LauncherApp : Application Config = Config.LoadFromFile(); Logger.DebugLogEnabled = Config.debug; AvaloniaXamlLoader.Load(this); + + // some file required by forge installer + if (!File.Exists("launcher_profiles.json")) + { + File.WriteAllText("launcher_profiles.json", "{}"); + } } public override void OnFrameworkInitializationCompleted() diff --git a/Mlaumcherb.Client.Avalonia/зримое/MainWindow.axaml b/Mlaumcherb.Client.Avalonia/зримое/MainWindow.axaml index 6d28e4c..bcdf2a9 100644 --- a/Mlaumcherb.Client.Avalonia/зримое/MainWindow.axaml +++ b/Mlaumcherb.Client.Avalonia/зримое/MainWindow.axaml @@ -90,6 +90,9 @@ Скачивать джаву + + Выводить лог игры в лаунчер +