CLodHandler.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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]; //
  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();
  51. CPCXConv(){pcx=bmp=NULL;pcxs=bmps=0;};
  52. ~CPCXConv(){if (pcxs) delete[] pcx; if(bmps) delete[] bmp;}
  53. };
  54. class CLodHandler
  55. {
  56. private:
  57. FILE* FLOD;
  58. public:
  59. nodrze<Entry> entries;
  60. unsigned int totalFiles;
  61. int readNormalNr (unsigned char* bufor, int bytCon, bool cyclic=false); //lod header reading helper
  62. int decompress (unsigned char * source, int size, int realSize, std::ofstream & dest); //main decompression function
  63. int decompress (unsigned char * source, int size, int realSize, std::string & dest); //main decompression function
  64. int infm(FILE *source, FILE *dest, int wBits = 15); //zlib handler
  65. int infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits=15); //zlib fast handler
  66. int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler
  67. std::vector<CDefHandler *> extractManyFiles(std::vector<std::string> defNamesIn); //extrats given files (defs only)
  68. CDefHandler * giveDef(std::string defName);
  69. CDefEssential * giveDefEss(std::string defName);
  70. std::string getTextFile(std::string name); //extracts one file
  71. void extract(std::string FName);
  72. void extractFile(std::string FName, std::string name); //extracts a specific file
  73. void init(std::string lodFile);
  74. SDL_Surface * loadBitmap(std::string fname);
  75. };
  76. #endif //CLODHANDLER_H