mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-21 12:17:45 +00:00
Add index file parser
This commit is contained in:
parent
072421d935
commit
b4587ea71b
3 changed files with 131 additions and 1 deletions
|
@ -36,7 +36,9 @@ set(SRC
|
||||||
src/fiinparser.cpp
|
src/fiinparser.cpp
|
||||||
include/fiinparser.h
|
include/fiinparser.h
|
||||||
include/headline.h
|
include/headline.h
|
||||||
src/headline.cpp)
|
src/headline.cpp
|
||||||
|
include/indexparser.h
|
||||||
|
src/indexparser.cpp)
|
||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
|
|
62
include/indexparser.h
Normal file
62
include/indexparser.h
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#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;
|
||||||
|
};
|
||||||
|
|
||||||
|
IndexFile<IndexHashTableEntry> readIndexFile(const std::string_view path);
|
||||||
|
IndexFile<Index2HashTableEntry> readIndex2File(const std::string_view path);
|
66
src/indexparser.cpp
Normal file
66
src/indexparser.cpp
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
#include "indexparser.h"
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void commonParseSqPack(FILE* file, IndexFile<T> index) {
|
||||||
|
fread(&index.packHeader, sizeof index.packHeader, 1, file);
|
||||||
|
|
||||||
|
// data starts at size
|
||||||
|
fseek(file, index.packHeader.size, SEEK_SET);
|
||||||
|
|
||||||
|
// read index header
|
||||||
|
fread(&index.indexHeader, sizeof index.indexHeader, 1, file);
|
||||||
|
|
||||||
|
// version should be 1?
|
||||||
|
qInfo() << index.packHeader.version;
|
||||||
|
|
||||||
|
fseek(file, index.indexHeader.indexDataOffset, SEEK_SET);
|
||||||
|
|
||||||
|
qInfo() << "size: " << index.indexHeader.indexDataSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexFile<IndexHashTableEntry> readIndexFile(const std::string_view path) {
|
||||||
|
FILE* file = fopen(path.data(), "rb");
|
||||||
|
if(!file) {
|
||||||
|
qInfo() << "Failed to read file info " << path.data();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexFile<IndexHashTableEntry> index;
|
||||||
|
commonParseSqPack(file, index);
|
||||||
|
|
||||||
|
for(int i = 0; i < index.indexHeader.indexDataSize; i++) {
|
||||||
|
IndexHashTableEntry entry;
|
||||||
|
fread(&entry, sizeof entry, 1, file);
|
||||||
|
|
||||||
|
qInfo() << entry.hash;
|
||||||
|
qInfo() << entry.dataFileId;
|
||||||
|
qInfo() << entry.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexFile<Index2HashTableEntry> readIndex2File(const std::string_view path) {
|
||||||
|
FILE* file = fopen(path.data(), "rb");
|
||||||
|
if(!file) {
|
||||||
|
qInfo() << "Failed to read file info " << path.data();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexFile<Index2HashTableEntry> index;
|
||||||
|
commonParseSqPack(file, index);
|
||||||
|
|
||||||
|
for(int i = 0; i < index.indexHeader.indexDataSize; i++) {
|
||||||
|
Index2HashTableEntry entry;
|
||||||
|
fread(&entry, sizeof entry, 1, file);
|
||||||
|
|
||||||
|
qInfo() << entry.hash;
|
||||||
|
qInfo() << entry.dataFileId;
|
||||||
|
qInfo() << entry.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue