XIV Dev Wiki
Search…
SqPack
Everything SqPack: indexes, dat files
SqPack(s) are formed from the following concepts, in which order 'matters':
    1.
    2.
    3.
    4.
    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:
1
sqpack/
2
ex1/
3
ex2/
4
ex3/
5
ffxiv/
Copied!
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
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:
ID
Name
Notes
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
Contains Excel List, Header and Data files
B
game_script
Contains compiled LUA 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:
C++
C#
1
enum PlatformId : uint8_t
2
{
3
Win32,
4
PS3,
5
PS4
6
};
7
8
// https://github.com/SapphireServer/Sapphire/blob/develop/deps/datReader/SqPack.cpp#L5
9
struct SqPackHeader
10
{
11
char magic[0x8];
12
PlatformId platformId;
13
uint8_t padding0[3];
14
uint32_t size;
15
uint32_t version;
16
uint32_t type;
17
};
Copied!
1
public enum PlatformId : byte
2
{
3
Win32,
4
PS3,
5
PS4
6
}
7
8
// https://github.com/NotAdam/Lumina/blob/master/Lumina/Data/Structs/SqPackHeader.cs
9
[StructLayout( LayoutKind.Sequential )]
10
public unsafe struct SqPackHeader
11
{
12
public fixed byte magic[8];
13
public PlatformId platformId;
14
public fixed byte __unknown[3];
15
public UInt32 size;
16
public UInt32 version;
17
public UInt32 type;
18
}
Copied!
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):
C++
C#
1
struct SqPackIndexHeader
2
{
3
uint32_t size;
4
uint32_t type;
5
uint32_t indexDataOffset;
6
uint32_t indexDataSize;
7
};
Copied!
1
[StructLayout( LayoutKind.Sequential )]
2
public unsafe struct SqPackIndexHeader
3
{
4
public UInt32 size;
5
public UInt32 version;
6
public UInt32 indexDataOffset;
7
public UInt32 indexDataSize;
8
}
Copied!
The actual SqPackIndexHeader is 0x400bytes 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

C++
C#
1
struct IndexHashTableEntry
2
{
3
uint64_t hash;
4
uint32_t unknown : 1;
5
uint32_t dataFileId : 3;
6
uint32_t offset : 28;
7
uint32_t _padding;
8
};
Copied!
1
[StructLayout( LayoutKind.Sequential )]
2
public struct IndexHashTableEntry
3
{
4
public UInt64 hash;
5
public UInt32 data;
6
private UInt32 _padding;
7
8
public byte DataFileId => (byte) ( ( data & 0b1110 ) >> 1 );
9
10
public uint Offset => (uint) ( data & ~0xF ) * 0x08;
11
}
Copied!
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:
    1.
    Convert the path to lowercase
    2.
    Find the last instance of / and split the string with the last / existing in the first group. The filename needs to have no directory separators
    3.
    Calculate the CRC32 of both path segments
    4.
    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.
C++
C#
1
struct Index2HashTableEntry
2
{
3
uint32_t hash;
4
uint32_t unknown : 1;
5
uint32_t dataFileId : 3;
6
uint32_t offset : 28;
7
};
Copied!
1
[StructLayout( LayoutKind.Sequential )]
2
public struct Index2HashTableEntry
3
{
4
public UInt32 hash;
5
public UInt32 data;
6
7
public byte DataFileId => (byte) ( ( data & 0b1110 ) >> 1 );
8
9
public uint Offset => (uint) ( data & ~0xF ) * 0x08;
10
}
Copied!
Last modified 1yr ago