load.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. ** Command & Conquer Renegade(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. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /Commando/Library/LOAD.CPP $*
  25. * *
  26. * $Author:: Greg_h $*
  27. * *
  28. * $Modtime:: 7/22/97 11:37a $*
  29. * *
  30. * $Revision:: 1 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * Load_Uncompress -- Load and uncompress the given file. *
  35. * Uncompress_Data -- Uncompress standard CPS buffer. *
  36. * Load_Data -- Loads a data file from disk. *
  37. * Load_Alloc_Data -- Loads and allocates buffer for a file. *
  38. * Write_Data -- Writes a block of data as a file to disk. *
  39. * Uncompress_Data -- Uncompresses data from one buffer to another. *
  40. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  41. #include "always.h"
  42. #include "iff.h"
  43. #include "lcw.h"
  44. #include <string.h>
  45. /***************************************************************************
  46. * Uncompress_Data -- Uncompresses data from one buffer to another. *
  47. * *
  48. * This routine takes data from a compressed file (sans the first two *
  49. * size bytes) and uncompresses it to a destination buffer. The source *
  50. * data MUST have the CompHeaderType at its start. *
  51. * *
  52. * INPUT: src -- Source compressed data pointer. *
  53. * *
  54. * dst -- Destination (paragraph aligned) pointer. *
  55. * *
  56. * OUTPUT: Returns with the size of the uncompressed data. *
  57. * *
  58. * WARNINGS: If LCW compression is used, the destination buffer must *
  59. * be paragraph aligned. *
  60. * *
  61. * HISTORY: *
  62. * 09/17/1993 JLB : Created. *
  63. *=========================================================================*/
  64. unsigned long __cdecl Uncompress_Data(void const *src, void *dst)
  65. {
  66. unsigned int skip; // Number of leading data to skip.
  67. CompressionType method; // Compression method used.
  68. unsigned long uncomp_size;
  69. if (!src || !dst) return(NULL);
  70. /*
  71. ** Interpret the data block header structure to determine
  72. ** compression method, size, and skip data amount.
  73. */
  74. uncomp_size = ((CompHeaderType*)src)->Size;
  75. #if(AMIGA)
  76. uncomp_size = Reverse_Long(uncomp_size);
  77. #endif
  78. skip = ((CompHeaderType*)src)->Skip;
  79. #if(AMIGA)
  80. skip = Reverse_Word(skip);
  81. #endif
  82. method = (CompressionType) ((CompHeaderType*)src)->Method;
  83. src = ((char*)src) + (long)sizeof(CompHeaderType) + (long)skip;
  84. // src = Add_Long_To_Pointer((void *)src, (long)sizeof(CompHeaderType) + (long)skip);
  85. switch (method) {
  86. default:
  87. case NOCOMPRESS:
  88. memmove(dst, (void *) src, uncomp_size);
  89. // Mem_Copy((void *) src, dst, uncomp_size);
  90. break;
  91. case HORIZONTAL:
  92. break;
  93. case LCW:
  94. LCW_Uncomp((void *) src, (void *) dst, (unsigned long) uncomp_size);
  95. break;
  96. }
  97. return(uncomp_size);
  98. }