Archived
1
Fork 0
This repository has been archived on 2025-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
libxiv/include/indexparser.h
Joshua Goins b11767dc02 Big refactoring commit pt. 1
This is the first of many commits to improve code quality, and try to
tame my bad looking code.

Types such as Slot and Race are now living under types/ and have
dedicated functions to go between ids and enumerations without a heavy
std::map.

A new repository API lives in a new SqPack header, which replaces the
old crusty way of fetching repository information in GameData.

Building equipment paths now live in libxiv (moved from novus) provided
you have a model id. Standard methods to build index and dat filenames
are provided in their functions now too.
2022-04-17 16:55:41 -04:00

74 lines
No EOL
1.5 KiB
C++

#pragma once
#include <cstdint>
#include <vector>
#include <string_view>
// these are methods dedicated to reading ".index" and ".index2" files
// major thanks to xiv.dev for providing the struct definitions
enum PlatformId : uint8_t
{
Win32,
PS3,
PS4
};
// https://github.com/SapphireServer/Sapphire/blob/develop/deps/datReader/SqPack.cpp#L5
struct SqPackHeader
{
char magic[0x8];
PlatformId platformId;
uint8_t padding0[3];
uint32_t size;
uint32_t version;
uint32_t type;
};
struct SqPackIndexHeader
{
uint32_t size;
uint32_t type;
uint32_t indexDataOffset;
uint32_t indexDataSize;
};
struct IndexHashTableEntry
{
uint64_t hash;
uint32_t unknown : 1;
uint32_t dataFileId : 3;
uint32_t offset : 28;
uint32_t _padding;
};
struct Index2HashTableEntry
{
uint32_t hash;
uint32_t unknown : 1;
uint32_t dataFileId : 3;
uint32_t offset : 28;
};
template<class Entry>
struct IndexFile {
SqPackHeader packHeader;
SqPackIndexHeader indexHeader;
std::vector<Entry> entries;
};
struct IndexEntry {
uint64_t hash = 0;
uint32_t dataFileId = 0;
uint32_t offset = 0;
};
struct CombinedIndexFile {
std::vector<IndexEntry> entries;
};
IndexFile<IndexHashTableEntry> readIndexFile(std::string_view path);
IndexFile<Index2HashTableEntry> readIndex2File(std::string_view path);
CombinedIndexFile read_index_files(std::string_view index_filename, std::string_view index2_filename);