Skip to content

Commit

Permalink
add bres Wii Resource Archive Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Venomalia committed Jul 12, 2022
1 parent 53d9afb commit 0568b38
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 4 deletions.
5 changes: 4 additions & 1 deletion TextureExtraction tool/Data/TextureExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private void Scan(Stream stream, string subdirectory, in string Extension = "")
try
{
#endif
switch (filetype.Typ)
switch (filetype.Typ)
{
case FileTyp.Unknown:
if (options.Force)
Expand Down Expand Up @@ -328,6 +328,9 @@ private void Scan(Stream stream, string subdirectory, in string Extension = "")
}
result.ExtractedSize += stream.Length;
break;
case "bres":
Scan(new bres(stream), subdirectory);
break;
case "U8-":
Scan(new U8(stream), subdirectory);
break;
Expand Down
2 changes: 1 addition & 1 deletion TextureExtraction tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ static void PrintHeader()
#else
Console.WriteLine($"{System.Diagnostics.Process.GetCurrentProcess().ProcessName} v{System.Reflection.Assembly.GetExecutingAssembly().GetName().Version}\t\t{DateTime.Now.ToString()}");
#endif
Console.WriteLine($"Supported formats: RARC, U8, CPK, BDL4, BMD3, TPL, BTI, NUTC, TXE, {string.Join(", ", Compression.GetAvailablDecompress().Select(x => x.Name))}.");
Console.WriteLine($"Supported formats: RARC, U8, CPK, BDL4, BMD3, TPL, BTI, NUTC, TXE, bres, {string.Join(", ", Compression.GetAvailablDecompress().Select(x => x.Name))}.");
ConsoleEx.WriteLineColoured("".PadLeft(96, '-'), ConsoleColor.Blue);
ConsoleEx.WriteColoured("INFO:", ConsoleColor.Red);
Console.WriteLine(" currently no ROM images are supported, Please unpack them with dolphin into a folder.");
Expand Down
4 changes: 2 additions & 2 deletions TextureExtraction tool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.6.1.0")]
[assembly: AssemblyFileVersion("0.6.0.1")]
[assembly: AssemblyVersion("0.6.2.0")]
[assembly: AssemblyFileVersion("0.6.2.0")]
114 changes: 114 additions & 0 deletions lib/AuroraLip/Archives/Formats/bres.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using AuroraLip.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//https://wiki.tockdom.com/wiki/BRRES_(File_Format)
namespace AuroraLip.Archives.Formats
{
public class bres : Archive, IMagicIdentify
{
public string Magic => magic;

private const string magic = "bres";

#region Fields and Properties

public ushort ByteOrder { get; set; }

#endregion


public bres()
{
}

public bres(Stream File, string filename = null)
{
Read(File);
FileName = filename;
}

protected override void Read(Stream stream)
{
if (!stream.MatchString(magic))
throw new Exception($"Invalid Identifier. Expected \"{Magic}\"");
ByteOrder = BitConverter.ToUInt16(stream.Read(2), 0); //65534 BigEndian
if (ByteOrder != 65534)
{
throw new Exception($"ByteOrder: \"{ByteOrder}\" Not Implemented");
}
ushort Padding = BitConverter.ToUInt16(stream.ReadBigEndian(2), 0);
uint TotalSize = BitConverter.ToUInt32(stream.ReadBigEndian(4), 0);
ushort Offset = BitConverter.ToUInt16(stream.ReadBigEndian(2), 0);
ushort sections = BitConverter.ToUInt16(stream.ReadBigEndian(2), 0);
stream.Position = 0x10;
//root sections
if (!stream.MatchString("root"))
throw new Exception($"Invalid Identifier. Expected \"root\"");
uint RootSize = BitConverter.ToUInt32(stream.ReadBigEndian(4), 0);
Root = new ArchiveDirectory() { Name = "root", OwnerArchive = this};
ReadIndex(stream, (int)(stream.Position + RootSize-8), Root);
//Index Group

}

private void ReadIndex(Stream stream,in int EndOfRoot, ArchiveDirectory ParentDirectory)
{
//Index Group
long StartOfGroup = stream.Position;
uint GroupSize = BitConverter.ToUInt32(stream.ReadBigEndian(4), 0);
uint Groups = BitConverter.ToUInt32(stream.ReadBigEndian(4), 0);

for (int i = 0; i < Groups +1; i++)
{
ushort GroupID = BitConverter.ToUInt16(stream.ReadBigEndian(2), 0);
ushort Unknown = BitConverter.ToUInt16(stream.ReadBigEndian(2), 0);
ushort LeftIndex = BitConverter.ToUInt16(stream.ReadBigEndian(2), 0);
ushort RightIndex = BitConverter.ToUInt16(stream.ReadBigEndian(2), 0);
uint NamePointer = BitConverter.ToUInt32(stream.ReadBigEndian(4), 0);
uint DataPointer = BitConverter.ToUInt32(stream.ReadBigEndian(4), 0);
long EndOfGroup = stream.Position;
string Name = String.Empty;
if (NamePointer != 0)
{
stream.Position = StartOfGroup + NamePointer;
Name = stream.ReadString(x => x != 0);

if (DataPointer != 0)
{
if (StartOfGroup + DataPointer >= EndOfRoot)
{
ArchiveFile Sub = new ArchiveFile() { Name = Name, Parent = ParentDirectory };
stream.Position = StartOfGroup + DataPointer;
string Magic = stream.ReadString(4);
uint FileSize = BitConverter.ToUInt32(stream.ReadBigEndian(4), 0);
stream.Position -= 8;
if (Magic != "RASD" && FileSize <= stream.Length - stream.Position)
{
Sub.FileData = stream.Read((int)FileSize);
ParentDirectory.Items.Add(Sub.Name, Sub);
}
}
else
{
stream.Position = StartOfGroup + DataPointer;
ArchiveDirectory Sub = new ArchiveDirectory(this, ParentDirectory) { Name = Name };
ReadIndex(stream, EndOfRoot, Sub);
ParentDirectory.Items.Add(Sub.Name, Sub);
}
}
}
stream.Position = EndOfGroup;
}
}

protected override void Write(Stream ArchiveFile)
{
throw new NotImplementedException();
}
}
}
1 change: 1 addition & 0 deletions lib/AuroraLip/AuroraLip.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<Compile Include="Archives\ArchiveBase.cs" />
<Compile Include="Archives\ArchiveDirectory.cs" />
<Compile Include="Archives\ArchiveFile.cs" />
<Compile Include="Archives\Formats\bres.cs" />
<Compile Include="Archives\Formats\RARC.cs" />
<Compile Include="Archives\Formats\U8.cs" />
<Compile Include="Common\Extensions\BitConverterEx.cs" />
Expand Down

0 comments on commit 0568b38

Please sign in to comment.