OSDN Git Service

Assorted fixes
[automap/automap.git] / Automap / Designators / DefaultDesignators.cs
index 5c9aee2..33b499a 100644 (file)
@@ -3,7 +3,9 @@ using System.Collections.Generic;
 using System.Drawing;
 using System.Text;
 using System.Text.RegularExpressions;
+
 using HarmonyLib;
+
 using Vintagestory.API.Client;
 using Vintagestory.API.Common;
 using Vintagestory.API.Common.Entities;
@@ -123,6 +125,10 @@ namespace Automap
                        }
                }
 
+               internal static Encoding SaferUnicodeEncoding = Encoding.GetEncoding(Encoding.UTF8.WebName,
+               new EncoderReplacementFallback(@" "),
+               new DecoderReplacementFallback(@" "));
+
                #endregion
 
 
@@ -130,20 +136,22 @@ namespace Automap
 
                internal static void DecodeSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
                {
-#if DEBUG
+               #if DEBUG
                clientAPI.Logger.VerboseDebug("Sign Designator Invoked!");
-#endif
+               #endif
                //sign Text into a POI field...
                BlockEntitySign signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySign;
 
                if (signEntity != null && !String.IsNullOrEmpty(signEntity.text)) {
 
+               var textTemp = SaferUnicodeEncoding.GetBytes(signEntity.text);
+
                poi.AddReplace(
                                        new PointOfInterest {
                                                Name = "Sign",
                                                PrettyLocation = posn.PrettyCoords(clientAPI),
                                                Location = posn.Copy( ),
-                                               Notes = signEntity.text,
+                                               Notes = SaferUnicodeEncoding.GetString(textTemp).Normalize(),
                                                Timestamp = DateTime.UtcNow,
                                        }
                                        );
@@ -161,12 +169,14 @@ namespace Automap
 
                if (signEntity != null && signEntity.textByCardinalDirection?.Length > 0) {
 
+               var textTemp = SaferUnicodeEncoding.GetBytes(string.Join(",", signEntity.textByCardinalDirection));
+
                poi.AddReplace(
                                        new PointOfInterest {
                                                Name = "Signpost",
                                                PrettyLocation = posn.PrettyCoords(clientAPI),
                                                Location = posn.Copy( ),
-                                               Notes = string.Join(",", signEntity.textByCardinalDirection),
+                                               Notes = SaferUnicodeEncoding.GetString(textTemp).Normalize(),
                                                Timestamp = DateTime.UtcNow,
                                        }
                                        );