下面上修改的Launcher.cs代码:
using System;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;
using System.Reflection;
using System.Collections.Generic;
namespace JuicyLauncher
{
class LauncherReturn//返回的公共类
{
public String rtv;//子值,返回字符串
public String[] rtvs;//子值,返回字符串数组,在正版登陆时有用
public List<string> DUList = new List<string>();//子值,返回下载列表
}
class Launcher
{
private List<string> URLList = new List<string>();//声明总列表
/// <summary>
/// 启动主方法
/// </summary>
/// <param name="MaxMem">最大内存</param>
/// <param name="JavaPath">Javaw.exe路径</param>
/// <param name="UserName">用户名</param>
/// <param name="VerName">版本名</param>
/// <param name="returnvalue">返回值的指定。0为不返回,直接执行;1为返回库的完整字符串;2为返回完整的启动命令。默认为0。</param>
/// <param name="dc">指示是否下载文件。</param>
public LauncherReturn Launch(string MaxMem, string JavaPath, string UserName, string VerName, int returnvalue = 0, bool dc = false)
{
string rtxt = "";//声明
int tmp = 0;//声明
rtxt = File.ReadAllText(Application.StartupPath + "\\.minecraft\\versions\\" + VerName + "\\" + VerName + ".json").Replace(" ", "").Replace("\n", "");//读取内容
tmp = rtxt.IndexOf("mainClass") + "mainClass".Length + 3;//取名称起始位置并赋值到tmp
String mainClass = rtxt.Substring(tmp, rtxt.IndexOf("\"", tmp) - tmp);//截取值
tmp = rtxt.IndexOf("minecraftArguments") + "minecraftArguments".Length + 3;//json读取部分,同上
String minecraftArguments = rtxt.Substring(tmp, rtxt.IndexOf("\"", tmp) - tmp).Replace("${", " ${").Replace("}", "} ").Replace("cpw", " cpw");//json读取部分,同上
tmp = rtxt.IndexOf("libraries") + "libraries".Length + 3;//json读取部分,同上
String libraries = rtxt.Substring(tmp + 1, rtxt.LastIndexOf("]") - tmp);//json读取部分,同上
String natives = Application.StartupPath + "\\.minecraft\\versions\\" + VerName + "\\" + VerName + "-natives";//设置natives路径
if (!Directory.Exists(natives))//目录不存在
{
Directory.CreateDirectory(natives);//创建
}
String[] libs = libraries.Replace("${arch}", "32").Replace("},{", "^").Split("^".ToCharArray());//将},{替换为^然后以^进行分割,顺便决定32位系统
String libp = "";//声明libp
for (int i = 0; i < libs.Length; i++)//为数组内容循环,也可以考虑foreach
{
if (libs[i].IndexOf("name") == -1)//如果没有name值
{
continue;//跳过
}
String tml = libs[i];//声明临时字符串变量tml
if (tml.IndexOf("{") != -1)//如果含有子json对象,则去掉子项
{
do//循环
{
try//捕获错误
{
tml = tml.Replace(tml.Substring(tml.LastIndexOf("{") - 1, tml.IndexOf("}", tml.LastIndexOf("{")) - tml.LastIndexOf("{") + 1), "");//去掉子项
}
catch (ArgumentOutOfRangeException)//如果是干扰的
{
tml = tml + "," + libs[i + 1];//追加
tml = tml.Replace(tml.Substring(tml.LastIndexOf("{") - 1, tml.IndexOf("}", tml.LastIndexOf("{")) - tml.LastIndexOf("{") + 1), "");//再去掉子项
}
} while (tml.IndexOf("{") != -1);//有子项则仍然循环
tml = tml.Replace("{", "").Replace("}", "");//去掉干扰的{}
}
tmp = tml.IndexOf("name") + "name".Length + 3;//json读取部分,同上
String libn = tml.Substring(tmp, tml.IndexOf("\"", tmp) - tmp);//json读取部分,同上
if (libn.IndexOf(":") == -1)//如果name的值不合法
{
continue;//跳过
}
String[] tlib = new String[] { libn.Substring(0, libn.IndexOf(":")).Replace(":", ""), libn.Substring(libn.IndexOf(":") + 1, libn.IndexOf(":", libn.IndexOf(":") + 1) - libn.IndexOf(":")).Replace(":", ""), libn.Substring(libn.IndexOf(":", libn.IndexOf(":") + 1)).Replace(":", "") };//将读取的name值转成路径
String tpath = Application.StartupPath + "\\.minecraft\\libraries\\" + tlib[0].Replace(".", "\\") + "\\" + tlib[1] + "\\" + tlib[2] + "\\" + tlib[1] + "-" + tlib[2] + ".jar";//同上
if (libs[i].IndexOf("natives") != -1 && libs[i].IndexOf("windows") != -1)//如果有natives指定
{
tmp = libs[i].IndexOf("windows") + "windows".Length + 3;//json读取部分,同上
tpath = tpath.Replace(".jar", "") + "-" + libs[i].Substring(tmp, libs[i].IndexOf("\"", tmp) - tmp) + ".jar";//json读取部分,同上
}
if (File.Exists(tpath))//检查文件是否存在
{
libp = libp + tpath + ";";//存在就加录
}
else//如果不存在
{
if (libs[i].IndexOf("url") == -1)//判断是否存在url
{//不存在
using System;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;
using System.Reflection;
using System.Collections.Generic;
namespace JuicyLauncher
{
class LauncherReturn//返回的公共类
{
public String rtv;//子值,返回字符串
public String[] rtvs;//子值,返回字符串数组,在正版登陆时有用
public List<string> DUList = new List<string>();//子值,返回下载列表
}
class Launcher
{
private List<string> URLList = new List<string>();//声明总列表
/// <summary>
/// 启动主方法
/// </summary>
/// <param name="MaxMem">最大内存</param>
/// <param name="JavaPath">Javaw.exe路径</param>
/// <param name="UserName">用户名</param>
/// <param name="VerName">版本名</param>
/// <param name="returnvalue">返回值的指定。0为不返回,直接执行;1为返回库的完整字符串;2为返回完整的启动命令。默认为0。</param>
/// <param name="dc">指示是否下载文件。</param>
public LauncherReturn Launch(string MaxMem, string JavaPath, string UserName, string VerName, int returnvalue = 0, bool dc = false)
{
string rtxt = "";//声明
int tmp = 0;//声明
rtxt = File.ReadAllText(Application.StartupPath + "\\.minecraft\\versions\\" + VerName + "\\" + VerName + ".json").Replace(" ", "").Replace("\n", "");//读取内容
tmp = rtxt.IndexOf("mainClass") + "mainClass".Length + 3;//取名称起始位置并赋值到tmp
String mainClass = rtxt.Substring(tmp, rtxt.IndexOf("\"", tmp) - tmp);//截取值
tmp = rtxt.IndexOf("minecraftArguments") + "minecraftArguments".Length + 3;//json读取部分,同上
String minecraftArguments = rtxt.Substring(tmp, rtxt.IndexOf("\"", tmp) - tmp).Replace("${", " ${").Replace("}", "} ").Replace("cpw", " cpw");//json读取部分,同上
tmp = rtxt.IndexOf("libraries") + "libraries".Length + 3;//json读取部分,同上
String libraries = rtxt.Substring(tmp + 1, rtxt.LastIndexOf("]") - tmp);//json读取部分,同上
String natives = Application.StartupPath + "\\.minecraft\\versions\\" + VerName + "\\" + VerName + "-natives";//设置natives路径
if (!Directory.Exists(natives))//目录不存在
{
Directory.CreateDirectory(natives);//创建
}
String[] libs = libraries.Replace("${arch}", "32").Replace("},{", "^").Split("^".ToCharArray());//将},{替换为^然后以^进行分割,顺便决定32位系统
String libp = "";//声明libp
for (int i = 0; i < libs.Length; i++)//为数组内容循环,也可以考虑foreach
{
if (libs[i].IndexOf("name") == -1)//如果没有name值
{
continue;//跳过
}
String tml = libs[i];//声明临时字符串变量tml
if (tml.IndexOf("{") != -1)//如果含有子json对象,则去掉子项
{
do//循环
{
try//捕获错误
{
tml = tml.Replace(tml.Substring(tml.LastIndexOf("{") - 1, tml.IndexOf("}", tml.LastIndexOf("{")) - tml.LastIndexOf("{") + 1), "");//去掉子项
}
catch (ArgumentOutOfRangeException)//如果是干扰的
{
tml = tml + "," + libs[i + 1];//追加
tml = tml.Replace(tml.Substring(tml.LastIndexOf("{") - 1, tml.IndexOf("}", tml.LastIndexOf("{")) - tml.LastIndexOf("{") + 1), "");//再去掉子项
}
} while (tml.IndexOf("{") != -1);//有子项则仍然循环
tml = tml.Replace("{", "").Replace("}", "");//去掉干扰的{}
}
tmp = tml.IndexOf("name") + "name".Length + 3;//json读取部分,同上
String libn = tml.Substring(tmp, tml.IndexOf("\"", tmp) - tmp);//json读取部分,同上
if (libn.IndexOf(":") == -1)//如果name的值不合法
{
continue;//跳过
}
String[] tlib = new String[] { libn.Substring(0, libn.IndexOf(":")).Replace(":", ""), libn.Substring(libn.IndexOf(":") + 1, libn.IndexOf(":", libn.IndexOf(":") + 1) - libn.IndexOf(":")).Replace(":", ""), libn.Substring(libn.IndexOf(":", libn.IndexOf(":") + 1)).Replace(":", "") };//将读取的name值转成路径
String tpath = Application.StartupPath + "\\.minecraft\\libraries\\" + tlib[0].Replace(".", "\\") + "\\" + tlib[1] + "\\" + tlib[2] + "\\" + tlib[1] + "-" + tlib[2] + ".jar";//同上
if (libs[i].IndexOf("natives") != -1 && libs[i].IndexOf("windows") != -1)//如果有natives指定
{
tmp = libs[i].IndexOf("windows") + "windows".Length + 3;//json读取部分,同上
tpath = tpath.Replace(".jar", "") + "-" + libs[i].Substring(tmp, libs[i].IndexOf("\"", tmp) - tmp) + ".jar";//json读取部分,同上
}
if (File.Exists(tpath))//检查文件是否存在
{
libp = libp + tpath + ";";//存在就加录
}
else//如果不存在
{
if (libs[i].IndexOf("url") == -1)//判断是否存在url
{//不存在












