public GameCacheHaloOnline(DirectoryInfo directory) { Directory = directory; TagsFile = new FileInfo(Path.Combine(directory.FullName, "tags.dat")); TagNamesFile = new FileInfo(Path.Combine(directory.FullName, "tag_list.csv")); StringIdCacheFile = new FileInfo(Path.Combine(directory.FullName, "string_ids.dat")); Endianness = EndianFormat.LittleEndian; var names = TagCacheHaloOnline.LoadTagNames(TagNamesFile.FullName); using (var stream = TagsFile.OpenRead()) TagCacheGenHO = new TagCacheHaloOnline(stream, names); if (CacheVersion.Unknown == (Version = CacheVersionDetection.DetectFromTimestamp(TagCacheGenHO.Header.CreationTime, out var closestVersion))) { Version = closestVersion; } using (var stream = StringIdCacheFile.OpenRead()) StringTableHaloOnline = new StringTableHaloOnline(Version, stream); DisplayName = Version.ToString(); Deserializer = new TagDeserializer(Version); Serializer = new TagSerializer(Version); ResourceCaches = new ResourceCachesHaloOnline(this); }
/// <summary> /// Parses a map from a CSV. /// </summary> /// <param name="reader">The reader to read from.</param> /// <returns>The map that was read.</returns> public static TagVersionMap ParseTagVersionMap(TextReader reader) { var result = new TagVersionMap(); // Skip the first line, we don't need it if (reader.ReadLine() == null) { return(result); } // Read the timestamp list and resolve each one var timestampLine = reader.ReadLine(); if (timestampLine == null) { return(result); } var timestamps = timestampLine.Split(',').Select(t => { if (long.TryParse(t, NumberStyles.HexNumber, null, out long r)) { return(r); } return(-1); }); var versions = timestamps.Select(t => { return(CacheVersionDetection.DetectFromTimestamp(t, out CacheVersion closest)); }).ToArray(); // Read each line and store the tag indices in the result map while (true) { var line = reader.ReadLine(); if (line == null) { break; } if (string.IsNullOrWhiteSpace(line)) { continue; } // Parse each tag index as a hex number var tags = line.Split(','); var tagIndices = tags.Select(t => { if (int.TryParse(t, NumberStyles.HexNumber, null, out int r)) { return(r); } return(-1); }).ToArray(); // Now connect all of them to the first tag for (var i = 1; i < tagIndices.Length; i++) { if (tagIndices[i] >= 0) { result.Add(versions[0], tagIndices[0], versions[i], tagIndices[i]); } } } return(result); }