2018-01-23 04:02:39 -06:00
|
|
|
using System;
|
2017-03-04 07:59:37 -05:00
|
|
|
using System.IO;
|
2017-03-15 08:12:21 -04:00
|
|
|
using System.Linq;
|
2017-03-04 07:59:37 -05:00
|
|
|
|
|
|
|
|
namespace ACE.DatLoader
|
|
|
|
|
{
|
2018-02-06 10:18:38 -06:00
|
|
|
public class DatFile : IUnpackable
|
2017-03-04 07:59:37 -05:00
|
|
|
{
|
2018-02-06 10:18:38 -06:00
|
|
|
internal static readonly uint ObjectSize = (sizeof(uint) * 6);
|
2017-03-04 07:59:37 -05:00
|
|
|
|
2018-02-06 10:18:38 -06:00
|
|
|
|
2017-03-04 07:59:37 -05:00
|
|
|
public uint BitFlags { get; private set; }
|
|
|
|
|
|
|
|
|
|
public uint ObjectId { get; private set; }
|
|
|
|
|
|
|
|
|
|
public uint FileOffset { get; private set; }
|
|
|
|
|
|
|
|
|
|
public uint FileSize { get; private set; }
|
|
|
|
|
|
|
|
|
|
public uint Date { get; private set; }
|
|
|
|
|
|
|
|
|
|
public uint Iteration { get; private set; }
|
|
|
|
|
|
2018-02-06 10:18:38 -06:00
|
|
|
public void Unpack(BinaryReader reader)
|
2017-03-04 07:59:37 -05:00
|
|
|
{
|
2018-02-06 10:18:38 -06:00
|
|
|
BitFlags = reader.ReadUInt32();
|
|
|
|
|
ObjectId = reader.ReadUInt32();
|
|
|
|
|
FileOffset = reader.ReadUInt32();
|
|
|
|
|
FileSize = reader.ReadUInt32();
|
|
|
|
|
Date = reader.ReadUInt32();
|
|
|
|
|
Iteration = reader.ReadUInt32();
|
2017-03-04 07:59:37 -05:00
|
|
|
}
|
|
|
|
|
|
2018-02-06 10:18:38 -06:00
|
|
|
|
|
|
|
|
private DatFileType? fileType;
|
|
|
|
|
|
|
|
|
|
public DatFileType? GetFileType(DatDatabaseType datDatabaseType)
|
2017-03-15 08:12:21 -04:00
|
|
|
{
|
|
|
|
|
if (fileType != null)
|
|
|
|
|
return fileType.Value;
|
|
|
|
|
|
|
|
|
|
var type = typeof(DatFileType);
|
|
|
|
|
var enumTypes = Enum.GetValues(typeof(DatFileType)).Cast<DatFileType>().ToList();
|
|
|
|
|
|
2018-02-06 10:18:38 -06:00
|
|
|
foreach (var enumType in enumTypes)
|
2017-03-15 08:12:21 -04:00
|
|
|
{
|
2018-02-06 10:18:38 -06:00
|
|
|
var memInfo = type.GetMember(enumType.ToString());
|
2017-03-15 08:12:21 -04:00
|
|
|
var datType = memInfo[0].GetCustomAttributes(typeof(DatDatabaseTypeAttribute), false).Cast<DatDatabaseTypeAttribute>().ToList();
|
|
|
|
|
|
2018-02-06 10:18:38 -06:00
|
|
|
if (datType?.Count > 0 && datType[0].Type == datDatabaseType)
|
2017-03-15 08:12:21 -04:00
|
|
|
{
|
|
|
|
|
// file type matches, now check id range
|
|
|
|
|
var idRange = memInfo[0].GetCustomAttributes(typeof(DatFileTypeIdRangeAttribute), false).Cast<DatFileTypeIdRangeAttribute>().ToList();
|
2018-01-23 04:02:39 -06:00
|
|
|
if (idRange?.Count > 0 && idRange[0].BeginRange <= ObjectId && idRange[0].EndRange >= ObjectId)
|
2017-03-15 08:12:21 -04:00
|
|
|
{
|
|
|
|
|
// id range matches
|
2018-02-06 10:18:38 -06:00
|
|
|
fileType = enumType;
|
2017-03-15 08:12:21 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fileType;
|
|
|
|
|
}
|
2017-03-04 07:59:37 -05:00
|
|
|
}
|
|
|
|
|
}
|