Automap (client) [VS plugin mod]
Revisão | 0fa1d15bd509262acce758c9a2fd3cc7b3552dc5 (tree) |
---|---|
Hora | 2020-09-17 12:51:03 |
Autor | melchior <melchior@user...> |
Commiter | melchior |
1st attempt to fix Protocol buffer corruption issue
@@ -1,41 +1,42 @@ | ||
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Collections.Specialized; |
4 | - | |
4 | +using System.Diagnostics; | |
5 | +using System.IO; | |
6 | +using System.Collections.ObjectModel; | |
7 | +using System.Text; | |
5 | 8 | |
6 | 9 | using Vintagestory.API.MathTools; |
7 | 10 | using Vintagestory.API.Common; |
11 | +using Vintagestory.API.Client; | |
8 | 12 | |
9 | 13 | 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; | |
15 | 14 | |
16 | 15 | namespace Automap |
17 | 16 | { |
18 | - [ProtoContract] | |
17 | + [ProtoContract(ImplicitFields = ImplicitFields.None)] | |
19 | 18 | public struct ColumnMeta |
20 | 19 | { |
21 | 20 | [ProtoMember(1)] |
22 | 21 | public Vec2i Location; |
23 | 22 | |
24 | 23 | [DisplayName(0, "Coords.")] |
24 | + [ProtoIgnore] | |
25 | 25 | public string PrettyLocation; |
26 | 26 | |
27 | 27 | [ProtoMember(2)] |
28 | 28 | public TimeSpan ChunkAge;//OLDEST CHUNK. from chunk last edit |
29 | 29 | |
30 | 30 | [DisplayName(1, "Age")] |
31 | + [ProtoIgnore] | |
31 | 32 | public string ShortChunkAge { get => ChunkAge.ToString("c"); } |
32 | 33 | |
33 | - [ProtoMember(3)] | |
34 | 34 | [DisplayName(2, "Temp.")] |
35 | + [ProtoMember(3)] | |
35 | 36 | public float Temperature;// Temperature - surface |
36 | 37 | |
37 | - [ProtoMember(4)] | |
38 | 38 | [DisplayName(3, "Y Max.")] |
39 | + [ProtoMember(4)] | |
39 | 40 | public ushort YMax;// Y feature height |
40 | 41 | |
41 | 42 | [ProtoMember(5)] |
@@ -56,28 +57,28 @@ namespace Automap | ||
56 | 57 | //} |
57 | 58 | |
58 | 59 | |
59 | - [ProtoMember(6)] | |
60 | 60 | [DisplayName(4, "Fert.")] |
61 | + [ProtoMember(6)] | |
61 | 62 | public float Fertility; |
62 | 63 | |
63 | - [ProtoMember(7)] | |
64 | 64 | //[DisplayName(5, "Forest")] |
65 | + [ProtoMember(7)] | |
65 | 66 | public float ForestDensity; // not given to client |
66 | 67 | |
67 | - [ProtoMember(8)] | |
68 | 68 | [DisplayName(6, "Rain")] |
69 | + [ProtoMember(8)] | |
69 | 70 | public float Rainfall; |
70 | 71 | |
71 | - [ProtoMember(9)] | |
72 | 72 | //[DisplayName(7, "Shrub")] |
73 | + [ProtoMember(9)] | |
73 | 74 | public float ShrubDensity; // not given to client |
74 | 75 | |
75 | - [ProtoMember(10)] | |
76 | 76 | [DisplayName(8, "Air blocks")] |
77 | + [ProtoMember(10)] | |
77 | 78 | public uint AirBlocks; |
78 | 79 | |
79 | - [ProtoMember(11)] | |
80 | 80 | [DisplayName(9, "Non-air")] |
81 | + [ProtoMember(11)] | |
81 | 82 | public uint NonAirBlocks; |
82 | 83 | |
83 | 84 | [ProtoMember(12)] |
@@ -176,7 +177,7 @@ namespace Automap | ||
176 | 177 | internal ColumnMeta Reload(ICoreClientAPI clientAPI) |
177 | 178 | { |
178 | 179 | this.PrettyLocation = Location.PrettyCoords(clientAPI); |
179 | - Console.Write(PrettyLocation == null ? "*" : ","); | |
180 | + Debug.Write(PrettyLocation == null ? "*" : ","); | |
180 | 181 | return this; |
181 | 182 | } |
182 | 183 | } |
@@ -17,7 +17,7 @@ namespace Automap | ||
17 | 17 | /// <summary> |
18 | 18 | /// Basically the same as a POI but for an entity |
19 | 19 | /// </summary> |
20 | - [ProtoContract] | |
20 | + [ProtoContract(ImplicitFields = ImplicitFields.None)] | |
21 | 21 | public struct EntityOfInterest |
22 | 22 | { |
23 | 23 |
@@ -30,6 +30,7 @@ namespace Automap | ||
30 | 30 | public string Notes; |
31 | 31 | |
32 | 32 | [DisplayName(1, "Loc.")] |
33 | + [ProtoIgnore] | |
33 | 34 | public string PrettyLocation; |
34 | 35 | |
35 | 36 | [ProtoMember(3)] |
@@ -1,10 +1,12 @@ | ||
1 | 1 | using System; |
2 | - | |
3 | -using Vintagestory.API.Util; | |
2 | +using System.Diagnostics; | |
3 | +using System.IO; | |
4 | 4 | |
5 | 5 | using Hjg.Pngcs; |
6 | 6 | using Hjg.Pngcs.Chunks; |
7 | 7 | |
8 | +using ProtoBuf; | |
9 | + | |
8 | 10 | namespace Automap |
9 | 11 | { |
10 | 12 | /// <summary> |
@@ -31,17 +33,23 @@ namespace Automap | ||
31 | 33 | |
32 | 34 | public override ChunkRaw CreateRawChunk() |
33 | 35 | { |
34 | - var datas = SerializerUtil.Serialize<ColumnMeta>(ChunkMetadata); | |
36 | + using (MemoryStream outputStream = new MemoryStream( )) | |
37 | + { | |
38 | + Serializer.Serialize<ColumnMeta>(outputStream, this.ChunkMetadata); | |
35 | 39 | |
36 | - ChunkRaw rawChunk = createEmptyChunk(datas.Length, true); | |
37 | - rawChunk.Data = datas; | |
40 | + ChunkRaw pngChunk = createEmptyChunk(( int )outputStream.Length, true); | |
41 | + pngChunk.Data = outputStream.ToArray(); | |
38 | 42 | |
39 | - return rawChunk; | |
43 | + return pngChunk; | |
44 | + } | |
40 | 45 | } |
41 | 46 | |
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 | + } | |
45 | 53 | } |
46 | 54 | |
47 | 55 | public override void CloneDataFromRead(PngChunk other) |
@@ -15,7 +15,7 @@ namespace Automap | ||
15 | 15 | /// <summary> |
16 | 16 | /// Actual Physical Point in space - that is interesting. |
17 | 17 | /// </summary> |
18 | - [ProtoContract] | |
18 | + [ProtoContract(ImplicitFields = ImplicitFields.None)] | |
19 | 19 | public struct PointOfInterest |
20 | 20 | { |
21 | 21 | [DisplayName(0, "Name")] |
@@ -27,6 +27,7 @@ namespace Automap | ||
27 | 27 | public string Notes; |
28 | 28 | |
29 | 29 | [DisplayName(1, "Loc.")] |
30 | + [ProtoIgnore] | |
30 | 31 | public string PrettyLocation; |
31 | 32 | |
32 | 33 | [ProtoMember(3)] |
@@ -167,14 +167,14 @@ namespace Automap | ||
167 | 167 | |
168 | 168 | if (te != null) |
169 | 169 | { |
170 | - | |
170 | + //FIXME: Delayed rescan ? | |
171 | 171 | StringBuilder textTarget = new StringBuilder(); |
172 | 172 | //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); | |
178 | 178 | poi.AddReplace( |
179 | 179 | new PointOfInterest |
180 | 180 | { |
@@ -183,10 +183,9 @@ namespace Automap | ||
183 | 183 | Location = posn.Copy(), |
184 | 184 | Notes = textTarget.ToString(), |
185 | 185 | 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 | |
187 | 187 | } |
188 | 188 | ); |
189 | - | |
190 | 189 | } |
191 | 190 | } |
192 | 191 |
@@ -3,7 +3,6 @@ using System.Collections.Concurrent; | ||
3 | 3 | using System.Collections.Generic; |
4 | 4 | using System.IO; |
5 | 5 | using System.Linq; |
6 | -using System.Reflection; | |
7 | 6 | using System.Text; |
8 | 7 | using System.Text.RegularExpressions; |
9 | 8 | using System.Threading; |
@@ -11,8 +10,6 @@ using System.Threading; | ||
11 | 10 | using Hjg.Pngcs; |
12 | 11 | using Hjg.Pngcs.Chunks; |
13 | 12 | |
14 | -using Newtonsoft.Json; | |
15 | - | |
16 | 13 | using ProtoBuf; |
17 | 14 | |
18 | 15 | using Vintagestory.API.Client; |
@@ -496,6 +493,11 @@ namespace Automap | ||
496 | 493 | Logger.Error("PNG Corruption file '{0}' - Reason: {1}", shardFile.Name, someEx); |
497 | 494 | continue; |
498 | 495 | } |
496 | + catch (ProtoException protoEx) | |
497 | + { | |
498 | + Logger.Error("ProtoBuf invalid! file:'{0}' - Reason: {1}", shardFile.Name, protoEx); | |
499 | + continue; | |
500 | + } | |
499 | 501 | } |
500 | 502 | } |
501 | 503 |
@@ -45,7 +45,7 @@ namespace Automap | ||
45 | 45 | var t = new Stopwatch(); |
46 | 46 | t.Start(); |
47 | 47 | |
48 | - Console.WriteLine("snapshot started"); | |
48 | + Debug.WriteLine("snapshot started"); | |
49 | 49 | |
50 | 50 | ImageInfo info = new ImageInfo(Width * chunkSize, Height * chunkSize, 8, false); |
51 | 51 | PngWriter snapWriter = FileHelper.CreatePngWriter(fileName, info, true); |
@@ -114,9 +114,9 @@ namespace Automap | ||
114 | 114 | } |
115 | 115 | catch (Exception) |
116 | 116 | { |
117 | - Console.WriteLine("Snapshot exception!"); | |
117 | + Debug.WriteLine("Snapshot exception!"); | |
118 | 118 | } |
119 | - Console.WriteLine($"snapshot finished in {t.ElapsedMilliseconds}"); | |
119 | + Debug.WriteLine($"snapshot finished in {t.ElapsedMilliseconds}"); | |
120 | 120 | } |
121 | 121 | |
122 | 122 | private async Task<Dictionary<int, byte[][]>> ReadAllInGroup(IGrouping<int, ColumnMeta> group) |
@@ -138,7 +138,7 @@ namespace Automap | ||
138 | 138 | } |
139 | 139 | catch (Exception e) |
140 | 140 | { |
141 | - Console.WriteLine(e.Message); | |
141 | + Debug.WriteLine(e.Message); | |
142 | 142 | return null; |
143 | 143 | } // do nothing on error |
144 | 144 | } |