public DatFileIndex(IDirectory directory, DetSpecificationIndex specIndex, bool lazyLoad = true) { var files = directory.Files.Where(c => c.Name.EndsWith(".dat")).ToArray(); if (files.Length == 0) { var dataDirectory = directory.Directories.FirstOrDefault(c => c.Name == "Data"); if (dataDirectory != null) { files = dataDirectory.Files.Where(c => c.Name.EndsWith(".dat")).ToArray(); } } foreach (var file in files) { if (Underlying.ContainsKey(file.Name) || !specIndex.ContainsKey(file.Name)) { continue; } var dat = new DatFile(file, specIndex[file.Name], this, lazyLoad); Underlying.Add(file.Name, dat); } }
public static int GetUtf8Bytes(ref char chars, int length, byte *bytes) { var offset = bytes; while (length >= 4 && (Underlying.As <char, ulong>(ref chars) & 0xff80ff80ff80ff80) == 0) { *(uint *)offset = Close(Underlying.As <char, ulong>(ref chars)); chars = ref Underlying.Add(ref chars, 4); length -= 4; offset += 4; } for (int i = 0; i < length; i++) { int @char = Underlying.Add(ref chars, i); if (@char <= 0x7f) { *offset = (byte)@char; ++offset; } else if (@char <= 0x7ff) { offset[0] = (byte)(0xc0 | (@char >> 6)); offset[1] = (byte)(0x80 | (@char & 0x3f)); offset += 2; } else if (@char >= 0xd800 && @char <= 0xdbff) { @char = (((@char & 0x3ff) << 10) | (Underlying.Add(ref chars, ++i) & 0x3ff)) + 0x10000; offset[0] = (byte)(0xf0 | (@char >> 18)); offset[1] = (byte)(0x80 | ((@char >> 12) & 0x3f)); offset[2] = (byte)(0x80 | ((@char >> 6) & 0x3f)); offset[3] = (byte)(0x80 | (@char & 0x3f)); offset += 4; } else { offset[0] = (byte)(0xe0 | (@char >> 12)); offset[1] = (byte)(0x80 | ((@char >> 6) & 0x3f)); offset[2] = (byte)(0x80 | (@char & 0x3f)); offset += 3; } } return((int)(offset - bytes)); }
public static int GetUtf8Chars(byte *bytes, int length, ref char chars) { var num = 0; while (length >= 4 && (*(uint *)bytes & 0x80808080) == 0) { Underlying.As <char, ulong>(ref Underlying.Add(ref chars, num)) = Open(*(uint *)bytes); bytes += 4; length -= 4; num += 4; } for (var end = bytes + length; bytes < end; bytes++, num++) { int @byte = *bytes; if (@byte <= 0x7f) { Underlying.Add(ref chars, num) = (char)@byte; } else if (@byte <= 0xdf) { Underlying.Add(ref chars, num) = (char)(((@byte & 0x1f) << 6) | (*(++bytes) & 0x3f)); } else if (@byte <= 0xef) { Underlying.Add(ref chars, num) = (char)(((@byte & 0xf) << 12) | ((*(++bytes) & 0x3f) << 6) + (*(++bytes) & 0x3f)); } else { @byte = (((@byte & 0x7) << 18) | ((*(++bytes) & 0x3f) << 12) | ((*(++bytes) & 0x3f) << 6) + (*(++bytes) & 0x3f)) - 0x10000; Underlying.Add(ref chars, num) = (char)(0xd800 | (@byte >> 10)); ++num; Underlying.Add(ref chars, num) = (char)(0xdc00 | (@byte & 0x3ff)); } } return(num); }
public static bool Equals(byte *bytes, int bytesLength, ref char firstChar, int charCount, bool ignoreCase) { if (charCount <= GetUtf8MaxCharsLength(bytesLength) && bytesLength <= GetUtf8MaxBytesLength(charCount)) { int charOffset = 0; for (var end = bytes + bytesLength; bytes < end; bytes++, charOffset++) { int @byte = *bytes; if (@byte <= 0x7f) { if (charOffset < charCount && Equal( Underlying.Add(ref firstChar, charOffset), (char)@byte, ignoreCase)) { continue; } } else if (@byte <= 0xdf) { if (charOffset < charCount && Equal( Underlying.Add(ref firstChar, charOffset), (char)(((@byte & 0x1f) << 6) | (*(++bytes) & 0x3f)), ignoreCase)) { continue; } } else if (@byte <= 0xef) { if (charOffset < charCount && Equal( Underlying.Add(ref firstChar, charOffset), (char)(((@byte & 0xf) << 12) | ((*(++bytes) & 0x3f) << 6) + (*(++bytes) & 0x3f)), ignoreCase)) { continue; } } else { @byte = (((@byte & 0x7) << 18) | ((*(++bytes) & 0x3f) << 12) | ((*(++bytes) & 0x3f) << 6) + (*(++bytes) & 0x3f)) - 0x10000; if (charOffset < charCount && Equal( Underlying.Add(ref firstChar, charOffset), (char)(0xd800 | (@byte >> 10)), ignoreCase) && (++charOffset) < charCount && Equal( Underlying.Add(ref firstChar, charOffset), (char)(0xdc00 | (@byte & 0x3ff)), ignoreCase)) { continue; } } return(false); } return(charOffset == charCount); } return(false); }
public static void StoreStructFieldValue <TValue>(ref byte obj, TValue value, int offset) { Underlying.As <byte, TValue>(ref Underlying.Add(ref obj, offset)) = value; }
public static TValue LoadStructFieldValue <TValue>(ref byte obj, int offset) { return(Underlying.As <byte, TValue>(ref Underlying.Add(ref obj, offset))); }
public static void StoreFieldValue <TValue>(object obj, TValue value, int offset) { Underlying.As <byte, TValue>(ref Underlying.Add(ref TypeHelper.Unbox <byte>(obj), offset)) = value; }
public static TValue LoadFieldValue <TValue>(object obj, int offset) { return(Underlying.As <byte, TValue>(ref Underlying.Add(ref TypeHelper.Unbox <byte>(obj), offset))); }