diff --git a/GameRes/ByteArray.cs b/GameRes/ByteArray.cs index b9352405..21bf900d 100644 --- a/GameRes/ByteArray.cs +++ b/GameRes/ByteArray.cs @@ -140,17 +140,17 @@ namespace GameRes public static class ByteArrayExt { - public static ushort ToUInt16 (this CowArray arr, int index) + public static ushort ToUInt16 (this TArray arr, int index) where TArray : IList { return (ushort)(arr[index] | arr[index+1] << 8); } - public static short ToInt16 (this CowArray arr, int index) + public static short ToInt16 (this TArray arr, int index) where TArray : IList { return (short)(arr[index] | arr[index+1] << 8); } - public static int ToInt24 (this CowArray arr, int index) + public static int ToInt24 (this TArray arr, int index) where TArray : IList { return arr[index] | arr[index+1] << 8 | arr[index+2] << 16; } @@ -165,26 +165,29 @@ namespace GameRes return (int)ToUInt32 (arr, index); } - public static ulong ToUInt64 (this CowArray arr, int index) + public static ulong ToUInt64 (this TArray arr, int index) where TArray : IList { return (ulong)ToUInt32 (arr, index) | ((ulong)ToUInt32 (arr, index+4) << 32); } - public static long ToInt64 (this CowArray arr, int index) + public static long ToInt64 (this TArray arr, int index) where TArray : IList { return (long)ToUInt64 (arr, index); } - public static bool AsciiEqual (this CowArray arr, int index, string str) + public static bool AsciiEqual (this TArray arr, int index, string str) where TArray : IList { - arr.Reclaim(); - return Binary.AsciiEqual (arr.ToArray(), index, str); + if (arr.Length-index < str.Length) + return false; + for (int i = 0; i < str.Length; ++i) + if ((char)arr[index+i] != str[i]) + return false; + return true; } - public static bool AsciiEqual (this CowArray arr, string str) + public static bool AsciiEqual (this TArray arr, string str) where TArray : IList { - arr.Reclaim(); - return Binary.AsciiEqual (arr.ToArray(), str); + return arr.AsciiEqual (0, str); } public static string GetCString (this CowArray arr, int index, int length_limit)