51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
using BeyondTools.SparkBuffer.Extensions;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace BeyondTools.SparkBuffer
|
|
{
|
|
public static class SparkManager
|
|
{
|
|
public static readonly JsonSerializerOptions jsonSerializerOptions = new() { IncludeFields = true, WriteIndented = true, NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals };
|
|
|
|
private static readonly Dictionary<int, BeanType> beanTypeMap = [];
|
|
private static readonly Dictionary<int, EnumType> enumTypeMap = [];
|
|
|
|
public static BeanType BeanTypeFromHash(int hash)
|
|
=> beanTypeMap[hash];
|
|
|
|
public static EnumType EnumTypeFromHash(int hash)
|
|
=> enumTypeMap[hash];
|
|
|
|
public static void ReadTypeDefinitions(BinaryReader reader)
|
|
{
|
|
var typeDefCount = reader.ReadInt32();
|
|
while (typeDefCount-- > 0)
|
|
{
|
|
var sparkType = reader.ReadSparkType();
|
|
reader.Align4Bytes();
|
|
|
|
switch (sparkType)
|
|
{
|
|
case SparkType.Enum:
|
|
{
|
|
var enumType = new EnumType(reader);
|
|
enumTypeMap.TryAdd(enumType.typeHash, enumType);
|
|
break;
|
|
}
|
|
case SparkType.Bean:
|
|
{
|
|
var beanType = new BeanType(reader);
|
|
beanTypeMap.TryAdd(beanType.typeHash, beanType);
|
|
break;
|
|
}
|
|
default:
|
|
#pragma warning disable CA2208
|
|
throw new ArgumentOutOfRangeException(nameof(sparkType), sparkType.ToString(), "Invalid spark type on type definition section");
|
|
#pragma warning restore CA2208
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|