private void LoadEbl(UnpackEbl ebl, string gameDirectory, EblDictionary eblDict, BHD5.Game game) { gameDirectory = gameDirectory.TrimEnd('\\'); string bhdPath = $@"{gameDirectory}\{ebl.Name}.bhd"; string bdtPath = $@"{gameDirectory}\{ebl.Name}.bdt"; if (!ebl.Optional) { if (!File.Exists(bhdPath)) { throw new FileNotFoundException($"Mandatory header file not found:\n{bhdPath}"); } else if (!File.Exists(bdtPath)) { throw new FileNotFoundException($"Mandatory data file not found:\n{bdtPath}"); } } else if (!File.Exists(bhdPath) || !File.Exists(bdtPath)) { return; } BHD5 bhd = ReadBHD5(bhdPath, ebl.Key, game); FileStream bdtStream = File.OpenRead(bdtPath); DataStreams.Enqueue(bdtStream); foreach (BHD5.Bucket bucket in bhd.Buckets) { foreach (BHD5.FileHeader header in bucket) { if (eblDict.GetPath(header.FileNameHash, out string path)) { path = path.Replace('/', '\\').TrimStart('\\'); var file = new EblFile(path, header, bdtStream); Files[path.ToLower()] = file; } } } }
private static BHD5 ReadBHD5(string path, string key, BHD5.Game game) { using (FileStream fs = File.OpenRead(path)) { var magic = new byte[4]; fs.Read(magic, 0, 4); fs.Seek(0, SeekOrigin.Begin); bool encrypted = Encoding.ASCII.GetString(magic) != "BHD5"; if (encrypted) { using (var ms = TPUtil.DecryptRsa(fs, key)) { return(BHD5.Read(ms, game)); } } else { return(BHD5.Read(fs, game)); } } }