From 098c8fb8425360935addf53330f55c5278a07119 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Fri, 18 Oct 2019 18:59:04 -0400 Subject: [PATCH] Auto calculate hashed texture names for layouts in sarcs --- .../FileFormats/Archives/SARC.cs | 17 +++++++++++++++++ .../FileFormats/Layout/CAFE/BFLYT.cs | 14 +++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/File_Format_Library/FileFormats/Archives/SARC.cs b/File_Format_Library/FileFormats/Archives/SARC.cs index 84aa86ed..35f3afa4 100644 --- a/File_Format_Library/FileFormats/Archives/SARC.cs +++ b/File_Format_Library/FileFormats/Archives/SARC.cs @@ -293,6 +293,23 @@ namespace FirstPlugin } } + public string TryGetHash(List names, string folder) + { + //Name is not hashed so return + if (!FileName.Contains(HashName)) + return FileName; + + for (int i = 0; i < names?.Count; i++) + { + uint hash = StringHashToUint(hashName); + Console.WriteLine($"{FileName} {hash} {names[i]} {NameHash(names[i])}"); + if (hash == NameHash($"{folder}/{names[i]}")) + return names[i]; + } + + return FileName; + } + public bool IsHashMatch(string fileName) { uint hash = StringHashToUint(hashName); diff --git a/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs b/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs index 336c029c..98e36deb 100644 --- a/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs +++ b/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs @@ -256,9 +256,21 @@ namespace LayoutBXLYT.Cafe if (Utils.GetExtension(file.FileName) == ".bflim") { BFLIM bflim = (BFLIM)file.OpenFile(); + string name = bflim.FileName; + if (archive is SARC) + { + if (((SARC)archive).sarcData.HashOnly) + { + var sarcEntry = file as SARC.SarcEntry; + + //Look through all textures and find a hash match + name = sarcEntry.TryGetHash(header.Textures, "timg"); + } + } + file.FileFormat = bflim; if (!textures.ContainsKey(bflim.FileName)) - textures.Add(bflim.FileName, bflim); + textures.Add(name, bflim); } } catch (Exception ex)