Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions Core/FileFormats/ArcturusPAK.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include <iostream>
#include <cstdint>
#include <fstream>
#include <vector>
#include <string>

enum class EntryType : uint8_t {
File = 0,
Directory = 1
};

struct FileEntry {
EntryType Type;
int32_t Offset;
int32_t SizeCompressed;
int32_t SizeOriginal;
std::string FileName;
};

std::vector<FileEntry> ReadEntries(std::istream& stream, int version) {
std::vector<FileEntry> entries;

stream.seekg(-9, std::ios_base::end);
if(!stream) {
return entries;
}

uint32_t entryTableOffset;
uint16_t entryCount;

if(version == 0) {
stream.read(reinterpret_cast<char*>(&entryTableOffset), sizeof(entryTableOffset));
stream.read(reinterpret_cast<char*>(&entryCount), sizeof(entryCount));
} else {
stream.read(reinterpret_cast<char*>(&entryTableOffset), sizeof(entryTableOffset));
stream.seekg(2, std::ios_base::cur);
stream.read(reinterpret_cast<char*>(&entryCount), sizeof(entryCount));
stream.seekg(1, std::ios_base::cur);
}

std::cout << "entryTableOffset: " << entryTableOffset << std::endl;
std::cout << "entryCount: " << entryCount << std::endl;

stream.seekg(entryTableOffset, std::ios_base::beg);
for(size_t i = 0; i < entryCount; i++) {
uint8_t strLen;

stream.read(reinterpret_cast<char*>(&strLen), sizeof(strLen));

FileEntry entry;
entry.Type = static_cast<EntryType>(stream.get());
stream.read(reinterpret_cast<char*>(&entry.Offset), sizeof(entry.Offset));
stream.read(reinterpret_cast<char*>(&entry.SizeCompressed), sizeof(entry.SizeCompressed));
stream.read(reinterpret_cast<char*>(&entry.SizeOriginal), sizeof(entry.SizeOriginal));

std::string fileName;
fileName.resize(strLen);
stream.read(&fileName[0], strLen);
stream.seekg(1, std::ios::cur); // Skip null terminator
entry.FileName = fileName;

entries.push_back(entry);
}

return entries;
}

int main() {

const std::string EXPECTED_PAK_FILE = "data.pak";
std::ifstream file(EXPECTED_PAK_FILE, std::ios::binary);
if(!file) {
std::cerr << "Failed to open file handle for " << EXPECTED_PAK_FILE << std::endl;
std::cerr << "Reason: I/O error - make sure this file exists and is readable" << std::endl;
return 1;
}

std::cout << "Reading PAK data from " << EXPECTED_PAK_FILE << " ..." << std::endl;

auto entries = ReadEntries(file, 0);
for(const auto& entry : entries) {
std::cout << "Type: " << static_cast<int>(entry.Type) << std::endl;
std::cout << "Offset: " << entry.Offset << std::endl;
std::cout << "SizeCompressed: " << entry.SizeCompressed << std::endl;
std::cout << "SizeOriginal: " << entry.SizeOriginal << std::endl;
std::cout << "FileName: " << entry.FileName << std::endl;
std::cout << std::endl;
}

std::cout << "Read " << entries.size() << " entries " << std::endl;

return 0;
}
3 changes: 3 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ if not exist %DEFAULT_BUILD_DIR% mkdir %DEFAULT_BUILD_DIR%
set CPP_MAIN=Core\RagLite2.cpp
set DEBUG_EXE=%DEFAULT_BUILD_DIR%/RagLiteWin32Dbg.exe
set RELEASE_EXE=%DEFAULT_BUILD_DIR%/RagLiteWin32.exe
set PAK_MAIN=Core\FileFormats\ArcturusPAK.cpp
set PAK_COMMANDLINE_EXE=%DEFAULT_BUILD_DIR%/ArcturusPAK.exe
set PROGRAM_DLLS=PatternTest DummyTest
set CLI_TOOLS=DependencyCheck
set RUNTIME_LIBS=gdi32.lib shlwapi.lib user32.lib xinput.lib winmm.lib imagehlp.lib
Expand Down Expand Up @@ -130,6 +132,7 @@ for %%T in (%CLI_TOOLS%) do (

call :msvcbuild !DEBUG_EXE! "%CPP_MAIN%" "%RUNTIME_LIBS%" "%DEBUG_COMPILE_FLAGS%" "%ICON_RES% %DEBUG_LINK_FLAGS%" || exit /b
call :msvcbuild !RELEASE_EXE! "%CPP_MAIN%" "%RUNTIME_LIBS%" "%RELEASE_COMPILE_FLAGS%" "%ICON_RES% %RELEASE_LINK_FLAGS%" || exit /b
call :msvcbuild !PAK_COMMANDLINE_EXE! "%PAK_MAIN%" "%RUNTIME_LIBS%" "%RELEASE_COMPILE_FLAGS%" "%ICON_RES% %RELEASE_LINK_FLAGS%" || exit /b
call :checkdeps !DEBUG_EXE! %DEFAULT_BUILD_DIR% || exit /b
call :checkdeps !RELEASE_EXE! %DEFAULT_BUILD_DIR% || exit /b

Expand Down
Loading