public static void Initialize() { path = Files.GetFilePath("verdata.mul"); if (path == null) { Patches = new Entry5D[0]; Stream = Stream.Null; } else { using (Stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (BinaryReader bin = new BinaryReader(Stream)) { Patches = new Entry5D[bin.ReadInt32()]; for (int i = 0; i < Patches.Length; ++i) { Patches[i].file = bin.ReadInt32(); Patches[i].index = bin.ReadInt32(); Patches[i].lookup = bin.ReadInt32(); Patches[i].length = bin.ReadInt32(); Patches[i].extra = bin.ReadInt32(); } } } Stream.Close(); } }
public Verdata(Files files) { path = files.GetFilePath("verdata.mul"); if (path == null) { Patches = new Entry5D[0]; Stream = Stream.Null; } else { using (Stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var bin = new BinaryReader(Stream)) { Patches = new Entry5D[bin.ReadInt32()]; for (int i = 0; i < Patches.Length; ++i) { Patches[i].file = bin.ReadInt32(); Patches[i].index = bin.ReadInt32(); Patches[i].lookup = bin.ReadInt32(); Patches[i].length = bin.ReadInt32(); Patches[i].extra = bin.ReadInt32(); } } } Stream.Close(); } }
public FileIndex(string idxFile, string mulFile, int length, int file) { m_Index = new Entry3D[length]; m_IndexPath = Client.GetFilePath(idxFile); m_MulPath = Client.GetFilePath(mulFile); if (m_IndexPath != null && m_MulPath != null) { using (FileStream index = new FileStream(m_IndexPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader bin = new BinaryReader(index); m_Stream = new FileStream(m_MulPath, FileMode.Open, FileAccess.Read, FileShare.Read); int count = (int)(index.Length / 12); for (int i = 0; i < count && i < length; ++i) { m_Index[i].lookup = bin.ReadInt32(); m_Index[i].length = bin.ReadInt32(); m_Index[i].extra = bin.ReadInt32(); } for (int i = count; i < length; ++i) { m_Index[i].lookup = -1; m_Index[i].length = -1; m_Index[i].extra = -1; } } } Entry5D[] patches = Verdata.Patches; for (int i = 0; i < patches.Length; ++i) { Entry5D patch = patches[i]; if (patch.file == file && patch.index >= 0 && patch.index < length) { m_Index[patch.index].lookup = patch.lookup; m_Index[patch.index].length = patch.length | (1 << 31); m_Index[patch.index].extra = patch.extra; } } }
public FileIndex(string idxFile, string mulFile, int length, int file) { this.m_Index = new Entry3D[length]; string filePath = Client.GetFilePath(idxFile); string str = Client.GetFilePath(mulFile); if (filePath != null && str != null) { using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader binaryReader = new BinaryReader(fileStream); this.m_Stream = new FileStream(str, FileMode.Open, FileAccess.Read, FileShare.Read); int num = (int)(fileStream.Length / (long)12); for (int i = 0; i < num && i < length; i++) { this.m_Index[i].lookup = binaryReader.ReadInt32(); this.m_Index[i].length = binaryReader.ReadInt32(); this.m_Index[i].extra = binaryReader.ReadInt32(); } for (int j = num; j < length; j++) { this.m_Index[j].lookup = -1; this.m_Index[j].length = -1; this.m_Index[j].extra = -1; } } } Entry5D[] patches = Verdata.Patches; for (int k = 0; k < (int)patches.Length; k++) { Entry5D entry5D = patches[k]; if (entry5D.file == file && entry5D.index >= 0 && entry5D.index < length) { this.m_Index[entry5D.index].lookup = entry5D.lookup; this.m_Index[entry5D.index].length = entry5D.length | -2147483648; this.m_Index[entry5D.index].extra = entry5D.extra; } } }
public FileIndex(string idxFile, string mulFile, int file) { string idxPath = null; MulPath = null; if (Files.MulPath == null) { Files.LoadMulPath(); } if (Files.MulPath.Count > 0) { idxPath = Files.MulPath[idxFile.ToLower()]; MulPath = Files.MulPath[mulFile.ToLower()]; if (String.IsNullOrEmpty(idxPath)) { idxPath = null; } else { if (String.IsNullOrEmpty(Path.GetDirectoryName(idxPath))) { idxPath = Path.Combine(Files.RootDir, idxPath); } if (!File.Exists(idxPath)) { idxPath = null; } } if (String.IsNullOrEmpty(MulPath)) { MulPath = null; } else { if (String.IsNullOrEmpty(Path.GetDirectoryName(MulPath))) { MulPath = Path.Combine(Files.RootDir, MulPath); } if (!File.Exists(MulPath)) { MulPath = null; } } } if ((idxPath != null) && (MulPath != null)) { using (FileStream index = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { Stream = new FileStream(MulPath, FileMode.Open, FileAccess.Read, FileShare.Read); int count = (int)(index.Length / 12); IdxLength = index.Length; Index = new Entry3D[count]; GCHandle gc = GCHandle.Alloc(Index, GCHandleType.Pinned); byte[] buffer = new byte[index.Length]; index.Read(buffer, 0, (int)index.Length); Marshal.Copy(buffer, 0, gc.AddrOfPinnedObject(), (int)index.Length); gc.Free(); } } else { Stream = null; Index = new Entry3D[1]; return; } Entry5D[] patches = Verdata.Patches; if (file > -1) { for (int i = 0; i < patches.Length; ++i) { Entry5D patch = patches[i]; if (patch.file == file && patch.index >= 0 && patch.index < Index.Length) { Index[patch.index].lookup = patch.lookup; Index[patch.index].length = patch.length | (1 << 31); Index[patch.index].extra = patch.extra; } } } }
public FileIndex(string idxFile, string mulFile, string uopFile, int length, int file, string uopEntryExtension, int idxLength, bool hasExtra) { Index = new Entry3D[length]; string idxPath = null; MulPath = null; string uopPath = null; if (Files.MulPath == null) { Files.LoadMulPath(); } if (Files.MulPath.Count > 0) { idxPath = Files.MulPath[idxFile.ToLower()]; MulPath = Files.MulPath[mulFile.ToLower()]; if (!String.IsNullOrEmpty(uopFile) && Files.MulPath.ContainsKey(uopFile.ToLower())) { uopPath = Files.MulPath[uopFile.ToLower()]; } if (String.IsNullOrEmpty(idxPath)) { idxPath = null; } else { if (String.IsNullOrEmpty(Path.GetDirectoryName(idxPath))) { idxPath = Path.Combine(Files.RootDir, idxPath); } if (!File.Exists(idxPath)) { idxPath = null; } } if (String.IsNullOrEmpty(MulPath)) { MulPath = null; } else { if (String.IsNullOrEmpty(Path.GetDirectoryName(MulPath))) { MulPath = Path.Combine(Files.RootDir, MulPath); } if (!File.Exists(MulPath)) { MulPath = null; } } if (String.IsNullOrEmpty(uopPath)) { uopPath = null; } else { if (String.IsNullOrEmpty(Path.GetDirectoryName(uopPath))) { uopPath = Path.Combine(Files.RootDir, uopPath); } if (!File.Exists(uopPath)) { uopPath = null; } else { MulPath = uopPath; } } } /* UOP files support code, written by Wyatt (c) www.ruosi.org * idxLength variable was added for compatibility with legacy code for art (see art.cs) * At the moment the only UOP file having entries with extra field is gumpartlegacy.uop, * and it's two dwords in the beginning of the entry. * It's possible that UOP can include some entries with unknown hash: not really unknown for me, but * not useful for reading legacy entries. That's why i removed unknown hash exception throwing from this code */ if (MulPath != null && MulPath.EndsWith(".uop")) { using (FileStream index = new FileStream(MulPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { Stream = new FileStream(MulPath, FileMode.Open, FileAccess.Read, FileShare.Read); FileInfo fi = new FileInfo(MulPath); string uopPattern = fi.Name.Replace(fi.Extension, "").ToLowerInvariant(); using (BinaryReader br = new BinaryReader(Stream)) { br.BaseStream.Seek(0, SeekOrigin.Begin); if (br.ReadInt32() != 0x50594D) { throw new ArgumentException("Bad UOP file."); } br.ReadInt64(); // version + signature long nextBlock = br.ReadInt64(); br.ReadInt32(); // block capacity int count = br.ReadInt32(); if (idxLength > 0) { IdxLength = idxLength * 12; } Dictionary <ulong, int> hashes = new Dictionary <ulong, int>(); for (int i = 0; i < length; i++) { string entryName = string.Format("build/{0}/{1:D8}{2}", uopPattern, i, uopEntryExtension); ulong hash = HashFileName(entryName); if (!hashes.ContainsKey(hash)) { hashes.Add(hash, i); } } br.BaseStream.Seek(nextBlock, SeekOrigin.Begin); do { int filesCount = br.ReadInt32(); nextBlock = br.ReadInt64(); for (int i = 0; i < filesCount; i++) { long offset = br.ReadInt64(); int headerLength = br.ReadInt32(); int compressedLength = br.ReadInt32(); int decompressedLength = br.ReadInt32(); ulong hash = br.ReadUInt64(); br.ReadUInt32(); // Adler32 short flag = br.ReadInt16(); int entryLength = flag == 1 ? compressedLength : decompressedLength; if (offset == 0) { continue; } int idx; if (hashes.TryGetValue(hash, out idx)) { if (idx < 0 || idx > Index.Length) { throw new IndexOutOfRangeException("hashes dictionary and files collection have different count of entries!"); } Index[idx].lookup = (int)(offset + headerLength); Index[idx].length = entryLength; if (hasExtra) { long curPos = br.BaseStream.Position; br.BaseStream.Seek(offset + headerLength, SeekOrigin.Begin); byte[] extra = br.ReadBytes(8); short extra1 = (short)((extra[3] << 24) | (extra[2] << 16) | (extra[1] << 8) | extra[0]); short extra2 = (short)((extra[7] << 24) | (extra[6] << 16) | (extra[5] << 8) | extra[4]); Index[idx].lookup += 8; Index[idx].extra = extra1 << 16 | extra2; br.BaseStream.Seek(curPos, SeekOrigin.Begin); } } } }while (br.BaseStream.Seek(nextBlock, SeekOrigin.Begin) != 0); } } } else if ((idxPath != null) && (MulPath != null)) { using (FileStream index = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { Stream = new FileStream(MulPath, FileMode.Open, FileAccess.Read, FileShare.Read); int count = (int)(index.Length / 12); IdxLength = index.Length; GCHandle gc = GCHandle.Alloc(Index, GCHandleType.Pinned); byte[] buffer = new byte[index.Length]; index.Read(buffer, 0, (int)index.Length); Marshal.Copy(buffer, 0, gc.AddrOfPinnedObject(), (int)Math.Min(IdxLength, length * 12)); gc.Free(); for (int i = count; i < length; ++i) { Index[i].lookup = -1; Index[i].length = -1; Index[i].extra = -1; } } } else { Stream = null; return; } Entry5D[] patches = Verdata.Patches; if (file > -1) { for (int i = 0; i < patches.Length; ++i) { Entry5D patch = patches[i]; if (patch.file == file && patch.index >= 0 && patch.index < length) { Index[patch.index].lookup = patch.lookup; Index[patch.index].length = patch.length | (1 << 31); Index[patch.index].extra = patch.extra; } } } }