OSDN Git Service

W.I.P. P.O.C. Shard Post Processor Skeliton
authormelchior <melchior@users.osdn.me>
Sat, 7 Nov 2020 20:15:59 +0000 (15:15 -0500)
committermelchior <melchior@users.osdn.me>
Sat, 7 Nov 2020 20:15:59 +0000 (15:15 -0500)
ShardProcessor/Program.cs
ShardProcessor/ShardProcessor.csproj

index e9e5b6c..0d2f1e1 100644 (file)
 using System;
+using System.IO;
+using System.Text.RegularExpressions;
+
+using Automap;
+
+using Hjg.Pngcs;
+using Hjg.Pngcs.Chunks;
+
+using ProtoBuf;
 
 namespace ShardProcessor
-{
+{      
        class MainClass
        {
-               /*
+               //private ILogger Logger { get; set; }
+               const string chunkFile_filter = @"*_*.png";
+               static Regex chunkShardRegex = new Regex(@"(?<X>[\d]+)_(?<Z>[\d]+)\.png", RegexOptions.Singleline);
+               static string mapPath;
+               internal const string _chunkPath = @"Chunks";
+
+               /* TODO:
                        -Process existing PNGs: Report/Dump contents of Chunk Metadata, as per current version
+                       -Grayscale Heightmap extraction from P.Buf heightmap from shards
                        -Extract contents of game's SQLLite map DB, INTO Automap type shards...
                        -Other stuff? chunk fixing / validation?
                */
                public static void Main(string[ ] args)
                {
                Console.WriteLine("AUTOMAP Offline Shard processor v0.1");
+               //Called once - thus it can only be in a static constructor.
+               PngChunk.FactoryRegister(PngMetadataChunk.ID, typeof(PngMetadataChunk));
 
+               ArgsDecoder(args);
 
                }
+
+               private static void ArgsDecoder(string[ ] args)
+               {
+               //#1 Path to maps '~/ApplicationData/vintagestory/Map/World_1234567890
+               mapPath = args[1];
+
+               //#0 Command: Heightmaps (Generation from existing shard data)
+               string command = args[0];
+
+               if (command == "--heightmap") {
+               Process_ShardData( );
+               }
+
+               }
+
+               private static void Process_ShardData( )
+               {
+               var shardsDir = new DirectoryInfo( Path.Combine(mapPath , _chunkPath));
+                                       
+               var shardFiles = shardsDir.GetFiles(chunkFile_filter);
+
+               if (shardFiles.Length > 0) {
+               #if DEBUG
+               //Logger.VerboseDebug("Metadata reloading from {0} shards", shardFiles.Length);
+               #endif
+
+               foreach (var shardFile in shardFiles) {
+
+               if (shardFile.Length < 1024) continue;
+               var result = chunkShardRegex.Match(shardFile.Name);
+               if (!result.Success) continue;
+
+               int X_chunk_pos = int.Parse(result.Groups["X"].Value);
+               int Z_chunk_pos = int.Parse(result.Groups["Z"].Value);
+
+               try {
+               using (var fileStream = shardFile.OpenRead( )) {
+
+               PngReader pngRead = new PngReader(fileStream);
+               pngRead.ReadSkippingAllRows( );
+               pngRead.End( );
+               //Parse PNG chunks for METADATA in shard
+               PngMetadataChunk metadataFromPng = pngRead.GetChunksList( ).GetById1(PngMetadataChunk.ID) as PngMetadataChunk;
+               ColumnMeta columnData = metadataFromPng.ChunkMetadata;
+               //columnData.HeightMap //Should be sane Heightmap...
+
+               
+
+               }
+
+               } catch (PngjException someEx) {
+               //Logger.Error("PNG Corruption file '{0}' - Reason: {1}", shardFile.Name, someEx);
+               continue;
+               } catch (ProtoException protoEx) {
+               //Logger.Error("ProtoBuf invalid! file:'{0}' - Reason: {1}", shardFile.Name, protoEx);
+               continue;
+               }
+               }
+               }
+
+               
+               }
+
        }
 }
index ba17e0f..2d9462d 100644 (file)
@@ -18,6 +18,7 @@
     <ErrorReport>prompt</ErrorReport>\r
     <WarningLevel>4</WarningLevel>\r
     <ExternalConsole>true</ExternalConsole>\r
+    <Commandlineparameters>--heightmap ~/ApplicationData/vintagestory/Maps/World_19781215</Commandlineparameters>\r
   </PropertyGroup>\r
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">\r
     <Optimize>true</Optimize>\r
   </PropertyGroup>\r
   <ItemGroup>\r
     <Reference Include="System" />\r
+    <Reference Include="protobuf-net">\r
+      <HintPath>..\Automap\VS_libs\protobuf-net.dll</HintPath>\r
+    </Reference>\r
+    <Reference Include="Pngcs">\r
+      <HintPath>..\Automap\VS_libs\Pngcs.dll</HintPath>\r
+    </Reference>\r
+    <Reference Include="Newtonsoft.Json">\r
+      <HintPath>..\Automap\VS_libs\Newtonsoft.Json.dll</HintPath>\r
+    </Reference>\r
+    <Reference Include="Automap">\r
+      <HintPath>..\Automap\bin\Debug\Automap.dll</HintPath>\r
+    </Reference>\r
+    <Reference Include="VintagestoryAPI">\r
+      <HintPath>..\Automap\VS_libs\VintagestoryAPI.dll</HintPath>\r
+    </Reference>\r
+    <Reference Include="VintagestoryLib">\r
+      <HintPath>..\Automap\VS_libs\VintagestoryLib.dll</HintPath>\r
+    </Reference>\r
+    <Reference Include="VSEssentials">\r
+      <HintPath>..\Automap\VS_libs\VSEssentials.dll</HintPath>\r
+    </Reference>\r
+    <Reference Include="VSCreativeMod">\r
+      <HintPath>..\Automap\VS_libs\VSCreativeMod.dll</HintPath>\r
+    </Reference>\r
+    <Reference Include="VSSurvivalMod">\r
+      <HintPath>..\Automap\VS_libs\VSSurvivalMod.dll</HintPath>\r
+    </Reference>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <Compile Include="Program.cs" />\r