MIXFILE.H 3.8 KB

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