#define VCMI_DLL #include "../stdafx.h" #include "zlib.h" #include "CLodHandler.h" #include #include #include #include #include "boost/filesystem/operations.hpp" #include #include DLL_EXPORT int readNormalNr (int pos, int bytCon, unsigned char * str) { int ret=0; int amp=1; if (str) { for (int i=0; irealSize; fseek(FLOD, ourEntry->offset, 0); unsigned char * outp; if (ourEntry->offset<0) //file is in the sprites/ folder; no compression { unsigned char * outp = new unsigned char[ourEntry->realSize]; char name[30];memset(name,0,30); strcat(name,"Sprites/"); strcat(name,(char*)ourEntry->name); FILE * f = fopen(name,"rb"); int result = fread(outp,1,ourEntry->realSize,f); if(result<0) {std::cout<<"Error in file reading: "<size==0) //file is not compressed { outp = new unsigned char[ourEntry->realSize]; fread((char*)outp, 1, ourEntry->realSize, FLOD); return outp; } else //we will decompress file { outp = new unsigned char[ourEntry->size]; fread((char*)outp, 1, ourEntry->size, FLOD); fseek(FLOD, 0, 0); unsigned char * decomp = NULL; int decRes = infs2(outp, ourEntry->size, ourEntry->realSize, decomp); delete[] outp; return decomp; } return NULL; } int CLodHandler::infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits) { int ret; unsigned have; z_stream strm; unsigned char inx[NLoadHandlerHelp::fCHUNK]; unsigned char outx[NLoadHandlerHelp::fCHUNK]; /* allocate inflate state */ strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; strm.avail_in = 0; strm.next_in = Z_NULL; ret = inflateInit2(&strm, wBits); if (ret != Z_OK) return ret; int chunkNumber = 0; do { int readBytes = 0; for(int i=0; i=amp/2) { ret = ret-amp; } return ret; } void CLodHandler::init(std::string lodFile, std::string dirName) { std::string Ts; FLOD = fopen(lodFile.c_str(), "rb"); fseek(FLOD, 8, 0); unsigned char temp[4]; fread((char*)temp, 1, 4, FLOD); totalFiles = readNormalNr(temp,4); fseek(FLOD, 0x5c, 0); for (int i=0; istatus())) { std::string name = dir->path().leaf(); std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper); boost::algorithm::replace_all(name,".BMP",".PCX"); Entry * e = entries.znajdz(name); if(e) { e->offset = -1; e->realSize = e->size = boost::filesystem::file_size(dir->path()); } } } } else std::cout<<"Warning: No "+dirName+"/ folder!"<