예제 #1
0
파일: Quests.cs 프로젝트: betenner/D2RTools
 public static byte[] Write(QuestsDifficulty questsDifficulty)
 {
     using (BitWriter writer = new BitWriter())
     {
         Type questsDifficultyType = typeof(QuestsDifficulty);
         foreach (var questsDifficultyProperty in questsDifficultyType.GetProperties())
         {
             Type type   = questsDifficultyProperty.PropertyType;
             var  quests = questsDifficultyProperty.GetValue(questsDifficulty);
             foreach (var property in type.GetProperties())
             {
                 Quest quest = (Quest)property.GetValue(quests);
                 writer.WriteBytes(Quest.Write(quest));
             }
         }
         Debug.Assert(writer.Position == 96 * 8);
         return(writer.ToArray());
     }
 }
예제 #2
0
파일: Quests.cs 프로젝트: betenner/D2RTools
 public static byte[] Write(QuestsSection questSection)
 {
     using (BitWriter writer = new BitWriter())
     {
         writer.WriteUInt32(questSection.Magic ?? 0x1);
         writer.WriteUInt32(questSection.Header ?? 0x216F6F57);
         writer.WriteUInt32(questSection.Version ?? 0x6);
         writer.WriteUInt16(questSection.Length ?? (UInt16)0x12A);
         var skippedProperties = new string[] { "Magic", "Header", "Version", "Length" };
         foreach (var property in typeof(QuestsSection).GetProperties())
         {
             if (skippedProperties.Contains(property.Name))
             {
                 continue;
             }
             QuestsDifficulty questsDifficulty = (QuestsDifficulty)property.GetValue(questSection);
             writer.WriteBytes(QuestsDifficulty.Write(questsDifficulty));
         }
         return(writer.ToArray());
     }
 }
예제 #3
0
파일: Quests.cs 프로젝트: betenner/D2RTools
        public static QuestsDifficulty Read(byte[] bytes)
        {
            QuestsDifficulty questsDifficulty = new QuestsDifficulty();

            using (BitReader reader = new BitReader(bytes))
            {
                Type questsDifficultyType = typeof(QuestsDifficulty);
                foreach (var questsDifficultyProperty in questsDifficultyType.GetProperties())
                {
                    Type type   = questsDifficultyProperty.PropertyType;
                    var  quests = Activator.CreateInstance(type);
                    foreach (var property in type.GetProperties())
                    {
                        Quest quest = new Quest();
                        property.SetValue(quests, Quest.Read(reader.ReadBytes(2)));
                    }
                    questsDifficultyProperty.SetValue(questsDifficulty, quests);
                }
                return(questsDifficulty);
            }
        }
예제 #4
0
파일: Quests.cs 프로젝트: betenner/D2RTools
        public static QuestsSection Read(byte[] bytes)
        {
            QuestsSection questSection = new QuestsSection();

            using (BitReader reader = new BitReader(bytes))
            {
                questSection.Magic   = reader.ReadUInt32();
                questSection.Header  = reader.ReadUInt32();
                questSection.Version = reader.ReadUInt32();
                questSection.Length  = reader.ReadUInt16();
                var skippedProperties = new string[] { "Magic", "Header", "Version", "Length" };
                foreach (var property in typeof(QuestsSection).GetProperties())
                {
                    if (skippedProperties.Contains(property.Name))
                    {
                        continue;
                    }
                    property.SetValue(questSection, QuestsDifficulty.Read(reader.ReadBytes(96)));
                }
                return(questSection);
            }
        }