namespace Decal.Filters;

public sealed class SkillTable : IdNameTable<Skill>
{
	internal SkillTable(byte[] Data)
	{
		LoadFrom(Data);
	}

	internal override bool LoadFrom(byte[] Data)
	{
		int Index = 0;
		if (Get.DWord(Data, ref Index) != 234881028)
		{
			return false;
		}
		int num = Get.Word(Data, ref Index);
		InitializeTable(num);
		Index += 2;
		for (int i = 0; i < num; i++)
		{
			Skill skill = new Skill(Get.DWord(Data, ref Index));
			skill.Description = Get.String(Data, ref Index);
			skill.Name = Get.String(Data, ref Index);
			skill.IconId = Get.DWord(Data, ref Index);
			skill.CreditsToTrain = Get.DWord(Data, ref Index);
			skill.CreditsToSpecialize = Get.DWord(Data, ref Index);
			skill.Type = SkillType.GetById(Get.DWord(Data, ref Index));
			skill.Unknown1 = Get.DWord(Data, ref Index);
			skill.Usability = SkillState.GetById(Get.DWord(Data, ref Index));
			skill.Unknown2 = Get.DWord(Data, ref Index);
			skill.IsAttribute1Valid = Get.DWord(Data, ref Index) == 1;
			skill.IsAttribute2Valid = Get.DWord(Data, ref Index) == 1;
			skill.AttributeDivisor = Get.DWord(Data, ref Index);
			skill.Attribute1Id = Get.DWord(Data, ref Index);
			skill.Attribute2Id = Get.DWord(Data, ref Index);
			skill.XPTimerLimit = Get.Double(Data, ref Index);
			skill.XPTimerStart = Get.Double(Data, ref Index);
			skill.Unknown3 = Get.Double(Data, ref Index);
			Add(skill);
		}
		return true;
	}
}
