Esempio n. 1
0
 public static byte[] Write(NPCDialogSection npcDialogSection)
 {
     using (BitWriter writer = new BitWriter())
     {
         writer.WriteUInt16(npcDialogSection.Header ?? (UInt16)0x7701);
         writer.WriteUInt16(npcDialogSection.Length ?? (UInt16)0x34);
         var skippedProperties = new string[] { "Header", "Length" };
         var start             = writer.Position;
         foreach (var npcDialogSectionProperty in typeof(NPCDialogSection).GetProperties())
         {
             if (skippedProperties.Contains(npcDialogSectionProperty.Name))
             {
                 continue;
             }
             NPCDialogDifficulty npcDialogDifficulty = (NPCDialogDifficulty)npcDialogSectionProperty.GetValue(npcDialogSection);
             foreach (var property in typeof(NPCDialogDifficulty).GetProperties())
             {
                 NPCDialogData npcDialogData = (NPCDialogData)property.GetValue(npcDialogDifficulty);
                 int           position      = writer.Position;
                 writer.WriteBit(npcDialogData.Introduction);
                 writer.SeekBits(position + (0x18 * 8));
                 writer.WriteBit(npcDialogData.Congratulations);
                 writer.SeekBits(position + 1);
             }
         }
         writer.SeekBits(start + (0x30 * 8));
         return(writer.ToArray());
     }
 }
Esempio n. 2
0
        public static NPCDialogSection Read(byte[] bytes)
        {
            NPCDialogSection npcDialogSection = new NPCDialogSection();

            using (BitReader reader = new BitReader(bytes))
            {
                npcDialogSection.Header = reader.ReadUInt16();
                npcDialogSection.Length = reader.ReadUInt16();
                Type     type = typeof(NPCDialogDifficulty);
                BitArray bits = new BitArray(reader.ReadBytes(0x30));
                //Introductions
                var skippedProperties = new string[] { "Header", "Length" };
                foreach (var npcDialogSectionProperty in typeof(NPCDialogSection).GetProperties())
                {
                    if (skippedProperties.Contains(npcDialogSectionProperty.Name))
                    {
                        continue;
                    }
                    NPCDialogDifficulty npcDialogDifficulty = new NPCDialogDifficulty();
                    int idx = 0;
                    foreach (var property in typeof(NPCDialogDifficulty).GetProperties())
                    {
                        NPCDialogData data = new NPCDialogData();
                        data.Introduction    = bits[idx];
                        data.Congratulations = bits[idx + (0x18 * 8)];
                        idx++;
                        property.SetValue(npcDialogDifficulty, data);
                    }
                    npcDialogSectionProperty.SetValue(npcDialogSection, npcDialogDifficulty);
                }
                return(npcDialogSection);
            }
        }
Esempio n. 3
0
 public static byte[] Write(D2S d2s)
 {
     using (BitWriter writer = new BitWriter()) {
         writer.WriteBytes(Header.Write(d2s.Header));
         writer.WriteUInt32(d2s.ActiveWeapon);
         writer.WriteString(d2s.Name, 16);
         writer.WriteBytes(Status.Write(d2s.Status));
         writer.WriteByte(d2s.Progression);
         //Unk0x0026
         writer.WriteBytes(d2s.Unk0x0026 ?? new byte[2]);
         writer.WriteByte(d2s.ClassId);
         //Unk0x0029
         writer.WriteBytes(d2s.Unk0x0029 ?? new byte[] { 0x10, 0x1e });
         writer.WriteByte(d2s.Level);
         writer.WriteUInt32(d2s.Created);
         writer.WriteUInt32(d2s.LastPlayed);
         //Unk0x0034
         writer.WriteBytes(d2s.Unk0x0034 ?? new byte[] { 0xff, 0xff, 0xff, 0xff });
         for (int i = 0; i < 16; i++)
         {
             writer.WriteBytes(Skill.Write(d2s.AssignedSkills[i]));
         }
         writer.WriteBytes(Skill.Write(d2s.LeftSkill));
         writer.WriteBytes(Skill.Write(d2s.RightSkill));
         writer.WriteBytes(Skill.Write(d2s.LeftSwapSkill));
         writer.WriteBytes(Skill.Write(d2s.RightSwapSkill));
         writer.WriteBytes(Appearances.Write(d2s.Appearances));
         writer.WriteBytes(Locations.Write(d2s.Location));
         writer.WriteUInt32(d2s.MapId);
         //0x00af [unk = 0x0, 0x0]
         writer.WriteBytes(d2s.Unk0x00af ?? new byte[2]);
         writer.WriteBytes(Mercenary.Write(d2s.Mercenary));
         //0x00bf [unk = 0x0] (server related data)
         writer.WriteBytes(d2s.RealmData ?? new byte[140]);
         writer.WriteBytes(QuestsSection.Write(d2s.Quests));
         writer.WriteBytes(WaypointsSection.Write(d2s.Waypoints));
         writer.WriteBytes(NPCDialogSection.Write(d2s.NPCDialog));
         writer.WriteBytes(Attributes.Write(d2s.Attributes));
         writer.WriteBytes(ClassSkills.Write(d2s.ClassSkills));
         writer.WriteBytes(ItemList.Write(d2s.PlayerItemList, d2s.Header.Version));
         writer.WriteBytes(CorpseList.Write(d2s.PlayerCorpses, d2s.Header.Version));
         if (d2s.Status.IsExpansion)
         {
             writer.WriteBytes(MercenaryItemList.Write(d2s.MercenaryItemList, d2s.Mercenary, d2s.Header.Version));
             writer.WriteBytes(Golem.Write(d2s.Golem, d2s.Header.Version));
         }
         byte[] bytes = writer.ToArray();
         Header.Fix(bytes);
         return(bytes);
     }
 }
