Пример #1
0
        private static void InitializeUnitFields(UpdateFieldValueCollection updateCollection, Dictionary <int, int> valuesDictionary, ref int valueIndex, EUnitFields_Vanilla endField = EUnitFields_Vanilla.PLAYER_END)
        {
            //subtract 1 from the length size because it's PlayerEnd
            for (int i = (int)EObjectFields.OBJECT_END; i < updateCollection.UpdateMask.Length && i < (int)endField; i++)
            {
                //TODO: Blacklist these fields
                //UNIT_FIELD_PERSUADED and UNIT_FIELD_PERSUADED +1
                //UNIT_CHANNEL_SPELL

                bool shouldWrite = VanillaToWotlkConverter.ConvertUpdateFieldsPlayer((EUnitFields_Vanilla)i, out int shiftAmount);

                //We need to track the index of nonwritten to wotlk, but written to the vanilla update block,
                //so that we may remove the byte chunk that represents the indicies
                if (updateCollection.UpdateMask[i])
                {
                    if (shouldWrite)
                    {
                        try
                        {
                            //We store in a dictionary with the value so that it may be written
                            //TODO: Store only index so we can do quick memcpy to new values array in the future for perf
                            valuesDictionary.Add(i + shiftAmount, updateCollection.UpdateDiffValues.Reinterpret <int>(valueIndex * sizeof(int)));
                        }
                        catch (Exception e)
                        {
                            throw new InvalidOperationException($"Failed to insert: i:{i}:{((EUnitFields_Vanilla)i).ToString()} [{i + shiftAmount}] [{((EUnitFields)(i + shiftAmount)).ToString()}] {updateCollection.UpdateDiffValues.Reinterpret<int>(valueIndex * sizeof(int))} into dictionary. \n\n Exception: {e.Message}", e);
                        }
                    }

                    //no matter what the value index should increase. Because
                    //otherwise it will get descyned from the new values
                    valueIndex++;
                }
            }
        }
Пример #2
0
 /// <inheritdoc />
 public ObjectCreationData(PackedGuid creationGuid, ObjectType creationObjectType, MovementBlockData movementData, UpdateFieldValueCollection objectValuesCollection)
 {
     CreationGuid           = creationGuid;
     CreationObjectType     = creationObjectType;
     MovementData           = movementData;
     ObjectValuesCollection = objectValuesCollection;
 }
Пример #3
0
        private static void InitializeContainerFields(UpdateFieldValueCollection updateCollection, Dictionary <int, int> valuesDictionary, ref int valueIndex)
        {
            for (int i = (int)EItemFields_Vanilla.ITEM_END; i < updateCollection.UpdateMask.Length && i < (int)EContainerFields_Vanilla.CONTAINER_END; i++)
            {
                bool shouldWrite = VanillaToWotlkConverter.ConvertUpdateFieldsContainer((EContainerFields_Vanilla)i, out int shiftAmount);

                //We need to track the index of nonwritten to wotlk, but written to the vanilla update block,
                //so that we may remove the byte chunk that represents the indicies
                if (updateCollection.UpdateMask[i])
                {
                    if (shouldWrite)
                    {
                        try
                        {
                            //We store in a dictionary with the value so that it may be written
                            //TODO: Store only index so we can do quick memcpy to new values array in the future for perf
                            valuesDictionary.Add(i + shiftAmount, updateCollection.UpdateDiffValues.Reinterpret <int>(valueIndex * sizeof(int)));
                        }
                        catch (Exception e)
                        {
                            throw new InvalidOperationException($"Failed to insert: i:{i}:{((EContainerFields_Vanilla)i).ToString()} [{i + shiftAmount}] [{((EContainerFields_Vanilla)(i + shiftAmount)).ToString()}] {updateCollection.UpdateDiffValues.Reinterpret<int>(valueIndex * sizeof(int))} into dictionary. \n\n Exception: {e.Message}", e);
                        }
                    }

                    //no matter what the value index should increase. Because
                    //otherwise it will get descyned from the new values
                    valueIndex++;
                }
            }
        }
Пример #4
0
 private static void InitializeObjectFields(UpdateFieldValueCollection updateCollection, Dictionary <int, int> valuesDictionary, ref int valueIndex)
 {
     //Wotlk and vanilla both have the same object field
     for (int i = 0; i < (int)EObjectFields.OBJECT_END; i++)
     {
         if (updateCollection.UpdateMask[i])
         {
             valuesDictionary.Add(i, updateCollection.UpdateDiffValues.Reinterpret <int>(valueIndex * sizeof(int)));
             valueIndex++;
         }
     }
 }
Пример #5
0
        private UpdateFieldValueCollection BuildWotlkItemUpdateFieldCollection(UpdateFieldValueCollection updateCollection)
        {
            //We need to build a new dictionary of update values because the value array could likely change too
            //TODO: Don't hardcode size value, compute block size manually
            BitArray bitMaskPlayer = new BitArray((int)64, false);
            Dictionary <int, int> valuesDictionary = new Dictionary <int, int>(updateCollection.UpdateDiffValues.Length / sizeof(int));
            int valueIndex = 0;

            InitializeObjectFields(updateCollection, valuesDictionary, ref valueIndex);
            InitializeItemFields(updateCollection, valuesDictionary, ref valueIndex);

            int[] values = SetBitMaskAndBuildValues(bitMaskPlayer, valuesDictionary);

            return(new UpdateFieldValueCollection(bitMaskPlayer, values.Reinterpret()));
        }
