Exemplo n.º 1
0
        public override void Read(BinaryReader reader)
        {
            try
            {
                byte[] header = reader.ReadBytes(4);
                reader.BaseStream.Seek(-4, SeekOrigin.Current);
                if (header.SequenceEqual(oldHeader) || header.SequenceEqual(newHeader))
                {
                    ReadV1_17(reader);
                }
                else
                {
                    MemoryStream currentReader = new MemoryStream(reader.ReadBytes((int)reader.BaseStream.Length));
                    XDocument    document      = XDocument.Load(currentReader);
                    XElement     root          = document.Element("root");

                    if (root != null)
                    {
                        XElement enabledElement = root.Element("enabled");
                        if (enabledElement != null)
                        {
                            Enabled = (bool)enabledElement;
                        }
                        XElement doDashFlashElement = root.Element("doDashFlash");
                        if (doDashFlashElement != null)
                        {
                            DoDashFlash = (bool)doDashFlashElement;
                        }

                        XElement allowMapColors = root.Element("allowMapHairColor");
                        if (allowMapColors != null)
                        {
                            AllowMapHairColors = (bool)allowMapColors;
                        }
                        XElement doMaddyCrown = root.Element("doMaddyCrown");
                        if (doMaddyCrown != null)
                        {
                            DoMaddyCrown = (bool)doMaddyCrown;
                        }

                        XElement hyperlineSoftCap = root.Element("hairLengthSoftCap");
                        if (hyperlineSoftCap != null)
                        {
                            HairLengthSoftCap = (int)hyperlineSoftCap;
                        }
                        if (HairLengthSoftCap > MAX_HAIR_LENGTH)
                        {
                            HairLengthSoftCap = MAX_HAIR_LENGTH;
                        }

                        XElement doFeatherColor = root.Element("doFeatherColor");
                        if (doFeatherColor != null)
                        {
                            DoFeatherColor = (bool)doFeatherColor;
                        }

                        XElement dashesElement = root.Element("dashes");
                        if (dashesElement != null)
                        {
                            foreach (XElement dashCountElement in dashesElement.Elements("dash"))
                            {
                                XAttribute dashAttr = dashCountElement.Attribute("count");
                                if (dashAttr != null)
                                {
                                    int dash = (int)dashAttr;
                                    if (dash < Hyperline.MAX_DASH_COUNT)
                                    {
                                        XElement hairLengthElement = dashCountElement.Element("hairLength");
                                        if (hairLengthElement != null)
                                        {
                                            hairLengthList[dash] = (int)hairLengthElement;
                                            if (hairLengthList[dash] > HairLengthSoftCap || hairLengthList[dash] < MIN_HAIR_LENGTH)
                                            {
                                                hairLengthList[dash] = 4;
                                            }
                                        }
                                        else
                                        {
                                            Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dash hair length element.");
                                        }

                                        XElement hairSpeedElement = dashCountElement.Element("hairSpeed");
                                        if (hairSpeedElement != null)
                                        {
                                            hairSpeedList[dash] = (int)hairSpeedElement;
                                            if (hairSpeedList[dash] > MAX_HAIR_SPEED || hairSpeedList[dash] < MIN_HAIR_SPEED)
                                            {
                                                hairSpeedList[dash] = 0;
                                            }
                                        }
                                        else
                                        {
                                            Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dash hair speed element.");
                                        }

                                        XElement hairBangsElement = dashCountElement.Element("bangsTexture");
                                        if (hairBangsElement != null)
                                        {
                                            hairBangsSource[dash] = (string)hairBangsElement;
                                        }
                                        XElement hairTextureElement = dashCountElement.Element("hairTexture");
                                        if (hairTextureElement != null)
                                        {
                                            hairTextureSource[dash] = (string)hairTextureElement;
                                        }

                                        string   chosenType      = SolidHair.id;
                                        XElement hairTypeElement = dashCountElement.Element("type");
                                        if (hairTypeElement != null)
                                        {
                                            chosenType = (string)hairTypeElement;
                                        }
                                        else
                                        {
                                            Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dash hair type element.");
                                        }
                                        if (Hyperline.Instance.hairTypes.Has(Hashing.FNV1Hash(chosenType)))
                                        {
                                            hairTypeList[dash] = Hashing.FNV1Hash(chosenType);
                                        }

                                        XElement tp = dashCountElement.Element("types");
                                        if (tp != null)
                                        {
                                            foreach (XElement currentType in tp.Elements())
                                            {
                                                uint type = Hashing.FNV1Hash(currentType.Name.LocalName);
                                                try
                                                {
                                                    IHairType hair = Hyperline.Instance.hairTypes.CreateNewHairType(type);
                                                    if (hair != null)
                                                    {
                                                        hair.Read(currentType);
                                                        hairList[dash][type] = hair;
                                                    }
                                                    else
                                                    {
                                                        Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline contained invalid hair type " + currentType.Name);
                                                    }
                                                }
                                                catch (Exception exception)
                                                {
                                                    Logger.Log(LogLevel.Warn, "Hyperline", "Exception occured while loading hair type " + currentType.Name.LocalName + " dash count " + dash + "\n" + exception);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            Logger.Log(LogLevel.Warn, "Hyperline", "XML file missing types for dash count " + dash);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dashs element.");
                        }
                    }
                    else
                    {
                        Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing root element.");
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.Log(LogLevel.Error, "Hyperline", "Error while loading save file...\n" + exception.ToString());
            }
        }
Exemplo n.º 2
0
        public void Read(BinaryReader reader)
        {
            MemoryStream currentReader = new MemoryStream(reader.ReadBytes((int)reader.BaseStream.Length));
            XDocument    document      = XDocument.Load(currentReader);
            XElement     root          = document.Element("root");

            if (root != null)
            {
                XElement hairChangesElement = root.Element("hairChanges");
                if (hairChangesElement != null)
                {
                    foreach (XElement dashCountElement in hairChangesElement.Elements("dash"))
                    {
                        XAttribute dashAttr = dashCountElement.Attribute("count");
                        if (dashAttr != null)
                        {
                            int dash = (int)dashAttr;
                            if (dash < Hyperline.MAX_DASH_COUNT)
                            {
                                foreach (XElement hairElement in dashCountElement.Elements())
                                {
                                    uint      type        = Hashing.FNV1Hash(hairElement.Name.LocalName);
                                    IHairType currentHair = Hyperline.Instance.hairTypes.CreateNewHairType(type);
                                    if (currentHair != null)
                                    {
                                        currentHair.Read(hairElement);
                                        hairChanges[dash] = currentHair;
                                    }
                                }
                            }
                        }
                    }
                }

                XElement speedChangesElement = root.Element("speedChanges");
                if (speedChangesElement != null)
                {
                    foreach (XElement dashCountElement in speedChangesElement.Elements("dash"))
                    {
                        XAttribute dashAttr = dashCountElement.Attribute("count");
                        if (dashAttr != null)
                        {
                            int dash = (int)dashAttr;
                            if (dash < Hyperline.MAX_DASH_COUNT)
                            {
                                XElement speedElement = dashCountElement.Element("speed");
                                if (speedElement != null)
                                {
                                    hairSpeedChanges[dash] = (int)speedElement;
                                }
                            }
                        }
                    }
                }

                XElement lengthChangesElement = root.Element("speedChanges");
                if (speedChangesElement != null)
                {
                    foreach (XElement dashCountElement in lengthChangesElement.Elements("dash"))
                    {
                        XAttribute dashAttr = dashCountElement.Attribute("count");
                        if (dashAttr != null)
                        {
                            int dash = (int)dashAttr;
                            if (dash < Hyperline.MAX_DASH_COUNT)
                            {
                                XElement lengthElement = dashCountElement.Element("length");
                                if (lengthElement != null)
                                {
                                    hairLengthChanges[dash] = (int)lengthElement;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 public IHairType GetType(string str)
 {
     return(GetType(Hashing.FNV1Hash(str)));
 }
Exemplo n.º 4
0
            public void Read(BinaryReader reader)
            {
                try
                {
                    MemoryStream currentReader = new MemoryStream(reader.ReadBytes((int)reader.BaseStream.Length));
                    XDocument    document      = XDocument.Load(currentReader);
                    XElement     root          = document.Element("root");

                    if (root != null)
                    {
                        XElement dashesElement = root.Element("dashes");
                        if (dashesElement != null)
                        {
                            foreach (XElement dashCountElement in dashesElement.Elements("dash"))
                            {
                                XAttribute dashAttr = dashCountElement.Attribute("count");
                                if (dashAttr != null)
                                {
                                    int dash = (int)dashAttr;
                                    if (dash < Hyperline.MAX_DASH_COUNT)
                                    {
                                        XElement hairLengthElement = dashCountElement.Element("hairLength");
                                        if (hairLengthElement != null)
                                        {
                                            hairLengthList[dash] = (int)hairLengthElement;
                                            if (hairLengthList[dash] > HyperlineSettings.MAX_HAIR_LENGTH || hairLengthList[dash] < HyperlineSettings.MIN_HAIR_LENGTH)
                                            {
                                                hairLengthList[dash] = 4;
                                            }
                                        }
                                        else
                                        {
                                            Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dash hair length element.");
                                        }

                                        XElement hairSpeedElement = dashCountElement.Element("hairSpeed");
                                        if (hairSpeedElement != null)
                                        {
                                            hairSpeedList[dash] = (int)hairSpeedElement;
                                            if (hairSpeedList[dash] > HyperlineSettings.MAX_HAIR_SPEED || hairSpeedList[dash] < HyperlineSettings.MIN_HAIR_SPEED)
                                            {
                                                hairSpeedList[dash] = 0;
                                            }
                                        }
                                        else
                                        {
                                            Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dash hair speed element.");
                                        }

                                        XElement hairBangsElement = dashCountElement.Element("bangsTexture");
                                        if (hairBangsElement != null)
                                        {
                                            hairBangsSource[dash] = (string)hairBangsElement;
                                        }
                                        XElement hairTextureElement = dashCountElement.Element("hairTexture");
                                        if (hairTextureElement != null)
                                        {
                                            hairTextureSource[dash] = (string)hairTextureElement;
                                        }

                                        string   chosenType      = SolidHair.id;
                                        XElement hairTypeElement = dashCountElement.Element("type");
                                        if (hairTypeElement != null)
                                        {
                                            chosenType = (string)hairTypeElement;
                                        }
                                        else
                                        {
                                            Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dash hair type element.");
                                        }
                                        if (Hyperline.Instance.hairTypes.Has(Hashing.FNV1Hash(chosenType)))
                                        {
                                            hairTypeList[dash] = Hashing.FNV1Hash(chosenType);
                                        }

                                        XElement tp = dashCountElement.Element("types");
                                        if (tp != null)
                                        {
                                            foreach (XElement currentType in tp.Elements())
                                            {
                                                uint type = Hashing.FNV1Hash(currentType.Name.LocalName);
                                                try
                                                {
                                                    IHairType hair = Hyperline.Instance.hairTypes.CreateNewHairType(type);
                                                    if (hair != null)
                                                    {
                                                        hair.Read(currentType);
                                                        hairList[dash][type] = hair;
                                                    }
                                                    else
                                                    {
                                                        Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline contained invalid hair type " + currentType.Name);
                                                    }
                                                }
                                                catch (Exception exception)
                                                {
                                                    Logger.Log(LogLevel.Warn, "Hyperline", "Exception occured while loading hair type " + currentType.Name.LocalName + " dash count " + dash + "\n" + exception);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            Logger.Log(LogLevel.Warn, "Hyperline", "XML file missing types for dash count " + dash);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dashs element.");
                        }
                    }
                    else
                    {
                        Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing root element.");
                    }
                }
                catch (Exception exception)
                {
                    Logger.Log(LogLevel.Error, "Hyperline", "Error while loading save file...\n" + exception.ToString());
                }
            }
Exemplo n.º 5
0
        public IHairType CreateNewHairType(string str)
        {
            uint id = Hashing.FNV1Hash(str);

            return(CreateNewHairType(id));
        }