aboutsummaryrefslogtreecommitdiff
path: root/Src/external_dependencies/openmpt-trunk/include/ancient/src/CYB2Decoder.cpp
blob: 2deca68f95b450bd3c9d0dc570109e65644ac593 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Copyright (C) Teemu Suutari */

#include <cstring>

#include "common/SubBuffer.hpp"
#include "CYB2Decoder.hpp"
#include "XPKMain.hpp"
#include "common/Common.hpp"


namespace ancient::internal
{

bool CYB2Decoder::detectHeaderXPK(uint32_t hdr) noexcept
{
	return hdr==FourCC("CYB2");
}

std::shared_ptr<XPKDecompressor> CYB2Decoder::create(uint32_t hdr,uint32_t recursionLevel,const Buffer &packedData,std::shared_ptr<XPKDecompressor::State> &state,bool verify)
{
	return std::make_shared<CYB2Decoder>(hdr,recursionLevel,packedData,state,verify);
}

CYB2Decoder::CYB2Decoder(uint32_t hdr,uint32_t recursionLevel,const Buffer &packedData,std::shared_ptr<XPKDecompressor::State> &state,bool verify) :
	XPKDecompressor(recursionLevel),
	_packedData(packedData)
{
	if (!detectHeaderXPK(hdr) || _packedData.size()<=10) throw Decompressor::InvalidFormatError();
	_blockHeader=_packedData.readBE32(0);
	// after the block header, the next 6 bytes seem to be
	// 00 64 00 00 00 00
	// Those bytes do not seem to be terribly important though...

	if (verify)
	{
		// trigger child checks...
		ConstSubBuffer blockData(_packedData,10,_packedData.size()-10);
		std::shared_ptr<XPKDecompressor::State> state;
		auto sub=XPKMain::createDecompressor(_blockHeader,_recursionLevel+1,blockData,state,true);
	}
}

CYB2Decoder::~CYB2Decoder()
{
	// nothing needed
}

const std::string &CYB2Decoder::getSubName() const noexcept
{
	static std::string name="XPK-CYB2: xpkCybPrefs container";
	return name;
}

void CYB2Decoder::decompressImpl(Buffer &rawData,const Buffer &previousData,bool verify)
{
	ConstSubBuffer blockData(_packedData,10,_packedData.size()-10);
	std::shared_ptr<XPKDecompressor::State> state;
	auto sub=XPKMain::createDecompressor(_blockHeader,_recursionLevel+1,blockData,state,verify);
	sub->decompressImpl(rawData,previousData,verify);
}

}