Пример #6
0
        /// <inheritdoc />
        public ObjectUpdateValuesObjectBlock Convert(ObjectUpdateValuesObjectBlock_Vanilla fromObj)
        {
            if (fromObj == null)
            {
                return(null);
            }

            UpdateFieldValueCollection fieldValueCollection = ToWotlkUpdateValues(fromObj.ObjectToUpdate, fromObj.UpdateValuesCollection);

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

            return(new ObjectUpdateValuesObjectBlock(fromObj.ObjectToUpdate, fieldValueCollection));
        }
Пример #7
0
        private static UpdateFieldValueCollection BuildWotlkPlayerUpdateFieldCollection(UpdateFieldValueCollection updateCollection)
        {
            //We need to build a new dictionary of update values because the value array could likely change too
            //TODO: Don't hardcode size value, compute block size manually
            BitArray bitMaskPlayer = new BitArray((int)1344, false);
            Dictionary <int, int> valuesDictionary = new Dictionary <int, int>(updateCollection.UpdateDiffValues.Length / sizeof(int));
            int valueIndex = 0;

            InitializeObjectFields(updateCollection, valuesDictionary, ref valueIndex);

            InitializeUnitFields(updateCollection, valuesDictionary, ref valueIndex);

            //if(!ValuesDictionary.ContainsKey((int)EUnitFields.UNIT_FIELD_FLAGS_2)) ValuesDictionary.Add((int)EUnitFields.UNIT_FIELD_FLAGS_2, 264192);
            //if(!ValuesDictionary.ContainsKey((int)EUnitFields.UNIT_FIELD_HOVERHEIGHT)) ValuesDictionary.Add((int)EUnitFields.UNIT_FIELD_HOVERHEIGHT, 1.0f.Reinterpret().Reinterpret<int>()); //TODO: change to constant
            //if(!ValuesDictionary.ContainsKey((int)EUnitFields.UNIT_FIELD_POWER_REGEN_FLAT_MODIFIER)) ValuesDictionary.Add((int)EUnitFields.UNIT_FIELD_POWER_REGEN_FLAT_MODIFIER, 1082423867);
            //if(!ValuesDictionary.ContainsKey((int)EUnitFields.PLAYER_FIELD_MAX_LEVEL)) ValuesDictionary.Add((int)EUnitFields.PLAYER_FIELD_MAX_LEVEL, 60);

            int[] values = SetBitMaskAndBuildValues(bitMaskPlayer, valuesDictionary);

            return(new UpdateFieldValueCollection(bitMaskPlayer, values.Reinterpret()));
        }
Пример #8
0
        private UpdateFieldValueCollection ToWotlkUpdateValues(PackedGuid objectGuid, UpdateFieldValueCollection updateCollection)
        {
            if (objectGuid.isType(EntityGuidMask.Player))
            {
                return(BuildWotlkPlayerUpdateFieldCollection(updateCollection));
            }
            else if (objectGuid.isType(EntityGuidMask.Unit))
            {
                return(BuildWotlkUnitUpdateFieldCollection(updateCollection));
            }

            return(null);
        }
Пример #9
0
        private static UpdateFieldValueCollection BuildWotlkUnitUpdateFieldCollection(UpdateFieldValueCollection updateCollection)
        {
            //We need to build a new dictionary of update values because the value array could likely change too
            //TODO: Don't hardcode size value, compute block size manually
            BitArray bitMaskPlayer = new BitArray((int)192, false);             //TODO: What is the unit size? Is UNIT_END correct?
            Dictionary <int, int> ValuesDictionary = new Dictionary <int, int>(updateCollection.UpdateDiffValues.Length / sizeof(int));
            int valueIndex = 0;

            InitializeObjectFields(updateCollection, ValuesDictionary, ref valueIndex);
            InitializeUnitFields(updateCollection, ValuesDictionary, ref valueIndex, EUnitFields_Vanilla.UNIT_END);

            int[] values = SetBitMaskAndBuildValues(bitMaskPlayer, ValuesDictionary);

            return(new UpdateFieldValueCollection(bitMaskPlayer, values.Reinterpret()));
        }
Пример #10
0
 /// <inheritdoc />
 public ObjectUpdateValuesObjectBlock(PackedGuid objectToUpdate, UpdateFieldValueCollection updateValuesCollection)
 {
     ObjectToUpdate         = objectToUpdate;
     UpdateValuesCollection = updateValuesCollection;
 }
Пример #11
0
 /// <inheritdoc />
 public ObjectUpdateValuesObjectBlock_Vanilla(PackedGuid objectToUpdate, UpdateFieldValueCollection updateValuesCollection)
     : base()
 {
     ObjectToUpdate         = objectToUpdate;
     UpdateValuesCollection = updateValuesCollection;
 }
Пример #12
0
        private UpdateFieldValueCollection ToWotlkUpdateValues(PackedGuid objectGuid, UpdateFieldValueCollection updateCollection)
        {
            if (objectGuid.isType(EntityGuidMask.Player))
            {
                return(BuildWotlkPlayerUpdateFieldCollection(updateCollection));
            }
            else if (objectGuid.isType(EntityGuidMask.Unit))
            {
                return(BuildWotlkUnitUpdateFieldCollection(updateCollection));
            }
            else if (objectGuid.isType(EntityGuidMask.Container))
            {
                if (updateCollection.UpdateMask.Length > 63)
                {
                    return(BuildWotlkContainerUpdateFieldCollection(updateCollection));
                }
                else
                {
                    return(BuildWotlkItemUpdateFieldCollection(updateCollection));
                }
            }
            else if (objectGuid.isType(EntityGuidMask.GameObject))
            {
                return(BuildWotlkGameObjectUpdateFieldCollection(updateCollection));
            }
            else
            if (Logger.IsWarnEnabled)
            {
                Logger.Warn($"Failed to handle update values for Entity: {objectGuid.RawGuidValue}");
            }

            return(null);
        }