Compare commits

..

2 Commits

Author SHA1 Message Date
5129f68dad fix web login 2024-07-09 02:23:49 +08:00
8e3535ecf6 add 43经典 2024-07-05 16:32:50 +08:00
33 changed files with 591 additions and 1248 deletions

View File

@ -1,13 +0,0 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# Rider 忽略的文件
/modules.xml
/contentModel.xml
/projectSettingsUpdater.xml
/.idea.Zerolauncher.iml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -28,7 +28,7 @@ namespace Zerolauncher.AboutDialog
private void Hyperlink_Click_1(object sender, RoutedEventArgs e) private void Hyperlink_Click_1(object sender, RoutedEventArgs e)
{ {
MessageBox.Show("已拷贝到粘贴板呢喵", "提示"); MessageBox.Show("已拷贝到粘贴板", "提示");
Clipboard.SetDataObject("ddfgame@foxmail.com", true); Clipboard.SetDataObject("ddfgame@foxmail.com", true);
} }

View File

@ -82,9 +82,9 @@ namespace Zerolauncher
for (int i = 0; i < 3 && !TryDeleteDirectory(@"./cache", true); i++) await Task.Delay(3000); for (int i = 0; i < 3 && !TryDeleteDirectory(@"./cache", true); i++) await Task.Delay(3000);
} }
}); });
DataStreamNew.Load(); DataStream.Load();
_ = WebApiManager.StartListener(); _ = WebApiManager.StartListener();
AccountManager.InitLoadData(); AccountManager.initLoadData();
} }
protected override void OnExit(ExitEventArgs e) protected override void OnExit(ExitEventArgs e)

View File

@ -1,9 +0,0 @@

namespace Zerolauncher.Defender
{
class SystemSha
{
}
}

View File

@ -29,18 +29,13 @@ namespace Zerolauncher
memberBG.ContextMenu = CreateContextMenu(); memberBG.ContextMenu = CreateContextMenu();
int i = 0; int i = 0;
foreach (var account in AccountManager.AccountsList) foreach (var account in AccountManager.accountsList)
{ {
var member = new MemberControl(); var member = new MemberControl();
member.memberId = i++; member.memberId = i++;
member.text.Content = ServicesStaticInfo.ServicesShortName[account.ProviderId] + "-" + account.nickName; member.text.Content = ServicesStaticInfo.ServicesShortName[account.providerId] + "-" + account.nickName;
mLayout.Children.Add(member); mLayout.Children.Add(member);
} }
if (i ==0)
{
EditMemberDialog.CreateDailog(null);
MessageBox.Show("下次右键账号和窗口空白处可以打菜单喵", "小提示");
}
} }
public void ReloadBtn() public void ReloadBtn()
@ -48,11 +43,11 @@ namespace Zerolauncher
//foreach (var btn in mLayout.Children.) //foreach (var btn in mLayout.Children.)
mLayout.Children.Clear(); mLayout.Children.Clear();
int i = 0; int i = 0;
foreach (var account in AccountManager.AccountsList) foreach (var account in AccountManager.accountsList)
{ {
var member = new MemberControl(); var member = new MemberControl();
member.memberId = i++; member.memberId = i++;
member.text.Content = ServicesStaticInfo.ServicesShortName[account.ProviderId] + "-" + account.nickName; member.text.Content = ServicesStaticInfo.ServicesShortName[account.providerId] + "-" + account.nickName;
mLayout.Children.Add(member); mLayout.Children.Add(member);
} }
} }
@ -97,7 +92,7 @@ namespace Zerolauncher
MenuItem menuItem = sender as MenuItem; MenuItem menuItem = sender as MenuItem;
int i = (int)menuItem.Tag; int i = (int)menuItem.Tag;
Trace.WriteLine("Clicked item index: " + i); Trace.WriteLine("Clicked item index: " + i);
AccountManager.ChangeTeam(i); AccountManager.reloadData(i);
ReloadBtn(); ReloadBtn();
}; };
changeTeamItem.Items.Add(menuItem); changeTeamItem.Items.Add(menuItem);
@ -124,7 +119,7 @@ namespace Zerolauncher
private void editTeamItem_Click(object sender, RoutedEventArgs e) private void editTeamItem_Click(object sender, RoutedEventArgs e)
{ {
EditTeamDialog.CreateDailog(AccountManager.TeamName); EditTeamDialog.CreateDailog(AccountManager.teamName);
} }
private void Button_Click_3(object sender, RoutedEventArgs e) private void Button_Click_3(object sender, RoutedEventArgs e)

View File

@ -1,132 +1,155 @@
 
