public GameInfo(string xmlStr, string dictionaryStr) { Dictionary = new ArchiveDictionary(dictionaryStr); XDocument xml = XDocument.Parse(xmlStr); RequiredGB = long.Parse(xml.Root.Element("required_gb").Value); BHD5Game = (BHD5.Game)Enum.Parse(typeof(BHD5.Game), xml.Root.Element("bhd5_game").Value); Archives = xml.Root.Element("archives").Elements().Select(element => element.Value).ToList(); BackupDirs = xml.Root.Element("backup_dirs").Elements().Select(element => element.Value).ToList(); DeleteDirs = xml.Root.Element("delete_dirs").Elements().Select(element => element.Value).ToList(); Replacements = xml.Root.Element("replacements").Elements().Select(element => element.Value).ToList(); }
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)); } } }
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; } } } }