SARC: Difference between revisions
imported>Leoetlino |
imported>Leoetlino m (→Hash algorithm) |
||
Line 10: | Line 10: | ||
<source lang="c++"> | <source lang="c++"> | ||
const uint32_t multiplier = 0x65; | |||
const char* string = "月クッパ戦Lv3(クリア後).baglshpp"; | |||
uint32_t hash = 0; | |||
int i = 0; | |||
while (true) { | |||
char c = string[i++]; // *signed* char | |||
if (!c) | |||
break; | |||
hash = hash * multiplier + c; | |||
} | |||
</source> | </source> | ||
Revision as of 21:26, 20 November 2018
SARCs are archive files.
Structure
The basic structure of SARC files is documented on the MK8 wiki.
Hash algorithm
The algorithm given on the MK8 wiki is not fully correct: it fails to account for the fact that Nintendo's algorithm uses an unsigned 32-bit integer for the hash variable, and a signed char variable.
Here is more accurate implementation of the algorithm, written in C++:
const uint32_t multiplier = 0x65;
const char* string = "月クッパ戦Lv3(クリア後).baglshpp";
uint32_t hash = 0;
int i = 0;
while (true) {
char c = string[i++]; // *signed* char
if (!c)
break;
hash = hash * multiplier + c;
}
It appears that Nintendo's compiler treats a char as a signed type.
Usage in Breath of the Wild
SARCs are used extensively in Breath of the Wild to keep related data in memory and minimise loading times.
Extensions
Archives have a wide range of extensions. However, the file format is completely the same regardless of the extension.
The following extensions are specific to the game:
- pack
- bactorpack
- bmodelsh
- beventpack
- stera
- stats
The following extensions are used by Nintendo libraries that are included in the game (non exhaustive list):
- sarc
- bgenv
- genvb
- blarc
Data alignment
Some files have specific alignment requirements (e.g. for GPU data). Because Nintendo's SARC library returns file data by giving pointers to the data section directly, special care must be taken to pack files in a way that satisfies all alignment requirements.
Nintendo libraries do not use BotW's resource system and expect files to be properly aligned. This is the case for layout archives (blarc) and agl environment files (Pack/Bootup.pack/Env/env.genvb).
However unlike most other Nintendo games, for files that are managed by the game's resource system, aligning archive file data is usually unnecessary because the system will automatically allocate an aligned buffer and copy the archive data into it.
Tools
Because of the alignment problem and file size limitations due to Breath of the Wild's resource system, only the following tools are recommended:
Tool | Cross-platform | Setup | Known issues |
---|---|---|---|
SARC Tool | Yes |
|
|
sarc | Yes |
Install the |
None |
BotW Unpacker | Yes |
Download the latest release from GitHub. |
|
Wild Bits | Yes |
|
On some system configurations, launching with |
Switch Toolbox | No |
|
We strongly advise against using other tools because they do not handle file alignment properly.