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++; } } }
public static void Test_ConvertUnitFieldPlayer_Converts_All_Values([Range((int)EObjectFields_Vanilla.OBJECT_END, (int)EUnitFields_Vanilla.PLAYER_END - 1)] int fieldNumber) { //arrange EUnitFields_Vanilla vanillaUnitField = (EUnitFields_Vanilla)fieldNumber; //act bool?result = null; int shiftValue = 0; Assert.DoesNotThrow(() => result = VanillaToWotlkConverter.ConvertUpdateFieldsPlayer(vanillaUnitField, out shiftValue), $"Field: {fieldNumber}:{vanillaUnitField}:{fieldNumber:X} is not converted."); int newFieldNumber = (shiftValue + fieldNumber); //Assert Assert.NotNull(result); Assert.True(newFieldNumber >= (int)EObjectFields.OBJECT_END && newFieldNumber <= (int)EUnitFields.PLAYER_END); }