diff --git a/EXILED/Exiled.Loader/Features/Configs/CustomConverters/ColorConverter.cs b/EXILED/Exiled.Loader/Features/Configs/CustomConverters/ColorConverter.cs index 3253d1012..04e15c00c 100644 --- a/EXILED/Exiled.Loader/Features/Configs/CustomConverters/ColorConverter.cs +++ b/EXILED/Exiled.Loader/Features/Configs/CustomConverters/ColorConverter.cs @@ -14,9 +14,7 @@ namespace Exiled.Loader.Features.Configs.CustomConverters using Exiled.API.Features; using Exiled.API.Features.Pools; - using UnityEngine; - using YamlDotNet.Core; using YamlDotNet.Core.Events; using YamlDotNet.Serialization; @@ -36,13 +34,20 @@ public bool Accepts(Type type) /// public object ReadYaml(IParser parser, Type type) { - Type baseType = Nullable.GetUnderlyingType(type) ?? type; + Type baseType = Nullable.GetUnderlyingType(type); + + bool isNullable = true; + if (baseType == null) + { + baseType = type; + isNullable = false; + } if (parser.TryConsume(out Scalar scalar)) { if (string.IsNullOrEmpty(scalar.Value) || scalar.Value.Equals("null", StringComparison.OrdinalIgnoreCase)) { - if (Nullable.GetUnderlyingType(type) != null) + if (isNullable) return null; Log.Error($"Cannot assign null to non-nullable type {baseType.FullName}."); @@ -83,7 +88,11 @@ public object ReadYaml(IParser parser, Type type) } } - object color = Activator.CreateInstance(type, coordinates.ToArray()); + object color; + if (isNullable) + color = Activator.CreateInstance(type, Activator.CreateInstance(baseType, coordinates.ToArray())); + else + color = Activator.CreateInstance(type, coordinates.ToArray()); ListPool.Pool.Return(coordinates); diff --git a/EXILED/Exiled.Loader/Features/Configs/CustomConverters/VectorsConverter.cs b/EXILED/Exiled.Loader/Features/Configs/CustomConverters/VectorsConverter.cs index 63f413247..cdf89ab3d 100644 --- a/EXILED/Exiled.Loader/Features/Configs/CustomConverters/VectorsConverter.cs +++ b/EXILED/Exiled.Loader/Features/Configs/CustomConverters/VectorsConverter.cs @@ -14,9 +14,7 @@ namespace Exiled.Loader.Features.Configs.CustomConverters using Exiled.API.Features; using Exiled.API.Features.Pools; - using UnityEngine; - using YamlDotNet.Core; using YamlDotNet.Core.Events; using YamlDotNet.Serialization; @@ -30,19 +28,26 @@ public sealed class VectorsConverter : IYamlTypeConverter public bool Accepts(Type type) { Type baseType = Nullable.GetUnderlyingType(type) ?? type; - return baseType == typeof(Vector2) || baseType == typeof(Vector3) || baseType == typeof(Vector4); + return baseType == typeof(Vector2) || baseType == typeof(Vector3) || baseType == typeof(Vector4) || baseType == typeof(Quaternion); } /// public object ReadYaml(IParser parser, Type type) { - Type baseType = Nullable.GetUnderlyingType(type) ?? type; + Type baseType = Nullable.GetUnderlyingType(type); + + bool isNullable = true; + if (baseType == null) + { + isNullable = false; + baseType = type; + } if (parser.TryConsume(out Scalar scalar)) { if (string.IsNullOrEmpty(scalar.Value) || scalar.Value.Equals("null", StringComparison.OrdinalIgnoreCase)) { - if (Nullable.GetUnderlyingType(type) != null) + if (isNullable) return null; Log.Error($"Cannot assign null to non-nullable type {baseType.FullName}."); @@ -75,7 +80,11 @@ public object ReadYaml(IParser parser, Type type) coordinates.Add(coordinate); } - object vector = Activator.CreateInstance(baseType, coordinates.ToArray()); + object vector; + if (isNullable) + vector = Activator.CreateInstance(type, Activator.CreateInstance(baseType, coordinates.ToArray())); + else + vector = Activator.CreateInstance(type, coordinates.ToArray()); ListPool.Pool.Return(coordinates); @@ -111,6 +120,13 @@ public void WriteYaml(IEmitter emitter, object value, Type type) coordinates["z"] = vector4.z; coordinates["w"] = vector4.w; } + else if (value is Quaternion quaternion) + { + coordinates["x"] = quaternion.x; + coordinates["y"] = quaternion.y; + coordinates["z"] = quaternion.z; + coordinates["w"] = quaternion.w; + } emitter.Emit(new MappingStart());