SARC: Difference between revisions

1,306 bytes added ,  3 years ago
m
imported>Leoetlino
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
'''SARC'''s are archives that are used in many recent Nintendo games such as ''Breath of the Wild''.
<onlyinclude>'''SARC'''s are archive files.</onlyinclude>


== Structure ==
== Structure ==
The basic structure of SARC files is documented on the [[mk8:SARC (File Format)|MK8 wiki]].
The basic structure of SARC files is documented on the [[mk8:SARC (File Format)|MK8 wiki]].
=== Hash algorithm ===
Nintendo's algorithm uses an unsigned 32-bit integer for the hash variable. Also note that Nintendo iterates over each byte, not each string character.
Here is an accurate implementation of the algorithm, written in C++:
<source lang="c++">
// key is equal to 0x65
u32 calcHash32(const sead::SafeString& str, u32 key)
{
    const char* str_ = str.cstr();
    u32 result = 0;
    // Each character must be treated as a signed value.
    // The cast to s8 (not s32) is necessary to avoid unsigned conversions.
    for (s32 i = 0; str_[i] != '\0'; i++)
        result = result * key + s8(str_[i]);
    return result;
}
</source>
Note that in older versions of sead, characters were not explicitly casted to <code>s8</code> so the end result would depend on the signedness of <code>char</code> (which is implementation-defined). For GHS compiled code on the Wii U, <code>char</code> is unsigned whereas it's signed with Clang (AArch64 target). PC tools most likely use a signed <code>char</code> as that is the default signedness for x86 targets.
In newer versions of sead, an explicit cast to <code>signed char</code>, aka <code>std::int8_t</code>, aka <code>s8</code>, was added to ensure hashes are the same regardless of the target platform. Without the cast, non-ASCII characters (e.g. Japanese UTF-8 bytes) would result in hashes being different across platforms.


== Usage in ''Breath of the Wild'' ==
== Usage in ''Breath of the Wild'' ==
Line 11: Line 36:


The following extensions are specific to the game:
The following extensions are specific to the game:
* pack
* [[pack]]
* bactorpack
* [[bactorpack]]
* bmodelsh
* bmodelsh
* beventpack
* [[beventpack]]
* stera
* stera
* stats
* stats
Line 34: Line 59:
Because of the alignment problem and file size limitations due to ''Breath of the Wild'''s [[Resource system|resource system]], only the following tools are recommended:
Because of the alignment problem and file size limitations due to ''Breath of the Wild'''s [[Resource system|resource system]], only the following tools are recommended:


* [https://github.com/aboood40091/SARC-Tool SARC Tool] (for Wii U and Switch)
{{tool table|category=Tools (SARC)|notcategory=Unrecommended tools}}
* [https://github.com/Shadsterwolf/BotWUnpacker BotW Unpacker] (for Wii U)
 
* [https://github.com/leoetlino/sarc <code>sarc</code>] (for Wii U and Switch)  [[Category:File formats]] 
'''We strongly advise against using other tools because they do not handle file alignment properly.'''
 
[[Category:File formats]]