private static void WriteFieldFromArray(List<string> array, TextWriter writer, UpdateField field, int fieldStart, int id)
		{
			writer.WriteLine("\t\t/// <summary>");
			writer.WriteLine("\t\t/// {0}", field.Description);
			writer.WriteLine("\t\t/// </summary>");
			writer.WriteLine("\t\t{0} = {1},", array[fieldStart + id], field.Offset + id);
		}
		private static void WriteArrayField(TextWriter writer, UpdateField field, int num)
		{
			writer.WriteLine("\t\t/// <summary>");
			writer.WriteLine("\t\t/// {0}", field.Description);
			writer.WriteLine("\t\t/// </summary>");
			writer.WriteLine("\t\t{0}_{1} = {2},", field.Name, num + 1, field.Offset + num);
		}
		private static void WriteField(UpdateField field, TextWriter writer)
		{
			writer.WriteLine("\t\t/// <summary>");
			writer.WriteLine("\t\t/// {0}", field.Description);
			writer.WriteLine("\t\t/// </summary>");
			writer.WriteLine("\t\t{0} = {1},", field.Name, field.Offset);
		}
		static void AddToGroup(UpdateField field, UpdateFieldGroup group)
		{
			var groupList = s_updateFieldsByGroup.Get((uint)group);
			if (groupList == null)
			{
				s_updateFieldsByGroup[(uint)group] = groupList = new List<UpdateField>(200);
			}
			groupList.Add(field);

			field.Group = group;
		}
		private static void FillList(BinaryReader binReader)
		{
			s_fieldCount = 0;

			string previousField = String.Empty;
			string currentField;

			binReader.BaseStream.Position = s_dataStartOffset;

			while (true)
			{
				UpdateField field = new UpdateField();
				// 4A4C90 for OBJECT_FIELD_GUID (4869264)
				field.NameOffset = binReader.ReadUInt32();

				if (field.NameOffset < 0x9999)
				{
					uint oldNameOffset = field.NameOffset;
					field.NameOffset = binReader.ReadUInt32();
				}

				field.Offset = binReader.ReadUInt32();
				field.Size = binReader.ReadUInt32();
				field.Type = (UpdateFieldType)binReader.ReadUInt32();
				field.Flags = (FieldFlag)binReader.ReadUInt32();

				if (s_fieldCount == 0)
				{
					// 0x401A00
					s_stringOffsetDelta = field.NameOffset - s_stringStartOffset;
				}

				long stringOffset = field.NameOffset - s_stringOffsetDelta;

				long oldpos = binReader.BaseStream.Position;
				binReader.BaseStream.Position = stringOffset;
				currentField = binReader.ReadCString();
				binReader.BaseStream.Position = oldpos;

				StringBuilder sb = new StringBuilder();
				sb.AppendFormat("Size: {0} - ", field.Size);
				sb.AppendFormat("Type: {0} - ", field.Type);
				sb.AppendFormat("Flags: {0}", field.Flags);
				field.Description = sb.ToString();

				field.Name = currentField;

				m_updateFieldList.Add(field);

				s_fieldCount++;

				if (!previousField.Equals("CORPSE_FIELD_PAD") && currentField.Equals("CORPSE_FIELD_PAD"))
					break;

				previousField = currentField;
			}
		}
 private static void WriteFieldFromArray(List <string> array, TextWriter writer, UpdateField field, int fieldStart, int id)
 {
     writer.WriteLine("\t\t/// <summary>");
     writer.WriteLine("\t\t/// {0}", field.Description);
     writer.WriteLine("\t\t/// </summary>");
     writer.WriteLine("\t\t{0} = {1},", array[fieldStart + id], field.Offset + id);
 }
        private static void FillStartAndEndValues()
        {
            for (int i = 0; i < s_fieldCount; i++)
            {
                UpdateField field = m_updateFieldList[i];
                if (field.Name.StartsWith("OBJECT"))
                {
                    var groupList = s_updateFieldsByGroup.Get((uint)UpdateFieldGroup.Object);
                    if (groupList == null)
                    {
                        s_updateFieldsByGroup[(uint)UpdateFieldGroup.Object] = groupList = new List <UpdateField>(200);
                    }
                    groupList.Add(field);

                    // workaround for GameObjectFields first field being named OBJECT_FIELD_CREATED_BY
                    if (field.Name.StartsWith("OBJECT_FIELD_CREATED_BY"))
                    {
                        AddToGroup(field, UpdateFieldGroup.GameObject);

                        if (m_gameObjectStart == 0)
                        {
                            m_gameObjectStart = i;
                            m_gameObjectEnd   = m_gameObjectStart;
                        }
                        m_gameObjectEnd++;
                        s_totalGameObjectSize += (int)field.Size;
                        continue;
                    }
                    AddToGroup(field, UpdateFieldGroup.Object);

                    if (field.Offset == 0)
                    {
                        m_objectStart = i;
                        m_objectEnd   = m_objectStart;
                    }
                    m_objectEnd++;
                    s_totalObjectSize += (int)field.Size;
                }

                if (field.Name.StartsWith("ITEM"))
                {
                    AddToGroup(field, UpdateFieldGroup.Item);

                    if (field.Offset == 0)
                    {
                        m_itemStart = i;
                        m_itemEnd   = m_itemStart;
                    }
                    m_itemEnd++;
                    s_totalItemSize += (int)field.Size;
                    continue;
                }

                if (field.Name.StartsWith("CONTAINER"))
                {
                    AddToGroup(field, UpdateFieldGroup.Container);

                    if (field.Offset == 0)
                    {
                        m_containerStart = i;
                        m_containerEnd   = m_containerStart;
                    }
                    m_containerEnd++;
                    s_totalContainerSize += (int)field.Size;
                    continue;
                }

                if (field.Name.StartsWith("GAMEOBJECT"))
                {
                    AddToGroup(field, UpdateFieldGroup.GameObject);

                    // Dont need to check for first because first GameObject field is OBJECT_FIELD_CREATED_BY
                    m_gameObjectEnd++;
                    s_totalGameObjectSize += (int)field.Size;
                    continue;
                }

                if (field.Name.StartsWith("UNIT"))
                {
                    AddToGroup(field, UpdateFieldGroup.Unit);

                    if (field.Offset == 0)
                    {
                        m_unitStart = i;
                        m_unitEnd   = m_unitStart;
                    }
                    m_unitEnd++;
                    s_totalUnitSize += (int)field.Size;
                    continue;
                }

                if (field.Name.StartsWith("PLAYER"))
                {
                    AddToGroup(field, UpdateFieldGroup.Player);

                    if (field.Offset == 0)
                    {
                        m_playerStart = i;
                        m_playerEnd   = m_playerStart;
                    }
                    m_playerEnd++;
                    s_totalPlayerSize += (int)field.Size;
                    continue;
                }

                if (field.Name.StartsWith("CORPSE"))
                {
                    AddToGroup(field, UpdateFieldGroup.Corpse);

                    if (field.Offset == 0)
                    {
                        m_corpseStart = i;
                        m_corpseEnd   = m_corpseStart;
                    }
                    m_corpseEnd++;
                    s_totalCorpseSize += (int)field.Size;
                    continue;
                }

                if (field.Name.StartsWith("DYNAMIC"))
                {
                    AddToGroup(field, UpdateFieldGroup.DynamicObject);

                    if (field.Offset == 0)
                    {
                        m_dynamicObjectStart = i;
                        m_dynamicObjectEnd   = m_dynamicObjectStart;
                    }
                    m_dynamicObjectEnd++;
                    s_totalDynamicObjectSize += (int)field.Size;
                    continue;
                }
            }
        }