From bca2a4116c9b4f171441ff11c7d1eba989565ab0 Mon Sep 17 00:00:00 2001 From: ORelio Date: Sat, 11 Jan 2014 12:48:59 +0100 Subject: [PATCH 01/20] Support text pasting with Ctrl+V --- MinecraftClient/ConsoleIO.cs | 164 +++++++++++++++---------- MinecraftClient/MinecraftClient.csproj | 1 + 2 files changed, 99 insertions(+), 66 deletions(-) diff --git a/MinecraftClient/ConsoleIO.cs b/MinecraftClient/ConsoleIO.cs index b01f1137..25bbacce 100644 --- a/MinecraftClient/ConsoleIO.cs +++ b/MinecraftClient/ConsoleIO.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Windows.Forms; +using System.Threading; namespace MinecraftClient { @@ -80,77 +82,86 @@ namespace MinecraftClient k = Console.ReadKey(true); while (writing_lock) { } reading_lock = true; - switch (k.Key) + if (k.Key == ConsoleKey.V && k.Modifiers == ConsoleModifiers.Control) { - case ConsoleKey.Escape: - ClearLineAndBuffer(); - break; - case ConsoleKey.Backspace: - RemoveOneChar(); - break; - case ConsoleKey.Enter: - Console.Write('\n'); - break; - case ConsoleKey.LeftArrow: - GoLeft(); - break; - case ConsoleKey.RightArrow: - GoRight(); - break; - case ConsoleKey.Home: - while (buffer.Length > 0) { GoLeft(); } - break; - case ConsoleKey.End: - while (buffer2.Length > 0) { GoRight(); } - break; - case ConsoleKey.Delete: - if (buffer2.Length > 0) - { - GoRight(); + string clip = ReadClipboard(); + foreach (char c in clip) + AddChar(c); + } + else + { + switch (k.Key) + { + case ConsoleKey.Escape: + ClearLineAndBuffer(); + break; + case ConsoleKey.Backspace: RemoveOneChar(); - } - break; - case ConsoleKey.Oem6: - break; - case ConsoleKey.DownArrow: - if (previous.Count > 0) - { - ClearLineAndBuffer(); - buffer = previous.First.Value; - previous.AddLast(buffer); - previous.RemoveFirst(); - Console.Write(buffer); - } - break; - case ConsoleKey.UpArrow: - if (previous.Count > 0) - { - ClearLineAndBuffer(); - buffer = previous.Last.Value; - previous.AddFirst(buffer); - previous.RemoveLast(); - Console.Write(buffer); - } - break; - case ConsoleKey.Tab: - if (autocomplete_engine != null && buffer.Length > 0) - { - string[] tmp = buffer.Split(' '); - if (tmp.Length > 0) + break; + case ConsoleKey.Enter: + Console.Write('\n'); + break; + case ConsoleKey.LeftArrow: + GoLeft(); + break; + case ConsoleKey.RightArrow: + GoRight(); + break; + case ConsoleKey.Home: + while (buffer.Length > 0) { GoLeft(); } + break; + case ConsoleKey.End: + while (buffer2.Length > 0) { GoRight(); } + break; + case ConsoleKey.Delete: + if (buffer2.Length > 0) { - string word_tocomplete = tmp[tmp.Length - 1]; - string word_autocomplete = autocomplete_engine.AutoComplete(word_tocomplete); - if (!String.IsNullOrEmpty(word_autocomplete) && word_autocomplete != word_tocomplete) + GoRight(); + RemoveOneChar(); + } + break; + case ConsoleKey.Oem6: + break; + case ConsoleKey.DownArrow: + if (previous.Count > 0) + { + ClearLineAndBuffer(); + buffer = previous.First.Value; + previous.AddLast(buffer); + previous.RemoveFirst(); + Console.Write(buffer); + } + break; + case ConsoleKey.UpArrow: + if (previous.Count > 0) + { + ClearLineAndBuffer(); + buffer = previous.Last.Value; + previous.AddFirst(buffer); + previous.RemoveLast(); + Console.Write(buffer); + } + break; + case ConsoleKey.Tab: + if (autocomplete_engine != null && buffer.Length > 0) + { + string[] tmp = buffer.Split(' '); + if (tmp.Length > 0) { - while (buffer.Length > 0 && buffer[buffer.Length - 1] != ' ') { RemoveOneChar(); } - foreach (char c in word_autocomplete) { AddChar(c); } + string word_tocomplete = tmp[tmp.Length - 1]; + string word_autocomplete = autocomplete_engine.AutoComplete(word_tocomplete); + if (!String.IsNullOrEmpty(word_autocomplete) && word_autocomplete != word_tocomplete) + { + while (buffer.Length > 0 && buffer[buffer.Length - 1] != ' ') { RemoveOneChar(); } + foreach (char c in word_autocomplete) { AddChar(c); } + } } } - } - break; - default: - AddChar(k.KeyChar); - break; + break; + default: + AddChar(k.KeyChar); + break; + } } reading_lock = false; } @@ -212,7 +223,7 @@ namespace MinecraftClient } #endregion - #region subfunctions + #region Subfunctions private static void ClearLineAndBuffer() { while (buffer2.Length > 0) { GoRight(); } @@ -275,6 +286,27 @@ namespace MinecraftClient for (int i = 0; i < buffer2.Length; i++) { GoBack(); } } #endregion + + #region Clipboard management + private static string ReadClipboard() + { + string clipdata = ""; + Thread staThread = new Thread(new ThreadStart( + delegate + { + try + { + clipdata = Clipboard.GetText(); + } + catch { } + } + )); + staThread.SetApartmentState(ApartmentState.STA); + staThread.Start(); + staThread.Join(); + return clipdata; + } + #endregion } /// diff --git a/MinecraftClient/MinecraftClient.csproj b/MinecraftClient/MinecraftClient.csproj index 78e2c47e..48af6f73 100644 --- a/MinecraftClient/MinecraftClient.csproj +++ b/MinecraftClient/MinecraftClient.csproj @@ -74,6 +74,7 @@ + From 7e8b750100041043bcd977f2b8f7d91b5c176284 Mon Sep 17 00:00:00 2001 From: ORelio Date: Sat, 11 Jan 2014 14:38:00 +0100 Subject: [PATCH 02/20] Fix for chat translation rules Eg: achievement messages are now properly displayed --- MinecraftClient/ChatParser.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/MinecraftClient/ChatParser.cs b/MinecraftClient/ChatParser.cs index 2faff1d3..36e9437c 100644 --- a/MinecraftClient/ChatParser.cs +++ b/MinecraftClient/ChatParser.cs @@ -294,7 +294,7 @@ namespace MinecraftClient { JSONData[] extras = data.Properties["extra"].DataArray.ToArray(); foreach (JSONData item in extras) - extra_result = extra_result + JSONData2String(item) + "§r"; + extra_result = extra_result + JSONData2String(item); } if (data.Properties.ContainsKey("color")) { @@ -302,20 +302,22 @@ namespace MinecraftClient } if (data.Properties.ContainsKey("text")) { - return extra_result + colorcode + JSONData2String(data.Properties["text"]) + colorcode; + return colorcode + JSONData2String(data.Properties["text"]) + extra_result; } else if (data.Properties.ContainsKey("translate")) { List using_data = new List(); - if (data.Properties.ContainsKey("using")) + if (data.Properties.ContainsKey("using") && !data.Properties.ContainsKey("with")) + data.Properties["with"] = data.Properties["using"]; + if (data.Properties.ContainsKey("with")) { - JSONData[] array = data.Properties["using"].DataArray.ToArray(); + JSONData[] array = data.Properties["with"].DataArray.ToArray(); for (int i = 0; i < array.Length; i++) { using_data.Add(JSONData2String(array[i])); } } - return extra_result + colorcode + TranslateString(JSONData2String(data.Properties["translate"]), using_data) + colorcode; + return colorcode + TranslateString(JSONData2String(data.Properties["translate"]), using_data) + extra_result; } else return extra_result; From adba89794e67ae3fecdb39a4fb73812529860e8c Mon Sep 17 00:00:00 2001 From: ORelio Date: Sat, 11 Jan 2014 16:17:48 +0100 Subject: [PATCH 03/20] Fix for text coloration - Recursive text coloration (like in MC 1.7) - Fix for color bug introduced in 7e8b750 --- MinecraftClient/ChatParser.cs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/MinecraftClient/ChatParser.cs b/MinecraftClient/ChatParser.cs index 36e9437c..9bbdb80e 100644 --- a/MinecraftClient/ChatParser.cs +++ b/MinecraftClient/ChatParser.cs @@ -21,7 +21,7 @@ namespace MinecraftClient { int cursorpos = 0; JSONData jsonData = String2Data(json, ref cursorpos); - return JSONData2String(jsonData); + return JSONData2String(jsonData, ""); } /// @@ -281,28 +281,28 @@ namespace MinecraftClient /// Use a JSON Object to build the corresponding string /// /// JSON object to convert + /// Allow parent color code to affect child elements (set to "" for function init) /// returns the Minecraft-formatted string - private static string JSONData2String(JSONData data) + private static string JSONData2String(JSONData data, string colorcode) { string extra_result = ""; - string colorcode = ""; switch (data.Type) { case JSONData.DataType.Object: + if (data.Properties.ContainsKey("color")) + { + colorcode = color2tag(JSONData2String(data.Properties["color"], "")); + } if (data.Properties.ContainsKey("extra")) { JSONData[] extras = data.Properties["extra"].DataArray.ToArray(); foreach (JSONData item in extras) - extra_result = extra_result + JSONData2String(item); - } - if (data.Properties.ContainsKey("color")) - { - colorcode = color2tag(JSONData2String(data.Properties["color"])); + extra_result = extra_result + JSONData2String(item, colorcode) + "§r"; } if (data.Properties.ContainsKey("text")) { - return colorcode + JSONData2String(data.Properties["text"]) + extra_result; + return colorcode + JSONData2String(data.Properties["text"], colorcode) + extra_result; } else if (data.Properties.ContainsKey("translate")) { @@ -314,10 +314,10 @@ namespace MinecraftClient JSONData[] array = data.Properties["with"].DataArray.ToArray(); for (int i = 0; i < array.Length; i++) { - using_data.Add(JSONData2String(array[i])); + using_data.Add(JSONData2String(array[i], colorcode)); } } - return colorcode + TranslateString(JSONData2String(data.Properties["translate"]), using_data) + extra_result; + return colorcode + TranslateString(JSONData2String(data.Properties["translate"], ""), using_data) + extra_result; } else return extra_result; @@ -325,12 +325,12 @@ namespace MinecraftClient string result = ""; foreach (JSONData item in data.DataArray) { - result += JSONData2String(item); + result += JSONData2String(item, colorcode); } return result; case JSONData.DataType.String: - return data.StringValue; + return colorcode + data.StringValue; } return ""; From afff1ef89eaeaae0b7e7a0bf7179c5a4ff202e45 Mon Sep 17 00:00:00 2001 From: ORelio Date: Sun, 12 Jan 2014 13:38:52 +0100 Subject: [PATCH 04/20] Fix for respawning + /respawn command - Player is automatically respawned when logging in - Added /respawn command (MC 1.7 does not fail to respawn) - Cleaned MCC command handling code, /exec is now /script --- MinecraftClient/McTcpClient.cs | 41 ++++++++++++++++++--------------- MinecraftClient/MinecraftCom.cs | 3 +++ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index c2ffa6cc..7c99eb61 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -143,6 +143,9 @@ namespace MinecraftClient { try { + //Needed if the player is dead + handler.SendRespawnPacket(); + while (client.Client.Connected) { text = ConsoleIO.ReadLine(); @@ -160,9 +163,21 @@ namespace MinecraftClient } else { - if (text.ToLower() == "/quit" || text.ToLower().StartsWith("/exec ") || text.ToLower() == "/reco" || text.ToLower() == "/reconnect") { break; } - while (text.Length > 0 && text[0] == ' ') { text = text.Substring(1); } - if (text != "") + text = text.Trim(); + if (text.ToLower() == "/quit" || text.ToLower() == "/reco") + { + break; + } + else if (text.ToLower() == "/respawn") + { + handler.SendRespawnPacket(); + ConsoleIO.WriteLine("You have respawned."); + } + else if (text.ToLower().StartsWith("/script ")) + { + handler.BotLoad(new Bots.Scripting(text.Substring(8))); + } + else if (text != "") { //Message is too long if (text.Length > 100) @@ -175,7 +190,7 @@ namespace MinecraftClient } else { - //Send the message splitted in sereval messages + //Send the message splitted in several messages while (text.Length > 100) { handler.SendChatMessage(text.Substring(0, 100)); @@ -189,22 +204,10 @@ namespace MinecraftClient } } - if (text.ToLower() == "/quit") + switch (text.ToLower()) { - ConsoleIO.WriteLine("You have left the server."); - Disconnect(); - } - - else if (text.ToLower().StartsWith("/exec ")) { - handler.BotLoad(new Bots.Scripting("config/" + text.Split()[1])); - } - - - else if (text.ToLower() == "/reco" || text.ToLower() == "/reconnect") - { - ConsoleIO.WriteLine("You have left the server."); - handler.SendRespawnPacket(); - Program.Restart(); + case "/quit": Program.Exit(); break; + case "/reco": Program.Restart(); break; } } catch (IOException) { } diff --git a/MinecraftClient/MinecraftCom.cs b/MinecraftClient/MinecraftCom.cs index ec22a810..f58588bc 100644 --- a/MinecraftClient/MinecraftCom.cs +++ b/MinecraftClient/MinecraftCom.cs @@ -549,6 +549,9 @@ namespace MinecraftClient if (message == null) message = ""; + message.Replace("\"", "\\\""); + message = "\"" + message + "\""; + try { byte[] packet_id = getVarInt(0x40); From baaf37f28b1cc1dc4f89267aae983e4a42a2d4f6 Mon Sep 17 00:00:00 2001 From: ORelio Date: Sun, 12 Jan 2014 13:41:40 +0100 Subject: [PATCH 05/20] Scripting bot : automatically find script file - Automatically look for script file in config/ and scripts/ folders - Automacically try to add '.txt' extension to the script filename - Eg "/script testscript" properly loads "config/testscript.txt" script --- MinecraftClient/Bots.cs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index ca3b34c7..d78a88d8 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -875,14 +875,33 @@ namespace MinecraftClient public override void Initialize() { - // Loads the given file from the startup parameters - if (System.IO.File.Exists(file)) + //Load the given file from the startup parameters + //Automatically look in subfolders and try to add ".txt" file extension + string[] files = new string[] { - lines = System.IO.File.ReadAllLines(file); // Load the given bot text file (containing commands) + file, + file + ".txt", + "scripts\\" + file, + "scripts\\" + file + ".txt", + "config\\" + file, + "config\\" + file + ".txt", + }; + + bool file_found = false; + + foreach (string possible_file in files) + { + if (System.IO.File.Exists(possible_file)) + { + lines = System.IO.File.ReadAllLines(possible_file); + file_found = true; + break; + } } - else + + if (!file_found) { - LogToConsole("File not found: " + file); + LogToConsole("File not found: '" + file + "'"); UnloadBot(); //No need to keep the bot active } } From f6de2e4aeea8e255445df744fdf3be9ba4dc8e28 Mon Sep 17 00:00:00 2001 From: ORelio Date: Sun, 12 Jan 2014 15:36:41 +0100 Subject: [PATCH 06/20] Removed "You are dead" ingame message - Death detector didn't work anyway, stats packet is not sent on death - Could sometime crash the app due to a "VarInt too big" issue - Note: "health upade" packet is also not sent by the server --- MinecraftClient/MinecraftCom.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/MinecraftClient/MinecraftCom.cs b/MinecraftClient/MinecraftCom.cs index f58588bc..233c50fd 100644 --- a/MinecraftClient/MinecraftCom.cs +++ b/MinecraftClient/MinecraftCom.cs @@ -132,16 +132,6 @@ namespace MinecraftClient message = ChatParser.ParseText(message); printstring(message, false); for (int i = 0; i < bots.Count; i++) { bots[i].GetText(message); } break; - case 0x37: - int stats_count = readNextVarInt(); - for (int i = 0; i < stats_count; i++) - { - string stat_name = readNextString(); - readNextVarInt(); //stat value - if (stat_name == "stat.deaths") - printstring("You are dead. Type /reco to respawn & reconnect.", false); - } - break; case 0x3A: int autocomplete_count = readNextVarInt(); string tab_list = ""; From c826dd3b79e9fc38fb586e7429bf0d77385ddb44 Mon Sep 17 00:00:00 2001 From: ORelio Date: Mon, 13 Jan 2014 12:38:01 +0100 Subject: [PATCH 07/20] Automatically download en_GB.lang from Mojang - Removed en_US.lang checking since it does not exist anymore in assets - If Minecraft 1.6+ is not installed, download en_GB.lang from Mojang's servers --- MinecraftClient/ChatParser.cs | 53 +++++++++++++++++++++++++++++++---- MinecraftClient/Settings.cs | 5 ++-- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/MinecraftClient/ChatParser.cs b/MinecraftClient/ChatParser.cs index 9bbdb80e..5f9daf6b 100644 --- a/MinecraftClient/ChatParser.cs +++ b/MinecraftClient/ChatParser.cs @@ -96,14 +96,37 @@ namespace MinecraftClient TranslationRules["commands.message.display.outgoing"] = "§7You whisper to %s: %s"; //Use translations from Minecraft assets if translation file is not found but a copy of the game is installed? - if (!System.IO.File.Exists(Settings.TranslationsFile) //Try en_US.lang + if (!System.IO.File.Exists(Settings.TranslationsFile) //Try en_GB.lang && System.IO.File.Exists(Settings.TranslationsFile_FromMCDir)) - { Settings.TranslationsFile = Settings.TranslationsFile_FromMCDir; } - if (!System.IO.File.Exists(Settings.TranslationsFile) //Still not found? try en_GB.lang - && System.IO.File.Exists(Settings.TranslationsFile_FromMCDir_Alt)) - { Settings.TranslationsFile = Settings.TranslationsFile_FromMCDir_Alt; } + { + Settings.TranslationsFile = Settings.TranslationsFile_FromMCDir; + Console.ForegroundColor = ConsoleColor.DarkGray; + ConsoleIO.WriteLine("Using en_GB.lang from your Minecraft directory."); + Console.ForegroundColor = ConsoleColor.Gray; + } - //Load an external dictionnary of translation rules + //Still not found? try downloading en_GB from Mojang's servers? + if (!System.IO.File.Exists(Settings.TranslationsFile)) + { + Console.ForegroundColor = ConsoleColor.DarkGray; + ConsoleIO.WriteLine("Downloading en_GB.lang from Mojang's servers..."); + try + { + string assets_index = downloadString(Settings.TranslationsFile_Website_Index); + string[] tmp = assets_index.Split(new string[] { "lang/en_GB.lang" }, StringSplitOptions.None); + tmp = tmp[1].Split(new string[] { "hash\": \"" }, StringSplitOptions.None); + string hash = tmp[1].Split('"')[0]; //Translations file identifier on Mojang's servers + System.IO.File.WriteAllText(Settings.TranslationsFile, downloadString(Settings.TranslationsFile_Website_Download + '/' + hash.Substring(0, 2) + '/' + hash)); + ConsoleIO.WriteLine("Done. File saved as \"" + Settings.TranslationsFile + '"'); + } + catch + { + ConsoleIO.WriteLine("Failed to download the file."); + } + Console.ForegroundColor = ConsoleColor.Gray; + } + + //Load the external dictionnary of translation rules or display an error message if (System.IO.File.Exists(Settings.TranslationsFile)) { string[] translations = System.IO.File.ReadAllLines(Settings.TranslationsFile); @@ -343,5 +366,23 @@ namespace MinecraftClient /// True if hexadecimal private static bool isHex(char c) { return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); } + + /// + /// Do a HTTP request to get a webpage or text data from a server file + /// + /// URL of resource + /// Returns resource data if success, otherwise a WebException is raised + + private static string downloadString(string url) + { + System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); + myRequest.Method = "GET"; + System.Net.WebResponse myResponse = myRequest.GetResponse(); + System.IO.StreamReader sr = new System.IO.StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8); + string result = sr.ReadToEnd(); + sr.Close(); + myResponse.Close(); + return result; + } } } diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index f6a3284c..87bedeef 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -23,8 +23,9 @@ namespace MinecraftClient public static string SingleCommand = ""; //Other Settings - public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\virtual\legacy\lang\en_US.lang"; - public static string TranslationsFile_FromMCDir_Alt = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\virtual\legacy\lang\en_GB.lang"; + public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\virtual\legacy\lang\en_GB.lang"; + public static string TranslationsFile_Website_Index = "https://s3.amazonaws.com/Minecraft.Download/indexes/1.7.4.json"; + public static string TranslationsFile_Website_Download = "http://resources.download.minecraft.net"; public static string TranslationsFile = "translations.lang"; public static string Bots_OwnersFile = "bot-owners.txt"; From 19c3fb9485eafd74424384944bb5f5b7ddb60079 Mon Sep 17 00:00:00 2001 From: ORelio Date: Mon, 13 Jan 2014 22:40:24 +0100 Subject: [PATCH 08/20] Removed a check before reading data from server - Fix hanging issue with very long strings (eg. heavy server icon in json response) --- MinecraftClient/MinecraftCom.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/MinecraftClient/MinecraftCom.cs b/MinecraftClient/MinecraftCom.cs index 233c50fd..12cbb708 100644 --- a/MinecraftClient/MinecraftCom.cs +++ b/MinecraftClient/MinecraftCom.cs @@ -333,7 +333,6 @@ namespace MinecraftClient private void setEncryptedClient(Crypto.AesStream n) { s = n; encrypted = true; } private void Receive(byte[] buffer, int start, int offset, SocketFlags f) { - while (c.Client.Available < start + offset) { } if (encrypted) { s.Read(buffer, start, offset); From bf87374b483d4321866d99797af7c4cf1cccff0c Mon Sep 17 00:00:00 2001 From: v1RuX Date: Thu, 16 Jan 2014 16:21:15 +0100 Subject: [PATCH 09/20] Show username in title Shows the username in console title to make identification easier when multiple instances of the client are running --- MinecraftClient/Program.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 9602e4c4..cf6568a7 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -167,6 +167,9 @@ namespace MinecraftClient } } + //Set login as console title to identify it easier when multiple instances are running + Console.Title = "Console Client for MC - " + Settings.Login; + startupargs = args; InitializeClient(); } From b49850e0426a505de72588fe1cd965eb93af7fc1 Mon Sep 17 00:00:00 2001 From: ORelio Date: Thu, 16 Jan 2014 19:27:06 +0100 Subject: [PATCH 10/20] Default console title + add username after login - Default console title is set if no title is provided in config file - Fix custom console title beign replaced when adding username - Idea is from v1RuX, see commit bf87374 --- MinecraftClient/Program.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 69a8b5d5..c4f424a9 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -23,6 +23,7 @@ namespace MinecraftClient static void Main(string[] args) { + Console.Title = "Minecraft Console Client"; Console.WriteLine("Console Client for MC 1.7.2 to 1.7.4 - v" + Version + " - By ORelio & Contributors"); //Basic Input/Output ? @@ -167,9 +168,6 @@ namespace MinecraftClient } } - //Set login as console title to identify it easier when multiple instances are running - Console.Title = "Console Client for MC - " + Settings.Login; - startupargs = args; InitializeClient(); } @@ -201,6 +199,8 @@ namespace MinecraftClient } if (result == MinecraftCom.LoginResult.Success) { + Console.Title += " - " + Settings.Username; + Console.WriteLine("Success. (session ID: " + sessionID + ')'); if (Settings.ServerIP == "") { From fa6aa107c8884c06bad63d4f4ce10898f9c808af Mon Sep 17 00:00:00 2001 From: ORelio Date: Thu, 16 Jan 2014 19:33:48 +0100 Subject: [PATCH 11/20] Fixed username added several times with autorelog - If using autorelog bot, " - Username" was added each time the app was restarting - To fix this, added a ConsoleTitle setting which is re-used when restarting --- MinecraftClient/Program.cs | 5 +++-- MinecraftClient/Settings.cs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index c4f424a9..b0d5e0db 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -23,7 +23,6 @@ namespace MinecraftClient static void Main(string[] args) { - Console.Title = "Minecraft Console Client"; Console.WriteLine("Console Client for MC 1.7.2 to 1.7.4 - v" + Version + " - By ORelio & Contributors"); //Basic Input/Output ? @@ -148,6 +147,8 @@ namespace MinecraftClient } else Settings.WriteDefaultSettings("MinecraftClient.ini"); + Console.Title = Settings.ConsoleTitle; + //Asking the user to type in missing data such as Username and Password if (Settings.Login == "") @@ -199,7 +200,7 @@ namespace MinecraftClient } if (result == MinecraftCom.LoginResult.Success) { - Console.Title += " - " + Settings.Username; + Console.Title = Settings.ConsoleTitle + " - " + Settings.Username; Console.WriteLine("Success. (session ID: " + sessionID + ')'); if (Settings.ServerIP == "") diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 87bedeef..0ae80c53 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -21,6 +21,7 @@ namespace MinecraftClient public static string Password = ""; public static string ServerIP = ""; public static string SingleCommand = ""; + public static string ConsoleTitle = "Minecraft Console Client"; //Other Settings public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\virtual\legacy\lang\en_GB.lang"; @@ -121,7 +122,7 @@ namespace MinecraftClient case "singlecommand": SingleCommand = argValue; break; case "translationsfile": TranslationsFile = argValue; break; case "botownersfile": Bots_OwnersFile = argValue; break; - case "consoletitle": Console.Title = argValue; break; + case "consoletitle": ConsoleTitle = argValue; break; } break; From ed3079091bd1f7b51ca407a113d46492f5b0bf60 Mon Sep 17 00:00:00 2001 From: ORelio Date: Fri, 17 Jan 2014 19:20:41 +0100 Subject: [PATCH 12/20] Add AntiAFK command setting (see pull request #18) - AntiAFK command can be customized through INI file - Clearer WriteDefaultSettings() function --- MinecraftClient/Bots.cs | 8 +++--- MinecraftClient/Settings.cs | 53 ++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index d78a88d8..29c236bb 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -264,7 +264,7 @@ namespace MinecraftClient } /// - /// This bot sends a /ping command every 60 seconds in order to stay non-afk. + /// This bot sends a command every 60 seconds in order to stay non-afk. /// public class AntiAFK : ChatBot @@ -289,7 +289,7 @@ namespace MinecraftClient count++; if (count == timeping) { - SendText("/ping"); + SendText(Settings.AntiAFK_Command); count = 0; } } @@ -917,9 +917,9 @@ namespace MinecraftClient nextline++; //Move the cursor so that the next time the following line will be interpreted sleepticks = sleepticks_interval; //Used to delay next command sending and prevent from beign kicked for spamming - if (instruction_line.Length > 0) + if (instruction_line.Length > 1) { - if (!instruction_line.StartsWith("//") && !instruction_line.StartsWith("#")) + if (instruction_line[0] != '#' && instruction_line[0] != '/' && instruction_line[1] != '/') { string instruction_name = instruction_line.Split(' ')[0]; switch (instruction_name.ToLower()) diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 0ae80c53..49c17975 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -33,6 +33,7 @@ namespace MinecraftClient //AntiAFK Settings public static bool AntiAFK_Enabled = false; public static int AntiAFK_Delay = 600; + public static string AntiAFK_Command = "/ping"; //Hangman Settings public static bool Hangman_Enabled = false; @@ -140,6 +141,7 @@ namespace MinecraftClient { case "enabled": AntiAFK_Enabled = str2bool(argValue); break; case "delay": AntiAFK_Delay = str2int(argValue); break; + case "command": AntiAFK_Command = argValue == "" ? "/ping" : argValue; break; } break; @@ -197,7 +199,56 @@ namespace MinecraftClient public static void WriteDefaultSettings(string settingsfile) { - System.IO.File.WriteAllText(settingsfile, "#Minecraft Console Client v" + Program.Version + "\r\n#Startup Config File\r\n\r\n[Main]\r\n\r\n#General settings\r\n#leave blank = prompt user on startup\r\n#Use \"-\" as password for offline mode\r\n\r\nlogin=\r\npassword=\r\nserverip=\r\n\r\n#Advanced settings\r\n\r\ntranslationsfile=translations.lang\r\nbotownersfile=bot-owners.txt\r\nconsoletitle=Minecraft Console Client\r\n\r\n#Bot Settings\r\n\r\n[Alerts]\r\nenabled=false\r\nalertsfile=alerts.txt\r\nexcludesfile=alerts-exclude.txt\r\n\r\n[AntiAFK]\r\nenabled=false\r\ndelay=600 #10 = 1s\r\n\r\n[AutoRelog]\r\nenabled=false\r\ndelay=10\r\nretries=3 #-1 = unlimited\r\nkickmessagesfile=kickmessages.txt\r\n\r\n[ChatLog]\r\nenabled=false\r\ntimestamps=true\r\nfilter=messages\r\nlogfile=chatlog.txt\r\n\r\n[Hangman]\r\nenabled=false\r\nenglish=true\r\nwordsfile=hangman-en.txt\r\nfichiermots=hangman-fr.txt\r\n\r\n[Scripting]\r\nenabled=false\r\nscriptfile=testscript.txt\r\n", Encoding.UTF8); + System.IO.File.WriteAllText(settingsfile, "#Minecraft Console Client v" + Program.Version + "\r\n" + + "#Startup Config File\r\n" + + "\r\n" + + "[Main]\r\n" + + "\r\n" + + "#General settings\r\n" + + "#leave blank = prompt user on startup\r\n" + + "#Use \"-\" as password for offline mode\r\n" + + "\r\n" + + "login=\r\npassword=\r\nserverip=\r\n" + + "\r\n" + + "#Advanced settings\r\n" + + "\r\n" + + "translationsfile=translations.lang\r\n" + + "botownersfile=bot-owners.txt\r\n" + + "consoletitle=Minecraft Console Client\r\n" + + "\r\n" + + "#Bot Settings\r\n" + + "\r\n" + + "[Alerts]\r\n" + + "enabled=false\r\n" + + "alertsfile=alerts.txt\r\n" + + "excludesfile=alerts-exclude.txt\r\n" + + "\r\n" + + "[AntiAFK]\r\n" + + "enabled=false\r\n" + + "delay=600 #10 = 1s\r\n" + + "command=/ping\r\n" + + "\r\n" + + "[AutoRelog]\r\n" + + "enabled=false\r\n" + + "delay=10\r\n" + + "retries=3 #-1 = unlimited\r\n" + + "kickmessagesfile=kickmessages.txt\r\n" + + "\r\n" + + "[ChatLog]\r\n" + + "enabled=false\r\n" + + "timestamps=true\r\n" + + "filter=messages\r\n" + + "logfile=chatlog.txt\r\n" + + "\r\n" + + "[Hangman]\r\n" + + "enabled=false\r\n" + + "english=true\r\n" + + "wordsfile=hangman-en.txt\r\n" + + "fichiermots=hangman-fr.txt\r\n" + + "\r\n" + + "[Scripting]\r\n" + + "enabled=false\r\n" + + "scriptfile=testscript.txt\r\n", Encoding.UTF8); } public static int str2int(string str) { try { return Convert.ToInt32(str); } catch { return 0; } } From a627842bed13057ee9fecee8d130465bb58adf8d Mon Sep 17 00:00:00 2001 From: ORelio Date: Fri, 17 Jan 2014 19:54:10 +0100 Subject: [PATCH 13/20] Username in window title using %username% - No window title is set if 'consoletitle' setting is not set - Lowercase %username% will be replaced by the user's name --- MinecraftClient/Program.cs | 10 ++++++++-- MinecraftClient/Settings.cs | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index b0d5e0db..7cd82cd7 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -147,7 +147,10 @@ namespace MinecraftClient } else Settings.WriteDefaultSettings("MinecraftClient.ini"); - Console.Title = Settings.ConsoleTitle; + if (Settings.ConsoleTitle != "") + { + Console.Title = Settings.ConsoleTitle.Replace("%username%", "New Window"); + } //Asking the user to type in missing data such as Username and Password @@ -200,7 +203,10 @@ namespace MinecraftClient } if (result == MinecraftCom.LoginResult.Success) { - Console.Title = Settings.ConsoleTitle + " - " + Settings.Username; + if (Settings.ConsoleTitle != "") + { + Console.Title = Settings.ConsoleTitle.Replace("%username%", Settings.Username); + } Console.WriteLine("Success. (session ID: " + sessionID + ')'); if (Settings.ServerIP == "") diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 49c17975..c6b318ac 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -21,7 +21,7 @@ namespace MinecraftClient public static string Password = ""; public static string ServerIP = ""; public static string SingleCommand = ""; - public static string ConsoleTitle = "Minecraft Console Client"; + public static string ConsoleTitle = ""; //Other Settings public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\virtual\legacy\lang\en_GB.lang"; @@ -214,7 +214,7 @@ namespace MinecraftClient + "\r\n" + "translationsfile=translations.lang\r\n" + "botownersfile=bot-owners.txt\r\n" - + "consoletitle=Minecraft Console Client\r\n" + + "consoletitle=Minecraft Console Client - %username%\r\n" + "\r\n" + "#Bot Settings\r\n" + "\r\n" From c6e44041d2680939bc0aad3f92a6bb48afadd99e Mon Sep 17 00:00:00 2001 From: ORelio Date: Fri, 17 Jan 2014 20:39:55 +0100 Subject: [PATCH 14/20] Use Minecraft 1.7.4's en_GB object from assets - en_GB.lang is not downloaded for Minecraft 1.7.4 and above - try to use MC 1.7.4's en_GB object (works only if 1.7.4 is installed) --- MinecraftClient/Settings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index c6b318ac..b1b3c1a2 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -24,7 +24,7 @@ namespace MinecraftClient public static string ConsoleTitle = ""; //Other Settings - public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\virtual\legacy\lang\en_GB.lang"; + public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\objects\9e\9e2fdc43fc1c7024ff5922b998fadb2971a64ee0"; //MC 1.7.4 en_GB.lang public static string TranslationsFile_Website_Index = "https://s3.amazonaws.com/Minecraft.Download/indexes/1.7.4.json"; public static string TranslationsFile_Website_Download = "http://resources.download.minecraft.net"; public static string TranslationsFile = "translations.lang"; From 07ef031bb9e75a9781217f1b5785c7b09dbf8453 Mon Sep 17 00:00:00 2001 From: ORelio Date: Fri, 17 Jan 2014 20:58:42 +0100 Subject: [PATCH 15/20] Allow to use both INI files and command-line args - MinecraftClient.ini or the specified INI file is loaded anyway - Command-line arguments overrides the INI file settings - INI file is added in front of the command-line args - eg. MinecraftClient.exe my.ini Login Password IP --- MinecraftClient/Program.cs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 7cd82cd7..f04a7063 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -32,13 +32,24 @@ namespace MinecraftClient args = args.Where(o => !Object.ReferenceEquals(o, args[args.Length - 1])).ToArray(); } - //Processing Command-line arguments or Config File - - if (args.Length == 1 && System.IO.File.Exists(args[0])) + //Process ini configuration file + if (args.Length >= 1 && System.IO.File.Exists(args[0]) && System.IO.Path.GetExtension(args[0]).ToLower() == ".ini") { Settings.LoadSettings(args[0]); + + //remove ini configuration file from arguments array + List args_tmp = args.ToList(); + args_tmp.RemoveAt(0); + args = args_tmp.ToArray(); } - else if (args.Length >= 1) + else if (System.IO.File.Exists("MinecraftClient.ini")) + { + Settings.LoadSettings("MinecraftClient.ini"); + } + else Settings.WriteDefaultSettings("MinecraftClient.ini"); + + //Other command-line arguments + if (args.Length >= 1) { Settings.Login = args[0]; if (args.Length >= 2) @@ -141,11 +152,6 @@ namespace MinecraftClient } } } - else if (System.IO.File.Exists("MinecraftClient.ini")) - { - Settings.LoadSettings("MinecraftClient.ini"); - } - else Settings.WriteDefaultSettings("MinecraftClient.ini"); if (Settings.ConsoleTitle != "") { From 7f65a5d69e2640150791d8cccf13140ce611d3e7 Mon Sep 17 00:00:00 2001 From: ORelio Date: Sat, 18 Jan 2014 01:09:21 +0100 Subject: [PATCH 16/20] Change for vanilla whisper detection - Before: Player whispers message - After: Player whispers to you: message --- MinecraftClient/Bots.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index 29c236bb..4da3f296 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -127,10 +127,10 @@ namespace MinecraftClient try { //Detect vanilla /tell messages - //Someone whispers message + //Someone whispers to you: message if (tmp.Length > 2 && tmp[1] == "whispers") { - message = text.Substring(tmp[0].Length + 10); + message = text.Substring(tmp[0].Length + 18); sender = tmp[0]; return isValidName(sender); } From 6e6fa6a50fdd964bb08d08ba4434e1e645d78685 Mon Sep 17 00:00:00 2001 From: ORelio Date: Tue, 21 Jan 2014 18:28:14 +0100 Subject: [PATCH 17/20] Fix text encoding for GUI (BasicIO) mode - Fix encoding when using a GUI on non-ascii langages (eg russian) - See discussion in pull request #30 for more info --- MinecraftClient/Program.cs | 1 + MinecraftClientGUI/MinecraftClient.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index f04a7063..9829187c 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -29,6 +29,7 @@ namespace MinecraftClient if (args.Length >= 1 && args[args.Length - 1] == "BasicIO") { ConsoleIO.basicIO = true; + Console.OutputEncoding = Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage); args = args.Where(o => !Object.ReferenceEquals(o, args[args.Length - 1])).ToArray(); } diff --git a/MinecraftClientGUI/MinecraftClient.cs b/MinecraftClientGUI/MinecraftClient.cs index 1675f4dc..987be7cd 100644 --- a/MinecraftClientGUI/MinecraftClient.cs +++ b/MinecraftClientGUI/MinecraftClient.cs @@ -59,7 +59,7 @@ namespace MinecraftClientGUI Client.StartInfo.FileName = ExePath; Client.StartInfo.Arguments = arguments; Client.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; - Client.StartInfo.StandardOutputEncoding = Encoding.GetEncoding(850); + Client.StartInfo.StandardOutputEncoding = Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage); Client.StartInfo.UseShellExecute = false; Client.StartInfo.RedirectStandardOutput = true; Client.StartInfo.RedirectStandardInput = true; From 420c93a5dd451cf7e378f5e42a31439f5b343ff2 Mon Sep 17 00:00:00 2001 From: Vitalij Date: Tue, 21 Jan 2014 22:40:23 +0400 Subject: [PATCH 18/20] Input GUI fix :D --- MinecraftClient/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 9829187c..79f65186 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -30,6 +30,7 @@ namespace MinecraftClient { ConsoleIO.basicIO = true; Console.OutputEncoding = Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage); + Console.InputEncoding = Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage); args = args.Where(o => !Object.ReferenceEquals(o, args[args.Length - 1])).ToArray(); } From d08634789b3b5bd2fc71d49ba840f27d24d54201 Mon Sep 17 00:00:00 2001 From: ORelio Date: Wed, 22 Jan 2014 11:44:53 +0100 Subject: [PATCH 19/20] Little optimization from dogwatch See comment in commit 420c93a --- MinecraftClient/Program.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 79f65186..4ac67962 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -29,8 +29,7 @@ namespace MinecraftClient if (args.Length >= 1 && args[args.Length - 1] == "BasicIO") { ConsoleIO.basicIO = true; - Console.OutputEncoding = Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage); - Console.InputEncoding = Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage); + Console.OutputEncoding = Console.InputEncoding = Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage); args = args.Where(o => !Object.ReferenceEquals(o, args[args.Length - 1])).ToArray(); } From 86908c35a0a24eec4fb49430bb1608692f32ebf0 Mon Sep 17 00:00:00 2001 From: ORelio Date: Tue, 28 Jan 2014 18:46:41 +0100 Subject: [PATCH 20/20] Change version number for 1.7.1 release --- MinecraftClient/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 4ac67962..aa0516d0 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -15,7 +15,7 @@ namespace MinecraftClient { private static McTcpClient Client; public static string[] startupargs; - public const string Version = "1.7.0"; + public const string Version = "1.7.1"; /// /// The main entry point of Minecraft Console Client