示例#1
0
文件: WCT.cs 项目: DrizztDoUrden/WPSC
        public WCT(Stream from)
        {
            using var reader = new WcDataReader(from);
            if (reader.ReadUInt32() != MagicNumber)
            {
                throw new Exception("Invalid wct file: invalid magic number");
            }

            FormatVersion = reader.ReadUInt32();
            if (FormatVersion != 0 && FormatVersion != 1)
            {
                throw new Exception("Unexpected format version of wct file.");
            }

            if (FormatVersion != 0)
            {
                MainComment = reader.ReadString();
                MainCT      = reader.ReadPrefixedString();
            }

            var cts = new List <string>();

            while (from.Position < from.Length)
            {
                cts.Add(reader.ReadPrefixedString());
            }
            Triggers = cts.ToList();
        }
示例#2
0
文件: WTG.cs 项目: DrizztDoUrden/WPSC
        private WtgTrigger ParseTrigger(WcDataReader reader)
        {
            var trigger = new WtgTrigger();

            trigger.Name        = reader.ReadString();
            trigger.Description = reader.ReadString();
            if (FormatVersion >= 7)
            {
                trigger.IsComment = reader.ReadBoolean();
            }
            trigger.Id                   = reader.ReadUInt32();
            trigger.IsEnabled            = reader.ReadBoolean();
            trigger.IsText               = reader.ReadBoolean();
            trigger.IsEnabledFromStart   = reader.ReadBoolean();
            trigger.InitializeOnMapStart = reader.ReadBoolean();
            trigger.ParentId             = reader.ReadUInt32();
            trigger.EACCount             = reader.ReadUInt32();

            if (trigger.EACCount > 0)
            {
                throw new NotImplementedException("Maps with ANY GUI triggers not supported yet.");
            }

            return(trigger);
        }
示例#3
0
文件: WTG.cs 项目: DrizztDoUrden/WPSC
 private void ReadUG(WcDataReader reader, uint[] ug)
 {
     for (var i = 0u; i < ug.Length; ++i)
     {
         ug[i] = reader.ReadUInt32();
     }
 }
示例#4
0
文件: WTG.cs 项目: DrizztDoUrden/WPSC
        private void IgnoreHeader(WcDataReader reader)
        {
            var count   = reader.ReadUInt32();
            var deleted = reader.ReadUInt32();

            for (var i = 0u; i < deleted; ++i)
            {
                reader.ReadUInt32();
            }
        }
示例#5
0
文件: WTG.cs 项目: DrizztDoUrden/WPSC
 private void ParseVariable2(WcDataReader reader, WtgVariable variable)
 {
     if (reader.ReadString() != variable.Name)
     {
         throw new Exception("Variable data mismatch.");
     }
     if (reader.ReadUInt32() != variable.ParentId)
     {
         throw new Exception("Variable data mismatch.");
     }
     variable.StoreAsElement = true;
 }
示例#6
0
文件: WTG.cs 项目: DrizztDoUrden/WPSC
        private WtgCategory ParseCategory(WcDataReader reader)
        {
            var category = new WtgCategory();

            category.Id   = reader.ReadUInt32();
            category.Name = reader.ReadString();
            if (FormatVersion >= 7)
            {
                category.IsComment = reader.ReadBoolean();
            }
            category.HasChildren = reader.ReadBoolean();
            category.ParentId    = reader.ReadUInt32();
            return(category);
        }
示例#7
0
文件: WTG.cs 项目: DrizztDoUrden/WPSC
        private WtgVariable ParseVariable(WcDataReader reader)
        {
            var variable = new WtgVariable();

            variable.Name    = reader.ReadString();
            variable.Type    = reader.ReadString();
            variable.ToKeep  = reader.ReadBoolean();
            variable.IsArray = reader.ReadBoolean();
            if (FormatVersion >= 7)
            {
                variable.ArraySize = reader.ReadUInt32();
            }
            variable.HasStartingValue = reader.ReadBoolean();
            variable.StartingValue    = reader.ReadString();
            variable.Id       = reader.ReadUInt32();
            variable.ParentId = reader.ReadUInt32();
            return(variable);
        }
示例#8
0
文件: WTG.cs 项目: DrizztDoUrden/WPSC
        public WTG(Stream from)
        {
            var reader = new WcDataReader(from);
            var mg0    = Encoding.ASCII.GetString(reader.ReadBytes(4));

            if (mg0 != MagicNumber0)
            {
                throw new Exception("Invalid wtg magic string.");
            }
            if (reader.ReadUInt32() != MagicNumber1)
            {
                throw new Exception("Invalid wtg magic number.");
            }

            FormatVersion = reader.ReadUInt32();
            if (FormatVersion != 4 && FormatVersion != 7)
            {
                throw new Exception("Unexpected format version of wct file.");
            }

            ReadUG(reader, UG0);

            IgnoreHeader(reader);
            IgnoreHeader(reader);
            IgnoreHeader(reader);
            IgnoreHeader(reader);
            IgnoreHeader(reader);

            ReadUG(reader, UG1);

            WarcraftVersion = reader.ReadUInt32();
            if (WarcraftVersion != 1 && WarcraftVersion != 2)
            {
                throw new Exception("Unexpected warcraft version of wct file.");
            }

            var varsCount = reader.ReadUInt32();

            for (var i = 0; i < varsCount; ++i)
            {
                Elements.Add(ParseVariable(reader));
            }

            var elementsCount = reader.ReadUInt32();

            Elements = new List <WtgObject>((int)elementsCount);
            ReadUG(reader, UG2);
            MapFileName = reader.ReadString();
            ReadUG(reader, UG3);

            if (FormatVersion >= 7)
            {
                ReadUG(reader, UG4);
            }

            for (var i = 0u; i < (int)elementsCount - 1 && from.Position < from.Length; ++i)
            {
                var type = reader.ReadUInt32();
                switch (type)
                {
                case 4: Elements.Add(ParseCategory(reader)); break;

                case 8: Elements.Add(ParseTrigger(reader)); break;

                case 16: Elements.Add(ParseTrigger(reader)); break;

                case 32: Elements.Add(ParseTrigger(reader)); break;

                case 64: ParseVariable2(reader, Variables.First(v => v.Id == reader.ReadUInt32()) !); break;
                }
            }
        }