SHARE
TWEET

BlockWorks - World Reader

capasha Sep 8th, 2017 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This is created by Processor/Yonom and updated by Capasha to work on BlockWorks.
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using PlayerIOClient;
  6. using System.Drawing;
  7.  
  8. namespace BlockWorksTest
  9. {
  10.     public static class InitParse
  11.     {
  12.         public static DataChunk[] Parse(Message m)
  13.         {
  14.             if (m == null) throw new ArgumentNullException("m");
  15.             if (m.Type != "world" && m.Type != "reset") throw new ArgumentException("Invalid message type.", "m");
  16.  
  17.             var p = 0u;
  18.             var data = new Stack<object>();
  19.             while (m[p++] as string != "WS") { }
  20.             p++;
  21.             while (m[p] as string != "WE") { data.Push(m[p++]); }
  22.  
  23.             var chunks = new List<DataChunk>();
  24.             while (data.Count > 0)
  25.             {
  26.                 var args = new Stack<object>();
  27.                 while (!(data.Peek() is byte[]))
  28.                     args.Push(data.Pop());
  29.                 var ys = (byte[])data.Pop();
  30.                 var xs = (byte[])data.Pop();
  31.                 var type = (uint)data.Pop();
  32.                 var layer = (int)data.Pop();
  33.  
  34.  
  35.  
  36.                 chunks.Add(new DataChunk(layer, type, xs, ys, args.ToArray()));
  37.             }
  38.  
  39.             return chunks.ToArray();
  40.         }
  41.  
  42.  
  43.         public class DataChunk
  44.         {
  45.             public int Layer { get; set; }
  46.             public uint Type { get; set; }
  47.             public Point[] Locations { get; set; }
  48.             public object[] Args { get; set; }
  49.  
  50.             public DataChunk(int layer, uint type, byte[] xs, byte[] ys, object[] args)
  51.             {
  52.                 this.Layer = layer;
  53.                 this.Type = type;
  54.                 this.Args = args;
  55.                 this.Locations = GetLocations(xs, ys);
  56.             }
  57.  
  58.             private static Point[] GetLocations(byte[] xs, byte[] ys)
  59.             {
  60.                 var points = new List<Point>();
  61.                 for (var i = 0; i < xs.Length; i += 1)
  62.                 {
  63.                     points.Add(new Point(xs[i], ys[i]));
  64.                 }
  65.                 return points.ToArray();
  66.             }
  67.         }
  68.  
  69.  
  70.         /* Only use for consoles public struct Point
  71.         {
  72.             public int X { get; set; }
  73.             public int Y { get; set; }
  74.  
  75.             public Point(int x, int y) : this()
  76.             {
  77.                 this.X = x;
  78.                 this.Y = y;
  79.             }
  80.         }*/
  81.     }
  82. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top