From d25fef7d6967819f7e445516da9150d0eb1cdf3e Mon Sep 17 00:00:00 2001 From: Florian Schulze Date: Sun, 30 Mar 2003 18:20:20 +0000 Subject: [PATCH] Enabled support for gzip compressed levels and added support for bzip2 compressed levels. --- ChangeLog | 3 ++ Makefile | 5 +-- VisualC6/jumpnbump.dsp | 8 ++--- globals.pre | 4 +-- main.c | 70 +++++++++++++++++++++++++++++++++++++++--- 5 files changed, 78 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4ae0fa3..421d5da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +30 Mar 2004 - 1.42 + - added support for gzip and bzip2 packed levels. + 21 Mar 2003 - 1.41 - new scaling filter which works with 8bit graphics. Removed the old scaler completely, now fading and everything else works in scaled up mode. diff --git a/Makefile b/Makefile index cef00ca..1f5611d 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ SDL_CFLAGS = `sdl-config --cflags` SDL_LIBS = `sdl-config --libs` CFLAGS = -Wall -O2 -ffast-math -funroll-loops -Dstricmp=strcasecmp \ - -Dstrnicmp=strncasecmp -DUSE_SDL -DNDEBUG -I. $(SDL_CFLAGS) -DUSE_NET -LIBS = -lm $(SDL_LIBS) -lSDL_mixer -lSDL_net + -Dstrnicmp=strncasecmp -DUSE_SDL -DNDEBUG -I. $(SDL_CFLAGS) \ + -DUSE_NET -DZLIB_SUPPORT -DBZLIB_SUPPORT +LIBS = -lm $(SDL_LIBS) -lSDL_mixer -lSDL_net -lbz2 -lz SDL_TARGET = sdl.a MODIFY_TARGET = gobpack jnbpack jnbunpack OBJS = fireworks.o main.o menu.o filter.o diff --git a/VisualC6/jumpnbump.dsp b/VisualC6/jumpnbump.dsp index 50efec3..de65599 100644 --- a/VisualC6/jumpnbump.dsp +++ b/VisualC6/jumpnbump.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "USE_SDL" /D "USE_NET" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "USE_SDL" /D "USE_NET" /D "ZLIB_SUPPORT" /D "BZLIB_SUPPORT" /YX /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x407 /d "NDEBUG" @@ -53,7 +53,7 @@ BSC32=bscmake.exe # 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 /nologo /subsystem:windows /machine:I386 -# ADD 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 SDLmain.lib SDL.lib SDL_mixer.lib SDL_net.lib /nologo /subsystem:windows /profile /machine:I386 +# ADD 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 SDLmain.lib SDL.lib SDL_mixer.lib SDL_net.lib zlib.lib libbz2.lib /nologo /subsystem:windows /profile /machine:I386 # SUBTRACT LINK32 /debug # Begin Custom Build ProjDir=. @@ -93,7 +93,7 @@ BuildCmds= \ # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "USE_SDL" /D "USE_NET" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "USE_SDL" /D "USE_NET" /D "ZLIB_SUPPORT" /D "BZLIB_SUPPORT" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x407 /d "_DEBUG" @@ -103,7 +103,7 @@ BSC32=bscmake.exe # 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 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept -# ADD 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 SDLmain.lib SDL.lib SDL_mixer.lib SDL_net.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept +# ADD 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 SDLmain.lib SDL.lib SDL_mixer.lib SDL_net.lib zlib.lib libbz2.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept # Begin Custom Build ProjDir=. InputPath=.\Debug\jumpnbump.exe diff --git a/globals.pre b/globals.pre index 19a257b..469576e 100644 --- a/globals.pre +++ b/globals.pre @@ -1,7 +1,7 @@ /* * globals.h * Copyright (C) 1998 Brainchild Design - http://brainchilddesign.com/ - * + * * Copyright (C) 2001 Chuck Mason * * Copyright (C) 2002 Florian Schulze @@ -79,7 +79,7 @@ void tellServerPlayerMoved(int playerid, int movement_type, int newval); #define MOVEMENT_RIGHT 2 #define MOVEMENT_UP 3 -#define JNB_VERSION "1.41" +#define JNB_VERSION "1.42" #define JNB_WIDTH 400 #define JNB_HEIGHT 256 diff --git a/main.c b/main.c index d8a9c7d..b6b13c3 100644 --- a/main.c +++ b/main.c @@ -29,6 +29,14 @@ #include #endif +#ifdef BZLIB_SUPPORT +#include "bzlib.h" +#endif + +#ifdef ZLIB_SUPPORT +#include "zlib.h" +#endif + #ifdef USE_NET #include "SDL_net.h" #endif /* USE_NET */ @@ -2629,16 +2637,70 @@ static void preread_datafile(const char *fname) int len; #ifdef ZLIB_SUPPORT - char *gzfilename = alloca(strlen(fname) + 4); - int bufsize = 0; - int bufpos = 0; + char *gzfilename; gzFile gzf; +#endif + +#ifdef BZLIB_SUPPORT + char *bzfilename; + BZFILE *bzf; +#endif + +#ifdef BZLIB_SUPPORT + bzfilename = malloc(strlen(fname) + 5); + strcpy(bzfilename, fname); + strcat(bzfilename, ".bz2"); + bzf = BZ2_bzopen(bzfilename, "rb"); + free(bzfilename); + bzfilename = NULL; + + if (bzf != NULL) { + int bufsize = 0; + int bufpos = 0; + int br; + unsigned char *ptr; + do { + if (bufpos >= bufsize) { + bufsize += 1024 * 1024; + datafile_buffer = (unsigned char *) realloc(datafile_buffer, bufsize); + if (datafile_buffer == NULL) { + perror("realloc()"); + exit(42); + } + } + br = BZ2_bzread(bzf, datafile_buffer + bufpos, bufsize - bufpos); + if (br == -1) { + fprintf(stderr, "gzread failed.\n"); + exit(42); + } + + bufpos += br; + } while (br>0); + + /* try to shrink buffer... */ + ptr = (unsigned char *) realloc(datafile_buffer, bufpos); + if (ptr != NULL) + datafile_buffer = ptr; + + BZ2_bzclose(bzf); + return; + } + + /* drop through and try for an gzip compressed or uncompressed datafile... */ +#endif + +#ifdef ZLIB_SUPPORT + gzfilename = malloc(strlen(fname) + 4); strcpy(gzfilename, fname); strcat(gzfilename, ".gz"); - gzf = gzopen(gzfilename, "rb"); + free(gzfilename); + gzfilename = NULL; + if (gzf != NULL) { + int bufsize = 0; + int bufpos = 0; unsigned char *ptr; do { int br; -- 2.39.2