v1.00.00
This commit is contained in:
25
AssetStudio/YAML/Utils/Extensions/ArrayYAMLExtensions.cs
Normal file
25
AssetStudio/YAML/Utils/Extensions/ArrayYAMLExtensions.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class ArrayYAMLExtensions
|
||||
{
|
||||
public static YAMLNode ExportYAML(this byte[] _this)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Length * 2);
|
||||
for (int i = 0; i < _this.Length; i++)
|
||||
{
|
||||
sb.AppendHex(_this[i]);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this T[][] _this, int[] version)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
return ((IEnumerable<IEnumerable<T>>)_this).ExportYAML(version);
|
||||
}
|
||||
}
|
||||
}
|
||||
107
AssetStudio/YAML/Utils/Extensions/BitConverterExtensions.cs
Normal file
107
AssetStudio/YAML/Utils/Extensions/BitConverterExtensions.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class BitConverterExtensions
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
private struct FloatUIntUnion
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public uint Int;
|
||||
[FieldOffset(0)]
|
||||
public float Float;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static uint ToUInt32(float value)
|
||||
{
|
||||
return new FloatUIntUnion { Float = value }.Int;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ulong ToUInt64(double value)
|
||||
{
|
||||
return unchecked((ulong)BitConverter.DoubleToInt64Bits(value));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float ToSingle(uint value)
|
||||
{
|
||||
return new FloatUIntUnion { Int = value }.Float;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double ToDouble(ulong value)
|
||||
{
|
||||
return BitConverter.Int64BitsToDouble(unchecked((long)value));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void GetBytes(ushort value, byte[] buffer, int offset)
|
||||
{
|
||||
buffer[offset + 0] = unchecked((byte)(value >> 0));
|
||||
buffer[offset + 1] = unchecked((byte)(value >> 8));
|
||||
}
|
||||
|
||||
public static void GetBytes(uint value, byte[] buffer, int offset)
|
||||
{
|
||||
buffer[offset + 0] = unchecked((byte)(value >> 0));
|
||||
buffer[offset + 1] = unchecked((byte)(value >> 8));
|
||||
buffer[offset + 2] = unchecked((byte)(value >> 16));
|
||||
buffer[offset + 3] = unchecked((byte)(value >> 24));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static short Swap(short value)
|
||||
{
|
||||
return unchecked((short)(Swap(unchecked((ushort)value))));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ushort Swap(ushort value)
|
||||
{
|
||||
return unchecked((ushort)(value >> 8 | value << 8));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int Swap(int value)
|
||||
{
|
||||
return unchecked((int)(Swap(unchecked((uint)value))));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static uint Swap(uint value)
|
||||
{
|
||||
value = value >> 16 | value << 16;
|
||||
return ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static long Swap(long value)
|
||||
{
|
||||
return unchecked((long)(Swap(unchecked((ulong)value))));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ulong Swap(ulong value)
|
||||
{
|
||||
value = value >> 32 | value << 32;
|
||||
value = ((value & 0xFFFF0000FFFF0000) >> 16) | ((value & 0x0000FFFF0000FFFF) << 16);
|
||||
return ((value & 0xFF00FF00FF00FF00) >> 8) | ((value & 0x00FF00FF00FF00FF) << 8);
|
||||
}
|
||||
|
||||
public static int GetDigitsCount(uint value)
|
||||
{
|
||||
int count = 0;
|
||||
while (value != 0)
|
||||
{
|
||||
value /= 10;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
82
AssetStudio/YAML/Utils/Extensions/EmitterExtensions.cs
Normal file
82
AssetStudio/YAML/Utils/Extensions/EmitterExtensions.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
namespace AssetStudio
|
||||
{
|
||||
internal static class EmitterExtensions
|
||||
{
|
||||
public static Emitter WriteHex(this Emitter _this, byte value)
|
||||
{
|
||||
_this.Write(HexAlphabet[value >> 4]);
|
||||
_this.Write(HexAlphabet[value & 0xF]);
|
||||
return _this;
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, ushort value)
|
||||
{
|
||||
_this.Write(HexAlphabet[(value >> 4) & 0xF]);
|
||||
_this.Write(HexAlphabet[(value >> 0) & 0xF]);
|
||||
_this.Write(HexAlphabet[(value >> 12) & 0xF]);
|
||||
_this.Write(HexAlphabet[(value >> 8) & 0xF]);
|
||||
return _this;
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, short value)
|
||||
{
|
||||
return WriteHex(_this, unchecked((ushort)value));
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, uint value)
|
||||
{
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 4) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 0) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 12) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 8) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 20) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 16) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 28) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 24) & 0xF)]);
|
||||
return _this;
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, int value)
|
||||
{
|
||||
return WriteHex(_this, unchecked((uint)value));
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, ulong value)
|
||||
{
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 4) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 0) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 12) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 8) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 20) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 16) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 28) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 24) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 36) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 32) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 44) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 40) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 52) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 48) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 60) & 0xF)]);
|
||||
_this.Write(HexAlphabet[unchecked((int)(value >> 56) & 0xF)]);
|
||||
return _this;
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, long value)
|
||||
{
|
||||
return WriteHex(_this, unchecked((ulong)value));
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, float value)
|
||||
{
|
||||
return WriteHex(_this, BitConverterExtensions.ToUInt32(value));
|
||||
}
|
||||
|
||||
public static Emitter WriteHex(this Emitter _this, double value)
|
||||
{
|
||||
return WriteHex(_this, BitConverterExtensions.ToUInt64(value));
|
||||
}
|
||||
|
||||
private static readonly string HexAlphabet = "0123456789ABCDEF";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class IDictionaryExportYAMLExtensions
|
||||
{
|
||||
public static YAMLNode ExportYAML<T>(this IReadOnlyDictionary<int, T> _this, int[] version)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
map.Add(kvp.Key, kvp.Value.ExportYAML(version));
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IReadOnlyDictionary<string, T> _this, int[] version)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
map.Add(kvp.Key, kvp.Value.ExportYAML(version));
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T1, T2>(this IReadOnlyDictionary<Tuple<T1, long>, T2> _this, int[] version)
|
||||
where T1 : IYAMLExportable
|
||||
where T2 : IYAMLExportable
|
||||
{
|
||||
// TODO: test
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode kvpMap = new YAMLMappingNode();
|
||||
YAMLMappingNode keyMap = new YAMLMappingNode();
|
||||
keyMap.Add("first", kvp.Key.Item1.ExportYAML(version));
|
||||
keyMap.Add("second", kvp.Key.Item2);
|
||||
kvpMap.Add("first", keyMap);
|
||||
kvpMap.Add("second", kvp.Value.ExportYAML(version));
|
||||
node.Add(kvpMap);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IReadOnlyDictionary<T, int> _this, int[] version)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
YAMLNode key = kvp.Key.ExportYAML(version);
|
||||
if (key.NodeType == YAMLNodeType.Scalar)
|
||||
{
|
||||
map.Add(key, kvp.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
map.Add("first", key);
|
||||
map.Add("second", kvp.Value);
|
||||
}
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IReadOnlyDictionary<T, float> _this, int[] version)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
YAMLNode key = kvp.Key.ExportYAML(version);
|
||||
if (key.NodeType == YAMLNodeType.Scalar)
|
||||
{
|
||||
map.Add(key, kvp.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
map.Add("first", key);
|
||||
map.Add("second", kvp.Value);
|
||||
}
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T1, T2>(this IReadOnlyDictionary<T1, T2> _this, int[] version)
|
||||
where T1 : IYAMLExportable
|
||||
where T2 : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
YAMLNode key = kvp.Key.ExportYAML(version);
|
||||
if (key.NodeType == YAMLNodeType.Scalar)
|
||||
{
|
||||
map.Add(key, kvp.Value.ExportYAML(version));
|
||||
}
|
||||
else
|
||||
{
|
||||
map.Add("first", key);
|
||||
map.Add("second", kvp.Value.ExportYAML(version));
|
||||
}
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T1, T2>(this IReadOnlyDictionary<T1, T2[]> _this, int[] version)
|
||||
where T1 : IYAMLExportable
|
||||
where T2 : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
YAMLNode key = kvp.Key.ExportYAML(version);
|
||||
if (key.NodeType == YAMLNodeType.Scalar)
|
||||
{
|
||||
map.Add(key, kvp.Value.ExportYAML(version));
|
||||
}
|
||||
else
|
||||
{
|
||||
map.Add("first", key);
|
||||
map.Add("second", kvp.Value.ExportYAML(version));
|
||||
}
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
105
AssetStudio/YAML/Utils/Extensions/IDictionaryYAMLExtensions.cs
Normal file
105
AssetStudio/YAML/Utils/Extensions/IDictionaryYAMLExtensions.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class IDictionaryYAMLExtensions
|
||||
{
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<uint, string> _this)
|
||||
{
|
||||
YAMLMappingNode node = new YAMLMappingNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
node.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<long, string> _this)
|
||||
{
|
||||
YAMLMappingNode node = new YAMLMappingNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
node.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<string, string> _this)
|
||||
{
|
||||
YAMLMappingNode node = new YAMLMappingNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
node.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<string, int> _this)
|
||||
{
|
||||
YAMLMappingNode node = new YAMLMappingNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
node.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<string, float> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
map.Add(kvp.Key, kvp.Value);
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<Tuple<ushort, ushort>, float> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode keyNode = new YAMLMappingNode();
|
||||
keyNode.Add(kvp.Key.Item1, kvp.Key.Item2);
|
||||
YAMLMappingNode kvpMap = new YAMLMappingNode();
|
||||
kvpMap.Add("first", keyNode);
|
||||
kvpMap.Add("second", kvp.Value);
|
||||
node.Add(kvpMap);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<Tuple<int, long>, string> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode keyNode = new YAMLMappingNode();
|
||||
keyNode.Add(kvp.Key.Item1, kvp.Key.Item2);
|
||||
YAMLMappingNode kvpMap = new YAMLMappingNode();
|
||||
kvpMap.Add("first", keyNode);
|
||||
kvpMap.Add("second", kvp.Value);
|
||||
node.Add(kvpMap);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IReadOnlyDictionary<Tuple<T, long>, string> _this, Func<T, int> converter)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode keyNode = new YAMLMappingNode();
|
||||
keyNode.Add(converter(kvp.Key.Item1), kvp.Key.Item2);
|
||||
YAMLMappingNode kvpMap = new YAMLMappingNode();
|
||||
kvpMap.Add("first", keyNode);
|
||||
kvpMap.Add("second", kvp.Value);
|
||||
node.Add(kvpMap);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
273
AssetStudio/YAML/Utils/Extensions/IEnumerableYAMLExtensions.cs
Normal file
273
AssetStudio/YAML/Utils/Extensions/IEnumerableYAMLExtensions.cs
Normal file
@@ -0,0 +1,273 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class IEnumerableYAMLExtensions
|
||||
{
|
||||
public static YAMLNode ExportYAML(this IEnumerable<bool> _this)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (bool value in _this)
|
||||
{
|
||||
byte bvalue = unchecked((byte)(value ? 1 : 0));
|
||||
sb.AppendHex(bvalue);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<char> _this)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (char value in _this)
|
||||
{
|
||||
sb.AppendHex((ushort)value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<byte> _this)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (byte value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<ushort> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (ushort value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (ushort value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<short> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (short value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (short value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<uint> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (uint value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (uint value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<int> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (int value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (int value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<ulong> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (ulong value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (ulong value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<long> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (long value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (long value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<float> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (float value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<double> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (double value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<string> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (string value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IEnumerable<IEnumerable<string>> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (IEnumerable<string> export in _this)
|
||||
{
|
||||
node.Add(export.ExportYAML());
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IEnumerable<T> _this, int[] version)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (T export in _this)
|
||||
{
|
||||
node.Add(export.ExportYAML(version));
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IEnumerable<IEnumerable<T>> _this, int[] version)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (IEnumerable<T> export in _this)
|
||||
{
|
||||
node.Add(export.ExportYAML(version));
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IEnumerable<Tuple<string, T>> _this, int[] version)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
map.Add(kvp.Item1, kvp.Item2.ExportYAML(version));
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T1, T2>(this IEnumerable<Tuple<T1, T2>> _this, Func<T1, int> converter, int[] version)
|
||||
where T2 : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
map.Add(converter(kvp.Item1), kvp.Item2.ExportYAML(version));
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IEnumerable<KeyValuePair<string, T>> _this, int[] version)
|
||||
where T : IYAMLExportable
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
map.Add(kvp.Key, kvp.Value.ExportYAML(version));
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
171
AssetStudio/YAML/Utils/Extensions/IListYAMLExtensions.cs
Normal file
171
AssetStudio/YAML/Utils/Extensions/IListYAMLExtensions.cs
Normal file
@@ -0,0 +1,171 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class IListYAMLExtensions
|
||||
{
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<bool> _this)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 2);
|
||||
foreach (bool value in _this)
|
||||
{
|
||||
byte bvalue = unchecked((byte)(value ? 1 : 0));
|
||||
sb.AppendHex(bvalue);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<char> _this)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 4);
|
||||
foreach (char value in _this)
|
||||
{
|
||||
sb.AppendHex((ushort)value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<byte> _this)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 2);
|
||||
foreach (byte value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<ushort> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 4);
|
||||
foreach (ushort value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (ushort value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<short> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 4);
|
||||
foreach (short value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (short value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<uint> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 8);
|
||||
foreach (uint value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (uint value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<int> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 8);
|
||||
foreach (int value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (int value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<ulong> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 16);
|
||||
foreach (ulong value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (ulong value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyList<long> _this, bool isRaw)
|
||||
{
|
||||
if (isRaw)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(_this.Count * 16);
|
||||
foreach (long value in _this)
|
||||
{
|
||||
sb.AppendHex(value);
|
||||
}
|
||||
return new YAMLScalarNode(sb.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.Block);
|
||||
foreach (long value in _this)
|
||||
{
|
||||
node.Add(value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
79
AssetStudio/YAML/Utils/Extensions/PrimitiveExtensions.cs
Normal file
79
AssetStudio/YAML/Utils/Extensions/PrimitiveExtensions.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class PrimitiveExtensions
|
||||
{
|
||||
public static int ParseDigit(this char _this)
|
||||
{
|
||||
return _this - '0';
|
||||
}
|
||||
|
||||
public static string ToHexString(this byte _this)
|
||||
{
|
||||
return _this.ToString("x2");
|
||||
}
|
||||
|
||||
public static string ToHexString(this short _this)
|
||||
{
|
||||
ushort value = unchecked((ushort)_this);
|
||||
return ToHexString(value);
|
||||
}
|
||||
|
||||
public static string ToHexString(this ushort _this)
|
||||
{
|
||||
ushort reverse = unchecked((ushort)(((0xFF00 & _this) >> 8) | ((0x00FF & _this) << 8)));
|
||||
return reverse.ToString("x4");
|
||||
}
|
||||
|
||||
public static string ToHexString(this int _this)
|
||||
{
|
||||
uint value = unchecked((uint)_this);
|
||||
return ToHexString(value);
|
||||
}
|
||||
|
||||
public static string ToHexString(this uint _this)
|
||||
{
|
||||
uint reverse = ((0xFF000000 & _this) >> 24) | ((0x00FF0000 & _this) >> 8) | ((0x0000FF00 & _this) << 8) | ((0x000000FF & _this) << 24);
|
||||
return reverse.ToString("x8");
|
||||
}
|
||||
|
||||
public static string ToHexString(this long _this)
|
||||
{
|
||||
ulong value = unchecked((ulong)_this);
|
||||
return ToHexString(value);
|
||||
}
|
||||
|
||||
public static string ToHexString(this ulong _this)
|
||||
{
|
||||
ulong reverse = (_this & 0x00000000000000FFUL) << 56 | (_this & 0x000000000000FF00UL) << 40 |
|
||||
(_this & 0x0000000000FF0000UL) << 24 | (_this & 0x00000000FF000000UL) << 8 |
|
||||
(_this & 0x000000FF00000000UL) >> 8 | (_this & 0x0000FF0000000000UL) >> 24 |
|
||||
(_this & 0x00FF000000000000UL) >> 40 | (_this & 0xFF00000000000000UL) >> 56;
|
||||
return reverse.ToString("x16");
|
||||
}
|
||||
|
||||
public static string ToHexString(this float _this)
|
||||
{
|
||||
uint value = BitConverterExtensions.ToUInt32(_this);
|
||||
return ToHexString(value);
|
||||
}
|
||||
|
||||
public static string ToHexString(this double _this)
|
||||
{
|
||||
ulong value = BitConverterExtensions.ToUInt64(_this);
|
||||
return ToHexString(value);
|
||||
}
|
||||
|
||||
public static int ToClosestInt(this long _this)
|
||||
{
|
||||
if (_this > int.MaxValue)
|
||||
{
|
||||
return int.MaxValue;
|
||||
}
|
||||
if (_this < int.MinValue)
|
||||
{
|
||||
return int.MinValue;
|
||||
}
|
||||
return unchecked((int)_this);
|
||||
}
|
||||
}
|
||||
}
|
||||
87
AssetStudio/YAML/Utils/Extensions/StringBuilderExtensions.cs
Normal file
87
AssetStudio/YAML/Utils/Extensions/StringBuilderExtensions.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System.Text;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class StringBuilderExtensions
|
||||
{
|
||||
static StringBuilderExtensions()
|
||||
{
|
||||
for (int i = 0; i <= byte.MaxValue; i++)
|
||||
{
|
||||
ByteHexRepresentations[i] = i.ToString("x2");
|
||||
}
|
||||
}
|
||||
|
||||
public static StringBuilder AppendHex(this StringBuilder _this, byte value)
|
||||
{
|
||||
_this.Append(ByteHexRepresentations[value]);
|
||||
return _this;
|
||||
}
|
||||
|
||||
public static StringBuilder AppendHex(this StringBuilder _this, ushort value)
|
||||
{
|
||||
_this.Append(ByteHexRepresentations[(value >> 0) & 0xFF]);
|
||||
_this.Append(ByteHexRepresentations[(value >> 8) & 0xFF]);
|
||||
return _this;
|
||||
}
|
||||
|
||||
public static StringBuilder AppendHex(this StringBuilder _this, short value)
|
||||
{
|
||||
return AppendHex(_this, unchecked((ushort)value));
|
||||
}
|
||||
|
||||
public static StringBuilder AppendHex(this StringBuilder _this, uint value)
|
||||
{
|
||||
_this.Append(ByteHexRepresentations[unchecked((int)(value >> 0) & 0xFF)]);
|
||||
_this.Append(ByteHexRepresentations[unchecked((int)(value >> 8) & 0xFF)]);
|
||||
_this.Append(ByteHexRepresentations[unchecked((int)(value >> 16) & 0xFF)]);
|
||||
_this.Append(ByteHexRepresentations[unchecked((int)(value >> 24) & 0xFF)]);
|
||||
return _this;
|
||||
}
|
||||
|
||||
public static StringBuilder AppendHex(this StringBuilder _this, int value)
|
||||
{
|
||||
return AppendHex(_this, unchecked((uint)value));
|
||||
}
|
||||
|
||||
public static StringBuilder AppendHex(this StringBuilder _this, ulong value)
|
||||
{
|
||||
_this.Append(ByteHexRepresentations[unchecked((int)(value >> 0) & 0xFF)]);
|
||||
_this.Append(ByteHexRepresentations[unchecked((int)(value >> 8) & 0xFF)]);
|
||||
_this.Append(ByteHexRepresentations[unchecked((int)(value >> 16) & 0xFF)]);
|
||||
_this.Append(ByteHexRepresentations[unchecked((int)(value >> 24) & 0xFF)]);
|
||||
_this.Append(ByteHexRepresentations[unchecked((int)(value >> 32) & 0xFF)]);
|
||||
_this.Append(ByteHexRepresentations[unchecked((int)(value >> 40) & 0xFF)]);
|
||||
_this.Append(ByteHexRepresentations[unchecked((int)(value >> 48) & 0xFF)]);
|
||||
_this.Append(ByteHexRepresentations[unchecked((int)(value >> 56) & 0xFF)]);
|
||||
return _this;
|
||||
}
|
||||
|
||||
public static StringBuilder AppendHex(this StringBuilder _this, long value)
|
||||
{
|
||||
return AppendHex(_this, unchecked((ulong)value));
|
||||
}
|
||||
|
||||
public static StringBuilder AppendHex(this StringBuilder _this, float value)
|
||||
{
|
||||
return AppendHex(_this, BitConverterExtensions.ToUInt32(value));
|
||||
}
|
||||
|
||||
public static StringBuilder AppendHex(this StringBuilder _this, double value)
|
||||
{
|
||||
return AppendHex(_this, BitConverterExtensions.ToUInt64(value));
|
||||
}
|
||||
|
||||
public static StringBuilder AppendIndent(this StringBuilder _this, int count)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
_this.Append('\t');
|
||||
}
|
||||
return _this;
|
||||
}
|
||||
|
||||
public static readonly string HexAlphabet = "0123456789abcdef";
|
||||
public static readonly string[] ByteHexRepresentations = new string[256];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class YAMLMappingNodeExtensions
|
||||
{
|
||||
public static void AddSerializedVersion(this YAMLMappingNode _this, int version)
|
||||
{
|
||||
if(version > 1)
|
||||
{
|
||||
_this.Add(SerializedVersionName, version);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ForceAddSerializedVersion(this YAMLMappingNode _this, int version)
|
||||
{
|
||||
if (version > 0)
|
||||
{
|
||||
_this.Add(SerializedVersionName, version);
|
||||
}
|
||||
}
|
||||
|
||||
public static void InsertSerializedVersion(this YAMLMappingNode _this, int version)
|
||||
{
|
||||
if(version > 1)
|
||||
{
|
||||
_this.InsertBegin(SerializedVersionName, version);
|
||||
}
|
||||
}
|
||||
|
||||
public const string SerializedVersionName = "serializedVersion";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user