コード例 #1
0
        public void ConvertChunks(string directoryName)
        {
            string path  = Storage.CombinePaths(directoryName, "Chunks.dat");
            string path2 = Storage.CombinePaths(directoryName, "Chunks32.dat");

            using (Stream stream2 = Storage.OpenFile(path, OpenFileMode.Read))
            {
                using (Stream stream = Storage.OpenFile(path2, OpenFileMode.Create))
                {
                    byte[] array  = new byte[65536];
                    byte[] array2 = new byte[131072];
                    for (int i = 0; i < 65537; i++)
                    {
                        TerrainSerializer129.WriteTOCEntry(stream, 0, 0, -1);
                    }
                    int num = 0;
                    while (true)
                    {
                        stream2.Position = 12 * num;
                        TerrainSerializer14.ReadTOCEntry(stream2, out int cx, out int cz, out int offset);
                        if (offset == 0)
                        {
                            break;
                        }
                        stream.Position = 12 * num;
                        TerrainSerializer129.WriteTOCEntry(stream, cx, cz, num);
                        stream2.Position = offset;
                        stream.Position  = stream.Length;
                        TerrainSerializer14.ReadChunkHeader(stream2);
                        TerrainSerializer129.WriteChunkHeader(stream, cx, cz);
                        stream2.Read(array, 0, 65536);
                        int num2 = 0;
                        for (int j = 0; j < 16; j++)
                        {
                            for (int k = 0; k < 16; k++)
                            {
                                for (int l = 0; l < 128; l++)
                                {
                                    int num3 = array[2 * num2] | (array[2 * num2 + 1] << 8);
                                    int num4 = ConvertValue(num3);
                                    if (l < 127)
                                    {
                                        int num5 = num3 & 0xFF;
                                        if (num5 == 18 || num5 == 92)
                                        {
                                            int num6 = (array[2 * num2 + 2] | (array[2 * num2 + 3] << 8)) & 0xFF;
                                            if (num5 != num6)
                                            {
                                                num4 |= 0x40000;
                                            }
                                        }
                                    }
                                    array2[4 * num2]     = (byte)num4;
                                    array2[4 * num2 + 1] = (byte)(num4 >> 8);
                                    array2[4 * num2 + 2] = (byte)(num4 >> 16);
                                    array2[4 * num2 + 3] = (byte)(num4 >> 24);
                                    num2++;
                                }
                            }
                        }
                        stream.Write(array2, 0, 131072);
                        stream2.Read(array, 0, 1024);
                        stream.Write(array, 0, 1024);
                        num++;
                    }
                }
            }
            Storage.DeleteFile(path);
        }
コード例 #2
0
        public void ConvertChunks(string directoryName)
        {
            string path  = Storage.CombinePaths(directoryName, "Chunks32.dat");
            string path2 = Storage.CombinePaths(directoryName, "Chunks32h.dat.new");
            long   num   = 2 * Storage.GetFileSize(path) + 52428800;

            if (Storage.FreeSpace < num)
            {
                throw new InvalidOperationException($"Not enough free space to convert world. {num / 1024 / 1024}MB required.");
            }
            using (Stream stream2 = Storage.OpenFile(path, OpenFileMode.Read))
            {
                using (Stream stream = Storage.OpenFile(path2, OpenFileMode.Create))
                {
                    byte[] array  = new byte[131072];
                    byte[] array2 = new byte[262144];
                    for (int i = 0; i < 65537; i++)
                    {
                        TerrainSerializer22.WriteTOCEntry(stream, 0, 0, -1);
                    }
                    int num2 = 0;
                    while (true)
                    {
                        stream2.Position = 12 * num2;
                        TerrainSerializer129.ReadTOCEntry(stream2, out int cx, out int cz, out int index);
                        if (index < 0)
                        {
                            break;
                        }
                        stream.Position = 12 * num2;
                        TerrainSerializer22.WriteTOCEntry(stream, cx, cz, num2);
                        stream2.Position = 786444 + 132112L * (long)index;
                        stream.Position  = stream.Length;
                        TerrainSerializer129.ReadChunkHeader(stream2);
                        TerrainSerializer22.WriteChunkHeader(stream, cx, cz);
                        stream2.Read(array, 0, 131072);
                        int num3 = 0;
                        int num4 = 0;
                        for (int j = 0; j < 16; j++)
                        {
                            for (int k = 0; k < 16; k++)
                            {
                                for (int l = 0; l < 256; l++)
                                {
                                    int num5;
                                    if (l <= 127)
                                    {
                                        num5 = ConvertValue(array[4 * num3] | (array[4 * num3 + 1] << 8) | (array[4 * num3 + 2] << 16) | (array[4 * num3 + 3] << 24));
                                        num3++;
                                    }
                                    else
                                    {
                                        num5 = 0;
                                    }
                                    array2[4 * num4]     = (byte)num5;
                                    array2[4 * num4 + 1] = (byte)(num5 >> 8);
                                    array2[4 * num4 + 2] = (byte)(num5 >> 16);
                                    array2[4 * num4 + 3] = (byte)(num5 >> 24);
                                    num4++;
                                }
                            }
                        }
                        stream.Write(array2, 0, 262144);
                        stream2.Read(array, 0, 1024);
                        stream.Write(array, 0, 1024);
                        num2++;
                    }
                }
            }
            Storage.MoveFile(Storage.CombinePaths(directoryName, "Chunks32.dat"), Storage.CombinePaths(directoryName, "Chunks32.dat.old"));
        }