This commit is contained in:
BruceChen 2022-10-16 20:37:07 +08:00
parent 8d15acaef3
commit db6d6c80bf
22 changed files with 130 additions and 152 deletions

View file

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using MinecraftClient.Inventory;
using MinecraftClient.Mapping;

View file

@ -1,4 +1,5 @@
using System;
using System.Xml.Linq;
using Tomlet.Attributes;
using static MinecraftClient.ChatBots.ScriptScheduler.Configs;
@ -249,7 +250,7 @@ namespace MinecraftClient.ChatBots
task.Trigger_On_Login,
task.Trigger_On_Times.Enable,
task.Trigger_On_Interval.Enable,
task.Trigger_On_Times.Times,
string.Join(", ", Array.ConvertAll(task.Trigger_On_Times.Times, time => time.ToString())),
task.Trigger_On_Interval.MinTime + '-' + task.Trigger_On_Interval.MaxTime,
task.Action
);

View file

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using MinecraftClient.Inventory;

View file

@ -8,8 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace MinecraftClient
{
namespace MinecraftClient {
using System;
@ -23,28 +22,23 @@ namespace MinecraftClient
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class DefaultConfigResource
{
internal class DefaultConfigResource {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal DefaultConfigResource()
{
internal DefaultConfigResource() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if (object.ReferenceEquals(resourceMan, null))
{
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MinecraftClient.DefaultConfigResource", typeof(DefaultConfigResource).Assembly);
resourceMan = temp;
}
@ -57,14 +51,11 @@ namespace MinecraftClient
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set
{
set {
resourceCulture = value;
}
}
@ -84,10 +75,8 @@ namespace MinecraftClient
///║║ 5 ║ 6 ║ 7 ║ 8 ║ 9 ║10 ║11 ║12 ║13 ║║
///║╠═══╬═══╬═══╬═══╬══ [rest of string was truncated]&quot;;.
/// </summary>
internal static string ContainerType_BrewingStand
{
get
{
internal static string ContainerType_BrewingStand {
get {
return ResourceManager.GetString("ContainerType_BrewingStand", resourceCulture);
}
}
@ -107,17 +96,29 @@ namespace MinecraftClient
///║║10 ║11 ║12 ║13 ║14 ║15 ║16 ║17 ║18 ║║
///║╠═══╬═══╬═══╬═══╬══ [rest of string was truncated]&quot;;.
/// </summary>
internal static string ContainerType_Crafting
{
get
{
internal static string ContainerType_Crafting {
get {
return ResourceManager.GetString("ContainerType_Crafting", resourceCulture);
}
}
internal static string ContainerType_EnchantingTable
{
get
{
/// <summary>
/// Looks up a localized string similar to ╔═════════════════════════════════════╗
///║ Enchant ║
///║ ╔════════════════════╗ ║
///║ ║ Top ║ ║
///║ ╔═══╦═══╗ ╠════════════════════╣ ║
///║ ║ 0 ║ 1 ║ ║ Middle ║ ║
///║ ╚═══╩═══╝ ╠════════════════════╣ ║
///║ ║ Bottom ║ ║
///║ ╚════════════════════╝ ║
///║ Inventory ║
///║╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗║
///║║ 2 ║ 3 ║ 4 ║ 5 ║ 6 ║ 7 ║ 8 ║ 9 ║10 ║║
///║╠═══╬═══╬═══╬═══╬══ [rest of string was truncated]&quot;;.
/// </summary>
internal static string ContainerType_EnchantingTable {
get {
return ResourceManager.GetString("ContainerType_EnchantingTable", resourceCulture);
}
}
@ -137,10 +138,8 @@ namespace MinecraftClient
///║╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗║
///║║ 3 ║ 4 ║ 5 ║ 6 ║ 7 [rest of string was truncated]&quot;;.
/// </summary>
internal static string ContainerType_Furnace
{
get
{
internal static string ContainerType_Furnace {
get {
return ResourceManager.GetString("ContainerType_Furnace", resourceCulture);
}
}
@ -160,10 +159,8 @@ namespace MinecraftClient
///║║ 9 ║10 ║11 ║12 ║13 ║14 ║15 ║16 ║17 ║║
///║╠═══╬═══╬═══╬═══╬══ [rest of string was truncated]&quot;;.
/// </summary>
internal static string ContainerType_Generic_3x3
{
get
{
internal static string ContainerType_Generic_3x3 {
get {
return ResourceManager.GetString("ContainerType_Generic_3x3", resourceCulture);
}
}
@ -183,10 +180,8 @@ namespace MinecraftClient
///║║27 ║28 ║29 ║30 ║31 ║32 ║33 ║34 ║35 ║║
///║╠═══╬═══╬═══╬═══╬══ [rest of string was truncated]&quot;;.
/// </summary>
internal static string ContainerType_Generic_9x3
{
get
{
internal static string ContainerType_Generic_9x3 {
get {
return ResourceManager.GetString("ContainerType_Generic_9x3", resourceCulture);
}
}
@ -206,10 +201,8 @@ namespace MinecraftClient
///║║36 ║37 ║38 ║39 ║40 ║41 ║42 ║43 ║44 ║║
///║╠═══╬═══╬═══╬═══╬══ [rest of string was truncated]&quot;;.
/// </summary>
internal static string ContainerType_Generic_9x6
{
get
{
internal static string ContainerType_Generic_9x6 {
get {
return ResourceManager.GetString("ContainerType_Generic_9x6", resourceCulture);
}
}
@ -229,10 +222,8 @@ namespace MinecraftClient
///║ ╚══╝ ╚══╝ ║
///║ [rest of string was truncated]&quot;;.
/// </summary>
internal static string ContainerType_Grindstone
{
get
{
internal static string ContainerType_Grindstone {
get {
return ResourceManager.GetString("ContainerType_Grindstone", resourceCulture);
}
}
@ -252,10 +243,8 @@ namespace MinecraftClient
///║║23 ║24 ║25 ║26 ║27 ║28 ║29 ║30 ║31 ║║
///║╚═══╩═══╩═══╩═══╩══ [rest of string was truncated]&quot;;.
/// </summary>
internal static string ContainerType_Hopper
{
get
{
internal static string ContainerType_Hopper {
get {
return ResourceManager.GetString("ContainerType_Hopper", resourceCulture);
}
}
@ -275,10 +264,8 @@ namespace MinecraftClient
///║║ 9 ║10 ║11 ║12 ║13 ║14 ║15 ║16 ║17 ║║
///║╠═══╬═══╬═══╬═══╬══ [rest of string was truncated]&quot;;.
/// </summary>
internal static string ContainerType_PlayerInventory
{
get
{
internal static string ContainerType_PlayerInventory {
get {
return ResourceManager.GetString("ContainerType_PlayerInventory", resourceCulture);
}
}
@ -299,10 +286,8 @@ namespace MinecraftClient
///mcc.session_invalid=§8Gespeicherte Session ungültig oder abgelaufen.
///mcc.session_valid=§8Gespeicherte Ses [rest of string was truncated]&quot;;.
/// </summary>
internal static string Translation_de
{
get
{
internal static string Translation_de {
get {
return ResourceManager.GetString("Translation_de", resourceCulture);
}
}
@ -321,10 +306,8 @@ namespace MinecraftClient
///mcc.password_hidden=Password(invisible): {0}
///mcc.off [rest of string was truncated]&quot;;.
/// </summary>
internal static string Translation_en
{
get
{
internal static string Translation_en {
get {
return ResourceManager.GetString("Translation_en", resourceCulture);
}
}
@ -345,10 +328,8 @@ namespace MinecraftClient
///mcc.session_invalid=§8Le cache de la session est invalide ou a expiré.
///mcc.session_va [rest of string was truncated]&quot;;.
/// </summary>
internal static string Translation_fr
{
get
{
internal static string Translation_fr {
get {
return ResourceManager.GetString("Translation_fr", resourceCulture);
}
}
@ -369,10 +350,8 @@ namespace MinecraftClient
///mcc.session_invalid=§8Кэшированная сессия недействительна или истекла.
///mcc.session_valid=§8Кэшированная се [rest of string was truncated]&quot;;.
/// </summary>
internal static string Translation_ru
{
get
{
internal static string Translation_ru {
get {
return ResourceManager.GetString("Translation_ru", resourceCulture);
}
}
@ -394,10 +373,8 @@ namespace MinecraftClient
///mcc.session_valid=§8Phiên vẫn còn hợp lệ cho {0}.
///mcc.profile_ke [rest of string was truncated]&quot;;.
/// </summary>
internal static string Translation_vi
{
get
{
internal static string Translation_vi {
get {
return ResourceManager.GetString("Translation_vi", resourceCulture);
}
}
@ -420,10 +397,8 @@ namespace MinecraftClient
///mcc.profile_key_invalid=§8缓存的聊天签名密钥需要刷新。
///mcc.profile_key_valid=§8{0 [rest of string was truncated]&quot;;.
/// </summary>
internal static string Translation_zh_Hans
{
get
{
internal static string Translation_zh_Hans {
get {
return ResourceManager.GetString("Translation_zh_Hans", resourceCulture);
}
}
@ -446,10 +421,8 @@ namespace MinecraftClient
///mcc.profile_key_invalid=§8快取的聊天簽名金鑰需要重新整理。
///mcc.profile_key_valid [rest of string was truncated]&quot;;.
/// </summary>
internal static string Translation_zh_Hant
{
get
{
internal static string Translation_zh_Hant {
get {
return ResourceManager.GetString("Translation_zh_Hant", resourceCulture);
}
}

View file

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MinecraftClient.Commands;
using MinecraftClient.Protocol.Handlers;
namespace MinecraftClient.Inventory

View file

@ -4,7 +4,6 @@ using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Transactions;
using MinecraftClient.ChatBots;
using MinecraftClient.Inventory;
using MinecraftClient.Logger;

View file

@ -397,19 +397,19 @@ namespace MinecraftClient
//Asking the user to type in missing data such as Username and Password
bool useBrowser = Config.Main.General.AccountType == LoginType.microsoft && Config.Main.General.Method == LoginMethod.browser;
if (string.IsNullOrEmpty(Config.Main.General.Account.Login) && !useBrowser)
if (string.IsNullOrEmpty(InternalConfig.Login) && !useBrowser)
{
ConsoleIO.WriteLine(ConsoleIO.BasicIO ? Translations.Get("mcc.login_basic_io") : Translations.Get("mcc.login"));
Config.Main.General.Account.Login = ConsoleIO.ReadLine().Trim();
if (string.IsNullOrEmpty(Config.Main.General.Account.Login))
InternalConfig.Login = ConsoleIO.ReadLine().Trim();
if (string.IsNullOrEmpty(InternalConfig.Login))
{
HandleFailure(Translations.Get("error.login.blocked"), false, ChatBot.DisconnectReason.LoginRejected);
return;
}
}
InternalConfig.Username = Config.Main.General.Account.Login;
InternalConfig.Username = InternalConfig.Login;
if (string.IsNullOrEmpty(Config.Main.General.Account.Password) && !useBrowser &&
(Config.Main.Advanced.SessionCache == CacheType.none || !SessionCache.Contains(Settings.ToLowerIfNeed(Config.Main.General.Account.Login))))
(Config.Main.Advanced.SessionCache == CacheType.none || !SessionCache.Contains(Settings.ToLowerIfNeed(InternalConfig.Login))))
{
RequestPassword();
}
@ -427,7 +427,7 @@ namespace MinecraftClient
/// </summary>
private static void RequestPassword()
{
ConsoleIO.WriteLine(ConsoleIO.BasicIO ? Translations.Get("mcc.password_basic_io", Config.Main.General.Account.Login) + "\n" : Translations.Get("mcc.password"));
ConsoleIO.WriteLine(ConsoleIO.BasicIO ? Translations.Get("mcc.password_basic_io", InternalConfig.Login) + "\n" : Translations.Get("mcc.password"));
string? password = ConsoleIO.BasicIO ? Console.ReadLine() : ConsoleIO.ReadPassword();
if (password == null || password == string.Empty) { password = "-"; }
InternalConfig.Password = password;
@ -445,7 +445,7 @@ namespace MinecraftClient
ProtocolHandler.LoginResult result = ProtocolHandler.LoginResult.LoginRequired;
string loginLower = Settings.ToLowerIfNeed(Config.Main.General.Account.Login);
string loginLower = Settings.ToLowerIfNeed(InternalConfig.Login);
if (InternalConfig.Password == "-")
{
Translations.WriteLineFormatted("mcc.offline");
@ -488,7 +488,7 @@ namespace MinecraftClient
if (result != ProtocolHandler.LoginResult.Success)
{
Translations.WriteLine("mcc.connecting", Config.Main.General.AccountType == LoginType.mojang ? "Minecraft.net" : "Microsoft");
result = ProtocolHandler.GetLogin(Config.Main.General.Account.Login, InternalConfig.Password, Config.Main.General.AccountType, out session);
result = ProtocolHandler.GetLogin(InternalConfig.Login, InternalConfig.Password, Config.Main.General.AccountType, out session);
}
if (result == ProtocolHandler.LoginResult.Success && Config.Main.Advanced.SessionCache != CacheType.none)

View file

@ -446,9 +446,9 @@ namespace MinecraftClient.Protocol.Handlers
else
entityType = entityPalette.FromId(ReadNextByte(cache), living);
Double entityX = ReadNextDouble(cache);
Double entityY = ReadNextDouble(cache);
Double entityZ = ReadNextDouble(cache);
double entityX = ReadNextDouble(cache);
double entityY = ReadNextDouble(cache);
double entityZ = ReadNextDouble(cache);
byte entityPitch = ReadNextByte(cache);
byte entityYaw = ReadNextByte(cache);

View file

@ -535,7 +535,7 @@ namespace MinecraftClient.Protocol.Handlers
{
session.ServerIDhash = serverIDhash;
session.ServerPublicKey = serverPublicKey;
SessionCache.Store(Config.Main.General.Account.Login.ToLower(), session);
SessionCache.Store(InternalConfig.Login.ToLower(), session);
}
else
{

View file

@ -1974,7 +1974,7 @@ namespace MinecraftClient.Protocol.Handlers
{
session.ServerIDhash = serverIDhash;
session.ServerPublicKey = serverPublicKey;
SessionCache.Store(Config.Main.General.Account.Login.ToLower(), session);
SessionCache.Store(InternalConfig.Login.ToLower(), session);
}
else
{

View file

@ -603,7 +603,7 @@ namespace MinecraftClient.Protocol
session.PlayerID = profile.UUID;
session.ID = accessToken;
session.RefreshToken = msaResponse.RefreshToken;
Config.Main.General.Account.Login = msaResponse.Email;
InternalConfig.Login = msaResponse.Email;
return LoginResult.Success;
}
else

View file

@ -1,4 +1,4 @@
[mcc]
[mcc]
# Messages from MCC itself
mcc.help_us_translate=Help us translate MCC: {0}
mcc.run_with_default_settings=\nMCC is running with default settings.

View file

@ -45,6 +45,8 @@ namespace MinecraftClient
public static ushort ServerPort = 25565;
public static string Login = string.Empty;
public static string Username = string.Empty;
public static string Password = string.Empty;
@ -243,7 +245,7 @@ namespace MinecraftClient
switch (positionalIndex)
{
case 0:
Config.Main.General.Account.Login = argument;
InternalConfig.Login = argument;
break;
case 1:
InternalConfig.Password = argument;
@ -360,6 +362,7 @@ namespace MinecraftClient
General.Account.Login ??= string.Empty;
General.Account.Password ??= string.Empty;
InternalConfig.Login = General.Account.Login;
General.Server.Host ??= string.Empty;
@ -841,7 +844,7 @@ namespace MinecraftClient
switch (varname_lower)
{
case "username": result.Append(InternalConfig.Username); break;
case "login": result.Append(Settings.Config.Main.General.Account.Login); break;
case "login": result.Append(InternalConfig.Login); break;
case "serverip": result.Append(InternalConfig.ServerIP); break;
case "serverport": result.Append(InternalConfig.ServerPort); break;
case "datetime":

View file

@ -659,17 +659,21 @@ namespace MinecraftClient
string[] transEn = DefaultConfigResource.ResourceManager.GetString("Translation_en")!
.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
foreach (string lang in new string[] { "de", "fr", "ru", "vi", "zh_Hans", "zh_Hant" })
foreach (string lang in new string[] { "de", "fr", "ru", "vi", "zh-Hans", "zh-Hant" })
{
Dictionary<string, string> trans = ParseTranslationContent(
DefaultConfigResource.ResourceManager.GetString("Translation_" + lang)!
DefaultConfigResource.ResourceManager.GetString("Translation_" + lang.Replace('-', '_'), System.Globalization.CultureInfo.InvariantCulture)!
.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None)
);
string fileName = AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + translationFilePath + Path.DirectorySeparatorChar + lang + ".ini";
if (File.Exists(fileName))
{
string backupFilePath = Path.ChangeExtension(fileName, ".backup.ini");
try { File.Copy(fileName, backupFilePath, true); }
try
{
File.Copy(fileName, backupFilePath, true);
File.Delete(fileName);
}
catch (Exception ex)
{
ConsoleIO.WriteLineFormatted(Translations.TryGet("config.backup.fail", backupFilePath));
@ -677,7 +681,7 @@ namespace MinecraftClient
return;
}
}
using FileStream file = File.OpenWrite(fileName);
StringBuilder sb = new();
int total = 0, translated = 0;
for (int i = 0; i < transEn.Length; ++i)
{
@ -685,16 +689,15 @@ namespace MinecraftClient
int index = transEn[i].IndexOf('=');
if (line.Length < 3 || !char.IsLetterOrDigit(line[0]) || index == -1 || line.Length <= (index + 1))
{
file.Write(Encoding.UTF8.GetBytes(line));
sb.Append(line);
}
else
{
string key = line[..index];
file.Write(Encoding.UTF8.GetBytes(key));
file.Write(Encoding.UTF8.GetBytes("="));
sb.Append(key).Append('=');
if (trans.TryGetValue(key, out string? value))
{
file.Write(Encoding.UTF8.GetBytes(value.Replace("\n", "\\n")));
sb.Append(value.Replace("\n", "\\n"));
++total;
++translated;
}
@ -703,8 +706,9 @@ namespace MinecraftClient
++total;
}
}
file.Write(Encoding.UTF8.GetBytes(Environment.NewLine));
sb.AppendLine();
}
File.WriteAllText(fileName, sb.ToString(), Encoding.Unicode);
ConsoleIO.WriteLine(string.Format("Language {0}: Translated {1} of {2}, {3:0.00}%", lang, translated, total, 100.0 * (double)translated / total));
}
}

View file

@ -53,7 +53,8 @@ MCC 现在支持这些语言(按字母顺序排列):
* `fr.ini`: Français (France) - French
* `ru.ini`: Русский (Russkiy) - Russian
* `vi.ini`: Tiếng Việt (Việt Nam) - Vietnamese
* `zh-Hans.ini` : 简体中文(中国大陆) - Chinese Simplified (China; Mandarin)
* `zh-Hans.ini`: 简体中文 - Chinese Simplified
* `zh-Hant.ini`: 繁體中文 - Chinese Traditional
## 从源码构建 🏗️

View file

@ -50,13 +50,13 @@ If you'd like to contribute to Minecraft Console Client, great, just fork the re
Check out: [How to update or add translations for MCC](https://mccteam.github.io/guide/contibuting.html#translations).
MCC now supports the following languages (Alphabetical order) :
* `de.ini` (54.40% translated) : Deutsch - German
* `de.ini` (49.19% translated) : Deutsch - German
* `en.ini` : English - English
* `fr.ini` (54.40% translated) : Français (France) - French
* `ru.ini` (53.50% translated) : Русский (Russkiy) - Russian
* `vi.ini` (53.50% translated) : Tiếng Việt (Việt Nam) - Vietnamese
* `zh-Hans.ini` (100.00% translated) : 简体中文 - Chinese Simplified
* `zh-Hant.ini` (100.00% translated) : 繁體中文 - Chinese Traditional
* `fr.ini` (49.19% translated) : Français (France) - French
* `ru.ini` (48.38% translated) : Русский (Russkiy) - Russian
* `vi.ini` (48.38% translated) : Tiếng Việt (Việt Nam) - Vietnamese
* `zh-Hans.ini` (90.43% translated) : 简体中文 - Chinese Simplified
* `zh-Hant.ini` (90.43% translated) : 繁體中文 - Chinese Traditional
## Building from the source 🏗️