1 //************************************************************************** 2 //** 3 //** ## ## ## ## ## #### #### ### ### 4 //** ## ## ## ## ## ## ## ## ## ## #### #### 5 //** ## ## ## ## ## ## ## ## ## ## ## ## ## ## 6 //** ## ## ######## ## ## ## ## ## ## ## ### ## 7 //** ### ## ## ### ## ## ## ## ## ## 8 //** # ## ## # #### #### ## ## 9 //** 10 //** $Id: wadlib.h 1599 2006-07-06 17:20:16Z dj_jl $ 11 //** 12 //** Copyright (C) 1999-2006 Jānis Legzdiņš 13 //** 14 //** This program is free software; you can redistribute it and/or 15 //** modify it under the terms of the GNU General Public License 16 //** as published by the Free Software Foundation; either version 2 17 //** of the License, or (at your option) any later version. 18 //** 19 //** This program is distributed in the hope that it will be useful, 20 //** but WITHOUT ANY WARRANTY; without even the implied warranty of 21 //** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 //** GNU General Public License for more details. 23 //** 24 //************************************************************************** 25 26 #ifndef WADLIB_H 27 #define WADLIB_H 28 29 namespace VavoomUtils { 30 31 // HEADER FILES ------------------------------------------------------------ 32 33 // MACROS ------------------------------------------------------------------ 34 35 // TYPES ------------------------------------------------------------------- 36 37 struct lumpinfo_t 38 { 39 char name[12]; 40 int position; 41 int size; 42 }; 43 44 class WadLibError 45 { 46 public: WadLibError(const char * Amessage)47 WadLibError(const char *Amessage) 48 { 49 strcpy(message, Amessage); 50 } 51 52 char message[256]; 53 }; 54 55 class TIWadFile 56 { 57 public: TIWadFile()58 TIWadFile() 59 { 60 handle = NULL; 61 } ~TIWadFile()62 ~TIWadFile() 63 { 64 if (handle) 65 { 66 Close(); 67 } 68 } 69 void Open(const char* filename); 70 int LumpNumForName(const char* name); LumpName(int lump)71 const char* LumpName(int lump) 72 { 73 return lump >= numlumps ? "" : lumpinfo[lump].name; 74 } LumpSize(int lump)75 int LumpSize(int lump) 76 { 77 return lump >= numlumps ? 0 : lumpinfo[lump].size; 78 } 79 void* GetLump(int lump); GetLumpName(const char * name)80 void* GetLumpName(const char* name) 81 { 82 return GetLump(LumpNumForName(name)); 83 } 84 void Close(); 85 86 FILE* handle; 87 char wadid[4]; 88 lumpinfo_t* lumpinfo; 89 int numlumps; 90 }; 91 92 class TOWadFile 93 { 94 public: TOWadFile()95 TOWadFile() 96 { 97 handle = NULL; 98 } ~TOWadFile()99 ~TOWadFile() 100 { 101 if (handle) 102 { 103 fclose(handle); 104 } 105 } 106 void Open(const char *filename, const char *Awadid); 107 void AddLump(const char *name, const void *data, int size); 108 void Close(); 109 110 FILE* handle; 111 char wadid[4]; 112 lumpinfo_t* lumpinfo; 113 int numlumps; 114 }; 115 116 // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- 117 118 // PUBLIC DATA DECLARATIONS ------------------------------------------------ 119 120 //========================================================================== 121 // 122 // CleanupName 123 // 124 //========================================================================== 125 CleanupName(const char * src,char * dst)126inline void CleanupName(const char *src, char *dst) 127 { 128 int i; 129 for (i = 0; i < 8 && src[i]; i++) 130 { 131 dst[i] = toupper(src[i]); 132 } 133 for (; i < 12; i++) 134 { 135 dst[i] = 0; 136 } 137 } 138 139 } // namespace VavoomUtils 140 141 #endif 142