Advertisement
den3107

EE V.193 WorldData Deserialization

May 4th, 2015
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.63 KB | None | 0 0
  1.             // Original deserializer is made by Capasha, this is an updated and slightly improved version
  2.             // Original (outdated): http://pastebin.com/9uFrYtYp
  3.  
  4.             // It's advisable to place this code inside a method.
  5.             // Near the end of the code are instructions on how to handle the received blocks.
  6.  
  7.             // Return value
  8.             List<Block> blocks = new List<Block>();
  9.  
  10.             // Start of room data
  11.             uint current;
  12.             if (m.Type == "init")
  13.             {
  14.                 current = 26;
  15.             }
  16.             else
  17.             {
  18.                 current = 0;
  19.             }
  20.             var end = m.Count; // End of room data
  21.             int amount; // Get amount of times the first block excists
  22.  
  23.             // Variable declaration for (possible) block information (for easy reading what can be obtained)
  24.             int blockId = -1;
  25.             int layer;
  26.             List<int> x;
  27.             List<int> y;
  28.             int rotation;
  29.             int portalId;
  30.             int targetId;
  31.             int coins;
  32.             int deaths;
  33.             int switchId;
  34.             int color;
  35.             int status;
  36.             int duration;
  37.             int note;
  38.             String text;
  39.  
  40.             // Read all blocks
  41.             while (current < end)
  42.             {
  43.                 // For debugging
  44.                 String message = "";
  45.  
  46.                 // End if end of world data reached
  47.                 if (m[current].ToString() == "we")
  48.                 {
  49.                     break;
  50.                 }
  51.                 else if (m[current].ToString() == "ws")
  52.                 {
  53.                     current++;
  54.                 }
  55.                 else // End not reached
  56.                 {
  57.                     try
  58.                     {
  59.                         // Give everything unreal value
  60.                         // Use this to check if a block uses the parameter or not
  61.                         blockId = -1;
  62.                         layer = -1;
  63.                         x = new List<int>();
  64.                         y = new List<int>();
  65.                         rotation = -1;
  66.                         portalId = -1;
  67.                         targetId = -1;
  68.                         coins = -1;
  69.                         deaths = -1;
  70.                         switchId = -1;
  71.                         color = -1;
  72.                         status = -1;
  73.                         duration = -1;
  74.                         note = -1;
  75.                         text = null;
  76.  
  77.                         // Get real values
  78.  
  79.                         // Get block ID
  80.                         blockId = m.GetInt(current);
  81.                         message += "block ID: " + blockId;
  82.  
  83.                         // Get block layer
  84.                         layer = m.GetInt(current + 1);
  85.                         message += " ~~~ layer: " + layer;
  86.  
  87.                         // Get how many times this block excists
  88.                         amount = m.GetByteArray(current + 2).Length;
  89.  
  90.                         // Loop through all entries of this block to get position
  91.                         for (int n = 0; n < amount; n += 2)
  92.                         {
  93.                             // Get block coordinates
  94.                             x.Add(m.GetByteArray(current + 2)[n] << 8 | m.GetByteArray(current + 2)[n + 1]);
  95.                             y.Add(m.GetByteArray(current + 3)[n] << 8 | m.GetByteArray(current + 3)[n + 1]);
  96.                             message += " ~~~ x" + (x.Count - 1) + ": " + x[x.Count - 1];
  97.                             message += " ~~~ y" + (x.Count - 1) + ": " + y[x.Count - 1];
  98.                         }
  99.  
  100.                         if (blockId == 242 || blockId == 381) // Portal (0 down, 1 left, 2 up, 3 right)
  101.                         {
  102.                             rotation = m.GetInt(current + 4);
  103.                             portalId = m.GetInt(current + 5);
  104.                             targetId = m.GetInt(current + 6);
  105.                             message += " ~~~ rotation: " + rotation;
  106.                             message += " ~~~ portal ID: " + portalId;
  107.                             message += " ~~~ target ID: " + targetId;
  108.                         }
  109.  
  110.                         if (blockId == 43 || blockId == 165 || blockId == 214 || blockId == 213) // Coin/death door/gate
  111.                         {
  112.                             coins = m.GetInt(current + 4);
  113.                             message += " ~~~ coins: " + coins;
  114.                         }
  115.  
  116.                         if (blockId == 1012 || blockId == 1011) // death door/gate
  117.                         {
  118.                             deaths = m.GetInt(current + 4);
  119.                             message += " ~~~ deaths: " + deaths;
  120.                         }
  121.  
  122.                         if (blockId == 113 || blockId == 185 || blockId == 184) //switches and switch door/gate
  123.                         {
  124.                             switchId = m.GetInt(current + 4);
  125.                             message += " ~~~ switch ID: " + switchId;
  126.                         }
  127.  
  128.                         if (blockId == 1028 || blockId == 1027 || blockId == 423) // Team door/gate/effect
  129.                         {
  130.                             color = m.GetInt(current + 4); // (0 none, 1 red, 2 blue, 3 green, 4 cyan, 5 magenta, 6 yellow)
  131.                             message += " ~~~ color: " + color;
  132.                         }
  133.  
  134.                         if (blockId >= 417 && blockId <= 420) // Effects (curse and zombie excluded)
  135.                         {
  136.                             status = m.GetInt(current + 4); // (0 disable, 1 enable)
  137.                             message += " ~~~ on/off: " + status;
  138.                         }
  139.  
  140.                         if (blockId == 421 || blockId == 422) // Curse/zombie
  141.                         {
  142.                             duration = m.GetInt(current + 4); // (0 disable, 1 enable)
  143.                             message += " ~~~ duration: " + duration;
  144.                         }
  145.                        
  146.                         if (blockId == 361 || (blockId >= 1001 && blockId <= 1004) || (blockId >= 375 && blockId <= 380) || (blockId >= 438 && blockId <= 440) || (blockId >= 275 && blockId <= 277) || blockId == 279 || blockId == 280 || blockId == 329 || blockId == 273 || blockId == 327 || blockId == 328 || (blockId >= 338 && blockId <= 340)) // Rotatable
  147.                         {
  148.                             rotation = m.GetInt(current + 4); // (0 left, 1 up, 2 right, 3 down)
  149.                             message += " ~~~ rotation: " + rotation;
  150.                         }
  151.  
  152.                         if (blockId == 77 || blockId == 83) // Piano or Drums
  153.                         {
  154.                             note = m.GetInt(current + 4);
  155.                             message += " ~~~ note: " + note;
  156.                         }
  157.  
  158.                         if (blockId == 1000 || blockId == 385 || blockId == 374) // Label, Sign, World Portal
  159.                         {
  160.                             text = m.GetString(current + 4);
  161.                             message += " ~~~ text: " + text;
  162.                         }
  163.  
  164.                         // For debugging: the block (or border) is written to the console
  165.                         //Console.WriteLine("block info: " + message + "\n");
  166.  
  167.                         // Here you can handle the received parameters.
  168.                         // Make sure to make a check on the unreal values stated above.
  169.                         // If a value is unreal, that means that this wasn't a parameter for this block.
  170.  
  171.                         // Make sure it starts again at the correct position
  172.                         if (blockId == 43 || blockId == 165 || blockId == 214 || blockId == 213 || blockId == 1012 || blockId == 1011 || blockId == 113 || blockId == 185 || blockId == 184 || blockId == 1028 || blockId == 1027 || (blockId >= 417 && blockId <= 423) || blockId == 361 || (blockId >= 1000 && blockId <= 1004) || (blockId >= 374 && blockId <= 380) || (blockId >= 438 && blockId <= 440) || (blockId >= 275 && blockId <= 277) || blockId == 279 || blockId == 280 || (blockId >= 327 && blockId <= 329) || blockId == 273 || (blockId >= 338 && blockId <= 340) || blockId == 77 || blockId == 83 || blockId == 385) { current += 5; }
  173.                         else if (blockId == 242 || blockId == 381) { current += 7; }
  174.                         else { current += 4; }
  175.                     }
  176.                     catch (Exception ee)
  177.                     {
  178.                         Console.WriteLine("*** Error reading block: ***\nId: " + blockId + " Message: " + ee.Message);
  179.                     }
  180.                 }
  181.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement