CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

MIXFILE.H (3897B)


      1 //
      2 // Copyright 2020 Electronic Arts Inc.
      3 //
      4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 
      5 // software: you can redistribute it and/or modify it under the terms of 
      6 // the GNU General Public License as published by the Free Software Foundation, 
      7 // either version 3 of the License, or (at your option) any later version.
      8 
      9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 
     10 // in the hope that it will be useful, but with permitted additional restrictions 
     11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 
     12 // distributed with this program. You should have received a copy of the 
     13 // GNU General Public License along with permitted additional restrictions 
     14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
     15 
     16 /* $Header: /CounterStrike/MIXFILE.H 1     3/03/97 10:25a Joe_bostic $ */
     17 
     18 #ifndef MIXFILE_H
     19 #define MIXFILE_H
     20 
     21 
     22 /*
     23 **	The "bool" integral type was defined by the C++ committee in
     24 **	November of '94. Until the compiler supports this, use the following
     25 **	definition.
     26 */
     27 #ifndef __BORLANDC__
     28 #ifndef TRUE_FALSE_DEFINED
     29 #define TRUE_FALSE_DEFINED
     30 enum {false=0,true=1};
     31 typedef int bool;
     32 #endif
     33 #endif
     34 
     35 #include	<stdlib.h>
     36 #include	"listnode.h"
     37 #include	"pk.h"
     38 #include "buff.h"
     39 
     40 template<class T>
     41 class MixFileClass : public Node<MixFileClass<T>>
     42 {
     43 	public:
     44 		char const * Filename;			// Filename of mixfile.
     45 
     46 
     47 		MixFileClass(char const *filename, PKey const * key);
     48 		~MixFileClass(void);
     49 
     50 		static bool Free(char const *filename);
     51 		void Free(void);
     52 		static void Free_All(void);	// ST - 12/18/2019 11:35AM
     53 		bool Cache(Buffer const * buffer = NULL);
     54 		static bool Cache(char const *filename, Buffer const * buffer=NULL);
     55 		static bool Offset(char const *filename, void ** realptr = 0, MixFileClass ** mixfile = 0, long * offset = 0, long * size = 0);
     56 		static void const * Retrieve(char const *filename);
     57 
     58 		struct SubBlock {
     59 			long CRC;				// CRC code for embedded file.
     60 			long Offset;			// Offset from start of data section.
     61 			long Size;				// Size of data subfile.
     62 
     63 			int operator < (SubBlock & two) const {return (CRC < two.CRC);};
     64 			int operator > (SubBlock & two) const {return (CRC > two.CRC);};
     65 			int operator == (SubBlock & two) const {return (CRC == two.CRC);};
     66 		};
     67 
     68 	private:
     69 		static MixFileClass * Finder(char const * filename);
     70 		//long Offset(long crc, long * size = 0) const;	// ST - 5/10/2019
     71 
     72 		/*
     73 		**	If this mixfile has an attached message digest, then this flag
     74 		**	will be true. The digest is checked only when the mixfile is
     75 		**	cached.
     76 		*/
     77 		unsigned IsDigest:1;
     78 
     79 		/*
     80 		**	If the header to this mixfile has been encrypted, then this flag
     81 		**	will be true. Although the header of the mixfile may be encrypted,
     82 		**	the attached data files are not.
     83 		*/
     84 		unsigned IsEncrypted:1;
     85 
     86 		/*
     87 		**	If the cached memory block was allocated by this routine, then this
     88 		**	flag will be true.
     89 		*/
     90 		unsigned IsAllocated:1;
     91 
     92 		/*
     93 		**	This is the initial file header. It tells how many files are embedded
     94 		**	within this mixfile and the total size of all embedded files.
     95 		*/
     96 		typedef struct {
     97 			short	count;
     98 			long	size;
     99 		} FileHeader;
    100 
    101 		/*
    102 		**	The number of files within the mixfile.
    103 		*/
    104 		int Count;
    105 
    106 		/*
    107 		**	This is the total size of all the data file embedded within the mixfile.
    108 		**	It does not include the header or digest bytes.
    109 		*/
    110 		long DataSize;
    111 
    112 		/*
    113 		**	Start of raw data in within the mixfile.
    114 		*/
    115 		long DataStart;
    116 
    117 		/*
    118 		**	Points to the file header control block array. Each file in the mixfile will
    119 		**	have an entry in this table. The entries are sorted by their (signed) CRC value.
    120 		*/
    121 		SubBlock * HeaderBuffer;
    122 
    123 		/*
    124 		**	If the mixfile has been cached, then this points to the cached data.
    125 		*/
    126 		void * Data;						// Pointer to raw data.
    127 
    128 		static List<MixFileClass> List;
    129 };
    130 
    131 #endif