keybode

parse bsp

Jan 30th, 2015
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. struct lump_t {
  6.     int     fileofs;
  7.     int     filelen;
  8.     int     version;
  9.     char    fourCC[4];
  10. };
  11.  
  12. struct dheader_t {
  13.     int     ident;
  14.     int     version;
  15.     lump_t  lumps[64];
  16.     int     mapRevision;
  17. };
  18.  
  19. dheader_t* LoadBSP(const std::string& path, BYTE** fileData) {
  20.     HANDLE hFile = CreateFile(path.c_str(), GENERIC_READ, NULL, NULL, OPEN_ALWAYS, NULL, NULL);
  21.  
  22.     if (hFile == INVALID_HANDLE_VALUE) {
  23.         return nullptr;
  24.     }
  25.  
  26.     DWORD dwSize = GetFileSize(hFile, NULL);
  27.  
  28.     if (!dwSize) {
  29.         CloseHandle(hFile);
  30.         return nullptr;
  31.     }
  32.  
  33.     printf("File Size: %i bytes\n", (int)dwSize);
  34.  
  35.     if (!(*fileData)) {
  36.         *fileData = new BYTE[dwSize];
  37.     }
  38.  
  39.     DWORD dwReadSize = NULL;
  40.  
  41.     if (!ReadFile(hFile, *fileData, dwSize, &dwReadSize, NULL)) {
  42.         CloseHandle(hFile);
  43.         delete *fileData;
  44.         return nullptr;
  45.     }
  46.  
  47.     return (dheader_t*)*fileData;
  48. }
  49.  
  50. int main() {
  51.     SetConsoleTitle("BSP Parser");
  52.  
  53.     BYTE* pDataBSP = nullptr;
  54.  
  55.     dheader_t* header = LoadBSP("D:\\Games\\Steam\\steamapps\\common\\Counter-Strike Global Offensive\\csgo\\maps\\de_dust2.bsp", &pDataBSP);
  56.  
  57.     printf("ident = %i\n", header->ident);
  58.     printf("version = %i\n", header->version);
  59.     printf("mapRevision = %i\n", header->mapRevision);
  60.  
  61.     printf("\n");
  62.     system("pause");
  63.  
  64.     return NULL;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment