Source release of Wolfenstein 3D Classic Platinum for iOS, 2.1

This commit is contained in:
Travis Bradshaw
2012-01-31 17:08:50 -06:00
parent 16304944b4
commit d7fff51d7d
235 changed files with 64191 additions and 1418 deletions

View File

@@ -0,0 +1,359 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* adlib.c: Interface to adlib hardware.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* Portion of this code was derived from Wolfenstein3-D, and was originally
* written by Id Software, Inc.
*
* Portion of this code was derived from code written by DarkOne the Hacker.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include "adlib.h"
#include "fmopl.h"
#include "../../../common/arch.h"
#include "../../../common/common_utils.h"
#include "../memory/memory.h"
#define OPL_INTERNAL_FREQ 3600000 // The OPL operates at 3.6MHz
#define OPL_NUM_CHIPS 1 // Number of OPL chips
#define ADLIB_FREQ 22050 // in Hz
// Registers for the AdLib card
#define alFMStatus 0x388 // Read
#define alFMAddr 0x388 // Write
#define alFMData 0x389 // Write
// Register addresses
// Operator stuff
#define alChar 0x20
#define alScale 0x40
#define alAttack 0x60
#define alSus 0x80
#define alWave 0xe0
// Channel stuff
#define alFreqL 0xa0
#define alFreqH 0xb0
#define alFeedCon 0xc0
// Global stuff
#define alEffects 0xbd
// This table maps channel numbers to carrier and modulator op cells
PRIVATE W8 carriers[ 9 ] = { 3, 4, 5,11,12,13,19,20,21 },
modifiers[ 9 ] = { 0, 1, 2, 8, 9,10,16,17,18 };
PRIVATE FM_OPL *hAdLib = NULL;
/*
-----------------------------------------------------------------------------
Function: ADLIB_Init() -Start adlib hardware.
Parameters: Nothing.
Returns: 1 on success, otherwise 0.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC _boolean ADLIB_Init( W32 freq )
{
hAdLib = OPLCreate( OPL_TYPE_YM3812, OPL_INTERNAL_FREQ, freq );
if( hAdLib == NULL )
{
printf( "Could not create AdLib OPL Emulator\n" );
return false;
}
OPLWrite( hAdLib, 0x01, 0x20 ); /* Set WSE=1 */
OPLWrite( hAdLib, 0x08, 0x00 ); /* Set CSM=0 & SEL=0 */
return true;
}
/*
-----------------------------------------------------------------------------
Function: ADLIB_Init() -Shutdown adlib hardware.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void ADLIB_Shutdown( void )
{
OPLDestroy( hAdLib );
}
/*
-----------------------------------------------------------------------------
Function: ADLIB_SetFXInst() -Shutdown adlib hardware.
Parameters: inst -[in] Valid pointer to Instrument structure.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void ADLIB_SetFXInst( Instrument *inst )
{
W8 c, m;
m = modifiers[ 0 ];
c = carriers[ 0 ];
OPLWrite( hAdLib, m + alChar, inst->mChar );
OPLWrite( hAdLib, m + alScale, inst->mScale );
OPLWrite( hAdLib, m + alAttack, inst->mAttack );
OPLWrite( hAdLib, m + alSus, inst->mSus );
OPLWrite( hAdLib, m + alWave, inst->mWave );
OPLWrite( hAdLib, c + alChar, inst->cChar );
OPLWrite( hAdLib, c + alScale, inst->cScale );
OPLWrite( hAdLib, c + alAttack, inst->cAttack );
OPLWrite( hAdLib, c + alSus, inst->cSus );
OPLWrite( hAdLib, c + alWave, inst->cWave );
OPLWrite( hAdLib, alFeedCon, 0 );
}
/*
-----------------------------------------------------------------------------
Function: ADLIB_DecodeSound() -Decode adlib sound.
Parameters: sound -[in] Valid pointer to AdLibSound structure.
buffer -[in/out] Hold decoded sound data.
length -[out] Length of sound data.
Returns: 1 on success, otherwise 0.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC W8 ADLIB_DecodeSound( AdLibSound *sound, W8 *buffer, W32 *length )
{
Instrument inst;
W32 alLengthLeft;
W32 alBlock;
W8 *alSound, s;
W16 *ptr;
inst = sound->inst;
alBlock = ( (sound->block & 7) << 2 ) | 0x20;
alLengthLeft= *((PW32)sound->common.length);
alSound = sound->data;
*length = alLengthLeft * 157 * 2; // 157[.5] = 22050 / 140
if( *length > MAX_WAV_SIZE )
{
return 0;
}
ptr = (PW16) buffer;
OPLWrite( hAdLib, alFreqL, 0 );
OPLWrite( hAdLib, alFreqH, 0 );
ADLIB_SetFXInst( &inst );
while( alLengthLeft )
{
s = *alSound++;
if( ! s )
{
OPLWrite( hAdLib, alFreqH+0, 0 );
}
else
{
OPLWrite( hAdLib, alFreqL+0, s );
OPLWrite( hAdLib, alFreqH+0, alBlock );
}
if( ! ( --alLengthLeft ) )
{
OPLWrite( hAdLib, alFreqH+0, 0 );
}
YM3812UpdateOne( hAdLib, ptr, 157 );
ptr += 157;
}
return 1;
}
W16 *sqHack, *sqHackPtr;
W32 sqHackLen, sqHackSeqLen;
W32 sqHackTime;
W32 alTimeCount;
#define ADLIB_MUSIC_SPEED 44100
#define ADLIB_MUSIC_BYPS (ADLIB_MUSIC_SPEED*2) // bytes per second (16 bit)
typedef struct
{
W16 length;
W16 values[ 1 ];
} musicGroup_t;
musicGroup_t *music;
/*
-----------------------------------------------------------------------------
Function: ADLIB_LoadMusic() -Setup music decoder.
Parameters: musbuffer -[in] musicGroup_t data structure.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void ADLIB_LoadMusic( void *musbuffer )
{
music = (musicGroup_t *)musbuffer;
sqHackPtr = music->values;
sqHackLen = music->length;
sqHackTime = alTimeCount = 0;
}
/*
-----------------------------------------------------------------------------
Function: ADLIB_UpdateMusic() -Decode adlib music sound.
Parameters: size -[in] Number of bytes to write to buffer.
buffer -[in/out] Hold decoded sound data.
Returns: 1 on success, otherwise 0.
Notes: Data written to buffer is 44100/16/mono
-----------------------------------------------------------------------------
*/
PUBLIC W32 ADLIB_UpdateMusic( W32 size, void *buffer )
{
W8 *al; //[2] {a, v} (register, value)
W16 *ptr;
W32 n;
W32 AdLibTicks;
_boolean flag = false;
AdLibTicks = size;
ptr = (PW16)buffer;
for( n = 0 ; n < AdLibTicks; ++n )
{
while( sqHackLen && (sqHackTime <= alTimeCount) )
{
al = (PW8)sqHackPtr++;
sqHackTime = alTimeCount + *sqHackPtr++;
OPLWrite( hAdLib, al[ 0 ], al[ 1 ] );
sqHackLen -= 4;
}
alTimeCount++;
// now we'll get AdLib Output!
YM3812UpdateOne( hAdLib, ptr, 63 );
ptr += 63;
if( sqHackLen <= 0 )
{
return (long)ptr - (long)buffer;
}
}
return AdLibTicks * ADLIB_MUSIC_BYPS / 700;
}
/*
-----------------------------------------------------------------------------
Function: ADLIB_getLength() -Get music length in milliseconds.
Parameters: musbuffer -[in] musicGroup_t data structure.
Returns: On success length in milliseconds.
Notes: Data written to buffer is 44100/16/mono
-----------------------------------------------------------------------------
*/
PUBLIC W32 ADLIB_getLength( void *musbuffer )
{
W16 *Ptr, Len;
W32 Time;
W32 alTime;
Ptr = ((musicGroup_t*)musbuffer)->values;
Len = ((musicGroup_t*)musbuffer)->length;
Time = alTime = 0;
for( ; ; )
{
while( Len && Time <= alTime )
{
Ptr++;
Time = alTime + *Ptr++;
Len -= 4;
}
alTime++;
if( Len <= 0 )
{
break;
}
}
return alTime * 1000 / 700; // in milliseconds
}

View File

@@ -0,0 +1,90 @@
/*
Copyright (C) 2004 Michael Liebscher
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* adlib.h: Interface to adlib hardware.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Wolfenstein 3-D, and was originally
* written by Id Software, Inc.
*
*/
/*
Notes:
This module is implemented by adlib.c
*/
#ifndef __ADLIB_H__
#define __ADLIB_H__
#include "../../../common/arch.h"
#define MAX_WAV_SIZE 100000
typedef struct
{
W8 mChar, cChar,
mScale, cScale,
mAttack, cAttack,
mSus, cSus,
mWave, cWave,
nConn,
// These are only for Muse - these bytes are really unused
voice,
mode,
unused[ 3 ];
} Instrument;
typedef struct
{
char length[4];
char priority[2];
} SoundCommon;
typedef struct
{
SoundCommon common;
Instrument inst;
W8 block;
W8 data[ 1 ];
} AdLibSound;
extern W8 ADLIB_Init();
extern void ADLIB_Shutdown();
extern W8 ADLIB_DecodeSound( AdLibSound *sound, W8 *buffer, W32 *length );
#endif /* __ADLIB_H__ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,134 @@
/* tab setting : 4
*
* FM OPL2 synth
*
* Copyright (C) 1999,2000 Tatsuyuki Satoh , MultiArcadeMachineEmulator development
* Modified for Wolfenstein 3D by Steven Fuller
* Future Modifications by DarkOne for WolfGL! (wolfgl.narod.ru)
*/
#ifndef __FMOPL_H_
#define __FMOPL_H_
// Register addresses
// Operator stuff
#define alChar 0x20
#define alScale 0x40
#define alAttack 0x60
#define alSus 0x80
#define alWave 0xe0
// Channel stuff
#define alFreqL 0xa0
#define alFreqH 0xb0
#define alFeedCon 0xc0
// Global stuff
#define alEffects 0xbd
#define OPL_OUTPUT_BIT 16
typedef unsigned char UINT8; /* unsigned 8bit */
typedef unsigned short UINT16; /* unsigned 16bit */
typedef unsigned long UINT32; /* unsigned 32bit */
typedef signed char INT8; /* signed 8bit */
typedef signed short INT16; /* signed 16bit */
typedef signed long INT32; /* signed 32bit */
#if (OPL_OUTPUT_BIT==16)
typedef INT16 OPLSAMPLE;
#endif
#if (OPL_OUTPUT_BIT==8)
typedef unsigned char OPLSAMPLE;
#endif
/* ---------- OPL one of slot ---------- */
typedef struct fm_opl_slot
{
INT32 TL; /* total level :TL << 8 */
INT32 TLL; /* adjusted now TL */
UINT8 KSR; /* key scale rate :(shift down bit) */
INT32 *AR; /* attack rate :&AR_TABLE[AR<<2] */
INT32 *DR; /* decay rate :&DR_TALBE[DR<<2] */
INT32 SL; /* sustin level :SL_TALBE[SL] */
INT32 *RR; /* release rate :&DR_TABLE[RR<<2] */
UINT8 ksl; /* keyscale level :(shift down bits) */
UINT8 ksr; /* key scale rate :kcode>>KSR */
UINT32 mul; /* multiple :ML_TABLE[ML] */
UINT32 Cnt; /* frequency count : */
UINT32 Incr; /* frequency step : */
/* envelope generator state */
UINT8 eg_typ; /* envelope type flag */
UINT8 evm; /* envelope phase */
INT32 evc; /* envelope counter */
INT32 eve; /* envelope counter end point */
INT32 evs; /* envelope counter step */
INT32 evsa; /* envelope step for AR :AR[ksr] */
INT32 evsd; /* envelope step for DR :DR[ksr] */
INT32 evsr; /* envelope step for RR :RR[ksr] */
/* LFO */
UINT8 ams; /* ams flag */
UINT8 vib; /* vibrate flag */
/* wave selector */
INT32 **wavetable;
} OPL_SLOT;
/* ---------- OPL one of channel ---------- */
typedef struct fm_opl_channel
{
OPL_SLOT SLOT[2];
UINT8 CON; /* connection type */
UINT8 FB; /* feed back :(shift down bit) */
INT32 *connect1; /* slot1 output pointer */
INT32 *connect2; /* slot2 output pointer */
INT32 op1_out[2]; /* slot1 output for selfeedback */
/* phase generator state */
UINT32 block_fnum; /* block+fnum : */
UINT8 kcode; /* key code : KeyScaleCode */
UINT32 fc; /* Freq. Increment base */
UINT32 ksl_base; /* KeyScaleLevel Base step */
UINT8 keyon; /* key on/off flag */
} OPL_CH;
/* OPL state */
typedef struct fm_opl_f {
UINT8 type; /* chip type */
int clock; /* master clock (Hz) */
int rate; /* sampling rate (Hz) */
double freqbase; /* frequency base */
UINT8 address; /* address register */
UINT32 mode; /* Reg.08 : CSM , notesel,etc. */
/* FM channel slots */
OPL_CH *P_CH; /* pointer of CH */
int max_ch; /* maximum channel */
/* Rythm sention */
UINT8 rythm; /* Rythm mode , key flag */
INT32 AR_TABLE[75]; /* attack rate tables */
INT32 DR_TABLE[75]; /* decay rate tables */
UINT32 FN_TABLE[1024]; /* fnumber -> increment counter */
/* LFO */
INT32 *ams_table;
INT32 *vib_table;
INT32 amsCnt;
INT32 amsIncr;
INT32 vibCnt;
INT32 vibIncr;
/* wave selector enable flag */
UINT8 wavesel;
} FM_OPL;
/* ---------- Generic interface section ---------- */
#define OPL_TYPE_YM3812 0
FM_OPL *OPLCreate(int type, int clock, int rate);
void OPLDestroy(FM_OPL *OPL);
void OPLResetChip(FM_OPL *OPL);
void OPLWrite(FM_OPL *OPL,int a,int v);
unsigned char OPLRead(FM_OPL *OPL,int a);
void YM3812UpdateOne(FM_OPL *OPL, void *buffer, int length);
#endif /* __FMPOL_H */
/* end of file */

View File

@@ -0,0 +1,383 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* file.c: Portable file system services.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#include <string.h>
#include <time.h>
#include "file.h"
#include "../../../common/common_utils.h"
#include "../string/com_string.h"
#include "../memory/memory.h"
/*
-----------------------------------------------------------------------------
Function: DOSTIME -Convert the date y/n/d and time h:m:s to a four byte
DOS date and time (date in high two bytes, time in low
two bytes).
Parameters:
y -[in] year
c -[in] month
d -[in] day
h -[in] hour
m -[in] minute
s -[in] second
Returns: dos time
Notes:
-----------------------------------------------------------------------------
*/
// dos time start date is January 1, 1980
#define DOSTIME_STARTDATE 0x00210000L
#define DOSTIME( y, c, d, h, m, s ) ( ((y) < 1980) ? DOSTIME_STARTDATE : (((W32)(y) - 1980) << 25) | ((W32)(c) << 21) | ((W32)(d) << 16) | ((W32)(h) << 11) | ((W32)(m) << 5) | ((W32)(s) >> 1) )
/*
-----------------------------------------------------------------------------
Function: UnixTimeToDosTime -Converts Unix time_t into DOS format.
Parameters:
t -[in] unix time to convert.
Returns:
Unix time_t in DOS format, rounded up to the next two second
boundary.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC W32 UnixTimeToDosTime( time_t *t )
{
time_t t_even;
struct tm *s;
// Round up to even seconds.
t_even = (time_t)(((W32)(*t) + 1) & (~1));
s = localtime( &t_even );
if( s == (struct tm *)NULL )
{
// time conversion error; use current time instead
t_even = (time_t)(((W32)time(NULL) + 1) & (~1));
s = localtime( &t_even );
}
return DOSTIME( s->tm_year + 1900, s->tm_mon + 1, s->tm_mday,
s->tm_hour, s->tm_min, s->tm_sec );
}
/////////////////////////////////////////////////////////////////////
//
// File path/name manipulation
//
/////////////////////////////////////////////////////////////////////
PUBLIC char *FS_SkipPath( char *pathname )
{
char *last;
last = pathname;
while( *pathname )
{
if( *pathname == '/' )
{
last = pathname + 1;
}
pathname++;
}
return last;
}
PUBLIC void FS_StripExtension( char *in, char *out )
{
while (*in && *in != '.')
*out++ = *in++;
*out = 0;
}
PUBLIC char *FS_FileExtension( char *in )
{
static char exten[ 8 ];
int i;
while (*in && *in != '.')
in++;
if (!*in)
return "";
in++;
for (i=0 ; i<7 && *in ; i++,in++)
exten[i] = *in;
exten[i] = 0;
return exten;
}
PUBLIC void FS_FileBase( char *in, char *out )
{
char *s, *s2;
s = in + strlen( in ) - 1;
while( s != in && *s != '.' )
{
s--;
}
for( s2 = s ; s2 != in && *s2 != '/' ; s2-- )
{
;
}
if( s - s2 < 2 )
{
out[ 0 ] = 0;
}
else
{
s--;
strncpy( out, s2 + 1, s - s2 );
out[ s - s2 ] = 0;
}
}
PUBLIC void FS_FilePath( char *in, char *out )
{
char *s;
s = in + strlen(in) - 1;
while (s != in && *s != '/')
s--;
strncpy (out,in, s-in);
out[s-in] = '\0';
}
/////////////////////////////////////////////////////////////////////
//
// File I/O functions
//
/////////////////////////////////////////////////////////////////////
/*
-----------------------------------------------------------------------------
Function: FS_FileLength() -Calculate file position.
Parameters: filestream -[in] Pointer to valid FILE structure.
Returns: The position as an offset relative to the beginning of
the stream.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC SW32 FS_FileLength( FILE *filestream )
{
SW32 pos;
SW32 end;
pos = ftell( filestream );
fseek( filestream, 0, SEEK_END );
end = ftell( filestream );
fseek( filestream, pos, SEEK_SET );
return end;
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void FS_Read( void *buffer, int len, FILE *f )
{
int block, remaining;
int read;
W8 *buf;
int tries;
buf = (PW8)buffer;
// read in chunks for progress bar
remaining = len;
tries = 0;
#define MAX_READ 0x10000 // read in blocks of 64k
while( remaining )
{
block = remaining;
if( block > MAX_READ )
{
block = MAX_READ;
}
read = fread( buf, 1, block, f );
if( read == 0 )
{
// we might have been trying to read from a CD
if( ! tries )
{
tries = 1;
}
else
{
printf( "FS_Read: 0 bytes read" );
}
}
if( read == -1 )
{
printf( "FS_Read: -1 bytes read" );
}
remaining -= read;
buf += read;
}
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC SW32 FS_FOpenFile( const char *filename, FILE **file )
{
*file = fopen( filename, "rb" );
if( ! *file )
{
*file = NULL;
return -1;
}
return FS_FileLength( *file );
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC SW32 FS_LoadFile( const char *path, void **buffer )
{
FILE *fhandle;
W8 *buf;
long length;
buf = NULL; // quiet compiler warning
// look for it in the filesystem or pack files
length = FS_FOpenFile( path, &fhandle );
if( ! fhandle )
{
if( buffer )
{
*buffer = NULL;
}
return -1;
}
if( ! buffer )
{
fclose( fhandle );
return length;
}
buf = MM_MALLOC( length );
*buffer = buf;
FS_Read( buf, length, fhandle );
fclose( fhandle );
return length;
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void FS_FreeFile( void *buffer )
{
MM_FREE( buffer );
}

View File

@@ -0,0 +1,118 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* file.h: Access methods to file system services.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
/*
Notes:
This module is implemented by file.c
Non-portable methods are implemented in:
win32/win_file.c for Windows
unix/unix_file.c for unix
*/
#ifndef __FILE_H__
#define __FILE_H__
#include <stdio.h>
#include <time.h>
#include "../../../common/arch.h"
// filename/path manipulation
extern char *FS_SkipPath( char *pathname );
extern void FS_StripExtension( char *in, char *out );
extern char *FS_FileExtension( char *in );
extern void FS_FileBase( char *in, char *out );
extern void FS_FilePath( char *in, char *out );
extern W32 UnixTimeToDosTime( time_t *t );
/////////////////////////////////////////////////////////////////////
//
// PORTABLE FILE SYSTEM SERVICES
//
/////////////////////////////////////////////////////////////////////
extern SW32 FS_FileLength( FILE *filestream );
extern void FS_Read( void *buffer, int len, FILE *f );
extern SW32 FS_FOpenFile( const char *filename, FILE **file );
extern SW32 FS_LoadFile( const char *path, void **buffer );
extern void FS_FreeFile( void *buffer );
/////////////////////////////////////////////////////////////////////
//
// NON-PORTABLE FILE SYSTEM SERVICES
//
/////////////////////////////////////////////////////////////////////
extern W8 FS_Mkdir( const char *dirname );
extern W8 FS_ChangeCurrentDirectory( const char *path );
extern _boolean FS_DeleteFile( const char *filename );
extern _boolean FS_RemoveDirectory( const char *pathname );
// directory/file attributes
#define FA_ARCH 0x01
#define FA_HIDDEN 0x02
#define FA_RDONLY 0x04
#define FA_DIR 0x08
#define FA_SYSTEM 0x10
// pass in an attribute mask of things you wish to REJECT
extern char *FS_FindFirst( const char *path, W32 musthave, W32 canthave );
extern char *FS_FindNext( W32 musthave, W32 canthave );
extern void FS_FindClose( void );
struct filestats
{
W32 attributes; /* The following attributes are defined as FA_ARCH to FA_SYSTEM*/
W32 creationtime; /* Time when file data last modified */
W32 lastaccesstime; /* Time when file data last accessed */
W32 lastwritetime; /* Time when file data last modified */
};
extern _boolean FS_GetFileAttributes( const char *filename, struct filestats *fs );
#endif /* __FILE_H__ */

View File

@@ -0,0 +1,183 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include "glob.h"
/* Like glob_match, but match PATTERN against any final segment of TEXT. */
static int glob_match_after_star(char *pattern, char *text)
{
register char *p = pattern, *t = text;
register char c, c1;
while ((c = *p++) == '?' || c == '*')
if (c == '?' && *t++ == '\0')
return 0;
if (c == '\0')
return 1;
if (c == '\\')
c1 = *p;
else
c1 = c;
while (1) {
if ((c == '[' || *t == c1) && glob_match(p - 1, t))
return 1;
if (*t++ == '\0')
return 0;
}
}
/* Return nonzero if PATTERN has any special globbing chars in it. */
static int glob_pattern_p(char *pattern)
{
register char *p = pattern;
register char c;
int open = 0;
while ((c = *p++) != '\0')
switch (c) {
case '?':
case '*':
return 1;
case '[': /* Only accept an open brace if there is a close */
open++; /* brace to match it. Bracket expressions must be */
continue; /* complete, according to Posix.2 */
case ']':
if (open)
return 1;
continue;
case '\\':
if (*p++ == '\0')
return 0;
}
return 0;
}
/* Match the pattern PATTERN against the string TEXT;
return 1 if it matches, 0 otherwise.
A match means the entire string TEXT is used up in matching.
In the pattern string, `*' matches any sequence of characters,
`?' matches any character, [SET] matches any character in the specified set,
[!SET] matches any character not in the specified set.
A set is composed of characters or ranges; a range looks like
character hyphen character (as in 0-9 or A-Z).
[0-9a-zA-Z_] is the set of characters allowed in C identifiers.
Any other character in the pattern must be matched exactly.
To suppress the special syntactic significance of any of `[]*?!-\',
and match the character exactly, precede it with a `\'.
*/
int glob_match(char *pattern, char *text)
{
register char *p = pattern, *t = text;
register char c;
while ((c = *p++) != '\0')
switch (c) {
case '?':
if (*t == '\0')
return 0;
else
++t;
break;
case '\\':
if (*p++ != *t++)
return 0;
break;
case '*':
return glob_match_after_star(p, t);
case '[':
{
register char c1 = *t++;
int invert;
if (!c1)
return (0);
invert = ((*p == '!') || (*p == '^'));
if (invert)
p++;
c = *p++;
while (1) {
register char cstart = c, cend = c;
if (c == '\\') {
cstart = *p++;
cend = cstart;
}
if (c == '\0')
return 0;
c = *p++;
if (c == '-' && *p != ']') {
cend = *p++;
if (cend == '\\')
cend = *p++;
if (cend == '\0')
return 0;
c = *p++;
}
if (c1 >= cstart && c1 <= cend)
goto match;
if (c == ']')
break;
}
if (!invert)
return 0;
break;
match:
/* Skip the rest of the [...] construct that already matched. */
while (c != ']') {
if (c == '\0')
return 0;
c = *p++;
if (c == '\0')
return 0;
else if (c == '\\')
++p;
}
if (invert)
return 0;
break;
}
default:
if (c != *t++)
return 0;
}
return *t == '\0';
}

View File

@@ -0,0 +1,21 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
int glob_match( char *pattern, char *text );

View File

