Timothy Schenk
9f3007b10e
All checks were successful
Build, Package and Push Images / preprocess (push) Successful in 2s
Build, Package and Push Images / build (push) Successful in 25s
Build, Package and Push Images / sbom-scan (push) Successful in 49s
Build, Package and Push Images / container-build (push) Successful in 2m11s
Build, Package and Push Images / sonarqube (push) Successful in 2m12s
Build, Package and Push Images / container-sbom-scan (push) Successful in 39s
58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
using System.Reflection;
|
|
|
|
namespace Wonderking.Game;
|
|
|
|
public abstract class DataReader<T>
|
|
{
|
|
private readonly string _datFileName;
|
|
|
|
private readonly byte _xorKey;
|
|
protected readonly ushort SizeOfEntry;
|
|
|
|
protected DataReader(string path)
|
|
{
|
|
Path = path;
|
|
_xorKey = GetXorKey();
|
|
SizeOfEntry = GetSizeOfEntry();
|
|
_datFileName = GetDatFileName();
|
|
DatFileContent = GetDatFileContent(path).ToArray();
|
|
}
|
|
|
|
private protected string Path { get; init; }
|
|
|
|
protected byte[] DatFileContent { get; }
|
|
|
|
public abstract uint GetAmountOfEntries();
|
|
public abstract T GetEntry(uint entryId);
|
|
|
|
private static 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");
|
|
}
|
|
|
|
private Span<byte> GetDatFileContent(string path)
|
|
{
|
|
var fileData = File.ReadAllBytes(path + _datFileName);
|
|
var data = new byte[fileData.Length];
|
|
|
|
for (var i = 0; i < fileData.Length; i++)
|
|
{
|
|
data[i] = (byte)(fileData[i] ^ _xorKey);
|
|
}
|
|
|
|
return data;
|
|
}
|
|
}
|