private void reconst()
        {
            short num = 0;
            short num2;

            for (num2 = 0; num2 < 627; num2 += 1)
            {
                if (this.son[(int)num2] >= 627)
                {
                    this.freq[(int)num] = (ushort)((this.freq[(int)num2] + 1) / 2);
                    this.son[(int)num]  = this.son[(int)num2];
                    num += 1;
                }
            }
            num2 = 0;
            for (num = 314; num < 627; num += 1)
            {
                short  num3 = (short)(num2 + 1);
                ushort num4 = this.freq[(int)num] = (ushort)(this.freq[(int)num2] + this.freq[(int)num3]);
                num3 = (short)(num - 1);
                while (num4 < this.freq[(int)num3])
                {
                    num3 -= 1;
                }
                num3 += 1;
                ushort length = (ushort)((num - num3) * 2);
                LzssHuffmanStream.movmem(this.freq, (int)num3, this.freq, (int)(num3 + 1), (int)length);
                this.freq[(int)num3] = num4;
                LzssHuffmanStream.movmem(this.son, (int)num3, this.son, (int)(num3 + 1), (int)length);
                this.son[(int)num3] = num2;
                num2 += 2;
            }
            for (num2 = 0; num2 < 627; num2 += 1)
            {
                short num3;
                if ((num3 = this.son[(int)num2]) >= 627)
                {
                    this.prnt[(int)num3] = num2;
                }
                else
                {
                    this.prnt[(int)num3] = (this.prnt[(int)(num3 + 1)] = num2);
                }
            }
        }
        private bool loadData(Stream stream)
        {
            Td0Serializer.TD0_MAIN_HEADER td0_MAIN_HEADER = Td0Serializer.TD0_MAIN_HEADER.Deserialize(stream);
            if (td0_MAIN_HEADER == null)
            {
                return(false);
            }
            if (td0_MAIN_HEADER.Ver > 21 || td0_MAIN_HEADER.Ver < 10)
            {
                PlatformFactory.Platform.ShowWarning("Format version is not supported [0x" + td0_MAIN_HEADER.Ver.ToString("X2") + "]", "TD0 loader");
                return(false);
            }
            if (td0_MAIN_HEADER.DataDOS != 0)
            {
                PlatformFactory.Platform.ShowWarning("'DOS Allocated sectors were copied' option is not supported!", "TD0 loader");
                return(false);
            }
            Stream stream2 = stream;

            if (td0_MAIN_HEADER.IsAdvandcedCompression)
            {
                if (td0_MAIN_HEADER.Ver < 20)
                {
                    PlatformFactory.Platform.ShowWarning("Old Advanced compression is not implemented!", "TD0 loader");
                    return(false);
                }
                stream2 = new LzssHuffmanStream(stream);
            }
            string description = string.Empty;

            if ((td0_MAIN_HEADER.Info & 128) != 0)
            {
                byte[] array = new byte[4];
                stream2.Read(array, 0, 2);
                stream2.Read(array, 2, 2);
                byte[] array2 = new byte[(int)(FormatSerializer.getUInt16(array, 2) + 10)];
                for (int i = 0; i < 4; i++)
                {
                    array2[i] = array[i];
                }
                stream2.Read(array2, 4, 6);
                stream2.Read(array2, 10, array2.Length - 10);
                if (Td0Serializer.CalculateTD0CRC(array2, 2, (int)(8 + FormatSerializer.getUInt16(array2, 2))) != FormatSerializer.getUInt16(array2, 0))
                {
                    PlatformFactory.Platform.ShowWarning("Info crc wrong", "TD0 loader");
                }
                StringBuilder stringBuilder = new StringBuilder();
                int           num           = 10;
                for (int j = 10; j < array2.Length; j++)
                {
                    if (array2[j] == 0 && j > num)
                    {
                        stringBuilder.Append(Encoding.ASCII.GetString(array2, num, j - num));
                        stringBuilder.Append("\n");
                        num = j + 1;
                    }
                }
                description = stringBuilder.ToString();
            }
            int       num2      = -1;
            int       num3      = -1;
            ArrayList arrayList = new ArrayList();

            for (;;)
            {
                Td0Serializer.TD0_TRACK td0_TRACK = Td0Serializer.TD0_TRACK.Deserialize(stream2);
                if (td0_TRACK.SectorCount == 255)
                {
                    break;
                }
                arrayList.Add(td0_TRACK);
                if (num2 < td0_TRACK.Cylinder)
                {
                    num2 = td0_TRACK.Cylinder;
                }
                if (num3 < td0_TRACK.Side)
                {
                    num3 = td0_TRACK.Side;
                }
            }
            num2++;
            num3++;
            if (num2 < 1 || num3 < 1)
            {
                PlatformFactory.Platform.ShowWarning("Invalid disk structure", "td0");
                return(false);
            }
            this._diskImage.Init(num2, num3);
            foreach (object obj in arrayList)
            {
                Td0Serializer.TD0_TRACK td0_TRACK2 = (Td0Serializer.TD0_TRACK)obj;
                this._diskImage.GetTrackImage(td0_TRACK2.Cylinder, td0_TRACK2.Side).AssignSectors(td0_TRACK2.SectorList);
            }
            this._diskImage.Description = description;
            return(true);
        }