@@ -0,0 +1,337 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* unix_file.c: Handles non-portable file services.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <string.h>
#include "../../../../common/arch.h"
#include "../../../../common/common_utils.h"
#include "../../string/com_string.h"
#include "glob.h"
#include "../file.h"
PRIVATE char findbase[ 128 ];
PRIVATE char findpath[ 128 ];
PRIVATE char findpattern[ 128 ];
PRIVATE DIR *fdir;
/*
-----------------------------------------------------------------------------
Function: FS_Mkdir() -Creates a new directory.
Parameters: dirname -[in] Pointer to a NUL-terminated string that specifies
the path of the directory to be created.
Returns: On success nonzero, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC W8 FS_Mkdir( const char *dirname )
{
int ret_val = mkdir( dirname, S_IRUSR | S_IWUSR | S_IXUSR );
if( ret_val == -1 && errno == EEXIST )
{
return 1;
}
return (W8)(! ret_val);
}
/*
-----------------------------------------------------------------------------
Function: FS_ChangeCurrentDirectory() -Changes the current directory
Parameters: path -[in] Pointer to a NUL-terminated string that specifies
the path to the new directory.
Returns: On success nonzero, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC W8 FS_ChangeCurrentDirectory( const char *path )
{
return ! chdir( path );
}
/*
-----------------------------------------------------------------------------
Function: FS_GetFileAttributes() -Retrieves attributes for a specified file
or directory.
Parameters: filename -[in] Pointer to a NUL-terminated string that
specifies a file or directory.
fs -[in] Pointer to a filestats structure that receives the
attribute information.
Returns: On success true, otherwise false.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC _boolean FS_GetFileAttributes( const char *filename, struct filestats *fs )
{
struct stat st;
fs->attributes = 0;
if( stat( filename, &st ) == -1 )
{
return false;
}
if( st.st_mode & S_IFDIR )
{
fs->attributes |= FA_DIR;
}
fs->creationtime = st.st_ctime;
fs->lastaccesstime = st.st_atime;
fs->lastwritetime = st.st_ctime;
return true;
}
/*
-----------------------------------------------------------------------------
Function: CompareAttributes() -Compare directory and file attributes.
Parameters: path -[in] Specifies the path to compare file attributes.
musthave -[in] File or directory must have these attributes.
canthave- [in] File or directory can not have these attributes.
Returns: On success true, otherwise false.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE _boolean CompareAttributes( const char *path, W32 musthave, W32 canthave )
{
struct stat st;
if( stat( path, &st ) == -1 )
{
return false;
}
if( ( st.st_mode & S_IFDIR ) && ( canthave & FA_DIR ) )
{
return false;
}
if( ( musthave & FA_DIR ) && !( st.st_mode & S_IFDIR ) )
{
return false;
}
return true;
}
/*
-----------------------------------------------------------------------------
Function: FS_FindFirstFile() -Searches a directory for a file.
Parameters: path -[in] Pointer to a NUL-terminated string that specifies
a valid directory or path and file name.
musthave -[in] File or directory must have these attributes.
canthave- [in] File or directory can not have these attributes.
Returns: On success string of file name or directory, otherwise NULL.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *FS_FindFirst( const char *path, W32 musthave, W32 canthave )
{
struct dirent *d;
char *p;
if( fdir )
{
printf( "FS_FindFirst without close\n" );
return NULL;
}
FS_FilePath( path, findbase );
cs_strlcpy( findpattern, FS_SkipPath( path ), sizeof( findpattern ) );
if( ! *findbase )
{
if( (fdir = opendir( "." )) == NULL )
{
return NULL;
}
}
else
{
if( (fdir = opendir( findbase )) == NULL )
{
return NULL;
}
}
while( (d = readdir( fdir )) != NULL )
{
if( ! *findpattern || glob_match( findpattern, d->d_name ) )
{
if( ! *findbase )
{
cs_strlcpy( findpath, d->d_name, sizeof( findpath ) );
}
else
{
cs_snprintf( findpath, sizeof( findpath ), "%s/%s", findbase, d->d_name );
}
if( CompareAttributes( findpath, musthave, canthave ) )
{
return findpath;
}
}
}
return NULL;
}
/*
-----------------------------------------------------------------------------
Function: FS_FindNext -Continues a file search from a previous call to
the FS_FindFirst function.
Parameters: musthave -[in] File or directory must have these attributes.
canthave- [in] File or directory can not have these attributes.
Returns: On success string of file name or directory, otherwise NULL.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *FS_FindNext( W32 musthave, W32 canthave )
{
struct dirent *d;
if( fdir == NULL )
{
return NULL;
}
while( (d = readdir( fdir ) ) != NULL)
{
if( ! *findpattern || glob_match( findpattern, d->d_name ) )
{
if( ! *findbase )
{
cs_strlcpy( findpath, d->d_name, sizeof( findpath ) );
}
else
{
cs_snprintf( findpath, sizeof( findpath ), "%s/%s", findbase, d->d_name );
}
if( CompareAttributes( findpath, musthave, canthave ) )
{
return findpath;
}
}
}
return NULL;
}
/*
-----------------------------------------------------------------------------
Function: FS_FindClose() -Closes the search handle.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void FS_FindClose( void )
{
if( fdir )
{
closedir( fdir );
}
fdir = NULL;
}
/*
-----------------------------------------------------------------------------
Function: FS_DeleteFile() -Deletes an existing file.
Parameters: filename -[in] Pointer to a NUL-terminated string that
specifies the file to be deleted.
Returns: If successful the return value is nonzero, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC _boolean FS_DeleteFile( const char *filename )
{
return( ! unlink( filename ) );
}
/*
-----------------------------------------------------------------------------
Function: FS_RemoveDirectory() -Deletes an existing empty directory.
Parameters: pathname -[in] Pointer to a NUL-terminated string that
specifies the directory to be deleted.
Returns: If successful the return value is nonzero, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC _boolean FS_RemoveDirectory( const char *pathname )
{
return( ! rmdir( pathname ) );
}

View File

@@ -0,0 +1,398 @@
/*
Copyright (C) 2004 Michael Liebscher
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* win_file.c: Handles non-portable file services.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
*
*/
#include <windows.h>
#include <time.h>
#include "../file.h"
#include "../../string/com_string.h"
#include "../../../../common/arch.h"
#include "../../../../common/common_utils.h"
PRIVATE char findbase[ MAX_PATH ];
PRIVATE char findpath[ MAX_PATH ];
PRIVATE HANDLE FindHandle;
/*
-----------------------------------------------------------------------------
Function: FS_Mkdir() -Creates a new directory.
Parameters: dirname -[in] Pointer to a NUL-terminated string that specifies
the path of the directory to be created.
Returns: On success nonzero, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC W8 FS_Mkdir( const char *dirname )
{
BOOL ret_val = CreateDirectory( dirname, NULL );
if( ret_val == 0 && GetLastError() == ERROR_ALREADY_EXISTS )
{
return 1;
}
return (W8)ret_val;
}
/*
-----------------------------------------------------------------------------
Function: FS_ChangeCurrentDirectory() -Changes the current directory
Parameters: path -[in] Pointer to a NUL-terminated string that specifies
the path to the new directory.
Returns: On success nonzero, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC W8 FS_ChangeCurrentDirectory( const char *path )
{
return SetCurrentDirectory( path );
}
/*
-----------------------------------------------------------------------------
Function: FS_FileTimeToUnixTime() -Converts file time to UNIX time format.
Parameters: FILETIME -[in] Pointer to a FILETIME structure containing the
file time to convert to UNIX date and time format.
Returns: On success nonzero, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE W32 FS_FileTimeToUnixTime( FILETIME *ft )
{
time_t days;
SYSTEMTIME st;
static const W16 ydays[] =
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
if( ! FileTimeToSystemTime( ft, &st ) )
{
return 0;
}
// Protection from overflow
if( (ft->dwHighDateTime < 0x019DB1DEUL) ||
((ft->dwHighDateTime == 0x019DB1DEUL) &&
(ft->dwLowDateTime < 0xD53E8000UL)) )
{
return 0;
}
if( (ft->dwHighDateTime > 0x0236485EUL) ||
((ft->dwHighDateTime == 0x0236485EUL) &&
(ft->dwLowDateTime > 0xD4A5E980UL)) )
{
return 0;
}
#define leap(y) (((y)%4 == 0 && (y)%100 != 0) || (y)%400 == 0)
#define nleap(y) (((y)-1969)/4 - ((y)-1901)/100 + ((y)-1601)/400)
// set 'days' to the number of days into the year
days = st.wDay - 1 + ydays[ st.wMonth-1 ] + (st.wMonth > 2 && leap( st.wYear ));
// now set 'days' to the number of days since 1 Jan 1970
days += 365 * (time_t)(st.wYear - 1970) + (time_t)(nleap(st.wYear));
return (time_t)(86400L * days + 3600L * (time_t)st.wHour +
(time_t)(60 * st.wMinute + st.wSecond));
}
/*
-----------------------------------------------------------------------------
Function: FS_GetFileAttributes() -Retrieves attributes for a specified file
or directory.
Parameters: filename -[in] Pointer to a NUL-terminated string that
specifies a file or directory.
fs -[in] Pointer to a filestats structure that receives the
attribute information.
Returns: On success true, otherwise false.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC _boolean FS_GetFileAttributes( const char *filename, struct filestats *fs )
{
WIN32_FILE_ATTRIBUTE_DATA fdata;
fs->attributes = 0;
if( ! GetFileAttributesEx( filename, GetFileExInfoStandard, &fdata ) )
{
return false;
}
if( fdata.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE )
fs->attributes |= FA_ARCH;
if( fdata.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN )
fs->attributes |= FA_HIDDEN;
if( fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY )
fs->attributes |= FA_RDONLY;
if( fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
fs->attributes |= FA_DIR;
if( fdata.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM )
fs->attributes |= FA_SYSTEM;
// Convert FILETIME to UNIX time.
fs->creationtime = FS_FileTimeToUnixTime( &fdata.ftCreationTime );
fs->lastaccesstime = FS_FileTimeToUnixTime( &fdata.ftLastAccessTime );
fs->lastwritetime = FS_FileTimeToUnixTime( &fdata.ftLastWriteTime );
return true;
}
/*
-----------------------------------------------------------------------------
Function: CompareAttributes() -Compare directory and file attributes.
Parameters: found -[in] Specifies the file attributes of the file found.
musthave -[in] File or directory must have these attributes.
canthave- [in] File or directory can not have these attributes.
Returns: On success true, otherwise false.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE _boolean CompareAttributes( W32 found, W32 musthave, W32 canthave )
{
if( ( found & FILE_ATTRIBUTE_READONLY ) && ( canthave & FA_RDONLY ) )
return false;
if( ( found & FILE_ATTRIBUTE_HIDDEN ) && ( canthave & FA_HIDDEN ) )
return false;
if( ( found & FILE_ATTRIBUTE_SYSTEM ) && ( canthave & FA_SYSTEM ) )
return false;
if( ( found & FILE_ATTRIBUTE_DIRECTORY ) && ( canthave & FA_DIR ) )
return false;
if( ( found & FILE_ATTRIBUTE_ARCHIVE ) && ( canthave & FA_ARCH ) )
return false;
if( ( musthave & FA_RDONLY ) && !( found & FILE_ATTRIBUTE_READONLY ) )
return false;
if( ( musthave & FA_HIDDEN ) && !( found & FILE_ATTRIBUTE_HIDDEN ) )
return false;
if( ( musthave & FA_SYSTEM ) && !( found & FILE_ATTRIBUTE_SYSTEM ) )
return false;
if( ( musthave & FA_DIR ) && !( found & FILE_ATTRIBUTE_DIRECTORY ) )
return false;
if( ( musthave & FA_ARCH ) && !( found & FILE_ATTRIBUTE_ARCHIVE ) )
return false;
return true;
}
/*
-----------------------------------------------------------------------------
Function: FS_FindFirstFile() -Searches a directory for a file.
Parameters: path -[in] Pointer to a NUL-terminated string that specifies
a valid directory or path and file name.
musthave -[in] File or directory must have these attributes.
canthave- [in] File or directory can not have these attributes.
Returns: On success string of file name or directory, otherwise NULL.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *FS_FindFirst( const char *path, W32 musthave, W32 canthave )
{
WIN32_FIND_DATA FindFileData;
if( FindHandle )
{
printf( "FS_FindFirst without close\n" );
return NULL;
}
FS_FilePath( path, findbase );
FindHandle = FindFirstFile( path, &FindFileData );
if( FindHandle == INVALID_HANDLE_VALUE )
{
return NULL;
}
if( CompareAttributes( FindFileData.dwFileAttributes, musthave, canthave ) )
{
if( ! *findbase )
{
cs_strlcpy( findpath, FindFileData.cFileName, sizeof( findpath ) );
}
else
{
cs_snprintf( findpath, sizeof( findpath ), "%s/%s", findbase, FindFileData.cFileName );
}
return findpath;
}
return FS_FindNext( musthave, canthave );
}
/*
-----------------------------------------------------------------------------
Function: FS_FindNext -Continues a file search from a previous call to
the FS_FindFirst function.
Parameters: musthave -[in] File or directory must have these attributes.
canthave- [in] File or directory can not have these attributes.
Returns: On success string of file name or directory, otherwise NULL.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *FS_FindNext( W32 musthave, W32 canthave )
{
WIN32_FIND_DATA FindFileData;
if( FindHandle == INVALID_HANDLE_VALUE )
{
return NULL;
}
while( 1 )
{
if( FindNextFile( FindHandle, &FindFileData ) == 0 )
{
return NULL;
}
if( CompareAttributes( FindFileData.dwFileAttributes, musthave, canthave ) )
{
break;
}
}
if( ! *findbase )
{
cs_snprintf( findpath, sizeof( findpath ), "%s", FindFileData.cFileName );
}
else
{
cs_snprintf( findpath, sizeof( findpath ), "%s/%s", findbase, FindFileData.cFileName );
}
return findpath;
}
/*
-----------------------------------------------------------------------------
Function: FS_FindClose() -Closes the search handle.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void FS_FindClose( void )
{
if( FindHandle != INVALID_HANDLE_VALUE )
{
FindClose( FindHandle );
}
FindHandle = 0;
}
/*
-----------------------------------------------------------------------------
Function: FS_DeleteFile() -Deletes an existing file.
Parameters: filename -[in] Pointer to a NUL-terminated string that
specifies the file to be deleted.
Returns: If successful the return value is nonzero, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC _boolean FS_DeleteFile( const char *filename )
{
return DeleteFile( filename );
}
/*
-----------------------------------------------------------------------------
Function: FS_RemoveDirectory() -Deletes an existing empty directory.
Parameters: pathname -[in] Pointer to a NUL-terminated string that
specifies the directory to be deleted.
Returns: If successful the return value is nonzero, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC _boolean FS_RemoveDirectory( const char *pathname )
{
return RemoveDirectory( pathname );
}

2917
wolf3d/wolfextractor/hq2x.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,32 @@
/*
hq2x filter
----------------------------------------------------------
Copyright (C) 2003 MaxSt ( maxst@hiend3d.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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __HQ2X_H__
#define __HQ2X_H__
extern void InitLUTs( void );
extern void hq2x_32( unsigned char *pIn, unsigned char *pOut,
int Xres, int Yres, int BpL );
#endif /* __HQ2X_H__ */

View File

@@ -0,0 +1,531 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
Copyright (C) 1995 Spencer Kimball and Peter Mattis
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* tga.c: Handle Targa file format.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was
* originally written by id Software, Inc.
*
* Portion of this code was derived from The GIMP -- an image manipulation
* program, and was originally written by Spencer Kimball and Peter Mattis.
*/
#include <string.h>
#include <stdio.h>
#include "../../../common/arch.h"
#include "../memory/memory.h"
#include "../../../common/common_utils.h"
/*
-----------------------------------------------------------------------------
Function: rle_write -Run length encode scanline.
Parameters: fp -[in] Pointer to valid FILE structure.
buffer -[in] Scanline data.
width -[in] Image scanline width.
bytes -[in] Bytes per pixel.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void rle_write( FILE *fp,
W8 *buffer,
W32 width,
W32 bytes )
{
SW32 repeat = 0;
SW32 direct = 0;
W8 *from = buffer;
W32 x;
for( x = 1 ; x < width ; ++x )
{
if( memcmp( buffer, buffer + bytes, bytes ) )
{
/* next pixel is different */
if( repeat )
{
putc( 128 + repeat, fp );
fwrite( from, bytes, 1, fp );
from = buffer + bytes; /* point to first different pixel */
repeat = 0;
direct = 0;
}
else
{
direct += 1;
}
}
else
{
/* next pixel is the same */
if( direct )
{
putc( direct - 1, fp );
fwrite( from, bytes, direct, fp );
from = buffer; /* point to first identical pixel */
direct = 0;
repeat = 1;
}
else
{
repeat += 1;
}
}
if( repeat == 128 )
{
putc( 255, fp );
fwrite( from, bytes, 1, fp );
from = buffer + bytes;
direct = 0;
repeat = 0;
}
else if( direct == 128 )
{
putc( 127, fp );
fwrite( from, bytes, direct, fp );
from = buffer + bytes;
direct = 0;
repeat = 0;
}
buffer += bytes;
}
if( repeat > 0 )
{
putc( 128 + repeat, fp );
fwrite( from, bytes, 1, fp );
}
else
{
putc( direct, fp );
fwrite( from, bytes, direct + 1, fp );
}
}
/*
-----------------------------------------------------------------------------
Function: WriteTGA -Write targa image file.
Parameters: filename -[in] Name of TGA file to save as.
depth -[in] Bytes per pixel. (16, 24 or 32).
width -[in] Width of image.
height -[in] Height of image.
Data -[in] Raw image data.
upsideDown -[in] Is the data upside down? 1 yes, 0 no.
rle -[in] Run Length encode? 1 yes, 0 no.
Returns: 0 on error, otherwise 1.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC W8 WriteTGA( const char *filename, W16 bpp, W16 width, W16 height,
void *Data, W8 upsideDown, W8 rle )
{
W16 i, x, y, BytesPerPixel;
W8 *scanline;
W8 header[ 18 ];
FILE *filestream;
W8 *ptr = (PW8) Data;
W8 temp;
BytesPerPixel = bpp >> 3;
filestream = fopen( filename, "wb" );
if( filestream == NULL )
{
printf( "Could not open file (%s) for write!\n", filename );
return 0;
}
memset( header, 0, 18 );
header[2] = rle ? 10 : 2;
header[12] = width & 255; // width low
header[13] = width >> 8; // width high
header[14] = height & 255; // height low
header[15] = height >> 8; // height high
header[16] = bpp & 255; // pixel size
if( upsideDown )
{
header[17] |= 1 << 5; // Image Descriptor
}
fwrite( header, sizeof( W8 ), sizeof( header ), filestream );
scanline = (PW8) MM_MALLOC( width * BytesPerPixel );
if( scanline == NULL )
{
fclose( filestream );
return 0;
}
for( y = 0; y < height; ++y )
{
W32 k = 0;
for( i = 0; i < (width * BytesPerPixel); ++i )
{
scanline[ k++ ] = ptr[ (height - y - 1) * width * BytesPerPixel + i ];
}
if( bpp == 24 || bpp == 32 )
{
// swap rgb to bgr
for( x = 0 ; x < (width * BytesPerPixel) ; x += BytesPerPixel )
{
temp = scanline[ x ];
scanline[ x ] = scanline[ x + 2 ];
scanline[ x + 2 ] = temp;
}
}
if( rle )
{
rle_write( filestream, scanline, width, BytesPerPixel );
}
else
{
fwrite( scanline, sizeof( W8 ), width * BytesPerPixel, filestream );
}
}
MM_FREE( scanline );
fclose( filestream );
return 1;
}
//=======================================================================
typedef struct TargaHeader_s {
unsigned char id_length;
unsigned char colormap_type;
unsigned char image_type;
unsigned short colormap_index;
unsigned short colormap_length;
unsigned char colormap_size;
unsigned short x_origin;
unsigned short y_origin;
unsigned short width, height;
unsigned char pixel_size;
unsigned char attributes;
} TargaHeaeder_t;
static const int TGA_HEADER_SIZE = 18;
/*
========================
LoadTGAFromBuffer
Load a TGA from a buffer containing a TGA file.
========================
*/
int LoadTGAFromBuffer( const char *name, const W8 *buffer, const int bufferSize,
W8 **pic, int *width, int *height ) {
int columns, rows, numPixels;
size_t numBytes;
W8 *pixbuf;
int row, column;
const W8 *buf_p;
struct TargaHeader_s targa_header;
W8 *targa_rgba;
*pic = NULL;
buf_p = buffer;
targa_header.id_length = *buf_p++;
targa_header.colormap_type = *buf_p++;
targa_header.image_type = *buf_p++;
targa_header.colormap_index = *(short *)buf_p;
buf_p += 2;
targa_header.colormap_length = *(short *)buf_p;
buf_p += 2;
targa_header.colormap_size = *buf_p++;
targa_header.x_origin = *(short *)buf_p;
buf_p += 2;
targa_header.y_origin = *(short *)buf_p;
buf_p += 2;
targa_header.width = *(short *)buf_p;
buf_p += 2;
targa_header.height = *(short *)buf_p;
buf_p += 2;
targa_header.pixel_size = *buf_p++;
targa_header.attributes = *buf_p++;
if ( targa_header.image_type != 2 && targa_header.image_type != 10 && targa_header.image_type != 3 ) {
printf( "LoadTGA( %s ): Only type 2 (RGB), 3 (gray), and 10 (RGB) TGA images supported", name );
return false;
}
if ( targa_header.colormap_type != 0 ) {
printf( "LoadTGA( %s ): colormaps not supported", name );
return false;
}
if ( ( targa_header.pixel_size != 32 && targa_header.pixel_size != 24 ) && targa_header.image_type != 3 ) {
printf( "LoadTGA( %s ): Only 32 or 24 bit images supported (no colormaps)", name );
return false;
}
if ( targa_header.image_type == 2 || targa_header.image_type == 3 ) {
numBytes = targa_header.width * targa_header.height * ( targa_header.pixel_size >> 3 );
if ( numBytes > bufferSize - TGA_HEADER_SIZE - targa_header.id_length ) {
printf( "LoadTGA( %s ): incomplete file", name );
return false;
}
}
columns = targa_header.width;
rows = targa_header.height;
numPixels = columns * rows;
if ( width ) {
*width = columns;
}
if ( height ) {
*height = rows;
}
targa_rgba = (W8 *)malloc( numPixels*4 );
*pic = targa_rgba;
if ( targa_header.id_length != 0 ) {
buf_p += targa_header.id_length; // skip TARGA image comment
}
if ( targa_header.image_type == 2 || targa_header.image_type == 3 ) {
unsigned char red,green,blue,alphabyte;
switch( targa_header.pixel_size ) {
case 8:
// Uncompressed gray scale image
for( row = rows - 1; row >= 0; row-- ) {
pixbuf = targa_rgba + row*columns*4;
for( column = 0; column < columns; column++ ) {
blue = *buf_p++;
green = blue;
red = blue;
*pixbuf++ = red;
*pixbuf++ = green;
*pixbuf++ = blue;
*pixbuf++ = 255;
}
}
break;
case 24:
// Uncompressed RGB image
for( row = rows - 1; row >= 0; row-- ) {
pixbuf = targa_rgba + row*columns*4;
for( column = 0; column < columns; column++ ) {
blue = *buf_p++;
green = *buf_p++;
red = *buf_p++;
*pixbuf++ = red;
*pixbuf++ = green;
*pixbuf++ = blue;
*pixbuf++ = 255;
}
}
break;
case 32:
// Uncompressed RGBA image
for( row = rows - 1; row >= 0; row-- ) {
pixbuf = targa_rgba + row*columns*4;
for( column = 0; column < columns; column++ ) {
blue = *buf_p++;
green = *buf_p++;
red = *buf_p++;
alphabyte = *buf_p++;
*pixbuf++ = red;
*pixbuf++ = green;
*pixbuf++ = blue;
*pixbuf++ = alphabyte;
}
}
break;
default:
printf( "LoadTGA( %s ): illegal pixel_size '%d'", name, targa_header.pixel_size );
free( *pic );
*pic = NULL;
return false;
}
}
else if ( targa_header.image_type == 10 ) { // Runlength encoded RGB images
unsigned char red,green,blue,alphabyte,packetHeader,packetSize,j;
red = 0;
green = 0;
blue = 0;
alphabyte = 0xff;
for( row = rows - 1; row >= 0; row-- ) {
pixbuf = targa_rgba + row*columns*4;
for( column = 0; column < columns; ) {
packetHeader= *buf_p++;
packetSize = 1 + (packetHeader & 0x7f);
if ( packetHeader & 0x80 ) { // run-length packet
switch( targa_header.pixel_size ) {
case 24:
blue = *buf_p++;
green = *buf_p++;
red = *buf_p++;
alphabyte = 255;
break;
case 32:
blue = *buf_p++;
green = *buf_p++;
red = *buf_p++;
alphabyte = *buf_p++;
break;
default:
printf( "LoadTGA( %s ): illegal pixel_size '%d'", name, targa_header.pixel_size );
free( *pic );
*pic = NULL;
return false;
}
for( j = 0; j < packetSize; j++ ) {
*pixbuf++=red;
*pixbuf++=green;
*pixbuf++=blue;
*pixbuf++=alphabyte;
column++;
if ( column == columns ) { // run spans across rows
column = 0;
if ( row > 0) {
row--;
}
else {
goto breakOut;
}
pixbuf = targa_rgba + row*columns*4;
}
}
} else { // non run-length packet
for( j = 0; j < packetSize; j++ ) {
switch( targa_header.pixel_size ) {
case 24:
blue = *buf_p++;
green = *buf_p++;
red = *buf_p++;
*pixbuf++ = red;
*pixbuf++ = green;
*pixbuf++ = blue;
*pixbuf++ = 255;
break;
case 32:
blue = *buf_p++;
green = *buf_p++;
red = *buf_p++;
alphabyte = *buf_p++;
*pixbuf++ = red;
*pixbuf++ = green;
*pixbuf++ = blue;
*pixbuf++ = alphabyte;
break;
default:
printf( "LoadTGA( %s ): illegal pixel_size '%d'", name, targa_header.pixel_size );
free( *pic );
*pic = NULL;
return false;
}
column++;
if ( column == columns ) { // pixel packet run spans across rows
column = 0;
if ( row > 0 ) {
row--;
}
else {
goto breakOut;
}
pixbuf = targa_rgba + row*columns*4;
}
}
}
}
breakOut: ;
}
}
if ( (targa_header.attributes & (1<<5)) ) { // image flp bit
// R_VerticalFlip( *pic, *width, *height );
}
return true;
}
/*
========================
LoadTGA
Load TGA directly from a file.
========================
*/
int LoadTGA( const char *name, W8 **pic, int *width, int *height ) {
FILE *f = fopen( name, "rb" );
int len;
W8 *buf;
int ret;
if ( !f ) {
return 0;
}
fseek( f, 0, SEEK_END );
len = ftell( f );
fseek( f, 0, SEEK_SET );
buf = malloc( len );
fread( buf, 1, len, f );
fclose( f );
ret = LoadTGAFromBuffer( name, buf, len, pic, width, height );
free( buf );
return ret;
}

View File

@@ -0,0 +1,55 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
Copyright (C) 1995 Spencer Kimball and Peter Mattis
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* tga.h: Handle Targa file format.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was
* originally written by id Software, Inc.
*
* Portion of this code was derived from The GIMP -- an image manipulation
* program, and was originally written by Spencer Kimball and Peter Mattis.
*/
/*
Notes:
This module is implimented by tga.c
*/
#ifndef __TGA_H__
#define __TGA_H__
#include "../../../common/arch.h"
extern W8 WriteTGA( const char *filename, W16 depth, W16 width, W16 height,
void *Data, W8 upsideDown, W8 rle );
int LoadTGA( const char *name, W8 **pic, int *width, int *height );
#endif /* __TGA_H__ */

View File

@@ -0,0 +1,144 @@
/*
Copyright (C) 2004 Michael Liebscher
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* wav.c: Handles wav files.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
*/
#include <stdlib.h>
#include <stdio.h>
#include "../../../common/arch.h"
typedef struct
{
W8 riff[ 4 ];
W32 TotalLength;
W8 wave[ 8 ];
W32 LengthFORMAT;
W16 DataType;
W16 ChannelNumbers;
W32 SampleRate;
W32 BytesPerSecond;
W16 BytesPerSample;
W16 BitsPerSample;
W8 data[ 4 ];
W32 LengthData;
} wavheader_t;
/*
-----------------------------------------------------------------------------
Function: write_wav() -Writes a wav file.
Parameters: filename -[in] Pointer to a null-terminated string that
specifies the name of the file to save as.
data -[in] Pointer to audio data.
size -[in] Length of audio data.
channels -[in] Number of Channels (0x01 = Mono, 0x02 = Stereo).
sample_rate -[in] Sample Rate in Hz
sample_size -[in] Bytes Per Sample:
1 = 8 bit Mono,
2 = 8 bit Stereo or 16 bit Mono,
4 = 16 bit Stereo
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
void
write_wav( const char *filename, void *data, W32 size,
W16 channels, W32 sample_rate,
W16 sample_size )
{
wavheader_t header;
FILE *handle;
handle = fopen( filename, "wb" );
if( handle == NULL )
{
printf( "unable to write wav file\n" );
return;
}
// RIFF Chunk
header.riff[ 0 ] = 'R';
header.riff[ 1 ] = 'I';
header.riff[ 2 ] = 'F';
header.riff[ 3 ] = 'F';
// Total Length Of Package To Follow
header.TotalLength = size + 36;
// Format Chunk
header.wave[ 0 ] = 'W';
header.wave[ 1 ] = 'A';
header.wave[ 2 ] = 'V';
header.wave[ 3 ] = 'E';
header.wave[ 4 ] = 'f';
header.wave[ 5 ] = 'm';
header.wave[ 6 ] = 't';
header.wave[ 7 ] = ' ';
header.LengthFORMAT = 0x10; // Length Of FORMAT Chunk (always 0x10)
header.DataType = 0x01; // Always 0x01
// Channel Numbers (always 0x01 = Mono, 0x02 = Stereo)
header.ChannelNumbers = channels;
header.SampleRate = sample_rate; // Sample Rate in Hz
header.BytesPerSecond = sample_rate * sample_size * channels;
header.BytesPerSample = sample_size; // Bytes Per Sample: 1 = 8 bit Mono,
// 2 = 8 bit Stereo or 16 bit Mono,
// 4 = 16 bit Stereo
header.BitsPerSample = sample_size * 8;
// DATA Chunk
header.data[ 0 ] = 'd';
header.data[ 1 ] = 'a';
header.data[ 2 ] = 't';
header.data[ 3 ] = 'a';
// Length Of Data To Follow
header.LengthData = size;
fwrite( &header, sizeof( W8 ), sizeof( wavheader_t ), handle );
fwrite( data, sizeof( W8 ), size, handle );
fclose( handle );
}

View File

@@ -0,0 +1,39 @@
/*
Copyright (C) 2004 Michael Liebscher
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* wav.h: Handles wav files.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
*/
#ifndef __WAV_H__
#define __WAV_H__
#include "../../../common/arch.h"
extern void write_wav( const char *filename, void *data, W32 size,
W16 channels, W32 sample_rate,
W16 sample_size );
#endif /* __WAV_H__ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,53 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 2000 Steven Fuller <relnev@atdot.org>
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* mac.h: This module is used to extract data from the Macintosh
* version of Wolfenstein 3-D.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* Portion of this code was derived from code that was originally
* written by Steven Fuller.
*
*/
#ifndef __MAC_H__
#define __MAC_H__
/* Directory Paths */
#define DIRPATHSPRITES "macsprites"
#define DIRPATHWALLS "macwalls"
#define DIRPATHPICS "macpics"
#define DIRPATHMIDI "macmidi"
extern void ripMac( void );
#endif /* __MAC_H__ */

391
wolf3d/wolfextractor/main.c Normal file
View File

