Exemplo n.º 1
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);
     }
 }
Exemplo n.º 2
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);
     }
 }
Exemplo n.º 3
0
        public static byte[] Write(WaypointsSection waypointsSection)
        {
            using (BitWriter writer = new BitWriter())
            {
                writer.WriteUInt16(waypointsSection.Header ?? (UInt16)0x5357);
                writer.WriteUInt32(waypointsSection.Version ?? 0x1);
                writer.WriteUInt16(waypointsSection.Length ?? (UInt16)0x50);
                var skippedProperties = new string[] { "Header", "Version", "Length" };
                foreach (var property in typeof(WaypointsSection).GetProperties())
                {
                    if (skippedProperties.Contains(property.Name))
                    {
                        continue;
                    }
                    WaypointsDifficulty waypointsDifficulty = (WaypointsDifficulty)property.GetValue(waypointsSection);
                    writer.WriteBytes(WaypointsDifficulty.Write(waypointsDifficulty));
                }

                return(writer.ToArray());
            }
        }
Exemplo n.º 4
0
        public static WaypointsSection Read(byte[] bytes)
        {
            WaypointsSection waypointsSection = new WaypointsSection();

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