diff options
| author | John "Lameguy" Wilbert Villamor <lameguy64@gmail.com> | 2021-10-15 09:22:45 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-15 09:22:45 +0800 |
| commit | dd0f088aaa4c6bf013643be2d1d8621dbffdb000 (patch) | |
| tree | d848d6ce007d8bb9357c8b99d6a0a39ec41d244e /libpsn00b/include | |
| parent | 9e08d1047fa8deeb3ccb3ce9bb11d69e25a52d56 (diff) | |
| parent | eb719a424e6a16fb64209139a32c9f8a7235a929 (diff) | |
| download | psn00bsdk-dd0f088aaa4c6bf013643be2d1d8621dbffdb000.tar.gz | |
Merge pull request #38 from spicyjpeg/cmake
Full CMake support (in place of makefiles)
Diffstat (limited to 'libpsn00b/include')
| -rw-r--r-- | libpsn00b/include/dlfcn.h | 2 | ||||
| -rw-r--r-- | libpsn00b/include/lzp/lzp.h | 223 | ||||
| -rw-r--r-- | libpsn00b/include/lzp/lzqlp.h | 31 |
3 files changed, 255 insertions, 1 deletions
diff --git a/libpsn00b/include/dlfcn.h b/libpsn00b/include/dlfcn.h index 5fdd343..0c51821 100644 --- a/libpsn00b/include/dlfcn.h +++ b/libpsn00b/include/dlfcn.h @@ -119,7 +119,7 @@ void DL_SetResolveCallback(void *(*callback)(DLL *, const char *)); * * The third argument specifies when symbols in the DLL should be resolved. * Setting it to RTLD_LAZY defers resolution of undefined functions to when - * they are first called, while RTLD_DEFAULT forces all symbols to be resolved + * they are first called, while RTLD_NOW forces all symbols to be resolved * immediately. If a custom resolver has been set via DL_SetResolveCallback(), * it will be called for each symbol to resolve. * diff --git a/libpsn00b/include/lzp/lzp.h b/libpsn00b/include/lzp/lzp.h new file mode 100644 index 0000000..cfeeb72 --- /dev/null +++ b/libpsn00b/include/lzp/lzp.h @@ -0,0 +1,223 @@ +/*! \file lzp.h + * \brief Main library header + */ + +/*! \mainpage + * \version 0.20b + * \author John Wilbert 'Lameguy64' Villamor + * + * \section creditsSection Credits + * - LZ77 data compression/decompression routines based from Ilya Muravyov's + * crush.cpp released under public domain. Refined and ported to C by Lameguy64. + * - CRC calculation routines based from Lammert Bies' lib_crc routines. + * + */ + +#ifndef _LZPACK_H +#define _LZPACK_H + +#include <sys/types.h> +#ifdef _WIN32 +#include <windows.h> +#endif + +/*! \addtogroup crcBaseRemainders CRC Base Remainder Values + * @{ + */ +//! Initial remainder value for lzCRC16() +#define LZP_CRC16_REMAINDER 0x0000 +//! Initial remainder value for lzCRC32() +#define LZP_CRC32_REMAINDER 0xFFFFFFFF +/*! @} */ + + +/*! \addtogroup compLevels Compression Levels + * \brief Compression levels for the lzCompress() function. + * @{ + */ +//! Minimal (but fast) compression +#define LZP_COMPRESS_FAST 0 +//! Normal compression level +#define LZP_COMPRESS_NORMAL 1 +//! Maximum compression level +#define LZP_COMPRESS_MAX 2 +/*! @} */ + + +/*! \addtogroup libraryErrorCodes Library Error Codes + * @{ + */ +//! No error +#define LZP_ERR_NONE 0 +//! Decompression error +#define LZP_ERR_DECOMPRESS -1 +//! Not a valid LZP/QLP/PCK archive +#define LZP_ERR_INVALID_PACK -2 +//! File not found +#define LZP_ERR_NOTFOUND -3 +//! CRC check mismatch (data corruption) +#define LZP_ERR_CRC_MISMATCH -4 +/*! @} */ + + +//! Header structure of an LZP format archive file +typedef struct { + + //! File ID (must always be 'LZP') + char id[3]; + //! File count + u_char numFiles; + +} LZP_HEAD; + +//! File entry structure for an LZP format archive file +typedef struct { + + //! File name + char fileName[16]; + //! CRC32 checksum of file + u_int crc; + //! Original size of file in bytes + u_int fileSize; + //! Compressed size of file + u_int packedSize; + //! File data offset + u_int offset; + +} LZP_FILE; + + +// Function prototypes +#ifdef __cplusplus +extern "C" { +#endif + + +/*! \addtogroup compressFuncs Data Compression and Decompression Functions + * \brief Functions to compress and decompress data. + * @{ + */ + +/*! Compress a block of data. + * + * \details This function compresses a specified block of data in LZ77 encoding. + * Depending on the size of the input data and speed of the computer, compression + * may take a while to complete. + * + * \param[out] *outBuff Pointer to buffer to store compressed data. + * \param[in] *inBuff Pointer to data to compress. + * \param[in] inSize Size of data to compress in bytes. + * \param[in] level Compression level (see \ref compLevels). + * + * \returns The size of the compressed data in bytes. + */ +int lzCompress(void* outBuff, const void* inBuff, int inSize, int level); + +/*! Decompress a compressed block of data. + * + * \details Decompressed a compressed block of data produced by lzCompress(). It cannot + * return the decompressed size of the data ahead of time so you must preserve the decompressed + * size of the data yourself. + * + * \note The decompression algorithm used in this function is completely independent + * of the compression settings set by lzSetHashSizes() before compressing the data with + * lzCompress(). + * + * \param[out] *outBuff Pointer to buffer to store decompressed data. + * \param[in] *inBuff Pointer to compressed data to decompress. + * \param[in] inSize Compressed data size in bytes. + * + * \returns Size of decompressed data in bytes or LZP_ERR_DECOMPRESS if a + * decompression error occurred. + */ +int lzDecompress(void* outBuff, const void* inBuff, int inSize); + +int lzDecompressLen(void* outBuff, int outSize, const void* inBuff, int inSize); + +/*! Sets the sizes of hash tables for data compression. + * + * \param[in] window Sliding window size. + * \param[in] hash1 Hash table 1 size. + * \param[in] hash2 Hash table 2 size. + */ +void lzSetHashSizes(int window, int hash1, int hash2); + +/*! Reset the sizes of hash tables to their defaults. + */ +void lzResetHashSizes(); + +/*! @} */ + + +/*! \addtogroup crcFuncs CRC Hashing Functions + * \brief Functions to calculate CRC hashes of data. + * @{ + */ + +/*! Calculates a CRC16 hash of the specified buffer. + * + * \param[in] *buff Pointer to buffer to calculate a hash of. + * \param[in] bytes Size of buffer in bytes. + * \param[in] crc CRC remainder (use LZP_CRC16_REMAINDER). + * + * \returns CRC16 hash of specified buffer. + */ +unsigned short lzCRC16(const void* buff, int bytes, unsigned short crc); + +/*! Calculates a CRC32 hash of the specified buffer. + * + * \param[in] *buff Pointer to buffer to calculate a hash of. + * \param[in] bytes Size of buffer in bytes. + * \param[in] crc CRC remainder (use LZP_CRC16_REMAINDER). + * + * \returns CRC32 hash of specified buffer. + */ +unsigned int lzCRC32(const void* buff, int bytes, unsigned int crc); + +/*! @} */ + + +/*! \addtogroup lzpFunctions LZP Archive Handling Routines + * \brief Functions to index and unpack files from LZP archives. + * @{ + */ + +/*! Searches for a file by name in an LZP archive and returns a file entry number. + * + * \param[in] *fileName String of file to search (must be less than 13 characters). + * \param[in] *lzpack Pointer to LZP archive file. + * + * \returns File index of found file or one of \ref libraryErrorCodes if an error occurred. + */ +int lzpSearchFile(const char* fileName, const LZP_HEAD* lzpack); + +int lzpFileSize(const LZP_HEAD* lzpack, int fileNum); + +/*! Get a pointer to a file entry inside of an LZP archive. + * + * \param[in] *lzpack Pointer to LZP archive file. + * \param[in] fileNum File number to get an entry of (you may use lzpSearchFile()). + * + * \returns A pointer to an LZP_FILE struct or NULL if an error occurred. + */ +const LZP_FILE* lzpFileEntry(const LZP_HEAD* lzpack, int fileNum); + +/*! Unpacks a file from an LZP archive to the specified memory buffer. + * + * \param[in] *buff Pointer to buffer to store unpacked file. + * \param[in] *lzpack Pointer to LZP archive file. + * \param[in] fileNum File entry number of file to extract (you may use lzpSearchFile()). + * + * \returns Size of decompressed file in bytes or one of \ref libraryErrorCodes if an error occurred. + */ +int lzpUnpackFile(void* buff, const LZP_HEAD* lzpack, int fileNum); + +/*! @} */ + + +#ifdef __cplusplus +} +#endif + + +#endif // _LZPACK_H diff --git a/libpsn00b/include/lzp/lzqlp.h b/libpsn00b/include/lzp/lzqlp.h new file mode 100644 index 0000000..5b70b40 --- /dev/null +++ b/libpsn00b/include/lzp/lzqlp.h @@ -0,0 +1,31 @@ +#ifndef _QLP_H +#define _QLP_H + +#include <sys/types.h> +#ifdef _WIN32 +#include <windows.h> +#endif + +#define PACK_ERR_NONE 0 +#define PACK_ERR_INVALID -1 +#define PACK_ERR_NOTFOUND -2 +#define PACK_ERR_INCOMPLETE -3 +#define PACK_ERR_READ_FAULT -4 + +typedef struct { + char id[3]; + u_char numfiles; +} QLP_HEAD; + +typedef struct { + char name[16]; + u_int size; + u_int offs; +} QLP_FILE; + +int qlpFileCount(const QLP_HEAD* qlpfile); +const QLP_FILE* qlpFileEntry(int index, const QLP_HEAD* qlpfile); +const void* qlpFileAddr(int index, const QLP_HEAD* qlpfile); +int qlpFindFile(char* fileName, const QLP_HEAD* qlpfile); + +#endif // _QLP_H
\ No newline at end of file |
