Write() public method

Write data to the stream.

If you wish to use the DeflateStream to compress data while writing, you can create a DeflateStream with CompressionMode.Compress, and a writable output stream. Then call Write() on that DeflateStream, providing uncompressed data as input. The data sent to the output stream will be the compressed form of the data written. If you wish to use the DeflateStream to decompress data while writing, you can create a DeflateStream with CompressionMode.Decompress, and a writable output stream. Then call Write() on that stream, providing previously compressed data. The data sent to the output stream will be the decompressed form of the data written.

A DeflateStream can be used for Read() or Write(), but not both.

public Write ( byte buffer, int offset, int count ) : void
buffer byte The buffer holding data to write to the stream.
offset int the offset within that data array to find the first byte to write.
count int the number of bytes to write.
return void
        /// <summary>
        /// 지정된 데이타를 압축한다.
        /// </summary>
        /// <param name="input">압축할 Data</param>
        /// <returns>압축된 Data</returns>
        public override byte[] Compress(byte[] input) {
            if(IsDebugEnabled)
                log.Debug(CompressorTool.SR.CompressStartMsg);

            // check input data
            if(input.IsZeroLength()) {
                if(IsDebugEnabled)
                    log.Debug(CompressorTool.SR.InvalidInputDataMsg);

                return CompressorTool.EmptyBytes;
            }

            byte[] output;
            using(var outStream = new MemoryStream()) {
                using(var deflate = new DeflateStream(outStream, CompressionMode.Compress, CompressionLevel.BestSpeed)) {
                    deflate.Write(input, 0, input.Length);
                }
                output = outStream.ToArray();
            }

            if(IsDebugEnabled)
                log.Debug(CompressorTool.SR.CompressResultMsg, input.Length, output.Length, output.Length / (double)input.Length);

            return output;
        }
示例#2
0
        private byte[] compress(byte[] a, int level)
        {
            using (var ms = new MemoryStream())
            {
                CompressionLevel compressionLevel = CompressionLevel.Default;

                switch (level)
                {
                case 0:
                    compressionLevel = CompressionLevel.Level0;
                    break;

                case 1:
                    compressionLevel = CompressionLevel.Level1;
                    break;

                case 2:
                    compressionLevel = CompressionLevel.Level2;
                    break;

                case 3:
                    compressionLevel = CompressionLevel.Level3;
                    break;

                case 4:
                    compressionLevel = CompressionLevel.Level4;
                    break;

                case 5:
                    compressionLevel = CompressionLevel.Level5;
                    break;

                case 6:
                    compressionLevel = CompressionLevel.Level6;
                    break;

                case 7:
                    compressionLevel = CompressionLevel.Level7;
                    break;

                case 8:
                    compressionLevel = CompressionLevel.Level8;
                    break;

                case 9:
                    compressionLevel = CompressionLevel.Level9;
                    break;
                }

                using (var compresssor = new Ionic.Zlib.DeflateStream(ms, CompressionMode.Compress, compressionLevel))
                {
                    compresssor.Write(a, 0, a.Length);
                }
                return(ms.ToArray());
            }
        }
示例#3
0
		/// <summary>Deflate encoder, compatible with .NET one but with bettern compression 
		/// ratio (in .NET 4.0, in .NET 4.5 they are identical).</summary>
		/// <param name="input">The input.</param>
		/// <returns>Compressed data.</returns>
		public static byte[] DeflateEncoder(byte[] input)
		{
			using (var ostream = new MemoryStream())
			{
				using (var zstream = new DeflateStream(ostream, CompressionMode.Compress))
				{
					zstream.Write(input, 0, input.Length);
					zstream.Flush();
				}
				return ostream.ToArray();
			}
		}
        public static byte[] CompressDeflate(byte[] bytes)
        {
            using (var ms = new MemoryStream())
            {
                using (var zip = new DeflateStream(ms, CompressionMode.Compress, true))
                {
                    zip.Write(bytes, 0, bytes.Length);
                }

                return ms.ToArray();
            }
        }
        private static byte[] Deflate(byte[] bytes)
        {
            if (bytes == null) return new byte[0];

            using (var stream = new MemoryStream())
            {
                using (var compressor = new DeflateStream(stream,CompressionMode.Compress, CompressionLevel.BestSpeed))
                {
                    compressor.Write(bytes, 0, bytes.Length);
                }

                return stream.ToArray();
            }
        }
        public static byte[] DeflateByte(byte[] content)
        {
            if(null==content)
            {
                return null;
            }

            using (var stream = new MemoryStream())
            {
                using (var compressor = new DeflateStream(stream,CompressionMode.Compress,CompressionLevel.BestSpeed))
                {
                    compressor.Write(content,0,content.Length);
                }

                return stream.ToArray();
            }
        }
示例#7
0
文件: ZlibHelper.cs 项目: Wroud/Coob
 public static byte[] CompressBuffer(byte[] buffer, ushort key, uint keyend)
 {
     byte[] compressed;
     using (var compressStream = new MemoryStream())
     using (var compressor = new DeflateStream(compressStream, CompressionMode.Compress))
     {
         compressor.Write(buffer, 0, buffer.Length);
         compressor.Close();
         compressed = compressStream.ToArray();
     }
     byte[] returnbytes = new byte[compressed.Length + 6];
     byte[] kbyte = BitConverter.GetBytes(key);
     byte[] kebyte = BitConverter.GetBytes(keyend);
     Array.Copy(kbyte, 0, returnbytes, 0, kbyte.Length);
     Array.Copy(compressed, 0, returnbytes, 2, compressed.Length);
     Array.Copy(kebyte, 0, returnbytes, returnbytes.Length - 4, kebyte.Length);
     return returnbytes;
 }
示例#8
0
    public static byte[] DeflateByte(byte[] str)
    {
        if (str == null)
        {
            return(null);
        }

        using (var output = new MemoryStream())
        {
            using (
                var compressor = new Ionic.Zlib.DeflateStream(
                    output, Ionic.Zlib.CompressionMode.Compress,
                    Ionic.Zlib.CompressionLevel.BestSpeed))
            {
                compressor.Write(str, 0, str.Length);
            }

            return(output.ToArray());
        }
    }
        public static byte[] DeflateByte(byte[] str)
        {
            if (str == null)
            {
                return null;
            }

            using (var output = new MemoryStream())
            {
                using (
                    var compressor = new DeflateStream(
                    output, CompressionMode.Compress,
                    CompressionLevel.BestSpeed))
                {
                    compressor.Write(str, 0, str.Length);
                }

                return output.ToArray();
            }
        }
		public static void SaveMap()
		{
			bool isCloudSave = Main.ActivePlayerFileData.IsCloudSave;
			if (isCloudSave && SocialAPI.Cloud == null)
			{
				return;
			}
			if (!Main.mapEnabled || MapHelper.saveLock)
			{
				return;
			}
			string text = Main.playerPathName.Substring(0, Main.playerPathName.Length - 4);
			lock (MapHelper.padlock)
			{
				try
				{
					MapHelper.saveLock = true;
					try
					{
						if (!isCloudSave)
						{
							Directory.CreateDirectory(text);
						}
					}
					catch
					{
					}
					text = string.Concat(new object[]
					{
						text,
						Path.DirectorySeparatorChar,
						Main.worldID,
						".map"
					});
					Stopwatch stopwatch = new Stopwatch();
					stopwatch.Start();
					bool flag2 = false;
					if (!Main.gameMenu)
					{
						flag2 = true;
					}
					using (MemoryStream memoryStream = new MemoryStream(4000))
					{
						using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
						{
							using (DeflateStream deflateStream = new DeflateStream(memoryStream, 0))
							{
								int num = 0;
								byte[] array = new byte[16384];
								binaryWriter.Write(Main.curRelease);
								Main.MapFileMetadata.IncrementAndWrite(binaryWriter);
								binaryWriter.Write(Main.worldName);
								binaryWriter.Write(Main.worldID);
								binaryWriter.Write(Main.maxTilesY);
								binaryWriter.Write(Main.maxTilesX);
                                binaryWriter.Write((short)(419 + Main.ulterrariaTiles));//
                                binaryWriter.Write((short)225 + Main.ulterrariaWalls);
                                binaryWriter.Write((short)3);
                                binaryWriter.Write((short)256);
                                binaryWriter.Write((short)256);
                                binaryWriter.Write((short)256);
								byte b = 1;
								byte b2 = 0;
								int i;
                                for (i = 0; i < 419 + Main.ulterrariaTiles; i++)
								{
									if (MapHelper.tileOptionCounts[i] != 1)
									{
										b2 |= b;
									}
									if (b == 128)
									{
										binaryWriter.Write(b2);
										b2 = 0;
										b = 1;
									}
									else
									{
										b = (byte)(b << 1);
									}
								}
								if (b != 1)
								{
									binaryWriter.Write(b2);
								}
								i = 0;
								b = 1;
								b2 = 0;
                                while (i < 225 + Main.ulterrariaWalls)
								{
									if (MapHelper.wallOptionCounts[i] != 1)
									{
										b2 |= b;
									}
									if (b == 128)
									{
										binaryWriter.Write(b2);
										b2 = 0;
										b = 1;
									}
									else
									{
										b = (byte)(b << 1);
									}
									i++;
								}
								if (b != 1)
								{
									binaryWriter.Write(b2);
								}
                                for (i = 0; i < 419 + Main.ulterrariaTiles; i++)
								{
									if (MapHelper.tileOptionCounts[i] != 1)
									{
										binaryWriter.Write((byte)MapHelper.tileOptionCounts[i]);
									}
								}
                                for (i = 0; i < 225 + Main.ulterrariaWalls; i++)
								{
									if (MapHelper.wallOptionCounts[i] != 1)
									{
										binaryWriter.Write((byte)MapHelper.wallOptionCounts[i]);
									}
								}
								binaryWriter.Flush();
								for (int j = 0; j < Main.maxTilesY; j++)
								{
									if (!flag2)
									{
										float num2 = (float)j / (float)Main.maxTilesY;
										Main.statusText = string.Concat(new object[]
										{
											Lang.gen[66],
											" ",
											(int)(num2 * 100f + 1f),
											"%"
										});
									}
									for (int k = 0; k < Main.maxTilesX; k++)
									{
										MapTile mapTile = Main.Map[k, j];
										byte b4;
										byte b3 = b4 = 0;
										bool flag3 = true;
										bool flag4 = true;
										int num3 = 0;
										int num4 = 0;
										byte b5 = 0;
										int num5;
										ushort num6;
										int num7;
										if (mapTile.Light <= 18)
										{
											flag4 = false;
											flag3 = false;
											num5 = 0;
											num6 = 0;
											num7 = 0;
											int num8 = k + 1;
											int l = Main.maxTilesX - k - 1;
											while (l > 0)
											{
												if (Main.Map[num8, j].Light > 18)
												{
													break;
												}
												num7++;
												l--;
												num8++;
											}
										}
										else
										{
											b5 = mapTile.Color;
											num6 = mapTile.Type;
											if (num6 < MapHelper.wallPosition)
											{
												num5 = 1;
												num6 -= MapHelper.tilePosition;
											}
											else if (num6 < MapHelper.liquidPosition)
											{
												num5 = 2;
												num6 -= MapHelper.wallPosition;
											}
											else if (num6 < MapHelper.skyPosition)
											{
												num5 = (int)(3 + (num6 - MapHelper.liquidPosition));
												flag3 = false;
											}
											else if (num6 < MapHelper.dirtPosition)
											{
												num5 = 6;
												flag4 = false;
												flag3 = false;
											}
											else if (num6 < MapHelper.hellPosition)
											{
												num5 = 7;
												if (num6 < MapHelper.rockPosition)
												{
													num6 -= MapHelper.dirtPosition;
												}
												else
												{
													num6 -= MapHelper.rockPosition;
												}
											}
											else
											{
												num5 = 6;
												flag3 = false;
											}
											if (mapTile.Light == 255)
											{
												flag4 = false;
											}
											if (flag4)
											{
												num7 = 0;
												int num8 = k + 1;
												int l = Main.maxTilesX - k - 1;
												num3 = num8;
												while (l > 0)
												{
													MapTile mapTile2 = Main.Map[num8, j];
													if (!mapTile.EqualsWithoutLight(ref mapTile2))
													{
														num4 = num8;
														break;
													}
													l--;
													num7++;
													num8++;
												}
											}
											else
											{
												num7 = 0;
												int num8 = k + 1;
												int l = Main.maxTilesX - k - 1;
												while (l > 0)
												{
													MapTile mapTile3 = Main.Map[num8, j];
													if (!mapTile.Equals(ref mapTile3))
													{
														break;
													}
													l--;
													num7++;
													num8++;
												}
											}
										}
										if (b5 > 0)
										{
											b3 |= (byte)(b5 << 1);
										}
										if (b3 != 0)
										{
											b4 |= 1;
										}
										b4 |= (byte)(num5 << 1);
										if (flag3 && num6 > 255)
										{
											b4 |= 16;
										}
										if (flag4)
										{
											b4 |= 32;
										}
										if (num7 > 0)
										{
											if (num7 > 255)
											{
												b4 |= 128;
											}
											else
											{
												b4 |= 64;
											}
										}
										array[num] = b4;
										num++;
										if (b3 != 0)
										{
											array[num] = b3;
											num++;
										}
										if (flag3)
										{
											array[num] = (byte)num6;
											num++;
											if (num6 > 255)
											{
												array[num] = (byte)(num6 >> 8);
												num++;
											}
										}
										if (flag4)
										{
											array[num] = mapTile.Light;
											num++;
										}
										if (num7 > 0)
										{
											array[num] = (byte)num7;
											num++;
											if (num7 > 255)
											{
												array[num] = (byte)(num7 >> 8);
												num++;
											}
										}
										for (int m = num3; m < num4; m++)
										{
											array[num] = Main.Map[m, j].Light;
											num++;
										}
										k += num7;
										if (num >= 4096)
										{
											deflateStream.Write(array, 0, num);
											num = 0;
										}
									}
								}
								if (num > 0)
								{
									deflateStream.Write(array, 0, num);
								}
								deflateStream.Dispose();
								FileUtilities.WriteAllBytes(text, memoryStream.ToArray(), isCloudSave);
							}
						}
					}
				}
				catch (Exception value)
				{
					using (StreamWriter streamWriter = new StreamWriter("client-crashlog.txt", true))
					{
						streamWriter.WriteLine(DateTime.Now);
						streamWriter.WriteLine(value);
						streamWriter.WriteLine("");
					}
				}
				MapHelper.saveLock = false;
			}
		}