@@ -0,0 +1,391 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* main.c: Decode Wolfenstein 3-D data files.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
*/
/*
This program decodes the following Wolfenstein 3-D/Spear of Destiny files:
AUDIOHED.xxx -Contains offsets and lengths of the audio in AUDIOT.
AUDIOT.xxx -Contains Adlib audio data.
VGAHEAD.xxx -Contains data offsets for VGAGRAPH.
VGAGRAPH.xxx -Contains graphic data.
VGADICT.xxx -Contains Huffman dictionary data.
VSWAP.xxx -Contains audio and graphic data.
Wolfenstein 3D(tm).mac -Macintosh binary of Wolfenstein 3D
*/
#include <stdlib.h>
#include <stdio.h>
#include "../../common/arch.h"
#include "../../common/common_utils.h"
#include "string/com_string.h"
#include "wolf/wolf_def.h"
#include "filesys/file.h"
#include "hq2x.h"
#include "mac/mac.h"
#define APP_VERSION "0.01i"
#define BASEDIR "base/"
extern void PAK_builder( const char *filename, W16 version );
/*
-----------------------------------------------------------------------------
Function: deleteCacheDirectories -Delete directories created when caching.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void deleteCacheDirectories( W16 version )
{
FS_RemoveDirectory( GFXWALLDIR );
FS_RemoveDirectory( MAPDIR );
FS_RemoveDirectory( LGFXDIR );
if( version & WL1_PAK || version & WL6_PAK )
{
FS_RemoveDirectory( SFXDIR );
FS_RemoveDirectory( GFXSPRITEDIR );
FS_RemoveDirectory( LSFXDIR );
}
if( version & SDM_PAK || version & SOD_PAK )
{
FS_RemoveDirectory( SODSFXDIR );
FS_RemoveDirectory( SODGFXSPRITEDIR );
FS_RemoveDirectory( SODLSFXDIR );
}
}
/*
-----------------------------------------------------------------------------
Function: CheckForDataFiles -Check for data files.
Parameters: Wolf_Ext -[out] zero nothing found.
Bit 0 high -WL1 data files found.
Bit 1 high -WL6 data files found.
Bit 2 high -SDM data files found.
Bit 3 high -SOD data files found.
Bit 4 high -MAC data files found.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
void CheckForDataFiles( W16 *Wolf_Ext )
{
char ext[ 13 ];
//
// Wolfenstein 3-D Demo
//
cs_strlcpy( ext, WL1_FEXT, sizeof( ext ) );
if( FS_FindFirst( cs_strupr( ext ), 0, 0 ) )
{
*Wolf_Ext |= WL1_PAK;
}
FS_FindClose();
if( FS_FindFirst( cs_strlwr( ext ), 0, 0 ) )
{
*Wolf_Ext |= WL1_PAK;
}
FS_FindClose();
//
// Wolfenstein 3-D
//
cs_strlcpy( ext, WL6_FEXT, sizeof( ext ) );
if( FS_FindFirst( cs_strupr( ext ), 0, 0 ) )
{
*Wolf_Ext |= WL6_PAK;
}
FS_FindClose();
if( FS_FindFirst( cs_strlwr( ext ), 0, 0 ) )
{
*Wolf_Ext |= WL6_PAK;
}
FS_FindClose();
//
// Spear of Destiny Demo
//
cs_strlcpy( ext, SDM_FEXT, sizeof( ext ) );
if( FS_FindFirst( cs_strupr( ext ), 0, 0 ) )
{
*Wolf_Ext |= SDM_PAK;
}
FS_FindClose();
if( FS_FindFirst( cs_strlwr( ext ), 0, 0 ) )
{
*Wolf_Ext |= SDM_PAK;
}
FS_FindClose();
//
// Spear of Destiny
//
cs_strlcpy( ext, SOD_FEXT, sizeof( ext ) );
if( FS_FindFirst( cs_strupr( ext ), 0, 0 ) )
{
*Wolf_Ext |= SOD_PAK;
}
FS_FindClose();
if( FS_FindFirst( cs_strlwr( ext ), 0, 0 ) )
{
*Wolf_Ext |= SOD_PAK;
}
FS_FindClose();
//
// Macintosh Wolfenstein 3-D
//
cs_strlcpy( ext, MAC_FEXT, sizeof( ext ) );
if( FS_FindFirst( cs_strupr( ext ), 0, 0 ) )
{
*Wolf_Ext |= MAC_PAK;
}
FS_FindClose();
if( FS_FindFirst( cs_strlwr( ext ), 0, 0 ) )
{
*Wolf_Ext |= MAC_PAK;
}
FS_FindClose();
}
/*
-----------------------------------------------------------------------------
Function: main -Interface to Wolfenstein data decoder.
Parameters: Nothing.
Returns: 0 on success, non-zero otherwise.
Notes: This is the application entry point.
1. Search for Wolfenstein data files.
2. Decode data accordingly.
-----------------------------------------------------------------------------
*/
int main( int argc, char *argv[] )
{
W16 Wolf_Ext = 0; // bit 0 high -WL1 extension
// bit 1 high -WL6 extension
// bit 2 high -SDM extension
// bit 3 high -SOD extension
// bit 4 high -MAC extension
W32 retval;
#if 0
extern char gamepal[];
int test = 0x32 * 3;
printf( "%d, %d, %d\n", gamepal[ test ]<<2, gamepal[ test+1 ]<<2, gamepal[ test+2 ]<<2 );
return 0;
#endif
#if 0 // hack to just fix the red cross health pack sprite
{
void UpdateSingleSprite( const char *srcTGA, const char *destTGA );
UpdateSingleSprite( "c:/027.tga", "c:/fixed_027.tga" );
exit( 0 );
}
#endif
printf( "\nWolfExtractor %s %s\n", BUILDSTRING, CPUSTRING );
printf( "Version %s built on %s at %s\n\n", APP_VERSION, __DATE__, __TIME__ );
if( ! FS_ChangeCurrentDirectory( BASEDIR ) )
{
printf( "Unable to change into directory (%s)\n", BASEDIR );
return 1;
}
CheckForDataFiles( &Wolf_Ext );
if( ! Wolf_Ext )
{
printf( "No Wolfenstein data files found!\n" );
return 1;
}
InitLUTs(); // This is for hq2x
if( Wolf_Ext & WL1_PAK )
{
printf( "\nFound Wolfenstein 3-D demo data files\n" );
retval = 0;
retval = LumpExtractor( WL1_FEXT+1, WL1_LATCHPICS_LUMP_END+5, WL1_PAK );
retval += PExtractor( WL1_FEXT+1, WL1_PAK );
retval += AudioRipper( WL1_FEXT+1, 87, 174, WL1_PAK );
retval += MapRipper( WL1_FEXT+1, WL1_PAK );
if( retval != 4 )
{
printf( "\nAn Error Has Occurred, exiting!\n" );
return 1;
}
//!@# JDC PAK_builder( "wolf_demo.pak", WL1_PAK );
}
if( Wolf_Ext & WL6_PAK )
{
printf( "\nFound Wolfenstein 3-D data files\n" );
retval = 0;
retval = LumpExtractor( WL6_FEXT+1, WL6_LATCHPICS_LUMP_END, WL6_PAK );
retval += PExtractor( WL6_FEXT+1, WL6_PAK );
retval += AudioRipper( WL6_FEXT+1, 87, 174, WL6_PAK );
retval += MapRipper( WL6_FEXT+1, WL6_PAK );
if( retval != 4 )
{
printf( "\nAn Error Has Occurred, exiting!\n" );
return 1;
}
//!@# JDC PAK_builder( "wolf.pak", WL6_PAK );
}
if( Wolf_Ext & SDM_PAK )
{
printf( "\nFound Spear of Destiny demo data files\n" );
retval = 0;
retval = LumpExtractor( SDM_FEXT+1, 127, SDM_PAK );
retval += PExtractor( SDM_FEXT+1, SDM_PAK );
retval += AudioRipper( SDM_FEXT+1, 81, 162, SDM_PAK );
retval += MapRipper( SDM_FEXT+1, SDM_PAK );
if( retval != 4 )
{
printf( "\nAn Error Has Occurred, exiting!\n" );
return 1;
}
return;
//!@# JDC PAK_builder( "spear_demo.pak", SDM_PAK );
}
if( Wolf_Ext & SOD_PAK )
{
printf( "\nFound Spear of Destiny data files\n" );
retval = 0;
retval = LumpExtractor( SOD_FEXT+1, 149, SOD_PAK );
retval += PExtractor( SOD_FEXT+1, SOD_PAK );
retval += AudioRipper( SOD_FEXT+1, 81, 162, SOD_PAK );
retval += MapRipper( SOD_FEXT+1, SOD_PAK );
if( retval != 4 )
{
printf( "\nAn Error Has Occurred, exiting!\n" );
return 1;
}
//!@# JDC PAK_builder( "spear.pak", SOD_PAK );
}
if( Wolf_Ext & MAC_PAK )
{
printf( "\nFound Macintosh binary file\n" );
ripMac();
//PAK_builder( "mac.pak", MAC_PAK );
}
//!@# JDC deleteCacheDirectories( Wolf_Ext );
return 0;
}

View File

@@ -0,0 +1,191 @@
#
# Project: Wolfenstein 3-D Redux
#
# Program: wolfextractor
#
COMPILER = gcc
CFLAGS = -Wall -c -O2
LDFLAGS = -s
ODIR = Release
EXEBASE = wolfextractor
EXE = $(ODIR)/$(EXEBASE)
DO_CC = $(COMPILER) $(CFLAGS) -o $@ -c $<
all: $(EXE)
clean:
rm -f $(ODIR)/*.o $(EXE)
PROGRAM_FILES = $(ODIR)/adlib.o \
$(ODIR)/fmopl.o \
$(ODIR)/arch.o \
$(ODIR)/file.o \
$(ODIR)/unix_file.o \
$(ODIR)/glob.o \
$(ODIR)/com_string.o \
$(ODIR)/tga.o \
$(ODIR)/wav.o \
$(ODIR)/memory.o \
$(ODIR)/mac.o \
$(ODIR)/wl6_name.o \
$(ODIR)/wolf_aud.o \
$(ODIR)/wolf_gfx.o \
$(ODIR)/wolf_map.o \
$(ODIR)/wolf_pal.o \
$(ODIR)/wolf_pm.o \
$(ODIR)/zipfile.o \
$(ODIR)/adler32.o \
$(ODIR)/compress.o \
$(ODIR)/crc32.o \
$(ODIR)/deflate.o \
$(ODIR)/trees.o \
$(ODIR)/zutil.o \
$(ODIR)/hq2x.o \
$(ODIR)/pak.o \
$(ODIR)/vorbisenc_inter.o \
$(ODIR)/main.o
$(EXE): $(PROGRAM_FILES)
${COMPILER} -o $(EXE) $(PROGRAM_FILES) $(LDFLAGS) -lvorbis -lvorbisenc -logg -lm
#===========================================================================
# Build
#===========================================================================
#
# adlib/
#
$(ODIR)/adlib.o : adlib/adlib.c
$(DO_CC)
$(ODIR)/fmopl.o : adlib/fmopl.c
$(DO_CC)
#
# common/
#
$(ODIR)/arch.o : ../../common/arch.c
$(DO_CC)
#
# filesys/
#
$(ODIR)/file.o : filesys/file.c
$(DO_CC)
#
# filesys/unix/
#
$(ODIR)/unix_file.o : filesys/unix/unix_file.c
$(DO_CC)
$(ODIR)/glob.o : filesys/unix/glob.c
$(DO_CC)
#
# loaders/
#
$(ODIR)/tga.o : loaders/tga.c
$(DO_CC)
$(ODIR)/wav.o : loaders/wav.c
$(DO_CC)
#
# mac/
#
$(ODIR)/mac.o : mac/mac.c
$(DO_CC)
#
# memory/
#
$(ODIR)/memory.o : memory/memory.c
$(DO_CC)
#
# string/
#
$(ODIR)/com_string.o : string/com_string.c
$(DO_CC)
#
# wolf/
#
$(ODIR)/wl6_name.o : wolf/wl6_name.c
$(DO_CC)
$(ODIR)/wolf_aud.o : wolf/wolf_aud.c
$(DO_CC)
$(ODIR)/wolf_gfx.o : wolf/wolf_gfx.c
$(DO_CC)
$(ODIR)/wolf_map.o : wolf/wolf_map.c
$(DO_CC)
$(ODIR)/wolf_pal.o : wolf/wolf_pal.c
$(DO_CC)
$(ODIR)/wolf_pm.o : wolf/wolf_pm.c
$(DO_CC)
#
# zip/
#
$(ODIR)/zipfile.o : zip/zipfile.c
$(DO_CC)
#
# zlib/
#
$(ODIR)/adler32.o : ../../zlib/adler32.c
$(DO_CC)
$(ODIR)/compress.o : ../../zlib/compress.c
$(DO_CC)
$(ODIR)/crc32.o : ../../zlib/crc32.c
$(DO_CC)
$(ODIR)/deflate.o : ../../zlib/deflate.c
$(DO_CC)
$(ODIR)/trees.o : ../../zlib/trees.c
$(DO_CC)
$(ODIR)/zutil.o : ../../zlib/zutil.c
$(DO_CC)
#
#
#
$(ODIR)/hq2x.o : hq2x.c
$(DO_CC)
$(ODIR)/pak.o : pak.c
$(DO_CC)
$(ODIR)/vorbisenc_inter.o : vorbisenc_inter.c
$(DO_CC)
$(ODIR)/main.o : main.c
$(DO_CC)

View File

@@ -0,0 +1,190 @@
#
# Project: Wolfenstein 3-D Redux
#
# Program: wolfextractor
#
COMPILER = gcc
CFLAGS = -Wall -c -O2 -idirafter /usr/local/include
LDFLAGS = -s
ODIR = Release
EXEBASE = wolfextractor
EXE = $(ODIR)/$(EXEBASE)
all: $(EXE)
VORBISFLAGS = -L/usr/local/lib -lvorbis -lvorbisenc -logg
clean:
rm -f $(ODIR)/*.o $(EXE)
PROGRAM_FILES = $(ODIR)/adlib.o $(ODIR)/fmopl.o $(ODIR)/arch.o $(ODIR)/file.o $(ODIR)/unix_file.o $(ODIR)/glob.o $(ODIR)/com_string.o $(ODIR)/tga.o $(ODIR)/wav.o $(ODIR)/mac.o $(ODIR)/memory.o $(ODIR)/wl6_name.o $(ODIR)/wolf_aud.o $(ODIR)/wolf_gfx.o $(ODIR)/wolf_map.o $(ODIR)/wolf_pal.o $(ODIR)/wolf_pm.o $(ODIR)/zipfile.o $(ODIR)/adler32.o $(ODIR)/compress.o $(ODIR)/crc32.o $(ODIR)/deflate.o $(ODIR)/trees.o $(ODIR)/zutil.o $(ODIR)/hq2x.o $(ODIR)/pak.o $(ODIR)/vorbisenc_inter.o $(ODIR)/main.o
$(EXE): $(PROGRAM_FILES)
${COMPILER} -o $(EXE) $(PROGRAM_FILES) $(LDFLAGS) $(VORBISFLAGS) -lm
#===========================================================================
# Build
#===========================================================================
#
# adlib/
#
$(ODIR)/adlib.o : adlib/adlib.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/fmopl.o : adlib/fmopl.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
#
# common/
#
$(ODIR)/arch.o : ../../common/arch.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
#
# filesys/
#
$(ODIR)/file.o : filesys/file.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
#
# filesys/unix/
#
$(ODIR)/unix_file.o : filesys/unix/unix_file.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/glob.o : filesys/unix/glob.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
#
# loaders/
#
$(ODIR)/tga.o : loaders/tga.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/wav.o : loaders/wav.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
#
# mac/
#
$(ODIR)/mac.o : mac/mac.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
#
# memory/
#
$(ODIR)/memory.o : memory/memory.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
#
# string/
#
$(ODIR)/com_string.o : string/com_string.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
#
# wolf/
#
$(ODIR)/wl6_name.o : wolf/wl6_name.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/wolf_aud.o : wolf/wolf_aud.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/wolf_gfx.o : wolf/wolf_gfx.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/wolf_map.o : wolf/wolf_map.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/wolf_pal.o : wolf/wolf_pal.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/wolf_pm.o : wolf/wolf_pm.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
#
# zip/
#
$(ODIR)/zipfile.o : zip/zipfile.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
#
# zlib/
#
$(ODIR)/adler32.o : ../../zlib/adler32.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/compress.o : ../../zlib/compress.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/crc32.o : ../../zlib/crc32.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/deflate.o : ../../zlib/deflate.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/trees.o : ../../zlib/trees.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/zutil.o : ../../zlib/zutil.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
#
#
#
$(ODIR)/hq2x.o : hq2x.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/pak.o : pak.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/vorbisenc_inter.o : vorbisenc_inter.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i
$(ODIR)/main.o : main.c
${COMPILER} $(CFLAGS) -E $? | tr -d '\015' > /tmp/temp.i
${COMPILER} $(CFLAGS) -o $@ /tmp/temp.i

View File

@@ -0,0 +1,198 @@
/*
Copyright (C) 2004 Michael Liebscher
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* memory.c: Memory allocation module.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
*
*/
#include <stdlib.h>
#include <stdio.h>
#include "memory.h"
#ifndef PARANOID
#define PARANOID 0
#endif /* PARANOID */
/*
-----------------------------------------------------------------------------
Function: Memory_malloc -Allocates memory blocks.
Parameters: size -[in] Bytes to allocate.
Returns:
Void pointer to the allocated space on success, or NULL if
there is insufficient memory available.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void *Memory_malloc( size_t size )
{
void *ptr;
ptr = malloc( size );
if( ptr != NULL )
{
#if PARANOID
printf( "Memory malloc: %p size:%ld\n", ptr, size );
#endif
return ptr;
}
printf( "[memory.c] Could not allocate %d bytes\n", size );
return NULL;
}
/*
-----------------------------------------------------------------------------
Function: Memory_calloc -Allocates an array in memory with elements
initialized to 0.
Parameters:
num -[in] Number of elements.
size -[in] Bytes to allocate.
Returns:
Void pointer to the allocated space on success, or NULL if
there is insufficient memory available.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void *Memory_calloc( size_t num, size_t size )
{
void *ptr;
ptr = calloc( num, size );
if( ptr != NULL )
{
#if PARANOID
printf( "Memory calloc: %p size:%ld num:%ld\n", ptr, size, num );
#endif
return ptr;
}
printf( "[memory.c] Could not allocate %d objects of size %d\n", num, size);
return NULL;
}
/*
-----------------------------------------------------------------------------
Function: Memory_realloc -Reallocate memory blocks.
Parameters:
memblock -[in] Pointer to previously allocated memory block.
size -[in] Bytes to allocate.
Returns:
A void pointer to the reallocated (and possibly moved) memory
block. The return value is NULL if the size is zero and the
buffer argument is not NULL, or if there is not enough
available memory to expand the block to the given size.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void *Memory_realloc( void *memblock, size_t size )
{
void *ptr;
ptr = realloc( memblock, size );
if( ptr != NULL )
{
#if PARANOID
printf( "Memory realloc: %p size:%ld\n", ptr, size );
#endif
return ptr;
}
printf( "[memory.c] Could not reallocate %d bytes\n", size );
return NULL;
}
/*
-----------------------------------------------------------------------------
Function: Memory_free -Deallocates or frees a memory block.
Parameters:
memblock -[in] Previously allocated memory block to be freed.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Memory_free( void *memblock )
{
if( memblock )
{
#if PARANOID
printf( "Memory free: %p\n", memblock );
#endif
free( memblock );
}
}
PUBLIC void Memory_outofmem( const char *name, const char *file, W32 line )
{
printf( "%s:%ld failed allocation for \"%s\"\n", file, line, name );
}

View File

@@ -0,0 +1,67 @@
/*
Copyright (C) 2004 Michael Liebscher
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* memory.h: Memory allocation manager.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
*/
/*
Notes:
This module is implemented by memory.c.
*/
#ifndef __MEMORY_H__
#define __MEMORY_H__
#include <stdlib.h>
#include "../../../common/arch.h"
#include "../../../common/common_utils.h"
// Use the macros
extern void *Memory_malloc( size_t size );
extern void *Memory_calloc( size_t num, size_t size );
extern void *Memory_realloc( void *memblock, size_t size );
extern void Memory_free( void *memblock );
extern void Memory_outofmem( const char *name, const char *file, W32 line );
#define MM_MALLOC( size ) Memory_malloc( (size) )
#define MM_CALLOC( num, size ) Memory_calloc( (num), (size) )
#define MM_REALLOC( memblock, size ) Memory_realloc( (memblock), (size) )
#define MM_FREE( memblock ) { Memory_free( (memblock) ); ((memblock)) = NULL; }
#define MM_OUTOFMEM( name ) Memory_outofmem( (name), __FILE__, __LINE__ )
#endif /* __MEMORY_H__ */

Binary file not shown.

640
wolf3d/wolfextractor/pak.c Normal file
View File

@@ -0,0 +1,640 @@
/*
Copyright (C) 2004 Michael Liebscher
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* pak.c: Creates PAK files for Wolfenstein 3-D Redux
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
*/
#include <string.h>
#include "wolf/wolf_def.h"
#include "mac/mac.h"
#include "memory/memory.h"
#include "../../common/arch.h"
#include "../../common/common_utils.h"
#include "string/com_string.h"
#include "filesys/file.h"
#include "zip/zip.h"
#include "../../zlib/zlib.h"
#define SCRIPTNAME "DEFAULT.CFG"
#define GVERSION_TEXT "set g_version "
#define SCRIPT_DIR "script"
PRIVATE struct zlist *zfchain = NULL; // Zip file chain
/*
-----------------------------------------------------------------------------
Function: writelocalfilechunk() -Zip file.
Parameters: filename -[in] Pointer to a NUL-terminated string that specifies
the path of the file to zip.
fout -[in] file to zip to.
Returns: On success pointer to zlist structure, otherwise NULL.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE struct zlist *writelocalfilechunk( const char *filename, FILE *fout )
{
W8 *data;
struct zlist *zentry;
struct filestats fs;
int err;
W8 *compr;
W32 retval;
z_stream c_stream; /* compression stream */
zentry = MM_MALLOC( sizeof( *zentry ) );
memset( zentry, 0, sizeof( *zentry ) );
zentry->next = NULL;
zentry->versionmadeby = VMB_VFAT;
zentry->versionneeded = 20;
zentry->disknumstart = 0;
zentry->compression_method = CM_DEFLATED;
zentry->deletefile = 1;
zentry->uncompressed_size = FS_LoadFile( filename, &data );
if( zentry->uncompressed_size == -1 || data == NULL )
{
printf( "Could not open file (%s)\n", filename );
MM_FREE( zentry );
return NULL;
}
FS_GetFileAttributes( filename, &fs );
zentry->timedate = UnixTimeToDosTime( &fs.lastwritetime );
//
// Compression
//
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit( &c_stream, Z_DEFAULT_COMPRESSION );
if( err != Z_OK )
{
MM_FREE( data );
MM_FREE( zentry );
return NULL;
}
zentry->compressed_size = (zentry->uncompressed_size / 10) + 12 + zentry->uncompressed_size;
compr = MM_MALLOC( zentry->compressed_size );
c_stream.next_out = compr;
c_stream.avail_out = (uInt)zentry->compressed_size;
c_stream.next_in = data;
c_stream.avail_in = (uInt)zentry->uncompressed_size;
err = deflate( &c_stream, Z_FINISH );
if( err != Z_STREAM_END )
{
MM_FREE( compr );
MM_FREE( data );
MM_FREE( zentry );
return NULL;
}
err = deflateEnd( &c_stream );
if( err != Z_OK )
{
MM_FREE( compr );
MM_FREE( data );
MM_FREE( zentry );
return NULL;
}
// When using the deflate method, ZLib adds a 2 byte head
// and a 4 byte tail. The head must be removed for zip
// compatability and the tail is not necessary.
zentry->compressed_size = c_stream.total_out - 6;
//
// End of compression
//
zentry->crc32 = crc32( 0, data, zentry->uncompressed_size );
cs_strlcpy( zentry->filename, filename, sizeof( zentry->filename ) );
zentry->filename_length = strlen( zentry->filename );
zentry->offset = ftell( fout );
// Write header to file
if( ! zip_writelocalfileheader( zentry, fout ) )
{
printf( "Error writing local header to zip file\n" );
MM_FREE( compr );
MM_FREE( data );
MM_FREE( zentry );
return NULL;
}
// Write data to file
retval = fwrite( compr+2, 1, zentry->compressed_size, fout );
if( retval != zentry->compressed_size )
{
printf( "Error writing data after local header to zip file\n" );
MM_FREE( compr );
MM_FREE( data );
MM_FREE( zentry );
return NULL;
}
MM_FREE( compr );
MM_FREE( data );
return zentry;
}
/*
-----------------------------------------------------------------------------
Function: writecentralchunk() -Write central headers for Zip file.
Parameters: z -[in] Chain of zlist structures.
fout -[in] file to write to.
Returns: On success true, otherwise false.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE _boolean writecentralchunk( struct zlist *z, FILE *fout )
{
W32 central_offset;
W32 central_size;
W32 num = 0;
struct zlist *ztemp;
if( z == NULL )
{
printf( "NULL zip list passed into writecentralchunk().\n" );
return false;
}
central_offset = ftell( fout );
ztemp = z;
do
{
++num;
if( ! zip_writecentral( ztemp, fout ) )
{
printf( "Error writing central header to zip file\n" );
return false;
}
ztemp = ztemp->next;
} while( ztemp );
central_size = ftell( fout ) - central_offset;
if( ! zip_writeend( num, central_size, central_offset, 0, NULL, fout ) )
{
printf( "Error writing end header to zip file\n" );
return false;
}
return true;
}
/*
-----------------------------------------------------------------------------
Function: parsedirectory() -Write central headers for Zip file.
Parameters: path -[in] path to parse.
fout -[in] zip file to write to.
Returns: On success pointer to zlist structure, otherwise NULL.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE _boolean parsedirectory( const char *path, FILE *f )
{
char temp[ 256 ];
char *ptr;
struct zlist *znewnode = NULL;
cs_strlcpy( temp, path, sizeof( temp ) );
if( strstr( temp, "*" ) == NULL )
{
cs_strlcat( temp, "/*", sizeof( temp ) );
}
// run findfirst once so we can use findnext in a loop.
// This will return the current directory
(void)FS_FindFirst( temp, 0, 0 );
// Look for files
while( (ptr = FS_FindNext( 0, FA_DIR )) != NULL )
{
znewnode = writelocalfilechunk( ptr, f );
if( znewnode == NULL )
{
continue;
}
// add new link to chain
znewnode->next = zfchain;
zfchain = znewnode;
}
FS_FindClose();
return true; // return pointer to start of chain
}
/*
-----------------------------------------------------------------------------
Function: addscripttozipfile() -Add script file to zip file.
Parameters: filename -[in] File name of script file.
fout -[in] zip file to write to.
version -[in]
Returns: On success pointer to zlist structure, otherwise NULL.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE struct zlist *addscripttozipfile( char *filename, FILE *fout, W16 version )
{
W8 *data;
struct zlist *zentry;
struct filestats fs;
int err;
W32 retval;
W8 *compr;
z_stream c_stream; /* compression stream */
char commandline[ 256 ];
int value = 0;
FILE *fin;
fin = fopen( filename, "rb" );
if( fin == NULL )
{
return NULL;
}
retval = FS_FileLength( fin );
if( retval == -1 )
{
printf( "Could not open file (%s)\n", filename );
return NULL;
}
// add g_version command
if( version == SDM_PAK || version == SOD_PAK )
{
value = 1;
}
else
{
value = 0;
}
cs_snprintf( commandline, sizeof( commandline ), "\n%s%d\n", GVERSION_TEXT, value );
data = MM_MALLOC( retval + strlen( commandline ) + 1 );
if( fread( data, 1, retval, fin ) != retval )
{
printf( "Could not read from file (%s)\n", filename );
MM_FREE( data )
return NULL;
}
fclose( fin );
memcpy( data + retval, commandline, strlen( commandline ) );
zentry = MM_MALLOC( sizeof( *zentry ) );
memset( zentry, 0, sizeof( *zentry ) );
zentry->next = NULL;
zentry->versionmadeby = VMB_VFAT;
zentry->versionneeded = 20;
zentry->disknumstart = 0;
zentry->compression_method = CM_DEFLATED;
zentry->deletefile = 0;
zentry->uncompressed_size = retval + strlen( commandline );
FS_GetFileAttributes( filename, &fs );
zentry->timedate = UnixTimeToDosTime( &fs.lastwritetime );
//
// Compression
//
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit( &c_stream, Z_DEFAULT_COMPRESSION );
if( err != Z_OK )
{
MM_FREE( data );
MM_FREE( zentry );
return NULL;
}
zentry->compressed_size = (zentry->uncompressed_size / 10) + 12 + zentry->uncompressed_size;
compr = MM_MALLOC( zentry->compressed_size );
c_stream.next_out = compr;
c_stream.avail_out = (uInt)zentry->compressed_size;
c_stream.next_in = data;
c_stream.avail_in = (uInt)zentry->uncompressed_size;
err = deflate( &c_stream, Z_FINISH );
if( err != Z_STREAM_END )
{
MM_FREE( compr );
MM_FREE( data );
MM_FREE( zentry );
return NULL;
}
err = deflateEnd( &c_stream );
if( err != Z_OK )
{
MM_FREE( compr );
MM_FREE( data );
MM_FREE( zentry );
return NULL;
}
// When using the deflate method, ZLib adds a 2 byte head
// and a 4 byte tail. The head must be removed for zip
// compatability and the tail is not necessary.
zentry->compressed_size = c_stream.total_out - 6;
//
// End of compression
//
zentry->crc32 = crc32( 0, data, zentry->uncompressed_size );
cs_strlcpy( zentry->filename, filename, sizeof( zentry->filename ) );
zentry->filename_length = strlen( zentry->filename );
zentry->offset = ftell( fout );
// Write header to file
if( ! zip_writelocalfileheader( zentry, fout ) )
{
printf( "Error writing local header to zip file\n" );
MM_FREE( compr );
MM_FREE( data );
MM_FREE( zentry );
return NULL;
}
// Write data to file
retval = fwrite( compr+2, 1, zentry->compressed_size, fout );
if( retval != zentry->compressed_size )
{
printf( "Error writing data after local header to zip file\n" );
MM_FREE( compr );
MM_FREE( data );
MM_FREE( zentry );
return NULL;
}
MM_FREE( compr );
MM_FREE( data );
return zentry;
}
/*
-----------------------------------------------------------------------------
Function: deletezlist() -delete zip file chain.
Parameters: in -[in] zlist structure chain to delete.
deletefile -[in] Delete the file?
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void deletezlist( struct zlist *in, _boolean deletefile )
{
struct zlist *z1;
if( in == NULL )
{
printf( "NULL zip list passed into deletezlist.\n" );
return;
}
if( deletefile )
{
printf( "Removing cached files.\n" );
}
z1 = in->next;
do
{
if( in )
{
// delete file
if( deletefile && in->deletefile )
{
if( ! FS_DeleteFile( in->filename ) )
{
printf( "Unable to delete file (%s)\n", in->filename );
}
}
MM_FREE( in );
}
if( z1 )
{
in = z1;
z1 = in->next;
}
} while( in );
}
/*
-----------------------------------------------------------------------------
Function: PAK_builder() -Builds a PAK file for Wolfenstein 3-D Redux.
Parameters: path -[in] game path.
packname -[in] Name of PAK file to create.
version -[in] Versions of game files create/found.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void PAK_builder( const char *packname, W16 version )
{
FILE *fout;
printf( "\n\nGenerating pack file (%s)\nThis could take a few minutes.\n", packname );
fout = fopen( packname, "wb" );
if( fout == NULL )
{
printf( "[PAK_builder]: Could not create file (%s)\n", packname );
return;
}
// Script file should be first
zfchain = addscripttozipfile( SCRIPTNAME, fout, version );
if( version & WL1_PAK || version & WL6_PAK ||
version & SDM_PAK || version & SOD_PAK )
{
parsedirectory( MAPDIR, fout );
parsedirectory( LGFXDIR, fout );
parsedirectory( GFXWALLDIR, fout );
parsedirectory( MUSICDIR, fout );
if( version & WL1_PAK || version & WL6_PAK )
{
parsedirectory( SCRIPT_DIR, fout );
parsedirectory( SFXDIR, fout );
parsedirectory( GFXSPRITEDIR, fout );
parsedirectory( LSFXDIR, fout );
}
if( version & SDM_PAK || version & SOD_PAK )
{
parsedirectory( SODSFXDIR, fout );
parsedirectory( SODGFXSPRITEDIR, fout );
parsedirectory( SODLSFXDIR, fout );
}
}
if( version & MAC_PAK )
{
parsedirectory( DIRPATHSPRITES, fout );
parsedirectory( DIRPATHWALLS, fout );
parsedirectory( DIRPATHPICS, fout );
parsedirectory( DIRPATHMIDI, fout );
}
if( ! writecentralchunk( zfchain, fout ) )
{
deletezlist( zfchain, false );
// close and delete zip file.
fclose( fout );
FS_DeleteFile( packname );
return;
}
// close zip file.
fclose( fout );
deletezlist( zfchain, true );
zfchain = NULL;
}

View File

@@ -0,0 +1,359 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
Copyright (C) 1997-2001 Id Software, Inc.
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* com_string.c: Common string functions done in a portable manner.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
* Portion of this code was derived from code that was originally
* written by Todd C. Miller.
*
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include "com_string.h"
#include "../../../common/arch.h"
#include "../../../common/common_utils.h"
/*
-----------------------------------------------------------------------------
Function: cs_strlcpy -Copies a specified number of characters from a
source string into a buffer.
Parameters: dest -[in/out] Pointer to a buffer into which the function
copies characters
source -[in] Pointer to a NUL-terminated string from which
the function copies characters.
nMaxLength -[in] Specifies the number of bytes to be copied
from the string pointed to by source into the
buffer pointed to by dest.
Returns: Returns strlen( source ); if retval >= nMaxLength, truncation
occurred.
Notes:
At most nMaxLength-1 characters will be copied. Always NUL-
terminates (unless nMaxLength == 0).
-----------------------------------------------------------------------------
*/
PUBLIC size_t cs_strlcpy( char *dest, const char *source, size_t nMaxLength )
{
char *d = dest;
const char *s = source;
size_t n = nMaxLength;
/* Copy as many bytes as will fit */
if( n != 0 && --n != 0 )
{
do
{
if( (*d++ = *s++) == 0 )
{
break;
}
} while( --n != 0 );
}
/* Not enough room in dest, add NUL and traverse rest of source */
if( n == 0 )
{
if( nMaxLength != 0 )
{
*d = '\0'; /* NUL-terminate dest */
}
while( *s++ )
{
;
}
}
return( s - source - 1 ); /* count does not include NUL */
}
/*
-----------------------------------------------------------------------------
Function: cs_strlcat -Appends one string to another.
Parameters: dest -[in/out] Pointer to a NUL-terminated string. The buffer
must be large enough to contain both strings or else
truncation will occur.
source -[in] Pointer to a NUL-terminated string from which
the function copies characters.
nMaxLength -[in] full size of dest, not space left.
Returns: Returns strlen( source ) + MIN( nMaxLength, strlen( initial dest ) ).
If retval >= nMaxLength, truncation occurred.
Notes:
At most nMaxLength-1 characters will be copied. Always NUL-
terminates (unless nMaxLength <= strlen( dest ) ).
-----------------------------------------------------------------------------
*/
PUBLIC size_t cs_strlcat( char *dest, const char *source, size_t nMaxLength )
{
char *d = dest;
const char *s = source;
size_t n = nMaxLength;
size_t dlen;
/* Find the end of dest and adjust bytes left but don't go past end */
while( n-- != 0 && *d != '\0' )
{
d++;
}
dlen = d - dest;
n = nMaxLength - dlen;
/* No room left to append string */
if( n == 0 )
{
return( dlen + strlen( s ) );
}
while( *s != '\0' )
{
if( n != 1 )
{
*d++ = *s;
n--;
}
s++;
}
*d = '\0'; /* NUL-terminate string */
return( dlen + (s - source) ); /* count does not include NUL */
}
/*
-----------------------------------------------------------------------------
Function: cs_strnicmp -Compare characters of two strings without regard to case.
Parameters: string1, string2 -[in] NUL-terminated strings to compare.
count -[in] Number of characters to compare.
Returns: 0 string1 identical to string2, -1 otherwise.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC int cs_strnicmp( const char *string1, const char *string2, size_t count )
{
char c1, c2;
if( ! string1 || ! *string1 ||
! string2 || ! *string2 )
{
return -1;
}
do
{
c1 = *string1++;
c2 = *string2++;
if( ! count-- )
{
return 0; /* strings are equal until end point */
}
if( c1 != c2 )
{
if( TOUPPER( c1 ) != TOUPPER( c2 ) ) /* Uppercase compare */
{
return -1; /* strings are not equal */
}
}
} while( c1 );
return 0; /* strings are equal */
}
/*
-----------------------------------------------------------------------------
Function: cs_stricmp -Perform an uppercase comparison of strings.
Parameters: string1, string2 -[in] Null-terminated strings to compare.
Returns: 0 string1 identical to string2, -1 otherwise.
Notes:
This is a case insensitive compare.
Calls cs_strnicmp, where count is 99999
-----------------------------------------------------------------------------
*/
PUBLIC int cs_stricmp( const char *string1, const char *string2 )
{
return cs_strnicmp( string1, string2, 99999 );
}
/*
-----------------------------------------------------------------------------
Function: cs_snprintf -Write formatted data to a string.
Parameters: dest -[out] Storage location for output.
size -[in] Maximum number of characters to store.
format -[in] Format-control string.
... -[in] Optional arguments.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void cs_snprintf( char *dest, size_t size, const char *format, ... )
{
va_list argptr;
char bigbuffer[ 0x8000 ];
va_start( argptr, format );
(void)vsnprintf( bigbuffer, sizeof( bigbuffer ), format, argptr );
va_end( argptr );
bigbuffer[ sizeof( bigbuffer ) - 1 ] = '\0';
cs_strlcpy( dest, bigbuffer, size );
}
/*
-----------------------------------------------------------------------------
Function: cs_strhash -Create a hash id from string.
Parameters: string -[in] NUL-terminated string.
Returns: Hash id.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC W32 cs_strhash( const char *string )
{
W32 hash = *string;
if( hash )
{
for( string += 1; *string != '\0'; ++string )
{
hash = (hash << 5) - hash + *string;
}
}
return hash;
}
/*
-----------------------------------------------------------------------------
Function: cs_strupr -Convert a string to uppercase.
Parameters: string -[in/out] NUL-terminated string to capitalize.
Returns:
This functions returns a pointer to the converted string. Because
the modification is done in place, the pointer returned is the same
as the pointer passed as the input argument. No return value is
reserved to indicate an error.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *cs_strupr( char *string )
{
W8 *ptr;
if( ! string || ! *string )
{
return string;
}
ptr = string;
do
{
*ptr = TOUPPER( *ptr );
ptr++;
} while( *ptr );
return string;
}
/*
-----------------------------------------------------------------------------
Function: cs_strlwr -Convert a string to lowercase.
Parameters: string -[in/out] NUL-terminated string to convert to lowercase.
Returns:
This functions returns a pointer to the converted string. Because
the modification is done in place, the pointer returned is the same
as the pointer passed as the input argument. No return value is
reserved to indicate an error.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *cs_strlwr( char *string )
{
W8 *ptr;
if( ! string || ! *string )
{
return string;
}
ptr = string;
do
{
*ptr = TOLOWER( *ptr );
ptr++;
} while( *ptr );
return string;
}

View File

@@ -0,0 +1,79 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
Copyright (C) 1997-2001 Id Software, Inc.
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* com_string.h: Common string functions done in a portable manner.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
* Portion of this code was derived from code that was originally
* written by Todd C. Miller.
*
*/
/*
Notes:
This module is implemented by com_string.c.
*/
#ifndef __COM_STRING_H__
#define __COM_STRING_H__
#include <stdlib.h>
#include "../../../common/arch.h"
#define ISSPACE( c ) ( ( c ) == ' ' || ( c ) == '\f' || ( c ) == '\n' || ( c ) == '\r' || ( c ) == '\t' || ( c ) == '\v' )
#define ISUPPER( c ) ( ( c ) >= 'A' && ( c ) <= 'Z' )
#define ISLOWER( c ) ( ( c ) >= 'a' && ( c ) <= 'z' )
#define ISALPHA( c ) ( ISUPPER( c ) || ISLOWER( c ) )
#define TOUPPER( c ) ( ISLOWER( c ) ? (c) - 'a' + 'A' : ( c ) )
#define TOLOWER( c ) ( ISUPPER( c ) ? (c) - 'A' + 'a' : ( c ) )
extern size_t cs_strlcpy( char *dest, const char *source, size_t nMaxLength );
extern size_t cs_strlcat( char *dest, const char *source, size_t nMaxLength );
extern int cs_stricmp( const char *string1, const char *string2 );
extern int cs_strnicmp( const char *string1, const char *string2, size_t count );
extern void cs_snprintf( char *dest, size_t size, const char *format, ... );
extern char *cs_CopyString( const char *in );
extern W32 cs_strhash( const char *string );
extern char *cs_strupr( char *string );
extern char *cs_strlwr( char *string );
#endif /* __COM_STRING_H__ */

