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++; } } }
public static void Test_ConvertUpdateFieldContainer_Converts_All_Values([Range((int)EItemFields_Vanilla.ITEM_END, (int)EContainerFields_Vanilla.CONTAINER_END - 1)] int fieldNumber) { //arrange EContainerFields_Vanilla vanillaContainerField = (EContainerFields_Vanilla)fieldNumber; //act bool?result = null; int shiftValue = 0; Assert.DoesNotThrow(() => result = VanillaToWotlkConverter.ConvertUpdateFieldsContainer(vanillaContainerField, out shiftValue), $"Field: {fieldNumber}:{vanillaContainerField}:{fieldNumber:X} is not converted."); int newFieldNumber = (shiftValue + fieldNumber); //Assert Assert.NotNull(result); Assert.True(newFieldNumber >= (int)EItemFields.ITEM_END && newFieldNumber <= (int)EContainerFields.CONTAINER_END, $"Failed for {fieldNumber}:0x{fieldNumber:X}:{((EContainerFields_Vanilla)fieldNumber).ToString()}"); }