示例#11
0
 /*public static void SaveMap()
 {
     bool isCloudSave = Main.ActivePlayerFileData.IsCloudSave;
     if (isCloudSave && SocialAPI.Cloud == null)
     {
         return;
     }
     if (!Main.mapEnabled || MapHelper.saveLock)
     {
         return;
     }
     string text = Main.playerPathName.Substring(0, Main.playerPathName.Length - 4);
     lock (MapHelper.padlock)
     {
         try
         {
             MapHelper.saveLock = true;
             try
             {
                 if (!isCloudSave)
                 {
                     Directory.CreateDirectory(text);
                 }
             }
             catch
             {
             }
             text = string.Concat(new object[]
             {
                 text,
                 Path.DirectorySeparatorChar,
                 Main.worldID,
                 ".map"
             });
             Stopwatch stopwatch = new Stopwatch();
             stopwatch.Start();
             bool flag2 = false;
             if (!Main.gameMenu)
             {
                 flag2 = true;
             }
             using (MemoryStream memoryStream = new MemoryStream(4000))
             {
                 using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
                 {
                     using (DeflateStream deflateStream = new DeflateStream(memoryStream, 0))
                     {
                         int num = 0;
                         byte[] array = new byte[16384];
                         binaryWriter.Write(Main.curRelease);
                         Main.MapFileMetadata.IncrementAndWrite(binaryWriter);
                         binaryWriter.Write(Main.worldName);
                         binaryWriter.Write(Main.worldID);
                         binaryWriter.Write(Main.maxTilesY);
                         binaryWriter.Write(Main.maxTilesX);
                         binaryWriter.Write(419);
                         binaryWriter.Write(225);
                         binaryWriter.Write(3);
                         binaryWriter.Write(256);
                         binaryWriter.Write(256);
                         binaryWriter.Write(256);
                         byte b = 1;
                         byte b2 = 0;
                         int i;
                         for (i = 0; i < 419; i++)
                         {
                             if (MapHelper.tileOptionCounts[i] != 1)
                             {
                                 b2 |= b;
                             }
                             if (b == 128)
                             {
                                 binaryWriter.Write(b2);
                                 b2 = 0;
                                 b = 1;
                             }
                             else
                             {
                                 b = (byte)(b << 1);
                             }
                         }
                         if (b != 1)
                         {
                             binaryWriter.Write(b2);
                         }
                         i = 0;
                         b = 1;
                         b2 = 0;
                         while (i < 225)
                         {
                             if (MapHelper.wallOptionCounts[i] != 1)
                             {
                                 b2 |= b;
                             }
                             if (b == 128)
                             {
                                 binaryWriter.Write(b2);
                                 b2 = 0;
                                 b = 1;
                             }
                             else
                             {
                                 b = (byte)(b << 1);
                             }
                             i++;
                         }
                         if (b != 1)
                         {
                             binaryWriter.Write(b2);
                         }
                         for (i = 0; i < 419; i++)
                         {
                             if (MapHelper.tileOptionCounts[i] != 1)
                             {
                                 binaryWriter.Write((byte)MapHelper.tileOptionCounts[i]);
                             }
                         }
                         for (i = 0; i < 225; i++)
                         {
                             if (MapHelper.wallOptionCounts[i] != 1)
                             {
                                 binaryWriter.Write((byte)MapHelper.wallOptionCounts[i]);
                             }
                         }
                         binaryWriter.Flush();
                         for (int j = 0; j < Main.maxTilesY; j++)
                         {
                             if (!flag2)
                             {
                                 float num2 = (float)j / (float)Main.maxTilesY;
                                 Main.statusText = string.Concat(new object[]
                                 {
                                     Lang.gen[66],
                                     " ",
                                     (int)(num2 * 100f + 1f),
                                     "%"
                                 });
                             }
                             for (int k = 0; k < Main.maxTilesX; k++)
                             {
                                 MapTile mapTile = Main.Map[k, j];
                                 byte b4;
                                 byte b3 = b4 = 0;
                                 bool flag3 = true;
                                 bool flag4 = true;
                                 int num3 = 0;
                                 int num4 = 0;
                                 byte b5 = 0;
                                 int num5;
                                 ushort num6;
                                 int num7;
                                 if (mapTile.Light <= 18)
                                 {
                                     flag4 = false;
                                     flag3 = false;
                                     num5 = 0;
                                     num6 = 0;
                                     num7 = 0;
                                     int num8 = k + 1;
                                     int l = Main.maxTilesX - k - 1;
                                     while (l > 0)
                                     {
                                         if (Main.Map[num8, j].Light > 18)
                                         {
                                             break;
                                         }
                                         num7++;
                                         l--;
                                         num8++;
                                     }
                                 }
                                 else
                                 {
                                     b5 = mapTile.Color;
                                     num6 = mapTile.Type;
                                     if (num6 < MapHelper.wallPosition)
                                     {
                                         num5 = 1;
                                         num6 -= MapHelper.tilePosition;
                                     }
                                     else if (num6 < MapHelper.liquidPosition)
                                     {
                                         num5 = 2;
                                         num6 -= MapHelper.wallPosition;
                                     }
                                     else if (num6 < MapHelper.skyPosition)
                                     {
                                         num5 = (int)(3 + (num6 - MapHelper.liquidPosition));
                                         flag3 = false;
                                     }
                                     else if (num6 < MapHelper.dirtPosition)
                                     {
                                         num5 = 6;
                                         flag4 = false;
                                         flag3 = false;
                                     }
                                     else if (num6 < MapHelper.hellPosition)
                                     {
                                         num5 = 7;
                                         if (num6 < MapHelper.rockPosition)
                                         {
                                             num6 -= MapHelper.dirtPosition;
                                         }
                                         else
                                         {
                                             num6 -= MapHelper.rockPosition;
                                         }
                                     }
                                     else
                                     {
                                         num5 = 6;
                                         flag3 = false;
                                     }
                                     if (mapTile.Light == 255)
                                     {
                                         flag4 = false;
                                     }
                                     if (flag4)
                                     {
                                         num7 = 0;
                                         int num8 = k + 1;
                                         int l = Main.maxTilesX - k - 1;
                                         num3 = num8;
                                         while (l > 0)
                                         {
                                             MapTile mapTile2 = Main.Map[num8, j];
                                             if (!mapTile.EqualsWithoutLight(ref mapTile2))
                                             {
                                                 num4 = num8;
                                                 break;
                                             }
                                             l--;
                                             num7++;
                                             num8++;
                                         }
                                     }
                                     else
                                     {
                                         num7 = 0;
                                         int num8 = k + 1;
                                         int l = Main.maxTilesX - k - 1;
                                         while (l > 0)
                                         {
                                             MapTile mapTile3 = Main.Map[num8, j];
                                             if (!mapTile.Equals(ref mapTile3))
                                             {
                                                 break;
                                             }
                                             l--;
                                             num7++;
                                             num8++;
                                         }
                                     }
                                 }
                                 if (b5 > 0)
                                 {
                                     b3 |= (byte)(b5 << 1);
                                 }
                                 if (b3 != 0)
                                 {
                                     b4 |= 1;
                                 }
                                 b4 |= (byte)(num5 << 1);
                                 if (flag3 && num6 > 255)
                                 {
                                     b4 |= 16;
                                 }
                                 if (flag4)
                                 {
                                     b4 |= 32;
                                 }
                                 if (num7 > 0)
                                 {
                                     if (num7 > 255)
                                     {
                                         b4 |= 128;
                                     }
                                     else
                                     {
                                         b4 |= 64;
                                     }
                                 }
                                 array[num] = b4;
                                 num++;
                                 if (b3 != 0)
                                 {
                                     array[num] = b3;
                                     num++;
                                 }
                                 if (flag3)
                                 {
                                     array[num] = (byte)num6;
                                     num++;
                                     if (num6 > 255)
                                     {
                                         array[num] = (byte)(num6 >> 8);
                                         num++;
                                     }
                                 }
                                 if (flag4)
                                 {
                                     array[num] = mapTile.Light;
                                     num++;
                                 }
                                 if (num7 > 0)
                                 {
                                     array[num] = (byte)num7;
                                     num++;
                                     if (num7 > 255)
                                     {
                                         array[num] = (byte)(num7 >> 8);
                                         num++;
                                     }
                                 }
                                 for (int m = num3; m < num4; m++)
                                 {
                                     array[num] = Main.Map[m, j].Light;
                                     num++;
                                 }
                                 k += num7;
                                 if (num >= 4096)
                                 {
                                     deflateStream.Write(array, 0, num);
                                     num = 0;
                                 }
                             }
                         }
                         if (num > 0)
                         {
                             deflateStream.Write(array, 0, num);
                         }
                         deflateStream.Dispose();
                         FileUtilities.WriteAllBytes(text, memoryStream.ToArray(), isCloudSave);
                     }
                 }
             }
         }
         catch (Exception value)
         {
             using (StreamWriter streamWriter = new StreamWriter("client-crashlog.txt", true))
             {
                 streamWriter.WriteLine(DateTime.Now);
                 streamWriter.WriteLine(value);
                 streamWriter.WriteLine("");
             }
         }
         MapHelper.saveLock = false;
     }
 }*/
 public static void SaveMap()
 {
     int i;
     int num;
     int num1;
     ushort type;
     int num2;
     bool isCloudSave = Main.ActivePlayerFileData.IsCloudSave;
     if (isCloudSave && SocialAPI.Cloud == null)
     {
         return;
     }
     if (!Main.mapEnabled || MapHelper.saveLock)
     {
         return;
     }
     string str = Main.playerPathName.Substring(0, Main.playerPathName.Length - 4);
     lock (MapHelper.padlock)
     {
         try
         {
             MapHelper.saveLock = true;
             try
             {
                 if (!isCloudSave)
                 {
                     Directory.CreateDirectory(str);
                 }
             }
             catch
             {
             }
             object[] directorySeparatorChar = new object[] { str, Path.DirectorySeparatorChar, Main.worldID, ".map" };
             str = string.Concat(directorySeparatorChar);
             (new Stopwatch()).Start();
             bool flag = false;
             if (!Main.gameMenu)
             {
                 flag = true;
             }
             using (MemoryStream memoryStream = new MemoryStream(4000))
             {
                 using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
                 {
                     using (DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionMode.Compress))
                     {
                         int num3 = 0;
                         byte[] light = new byte[16384];
                         binaryWriter.Write(Main.curRelease);
                         Main.MapFileMetadata.IncrementAndWrite(binaryWriter);
                         binaryWriter.Write(Main.worldName);
                         binaryWriter.Write(Main.worldID);
                         binaryWriter.Write(Main.maxTilesY);
                         binaryWriter.Write(Main.maxTilesX);
                         binaryWriter.Write((short)419);
                         binaryWriter.Write((short)225);
                         binaryWriter.Write((short)3);
                         binaryWriter.Write((short)256);
                         binaryWriter.Write((short)256);
                         binaryWriter.Write((short)256);
                         byte num4 = 1;
                         byte num5 = 0;
                         for (i = 0; i < 419; i++)
                         {
                             if (MapHelper.tileOptionCounts[i] != 1)
                             {
                                 num5 = (byte)(num5 | num4);
                             }
                             if (num4 != 128)
                             {
                                 num4 = (byte)(num4 << 1);
                             }
                             else
                             {
                                 binaryWriter.Write(num5);
                                 num5 = 0;
                                 num4 = 1;
                             }
                         }
                         if (num4 != 1)
                         {
                             binaryWriter.Write(num5);
                         }
                         i = 0;
                         num4 = 1;
                         num5 = 0;
                         while (i < 225)
                         {
                             if (MapHelper.wallOptionCounts[i] != 1)
                             {
                                 num5 = (byte)(num5 | num4);
                             }
                             if (num4 != 128)
                             {
                                 num4 = (byte)(num4 << 1);
                             }
                             else
                             {
                                 binaryWriter.Write(num5);
                                 num5 = 0;
                                 num4 = 1;
                             }
                             i++;
                         }
                         if (num4 != 1)
                         {
                             binaryWriter.Write(num5);
                         }
                         for (i = 0; i < 419; i++)
                         {
                             if (MapHelper.tileOptionCounts[i] != 1)
                             {
                                 binaryWriter.Write((byte)MapHelper.tileOptionCounts[i]);
                             }
                         }
                         for (i = 0; i < 225; i++)
                         {
                             if (MapHelper.wallOptionCounts[i] != 1)
                             {
                                 binaryWriter.Write((byte)MapHelper.wallOptionCounts[i]);
                             }
                         }
                         binaryWriter.Flush();
                         for (int j = 0; j < Main.maxTilesY; j++)
                         {
                             if (!flag)
                             {
                                 float single = (float)j / (float)Main.maxTilesY;
                                 object[] objArray = new object[] { Lang.gen[66], " ", (int)(single * 100f + 1f), "%" };
                                 Main.statusText = string.Concat(objArray);
                             }
                             for (int k = 0; k < Main.maxTilesX; k++)
                             {
                                 MapTile item = Main.Map[k, j];
                                 int num6 = 0;
                                 byte num7 = (byte)num6;
                                 byte num8 = (byte)num6;
                                 int num9 = 0;
                                 bool flag1 = true;
                                 bool flag2 = true;
                                 int num10 = 0;
                                 int num11 = 0;
                                 byte color = 0;
                                 if (item.Light > 18)
                                 {
                                     color = item.Color;
                                     type = item.Type;
                                     if (type < MapHelper.wallPosition)
                                     {
                                         num1 = 1;
                                         type = (ushort)(type - MapHelper.tilePosition);
                                     }
                                     else if (type < MapHelper.liquidPosition)
                                     {
                                         num1 = 2;
                                         type = (ushort)(type - MapHelper.wallPosition);
                                     }
                                     else if (type < MapHelper.skyPosition)
                                     {
                                         num1 = 3 + (type - MapHelper.liquidPosition);
                                         flag1 = false;
                                     }
                                     else if (type < MapHelper.dirtPosition)
                                     {
                                         num1 = 6;
                                         flag2 = false;
                                         flag1 = false;
                                     }
                                     else if (type >= MapHelper.hellPosition)
                                     {
                                         num1 = 6;
                                         flag1 = false;
                                     }
                                     else
                                     {
                                         num1 = 7;
                                         type = (type >= MapHelper.rockPosition ? (ushort)(type - MapHelper.rockPosition) : (ushort)(type - MapHelper.dirtPosition));
                                     }
                                     if (item.Light == 255)
                                     {
                                         flag2 = false;
                                     }
                                     if (!flag2)
                                     {
                                         num9 = 0;
                                         num = k + 1;
                                         num2 = Main.maxTilesX - k - 1;
                                         while (num2 > 0)
                                         {
                                             MapTile mapTile = Main.Map[num, j];
                                             if (!item.Equals(ref mapTile))
                                             {
                                                 break;
                                             }
                                             num2--;
                                             num9++;
                                             num++;
                                         }
                                     }
                                     else
                                     {
                                         num9 = 0;
                                         num = k + 1;
                                         num2 = Main.maxTilesX - k - 1;
                                         num10 = num;
                                         while (num2 > 0)
                                         {
                                             MapTile item1 = Main.Map[num, j];
                                             if (!item.EqualsWithoutLight(ref item1))
                                             {
                                                 num11 = num;
                                                 goto Label0;
                                             }
                                             else
                                             {
                                                 num2--;
                                                 num9++;
                                                 num++;
                                             }
                                         }
                                     }
                                 }
                                 else
                                 {
                                     flag2 = false;
                                     flag1 = false;
                                     num1 = 0;
                                     type = 0;
                                     num9 = 0;
                                     num = k + 1;
                                     num2 = Main.maxTilesX - k - 1;
                                     while (num2 > 0)
                                     {
                                         if (Main.Map[num, j].Light > 18)
                                         {
                                             goto Label0;
                                         }
                                         num9++;
                                         num2--;
                                         num++;
                                     }
                                 }
                             Label0:
                                 if (color > 0)
                                 {
                                     num7 = (byte)(num7 | (byte)(color << 1));
                                 }
                                 if (num7 != 0)
                                 {
                                     num8 = (byte)(num8 | 1);
                                 }
                                 num8 = (byte)(num8 | (byte)(num1 << 1));
                                 if (flag1 && type > 255)
                                 {
                                     num8 = (byte)(num8 | 16);
                                 }
                                 if (flag2)
                                 {
                                     num8 = (byte)(num8 | 32);
                                 }
                                 if (num9 > 0)
                                 {
                                     num8 = (num9 <= 255 ? (byte)(num8 | 64) : (byte)(num8 | 128));
                                 }
                                 light[num3] = num8;
                                 num3++;
                                 if (num7 != 0)
                                 {
                                     light[num3] = num7;
                                     num3++;
                                 }
                                 if (flag1)
                                 {
                                     light[num3] = (byte)type;
                                     num3++;
                                     if (type > 255)
                                     {
                                         light[num3] = (byte)(type >> 8);
                                         num3++;
                                     }
                                 }
                                 if (flag2)
                                 {
                                     light[num3] = item.Light;
                                     num3++;
                                 }
                                 if (num9 > 0)
                                 {
                                     light[num3] = (byte)num9;
                                     num3++;
                                     if (num9 > 255)
                                     {
                                         light[num3] = (byte)(num9 >> 8);
                                         num3++;
                                     }
                                 }
                                 for (int l = num10; l < num11; l++)
                                 {
                                     light[num3] = Main.Map[l, j].Light;
                                     num3++;
                                 }
                                 k = k + num9;
                                 if (num3 >= 4096)
                                 {
                                     deflateStream.Write(light, 0, num3);
                                     num3 = 0;
                                 }
                             }
                         }
                         if (num3 > 0)
                         {
                             deflateStream.Write(light, 0, num3);
                         }
                         deflateStream.Dispose();
                         FileUtilities.WriteAllBytes(str, memoryStream.ToArray(), isCloudSave);
                     }
                 }
             }
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             using (StreamWriter streamWriter = new StreamWriter("client-crashlog.txt", true))
             {
                 streamWriter.WriteLine(DateTime.Now);
                 streamWriter.WriteLine(exception);
                 streamWriter.WriteLine("");
             }
         }
         MapHelper.saveLock = false;
     }
 }
