示例#1
0
 public static void RepairWorldIfNeeded(string directoryName)
 {
     try
     {
         string text = Storage.CombinePaths(directoryName, "Project.xml");
         if (!TestXmlFile(text, "Project"))
         {
             Log.Warning($"Project file at \"{text}\" is corrupt or nonexistent. Will try copying data from the backup file. If that fails, will try making a recovery project file.");
             string text2 = Storage.CombinePaths(directoryName, "Project.bak");
             if (TestXmlFile(text2, "Project"))
             {
                 Storage.CopyFile(text2, text);
             }
             else
             {
                 string path = Storage.CombinePaths(directoryName, "Chunks.dat");
                 if (!Storage.FileExists(path))
                 {
                     throw new InvalidOperationException("Recovery project file could not be generated because chunks file does not exist.");
                 }
                 XElement xElement = ContentManager.Get <XElement>("RecoveryProject");
                 using (Stream stream = Storage.OpenFile(path, OpenFileMode.Read))
                 {
                     TerrainSerializer14.ReadTOCEntry(stream, out int cx, out int cz, out int _);
                     Vector3 vector = new Vector3(16 * cx, 255f, 16 * cz);
                     xElement.Element("Subsystems").Element("Values").Element("Value")
                     .Attribute("Value")
                     .SetValue(HumanReadableConverter.ConvertToString(vector));
                 }
                 using (Stream stream2 = Storage.OpenFile(text, OpenFileMode.Create))
                 {
                     XmlUtils.SaveXmlToStream(xElement, stream2, null, throwOnError: true);
                 }
             }
         }
     }
     catch (Exception)
     {
         throw new InvalidOperationException("The world files are corrupt and could not be repaired.");
     }
 }
示例#2
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);
        }