• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

Automap (client) [VS plugin mod]


Commit MetaInfo

Revision0fa1d15bd509262acce758c9a2fd3cc7b3552dc5 (tree)
Time2020-09-17 12:51:03
Authormelchior <melchior@user...>
Commitermelchior

Log Message

1st attempt to fix Protocol buffer corruption issue

Change Summary

Incremental Difference

--- a/Automap/Data/ColumnMeta.cs
+++ b/Automap/Data/ColumnMeta.cs
@@ -1,41 +1,42 @@
11 using System;
22 using System.Collections.Generic;
33 using System.Collections.Specialized;
4-
4+using System.Diagnostics;
5+using System.IO;
6+using System.Collections.ObjectModel;
7+using System.Text;
58
69 using Vintagestory.API.MathTools;
710 using Vintagestory.API.Common;
11+using Vintagestory.API.Client;
812
913 using ProtoBuf;
10-using System.IO;
11-using System.Collections.ObjectModel;
12-using System.Text;
13-using Vintagestory.API.Client;
14-using Newtonsoft.Json.Linq;
1514
1615 namespace Automap
1716 {
18- [ProtoContract]
17+ [ProtoContract(ImplicitFields = ImplicitFields.None)]
1918 public struct ColumnMeta
2019 {
2120 [ProtoMember(1)]
2221 public Vec2i Location;
2322
2423 [DisplayName(0, "Coords.")]
24+ [ProtoIgnore]
2525 public string PrettyLocation;
2626
2727 [ProtoMember(2)]
2828 public TimeSpan ChunkAge;//OLDEST CHUNK. from chunk last edit
2929
3030 [DisplayName(1, "Age")]
31+ [ProtoIgnore]
3132 public string ShortChunkAge { get => ChunkAge.ToString("c"); }
3233
33- [ProtoMember(3)]
3434 [DisplayName(2, "Temp.")]
35+ [ProtoMember(3)]
3536 public float Temperature;// Temperature - surface
3637
37- [ProtoMember(4)]
3838 [DisplayName(3, "Y Max.")]
39+ [ProtoMember(4)]
3940 public ushort YMax;// Y feature height
4041
4142 [ProtoMember(5)]
@@ -56,28 +57,28 @@ namespace Automap
5657 //}
5758
5859
59- [ProtoMember(6)]
6060 [DisplayName(4, "Fert.")]
61+ [ProtoMember(6)]
6162 public float Fertility;
6263
63- [ProtoMember(7)]
6464 //[DisplayName(5, "Forest")]
65+ [ProtoMember(7)]
6566 public float ForestDensity; // not given to client
6667
67- [ProtoMember(8)]
6868 [DisplayName(6, "Rain")]
69+ [ProtoMember(8)]
6970 public float Rainfall;
7071
71- [ProtoMember(9)]
7272 //[DisplayName(7, "Shrub")]
73+ [ProtoMember(9)]
7374 public float ShrubDensity; // not given to client
7475
75- [ProtoMember(10)]
7676 [DisplayName(8, "Air blocks")]
77+ [ProtoMember(10)]
7778 public uint AirBlocks;
7879
79- [ProtoMember(11)]
8080 [DisplayName(9, "Non-air")]
81+ [ProtoMember(11)]
8182 public uint NonAirBlocks;
8283
8384 [ProtoMember(12)]
@@ -176,7 +177,7 @@ namespace Automap
176177 internal ColumnMeta Reload(ICoreClientAPI clientAPI)
177178 {
178179 this.PrettyLocation = Location.PrettyCoords(clientAPI);
179- Console.Write(PrettyLocation == null ? "*" : ",");
180+ Debug.Write(PrettyLocation == null ? "*" : ",");
180181 return this;
181182 }
182183 }
--- a/Automap/Data/EntitiesOfInterest.cs
+++ b/Automap/Data/EntitiesOfInterest.cs
@@ -17,7 +17,7 @@ namespace Automap
1717 /// <summary>
1818 /// Basically the same as a POI but for an entity
1919 /// </summary>
20- [ProtoContract]
20+ [ProtoContract(ImplicitFields = ImplicitFields.None)]
2121 public struct EntityOfInterest
2222 {
2323
@@ -30,6 +30,7 @@ namespace Automap
3030 public string Notes;
3131
3232 [DisplayName(1, "Loc.")]
33+ [ProtoIgnore]
3334 public string PrettyLocation;
3435
3536 [ProtoMember(3)]
--- a/Automap/Data/PngMetadataChunk.cs
+++ b/Automap/Data/PngMetadataChunk.cs
@@ -1,10 +1,12 @@
11 using System;
2-
3-using Vintagestory.API.Util;
2+using System.Diagnostics;
3+using System.IO;
44
55 using Hjg.Pngcs;
66 using Hjg.Pngcs.Chunks;
77
8+using ProtoBuf;
9+
810 namespace Automap
911 {
1012 /// <summary>
@@ -31,17 +33,23 @@ namespace Automap
3133
3234 public override ChunkRaw CreateRawChunk()
3335 {
34- var datas = SerializerUtil.Serialize<ColumnMeta>(ChunkMetadata);
36+ using (MemoryStream outputStream = new MemoryStream( ))
37+ {
38+ Serializer.Serialize<ColumnMeta>(outputStream, this.ChunkMetadata);
3539
36- ChunkRaw rawChunk = createEmptyChunk(datas.Length, true);
37- rawChunk.Data = datas;
40+ ChunkRaw pngChunk = createEmptyChunk(( int )outputStream.Length, true);
41+ pngChunk.Data = outputStream.ToArray();
3842
39- return rawChunk;
43+ return pngChunk;
44+ }
4045 }
4146
42- public override void ParseFromRaw(ChunkRaw rawChunk)
43- {
44- this.ChunkMetadata = SerializerUtil.Deserialize<ColumnMeta>(rawChunk.Data);
47+ public override void ParseFromRaw(ChunkRaw pngChunk)
48+ {
49+ using (MemoryStream inputStream = new MemoryStream(pngChunk.Data, false))
50+ {
51+ this.ChunkMetadata = Serializer.Deserialize<ColumnMeta>(inputStream);
52+ }
4553 }
4654
4755 public override void CloneDataFromRead(PngChunk other)
--- a/Automap/Data/PointOfInterest.cs
+++ b/Automap/Data/PointOfInterest.cs
@@ -15,7 +15,7 @@ namespace Automap
1515 /// <summary>
1616 /// Actual Physical Point in space - that is interesting.
1717 /// </summary>
18- [ProtoContract]
18+ [ProtoContract(ImplicitFields = ImplicitFields.None)]
1919 public struct PointOfInterest
2020 {
2121 [DisplayName(0, "Name")]
@@ -27,6 +27,7 @@ namespace Automap
2727 public string Notes;
2828
2929 [DisplayName(1, "Loc.")]
30+ [ProtoIgnore]
3031 public string PrettyLocation;
3132
3233 [ProtoMember(3)]
--- a/Automap/Designators/DefaultDesignators.cs
+++ b/Automap/Designators/DefaultDesignators.cs
@@ -167,14 +167,14 @@ namespace Automap
167167
168168 if (te != null)
169169 {
170-
170+ //FIXME: Delayed rescan ?
171171 StringBuilder textTarget = new StringBuilder();
172172 //translocatorEntity.GetBlockInfo(clientAPI.World.Player, textTarget);
173- textTarget.Append(te.FullyRepaired ? "Functional " : "Broken ");
174- textTarget.Append(te.Activated ? "Online " : "Offline ");
175- textTarget.Append(" Target: ");
176- textTarget.Append(te.TargetLocation != null ? "Set" : "Invalid");//Or ABS coords?
177- textTarget.AppendFormat(" Range ({0} ~ {1})", te.MinTeleporterRangeInBlocks, te.MaxTeleporterRangeInBlocks);
173+ textTarget.Append(te.FullyRepaired ? "Functional, " : "Broken, ");
174+ textTarget.Append(te.Activated ? "Online, " : "Offline, ");
175+ textTarget.Append(" Target: [ ");
176+ textTarget.Append(te.TargetLocation != null ? "Set ]" : "Invalid ]");//Or ABS coords?
177+ textTarget.AppendFormat(", Range ({0} ~ {1})", te.MinTeleporterRangeInBlocks, te.MaxTeleporterRangeInBlocks);
178178 poi.AddReplace(
179179 new PointOfInterest
180180 {
@@ -183,10 +183,9 @@ namespace Automap
183183 Location = posn.Copy(),
184184 Notes = textTarget.ToString(),
185185 Timestamp = DateTime.UtcNow,
186- Destination = te.TargetLocation != null ? new BlockPosJson(te.TargetLocation) : null//FIXME: Delayed rescan
186+ Destination = te.TargetLocation != null ? new BlockPosJson(te.TargetLocation.Copy()) : null
187187 }
188188 );
189-
190189 }
191190 }
192191
--- a/Automap/Subsystems/AutomapSystem.cs
+++ b/Automap/Subsystems/AutomapSystem.cs
@@ -3,7 +3,6 @@ using System.Collections.Concurrent;
33 using System.Collections.Generic;
44 using System.IO;
55 using System.Linq;
6-using System.Reflection;
76 using System.Text;
87 using System.Text.RegularExpressions;
98 using System.Threading;
@@ -11,8 +10,6 @@ using System.Threading;
1110 using Hjg.Pngcs;
1211 using Hjg.Pngcs.Chunks;
1312
14-using Newtonsoft.Json;
15-
1613 using ProtoBuf;
1714
1815 using Vintagestory.API.Client;
@@ -496,6 +493,11 @@ namespace Automap
496493 Logger.Error("PNG Corruption file '{0}' - Reason: {1}", shardFile.Name, someEx);
497494 continue;
498495 }
496+ catch (ProtoException protoEx)
497+ {
498+ Logger.Error("ProtoBuf invalid! file:'{0}' - Reason: {1}", shardFile.Name, protoEx);
499+ continue;
500+ }
499501 }
500502 }
501503
--- a/Automap/Subsystems/Snapshot.cs
+++ b/Automap/Subsystems/Snapshot.cs
@@ -45,7 +45,7 @@ namespace Automap
4545 var t = new Stopwatch();
4646 t.Start();
4747
48- Console.WriteLine("snapshot started");
48+ Debug.WriteLine("snapshot started");
4949
5050 ImageInfo info = new ImageInfo(Width * chunkSize, Height * chunkSize, 8, false);
5151 PngWriter snapWriter = FileHelper.CreatePngWriter(fileName, info, true);
@@ -114,9 +114,9 @@ namespace Automap
114114 }
115115 catch (Exception)
116116 {
117- Console.WriteLine("Snapshot exception!");
117+ Debug.WriteLine("Snapshot exception!");
118118 }
119- Console.WriteLine($"snapshot finished in {t.ElapsedMilliseconds}");
119+ Debug.WriteLine($"snapshot finished in {t.ElapsedMilliseconds}");
120120 }
121121
122122 private async Task<Dictionary<int, byte[][]>> ReadAllInGroup(IGrouping<int, ColumnMeta> group)
@@ -138,7 +138,7 @@ namespace Automap
138138 }
139139 catch (Exception e)
140140 {
141- Console.WriteLine(e.Message);
141+ Debug.WriteLine(e.Message);
142142 return null;
143143 } // do nothing on error
144144 }