Esempio n. 4
0
 public static D2S Read(byte[] bytes)
 {
     using (BitReader reader = new BitReader(bytes))
     {
         D2S d2s = new D2S();
         d2s.Header         = Header.Read(reader.ReadBytes(16));
         d2s.ActiveWeapon   = reader.ReadUInt32();
         d2s.Name           = reader.ReadString(16);
         d2s.Status         = Status.Read(reader.ReadByte());
         d2s.Progression    = reader.ReadByte();
         d2s.Unk0x0026      = reader.ReadBytes(2);
         d2s.ClassId        = reader.ReadByte();
         d2s.Unk0x0029      = reader.ReadBytes(2);
         d2s.Level          = reader.ReadByte();
         d2s.Created        = reader.ReadUInt32();
         d2s.LastPlayed     = reader.ReadUInt32();
         d2s.Unk0x0034      = reader.ReadBytes(4);
         d2s.AssignedSkills = Enumerable.Range(0, 16).Select(e => Skill.Read(reader.ReadBytes(4))).ToArray();
         d2s.LeftSkill      = Skill.Read(reader.ReadBytes(4));
         d2s.RightSkill     = Skill.Read(reader.ReadBytes(4));
         d2s.LeftSwapSkill  = Skill.Read(reader.ReadBytes(4));
         d2s.RightSwapSkill = Skill.Read(reader.ReadBytes(4));
         d2s.Appearances    = Appearances.Read(reader.ReadBytes(32));
         d2s.Location       = Locations.Read(reader.ReadBytes(3));
         d2s.MapId          = reader.ReadUInt32();
         d2s.Unk0x00af      = reader.ReadBytes(2);
         d2s.Mercenary      = Mercenary.Read(reader.ReadBytes(14));
         d2s.RealmData      = reader.ReadBytes(140);
         d2s.Quests         = QuestsSection.Read(reader.ReadBytes(302));
         d2s.Waypoints      = WaypointsSection.Read(reader.ReadBytes(80));
         d2s.NPCDialog      = NPCDialogSection.Read(reader.ReadBytes(52));
         d2s.Attributes     = Attributes.Read(reader);
         d2s.ClassSkills    = ClassSkills.Read(reader.ReadBytes(32), d2s.ClassId);
         d2s.PlayerItemList = ItemList.Read(reader, d2s.Header.Version);
         d2s.PlayerCorpses  = CorpseList.Read(reader, d2s.Header.Version);
         if (d2s.Status.IsExpansion)
         {
             d2s.MercenaryItemList = MercenaryItemList.Read(reader, d2s.Mercenary, d2s.Header.Version);
             d2s.Golem             = Golem.Read(reader, d2s.Header.Version);
         }
         Debug.Assert(reader.Position == (bytes.Length * 8));
         return(d2s);
     }
 }