Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
/ SarcLibrary Public archive

Nintendo SEAD Archive Library | Based on oead/sarc by Léo Lam

License

Notifications You must be signed in to change notification settings

NCF-Library/SarcLibrary

Repository files navigation

SarcLibrary

Nintendo SEAD Archive Library | Based on oead/sarc by Léo Lam

SarcLibrary has been tested to parse and re-write (almost) every SARC file found in Breath of the Wild byte-perfectly.

Usage

Reading a Sarc File

// Read from File Path
SarcFile sarc = SarcFile.FromBinary("content/Pack/Bootup.pack");
// Read from a byte[]
// Do not use with File.ReadAllBytes(), use
// a Stream instead.
SarcFile sarc = SarcFile.FromBinary("content/Pack/Bootup.pack");
byte[] decompressedData = Yaz0.Decompress(sarc["GameData/gamedata.ssarc"]);
SarcFile nestedSarc = SarcFile.FromBinary(decompressedData);
// Read from a Stream
using FileStream fs = File.OpenRead("content/Pack/Bootup.pack");
SarcFile sarc = new(fs);

Writing a Sarc File

// Write to a File
sarc.ToBinary("content/Pack/Bootup.pack");
// Write to a byte[]
byte[] data = sarc.ToBinary();
// Write to a Stream
using MemoryStream ms = new();
sarc.ToBinary(ms);

Sarc Tools

// Extract to a Directory
await sarc.ExtractTodirectory("path/to/output");
// Load from a Directory
SarcFile sarc = SarcFile.LoadFromDirectory("path/to/input", searchPattern: "*.*", searchOption: SearchOption.AllDirectories)

Benchmarks

Function Elapsed Allocated
Read TitleBG (75MB, BigEndian) 29.16 ms 75,307 KB
Read TitleBG (143MB. LittleEndian) 51.02 ms 143,854 KB
Write TitleBG (75MB, BigEndian) 40.90 ms 110 KB
Write TitleBG (143MB, LittleEndian) 127.49 ms 110 KB
Extract TitleBG (75MB, BigEndian) 133.18 ms 732 KB
Extract TitleBG (143MB, LittleEndian) 170.64 ms 726 KB
Load from Folder (409 Files, ~73MB) 40.61 ms 73,365 KB
Load from Folder (409 Files, ~140MB) 68.11 ms 143,910 KB

Benchmarks run on an AMD Ryzen 7 3700X CPU, 64GB (4 x 16GB) of VENGEANCE® DDR4 DRAM 3200MHz C16 memory, and a Kingston KC3000 PCIe 4.0 NVMe M.2 SSD

Byte-Perfect Exceptions

Exceptions to every file being parsed and re-written byte-perfectly are a the sbeventpack archives in content/Event, which seems to use a mix of alignments. During tests, I found offsets of 0x100 and 0x8 that had varying reliability.
These odd occurrences are also ignored in oead/sarc. Luckily, the game does not seem to care if these files are aligned to 4-bytes, so the error is not detrimental (at least not in BOTW).

Install

NuGet NuGet

NuGet

Install-Package SarcLibrary

Build From Source

git clone https://github.com/NCF-Library/SarcLibrary.git
dotnet build SarcLibrary

Credit

About

Nintendo SEAD Archive Library | Based on oead/sarc by Léo Lam

Topics

Resources

License

Stars

Watchers

Forks

Languages