diff --git a/eAmuseCore/KBinXML/XmlTypes.cs b/eAmuseCore/KBinXML/XmlTypes.cs index 90eb263..fc0ac7c 100644 --- a/eAmuseCore/KBinXML/XmlTypes.cs +++ b/eAmuseCore/KBinXML/XmlTypes.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Net; using System.Text; using System.Collections; +using System.Globalization; namespace eAmuseCore.KBinXML.XmlTypes { @@ -162,6 +163,52 @@ namespace eAmuseCore.KBinXML.XmlTypes } } + [KValue(14, "float", "f", Count = 1, Size = 4)] + public class KFloat : KValue + { + public KFloat(float value) => Value = value; + + public override string ToString() + { + return Value.ToString(CultureInfo.InvariantCulture); + } + + public override IEnumerable ToBytes() + { + IEnumerable res = BitConverter.GetBytes(Value); + if (BitConverter.IsLittleEndian) + res = res.Reverse(); + return res; + } + + static public KFloat FromString(string input) => new KFloat(Convert.ToSingle(input, CultureInfo.InvariantCulture)); + + static public KFloat FromBytes(IEnumerable input) => new KFloat(input.FirstF()); + } + + [KValue(15, "double", "d", Count = 1, Size = 8)] + public class KDouble : KValue + { + public KDouble(double value) => Value = value; + + public override string ToString() + { + return Value.ToString(CultureInfo.InvariantCulture); + } + + public override IEnumerable ToBytes() + { + IEnumerable res = BitConverter.GetBytes(Value); + if (BitConverter.IsLittleEndian) + res = res.Reverse(); + return res; + } + + static public KDouble FromString(string input) => new KDouble(Convert.ToDouble(input, CultureInfo.InvariantCulture)); + + static public KDouble FromBytes(IEnumerable input) => new KDouble(input.FirstD()); + } + [KValue(27, "3u8", Count = 3, Size = 1)] public class K3U8 : KValueList { @@ -207,7 +254,7 @@ namespace eAmuseCore.KBinXML.XmlTypes { foreach (Type type in Assembly.GetExecutingAssembly().GetTypes()) { - KValueAttribute attr = type.GetCustomAttribute(true); + KValueAttribute attr = type.GetCustomAttribute(false); if (attr == null) continue; diff --git a/eAmuseTest/Program.cs b/eAmuseTest/Program.cs index 72e0d96..2fab9e0 100644 --- a/eAmuseTest/Program.cs +++ b/eAmuseTest/Program.cs @@ -46,9 +46,7 @@ namespace eAmuseTest else if (compress != "none") throw new ArgumentException("Unsupported compression algorithm"); - Console.WriteLine(BytesToString(BitConverter.GetBytes((byte)1))); - - KBinXML kbinxml = new KBinXML(rawData); + //KBinXML kbinxml = new KBinXML(rawData); KBinXML testDoc = new KBinXML(ExtractResource("eAmuseTest.testcases_out.kbin")); }