MIXFILE.H 3.6 KB

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