CLodHandler.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 Entry & comp) const
  29. {
  30. return nameStr<comp.nameStr;
  31. }
  32. Entry(std::string con): nameStr(con){};
  33. //Entry(unsigned char ): nameStr(con){};
  34. Entry(){};
  35. };
  36. class CPCXConv
  37. {
  38. public:
  39. unsigned char * pcx, *bmp;
  40. int pcxs, bmps;
  41. void fromFile(std::string path);
  42. void saveBMP(std::string path);
  43. void openPCX(char * PCX, int len);
  44. void openPCX();
  45. void convert();
  46. SDL_Surface * getSurface();
  47. CPCXConv(){pcx=bmp=NULL;pcxs=bmps=0;};
  48. ~CPCXConv(){if (pcxs) delete[] pcx; if(bmps) delete[] bmp;}
  49. };
  50. class CLodHandler
  51. {
  52. private:
  53. std::ifstream FLOD;
  54. public:
  55. nodrze<Entry> entries;
  56. unsigned int totalFiles;
  57. int readNormalNr (unsigned char* bufor, int bytCon, bool cyclic=false); //lod header reading helper
  58. int decompress (unsigned char * source, int size, int realSize, std::ofstream & dest); //main decompression function
  59. int decompress (unsigned char * source, int size, int realSize, std::string & dest); //main decompression function
  60. int infm(FILE *source, FILE *dest, int wBits = 15); //zlib handler
  61. int infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits=15); //zlib fast handler
  62. int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler
  63. std::vector<CDefHandler *> extractManyFiles(std::vector<std::string> defNamesIn); //extrats given files (defs only)
  64. CDefHandler * giveDef(std::string defName);
  65. CDefEssential * giveDefEss(std::string defName);
  66. std::string getTextFile(std::string name); //extracts one file
  67. void extract(std::string FName);
  68. void extractFile(std::string FName, std::string name); //extracts a specific file
  69. void init(std::string lodFile);
  70. SDL_Surface * loadBitmap(std::string fname);
  71. };
  72. #endif //CLODHANDLER_H