private void DumpSyncPairPreviewVideo(string outRoot) { var pbPath = Path.Combine(outRoot, @"db\master\pb\ScoutPickup.pb"); if (!File.Exists(pbPath)) { pbPath = Path.Combine(outRoot, @"db\master\pb\LotteryPickup.pb"); // different name in v1.0.0 } if (!File.Exists(pbPath)) { Console.WriteLine($"Failed to find ScoutPickup.pb or LotteryPickup.pb: skip Sync Pair Preview videos"); return; } var table = ScoutPickupTable.Parser.ParseFrom(File.ReadAllBytes(pbPath)); foreach (var message in table.Entries) { var path = $"Movie/Scout/Pickup/{message.ScoutId}/{message.ScoutPickupId}.mp4"; var fileIDString = $"{XXH64.DigestOf(Encoding.ASCII.GetBytes(path))}"; var resourcePath = Path.Combine(DownloadPath, $"{fileIDString[0]}", fileIDString); if (!File.Exists(resourcePath)) { Console.WriteLine($"Failed to find {path} ({resourcePath})"); continue; } var outPath = $"{Path.Combine(outRoot, path.Replace("/", $"{Path.DirectorySeparatorChar}"))}"; Directory.CreateDirectory(Path.GetDirectoryName(outPath)); System.IO.File.Copy(resourcePath, outPath, true); } }
public void SingleBlockXxh64UsingSpanMatchesTheirs(string text) { var input = Encoding.UTF8.GetBytes(text); var expected = Theirs64(input); var actual = XXH64.DigestOf(input.AsSpan()); Assert.Equal(expected, actual); }
public void DumpMiscVideo(string outRoot) { var jsonPath = Path.Combine(outRoot, @"db\asset\bundles_archives.json"); if (!File.Exists(jsonPath)) { return; } var unkNameVideos = new Dictionary <string, string>(); var json = JObject.Parse(File.ReadAllText(jsonPath)); foreach (var archive in json["archives"]) { var archiveName = archive["name"].ToString(); if (!archiveName.StartsWith("archive_Movie_")) { continue; } foreach (var p in archive["include"]) { var path = p.ToString(); if (path.EndsWith(".mp4")) { var fileIDString = $"{XXH64.DigestOf(Encoding.ASCII.GetBytes(path))}"; var resourcePath = Path.Combine(DownloadPath, $"{fileIDString[0]}", fileIDString); if (!File.Exists(resourcePath)) { Console.WriteLine($"Failed to find {path} ({resourcePath})"); continue; } var outPath = $"{Path.Combine(outRoot, path.Replace("/", $"{Path.DirectorySeparatorChar}"))}"; Directory.CreateDirectory(Path.GetDirectoryName(outPath)); System.IO.File.Copy(resourcePath, outPath, true); } else if (!path.StartsWith("Movie/Scout/Pickup/")) { var archiveNameHashString = $"{XXH64.DigestOf(Encoding.ASCII.GetBytes(archiveName))}"; if (unkNameVideos.ContainsKey(archiveNameHashString)) { Console.WriteLine($"Multiple paths given for {archiveName}: fallback to {path}"); } unkNameVideos[archiveNameHashString] = path; } } } DumpVideoWithUnknownName(outRoot, unkNameVideos); }
public void DumpSound(string outRoot) { foreach (var audioType in new[] { "BGM", "SE", "Voice_en", "Voice_ja" }) { var jsonPath = Path.Combine(outRoot, "sound", $"{audioType}.json"); if (!File.Exists(jsonPath)) { continue; } var audioJson = JObject.Parse(File.ReadAllText(jsonPath)); foreach (var audioBank in audioJson["audioBanks"]) { foreach (var audioResource in audioBank["audioResources"]) { var name = audioResource["name"].ToString(); var format = audioResource["format"].ToString(); if (format != "ogg") { throw new ArgumentException($"Unknown format for {name}: {format}"); } var fileID = XXH64.DigestOf(Encoding.ASCII.GetBytes($"{name}.{format}")); var folder = fileID; while (folder >= 10) { folder /= 10; } var resourcePath = Path.Combine(DownloadPath, $"{folder}", $"{fileID}"); if (!File.Exists(resourcePath)) { if (!name.StartsWith("sound/Bundle")) { Console.WriteLine($"Failed to find {name} ({resourcePath})"); } continue; } var sf = new SoundFile(File.ReadAllBytes(resourcePath)); var outPath = $"{Path.Combine(outRoot, name.Replace("/", $"{Path.DirectorySeparatorChar}"))}.{format}"; Directory.CreateDirectory(Path.GetDirectoryName(outPath)); File.WriteAllBytes(outPath, sf.Data); } } } }
public void HashMatchesPregeneratedHashesForSmallBlocks(int length, ulong expected) { var bytes = new byte[length]; for (var i = 0; i < bytes.Length; i++) { bytes[i] = (byte)i; } var actual = XXH64.DigestOf(bytes, 0, bytes.Length); var confirm = Theirs64(bytes); Assert.Equal(expected, confirm); Assert.Equal(expected, actual); }
public void CalculatingHashInChunksReturnsSameResultAsInOneGo(int length, int chuck) { var bytes = new byte[length]; var random = new Random(0); random.NextBytes(bytes); var transform = new XXH64(); var i = 0; while (i < length) { var l = Math.Min(chuck, length - i); transform.Update(bytes, i, l); i += l; } Assert.Equal(XXH64.DigestOf(bytes, 0, bytes.Length), transform.Digest()); }
public unsafe void EmptyHash() { var input = Array.Empty <byte>(); var expected = Theirs64(input); var actual1 = XXH64.DigestOf(input, 0, input.Length); Assert.Equal(expected, actual1); fixed(byte *inputP = input) { var actual2 = XXH64.DigestOf(inputP, 0); Assert.Equal(expected, actual2); } var actual3 = XXH64.EmptyHash; Assert.Equal(expected, actual3); }