using System.Diagnostics;
using System.Windows.Input;
namespace Zerolauncher.Manager namespace Zerolauncher.Manager
{ {
internal static class AccountManager internal class AccountManager
{ {
static int _teamId; static int teamIndex=0;
public static string TeamName = ""; public static string teamName = "";
public static List<AccountNew>? AccountsList; public static List<Account> accountsList = new List<Account>();
public static void InitLoadData() public static void initLoadData()
{ {
_teamId = AccountData.TeamIndex; teamIndex = DataStream.dataStream.teamIndex;
foreach (var pair in GroupsData.Data) var group = DataStream.dataStream.Groups[teamIndex];
teamName = group.Name;
foreach (var acc in group.Accounts)
{ {
Trace.WriteLine(pair.Key, pair.Value); accountsList.Add(acc);
} }
TeamName = GroupsData.Data[_teamId];
AccountsList = AccountData.Data[_teamId];
} }
public static void ChangeTeam(int index) public static void reloadData(int index = -1)
{ {
_teamId = TeamManager.Index2Key(index); if (index < 0) index = teamIndex;
AccountData.TeamIndex = _teamId; var group = DataStream.dataStream.Groups[index];
TeamName = GroupsData.Data[_teamId]; if (teamIndex!=index)
if (!AccountData.Data.ContainsKey(_teamId)) {
AccountData.Data.Add(_teamId, []); teamIndex = index;
AccountsList = AccountData.Data[_teamId]; teamName = group.Name;
DataStreamNew.Save(); DataStream.dataStream.teamIndex = index;
} DataStream.write();
}
accountsList.Clear();
foreach (var acc in group.Accounts)
{
accountsList.Add(acc);
}
}
public static void SaveEdit() public static void saveEdit()
{ {
DataStreamNew.Save(); DataStream.write();
MainWindow.Instance.ReloadBtn(); MainWindow.Instance.ReloadBtn();
} }
public static bool AddAccount(AccountNew account) public static bool AddAccount(Account account)
{ {
account.GroupId = _teamId; if (TeamManager.Nick2Acc(account.nickName) != null)
AccountData.AddAccount(account); {
return false;
}
var group = DataStream.dataStream.Groups[teamIndex];
group.Accounts.Add(account);
DataStreamNew.Save(); accountsList.Add(account);
DataStream.write();
MainWindow.Instance.ReloadBtn(); MainWindow.Instance.ReloadBtn();
return true; return true;
} }
public static bool AddAccounts(AccountNew account) public static bool AddAccounts(Account account)
{ {
account.GroupId = _teamId; if (TeamManager.Nick2Acc(account.nickName) != null)
AccountData.AddAccount(account); {
return false;
}
var group = DataStream.dataStream.Groups[teamIndex];
group.Accounts.Add(account);
accountsList.Add(account);
//DataStream.write(); 不写
//MainWindow.Instance.ReloadBtn(); 不更新
return true; return true;
} }
public static void MoveAccount(int memberId, int newIndex) public static void MoveAccount(int memberId, int newIndex)
{ {
var groupId = TeamManager.Index2Key(newIndex); var group1 = DataStream.dataStream.Groups[newIndex];
if (AccountsList != null) group1.Accounts.Add(accountsList[memberId]);
{ var group = DataStream.dataStream.Groups[teamIndex];
var acc = AccountsList[memberId]; group.Accounts.RemoveAt(memberId);
AccountsList.RemoveAt(memberId); DataStream.write();
if (!AccountData.CheckGroup(groupId)) return; reloadData();
AccountData.Data[groupId].Add(acc);
}
DataStreamNew.Save();
MainWindow.Instance.ReloadBtn(); MainWindow.Instance.ReloadBtn();
} }
public static void DeleteAccount(int index) { public static void DeleteAccount(int index) {
if (AccountsList != null) var group = DataStream.dataStream.Groups[teamIndex];
{ group.Accounts.RemoveAt(index);
var nick = AccountsList[index].nickName; DataStream.write();
AccountsList.RemoveAt(index); reloadData();
AccountData.Dict.Remove(nick);
}
DataStreamNew.Save();
MainWindow.Instance.ReloadBtn(); MainWindow.Instance.ReloadBtn();
} }
public static void EditTeamName(string teamName0) public static void editTeamName(string teamName0)
{ {
TeamName = teamName0; teamName = teamName0;
GroupsData.Data[_teamId] = TeamName; var group = DataStream.dataStream.Groups[teamIndex];
DataStreamNew.Save(); group.Name = teamName;
DataStream.write();
} }
public static bool DeleteTeam() public static bool DeleteTeam()
{ {
if (GroupsData.Data.Keys.Count == 1) if (DataStream.dataStream.Groups.Count == 1)
{ {
return false; return false;
} }
AccountData.RemoveGroup(); DataStream.dataStream.Groups.RemoveAt(teamIndex);
ChangeTeam(GroupsData.Data.Keys.First()); DataStream.write();
DataStreamNew.Save(); reloadData(0);
MainWindow.Instance.ReloadBtn(); MainWindow.Instance.ReloadBtn();
return true; return true;
} }
} }
internal static class TeamManager internal class TeamManager
{ {
public static int Index2Key(int index) { return GroupsData.Data.ElementAt(index).Key; }
public static string[] GetAllTeamName() public static string[] GetAllTeamName()
{ {
return GroupsData.Data.Values.ToArray(); string[] names = new string[DataStream.dataStream.Groups.Count];
int i = 0;
foreach (var group in DataStream.dataStream.Groups)
{
names[i++] = group.Name;
}
return names;
} }
public static void AddTeam(string teamName) public static void addTeam(string teamName)
{ {
var key = GroupsData.Data.Keys.LastOrDefault() + 1; var group = new Group { Name = teamName, Accounts = new List<Account> { } };
GroupsData.Data.Add(key, teamName); DataStream.dataStream.Groups.Add(group);
DataStreamNew.Save(); DataStream.write();
} }
//运行时才能决定是否执行内联 //运行时才能决定是否执行内联
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static AccountNew? Nick2Acc(string nickName) public static Account? Nick2Acc(string nickName)
{ {
return AccountData.Dict.GetValueOrDefault(nickName); // find and return first take
foreach (var group in DataStream.dataStream.Groups)
{
foreach (var acc in group.Accounts)
{
if (acc.nickName.Equals(nickName)) return acc;
}
}
return null;
} }
} }

View File

@ -1,12 +0,0 @@

namespace Zerolauncher.Manager
{
static class BusinessManager
{
public static bool checkIsBuy()
{
return false;
}
}
}

View File

@ -12,7 +12,6 @@ namespace Zerolauncher.Manager
public const string MasterMessage = "54aeb77c47b967d22c2c1396d00d91f0"; public const string MasterMessage = "54aeb77c47b967d22c2c1396d00d91f0";
public const string SummerMessage = "037846c482eddc948612b0d0f8ed98d5"; public const string SummerMessage = "037846c482eddc948612b0d0f8ed98d5";
public const string LoveMessage = "539e3389078daa765ac0abdcc97eebce"; public const string LoveMessage = "539e3389078daa765ac0abdcc97eebce";
public const string TWMasterMessage = "3ca068a2cdb1ee85fc1152ff6cabefcd";
} }
class UpDateData class UpDateData
@ -38,7 +37,7 @@ namespace Zerolauncher.Manager
try try
{ {
client.Timeout = TimeSpan.FromMinutes(3); client.Timeout = TimeSpan.FromMinutes(3);
response = await client.GetAsync($"{StaticUrl.QMessageMain}{StaticUrl.TWMasterMessage}"); response = await client.GetAsync($"{StaticUrl.QMessageMain}{StaticUrl.MasterMessage}");
} }
catch (Exception _ex) catch (Exception _ex)
{ {

90
Manager/DataStream.cs Normal file
View File

@ -0,0 +1,90 @@
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Text;
using Newtonsoft.Json;
namespace Zerolauncher.Manager
{
class DataStream
{
private const string path = "user.data";
public static Data dataStream;
public static void Load()
{
if (File.Exists(path))
{
dataStream = JsonConvert.DeserializeObject<Data>(Encoding.UTF8.GetString(Decompress(File.ReadAllBytes(path))));
}
else
{
dataStream = JsonConvert.DeserializeObject<Data>(
"{\"teamIndex\":0,\"Groups\":[{\"Name\":\"队伍1\", \"Accounts\": [{\"providerId\":0,\"userName\":\"test\",\"userPWD\":\"test\",\"nickName\":\"测试账号\",\"serverId\":\"1\"}]}], \"ecs\": \"\"}");
}
}
public static void write()
{
string? data = JsonConvert.SerializeObject(dataStream);
//Trace.WriteLine(data);
if (data == null) return;
File.WriteAllBytes(path, CompressBytes(Encoding.UTF8.GetBytes(data)));
}
//压缩字节
//1.创建压缩的数据流
//2.设定compressStream为存放被压缩的文件流,并设定为压缩模式
//3.将需要压缩的字节写到被压缩的文件流
public static byte[] CompressBytes(byte[] bytes)
{
using (MemoryStream compressStream = new MemoryStream())
{
using (var zipStream = new GZipStream(compressStream, CompressionMode.Compress))
zipStream.Write(bytes, 0, bytes.Length);
return compressStream.ToArray();
}
}
//解压缩字节
//1.创建被压缩的数据流
//2.创建zipStream对象并传入解压的文件流
//3.创建目标流
//4.zipStream拷贝到目标流
//5.返回目标流输出字节
public static byte[] Decompress(byte[] bytes)
{
using (var compressStream = new MemoryStream(bytes))
{
using (var zipStream = new GZipStream(compressStream, CompressionMode.Decompress))
{
using (var resultStream = new MemoryStream())
{
zipStream.CopyTo(resultStream);
return resultStream.ToArray();
}
}
}
}
}
public class Account
{
public int providerId;
public string userName, userPWD, nickName, serverId;
}
class Group
{
public string Name;
public List<Account> Accounts;
}
struct Data
{
public int teamIndex;
public List<Group> Groups;
public string ecs;
}
}

View File

@ -1,276 +0,0 @@
using System.Buffers;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
namespace Zerolauncher.Manager
{
class DiyWriteSteamer()
{
ArrayBufferWriter<byte> data = new();
public void WriteInt(int value)
{
data.Write(BitConverter.GetBytes(value));
}
public void WriteString(string value)
{
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(value);
WriteInt(bytes.Length);
data.Write(bytes);
}
public byte[] GetBytes() => data.WrittenSpan.ToArray();
}
class DiyReader(byte[] data, int _offset=0)
{
public int ReadInt()
{
_offset += 4;
return BitConverter.ToInt32(data, _offset - 4);
}
public string ReadStr()
{
int lenght = ReadInt();
_offset += lenght;
return System.Text.Encoding.UTF8.GetString(data, _offset - lenght, lenght);
}
}
internal static class DataStreamNew
{
private const string Path = "users.data";
private static readonly byte[] Key = [9, 5, 33, 64, 99, 200, 66, 77];
private const int HeaderVersion = 20250228;
public static void Load()
{
if (File.Exists(Path))
{
byte[] byteArray;
using (var fs = new FileStream(Path, FileMode.Open, FileAccess.Read))
{
byteArray = new byte[fs.Length];
fs.ReadExactly(byteArray, 0, byteArray.Length);
}
ByteCry(byteArray);
byteArray = Decompress(byteArray);
{
var data = new DiyReader(byteArray);
if (data.ReadInt() != HeaderVersion)
{
OldDataUpdate(data);
return;
}
GroupsData.Init(data);
AccountData.Init(data);
}
return;
}
InitDefaultData();
}
static void OldDataUpdate(DiyReader _item)
{
InitDefaultData();
}
static void InitDefaultData()
{
Trace.WriteLine("加载初始数据");
GroupsData.InitDefaultData();
AccountData.InitDefaultData();
}
public static void Save()
{
var data = new DiyWriteSteamer();
data.WriteInt(HeaderVersion);
GroupsData.Out(data);
AccountData.Out(data);
var buffer = CompressBytes(data.GetBytes());
ByteCry(buffer);
using (FileStream file = new(Path, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
file.Seek(0, SeekOrigin.Begin);
file.Write(buffer);
}
}
static void ByteCry(byte[] data)
{
for (int i = 0; i < data.Length; i++)
{
data[i] = (byte)(data[i] ^ Key[i % Key.Length]);
}
}
//压缩字节
//1.创建压缩的数据流
//2.设定compressStream为存放被压缩的文件流,并设定为压缩模式
//3.将需要压缩的字节写到被压缩的文件流
static byte[] CompressBytes(byte[] bytes)
{
using var compressStream = new MemoryStream();
using (var zipStream = new GZipStream(compressStream, CompressionMode.Compress))
zipStream.Write(bytes, 0, bytes.Length);
return compressStream.ToArray();
}
//解压缩字节
//1.创建被压缩的数据流
//2.创建zipStream对象并传入解压的文件流
//3.创建目标流
//4.zipStream拷贝到目标流
//5.返回目标流输出字节
static byte[] Decompress(byte[] bytes)
{
using (var compressStream = new MemoryStream(bytes))
{
using (var zipStream = new GZipStream(compressStream, CompressionMode.Decompress))
{
using (var resultStream = new MemoryStream())
{
zipStream.CopyTo(resultStream);
return resultStream.ToArray();
}
}
}
}
}
public class AccountNew
{
public int GroupId, ProviderId, ServerId;
public string userName, userPWD, nickName;
}
internal static class AccountData
{
public static int TeamIndex = 0;
public static readonly Dictionary<int, List<AccountNew>> Data = [];
public static readonly Dictionary<string, AccountNew> Dict = [];
public static void Init(DiyReader data)
{
TeamIndex = data.ReadInt();
var accountCount = data.ReadInt();
for (var i = 0; i < accountCount; i++)
{
AddAccount(new AccountNew()
{
GroupId = data.ReadInt(),
ProviderId = data.ReadInt(),
ServerId = data.ReadInt(),
userName = data.ReadStr(),
userPWD = data.ReadStr(),
nickName = data.ReadStr()
});
}
}
public static void InitDefaultData()
{
AddAccount(new AccountNew()
{
GroupId = 0,
ProviderId = 0,
ServerId = 1,
userName = "test",
userPWD = "test",
nickName = "右键修改账号"
});
}
public static void AddAccount(AccountNew item)
{
var count = 0;
while (Dict.ContainsKey(item.nickName))
item.nickName += count++.ToString();
if (CheckGroup(item.GroupId))
Data[item.GroupId].Add(item);
}
public static bool CheckGroup(int groupId)
{
if (!GroupsData.Data.ContainsKey(groupId)) return false;
if (!Data.ContainsKey(groupId)) Data.Add(groupId, []);
return true;
}
public static void RemoveGroup()
{
GroupsData.Data.Remove(TeamIndex);
foreach (var item in Data[TeamIndex])
{
Dict.Remove(item.nickName);
}
Data.Remove(TeamIndex);
}
public static void Out(DiyWriteSteamer data)
{
data.WriteInt(TeamIndex);
var arr = new List<AccountNew>();
foreach (var item in Data.Values)
arr.AddRange(item);
data.WriteInt(arr.Count);
foreach (var item in arr)
{
data.WriteInt(item.GroupId);
data.WriteInt(item.ProviderId);
data.WriteInt(item.ServerId);
data.WriteString(item.userName);
data.WriteString(item.userPWD);
data.WriteString(item.nickName);
}
}
}
internal static class GroupsData
{
public static readonly Dictionary<int, string> Data = [];
public static void Init(DiyReader dataItem)
{
var count = dataItem.ReadInt();
for (var i = 0; i < count; i++)
{
Data.Add(dataItem.ReadInt(), dataItem.ReadStr());
}
}
public static void InitDefaultData()
{
Data.Add(0, "队伍1");
}
public static void Out(DiyWriteSteamer data)
{
data.WriteInt(Data.Count);
foreach (var item in Data)
{
data.WriteInt(item.Key);
data.WriteString(item.Value);
}
}
}
}

View File

@ -12,36 +12,36 @@ namespace Zerolauncher.Manager
//运行时才能决定是否执行内联 //运行时才能决定是否执行内联
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
private static string AccToKey(AccountNew account) private static string AccToKey(Account account)
{ {
return string.Format("{0}{1}{2}", account.ProviderId, account.ServerId, account.userName); return string.Format("{0}{1}{2}", account.providerId, account.serverId, account.userName);
} }
public static bool CreateGame(AccountNew account) public static bool CreateGame(Account account)
{ {
if (UpDateData.is_check == false) if (UpDateData.is_check == false)
{ {
MessageBox.Show("正在更新游戏数据请等待1-3秒喵。\n 请检查网络", "错误", MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show("正在更新游戏数据请等待1-3秒。\n 请检查网络", "错误", MessageBoxButton.OK, MessageBoxImage.Warning);
return true;
}
if (UpDateManager.state)
{
UpDateManager.DoUpdate();
return true; return true;
} }
//if (UpDateManager.state)
//{
// UpDateManager.DoUpdate();
// return true;
//}
var key = AccToKey(account); var key = AccToKey(account);
if (mGame.ContainsKey(key)) { return false; } if (mGame.ContainsKey(key)) { return false; }
if (CacheSha.errorCode != 0) { if (CacheSha.errorCode != 0) {
switch (CacheSha.errorCode) switch (CacheSha.errorCode)
{ {
case 1: case 1:
MessageBox.Show("发生网络错误==EMS。\n 请检查网络", "错误", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show("发生网络错误==EMS。\n 请检查网络", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
break; break;
case 2: case 2:
MessageBox.Show("发生游戏服务错误==EMS。\n 请联系管理员", "错误", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show("发生游戏服务错误==EMS。\n 请联系管理员", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
break; break;
default: default:
MessageBox.Show("发生未知错误==EMS。\n 请联系管理员", "错误", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show("发生未知错误==EMS。\n 请联系管理员", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
break; break;
} }
return true; return true;
@ -59,17 +59,17 @@ namespace Zerolauncher.Manager
public static bool CreateGame(int memberId) public static bool CreateGame(int memberId)
{ {
return CreateGame(AccountManager.AccountsList[memberId]); return CreateGame(AccountManager.accountsList[memberId]);
} }
public static int CheckGameState(AccountNew account) public static int CheckGameState(Account account)
{ {
var key = AccToKey(account); var key = AccToKey(account);
if (mGame.ContainsKey(key)) { return mGame[key].mHandle; } if (mGame.ContainsKey(key)) { return mGame[key].mHandle; }
return -1; return -1;
} }
public static short TurnGameSizeMini(AccountNew account) public static short TurnGameSizeMini(Account account)
{ {
var key = AccToKey(account); var key = AccToKey(account);
if (mGame.ContainsKey(key)) if (mGame.ContainsKey(key))
@ -85,7 +85,7 @@ namespace Zerolauncher.Manager
return 0; return 0;
} }
public static short TurnGameSizeNormal(AccountNew account) public static short TurnGameSizeNormal(Account account)
{ {
var key = AccToKey(account); var key = AccToKey(account);
if (mGame.ContainsKey(key)) if (mGame.ContainsKey(key))
@ -101,7 +101,7 @@ namespace Zerolauncher.Manager
return 0; return 0;
} }
public static bool ExitGame(AccountNew account) public static bool ExitGame(Account account)
{ {
var key = AccToKey(account); var key = AccToKey(account);
if (!mGame.ContainsKey(key)) { return false; } if (!mGame.ContainsKey(key)) { return false; }
@ -109,7 +109,7 @@ namespace Zerolauncher.Manager
return true; return true;
} }
public static void OnGameExit(AccountNew account) public static void OnGameExit(Account account)
{ {
mGame.Remove(AccToKey(account)); mGame.Remove(AccToKey(account));
} }
@ -125,10 +125,10 @@ namespace Zerolauncher.Manager
Process process; Process process;
string? restartUrl; string? restartUrl;
public int mHandle; public int mHandle;
public AccountNew? account; public Account? account;
string gameMode; string gameMode;
public SingleGame(AccountNew? acc, string mod = StaticHandleA.GameMode) public SingleGame(Account? acc, string mod = StaticHandleA.GameMode)
{ {
restartUrl = null; restartUrl = null;
account = acc; account = acc;
@ -136,7 +136,6 @@ namespace Zerolauncher.Manager
mHandle = 0; mHandle = 0;
process = EngineShell.CheckEngineSafe(gameMode); process = EngineShell.CheckEngineSafe(gameMode);
process.OutputDataReceived += Handle; process.OutputDataReceived += Handle;
process.ErrorDataReceived += Handle;
process.Exited += Process_Exited; process.Exited += Process_Exited;
process.Start(); process.Start();
@ -155,12 +154,11 @@ namespace Zerolauncher.Manager
private void Process_Exited(object? sender, EventArgs e) private void Process_Exited(object? sender, EventArgs e)
{ {
if (account == null) return; //Trace.WriteLine(
Trace.WriteLine( // $"Exit time : {process.ExitTime}\n" +
$"Exit time : {process.ExitTime}\n" + // $"Exit code : {process.ExitCode}\n" +
$"Exit code : {process.ExitCode}\n" + // $"Elapsed time : {Math.Round((process.ExitTime - process.StartTime).TotalMilliseconds)}");
$"Elapsed time : {Math.Round((process.ExitTime - process.StartTime).TotalMilliseconds)}"); //Trace.WriteLine($"进程已退出:{account.nickName}");
Trace.WriteLine($"进程已退出:{account.nickName}");
if (gameMode != StaticHandleA.GameMode) return; if (gameMode != StaticHandleA.GameMode) return;
if ( restartUrl == null) if ( restartUrl == null)
{ {
@ -172,6 +170,7 @@ namespace Zerolauncher.Manager
private void Handle(object sender, DataReceivedEventArgs e) private void Handle(object sender, DataReceivedEventArgs e)
{ {
Trace.WriteLine($"from client:{e.Data}");
var lines = e.Data == null? [""] : e.Data.Split(" ", 2); // 切成两半 var lines = e.Data == null? [""] : e.Data.Split(" ", 2); // 切成两半
switch (lines[0]) switch (lines[0])
{ {
@ -181,7 +180,7 @@ namespace Zerolauncher.Manager
UpDateManager.DoUpdate1(); UpDateManager.DoUpdate1();
return; return;
} }
Send($"{StaticHandleS.ShowWindow} {ServicesStaticInfo.ServicesName[account.ProviderId]}-{account.nickName}"); Send($"{StaticHandleS.ShowWindow} {ServicesStaticInfo.ServicesName[account.providerId]}-{account.nickName}");
break; break;
case StaticHandleC.StartDone: case StaticHandleC.StartDone:
if (gameMode == StaticHandleA.UpdateMode) if (gameMode == StaticHandleA.UpdateMode)
@ -194,7 +193,7 @@ namespace Zerolauncher.Manager
Task.Run(async delegate Task.Run(async delegate
{ {
if (lines[1] == "True") await Task.Delay(5000); if (lines[1] == "True") await Task.Delay(5000);
LoginManager.DoLogin(this); _ = LoginManager.DoLogin(this);
}); });
} }
else else
@ -207,7 +206,6 @@ namespace Zerolauncher.Manager
mHandle = int.Parse(lines[1]); mHandle = int.Parse(lines[1]);
break; break;
case StaticHandleC.BrowserDone: case StaticHandleC.BrowserDone:
Trace.WriteLine($"尝试让游戏退出:{account.nickName}");
restartUrl = lines[1]; restartUrl = lines[1];
Send(StaticHandleS.CloseGame); Send(StaticHandleS.CloseGame);
break; break;
@ -217,13 +215,6 @@ namespace Zerolauncher.Manager
case StaticHandleC.DownloadDone: case StaticHandleC.DownloadDone:
UpDateManager.OnDownLoadDone(lines[1]); UpDateManager.OnDownLoadDone(lines[1]);
break; break;
case StaticHandleC.TakeVerify:
var args = lines[1].Split(' ');
_ = LoginManager.DoVerify(this, args[0], args[1]);
break;
default:
Trace.WriteLine($"from client:{e.Data}");
break;
} }
} }
@ -251,29 +242,47 @@ namespace Zerolauncher.Manager
public static Process CheckEngineSafe(string mod) public static Process CheckEngineSafe(string mod)
{ {
bool is_first_luancher = EngineManager.CheckEmpy(); bool is_first_luancher = EngineManager.CheckEmpy();
#region //#region 检测代码
if (mod == StaticHandleA.UpdateMode) //if (mod == StaticHandleA.UpdateMode)
{ //{
} // if (DataStream.dataStream.ecs.Length > 10)
else if (!is_check && is_first_luancher) // {
{ // string? now_bit;
string? now_bit; // using (SHA256 sha256 = SHA256.Create())
using (SHA256 sha256 = SHA256.Create()) // {
{ // using (FileStream fileStream = File.OpenRead(engine_file))
using (FileStream fileStream = File.OpenRead(engine_file)) // {
{ // byte[] hashBytes = sha256.ComputeHash(fileStream);
byte[] hashBytes = sha256.ComputeHash(fileStream); // now_bit = BitConverter.ToString(hashBytes).Replace("-", string.Empty);
now_bit = BitConverter.ToString(hashBytes).Replace("-", string.Empty); // }
} // }
} // if (DataStream.dataStream.ecs != now_bit)
if (CacheSha.GetE() != now_bit) // {
{ // Trace.WriteLine("lalalala" + DataStream.dataStream.ecs);
Trace.WriteLine("lalalala1"); // throw new FileReadException("error esu1!");
throw new FileReadException("error esu0!"); // }
} // }
is_check = true; //}
} //else if (!is_check && is_first_luancher)
#endregion //{
// string? now_bit;
// using (SHA256 sha256 = SHA256.Create())
// {
// using (FileStream fileStream = File.OpenRead(engine_file))
// {
// byte[] hashBytes = sha256.ComputeHash(fileStream);
// now_bit = BitConverter.ToString(hashBytes).Replace("-", string.Empty);
// }
// }
// if (CacheSha.GetE() != now_bit)
// {
// Trace.WriteLine("lalalala1");
// throw new FileReadException("error esu0!");
// }
// if (DataStream.dataStream.ecs != now_bit) { DataStream.dataStream.ecs = now_bit; DataStream.write(); }
// is_check = true;
//}
//#endregion
var process = new Process var process = new Process
{ {
@ -284,9 +293,8 @@ namespace Zerolauncher.Manager
UseShellExecute = false, UseShellExecute = false,
CreateNoWindow = true, CreateNoWindow = true,
RedirectStandardInput = true, RedirectStandardInput = true,
RedirectStandardOutput = true, RedirectStandardOutput = true
RedirectStandardError = true },
},
EnableRaisingEvents = true EnableRaisingEvents = true
}; };
if (needShowTis) needShowTis = false; if (needShowTis) needShowTis = false;

View File

@ -1,9 +1,7 @@
using System.Diagnostics; using Newtonsoft.Json.Linq;
using System.Drawing; using System.Diagnostics;
using System.IO;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using Zerolauncher.util;
namespace Zerolauncher.Manager namespace Zerolauncher.Manager
{ {
@ -62,7 +60,7 @@ namespace Zerolauncher.Manager
} }
public static void DoLogin(SingleGame game) public static async Task DoLogin(SingleGame game)
{ {
var client = new HttpClient(); var client = new HttpClient();
client.DefaultRequestVersion = HttpVersion.Version20; client.DefaultRequestVersion = HttpVersion.Version20;
@ -70,51 +68,133 @@ namespace Zerolauncher.Manager
client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0"); client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0");
string? need_web = null; string? need_web = null;
client.Timeout = TimeSpan.FromSeconds(3); client.Timeout = TimeSpan.FromSeconds(3);
game.Send($"{StaticHandleS.HintText} 尝试登玩家{game.account.nickName}到{ServicesStaticInfo.ServicesName[game.account.ProviderId]}的{ServicesStaticInfo.ServerNames[game.account.ServerId]}服"); game.Send($"{StaticHandleS.HintText} 尝试登玩家{game.account.nickName}到{ServicesStaticInfo.ServicesName[game.account.providerId]}的{game.account.serverId}服");
switch (game.account.ProviderId) switch (game.account.providerId)
{ {
case 3:
case 0: case 0:
case 1: need_web = $"http://web.4399.com/stat/togame.php?target={(game.account.providerId == 3? "ddts":"ddt")}&server_id=S{game.account.serverId}";
need_web = "https://www.917play.com.tw/ddt_webserver"; {
var values = new Dictionary<string, string>
{
{ "loginFrom", "uframe" },
{ "postLoginHandler", "default" },
{ "layoutSelfAdapting", "true" },
{ "externalLogin", "qq" },
{ "displayMode", "popup" },
{ "layout", "vertical" },
{ "appId", "www_home" },
{ "mainDivId", "popup_login_div" },
{ "includeFcmInfo", "false" },
{ "userNameLabel", "4399用户名" },
{ "userNameTip", "请输入4399用户名" },
{ "welcomeTip", "欢迎回到4399" },
{ "username", game.account.userName },
{ "password", game.account.userPWD }
};
var responseString = await AssetNet(client, game, "http://ptlogin.4399.com/ptlogin/login.do?v=1", new FormUrlEncodedContent(values));
// eventHandles.__errorCallback('密码错误');
if (responseString == null) break;
if (responseString.Contains("eventHandles.__errorCallback"))
{
game.Send($"{StaticHandleS.HintText} 登录异常:{responseString.Split("eventHandles.__errorCallback('")[1].Split("'")[0]}");
break;
}
if (!game.Send($"{StaticHandleS.HintText} 登录成功,开始解析iframe")) return;
}
{
var responseString = await AssetNet(client, game, need_web);
if (responseString == null) break;
if (!responseString.Contains("name=\"game_box\""))
{
game.Send($"{StaticHandleS.HintText} 解析异常:服务器返回数据不正确");
Trace.WriteLine(responseString);
if (responseString.Contains("维护")) game.Send($"{StaticHandleS.HintText} 检测到服务器在维护中,请耐心等候官方开服");
break;
}
responseString = responseString.Split("name=\"game_box\"")[1].Split("src=\"")[1].Split("\"")[0];
HttpResponseMessage response;
try
{
response = await client.PostAsync(responseString, null);
}
catch (Exception ex)
{
game.Send($"{StaticHandleS.HintText} 网络发生错误,类型:{ex.GetType().Name.Replace(" ", "_")},消息:{ex.Message.Replace(" ", "_")}");
break;
}
responseString = await response.Content.ReadAsStringAsync();
if (game.account.providerId == 3)
{
responseString = responseString.Split("\"movie\" value='")[1].Split("'", 2)[0];
}else
{
responseString = "http://" + response.RequestMessage.RequestUri.ToString().Split("/")[2] + "/" + responseString.Split("movie\" value='")[1].Split("'")[0];
}
game.Send($"{StaticHandleS.GameSa} {responseString}");
}
need_web = null ;
break; break;
case 1:
need_web = $"http://web.7k7k.com/games/togame.php?target=ddt_7&server_id={game.account.serverId}";
{
var values = new Dictionary<string, string>
{
{ "username", game.account.userName },
{ "password", game.account.userPWD },
{"auto", "1" },
{"formtype", "index_log" }
};
var responseString = await AssetNet(client, game, "https://web.7k7k.com/source/Post.php", new FormUrlEncodedContent(values));
if (responseString == null) break;
//game.Send($"{StaticHandleS.HintText} {responseString}");
JObject jsonObj = JObject.Parse(responseString);
game.Send($"{StaticHandleS.HintText} {jsonObj["info"]}");
if ((int)jsonObj["status"] != 1) break;
if (!game.Send($"{StaticHandleS.HintText} 登录成功,开始解析iframe")) return;
}
{
HttpResponseMessage response;
try
{
response = await client.GetAsync(need_web);
}
catch (Exception ex)
{
game.Send($"{StaticHandleS.HintText} 网络发生错误,类型:{ex.GetType().Name.Replace(" ", "_")},消息:{ex.Message.Replace(" ", "_")}");
break;
}
var responseString = await response.Content.ReadAsStringAsync();
if (!responseString.Contains("movie\" value='"))
{
game.Send($"{StaticHandleS.HintText} 解析异常:服务器返回数据不正确");
if (responseString.Contains("维护")) game.Send($"{StaticHandleS.HintText} 检测到服务器在维护中,请耐心等候官方开服");
break;
}
responseString = "http://" + response.RequestMessage.RequestUri.ToString().Split("/")[2] + "/" + responseString.Split("movie\" value='")[1].Split("'")[0];
//Trace.WriteLine(responseString);
game.Send($"{StaticHandleS.GameSa} {responseString}");
}
break;
case 2:
need_web = $"http://www.wan.com/game/play/id/{game.account.serverId}";
break;
// case 3:
//need_web = $"https://web.4399.com/stat/togame.php?target=ddts&server_id=S{game.account.serverId}";
// break;
default: default:
game.Send($"{StaticHandleS.HintText} 错误。未适配的运营商:{game.account.ServerId}"); game.Send($"{StaticHandleS.HintText} 错误。未适配的运营商:{game.account.serverId}");
break; break;
} }
client.Dispose(); client.Dispose();
if (need_web == null) return; if (need_web == null) return;
//for (int i = 6; i > 0; i--) for (int i = 6; i > 0; i--)
//{ {
// await Task.Delay(1000); await Task.Delay(1000);
// if (!game.Send($"{StaticHandleS.HintText} 自动登录失败,将在{i}后启用网页登录,关闭窗口取消")) { return; } if (!game.Send($"{StaticHandleS.HintText} 自动登录失败,将在{i}后启用网页登录,关闭窗口取消")) { return; }
//} }
game.Send($"{StaticHandleS.UseBrowser} {need_web} {game.account.ProviderId + 4} {ServicesStaticInfo.ServerIds[game.account.ServerId]} {game.account.userName} {game.account.userPWD}"); game.Send($"{StaticHandleS.UseBrowser} {need_web} {game.account.providerId + 1} {game.account.serverId} {game.account.userName} {game.account.userPWD}");
}
public static async Task DoVerify(SingleGame game, string vid, string cookie)
{
var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(3);
client.DefaultRequestHeaders.Add("Cookie", cookie);
try
{
var response = await client.GetAsync($"https://www.917play.com.tw/ddt_webserver/verify?{vid}");
var bin = response.Content.ReadAsStream();
if (OnnxManager.onnxVerify == null) OnnxManager.onnxVerify = new OnnxVerify();
var verify = OnnxManager.onnxVerify.RunInference(new Bitmap(bin));
//using (var fileStream = File.Create("tmp.png"))
//{
// bin.Seek(0, SeekOrigin.Begin);//设置复制开始的地方
// bin.CopyTo(fileStream);
//}
game.Send($"{StaticHandleS.VerifyDone} {verify}");
Trace.WriteLine(verify);
}
catch (Exception ex)
{
Trace.WriteLine($"{StaticHandleS.HintText} 请求验证码时网络发生错误,类型:{ex.GetType().Name},消息:{ex.Message}");
}
} }
} }
} }

View File

@ -58,31 +58,30 @@ namespace Zerolauncher.Manager
switch (CacheSha.errorCode) switch (CacheSha.errorCode)
{ {
case 1: case 1:
MessageBox.Show("检查更新出错。\n 请检查网络", "错误", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show("检查更新出错。\n 请检查网络", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
break; break;
case 2: case 2:
MessageBox.Show("软件已停止服务或服务错误。\n 请联系管理员", "错误", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show("软件已停止服务或服务错误。\n 请联系管理员", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
break; break;
default: default:
MessageBox.Show("检查更新出错。", "错误", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show("检查更新出错。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
break; break;
} }
return; return;
} }
MessageBoxResult result = MessageBox.Show($"大厅组件需要更新\n是否更新?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning); MessageBoxResult result = MessageBox.Show($"大厅组件需要更新\n是否更新?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
if (result == MessageBoxResult.OK) if (result == MessageBoxResult.OK)
{ {
Process.Start(new ProcessStartInfo(UpDateData.lanzou + UpDateData.user_packet_url) { UseShellExecute = true }); try
// try {
// { updateProcess = new SingleGame(null, StaticHandleA.UpdateMode);
// updateProcess = new SingleGame(null, StaticHandleA.UpdateMode); return;
// return; }
// } catch (Exception _ex)
// catch (Exception _ex) {
// { MessageBox.Show("执行自动更新失败!,\n请手动访问链接重新下载大厅文件或联系管理员。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
// MessageBox.Show("执行自动更新失败!,\n请手动访问链接重新下载大厅文件或联系管理员喵。", "错误", MessageBoxButton.OK, MessageBoxImage.Error); }
//} }
}
} }
public static void DoUpdate1() public static void DoUpdate1()

View File

@ -4,23 +4,23 @@ using System.Net;
using System.Text; using System.Text;
namespace Zerolauncher.Manager namespace Zerolauncher.Manager
{ {
internal static class WebApiManager internal class WebApiManager
{ {
static readonly HttpListener Listener = new HttpListener(); static HttpListener listener = new HttpListener();
static readonly CancellationTokenSource Cts = new CancellationTokenSource(); static CancellationTokenSource cts = new CancellationTokenSource();
public static async Task StartListener() public static async Task StartListener()
{ {
Listener.Prefixes.Add("http://127.0.0.1:7233/"); listener.Prefixes.Add("http://127.0.0.1:7233/");
Listener.Start(); listener.Start();
Trace.WriteLine("Listening..."); Trace.WriteLine("Listening...");
while (!Cts.Token.IsCancellationRequested) while (!cts.Token.IsCancellationRequested)
{ {
var context = await Listener.GetContextAsync(); HttpListenerContext context = await listener.GetContextAsync();
var request = context.Request; HttpListenerRequest request = context.Request;
var response = context.Response; HttpListenerResponse response = context.Response;
var raw = request.RawUrl; var raw = request.RawUrl;
ResponseBody? rb = null; ResponesBody? rb = null;
if (raw != null && raw.Contains("?")) if (raw != null && raw.Contains("?"))
{ {
var lines = raw.Split("?"); var lines = raw.Split("?");
@ -34,79 +34,121 @@ namespace Zerolauncher.Manager
switch (lines[0]) switch (lines[0])
{ {
case "/CloseGame": case "/CloseGame":
{ {
rb = EngineManager.ExitGame(acc) ? new ResponseBody(1, 0, $"Account [{nick}] successful to close.") : new ResponseBody($"Account [{nick}] is unluacher."); if (EngineManager.ExitGame(acc))
} {
rb = new ResponesBody(1, 0, $"Account [{nick}] successful to close.");
}
else
{
rb = new ResponesBody($"Account [{nick}] is unluacher.");
break;
}
}
break; break;
case "/ToNormalSize": case "/ToNormalSize":
{
rb = EngineManager.TurnGameSizeNormal(acc) switch
{ {
2 => new ResponseBody(1, 0, $"Account [{nick}] now is normal size."), switch (EngineManager.TurnGameSizeNormal(acc))
1 => new ResponseBody(0, 0, $"Account [{nick}] is loading, please wait."), {
0 => new ResponseBody($"Account [{nick}] is unluacher."), case 2:
_ => rb rb = new ResponesBody(1, 0, $"Account [{nick}] now is normal size.");
}; break;
} case 1:
rb = new ResponesBody(0, 0, $"Account [{nick}] is loading, please wait.");
break;
case 0:
rb = new ResponesBody($"Account [{nick}] is unluacher.");
break;
}
}
break; break;
case "/ToMiniSize": case "/ToMiniSize":
{
rb = EngineManager.TurnGameSizeMini(acc) switch
{ {
2 => new ResponseBody(1, 0, $"Account [{nick}] now is mini size."), switch (EngineManager.TurnGameSizeMini(acc))
1 => new ResponseBody(0, 0, $"Account [{nick}] is loading, please wait."), {
0 => new ResponseBody($"Account [{nick}] is unluacher."), case 2:
_ => rb rb = new ResponesBody(1, 0, $"Account [{nick}] now is mini size.");
}; break;
} case 1:
rb = new ResponesBody(0, 0, $"Account [{nick}] is loading, please wait.");
break;
case 0:
rb = new ResponesBody($"Account [{nick}] is unluacher.");
break;
}
}
break; break;
case "/LoginGame": case "/LoginGame":
{ {
if (EngineManager.CreateGame(acc)) if (EngineManager.CreateGame(acc))
{ {
rb = new ResponseBody(0, 0, $"Account [{nick}] successful to start."); rb = new ResponesBody(0, 0, $"Account [{nick}] successful to start.");
} }
else else
{ {
var hwnd = EngineManager.CheckGameState(acc); int hwnd = EngineManager.CheckGameState(acc);
rb = hwnd <= 0 ? new ResponseBody(0, 0, $"Account [{nick}] is loading, please wait.") : new ResponseBody(1, hwnd, $"Account [{nick}] now is running."); if (hwnd <= 0)
{
rb = new ResponesBody(0, 0, $"Account [{nick}] is loading, please wait.");
}
else
{
rb = new ResponesBody(1, hwnd, $"Account [{nick}] now is running.");
}
} }
} }
break; break;
default: default:
rb = new ResponseBody($"commad [{lines[0]}] undefind."); rb = new ResponesBody($"commad [{lines[0]}] undefind.");
break; break;
} }
} }
else else
{ {
rb = new ResponseBody($"Account [{nick}] undefind."); rb = new ResponesBody($"Account [{nick}] undefind.");
} }
} }
else else
{ {
rb = new ResponseBody("args is missing."); rb = new ResponesBody("args is missing.");
} }
} }
rb ??= new ResponseBody(); if (rb == null)
var buffer = Encoding.UTF8.GetBytes(rb.Encode()); {
rb = new ResponesBody();
}
byte[] buffer = Encoding.UTF8.GetBytes(rb.Encode());
response.ContentLength64 = buffer.Length; response.ContentLength64 = buffer.Length;
var output = response.OutputStream; Stream output = response.OutputStream;
await output.WriteAsync(buffer, 0, buffer.Length); await output.WriteAsync(buffer, 0, buffer.Length);
output.Close(); output.Close();
} }
Listener.Stop(); listener.Stop();
} }
public static void StopListener() { Cts.Cancel(); } public static void StopListener() { cts.Cancel(); }
} }
class ResponseBody(int status = -1, int hwnd = 0, string message = "Hello, World!") class ResponesBody
{ {
public ResponseBody(string message) : this(-1, 0, message) public int status;
public int hwnd;
public string message;
public ResponesBody(string message)
{ {
this.status = -1;
this.hwnd = 0;
this.message = message;
}
public ResponesBody(int status=-1, int hwnd=0, string message= "Hello, World!")
{
this.status = status;
this.hwnd = hwnd;
this.message = message;
} }
public string Encode() public string Encode()

View File

@ -2,9 +2,7 @@
{ {
class ServicesStaticInfo class ServicesStaticInfo
{ {
public static string[] ServicesName = ["61平台"]; public static string[] ServicesName = ["4399大区", "7k7k大区", "第七大道", "4399经典"];
public static string[] ServicesShortName = ["61"]; public static string[] ServicesShortName = ["43", "7k", "7d", "典"];
public static string[] ServerNames = ["請選擇伺服器", "星之城", "夢之船(合併)", "謎之峽(合併)", "喵之影(合併)", "龍之吼"]; }
public static int[] ServerIds = [ 0, 1, 2, 34, 38, 44 ];
}
} }

View File

@ -1,34 +1,34 @@
namespace Zerolauncher namespace Zerolauncher
{ {
class StaticHandleS class StaticHandleS
{ {
public const string ShowWindow = "a0"; public const string ShowWindow = "a0";
public const string HintText = "b0"; public const string HintText = "b0";
public const string MiniSize = "c0"; public const string MiniSize = "c0";
public const string NormalSize = "d0"; public const string NormalSize = "d0";
public const string UseBrowser = "e0"; public const string UseBrowser = "e0";
public const string GameSa = "f0"; public const string GameSa = "f0";
public const string CloseGame = "g0"; public const string CloseGame = "g0";
public const string UpdateInfo = "h0"; public const string UpdateInfo = "h0";
public const string VerifyDone = "i0"; public const string VerifyDone = "i0";
} }
class StaticHandleC class StaticHandleC
{ {
public const string LoadDone = "0a"; public const string LoadDone = "0a";
public const string StartDone = "0b"; public const string StartDone = "0b";
public const string BrowserDone = "0c"; public const string BrowserDone = "0c";
public const string StartGame = "0d"; public const string StartGame = "0d";
public const string GameDone = "0e"; public const string GameDone = "0e";
public const string Version = "0f"; public const string Version = "0f";
public const string DownloadDone = "0g"; public const string DownloadDone = "0g";
public const string TakeVerify = "0i"; public const string TakeVerify = "0i";
} }
class StaticHandleA class StaticHandleA
{ {
public const string GameMode = "0a"; public const string GameMode = "0a";
public const string UpdateMode = "0b"; public const string UpdateMode = "0b";
public const string VersionMode = "0c"; public const string VersionMode = "0c";
} }
} }

View File

@ -9,7 +9,6 @@
<ApplicationIcon>res\title.ico</ApplicationIcon> <ApplicationIcon>res\title.ico</ApplicationIcon>
<Obfuscate>true</Obfuscate> <Obfuscate>true</Obfuscate>
<ConfuserReplaceOutput>true</ConfuserReplaceOutput> <ConfuserReplaceOutput>true</ConfuserReplaceOutput>
<StartupObject>Zerolauncher.App</StartupObject>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@ -47,10 +46,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Downloader" Version="3.0.6" /> <PackageReference Include="Downloader" Version="3.0.6" />
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.17.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Drawing.Common" Version="8.0.4" />
<PackageReference Include="System.Management" Version="8.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -68,9 +64,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="plugin\model.bin">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ZeroEngine.exe"> <None Update="ZeroEngine.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>

View File

@ -1,200 +0,0 @@
Subject: [PATCH] clean up code
---
Index: Manager/WebApiManager.cs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Manager/WebApiManager.cs b/Manager/WebApiManager.cs
--- a/Manager/WebApiManager.cs (revision 5129f68dadfebc3477fa29452cc914fcbcbb0106)
+++ b/Manager/WebApiManager.cs (revision cc94e7fcc8edfcb500c176ec8e111d0f8ca98866)
@@ -4,23 +4,23 @@
using System.Text;
namespace Zerolauncher.Manager
{
- internal class WebApiManager
+ internal static class WebApiManager
{
- static HttpListener listener = new HttpListener();
- static CancellationTokenSource cts = new CancellationTokenSource();
+ static readonly HttpListener Listener = new HttpListener();
+ static readonly CancellationTokenSource Cts = new CancellationTokenSource();
public static async Task StartListener()
{
- listener.Prefixes.Add("http://127.0.0.1:7233/");
- listener.Start();
+ Listener.Prefixes.Add("http://127.0.0.1:7233/");
+ Listener.Start();
Trace.WriteLine("Listening...");
- while (!cts.Token.IsCancellationRequested)
+ while (!Cts.Token.IsCancellationRequested)
{
- HttpListenerContext context = await listener.GetContextAsync();
- HttpListenerRequest request = context.Request;
- HttpListenerResponse response = context.Response;
+ var context = await Listener.GetContextAsync();
+ var request = context.Request;
+ var response = context.Response;
var raw = request.RawUrl;
- ResponesBody? rb = null;
+ ResponseBody? rb = null;
if (raw != null && raw.Contains("?"))
{
var lines = raw.Split("?");
@@ -34,121 +34,79 @@
switch (lines[0])
{
case "/CloseGame":
- {
- if (EngineManager.ExitGame(acc))
- {
- rb = new ResponesBody(1, 0, $"Account [{nick}] successful to close.");
- }
- else
- {
- rb = new ResponesBody($"Account [{nick}] is unluacher.");
- break;
- }
- }
+ {
+ rb = EngineManager.ExitGame(acc) ? new ResponseBody(1, 0, $"Account [{nick}] successful to close.") : new ResponseBody($"Account [{nick}] is unluacher.");
+ }
break;
case "/ToNormalSize":
- {
- switch (EngineManager.TurnGameSizeNormal(acc))
- {
- case 2:
- rb = new ResponesBody(1, 0, $"Account [{nick}] now is normal size.");
- break;
- case 1:
- rb = new ResponesBody(0, 0, $"Account [{nick}] is loading, please wait.");
- break;
- case 0:
- rb = new ResponesBody($"Account [{nick}] is unluacher.");
- break;
- }
- }
+ {
+ rb = EngineManager.TurnGameSizeNormal(acc) switch
+ {
+ 2 => new ResponseBody(1, 0, $"Account [{nick}] now is normal size."),
+ 1 => new ResponseBody(0, 0, $"Account [{nick}] is loading, please wait."),
+ 0 => new ResponseBody($"Account [{nick}] is unluacher."),
+ _ => rb
+ };
+ }
break;
case "/ToMiniSize":
- {
- switch (EngineManager.TurnGameSizeMini(acc))
- {
- case 2:
- rb = new ResponesBody(1, 0, $"Account [{nick}] now is mini size.");
- break;
- case 1:
- rb = new ResponesBody(0, 0, $"Account [{nick}] is loading, please wait.");
- break;
- case 0:
- rb = new ResponesBody($"Account [{nick}] is unluacher.");
- break;
- }
- }
+ {
+ rb = EngineManager.TurnGameSizeMini(acc) switch
+ {
+ 2 => new ResponseBody(1, 0, $"Account [{nick}] now is mini size."),
+ 1 => new ResponseBody(0, 0, $"Account [{nick}] is loading, please wait."),
+ 0 => new ResponseBody($"Account [{nick}] is unluacher."),
+ _ => rb
+ };
+ }
break;
case "/LoginGame":
{
if (EngineManager.CreateGame(acc))
{
- rb = new ResponesBody(0, 0, $"Account [{nick}] successful to start.");
+ rb = new ResponseBody(0, 0, $"Account [{nick}] successful to start.");
}
else
{
- int hwnd = EngineManager.CheckGameState(acc);
- if (hwnd <= 0)
- {
- rb = new ResponesBody(0, 0, $"Account [{nick}] is loading, please wait.");
- }
- else
- {
- rb = new ResponesBody(1, hwnd, $"Account [{nick}] now is running.");
- }
+ var hwnd = EngineManager.CheckGameState(acc);
+ rb = hwnd <= 0 ? new ResponseBody(0, 0, $"Account [{nick}] is loading, please wait.") : new ResponseBody(1, hwnd, $"Account [{nick}] now is running.");
}
}
break;
default:
- rb = new ResponesBody($"commad [{lines[0]}] undefind.");
+ rb = new ResponseBody($"commad [{lines[0]}] undefind.");
break;
}
}
else
{
- rb = new ResponesBody($"Account [{nick}] undefind.");
+ rb = new ResponseBody($"Account [{nick}] undefind.");
}
}
else
{
- rb = new ResponesBody("args is missing.");
+ rb = new ResponseBody("args is missing.");
}
}
- if (rb == null)
- {
- rb = new ResponesBody();
- }
- byte[] buffer = Encoding.UTF8.GetBytes(rb.Encode());
+ rb ??= new ResponseBody();
+ var buffer = Encoding.UTF8.GetBytes(rb.Encode());
response.ContentLength64 = buffer.Length;
- Stream output = response.OutputStream;
+ var output = response.OutputStream;
await output.WriteAsync(buffer, 0, buffer.Length);
output.Close();
}
- listener.Stop();
+ Listener.Stop();
}
- public static void StopListener() { cts.Cancel(); }
+ public static void StopListener() { Cts.Cancel(); }
}
- class ResponesBody
+ class ResponseBody(int status = -1, int hwnd = 0, string message = "Hello, World!")
{
- public int status;
- public int hwnd;
- public string message;
-
- public ResponesBody(string message)
+ public ResponseBody(string message) : this(-1, 0, message)
{
- this.status = -1;
- this.hwnd = 0;
- this.message = message;
- }
-
- public ResponesBody(int status=-1, int hwnd=0, string message= "Hello, World!")
- {
- this.status = status;
- this.hwnd = hwnd;
- this.message = message;
}
public string Encode()

View File

@ -5,9 +5,10 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="75" d:DesignWidth="65" Margin="5"> d:DesignHeight="75" d:DesignWidth="65" Margin="5">
<Grid>
<DockPanel> <DockPanel>
<Image Name="icon" DockPanel.Dock="Top" Source="/res/player_ico1.png" Width="60" Height="60"/> <Image Name="icon" DockPanel.Dock="Top" Source="/res/player_ico1.png" Width="60" Height="60"/>
<Label Name="text" DockPanel.Dock="Bottom" Content="43-测试账号" FontSize="9" Padding="0" Width="65"/> <Label Name="text" DockPanel.Dock="Bottom" Content="43-测试账号" FontSize="9" Padding="0" Width="65"/>
</DockPanel> </DockPanel>
</Grid>
</UserControl> </UserControl>

View File

@ -27,17 +27,35 @@
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<!--<Button x:Name="btn_diy" Content="自定义图片"/>--> <Button x:Name="btn_diy" Content="自定义图片"/>
<Button x:Name="btn_clut" Content="截取游戏" Grid.Row="1"/>
<Image Grid.Column="1" Grid.RowSpan="2" Source="/res/player_ico1.png"/> <Image Grid.Column="1" Grid.RowSpan="2" Source="/res/player_ico1.png"/>
</Grid> </Grid>
<DockPanel Grid.ColumnSpan="1" Margin="2"> <DockPanel Grid.ColumnSpan="1" Margin="2">
<Label Content="运营商:" Foreground="White"/> <Label Content="运营商:" Foreground="White"/>
<ComboBox Name="cb_pid"/> <ComboBox Name="cb_pid"/>
</DockPanel> </DockPanel>
<DockPanel Grid.Row="1" Margin="2"> <TextBox Name="edit_sid" Grid.Row="1" Margin="10,3,50,3" SelectionTextBrush="#4CFFFFFF">
<Label Content="服务器:" Foreground="White"/> <TextBox.Resources>
<ComboBox Name="cb_sid"/> <VisualBrush x:Key="HelpBrush" TileMode="None" Opacity="0.7" Stretch="None" AlignmentX="Left">
</DockPanel> <VisualBrush.Visual>
<TextBlock FontStyle="Italic" Text="请输入区服" Foreground="Cyan"/>
</VisualBrush.Visual>
</VisualBrush>
</TextBox.Resources>
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<Trigger Property="Text" Value="{x:Null}">
<Setter Property="Background" Value="{StaticResource HelpBrush}"/>
</Trigger>
<Trigger Property="Text" Value="">
<Setter Property="Background" Value="{StaticResource HelpBrush}"/>
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<TextBox Name="edit_acc" Grid.Row="2" Grid.ColumnSpan="2" Margin="10,2,50,2" SelectionTextBrush="#07FFFFFF"> <TextBox Name="edit_acc" Grid.Row="2" Grid.ColumnSpan="2" Margin="10,2,50,2" SelectionTextBrush="#07FFFFFF">
<TextBox.Resources> <TextBox.Resources>
<VisualBrush x:Key="HelpBrush" TileMode="None" Opacity="0.7" Stretch="None" AlignmentX="Left"> <VisualBrush x:Key="HelpBrush" TileMode="None" Opacity="0.7" Stretch="None" AlignmentX="Left">

View File

@ -23,23 +23,26 @@ namespace Zerolauncher.dialog
} }
InitializeComponent(); InitializeComponent();
cb_pid.ItemsSource = _services; cb_pid.ItemsSource = _services;
cb_sid.ItemsSource = ServicesStaticInfo.ServerNames; if(EditMemberDialog.member != null)
if (EditMemberDialog.member != null)
{ {
int index = (int)EditMemberDialog.member; int index = (int)EditMemberDialog.member;
var acc = AccountManager.AccountsList[index]; var acc = AccountManager.accountsList[index];
cb_pid.SelectedIndex = acc.ProviderId; cb_pid.SelectedIndex = acc.providerId;
cb_sid.SelectedIndex = acc.ServerId; edit_sid.Text = acc.serverId;
edit_acc.Text = acc.userName; edit_acc.Text = acc.userName;
edit_pwd.Password = acc.userPWD; edit_pwd.Password = acc.userPWD;
edit_nick.Text = acc.nickName; edit_nick.Text = acc.nickName;
} }
return;
cb_pid.SelectedIndex = 0; // 私服用
cb_pid.IsEditable = false; if (ServicesStaticInfo.ServicesName.Length == 1)
{
} cb_pid.SelectedIndex = 0;
edit_sid.Text = "1";
cb_pid.IsEditable = false;
edit_sid.IsEnabled = false;
}
}
private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e) private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{ {
@ -57,29 +60,30 @@ namespace Zerolauncher.dialog
private void Button_Click(object sender, RoutedEventArgs e) private void Button_Click(object sender, RoutedEventArgs e)
{ {
if (string.IsNullOrEmpty(cb_pid.Text) || cb_sid.SelectedIndex == 0 || string.IsNullOrEmpty(edit_acc.Text) || string.IsNullOrEmpty(edit_pwd.Password) || string.IsNullOrEmpty(edit_nick.Text)) if (string.IsNullOrEmpty(cb_pid.Text) || string.IsNullOrEmpty(edit_sid.Text) || string.IsNullOrEmpty(edit_acc.Text) || string.IsNullOrEmpty(edit_pwd.Password) || string.IsNullOrEmpty(edit_nick.Text))
{ {
MessageBox.Show("所有选项均不能为空!", "提示"); MessageBox.Show("所有选项均不能为空!", "提示");
return; return;
} }
if (EditMemberDialog.member == null) if (EditMemberDialog.member == null)
{ {
AccountManager.AddAccount(new AccountNew { ProviderId = cb_pid.SelectedIndex, ServerId = cb_sid.SelectedIndex, userName = edit_acc.Text, userPWD = edit_pwd.Password, nickName = edit_nick.Text }); AccountManager.AddAccount(new Account { providerId = cb_pid.SelectedIndex, serverId = edit_sid.Text, userName = edit_acc.Text, userPWD = edit_pwd.Password, nickName = edit_nick.Text });
EditMemberDialog.Close(); EditMemberDialog.Close();
return; return;
} }
int index = (int)EditMemberDialog.member; int index = (int)EditMemberDialog.member;
var acc = AccountManager.AccountsList[index]; var acc = AccountManager.accountsList[index];
acc.ProviderId = cb_pid.SelectedIndex; acc.providerId = cb_pid.SelectedIndex;
acc.ServerId = cb_sid.SelectedIndex; acc.serverId = edit_sid.Text;
acc.userName = edit_acc.Text; acc.userName = edit_acc.Text;
acc.userPWD = edit_pwd.Password; acc.userPWD = edit_pwd.Password;
acc.nickName = edit_nick.Text; acc.nickName = edit_nick.Text;
AccountManager.SaveEdit(); AccountManager.saveEdit();
EditMemberDialog.Close(); EditMemberDialog.Close();
return; return;
} }
} }
} }

View File

@ -22,24 +22,21 @@ namespace Zerolauncher.dialog
{ {
if(string.IsNullOrEmpty(edit_name.Text)) if(string.IsNullOrEmpty(edit_name.Text))
{ {
MessageBox.Show("昵称不能为空!", "提示"); MessageBox.Show("昵称不能为空!", "提示");
return; return;
} }
if (isEditModle) AccountManager.EditTeamName(edit_name.Text); else TeamManager.AddTeam(edit_name.Text); if (isEditModle) AccountManager.editTeamName(edit_name.Text); else TeamManager.addTeam(edit_name.Text);
EditTeamDialog.Close(); EditTeamDialog.Close();
} }
private void Button_Click_1(object sender, RoutedEventArgs e) private void Button_Click_1(object sender, RoutedEventArgs e)
{ {
MessageBoxResult result = MessageBox.Show("放生此队伍以及队伍里所有的账号\n为你带来114514点功德\n要执行此操作喵", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel); MessageBoxResult result = MessageBox.Show("即将放生此队伍以及队伍里所有的账号\n将会为你带来114点功德\n您确定要执行此操作吗", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel);
if (result == MessageBoxResult.OK) if (result == MessageBoxResult.OK)
{ {
if (!AccountManager.DeleteTeam()) if (!AccountManager.DeleteTeam()) MessageBox.Show("少爷这已经是最后一个队伍了!\n请新建一个队伍后再放生这个吧~", "提示");
{
MessageBox.Show("已经是最后一个队伍了喵!\n新建一个队伍后再放生这个~", "提示");
}
else EditTeamDialog.Close(); else EditTeamDialog.Close();
} }
} }
} }

View File

@ -1,60 +0,0 @@
<Window x:Class="Zerolauncher.dialog.RegDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="注册账号.."
MinHeight="200"
MinWidth="300"
SizeToContent="WidthAndHeight"
ResizeMode="NoResize"
ShowInTaskbar="False"
WindowStartupLocation="CenterOwner"
FocusManager.FocusedElement="{Binding ElementName=leftMarginTextBox}">
<Grid Margin="10">
<Grid.Resources>
<!-- Default settings for controls -->
<Style TargetType="{x:Type Label}">
<Setter Property="Margin" Value="0,3,5,5" />
<Setter Property="Padding" Value="0,0,0,5" />
</Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="0,0,0,5" />
</Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Width" Value="70" />
<Setter Property="Height" Value="25" />
<Setter Property="Margin" Value="5,0,0,0" />
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<!-- Left,Top,Right,Bottom margins-->
<Button Width="200" Margin="0, 0, 0, 30" Height="50" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Grid.RowSpan="2" Click="FleshPic">
<Image x:Name="CapPic" Source="/res/captcha.jpg"/>
</Button>
<Label Grid.Column="0" Grid.Row="2">验证码:</Label>
<TextBox Name="RightMarginTextBox" Grid.Column="1" Grid.Row="2" />
<Label Grid.Column="0" Grid.Row="3">注册邮箱:</Label>
<TextBox Name="BottomMarginTextBox" Grid.Column="1" Grid.Row="3" />
<!-- Accept or Cancel -->
<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Name="OkButton" IsDefault="True" Click="okButton_Click" >确定</Button>
<Button Name="CancelButton" IsCancel="True" Click="cancelButton_Click">取消</Button>
</StackPanel>
</Grid >
</Window>

View File

@ -1,94 +0,0 @@
using Newtonsoft.Json.Linq;
using System.Net.Http;
using System.Windows;
using System.Windows.Media.Imaging;
using Zerolauncher.Manager;
namespace Zerolauncher.dialog
{
/// <summary>
/// RegDialog.xaml 的交互逻辑
/// </summary>
public partial class RegDialog : Window
{
private HttpClient client;
private string user;
private string password;
public RegDialog(String acc, String pwd)
{
user = acc;
password = pwd;
InitializeComponent();
client = new();
FleshPic(null, null);
}
private async void FleshPic(object _, RoutedEventArgs e)
{
// var main_ip = UpDateData.game_url;
// HttpResponseMessage? response = null;
// try
// {
// response = await client.GetAsync($"http://{main_ip}/module/captcha.php");
// if (response != null)
// {
// foreach (var item in response.Headers)
// Console.WriteLine($"{item.Key}");
// }
// //var bin = response.Content.ReadAsStream();
// //verify = ocr.RunInference(new Bitmap(bin));
// //using (var fileStream = File.Create("tmp.png"))
// //{
// // bin.Seek(0, SeekOrigin.Begin);//设置复制开始的地方
// // bin.CopyTo(fileStream);
// //}
// using (var stream = response.Content.ReadAsStream())
// {
// BitmapImage bitmap = new BitmapImage();
// bitmap.BeginInit();
// bitmap.CacheOption = BitmapCacheOption.OnLoad;
// bitmap.StreamSource = stream;
// bitmap.EndInit();
// bitmap.Freeze(); // 为了线程安全
//
// CapPic.Source = bitmap; // 设置Image控件的Source
// }
// }
// catch (Exception ex)
// {
// Console.WriteLine($" 网络发生错误,类型:{ex.GetType().Name},消息:{ex.Message}");
// }
}
private async void okButton_Click(object _, RoutedEventArgs e)
{
// var main_ip = UpDateData.game_url;
// var values = new Dictionary<string, string>
// {
// { "rUsername", user },
// { "rPassword", password },
// { "rPasswords", password },
// { "rEmail", BottomMarginTextBox.Text },
// { "rCode", RightMarginTextBox.Text }
// };
// var content = new FormUrlEncodedContent(values);
// try
// {
// var response = await client.PostAsync($"http://{main_ip}/form/register.php", content);
// var src = await response.Content.ReadAsStringAsync();
// var jsonObj = JObject.Parse(src);
// MessageBox.Show(jsonObj["content"].ToString(), jsonObj["title"].ToString());
// if(int.Parse(jsonObj["type"].ToString()) == 0) Close();
// }
// catch (Exception ex)
// {
// MessageBox.Show($"类型:{ex.GetType().Name},消息:{ex.Message}", "发生错误喵");
// }
}
private void cancelButton_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}

View File

@ -9,7 +9,7 @@
<TextBlock DockPanel.Dock="Top" Margin="5" Text="文本格式:一行一个账号,如:&#x0a; 服务器---区号---账号---密码---备注&#x0a;服务器填代号:&#x0a; 如[0, 4399大区]意味着4399大区的代号是0&#x0a; 具体查看添加账号时,以列表显示的为准" Foreground="#FFB44242"/> <TextBlock DockPanel.Dock="Top" Margin="5" Text="文本格式:一行一个账号,如:&#x0a; 服务器---区号---账号---密码---备注&#x0a;服务器填代号:&#x0a; 如[0, 4399大区]意味着4399大区的代号是0&#x0a; 具体查看添加账号时,以列表显示的为准" Foreground="#FFB44242"/>
<DockPanel DockPanel.Dock="Bottom"> <DockPanel DockPanel.Dock="Bottom">
<Button DockPanel.Dock="Right" Content="选择文件" Click="Button_Click"/> <Button DockPanel.Dock="Right" Content="选择文件" Click="Button_Click"/>
<TextBox Name="InputSplit" DockPanel.Dock="Right" Text="---" Width="100"/> <TextBox Name="input_split" DockPanel.Dock="Right" Text="---" Width="100"/>
<TextBlock DockPanel.Dock="Right" Text="分隔符:" Foreground="#FFEE9595"/> <TextBlock DockPanel.Dock="Right" Text="分隔符:" Foreground="#FFEE9595"/>
<Label/> <Label/>
</DockPanel> </DockPanel>

View File

@ -2,6 +2,7 @@
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using Zerolauncher.Manager; using Zerolauncher.Manager;
namespace Zerolauncher.dialog namespace Zerolauncher.dialog
@ -9,7 +10,7 @@ namespace Zerolauncher.dialog
/// <summary> /// <summary>
/// UseAccDataTextAdd.xaml 的交互逻辑 /// UseAccDataTextAdd.xaml 的交互逻辑
/// </summary> /// </summary>
public partial class UseAccDataTextAdd public partial class UseAccDataTextAdd : UserControl
{ {
public UseAccDataTextAdd() public UseAccDataTextAdd()
{ {
@ -19,55 +20,45 @@ namespace Zerolauncher.dialog
private void Button_Click(object sender, RoutedEventArgs e) private void Button_Click(object sender, RoutedEventArgs e)
{ {
//创建一个打开文件式的对话框 //创建一个打开文件式的对话框
var ofd = new OpenFileDialog OpenFileDialog ofd = new OpenFileDialog();
{ //设置这个对话框的起始打开路径
//设置这个对话框的起始打开路径 ofd.InitialDirectory = @"C:\";
InitialDirectory = @"C:\", //设置打开的文件的类型,注意过滤器的语法
//设置打开的文件的类型,注意过滤器的语法 ofd.Filter = "账号文本|*.txt|其他格式|*.";
Filter = "账号文本|*.txt|其他格式|*."
};
//调用ShowDialog()方法显示该对话框,该方法的返回值代表用户是否点击了确定按钮 //调用ShowDialog()方法显示该对话框,该方法的返回值代表用户是否点击了确定按钮
if (ofd.ShowDialog() == true) if (ofd.ShowDialog() == true)
{ {
var lines = File.ReadAllLines(ofd.FileName, Encoding.UTF8); string[] lines = File.ReadAllLines(ofd.FileName, Encoding.UTF8);
for (var i = 0; i < lines.Length; i++) for (int i = 0; i < lines.Length; i++)
{ {
var accTexts = lines[i].Split(InputSplit.Text); var accTexts = lines[i].Split(input_split.Text);
if (accTexts.Length != 5) if (accTexts.Length != 5)
{ {
MessageBox.Show($"文本在{i}行非法\n{lines[i]}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show($"文本在{i}行非法\n{lines[i]}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return; return;
} }
var acc = new AccountNew { }; var acc = new Account { };
if (!int.TryParse(accTexts[0], out acc.ProviderId)) if (!int.TryParse(accTexts[0], out acc.providerId))
{ {
MessageBox.Show($"输入的服务器代号错误!在{i}行\n错误[{lines[i]}]无法转换成服务器代号", "Error", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show($"输入的服务器代号错误!在{i}行\n错误[{lines[i]}]无法转换成服务器代号", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return; return;
} }
if(0 < acc.ProviderId || acc.ProviderId > ServicesStaticInfo.ServicesName.Length) if(0 < acc.providerId || acc.providerId > ServicesStaticInfo.ServicesName.Length)
{ {
MessageBox.Show($"输入的服务器代号错误喵!在{i}行\n错误[{acc.ProviderId}]不是有效的服务器代号", "Error", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show($"输入的服务器代号错误!在{i}行\n错误[{acc.providerId}]不是有效的服务器代号", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
if (!int.TryParse(accTexts[1], out acc.ServerId))
{
MessageBox.Show($"输入的服务器代号错误喵!在{i}行\n错误[{lines[i]}]无法转换成服务器代号", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
if (0 < acc.ProviderId || acc.ProviderId > ServicesStaticInfo.ServerIds.Length)
{
MessageBox.Show($"输入的服务器代号错误喵!在{i}行\n错误[{acc.ProviderId}]不是有效的服务器代号", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return; return;
} }
acc.serverId = accTexts[1];
acc.userName = accTexts[2]; acc.userName = accTexts[2];
acc.userPWD = accTexts[3]; acc.userPWD = accTexts[3];
acc.nickName = accTexts[4]; acc.nickName = accTexts[4];
if (AccountManager.AddAccounts(acc)) continue; if (!AccountManager.AddAccounts(acc))
MessageBox.Show($"文本在{i}行出错喵!\n警告[{acc.nickName}]昵称冲突,将跳过添加此账号", "Warring", MessageBoxButton.OK, MessageBoxImage.Error); {
return; MessageBox.Show($"文本在{i}行出错!\n警告[{acc.nickName}]昵称冲突,将跳过添加此账号", "Warring", MessageBoxButton.OK, MessageBoxImage.Error);
}
} }
MessageBox.Show("添加完成", "提示"); MessageBox.Show("添加完成", "提示");
AccountManager.SaveEdit(); AccountManager.saveEdit();
AddMemebersDialog.Close(); AddMemebersDialog.Close();
} }
else else

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -1,99 +0,0 @@
using Microsoft.ML.OnnxRuntime.Tensors;
using Microsoft.ML.OnnxRuntime;
using System.Diagnostics;
using System.Text;
using System.Drawing;
namespace Zerolauncher.util
{
public class OnnxManager
{
public static OnnxVerify? onnxVerify;
}
public class OnnxVerify
{
private string _modelPath;
private InferenceSession _session;
private readonly string _inputName;
static string[] labels = [
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
];
public OnnxVerify(string modelPath = "plugin/model.bin")
{
_modelPath = modelPath;
_session = new InferenceSession(_modelPath);
// 获取模型的输入节点名称
_inputName = _session.InputMetadata.Keys.First();
}
public string RunInference(Bitmap image)
{
var tensor = CtcPreprocess(image, (3, 48, 320));
var inputs = new List<NamedOnnxValue> { NamedOnnxValue.CreateFromTensor(_inputName, tensor) };
using var results = _session.Run(inputs);
var outputs = results.First().AsTensor<float>();
var dimensions = outputs.Dimensions;
var sb = new StringBuilder();
float tmp; int tmp_index, last_index = -1;
for (int j = 0; j < dimensions[1]; j++)
{
tmp = 0; tmp_index = 0;
for (int k = 0; k < dimensions[2]; k++)
{
var tmp1 = outputs[0, j, k];
if (tmp < tmp1) { tmp = tmp1; tmp_index = k; }
}
if (tmp_index == 0 || last_index == tmp_index)
{
// 试着过滤一下重复的字符假设最大重复长度为2
last_index = -1;
continue;
}
last_index = tmp_index;
sb.Append(labels[tmp_index - 1]);
}
return sb.ToString();
}
static DenseTensor<float> CtcPreprocess(Bitmap image, (int, int, int) recImageShape)
{
var (imgC, imgH, imgW) = recImageShape;
var maxWhRatio = imgW / (float)imgH;
var h = image.Height;
var w = image.Width;
var whRatio = w * 1.0f / h;
maxWhRatio = Math.Max(maxWhRatio, whRatio);
Debug.Assert(imgC == 3); // Assuming the image is in RGB format
imgW = (int)(imgH * maxWhRatio);
var ratio = w / (float)h;
var resizedW = Math.Ceiling(imgH * ratio) > imgW ? imgW : (int)Math.Ceiling(imgH * ratio);
var resizedImage = new Bitmap(image, new Size(resizedW, imgH));
var paddingIm = new DenseTensor<float>([1, imgC, imgH, imgW]);
for (int i = 0; i < resizedW; i++)
{
for (int j = 0; j < imgH; j++)
{
var pixel = resizedImage.GetPixel(i, j);
paddingIm[0, 0, j, i] = (pixel.R / 255.0f - 0.5f) / 0.5f;
paddingIm[0, 1, j, i] = (pixel.G / 255.0f - 0.5f) / 0.5f;
paddingIm[0, 2, j, i] = (pixel.B / 255.0f - 0.5f) / 0.5f;
}
}
return paddingIm;
}
}
}

View File

@ -83,109 +83,4 @@ namespace Zerolauncher.util
return sb.ToString(); return sb.ToString();
} }
} }
class UrlEncoder
{
static readonly Dictionary<char, char> map = new Dictionary<char, char> {
{'0', (char)8194},
{'1', (char)8196},
{'2', (char)8197},
{'3', (char)8198},
{'4', (char)8199},
{'5', (char)8200},
{'6', (char)8201},
{'7', (char)8202},
{'8', (char)8239},
{'9', (char)8287},
};
static readonly Dictionary<char, char> map1 = new Dictionary<char, char>
{
{'.', (char)8192},
{':', (char)8194},
};
static readonly Dictionary<char, char> dmap1 = new Dictionary<char, char>
{
{(char)8192, '.'},
{(char)8194, ':'},
};
static readonly Dictionary<char, char> dmap = new Dictionary<char, char> {
{(char)8194, '0'},
{(char)8196, '1'},
{(char)8197, '2'},
{(char)8198, '3'},
{(char)8199, '4'},
{(char)8200, '5'},
{(char)8201, '6'},
{(char)8202, '7'},
{(char)8239, '8'},
{(char)8287, '9'},
};
static readonly char end_line = (char)8193;
static readonly char sec_char = (char)32;
public static string? Encode(string url, out int counter)
{
var sb = new StringBuilder();
sb.Append(end_line);
counter = 0;
foreach (var item in url)
{
if (map.ContainsKey(item)) sb.Append(map[item]);
else if (map1.ContainsKey(item)) { sb.Append(sec_char); sb.Append(map1[item]); }
else return null;
counter++;
}
sb.Append(end_line);
return sb.ToString();
}
public static string? Decode(string space, out int counter)
{
var sb = new StringBuilder();
counter = 0;
bool is_sec_char = false;
foreach (var item in space)
{
if (counter != 0)
{
if (item == end_line) break;
else if (is_sec_char)
{
if (!dmap1.ContainsKey(item)) return null;
sb.Append(dmap1[item]);
is_sec_char = false;
}
else if (item == sec_char) is_sec_char = true;
else if (dmap.ContainsKey(item)) sb.Append(dmap[item]);
else return null;
}
counter++;
}
return sb.ToString();
}
}
class KeyUrlEncoder
{
static readonly string key = "TestKey123456";
public static string XorEncryptDecrypt(string input)
{
char[] output = new char[input.Length];
for (int i = 0; i < input.Length; i++)
{
output[i] = (char)(input[i] ^ key[i % key.Length]);
}
return new string(output);
}
}
} }

View File

@ -1,9 +0,0 @@

namespace Zerolauncher.util
{
static class SyStemExcuteCommand
{
}
}