2019-10-28 22:46:15 +00:00
|
|
|
#include "files.h"
|
2020-04-11 21:50:43 +00:00
|
|
|
#include "engineerrors.h"
|
2019-10-28 22:46:15 +00:00
|
|
|
|
|
|
|
class FZipExploder
|
|
|
|
{
|
|
|
|
unsigned int Hold, Bits;
|
|
|
|
FileReader *In;
|
|
|
|
unsigned int InLeft;
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
Shannon-Fano tree structures, variables and related routines
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
struct HuffNode
|
|
|
|
{
|
|
|
|
unsigned char Value;
|
|
|
|
unsigned char Length;
|
|
|
|
unsigned short ChildTable;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TableBuilder
|
|
|
|
{
|
|
|
|
unsigned char Value;
|
|
|
|
unsigned char Length;
|
|
|
|
unsigned short Code;
|
|
|
|
};
|
|
|
|
|
|
|
|
TArray<HuffNode> LiteralDecoder;
|
|
|
|
TArray<HuffNode> DistanceDecoder;
|
|
|
|
TArray<HuffNode> LengthDecoder;
|
|
|
|
unsigned char ReadBuf[256];
|
|
|
|
unsigned int bs, be;
|
|
|
|
|
|
|
|
static int buildercmp(const void *a, const void *b);
|
|
|
|
void InsertCode(TArray<HuffNode> &decoder, unsigned int pos, int bits, unsigned short code, int len, unsigned char value);
|
|
|
|
unsigned int InitTable(TArray<HuffNode> &decoder, int numspots);
|
|
|
|
int BuildDecoder(TArray<HuffNode> &decoder, TableBuilder *values, int numvals);
|
|
|
|
int DecodeSFValue(const TArray<HuffNode> ¤tTree);
|
|
|
|
int DecodeSF(TArray<HuffNode> &decoder, int numvals);
|
|
|
|
public:
|
|
|
|
int Explode(unsigned char *out, unsigned int outsize, FileReader &in, unsigned int insize, int flags);
|
|
|
|
};
|
|
|
|
|
2020-04-11 21:54:33 +00:00
|
|
|
class CExplosionError : CRecoverableError
|
2019-10-28 22:46:15 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-04-11 21:50:43 +00:00
|
|
|
CExplosionError(const char *message) : CRecoverableError(message) {}
|
2019-10-28 22:46:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int ShrinkLoop(unsigned char *out, unsigned int outsize, FileReader &in, unsigned int insize);
|