Polyphase Game Engine
Loading...
Searching...
No Matches
ContentPak.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <string>
5#include <vector>
6
7#include "PolyphaseAPI.h"
8
9// Content.pak -- a single-archive shipping format for Static builds.
10//
11// Phase 1 obfuscated loose files: contents were protected but the filenames and
12// directory tree stayed readable, and every asset still cost a directory entry
13// on the target's filesystem. A pak folds all of it into one file:
14//
15// [ header 32 bytes, plain -- just enough to find the index ]
16// [ data per-entry ContentObfuscation containers, concatenated ]
17// [ index entry table + path blob, itself obfuscated ]
18//
19// Only the index is resident at runtime; entry bytes are read and decoded on
20// demand, so console memory behaviour matches the loose-file path it replaces.
21// Because the index is obfuscated, the paths are hidden too -- a shipped pak
22// leaks neither content nor names.
23//
24// Entries are stored as the same containers Phase 1 writes, so Stream::ReadFile's
25// existing decode handles them unchanged; the pak layer only has to hand back the
26// right span of bytes. That also keeps truncated reads working: the keystream is
27// offset-addressable, so a capped read decodes a correct prefix.
28//
29// Lookups are path-keyed, which Phase 1 deliberately avoided. It is safe here
30// because the pak index is the single authority on naming -- keys are written by
31// the cook and read back verbatim, with no per-platform path canonicalisation to
32// disagree about. Hash hits are confirmed against the stored path, so a 64-bit
33// collision degrades to a miss rather than to silently serving the wrong asset.
34
35namespace ContentPak
36{
37 static const uint32_t kHeaderSize = 32;
38
39 // ---- Runtime -----------------------------------------------------------
40
41 // Reads the header and index only. Safe to call when the file is absent --
42 // returns false and leaves the pak unmounted so callers fall back to loose
43 // files.
44 bool Mount(const char* pakPath);
45 void Unmount();
46 bool IsMounted();
47
48 bool Exists(const char* path);
49
50 // Reads an entry's stored (still-obfuscated) bytes. `outData` is malloc'd so
51 // Stream can take ownership and free() it, matching SYS_AcquireFileData.
52 // `maxSize > 0` reads a prefix; the container header is accounted for.
53 bool Read(const char* path, int32_t maxSize, char*& outData, uint32_t& outSize);
54
55 // Locates an entry's raw span for the seekable streaming reader, which needs
56 // its own handle rather than a whole-file read.
57 bool FindEntry(const char* path, uint32_t& outDataOffset, uint32_t& outDataSize);
58
59 // Path the pak was mounted from, for opening independent streaming handles.
60 const char* GetPakPath();
61
62 // Every key under `prefix`. Needed because some content is discovered by
63 // walking a directory rather than by name -- the Vulkan global shaders are
64 // enumerated from Engine/Shaders/GLSL/bin/ -- and a packed build has no
65 // directory to walk.
66 void List(const char* prefix, std::vector<std::string>& outKeys);
67
68 // ---- Cook --------------------------------------------------------------
69
71 {
72 std::string mKey; // canonical, package-relative (e.g. "Game/Assets/T.oct")
73 std::string mSourcePath; // absolute path to read from
74 };
75
76 // Writes `pakPath` from `files`. Each file is wrapped in a ContentObfuscation
77 // container (or passed through if already wrapped). Returns false on any I/O
78 // failure -- callers must not prune loose content unless this succeeded.
79 bool Build(const char* pakPath, const std::vector<SourceFile>& files, uint32_t& outEntryCount);
80}
Export macros for Polyphase Engine symbols.
Definition ContentPak.h:36
bool Build(const char *pakPath, const std::vector< SourceFile > &files, uint32_t &outEntryCount)
Definition ContentPak.cpp:363
bool IsMounted()
Definition ContentPak.cpp:260
bool Exists(const char *path)
Definition ContentPak.cpp:265
bool FindEntry(const char *path, uint32_t &outDataOffset, uint32_t &outDataSize)
Definition ContentPak.cpp:303
void Unmount()
Definition ContentPak.cpp:247
bool Read(const char *path, int32_t maxSize, char *&outData, uint32_t &outSize)
Definition ContentPak.cpp:318
const char * GetPakPath()
Definition ContentPak.cpp:270
bool Mount(const char *pakPath)
Definition ContentPak.cpp:160
void List(const char *prefix, std::vector< std::string > &outKeys)
Definition ContentPak.cpp:275
Definition ContentPak.h:71
std::string mKey
Definition ContentPak.h:72
std::string mSourcePath
Definition ContentPak.h:73