Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Original deserializer is made by Capasha, this is an updated and slightly improved version
- // Original (outdated): http://pastebin.com/9uFrYtYp
- // It's advisable to place this code inside a method.
- // Near the end of the code are instructions on how to handle the received blocks.
- // Return value
- List<Block> blocks = new List<Block>();
- // Start of room data
- uint current;
- if (m.Type == "init")
- {
- current = 26;
- }
- else
- {
- current = 0;
- }
- var end = m.Count; // End of room data
- int amount; // Get amount of times the first block excists
- // Variable declaration for (possible) block information (for easy reading what can be obtained)
- int blockId = -1;
- int layer;
- List<int> x;
- List<int> y;
- int rotation;
- int portalId;
- int targetId;
- int coins;
- int deaths;
- int switchId;
- int color;
- int status;
- int duration;
- int note;
- String text;
- // Read all blocks
- while (current < end)
- {
- // For debugging
- String message = "";
- // End if end of world data reached
- if (m[current].ToString() == "we")
- {
- break;
- }
- else if (m[current].ToString() == "ws")
- {
- current++;
- }
- else // End not reached
- {
- try
- {
- // Give everything unreal value
- // Use this to check if a block uses the parameter or not
- blockId = -1;
- layer = -1;
- x = new List<int>();
- y = new List<int>();
- rotation = -1;
- portalId = -1;
- targetId = -1;
- coins = -1;
- deaths = -1;
- switchId = -1;
- color = -1;
- status = -1;
- duration = -1;
- note = -1;
- text = null;
- // Get real values
- // Get block ID
- blockId = m.GetInt(current);
- message += "block ID: " + blockId;
- // Get block layer
- layer = m.GetInt(current + 1);
- message += " ~~~ layer: " + layer;
- // Get how many times this block excists
- amount = m.GetByteArray(current + 2).Length;
- // Loop through all entries of this block to get position
- for (int n = 0; n < amount; n += 2)
- {
- // Get block coordinates
- x.Add(m.GetByteArray(current + 2)[n] << 8 | m.GetByteArray(current + 2)[n + 1]);
- y.Add(m.GetByteArray(current + 3)[n] << 8 | m.GetByteArray(current + 3)[n + 1]);
- message += " ~~~ x" + (x.Count - 1) + ": " + x[x.Count - 1];
- message += " ~~~ y" + (x.Count - 1) + ": " + y[x.Count - 1];
- }
- if (blockId == 242 || blockId == 381) // Portal (0 down, 1 left, 2 up, 3 right)
- {
- rotation = m.GetInt(current + 4);
- portalId = m.GetInt(current + 5);
- targetId = m.GetInt(current + 6);
- message += " ~~~ rotation: " + rotation;
- message += " ~~~ portal ID: " + portalId;
- message += " ~~~ target ID: " + targetId;
- }
- if (blockId == 43 || blockId == 165 || blockId == 214 || blockId == 213) // Coin/death door/gate
- {
- coins = m.GetInt(current + 4);
- message += " ~~~ coins: " + coins;
- }
- if (blockId == 1012 || blockId == 1011) // death door/gate
- {
- deaths = m.GetInt(current + 4);
- message += " ~~~ deaths: " + deaths;
- }
- if (blockId == 113 || blockId == 185 || blockId == 184) //switches and switch door/gate
- {
- switchId = m.GetInt(current + 4);
- message += " ~~~ switch ID: " + switchId;
- }
- if (blockId == 1028 || blockId == 1027 || blockId == 423) // Team door/gate/effect
- {
- color = m.GetInt(current + 4); // (0 none, 1 red, 2 blue, 3 green, 4 cyan, 5 magenta, 6 yellow)
- message += " ~~~ color: " + color;
- }
- if (blockId >= 417 && blockId <= 420) // Effects (curse and zombie excluded)
- {
- status = m.GetInt(current + 4); // (0 disable, 1 enable)
- message += " ~~~ on/off: " + status;
- }
- if (blockId == 421 || blockId == 422) // Curse/zombie
- {
- duration = m.GetInt(current + 4); // (0 disable, 1 enable)
- message += " ~~~ duration: " + duration;
- }
- 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
- {
- rotation = m.GetInt(current + 4); // (0 left, 1 up, 2 right, 3 down)
- message += " ~~~ rotation: " + rotation;
- }
- if (blockId == 77 || blockId == 83) // Piano or Drums
- {
- note = m.GetInt(current + 4);
- message += " ~~~ note: " + note;
- }
- if (blockId == 1000 || blockId == 385 || blockId == 374) // Label, Sign, World Portal
- {
- text = m.GetString(current + 4);
- message += " ~~~ text: " + text;
- }
- // For debugging: the block (or border) is written to the console
- //Console.WriteLine("block info: " + message + "\n");
- // Here you can handle the received parameters.
- // Make sure to make a check on the unreal values stated above.
- // If a value is unreal, that means that this wasn't a parameter for this block.
- // Make sure it starts again at the correct position
- 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; }
- else if (blockId == 242 || blockId == 381) { current += 7; }
- else { current += 4; }
- }
- catch (Exception ee)
- {
- Console.WriteLine("*** Error reading block: ***\nId: " + blockId + " Message: " + ee.Message);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement