[go: up one dir, main page]

Menu

[904618]: / src / w_wad.h  Maximize  Restore  History

Download this file

324 lines (266 with data), 11.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
// -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-
// ----------------------------------------------------------------------------
// :oCCCCOCoc.
// .cCO8OOOOOOOOO8Oo:
// .oOO8OOOOOOOOOOOOOOOCc
// cO8888: .:oOOOOC. TM
// :888888: :CCCc .oOOOOC. ### ### #########
// C888888: .ooo: .C######## ##### ##### ###### ###### ##########
// O888888: .oO### ### ##### ##### ######## ######## #### ###
// C888888: :8O. .C########## ### #### ### ## ## ## ## #### ###
// :8@@@@8: :888c o### ### #### ### ######## ######## ##########
// :8@@@@C C@@@@ oo######## ### ## ### ###### ###### #########
// cO@@@@@@@@@@@@@@@@@Oc0
// :oO8@@@@@@@@@@Oo.
// .oCOOOOOCc. http://remood.org/
// ----------------------------------------------------------------------------
// Copyright (C) 2008-2013 GhostlyDeath <ghostlydeath@remood.org>
// <ghostlydeath@gmail.com>
// ----------------------------------------------------------------------------
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// ----------------------------------------------------------------------------
// DESCRIPTION: WAD I/O functions, wad resource definitions (some).
#ifndef __W_WAD_H__
#define __W_WAD_H__
#include "doomtype.h"
/*************
*** GLOBAL ***
*************/
#define INVALIDLUMP -1
/* Define WadIndex_t */
#if !defined(__REMOOD_WADINDEXT_DEFINED)
typedef int WadIndex_t;
#define __REMOOD_WADINDEXT_DEFINED
#endif
/************************
*** LITE WAD HANDLING ***
************************/
/*** CONSTANTS ***/
#define WLMAXENTRYNAME 24 // Max characters in entry name
#define WLMAXPRIVATEWADSTUFF 32 // Maximum number of private WAD Stuffs
#define WLMAXDOSNAME 13 // nnnnnnnn.xxx\0
/* WL_DataPDCOrder_t -- Orders for data handling (PDCs) */
typedef enum WL_DataPDCOrder_e
{
WLDPO_VIMAGES = 20, // Image_t
WLDPO_RMOD = 30, // ReMooD Map Object Data
WLDPO_VFONTS = 75, // Fonts
WLDPO_TEXTURES = 100, // Textures
WLDPO_MAPINFO = 125, // MAPINFO
} WL_DataPDCOrder_t;
/* WL_DataOCCBOrder_t -- Orders for data handling (OCCBs) */
typedef enum WL_DataOCCBOrder_e
{
WLDCO_IWADDETECT = 1, // IWAD Detection
WLDCO_RWADDETECT = 2, // ReMooD.WAD Detection
WLDCO_UIIMAGES = 29, // UI Image Stuff
WLDCO_RMOD = 30, // ReMooD Map Object Data
WLDCO_VVIDEO = 70, // Video
WLDCO_VFONTS = 75, // Fonts
WLDCO_TEXTURES = 75, // Textures
WLDCO_EXTRASPECIALS = 100, // Extra Special Stuff
WLDCO_BOTSTUFF = 120, // Bot Things
} WL_DataOCCBOrder_t;
/* WL_DataKeys_t -- Keys for data handling, shortcuts */
// Helps prevent magic
typedef enum WL_DataKeys_e
{
WLDK_RMOD = 0x524D4F44U, // ReMooD Map Object Data
WLDK_VIMAGES = 0x8C064303U, // Image_t
WLDK_VFONTS = 0x464F4E54U, // Fonts
WLDK_MAPINFO = 0x4F464E49U, // Map Information
WLDK_TEXTURES = 0x72547854U, // Textures
} WL_DataKeys_t;
/* WL_FindFlags_t -- Flags when finding things */
typedef enum WL_FindFlags_e
{
WLFF_DEFAULTS = 0, // Default stuff
WLFF_FORWARDS = 0x0001, // Search forwards instead of backwards
WLFF_IMPORTANT = 0x0010, // I_Error if not found (not recommended!)
} WL_FindFlags_t;
/*** STRUCTURES ***/
/* Define WL_WADEntry_t */
#if !defined(__REMOOD_WLWADENT_DEFINED)
typedef struct WL_WADEntry_s WL_WADEntry_t;
#define __REMOOD_WLWADENT_DEFINED
#endif
/* Define WL_WADFile_t */
#if !defined(__REMOOD_WLWADFILE_DEFINED)
typedef struct WL_WADFile_s WL_WADFile_t;
#define __REMOOD_WLWADFILE_DEFINED
#endif
/* Define Z_HashTable_t */
#if !defined(__REMOOD_ZHT_DEFINED)
typedef struct Z_HashTable_s Z_HashTable_t;
#define __REMOOD_ZHT_DEFINED
#endif
/* Define UI_Img_t */
#if !defined(__REMOOD_UIIMG_DEFINED)
typedef struct UI_Img_s UI_Img_t;
#define __REMOOD_UIIMG_DEFINED
#endif
// WAD Data loading
typedef void (*WL_RemoveFunc_t)(const WL_WADFile_t* a_WAD);
typedef bool_t (*WL_PCCreatorFunc_t)(const WL_WADFile_t* const a_WAD, const uint32_t a_Key, void** const a_DataPtr, size_t* const a_SizePtr, WL_RemoveFunc_t* const a_RemoveFuncPtr);
// Order Change
typedef bool_t (*WL_OrderCBFunc_t)(const bool_t a_Pushed, const WL_WADFile_t* const a_WAD);
/* WL_WADEntry_t -- A lite WAD entry */
struct WL_WADEntry_s
{
/* Public Stuff You Read From */
// Normal Stuff
char Name[WLMAXENTRYNAME]; // Name of entry
uint32_t Hash; // Hash for this entry
WadIndex_t Index; // Index for this entry (WAD Local)
WadIndex_t GlobalIndex; // Global Index for this entry (of all WADs)
// Data Related
size_t Size; // Size of the data
// Owner
WL_WADFile_t* Owner; // WAD that owns this
// Linkage
WL_WADEntry_t* PrevEntry; // Previous Entry
WL_WADEntry_t* NextEntry; // Next Entry
/* Private Stuff You Don't Touch */
struct
{
bool_t __Compressed; // Entry is compressed
int32_t __UsageCount; // Times entry used
void* __Data; // Loaded Data (cached)
size_t __Offset; // Offset of the internal data
size_t __InternalSize; // Internal size (could be compressed)
void* __WXClone; // Cloned data for WX
bool_t __MapReal; // REAL memory map (not faked)
int32_t __MapCount; // Memory Map Count
void* __MapPtr; // Map Pointer
UI_Img_t* __Img; // Loaded image
} __Private; // Don't mess with me
};
/* WL_WADFile_t -- A lite WAD file */
struct WL_WADFile_s
{
/* Private Stuff You Don't Touch */
struct
{
// Validity
bool_t __IsValid; // Is this WAD valid?
bool_t __IsWAD; // Is this a WAD?
bool_t __IsIWAD; // Is this an IWAD?
// File related stuff
char __PathName[PATH_MAX]; // Path to WAD File
char __FileName[PATH_MAX]; // File name of WAD
char __DOSName[WLMAXDOSNAME]; // DOS Name of the WAD
void* __CFile; // File on disk
size_t __IndexOff; // Offset of index
size_t __Size; // Size of WAD
// Entries
uint32_t __TopHash; // Top 8-bits of hash (indexes)
Z_HashTable_t* __EntryHashes; // Hash table for find speed
// Public Data (per WAD basis)
struct
{
size_t __NumStuffs; // Amount of stuff there is
struct
{
uint32_t __Key; // Key to the data
void* __DataPtr; // Pointer to data
size_t __Size; // Size of data
WL_RemoveFunc_t __RemoveFunc; // Function that removes the data loaded (when WAD unloaded)
} __Stuff[WLMAXPRIVATEWADSTUFF]; // Private Stuff
} __PublicData; // Public data for perWAD data storage
// Linkage
bool_t __Linked; // Is the WAD virtually linked?
WL_WADFile_t* __PrevWAD; // Previous WAD
WL_WADFile_t* __NextWAD; // Next WAD
} __Private; // Don't mess with me
/* Public Stuff You Read From */
// Data Related Stuff
size_t TotalSize; // Size of all entries added together
uint32_t CheckSum[4]; // MD5 Sum
char CheckSumChars[33]; // MD5 Sum (As hex characters)
uint32_t SimpleSum[4]; // Simple Sum
char SimpleSumChars[33]; // Simple Sum (As hex characters)
// Entries
WL_WADEntry_t* Entries; // Entries in the WAD
WadIndex_t NumEntries; // Number of entries
// Virtual Linkage
WL_WADFile_t* PrevVWAD; // Previous virtual WAD
WL_WADFile_t* NextVWAD; // Next virtual WAD
// Attached WADs
WL_WADFile_t** Attached; // WADs attached
size_t NumAttached; // Number of attached WADs
};
/* Define WL_ES_t */
#if !defined(__REMOOD_WLEST_DEFINED)
typedef struct WL_ES_s WL_ES_t;
#define __REMOOD_WLEST_DEFINED
#endif
/*** PROTOTYPES ***/
const char* WL_BaseNameEx(const char* const a_File);
bool_t WL_ValidExt(const char* const a_File);
// WAD Handling
void WL_Init(void);
const WL_WADFile_t* WL_OpenWAD(const char* const a_PathName, const char* const a_MD5);
void WL_AttachWAD(const WL_WADFile_t* const a_WAD, const WL_WADFile_t* a_OtherWAD);
void WL_CloseWAD(const WL_WADFile_t* const a_WAD);
bool_t WL_LocateWAD(const char* const a_Name, const char* const a_MD5, char* const a_OutPath, const size_t a_OutSize);
const char* const WL_GetWADName(const WL_WADFile_t* const a_WAD, const bool_t a_NonDOSName);
const WL_WADFile_t* WL_IterateVWAD(const WL_WADFile_t* const a_WAD, const bool_t a_Forwards);
void WL_PushWAD(const WL_WADFile_t* const a_WAD);
const WL_WADFile_t* WL_PopWAD(void);
void WL_CloseNotStacked(void);
bool_t WL_LockOCCB(const bool_t a_DoLock);
bool_t WL_RegisterOCCB(WL_OrderCBFunc_t const a_Func, const uint8_t a_Order);
bool_t WL_RegisterPDC(const uint32_t a_Key, const uint8_t a_Order, WL_PCCreatorFunc_t const a_CreatorFunc, WL_RemoveFunc_t const a_RemoveFunc);
void* WL_GetPrivateData(const WL_WADFile_t* const a_WAD, const uint32_t a_Key, size_t* const a_SizePtr);
// Entry Handling
#define WL_BasicFind(n) (WL_FindEntry(NULL, 0, (n)))
#define WL_BasicFindF(b) (WL_FindEntry(NULL, WLFF_FORWARDS, (n)))
const WL_WADEntry_t* WL_FindEntry(const WL_WADFile_t* const a_BaseSearch, const uint32_t a_Flags, const char* const a_Name);
uintptr_t WL_TranslateEntry(const WadIndex_t a_GlobalIndex, const WL_WADFile_t* const a_Entry);
size_t WL_ReadData(const WL_WADEntry_t* const a_Entry, const size_t a_Offset, void* const a_Out, const size_t a_OutSize);
// Entry Memory Mapping
void* WL_MapEntry(const WL_WADEntry_t* const a_Entry);
void WL_UnMapEntry(const WL_WADEntry_t* const a_Entry);
// WAD Stream Buffer
WL_ES_t* WL_StreamOpen(const WL_WADEntry_t* const a_Entry);
void WL_StreamClose(WL_ES_t* const a_Stream);
const WL_WADEntry_t* WL_StreamGetEntry(WL_ES_t* const a_Stream);
uint32_t WL_StreamTell(WL_ES_t* const a_Stream);
uint32_t WL_StreamSeek(WL_ES_t* const a_Stream, const uint32_t a_NewPos, const bool_t a_End);
bool_t WL_StreamEOF(WL_ES_t* const a_Stream);
size_t WL_StreamRawRead(WL_ES_t* const a_Stream, const size_t a_Offset, void* const a_Out, const size_t a_OutSize);
int8_t WL_Sri8(WL_ES_t* const a_Stream);
int16_t WL_Sri16(WL_ES_t* const a_Stream);
int32_t WL_Sri32(WL_ES_t* const a_Stream);
uint8_t WL_Sru8(WL_ES_t* const a_Stream);
uint16_t WL_Sru16(WL_ES_t* const a_Stream);
uint32_t WL_Sru32(WL_ES_t* const a_Stream);
int16_t WL_Srli16(WL_ES_t* const a_Stream);
int32_t WL_Srli32(WL_ES_t* const a_Stream);
uint16_t WL_Srlu16(WL_ES_t* const a_Stream);
uint32_t WL_Srlu32(WL_ES_t* const a_Stream);
bool_t WL_StreamCheckUnicode(WL_ES_t* const a_Stream);
char WL_Src(WL_ES_t* const a_Stream);
size_t WL_Srl(WL_ES_t* const a_Stream, char* const a_Buf, const size_t a_Size);
/****************************
*** EXTENDED WAD HANDLING ***
****************************/
/*** STRUCTURES ***/
// Since I hid WX_ from the start, they can easily adapt to WL!
typedef WL_WADFile_t WX_WADFile_t;
typedef WL_WADEntry_t WX_WADEntry_t;
/*** PROTOTYPES ***/
WX_WADEntry_t* __REMOOD_DEPRECATED WX_EntryForName(WX_WADFile_t* const a_WAD, const char* const a_Name, const bool_t a_Forwards);
void* __REMOOD_DEPRECATED WX_CacheEntry(WX_WADEntry_t* const a_Entry);
size_t __REMOOD_DEPRECATED WX_GetEntrySize(WX_WADEntry_t* const a_Entry);
/*** THE LAST REMAINING FUNCTION ***/
size_t W_InitMultipleFiles(char** filenames);
#endif /* __W_WAD_H__ */