namespace KMCCC.Launcher { #region using System; using System.Collections.Generic; using System.Text; using Authentication; using Tools; #endregion /// /// Launch Arguments /// public class MinecraftLaunchArguments { internal AuthenticationInfo Authentication; internal Version Version; /// /// 新建启动参数 /// public MinecraftLaunchArguments() { CGCEnabled = true; Tokens = new Dictionary(); AdvencedArguments = new List(); } /// /// 主类 /// public string MainClass { get; set; } /// /// 库文件列表(推荐绝对路径) /// public List Libraries { get; set; } /// /// 最大内存 /// public int MaxMemory { get; set; } /// /// 最小内存,推荐不设置 /// public int MinMemory { get; set; } /// /// 默认true,不要作死去设置成false /// public bool CGCEnabled { get; set; } /// /// 本地dll文件地址 /// public string NativePath { get; set; } /// /// MC主参数(将由Token进行替换操作) /// public string MinecraftArguments { get; set; } /// /// 对MC主参数要进行的替换操作表 /// public Dictionary Tokens { get; set; } /// /// 启动后直接连接到服务器 /// public ServerInfo Server { get; set; } /// /// 启动后的窗口大小设置 /// public WindowSize Size { get; set; } /// /// 附加参数 /// public List AdvencedArguments { get; set; } /// /// 转化为String参数 /// /// 转化后的参数 public string ToArguments() { var sb = new StringBuilder(); if (CGCEnabled) { sb.Append("-Xincgc"); } if (MinMemory > 0) { sb.Append(" -Xms").Append(MinMemory).Append("M "); } if (MaxMemory > 0) { sb.Append(" -Xmx").Append(MaxMemory).Append("M"); } else { sb.Append("-Xmx2048M "); } foreach (var adv in AdvencedArguments) { sb.Append(' ').Append(adv); } sb.Append(" -Djava.library.path=\"").Append(NativePath); sb.Append("\" -cp \""); foreach (var lib in Libraries) { sb.Append(lib).Append(';'); } sb.Append("\" ").Append(MainClass).Append(' ').Append(MinecraftArguments.DoReplace(Tokens)); if (Server != null) { if (!String.IsNullOrWhiteSpace(Server.Address)) { sb.Append(" --server " + Server.Address); if (Server.Port == 0) { sb.Append(" --port 25565"); } else { sb.Append(" --port " + Server.Port); } } } if (Size != null) { if (Size.FullScreen == true) { sb.Append(" --fullscreen"); } if (Size.Height != null) { var height = (ushort) Size.Height; if (height > 0) { sb.Append(String.Format(" --height {0}", height)); } } if (Size.Width != null) { var width = (ushort) Size.Width; if (width > 0) { sb.Append(String.Format(" --width {0}", width)); } } } return sb.ToString(); } } public class ServerInfo { public string Address { get; set; } public ushort Port { get; set; } public override string ToString() { return string.Format("{0}:{1}", Address, Port); } } public class WindowSize { public bool? FullScreen { get; set; } public ushort? Height { get; set; } public ushort? Width { get; set; } } }