示例#12
0
        private void PerformTrialWi8870(byte[] buffer)
        {
            TestContext.WriteLine("Original");

            byte[] compressedBytes = null;
            using (MemoryStream ms1 = new MemoryStream())
            {
                using (DeflateStream compressor = new DeflateStream(ms1, CompressionMode.Compress, false))
                {
                    compressor.Write(buffer, 0, buffer.Length);
                }
                compressedBytes = ms1.ToArray();
            }

            TestContext.WriteLine("Compressed {0} bytes into {1} bytes",
                                  buffer.Length, compressedBytes.Length);

            byte[] decompressed= null;
            using (MemoryStream ms2 = new MemoryStream())
            {
                using (var deflateStream = new DeflateStream(ms2, CompressionMode.Decompress, false))
                {
                    deflateStream.Write(compressedBytes, 0, compressedBytes.Length);
                }
                decompressed = ms2.ToArray();
            }

            TestContext.WriteLine("Decompressed");


            bool check = true;
            if (buffer.Length != decompressed.Length)
            {
                TestContext.WriteLine("Different lengths.");
                check = false;
            }
            else
            {
                for (int i=0; i < buffer.Length; i++)
                {
                    if (buffer[i] != decompressed[i])
                    {
                        TestContext.WriteLine("byte {0} differs", i);
                        check = false;
                        break;
                    }
                }
            }

            Assert.IsTrue(check,"Data check failed.");
        }
示例#13
0
        private static void inflate(out byte[] conversionBuffer)
        {
            byte[] bufferin = null;
            foreach (PngTrunk dataTrunk in _trunks)
            {
                if (dataTrunk.getName().Equals("IDAT", StringComparison.OrdinalIgnoreCase))
                {
                    bufferin = dataTrunk.getData();

                }
            }
            var ms = new MemoryStream();
            var deflateStream = new DeflateStream(ms,CompressionMode.Decompress,true);
            if (bufferin != null) deflateStream.Write(bufferin,0,bufferin.Length);
            conversionBuffer = ms.GetBuffer();
        }