Timothy Schenk
46649adfd8
All checks were successful
Build, Package and Push Images / preprocess (push) Successful in 2s
Build, Package and Push Images / build (push) Successful in 23s
Build, Package and Push Images / sonarqube (push) Has been skipped
Build, Package and Push Images / sbom-scan (push) Successful in 32s
Build, Package and Push Images / container-build (push) Successful in 3m16s
Build, Package and Push Images / container-sbom-scan (push) Successful in 32s
requires base stats and parsing of values provided by user
50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using System.Reflection;
|
|
|
|
namespace Wonderking.Game;
|
|
|
|
public abstract class DataReader<T>
|
|
{
|
|
protected DataReader(string path)
|
|
{
|
|
Path = path;
|
|
DatFileContent = GetDatFileContent(path).ToArray();
|
|
}
|
|
|
|
private protected string Path { get; init; }
|
|
|
|
public abstract uint GetAmountOfEntries();
|
|
public abstract T GetEntry(uint entryId);
|
|
|
|
protected ushort GetSizeOfEntry()
|
|
{
|
|
return typeof(T).GetCustomAttribute<GameDataMetadataAttribute>()?.DataEntrySize ??
|
|
throw new NotSupportedException("DataEntrySize is null");
|
|
}
|
|
|
|
private static string GetDatFileName()
|
|
{
|
|
return typeof(T).GetCustomAttribute<GameDataMetadataAttribute>()?.DatFileName ??
|
|
throw new NotSupportedException("DatFileName is null");
|
|
}
|
|
|
|
private static byte GetXorKey()
|
|
{
|
|
return typeof(T).GetCustomAttribute<GameDataMetadataAttribute>()?.XorKey ??
|
|
throw new NotSupportedException("XorKey is null");
|
|
}
|
|
|
|
protected byte[] DatFileContent { get; }
|
|
|
|
private static Span<byte> GetDatFileContent(string path)
|
|
{
|
|
var fileData = File.ReadAllBytes(path + GetDatFileName());
|
|
var data = new byte[fileData.Length];
|
|
|
|
for (var i = 0; i < fileData.Length; i++)
|
|
{
|
|
data[i] = (byte)(fileData[i] ^ GetXorKey());
|
|
}
|
|
|
|
return data;
|
|
}
|
|
}
|