合并库文件到EXE...

master
j502647092 2015-08-03 00:00:40 +08:00
parent 22dabdb0bd
commit 06cbb9c434
31 changed files with 506 additions and 489 deletions

View File

@ -1,10 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KMCCC", "KMCCC.Shared\KMCCC.csproj", "{52E292BB-FC7A-46E6-A8E8-B71E46FAF54E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CTZLauncher", "CTZLauncher\CTZLauncher.csproj", "{EC25362D-5BA7-4CB3-BDA2-C575B9318086}"
EndProject
Global
@ -13,10 +11,6 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{52E292BB-FC7A-46E6-A8E8-B71E46FAF54E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{52E292BB-FC7A-46E6-A8E8-B71E46FAF54E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52E292BB-FC7A-46E6-A8E8-B71E46FAF54E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{52E292BB-FC7A-46E6-A8E8-B71E46FAF54E}.Release|Any CPU.Build.0 = Release|Any CPU
{EC25362D-5BA7-4CB3-BDA2-C575B9318086}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC25362D-5BA7-4CB3-BDA2-C575B9318086}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC25362D-5BA7-4CB3-BDA2-C575B9318086}.Release|Any CPU.ActiveCfg = Release|Any CPU

View File

@ -1,70 +1,70 @@
namespace KMCCC.Authentication
{
#region
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#endregion
/// <summary>
/// 离线验证器
/// </summary>
public class OfflineAuthenticator : IAuthenticator
{
/// <summary>
/// 玩家的名字
/// </summary>
public readonly string DisplayName;
/// <summary>
/// 构造离线验证器
/// </summary>
/// <param name="displayName">玩家的名字</param>
public OfflineAuthenticator(string displayName)
{
DisplayName = displayName;
}
/// <summary>
/// 标注离线验证器
/// </summary>
public string Type
{
get { return "KMCCC.Offline"; }
}
public AuthenticationInfo Do()
{
if (String.IsNullOrWhiteSpace(DisplayName))
{
return new AuthenticationInfo
{
Error = "DisplayName不符合规范"
};
}
if (DisplayName.Count(char.IsWhiteSpace) > 0)
{
return new AuthenticationInfo
{
Error = "DisplayName不符合规范"
};
}
return new AuthenticationInfo
{
AccessToken = null,
DisplayName = DisplayName,
UUID = null,
Properties = "{}",
UserType = "Mojang"
};
}
public Task<AuthenticationInfo> DoAsync(CancellationToken token)
{
return Task.Factory.StartNew((Func<AuthenticationInfo>)Do, token);
}
}
namespace KMCCC.Authentication
{
#region
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#endregion
/// <summary>
/// 离线验证器
/// </summary>
public class OfflineAuthenticator : IAuthenticator
{
/// <summary>
/// 玩家的名字
/// </summary>
public readonly string DisplayName;
/// <summary>
/// 构造离线验证器
/// </summary>
/// <param name="displayName">玩家的名字</param>
public OfflineAuthenticator(string displayName)
{
DisplayName = displayName;
}
/// <summary>
/// 标注离线验证器
/// </summary>
public string Type
{
get { return "KMCCC.Offline"; }
}
public AuthenticationInfo Do()
{
if (String.IsNullOrWhiteSpace(DisplayName))
{
return new AuthenticationInfo
{
Error = "DisplayName不符合规范"
};
}
if (DisplayName.Count(char.IsWhiteSpace) > 0)
{
return new AuthenticationInfo
{
Error = "DisplayName不符合规范"
};
}
return new AuthenticationInfo
{
AccessToken = null,
DisplayName = DisplayName,
UUID = null,
Properties = "{}",
UserType = "Mojang"
};
}
public Task<AuthenticationInfo> DoAsync(CancellationToken token)
{
return Task.Factory.StartNew((Func<AuthenticationInfo>)Do, token);
}
}
}

View File

@ -41,6 +41,7 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xaml" />
@ -57,6 +58,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Tools\SystemTools.cs" />
<Compile Include="Tools\UsefulTools.cs" />
<Compile Include="Tools\ZipTools.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@ -65,15 +69,40 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Authentication\AuthenticationInfo.cs" />
<Compile Include="Authentication\IAuthenticator.cs" />
<Compile Include="Authentication\OfflineAuthenticator.cs" />
<Compile Include="Authentication\WarpedAuhenticator.cs" />
<Compile Include="Authentication\Yggdrasil.cs" />
<Compile Include="CTZAuth\CTZAuth.cs" />
<Compile Include="CTZAuth\ICTZAuth.cs" />
<Compile Include="HttpHelper.cs" />
<Compile Include="Launcher\LaunchArguments.cs" />
<Compile Include="Launcher\LauncherCore.cs" />
<Compile Include="Launcher\LauncherCoreInternal.cs" />
<Compile Include="Launcher\LaunchHandle.cs" />
<Compile Include="Launcher\LaunchHandleExtensions.cs" />
<Compile Include="Launcher\LaunchMode.cs" />
<Compile Include="Launcher\Version.cs" />
<Compile Include="LitJson\IJsonWrapper.cs" />
<Compile Include="LitJson\JsonData.cs" />
<Compile Include="LitJson\JsonException.cs" />
<Compile Include="LitJson\JsonMapper.cs" />
<Compile Include="LitJson\JsonMockWrapper.cs" />
<Compile Include="LitJson\JsonPropertyName.cs" />
<Compile Include="LitJson\JsonReader.cs" />
<Compile Include="LitJson\JsonWriter.cs" />
<Compile Include="LitJson\Lexer.cs" />
<Compile Include="LitJson\ParserToken.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Modules\JVersion\JVersion.cs" />
<Compile Include="Modules\JVersion\JVersionLocator.cs" />
<Compile Include="Modules\Yggdrasil\YggdrasilClient.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
@ -101,12 +130,6 @@
<ItemGroup>
<Resource Include="ico.ico" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KMCCC.Shared\KMCCC.csproj">
<Project>{52e292bb-fc7a-46e6-a8e8-b71e46faf54e}</Project>
<Name>KMCCC</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Resource Include="IZ.ico" />
</ItemGroup>

View File

@ -1,217 +1,217 @@
namespace KMCCC.Launcher
{
#region
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Tools;
#endregion
partial class LauncherCore
{
internal object Locker = new object();
private LaunchResult GenerateArguments(LaunchOptions options, ref MinecraftLaunchArguments args)
{
try
{
var authentication = options.Authenticator.Do();
if (!string.IsNullOrWhiteSpace(authentication.Error))
return new LaunchResult
{
Success = false,
ErrorType = ErrorType.AuthenticationFailed,
ErrorMessage = "验证错误: " + authentication.Error
};
args.CGCEnabled = true;
args.MainClass = options.Version.MainClass;
args.MaxMemory = options.MaxMemory;
args.MinMemory = options.MinMemory;
args.NativePath = GameRootPath + options.Version.Id + @"\\" + options.Version.Id + @"-natives";
foreach (var native in options.Version.Natives)
{
var exp = ZipTools.UnzipFile(this.GetNativePath(native), args.NativePath, native.Options);
if (exp == null)
{
continue;
}
return new LaunchResult
{
Success = false,
ErrorType = ErrorType.UncompressingFailed,
ErrorMessage = string.Format("解压错误: {0}:{1}:{2}", native.NS, native.Name, native.Version),
Exception = exp
};
}
args.Server = options.Server;
args.Size = options.Size;
args.Libraries = options.Version.Libraries.Select(this.GetLibPath).ToList();
args.Libraries.Add(this.GetVersionJarPath(options.Version.JarId));
args.MinecraftArguments = options.Version.MinecraftArguments;
args.Tokens.Add("auth_access_token", authentication.AccessToken.GoString());
args.Tokens.Add("auth_session", authentication.AccessToken.GoString());
args.Tokens.Add("auth_player_name", authentication.DisplayName);
args.Tokens.Add("version_name", options.Version.Id);
args.Tokens.Add("game_directory", ".");
args.Tokens.Add("game_assets", "assets");
args.Tokens.Add("assets_root", "assets");
args.Tokens.Add("assets_index_name", options.Version.Assets);
args.Tokens.Add("auth_uuid", authentication.UUID.GoString());
args.Tokens.Add("user_properties", authentication.Properties);
args.Tokens.Add("user_type", authentication.UserType);
args.AdvencedArguments = new List<string> { "-Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true" };
args.Authentication = authentication;
args.Version = options.Version;
if (options.Mode != null)
{
options.Mode.Operate(this, args);
}
return null;
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
Console.WriteLine(exp.Source);
Console.WriteLine(exp.StackTrace);
return new LaunchResult { Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "在生成参数时发生了意外的错误", Exception = exp };
}
}
internal LaunchResult LaunchInternal(LaunchOptions options, params Action<MinecraftLaunchArguments>[] argumentsOperators)
{
lock (Locker)
{
if (!File.Exists(JavaPath))
{
return new LaunchResult { Success = false, ErrorType = ErrorType.NoJAVA, ErrorMessage = "指定的JAVA位置不存在" };
}
CurrentCode = Random.Next();
var args = new MinecraftLaunchArguments();
var result = GenerateArguments(options, ref args);
if (result != null)
{
return result;
}
if (argumentsOperators == null) return LaunchGame(args);
foreach (var opt in argumentsOperators)
{
try
{
if (opt != null)
{
opt(args);
}
}
catch (Exception exp)
{
return new LaunchResult { Success = false, ErrorType = ErrorType.OperatorException, ErrorMessage = "指定的操作器引发了异常", Exception = exp };
}
}
return LaunchGame(args);
}
}
private LaunchResult LaunchGame(MinecraftLaunchArguments args)
{
Console.WriteLine(args.ToArguments());
try
{
var handle = new LaunchHandle(args.Authentication)
{
Code = CurrentCode,
Core = this,
Arguments = args,
Process = Process.Start(new ProcessStartInfo(JavaPath)
{
Arguments = args.ToArguments(),
UseShellExecute = false,
WorkingDirectory = GameRootPath,
RedirectStandardError = true,
RedirectStandardOutput = true
})
};
handle.Work();
Task.Factory.StartNew(handle.Process.WaitForExit).ContinueWith(t => Exit(handle, handle.Process.ExitCode));
return new LaunchResult { Success = true, Handle = handle };
}
catch (Exception exp)
{
return new LaunchResult { Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "启动时出现了异常", Exception = exp };
}
}
#region 复制文件夹
public void CopyVersionDirectory(string directoryName, string versionId)
{
CopyDirectory(string.Format(@"{0}\versions\{2}\{1}", GameRootPath, directoryName, versionId),
string.Format(@"{0}\{1}", GameRootPath, directoryName));
}
public void CopyDirectory(string source, string target)
{
var code = CurrentCode;
if (!Directory.Exists(source)) return;
if (Directory.Exists(target))
{
Directory.Delete(target, true);
}
UsefulTools.Dircopy(source, target);
Action<LaunchHandle, int> handler = null;
handler = (handle, c) =>
{
if (handle.Code == code)
{
Directory.Delete(source, true);
UsefulTools.Dircopy(target, source);
Directory.Delete(target, true);
}
GameExit -= handler;
};
GameExit += handler;
}
public void CopyVersionDirectories(string ver)
{
var root = string.Format(@"{0}\versions\{1}\moddir", GameRootPath, ver);
if (!Directory.Exists(root))
{
return;
}
foreach (var dir in new DirectoryInfo(root).EnumerateDirectories())
{
CopyDirectory(dir.FullName, string.Format(@"{0}\{1}", GameRootPath, dir.Name));
}
}
#endregion
#region 事件
internal void Log(LaunchHandle handle, string line)
{
if (GameLog != null)
{
GameLog(handle, line);
}
}
internal void Exit(LaunchHandle handle, int code)
{
if (GameExit != null)
{
GameExit(handle, code);
}
}
#endregion
}
namespace KMCCC.Launcher
{
#region
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Tools;
#endregion
partial class LauncherCore
{
internal object Locker = new object();
private LaunchResult GenerateArguments(LaunchOptions options, ref MinecraftLaunchArguments args)
{
try
{
var authentication = options.Authenticator.Do();
if (!string.IsNullOrWhiteSpace(authentication.Error))
return new LaunchResult
{
Success = false,
ErrorType = ErrorType.AuthenticationFailed,
ErrorMessage = "验证错误: " + authentication.Error
};
args.CGCEnabled = true;
args.MainClass = options.Version.MainClass;
args.MaxMemory = options.MaxMemory;
args.MinMemory = options.MinMemory;
args.NativePath = GameRootPath + options.Version.Id + @"\\" + options.Version.Id + @"-natives";
foreach (var native in options.Version.Natives)
{
var exp = ZipTools.UnzipFile(this.GetNativePath(native), args.NativePath, native.Options);
if (exp == null)
{
continue;
}
return new LaunchResult
{
Success = false,
ErrorType = ErrorType.UncompressingFailed,
ErrorMessage = string.Format("解压错误: {0}:{1}:{2}", native.NS, native.Name, native.Version),
Exception = exp
};
}
args.Server = options.Server;
args.Size = options.Size;
args.Libraries = options.Version.Libraries.Select(this.GetLibPath).ToList();
args.Libraries.Add(this.GetVersionJarPath(options.Version.JarId));
args.MinecraftArguments = options.Version.MinecraftArguments;
args.Tokens.Add("auth_access_token", authentication.AccessToken.GoString());
args.Tokens.Add("auth_session", authentication.AccessToken.GoString());
args.Tokens.Add("auth_player_name", authentication.DisplayName);
args.Tokens.Add("version_name", options.Version.Id);
args.Tokens.Add("game_directory", ".");
args.Tokens.Add("game_assets", "assets");
args.Tokens.Add("assets_root", "assets");
args.Tokens.Add("assets_index_name", options.Version.Assets);
args.Tokens.Add("auth_uuid", authentication.UUID.GoString());
args.Tokens.Add("user_properties", authentication.Properties);
args.Tokens.Add("user_type", authentication.UserType);
args.AdvencedArguments = new List<string> { "-Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true" };
args.Authentication = authentication;
args.Version = options.Version;
if (options.Mode != null)
{
options.Mode.Operate(this, args);
}
return null;
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
Console.WriteLine(exp.Source);
Console.WriteLine(exp.StackTrace);
return new LaunchResult { Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "在生成参数时发生了意外的错误", Exception = exp };
}
}
internal LaunchResult LaunchInternal(LaunchOptions options, params Action<MinecraftLaunchArguments>[] argumentsOperators)
{
lock (Locker)
{
if (!File.Exists(JavaPath))
{
return new LaunchResult { Success = false, ErrorType = ErrorType.NoJAVA, ErrorMessage = "指定的JAVA位置不存在" };
}
CurrentCode = Random.Next();
var args = new MinecraftLaunchArguments();
var result = GenerateArguments(options, ref args);
if (result != null)
{
return result;
}
if (argumentsOperators == null) return LaunchGame(args);
foreach (var opt in argumentsOperators)
{
try
{
if (opt != null)
{
opt(args);
}
}
catch (Exception exp)
{
return new LaunchResult { Success = false, ErrorType = ErrorType.OperatorException, ErrorMessage = "指定的操作器引发了异常", Exception = exp };
}
}
return LaunchGame(args);
}
}
private LaunchResult LaunchGame(MinecraftLaunchArguments args)
{
Console.WriteLine(args.ToArguments());
try
{
var handle = new LaunchHandle(args.Authentication)
{
Code = CurrentCode,
Core = this,
Arguments = args,
Process = Process.Start(new ProcessStartInfo(JavaPath)
{
Arguments = args.ToArguments(),
UseShellExecute = false,
WorkingDirectory = GameRootPath,
RedirectStandardError = true,
RedirectStandardOutput = true
})
};
handle.Work();
Task.Factory.StartNew(handle.Process.WaitForExit).ContinueWith(t => Exit(handle, handle.Process.ExitCode));
return new LaunchResult { Success = true, Handle = handle };
}
catch (Exception exp)
{
return new LaunchResult { Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "启动时出现了异常", Exception = exp };
}
}
#region 复制文件夹
public void CopyVersionDirectory(string directoryName, string versionId)
{
CopyDirectory(string.Format(@"{0}\versions\{2}\{1}", GameRootPath, directoryName, versionId),
string.Format(@"{0}\{1}", GameRootPath, directoryName));
}
public void CopyDirectory(string source, string target)
{
var code = CurrentCode;
if (!Directory.Exists(source)) return;
if (Directory.Exists(target))
{
Directory.Delete(target, true);
}
UsefulTools.Dircopy(source, target);
Action<LaunchHandle, int> handler = null;
handler = (handle, c) =>
{
if (handle.Code == code)
{
Directory.Delete(source, true);
UsefulTools.Dircopy(target, source);
Directory.Delete(target, true);
}
GameExit -= handler;
};
GameExit += handler;
}
public void CopyVersionDirectories(string ver)
{
var root = string.Format(@"{0}\versions\{1}\moddir", GameRootPath, ver);
if (!Directory.Exists(root))
{
return;
}
foreach (var dir in new DirectoryInfo(root).EnumerateDirectories())
{
CopyDirectory(dir.FullName, string.Format(@"{0}\{1}", GameRootPath, dir.Name));
}
}
#endregion
#region 事件
internal void Log(LaunchHandle handle, string line)
{
if (GameLog != null)
{
GameLog(handle, line);
}
}
internal void Exit(LaunchHandle handle, int code)
{
if (GameExit != null)
{
GameExit(handle, code);
}
}
#endregion
}
}

View File

@ -1,190 +1,190 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using KMCCC.Authentication;
using KMCCC.Launcher;
using KMCCC.Tools;
using KMCCC.Modules;
using KMCCC.Modules.JVersion;
using CityCraft;
using System.IO;
using System.Windows.Threading;
namespace CTZLauncher
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
LauncherCore launcher = null;
public MainWindow()
{
InitializeComponent();
}
private void Window_Initialized(object sender, EventArgs e)
{
if (Directory.Exists(".minecraft"))
{
launcher = LauncherCore.Create(".minecraft");
launcher.GameLog += launcher_GameLog;
}
else
{
Directory.CreateDirectory(".minecraft");
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
foreach (var item in SystemTools.FindJava())
{
javacombo.Items.Add(item);
}
if (!javacombo.Items.IsEmpty)
javacombo.SelectedIndex = 0;
foreach (var item in launcher.GetVersions())
{
gamecombo.Items.Add(item.Id);
}
if (!gamecombo.Items.IsEmpty)
gamecombo.SelectedIndex = 0;
maxmem.Text = "2048";
}
private void Window_MouseMove(object sender, MouseEventArgs e)
{
}
private void barclick_MouseDown(object sender, MouseButtonEventArgs e)
{
Label bar = (Label)sender;
MessageBox.Show(bar.Name);
switch (bar.Name.Substring(4))
{
case "l1":
break;
case "l2":
break;
case "l3":
break;
case "l4":
break;
case "r1":
break;
case "r2":
break;
case "r3":
break;
case "r4":
break;
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
IAuthenticator auth = new YggdrasilLogin("jtb1@163.com", "jtb325325", false);
AuthenticationInfo result = auth.Do();
MessageBox.Show(result.UUID.ToString());
}
private void Login_Click(object sender, RoutedEventArgs e)
{
HttpHelper http = new HttpHelper();
http.Send(HttpMethod.GET, "http://127.0.0.1:2000/isregistered?username=" + username.Text);
while (http.readyState != HttpReadyState.)
{
DoEvent();
}
String result = http.responseBody;
Console.WriteLine("服务器返回结果" + result);
}
/// <summary>
/// 模仿C#的Application.Doevent函数。可以适当添加try catch 模块
/// </summary>
public void DoEvent()
{
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrame), frame);
Dispatcher.PushFrame(frame);
}
public object ExitFrame(object f)
{
((DispatcherFrame)f).Continue = false;
return null;
}
private void outline_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
this.DragMove();
}
private void StartGame_Click(object sender, RoutedEventArgs e)
{
Console.WriteLine("StartGame");
LaunchOptions option = new LaunchOptions();
option.Mode = LaunchMode.MCLauncher;
option.MaxMemory = int.Parse(maxmem.Text);
option.Authenticator = new OfflineAuthenticator(username.Text); // offline
option.Version = launcher.GetVersion(gamecombo.Text);
launcher.JavaPath = javacombo.Text;
launcher.Launch(option);
}
void launcher_GameLog(LaunchHandle arg1, string arg2)
{
Console.WriteLine(arg2);
}
private void close_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void maxmem_TextChanged(object sender, TextChangedEventArgs e)
{
//屏蔽中文输入和非法字符粘贴输入
TextBox textBox = sender as TextBox;
TextChange[] change = new TextChange[e.Changes.Count];
e.Changes.CopyTo(change, 0);
int offset = change[0].Offset;
if (change[0].AddedLength > 0)
{
double num = 0;
if (!Double.TryParse(textBox.Text, out num))
{
textBox.Text = textBox.Text.Remove(offset, change[0].AddedLength);
textBox.Select(offset, 0);
}
}
}
private void register_Click(object sender, RoutedEventArgs e)
{
if (username.Text.Length == 0 || password.Text.Length == 0)
{
MessageBox.Show("请输入账号密码!");
return;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using KMCCC.Authentication;
using KMCCC.Launcher;
using KMCCC.Tools;
using KMCCC.Modules;
using KMCCC.Modules.JVersion;
using CityCraft;
using System.IO;
using System.Windows.Threading;
namespace CTZLauncher
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
LauncherCore launcher = null;
public MainWindow()
{
InitializeComponent();
}
private void Window_Initialized(object sender, EventArgs e)
{
if (Directory.Exists(".minecraft"))
{
launcher = LauncherCore.Create(".minecraft");
launcher.GameLog += launcher_GameLog;
}
else
{
Directory.CreateDirectory(".minecraft");
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
foreach (var item in SystemTools.FindJava())
{
javacombo.Items.Add(item);
}
if (!javacombo.Items.IsEmpty)
javacombo.SelectedIndex = 0;
foreach (var item in launcher.GetVersions())
{
gamecombo.Items.Add(item.Id);
}
if (!gamecombo.Items.IsEmpty)
gamecombo.SelectedIndex = 0;
maxmem.Text = "2048";
}
private void Window_MouseMove(object sender, MouseEventArgs e)
{
}
private void barclick_MouseDown(object sender, MouseButtonEventArgs e)
{
Label bar = (Label)sender;
MessageBox.Show(bar.Name);
switch (bar.Name.Substring(4))
{
case "l1":
break;
case "l2":
break;
case "l3":
break;
case "l4":
break;
case "r1":
break;
case "r2":
break;
case "r3":
break;
case "r4":
break;
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
IAuthenticator auth = new YggdrasilLogin("jtb1@163.com", "jtb325325", false);
AuthenticationInfo result = auth.Do();
MessageBox.Show(result.UUID.ToString());
}
private void Login_Click(object sender, RoutedEventArgs e)
{
HttpHelper http = new HttpHelper();
http.Send(HttpMethod.GET, "http://127.0.0.1:2000/isregistered?username=" + username.Text);
while (http.readyState != HttpReadyState.)
{
DoEvent();
}
String result = http.responseBody;
Console.WriteLine("服务器返回结果" + result);
}
/// <summary>
/// 模仿C#的Application.Doevent函数。可以适当添加try catch 模块
/// </summary>
public void DoEvent()
{
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrame), frame);
Dispatcher.PushFrame(frame);
}
public object ExitFrame(object f)
{
((DispatcherFrame)f).Continue = false;
return null;
}
private void outline_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
this.DragMove();
}
private void StartGame_Click(object sender, RoutedEventArgs e)
{
Console.WriteLine("StartGame");
LaunchOptions option = new LaunchOptions();
option.Mode = LaunchMode.MCLauncher;
option.MaxMemory = int.Parse(maxmem.Text);
option.Authenticator = new OfflineAuthenticator(username.Text); // offline
option.Version = launcher.GetVersion(gamecombo.Text);
launcher.JavaPath = javacombo.Text;
launcher.Launch(option);
}
void launcher_GameLog(LaunchHandle arg1, string arg2)
{
Console.WriteLine(arg2);
}
private void close_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void maxmem_TextChanged(object sender, TextChangedEventArgs e)
{
//屏蔽中文输入和非法字符粘贴输入
TextBox textBox = sender as TextBox;
TextChange[] change = new TextChange[e.Changes.Count];
e.Changes.CopyTo(change, 0);
int offset = change[0].Offset;
if (change[0].AddedLength > 0)
{
double num = 0;
if (!Double.TryParse(textBox.Text, out num))
{
textBox.Text = textBox.Text.Remove(offset, change[0].AddedLength);
textBox.Select(offset, 0);
}
}
}
private void register_Click(object sender, RoutedEventArgs e)
{
if (username.Text.Length == 0 || password.Text.Length == 0)
{
MessageBox.Show("请输入账号密码!");
return;
}
}
}
}