diff --git a/MCGalaxy/Network/NetUtils.cs b/MCGalaxy/Network/NetUtils.cs index 9f451d8c2..3f9a7ee79 100644 --- a/MCGalaxy/Network/NetUtils.cs +++ b/MCGalaxy/Network/NetUtils.cs @@ -74,7 +74,7 @@ namespace MCGalaxy { public static void WriteAscii(string str, byte[] array, int offset) { int count = Math.Min(str.Length, StringSize); for (int i = 0; i < count; i++) { - char raw = str[i]; + char raw = str[i].UnicodeToCp437(); array[offset + i] = raw >= '\u0080' ? (byte)'?' : (byte)raw; } for (int i = count; i < StringSize; i++) @@ -84,7 +84,7 @@ namespace MCGalaxy { public static void WriteCP437(string str, byte[] array, int offset) { int count = Math.Min(str.Length, StringSize); for (int i = 0; i < count; i++) - array[offset + i] = (byte)str[i]; + array[offset + i] = (byte)str[i].UnicodeToCp437(); for (int i = count; i < StringSize; i++) array[offset + i] = (byte)' '; } diff --git a/MCGalaxy/Network/Opcode.cs b/MCGalaxy/Network/Opcode.cs index 47082cf37..25dfdf658 100644 --- a/MCGalaxy/Network/Opcode.cs +++ b/MCGalaxy/Network/Opcode.cs @@ -64,5 +64,6 @@ namespace MCGalaxy { public const byte CpeSetTextColor = 39; public const byte CpeSetMapEnvUrl = 40; public const byte CpeSetMapEnvProperty = 41; + public const byte CpeSetEntityProperty = 42; } } diff --git a/MCGalaxy/Network/Packets/Packet.CPE.cs b/MCGalaxy/Network/Packets/Packet.CPE.cs index aff994b7c..3a68c74e0 100644 --- a/MCGalaxy/Network/Packets/Packet.CPE.cs +++ b/MCGalaxy/Network/Packets/Packet.CPE.cs @@ -172,5 +172,13 @@ namespace MCGalaxy { NetUtils.WriteI32(value, buffer, 2); return buffer; } + + public static byte[] EntityProperty(EntityProp prop, int value) { + byte[] buffer = new byte[6]; + buffer[0] = Opcode.CpeSetEntityProperty; + buffer[1] = (byte)prop; + NetUtils.WriteI32(value, buffer, 2); + return buffer; + } } } diff --git a/MCGalaxy/Network/Player.Networking.cs b/MCGalaxy/Network/Player.Networking.cs index ba939fc0c..0e9c89d3f 100644 --- a/MCGalaxy/Network/Player.Networking.cs +++ b/MCGalaxy/Network/Player.Networking.cs @@ -226,7 +226,6 @@ namespace MCGalaxy { public void SendMessage(byte id, string message, bool colorParse = true) { message = Chat.Format(message, this, colorParse); - message.UnicodeToCp437InPlace(); int totalTries = 0; if (MessageRecieve != null) diff --git a/MCGalaxy/Player/Player.CPE.cs b/MCGalaxy/Player/Player.CPE.cs index 01192fedb..11a1f681b 100644 --- a/MCGalaxy/Player/Player.CPE.cs +++ b/MCGalaxy/Player/Player.CPE.cs @@ -16,33 +16,17 @@ permissions and limitations under the Licenses. */ using System; -using System.Drawing; namespace MCGalaxy { public partial class Player { - public int ClickDistance = 0; - public int CustomBlocks = 0; - public int HeldBlock = 0; - public int TextHotKey = 0; - public int ExtPlayerList = 0; - public int EnvColors = 0; - public int SelectionCuboid = 0; - public int BlockPermissions = 0; - public int ChangeModel = 0; - public int EnvMapAppearance = 0; - public int EnvWeatherType = 0; - public int HackControl = 0; - public int EmoteFix = 0; - public int MessageTypes = 0; - public int LongerMessages = 0; - public int FullCP437 = 0; - public int BlockDefinitions = 0; - public int BlockDefinitionsExt = 0; - public int TextColors = 0; - public int BulkBlockUpdate = 0; - public int EnvMapAspect = 0; - public int PlayerClick = 0; + public int ClickDistance, CustomBlocks, HeldBlock, TextHotKey; + public int ExtPlayerList, EnvColors, SelectionCuboid, BlockPermissions; + public int ChangeModel, EnvMapAppearance, EnvWeatherType, HackControl; + public int EmoteFix, MessageTypes, LongerMessages, FullCP437; + public int BlockDefinitions, BlockDefinitionsExt, TextColors, BulkBlockUpdate; + public int EnvMapAspect, PlayerClick, EntityProperty; + // these are checked frequently, so avoid overhead of HasCpeExt public bool hasCustomBlocks, hasBlockDefs, hasTextColors, hasChangeModel, hasExtList; @@ -105,6 +89,8 @@ namespace MCGalaxy { EnvMapAspect = version; break; case CpeExt.PlayerClick: PlayerClick = version; break; + case CpeExt.EntityProperty: + EntityProperty = version; break; } } @@ -283,6 +269,7 @@ namespace MCGalaxy { public const string BulkBlockUpdate = "BulkBlockUpdate"; public const string EnvMapAspect = "EnvMapAspect"; public const string PlayerClick = "PlayerClick"; + public const string EntityProperty = "EntityProperty"; } public enum CpeMessageType : byte { @@ -296,4 +283,8 @@ namespace MCGalaxy { CloudsLevel = 3, MaxFog = 4, CloudsSpeed = 5, WeatherSpeed = 6, WeatherFade = 7, ExpFog = 8, } + + public enum EntityProp : byte { + RotX = 0, RotY = 1, RotZ = 2, + } } \ No newline at end of file diff --git a/MCGalaxy/util/Extensions/StringExts.cs b/MCGalaxy/util/Extensions/StringExts.cs index 6ddce6e8b..06185b4e5 100644 --- a/MCGalaxy/util/Extensions/StringExts.cs +++ b/MCGalaxy/util/Extensions/StringExts.cs @@ -66,7 +66,7 @@ namespace MCGalaxy { } - static char Cp437ToUnicode(char c) { + public static char Cp437ToUnicode(this char c) { if (c < 0x20) { return FullCP437Handler.ControlCharReplacements[c]; } else if (c < 0x7F) { @@ -77,7 +77,7 @@ namespace MCGalaxy { return '?'; } - static char UnicodeToCp437(char c) { + public static char UnicodeToCp437(this char c) { int cpIndex = 0; if (c >= ' ' && c <= '~') { return c;