CmlLib
English (v4)
English (v4)
  • 🧊CmlLib Projects
  • 🚀CmlLib.Core
    • Home
    • Getting Started
      • Minecraft Launcher
      • Minecraft Path
      • Versions
      • Launch Options
      • Event Handling
    • Login and Sessions
      • Microsoft Xbox Account
      • Offline Account
    • More APIs
      • MinecraftLauncherParameters
      • Rules
      • FileExtractor
      • GameInstaller
      • Java
    • Mod Loader Installers
      • Forge Installer
      • Fabric Installer
      • Quilt Installer
      • LiteLoader Installer
    • Utilities
      • Minecraft Changelogs
    • Resources
      • FAQ
      • Known Issues
      • Sample Launcher
      • License
  • 🔓Auth.Microsoft
    • Home
    • CmlLib.Core.Auth.Microsoft
      • JELoginHandler
      • JELoginHandlerBuilder
      • JEAuthenticator
      • Authentication with MSAL
    • XboxAuthNet.Game
      • OAuth
      • XboxAuth
      • XboxAuthException
      • AccountManager
      • Accounts
    • XboxAuthNet.Game.Msal
      • ClientID
      • MsalClientHelper
      • OAuth
    • CmlLib.Core.Bedrock.Auth
    • Resources
  • 🌐MojangAPI
    • Home
    • Mojang API
    • SecurityQuestion
  • ⚒️Installer.Forge
    • Home
    • Supported Versions
    • Getting Started
    • MForge
    • ForgeVersionLoader
Powered by GitBook
On this page
  • Example: Print all versions
  • Example: Get specific version
  • Example: Manipulate version
Edit on GitHub
  1. CmlLib.Core
  2. Getting Started

Versions

Example: Print all versions

The GetAllVersionsAsync method returns all vanilla and locally installed versions of Minecraft.

var launcher = new MinecraftLauncher();
var versions = await launcher.GetAllVersionsAsync();
foreach (var version in versions)
{
    Console.WriteLine("Name: " + version.Name);
    Console.WriteLine("Type: " + version.GetVersionType());
    Console.WriteLine("ReleaseTime: " + version.ReleaseTime);
}

Example: Get specific version

GetVersionAsync method load and parse version json file.

var launcher = new MinecraftLauncher();
var version = await launcher.GetVersionAsync("1.20.4");
// version.Id
// version.Jar
// version.Libraries
// etc...

Example: Manipulate version

IVersion is designed to be an immutable type. With .ToMutableVersion(), you can convert any version to a mutable version, so that you can change the version data.

var launcher = new MinecraftLauncher();
var version = (await launcher.GetVersionAsync("1.16.5")).ToMutableVersion();

// remove existing authlib
version.LibraryList.RemoveAt(version.LibraryList.FindIndex(lib => lib.Name == "com.mojang:authlib:2.1.28"));

// add modified authlib
// download authlib-2.1.28-workaround.jar file and place it in <game_directory>/libraries/com/mojang/authlib/2.1.28/authlib-2.1.28-workaround.jar
version.LibraryList.Add(new MLibrary("com.mojang:authlib:2.1.28")
{
    Artifact = new CmlLib.Core.Files.MFileMetadata
    {
        Path = "com/mojang/authlib/2.1.28/authlib-2.1.28-workaround.jar",
        Sha1 = "", // (optional) SHA1 checksum of the library
        Url = "" // (optional) URL to download library if file does not exist or checksum is not equal
    }
});

await launcher.InstallAsync(version);
var process = launcher.BuildProcess(version, new MLaunchOption
{
    Session = MSession.CreateOfflineSession("tester123")
});
process.Start(); 
PreviousMinecraft PathNextLaunch Options

Last updated 4 months ago

In version 1.16.5, the Multiplayer button is disabled when launch the game with an offline session. This can be fixed by using a modified authlib library. ()

🚀
#85