CLodHandler.h 2.5 KB

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