2 Copyright (C) 2004-2010 Parallel Realities
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
42 void Pak::showPakErrorAndExit()
44 printf("\nFatal Error: The Blob Wars PAK file was either not found or was not accessable.\n");
45 printf("(If you compiled from source did you forget to run make install?)\n");
46 printf("The path to the file was expected to be,\n\n");
47 printf(PAKFULLPATH"\n\n");
48 printf("Please try running the game again. If problems persist either reinstall the game or check,\n\n");
49 printf("http://www.parallelrealities.co.uk/blobWars.php\n\n");
50 printf("for updates.\n\n");
54 void Pak::setPakFile(const char *pakFilename)
57 strlcpy(this->pakFilename, pakFilename, sizeof this->pakFilename);
59 debug(("Pak : Filename set to %s\n", pakFilename));
61 FILE *pak = fopen(pakFilename, "rb");
65 showPakErrorAndExit();
68 fseek(pak, (-sizeof(Uint32)) * 2, SEEK_END);
69 fread(&listPos, sizeof(Uint32), 1, pak);
70 fread(&numberOfFiles, sizeof(Uint32), 1, pak);
72 debug(("Pak : File list resides at %d\n", (int)listPos));
73 debug(("Pak : Number of files are %d\n", (int)numberOfFiles));
75 fd = new FileData[numberOfFiles];
77 fseek(pak, listPos, SEEK_SET);
81 for (unsigned int i = 0 ; i < numberOfFiles ; i++)
83 result = fread(&fd[i], sizeof(FileData), 1, pak);
88 showPakErrorAndExit();
91 debug(("Read FileData #%d / %d : %s\n", (i + 1), numberOfFiles, fd[i].filename));
99 bool Pak::unpack(const char *filename, unsigned char **buffer)
101 debug(("Pak : Unpacking %s...\n", filename));
105 for (unsigned int i = 0 ; i < numberOfFiles ; i++)
107 if (strcmp(filename, fd[i].filename) == 0)
109 currentFile = &fd[i];
114 if (currentFile == NULL)
119 FILE *pak = fopen(pakFilename, "rb");
122 showPakErrorAndExit();
125 fseek(pak, currentFile->location, SEEK_SET);
130 input = new unsigned char[(int)(currentFile->cSize * 1.01) + 12];
131 *buffer = new unsigned char[currentFile->fSize + 1];
133 fread(input, 1, currentFile->cSize, pak);
135 uLongf fSize = (uLongf)currentFile->fSize;
137 uncompress(*buffer, &fSize, input, currentFile->cSize);
138 (*buffer)[currentFile->fSize] = 0;
145 debug(("Pak : Unpack %s...Done\n", filename));
150 bool Pak::fileExists(const char *filename)
152 for (unsigned int i = 0 ; i < numberOfFiles ; i++)
154 if (strcmp(fd[i].filename, filename) == 0)
163 unsigned int Pak::getUncompressedSize() const
165 return (unsigned int)currentFile->fSize;