A single header c++ library for reading and writing Neversoft pre/prx files.
As a single header library, the declarations and definitions in this library are in the same file. To avoid violating the one definition rule you need to write #define NSPRE_IMPL before #include "nspre.hpp" in only one source file. This will put the definitions for all the classes and functions in that source file. You can #include "nspre.hpp" as usual in any other file.
These are example programs to demonstrate basic use of the library.
Build using cmake:
cd nspre
mkdir build
cmake -S . -B build/
cmake --build build/
Programs can be found at build/pack/ns-pack and build/unpack/ns-unpack.
A class representing a successfully opened pre/prx file.
Constructor for the Reader class.
path: Path to the pre/prx file to be read
Constructor for the Reader class. You must use Reader::open() before you can do anything.
Open a pre/prx file. Equivalent to the Reader(const std::filesystem::path& path) constructor.
path: Path to the pre/prx file to be read
Reset a Reader to an uninitialized state.
Returns the Subfiles from a successfully opened pre/prx file. Will be an empty vector if opening the file failed.
Returns the total file size as recorded in the file.
Returns a vector containing the raw 12 byte header of the file.
Returns the error state of the reader. Anything other than 0 indicates failure to open the file.
A subfile within the pre/prx file.
Returns a reference to the internal path recorded in the Subfile.
Returns the filename from the internal path.
Returns the compressed size of the file if it is compressed. Returns 0 if it is uncompressed.
Returns the actual size of the file.
Returns a vector containing the raw 16 byte header of the Subfile.
Returns the offset to the start of the Subfile data.
Decompress the file if necessary and copy it to a char array. Size of the array must be greater than or equal to the value returned by size(). Returns 0 on success.
Decompress the file if necessary and copy it to a char vector. Vector will automatically be resized to appropriate size and overwritten. Returns 0 on success.
Decompress the file if necessary and write it to a file. Returns 0 on success.
Represents an external file and its associated internal path to be included in a pre file.
Constructor for the Subfile class.
i_source: Path to the file on disk
i_prepath: Internal path to be recorded in Subfile
Returns a reference to the internal path recorded in the Subfile.
Returns the filename from the internal path.
The path to the file on disk.
Writes a list of files to a pre file. Can't perform compression. Returns 0 on success.
subfiles: Pointer to an array of Subfiles
count: Number of Subfiles
path: File to write to
Writes a list of files to a pre file. Can't perform compression. Returns 0 on success.
subfiles: Vector of Subfiles
path: File to write to