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:
bg/ex3/01_nvt_n4/twn/n4t1/bgparts/n4t1_a1_chr03.mdl
ex3
bg
music/ex2/bgm_ex2_system_title.scd
ex2
music
chara/weapon/w0501/obj/body/b0018/vfx/texture/uv_cryst_128s.atex
ffxiv
chara
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:
0
common
Contains basic data like fonts, vulgar words dictionary, shader input textures
1
bgcommon
Contains textures, models, environments and collision that are shared between territories
2
bg
Contains layouts, definitions, collision, models and textures for specific territories
3
cut
Contains cutscene animations and definitions
4
chara
Contains models, textures and definition files for all humans/demihumans/monsters
5
shader
Contains compiled shaders
6
ui
Contains UI layouts and textures
7
sound
Contains sound effects
8
vfx
Contains textures and VFX definition files(AVFX)
9
ui_script
No index/dat in retail client, likely leftover from silverlight
A
exd
B
game_script
Contains compiled Lua scripts (5.1) for quests, cutscenes and battles
C
music
Contains BGM
12
sqpack_test
Category missing in retail client/no files.
13
debug
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