MissionEditorPackLib.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. FinalSun/FinalAlert 2 Mission Editor
  3. Copyright (C) 1999-2024 Electronic Arts, Inc.
  4. Authored by Matthias Wagner
  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. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. #ifndef FSUNPACKLIB_INCLUDED
  17. #define FSUNPACKLIB_INCLUDED
  18. #include <windows.h>
  19. #include <ddraw.h>
  20. #include <memory>
  21. #include <vector>
  22. #include <string>
  23. #include "Vec3.h"
  24. class VoxelNormalTables;
  25. typedef DWORD HMIXFILE;
  26. typedef DWORD HTSPALETTE;
  27. struct SHPHEADER
  28. {
  29. __int16 zero;
  30. __int16 cx;
  31. __int16 cy;
  32. __int16 c_images;
  33. };
  34. struct SHPIMAGEHEADER
  35. {
  36. __int16 x;
  37. __int16 y;
  38. __int16 cx;
  39. __int16 cy;
  40. __int32 compression;
  41. __int32 unknown;
  42. __int32 zero;
  43. __int32 offset;
  44. };
  45. namespace FSunPackLib
  46. {
  47. enum Game
  48. {
  49. RA2,
  50. RA2_YR,
  51. TS,
  52. TS_FS
  53. };
  54. enum class VoxelNormalClass: std::uint8_t
  55. {
  56. Unknown = 0,
  57. Gen1 = 1,
  58. TS = 2,
  59. Gen3 = 3,
  60. RA2 = 4,
  61. };
  62. extern "C" extern bool _DEBUG_EnableLogs; // only useable in debug library builds
  63. extern "C" extern bool _DEBUG_EnableBreakpoints; // only useable in debug library builds
  64. struct FSPL_EXCEPTION
  65. {
  66. int err_code;
  67. };
  68. extern "C" extern int last_succeeded_operation;
  69. class ColorConverterImpl;
  70. class ColorConverter
  71. {
  72. public:
  73. ColorConverter(const DDPIXELFORMAT& pf);
  74. int GetColor(int a, int r, int g, int b) const;
  75. int GetColor(int r, int g, int b) const;
  76. int GetColor(COLORREF col) const;
  77. private:
  78. std::shared_ptr<ColorConverterImpl> m_impl;
  79. };
  80. // base 64
  81. /*
  82. Converts hex data to Base64 data.
  83. sp - source poINTer
  84. len - length of hex data
  85. Returns a poINTer to the base64 data. Caller must free this memory.
  86. */
  87. BYTE* EncodeBase64(BYTE* sp, UINT len);
  88. /*
  89. Converts Base64 data to hex data.
  90. sp - source poINTer
  91. dp - dest buffer (should be as large as sp)
  92. Returns the hex data length
  93. */
  94. int DecodeBase64(const char* sp, std::vector<BYTE>& dest);
  95. // format 80
  96. /*
  97. Pack to a simple format 80 pack like Overlay & OverlayData-Pack
  98. sp - source poINTer (should be the 262144 bytes for overlay & overlaydata)
  99. len - length of the source data (should be 262144)
  100. nSections - section count. should be 32
  101. dest - poINTer to dest poINTer. Function allocates memory, caller must free this memory.
  102. Returns the length of the packed data.
  103. */
  104. INT EncodeF80(BYTE* sp, UINT len, UINT nSections, BYTE** dest);
  105. /*
  106. Extracts a simple format 80 pack like the Overlay & OverlayData-Pack
  107. Note that it extracts a whole pack, not just a simple section.
  108. In order to simply decode/encode Format80, you should use ConvertFromF80 and ConvertToF80
  109. sp - source poINTer
  110. SourceLength - length of the source
  111. dp - dest buffer
  112. max_size - maximum allowed destination size
  113. */
  114. bool DecodeF80(const BYTE* sp, UINT SourceLength, std::vector<BYTE>& dp, std::size_t max_size);
  115. // IsoMapPack5
  116. /*
  117. Pack IsoMapPack5.
  118. sp - source poINTer
  119. SourceLength - length of source
  120. dp - destination buffer
  121. Returns size of packed data
  122. */
  123. UINT EncodeIsoMapPack5(BYTE* sp, UINT SourceLength, BYTE** dp);
  124. /*
  125. Unpack IsoMapPack5.
  126. sp - source poINTer
  127. SourceLength - length of source
  128. dp - destination buffer
  129. */
  130. UINT DecodeIsoMapPack5(BYTE* sp, UINT SourceLength, BYTE* dp, HWND hProgressBar, BOOL bDebugMode);
  131. BOOL XCC_Initialize(BOOL bUseCache);
  132. HMIXFILE XCC_OpenMix(LPCTSTR szMixFile, HMIXFILE hOwner);
  133. BOOL XCC_GetMixName(HMIXFILE hOwner, std::string& sMixFile);
  134. BOOL XCC_DoesFileExist(LPCSTR szFile, HMIXFILE hOwner);
  135. BOOL XCC_CloseMix(HMIXFILE hMixFile);
  136. BOOL XCC_ExtractFile(const std::string& szFilename, const std::string& szSaveTo, HMIXFILE hOwner);
  137. BOOL XCC_ExtractFile(LPCSTR szFilename, LPCSTR szSaveTo, HMIXFILE hOwner);
  138. BOOL XCC_GetSHPHeader(SHPHEADER* pHeader);
  139. /*
  140. Returns the SHP image header of a image in a SHP file
  141. */
  142. BOOL XCC_GetSHPImageHeader(int iImageIndex, SHPIMAGEHEADER* pImageHeader);
  143. BOOL SetCurrentTMP(LPCSTR szTMP, HMIXFILE hOwner);
  144. BOOL SetCurrentSHP(LPCSTR szSHP, HMIXFILE hOwner);
  145. BOOL XCC_GetTMPTileInfo(int iTile, POINT* lpPos, int* lpWidth, int* lpHeight, BYTE* lpDirection, BYTE* lpTileHeight, BYTE* lpTileType, RGBTRIPLE* lpRgbLeft, RGBTRIPLE* lpRgbRight);
  146. BOOL XCC_GetTMPInfo(RECT* lpRect, int* iTileCount, int* iTilesX, int* iTilesY);
  147. BOOL LoadTMPImageInSurface(IDirectDraw4* pdd, int iStart, int iCount, LPDIRECTDRAWSURFACE4* pdds, HTSPALETTE hPalette);
  148. BOOL LoadTMPImage(int iStart, int iCount, BYTE** lpTileArray);
  149. BOOL LoadSHPImageInSurface(IDirectDraw4* pdd, HTSPALETTE hPalette, int iImageIndex, int iCount, LPDIRECTDRAWSURFACE4* pdds);
  150. BOOL LoadSHPImage(int iImageIndex, int iCount, BYTE** lpPics);
  151. BOOL LoadSHPImage(int iImageIndex, std::vector<BYTE>& pic);
  152. HTSPALETTE LoadTSPalette(LPCSTR szPalette, HMIXFILE hPaletteOwner);
  153. HTSPALETTE LoadTSPalette(const std::string& szPalette, HMIXFILE hPaletteOwner);
  154. BOOL SetTSPaletteEntry(HTSPALETTE hPalette, BYTE bIndex, RGBTRIPLE* rgb, RGBTRIPLE* orig);
  155. BOOL SetCurrentVXL(LPCSTR lpVXLFile, HMIXFILE hMixFile);
  156. BOOL GetVXLInfo(int* cSections);
  157. BOOL GetVXLSectionInfo(int section, VoxelNormalClass& normalClass);
  158. BOOL LoadVXLImageInSurface(const VoxelNormalTables& normalTables, Vec3f lightDirection, IDirectDraw4* pdd, int iStart, int iCount, Vec3f rotation, Vec3f modelOffset, LPDIRECTDRAWSURFACE4* pdds, HTSPALETTE hPalette, int* lpXCenter = NULL, int* lpYCenter = NULL, int ZAdjust = 0, int* lpXCenterZMax = NULL, int* lpYCenterZMax = NULL, int i3dCenterX = -1, int i3dCenterY = -1);
  159. // modelOffset is applied before VXL/HVA translates and scales and before model-to-world rotation
  160. BOOL LoadVXLImage(const VoxelNormalTables& normalTables, Vec3f lightDirection, Vec3f rotation, Vec3f modelOffset, std::vector<BYTE>& image, std::vector<BYTE>& lighting, int* lpXCenter = NULL, int* lpYCenter = NULL, int ZAdjust = 0, int* lpXCenterZMax = NULL, int* lpYCenterZMax = NULL, int i3dCenterX = -1, int i3dCenterY = -1, RECT* vxlrect = NULL);
  161. BOOL WriteMixFile(LPCTSTR lpMixFile, LPCSTR* lpFiles, DWORD dwFileCount, Game game);
  162. HRESULT SetColorKey(IDirectDrawSurface4* pDDS, COLORREF rgb);
  163. };
  164. #endif