Automap (client) [VS plugin mod]
リビジョン | ec3438c8c02c57ac0241b388851e659b1cc0fc65 (tree) |
---|---|
日時 | 2020-11-08 05:15:59 |
作者 | melchior <melchior@user...> |
コミッター | melchior |
W.I.P. P.O.C. Shard Post Processor Skeliton
@@ -1,19 +1,101 @@ | ||
1 | 1 | using System; |
2 | +using System.IO; | |
3 | +using System.Text.RegularExpressions; | |
4 | + | |
5 | +using Automap; | |
6 | + | |
7 | +using Hjg.Pngcs; | |
8 | +using Hjg.Pngcs.Chunks; | |
9 | + | |
10 | +using ProtoBuf; | |
2 | 11 | |
3 | 12 | namespace ShardProcessor |
4 | -{ | |
13 | +{ | |
5 | 14 | class MainClass |
6 | 15 | { |
7 | - /* | |
16 | + //private ILogger Logger { get; set; } | |
17 | + const string chunkFile_filter = @"*_*.png"; | |
18 | + static Regex chunkShardRegex = new Regex(@"(?<X>[\d]+)_(?<Z>[\d]+)\.png", RegexOptions.Singleline); | |
19 | + static string mapPath; | |
20 | + internal const string _chunkPath = @"Chunks"; | |
21 | + | |
22 | + /* TODO: | |
8 | 23 | -Process existing PNGs: Report/Dump contents of Chunk Metadata, as per current version |
24 | + -Grayscale Heightmap extraction from P.Buf heightmap from shards | |
9 | 25 | -Extract contents of game's SQLLite map DB, INTO Automap type shards... |
10 | 26 | -Other stuff? chunk fixing / validation? |
11 | 27 | */ |
12 | 28 | public static void Main(string[ ] args) |
13 | 29 | { |
14 | 30 | Console.WriteLine("AUTOMAP Offline Shard processor v0.1"); |
31 | + //Called once - thus it can only be in a static constructor. | |
32 | + PngChunk.FactoryRegister(PngMetadataChunk.ID, typeof(PngMetadataChunk)); | |
15 | 33 | |
34 | + ArgsDecoder(args); | |
16 | 35 | |
17 | 36 | } |
37 | + | |
38 | + private static void ArgsDecoder(string[ ] args) | |
39 | + { | |
40 | + //#1 Path to maps '~/ApplicationData/vintagestory/Map/World_1234567890 | |
41 | + mapPath = args[1]; | |
42 | + | |
43 | + //#0 Command: Heightmaps (Generation from existing shard data) | |
44 | + string command = args[0]; | |
45 | + | |
46 | + if (command == "--heightmap") { | |
47 | + Process_ShardData( ); | |
48 | + } | |
49 | + | |
50 | + } | |
51 | + | |
52 | + private static void Process_ShardData( ) | |
53 | + { | |
54 | + var shardsDir = new DirectoryInfo( Path.Combine(mapPath , _chunkPath)); | |
55 | + | |
56 | + var shardFiles = shardsDir.GetFiles(chunkFile_filter); | |
57 | + | |
58 | + if (shardFiles.Length > 0) { | |
59 | + #if DEBUG | |
60 | + //Logger.VerboseDebug("Metadata reloading from {0} shards", shardFiles.Length); | |
61 | + #endif | |
62 | + | |
63 | + foreach (var shardFile in shardFiles) { | |
64 | + | |
65 | + if (shardFile.Length < 1024) continue; | |
66 | + var result = chunkShardRegex.Match(shardFile.Name); | |
67 | + if (!result.Success) continue; | |
68 | + | |
69 | + int X_chunk_pos = int.Parse(result.Groups["X"].Value); | |
70 | + int Z_chunk_pos = int.Parse(result.Groups["Z"].Value); | |
71 | + | |
72 | + try { | |
73 | + using (var fileStream = shardFile.OpenRead( )) { | |
74 | + | |
75 | + PngReader pngRead = new PngReader(fileStream); | |
76 | + pngRead.ReadSkippingAllRows( ); | |
77 | + pngRead.End( ); | |
78 | + //Parse PNG chunks for METADATA in shard | |
79 | + PngMetadataChunk metadataFromPng = pngRead.GetChunksList( ).GetById1(PngMetadataChunk.ID) as PngMetadataChunk; | |
80 | + ColumnMeta columnData = metadataFromPng.ChunkMetadata; | |
81 | + //columnData.HeightMap //Should be sane Heightmap... | |
82 | + | |
83 | + | |
84 | + | |
85 | + } | |
86 | + | |
87 | + } catch (PngjException someEx) { | |
88 | + //Logger.Error("PNG Corruption file '{0}' - Reason: {1}", shardFile.Name, someEx); | |
89 | + continue; | |
90 | + } catch (ProtoException protoEx) { | |
91 | + //Logger.Error("ProtoBuf invalid! file:'{0}' - Reason: {1}", shardFile.Name, protoEx); | |
92 | + continue; | |
93 | + } | |
94 | + } | |
95 | + } | |
96 | + | |
97 | + | |
98 | + } | |
99 | + | |
18 | 100 | } |
19 | 101 | } |
@@ -18,6 +18,7 @@ | ||
18 | 18 | <ErrorReport>prompt</ErrorReport> |
19 | 19 | <WarningLevel>4</WarningLevel> |
20 | 20 | <ExternalConsole>true</ExternalConsole> |
21 | + <Commandlineparameters>--heightmap ~/ApplicationData/vintagestory/Maps/World_19781215</Commandlineparameters> | |
21 | 22 | </PropertyGroup> |
22 | 23 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
23 | 24 | <Optimize>true</Optimize> |
@@ -28,6 +29,33 @@ | ||
28 | 29 | </PropertyGroup> |
29 | 30 | <ItemGroup> |
30 | 31 | <Reference Include="System" /> |
32 | + <Reference Include="protobuf-net"> | |
33 | + <HintPath>..\Automap\VS_libs\protobuf-net.dll</HintPath> | |
34 | + </Reference> | |
35 | + <Reference Include="Pngcs"> | |
36 | + <HintPath>..\Automap\VS_libs\Pngcs.dll</HintPath> | |
37 | + </Reference> | |
38 | + <Reference Include="Newtonsoft.Json"> | |
39 | + <HintPath>..\Automap\VS_libs\Newtonsoft.Json.dll</HintPath> | |
40 | + </Reference> | |
41 | + <Reference Include="Automap"> | |
42 | + <HintPath>..\Automap\bin\Debug\Automap.dll</HintPath> | |
43 | + </Reference> | |
44 | + <Reference Include="VintagestoryAPI"> | |
45 | + <HintPath>..\Automap\VS_libs\VintagestoryAPI.dll</HintPath> | |
46 | + </Reference> | |
47 | + <Reference Include="VintagestoryLib"> | |
48 | + <HintPath>..\Automap\VS_libs\VintagestoryLib.dll</HintPath> | |
49 | + </Reference> | |
50 | + <Reference Include="VSEssentials"> | |
51 | + <HintPath>..\Automap\VS_libs\VSEssentials.dll</HintPath> | |
52 | + </Reference> | |
53 | + <Reference Include="VSCreativeMod"> | |
54 | + <HintPath>..\Automap\VS_libs\VSCreativeMod.dll</HintPath> | |
55 | + </Reference> | |
56 | + <Reference Include="VSSurvivalMod"> | |
57 | + <HintPath>..\Automap\VS_libs\VSSurvivalMod.dll</HintPath> | |
58 | + </Reference> | |
31 | 59 | </ItemGroup> |
32 | 60 | <ItemGroup> |
33 | 61 | <Compile Include="Program.cs" /> |