Progress on twilight princess hd file table

This commit is contained in:
KillzXGaming 2019-06-11 19:35:02 -04:00
parent 9e132a68d3
commit bd7a173876
8 changed files with 88 additions and 32 deletions

Binary file not shown.

View file

@ -24,20 +24,15 @@ namespace Switch_Toolbox.Library
public Dictionary<string, uint> FileSizes = new Dictionary<string, uint>(); public Dictionary<string, uint> FileSizes = new Dictionary<string, uint>();
public Dictionary<string, DecompressedTableEntry> DecompressedFileSizes = new Dictionary<string, DecompressedTableEntry>(); public Dictionary<string, DecompressedTableEntry> DecompressedFileSizes = new Dictionary<string, DecompressedTableEntry>();
public static void SetTables(IFileFormat FileFormat) public bool IsInFileSizeList(string FileName) => FileSizes.ContainsKey(FileName);
{ public bool IsInDecompressedFileSizeList(string FileName) => DecompressedFileSizes.ContainsKey(FileName);
//Read the tables
TPFileSizeTable CompressedFileTbl = new TPFileSizeTable();
CompressedFileTbl.ReadCompressedTable(new FileReader($"{Runtime.TpGamePath}/FileSizeList.txt"));
TPFileSizeTable DecompressedFileTbl = new TPFileSizeTable(); public void SetFileSizeEntry(string FileName, uint Size) {
DecompressedFileTbl.ReadDecompressedTable(new FileReader($"{Runtime.TpGamePath}/DecompressedSizeList.txt")); FileSizes[FileName] = Size;
}
// var tableSave = new MemoryStream();
// CompressedFileTbl.Write(new FileWriter(tableSave));
// File.WriteAllBytes($"{Runtime.TpGamePath}/FileSizeListTEST.txt", tableSave.ToArray());
// bool IsSuccess = CompressedFileTbl.TrySetSize(FileName, IFileInfo.CompressedSize, IFileInfo.DecompressedSize, ArchiveSizes);
public void SetDecompressedFileSizeEntry(string FileName, uint Size) {
DecompressedFileSizes[FileName].Size = Size;
} }
public void ReadCompressedTable(FileReader reader) public void ReadCompressedTable(FileReader reader)
@ -63,6 +58,8 @@ namespace Switch_Toolbox.Library
entry.Precentage = reader.ReadString(BinaryStringFormat.ZeroTerminated); entry.Precentage = reader.ReadString(BinaryStringFormat.ZeroTerminated);
entry.FilePath = reader.ReadString(BinaryStringFormat.ZeroTerminated); entry.FilePath = reader.ReadString(BinaryStringFormat.ZeroTerminated);
Console.WriteLine($"Size {Size} Size2 {Size2} {entry.Precentage} {entry.FilePath}");
uint sizeNum = 0; uint sizeNum = 0;
uint sizeNum2 = 0; uint sizeNum2 = 0;
@ -76,23 +73,6 @@ namespace Switch_Toolbox.Library
} }
} }
public bool TrySetSize(string Path, uint DecompSize, uint CompSize, Dictionary<string, uint> ArchiveFiles = null)
{
string RelativePath = Path.Replace(Runtime.TpGamePath, string.Empty);
if (FileSizes.ContainsKey(RelativePath))
{
if (UseCompressedSizes)
FileSizes[RelativePath] = CompSize;
else
FileSizes[RelativePath] = DecompSize;
return true;
}
return false;
}
public void WriteCompressedTable(FileWriter writer) public void WriteCompressedTable(FileWriter writer)
{ {
foreach (var file in FileSizes) foreach (var file in FileSizes)

View file

@ -25,6 +25,32 @@ namespace Switch_Toolbox.Library
ReadOnly = true; ReadOnly = true;
} }
public static void WriteLine(object line, int ColorKeyIndex)
{
if (console == null)
return;
if (ColorKeyIndex == 0)
WriteLine(line.ToString(), Color.Red);
else if (ColorKeyIndex == 1)
WriteLine(line.ToString(), Color.Green);
else
WriteLine(line.ToString());
}
public static void WriteLine(string line, int ColorKeyIndex)
{
if (console == null)
return;
if (ColorKeyIndex == 0)
WriteLine(line.ToString(), Color.Red);
else if (ColorKeyIndex == 1)
WriteLine(line.ToString(), Color.Green);
else
WriteLine(line.ToString());
}
public static void WriteLine(object line, Color? color = null) public static void WriteLine(object line, Color? color = null)
{ {
if (console == null) if (console == null)

View file

@ -39,7 +39,7 @@ namespace Switch_Toolbox.Library.IO
FileFormat.IFileInfo.CompressedSize = (uint)FinalData.Length; FileFormat.IFileInfo.CompressedSize = (uint)FinalData.Length;
DetailsLog += "\n" + SatisfyFileTables(FileName, FinalData, DetailsLog += "\n" + SatisfyFileTables(FileFormat, FileName, FinalData,
FileFormat.IFileInfo.DecompressedSize, FileFormat.IFileInfo.DecompressedSize,
FileFormat.IFileInfo.CompressedSize, FileFormat.IFileInfo.CompressedSize,
FileFormat.IFileInfo.FileIsCompressed); FileFormat.IFileInfo.FileIsCompressed);
@ -51,7 +51,7 @@ namespace Switch_Toolbox.Library.IO
Cursor.Current = Cursors.Default; Cursor.Current = Cursors.Default;
} }
private static string SatisfyFileTables(string FilePath, byte[] Data, uint DecompressedSize, uint CompressedSize, bool IsCompressed) private static string SatisfyFileTables(IFileFormat FileFormat, string FilePath, byte[] Data, uint DecompressedSize, uint CompressedSize, bool IsCompressed)
{ {
string FileLog = ""; string FileLog = "";
@ -83,11 +83,17 @@ namespace Switch_Toolbox.Library.IO
//Now apply the file table then save the table //Now apply the file table then save the table
if (BotwResourceTable.IsInTable(newFilePath)) if (BotwResourceTable.IsInTable(newFilePath))
{
FileLog += $"File found in resource table! {newFilePath}"; FileLog += $"File found in resource table! {newFilePath}";
STConsole.WriteLine(FileLog, 1);
}
else else
{
FileLog += $"File NOT found in resource table! {newFilePath}"; FileLog += $"File NOT found in resource table! {newFilePath}";
STConsole.WriteLine(FileLog, 0);
}
STConsole.WriteLine(FileLog);
BotwResourceTable.SetEntry(newFilePath, Data); BotwResourceTable.SetEntry(newFilePath, Data);
BotwResourceTable.Write(new FileWriter(RstbPath)); BotwResourceTable.Write(new FileWriter(RstbPath));
@ -96,7 +102,51 @@ namespace Switch_Toolbox.Library.IO
if (Runtime.ResourceTables.TpTable && IsTPHDFile) if (Runtime.ResourceTables.TpTable && IsTPHDFile)
{ {
string newFilePath = FilePath.Replace(Runtime.BotwGamePath, string.Empty).Remove(0, 1);
newFilePath = newFilePath.Replace(".s", ".");
newFilePath = newFilePath.Replace(@"\", "/");
//Read the tables and set the new sizes if paths match
TPFileSizeTable CompressedFileTbl = new TPFileSizeTable();
CompressedFileTbl.ReadCompressedTable(new FileReader($"{Runtime.TpGamePath}/FileSizeList.txt"));
if (CompressedFileTbl.IsInFileSizeList(newFilePath))
{
STConsole.WriteLine("Found matching path in File Size List table! " + newFilePath, 1);
CompressedFileTbl.SetFileSizeEntry(newFilePath, CompressedSize);
}
else
STConsole.WriteLine("Failed to find path in File Size List table! " + newFilePath, 0);
TPFileSizeTable DecompressedFileTbl = new TPFileSizeTable();
DecompressedFileTbl.ReadDecompressedTable(new FileReader($"{Runtime.TpGamePath}/DecompressedSizeList.txt"));
bool IsArchive = false;
foreach (var inter in FileFormat.GetType().GetInterfaces())
if (inter.IsGenericType && inter.GetGenericTypeDefinition() == typeof(IArchiveFile))
IsArchive = true;
if (IsArchive)
{
IArchiveFile Archive = (IArchiveFile)FileFormat;
foreach (var file in Archive.Files)
{
uint DecompressedFileSize = (uint)file.FileData.Length;
string ArchiveFilePath = $"/DVDRoot/{file.FileName}";
DecompressedFileTbl.ReadCompressedTable(new FileReader($"{Runtime.TpGamePath}/FileSizeList.txt"));
if (DecompressedFileTbl.IsInDecompressedFileSizeList(newFilePath))
{
STConsole.WriteLine("Found matching path in File Size List table! " + newFilePath, 1);
DecompressedFileTbl.SetDecompressedFileSizeEntry(newFilePath, DecompressedFileSize);
}
else
STConsole.WriteLine("Failed to find path in File Size List table! " + newFilePath, 0);
}
}
DecompressedFileTbl.WriteCompressedTable(new FileWriter($"{Runtime.TpGamePath}/FileSizeListTEST.txt"));
DecompressedFileTbl.WriteDecompressedTable(new FileWriter($"{Runtime.TpGamePath}/DecompressedSizeListTEST.txt"));
} }
return FileLog; return FileLog;