2023-02-25 17:39:39 +08:00
|
|
|
#include "VTUtils.hpp"
|
|
|
|
#if defined(LIBCMO_OS_WIN32)
|
|
|
|
#define ZLIB_WINAPI
|
|
|
|
#endif
|
2023-03-01 10:48:50 +08:00
|
|
|
#include <zconf.h>
|
|
|
|
|
2023-02-25 17:39:39 +08:00
|
|
|
|
|
|
|
#include "CKGlobals.hpp"
|
|
|
|
#include <zlib.h>
|
|
|
|
|
2023-02-26 21:48:03 +08:00
|
|
|
namespace LibCmo::CK2 {
|
2023-02-25 17:39:39 +08:00
|
|
|
|
|
|
|
void* CKUnPackData(CKINT DestSize, const void* SrcBuffer, CKINT SrcSize) {
|
|
|
|
char* DestBuffer = new(std::nothrow) char[DestSize];
|
|
|
|
if (DestBuffer == nullptr) return nullptr;
|
|
|
|
|
|
|
|
uLongf cache = DestSize;
|
|
|
|
if (uncompress(
|
|
|
|
reinterpret_cast<Bytef*>(DestBuffer), &cache,
|
|
|
|
reinterpret_cast<const Bytef*>(SrcBuffer), SrcSize) != Z_OK) {
|
|
|
|
delete[] DestBuffer;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DestBuffer;
|
|
|
|
}
|
|
|
|
|
2023-02-26 21:48:03 +08:00
|
|
|
CKDWORD CKComputeDataCRC(const void* data, size_t size, CKDWORD PreviousCRC) {
|
2023-02-25 17:39:39 +08:00
|
|
|
return static_cast<CKDWORD>(adler32(
|
|
|
|
static_cast<uLong>(PreviousCRC),
|
|
|
|
reinterpret_cast<const Bytef*>(data),
|
|
|
|
static_cast<uInt>(size)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|