Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <string.h>
  4. #include "cubemap.h"
  5.  
  6. #ifndef __CUBEMAP_H
  7. #define __CUBEMAP_H
  8. #include <zlib.h>
  9. typedef unsigned char uchar;
  10.  
  11. struct ogzHeader             // map file format header
  12. {
  13.     char magic[4];              // "OCTA"
  14.     int version;                // any >8bit quantity is little endian
  15.     int headersize;             // sizeof(header)
  16.     int worldsize;
  17.     int numents;
  18.     int numpvs;
  19.     int lightmaps;
  20.     int lightprecision, lighterror, lightlod;
  21.     uchar ambient;
  22.     uchar watercolour[3];
  23.     uchar blendmap;
  24.     uchar lerpangle, lerpsubdiv, lerpsubdivsize;
  25.     uchar bumperror;
  26.     uchar skylight[3];
  27.     uchar lavacolour[3];
  28.     uchar waterfallcolour[3];
  29.     uchar reserved[10];
  30.     char maptitle[128];
  31. };
  32.  
  33. class SauerMap
  34. {
  35.     public:
  36.         SauerMap(char *);
  37.         void PrintMapData();
  38.         char *GetMagic();
  39.  
  40.     private:
  41.         ogzHeader header;
  42.         gzFile MapFile;
  43. };
  44. #endif
  45.  
  46. SauerMap::SauerMap(char *filename)
  47. {
  48.     MapFile = gzopen(filename, "r");
  49.     if(!MapFile)
  50.     {
  51.         std::cout << "ERROR: Failed to load \"" << filename << "\"" << std::endl;
  52.         return;
  53.     }
  54.     gzread(MapFile, &header, sizeof(ogzHeader));
  55. }
  56.  
  57. void SauerMap::PrintMapData()
  58. {
  59.     std::cout << "header " << header.magic << std::endl;
  60.     std::cout << "version " << header.version << std::endl;
  61.     std::cout << "headersize " << header.headersize << std::endl;
  62.     std::cout << "worldsize " << header.worldsize << std::endl;
  63.     std::cout << "numents " << header.numents << std::endl;
  64.     std::cout << "numpvs " << header.numpvs << std::endl;
  65.     std::cout << "lightmaps " << header.lightmaps << std::endl;
  66.     std::cout << "blendmap " << header.blendmap << std::endl;
  67.     std::cout << "lightprecision " << header.lightprecision << std::endl;
  68.     std::cout << "lighterror " << header.lighterror << std::endl;
  69.     std::cout << "lightlod " << header.lightlod << std::endl;
  70.  
  71.     std::cout << "ambient " << header.ambient << std::endl;
  72.     std::cout << "watercolour " << header.watercolour << std::endl;
  73.     std::cout << "lerpangle " << header.lerpangle << std::endl;
  74.     std::cout << "lerpsubdiv " << header.lerpsubdiv << std::endl;
  75.     std::cout << "lerpsubdivsize " << header.lerpsubdivsize << std::endl;
  76.     std::cout << "maptitle " << header.maptitle << std::endl;
  77. }
  78.  
  79. char *SauerMap::GetMagic()
  80. {
  81.     return header.magic;
  82. };
  83.  
  84. int main(int argc, char *argv[])
  85. {
  86.     if(argc > 1){
  87.         SauerMap ch(argv[1]);
  88.         if(strcmp(ch.GetMagic(),"OCTA"))
  89.         {
  90.             ch.PrintMapData();
  91.             std::cout<<"SUCCESS "<< argv[1] << " is a cube2 map " << std::endl;
  92.         }else std::cout<<"ERROR: "<< argv[1] <<" is not a valid Cube 2 map" << std::endl;
  93.     }else std::cout<<"ERROR: Usage c2mapreader.exe <mapname>"<<std::endl;
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement