namespace Decal.Filters;

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

	internal override bool LoadFrom(byte[] Data)
	{
		int Index = 0;
		if (Get.DWord(Data, ref Index) != 654311424)
		{
			return false;
		}
		Index++;
		int num = Get.Byte(Data, ref Index);
		InitializeTable(num);
		for (int i = 0; i < num; i++)
		{
			Material material = new Material(Get.DWord(Data, ref Index));
			material.Unknown = Get.DWord(Data, ref Index);
			Add(material);
		}
		Index++;
		num = Get.Byte(Data, ref Index);
		for (int j = 0; j < num; j++)
		{
			int id = Get.DWord(Data, ref Index);
			GetById(id).Name = Get.PString(Data, ref Index).Replace('_', ' ');
		}
		return true;
	}
}
