public object xCheckXFile(string Filename)
        {
            string str = "";
            int num = this.LoadXFile(Filename);
            byte[] sourceArray = new Decryptor().OpenFile(Filename);
            int num2 = 0;
            XFile file = new XFile();
            do
            {
                int length = sourceArray[num2 + 0] + ((sourceArray[num2 + 1] & 3) * 0x100);
                double num4 = Conversion.Int((double) (((double) sourceArray[num2 + 1]) / 4.0));
                byte[] destinationArray = new byte[(length - 1) + 1];
                if (length > 0)
                {
                    Array.Copy(sourceArray, num2 + 2, destinationArray, 0, length);
                }
                switch (num4)
                {
                    case 0.0:
                    case 9.0:
                        break;

                    case 8.0:
                    {
                        Header header = new Header(destinationArray);
                        file.AddObject(header);
                        break;
                    }
                    case 27.0:
                    {
                        Design design = new Design(destinationArray, 0x1b);
                        file.AddObject(design);
                        break;
                    }
                    default:
                        Debug.Print(Conversions.ToString(num4));
                        break;
                }
                num2 = (num2 + 2) + length;
            }
            while (num2 < sourceArray.Length);
            Debug.Print("");
            if (!this.Settings.Allow22OrMoreSuperlatinumInASlot[file.PlayerID])
            {
                int index = 0;
                do
                {
                    if (file.Designs[index] != null)
                    {
                        Design design2 = file.Designs[index];
                        foreach (DesignSlot slot in design2.Slots)
                        {
                            if ((slot != null) && (((slot.CategoryID == 8) & (slot.ItemID == 11)) & (slot.Count >= 0x16)))
                            {
                                str = str + "You are not allowed to have 22 Superlatinum in one slot on the " + design2.Name + " design\r\n";
                            }
                        }
                    }
                    index++;
                }
                while (index <= 0x19);
            }
            if (!this.Settings.AllowTenthStarbaseSlotToBeUsed[file.PlayerID] && (file.Designs[0x19] != null))
            {
                str = str + "You are not allowed to use the 10th Starbase design slot\r\n";
            }
            return str;
        }
        public int LoadXFile(string filename)
        {
            Decryptor decryptor = new Decryptor();
            int index = -1;
            byte[] sourceArray = decryptor.OpenFile(filename);
            int num3 = 0;
            XFile file = new XFile();
            do
            {
                int length = sourceArray[num3 + 0] + ((sourceArray[num3 + 1] & 3) * 0x100);
                double num5 = Conversion.Int((double) (((double) sourceArray[num3 + 1]) / 4.0));
                byte[] destinationArray = new byte[(length - 1) + 1];
                if (length > 0)
                {
                    Array.Copy(sourceArray, num3 + 2, destinationArray, 0, length);
                }
                double num8 = num5;
                switch (num8)
                {
                    case 0.0:
                    case 9.0:
                        break;

                    case 8.0:
                    {
                        Header header = new Header(destinationArray);
                        index = header.PlayerID;
                        break;
                    }
                    case 27.0:
                    {
                        Design design = new Design(destinationArray, 0x1b);
                        design.Dirty = true;
                        if (design.DesignID < 0x10)
                        {
                            if (design.DeletedDesign)
                            {
                                this.Races[index].ShipDesigns[design.DesignID] = null;
                            }
                            else
                            {
                                this.Races[index].ShipDesigns[design.DesignID] = design;
                            }
                        }
                        else if (design.DeletedDesign)
                        {
                            this.Races[index].StarbaseDesigns[design.DesignID - 0x10] = null;
                        }
                        else
                        {
                            this.Races[index].StarbaseDesigns[design.DesignID - 0x10] = design;
                        }
                        break;
                    }
                    default:
                        if (num8 == 29.0)
                        {
                            int num6 = (destinationArray[0] + (destinationArray[1] * 0x100)) & 0x3ff;
                            this.Planets[num6].ProductionQueue = new QueueItem[((int) Math.Round((double) ((((double) (destinationArray.Length - 2)) / 4.0) - 1.0))) + 1];
                            int num9 = destinationArray.Length - 1;
                            for (int i = 2; i <= num9; i += 4)
                            {
                                byte[] data = new byte[] { destinationArray[i], destinationArray[i + 1], destinationArray[i + 2], destinationArray[i + 3] };
                                QueueItem item = new QueueItem(data);
                                this.Planets[num6].ProductionQueue[(int) Math.Round((double) (((double) (i - 2)) / 4.0))] = item;
                            }
                        }
                        else
                        {
                            Debug.Print(Conversions.ToString(num5));
                        }
                        break;
                }
                num3 = (num3 + 2) + length;
            }
            while (num3 < sourceArray.Length);
            return index;
        }
        public object CheckXFile(string Filename)
        {
            string str   = "";
            string str2  = "";
            int    index = Strings.InStrRev(Filename, ".", -1, CompareMethod.Binary);

            if (index > 0)
            {
                str2 = Filename.Substring(0, index - 1);
            }
            this.LoadXYFile(str2 + ".xy");
            this.LoadHSTFile(str2 + ".hst");
            int num2 = this.LoadXFile(Filename);

            if (!this.Settings.Allow22OrMoreSuperlatinumInASlot[num2])
            {
                index = 0;
                do
                {
                    if (this.Races[num2].ShipDesigns[index] != null)
                    {
                        Design design = this.Races[num2].ShipDesigns[index];
                        foreach (DesignSlot slot in design.Slots)
                        {
                            if ((slot != null) && (((slot.CategoryID == 8) & (slot.ItemID == 11)) & (slot.Count >= 0x16)))
                            {
                                str = str + "You are not allowed to have 22 Superlatinum in one slot on the " + design.Name + " design\r\n";
                            }
                        }
                    }
                    index++;
                }while (index <= 15);
                index = 0;
                do
                {
                    if (this.Races[num2].StarbaseDesigns[index] != null)
                    {
                        Design design2 = this.Races[num2].StarbaseDesigns[index];
                        foreach (DesignSlot slot2 in design2.Slots)
                        {
                            if ((slot2 != null) && (((slot2.CategoryID == 8) & (slot2.ItemID == 11)) & (slot2.Count >= 0x16)))
                            {
                                str = str + "You are not allowed to have 22 Superlatinum in one slot on the " + design2.Name + " design\r\n";
                            }
                        }
                    }
                    index++;
                }while (index <= 9);
            }
            if (!this.Settings.AllowTenthStarbaseSlotToBeUsed[num2] && (this.Races[num2].StarbaseDesigns[9] != null))
            {
                str = str + "You are not allowed to use the 10th Starbase design slot\r\n";
            }
            if (!this.Settings.AllowDesignChangesToPartiallyCompletedItems[num2])
            {
                int num6 = this.PlanetCount - 1;
                for (int i = 0; i <= num6; i++)
                {
                    Planet planet = this.Planets[i];
                    if (planet.ProductionQueue != null)
                    {
                        foreach (QueueItem item in planet.ProductionQueue)
                        {
                            if (((item.Completion > 0) && ((item.ItemID >= 0x20) & (item.ItemID <= 0x29))) && ((this.Races[num2].StarbaseDesigns[item.ItemID - 0x20] != null) && this.Races[num2].StarbaseDesigns[item.ItemID - 0x20].Dirty))
                            {
                                str = str + "You are not allowed to edit the starbase designs " + this.Races[num2].StarbaseDesigns[item.ItemID - 0x20].Name + " because one is already partially completed at Planet No " + Conversions.ToString((int)(i + 1)) + "\r\n";
                            }
                        }
                    }
                }
            }
            return(str);
        }
        public object xCheckXFile(string Filename)
        {
            string str = "";
            int    num = this.LoadXFile(Filename);

            byte[] sourceArray = new Decryptor().OpenFile(Filename);
            int    num2        = 0;
            XFile  file        = new XFile();

            do
            {
                int    length           = sourceArray[num2 + 0] + ((sourceArray[num2 + 1] & 3) * 0x100);
                double num4             = Conversion.Int((double)(((double)sourceArray[num2 + 1]) / 4.0));
                byte[] destinationArray = new byte[(length - 1) + 1];
                if (length > 0)
                {
                    Array.Copy(sourceArray, num2 + 2, destinationArray, 0, length);
                }
                switch (num4)
                {
                case 0.0:
                case 9.0:
                    break;

                case 8.0:
                {
                    Header header = new Header(destinationArray);
                    file.AddObject(header);
                    break;
                }

                case 27.0:
                {
                    Design design = new Design(destinationArray, 0x1b);
                    file.AddObject(design);
                    break;
                }

                default:
                    Debug.Print(Conversions.ToString(num4));
                    break;
                }
                num2 = (num2 + 2) + length;
            }while (num2 < sourceArray.Length);
            Debug.Print("");
            if (!this.Settings.Allow22OrMoreSuperlatinumInASlot[file.PlayerID])
            {
                int index = 0;
                do
                {
                    if (file.Designs[index] != null)
                    {
                        Design design2 = file.Designs[index];
                        foreach (DesignSlot slot in design2.Slots)
                        {
                            if ((slot != null) && (((slot.CategoryID == 8) & (slot.ItemID == 11)) & (slot.Count >= 0x16)))
                            {
                                str = str + "You are not allowed to have 22 Superlatinum in one slot on the " + design2.Name + " design\r\n";
                            }
                        }
                    }
                    index++;
                }while (index <= 0x19);
            }
            if (!this.Settings.AllowTenthStarbaseSlotToBeUsed[file.PlayerID] && (file.Designs[0x19] != null))
            {
                str = str + "You are not allowed to use the 10th Starbase design slot\r\n";
            }
            return(str);
        }
        public int LoadXFile(string filename)
        {
            Decryptor decryptor = new Decryptor();
            int       index     = -1;

            byte[] sourceArray = decryptor.OpenFile(filename);
            int    num3        = 0;
            XFile  file        = new XFile();

            do
            {
                int    length           = sourceArray[num3 + 0] + ((sourceArray[num3 + 1] & 3) * 0x100);
                double num5             = Conversion.Int((double)(((double)sourceArray[num3 + 1]) / 4.0));
                byte[] destinationArray = new byte[(length - 1) + 1];
                if (length > 0)
                {
                    Array.Copy(sourceArray, num3 + 2, destinationArray, 0, length);
                }
                double num8 = num5;
                switch (num8)
                {
                case 0.0:
                case 9.0:
                    break;

                case 8.0:
                {
                    Header header = new Header(destinationArray);
                    index = header.PlayerID;
                    break;
                }

                case 27.0:
                {
                    Design design = new Design(destinationArray, 0x1b);
                    design.Dirty = true;
                    if (design.DesignID < 0x10)
                    {
                        if (design.DeletedDesign)
                        {
                            this.Races[index].ShipDesigns[design.DesignID] = null;
                        }
                        else
                        {
                            this.Races[index].ShipDesigns[design.DesignID] = design;
                        }
                    }
                    else if (design.DeletedDesign)
                    {
                        this.Races[index].StarbaseDesigns[design.DesignID - 0x10] = null;
                    }
                    else
                    {
                        this.Races[index].StarbaseDesigns[design.DesignID - 0x10] = design;
                    }
                    break;
                }

                default:
                    if (num8 == 29.0)
                    {
                        int num6 = (destinationArray[0] + (destinationArray[1] * 0x100)) & 0x3ff;
                        this.Planets[num6].ProductionQueue = new QueueItem[((int)Math.Round((double)((((double)(destinationArray.Length - 2)) / 4.0) - 1.0))) + 1];
                        int num9 = destinationArray.Length - 1;
                        for (int i = 2; i <= num9; i += 4)
                        {
                            byte[]    data = new byte[] { destinationArray[i], destinationArray[i + 1], destinationArray[i + 2], destinationArray[i + 3] };
                            QueueItem item = new QueueItem(data);
                            this.Planets[num6].ProductionQueue[(int)Math.Round((double)(((double)(i - 2)) / 4.0))] = item;
                        }
                    }
                    else
                    {
                        Debug.Print(Conversions.ToString(num5));
                    }
                    break;
                }
                num3 = (num3 + 2) + length;
            }while (num3 < sourceArray.Length);
            return(index);
        }