2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 lumpinfo_t
*wad_lumps
;
28 void SwapPic (qpic_t
*pic
);
34 Lowercases name and pads with spaces and a terminating 0 to the length of
36 Used so lumpname lookups can proceed rapidly by comparing 4 chars at a time
37 Space padding is so names can be printed nicely in tables.
38 Can safely be performed in place.
41 void W_CleanupName (char *in
, char *out
)
46 for (i
=0 ; i
<16 ; i
++ )
52 if (c
>= 'A' && c
<= 'Z')
68 void W_LoadWadFile (char *filename
)
75 wad_base
= COM_LoadHunkFile (filename
);
77 Sys_Error ("W_LoadWadFile: couldn't load %s", filename
);
79 header
= (wadinfo_t
*)wad_base
;
81 if (header
->identification
[0] != 'W'
82 || header
->identification
[1] != 'A'
83 || header
->identification
[2] != 'D'
84 || header
->identification
[3] != '2')
85 Sys_Error ("Wad file %s doesn't have WAD2 id\n",filename
);
87 wad_numlumps
= LittleLong(header
->numlumps
);
88 infotableofs
= LittleLong(header
->infotableofs
);
89 wad_lumps
= (lumpinfo_t
*)(wad_base
+ infotableofs
);
91 for (i
=0, lump_p
= wad_lumps
; i
<wad_numlumps
; i
++,lump_p
++)
93 lump_p
->filepos
= LittleLong(lump_p
->filepos
);
94 lump_p
->size
= LittleLong(lump_p
->size
);
95 W_CleanupName (lump_p
->name
, lump_p
->name
);
96 if (lump_p
->type
== TYP_QPIC
)
97 SwapPic ( (qpic_t
*)(wad_base
+ lump_p
->filepos
));
107 lumpinfo_t
*W_GetLumpinfo (char *name
)
113 W_CleanupName (name
, clean
);
115 for (lump_p
=wad_lumps
, i
=0 ; i
<wad_numlumps
; i
++,lump_p
++)
117 if (!strcmp(clean
, lump_p
->name
))
121 Sys_Error ("W_GetLumpinfo: %s not found", name
);
125 void *W_GetLumpName (char *name
)
129 lump
= W_GetLumpinfo (name
);
131 return (void *)(wad_base
+ lump
->filepos
);
134 void *W_GetLumpNum (int num
)
138 if (num
< 0 || num
> wad_numlumps
)
139 Sys_Error ("W_GetLumpNum: bad number: %i", num
);
141 lump
= wad_lumps
+ num
;
143 return (void *)(wad_base
+ lump
->filepos
);
147 =============================================================================
149 automatic byte swapping
151 =============================================================================
154 void SwapPic (qpic_t
*pic
)
156 pic
->width
= LittleLong(pic
->width
);
157 pic
->height
= LittleLong(pic
->height
);