CLodHandler.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef CLODHANDLER_H
  2. #define CLODHANDLER_H
  3. #include <iostream>
  4. #include <fstream>
  5. #include <vector>
  6. #include <string>
  7. #include "zlib.h"
  8. #include "CDefHandler.h"
  9. enum Epcxformat {PCX8B, PCX24B};
  10. namespace NLoadHandlerHelp
  11. {
  12. const int dmHelp=0, dmNoExtractingMask=1;
  13. //std::string P1,P2,CurDir;
  14. const int fCHUNK = 50000;
  15. };
  16. struct Entry
  17. {
  18. unsigned char name[12], //filename
  19. hlam_1[4], //
  20. hlam_2[4]; //
  21. std::string nameStr;
  22. int offset, //from beginning
  23. realSize, //size without compression
  24. size; //and with
  25. bool operator<(const Entry & comp) const
  26. {
  27. return this->nameStr<comp.nameStr;
  28. }
  29. Entry(std::string con): nameStr(con){};
  30. Entry(){};
  31. };
  32. class CPCXConv
  33. {
  34. public:
  35. unsigned char * pcx, *bmp;
  36. int pcxs, bmps;
  37. void fromFile(std::string path);
  38. void saveBMP(std::string path);
  39. void openPCX(char * PCX, int len);
  40. void openPCX();
  41. void convert();
  42. SDL_Surface * getSurface();
  43. CPCXConv(){pcx=bmp=NULL;pcxs=bmps=0;};
  44. ~CPCXConv(){if (pcxs) delete pcx; if(bmps) delete bmp;}
  45. };
  46. class CLodHandler
  47. {
  48. private:
  49. std::ifstream FLOD;
  50. public:
  51. std::vector<Entry> entries;
  52. unsigned int totalFiles;
  53. int readNormalNr (unsigned char* bufor, int bytCon, bool cyclic=false); //lod header reading helper
  54. int decompress (unsigned char * source, int size, int realSize, std::ofstream & dest); //main decompression function
  55. int decompress (unsigned char * source, int size, int realSize, std::string & dest); //main decompression function
  56. int infm(FILE *source, FILE *dest, int wBits = 15); //zlib handler
  57. int infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits=15); //zlib fast handler
  58. int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler
  59. std::vector<CDefHandler *> extractManyFiles(std::vector<std::string> defNamesIn); //extrats given files (defs only)
  60. CDefHandler * giveDef(std::string defName);
  61. void extract(std::string FName);
  62. void extractFile(std::string FName, std::string name); //extracts a specific file
  63. void init(std::string lodFile);
  64. SDL_Surface * loadBitmap(std::string fname);
  65. };
  66. #endif //CLODHANDLER_H