Binary file not shown.

View File

@@ -0,0 +1,302 @@
/*
Copyright (C) 2005 Michael Liebscher
Copyright 2000-2002, Michael Smith <msmith@xiph.org>
(c) Kenneth Arnold <kcarnold@yahoo.com>
(c) Monty <monty@xiph.org>
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* vorbisenc_inter.c: Simple Ogg Vorbis interface.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2005
*
* Acknowledgement:
* Portions from oggenc, Copyright 2000-2002, Michael Smith <msmith@xiph.org>
* Vorbize, (c) Kenneth Arnold <kcarnold@yahoo.com>
* and libvorbis examples, (c) Monty <monty@xiph.org>
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vorbis/vorbisenc.h>
#include "../../common/arch.h"
#include "../../common/common_utils.h"
#define READSIZE 1024
PRIVATE W32 channels;
PRIVATE W32 samplesize;
PRIVATE W8 *ptrCurrent;
PRIVATE W8 *ptrEnd;
long read_samples( float **buffer, int samples )
{
int sampbyte = samplesize / 8;
SW8 *buf;
long bytes_read;
int i,j;
long realsamples;
buf = ptrCurrent;
if( (samples * sampbyte * channels) > (ptrEnd - ptrCurrent) )
{
bytes_read = ptrEnd - ptrCurrent;
ptrCurrent = ptrEnd;
if( bytes_read == 0 )
{
return 0;
}
}
else
{
bytes_read = samples * sampbyte * channels;
ptrCurrent += samples * sampbyte * channels;
}
realsamples = bytes_read / (sampbyte * channels);
for( i = 0 ; i < realsamples ; ++i )
{
for( j = 0 ; j < channels ; ++j )
{
buffer[j][i] = ((buf[ i * 2 * channels + 2 * j + 1 ] << 8) |
(buf[ i * 2 * channels + 2 * j ] & 0xFF)) / 32768.0f;
}
}
return realsamples;
}
int vorbis_encode( const char *filename, void *data, W32 size, W32 in_channels, W32 in_samplesize,
W32 rate, W32 quality, W32 max_bitrate, W32 min_bitrate )
{
FILE *fp;
ogg_stream_state os;
ogg_page og;
ogg_packet op;
vorbis_dsp_state vd;
vorbis_block vb;
vorbis_info vi;
ogg_packet header_main;
ogg_packet header_comments;
ogg_packet header_codebooks;
int result;
unsigned int serialno = 0;
vorbis_comment comments;
int ret = 0;
int eos;
W32 samplesdone = 0;
W32 packetsdone = 0;
W32 bytes_written = 0;
fp = fopen( filename, "wb" );
if( fp == NULL )
{
return 0;
}
memset( &comments, 0, sizeof( comments ) );
channels = in_channels;
samplesize = in_samplesize;
ptrCurrent = (PW8)data;
ptrEnd = (PW8)data + size;
vorbis_info_init( &vi );
if( vorbis_encode_setup_vbr( &vi, channels, rate, quality ) )
{
fprintf( stderr, "Mode initialisation failed: invalid parameters for quality\n" );
vorbis_info_clear( &vi );
return 1;
}
/* do we have optional hard quality restrictions? */
if( max_bitrate > 0 || min_bitrate > 0 )
{
struct ovectl_ratemanage_arg ai;
vorbis_encode_ctl( &vi, OV_ECTL_RATEMANAGE_GET, &ai );
ai.bitrate_hard_min = min_bitrate;
ai.bitrate_hard_max = max_bitrate;
ai.management_active = 1;
vorbis_encode_ctl( &vi, OV_ECTL_RATEMANAGE_SET, &ai );
}
/* Turn off management entirely (if it was turned on). */
vorbis_encode_ctl( &vi, OV_ECTL_RATEMANAGE_SET, NULL );
vorbis_encode_setup_init( &vi );
vorbis_analysis_init( &vd, &vi );
vorbis_block_init( &vd, &vb );
ogg_stream_init( &os, serialno );
/* Now, build the three header packets and send through to the stream
output stage (but defer actual file output until the main encode loop) */
/* Build the packets */
ret = vorbis_analysis_headerout( &vd, &comments,
&header_main, &header_comments, &header_codebooks );
/* And stream them out */
ogg_stream_packetin( &os, &header_main );
ogg_stream_packetin( &os, &header_comments );
ogg_stream_packetin( &os, &header_codebooks );
while( (result = ogg_stream_flush( &os, &og )) )
{
if( ! result )
{
break;
}
ret = fwrite( og.header, 1, og.header_len, fp );
ret += fwrite( og.body, 1, og.body_len, fp );
if(ret != og.header_len + og.body_len)
{
printf( "Failed writing header to output stream\n") ;
ret = 1;
goto cleanup; /* Bail and try to clean up stuff */
}
}
eos = 0;
/* Main encode loop - continue until end of file */
while( ! eos )
{
float **buffer = vorbis_analysis_buffer( &vd, READSIZE );
long samples_read = read_samples( buffer, READSIZE );
if( samples_read == 0 )
{
/* Tell the library that we wrote 0 bytes - signalling the end */
vorbis_analysis_wrote( &vd, 0 );
}
else
{
samplesdone += samples_read;
/* Call progress update every 40 pages */
if( packetsdone >= 40 )
{
packetsdone = 0;
// progress bar here
}
/* Tell the library how many samples (per channel) we wrote
into the supplied buffer */
vorbis_analysis_wrote( &vd, samples_read );
}
/* While we can get enough data from the library to analyse, one
block at a time... */
while( vorbis_analysis_blockout( &vd, &vb ) == 1 )
{
/* Do the main analysis, creating a packet */
vorbis_analysis( &vb, NULL );
vorbis_bitrate_addblock( &vb );
while( vorbis_bitrate_flushpacket( &vd, &op ) )
{
/* Add packet to bitstream */
ogg_stream_packetin( &os, &op );
packetsdone++;
/* If we've gone over a page boundary, we can do actual output,
so do so (for however many pages are available) */
while( ! eos )
{
int result = ogg_stream_pageout( &os, &og );
if( ! result )
{
break;
}
ret = fwrite( og.header, 1, og.header_len, fp );
ret += fwrite( og.body, 1, og.body_len, fp );
if(ret != og.header_len + og.body_len)
{
printf( "Failed writing data to output stream\n" );
ret = 1;
goto cleanup; /* Bail */
}
else
{
bytes_written += ret;
}
if( ogg_page_eos( &og ) )
{
eos = 1;
}
}
}
}
}
cleanup:
fclose( fp );
ogg_stream_clear( &os );
vorbis_block_clear( &vb );
vorbis_dsp_clear( &vd );
vorbis_info_clear( &vi );
return 0;
}

Binary file not shown.

View File

@@ -0,0 +1,760 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* wl6_name.c: Convert chunk number to string name.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* This code was derived from Wolfenstein 3-D, and was originally
* written by Id Software, Inc.
*
*/
#include <stdlib.h>
#include "wolf_def.h"
#include "../../../common/arch.h"
#include "../../../common/common_utils.h"
/*
-----------------------------------------------------------------------------
Function: GetLumpFileName_WL1() -Returns lump name string.
Parameters: chunk -[in] Chunk value to get string name for.
Returns: NULL on error, otherwise string name.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *GetLumpFileName_WL1( W32 chunk )
{
switch( chunk )
{
case WL1_H_BJPIC: return "H_BJPIC";
case WL1_H_CASTLEPIC: return "H_CASTLEPIC";
case WL1_H_KEYBOARDPIC: return "H_KEYBOARDPIC";
case WL1_H_CONTROLPIC: return "H_CONTROLPIC";
case WL1_H_HEALPIC: return "H_HEALPIC";
case WL1_H_BGPIC: return "H_BGPIC";
case WL1_H_GUNPIC: return "H_GUNPIC";
case WL1_H_KEYPIC: return "H_KEYPIC";
case WL1_H_BLAZEPIC: return "H_BLAZEPIC";
case WL1_H_WEAPON1234PIC: return "H_WEAPON1234PIC";
case WL1_H_WOLFLOGOPIC: return "H_WOLFLOGOPIC";
case WL1_H_VISAPIC: return "H_VISAPIC";
case WL1_H_MCPIC: return "H_MCPIC";
case WL1_H_IDLOGOPIC: return "H_IDLOGOPIC";
case WL1_H_TOPWINDOWPIC: return "H_TOPWINDOWPI";
case WL1_H_LEFTWINDOWPIC: return "H_LEFTWINDOWPIC";
case WL1_H_RIGHTWINDOWPIC: return "H_RIGHTWINDOWPIC";
case WL1_H_BOTTOMINFOPIC: return "H_BOTTOMINFOPIC";
case WL1_H_GAMEPIC: return "H_GAMEPIC";
case WL1_C_OPTIONSPIC: return "C_OPTIONSPIC";
case WL1_C_CURSOR1PIC: return "C_CURSOR0PIC";
case WL1_C_CURSOR2PIC: return "C_CURSOR1PIC";
case WL1_C_NOTSELECTEDPIC: return "C_NOTSELECTEDPIC";
case WL1_C_SELECTEDPIC: return "C_SELECTEDPIC";
case WL1_C_FXTITLEPIC: return "C_FXTITLEPIC";
case WL1_C_DIGITITLEPIC: return "C_DIGITITLEPIC";
case WL1_C_MUSICTITLEPIC: return "C_MUSICTITLEPIC";
case WL1_C_MOUSELBACKPIC: return "C_MOUSELBACKPIC";
case WL1_C_BABYMODEPIC: return "C_SKILL1PIC";
case WL1_C_EASYPIC: return "C_SKILL2PIC";
case WL1_C_NORMALPIC: return "C_SKILL3PIC";
case WL1_C_HARDPIC: return "C_SKILL4PIC";
case WL1_C_LOADSAVEDISKPIC: return "C_LOADSAVEDISKPIC";
case WL1_C_DISKLOADING1PIC: return "C_DISKLOADING0PIC";
case WL1_C_DISKLOADING2PIC: return "C_DISKLOADING1PIC";
case WL1_C_CONTROLPIC: return "C_CONTROLPIC";
case WL1_C_CUSTOMIZEPIC: return "C_CUSTOMIZEPIC";
case WL1_C_LOADGAMEPIC: return "C_LOADGAMEPIC";
case WL1_C_SAVEGAMEPIC: return "C_SAVEGAMEPIC";
case WL1_C_EPISODE1PIC: return "C_EPISODE1PIC";
case WL1_C_EPISODE2PIC: return "C_EPISODE2PIC";
case WL1_C_EPISODE3PIC: return "C_EPISODE3PIC";
case WL1_C_EPISODE4PIC: return "C_EPISODE4PIC";
case WL1_C_EPISODE5PIC: return "C_EPISODE5PIC";
case WL1_C_EPISODE6PIC: return "C_EPISODE6PIC";
case WL1_C_CODEPIC: return "C_CODEPIC";
case WL1_C_TIMECODEPIC: return "C_TIMECODEPIC";
case WL1_C_LEVELPIC: return "C_LEVELPIC";
case WL1_C_NAMEPIC: return "C_NAMEPIC";
case WL1_C_SCOREPIC: return "C_SCOREPIC";
case WL1_C_JOY1PIC: return "C_JOY1PIC";
case WL1_C_JOY2PIC: return "C_JOY2PIC";
case WL1_L_GUYPIC: return "L_GUY0PIC";
case WL1_L_COLONPIC:
case WL1_L_NUM0PIC:
case WL1_L_NUM1PIC:
case WL1_L_NUM2PIC:
case WL1_L_NUM3PIC:
case WL1_L_NUM4PIC:
case WL1_L_NUM5PIC:
case WL1_L_NUM6PIC:
case WL1_L_NUM7PIC:
case WL1_L_NUM8PIC:
case WL1_L_NUM9PIC:
case WL1_L_PERCENTPIC:
case WL1_L_APIC:
case WL1_L_BPIC:
case WL1_L_CPIC:
case WL1_L_DPIC:
case WL1_L_EPIC:
case WL1_L_FPIC:
case WL1_L_GPIC:
case WL1_L_HPIC:
case WL1_L_IPIC:
case WL1_L_JPIC:
case WL1_L_KPIC:
case WL1_L_LPIC:
case WL1_L_MPIC:
case WL1_L_NPIC:
case WL1_L_OPIC:
case WL1_L_PPIC:
case WL1_L_QPIC:
case WL1_L_RPIC:
case WL1_L_SPIC:
case WL1_L_TPIC:
case WL1_L_UPIC:
case WL1_L_VPIC:
case WL1_L_WPIC:
case WL1_L_XPIC:
case WL1_L_YPIC:
case WL1_L_ZPIC:
case WL1_L_EXPOINTPIC:
case WL1_L_APOSTROPHEPIC: return "L_FONTPIC";
case WL1_L_GUY2PIC: return "L_GUY1PIC";
case WL1_L_BJWINSPIC: return "L_BJWINSPIC";
case WL1_STATUSBARPIC: return "STATUSBARPIC";
case WL1_TITLEPIC: return "TITLEPIC";
case WL1_PG13PIC: return "PC13PIC";
case WL1_CREDITSPIC: return "CREDITSPIC";
case WL1_HIGHSCORESPIC: return "HIGHSCORESPIC";
case WL1_KNIFEPIC: return "KNIFEPIC";
case WL1_GUNPIC: return "GUNPIC";
case WL1_MACHINEGUNPIC: return "MACHINEGUNPIC";
case WL1_GATLINGGUNPIC: return "GATLINGGUNPIC";
case WL1_NOKEYPIC: return "NOKEYPIC";
case WL1_GOLDKEYPIC: return "GOLDKEYPIC";
case WL1_SILVERKEYPIC: return "SILVERKEYPIC";
case WL1_N_BLANKPIC: return "N_BLANKPIC";
case WL1_N_0PIC:
case WL1_N_1PIC:
case WL1_N_2PIC:
case WL1_N_3PIC:
case WL1_N_4PIC:
case WL1_N_5PIC:
case WL1_N_6PIC:
case WL1_N_7PIC:
case WL1_N_8PIC:
case WL1_N_9PIC: return "N_NUMPIC";
case WL1_FACE1APIC: return "FACE1APIC";
case WL1_FACE1BPIC: return "FACE1BPIC";
case WL1_FACE1CPIC: return "FACE1CPIC";
case WL1_FACE2APIC: return "FACE2APIC";
case WL1_FACE2BPIC: return "FACE2BPIC";
case WL1_FACE2CPIC: return "FACE2CPIC";
case WL1_FACE3APIC: return "FACE3APIC";
case WL1_FACE3BPIC: return "FACE3BPIC";
case WL1_FACE3CPIC: return "FACE3CPIC";
case WL1_FACE4APIC: return "FACE4APIC";
case WL1_FACE4BPIC: return "FACE4BPIC";
case WL1_FACE4CPIC: return "FACE4CPIC";
case WL1_FACE5APIC: return "FACE5APIC";
case WL1_FACE5BPIC: return "FACE5BPIC";
case WL1_FACE5CPIC: return "FACE5CPIC";
case WL1_FACE6APIC: return "FACE6APIC";
case WL1_FACE6BPIC: return "FACE6BPIC";
case WL1_FACE6CPIC: return "FACE6CPIC";
case WL1_FACE7APIC: return "FACE7APIC";
case WL1_FACE7BPIC: return "FACE7BPIC";
case WL1_FACE7CPIC: return "FACE7CPIC";
case WL1_FACE8APIC: return "FACE8APIC";
case WL1_GOTGATLINGPIC: return "GOTGATLINGPIC";
case WL1_MUTANTBJPIC: return "MUTANTBJPIC";
case WL1_PAUSEDPIC: return "PAUSEDPIC";
case WL1_GETPSYCHEDPIC: return "GETPSYCHEDPIC";
default: return NULL;
} // End switch chunk
}
/*
-----------------------------------------------------------------------------
Function: GetLumpFileName_WL6() -Returns lump name string.
Parameters: chunk -[in] Chunk value to get string name for.
Returns: NULL on error, otherwise string name.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *GetLumpFileName_WL6( W32 chunk )
{
switch( chunk )
{
case H_BJPIC: return "H_BJPIC";
case H_CASTLEPIC: return "H_CASTLEPIC";
case H_BLAZEPIC: return "H_BLAZEPIC";
case H_TOPWINDOWPIC: return "H_TOPWINDOWPIC";
case H_LEFTWINDOWPIC: return "H_LEFTWINDOWPIC";
case H_RIGHTWINDOWPIC: return "H_RIGHTWINDOWPIC";
case H_BOTTOMINFOPIC: return "H_BOTTOMINFOPIC";
case C_OPTIONSPIC: return "C_OPTIONSPIC";
case C_CURSOR1PIC: return "C_CURSOR0PIC";
case C_CURSOR2PIC: return "C_CURSOR1PIC";
case C_NOTSELECTEDPIC: return "C_NOTSELECTEDPIC";
case C_SELECTEDPIC: return "C_SELECTEDPIC";
case C_FXTITLEPIC: return "C_FXTITLEPIC";
case C_DIGITITLEPIC: return "C_DIGITITLEPIC";
case C_MUSICTITLEPIC: return "C_MUSICTITLEPIC";
case C_MOUSELBACKPIC: return "C_MOUSELBACKPIC";
case C_BABYMODEPIC: return "C_SKILL1PIC";
case C_EASYPIC: return "C_SKILL2PIC";
case C_NORMALPIC: return "C_SKILL3PIC";
case C_HARDPIC: return "C_SKILL4PIC";
case C_LOADSAVEDISKPIC: return "C_LOADSAVEDISKPIC";
case C_DISKLOADING1PIC: return "C_DISKLOADING0PIC";
case C_DISKLOADING2PIC: return "C_DISKLOADING1PIC";
case C_CONTROLPIC: return "C_CONTROLPIC";
case C_CUSTOMIZEPIC: return "C_CUSTOMIZEPIC";
case C_LOADGAMEPIC: return "C_LOADGAMEPIC";
case C_SAVEGAMEPIC: return "C_SAVEGAMEPIC";
case C_EPISODE1PIC: return "C_EPISODE1PIC";
case C_EPISODE2PIC: return "C_EPISODE2PIC";
case C_EPISODE3PIC: return "C_EPISODE3PIC";
case C_EPISODE4PIC: return "C_EPISODE4PIC";
case C_EPISODE5PIC: return "C_EPISODE5PIC";
case C_EPISODE6PIC: return "C_EPISODE6PIC";
case C_CODEPIC: return "C_CODEPIC";
case C_TIMECODEPIC: return "C_TIMECODEPIC";
case C_LEVELPIC: return "C_LEVELPIC";
case C_NAMEPIC: return "C_NAMEPIC";
case C_SCOREPIC: return "C_SCOREPIC";
case C_JOY1PIC: return "C_JOY1PIC";
case C_JOY2PIC: return "C_JOY2PIC";
case L_GUYPIC: return "L_GUY0PIC";
case L_COLONPIC:
case L_NUM0PIC:
case L_NUM1PIC:
case L_NUM2PIC:
case L_NUM3PIC:
case L_NUM4PIC:
case L_NUM5PIC:
case L_NUM6PIC:
case L_NUM7PIC:
case L_NUM8PIC:
case L_NUM9PIC:
case L_PERCENTPIC:
case L_APIC:
case L_BPIC:
case L_CPIC:
case L_DPIC:
case L_EPIC:
case L_FPIC:
case L_GPIC:
case L_HPIC:
case L_IPIC:
case L_JPIC:
case L_KPIC:
case L_LPIC:
case L_MPIC:
case L_NPIC:
case L_OPIC:
case L_PPIC:
case L_QPIC:
case L_RPIC:
case L_SPIC:
case L_TPIC:
case L_UPIC:
case L_VPIC:
case L_WPIC:
case L_XPIC:
case L_YPIC:
case L_ZPIC:
case L_EXPOINTPIC:
case L_APOSTROPHEPIC: return "L_FONTPIC";
case L_GUY2PIC: return "L_GUY1PIC";
case L_BJWINSPIC: return "L_BJWINSPIC";
case STATUSBARPIC: return "STATUSBARPIC";
case TITLEPIC: return "TITLEPIC";
case PG13PIC: return "PC13PIC";
case CREDITSPIC: return "CREDITSPIC";
case HIGHSCORESPIC: return "HIGHSCORESPIC";
case KNIFEPIC: return "KNIFEPIC";
case GUNPIC: return "GUNPIC";
case MACHINEGUNPIC: return "MACHINEGUNPIC";
case GATLINGGUNPIC: return "GATLINGGUNPIC";
case NOKEYPIC: return "NOKEYPIC";
case GOLDKEYPIC: return "GOLDKEYPIC";
case SILVERKEYPIC: return "SILVERKEYPIC";
case N_BLANKPIC: return "N_BLANKPIC";
case N_0PIC:
case N_1PIC:
case N_2PIC:
case N_3PIC:
case N_4PIC:
case N_5PIC:
case N_6PIC:
case N_7PIC:
case N_8PIC:
case N_9PIC: return "N_NUMPIC";
case FACE1APIC: return "FACE1APIC";
case FACE1BPIC: return "FACE1BPIC";
case FACE1CPIC: return "FACE1CPIC";
case FACE2APIC: return "FACE2APIC";
case FACE2BPIC: return "FACE2BPIC";
case FACE2CPIC: return "FACE2CPIC";
case FACE3APIC: return "FACE3APIC";
case FACE3BPIC: return "FACE3BPIC";
case FACE3CPIC: return "FACE3CPIC";
case FACE4APIC: return "FACE4APIC";
case FACE4BPIC: return "FACE4BPIC";
case FACE4CPIC: return "FACE4CPIC";
case FACE5APIC: return "FACE5APIC";
case FACE5BPIC: return "FACE5BPIC";
case FACE5CPIC: return "FACE5CPIC";
case FACE6APIC: return "FACE6APIC";
case FACE6BPIC: return "FACE6BPIC";
case FACE6CPIC: return "FACE6CPIC";
case FACE7APIC: return "FACE7APIC";
case FACE7BPIC: return "FACE7BPIC";
case FACE7CPIC: return "FACE7CPIC";
case FACE8APIC: return "FACE8APIC";
case GOTGATLINGPIC: return "GOTGATLINGPIC";
case MUTANTBJPIC: return "MUTANTBJPIC";
case PAUSEDPIC: return "PAUSEDPIC";
case GETPSYCHEDPIC: return "GETPSYCHEDPIC";
default: return NULL;
} // End switch chunk
}
/*
-----------------------------------------------------------------------------
Function: GetLumpFileName_SDM() -Returns lump name string.
Parameters: chunk -[in] Chunk value to get string name for.
Returns: NULL on error, otherwise string name.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *GetLumpFileName_SDM( W32 chunk )
{
switch( chunk )
{
case SDM_C_BACKDROPPIC: return "C_BACKDROPPIC";
case SDM_C_MOUSELBACKPIC: return "SC_MOUSELBACKPIC";
case SDM_C_CURSOR1PIC: return "SC_CURSOR0PIC";
case SDM_C_CURSOR2PIC: return "SC_CURSOR1PIC";
case SDM_C_NOTSELECTEDPIC: return "SC_NOTSELECTEDPIC";
case SDM_C_SELECTEDPIC: return "SC_SELECTEDPIC";
case SDM_C_CUSTOMIZEPIC: return "SC_CUSTOMIZEPIC";
case SDM_C_JOY1PIC: return "C_JOY1PIC";
case SDM_C_JOY2PIC: return "C_JOY2PIC";
case SDM_C_MOUSEPIC: return "C_MOUSEPIC";
case SDM_C_JOYSTICKPIC: return "C_JOYSTICKPIC";
case SDM_C_KEYBOARDPIC: return "C_KEYBOARDPIC";
case SDM_C_CONTROLPIC: return "SC_CONTROLPIC";
case SDM_C_OPTIONSPIC: return "SC_OPTIONSPIC";
case SDM_C_FXTITLEPIC: return "SC_FXTITLEPIC";
case SDM_C_DIGITITLEPIC: return "SC_DIGITITLEPIC";
case SDM_C_MUSICTITLEPIC: return "SC_MUSICTITLEPIC";
case SDM_C_HOWTOUGHPIC: return "C_HOWTOUGHPIC";
case SDM_C_BABYMODEPIC: return "SC_SKILL1PIC";
case SDM_C_EASYPIC: return "SC_SKILL2PIC";
case SDM_C_NORMALPIC: return "SC_SKILL3PIC";
case SDM_C_HARDPIC: return "SC_SKILL4PIC";
case SDM_C_DISKLOADING1PIC: return "C_DISKLOADING0PIC";
case SDM_C_DISKLOADING2PIC: return "C_DISKLOADING1PIC";
case SDM_C_LOADGAMEPIC: return "SC_LOADGAMEPIC";
case SDM_C_SAVEGAMEPIC: return "SC_SAVEGAMEPIC";
case SDM_HIGHSCORESPIC: return "SHIGHSCORESPIC";
case SDM_C_WONSPEARPIC: return "C_WONSPEARPIC";
case SDM_L_GUYPIC: return "L_GUY0PIC";
case SDM_L_COLONPIC:
case SDM_L_NUM0PIC:
case SDM_L_NUM1PIC:
case SDM_L_NUM2PIC:
case SDM_L_NUM3PIC:
case SDM_L_NUM4PIC:
case SDM_L_NUM5PIC:
case SDM_L_NUM6PIC:
case SDM_L_NUM7PIC:
case SDM_L_NUM8PIC:
case SDM_L_NUM9PIC:
case SDM_L_PERCENTPIC:
case SDM_L_APIC:
case SDM_L_BPIC:
case SDM_L_CPIC:
case SDM_L_DPIC:
case SDM_L_EPIC:
case SDM_L_FPIC:
case SDM_L_GPIC:
case SDM_L_HPIC:
case SDM_L_IPIC:
case SDM_L_JPIC:
case SDM_L_KPIC:
case SDM_L_LPIC:
case SDM_L_MPIC:
case SDM_L_NPIC:
case SDM_L_OPIC:
case SDM_L_PPIC:
case SDM_L_QPIC:
case SDM_L_RPIC:
case SDM_L_SPIC:
case SDM_L_TPIC:
case SDM_L_UPIC:
case SDM_L_VPIC:
case SDM_L_WPIC:
case SDM_L_XPIC:
case SDM_L_YPIC:
case SDM_L_ZPIC:
case SDM_L_EXPOINTPIC:
case SDM_L_APOSTROPHEPIC: return "L_FONTPIC";
case SDM_L_GUY2PIC: return "L_GUY1PIC";
case SDM_L_BJWINSPIC: return "L_BJWINSPIC";
case SDM_TITLE1PIC:
case SDM_TITLE2PIC: return "STITLEPIC";
case SDM_STATUSBARPIC: return "STATUSBARPIC";
case SDM_PG13PIC: return "PC13PIC";
case SDM_CREDITSPIC: return "SCREDITSPIC";
case SDM_KNIFEPIC: return "KNIFEPIC";
case SDM_GUNPIC: return "GUNPIC";
case SDM_MACHINEGUNPIC: return "MACHINEGUNPIC";
case SDM_GATLINGGUNPIC: return "GATLINGGUNPIC";
case SDM_NOKEYPIC: return "NOKEYPIC";
case SDM_GOLDKEYPIC: return "GOLDKEYPIC";
case SDM_SILVERKEYPIC: return "SILVERKEYPIC";
case SDM_N_BLANKPIC: return "N_BLANKPIC";
case SDM_N_0PIC:
case SDM_N_1PIC:
case SDM_N_2PIC:
case SDM_N_3PIC:
case SDM_N_4PIC:
case SDM_N_5PIC:
case SDM_N_6PIC:
case SDM_N_7PIC:
case SDM_N_8PIC:
case SDM_N_9PIC: return "N_NUMPIC";
case SDM_FACE1APIC: return "FACE1APIC";
case SDM_FACE1BPIC: return "FACE1BPIC";
case SDM_FACE1CPIC: return "FACE1CPIC";
case SDM_FACE2APIC: return "FACE2APIC";
case SDM_FACE2BPIC: return "FACE2BPIC";
case SDM_FACE2CPIC: return "FACE2CPIC";
case SDM_FACE3APIC: return "FACE3APIC";
case SDM_FACE3BPIC: return "FACE3BPIC";
case SDM_FACE3CPIC: return "FACE3CPIC";
case SDM_FACE4APIC: return "FACE4APIC";
case SDM_FACE4BPIC: return "FACE4BPIC";
case SDM_FACE4CPIC: return "FACE4CPIC";
case SDM_FACE5APIC: return "FACE5APIC";
case SDM_FACE5BPIC: return "FACE5BPIC";
case SDM_FACE5CPIC: return "FACE5CPIC";
case SDM_FACE6APIC: return "FACE6APIC";
case SDM_FACE6BPIC: return "FACE6BPIC";
case SDM_FACE6CPIC: return "FACE6CPIC";
case SDM_FACE7APIC: return "FACE7APIC";
case SDM_FACE7BPIC: return "FACE7BPIC";
case SDM_FACE7CPIC: return "FACE7CPIC";
case SDM_FACE8APIC: return "FACE8APIC";
case SDM_GOTGATLINGPIC: return "GOTGATLINGPIC";
case SDM_GODMODEFACE1PIC: return "GODMODEFACE0PIC";
case SDM_GODMODEFACE2PIC: return "GODMODEFACE1PIC";
case SDM_GODMODEFACE3PIC: return "GODMODEFACE2PIC";
case SDM_BJWAITING1PIC: return "BJWAITING0PIC";
case SDM_BJWAITING2PIC: return "BJWAITING1PIC";
case SDM_BJOUCHPIC: return "BJOUCHPIC";
case SDM_PAUSEDPIC: return "PAUSEDPIC";
case SDM_GETPSYCHEDPIC: return "GETPSYCHEDPIC";
default: return NULL;
} // End switch chunk
}
/*
-----------------------------------------------------------------------------
Function: GetLumpFileName_SOD() -Returns lump name string.
Parameters: chunk -[in] Chunk value to get string name for.
Returns: NULL on error, otherwise string name.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *GetLumpFileName_SOD( W32 chunk )
{
switch( chunk )
{
case SOD_C_BACKDROPPIC: return "C_BACKDROPPIC";
case SOD_C_MOUSELBACKPIC: return "SC_MOUSELBACKPIC";
case SOD_C_CURSOR1PIC: return "SC_CURSOR0PIC";
case SOD_C_CURSOR2PIC: return "SC_CURSOR1PIC";
case SOD_C_NOTSELECTEDPIC: return "SC_NOTSELECTEDPIC";
case SOD_C_SELECTEDPIC: return "SC_SELECTEDPIC";
case SOD_C_CUSTOMIZEPIC: return "SC_CUSTOMIZEPIC";
case SOD_C_JOY1PIC: return "C_JOY1PIC";
case SOD_C_JOY2PIC: return "C_JOY2PIC";
case SOD_C_MOUSEPIC: return "C_MOUSEPIC";
case SOD_C_JOYSTICKPIC: return "C_JOYSTICKPIC";
case SOD_C_KEYBOARDPIC: return "C_KEYBOARDPIC";
case SOD_C_CONTROLPIC: return "SC_CONTROLPIC";
case SOD_C_OPTIONSPIC: return "SC_OPTIONSPIC";
case SOD_C_FXTITLEPIC: return "SC_FXTITLEPIC";
case SOD_C_DIGITITLEPIC: return "SC_DIGITITLEPIC";
case SOD_C_MUSICTITLEPIC: return "SC_MUSICTITLEPIC";
case SOD_C_HOWTOUGHPIC: return "C_HOWTOUGHPIC";
case SOD_C_BABYMODEPIC: return "SC_SKILL1PIC";
case SOD_C_EASYPIC: return "SC_SKILL2PIC";
case SOD_C_NORMALPIC: return "SC_SKILL3PIC";
case SOD_C_HARDPIC: return "SC_SKILL4PIC";
case SOD_C_DISKLOADING1PIC: return "C_DISKLOADING0PIC";
case SOD_C_DISKLOADING2PIC: return "C_DISKLOADING1PIC";
case SOD_C_LOADGAMEPIC: return "SC_LOADGAMEPIC";
case SOD_C_SAVEGAMEPIC: return "SC_SAVEGAMEPIC";
case SOD_HIGHSCORESPIC: return "SHIGHSCORESPIC";
case SOD_C_WONSPEARPIC: return "C_WONSPEARPIC";
case SOD_BJCOLLAPSE1PIC: return "BJCOLLAPSE1PIC";
case SOD_BJCOLLAPSE2PIC: return "BJCOLLAPSE2PIC";
case SOD_BJCOLLAPSE3PIC: return "BJCOLLAPSE3PIC";
case SOD_BJCOLLAPSE4PIC: return "BJCOLLAPSE4PIC";
case SOD_ENDPICPIC: return "ENDPICPIC";
case SOD_L_GUYPIC: return "L_GUY0PIC";
case SOD_L_COLONPIC:
case SOD_L_NUM0PIC:
case SOD_L_NUM1PIC:
case SOD_L_NUM2PIC:
case SOD_L_NUM3PIC:
case SOD_L_NUM4PIC:
case SOD_L_NUM5PIC:
case SOD_L_NUM6PIC:
case SOD_L_NUM7PIC:
case SOD_L_NUM8PIC:
case SOD_L_NUM9PIC:
case SOD_L_PERCENTPIC:
case SOD_L_APIC:
case SOD_L_BPIC:
case SOD_L_CPIC:
case SOD_L_DPIC:
case SOD_L_EPIC:
case SOD_L_FPIC:
case SOD_L_GPIC:
case SOD_L_HPIC:
case SOD_L_IPIC:
case SOD_L_JPIC:
case SOD_L_KPIC:
case SOD_L_LPIC:
case SOD_L_MPIC:
case SOD_L_NPIC:
case SOD_L_OPIC:
case SOD_L_PPIC:
case SOD_L_QPIC:
case SOD_L_RPIC:
case SOD_L_SPIC:
case SOD_L_TPIC:
case SOD_L_UPIC:
case SOD_L_VPIC:
case SOD_L_WPIC:
case SOD_L_XPIC:
case SOD_L_YPIC:
case SOD_L_ZPIC:
case SOD_L_EXPOINTPIC:
case SOD_L_APOSTROPHEPIC: return "L_FONTPIC";
case SOD_L_GUY2PIC: return "L_GUY1PIC";
case SOD_L_BJWINSPIC: return "L_BJWINSPIC";
case SOD_TITLE1PIC:
case SOD_TITLE2PIC: return "STITLEPIC";
case SOD_ENDSCREEN11PIC: return "ENDSCREEN11PIC";
case SOD_ENDSCREEN12PIC: return "ENDSCREEN12PIC";
case SOD_ENDSCREEN3PIC: return "ENDSCREEN3PIC";
case SOD_ENDSCREEN4PIC: return "ENDSCREEN4PIC";
case SOD_ENDSCREEN5PIC: return "ENDSCREEN5PIC";
case SOD_ENDSCREEN6PIC: return "ENDSCREEN6PIC";
case SOD_ENDSCREEN7PIC: return "ENDSCREEN7PIC";
case SOD_ENDSCREEN8PIC: return "ENDSCREEN8PIC";
case SOD_ENDSCREEN9PIC: return "ENDSCREEN9PIC";
case SOD_STATUSBARPIC: return "STATUSBARPIC";
case SOD_PG13PIC: return "PC13PIC";
case SOD_CREDITSPIC: return "SCREDITSPIC";
case SOD_IDGUYS1PIC:
case SOD_IDGUYS2PIC: return "IDGUYSPIC";
case SOD_COPYPROTTOPPIC: return "COPYPROTTOPPIC";
case SOD_COPYPROTBOXPIC: return "COPYPROTBOXPIC";
case SOD_BOSSPIC1PIC: return "BOSSPIC1PIC";
case SOD_BOSSPIC2PIC: return "BOSSPIC2PIC";
case SOD_BOSSPIC3PIC: return "BOSSPIC3PIC";
case SOD_BOSSPIC4PIC: return "BOSSPIC4PIC";
case SOD_KNIFEPIC: return "KNIFEPIC";
case SOD_GUNPIC: return "GUNPIC";
case SOD_MACHINEGUNPIC: return "MACHINEGUNPIC";
case SOD_GATLINGGUNPIC: return "GATLINGGUNPIC";
case SOD_NOKEYPIC: return "NOKEYPIC";
case SOD_GOLDKEYPIC: return "GOLDKEYPIC";
case SOD_SILVERKEYPIC: return "SILVERKEYPIC";
case SOD_N_BLANKPIC: return "N_BLANKPIC";
case SOD_N_0PIC:
case SOD_N_1PIC:
case SOD_N_2PIC:
case SOD_N_3PIC:
case SOD_N_4PIC:
case SOD_N_5PIC:
case SOD_N_6PIC:
case SOD_N_7PIC:
case SOD_N_8PIC:
case SOD_N_9PIC: return "N_NUMPIC";
case SOD_FACE1APIC: return "FACE1APIC";
case SOD_FACE1BPIC: return "FACE1BPIC";
case SOD_FACE1CPIC: return "FACE1CPIC";
case SOD_FACE2APIC: return "FACE2APIC";
case SOD_FACE2BPIC: return "FACE2BPIC";
case SOD_FACE2CPIC: return "FACE2CPIC";
case SOD_FACE3APIC: return "FACE3APIC";
case SOD_FACE3BPIC: return "FACE3BPIC";
case SOD_FACE3CPIC: return "FACE3CPIC";
case SOD_FACE4APIC: return "FACE4APIC";
case SOD_FACE4BPIC: return "FACE4BPIC";
case SOD_FACE4CPIC: return "FACE4CPIC";
case SOD_FACE5APIC: return "FACE5APIC";
case SOD_FACE5BPIC: return "FACE5BPIC";
case SOD_FACE5CPIC: return "FACE5CPIC";
case SOD_FACE6APIC: return "FACE6APIC";
case SOD_FACE6BPIC: return "FACE6BPIC";
case SOD_FACE6CPIC: return "FACE6CPIC";
case SOD_FACE7APIC: return "FACE7APIC";
case SOD_FACE7BPIC: return "FACE7BPIC";
case SOD_FACE7CPIC: return "FACE7CPIC";
case SOD_FACE8APIC: return "FACE8APIC";
case SOD_GOTGATLINGPIC: return "GOTGATLINGPIC";
case SOD_GODMODEFACE1PIC: return "GODMODEFACE0PIC";
case SOD_GODMODEFACE2PIC: return "GODMODEFACE1PIC";
case SOD_GODMODEFACE3PIC: return "GODMODEFACE2PIC";
case SOD_BJWAITING1PIC: return "BJWAITING0PIC";
case SOD_BJWAITING2PIC: return "BJWAITING1PIC";
case SOD_BJOUCHPIC: return "BJOUCHPIC";
case SOD_PAUSEDPIC: return "PAUSEDPIC";
case SOD_GETPSYCHEDPIC: return "GETPSYCHEDPIC";
default: return NULL;
} // End switch chunk
}
PUBLIC char *GetMusicFileName_WL6( W32 chunk )
{
switch( chunk )
{
case CORNER_MUS: return "CORNER";
case DUNGEON_MUS: return "DUNGEON";
case WARMARCH_MUS: return "WARMARCH";
case GETTHEM_MUS: return "GETTHEM";
case HEADACHE_MUS: return "HEADACHE";
case HITLWLTZ_MUS: return "HITLWLTZ";
case INTROCW3_MUS: return "INTROCW3";
case NAZI_NOR_MUS: return "NAZI_NOR";
case NAZI_OMI_MUS: return "NAZI_OMI";
case POW_MUS: return "POW";
case SALUTE_MUS: return "SALUTE";
case SEARCHN_MUS: return "SEARCHN";
case SUSPENSE_MUS: return "SUSPENSE";
case VICTORS_MUS: return "VICTORS";
case WONDERIN_MUS: return "WONDERIN";
case FUNKYOU_MUS: return "FUNKYOU";
case ENDLEVEL_MUS: return "ENDLEVEL";
case GOINGAFT_MUS: return "GOINGAFT";
case PREGNANT_MUS: return "PREGNANT";
case ULTIMATE_MUS: return "ULTIMATE";
case NAZI_RAP_MUS: return "NAZI_RAP";
case ZEROHOUR_MUS: return "ZEROHOUR";
case TWELFTH_MUS: return "TWELFTH";
case ROSTER_MUS: return "ROSTER";
case URAHERO_MUS: return "URAHERO";
case VICMARCH_MUS: return "VICMARCH";
case PACMAN_MUS: return "PACMAN";
default: return NULL;
} // End switch chunk
}
PUBLIC char *GetMusicFileName_SOD( W32 chunk )
{
switch( chunk )
{
case SOD_XFUNKIE_MUS: return "XFUNKIE";
case SOD_DUNGEON_MUS: return "DUNGEON";
case SOD_XDEATH_MUS: return "XDEATH";
case SOD_GETTHEM_MUS: return "GETTHEM";
case SOD_XTIPTOE_MUS: return "XTIPTOE";
case SOD_GOINGAFT_MUS: return "GOINGAFT";
case SOD_URAHERO_MUS: return "URAHERO";
case SOD_XTHEEND_MUS: return "XTHEEND";
case SOD_NAZI_OMI_MUS: return "NAZI_OMI";
case SOD_POW_MUS: return "POW";
case SOD_TWELFTH_MUS: return "TWELFTH";
case SOD_SEARCHN_MUS: return "SEARCHN";
case SOD_SUSPENSE_MUS: return "SUSPENSE";
case SOD_ZEROHOUR_MUS: return "ZEROHOUR";
case SOD_WONDERIN_MUS: return "WONDERIN";
case SOD_ULTIMATE_MUS: return "ULTIMATE";
case SOD_ENDLEVEL_MUS: return "ENDLEVEL";
case SOD_XEVIL_MUS: return "XEVIL";
case SOD_XJAZNAZI_MUS: return "XJAZNAZI";
case SOD_COPYPRO_MUS: return "COPYPRO";
case SOD_XAWARD_MUS: return "XAWARD";
case SOD_XPUTIT_MUS: return "XPUTIT";
case SOD_XGETYOU_MUS: return "XGETYOU";
case SOD_XTOWER2_MUS: return "XTOWER2";
default: return NULL;
} // End switch chunk
}

View File

@@ -0,0 +1,507 @@
/*
Copyright (C) 2004 Michael Liebscher
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* wolf_aud.c: Decode Wolfenstein 3-D Adlib audio data.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Wolfenstein 3-D, and was originally
* written by Id Software, Inc.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "wolf_def.h"
#include "../string/com_string.h"
#include "../adlib/adlib.h"
#include "../adlib/fmopl.h"
#include "../loaders/wav.h"
#include "../filesys/file.h"
#include "../../../common/common_utils.h"
#include "../../../common/arch.h"
#include "../memory/memory.h"
#define AHEADFNAME "AUDIOHED"
#define AUDIOFNAME "AUDIOT"
#define MAX_CHUNK_SIZE 500
#define WL6_STARTMUSIC 262
#define SOD_STARTMUSIC 243
PRIVATE FILE *audiohandle;
PRIVATE W32 *audiostarts;
/*
-----------------------------------------------------------------------------
Function: CAL_SetupAudioFile() -Setup for decoding audio data.
Parameters: fextension -[in] Pointer to string with file extension.
Returns: Non-zero on success, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE W8 CAL_SetupAudioFile( const char *fextension )
{
FILE *handle;
SW32 length;
W32 count;
char fname[ 13 ];
if( ! fextension || ! *fextension )
{
printf( "NULL extension passed into CAL_SetupAudioFile!\n" );
return 0;
}
//
// load audiohed.XXX (offsets and lengths for audio file)
//
cs_strlcpy( fname, AHEADFNAME, sizeof( fname ) );
cs_strlcat( fname, fextension, sizeof( fname ) );
handle = fopen( cs_strupr( fname ), "rb" );
if( handle == NULL )
{
handle = fopen( cs_strlwr( fname ), "rb" );
if( handle == NULL )
{
printf( "Can not open file (%s) for read!\n", fname );
return 0;
}
}
length = FS_FileLength( handle );
if( length < 4 )
{
fclose( handle );
printf( "Incorrect audio header size on file: %s\n", fname );
return 0;
}
audiostarts = (PW32) MM_MALLOC( length );
if( audiostarts == NULL )
{
return 0;
}
count = fread( audiostarts, sizeof( W32 ), length >> 2, handle );
if( count != (W32)(length >> 2) )
{
fclose( handle );
printf( "[Error]: Read error on file: (%s)", fname );
return 0;
}
fclose( handle );
//
// open the Audio data file
//
cs_strlcpy( fname, AUDIOFNAME, sizeof( fname ) );
cs_strlcat( fname, fextension, sizeof( fname ) );
audiohandle = fopen( cs_strupr( fname ), "rb" );
if( audiohandle == NULL )
{
audiohandle = fopen( cs_strlwr( fname ), "rb" );
if( audiohandle == NULL )
{
printf( "Could not open file (%s) for read!\n", fname );
return 0;
}
}
return 1;
}
/*
-----------------------------------------------------------------------------
Function: CA_CacheAudioChunk() -Cache audio data.
Parameters: chunk -[in] Chunk number to cache.
BuffChunk -[in] Allocated memory block to hold data.
Returns: Non-zero on success, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE W8 CA_CacheAudioChunk( W32 chunk, W8 *BuffChunk )
{
W32 pos, length, count;
//
// load the chunk into a buffer
//
pos = audiostarts[ chunk ];
length = audiostarts[ chunk+1 ] - pos;
if( length < 1 || length > MAX_CHUNK_SIZE )
{
printf( "[CA_CacheAudioChunk]: Chunk length not valid\n" );
return 0;
}
if( fseek( audiohandle, pos, SEEK_SET ) != 0 )
{
printf( "[CA_CacheAudioChunk]: Could not seek!\n" );
return 0;
}
count = fread( BuffChunk, 1, length, audiohandle );
if( count != length )
{
printf( "[CA_CacheAudioChunk]: Read error!\n" );
return 0;
}
return 1;
}
/*
-----------------------------------------------------------------------------
Function: CA_SaveAudioChunk() -Decode and save audio data.
Parameters: chunk -[in] Chunk number to cache.
filename -[in] Save as filename.
BuffChunk -[in] Sound data to decode.
BuffWav -[in] Allocated memory block to hold decoded data.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void CA_SaveAudioChunk( W32 chunk, const char *filename,
W8 *BuffChunk, W8 *BuffWav )
{
W32 length;
if( ! filename || ! *filename )
{
return;
}
if( ! CA_CacheAudioChunk( chunk, BuffChunk ) )
{
return;
}
if( ADLIB_DecodeSound( (AdLibSound *)BuffChunk, BuffWav, &length ) == 0 )
{
return;
}
write_wav( filename, BuffWav, length, 1, 22050, 2 );
}
extern W32 ADLIB_UpdateMusic( W32 size, void *buffer );
extern W32 ADLIB_getLength( void *musbuffer );
extern void ADLIB_LoadMusic( void *musbuffer );
extern int vorbis_encode( const char *filename, void *data, W32 size, W32 in_channels, W32 in_samplesize,
W32 rate, W32 quality, W32 max_bitrate, W32 min_bitrate );
#define NCH 1 // channels
#define BPS 16 // bit per second
PRIVATE void CA_SaveMusicChunk( W32 chunk, const char *filename )
{
W8 *data, *BuffWav;
W32 pos, length, uncompr_length;
W32 len;
pos = audiostarts[ chunk ];
length = audiostarts[ chunk+1 ] - pos;
data = MM_MALLOC( length );
if( data == NULL )
{
return;
}
if( fseek( audiohandle, pos, SEEK_SET ) != 0 )
{
printf( "[CA_SaveMusicChunk]: Could not seek!\n" );
MM_FREE( data );
return;
}
if( fread( data, 1, length, audiohandle ) != length )
{
printf( "[CA_SaveMusicChunk]: Read error!\n" );
MM_FREE( data );
return;
}
uncompr_length = ADLIB_getLength( data );
if( uncompr_length == 1 )
{
MM_FREE( data );
return;
}
ADLIB_LoadMusic( data );
BuffWav = MM_MALLOC( uncompr_length * 64 * 2 );
if( BuffWav == NULL )
{
MM_FREE( data );
return;
}
len = ADLIB_UpdateMusic( uncompr_length, BuffWav );
#if 1
vorbis_encode( filename, BuffWav, len, 1, 16, 44100, 0, 0, 0 );
#else
write_wav( filename, BuffWav, len, 1, 44100, 2 );
#endif
MM_FREE( BuffWav );
MM_FREE( data );
}
/*
-----------------------------------------------------------------------------
Function: CAL_ShutdownAudioFile() -Decode and save audio data.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void CAL_ShutdownAudioFile()
{
if( audiohandle )
{
fclose( audiohandle );
audiohandle = NULL;
}
if( audiostarts )
{
MM_FREE( audiostarts );
}
}
/*
-----------------------------------------------------------------------------
Function: AudioRipper() -Interface to audio decoder.
Parameters: fextension -[in] file extension string.
start -[in] Chunk number for start of audio data.
end -[in] Chunk number for end of audio data.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC _boolean AudioRipper( const char *fextension,
W32 start, W32 end, W16 version )
{
W32 i, j;
char filename[ 64 ];
W8 *buffChunk;
W8 *buffWav;
W32 startofmusic = WL6_STARTMUSIC - 1;
W32 endofmusic = LASTMUSIC;
//
// Setup
//
if( version == SOD_PAK || version == SDM_PAK )
{
if( 0 == FS_Mkdir( SODLSFXDIR ) )
{
printf( "[%s] Could not create directory (%s)!\n", "wolf_aud.c", SODLSFXDIR );
return false;
}
startofmusic = SOD_STARTMUSIC;
endofmusic = SOD_LASTMUSIC;
}
else
{
if( 0 == FS_Mkdir( LSFXDIR ) )
{
printf( "[%s] Could not create directory (%s)!\n", "wolf_aud.c", LSFXDIR );
return false;
}
}
if( 0 == FS_Mkdir( MUSICDIR ) )
{
printf( "[%s] Could not create directory (%s)!\n", "wolf_aud.c", LSFXDIR );
return false;
}
if( ! CAL_SetupAudioFile( fextension ) )
{
CAL_ShutdownAudioFile();
return false;
}
if( ! ADLIB_Init( 22050 ) )
{
CAL_ShutdownAudioFile();
return false;
}
//
// Allocate buffers
//
buffChunk = MM_MALLOC( MAX_CHUNK_SIZE );
if( buffChunk == NULL )
{
ADLIB_Shutdown();
CAL_ShutdownAudioFile();
return false;
}
buffWav = MM_MALLOC( MAX_WAV_SIZE );
if( buffWav == NULL )
{
ADLIB_Shutdown();
CAL_ShutdownAudioFile();
MM_FREE( buffChunk );
return false;
}
//
// Decode Audio data
//
printf( "Decoding Audio Data...\n" );
for( i = start, j = 0; i < end; ++i, ++j )
{
if( version == SOD_PAK || version == SDM_PAK )
{
cs_snprintf( filename, sizeof( filename ), "%s/%.3d.wav", SODLSFXDIR, j );
}
else
{
cs_snprintf( filename, sizeof( filename ), "%s/%.3d.wav", LSFXDIR, j );
}
CA_SaveAudioChunk( i, filename, buffChunk, buffWav );
}
ADLIB_Shutdown();
MM_FREE( buffWav );
MM_FREE( buffChunk );
//
// Decode Music data
//
if( ! ADLIB_Init( 44100 ) )
{
CAL_ShutdownAudioFile();
return false;
}
printf( "Decoding Music Data...\n" );
for( i = 0 ; i < endofmusic ; ++i )
{
if( version == SOD_PAK || version == SDM_PAK )
{
cs_snprintf( filename, sizeof( filename ), "%s/%s.ogg", MUSICDIR, GetMusicFileName_SOD( i ) );
}
else
{
cs_snprintf( filename, sizeof( filename ), "%s/%s.ogg", MUSICDIR, GetMusicFileName_WL6( i ) );
}
CA_SaveMusicChunk( startofmusic + i, filename );
}
ADLIB_Shutdown();
//
// Shutdown
//
CAL_ShutdownAudioFile();
return true;
}

View File

@@ -0,0 +1,919 @@
/*
Copyright (C) 2004 Michael Liebscher
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* wolf_def.h: Valid chunk numbers for Wolfenstein 3-D and Spear of Destiny.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Wolfenstein 3-D, and was originally
* written by Id Software, Inc.
*
*/
/*
Notes:
This module is implemented by wolf_aud.c, wolf_gfx.c, wolf_map.c,
wolf_pal.c, wolf_pm.c and wl6_name.c.
*/
#ifndef __WOLF_DEF_H__
#define __WOLF_DEF_H__
#include "../../../common/arch.h"
#define WL1_PAK (1<<0)
#define WL6_PAK (1<<1)
#define SDM_PAK (1<<2)
#define SOD_PAK (1<<3)
#define MAC_PAK (1<<4)
#define THREEDO_PAK (1<<5)
#define WL1_FEXT "*.WL1"
#define WL6_FEXT "*.WL6"
#define SDM_FEXT "*.SDM"
#define SOD_FEXT "*.SOD"
#define MAC_FEXT "*.MAC"
#define GFXWALLDIR "walls"
#define GFXSPRITEDIR "sprites"
#define SFXDIR "sfx"
#define SODGFXSPRITEDIR "sodsprites"
#define SODSFXDIR "sodsfx"
#define MAPDIR "maps"
#define LGFXDIR "pics"
#define LSFXDIR "lsfx"
#define SODLSFXDIR "sodlsfx"
#define MUSICDIR "music"
typedef enum
{
// Lump Start
WL1_H_BJPIC = 3,
WL1_H_CASTLEPIC, // 4
WL1_H_KEYBOARDPIC, // 5
WL1_H_CONTROLPIC, // 6
WL1_H_HEALPIC, // 7
WL1_H_BGPIC, // 8
WL1_H_GUNPIC, // 9
WL1_H_KEYPIC, // 10
WL1_H_BLAZEPIC, // 11
WL1_H_WEAPON1234PIC, // 12
WL1_H_WOLFLOGOPIC, // 13
WL1_H_VISAPIC, // 14
WL1_H_MCPIC, // 15
WL1_H_IDLOGOPIC, // 16
WL1_H_TOPWINDOWPIC, // 17
WL1_H_LEFTWINDOWPIC, // 18
WL1_H_RIGHTWINDOWPIC, // 19
WL1_H_BOTTOMINFOPIC, // 20
WL1_H_GAMEPIC, // 21
// Lump Start
WL1_C_OPTIONSPIC, // 22
WL1_C_CURSOR1PIC, // 23
WL1_C_CURSOR2PIC, // 24
WL1_C_NOTSELECTEDPIC, // 25
WL1_C_SELECTEDPIC, // 26
WL1_C_FXTITLEPIC, // 27
WL1_C_DIGITITLEPIC, // 28
WL1_C_MUSICTITLEPIC, // 29
WL1_C_MOUSELBACKPIC, // 30
WL1_C_BABYMODEPIC, // 31
WL1_C_EASYPIC, // 32
WL1_C_NORMALPIC, // 33
WL1_C_HARDPIC, // 34
WL1_C_LOADSAVEDISKPIC, // 35
WL1_C_DISKLOADING1PIC, // 36
WL1_C_DISKLOADING2PIC, // 37
WL1_C_CONTROLPIC, // 38
WL1_C_CUSTOMIZEPIC, // 39
WL1_C_LOADGAMEPIC, // 40
WL1_C_SAVEGAMEPIC, // 41
WL1_C_EPISODE1PIC, // 42
WL1_C_EPISODE2PIC, // 43
WL1_C_EPISODE3PIC, // 44
WL1_C_EPISODE4PIC, // 45
WL1_C_EPISODE5PIC, // 46
WL1_C_EPISODE6PIC, // 47
WL1_C_CODEPIC, // 48
WL1_C_TIMECODEPIC, // 49
WL1_C_LEVELPIC, // 50
WL1_C_NAMEPIC, // 51
WL1_C_SCOREPIC, // 52
WL1_C_JOY1PIC, // 53
WL1_C_JOY2PIC, // 54
// Lump Start
WL1_L_GUYPIC, // 55
WL1_L_COLONPIC, // 56
WL1_L_NUM0PIC, // 57
WL1_L_NUM1PIC, // 58
WL1_L_NUM2PIC, // 59
WL1_L_NUM3PIC, // 60
WL1_L_NUM4PIC, // 61
WL1_L_NUM5PIC, // 62
WL1_L_NUM6PIC, // 63
WL1_L_NUM7PIC, // 64
WL1_L_NUM8PIC, // 65
WL1_L_NUM9PIC, // 66
WL1_L_PERCENTPIC, // 67
WL1_L_APIC, // 68
WL1_L_BPIC, // 69
WL1_L_CPIC, // 70
WL1_L_DPIC, // 71
WL1_L_EPIC, // 72
WL1_L_FPIC, // 73
WL1_L_GPIC, // 74
WL1_L_HPIC, // 75
WL1_L_IPIC, // 76
WL1_L_JPIC, // 77
WL1_L_KPIC, // 78
WL1_L_LPIC, // 79
WL1_L_MPIC, // 80
WL1_L_NPIC, // 81
WL1_L_OPIC, // 82
WL1_L_PPIC, // 83
WL1_L_QPIC, // 84
WL1_L_RPIC, // 85
WL1_L_SPIC, // 86
WL1_L_TPIC, // 87
WL1_L_UPIC, // 88
WL1_L_VPIC, // 89
WL1_L_WPIC, // 90
WL1_L_XPIC, // 91
WL1_L_YPIC, // 92
WL1_L_ZPIC, // 93
WL1_L_EXPOINTPIC, // 94
WL1_L_APOSTROPHEPIC, // 95
WL1_L_GUY2PIC, // 96
WL1_L_BJWINSPIC, // 97
WL1_STATUSBARPIC, // 98
WL1_TITLEPIC, // 99
WL1_PG13PIC, // 100
WL1_CREDITSPIC, // 101
WL1_HIGHSCORESPIC, // 102
// Lump Start
WL1_KNIFEPIC, // 103
WL1_GUNPIC, // 104
WL1_MACHINEGUNPIC, // 105
WL1_GATLINGGUNPIC, // 106
WL1_NOKEYPIC, // 107
WL1_GOLDKEYPIC, // 108
WL1_SILVERKEYPIC, // 109
WL1_N_BLANKPIC, // 110
WL1_N_0PIC, // 111
WL1_N_1PIC, // 112
WL1_N_2PIC, // 113
WL1_N_3PIC, // 114
WL1_N_4PIC, // 115
WL1_N_5PIC, // 116
WL1_N_6PIC, // 117
WL1_N_7PIC, // 118
WL1_N_8PIC, // 119
WL1_N_9PIC, // 120
WL1_FACE1APIC, // 121
WL1_FACE1BPIC, // 122
WL1_FACE1CPIC, // 123
WL1_FACE2APIC, // 124
WL1_FACE2BPIC, // 125
WL1_FACE2CPIC, // 126
WL1_FACE3APIC, // 127
WL1_FACE3BPIC, // 128
WL1_FACE3CPIC, // 129
WL1_FACE4APIC, // 130
WL1_FACE4BPIC, // 131
WL1_FACE4CPIC, // 132
WL1_FACE5APIC, // 133
WL1_FACE5BPIC, // 134
WL1_FACE5CPIC, // 135
WL1_FACE6APIC, // 136
WL1_FACE6BPIC, // 137
WL1_FACE6CPIC, // 138
WL1_FACE7APIC, // 139
WL1_FACE7BPIC, // 140
WL1_FACE7CPIC, // 141
WL1_FACE8APIC, // 142
WL1_GOTGATLINGPIC, // 143
WL1_MUTANTBJPIC, // 144
WL1_PAUSEDPIC, // 145
WL1_GETPSYCHEDPIC, // 146
WL1_ENUMEND
} wl1_graphicnums;
typedef enum
{
// Lump Start
H_BJPIC = 3,
H_CASTLEPIC, // 4
H_BLAZEPIC, // 5
H_TOPWINDOWPIC, // 6
H_LEFTWINDOWPIC, // 7
H_RIGHTWINDOWPIC, // 8
H_BOTTOMINFOPIC, // 9
// Lump Start
C_OPTIONSPIC, // 10
C_CURSOR1PIC, // 11
C_CURSOR2PIC, // 12
C_NOTSELECTEDPIC, // 13
C_SELECTEDPIC, // 14
C_FXTITLEPIC, // 15
C_DIGITITLEPIC, // 16
C_MUSICTITLEPIC, // 17
C_MOUSELBACKPIC, // 18
C_BABYMODEPIC, // 19
C_EASYPIC, // 20
C_NORMALPIC, // 21
C_HARDPIC, // 22
C_LOADSAVEDISKPIC, // 23
C_DISKLOADING1PIC, // 24
C_DISKLOADING2PIC, // 25
C_CONTROLPIC, // 26
C_CUSTOMIZEPIC, // 27
C_LOADGAMEPIC, // 28
C_SAVEGAMEPIC, // 29
C_EPISODE1PIC, // 30
C_EPISODE2PIC, // 31
C_EPISODE3PIC, // 32
C_EPISODE4PIC, // 33
C_EPISODE5PIC, // 34
C_EPISODE6PIC, // 35
C_CODEPIC, // 36
C_TIMECODEPIC, // 37
C_LEVELPIC, // 38
C_NAMEPIC, // 39
C_SCOREPIC, // 40
C_JOY1PIC, // 41
C_JOY2PIC, // 42
// Lump Start
L_GUYPIC, // 43
L_COLONPIC, // 44
L_NUM0PIC, // 45
L_NUM1PIC, // 46
L_NUM2PIC, // 47
L_NUM3PIC, // 48
L_NUM4PIC, // 49
L_NUM5PIC, // 50
L_NUM6PIC, // 51
L_NUM7PIC, // 52
L_NUM8PIC, // 53
L_NUM9PIC, // 54
L_PERCENTPIC, // 55
L_APIC, // 56
L_BPIC, // 57
L_CPIC, // 58
L_DPIC, // 59
L_EPIC, // 60
L_FPIC, // 61
L_GPIC, // 62
L_HPIC, // 63
L_IPIC, // 64
L_JPIC, // 65
L_KPIC, // 66
L_LPIC, // 67
L_MPIC, // 68
L_NPIC, // 69
L_OPIC, // 70
L_PPIC, // 71
L_QPIC, // 72
L_RPIC, // 73
L_SPIC, // 74
L_TPIC, // 75
L_UPIC, // 76
L_VPIC, // 77
L_WPIC, // 78
L_XPIC, // 79
L_YPIC, // 80
L_ZPIC, // 81
L_EXPOINTPIC, // 82
L_APOSTROPHEPIC, // 83
L_GUY2PIC, // 84
L_BJWINSPIC, // 85
STATUSBARPIC, // 86
TITLEPIC, // 87
PG13PIC, // 88
CREDITSPIC, // 89
HIGHSCORESPIC, // 90
// Lump Start
KNIFEPIC, // 91
GUNPIC, // 92
MACHINEGUNPIC, // 93
GATLINGGUNPIC, // 94
NOKEYPIC, // 95
GOLDKEYPIC, // 96
SILVERKEYPIC, // 97
N_BLANKPIC, // 98
N_0PIC, // 99
N_1PIC, // 100
N_2PIC, // 101
N_3PIC, // 102
N_4PIC, // 103
N_5PIC, // 104
N_6PIC, // 105
N_7PIC, // 106
N_8PIC, // 107
N_9PIC, // 108
FACE1APIC, // 109
FACE1BPIC, // 110
FACE1CPIC, // 111
FACE2APIC, // 112
FACE2BPIC, // 113
FACE2CPIC, // 114
FACE3APIC, // 115
FACE3BPIC, // 116
FACE3CPIC, // 117
FACE4APIC, // 118
FACE4BPIC, // 119
FACE4CPIC, // 120
FACE5APIC, // 121
FACE5BPIC, // 122
FACE5CPIC, // 123
FACE6APIC, // 124
FACE6BPIC, // 125
FACE6CPIC, // 126
FACE7APIC, // 127
FACE7BPIC, // 128
FACE7CPIC, // 129
FACE8APIC, // 130
GOTGATLINGPIC, // 131
MUTANTBJPIC, // 132
PAUSEDPIC, // 133
GETPSYCHEDPIC, // 134
ORDERSCREEN=136,
ERRORSCREEN, // 137
T_HELPART, // 138
T_DEMO0, // 139
T_DEMO1, // 140
T_DEMO2, // 141
T_DEMO3, // 142
T_ENDART1, // 143
T_ENDART2, // 144
T_ENDART3, // 145
T_ENDART4, // 146
T_ENDART5, // 147
T_ENDART6, // 148
ENUMEND
} graphicnums;
typedef enum
{
// Lump Start
SDM_C_BACKDROPPIC = 3,
SDM_C_MOUSELBACKPIC, // 4
SDM_C_CURSOR1PIC, // 5
SDM_C_CURSOR2PIC, // 6
SDM_C_NOTSELECTEDPIC, // 7
SDM_C_SELECTEDPIC, // 8
// Lump Start
SDM_C_CUSTOMIZEPIC, // 9
SDM_C_JOY1PIC, // 10
SDM_C_JOY2PIC, // 11
SDM_C_MOUSEPIC, // 12
SDM_C_JOYSTICKPIC, // 13
SDM_C_KEYBOARDPIC, // 14
SDM_C_CONTROLPIC, // 15
// Lump Start
SDM_C_OPTIONSPIC, // 16
// Lump Start
SDM_C_FXTITLEPIC, // 17
SDM_C_DIGITITLEPIC, // 18
SDM_C_MUSICTITLEPIC, // 19
// Lump Start
SDM_C_HOWTOUGHPIC, // 20
SDM_C_BABYMODEPIC, // 21
SDM_C_EASYPIC, // 22
SDM_C_NORMALPIC, // 23
SDM_C_HARDPIC, // 24
// Lump Start
SDM_C_DISKLOADING1PIC, // 25
SDM_C_DISKLOADING2PIC, // 26
SDM_C_LOADGAMEPIC, // 27
SDM_C_SAVEGAMEPIC, // 28
// Lump Start
SDM_HIGHSCORESPIC, // 29
SDM_C_WONSPEARPIC, // 30
// Lump Start
SDM_L_GUYPIC, // 31
SDM_L_COLONPIC, // 32
SDM_L_NUM0PIC, // 33
SDM_L_NUM1PIC, // 34
SDM_L_NUM2PIC, // 35
SDM_L_NUM3PIC, // 36
SDM_L_NUM4PIC, // 37
SDM_L_NUM5PIC, // 38
SDM_L_NUM6PIC, // 39
SDM_L_NUM7PIC, // 40
SDM_L_NUM8PIC, // 41
SDM_L_NUM9PIC, // 42
SDM_L_PERCENTPIC, // 43
SDM_L_APIC, // 44
SDM_L_BPIC, // 45
SDM_L_CPIC, // 46
SDM_L_DPIC, // 47
SDM_L_EPIC, // 48
SDM_L_FPIC, // 49
SDM_L_GPIC, // 50
SDM_L_HPIC, // 51
SDM_L_IPIC, // 52
SDM_L_JPIC, // 53
SDM_L_KPIC, // 54
SDM_L_LPIC, // 55
SDM_L_MPIC, // 56
SDM_L_NPIC, // 57
SDM_L_OPIC, // 58
SDM_L_PPIC, // 59
SDM_L_QPIC, // 60
SDM_L_RPIC, // 61
SDM_L_SPIC, // 62
SDM_L_TPIC, // 63
SDM_L_UPIC, // 64
SDM_L_VPIC, // 65
SDM_L_WPIC, // 66
SDM_L_XPIC, // 67
SDM_L_YPIC, // 68
SDM_L_ZPIC, // 69
SDM_L_EXPOINTPIC, // 70
SDM_L_APOSTROPHEPIC, // 71
SDM_L_GUY2PIC, // 72
SDM_L_BJWINSPIC, // 73
// Lump Start
SDM_TITLE1PIC, // 74
SDM_TITLE2PIC, // 75
SDM_STATUSBARPIC, // 76
SDM_PG13PIC, // 77
SDM_CREDITSPIC, // 78
// Lump Start
SDM_KNIFEPIC, // 79
SDM_GUNPIC, // 80
SDM_MACHINEGUNPIC, // 81
SDM_GATLINGGUNPIC, // 82
SDM_NOKEYPIC, // 83
SDM_GOLDKEYPIC, // 84
SDM_SILVERKEYPIC, // 85
SDM_N_BLANKPIC, // 86
SDM_N_0PIC, // 87
SDM_N_1PIC, // 88
SDM_N_2PIC, // 89
SDM_N_3PIC, // 90
SDM_N_4PIC, // 91
SDM_N_5PIC, // 92
SDM_N_6PIC, // 93
SDM_N_7PIC, // 94
SDM_N_8PIC, // 95
SDM_N_9PIC, // 96
SDM_FACE1APIC, // 97
SDM_FACE1BPIC, // 98
SDM_FACE1CPIC, // 99
SDM_FACE2APIC, // 100
SDM_FACE2BPIC, // 101
SDM_FACE2CPIC, // 102
SDM_FACE3APIC, // 103
SDM_FACE3BPIC, // 104
SDM_FACE3CPIC, // 105
SDM_FACE4APIC, // 106
SDM_FACE4BPIC, // 107
SDM_FACE4CPIC, // 108
SDM_FACE5APIC, // 109
SDM_FACE5BPIC, // 110
SDM_FACE5CPIC, // 111
SDM_FACE6APIC, // 112
SDM_FACE6BPIC, // 113
SDM_FACE6CPIC, // 114
SDM_FACE7APIC, // 115
SDM_FACE7BPIC, // 116
SDM_FACE7CPIC, // 117
SDM_FACE8APIC, // 118
SDM_GOTGATLINGPIC, // 119
SDM_GODMODEFACE1PIC, // 120
SDM_GODMODEFACE2PIC, // 121
SDM_GODMODEFACE3PIC, // 122
SDM_BJWAITING1PIC, // 123
SDM_BJWAITING2PIC, // 124
SDM_BJOUCHPIC, // 125
SDM_PAUSEDPIC, // 126
SDM_GETPSYCHEDPIC, // 127
SDM_ORDERSCREEN = 129,
SDM_ERRORSCREEN, // 130
SDM_TITLEPALETTE, // 131
SDM_T_DEMO0, // 132
SDM_ENUMEND
} sdm_graphicnums;
typedef enum
{
// Lump Start
SOD_C_BACKDROPPIC = 3,
SOD_C_MOUSELBACKPIC, // 4
SOD_C_CURSOR1PIC, // 5
SOD_C_CURSOR2PIC, // 6
SOD_C_NOTSELECTEDPIC, // 7
SOD_C_SELECTEDPIC, // 8
// Lump Start
SOD_C_CUSTOMIZEPIC, // 9
SOD_C_JOY1PIC, // 10
SOD_C_JOY2PIC, // 11
SOD_C_MOUSEPIC, // 12
SOD_C_JOYSTICKPIC, // 13
SOD_C_KEYBOARDPIC, // 14
SOD_C_CONTROLPIC, // 15
// Lump Start
SOD_C_OPTIONSPIC, // 16
// Lump Start
SOD_C_FXTITLEPIC, // 17
SOD_C_DIGITITLEPIC, // 18
SOD_C_MUSICTITLEPIC, // 19
// Lump Start
SOD_C_HOWTOUGHPIC, // 20
SOD_C_BABYMODEPIC, // 21
SOD_C_EASYPIC, // 22
SOD_C_NORMALPIC, // 23
SOD_C_HARDPIC, // 24
// Lump Start
SOD_C_DISKLOADING1PIC, // 25
SOD_C_DISKLOADING2PIC, // 26
SOD_C_LOADGAMEPIC, // 27
SOD_C_SAVEGAMEPIC, // 28
// Lump Start
SOD_HIGHSCORESPIC, // 29
SOD_C_WONSPEARPIC, // 30
// Lump Start
SOD_BJCOLLAPSE1PIC, // 31
SOD_BJCOLLAPSE2PIC, // 32
SOD_BJCOLLAPSE3PIC, // 33
SOD_BJCOLLAPSE4PIC, // 34
SOD_ENDPICPIC, // 35
// Lump Start
SOD_L_GUYPIC, // 36
SOD_L_COLONPIC, // 37
SOD_L_NUM0PIC, // 38
SOD_L_NUM1PIC, // 39
SOD_L_NUM2PIC, // 40
SOD_L_NUM3PIC, // 41
SOD_L_NUM4PIC, // 42
SOD_L_NUM5PIC, // 43
SOD_L_NUM6PIC, // 44
SOD_L_NUM7PIC, // 45
SOD_L_NUM8PIC, // 46
SOD_L_NUM9PIC, // 47
SOD_L_PERCENTPIC, // 48
SOD_L_APIC, // 49
SOD_L_BPIC, // 50
SOD_L_CPIC, // 51
SOD_L_DPIC, // 52
SOD_L_EPIC, // 53
SOD_L_FPIC, // 54
SOD_L_GPIC, // 55
SOD_L_HPIC, // 56
SOD_L_IPIC, // 57
SOD_L_JPIC, // 58
SOD_L_KPIC, // 59
SOD_L_LPIC, // 60
SOD_L_MPIC, // 61
SOD_L_NPIC, // 62
SOD_L_OPIC, // 63
SOD_L_PPIC, // 64
SOD_L_QPIC, // 65
SOD_L_RPIC, // 66
SOD_L_SPIC, // 67
SOD_L_TPIC, // 68
SOD_L_UPIC, // 69
SOD_L_VPIC, // 70
SOD_L_WPIC, // 71
SOD_L_XPIC, // 72
SOD_L_YPIC, // 73
SOD_L_ZPIC, // 74
SOD_L_EXPOINTPIC, // 75
SOD_L_APOSTROPHEPIC, // 76
SOD_L_GUY2PIC, // 77
SOD_L_BJWINSPIC, // 78
// Lump Start
SOD_TITLE1PIC, // 79
SOD_TITLE2PIC, // 80
// Lump Start
SOD_ENDSCREEN11PIC, // 81
// Lump Start
SOD_ENDSCREEN12PIC, // 82
SOD_ENDSCREEN3PIC, // 83
SOD_ENDSCREEN4PIC, // 84
SOD_ENDSCREEN5PIC, // 85
SOD_ENDSCREEN6PIC, // 86
SOD_ENDSCREEN7PIC, // 87
SOD_ENDSCREEN8PIC, // 88
SOD_ENDSCREEN9PIC, // 89
SOD_STATUSBARPIC, // 90
SOD_PG13PIC, // 91
SOD_CREDITSPIC, // 92
// Lump Start
SOD_IDGUYS1PIC, // 93
SOD_IDGUYS2PIC, // 94
// Lump Start
SOD_COPYPROTTOPPIC, // 95
SOD_COPYPROTBOXPIC, // 96
SOD_BOSSPIC1PIC, // 97
SOD_BOSSPIC2PIC, // 98
SOD_BOSSPIC3PIC, // 99
SOD_BOSSPIC4PIC, // 100
// Lump Start
SOD_KNIFEPIC, // 101
SOD_GUNPIC, // 102
SOD_MACHINEGUNPIC, // 103
SOD_GATLINGGUNPIC, // 104
SOD_NOKEYPIC, // 105
SOD_GOLDKEYPIC, // 106
SOD_SILVERKEYPIC, // 107
SOD_N_BLANKPIC, // 108
SOD_N_0PIC, // 109
SOD_N_1PIC, // 110
SOD_N_2PIC, // 111
SOD_N_3PIC, // 112
SOD_N_4PIC, // 113
SOD_N_5PIC, // 114
SOD_N_6PIC, // 115
SOD_N_7PIC, // 116
SOD_N_8PIC, // 117
SOD_N_9PIC, // 118
SOD_FACE1APIC, // 119
SOD_FACE1BPIC, // 120
SOD_FACE1CPIC, // 121
SOD_FACE2APIC, // 122
SOD_FACE2BPIC, // 123
SOD_FACE2CPIC, // 124
SOD_FACE3APIC, // 125
SOD_FACE3BPIC, // 126
SOD_FACE3CPIC, // 127
SOD_FACE4APIC, // 128
SOD_FACE4BPIC, // 129
SOD_FACE4CPIC, // 130
SOD_FACE5APIC, // 131
SOD_FACE5BPIC, // 132
SOD_FACE5CPIC, // 133
SOD_FACE6APIC, // 134
SOD_FACE6BPIC, // 135
SOD_FACE6CPIC, // 136
SOD_FACE7APIC, // 137
SOD_FACE7BPIC, // 138
SOD_FACE7CPIC, // 139
SOD_FACE8APIC, // 140
SOD_GOTGATLINGPIC, // 141
SOD_GODMODEFACE1PIC, // 142
SOD_GODMODEFACE2PIC, // 143
SOD_GODMODEFACE3PIC, // 144
SOD_BJWAITING1PIC, // 145
SOD_BJWAITING2PIC, // 146
SOD_BJOUCHPIC, // 147
SOD_PAUSEDPIC, // 148
SOD_GETPSYCHEDPIC, // 149
SOD_ORDERSCREEN = 151,
SOD_ERRORSCREEN, // 152
SOD_TITLEPALETTE, // 153
SOD_END1PALETTE, // 154
SOD_END2PALETTE, // 155
SOD_END3PALETTE, // 156
SOD_END4PALETTE, // 157
SOD_END5PALETTE, // 158
SOD_END6PALETTE, // 159
SOD_END7PALETTE, // 160
SOD_END8PALETTE, // 161
SOD_END9PALETTE, // 162
SOD_IDGUYSPALETTE, // 163
SOD_T_DEMO0, // 164
SOD_T_DEMO1, // 165
SOD_T_DEMO2, // 166
SOD_T_DEMO3, // 167
SOD_T_ENDART1, // 168
SOD_ENUMEND
} sod_graphicnums;
typedef enum
{
CORNER_MUS, // 0
DUNGEON_MUS, // 1
WARMARCH_MUS, // 2
GETTHEM_MUS, // 3
HEADACHE_MUS, // 4
HITLWLTZ_MUS, // 5
INTROCW3_MUS, // 6
NAZI_NOR_MUS, // 7
NAZI_OMI_MUS, // 8
POW_MUS, // 9
SALUTE_MUS, // 10
SEARCHN_MUS, // 11
SUSPENSE_MUS, // 12
VICTORS_MUS, // 13
WONDERIN_MUS, // 14
FUNKYOU_MUS, // 15
ENDLEVEL_MUS, // 16
GOINGAFT_MUS, // 17
PREGNANT_MUS, // 18
ULTIMATE_MUS, // 19
NAZI_RAP_MUS, // 20
ZEROHOUR_MUS, // 21
TWELFTH_MUS, // 22
ROSTER_MUS, // 23
URAHERO_MUS, // 24
VICMARCH_MUS, // 25
PACMAN_MUS, // 26
LASTMUSIC
} wl6_musicnames;
typedef enum
{
SOD_XFUNKIE_MUS, // 0
SOD_DUNGEON_MUS, // 1
SOD_XDEATH_MUS, // 2
SOD_GETTHEM_MUS, // 3
SOD_XTIPTOE_MUS, // 4
SOD_GOINGAFT_MUS, // 5
SOD_URAHERO_MUS, // 6
SOD_XTHEEND_MUS, // 7
SOD_NAZI_OMI_MUS, // 8
SOD_POW_MUS, // 9
SOD_TWELFTH_MUS, // 10
SOD_SEARCHN_MUS, // 11
SOD_SUSPENSE_MUS, // 12
SOD_ZEROHOUR_MUS, // 13
SOD_WONDERIN_MUS, // 14
SOD_ULTIMATE_MUS, // 15
SOD_ENDLEVEL_MUS, // 16
SOD_XEVIL_MUS, // 17
SOD_XJAZNAZI_MUS, // 18
SOD_COPYPRO_MUS, // 19
SOD_XAWARD_MUS, // 20
SOD_XPUTIT_MUS, // 21
SOD_XGETYOU_MUS, // 22
SOD_XTOWER2_MUS, // 23
SOD_LASTMUSIC
} sod_musicnames;
/////////////////////////////////////////////////////////////////////
//
// WL1
//
/////////////////////////////////////////////////////////////////////
//
// Data LUMPs
//
#define WL1_README_LUMP_START 3
#define WL1_README_LUMP_END 25
#define WL1_CONTROLS_LUMP_START 26
#define WL1_CONTROLS_LUMP_END 52
#define WL1_LEVELEND_LUMP_START 53
#define WL1_LEVELEND_LUMP_END 93
#define WL1_LATCHPICS_LUMP_START 99
#define WL1_LATCHPICS_LUMP_END 141
/////////////////////////////////////////////////////////////////////
//
// WL6
//
/////////////////////////////////////////////////////////////////////
//
// Data LUMPs
//
#define WL6_README_LUMP_START 3
#define WL6_README_LUMP_END 9
#define WL6_CONTROLS_LUMP_START 10
#define WL6_CONTROLS_LUMP_END 42
#define WL6_LEVELEND_LUMP_START 43
#define WL6_LEVELEND_LUMP_END 85
#define WL6_LATCHPICS_LUMP_START 91
#define WL6_LATCHPICS_LUMP_END 134
//
// Amount of each data item
//
#define NUMFONT 2
#define NUMFONTM 0
#define NUMPICM 0
#define NUMSPRITES 0
#define NUMTILE8 72
#define NUMTILE8M 0
#define NUMTILE16 0
#define NUMTILE16M 0
#define NUMTILE32 0
#define NUMTILE32M 0
#define NUMEXTERNS 13
//
// File offsets for data items
//
#define STRUCTPIC 0
#define STARTFONT 1
#define STARTFONTM 3
#define STARTPICS 3
#define STARTPICM 135
#define STARTSPRITES 135
#define STARTTILE8 135
#define STARTTILE8M 136
#define STARTTILE16 136
#define STARTTILE16M 136
#define STARTTILE32 136
#define STARTTILE32M 136
#define STARTEXTERNS 136
/////////////////////////////////////////////////////////////////////
//
// Spear of Destiny
//
/////////////////////////////////////////////////////////////////////
//
// Amount of each data item
//
#define NUMCHUNKS 169
#define NUMPICS 147
#define SOD_NUMEXTERNS 18
//
// File offsets for data items
//
#define SOD_STARTDIFF 15
//// End SOD
extern _boolean LumpExtractor( const char *fextension, W32 limit, W16 version );
extern _boolean PExtractor( const char *extension, W16 version );
extern _boolean AudioRipper( const char *fextension, W32 start, W32 end, W16 version );
extern _boolean MapRipper( const char *fextension, W16 version );
extern char *GetMusicFileName_WL6( W32 chunk );
extern char *GetMusicFileName_SOD( W32 chunk );
extern char *GetLumpFileName_WL1( W32 chunk );
extern char *GetLumpFileName_WL6( W32 chunk );
extern char *GetLumpFileName_SDM( W32 chunk );
extern char *GetLumpFileName_SOD( W32 chunk );
#endif /* __WOLF_DEF_H__ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,692 @@
/*
Copyright (C) 2004-2005 Michael Liebscher
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* wolf_map.c: Decode Wolfenstein 3-D Map data.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Wolfenstein 3-D, and was originally
* written by Id Software, Inc.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "wolf_def.h"
#include "../string/com_string.h"
#include "../loaders/tga.h"
#include "../filesys/file.h"
#include "../../../common/arch.h"
#include "../memory/memory.h"
#include "../../../common/common_utils.h"
#define MAPHEADNAME "MAPHEAD"
#define MAPNAME "GAMEMAPS"
PRIVATE FILE *maphandle;
PRIVATE W32 headeroffsets[ 100 ];
PRIVATE W32 TotalMaps;
PRIVATE W16 RLEWtag;
PRIVATE W16 gameversion;
PRIVATE const W32 vgaCeilingWL6[] =
{
0x1d1d,0x1d1d,0x1d1d,0x1d1d,0x1d1d,0x1d1d,0x1d1d,0x1d1d,0x1d1d,0xbfbf,
0x4e4e,0x4e4e,0x4e4e,0x1d1d,0x8d8d,0x4e4e,0x1d1d,0x2d2d,0x1d1d,0x8d8d,
0x1d1d,0x1d1d,0x1d1d,0x1d1d,0x1d1d,0x2d2d,0xdddd,0x1d1d,0x1d1d,0x9898,
0x1d1d,0x9d9d,0x2d2d,0xdddd,0xdddd,0x9d9d,0x2d2d,0x4d4d,0x1d1d,0xdddd,
0x7d7d,0x1d1d,0x2d2d,0x2d2d,0xdddd,0xd7d7,0x1d1d,0x1d1d,0x1d1d,0x2d2d,
0x1d1d,0x1d1d,0x1d1d,0x1d1d,0xdddd,0xdddd,0x7d7d,0xdddd,0xdddd,0xdddd
};
PRIVATE const W32 vgaCeilingSOD[] =
{
0x6f6f,0x4f4f,0x1d1d,0xdede,0xdfdf,0x2e2e,0x7f7f,0x9e9e,0xaeae,0x7f7f,
0x1d1d,0xdede,0xdfdf,0xdede,0xdfdf,0xdede,0xe1e1,0xdcdc,0x2e2e,0x1d1d,0xdcdc
};
PRIVATE W32 WL6_songs[] =
{
//
// Episode One
//
GETTHEM_MUS,
SEARCHN_MUS,
POW_MUS,
SUSPENSE_MUS,
GETTHEM_MUS,
SEARCHN_MUS,
POW_MUS,
SUSPENSE_MUS,
WARMARCH_MUS, // Boss level
CORNER_MUS, // Secret level
//
// Episode Two
//
NAZI_OMI_MUS,
PREGNANT_MUS,
GOINGAFT_MUS,
HEADACHE_MUS,
NAZI_OMI_MUS,
PREGNANT_MUS,
HEADACHE_MUS,
GOINGAFT_MUS,
WARMARCH_MUS, // Boss level
DUNGEON_MUS, // Secret level
//
// Episode Three
//
INTROCW3_MUS,
NAZI_RAP_MUS,
TWELFTH_MUS,
ZEROHOUR_MUS,
INTROCW3_MUS,
NAZI_RAP_MUS,
TWELFTH_MUS,
ZEROHOUR_MUS,
ULTIMATE_MUS, // Boss level
PACMAN_MUS, // Secret level
//
// Episode Four
//
GETTHEM_MUS,
SEARCHN_MUS,
POW_MUS,
SUSPENSE_MUS,
GETTHEM_MUS,
SEARCHN_MUS,
POW_MUS,
SUSPENSE_MUS,
WARMARCH_MUS, // Boss level
CORNER_MUS, // Secret level
//
// Episode Five
//
NAZI_OMI_MUS,
PREGNANT_MUS,
GOINGAFT_MUS,
HEADACHE_MUS,
NAZI_OMI_MUS,
PREGNANT_MUS,
HEADACHE_MUS,
GOINGAFT_MUS,
WARMARCH_MUS, // Boss level
DUNGEON_MUS, // Secret level
//
// Episode Six
//
INTROCW3_MUS,
NAZI_RAP_MUS,
TWELFTH_MUS,
ZEROHOUR_MUS,
INTROCW3_MUS,
NAZI_RAP_MUS,
TWELFTH_MUS,
ZEROHOUR_MUS,
ULTIMATE_MUS, // Boss level
FUNKYOU_MUS // Secret level
};
PRIVATE W32 SOD_songs[] =
{
SOD_XTIPTOE_MUS,
SOD_XFUNKIE_MUS,
SOD_XDEATH_MUS,
SOD_XGETYOU_MUS, // DON'T KNOW
SOD_ULTIMATE_MUS, // Trans Grosse
SOD_DUNGEON_MUS,
SOD_GOINGAFT_MUS,
SOD_POW_MUS,
SOD_TWELFTH_MUS,
SOD_ULTIMATE_MUS, // Barnacle Wilhelm BOSS
SOD_NAZI_OMI_MUS,
SOD_GETTHEM_MUS,
SOD_SUSPENSE_MUS,
SOD_SEARCHN_MUS,
SOD_ZEROHOUR_MUS,
SOD_ULTIMATE_MUS, // Super Mutant BOSS
SOD_XPUTIT_MUS,
SOD_ULTIMATE_MUS, // Death Knight BOSS
SOD_XJAZNAZI_MUS, // Secret level
SOD_XFUNKIE_MUS, // Secret level (DON'T KNOW)
SOD_XEVIL_MUS // Angel of Death BOSS
};
typedef struct
{
float time;
char timestr[ 6 ];
} times;
PRIVATE times parTimesWL6[] =
{
//
// Episode One Par Times
//
{ 1.5, "01:30" },
{ 2, "02:00" },
{ 2, "02:00" },
{ 3.5, "03:30" },
{ 3, "03:00" },
{ 3, "03:00" },
{ 2.5, "02:30" },
{ 2.5, "02:30" },
{ 0, "??:??" }, // Boss level
{ 0, "??:??" }, // Secret level
//
// Episode Two Par Times
//
{ 1.5, "01:30" },
{ 3.5, "03:30" },
{ 3, "03:00" },
{ 2, "02:00" },
{ 4, "04:00" },
{ 6, "06:00" },
{ 1, "01:00" },
{ 3, "03:00" },
{ 0, "??:??" },
{ 0, "??:??" },
//
// Episode Three Par Times
//
{ 1.5, "01:30" },
{ 1.5, "01:30" },
{ 2.5, "02:30" },
{ 2.5, "02:30" },
{ 3.5, "03:30" },
{ 2.5, "02:30" },
{ 2, "02:00" },
{ 6, "06:00" },
{ 0, "??:??" },
{ 0, "??:??" },
//
// Episode Four Par Times
//
{ 2, "02:00" },
{ 2, "02:00" },
{ 1.5, "01:30" },
{ 1, "01:00" },
{ 4.5, "04:30" },
{ 3.5, "03:30" },
{ 2, "02:00" },
{ 4.5, "04:30" },
{ 0, "??:??" },
{ 0, "??:??" },
//
// Episode Five Par Times
//
{ 2.5, "02:30" },
{ 1.5, "01:30" },
{ 2.5, "02:30" },
{ 2.5, "02:30" },
{ 4, "04:00" },
{ 3, "03:00" },
{ 4.5, "04:30" },
{ 3.5, "03:30" },
{ 0, "??:??" },
{ 0, "??:??" },
//
// Episode Six Par Times
//
{ 6.5, "06:30" },
{ 4, "04:00" },
{ 4.5, "04:30" },
{ 6, "06:00" },
{ 5, "05:00" },
{ 5.5, "05:30" },
{ 5.5, "05:30" },
{ 8.5, "08:30" },
{ 0, "??:??" },
{ 0, "??:??" }
};
PRIVATE times parTimesSOD[] =
{
//
// SPEAR OF DESTINY TIMES
//
{ 1.5, "01:30" },
{ 3.5, "03:30" },
{ 2.75,"02:45" },
{ 3.5, "03:30" },
{ 0, "??:??" }, // Boss 1
{ 4.5, "04:30" },
{ 3.25,"03:15" },
{ 2.75,"02:45" },
{ 4.75,"04:45" },
{ 0, "??:??" }, // Boss 2
{ 6.5, "06:30" },
{ 4.5, "04:30" },
{ 2.75,"02:45" },
{ 4.5, "04:30" },
{ 6, "06:00" },
{ 0, "??:??" }, // Boss 3
{ 6, "06:00" },
{ 0, "??:??" }, // Boss 4
{ 0, "??:??" }, // Secret level 1
{ 0, "??:??" }, // Secret level 2
};
/*
-----------------------------------------------------------------------------
Function: CAL_SetupMapFile -Setup map files for decoding.
Parameters: extension -[in] file extension for map data files.
Returns: Non-zero on success, zero otherwise.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE W8 CAL_SetupMapFile( const char *extension )
{
FILE *handle;
SW32 length;
char fname[ 13 ];
//
// load maphead.xxx (offsets and tileinfo for map file)
//
cs_strlcpy( fname, MAPHEADNAME, sizeof( fname ) );
cs_strlcat( fname, extension, sizeof( fname ) );
handle = fopen( cs_strupr( fname ), "rb" );
if( handle == NULL )
{
handle = fopen( cs_strlwr( fname ), "rb" );
if( handle == NULL )
{
printf( "Could not open file (%s) for read!\n", fname );
return 0;
}
}
length = FS_FileLength( handle );
fread( &RLEWtag, 2, 1, handle );
for( TotalMaps = 0 ; TotalMaps < length ; ++TotalMaps )
{
fread( &headeroffsets[ TotalMaps ], 4, 1, handle );
if( ! headeroffsets[ TotalMaps ] )
{
break;
}
}
fclose( handle );
cs_strlcpy( fname, MAPNAME, sizeof( fname ) );
cs_strlcat( fname, extension, sizeof( fname ) );
maphandle = fopen( cs_strupr( fname ), "rb");
if( NULL == maphandle )
{
maphandle = fopen( cs_strlwr( fname ), "rb");
if( NULL == maphandle )
{
return 0;
}
}
return 1;
}
/*
-----------------------------------------------------------------------------
Function: CAL_ShutdownMapFile -Shutdown map file.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void CAL_ShutdownMapFile( void )
{
if( maphandle )
{
fclose( maphandle );
}
}
/*
-----------------------------------------------------------------------------
Function: CA_CacheMap -Cache and save map data.
Parameters:
ChunkOffset -[in] Chunk offset.
Chunklength -[in] Length of chunk.
filename -[in] File name to save map as.
index -[in] File name index number.
Returns: Non-zero on success, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE W8 CA_CacheMap( W32 ChunkOffset, W32 Chunklength, const char *filename, W32 index )
{
W32 offset[ 3 ];
W32 offsetin[ 3 ];
W32 temp;
W16 length[ 3 ];
W8 sig[ 5 ];
W16 w, h;
W8 *data;
W32 ceiling;
W32 floor;
FILE *fout;
float ftime;
char *stime;
char name[ 32 ];
char musicName[ 64 ];
extern char gamepal[];
SW32 jmp;
if( gameversion == SOD_PAK )
{
temp = (vgaCeilingSOD[ index ] & 0xff) * 3;
ceiling = ( (gamepal[ temp ] << 2) << 16 ) | ( (gamepal[ temp+1 ] << 2 ) << 8) | (gamepal[ temp+2 ]<<2);
temp = 0x19 * 3;
floor = ( (gamepal[ temp ] << 2) << 16 ) | ( (gamepal[ temp+1 ] << 2 ) << 8) | (gamepal[ temp+2 ]<<2);
ftime = parTimesSOD[ index ].time;
stime = parTimesSOD[ index ].timestr;
cs_snprintf( musicName, sizeof( musicName ), "music/%s.ogg", GetMusicFileName_SOD( SOD_songs[ index ] ) );
}
else
{
temp = (vgaCeilingWL6[ index ] & 0xff) * 3;
ceiling = ( (gamepal[ temp ] << 2) << 16 ) | ( (gamepal[ temp+1 ] << 2 ) << 8) | (gamepal[ temp+2 ]<<2);
temp = 0x19 * 3;
floor = ( (gamepal[ temp ] << 2) << 16 ) | ( (gamepal[ temp+1 ] << 2 ) << 8) | (gamepal[ temp+2 ]<<2);
ftime = parTimesWL6[ index ].time;
stime = parTimesWL6[ index ].timestr;
cs_snprintf( musicName, sizeof( musicName ), "music/%s.ogg", GetMusicFileName_WL6( WL6_songs[ index ] ) );
}
fout = fopen( filename, "wb");
if( NULL == fout )
{
return 0;
}
fseek( maphandle, ChunkOffset, SEEK_SET );
fread( &offsetin, sizeof( W32 ), 3, maphandle );
fread( &length, sizeof( W16 ), 3, maphandle );
fread( &w, sizeof( W16 ), 1, maphandle );
fread( &h, sizeof( W16 ), 1, maphandle );
fread( name, sizeof( W8 ), 16, maphandle );
fread( sig, sizeof( W8 ), 4, maphandle );
//
// Output header
//
// Map file header signature
fwrite( sig, sizeof( W8 ), 4, fout );
// RLE Word tag
fwrite( &RLEWtag, sizeof( W16 ), 1, fout );
// Max Width
fwrite( &w, sizeof( W16 ), 1, fout );
// Max Height
fwrite( &h, sizeof( W16 ), 1, fout );
// Ceiling Colour
fwrite( &ceiling, sizeof( W32 ), 1, fout );
// Floor Colour
fwrite( &floor, sizeof( W32 ), 1, fout );
// Length of layers
temp = length[ 0 ];
fwrite( &temp, sizeof( W16 ), 1, fout ); // Length One
temp = length[ 1 ];
fwrite( &temp, sizeof( W16 ), 1, fout ); // Length Two
temp = length[ 2 ];
fwrite( &temp, sizeof( W16 ), 1, fout ); // Length Three
jmp = ftell( fout );
temp = 0;
fwrite( &temp, sizeof( W32 ), 1, fout ); // Offset One
fwrite( &temp, sizeof( W32 ), 1, fout ); // Offset Two
fwrite( &temp, sizeof( W32 ), 1, fout ); // Offset Three
// Map name length
temp = strlen( name );
fwrite( &temp, sizeof( W16 ), 1, fout );
// Music name length
temp = strlen( musicName );
fwrite( &temp, sizeof( W16 ), 1, fout );
// Par time Float
fwrite( &ftime, sizeof( float ), 1, fout );
// Par time string
fwrite( stime, sizeof( W8 ), 5 , fout );
// Map name
fwrite( name, sizeof( W8 ), strlen( name ), fout );
// Music file name
fwrite( musicName, sizeof( W8 ), strlen( musicName ), fout );
data = MM_MALLOC( length[ 0 ] );
if( data == NULL )
{
return 0;
}
offset[ 0 ] = ftell( fout );
fseek( maphandle, offsetin[ 0 ], SEEK_SET );
fread( data, 1, length[ 0 ], maphandle );
fwrite( data, 1, length[ 0 ], fout );
data = MM_REALLOC( data, length[ 1 ] );
if( data == NULL )
{
return 0;
}
offset[ 1 ] = ftell( fout );
fseek( maphandle, offsetin[ 1 ], SEEK_SET );
fread( data, 1, length[ 1 ], maphandle );
fwrite( data, 1, length[ 1 ], fout );
data = MM_REALLOC( data, length[ 2 ] );
if( data == NULL )
{
return 0;
}
offset[ 2 ] = ftell( fout );
fseek( maphandle, offsetin[ 2 ], SEEK_SET );
fread( data, 1, length[ 2 ], maphandle );
fwrite( data, 1, length[ 2 ], fout );
MM_FREE( data );
fseek( fout, jmp, SEEK_SET );
temp = offset[ 0 ];
fwrite( &temp, sizeof( W32 ), 1, fout ); // Offset One
temp = offset[ 1 ];
fwrite( &temp, sizeof( W32 ), 1, fout ); // Offset Two
temp = offset[ 2 ];
fwrite( &temp, sizeof( W32 ), 1, fout ); // Offset Three
fclose( fout );
return 1;
}
/*
-----------------------------------------------------------------------------
Function: MapRipper -Re-encode map data.
Parameters: extension -[in] file extension for map data files.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC _boolean MapRipper( const char *fextension, W16 version )
{
W32 i;
char fname[ 32 ];
gameversion = version;
//
// Setup
//
if( 0 == FS_Mkdir( MAPDIR ) )
{
printf( "[%s] Could not create directory (%s)!\n", "wolf_map.c", MAPDIR );
return false;
}
if( ! CAL_SetupMapFile( fextension ) )
{
CAL_ShutdownMapFile();
return false;
}
//
// Decode Map data
//
printf( "Decoding Map Data...\n" );
for( i = 0 ; i < TotalMaps ; ++i )
{
cs_snprintf( fname, sizeof( fname ), "%s/%c%.2d.map", MAPDIR, TOLOWER( fextension[ 1 ] ), i );
CA_CacheMap( headeroffsets[ i ],
headeroffsets[ i + 1 ] - headeroffsets[ i ],
fname, i );
}
//
// Shutdown
//
CAL_ShutdownMapFile();
return true;
}

View File

@@ -0,0 +1,263 @@
char gamepal[ 768 ] = {
0, 0, 0,
0, 0, 42,
0, 42, 0,
0, 42, 42,
42, 0, 0,
42, 0, 42,
42, 21, 0,
42, 42, 42,
21, 21, 21,
21, 21, 63,
21, 63, 21,
21, 63, 63,
63, 21, 21,
63, 21, 63,
63, 63, 21,
63, 63, 63,
59, 59, 59,
55, 55, 55,
52, 52, 52,
48, 48, 48,
45, 45, 45,
42, 42, 42,
38, 38, 38,
35, 35, 35,
31, 31, 31,
28, 28, 28,
25, 25, 25,
21, 21, 21,
18, 18, 18,
14, 14, 14,
11, 11, 11,
8, 8, 8,
63, 0, 0,
59, 0, 0,
56, 0, 0,
53, 0, 0,
50, 0, 0,
47, 0, 0,
44, 0, 0,
41, 0, 0,
38, 0, 0,
34, 0, 0,
31, 0, 0,
28, 0, 0,
25, 0, 0,
22, 0, 0,
19, 0, 0,
16, 0, 0,
63, 54, 54,
63, 46, 46,
63, 39, 39,
63, 31, 31,
63, 23, 23,
63, 16, 16,
63, 8, 8,
63, 0, 0,
63, 42, 23,
63, 38, 16,
63, 34, 8,
63, 30, 0,
57, 27, 0,
51, 24, 0,
45, 21, 0,
39, 19, 0,
63, 63, 54,
63, 63, 46,
63, 63, 39,
63, 63, 31,
63, 62, 23,
63, 61, 16,
63, 61, 8,
63, 61, 0,
57, 54, 0,
51, 49, 0,
45, 43, 0,
39, 39, 0,
33, 33, 0,
28, 27, 0,
22, 21, 0,
16, 16, 0,
52, 63, 23,
49, 63, 16,
45, 63, 8,
40, 63, 0,
36, 57, 0,
32, 51, 0,
29, 45, 0,
24, 39, 0,
54, 63, 54,
47, 63, 46,
39, 63, 39,
32, 63, 31,
24, 63, 23,
16, 63, 16,
8, 63, 8,
0, 63, 0,
0, 63, 0,
0, 59, 0,
0, 56, 0,
0, 53, 0,
1, 50, 0,
1, 47, 0,
1, 44, 0,
1, 41, 0,
1, 38, 0,
1, 34, 0,
1, 31, 0,
1, 28, 0,
1, 25, 0,
1, 22, 0,
1, 19, 0,
1, 16, 0,
54, 63, 63,
46, 63, 63,
39, 63, 63,
31, 63, 62,
23, 63, 63,
16, 63, 63,
8, 63, 63,
0, 63, 63,
0, 57, 57,
0, 51, 51,
0, 45, 45,
0, 39, 39,
0, 33, 33,
0, 28, 28,
0, 22, 22,
0, 16, 16,
23, 47, 63,
16, 44, 63,
8, 42, 63,
0, 39, 63,
0, 35, 57,
0, 31, 51,
0, 27, 45,
0, 23, 39,
54, 54, 63,
46, 47, 63,
39, 39, 63,
31, 32, 63,
23, 24, 63,
16, 16, 63,
8, 9, 63,
0, 1, 63,
0, 0, 63,
0, 0, 59,
0, 0, 56,
0, 0, 53,
0, 0, 50,
0, 0, 47,
0, 0, 44,
0, 0, 41,
0, 0, 38,
0, 0, 34,
0, 0, 31,
0, 0, 28,
0, 0, 25,
0, 0, 22,
0, 0, 19,
0, 0, 16,
10, 10, 10,
63, 56, 13,
63, 53, 9,
63, 51, 6,
63, 48, 2,
63, 45, 0,
// 45, 8, 63, //hmmmm
// 42, 0, 63, //hmmmm
0, 14, 0,
0, 10, 0,
38, 0, 57,
32, 0, 51,
29, 0, 45,
24, 0, 39,
20, 0, 33,
17, 0, 28,
13, 0, 22,
10, 0, 16,
63, 54, 63,
63, 46, 63,
63, 39, 63,
63, 31, 63,
63, 23, 63,
63, 16, 63,
63, 8, 63,
63, 0, 63,
56, 0, 57,
50, 0, 51,
45, 0, 45,
39, 0, 39,
33, 0, 33,
27, 0, 28,
22, 0, 22,
16, 0, 16,
63, 58, 55,
63, 56, 52,
63, 54, 49,
63, 53, 47,
63, 51, 44,
63, 49, 41,
63, 47, 39,
63, 46, 36,
63, 44, 32,
63, 41, 28,
63, 39, 24,
60, 37, 23,
58, 35, 22,
55, 34, 21,
52, 32, 20,
50, 31, 19,
47, 30, 18,
45, 28, 17,
42, 26, 16,
40, 25, 15,
39, 24, 14,
36, 23, 13,
34, 22, 12,
32, 20, 11,
29, 19, 10,
27, 18, 9,
23, 16, 8,
21, 15, 7,
18, 14, 6,
16, 12, 6,
14, 11, 5,
10, 8, 3,
24, 0, 25,
0, 25, 25,
0, 24, 24,
0, 0, 7,
0, 0, 11,
12, 9, 4,
18, 0, 18,
20, 0, 20,
0, 0, 13,
7, 7, 7,
19, 19, 19,
23, 23, 23,
16, 16, 16,
12, 12, 12,
13, 13, 13,
54, 61, 61,
46, 58, 58,
39, 55, 55,
29, 50, 50,
18, 48, 48,
8, 45, 45,
8, 44, 44,
0, 41, 41,
0, 38, 38,
0, 35, 35,
0, 33, 33,
0, 31, 31,
0, 30, 30,
0, 29, 29,
0, 28, 28,
0, 27, 27,
38, 0, 34
};

View File

@@ -0,0 +1,943 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* wolf_pm.c: Decode Wolfenstein3-D Page data.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* This code was derived from Wolfenstein 3-D, and was originally
* written by Id Software, Inc.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "wolf_def.h"
#include "../../../common/arch.h"
#include "../../../common/common_utils.h"
#include "../loaders/tga.h"
#include "../hq2x.h"
#include "../loaders/wav.h"
#include "../filesys/file.h"
#include "../string/com_string.h"
#include "../memory/memory.h"
extern char gamepal[];
#define PAGEFNAME "VSWAP"
#define SAMPLERATE 7000 // In Hz
typedef struct
{
W32 offset; // Offset of chunk into file
W16 length; // Length of the chunk
} PageList_t;
typedef struct
{
W16 leftpix, rightpix;
W16 dataofs[ 64 ];
// table data after dataofs[ rightpix - leftpix + 1 ]
} t_compshape;
PRIVATE PageList_t *PMPages;
PRIVATE FILE *PageFile = NULL;
PRIVATE W16 PMNumBlocks;
PRIVATE W16 PMSpriteStart, PMSoundStart;
/*
-----------------------------------------------------------------------------
Function: CAL_GetGrChunkLength() -Opens the page file and sets up
the page info.
Parameters: extension -[in] Pointer to a null-terminated string that
specifies the file extension.
(must be in '.XXX' format)
Returns: 1 on success, otherwise 0.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE W8 PML_OpenPageFile( const char *extension )
{
W32 i;
W32 size;
void *buf;
char filename[ 16 ];
W32 *offsetptr;
W16 *lengthptr;
PageList_t *page;
if( ! extension || ! *extension )
{
printf( "Invalid file extension passed to PML_OpenPageFile()\n" );
return 0;
}
cs_strlcpy( filename, PAGEFNAME, sizeof( filename ) );
cs_strlcat( filename, extension, sizeof( filename ) );
PageFile = fopen( cs_strupr( filename ), "rb" );
if( PageFile == NULL )
{
PageFile = fopen( cs_strlwr( filename ), "rb" );
if( PageFile == NULL )
{
printf( "Could not open file (%s) for read!\n", filename );
return 0;
}
}
// Read in header variables
fread( &PMNumBlocks, sizeof( PMNumBlocks ), 1, PageFile );
fread( &PMSpriteStart, sizeof( PMSpriteStart ), 1, PageFile );
fread( &PMSoundStart, sizeof( PMSoundStart ), 1, PageFile );
// Allocate and clear the page list
PMPages = (PageList_t *) MM_MALLOC( sizeof( PageList_t ) * PMNumBlocks );
if( PMPages == NULL )
{
return 0;
}
memset( PMPages, 0, sizeof( PageList_t ) * PMNumBlocks );
// Read in the chunk offsets
size = sizeof( W32 ) * PMNumBlocks;
buf = MM_MALLOC( size );
if( buf == NULL )
{
return 0;
}
if( fread( buf, 1, size, PageFile ) == 0 )
{
printf( "PML_OpenPageFile: Length read failed\n" );
}
offsetptr = (PW32) buf;
for( i = 0, page = PMPages; i < PMNumBlocks; i++, page++ )
{
page->offset = *offsetptr++;
}
MM_FREE( buf );
// Read in the chunk lengths
size = sizeof( W16 ) * PMNumBlocks;
buf = MM_MALLOC( size );
if( buf == NULL )
{
return 0;
}
if( fread( buf, 1, size, PageFile ) == 0 )
{
printf( "PML_OpenPageFile: Length read failed\n" );
}
lengthptr = (PW16)buf;
for( i = 0, page = PMPages; i < PMNumBlocks; ++i, page++ )
{
page->length = *lengthptr++;
}
MM_FREE( buf );
return 1;
}
/*
-----------------------------------------------------------------------------
Function: PML_ReadFromFile() -Reads in data from Page file.
Parameters: buf -[out] Storage location for data.
offset -[in] Number of bytes from beginning of file.
length -[in] Maximum number of items to be read.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void PML_ReadFromFile( W8 *buf, SW32 offset, W16 length )
{
if( ! buf )
{
printf( "[PML_ReadFromFile]: NULL pointer\n" );
return;
}
if( ! offset )
{
printf( "[PML_ReadFromFile]: Zero offset\n" );
return;
}
if( fseek( PageFile, offset, SEEK_SET ) )
{
printf( "[PML_ReadFromFile]: Seek failed\n" );
return;
}
if( ! fread( buf, 1, length, PageFile ) )
{
printf( "[PML_ReadFromFile]: Read failed\n" );
return;
}
}
/*
-----------------------------------------------------------------------------
Function: PML_LoadPage() -Reads in data from Page file.
Parameters: buf -[out] Storage location for data.
offset -[in] Number of bytes from beginning of file.
clength -[in] Maximum number of items to be read.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void *PML_LoadPage( W32 pagenum, W16 *clength )
{
W8 *addr;
PageList_t *page;
page = &PMPages[ pagenum ];
if( page->length == 0 )
{
return NULL;
}
*clength = page->length;
addr = MM_MALLOC( page->length );
if( addr == NULL )
{
return NULL;
}
PML_ReadFromFile( addr, page->offset, page->length );
return addr;
}
void OutlineImage( W8 *rgba, int width, int height ) {
W8 *data_p;
W8 *copy_p;
W8 *copy = (W8 *)_alloca( width * height * 4 );
int x, y;
memcpy( copy, rgba, width * height * 4 );
data_p = rgba;
copy_p = copy;
for ( y = 0 ; y < height ; y++ ) {
for ( x = 0 ; x < width ; x++, data_p+=4, copy_p+=4 ) {
if ( data_p[3] != 0 ) {
continue;
}
if ( x < width-1 && copy_p[7] != 0 ) {
*(int *)data_p = ((int *)copy_p)[1];
} else if ( x > 0 && copy_p[-1] != 0 ) {
*(int *)data_p = ((int *)copy_p)[-1];
} else if ( y < height-1 && copy_p[width*4+3] != 0 ) {
*(int *)data_p = ((int *)copy_p)[width];
} else if ( y > 0 && copy_p[-width*4+3] != 0 ) {
*(int *)data_p = ((int *)copy_p)[-width];
}
data_p[3] = 1;
}
}
}
typedef struct {
int hasAlpha;
int srcWidth;
int srcHeight;
int uploadWidth;
int uploadHeight;
// track the outlines of up to two boxes of non-transparent pixels.
// The reason for two boxes is that the common lights have something
// at the top and something at the bottom, with nothing inbetween.
// These are inclusive bounds of the rows / columns with non-0 alpha
int numBounds;
int bounds[2][2][2];
} picHeader_t;
int RowClear( W8 *rgba, int w, int h, int y ) {
int x;
for ( x = 0 ; x < w ; x++ ) {
if ( rgba[(y*w+x)*4+3] != 0 ) {
return 0;
}
}
return 1;
}
void Write5551( const char *tgaName, int w, int h, W8 *rgba, int hasAlpha ) {
unsigned short *s = _alloca( w*h*4 );
FILE *f;
picHeader_t *header = (picHeader_t *)s;
unsigned short *s_p;
int i;
int shorts;
W8 *tempMip;
W8 *rgba_p;
int b, x, y, c;
char newName[1024];
char *ext;
memset( header, 0, sizeof( *header ) );
header->hasAlpha = hasAlpha;
header->srcWidth = w;
header->srcHeight = h;
header->uploadWidth = w;
header->uploadHeight = h;
if ( !hasAlpha ) {
// convert from 24 bit to 32 bit
W8 *newPic = _alloca( w * h * 4 );
for ( i = 0 ; i < w*h ; i++ ) {
newPic[i*4+0] = rgba[i*3+0];
newPic[i*4+1] = rgba[i*3+1];
newPic[i*4+2] = rgba[i*3+2];
newPic[i*4+3] = 255;
}
rgba = newPic;
}
// find the bounding boxes for more efficient drawing
header->numBounds = 1;
for ( y = 0 ; y < h ; y++ ) {
if ( !RowClear( rgba, w, h, y ) ) {
// this row is needed
header->bounds[0][0][1] = y;
break;
}
}
for ( y = h-1 ; y >= 0 ; y-- ) {
if ( !RowClear( rgba, w, h, y ) ) {
// this row is needed
header->bounds[0][1][1] = y;
break;
}
}
// if the middle row is clear, make two boxes
// We could make a better test, but this catches the ones we care about...
if ( header->bounds[0][0][1] < h/2 && header->bounds[0][1][1] > h / 2 && RowClear( rgba, w, h, h/2 ) ) {
header->numBounds = 2;
header->bounds[1][1][1] = header->bounds[0][1][1];
for ( y = h/2-1 ; y >= 0 ; y-- ) {
if ( !RowClear( rgba, w, h, y ) ) {
header->bounds[0][1][1] = y;
break;
}
}
for ( y = h/2+1 ; y < h ; y++ ) {
if ( !RowClear( rgba, w, h, y ) ) {
header->bounds[1][0][1] = y;
break;
}
}
}
for ( b = 0 ; b < header->numBounds ; b++ ) {
for ( x = 0 ; x < w ; x++ ) {
for ( y = header->bounds[b][0][1] ; y <= header->bounds[b][1][1] ; y++ ) {
if ( rgba[(y*w+x)*4+3] != 0 ) {
// this column is needed
header->bounds[b][0][0] = x;
break;
}
}
if ( y <= header->bounds[b][1][1] ) {
break;
}
}
for ( x = w-1 ; x >= 0 ; x-- ) {
for ( y = header->bounds[b][0][1] ; y <= header->bounds[b][1][1] ; y++ ) {
if ( rgba[(y*w+x)*4+3] != 0 ) {
// this column is needed
header->bounds[b][1][0] = x;
break;
}
}
if ( y <= header->bounds[b][1][1] ) {
break;
}
}
}
s_p = (unsigned short *)(header+1);
while ( 1 ) {
rgba_p = rgba;
// convert to 5551
for ( i = 0 ; i < w*h ; i++, rgba_p+=4 ) {
int r = rgba_p[0];
int g = rgba_p[1];
int b = rgba_p[2];
int a = rgba_p[3];
*s_p++ = ((r>>3)<<11) | ((g>>3)<<6) | ((b>>3)<<1) | (a>>7);
}
if ( w == 1 && h == 1 ) {
break;
}
// mip map
w >>= 1;
if ( w == 0 ) {
w = 1;
}
h >>= 1;
if ( h == 0 ) {
h = 1;
}
tempMip = _alloca( w * h * 4 );
for ( y = 0 ; y < h ; y++ ) {
for ( x = 0 ; x < w ; x++ ) {
for ( c = 0 ; c < 4 ; c++ ) {
tempMip[(y*w+x)*4+c] = (
rgba[((y*2+0)*w*2+(x*2+0))*4+c] +
rgba[((y*2+0)*w*2+(x*2+1))*4+c] +
rgba[((y*2+1)*w*2+(x*2+0))*4+c] +
rgba[((y*2+1)*w*2+(x*2+1))*4+c] ) >> 2;
}
}
}
rgba = tempMip;
}
shorts = s_p - s;
// byte swap
#if 0
for ( i = 0 ; i < shorts ; i++ ) {
int temp = ((W8 *)s)[i*2+0];
((W8 *)s)[i*2+0] = ((W8 *)s)[i*2+1];
((W8 *)s)[i*2+1] = temp;
}
#endif
// write
strcpy( newName, tgaName );
ext = strstr( newName, ".tga" );
strcpy( ext, ".5551" );
f = fopen( newName, "wb" );
if( f == NULL ) {
printf( "Could not open file (%s) for write!\n", newName );
return;
}
fwrite( s, 2, shorts, f );
fclose( f );
}
#include <assert.h>
void UpdateSingleSprite( const char *srcTGA, const char *destTGA ) {
W8 *rgba;
int width, height;
int i;
// HACK HACK HACK just to convert the single health pack sprite without the
// trademarked "red cross"
LoadTGA( srcTGA, &rgba, &width, &height );
assert( rgba );
assert( width == 64 && height == 64 );
// JDC: outline the image to avoid dark halos with filtering
for ( i = 0 ; i < 8 ; i++ ) {
OutlineImage( rgba, 64, 64 );
}
for ( i = 0 ; i < 64*64 ; i++ ) {
if ( rgba[i*4+3] == 1 ) {
rgba[i*4+3] = 0;
}
}
WriteTGA( destTGA, 32, 64, 64, rgba, 0, 1 );
Write5551( destTGA, 64, 64, rgba, 1 );
}
/*
-----------------------------------------------------------------------------
Function: PML_LoadPage() -Save image data from page file.
Parameters: nPage -[in] Page number to save.
filename -[in] Pointer to string with filename.
buffer -[in] Allocated memory buffer to hold image data.
buffer2 -[in] Allocated memory buffer to hold hq2x data.
Returns: Non-zero on success, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE W8 PML_SaveGFXPage( W32 nPage, const char *filename,
W8 *buffer, W8 *buffer2, _boolean iswall, W32 GunFlash )
{
W16 x, y;
W8 *data;
W8 *ptr;
W16 temp;
W8 r,g,b;
W16 clength; // Chunk length
data = (PW8)PML_LoadPage( nPage, &clength );
if( data == NULL )
{
return 0;
}
if( nPage < PMSpriteStart )
{
// simple 64x64 image
W8 *rgb = (W8 *)_alloca( 64*64*3 );
for( x = 0; x < 64; ++x )
{
for( y = 0; y < 64; ++y )
{
temp = ( data[ (x<<6)+y ] ) * 3;
// gamepal is in 6 bit color
r = gamepal[ temp ];
g = gamepal[ temp+1 ];
b = gamepal[ temp+2 ];
ptr = rgb + ( ( (y << 6) + x ) * 3 );
ptr[ 0 ] = ( r << 2 ) | ( r >> 4 );
ptr[ 1 ] = ( g << 2 ) | ( g >> 4 );
ptr[ 2 ] = ( b << 2 ) | ( b >> 4 );
}
}
WriteTGA( filename, 24, 64, 64, rgb, 0, 1 );
Write5551( filename, 64, 64, rgb, 0 );
}
else if( nPage >= PMSpriteStart && nPage < PMSoundStart )
{
W16 *cmdptr;
short *linecmds;
t_compshape *shape;
int x, y;
W8 *rgba = (W8 *)_alloca( 64*64*4 );
int i;
// all transparent at the beginning
memset( rgba, 0, 64*64*4 );
// draw the spans into the buffer
shape = (t_compshape *)data;
cmdptr = shape->dataofs;
for( x = shape->leftpix; x <= shape->rightpix; ++x )
{
linecmds = (short *)( data + *cmdptr++ );
for( ; *linecmds; linecmds += 3 )
{
i = linecmds[ 2 ] / 2 + linecmds[ 1 ];
for( y = linecmds[ 2 ] / 2; y < linecmds[ 0 ] / 2; ++y, ++i )
{
temp = ( data[ i ] ) * 3;
r = gamepal[ temp ];
g = gamepal[ temp+1 ];
b = gamepal[ temp+2 ];
ptr = rgba + ( (y * 64 + x) * 4 );
ptr[ 0 ] = ( r << 2 ) | ( r >> 4 );
ptr[ 1 ] = ( g << 2 ) | ( g >> 4 );
ptr[ 2 ] = ( b << 2 ) | ( b >> 4 );
ptr[ 3 ] = 255;
}
}
}
// JDC: outline the image to avoid dark halos with filtering
for ( i = 0 ; i < 8 ; i++ ) {
OutlineImage( rgba, 64, 64 );
}
for ( i = 0 ; i < 64*64 ; i++ ) {
if ( rgba[i*4+3] == 1 ) {
rgba[i*4+3] = 0;
}
}
WriteTGA( filename, 32, 64, 64, rgba, 0, 1 );
Write5551( filename, 64, 64, rgba, 1 );
}
else
{
MM_FREE( data );
printf( "Out of bounds page number passed into PML_SavePage()!\n" );
return 0;
}
MM_FREE( data );
return 1;
}
/*
-----------------------------------------------------------------------------
Function: PML_SaveSoundPage() -Save sound data from Page file.
Parameters: nPage -[in] Page number to save.
filename -[in] Pointer to string with filename.
buffer -[in] Allocated memory buffer to hold sound data.
size -[in] Size of allocated memory buffer.
Returns: Non-zero on success, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE W8 PML_SaveSoundPage( W32 nPage, char *filename,
W8 *buffer,
W32 size )
{
static W16 totallength = 0;
W8 *data;
W16 clength; // Chunk length
if( nPage < PMSoundStart || nPage > PMNumBlocks )
{
printf( "Out of bounds page number passed into PML_SaveSound()!\n" );
return 1;
}
data = (PW8) PML_LoadPage( nPage, &clength );
if( data == NULL )
{
return 1;
}
if( totallength > size )
{
printf( "[wolf_pmc] Buffer not large enough!\n" );
return 2;
}
memcpy( buffer + totallength, data, clength );
totallength += clength;
if( clength < 4096 )
{
write_wav( filename, buffer, totallength, 1, SAMPLERATE, 1 );
totallength = 0;
}
MM_FREE( data );
return 0;
}
/*
-----------------------------------------------------------------------------
Function: PML_Shutdown() -Shutdown page cache.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void PML_Shutdown()
{
if( PageFile )
{
fclose( PageFile );
PageFile = NULL;
}
if( PMPages )
{
MM_FREE( PMPages );
}
}
/*
-----------------------------------------------------------------------------
Function: PExtractor() -Interface to page manager.
Parameters: extension -[in] Ponter to string with file extenion of data
files.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC _boolean PExtractor( const char *extension, W16 version )
{
W32 i, j;
char filename[ 256 ];
W8 *buffer, *buffer2;
W32 Flash;
//
// Setup
//
if( 0 == FS_Mkdir( GFXWALLDIR ) )
{
printf( "[%s] Could not create directory (%s)!\n", "PExtractor", GFXWALLDIR );
return false;
}
if( version == SOD_PAK || version == SDM_PAK )
{
if( 0 == FS_Mkdir( SODGFXSPRITEDIR ) )
{
printf( "[%s] Could not create directory (%s)!\n", "PExtractor", GFXSPRITEDIR );
return false;
}
if( 0 == FS_Mkdir( SODSFXDIR ) )
{
printf( "[%s] Could not create directory (%s)!\n", "PExtractor", SODSFXDIR );
return false;
}
}
else
{
if( 0 == FS_Mkdir( GFXSPRITEDIR ) )
{
printf( "[%s] Could not create directory (%s)!\n", "PExtractor", GFXSPRITEDIR );
return false;
}
if( 0 == FS_Mkdir( SFXDIR ) )
{
printf( "[%s] Could not create directory (%s)!\n", "PExtractor", SFXDIR );
return false;
}
}
if( ! PML_OpenPageFile( extension ) )
{
PML_Shutdown();
return false;
}
//
// Allocate buffers
//
buffer = MM_MALLOC( 64 * 64 * 2 );
if( buffer == NULL )
{
PML_Shutdown();
return false;
}
buffer2 = MM_MALLOC( 128 * 128 * 4 );
if( buffer2 == NULL )
{
MM_FREE( buffer );
PML_Shutdown();
return false;
}
//
// Decode Page data
//
printf( "Decoding Page Data...\n" );
for( i = 0, j = 0; i < PMSpriteStart; ++i, ++j )
{
// Hacks
if( version == WL6_PAK || version == WL1_PAK )
{
if( 98 == j )
{
j = 126;
}
}
cs_snprintf( filename, sizeof( filename ), "%s/%.3d.tga", GFXWALLDIR, j );
PML_SaveGFXPage( i, filename, buffer, buffer2, 1, 0 );
}
for( i = PMSpriteStart, j = 0; i < PMSoundStart; ++i, ++j )
{
// Hacks
if( version == WL1_PAK )
{
if( j == 50 )
{
j = 54;
}
if( j == 191 )
{
j = 300;
i += 109;
}
if( j == 311 )
{
j = 431;
i += 101;
}
if( j == 439 )
{
j = 514;
}
}
if( version == WL6_PAK )
{
if( j == 50 )
{
j = 54;
}
if( j == 389 )
{
j = 408;
}
if( j == 439 )
{
j = 514;
}
}
if( version == SDM_PAK )
{
if( j == 401 )
{
j = 514;
}
}
if( version == SOD_PAK )
{
if( j == 292 )
{
j = 374;
}
if( j == 408 )
{
j = 439;
}
}
if( version == SOD_PAK || version == SDM_PAK )
{
cs_snprintf( filename, sizeof( filename ), "%s/%.3d.tga", SODGFXSPRITEDIR, j );
}
else
{
cs_snprintf( filename, sizeof( filename ), "%s/%.3d.tga", GFXSPRITEDIR, j );
}
if( j == 531 ||
j == 532 ||
j == 526 ||
j == 521 )
{
Flash = j;
}
else
{
Flash = 0;
}
PML_SaveGFXPage( i, filename, buffer, buffer2, 0, Flash );
}
for( i = PMSoundStart, j = 0; i < PMNumBlocks-1; ++i, ++j )
{
if( version == SOD_PAK || version == SDM_PAK )
{
cs_snprintf( filename, sizeof( filename ), "%s/%.3d.wav", SODSFXDIR, j );
}
else
{
cs_snprintf( filename, sizeof( filename ), "%s/%.3d.wav", SFXDIR, j );
}
PML_SaveSoundPage( i, filename, buffer2, 128 * 128 * 4 );
}
//
// Shutdown
//
MM_FREE( buffer );
MM_FREE( buffer2 );
PML_Shutdown();
return true;
}

View File

@@ -0,0 +1,257 @@
# Microsoft Developer Studio Project File - Name="wolfextractor" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=wolfextractor - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "wolfextractor.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "wolfextractor.mak" CFG="wolfextractor - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "wolfextractor - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "wolfextractor - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "wolfextractor - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D vsnprintf=_vsnprintf /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib vorbisenc_static.lib vorbis_static.lib ogg_static.lib /nologo /subsystem:console /machine:I386 /nodefaultlib:"libcmt.lib"
!ELSEIF "$(CFG)" == "wolfextractor - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D vsnprintf=_vsnprintf /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib vorbisenc_static.lib vorbis_static.lib ogg_static.lib /nologo /subsystem:console /profile /debug /machine:I386 /nodefaultlib:"libcmt.lib"
!ENDIF
# Begin Target
# Name "wolfextractor - Win32 Release"
# Name "wolfextractor - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=..\..\zlib\adler32.c
# End Source File
# Begin Source File
SOURCE=.\adlib\adlib.c
# End Source File
# Begin Source File
SOURCE=..\..\common\arch.c
# End Source File
# Begin Source File
SOURCE=.\string\com_string.c
# End Source File
# Begin Source File
SOURCE=..\..\zlib\compress.c
# End Source File
# Begin Source File
SOURCE=..\..\zlib\crc32.c
# End Source File
# Begin Source File
SOURCE=..\..\zlib\deflate.c
# End Source File
# Begin Source File
SOURCE=.\filesys\file.c
# End Source File
# Begin Source File
SOURCE=.\adlib\fmopl.c
# End Source File
# Begin Source File
SOURCE=.\hq2x.c
# End Source File
# Begin Source File
SOURCE=.\mac\mac.c
# End Source File
# Begin Source File
SOURCE=.\main.c
# End Source File
# Begin Source File
SOURCE=.\memory\memory.c
# End Source File
# Begin Source File
SOURCE=.\pak.c
# End Source File
# Begin Source File
SOURCE=.\loaders\tga.c
# End Source File
# Begin Source File
SOURCE=..\..\zlib\trees.c
# End Source File
# Begin Source File
SOURCE=.\vorbisenc_inter.c
# End Source File
# Begin Source File
SOURCE=.\loaders\wav.c
# End Source File
# Begin Source File
SOURCE=.\filesys\win32\win_file.c
# End Source File
# Begin Source File
SOURCE=.\wolf\wl6_name.c
# End Source File
# Begin Source File
SOURCE=.\wolf\wolf_aud.c
# End Source File
# Begin Source File
SOURCE=.\wolf\wolf_gfx.c
# End Source File
# Begin Source File
SOURCE=.\wolf\wolf_map.c
# End Source File
# Begin Source File
SOURCE=.\wolf\wolf_pal.c
# End Source File
# Begin Source File
SOURCE=.\wolf\wolf_pm.c
# End Source File
# Begin Source File
SOURCE=.\zip\zipfile.c
# End Source File
# Begin Source File
SOURCE=..\..\zlib\zutil.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\adlib\adlib.h
# End Source File
# Begin Source File
SOURCE=..\..\common\arch.h
# End Source File
# Begin Source File
SOURCE=.\string\com_string.h
# End Source File
# Begin Source File
SOURCE=..\..\common\common_utils.h
# End Source File
# Begin Source File
SOURCE=.\filesys\file.h
# End Source File
# Begin Source File
SOURCE=.\adlib\fmopl.h
# End Source File
# Begin Source File
SOURCE=.\hq2x.h
# End Source File
# Begin Source File
SOURCE=.\mac\mac.h
# End Source File
# Begin Source File
SOURCE=.\memory\memory.h
# End Source File
# Begin Source File
SOURCE=.\loaders\tga.h
# End Source File
# Begin Source File
SOURCE=.\loaders\wav.h
# End Source File
# Begin Source File
SOURCE=.\wolf\wolf_def.h
# End Source File
# Begin Source File
SOURCE=.\zip\zip.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "wolfextractor"=.\wolfextractor.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

Binary file not shown.

View File

@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wolfextractor", "wolfextractor.vcproj", "{22DE1107-6438-4DB7-BADB-EB734285B464}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{22DE1107-6438-4DB7-BADB-EB734285B464}.Debug|Win32.ActiveCfg = Debug|Win32
{22DE1107-6438-4DB7-BADB-EB734285B464}.Debug|Win32.Build.0 = Debug|Win32
{22DE1107-6438-4DB7-BADB-EB734285B464}.Release|Win32.ActiveCfg = Release|Win32
{22DE1107-6438-4DB7-BADB-EB734285B464}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Binary file not shown.

View File

@@ -0,0 +1,814 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="wolfextractor"
ProjectGUID="{22DE1107-6438-4DB7-BADB-EB734285B464}"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Release/wolfextractor.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;vsnprintf=_vsnprintf"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\Release/wolfextractor.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="vorbisenc_static.lib vorbis_static.lib ogg_static.lib"
OutputFile=".\Release/wolfextractor.exe"
LinkIncremental="1"
SuppressStartupBanner="true"
IgnoreDefaultLibraryNames="libcmt.lib"
ProgramDatabaseFile=".\Release/wolfextractor.pdb"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Release/wolfextractor.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Debug/wolfextractor.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/I &quot;c:\libvorbis-1.2.0\include&quot; /I &quot;c:\libogg-1.1.3\include&quot;"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;vsnprintf=_vsnprintf"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
PrecompiledHeaderFile=".\Debug/wolfextractor.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="vorbisenc_static.lib vorbis_static.lib ogg_static.lib"
OutputFile=".\Debug/wolfextractor.exe"
LinkIncremental="2"
SuppressStartupBanner="true"
IgnoreDefaultLibraryNames="libcmt.lib"
GenerateDebugInformation="true"
ProgramDatabaseFile=".\Debug/wolfextractor.pdb"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Debug/wolfextractor.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath="..\..\zlib\adler32.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="adlib\adlib.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\common\arch.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="string\com_string.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\zlib\compress.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\zlib\crc32.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\zlib\deflate.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="filesys\file.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="adlib\fmopl.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="hq2x.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="mac\mac.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="main.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="memory\memory.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="pak.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="loaders\tga.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\zlib\trees.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="vorbisenc_inter.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="loaders\wav.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="filesys\win32\win_file.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="wolf\wl6_name.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="wolf\wolf_aud.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="wolf\wolf_gfx.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="wolf\wolf_map.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="wolf\wolf_pal.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="wolf\wolf_pm.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="zip\zipfile.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\zlib\zutil.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath="adlib\adlib.h"
>
</File>
<File
RelativePath="..\..\common\arch.h"
>
</File>
<File
RelativePath="string\com_string.h"
>
</File>
<File
RelativePath="..\..\common\common_utils.h"
>
</File>
<File
RelativePath="filesys\file.h"
>
</File>
<File
RelativePath="adlib\fmopl.h"
>
</File>
<File
RelativePath="hq2x.h"
>
</File>
<File
RelativePath="mac\mac.h"
>
</File>
<File
RelativePath="memory\memory.h"
>
</File>
<File
RelativePath="loaders\tga.h"
>
</File>
<File
RelativePath="loaders\wav.h"
>
</File>
<File
RelativePath="wolf\wolf_def.h"
>
</File>
<File
RelativePath="zip\zip.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioUserFile
ProjectType="Visual C++"
Version="8.00"
ShowAllFiles="false"
>
<Configurations>
<Configuration
Name="Release|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="JOHNCMBP"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
<Configuration
Name="Debug|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory="c:\wolf3d"
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="JOHNCMBP"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor="0"
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
</Configurations>
</VisualStudioUserFile>

View File

@@ -0,0 +1,104 @@
/*
Copyright (C) 2004 Michael Liebscher
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __ZIP_H__
#define __ZIP_H__
#include "../../../common/arch.h"
/* compression method */
#define CM_NO_COMPRESSION 0
#define CM_SHRUNK 1
#define CM_REDUCED_F1 2
#define CM_REDUCED_F2 3
#define CM_REDUCED_F3 4
#define CM_REDUCED_F4 5
#define CM_IMPLODED 6
#define CM_RESERVED_7 7
#define CM_DEFLATED 8
#define CM_DEFLATE64 9
#define CM_IMPLODING 10
#define CM_RESERVED_11 11
#define CM_BZIP2 12
/* version made by */
#define VMB_MSDOS_FAT 0
#define VMB_AMIGA 1
#define VMB_OPENVMS 2
#define VMB_UNIX 3
#define VMB_VM_CMS 4
#define VMB_ATARI_ST 5
#define VMB_OS_2_HPFS 6
#define VMB_MACINTOSH 7
#define VMB_Z_SYSTEM 8
#define VMB_CP_M 9
#define VMB_WINDOWS_NTFS 10
#define VMB_MVS_OS_390_Z_OS 11
#define VMB_VSE 12
#define VMB_ACORN_RISC 13
#define VMB_VFAT 14
#define VMB_ALTERNATE_MVS 15
#define VMB_BEOS 16
#define VMB_TANDEM 17
#define VMB_OS_400 18
#define VMB_OS_X_DARWIN 19
struct zlist
{
W16 versionmadeby;
W16 versionneeded;
W16 flag;
W16 compression_method;
W32 timedate;
W32 crc32;
W32 compressed_size;
W32 uncompressed_size;
W16 filename_length;
W16 extrafield_length;
W16 centralextra_length;
W16 comment_length;
W16 disknumstart;
W16 internalattribute;
W16 localflag;
W32 externalattribute;
W32 offset;
_boolean deletefile;
char filename[ 256 ];
char extrafield[ 256 ];
char centralextra[ 256 ];
char comment[ 256 ];
struct zlist *next; /* Pointer to next header in chain */
};
extern _boolean zip_writelocalfileheader( struct zlist *z, FILE *f );
extern _boolean zip_writeextended( struct zlist *z, FILE *f );
extern _boolean zip_writecentral( struct zlist *z, FILE *f );
extern _boolean zip_writeend( SW32 num, W32 size, W32 offset, W16 len, char *comment, FILE *f );
#endif /* __ZIP_H__ */

