fix issues when map motds use code page 437

This commit is contained in:
UnknownShadow200 2017-02-06 17:20:35 +11:00
parent e473598c92
commit 50ca28e74b
6 changed files with 27 additions and 28 deletions

View File

@ -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)' ';
}

View File

@ -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;
}
}

View File

@ -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;
}
}
}

View File

@ -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)

View File

@ -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,
}
}

View File

@ -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;