SqPack
Everything SqPack: indexes, dat files
SqPack(s) are formed from the following concepts, in which order 'matters':
Data Files
Repositories
Repositories are essentially a collection of categories and there's not much to know here. As of writing, there's 4, one for the base game (ffxiv
) and one for each expansion (ex1
, ex2
, etc.). Consider the following directory structure:
Each folder inside sqpack/
is it's own repository. As an aside, when the game tries to access files, it distinguishes which repository to find a file in by parsing the file path and pulling out 2 segments, the repository name and the category.
For example:
Path | Repository | Category |
---|---|---|
|
|
|
|
|
|
|
|
|
The first two paths explicitly define their repository in their file path, and it's always the second segment - if it's omitted it defaults to the ffxiv
repository. Category is always the first segment and must be present for a path to resolve.
Categories
Categories are just logical separations of game data. The following categories exist:
ID | Name | Notes |
---|---|---|
|
| Contains basic data like fonts, vulgar words dictionary, shader input textures |
|
| Contains textures, models, environments and collision that are shared between territories |
|
| Contains layouts, definitions, collision, models and textures for specific territories |
|
| Contains cutscene animations and definitions |
|
| Contains models, textures and definition files for all humans/demihumans/monsters |
|
| Contains compiled shaders |
|
| Contains UI layouts and textures |
|
| Contains sound effects |
|
| Contains textures and VFX definition files(AVFX) |
|
| No index/dat in retail client, likely leftover from silverlight |
|
| |
|
| Contains compiled Lua scripts (5.1) for quests, cutscenes and battles |
|
| Contains BGM |
|
| Category missing in retail client/no files. |
|
| Category missing in retail client/no files. |
Every game path will start with one of the above names and it defines which index to search to find a file.
SqPack Files
Indexes and regular data files are effectively SqPack files and subsequently have a common header, SqPackHeader
. It looks like the following:
Indexes (and data) starts at size
so you want to seek to the value of size
before you read anything out of the file.
Reading Index Data
The index data is located directly after the header and depends on which variant of index file you load. The retail client ships with both variants of index files, which we'll mostly refer to as index
and index2
to make the difference obvious. Contrary to the retail client shipping with both index variants, benchmarks only ship with index2
files. The reason is unknown.
Immediately following the SqPackHeader
there's a SqPackIndexHeader
(which is only present in index files):
The actual SqPackIndexHeader
is 0x400
bytes large, but for the purposes of this, we're only interested in the first 16 bytes. From the indexDataOffset
and indexDataSize
, you can determine where to start reading from and how many index elements exist inside an index. indexDataOffset
is an absolute offset to where the index data is located, and indexDataSize
is the collective size of every IndexHashTableEntry
that's in a file. This entry is slightly different in the case of index2
files, so we'll generally cover the two with a focus on index1
files for now.
Reading Index
There's a couple notable differences between the C++ and C# version, so we'll just explain the C++ version and the latter will make sense too.
The hash is a u64 that contains two u32s: the lower bits are the filename CRC32, the higher bits are the folder CRC32.
Generally speaking, calculating a hash
works like this:
Convert the path to lowercase
Find the last instance of
/
and split the string with the last/
existing in the first group. The filename needs to have no directory separatorsCalculate the CRC32 of both path segments
Join both CRC32s into a u64, eg.
directoryHash << 32 | filenameHash
The dataFileId
is to identify which file (on disk) contains the file. Larger categories are split across multiple files (each is capped at 2,000,000,000 bytes, or 2 GB), so this is used to distinguish between 020000.win32.dat0
and 020000.win32.dat1
for example, where dataFileId
would be 0
and 1
respectively for files located in either dat.
The offset
is the absolute number of 8 byte aligned segments that the file is located at within a specific dat file. In a given dat file, a file is located at offset * 0x8
which gives you the absolute offset to start reading a file from.
Reading Index2
The main difference between index
and index2
is that the entire path is encoded into one CRC32 hash and does not split the path by folder and filename. Outside of that, everything is identical to index
.
Last updated