View File

@@ -0,0 +1,267 @@
/*
Copyright (C) 2004 Michael Liebscher
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* zipfile.c: Write zip file
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
*/
/*
Notes:
Reference document:
http://www.pkware.com/company/standards/appnote/appnote.txt
*/
#include <stdio.h>
#include "../../../common/arch.h"
#include "../../../common/common_utils.h"
#include "zip.h"
/* Signatures for zip file information headers */
#define SIG_LOCAL 0x04034b50L
#define SIG_CENTRAL 0x02014b50L
#define SIG_END 0x06054b50L
#define SIG_EXTENDLOCAL 0x08074b50L
#define SIG_EXTENDSPLOCAL 0x30304b50L
/* Length of header (not counting the signature) */
#define LOCALHEAD_SIZE 26
#define CENTRALHEAD_SIZE 42
#define ENDHEAD_SIZE 18
/*
-----------------------------------------------------------------------------
Function: zip_writelocalfileheader -Write a local header to file.
Parameters:
z -[in] zip entry to write local header for.
f -[in] File to write to.
Returns:
Notes:
-----------------------------------------------------------------------------
*/
_boolean zip_writelocalfileheader( struct zlist *z, FILE *f )
{
W32 temp32;
W16 temp16;
W32 retval;
temp32 = LittleLong( SIG_LOCAL );
retval = fwrite( &temp32, 1, 4, f );
temp16 = LittleShort( z->versionneeded );
retval += fwrite( &temp16, 1, 2, f );
temp16 = LittleShort( z->localflag );
retval += fwrite( &temp16, 1, 2, f );
temp16 = LittleShort( z->compression_method );
retval += fwrite( &temp16, 1, 2, f );
temp32 = LittleLong( z->timedate );
retval += fwrite( &temp32, 1, 4, f );
temp32 = LittleLong( z->crc32 );
retval += fwrite( &temp32, 1, 4, f );
temp32 = LittleLong( z->compressed_size );
retval += fwrite( &temp32, 1, 4, f );
temp32 = LittleLong( z->uncompressed_size );
retval += fwrite( &temp32, 1, 4, f );
temp16 = LittleShort( z->filename_length );
retval += fwrite( &temp16, 1, 2, f );
temp16 = LittleShort( z->extrafield_length );
retval += fwrite( &temp16, 1, 2, f );
if( retval != LOCALHEAD_SIZE + 4 )
{
return false;
}
if( fwrite( z->filename, 1, z->filename_length, f ) != z->filename_length ||
(z->extrafield && fwrite( z->extrafield, 1, z->extrafield_length, f) != z->extrafield_length) )
{
return false;
}
return true;
}
/*
-----------------------------------------------------------------------------
Function: zip_writecentral -Write a central header to file.
Parameters:
z -[in] zip entry to write central header for.
f -[in] File to write to.
Returns:
Notes:
-----------------------------------------------------------------------------
*/
_boolean zip_writecentral( struct zlist *z, FILE *f )
{
W32 temp32;
W16 temp16;
W32 retval;
temp32 = LittleLong( SIG_CENTRAL );
retval = fwrite( &temp32, 1, 4, f );
temp16 = LittleShort( z->versionmadeby );
retval += fwrite( &temp16, 1, 2, f );
temp16 = LittleShort( z->versionneeded );
retval += fwrite( &temp16, 1, 2, f );
temp16 = LittleShort( z->flag );
retval += fwrite( &temp16, 1, 2, f );
temp16 = LittleShort( z->compression_method );
retval += fwrite( &temp16, 1, 2, f );
temp32 = LittleLong( z->timedate );
retval += fwrite( &temp32, 1, 4, f );
temp32 = LittleLong( z->crc32 );
retval += fwrite( &temp32, 1, 4, f );
temp32 = LittleLong( z->compressed_size );
retval += fwrite( &temp32, 1, 4, f );
temp32 = LittleLong( z->uncompressed_size );
retval += fwrite( &temp32, 1, 4, f );
temp16 = LittleShort( z->filename_length );
retval += fwrite( &temp16, 1, 2, f );
temp16 = LittleShort( z->centralextra_length );
retval += fwrite( &temp16, 1, 2, f );
temp16 = LittleShort( z->comment_length );
retval += fwrite( &temp16, 1, 2, f );
temp16 = LittleShort( z->disknumstart );
retval += fwrite( &temp16, 1, 2, f );
temp16 = LittleShort( z->internalattribute );
retval += fwrite( &temp16, 1, 2, f );
temp32 = LittleLong( z->externalattribute );
retval += fwrite( &temp32, 1, 4, f );
temp32 = LittleLong( z->offset );
retval += fwrite( &temp32, 1, 4, f );
if( retval != CENTRALHEAD_SIZE + 4 )
{
return false;
}
if( fwrite(z->filename, 1, z->filename_length, f) != z->filename_length ||
(z->centralextra_length && fwrite(z->centralextra, 1, z->centralextra_length, f) != z->centralextra_length) ||
(z->comment_length && fwrite(z->comment, 1, z->comment_length, f) != z->comment_length) )
{
return false;
}
return true;
}
/*
-----------------------------------------------------------------------------
Function: zip_writeend -Write end of central directory data to file.
Parameters:
num -[in] Number of entries in central directory.
size -[in] Size of central directory.
offset -[in] Offset of central directory.
len -[in] Length of zip file comment (0 if none).
comment -[in] Zip file comment if len != 0.
f -[in] File to write to.
Returns:
Notes:
-----------------------------------------------------------------------------
*/
_boolean zip_writeend( SW32 num, W32 size, W32 offset, W16 len, char *comment, FILE *f )
{
W32 temp32;
W16 temp16;
W32 retval;
temp32 = LittleLong( SIG_END );
retval = fwrite( &temp32, 1, 4, f );
temp16 = 0;
retval += fwrite( &temp16, 1, 2, f );
temp16 = 0;
retval += fwrite( &temp16, 1, 2, f );
temp16 = LittleShort( num );
retval += fwrite( &temp16, 1, 2, f );
temp16 = LittleShort( num );
retval += fwrite( &temp16, 1, 2, f );
temp32 = LittleLong( size );
retval += fwrite( &temp32, 1, 4, f );
temp32 = LittleLong( offset );
retval += fwrite( &temp32, 1, 4, f );
temp16 = LittleShort( len );
retval += fwrite( &temp16, 1, 2, f );
if( retval != ENDHEAD_SIZE + 4 )
{
return false;
}
if( len && fwrite( comment, 1, len, f ) != len )
{
return false;
}
return true;
}