Exemplo n.º 1
0
        /// <summary>
        /// Get the equipment or accessory deformation set for a given item and race.
        /// Null if the set information doesn't exist.
        /// </summary>
        /// <param name="equipmentId"></param>
        /// <param name="race"></param>
        /// <param name="accessory"></param>
        /// <returns></returns>
        private async Task <EquipmentDeformationParameterSet> GetEquipmentDeformationSet(int equipmentId, XivRace race, bool accessory = false)
        {
            var raw = await GetRawEquipmentDeformationParameters(equipmentId, race, accessory);

            if (raw == null)
            {
                return(null);
            }

            var set = new EquipmentDeformationParameterSet(accessory);

            var list = EquipmentDeformationParameterSet.SlotsAsList(accessory);

            // Pull the value apart two bits at a time.
            // Last 6 bits are not used.
            for (var idx = 0; idx < 5; idx++)
            {
                var entry = new EquipmentDeformationParameter();

                entry.bit0 = (raw & 1) != 0;
                raw        = (ushort)(raw >> 1);
                entry.bit1 = (raw & 1) != 0;
                raw        = (ushort)(raw >> 1);

                var key = list[idx];
                set.Parameters[key] = entry;
            }


            return(set);
        }
Exemplo n.º 2
0
#pragma warning restore SA1307

            /// <summary>
            /// Create a EquipmentDeformation Parameter from a full byte representation.
            /// </summary>
            public static EquipmentDeformationParameter FromByte(byte b)
            {
                BitArray r = new BitArray(new byte[] { b });
                EquipmentDeformationParameter def = new EquipmentDeformationParameter();

                def.bit0 = r[0];
                def.bit1 = r[1];

                return(def);
            }
Exemplo n.º 3
0
        /// <summary>
        /// Deserializes the binary EQDP data into a dictionary of EQDP entries.
        /// </summary>
        private static Dictionary <XivRace, EquipmentDeformationParameter> DeserializeEqdpData(byte[] data, uint dataVersion)
        {
            const int eqdpEntrySize = 5;
            int       entries       = data.Length / eqdpEntrySize;

            Dictionary <XivRace, EquipmentDeformationParameter> ret = new Dictionary <XivRace, EquipmentDeformationParameter>();

            int read = 0;

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data)))
            {
                while (read < entries)
                {
                    int     raceCode = reader.ReadInt32();
                    XivRace race     = GetXivRace(raceCode.ToString().PadLeft(4, '0'));

                    byte eqpByte = reader.ReadByte();
                    EquipmentDeformationParameter entry = EquipmentDeformationParameter.FromByte(eqpByte);

                    ret.Add(race, entry);

                    read++;
                }
            }

            // Catch for cases where for some reason the EQP doesn't have all races,
            // for example, SE adding more races in the future, and we're
            // reading old metadata entries.
            foreach (XivRace race in PlayableRaces)
            {
                if (!ret.ContainsKey(race))
                {
                    ret.Add(race, new EquipmentDeformationParameter());
                }
            }

            return(ret);
        }