• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

CmlLib/MinecraftLauncherLibrary: C# Minecraft Launcher - EXACTLY WORKING, CLEAN ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

CmlLib/MinecraftLauncherLibrary

开源软件地址(OpenSource Url):

https://github.com/CmlLib/MinecraftLauncherLibrary

开源编程语言(OpenSource Language):

C# 99.9%

开源软件介绍(OpenSource Introduction):

Csharp Minecraft Launcher Library

NOTICE!!


USE CmlLib.Core
This library will not be developed anymore.


CmlLib 1.1.0

This library is minecraft launcher library for C#.
Support all version, with Forge

Only for Windows (use pml if you want crossplatform)

한국어

=====>>> 한국어 README

Contacts

Email : [email protected]
Discord : ksi123456ab#3719

License

MIT License

Crossplatform

This library doesn't support crossplatform. Only Windows
if you want Cross-Platform Minecraft Launcher Library,
use this python library.
pml github

Dependency

Newtonsoft.Json
DotNetZip

Functions

  • Online / Offline Login
  • Download game files in mojang file server
  • Launch All Versions (tested up to 1.14)
  • Launch Forge, Optifine or custom versions
  • Download minecraft java runtime in mojang file server
  • Launch with options (direct server connecting, screen resolution)
  • Support cross-platform (use pml if you want crossplatform)

Sample

If you want to learn more features of this library such as to download java runtime or launch with more detailed options, go to wiki

Simple Sample Code

Sample Launcher (CmlLibSample)
Download CmlLibSample.zip file, unzip file and execute CmlLibSample.exe

CmlLibSample Source Code

Build

Build CmlLib

  1. download source codes
  2. Build CmlLib project. if an error occurs, restore nuget package of CmlLib project. (Package name : Newtonsoft.Json, DotNetZip)

Required dll : Newtonsoft.Json.dll, DotNetZip.dll, CmlLib.dll

Build CmlLibSample (Sample launcher)

  1. Add reference above, 'Newtonsoft.Json.dll, DotNetZip.dll, CmlLib.dll'.
  2. Build CmlLibSample project.

Pre-built library

Nuget package : CustomMinecraftLauncher
or go to Release tab

How to use

Enter the source code in the order shown below.

1. Prepare

Install Nuget Package 'CustomMinecraftLauncher'
or download dll files in Release tab (CmlLib.dll, Newtonsoft.Json.dll, DotNetZip.dll) and add reference

write this on the top of your source code:

  using CmlLib.Launcher;

2. Minecraft Initialize

You should write this code before work.

  Minecraft.Initialize("GAME_DIRECTORY");

It set Game Directory that is used to download game files, load profiles, save login session, Launch, etc...
You can't use relative path.

3. Login

 MLogin login = new MLogin();
 MSession session = null;

 session = login.TryAutoLogin();
 if (session.Result != MLoginResult.Success)
 {
      session = login.Authenticate(
           "YOUR_MOJANG_EMAIL",
           "PASSWORD");

      if (session.result != MLoginResult.Success)
           throw new Exception("Failed login : " + session.result.ToString());
 }

 Console.WriteLine("Hello, " + session.Username);

The 'session' is login result. note : you can't use old login using username instead of mojang email.

or you can use offline session :

 MSession session = MSession.GetOfflineSession("USERNAME");

4. Get Profile Infos

Profile contain various data which launcher need. All Game Versions has its own profile, even old alpha version and forge. You can find it at (GameDirectory)₩versions₩(any-version)₩(version-name).json. MProfileInfo is metadata of profile, containing Name, Profile Path(Url), Type(Release, Snapshot, Old), ReleaseTime. and this code get profile info :

 MProfileInfo[] infos = MProfileInfo.GetProfiles();

It will return all metadata from mojang web server and your game directory.
but you can choose source :

 // get profiles from mojang server
 var web = MProfileInfo.GetProfilesFromWeb();
 // get profiles from game directory
 var local = MProfileInfo.GetProfilesFromLocal();

5. Choose ProfileInfo and Parse

In order to use profile data, you should parse profile.
This simple code will search version from metadatas, and return parsed profile data.

 MProfile profile = MProfile.FindProfile(infos, "1.14.4");

6. Check & Download Game Files

 MDownloader downloader = new MDownloader(profile);
 downloader.ChangeFile += change_file;
 downloader.ChangeProgress += change_progress;
 downloader.DownloadAll();

and the handler methods of ChangeFile and ChangeProgress event is :

 private void Downloader_ChangeProgress(object sender, System.ComponentModel.ProgressChangedEventArgs e)
 {
     // when download file was changed
     // 20%, 30%, 80%, ...
     Console.WriteLine("{0}%", e.ProgressPercentage);
 }

 private void Downloader_ChangeFile(DownloadFileChangedEventArgs e)
 {
     // when the progress of current downloading file was changed
     // [Library] hi.jar - 3/51
     Console.WriteLine("[{0}] {1} - {2}/{3}", e.FileKind.ToString(), e.FileName, e.ProgressedFileCount, e.TotalFileCount);
 }

DownloadAll() method check the existence of game file, and download game file from mojang server if file is not exist or not valid(compare hash).

7. Make game args and Launch

 var option = new MLaunchOption()
 {
      // must require
      StartProfile = profile,
      JavaPath = "java.exe", //SET YOUR JAVA PATH (if you want autoset, goto wiki)
      MaximumRamMb = 1024, // MB
      Session = session,
      
      // not require
      ServerIP = "", // connect server directly
      LauncherName = "", // display launcher name at main window
      CustomJavaParameter = "" // set your own java args
 };
 
 var launch = new MLaunch(option);
 var process = launch.GetProcess();
 process.Start();

set launch options, and launch it!

8. More Information

Sample Code

launch forge : You don't need any additional work to launch forge

bugs : go to issue tab




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap