Example #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);
     }
 }
Example #2
0
 public static byte[] Write(Appearances appearances)
 {
     using (BitWriter writer = new BitWriter())
     {
         foreach (var property in typeof(Appearances).GetProperties())
         {
             Appearance appearance = (Appearance)property.GetValue(appearances);
             writer.WriteByte(appearance.Graphic);
         }
         foreach (var property in typeof(Appearances).GetProperties())
         {
             Appearance appearance = (Appearance)property.GetValue(appearances);
             writer.WriteByte(appearance.Tint);
         }
         return(writer.ToArray());
     }
 }
Example #3
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);
     }
 }
Example #4
0
        public static Appearances Read(byte[] bytes)
        {
            Appearances appearances = new Appearances();

            using (BitReader reader = new BitReader(bytes))
            {
                foreach (var property in typeof(Appearances).GetProperties())
                {
                    Appearance Appearance = new Appearance();
                    Appearance.Graphic = reader.ReadByte();
                    property.SetValue(appearances, Appearance);
                }
                foreach (var property in typeof(Appearances).GetProperties())
                {
                    Appearance Appearance = (Appearance)property.GetValue(appearances);
                    Appearance.Tint = reader.ReadByte();
                }
                return(appearances);
            }
        }