From 5a82cfd7932465b065a981aeef3c7231c7d0d64a Mon Sep 17 00:00:00 2001 From: 4winyt <73720026+4winyt@users.noreply.github.com> Date: Sat, 26 Mar 2022 00:37:30 -0500 Subject: [PATCH 1/3] Fix a few spelling and grammar mistakes --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index bac8da4..257ce56 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ [![Discord](https://img.shields.io/discord/795952027443527690?label=discord\&logo=discord\&style=for-the-badge)](https://discord.gg/cDW2pvwHSc) -CmlLib.Core is minecraft launcher library for .NET\ -Support all version, with Forge +CmlLib.Core is a Minecraft launcher library for .NET\ +It supports all versions, including Forge [한국어 README](https://github.com/AlphaBs/CmlLib.Core/blob/master/docs/README-kr.md) @@ -26,15 +26,15 @@ Support all version, with Forge * Install Java runtime * Install Forge, LiteLoader, FabricMC * Launch with options (direct server connecting, screen resolution) -* Cross-platform (windows, ubuntu, macOS) +* Cross-platform (Windows, Linux, macOS) -[Go to wiki for all features](https://github.com/CmlLib/CmlLib.Core/wiki) +[Go to the wiki for all features](https://github.com/CmlLib/CmlLib.Core/wiki) ## Install Install the [CmlLib.Core Nuget package](https://www.nuget.org/packages/CmlLib.Core) -or download the dll files in [Releases](https://github.com/AlphaBs/CmlLib.Core/releases) and add references to them in your project. +or download the DLL files in [Releases](https://github.com/AlphaBs/CmlLib.Core/releases) and add references to them in your project. Write this at the top of your source code: @@ -45,10 +45,10 @@ using CmlLib.Core.Auth; ## Documentation -There are many features for custom launcher. Read wiki to use all features.\ +There are many features for custom launchers. Read the wiki to see all of the features.\ **Official documentation: [wiki](https://github.com/CmlLib/CmlLib.Core/wiki)** -## QuickStart +## Quick start ### Microsoft Xbox Login From 28ebc0cecc84163d359f1aded0f09df6ae22fbef Mon Sep 17 00:00:00 2001 From: Damian Date: Fri, 22 Apr 2022 20:43:27 +0300 Subject: [PATCH 2/3] add QuiltMC version loader --- CmlLib/Core/Installer/QuiltMC/QuiltLoader.cs | 16 +++ .../Installer/QuiltMC/QuiltVersionLoader.cs | 114 ++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 CmlLib/Core/Installer/QuiltMC/QuiltLoader.cs create mode 100644 CmlLib/Core/Installer/QuiltMC/QuiltVersionLoader.cs diff --git a/CmlLib/Core/Installer/QuiltMC/QuiltLoader.cs b/CmlLib/Core/Installer/QuiltMC/QuiltLoader.cs new file mode 100644 index 0000000..3739b35 --- /dev/null +++ b/CmlLib/Core/Installer/QuiltMC/QuiltLoader.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace CmlLib.Core.Installer.QuiltMC +{ + public class QuiltLoader + { + [JsonProperty("separator")] + public string? Separator { get; set; } + [JsonProperty("build")] + public string? Build { get; set; } + [JsonProperty("maven")] + public string? Maven { get; set; } + [JsonProperty("version")] + public string? Version { get; set; } + } +} diff --git a/CmlLib/Core/Installer/QuiltMC/QuiltVersionLoader.cs b/CmlLib/Core/Installer/QuiltMC/QuiltVersionLoader.cs new file mode 100644 index 0000000..df8cbe6 --- /dev/null +++ b/CmlLib/Core/Installer/QuiltMC/QuiltVersionLoader.cs @@ -0,0 +1,114 @@ +using CmlLib.Core.Version; +using Newtonsoft.Json.Linq; +using System.Collections.Generic; +using System.Net; +using System.Threading.Tasks; +using CmlLib.Core.VersionLoader; + +namespace CmlLib.Core.Installer.QuiltMC +{ + public class QuiltVersionLoader : IVersionLoader + { + public static readonly string ApiServer = "https://meta.quiltmc.org"; + private static readonly string LoaderUrl = ApiServer + "/v3/versions/loader"; + + public string? LoaderVersion { get; set; } + + protected string GetVersionName(string version, string loaderVersion) + { + return $"quilt-loader-{loaderVersion}-{version}"; + } + + public MVersionCollection GetVersionMetadatas() + => internalGetVersionMetadatasAsync(sync: true).GetAwaiter().GetResult(); + + public Task GetVersionMetadatasAsync() + => internalGetVersionMetadatasAsync(sync: false); + + private async Task internalGetVersionMetadatasAsync(bool sync) + { + if (string.IsNullOrEmpty(LoaderVersion)) + { + QuiltLoader[] loaders; + if (sync) + loaders = GetQuiltLoaders(); + else + loaders = await GetQuiltLoadersAsync().ConfigureAwait(false); + + LoaderVersion = loaders[0].Version; + if (loaders.Length == 0 || string.IsNullOrEmpty(LoaderVersion)) + throw new KeyNotFoundException("can't find loaders"); + } + + string url = "https://meta.quiltmc.org/v3/versions/game"; + string res; + using (var wc = new WebClient()) + { + if (sync) + res = wc.DownloadString(url); + else + res = await wc.DownloadStringTaskAsync(url).ConfigureAwait(false); + } + + var versions = parseVersions(res, LoaderVersion!); + return new MVersionCollection(versions.ToArray()); + } + + private List parseVersions(string res, string loader) + { + var jarr = JArray.Parse(res); + var versionList = new List(jarr.Count); + + foreach (var item in jarr) + { + string? versionName = item["version"]?.ToString(); + if (string.IsNullOrEmpty(versionName)) + continue; + + string jsonUrl = $"{ApiServer}/v3/versions/loader/{versionName}/{loader}/profile/json"; + + string id = GetVersionName(versionName, loader); + var versionMetadata = new WebVersionMetadata(id) + { + MType = MVersionType.Custom, + Path = jsonUrl, + Type = "quilt" + }; + versionList.Add(versionMetadata); + } + + return versionList; + } + + public QuiltLoader[] GetQuiltLoaders() + { + using var wc = new WebClient(); + var res = wc.DownloadString(LoaderUrl); + + return parseLoaders(res); + } + + public async Task GetQuiltLoadersAsync() + { + using var wc = new WebClient(); + var res = await wc.DownloadStringTaskAsync(LoaderUrl) + .ConfigureAwait(false); + + return parseLoaders(res); + } + + private QuiltLoader[] parseLoaders(string res) + { + var jarr = JArray.Parse(res); + var loaderList = new List(jarr.Count); + foreach (var item in jarr) + { + var obj = item.ToObject(); + if (obj != null) + loaderList.Add(obj); + } + + return loaderList.ToArray(); + } + } +} From bd0a9492fbec5a099b0ebaf2b89dc99c1af0d9ec Mon Sep 17 00:00:00 2001 From: AlphaBs Date: Tue, 26 Apr 2022 15:31:45 +0900 Subject: [PATCH 3/3] fix possible IndexOutOfRangeException on FabricVersionLoader.cs, QuiltVersionLoader.cs --- CmlLib/Core/Installer/FabricMC/FabricVersionLoader.cs | 5 +++-- CmlLib/Core/Installer/QuiltMC/QuiltVersionLoader.cs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CmlLib/Core/Installer/FabricMC/FabricVersionLoader.cs b/CmlLib/Core/Installer/FabricMC/FabricVersionLoader.cs index 430431e..0fe2662 100644 --- a/CmlLib/Core/Installer/FabricMC/FabricVersionLoader.cs +++ b/CmlLib/Core/Installer/FabricMC/FabricVersionLoader.cs @@ -35,9 +35,10 @@ private async Task internalGetVersionMetadatasAsync(bool syn else loaders = await GetFabricLoadersAsync().ConfigureAwait(false); - LoaderVersion = loaders[0].Version; - if (loaders.Length == 0 || string.IsNullOrEmpty(LoaderVersion)) + if (loaders.Length == 0 || string.IsNullOrEmpty(loaders[0].Version)) throw new KeyNotFoundException("can't find loaders"); + + LoaderVersion = loaders[0].Version; } string url = "https://meta.fabricmc.net/v2/versions/game/intermediary"; diff --git a/CmlLib/Core/Installer/QuiltMC/QuiltVersionLoader.cs b/CmlLib/Core/Installer/QuiltMC/QuiltVersionLoader.cs index df8cbe6..5b0b2c2 100644 --- a/CmlLib/Core/Installer/QuiltMC/QuiltVersionLoader.cs +++ b/CmlLib/Core/Installer/QuiltMC/QuiltVersionLoader.cs @@ -35,9 +35,10 @@ private async Task internalGetVersionMetadatasAsync(bool syn else loaders = await GetQuiltLoadersAsync().ConfigureAwait(false); - LoaderVersion = loaders[0].Version; - if (loaders.Length == 0 || string.IsNullOrEmpty(LoaderVersion)) + if (loaders.Length == 0 || string.IsNullOrEmpty(loaders[0].Version)) throw new KeyNotFoundException("can't find loaders"); + + LoaderVersion = loaders[0].Version; } string url = "https://meta.quiltmc.org/v3/versions/game";