CLodHandler.h 2.3 KB

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