From f69d4116d01f429ef416e53687a562ed22b12e22 Mon Sep 17 00:00:00 2001 From: BtbN Date: Wed, 17 Apr 2019 20:45:56 +0200 Subject: [PATCH] Implement some more types --- eAmuseCore/KBinXML/XmlTypes.cs | 47 +++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/eAmuseCore/KBinXML/XmlTypes.cs b/eAmuseCore/KBinXML/XmlTypes.cs index dcd26de..f83eb24 100644 --- a/eAmuseCore/KBinXML/XmlTypes.cs +++ b/eAmuseCore/KBinXML/XmlTypes.cs @@ -98,7 +98,12 @@ namespace eAmuseCore.KBinXML.XmlTypes static public Bin FromString(string input) { - throw new NotImplementedException(); + if ((input.Length % 2) != 2) + throw new ArgumentException("Hex string needs to consist of pairs of two chars.", "input"); + byte[] res = new byte[input.Length / 2]; + for (int i = 0, j = 0; i < input.Length; i += 2, ++j) + res[j] = Convert.ToByte(input.Substring(i, 2), 16); + return new Bin(res); } static public Bin FromBytes(IEnumerable input) => new Bin(input.ToArray()); @@ -198,6 +203,46 @@ namespace eAmuseCore.KBinXML.XmlTypes static public K2S8 FromBytes(IEnumerable input) => XmlTypes.ValueListTypeFromBytes(input); } + [KValue(17, "2u8", Count = 2, Size = 1)] + public class K2U8 : KValueArray + { + public K2U8(U8 v1, U8 v2) : base(v1, v2) { } + static public K2U8 FromString(string input) => XmlTypes.ValueListTypeFromString(input); + static public K2U8 FromBytes(IEnumerable input) => XmlTypes.ValueListTypeFromBytes(input); + } + + [KValue(18, "2s16", Count = 2, Size = 2)] + public class K2S16 : KValueArray + { + public K2S16(S16 v1, S16 v2) : base(v1, v2) { } + static public K2S16 FromString(string input) => XmlTypes.ValueListTypeFromString(input); + static public K2S16 FromBytes(IEnumerable input) => XmlTypes.ValueListTypeFromBytes(input); + } + + [KValue(19, "2u16", Count = 2, Size = 2)] + public class K2U16 : KValueArray + { + public K2U16(U16 v1, U16 v2) : base(v1, v2) { } + static public K2U16 FromString(string input) => XmlTypes.ValueListTypeFromString(input); + static public K2U16 FromBytes(IEnumerable input) => XmlTypes.ValueListTypeFromBytes(input); + } + + [KValue(20, "2s32", Count = 2, Size = 4)] + public class K2S32 : KValueArray + { + public K2S32(S32 v1, S32 v2) : base(v1, v2) { } + static public K2S32 FromString(string input) => XmlTypes.ValueListTypeFromString(input); + static public K2S32 FromBytes(IEnumerable input) => XmlTypes.ValueListTypeFromBytes(input); + } + + [KValue(21, "2u32", Count = 2, Size = 4)] + public class K2U32 : KValueArray + { + public K2U32(U32 v1, U32 v2) : base(v1, v2) { } + static public K2U32 FromString(string input) => XmlTypes.ValueListTypeFromString(input); + static public K2U32 FromBytes(IEnumerable input) => XmlTypes.ValueListTypeFromBytes(input); + } + [KValue(27, "3u8", Count = 3, Size = 1)] public class K3U8 : KValueArray {