2024-04-20 15:57:49 +00:00
|
|
|
/*
|
2024-04-26 22:28:24 +00:00
|
|
|
* Descent 3
|
2024-04-20 15:57:49 +00:00
|
|
|
* Copyright (C) 2024 Parallax Software
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2024-05-06 15:12:44 +00:00
|
|
|
--- HISTORICAL COMMENTS FOLLOW ---
|
|
|
|
|
2024-04-16 03:43:29 +00:00
|
|
|
* $Logfile: /DescentIII/Main/Cfile/hog.cpp $
|
|
|
|
* $Revision: 20 $
|
|
|
|
* $Date: 8/06/99 4:29p $
|
|
|
|
* $Author: Samir $
|
|
|
|
*
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
*
|
|
|
|
* $Log: /DescentIII/Main/Cfile/hog.cpp $
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 20 8/06/99 4:29p Samir
|
|
|
|
* added function to read record information for a hog file entry. needed
|
|
|
|
* from mn3edit.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 19 7/28/99 3:35p Kevin
|
|
|
|
* Mac!
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 18 5/10/99 10:25p Ardussi
|
|
|
|
* changes to compile on Mac
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 17 4/15/99 9:19p Jeff
|
|
|
|
* Changes for Linux version
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 16 2/16/99 2:08p Nate
|
|
|
|
* Made CreateNewHogFile() a bit friendlier
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 15 1/13/99 6:39a Jeff
|
|
|
|
* fixed some case-sensitive #includes
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 13 10/15/98 2:52p Nate
|
|
|
|
* Fixed FileCopy() by changing free() to mem_free()
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 12 10/08/98 4:23p Kevin
|
|
|
|
* Changed code to comply with memory library usage. Always use mem_malloc
|
|
|
|
* , mem_free and mem_strdup
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 11 8/16/98 4:23p Nate
|
|
|
|
* Added CreateNewHogFile()
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 10 8/14/98 4:38p Nate
|
|
|
|
* Fixed a few minor bugs and added better error reporting
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 9 8/14/98 1:01p Nate
|
|
|
|
* Added better error reporting for the HogEditor
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 8 7/27/98 9:48a Nate
|
|
|
|
* Fixed hog file header filling
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 7 7/24/98 6:39p Nate
|
|
|
|
* fixed hog bugs.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 6 7/20/98 3:34p Nate
|
|
|
|
* Fixed up Hog file stuff
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 5 7/13/98 6:20p Nate
|
|
|
|
* Fixed ReadHogEntry() and WriteHogEntry()
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 4 7/13/98 2:18p Nate
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 3 4/01/98 7:03p Samir
|
|
|
|
* modified some cfile stuff.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 2 3/31/98 6:13p Samir
|
|
|
|
* new hogfile format.
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
* 1 3/31/98 6:08p Samir
|
2024-04-16 18:56:40 +00:00
|
|
|
*
|
2024-04-16 03:43:29 +00:00
|
|
|
*
|
|
|
|
* $NoKeywords: $
|
|
|
|
*/
|
2024-05-06 19:50:07 +00:00
|
|
|
|
2024-04-16 03:43:29 +00:00
|
|
|
#include "byteswap.h"
|
2024-04-21 20:54:02 +00:00
|
|
|
#include "hogfile.h"
|
2024-04-16 20:34:28 +00:00
|
|
|
|
2024-05-06 19:50:07 +00:00
|
|
|
/*
|
|
|
|
HOG FILE FORMAT v2.0
|
2024-04-16 18:56:40 +00:00
|
|
|
|
2024-05-06 19:50:07 +00:00
|
|
|
HOG_TAG_STR [strlen()]
|
|
|
|
NFILES [int32]
|
|
|
|
HDRINFO [HOG_HDR_SIZE]
|
|
|
|
FILE_TABLE [sizeof(FILE_ENTRY) * NFILES]
|
|
|
|
FILE 0 [filelen(FILE 0)]
|
|
|
|
FILE 1 [filelen(FILE 1)]
|
|
|
|
.
|
|
|
|
.
|
|
|
|
.
|
|
|
|
FILE NFILES-1 [filelen(NFILES -1)]
|
2024-04-16 03:43:29 +00:00
|
|
|
*/
|
2024-05-06 19:50:07 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
bool ReadHogHeader(FILE *fp, tHogHeader *header) {
|
2024-05-06 19:50:07 +00:00
|
|
|
if (fread(&header->nfiles, sizeof(header->nfiles), 1, fp) != 1)
|
|
|
|
return false;
|
2024-04-16 18:56:40 +00:00
|
|
|
header->nfiles = INTEL_INT(header->nfiles);
|
|
|
|
|
2024-05-06 19:50:07 +00:00
|
|
|
if (fread(&header->file_data_offset, sizeof(header->file_data_offset), 1, fp) != 1)
|
2024-04-16 18:56:40 +00:00
|
|
|
return false;
|
2024-05-06 19:50:07 +00:00
|
|
|
header->file_data_offset = INTEL_INT(header->file_data_offset);
|
|
|
|
|
|
|
|
return true;
|
2024-04-16 03:43:29 +00:00
|
|
|
}
|
2024-05-06 19:50:07 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
bool ReadHogEntry(FILE *fp, tHogFileEntry *entry) {
|
2024-05-06 19:50:07 +00:00
|
|
|
if (fread(entry->name, sizeof(char), HOG_FILENAME_LEN, fp) != HOG_FILENAME_LEN)
|
|
|
|
return false;
|
|
|
|
if (fread(&entry->flags, sizeof(entry->flags), 1, fp) != 1)
|
|
|
|
return false;
|
2024-04-16 18:56:40 +00:00
|
|
|
entry->flags = INTEL_INT(entry->flags);
|
|
|
|
|
2024-05-06 19:50:07 +00:00
|
|
|
if (fread(&entry->len, sizeof(entry->len), 1, fp) != 1)
|
2024-04-16 18:56:40 +00:00
|
|
|
return false;
|
2024-05-06 19:50:07 +00:00
|
|
|
entry->len = INTEL_INT(entry->len);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-05-06 19:50:07 +00:00
|
|
|
if (fread(&entry->timestamp, sizeof(entry->timestamp), 1, fp) != 1)
|
2024-04-16 18:56:40 +00:00
|
|
|
return false;
|
2024-05-06 19:50:07 +00:00
|
|
|
entry->timestamp = INTEL_INT(entry->timestamp);
|
2024-04-18 19:32:10 +00:00
|
|
|
|
2024-05-06 19:50:07 +00:00
|
|
|
return true;
|
2024-04-16 03:43:29 +00:00
|
|
|
}
|