Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2793 lines
96 KiB

  1. //========= Copyright © 1996-2008, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Swaps the bytes in all file types generated by studiomdl
  4. // (.vvd, .vtx, .mdl, .phy, .ani) so the files can be loaded
  5. // on a big-endian machine, specifically the Xbox360. A new file is generated
  6. // with an extra extension in the form of <filename>.360.<ext>
  7. //
  8. //=============================================================================//
  9. #include "studio.h"
  10. #include "optimize.h"
  11. #include "phyfile.h"
  12. #include "studiobyteswap.h"
  13. #include "vphysics_interface.h"
  14. // NOTE: This has to be the last file included!
  15. #include "tier0/memdbgon.h"
  16. #undef ALIGN16
  17. #undef ALIGN32
  18. #undef ALIGN4
  19. #define ALIGN4( a ) a = (byte *)((intp)((byte *)a + 3) & ~ 3)
  20. #define ALIGN16( a ) a = (byte *)((intp)((byte *)a + 15) & ~ 15)
  21. #define ALIGN32( a ) a = (byte *)((intp)((byte *)a + 31) & ~ 31)
  22. #define ALIGN64( a ) a = (byte *)((intp)((byte *)a + 63) & ~ 63)
  23. // Fixup macros create variables that may not be referenced
  24. #pragma warning( push )
  25. #pragma warning( disable:4189 ) // local variable is initialized but not referenced
  26. #pragma warning( disable:4366 ) // The result of the unary '&' operator may be unaligned
  27. namespace StudioByteSwap
  28. {
  29. static bool g_bVerbose = true;
  30. static bool g_bNativeSrc;
  31. static CByteswap g_Swap;
  32. static IPhysicsCollision *pCollision;
  33. #ifdef _PS3
  34. static char *g_pFilename; // Used for warnings only, don't eat TLS slot on PS3
  35. #else
  36. CTHREADLOCALPTR(char) g_pFilename;
  37. #endif
  38. void ActivateByteSwapping( bool activate )
  39. {
  40. g_Swap.ActivateByteSwapping( activate );
  41. SourceIsNative( IsPC() );
  42. }
  43. void SourceIsNative( bool bNative )
  44. {
  45. g_bNativeSrc = bNative;
  46. }
  47. void SetCollisionInterface( IPhysicsCollision *pPhysicsCollision )
  48. {
  49. pCollision = pPhysicsCollision;
  50. }
  51. void SetVerbose( bool bVerbose )
  52. {
  53. g_bVerbose = bVerbose;
  54. }
  55. //----------------------------------------------------------------------
  56. // Helper to write a chunk of objects of the same type, and increment the buffer pointers.
  57. //----------------------------------------------------------------------
  58. template<class T> inline void WriteObjects( byte **pOutputBuffer, byte **pBaseData, int objectCount = 1 )
  59. {
  60. T tempObject;
  61. for ( int i = 0; i < objectCount; ++i )
  62. {
  63. Q_memcpy( &tempObject, *pBaseData, sizeof(T) );
  64. g_Swap.SwapFieldsToTargetEndian( &tempObject, &tempObject );
  65. Q_memcpy( *pOutputBuffer, &tempObject, sizeof(T) );
  66. *pOutputBuffer += sizeof(T);
  67. *pBaseData += sizeof(T);
  68. }
  69. }
  70. //----------------------------------------------------------------------
  71. // Helper to write a chunk of objects of the same type, and increment the buffer pointers.
  72. //----------------------------------------------------------------------
  73. template<class T> inline void WriteObjects( T **pOutputBuffer, T **pBaseData, int objectCount = 1 )
  74. {
  75. T tempObject;
  76. for ( int i = 0; i < objectCount; ++i )
  77. {
  78. Q_memcpy( &tempObject, *pBaseData, sizeof(T) );
  79. g_Swap.SwapFieldsToTargetEndian( &tempObject, &tempObject );
  80. Q_memcpy( *pOutputBuffer, &tempObject, sizeof(T) );
  81. ++*pOutputBuffer;
  82. ++*pBaseData;
  83. }
  84. }
  85. //----------------------------------------------------------------------
  86. // Helper to write a chunk of objects of the same type.
  87. //----------------------------------------------------------------------
  88. template<class T> inline void WriteObjects( byte *pOutputBuffer, byte *pBaseData, int objectCount = 1 )
  89. {
  90. T tempObject;
  91. for ( int i = 0; i < objectCount; ++i )
  92. {
  93. Q_memcpy( &tempObject, pBaseData, sizeof(T) );
  94. g_Swap.SwapFieldsToTargetEndian( &tempObject, &tempObject );
  95. Q_memcpy( pOutputBuffer, &tempObject, sizeof(T) );
  96. pOutputBuffer += sizeof(T);
  97. pBaseData += sizeof(T);
  98. }
  99. }
  100. //----------------------------------------------------------------------
  101. // Helper to write a chunk of objects of the same type.
  102. //----------------------------------------------------------------------
  103. template<class T> inline void WriteObjects( T *pOutputBuffer, T *pBaseData, int objectCount = 1 )
  104. {
  105. T tempObject;
  106. for ( int i = 0; i < objectCount; ++i )
  107. {
  108. Q_memcpy( &tempObject, pBaseData, sizeof(T) );
  109. g_Swap.SwapFieldsToTargetEndian( &tempObject, &tempObject );
  110. Q_memcpy( pOutputBuffer, &tempObject, sizeof(T) );
  111. ++pOutputBuffer;
  112. ++pBaseData;
  113. }
  114. }
  115. //----------------------------------------------------------------------
  116. // Helper to write a buffer of some integral type, and increment the buffer pointers.
  117. //----------------------------------------------------------------------
  118. template<class T> inline void WriteBuffer( byte **pOutputBuffer, byte **pBaseData, int objectCount = 1 )
  119. {
  120. T tempObject;
  121. for ( int i = 0; i < objectCount; ++i )
  122. {
  123. Q_memcpy( &tempObject, *pBaseData, sizeof(T) );
  124. g_Swap.SwapBufferToTargetEndian( &tempObject, &tempObject );
  125. Q_memcpy( *pOutputBuffer, &tempObject, sizeof(T) );
  126. *pOutputBuffer += sizeof(T);
  127. *pBaseData += sizeof(T);
  128. }
  129. }
  130. //----------------------------------------------------------------------
  131. // Helper to write a buffer of some integral type
  132. //----------------------------------------------------------------------
  133. template<class T> inline void WriteBuffer( byte *pOutputBuffer, byte *pBaseData, int objectCount = 1 )
  134. {
  135. T tempObject;
  136. for ( int i = 0; i < objectCount; ++i )
  137. {
  138. Q_memcpy( &tempObject, pBaseData, sizeof(T) );
  139. g_Swap.SwapBufferToTargetEndian( &tempObject, &tempObject );
  140. Q_memcpy( pOutputBuffer, &tempObject, sizeof(T) );
  141. pOutputBuffer += sizeof(T);
  142. pBaseData += sizeof(T);
  143. }
  144. }
  145. //----------------------------------------------------------------------
  146. // For getting values in the correct source/dest endian format
  147. //----------------------------------------------------------------------
  148. template< class T >
  149. T SrcNative( T *idx )
  150. {
  151. T ret = *idx;
  152. if ( !g_bNativeSrc )
  153. {
  154. g_Swap.SwapBuffer( &ret, idx );
  155. }
  156. return ret;
  157. }
  158. template< class T >
  159. T DestNative( T *idx )
  160. {
  161. T ret = *idx;
  162. if ( g_bNativeSrc )
  163. {
  164. g_Swap.SwapBuffer( &ret, idx );
  165. }
  166. return ret;
  167. }
  168. //----------------------------------------------------------------------
  169. // Declares objects pointers for src/dest buffer.
  170. // Because the declared pointers and even the base are likely to get
  171. // moved around by WriteObjects(), also stores off a copy of declared
  172. // pointer with a _Debug suffix -- purely for ease of watch window.
  173. //----------------------------------------------------------------------
  174. #define DECLARE_OBJECT_POINTERS( objPtr, base, type ) \
  175. type* objPtr##Src = (type*)base##Src; type* objPtr##Src_Debug = objPtr##Src; \
  176. type* objPtr##Dest = (type*)base##Dest; type* objPtr##Dest_Debug = objPtr##Dest; \
  177. type* objPtr = objPtr##Src;
  178. //----------------------------------------------------------------------
  179. // Same as DECLARE_OBJECT_POINTERS, but reuses existing type pointers.
  180. //----------------------------------------------------------------------
  181. #define SET_OBJECT_POINTERS( objPtr, base, type ) \
  182. objPtr##Src = (type*)base##Src; \
  183. objPtr##Dest = (type*)base##Dest; \
  184. objPtr = objPtr##Src;
  185. //----------------------------------------------------------------------
  186. // Declares src/dest byte pointers and sets them to some index offset in the buffers.
  187. //----------------------------------------------------------------------
  188. #define DECLARE_INDEX_POINTERS( ptr, base, index ) \
  189. byte *ptr##Src = (byte*)base##Src + SrcNative( &base##Src->index ); \
  190. byte *ptr##Dest = (byte*)base##Dest + SrcNative( &base##Src->index );
  191. //----------------------------------------------------------------------
  192. // Validates that the src pointer is DWORD aligned
  193. //----------------------------------------------------------------------
  194. #define DECLARE_INDEX_POINTERS_VALIDATE( ptr, base, index ) \
  195. DECLARE_INDEX_POINTERS( ptr, base, index ) \
  196. VALIDATE_ALIGNMENT( ptr##Src )
  197. //----------------------------------------------------------------------
  198. // Same as DECLARE_INDEX_POINTERS, but reuses existing byte pointers.
  199. //----------------------------------------------------------------------
  200. #define SET_INDEX_POINTERS( ptr, base, index ) \
  201. ptr##Src = (byte*)base##Src + SrcNative( &base##Src->index ); \
  202. ptr##Dest = (byte*)base##Dest + SrcNative( &base##Src->index );
  203. //----------------------------------------------------------------------
  204. // Validates that the src pointer is DWORD aligned
  205. //----------------------------------------------------------------------
  206. #define SET_INDEX_POINTERS_VALIDATE( ptr, base, index ) \
  207. SET_INDEX_POINTERS( ptr, base, index ) \
  208. VALIDATE_ALIGNMENT( ptr##Src )
  209. //----------------------------------------------------------------------
  210. // Same as DECLARE_INDEX_POINTERS, but reuses existing byte pointers.
  211. //----------------------------------------------------------------------
  212. #define VALIDATE_ALIGNMENT( ptr ) \
  213. { \
  214. byte *ptr##aligned = (byte*)ptr; \
  215. ALIGN4( ptr##aligned ); \
  216. if ( ptr##aligned != (byte*)ptr ) \
  217. { \
  218. Warning( "Studiobyteswap line %d: Misaligned data found in %s\n", __LINE__, (char *)g_pFilename ); \
  219. return ERROR_MISALIGNED_DATA; \
  220. } \
  221. }
  222. //----------------------------------------------------------------------
  223. // for() loop header, updates all three object pointers (src,dest,native)
  224. //----------------------------------------------------------------------
  225. #define ITERATE_BLOCK( objPtr, count ) \
  226. for ( int objPtr##_idx = 0; objPtr##_idx < SrcNative( &count ); ++objPtr##_idx, ++objPtr, ++objPtr##Src, ++objPtr##Dest )
  227. // Fake header declaration for easier phy swapping
  228. struct swapcompactsurfaceheader_t
  229. {
  230. DECLARE_BYTESWAP_DATADESC();
  231. int size;
  232. int vphysicsID;
  233. short version;
  234. short modelType;
  235. int surfaceSize;
  236. Vector dragAxisAreas;
  237. int axisMapSize;
  238. };
  239. BEGIN_BYTESWAP_DATADESC( swapcompactsurfaceheader_t )
  240. DEFINE_FIELD( size, FIELD_INTEGER ),
  241. DEFINE_FIELD( vphysicsID, FIELD_INTEGER ),
  242. DEFINE_FIELD( version, FIELD_SHORT ),
  243. DEFINE_FIELD( modelType, FIELD_SHORT ),
  244. DEFINE_FIELD( surfaceSize, FIELD_INTEGER ),
  245. DEFINE_FIELD( dragAxisAreas, FIELD_VECTOR ),
  246. DEFINE_FIELD( axisMapSize, FIELD_INTEGER ),
  247. END_BYTESWAP_DATADESC()
  248. // Fake header declaration for old style phy format
  249. #if defined( _X360 )
  250. #pragma bitfield_order( push, lsb_to_msb )
  251. #elif defined( _PS3 )
  252. #pragma ms_struct on
  253. #pragma reverse_bitfields on
  254. #endif
  255. struct legacysurfaceheader_t
  256. {
  257. DECLARE_BYTESWAP_DATADESC();
  258. int size;
  259. float mass_center[3];
  260. float rotation_inertia[3];
  261. float upper_limit_radius;
  262. BEGIN_BITFIELD( bf )
  263. int max_deviation : 8;
  264. int byte_size : 24;
  265. END_BITFIELD()
  266. int offset_ledgetree_root;
  267. int dummy[3];
  268. };
  269. #if defined( _X360 )
  270. #pragma bitfield_order( pop )
  271. #elif defined( _PS3 )
  272. #pragma ms_struct off
  273. #pragma reverse_bitfields off
  274. #endif
  275. BEGIN_BYTESWAP_DATADESC( legacysurfaceheader_t )
  276. DEFINE_FIELD( size, FIELD_INTEGER ),
  277. DEFINE_ARRAY( mass_center, FIELD_FLOAT, 3 ),
  278. DEFINE_ARRAY( rotation_inertia, FIELD_FLOAT, 3 ),
  279. DEFINE_FIELD( upper_limit_radius, FIELD_FLOAT ),
  280. DEFINE_BITFIELD( bf, FIELD_INTEGER, 32 ),
  281. DEFINE_FIELD( offset_ledgetree_root, FIELD_INTEGER ),
  282. DEFINE_ARRAY( dummy, FIELD_INTEGER, 3 ),
  283. END_BYTESWAP_DATADESC()
  284. //----------------------------------------------------------------------
  285. // Swap a .phy file
  286. //----------------------------------------------------------------------
  287. int ByteswapPHY( void *pDestBase, int destBaseSize, const void *pSrcBase, const int fileSize, CompressFunc_t pCompressFunc )
  288. {
  289. Assert( pCollision );
  290. if ( !pCollision )
  291. return 0;
  292. Q_memset( pDestBase, 0, fileSize );
  293. byte *pSrc = (byte*)pSrcBase;
  294. byte *pDest = (byte*)pDestBase;
  295. vcollide_t collide = {0};
  296. // file header
  297. phyheader_t *pHdr = (phyheader_t*)( g_bNativeSrc ? pSrc : pDest );
  298. WriteObjects<phyheader_t>( &pDest, &pSrc );
  299. if ( g_bNativeSrc )
  300. {
  301. // Reset the pointers and let ivp swap the binary physics data
  302. pSrc = (byte*)pSrcBase + pHdr->size;
  303. pDest = (byte*)pDestBase + pHdr->size;
  304. int bufSize = fileSize - pHdr->size;
  305. pCollision->VCollideLoad( &collide, pHdr->solidCount, (const char *)pSrc, bufSize, false );
  306. }
  307. // Swap the collision data headers
  308. for ( int i = 0; i < pHdr->solidCount; ++i )
  309. {
  310. swapcompactsurfaceheader_t *baseHdr = (swapcompactsurfaceheader_t*)( g_bNativeSrc ? pSrc : pDest );
  311. WriteObjects<swapcompactsurfaceheader_t>( pDest, pSrc );
  312. int srcIncrement = baseHdr->surfaceSize + sizeof(swapcompactsurfaceheader_t);
  313. int destIncrement = srcIncrement;
  314. bool bCopyToSrc = !g_bNativeSrc;
  315. if ( baseHdr->vphysicsID != MAKEID('V','P','H','Y') )
  316. {
  317. // May be old phy format
  318. legacysurfaceheader_t *legacyHdr = (legacysurfaceheader_t*)( g_bNativeSrc ? pSrc : pDest );
  319. WriteObjects<legacysurfaceheader_t>( pDest, pSrc );
  320. if ( legacyHdr->dummy[2] == MAKEID('I','V','P','S') || legacyHdr->dummy[2] == 0 )
  321. {
  322. srcIncrement = legacyHdr->byte_size + sizeof(int);
  323. destIncrement = legacyHdr->byte_size + sizeof(swapcompactsurfaceheader_t);
  324. bCopyToSrc = false;
  325. if ( !g_bNativeSrc )
  326. {
  327. // src needs the size member to be native to load vcollides
  328. Q_memcpy( pSrc, pDest, sizeof(int) );
  329. }
  330. }
  331. else
  332. {
  333. // Not recognized
  334. Assert(0);
  335. return 0;
  336. }
  337. }
  338. if ( bCopyToSrc )
  339. {
  340. // src needs the native header data to load the vcollides
  341. Q_memcpy( pSrc, pDest, sizeof(swapcompactsurfaceheader_t) );
  342. }
  343. pSrc += srcIncrement;
  344. pDest += destIncrement;
  345. }
  346. // the rest of the file is text
  347. int currPos = pSrc - (byte*)pSrcBase;
  348. int remainingBytes = fileSize - currPos;
  349. WriteBuffer<char>( &pDest, &pSrc, remainingBytes );
  350. if ( !g_bNativeSrc )
  351. {
  352. // let ivp swap the ledge tree
  353. pSrc = (byte*)pSrcBase + pHdr->size;
  354. int bufSize = fileSize - pHdr->size;
  355. pCollision->VCollideLoad( &collide, pHdr->solidCount, (const char *)pSrc, bufSize, true );
  356. }
  357. // Write out the ledge tree data
  358. pDest = (byte*)pDestBase + pHdr->size;
  359. for ( int i = 0; i < collide.solidCount; ++i )
  360. {
  361. // skip over the size
  362. pDest += sizeof(int);
  363. int offset = pCollision->CollideWrite( (char*)pDest, collide.solids[i], g_bNativeSrc );
  364. int destSize = g_bNativeSrc ? SwapLong( offset ) : offset;
  365. Q_memcpy( pDest - sizeof(int), &destSize, sizeof(int) );
  366. pDest += offset;
  367. }
  368. // Free the memory
  369. pCollision->VCollideUnload( &collide );
  370. int newFileSize = pDest - (byte*)pDestBase + remainingBytes;
  371. if ( pCompressFunc )
  372. {
  373. // compress entire swapped PHY
  374. void *pInput = pDestBase;
  375. int inputSize = newFileSize;
  376. void *pOutput;
  377. int outputSize;
  378. if ( pCompressFunc( pInput, inputSize, &pOutput, &outputSize ) )
  379. {
  380. // put the compressed version in its place
  381. V_memcpy( pDestBase, pOutput, outputSize );
  382. free( pOutput );
  383. newFileSize = outputSize;
  384. }
  385. }
  386. return newFileSize;
  387. }
  388. //----------------------------------------------------------------------
  389. // Swap a .vvd file
  390. //----------------------------------------------------------------------
  391. int ByteswapVVD( void *pDestBase, int destBaseSize, const void *pSrcBase, const int fileSize, CompressFunc_t pCompressFunc )
  392. {
  393. Q_memset( pDestBase, 0, fileSize );
  394. byte *pDataSrc = (byte*)pSrcBase;
  395. byte *pDataDest = (byte*)pDestBase;
  396. /** FILE HEADER **/
  397. DECLARE_OBJECT_POINTERS( pHdr, pData, vertexFileHeader_t )
  398. WriteObjects<vertexFileHeader_t>( &pDataDest, &pDataSrc );
  399. /** FIXUP TABLE **/
  400. SET_INDEX_POINTERS( pData, pHdr, fixupTableStart )
  401. WriteObjects<vertexFileFixup_t>( &pDataDest, &pDataSrc, SrcNative( &pHdr->numFixups ) );
  402. /** VERTEX DATA **/
  403. SET_INDEX_POINTERS( pData, pHdr, vertexDataStart )
  404. WriteObjects<mstudiovertex_t>( &pDataDest, &pDataSrc, SrcNative( &pHdr->numLODVertexes[0] ) );
  405. /** TANGENT DATA **/
  406. if ( pHdr->tangentDataStart != 0 )
  407. {
  408. SET_INDEX_POINTERS( pData, pHdr, tangentDataStart )
  409. WriteBuffer<float>( &pDataDest, &pDataSrc, 4 * SrcNative( &pHdr->numLODVertexes[0] ) );
  410. }
  411. int newFileSize = pDataDest - (byte*)pDestBase;
  412. // Need to support PS3 EDGE DMA INPUT stream
  413. if ( ( newFileSize < fileSize ) &&
  414. ( AlignValue( fileSize, 1 << 8 ) == fileSize ) )
  415. {
  416. // Everything else goes raw, processing tool performs PS3 byteswap!
  417. V_memcpy( pDataDest, pDataSrc, fileSize - newFileSize );
  418. newFileSize = fileSize;
  419. }
  420. if ( pCompressFunc )
  421. {
  422. void *pInput = (byte*)pDestBase + sizeof( vertexFileHeader_t );
  423. int inputSize = newFileSize - sizeof( vertexFileHeader_t );
  424. void *pOutput;
  425. int outputSize;
  426. if ( pCompressFunc( pInput, inputSize, &pOutput, &outputSize ) )
  427. {
  428. // place the compressed data after the header
  429. V_memcpy( pInput, pOutput, outputSize );
  430. free( pOutput );
  431. newFileSize = sizeof( vertexFileHeader_t ) + outputSize;
  432. }
  433. }
  434. return newFileSize;
  435. }
  436. //----------------------------------------------------------------------
  437. // Swap vertex indices in a .vtx file
  438. //----------------------------------------------------------------------
  439. void ByteswapVTX_Indices( byte *pDataDest, byte *pDataSrc, int numIndices )
  440. {
  441. WriteBuffer<short>( pDataDest, pDataSrc, numIndices );
  442. }
  443. //----------------------------------------------------------------------
  444. // Swap a .vtx file
  445. //----------------------------------------------------------------------
  446. int ByteswapVTX( void *pDestBase, int destBaseSize, const void *pSrcBase, const int fileSize, CompressFunc_t pCompressFunc )
  447. {
  448. Q_memset( pDestBase, 0, fileSize );
  449. // Do a straight copy first so the string table is transferred
  450. memcpy( pDestBase, pSrcBase, fileSize );
  451. // Start writing the file
  452. byte *pDataSrc = (byte*)pSrcBase;
  453. byte *pDataDest = (byte*)pDestBase;
  454. DECLARE_OBJECT_POINTERS( pVtxHeader, pData, OptimizedModel::FileHeader_t )
  455. if ( pVtxHeader->version != OPTIMIZED_MODEL_FILE_VERSION )
  456. {
  457. return ERROR_VERSION;
  458. }
  459. WriteObjects( pVtxHeaderDest, pVtxHeaderSrc );
  460. /** BODY PARTS **/
  461. SET_INDEX_POINTERS( pData, pVtxHeader, bodyPartOffset )
  462. DECLARE_OBJECT_POINTERS( pBodyPartHeader, pData, OptimizedModel::BodyPartHeader_t )
  463. ITERATE_BLOCK( pBodyPartHeader, pVtxHeader->numBodyParts )
  464. {
  465. WriteObjects( pBodyPartHeaderDest, pBodyPartHeaderSrc );
  466. /** MODELS **/
  467. SET_INDEX_POINTERS( pData, pBodyPartHeader, modelOffset )
  468. DECLARE_OBJECT_POINTERS( pModelHeader, pData, OptimizedModel::ModelHeader_t )
  469. ITERATE_BLOCK( pModelHeader, pBodyPartHeader->numModels )
  470. {
  471. WriteObjects( pModelHeaderDest, pModelHeaderSrc );
  472. /** MODEL LODS **/
  473. unsigned int meshOffset = 0;
  474. SET_INDEX_POINTERS( pData, pModelHeader, lodOffset )
  475. DECLARE_OBJECT_POINTERS( pModelLODHeader, pData, OptimizedModel::ModelLODHeader_t )
  476. ITERATE_BLOCK( pModelLODHeader, pModelHeader->numLODs )
  477. {
  478. WriteObjects( pModelLODHeaderDest, pModelLODHeaderSrc );
  479. /** MESHES **/
  480. unsigned int prevOffset = meshOffset;
  481. meshOffset = SrcNative( &pModelLODHeader->meshOffset );
  482. if ( prevOffset - sizeof(OptimizedModel::ModelLODHeader_t) == meshOffset )
  483. {
  484. // This LOD shares data with the previous LOD - don't reswap.
  485. continue;
  486. }
  487. SET_INDEX_POINTERS( pData, pModelLODHeader, meshOffset )
  488. DECLARE_OBJECT_POINTERS( pMeshHeader, pData, OptimizedModel::MeshHeader_t )
  489. ITERATE_BLOCK( pMeshHeader, pModelLODHeader->numMeshes )
  490. {
  491. WriteObjects( pMeshHeaderDest, pMeshHeaderSrc );
  492. /** STRIP GROUPS **/
  493. SET_INDEX_POINTERS( pData, pMeshHeader, stripGroupHeaderOffset )
  494. DECLARE_OBJECT_POINTERS( pStripGroupHeader, pData, OptimizedModel::StripGroupHeader_t )
  495. ITERATE_BLOCK( pStripGroupHeader, pMeshHeader->numStripGroups )
  496. {
  497. WriteObjects( pStripGroupHeaderDest, pStripGroupHeaderSrc );
  498. /** STRIP VERTS **/
  499. SET_INDEX_POINTERS( pData, pStripGroupHeader, vertOffset )
  500. WriteObjects<OptimizedModel::Vertex_t>( pDataDest, pDataSrc, SrcNative( &pStripGroupHeader->numVerts ) );
  501. /** VERT INDICES **/
  502. SET_INDEX_POINTERS( pData, pStripGroupHeader, indexOffset )
  503. ByteswapVTX_Indices( pDataDest, pDataSrc, SrcNative( &pStripGroupHeader->numIndices ) );
  504. /** STRIPS **/
  505. SET_INDEX_POINTERS( pData, pStripGroupHeader, stripOffset )
  506. DECLARE_OBJECT_POINTERS( pStripHeader, pData, OptimizedModel::StripHeader_t )
  507. ITERATE_BLOCK( pStripHeader, pStripGroupHeader->numStrips )
  508. {
  509. WriteObjects( pStripHeaderDest, pStripHeaderSrc );
  510. /** BONE STATE CHANGES **/
  511. SET_INDEX_POINTERS( pData, pStripHeader, boneStateChangeOffset )
  512. WriteObjects<OptimizedModel::BoneStateChangeHeader_t>( pDataDest, pDataSrc, SrcNative( &pStripHeader->numBoneStateChanges ) );
  513. }
  514. }
  515. }
  516. }
  517. }
  518. }
  519. /** MATERIAL REPLACEMENT HEADERS **/
  520. SET_INDEX_POINTERS( pData, pVtxHeader, materialReplacementListOffset )
  521. DECLARE_OBJECT_POINTERS( pMatRepListHeader, pData, OptimizedModel::MaterialReplacementListHeader_t )
  522. ITERATE_BLOCK( pMatRepListHeader, pVtxHeader->numLODs )
  523. {
  524. WriteObjects( pMatRepListHeaderDest, pMatRepListHeaderSrc );
  525. /** MATERIAL REPLACEMENTS **/
  526. SET_INDEX_POINTERS( pData, pMatRepListHeader, replacementOffset )
  527. WriteObjects<OptimizedModel::MaterialReplacementHeader_t>( &pDataDest, &pDataSrc, SrcNative( &pMatRepListHeader->numReplacements ) );
  528. }
  529. int newFileSize = fileSize;
  530. if ( pCompressFunc )
  531. {
  532. void *pInput = (byte*)pDestBase + sizeof( OptimizedModel::FileHeader_t );
  533. int inputSize = fileSize - sizeof( OptimizedModel::FileHeader_t );
  534. void *pOutput;
  535. int outputSize;
  536. if ( pCompressFunc( pInput, inputSize, &pOutput, &outputSize ) )
  537. {
  538. // place the compressed data after the header
  539. V_memcpy( pInput, pOutput, outputSize );
  540. free( pOutput );
  541. newFileSize = sizeof( OptimizedModel::FileHeader_t ) + outputSize;
  542. }
  543. }
  544. return newFileSize;
  545. }
  546. //----------------------------------------------------------------------
  547. // Swap RLE animation data (found inside .mdl and .ani)
  548. //----------------------------------------------------------------------
  549. void ByteswapRLEAnimData( mstudioanimdesc_t *pAnimDesc, int section, byte *&pDataSrc, byte *&pDataDest )
  550. {
  551. /** ANIMATIONS **/
  552. DECLARE_OBJECT_POINTERS( pAnimation, pData, mstudio_rle_anim_t )
  553. WriteObjects( pAnimationDest, pAnimationSrc );
  554. if ( pAnimation->bone == 255 )
  555. {
  556. // No animation data
  557. pAnimation = 0;
  558. }
  559. while( pAnimation )
  560. {
  561. if ( pAnimation->flags & ( STUDIO_ANIM_RAWROT | STUDIO_ANIM_RAWPOS | STUDIO_ANIM_RAWROT2 ) )
  562. {
  563. if ( pAnimation->flags & STUDIO_ANIM_RAWROT )
  564. {
  565. int offset = (byte*)pAnimation->pQuat48() - (byte*)pAnimation;
  566. pDataSrc = (byte*)pAnimationSrc + offset;
  567. pDataDest = (byte*)pAnimationDest + offset;
  568. // Write the quaternion (bit fields contained in 3 unsigned shorts)
  569. WriteBuffer<short>( &pDataDest, &pDataSrc, 3 );
  570. }
  571. if ( pAnimation->flags & STUDIO_ANIM_RAWROT2 )
  572. {
  573. int offset = (byte*)pAnimation->pQuat64() - (byte*)pAnimation;
  574. pDataSrc = (byte*)pAnimationSrc + offset;
  575. pDataDest = (byte*)pAnimationDest + offset;
  576. // Write the quaternion (bit fields contained in 1 64 bit int
  577. WriteBuffer<int64>( &pDataDest, &pDataSrc, 1 );
  578. }
  579. if ( pAnimation->flags & STUDIO_ANIM_RAWPOS )
  580. {
  581. int offset = (byte*)pAnimation->pPos() - (byte*)pAnimation;
  582. pDataSrc = (byte*)pAnimationSrc + offset;
  583. pDataDest = (byte*)pAnimationDest + offset;
  584. // Write the vector (3 float16)
  585. WriteBuffer<short>( &pDataDest, &pDataSrc, 3 );
  586. }
  587. }
  588. else
  589. {
  590. int offset = (byte*)pAnimation->pRotV() - (byte*)pAnimation;
  591. pDataSrc = (byte*)pAnimationSrc + offset;
  592. pDataDest = (byte*)pAnimationDest + offset;
  593. mstudioanim_valueptr_t *rotvptr = (mstudioanim_valueptr_t*)pDataSrc;
  594. WriteObjects<mstudioanim_valueptr_t>( &pDataDest, &pDataSrc );
  595. int animValueCt = 0;
  596. for ( int idx = 0; idx < 3; ++idx )
  597. {
  598. animValueCt += rotvptr->offset[idx] ? 1 : 0;
  599. }
  600. if ( pAnimation->flags & STUDIO_ANIM_ANIMPOS )
  601. {
  602. int offset = (byte*)pAnimation->pPosV() - (byte*)pAnimation;
  603. pDataSrc = (byte*)pAnimationSrc + offset;
  604. pDataDest = (byte*)pAnimationDest + offset;
  605. mstudioanim_valueptr_t *posvptr = (mstudioanim_valueptr_t*)pDataSrc;
  606. WriteObjects<mstudioanim_valueptr_t>( &pDataDest, &pDataSrc );
  607. for ( int idx = 0; idx < 3; ++idx )
  608. {
  609. animValueCt += posvptr->offset[idx] ? 1 : 0;
  610. }
  611. }
  612. // Write position and rotation animations
  613. // Note: destanimvalue_t is a union that can be either two bytes or a short.
  614. // This structure is used to compress animation data using RLE.
  615. // The first object of a chunk acts as the header, and uses the two bytes to
  616. // store how many objects follow, and how many frames are encoded by them.
  617. // The objects that follow use the short to store a value.
  618. // The total number of chunks has been determined by counting the number of valid (non-zero) offsets.
  619. for ( int animValue = 0; animValue < animValueCt; ++animValue )
  620. {
  621. int encodedFrames = 0;
  622. int totalFrames = SrcNative( &pAnimDesc->numframes );
  623. int sectionFrames = SrcNative( &pAnimDesc->sectionframes );
  624. if ( sectionFrames )
  625. {
  626. int iStartFrame = section * sectionFrames;
  627. int iEndFrame = (section + 1) * sectionFrames;
  628. iStartFrame = MIN( iStartFrame, totalFrames - 1 );
  629. iEndFrame = MIN( iEndFrame, totalFrames - 1 );
  630. totalFrames = iEndFrame - iStartFrame + 1;
  631. }
  632. while ( encodedFrames < totalFrames )
  633. {
  634. // Write the first animation value (struct of 2 bytes)
  635. mstudioanimvalue_t *pDestAnimvalue = (mstudioanimvalue_t*)( g_bNativeSrc ? pDataSrc : pDataDest );
  636. WriteBuffer<char>( &pDataDest, &pDataSrc, 2 );
  637. // Write the remaining animation values from this group (shorts)
  638. WriteBuffer<short>( &pDataDest, &pDataSrc, pDestAnimvalue->num.valid );
  639. encodedFrames += pDestAnimvalue->num.total;
  640. }
  641. }
  642. }
  643. if ( pAnimation->nextoffset )
  644. {
  645. // Set pointers to the next animation
  646. pAnimationSrc = (mstudio_rle_anim_t*)( (byte*)pAnimationSrc + SrcNative( &pAnimation->nextoffset ) );
  647. pAnimationDest = (mstudio_rle_anim_t*)( (byte*)pAnimationDest + SrcNative( &pAnimation->nextoffset ) );
  648. pAnimation = pAnimationSrc;
  649. // Swap the next animation
  650. WriteObjects( pAnimationDest, pAnimationSrc );
  651. }
  652. else
  653. {
  654. pAnimation = 0;
  655. pDataSrc += sizeof( mstudio_rle_anim_t );
  656. pDataDest += sizeof( mstudio_rle_anim_t );
  657. }
  658. }
  659. ALIGN4( pDataSrc );
  660. ALIGN4( pDataDest );
  661. }
  662. //----------------------------------------------------------------------
  663. // Swap Frame Animation data (found inside .mdl and .ani)
  664. //----------------------------------------------------------------------
  665. void ByteswapFrameAnimData( studiohdr_t *&pHdrSrc, mstudioanimdesc_t *pAnimDesc, int section, byte *&pDataSrc, byte *&pDataDest )
  666. {
  667. DECLARE_OBJECT_POINTERS( pFrame, pData, mstudio_frame_anim_t );
  668. /** FRAME ANIMATION BLOCK **/
  669. WriteObjects<mstudio_frame_anim_t>( &pDataDest, &pDataSrc );
  670. /** FLAGS **/
  671. byte *pBoneFlags = pDataSrc;
  672. WriteBuffer<byte>( &pDataDest, &pDataSrc, pHdrSrc->numbones );
  673. /** CONSTANTS **/
  674. SET_INDEX_POINTERS( pData, pFrame, constantsoffset );
  675. // printf("%s:\n", pAnimDesc->pszName() );
  676. for (int j = 0; j < pHdrSrc->numbones; j++)
  677. {
  678. if (pBoneFlags[j] & STUDIO_FRAME_CONST_ROT )
  679. {
  680. // Quaternion q = *(Quaternion48 *)(pDataSrc);
  681. // printf(" %7.4f %7.4f %7.4f %7.4f\n", q.x, q.y, q.z, q.w );
  682. // Write the quaternion (bit fields contained in 3 unsigned shorts)
  683. WriteBuffer<short>( &pDataDest, &pDataSrc, 3 );
  684. }
  685. else if (pBoneFlags[j] & STUDIO_FRAME_CONST_ROT2 )
  686. {
  687. // Quaternion q = *(Quaternion48S *)(pDataSrc);
  688. // printf(" %7.4f %7.4f %7.4f %7.4f : ", q.x, q.y, q.z, q.w );
  689. // Quaternion48S q2 = *(Quaternion48S *)(pDataSrc);
  690. // printf(" %5d %5d %5d %1d %1d\n", q2.a, q2.b, q2.c, q2.dneg, q2.offsetH * 2 + q2.offsetL );
  691. // Write the quaternion (bit fields contained in 3 unsigned shorts)
  692. WriteBuffer<short>( &pDataDest, &pDataSrc, 3 );
  693. }
  694. if (pBoneFlags[j] & STUDIO_FRAME_CONST_POS )
  695. {
  696. // Write the vector (3 float16)
  697. WriteBuffer<short>( &pDataDest, &pDataSrc, 3 );
  698. }
  699. else if (pBoneFlags[j] & STUDIO_FRAME_CONST_POS2 )
  700. {
  701. // Write the vector (3 float)
  702. WriteBuffer<float>( &pDataDest, &pDataSrc, 3 );
  703. }
  704. }
  705. /** FRAME ANIMATIONS **/
  706. SET_INDEX_POINTERS( pData, pFrame, frameoffset );
  707. int numFrames = pAnimDesc->numframes;
  708. if ( pAnimDesc->sectionframes )
  709. {
  710. int iStartFrame = MIN( section * pAnimDesc->sectionframes, pAnimDesc->numframes - 1 );
  711. int iEndFrame = MIN( (section + 1) * pAnimDesc->sectionframes, pAnimDesc->numframes - 1 );
  712. numFrames = iEndFrame - iStartFrame + 1;
  713. }
  714. for (int iFrame = 0; iFrame < numFrames; iFrame++)
  715. {
  716. for (int j = 0; j < pHdrSrc->numbones; j++)
  717. {
  718. if (pBoneFlags[j] & STUDIO_FRAME_ANIM_ROT )
  719. {
  720. // Quaternion q = *(Quaternion48 *)(pDataSrc);
  721. // printf(" %7.4f %7.4f %7.4f %7.4f\n", q.x, q.y, q.z, q.w );
  722. // Write the quaternion (bit fields contained in 3 unsigned shorts)
  723. WriteBuffer<short>( &pDataDest, &pDataSrc, 3 );
  724. }
  725. else if (pBoneFlags[j] & STUDIO_FRAME_ANIM_ROT2 )
  726. {
  727. // Quaternion q = *(Quaternion48S *)(pDataSrc);
  728. // printf(" %7.4f %7.4f %7.4f %7.4f\n", q.x, q.y, q.z, q.w );
  729. // Write the quaternion (bit fields contained in 1 int64)
  730. WriteBuffer<int64>( &pDataDest, &pDataSrc, 1 );
  731. }
  732. if (pBoneFlags[j] & STUDIO_FRAME_ANIM_POS )
  733. {
  734. // Write the vector (3 float16)
  735. WriteBuffer<short>( &pDataDest, &pDataSrc, 3 );
  736. }
  737. else if (pBoneFlags[j] & STUDIO_FRAME_ANIM_POS2 )
  738. {
  739. // printf("%.1f %.1f %.1f\n", ((float *)pDataSrc)[0], ((float *)pDataSrc)[1], ((float *)pDataSrc)[2] );
  740. // Write the vector (3 float)
  741. WriteBuffer<float>( &pDataDest, &pDataSrc, 3 );
  742. }
  743. }
  744. }
  745. ALIGN4( pDataSrc );
  746. ALIGN4( pDataDest );
  747. }
  748. //----------------------------------------------------------------------
  749. // Swap IKRules (found inside .mdl and .ani)
  750. //----------------------------------------------------------------------
  751. int ByteswapIKRules( studiohdr_t *&pHdrSrc, int numikrules, int numFrames, byte *&pDataSrc, byte *&pDataDest, const int fileSize )
  752. {
  753. DECLARE_OBJECT_POINTERS( pIKRule, pData, mstudioikrule_t )
  754. ITERATE_BLOCK( pIKRule, numikrules )
  755. {
  756. WriteObjects<mstudioikrule_t>( pIKRuleDest, pIKRuleSrc );
  757. /** IK ERROR KEYS **/
  758. // Calculate the number of ikerrors by converting the ikerror start and end float values to
  759. // frame numbers. (See the generation of these values in simplify.cpp: ProcessIKRules()).
  760. float start = floorf( SrcNative( &pIKRule->start ) * (numFrames - 1) + 0.5f );
  761. float end = floorf( SrcNative( &pIKRule->end ) * (numFrames - 1) + 0.5f );
  762. int totalerror = (int)( end - start + 1 );
  763. if ( end >= numFrames )
  764. totalerror += 2;
  765. // Uncompressed - only found in some older models (shipped hl2)
  766. if ( pIKRule->ikerrorindex )
  767. {
  768. SET_INDEX_POINTERS_VALIDATE( pData, pIKRule, ikerrorindex )
  769. WriteObjects<mstudioikerror_t>( pDataDest, pDataSrc, totalerror );
  770. }
  771. // Compressed - all models since hl2
  772. if ( pIKRule->compressedikerrorindex )
  773. {
  774. SET_INDEX_POINTERS_VALIDATE( pData, pIKRule, compressedikerrorindex )
  775. WriteObjects<mstudiocompressedikerror_t>( pDataDest, pDataSrc );
  776. mstudiocompressedikerror_t *pCompressed = (mstudiocompressedikerror_t *)pDataSrc;
  777. // Write the animvalues.
  778. for ( int idx = 0; idx < 6; ++idx )
  779. {
  780. if ( pCompressed->offset[idx] )
  781. {
  782. byte *pAnimvalueSrc = pDataSrc + SrcNative( &pCompressed->offset[idx] );
  783. byte *pAnimvalueDest = pDataDest + SrcNative( &pCompressed->offset[idx] );
  784. int numerror = 0;
  785. while ( numerror < totalerror )
  786. {
  787. // Write the first animation value (struct of 2 bytes)
  788. mstudioanimvalue_t *pDestAnimvalue = (mstudioanimvalue_t*)( g_bNativeSrc ? pAnimvalueSrc : pAnimvalueDest );
  789. WriteBuffer<char>( &pAnimvalueDest, &pAnimvalueSrc, 2 );
  790. // Write the remaining animation values from this group (shorts)
  791. WriteBuffer<short>( &pAnimvalueDest, &pAnimvalueSrc, pDestAnimvalue->num.valid );
  792. numerror += pDestAnimvalue->num.total;
  793. }
  794. }
  795. }
  796. if ( pIKRule->szattachmentindex )
  797. {
  798. SET_INDEX_POINTERS( pData, pIKRule, szattachmentindex )
  799. int size = strlen( (char*)pDataSrc ) + 1;
  800. WriteBuffer<char>( pDataDest, pDataSrc, size );
  801. }
  802. }
  803. }
  804. // successful swap
  805. return fileSize;
  806. }
  807. //----------------------------------------------------------------------
  808. // Swap IKErrors (found inside .mdl and .ani)
  809. //----------------------------------------------------------------------
  810. int ByteswapIKErrors( byte *&pDataSrc, byte *&pDataDest, int numlocalhierarchy, int numFrames, int fileSize )
  811. {
  812. DECLARE_OBJECT_POINTERS( pLocalHierarchy, pData, mstudiolocalhierarchy_t )
  813. // NOTE: The ITERATE_BLOCK macro assumes non-native endian data as input,
  814. // but in this one case we know the function parameters are already native.
  815. // So pre-swap numlocalhierarchy here to non-native so ITERATE_BLOCK gets the input data in the expected format.
  816. int numlocalhierarchy_nonnative = SrcNative( &numlocalhierarchy );
  817. ITERATE_BLOCK( pLocalHierarchy, numlocalhierarchy_nonnative )
  818. {
  819. WriteObjects<mstudiolocalhierarchy_t>( pLocalHierarchyDest, pLocalHierarchySrc, numlocalhierarchy );
  820. /** COMPRESSED IK ERRORS **/
  821. if ( pLocalHierarchy->localanimindex != 0 )
  822. {
  823. // Calculate the number of ikerrors by converting the ikerror start and end float values to
  824. // frame numbers. (See the generation of these values in simplify.cpp: ProcessIKRules()).
  825. float start = floorf( SrcNative( &pLocalHierarchy->start ) * (numFrames - 1) + 0.5f );
  826. float end = floorf( SrcNative( &pLocalHierarchy->end ) * (numFrames - 1) + 0.5f );
  827. int totalerror = (int)( end - start + 1 );
  828. if ( end >= numFrames )
  829. totalerror += 2;
  830. SET_INDEX_POINTERS( pData, pLocalHierarchy, localanimindex )
  831. WriteObjects<mstudiocompressedikerror_t>( pDataDest, pDataSrc );
  832. mstudiocompressedikerror_t *pCompressed = (mstudiocompressedikerror_t *)pDataSrc;
  833. // Write the animvalues.
  834. for ( int idx = 0; idx < 6; ++idx )
  835. {
  836. if ( pCompressed->offset[idx] )
  837. {
  838. byte *pAnimvalueSrc = pDataSrc + SrcNative( &pCompressed->offset[idx] );
  839. byte *pAnimvalueDest = pDataDest + SrcNative( &pCompressed->offset[idx] );
  840. int numerror = 0;
  841. while ( numerror < totalerror )
  842. {
  843. // Write the first animation value (struct of 2 bytes)
  844. mstudioanimvalue_t *pDestAnimvalue = (mstudioanimvalue_t*)( g_bNativeSrc ? pAnimvalueSrc : pAnimvalueDest );
  845. WriteBuffer<char>( &pAnimvalueDest, &pAnimvalueSrc, 2 );
  846. // Write the remaining animation values from this group (shorts)
  847. WriteBuffer<short>( &pAnimvalueDest, &pAnimvalueSrc, pDestAnimvalue->num.valid );
  848. numerror += pDestAnimvalue->num.total;
  849. }
  850. }
  851. }
  852. }
  853. } // Local Hierarchy block
  854. // successful swap
  855. return fileSize;
  856. }
  857. //----------------------------------------------------------------------
  858. // Swap an .ani file
  859. //----------------------------------------------------------------------
  860. int ByteswapANI( studiohdr_t* pHdr, void *pDestBase, int destBaseSize, const void *pSrcBase, const int fileSize, CompressFunc_t pCompressFunc )
  861. {
  862. // Note, pHdr came from a native .mdl -
  863. // so the header, animdescs and animblocks are already in native format.
  864. Assert( pHdr );
  865. if ( !pHdr )
  866. return false;
  867. Q_memset( pDestBase, 0, fileSize );
  868. // swap file header
  869. {
  870. byte *pHeaderSrc = (byte *)pSrcBase;
  871. byte *pHeaderDest = (byte *)pDestBase;
  872. DECLARE_OBJECT_POINTERS( pAniHeader, pHeader, studiohdr_t )
  873. WriteObjects( pAniHeaderDest, pAniHeaderSrc );
  874. }
  875. studiohdr_t *pHdrSrc = pHdr;
  876. // The animdesc_t header is always contained in the mdl file, but its data may be in
  877. // the mdl or the ani. When the data is contained in the mdl, the animdesc index fields
  878. // represent offsets from the location of the animdesc header. When the data is in the ani,
  879. // the index fields contain offsets from the start of the animblock in which the animdesc data is contained.
  880. mstudioanimdesc_t *pAnimDesc = pHdr->pLocalAnimdesc( 0 );
  881. for ( int i = 0; i < pHdr->numlocalanim; ++i, ++pAnimDesc )
  882. {
  883. // printf("anim %d : %d : %d\n", i, pAnimDesc->animblock, pAnimDesc->sectionframes );
  884. if ( pAnimDesc->animblock == -1)
  885. {
  886. // out of date model format
  887. continue;
  888. }
  889. if ( pAnimDesc->animblock == 0 && pAnimDesc->sectionframes == 0)
  890. {
  891. // already saved out
  892. continue;
  893. }
  894. if ( pAnimDesc->sectionframes == 0 )
  895. {
  896. mstudioanimblock_t *pAnimBlock = pHdr->pAnimBlock( pAnimDesc->animblock );
  897. // printf("block %d : start %d + %d\n", pAnimDesc->animblock, pAnimBlock->datastart, pAnimDesc->animindex );
  898. // Base address of the animblock
  899. byte *pBlockBaseSrc = (byte*)pSrcBase + pAnimBlock->datastart;
  900. byte *pBlockBaseDest = (byte*)pDestBase + pAnimBlock->datastart;
  901. // Base address of the animation in the animblock
  902. byte *pDataSrc = pBlockBaseSrc + pAnimDesc->animindex;
  903. byte *pDataDest = pBlockBaseDest + pAnimDesc->animindex;
  904. VALIDATE_ALIGNMENT( pDataSrc )
  905. if ( pAnimDesc->flags & STUDIO_FRAMEANIM )
  906. {
  907. ByteswapFrameAnimData( pHdrSrc, pAnimDesc, 0, pDataSrc, pDataDest );
  908. }
  909. else
  910. {
  911. ByteswapRLEAnimData( pAnimDesc, 0, pDataSrc, pDataDest );
  912. }
  913. }
  914. else
  915. {
  916. int numsections = pAnimDesc->numframes / pAnimDesc->sectionframes + 2;
  917. for ( int i = 0; i < numsections; ++i )
  918. {
  919. int block = pAnimDesc->pSection( i )->animblock;
  920. int index = pAnimDesc->pSection( i )->animindex;
  921. if ( block != 0 )
  922. {
  923. // printf("%s %d %d\n", pAnimDesc->pszName(), block, index );
  924. mstudioanimblock_t *pAnimBlock = pHdr->pAnimBlock( block );
  925. // Base address of the animblock
  926. byte *pBlockBaseSrc = (byte*)pSrcBase + pAnimBlock->datastart;
  927. byte *pBlockBaseDest = (byte*)pDestBase + pAnimBlock->datastart;
  928. VALIDATE_ALIGNMENT( pBlockBaseSrc )
  929. // Base address of the animation in the animblock
  930. byte *pDataSrc = pBlockBaseSrc + index;
  931. byte *pDataDest = pBlockBaseDest + index;
  932. if ( pAnimDesc->flags & STUDIO_FRAMEANIM )
  933. {
  934. ByteswapFrameAnimData( pHdrSrc, pAnimDesc, i, pDataSrc, pDataDest );
  935. }
  936. else
  937. {
  938. ByteswapRLEAnimData( pAnimDesc, i, pDataSrc, pDataDest );
  939. }
  940. }
  941. }
  942. }
  943. if ( pAnimDesc->animblock == 0)
  944. {
  945. // already saved out
  946. continue;
  947. }
  948. mstudioanimblock_t *pAnimBlock = pHdr->pAnimBlock( pAnimDesc->animblock );
  949. // Base address of the animblock
  950. byte *pBlockBaseSrc = (byte*)pSrcBase + pAnimBlock->datastart;
  951. byte *pBlockBaseDest = (byte*)pDestBase + pAnimBlock->datastart;
  952. VALIDATE_ALIGNMENT( pBlockBaseSrc )
  953. // Base address of the animation in the animblock
  954. byte *pDataSrc = pBlockBaseSrc + pAnimDesc->animindex;
  955. byte *pDataDest = pBlockBaseDest + pAnimDesc->animindex;
  956. VALIDATE_ALIGNMENT( pDataSrc )
  957. /** IK RULES **/
  958. if ( pAnimDesc->animblockikruleindex )
  959. {
  960. pDataSrc = (byte*)pBlockBaseSrc + pAnimDesc->animblockikruleindex;
  961. pDataDest = (byte*)pBlockBaseDest + pAnimDesc->animblockikruleindex;
  962. VALIDATE_ALIGNMENT( pDataSrc )
  963. int numikrules = SrcNative( &pAnimDesc->numikrules );
  964. if ( ERROR_MISALIGNED_DATA == ByteswapIKRules( pHdrSrc, pAnimDesc->numikrules, pAnimDesc->numframes, pDataSrc, pDataDest, fileSize ) )
  965. return ERROR_MISALIGNED_DATA;
  966. }
  967. /** LOCAL HIERARCHY **/
  968. if ( pAnimDesc->localhierarchyindex )
  969. {
  970. pDataSrc = (byte*)pBlockBaseSrc + pAnimDesc->localhierarchyindex;
  971. pDataDest = (byte*)pBlockBaseDest + pAnimDesc->localhierarchyindex;
  972. if ( ERROR_MISALIGNED_DATA == ByteswapIKErrors( pDataSrc, pDataDest, pAnimDesc->numlocalhierarchy, pAnimDesc->numframes, fileSize ) )
  973. return ERROR_MISALIGNED_DATA;
  974. }
  975. }
  976. // compressed file size could be smaller or larger (due to streaming alignment of blocks)
  977. int compressedFileSize = fileSize;
  978. // optionally compress the file
  979. if ( pCompressFunc && pHdr->numanimblocks >= 2 )
  980. {
  981. // assemble a new anim of compressed anim blocks
  982. // start with original size, with room for streaming alignment padding
  983. compressedFileSize += (pHdr->numanimblocks + 1) * 2048;
  984. byte *pNewDestBase = (byte *)malloc( compressedFileSize );
  985. Q_memset( pNewDestBase, 0, compressedFileSize );
  986. byte *pNewDest = pNewDestBase;
  987. // get the header payload as is
  988. // assuming the header is up to the first anim block
  989. mstudioanimblock_t *pAnimBlock = pHdr->pAnimBlock( 1 );
  990. V_memcpy( pNewDest, pDestBase, pAnimBlock->datastart );
  991. pNewDest += pAnimBlock->datastart;
  992. int padding = AlignValue( (uintp)pNewDest - (uintp)pNewDestBase, 2048 );
  993. padding -= (uintp)pNewDest - (uintp)pNewDestBase;
  994. pNewDest += padding;
  995. // iterate and compress anim blocks
  996. // compression may fail, input block is used, but is streaming aligned
  997. for ( int i = 1; i < pHdr->numanimblocks; ++i )
  998. {
  999. pAnimBlock = pHdr->pAnimBlock( i );
  1000. void *pInput = (byte *)pDestBase + pAnimBlock->datastart;
  1001. int inputSize = pAnimBlock->dataend - pAnimBlock->datastart;
  1002. pAnimBlock->datastart = (uintp)pNewDest - (uintp)pNewDestBase;
  1003. void *pOutput;
  1004. int outputSize;
  1005. if ( pCompressFunc( pInput, inputSize, &pOutput, &outputSize ) )
  1006. {
  1007. V_memcpy( pNewDest, pOutput, outputSize );
  1008. pNewDest += outputSize;
  1009. free( pOutput );
  1010. }
  1011. else
  1012. {
  1013. // as is
  1014. V_memcpy( pNewDest, pInput, inputSize );
  1015. pNewDest += inputSize;
  1016. }
  1017. padding = AlignValue( (uintp)pNewDest - (uintp)pNewDestBase, 2048 );
  1018. padding -= (uintp)pNewDest - (uintp)pNewDestBase;
  1019. pNewDest += padding;
  1020. pAnimBlock->dataend = (uintp)pNewDest - (uintp)pNewDestBase;
  1021. }
  1022. compressedFileSize = pNewDest - pNewDestBase;
  1023. if ( compressedFileSize > destBaseSize )
  1024. {
  1025. // provided destination is not large enough
  1026. free( pNewDestBase );
  1027. return ERROR_MISALIGNED_DATA;
  1028. }
  1029. V_memcpy( pDestBase, pNewDestBase, compressedFileSize );
  1030. free( pNewDestBase );
  1031. }
  1032. // printf("returning %d\n", fixedFileSize );
  1033. return compressedFileSize;
  1034. }
  1035. //----------------------------------------------------------------------
  1036. // Write a .mdl file in big-endian format
  1037. //----------------------------------------------------------------------
  1038. int ByteswapMDL( void *pDestBase, int destBaseSize, const void *pSrcBase, const int fileSize, CompressFunc_t pCompressFunc )
  1039. {
  1040. Q_memset( pDestBase, 0, fileSize );
  1041. byte *pDataSrc = (byte*)pSrcBase;
  1042. byte *pDataDest = (byte*)pDestBase;
  1043. /** FILE HEADER **/
  1044. DECLARE_OBJECT_POINTERS( pHdr, pData, studiohdr_t )
  1045. WriteObjects( pHdrDest, pHdrSrc );
  1046. /** BONES **/
  1047. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, boneindex )
  1048. DECLARE_OBJECT_POINTERS( pStudioBone, pData, mstudiobone_t )
  1049. ITERATE_BLOCK( pStudioBone, pHdr->numbones )
  1050. {
  1051. WriteObjects( pStudioBoneDest, pStudioBoneSrc );
  1052. if ( pStudioBone->procindex )
  1053. {
  1054. SET_INDEX_POINTERS_VALIDATE( pData, pStudioBone, procindex )
  1055. unsigned int index = SrcNative( &pStudioBone->proctype );
  1056. switch( index )
  1057. {
  1058. case STUDIO_PROC_AXISINTERP:
  1059. {
  1060. /** AXIS-INTERP BONES **/
  1061. DECLARE_OBJECT_POINTERS( pAxisInterpBone, pData, mstudioaxisinterpbone_t )
  1062. WriteObjects( pAxisInterpBoneDest, pAxisInterpBoneSrc );
  1063. break;
  1064. }
  1065. case STUDIO_PROC_QUATINTERP:
  1066. {
  1067. /** QUAT-INTERP BONES **/
  1068. DECLARE_OBJECT_POINTERS( pQuatInterpBone, pData, mstudioquatinterpbone_t )
  1069. WriteObjects( pQuatInterpBoneDest, pQuatInterpBoneSrc );
  1070. /** QUAT-INTERP TRIGGERS **/
  1071. SET_INDEX_POINTERS_VALIDATE( pData, pQuatInterpBone, triggerindex )
  1072. WriteObjects<mstudioquatinterpinfo_t>( pDataDest, pDataSrc, SrcNative( &pQuatInterpBone->numtriggers ) );
  1073. break;
  1074. }
  1075. case STUDIO_PROC_JIGGLE:
  1076. {
  1077. /** JIGGLE BONES **/
  1078. DECLARE_OBJECT_POINTERS( pJiggleBone, pData, mstudiojigglebone_t )
  1079. WriteObjects( pJiggleBoneDest, pJiggleBoneSrc );
  1080. break;
  1081. }
  1082. case STUDIO_PROC_AIMATBONE:
  1083. case STUDIO_PROC_AIMATATTACH:
  1084. {
  1085. /** AIM AT BONES **/
  1086. DECLARE_OBJECT_POINTERS( pAimAtBone, pData, mstudioaimatbone_t )
  1087. WriteObjects( pAimAtBoneDest, pAimAtBoneSrc );
  1088. break;
  1089. }
  1090. case STUDIO_PROC_TWIST_MASTER:
  1091. {
  1092. /** TWIST BONES **/
  1093. DECLARE_OBJECT_POINTERS( pTwistBone, pData, mstudiotwistbone_t )
  1094. WriteObjects( pTwistBoneDest, pTwistBoneSrc );
  1095. /** TWIST BONE TARGETS **/
  1096. SET_INDEX_POINTERS_VALIDATE( pData, pTwistBone, m_nTargetIndex );
  1097. WriteObjects< mstudiotwistbonetarget_t >( pDataDest, pDataSrc, SrcNative( &pTwistBone->m_nTargetCount ) );
  1098. break;
  1099. }
  1100. case STUDIO_PROC_POINT_CONSTRAINT:
  1101. {
  1102. /** POINT CONSTRAINT BONES **/
  1103. DECLARE_OBJECT_POINTERS( pConstraint, pData, mstudiopointconstraint_t )
  1104. WriteObjects( pConstraintDest, pConstraintSrc );
  1105. /** TARGETS **/
  1106. SET_INDEX_POINTERS_VALIDATE( pData, pConstraint, m_nTargetIndex );
  1107. WriteObjects< mstudioconstrainttarget_t >( pDataDest, pDataSrc, SrcNative( &pConstraint->m_nTargetCount ) );
  1108. break;
  1109. }
  1110. case STUDIO_PROC_ORIENT_CONSTRAINT:
  1111. {
  1112. /** ORIENT CONSTRAINT BONES **/
  1113. DECLARE_OBJECT_POINTERS( pConstraint, pData, mstudioorientconstraint_t )
  1114. WriteObjects( pConstraintDest, pConstraintSrc );
  1115. /** TARGETS **/
  1116. SET_INDEX_POINTERS_VALIDATE( pData, pConstraint, m_nTargetIndex );
  1117. WriteObjects< mstudioconstrainttarget_t >( pDataDest, pDataSrc, SrcNative( &pConstraint->m_nTargetCount ) );
  1118. break;
  1119. }
  1120. case STUDIO_PROC_AIM_CONSTRAINT:
  1121. {
  1122. /** AIM CONSTRAINT BONES **/
  1123. DECLARE_OBJECT_POINTERS( pConstraint, pData, mstudioaimconstraint_t )
  1124. WriteObjects( pConstraintDest, pConstraintSrc );
  1125. /** TARGETS **/
  1126. SET_INDEX_POINTERS_VALIDATE( pData, pConstraint, m_nTargetIndex );
  1127. WriteObjects< mstudioconstrainttarget_t >( pDataDest, pDataSrc, SrcNative( &pConstraint->m_nTargetCount ) );
  1128. break;
  1129. }
  1130. case STUDIO_PROC_IK_CONSTRAINT:
  1131. {
  1132. /** IK CONSTRAINT BONES **/
  1133. DECLARE_OBJECT_POINTERS( pConstraint, pData, mstudioikconstraint_t )
  1134. WriteObjects( pConstraintDest, pConstraintSrc );
  1135. /** TARGETS **/
  1136. /*
  1137. SET_INDEX_POINTERS_VALIDATE( pData, pConstraint, m_nTargetIndex );
  1138. WriteObjects< mstudioconstrainttarget_t >( pDataDest, pDataSrc, SrcNative( &pConstraint->m_nTargetCount ) );
  1139. */
  1140. break;
  1141. }
  1142. case STUDIO_PROC_PARENT_CONSTRAINT:
  1143. {
  1144. /** PARENT CONSTRAINT BONES **/
  1145. DECLARE_OBJECT_POINTERS( pConstraint, pData, mstudioparentconstraint_t )
  1146. WriteObjects( pConstraintDest, pConstraintSrc );
  1147. /** TARGETS **/
  1148. SET_INDEX_POINTERS_VALIDATE( pData, pConstraint, m_nTargetIndex );
  1149. WriteObjects< mstudioconstrainttarget_t >( pDataDest, pDataSrc, SrcNative( &pConstraint->m_nTargetCount ) );
  1150. break;
  1151. }
  1152. default:
  1153. Assert( 0 );
  1154. Warning( "Unknown bone type %d found!\n", index );
  1155. }
  1156. }
  1157. }
  1158. /** BONE CONTROLLERS **/
  1159. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, bonecontrollerindex )
  1160. WriteObjects<mstudiobonecontroller_t>( pDataDest, pDataSrc, SrcNative( &pHdr->numbonecontrollers ) );
  1161. /** ATTACHMENTS **/
  1162. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, localattachmentindex )
  1163. WriteObjects<mstudioattachment_t>( pDataDest, pDataSrc, SrcNative( &pHdr->numlocalattachments ) );
  1164. /** HITBOX SETS **/
  1165. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, hitboxsetindex )
  1166. DECLARE_OBJECT_POINTERS( pHitboxSet, pData, mstudiohitboxset_t )
  1167. ITERATE_BLOCK( pHitboxSet, pHdr->numhitboxsets )
  1168. {
  1169. WriteObjects( pHitboxSetDest, pHitboxSetSrc );
  1170. /** HITBOXES **/
  1171. SET_INDEX_POINTERS_VALIDATE( pData, pHitboxSet, hitboxindex )
  1172. WriteObjects<mstudiobbox_t>( pDataDest, pDataSrc, SrcNative( &pHitboxSet->numhitboxes ) );
  1173. }
  1174. /** BONE TABLE **/
  1175. SET_INDEX_POINTERS( pData, pHdr, bonetablebynameindex )
  1176. WriteBuffer<char>( pDataDest, pDataSrc, SrcNative( &pHdr->numbones ) );
  1177. /** ANIMATION DESCRIPTIONS **/
  1178. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, localanimindex )
  1179. DECLARE_OBJECT_POINTERS( pAnimDesc, pData, mstudioanimdesc_t )
  1180. ITERATE_BLOCK( pAnimDesc, pHdr->numlocalanim )
  1181. {
  1182. WriteObjects( pAnimDescDest, pAnimDescSrc );
  1183. if ( pAnimDesc->animblock == -1 )
  1184. {
  1185. // out of date model format
  1186. continue;
  1187. }
  1188. // section data can point to both internal and external blocks
  1189. int numsections = 0;
  1190. if ( pAnimDesc->sectionframes != 0 )
  1191. {
  1192. numsections = pAnimDesc->numframes / pAnimDesc->sectionframes + 2;
  1193. SET_INDEX_POINTERS( pData, pAnimDesc, sectionindex )
  1194. DECLARE_OBJECT_POINTERS( pSection, pData, mstudioanimsections_t )
  1195. WriteObjects( pSectionDest, pSectionSrc, numsections );
  1196. }
  1197. if ( pAnimDesc->animblock == 0 )
  1198. {
  1199. if ( pAnimDesc->animindex )
  1200. {
  1201. if ( numsections == 0 )
  1202. {
  1203. SET_INDEX_POINTERS( pData, pAnimDesc, animindex )
  1204. if ( pAnimDesc->flags & STUDIO_FRAMEANIM )
  1205. {
  1206. ByteswapFrameAnimData( pHdrSrc, pAnimDesc, 0, pDataSrc, pDataDest );
  1207. }
  1208. else
  1209. {
  1210. ByteswapRLEAnimData( pAnimDesc, 0, pDataSrc, pDataDest );
  1211. }
  1212. }
  1213. else
  1214. {
  1215. for ( int i = 0; i < numsections; ++i )
  1216. {
  1217. if ( pAnimDesc->pSection( i )->animblock == 0 )
  1218. {
  1219. int index = pAnimDesc->pSection( i )->animindex;
  1220. // Base address of the animation in the animblock
  1221. byte *pDataSrc = (byte *)pAnimDescSrc + index;
  1222. byte *pDataDest = (byte *)pAnimDescDest + index;
  1223. if ( pAnimDesc->flags & STUDIO_FRAMEANIM )
  1224. {
  1225. ByteswapFrameAnimData( pHdrSrc, pAnimDesc, i, pDataSrc, pDataDest );
  1226. }
  1227. else
  1228. {
  1229. ByteswapRLEAnimData( pAnimDesc, i, pDataSrc, pDataDest );
  1230. }
  1231. }
  1232. }
  1233. }
  1234. }
  1235. /** IK RULES **/
  1236. if ( pAnimDesc->ikruleindex )
  1237. {
  1238. SET_INDEX_POINTERS_VALIDATE( pData, pAnimDesc, ikruleindex )
  1239. // DECLARE_OBJECT_POINTERS( pIKRule, pData, mstudioikrule_t )
  1240. int numframes = SrcNative( &pAnimDesc->numframes );
  1241. if ( ERROR_MISALIGNED_DATA == ByteswapIKRules( pHdrSrc, pAnimDesc->numikrules, numframes, pDataSrc, pDataDest, fileSize ) )
  1242. return ERROR_MISALIGNED_DATA;
  1243. }
  1244. /** LOCAL HIERARCHY **/
  1245. if ( pAnimDesc->localhierarchyindex )
  1246. {
  1247. SET_INDEX_POINTERS( pData, pAnimDesc, localhierarchyindex )
  1248. if ( ERROR_MISALIGNED_DATA == ByteswapIKErrors( pDataSrc, pDataDest, SrcNative( &pAnimDesc->numlocalhierarchy ), SrcNative( &pAnimDesc->numframes ), fileSize ) )
  1249. return ERROR_MISALIGNED_DATA;
  1250. }
  1251. }
  1252. } // Animdesc block
  1253. /** MOVEMENTS **/
  1254. // Separate loop required by format of mstudioanimdesc_t data
  1255. SET_INDEX_POINTERS( pData, pHdr, localanimindex )
  1256. SET_OBJECT_POINTERS( pAnimDesc, pData, mstudioanimdesc_t )
  1257. ITERATE_BLOCK( pAnimDesc, pHdr->numlocalanim )
  1258. {
  1259. if ( pAnimDesc->nummovements )
  1260. {
  1261. SET_INDEX_POINTERS_VALIDATE( pData, pAnimDesc, movementindex )
  1262. WriteObjects<mstudiomovement_t>( pDataDest, pDataSrc, SrcNative( &pAnimDesc->nummovements ) );
  1263. }
  1264. }
  1265. /** ZERO FRAMES **/
  1266. SET_INDEX_POINTERS( pData, pHdr, localanimindex )
  1267. SET_OBJECT_POINTERS( pAnimDesc, pData, mstudioanimdesc_t )
  1268. ITERATE_BLOCK( pAnimDesc, pHdr->numlocalanim )
  1269. {
  1270. if ( pAnimDesc->pZeroFrameData( ) != NULL )
  1271. {
  1272. int offset = pAnimDesc->pZeroFrameData( ) - (byte *)pAnimDesc;
  1273. // Base address of the animation in the animblock
  1274. byte *pZeroFrameSrc = (byte *)pAnimDescSrc + offset;
  1275. byte *pZeroFrameDest = (byte *)pAnimDescDest + offset;
  1276. SET_INDEX_POINTERS( pData, pHdr, boneindex )
  1277. SET_OBJECT_POINTERS( pStudioBone, pData, mstudiobone_t )
  1278. ITERATE_BLOCK( pStudioBone, pHdr->numbones )
  1279. {
  1280. if ( pStudioBone->flags & BONE_HAS_SAVEFRAME_POS )
  1281. {
  1282. for ( int j = 0; j < pAnimDesc->zeroframecount; j++)
  1283. {
  1284. WriteBuffer<short>( &pZeroFrameDest, &pZeroFrameSrc, 3 );
  1285. }
  1286. }
  1287. if ( pStudioBone->flags & BONE_HAS_SAVEFRAME_ROT64 )
  1288. {
  1289. for ( int j = 0; j < pAnimDesc->zeroframecount; j++)
  1290. {
  1291. WriteBuffer<int64>( &pZeroFrameDest, &pZeroFrameSrc, 1 );
  1292. }
  1293. }
  1294. else if ( pStudioBone->flags & BONE_HAS_SAVEFRAME_ROT32 )
  1295. {
  1296. for ( int j = 0; j < pAnimDesc->zeroframecount; j++)
  1297. {
  1298. WriteBuffer<int32>( &pZeroFrameDest, &pZeroFrameSrc, 1 );
  1299. }
  1300. }
  1301. }
  1302. }
  1303. // write zero frame IK release rules
  1304. if ( pAnimDesc->pIKRuleZeroFrame( 0 ) )
  1305. {
  1306. int offset = (byte *)pAnimDesc->pIKRuleZeroFrame( 0 ) - (byte *)pAnimDesc;
  1307. // printf("%d : %d (%x %x)\n", offset, pAnimDesc->numikrules, pAnimDescSrc->ikrulezeroframeindex, pAnimDescDest->ikrulezeroframeindex );
  1308. // Base address of the animation in the animblock
  1309. byte *pIKRuleZeroFrameSrc = (byte *)pAnimDescSrc + offset;
  1310. byte *pIKRuleZeroFrameDest = (byte *)pAnimDescDest + offset;
  1311. for ( int j = 0; j < pAnimDesc->numikrules; j++)
  1312. {
  1313. WriteBuffer<short>( &pIKRuleZeroFrameDest, &pIKRuleZeroFrameSrc, 6 );
  1314. }
  1315. }
  1316. }
  1317. /** SEQUENCE INFO **/
  1318. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, localseqindex )
  1319. DECLARE_OBJECT_POINTERS( pSequence, pData, mstudioseqdesc_t )
  1320. ITERATE_BLOCK( pSequence, pHdr->numlocalseq )
  1321. {
  1322. WriteObjects( pSequenceDest, pSequenceSrc );
  1323. /** POSE KEYS **/
  1324. if ( pSequence->posekeyindex )
  1325. {
  1326. SET_INDEX_POINTERS_VALIDATE( pData, pSequence, posekeyindex )
  1327. WriteBuffer<float>( pDataDest, pDataSrc, SrcNative( &pSequence->groupsize[0] ) + SrcNative( &pSequence->groupsize[1] ) );
  1328. }
  1329. /** STUDIO EVENTS **/
  1330. SET_INDEX_POINTERS_VALIDATE( pData, pSequence, eventindex )
  1331. WriteObjects<mstudioevent_t>( pDataDest, pDataSrc, SrcNative( &pSequence->numevents ) );
  1332. /** AUTOLAYERS **/
  1333. SET_INDEX_POINTERS_VALIDATE( pData, pSequence, autolayerindex )
  1334. WriteObjects<mstudioautolayer_t>( pDataDest, pDataSrc, SrcNative( &pSequence->numautolayers ) );
  1335. /** BONE WEIGHTS **/
  1336. // Data may be shared across sequences
  1337. DECLARE_INDEX_POINTERS_VALIDATE( pWeight, pSequence, weightlistindex )
  1338. if ( pWeightSrc >= pDataSrc )
  1339. {
  1340. int numBoneWeights = ( SrcNative( &pSequence->iklockindex ) - SrcNative( &pSequence->weightlistindex ) ) / sizeof(float);
  1341. WriteBuffer<float>( pWeightDest, pWeightSrc, numBoneWeights );
  1342. }
  1343. /** IK LOCKS **/
  1344. SET_INDEX_POINTERS_VALIDATE( pData, pSequence, iklockindex )
  1345. WriteObjects<mstudioiklock_t>( pDataDest, pDataSrc, SrcNative( &pSequence->numiklocks ) );
  1346. /** ANIMATION INDICES **/
  1347. if ( pSequence->animindexindex )
  1348. {
  1349. SET_INDEX_POINTERS( pData, pSequence, animindexindex )
  1350. WriteBuffer<short>( pDataDest, pDataSrc, SrcNative( &pSequence->groupsize[0] ) * SrcNative( &pSequence->groupsize[1] ) );
  1351. }
  1352. /** KEYVALUES **/
  1353. SET_INDEX_POINTERS( pData, pSequence, keyvalueindex )
  1354. WriteBuffer<char>( pDataDest, pDataSrc, SrcNative( &pSequence->keyvaluesize ) );
  1355. /** ACTIVITY MODIFIERS **/
  1356. SET_INDEX_POINTERS_VALIDATE( pData, pSequence, activitymodifierindex )
  1357. WriteObjects<mstudioactivitymodifier_t>( pDataDest, pDataSrc, SrcNative( &pSequence->numactivitymodifiers ) );
  1358. }
  1359. /** TRANSITION GRAPH **/
  1360. int numLocalNodes = SrcNative( &pHdr->numlocalnodes );
  1361. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, localnodenameindex )
  1362. WriteBuffer<int>( pDataDest, pDataSrc, numLocalNodes );
  1363. /** LOCAL NODES **/
  1364. SET_INDEX_POINTERS( pData, pHdr, localnodeindex )
  1365. WriteBuffer<char>( pDataDest, pDataSrc, numLocalNodes * numLocalNodes );
  1366. /** BODYPART INFO **/
  1367. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, bodypartindex )
  1368. DECLARE_OBJECT_POINTERS( pBodypart, pData, mstudiobodyparts_t )
  1369. ITERATE_BLOCK( pBodypart, pHdr->numbodyparts )
  1370. {
  1371. WriteObjects( pBodypartDest, pBodypartSrc );
  1372. /** MODEL INFO **/
  1373. SET_INDEX_POINTERS_VALIDATE( pData, pBodypart, modelindex )
  1374. DECLARE_OBJECT_POINTERS( pModel, pData, mstudiomodel_t )
  1375. ITERATE_BLOCK( pModel, pBodypart->nummodels )
  1376. {
  1377. WriteObjects( pModelDest, pModelSrc );
  1378. /** MESHES **/
  1379. SET_INDEX_POINTERS_VALIDATE( pData, pModel, meshindex )
  1380. DECLARE_OBJECT_POINTERS( pMesh, pData, mstudiomesh_t )
  1381. ITERATE_BLOCK( pMesh, pModel->nummeshes )
  1382. {
  1383. WriteObjects( pMeshDest, pMeshSrc );
  1384. if ( !pMesh->numflexes )
  1385. continue;
  1386. /** FLEXES **/
  1387. SET_INDEX_POINTERS_VALIDATE( pData, pMesh, flexindex )
  1388. DECLARE_OBJECT_POINTERS( pFlex, pData, mstudioflex_t )
  1389. ITERATE_BLOCK( pFlex, pMesh->numflexes )
  1390. {
  1391. WriteObjects( pFlexDest, pFlexSrc );
  1392. /** VERT ANIMS **/
  1393. if ( SrcNative( &pFlex->vertanimtype ) == STUDIO_VERT_ANIM_WRINKLE )
  1394. {
  1395. SET_INDEX_POINTERS_VALIDATE( pData, pFlex, vertindex )
  1396. WriteObjects<mstudiovertanim_wrinkle_t>( pDataDest, pDataSrc, SrcNative( &pFlex->numverts ) );
  1397. }
  1398. else
  1399. {
  1400. SET_INDEX_POINTERS_VALIDATE( pData, pFlex, vertindex )
  1401. WriteObjects<mstudiovertanim_t>( pDataDest, pDataSrc, SrcNative( &pFlex->numverts ) );
  1402. }
  1403. }
  1404. }
  1405. /** EYEBALLS **/
  1406. SET_INDEX_POINTERS_VALIDATE( pData, pModel, eyeballindex )
  1407. WriteObjects<mstudioeyeball_t>( pDataDest, pDataSrc, SrcNative( &pModel->numeyeballs ) );
  1408. }
  1409. }
  1410. /** GLOBAL FLEX NAMES **/
  1411. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, flexdescindex )
  1412. WriteObjects<mstudioflexdesc_t>( pDataDest, pDataSrc, SrcNative( &pHdr->numflexdesc ) );
  1413. /** GLOBAL FLEX CONTROLLERS **/
  1414. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, flexcontrollerindex )
  1415. WriteObjects<mstudioflexcontroller_t>( pDataDest, pDataSrc, SrcNative( &pHdr->numflexcontrollers ) );
  1416. /** GLOBAL FLEX CONTROLLER REMAPS **/
  1417. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, flexcontrolleruiindex )
  1418. WriteObjects<mstudioflexcontrollerui_t>( pDataDest, pDataSrc, SrcNative( &pHdr->numflexcontrollerui ) );
  1419. // TODOKD: The remap indices after the flex controller remap headers need to be swapped as well?
  1420. /** FLEX RULES **/
  1421. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, flexruleindex )
  1422. DECLARE_OBJECT_POINTERS( pFlexRule, pData, mstudioflexrule_t )
  1423. ITERATE_BLOCK( pFlexRule, pHdr->numflexrules )
  1424. {
  1425. WriteObjects( pFlexRuleDest, pFlexRuleSrc );
  1426. /** FLEX OPS **/
  1427. SET_INDEX_POINTERS_VALIDATE( pData, pFlexRule, opindex )
  1428. WriteObjects<mstudioflexop_t>( pDataDest, pDataSrc, SrcNative( &pFlexRule->numops ) );
  1429. }
  1430. /** IK CHAINS **/
  1431. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, ikchainindex )
  1432. DECLARE_OBJECT_POINTERS( pIKChain, pData, mstudioikchain_t )
  1433. ITERATE_BLOCK( pIKChain, pHdr->numikchains )
  1434. {
  1435. WriteObjects( pIKChainDest, pIKChainSrc );
  1436. /** IK LINKS **/
  1437. SET_INDEX_POINTERS( pData, pIKChain, linkindex )
  1438. WriteObjects<mstudioiklink_t>( pDataDest, pDataSrc, SrcNative( &pIKChain->numlinks ) );
  1439. }
  1440. /** IK AUTOPLAY LOCKS **/
  1441. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, localikautoplaylockindex )
  1442. WriteObjects<mstudioiklock_t>( pDataDest, pDataSrc, SrcNative( &pHdr->numlocalikautoplaylocks ) );
  1443. /** MOUTH INFO **/
  1444. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, mouthindex )
  1445. WriteObjects<mstudiomouth_t>( pDataDest, pDataSrc, SrcNative( &pHdr->nummouths ) );
  1446. /** POSE PARAMATERS **/
  1447. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, localposeparamindex )
  1448. WriteObjects<mstudioposeparamdesc_t>( pDataDest, pDataSrc, SrcNative( &pHdr->numlocalposeparameters ) );
  1449. /** MODEL GROUPS **/
  1450. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, includemodelindex )
  1451. WriteObjects<mstudiomodelgroup_t>( pDataDest, pDataSrc, SrcNative( &pHdr->numincludemodels ) );
  1452. /** ANIMBLOCK GROUP INFO **/
  1453. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, animblockindex )
  1454. WriteObjects<mstudioanimblock_t>( pDataDest, pDataSrc, SrcNative( &pHdr->numanimblocks ) );
  1455. /** TEXTURE INFO **/
  1456. // While swapping, kill off unwanted textures by name
  1457. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, textureindex )
  1458. DECLARE_OBJECT_POINTERS( pTexture, pData, mstudiotexture_t )
  1459. int textureCt = SrcNative( &pHdr->numtextures );
  1460. int nameOffset = 0;
  1461. for ( int i = 0; i < SrcNative( &pHdr->numtextures ); ++i, ++pTexture, ++pTextureSrc )
  1462. {
  1463. WriteObjects<mstudiotexture_t>( pTextureDest, pTextureSrc );
  1464. int destnameindex = SrcNative( &pTexture->sznameindex ) + nameOffset;
  1465. pTextureDest->sznameindex = DestNative( &destnameindex );
  1466. char *pName = (char*)pTexture + SrcNative( &pTexture->sznameindex );
  1467. #if 0 // Undone: Killing textures here can cause crashes at runtime.
  1468. // Don't need pupil textures
  1469. if ( Q_stristr( pName, "pupil_" ) || !Q_stricmp( pName, "pupil" ) )
  1470. {
  1471. --textureCt;
  1472. nameOffset += sizeof(mstudiotexture_t);
  1473. }
  1474. else
  1475. #endif
  1476. {
  1477. ++pTextureDest;
  1478. }
  1479. }
  1480. pHdrDest->numtextures = DestNative( &textureCt );
  1481. /** TEXTURE INDICES **/
  1482. SET_INDEX_POINTERS_VALIDATE( pData, pHdr, cdtextureindex )
  1483. WriteBuffer<int>( &pDataDest, &pDataSrc, SrcNative( &pHdr->numcdtextures ) );
  1484. /** TEXTURE DICTIONARY **/
  1485. SET_INDEX_POINTERS( pData, pHdr, skinindex )
  1486. WriteBuffer<short>( &pDataDest, &pDataSrc, SrcNative( &pHdr->numskinfamilies ) * SrcNative( &pHdr->numskinref ) );
  1487. /** KEYVALUES **/
  1488. SET_INDEX_POINTERS( pData, pHdr, keyvalueindex )
  1489. WriteBuffer<char>( &pDataDest, &pDataSrc, SrcNative( &pHdr->keyvaluesize ) );
  1490. /** STUDIOHDR2 **/
  1491. if ( pHdr->studiohdr2index )
  1492. {
  1493. DECLARE_INDEX_POINTERS_VALIDATE( pLocalData, pHdr, studiohdr2index )
  1494. DECLARE_OBJECT_POINTERS( pStudioHdr2, pLocalData, studiohdr2_t )
  1495. // HACK: Pre-swap the constant "1" here so the automatic swap inside ITERATE_BLOCK will restore it
  1496. int studiohdr2ct = 1;
  1497. studiohdr2ct = SrcNative( &studiohdr2ct );
  1498. ITERATE_BLOCK( pStudioHdr2, studiohdr2ct )
  1499. {
  1500. WriteObjects( pStudioHdr2Dest, pStudioHdr2Src );
  1501. /** SRC BONE TRANSFORMS **/
  1502. if ( pStudioHdr2->numsrcbonetransform )
  1503. {
  1504. // Note, srcbonetransformindex is an offset from the start of the file, not the start of the studiohdr2
  1505. // as is the convention. That's why the macros can't be used here.
  1506. pDataSrc = (byte*)pHdrSrc + SrcNative( &pStudioHdr2->srcbonetransformindex );
  1507. pDataDest = (byte*)pHdrDest + SrcNative( &pStudioHdr2->srcbonetransformindex );
  1508. WriteObjects<mstudiosrcbonetransform_t>( &pDataDest, &pDataSrc, SrcNative( &pStudioHdr2->numsrcbonetransform ) );
  1509. }
  1510. if ( pStudioHdr2->linearboneindex )
  1511. {
  1512. SET_INDEX_POINTERS_VALIDATE( pData, pStudioHdr2, linearboneindex )
  1513. DECLARE_OBJECT_POINTERS( pLinearBone, pData, mstudiolinearbone_t )
  1514. WriteObjects( pLinearBoneDest, pLinearBoneSrc );
  1515. int numBones = SrcNative( &pLinearBone->numbones );
  1516. SET_INDEX_POINTERS_VALIDATE( pData, pLinearBone, flagsindex )
  1517. WriteBuffer<int>( &pDataDest, &pDataSrc, numBones );
  1518. SET_INDEX_POINTERS_VALIDATE( pData, pLinearBone, parentindex )
  1519. WriteBuffer<int>( &pDataDest, &pDataSrc, numBones );
  1520. SET_INDEX_POINTERS_VALIDATE( pData, pLinearBone, posindex )
  1521. WriteBuffer<float>( &pDataDest, &pDataSrc, 3*numBones );
  1522. SET_INDEX_POINTERS_VALIDATE( pData, pLinearBone, quatindex )
  1523. WriteBuffer<float>( &pDataDest, &pDataSrc, 4*numBones );
  1524. SET_INDEX_POINTERS_VALIDATE( pData, pLinearBone, rotindex )
  1525. WriteBuffer<float>( &pDataDest, &pDataSrc, 3*numBones );
  1526. SET_INDEX_POINTERS_VALIDATE( pData, pLinearBone, posetoboneindex )
  1527. WriteBuffer<float>( &pDataDest, &pDataSrc, 12*numBones );
  1528. SET_INDEX_POINTERS_VALIDATE( pData, pLinearBone, posscaleindex )
  1529. WriteBuffer<float>( &pDataDest, &pDataSrc, 3*numBones );
  1530. SET_INDEX_POINTERS_VALIDATE( pData, pLinearBone, rotscaleindex )
  1531. WriteBuffer<float>( &pDataDest, &pDataSrc, 3*numBones );
  1532. SET_INDEX_POINTERS_VALIDATE( pData, pLinearBone, qalignmentindex )
  1533. WriteBuffer<float>( &pDataDest, &pDataSrc, 4*numBones );
  1534. }
  1535. /** BONE FLEX DRIVERS **/
  1536. if ( pStudioHdr2->m_nBoneFlexDriverIndex )
  1537. {
  1538. SET_INDEX_POINTERS_VALIDATE( pData, pStudioHdr2, m_nBoneFlexDriverIndex )
  1539. DECLARE_OBJECT_POINTERS( pBoneFlexDriver, pData, mstudioboneflexdriver_t )
  1540. ITERATE_BLOCK( pBoneFlexDriver, pStudioHdr2->m_nBoneFlexDriverCount )
  1541. {
  1542. WriteObjects( pBoneFlexDriverDest, pBoneFlexDriverSrc );
  1543. /** BONE FLEX DRIVER CONTROLS **/
  1544. SET_INDEX_POINTERS_VALIDATE( pData, pBoneFlexDriver, m_nControlIndex );
  1545. WriteObjects< mstudioboneflexdrivercontrol_t >( &pDataDest, &pDataSrc, SrcNative( &pBoneFlexDriver->m_nControlCount ) );
  1546. }
  1547. }
  1548. }
  1549. }
  1550. /** STRING TABLE **/
  1551. // NOTE: The block of data (above) swapped immediately before the string table MUST update the
  1552. // pDataSrc pointer position, in order for this string table offset calculation to work correctly.
  1553. // To update the pointer position, pass the pointer address to WriteObjects().
  1554. int offset = pDataSrc - (byte*)pSrcBase;
  1555. int stringTableBytes = fileSize - offset;
  1556. WriteBuffer<char>( pDataDest, pDataSrc, stringTableBytes );
  1557. // Cleanup texture paths
  1558. // Some older MDL's have double terminal slashes
  1559. SET_INDEX_POINTERS( pData, pHdr, cdtextureindex )
  1560. int numCdTextures = SrcNative( &pHdr->numcdtextures );
  1561. for ( int i = 0; i < numCdTextures; ++i )
  1562. {
  1563. char *pPath = (char*)pHdrDest + SrcNative( &((int *)pDataSrc)[i] );
  1564. int len = strlen( pPath );
  1565. if ( len >= 2 && ( pPath[len-1] == '\\' || pPath[len-1] == '/' ) && ( pPath[len-2] == '\\' || pPath[len-2] == '/' ) )
  1566. {
  1567. pPath[len-1] = '\0';
  1568. }
  1569. }
  1570. int compressedFileSize = fileSize;
  1571. // Optionally compress the file
  1572. if ( pCompressFunc )
  1573. {
  1574. void *pInput = pDestBase;
  1575. int inputSize = compressedFileSize;
  1576. void *pOutput;
  1577. int outputSize;
  1578. if ( pCompressFunc( pInput, inputSize, &pOutput, &outputSize ) )
  1579. {
  1580. V_memcpy( pDestBase, pOutput, outputSize );
  1581. free( pOutput );
  1582. compressedFileSize = outputSize;
  1583. }
  1584. }
  1585. return compressedFileSize;
  1586. }
  1587. //----------------------------------------------------------------------
  1588. // Determines what kind of file this is and calls the correct swap function
  1589. //----------------------------------------------------------------------
  1590. int ByteswapStudioFile( const char *pFilename, void *pOutBase, int outBaseSize, const void *pFileBase, int fileSize, studiohdr_t *pHdr, CompressFunc_t pCompressFunc )
  1591. {
  1592. Assert( pFilename );
  1593. Assert( pOutBase != pFileBase );
  1594. g_pFilename = (char*)pFilename;
  1595. int retVal = 0;
  1596. if ( Q_stristr( pFilename, ".mdl" ) )
  1597. {
  1598. retVal = ByteswapMDL( pOutBase, outBaseSize, pFileBase, fileSize, pCompressFunc );
  1599. }
  1600. else if ( Q_stristr( pFilename, ".vvd" ) )
  1601. {
  1602. retVal = ByteswapVVD( pOutBase, outBaseSize, pFileBase, fileSize, pCompressFunc );
  1603. }
  1604. else if ( Q_stristr( pFilename, ".vtx" ) )
  1605. {
  1606. retVal = ByteswapVTX( pOutBase, outBaseSize, pFileBase, fileSize, pCompressFunc );
  1607. }
  1608. else if ( Q_stristr( pFilename, ".phy" ) )
  1609. {
  1610. retVal = ByteswapPHY( pOutBase, outBaseSize, pFileBase, fileSize, pCompressFunc );
  1611. }
  1612. else if ( Q_stristr( pFilename, ".ani" ) )
  1613. {
  1614. // some dead .ani files exist in the tree
  1615. // only process valid .ani files properly hooked to their .mdl
  1616. if ( pHdr && pHdr->numanimblocks != 0 )
  1617. {
  1618. retVal = ByteswapANI( pHdr, pOutBase, outBaseSize, pFileBase, fileSize, pCompressFunc );
  1619. }
  1620. }
  1621. return retVal;
  1622. }
  1623. #pragma warning( pop ) // local variable is initialized but not referenced
  1624. } // namespace StudioByteSwap
  1625. // Data descriptions for byte swapping - only needed
  1626. // for structures that are written to file for use by the game.
  1627. // For any fields that reference other data in the file, use the
  1628. // DEFINE_INDEX macro to identify them as such.
  1629. BEGIN_BYTESWAP_DATADESC( studiohdr_t )
  1630. DEFINE_FIELD( id, FIELD_INTEGER ),
  1631. DEFINE_FIELD( version, FIELD_INTEGER ),
  1632. DEFINE_FIELD( checksum, FIELD_INTEGER ),
  1633. DEFINE_ARRAY( name, FIELD_CHARACTER, 64 ),
  1634. DEFINE_FIELD( length, FIELD_INTEGER ),
  1635. DEFINE_FIELD( eyeposition, FIELD_VECTOR ),
  1636. DEFINE_FIELD( illumposition, FIELD_VECTOR ),
  1637. DEFINE_FIELD( hull_min, FIELD_VECTOR ),
  1638. DEFINE_FIELD( hull_max, FIELD_VECTOR ),
  1639. DEFINE_FIELD( view_bbmin, FIELD_VECTOR ),
  1640. DEFINE_FIELD( view_bbmax, FIELD_VECTOR ),
  1641. DEFINE_FIELD( flags, FIELD_INTEGER ),
  1642. DEFINE_FIELD( numbones, FIELD_INTEGER ), // bones
  1643. DEFINE_INDEX( boneindex, FIELD_INTEGER ),
  1644. DEFINE_FIELD( numbonecontrollers, FIELD_INTEGER ), // bone controllers
  1645. DEFINE_INDEX( bonecontrollerindex, FIELD_INTEGER ),
  1646. DEFINE_FIELD( numhitboxsets, FIELD_INTEGER ),
  1647. DEFINE_INDEX( hitboxsetindex, FIELD_INTEGER ),
  1648. DEFINE_FIELD( numlocalanim, FIELD_INTEGER ), // animations/poses
  1649. DEFINE_INDEX( localanimindex, FIELD_INTEGER ), // animation descriptions
  1650. DEFINE_FIELD( numlocalseq, FIELD_INTEGER ), // sequences
  1651. DEFINE_INDEX( localseqindex, FIELD_INTEGER ),
  1652. DEFINE_FIELD( activitylistversion, FIELD_INTEGER ), // initialization flag - have the sequences been indexed?
  1653. DEFINE_FIELD( eventsindexed, FIELD_INTEGER ),
  1654. DEFINE_FIELD( numtextures, FIELD_INTEGER ),
  1655. DEFINE_INDEX( textureindex, FIELD_INTEGER ),
  1656. DEFINE_FIELD( numcdtextures, FIELD_INTEGER ),
  1657. DEFINE_INDEX( cdtextureindex, FIELD_INTEGER ),
  1658. DEFINE_FIELD( numskinref, FIELD_INTEGER ),
  1659. DEFINE_FIELD( numskinfamilies, FIELD_INTEGER ),
  1660. DEFINE_INDEX( skinindex, FIELD_INTEGER ),
  1661. DEFINE_FIELD( numbodyparts, FIELD_INTEGER ),
  1662. DEFINE_INDEX( bodypartindex, FIELD_INTEGER ),
  1663. DEFINE_FIELD( numlocalattachments, FIELD_INTEGER ),
  1664. DEFINE_INDEX( localattachmentindex, FIELD_INTEGER ),
  1665. DEFINE_FIELD( numlocalnodes, FIELD_INTEGER ),
  1666. DEFINE_INDEX( localnodeindex, FIELD_INTEGER ),
  1667. DEFINE_INDEX( localnodenameindex, FIELD_INTEGER ),
  1668. DEFINE_FIELD( numflexdesc, FIELD_INTEGER ),
  1669. DEFINE_INDEX( flexdescindex, FIELD_INTEGER ),
  1670. DEFINE_FIELD( numflexcontrollers, FIELD_INTEGER ),
  1671. DEFINE_INDEX( flexcontrollerindex, FIELD_INTEGER ),
  1672. DEFINE_FIELD( numflexrules, FIELD_INTEGER ),
  1673. DEFINE_INDEX( flexruleindex, FIELD_INTEGER ),
  1674. DEFINE_FIELD( numikchains, FIELD_INTEGER ),
  1675. DEFINE_INDEX( ikchainindex, FIELD_INTEGER ),
  1676. DEFINE_FIELD( nummouths, FIELD_INTEGER ),
  1677. DEFINE_INDEX( mouthindex, FIELD_INTEGER ),
  1678. DEFINE_FIELD( numlocalposeparameters, FIELD_INTEGER ),
  1679. DEFINE_INDEX( localposeparamindex, FIELD_INTEGER ),
  1680. DEFINE_INDEX( surfacepropindex, FIELD_INTEGER ),
  1681. DEFINE_INDEX( keyvalueindex, FIELD_INTEGER ),
  1682. DEFINE_FIELD( keyvaluesize, FIELD_INTEGER ),
  1683. DEFINE_FIELD( numlocalikautoplaylocks, FIELD_INTEGER ),
  1684. DEFINE_INDEX( localikautoplaylockindex, FIELD_INTEGER ),
  1685. DEFINE_FIELD( mass, FIELD_FLOAT ),
  1686. DEFINE_FIELD( contents, FIELD_INTEGER ),
  1687. DEFINE_FIELD( numincludemodels, FIELD_INTEGER ),
  1688. DEFINE_INDEX( includemodelindex, FIELD_INTEGER ),
  1689. DEFINE_FIELD( unused_virtualModel, FIELD_INTEGER ),
  1690. DEFINE_INDEX( szanimblocknameindex, FIELD_INTEGER ),
  1691. DEFINE_FIELD( numanimblocks, FIELD_INTEGER ),
  1692. DEFINE_INDEX( animblockindex, FIELD_INTEGER ),
  1693. DEFINE_FIELD( unused_animblockModel, FIELD_INTEGER ),
  1694. DEFINE_INDEX( bonetablebynameindex, FIELD_INTEGER ),
  1695. DEFINE_FIELD( unused_pVertexBase, FIELD_INTEGER ),
  1696. DEFINE_FIELD( unused_pIndexBase, FIELD_INTEGER ),
  1697. DEFINE_FIELD( constdirectionallightdot, FIELD_CHARACTER ), // byte
  1698. DEFINE_FIELD( rootLOD, FIELD_CHARACTER ), // byte
  1699. DEFINE_FIELD( numAllowedRootLODs, FIELD_CHARACTER ), // byte
  1700. DEFINE_ARRAY( unused, FIELD_CHARACTER, 1 ), // byte
  1701. DEFINE_INDEX( unused4, FIELD_INTEGER ),
  1702. DEFINE_FIELD( numflexcontrollerui, FIELD_INTEGER ),
  1703. DEFINE_INDEX( flexcontrolleruiindex, FIELD_INTEGER ),
  1704. DEFINE_FIELD( surfacepropLookup, FIELD_INTEGER ),
  1705. DEFINE_FIELD( flVertAnimFixedPointScale, FIELD_FLOAT ),
  1706. DEFINE_INDEX( studiohdr2index, FIELD_INTEGER ),
  1707. DEFINE_ARRAY( unused2, FIELD_INTEGER, 1 ),
  1708. END_BYTESWAP_DATADESC()
  1709. // NOTE! Next time we up the .mdl file format, remove studiohdr2_t
  1710. // and insert all fields in this structure into studiohdr_t.
  1711. BEGIN_BYTESWAP_DATADESC( studiohdr2_t )
  1712. DEFINE_FIELD( numsrcbonetransform, FIELD_INTEGER ),
  1713. DEFINE_INDEX( srcbonetransformindex, FIELD_INTEGER ),
  1714. DEFINE_FIELD( illumpositionattachmentindex, FIELD_INTEGER ),
  1715. DEFINE_FIELD( flMaxEyeDeflection, FIELD_FLOAT ),
  1716. DEFINE_INDEX( linearboneindex, FIELD_INTEGER ),
  1717. DEFINE_INDEX( sznameindex, FIELD_INTEGER ),
  1718. DEFINE_INDEX( m_nBoneFlexDriverCount, FIELD_INTEGER ),
  1719. DEFINE_INDEX( m_nBoneFlexDriverIndex, FIELD_INTEGER ),
  1720. DEFINE_FIELD( virtualModel, FIELD_INTEGER64 ),
  1721. DEFINE_FIELD( animblockModel, FIELD_INTEGER64 ),
  1722. DEFINE_FIELD( pVertexBase, FIELD_INTEGER64 ),
  1723. DEFINE_FIELD( pIndexBase, FIELD_INTEGER64 ),
  1724. DEFINE_ARRAY( reserved, FIELD_INTEGER, 49 ),
  1725. END_BYTESWAP_DATADESC()
  1726. BEGIN_BYTESWAP_DATADESC( mstudiobone_t )
  1727. DEFINE_INDEX( sznameindex, FIELD_INTEGER ),
  1728. DEFINE_FIELD( parent, FIELD_INTEGER ),
  1729. DEFINE_ARRAY( bonecontroller, FIELD_INTEGER, 6 ),
  1730. DEFINE_FIELD( pos, FIELD_VECTOR ),
  1731. DEFINE_FIELD( quat, FIELD_QUATERNION ),
  1732. DEFINE_ARRAY( rot, FIELD_FLOAT, 3 ), // RadianEuler
  1733. DEFINE_FIELD( posscale, FIELD_VECTOR ),
  1734. DEFINE_FIELD( rotscale, FIELD_VECTOR ),
  1735. DEFINE_ARRAY( poseToBone, FIELD_FLOAT, 12 ), // matrix3x4_t
  1736. DEFINE_FIELD( qAlignment, FIELD_QUATERNION ),
  1737. DEFINE_FIELD( flags, FIELD_INTEGER ),
  1738. DEFINE_FIELD( proctype, FIELD_INTEGER ),
  1739. DEFINE_INDEX( procindex, FIELD_INTEGER ),
  1740. DEFINE_INDEX( physicsbone, FIELD_INTEGER ),
  1741. DEFINE_INDEX( surfacepropidx, FIELD_INTEGER ),
  1742. DEFINE_FIELD( contents, FIELD_INTEGER ),
  1743. DEFINE_FIELD( surfacepropLookup, FIELD_INTEGER ),
  1744. DEFINE_ARRAY( unused, FIELD_INTEGER, 7 ),
  1745. END_BYTESWAP_DATADESC()
  1746. BEGIN_BYTESWAP_DATADESC( mstudiolinearbone_t )
  1747. DEFINE_FIELD( numbones, FIELD_INTEGER ),
  1748. DEFINE_INDEX( flagsindex, FIELD_INTEGER ),
  1749. DEFINE_INDEX( parentindex, FIELD_INTEGER ),
  1750. DEFINE_INDEX( posindex, FIELD_INTEGER ),
  1751. DEFINE_INDEX( quatindex, FIELD_INTEGER ),
  1752. DEFINE_INDEX( rotindex, FIELD_INTEGER ),
  1753. DEFINE_INDEX( posetoboneindex, FIELD_INTEGER ),
  1754. DEFINE_INDEX( posscaleindex, FIELD_INTEGER ),
  1755. DEFINE_INDEX( rotscaleindex, FIELD_INTEGER ),
  1756. DEFINE_INDEX( qalignmentindex, FIELD_INTEGER ),
  1757. DEFINE_ARRAY( unused, FIELD_INTEGER, 6 ),
  1758. END_BYTESWAP_DATADESC()
  1759. BEGIN_BYTESWAP_DATADESC( mstudioboneflexdrivercontrol_t )
  1760. DEFINE_INDEX( m_nBoneComponent, FIELD_INTEGER ),
  1761. DEFINE_FIELD( m_nFlexControllerIndex, FIELD_INTEGER ),
  1762. DEFINE_INDEX( m_flMin, FIELD_FLOAT ),
  1763. DEFINE_INDEX( m_flMax, FIELD_FLOAT ),
  1764. END_BYTESWAP_DATADESC()
  1765. BEGIN_BYTESWAP_DATADESC( mstudioboneflexdriver_t )
  1766. DEFINE_INDEX( m_nBoneIndex, FIELD_INTEGER ),
  1767. DEFINE_FIELD( m_nControlCount, FIELD_INTEGER ),
  1768. DEFINE_INDEX( m_nControlIndex, FIELD_FLOAT ),
  1769. DEFINE_ARRAY( unused, FIELD_INTEGER, 3 ),
  1770. END_BYTESWAP_DATADESC()
  1771. BEGIN_BYTESWAP_DATADESC( mstudioaxisinterpbone_t )
  1772. DEFINE_FIELD( control, FIELD_INTEGER ),
  1773. DEFINE_FIELD( axis, FIELD_INTEGER ),
  1774. DEFINE_ARRAY( pos, FIELD_VECTOR, 6 ),
  1775. DEFINE_ARRAY( quat, FIELD_QUATERNION, 6 ),
  1776. END_BYTESWAP_DATADESC()
  1777. BEGIN_BYTESWAP_DATADESC( mstudioquatinterpbone_t )
  1778. DEFINE_FIELD( control, FIELD_INTEGER ),
  1779. DEFINE_FIELD( numtriggers, FIELD_INTEGER ),
  1780. DEFINE_INDEX( triggerindex, FIELD_INTEGER ),
  1781. END_BYTESWAP_DATADESC()
  1782. BEGIN_BYTESWAP_DATADESC( mstudiojigglebone_t )
  1783. DEFINE_FIELD( flags, FIELD_INTEGER ),
  1784. DEFINE_FIELD( length, FIELD_FLOAT ),
  1785. DEFINE_FIELD( tipMass, FIELD_FLOAT ),
  1786. DEFINE_FIELD( yawStiffness, FIELD_FLOAT ),
  1787. DEFINE_FIELD( yawDamping, FIELD_FLOAT ),
  1788. DEFINE_FIELD( pitchStiffness, FIELD_FLOAT ),
  1789. DEFINE_FIELD( pitchDamping, FIELD_FLOAT ),
  1790. DEFINE_FIELD( alongStiffness, FIELD_FLOAT ),
  1791. DEFINE_FIELD( alongDamping, FIELD_FLOAT ),
  1792. DEFINE_FIELD( angleLimit, FIELD_FLOAT ),
  1793. DEFINE_FIELD( minYaw, FIELD_FLOAT ),
  1794. DEFINE_FIELD( maxYaw, FIELD_FLOAT ),
  1795. DEFINE_FIELD( yawFriction, FIELD_FLOAT ),
  1796. DEFINE_FIELD( yawBounce, FIELD_FLOAT ),
  1797. DEFINE_FIELD( minPitch, FIELD_FLOAT ),
  1798. DEFINE_FIELD( maxPitch, FIELD_FLOAT ),
  1799. DEFINE_FIELD( pitchFriction, FIELD_FLOAT ),
  1800. DEFINE_FIELD( pitchBounce, FIELD_FLOAT ),
  1801. DEFINE_FIELD( baseMass, FIELD_FLOAT ),
  1802. DEFINE_FIELD( baseStiffness, FIELD_FLOAT ),
  1803. DEFINE_FIELD( baseDamping, FIELD_FLOAT ),
  1804. DEFINE_FIELD( baseMinLeft, FIELD_FLOAT ),
  1805. DEFINE_FIELD( baseMaxLeft, FIELD_FLOAT ),
  1806. DEFINE_FIELD( baseLeftFriction, FIELD_FLOAT ),
  1807. DEFINE_FIELD( baseMinUp, FIELD_FLOAT ),
  1808. DEFINE_FIELD( baseMaxUp, FIELD_FLOAT ),
  1809. DEFINE_FIELD( baseUpFriction, FIELD_FLOAT ),
  1810. DEFINE_FIELD( baseMinForward, FIELD_FLOAT ),
  1811. DEFINE_FIELD( baseMaxForward, FIELD_FLOAT ),
  1812. DEFINE_FIELD( baseForwardFriction, FIELD_FLOAT ),
  1813. END_BYTESWAP_DATADESC()
  1814. BEGIN_BYTESWAP_DATADESC( mstudioaimatbone_t )
  1815. DEFINE_FIELD( parent, FIELD_INTEGER ),
  1816. DEFINE_FIELD( aim, FIELD_INTEGER ),
  1817. DEFINE_ARRAY( aimvector, FIELD_FLOAT, 3 ),
  1818. DEFINE_ARRAY( upvector, FIELD_FLOAT, 3 ),
  1819. DEFINE_ARRAY( basepos, FIELD_FLOAT, 3 ),
  1820. END_BYTESWAP_DATADESC()
  1821. BEGIN_BYTESWAP_DATADESC( mstudiotwistbonetarget_t )
  1822. DEFINE_FIELD( m_nBone, FIELD_INTEGER ),
  1823. DEFINE_FIELD( m_flWeight, FIELD_FLOAT ),
  1824. DEFINE_FIELD( m_vBaseTranslate, FIELD_VECTOR ),
  1825. DEFINE_FIELD( m_qBaseRotation, FIELD_QUATERNION ),
  1826. END_BYTESWAP_DATADESC()
  1827. BEGIN_BYTESWAP_DATADESC( mstudiotwistbone_t )
  1828. DEFINE_FIELD( m_bInverse, FIELD_BOOLEAN ),
  1829. DEFINE_FIELD( m_vUpVector, FIELD_VECTOR ),
  1830. DEFINE_FIELD( m_nParentBone, FIELD_INTEGER ),
  1831. DEFINE_FIELD( m_qBaseInv, FIELD_QUATERNION ),
  1832. DEFINE_FIELD( m_nChildBone, FIELD_INTEGER ),
  1833. DEFINE_FIELD( m_nTargetCount, FIELD_INTEGER ),
  1834. DEFINE_FIELD( m_nTargetIndex, FIELD_INTEGER ),
  1835. END_BYTESWAP_DATADESC()
  1836. BEGIN_BYTESWAP_DATADESC( mstudioconstraintslave_t )
  1837. DEFINE_FIELD( m_nBone, FIELD_INTEGER ),
  1838. DEFINE_FIELD( m_vBasePosition, FIELD_VECTOR ),
  1839. DEFINE_FIELD( m_qBaseOrientation, FIELD_QUATERNION ),
  1840. END_BYTESWAP_DATADESC()
  1841. BEGIN_BYTESWAP_DATADESC( mstudioconstrainttarget_t )
  1842. DEFINE_FIELD( m_nBone, FIELD_INTEGER ),
  1843. DEFINE_FIELD( m_flWeight, FIELD_FLOAT ),
  1844. DEFINE_FIELD( m_vOffset, FIELD_VECTOR ),
  1845. DEFINE_FIELD( m_qOffset, FIELD_QUATERNION ),
  1846. END_BYTESWAP_DATADESC()
  1847. BEGIN_BYTESWAP_DATADESC( mstudiopointconstraint_t )
  1848. DEFINE_EMBEDDED( m_slave ),
  1849. DEFINE_FIELD( m_nTargetCount, FIELD_INTEGER ),
  1850. DEFINE_FIELD( m_nTargetIndex, FIELD_INTEGER ),
  1851. END_BYTESWAP_DATADESC()
  1852. BEGIN_BYTESWAP_DATADESC( mstudioorientconstraint_t )
  1853. DEFINE_EMBEDDED( m_slave ),
  1854. DEFINE_FIELD( m_nTargetCount, FIELD_INTEGER ),
  1855. DEFINE_FIELD( m_nTargetIndex, FIELD_INTEGER ),
  1856. END_BYTESWAP_DATADESC()
  1857. BEGIN_BYTESWAP_DATADESC( mstudioaimconstraint_t )
  1858. DEFINE_EMBEDDED( m_slave ),
  1859. DEFINE_FIELD( m_nTargetCount, FIELD_INTEGER ),
  1860. DEFINE_FIELD( m_nTargetIndex, FIELD_INTEGER ),
  1861. DEFINE_FIELD( m_qAimOffset, FIELD_QUATERNION ),
  1862. DEFINE_FIELD( m_vUp, FIELD_VECTOR ),
  1863. DEFINE_FIELD( m_nUpSpaceTarget, FIELD_SHORT ),
  1864. DEFINE_FIELD( m_nUpType, FIELD_CHARACTER ),
  1865. DEFINE_FIELD( m_unused, FIELD_CHARACTER ),
  1866. END_BYTESWAP_DATADESC()
  1867. BEGIN_BYTESWAP_DATADESC( mstudioikconstraint_t )
  1868. END_BYTESWAP_DATADESC()
  1869. BEGIN_BYTESWAP_DATADESC( mstudioparentconstraint_t )
  1870. DEFINE_EMBEDDED( m_slave ),
  1871. DEFINE_FIELD( m_nTargetCount, FIELD_INTEGER ),
  1872. DEFINE_FIELD( m_nTargetIndex, FIELD_INTEGER ),
  1873. END_BYTESWAP_DATADESC()
  1874. BEGIN_BYTESWAP_DATADESC( mstudioquatinterpinfo_t )
  1875. DEFINE_FIELD( inv_tolerance, FIELD_FLOAT ),
  1876. DEFINE_FIELD( trigger, FIELD_QUATERNION ),
  1877. DEFINE_FIELD( pos, FIELD_VECTOR ),
  1878. DEFINE_FIELD( quat, FIELD_QUATERNION ),
  1879. END_BYTESWAP_DATADESC()
  1880. BEGIN_BYTESWAP_DATADESC( mstudiobonecontroller_t )
  1881. DEFINE_FIELD( bone, FIELD_INTEGER ),
  1882. DEFINE_FIELD( type, FIELD_INTEGER ),
  1883. DEFINE_FIELD( start, FIELD_FLOAT ),
  1884. DEFINE_FIELD( end, FIELD_FLOAT ),
  1885. DEFINE_FIELD( rest, FIELD_INTEGER ),
  1886. DEFINE_FIELD( inputfield, FIELD_INTEGER ),
  1887. DEFINE_ARRAY( unused, FIELD_INTEGER, 8 ),
  1888. END_BYTESWAP_DATADESC()
  1889. BEGIN_BYTESWAP_DATADESC( mstudioattachment_t )
  1890. DEFINE_INDEX( sznameindex, FIELD_INTEGER ),
  1891. DEFINE_FIELD( flags, FIELD_INTEGER ),
  1892. DEFINE_FIELD( localbone, FIELD_INTEGER ),
  1893. DEFINE_ARRAY( local, FIELD_FLOAT, 12 ), // matrix3x4_t
  1894. DEFINE_ARRAY( unused, FIELD_INTEGER, 8 ),
  1895. END_BYTESWAP_DATADESC()
  1896. BEGIN_BYTESWAP_DATADESC( mstudiohitboxset_t )
  1897. DEFINE_INDEX( sznameindex, FIELD_INTEGER ),
  1898. DEFINE_FIELD( numhitboxes, FIELD_INTEGER ),
  1899. DEFINE_INDEX( hitboxindex, FIELD_INTEGER ),
  1900. END_BYTESWAP_DATADESC()
  1901. BEGIN_BYTESWAP_DATADESC( mstudiosrcbonetransform_t )
  1902. DEFINE_INDEX( sznameindex, FIELD_INTEGER ),
  1903. DEFINE_ARRAY( pretransform, FIELD_FLOAT, 12 ), // matrix3x4_t
  1904. DEFINE_ARRAY( posttransform, FIELD_FLOAT, 12 ), // matrix3x4_t
  1905. END_BYTESWAP_DATADESC()
  1906. BEGIN_BYTESWAP_DATADESC( mstudiobbox_t )
  1907. DEFINE_FIELD( bone, FIELD_INTEGER ),
  1908. DEFINE_FIELD( group, FIELD_INTEGER ),
  1909. DEFINE_FIELD( bbmin, FIELD_VECTOR ),
  1910. DEFINE_FIELD( bbmax, FIELD_VECTOR ),
  1911. DEFINE_INDEX( szhitboxnameindex, FIELD_INTEGER ),
  1912. DEFINE_ARRAY( unused, FIELD_INTEGER, 8 ),
  1913. END_BYTESWAP_DATADESC()
  1914. BEGIN_BYTESWAP_DATADESC( mstudioanim_valueptr_t )
  1915. DEFINE_ARRAY( offset, FIELD_SHORT, 3 ),
  1916. END_BYTESWAP_DATADESC()
  1917. BEGIN_BYTESWAP_DATADESC( mstudiolocalhierarchy_t )
  1918. DEFINE_FIELD( iBone, FIELD_INTEGER ),
  1919. DEFINE_FIELD( iNewParent, FIELD_INTEGER ),
  1920. DEFINE_FIELD( start, FIELD_FLOAT ),
  1921. DEFINE_FIELD( peak, FIELD_FLOAT ),
  1922. DEFINE_FIELD( tail, FIELD_FLOAT ),
  1923. DEFINE_FIELD( end, FIELD_FLOAT ),
  1924. DEFINE_FIELD( iStart, FIELD_INTEGER ),
  1925. DEFINE_INDEX( localanimindex, FIELD_INTEGER ),
  1926. DEFINE_ARRAY( unused, FIELD_INTEGER, 4 ),
  1927. END_BYTESWAP_DATADESC()
  1928. BEGIN_BYTESWAP_DATADESC( mstudioanimsections_t )
  1929. DEFINE_FIELD( animblock, FIELD_INTEGER ),
  1930. DEFINE_INDEX( animindex, FIELD_INTEGER ),
  1931. END_BYTESWAP_DATADESC()
  1932. BEGIN_BYTESWAP_DATADESC( mstudioanimdesc_t )
  1933. DEFINE_INDEX( baseptr, FIELD_INTEGER ),
  1934. DEFINE_INDEX( sznameindex, FIELD_INTEGER ),
  1935. DEFINE_FIELD( fps, FIELD_FLOAT ),
  1936. DEFINE_FIELD( flags, FIELD_INTEGER ),
  1937. DEFINE_FIELD( numframes, FIELD_INTEGER ),
  1938. DEFINE_FIELD( nummovements, FIELD_INTEGER ),
  1939. DEFINE_INDEX( movementindex, FIELD_INTEGER ),
  1940. DEFINE_INDEX( ikrulezeroframeindex, FIELD_INTEGER ),
  1941. DEFINE_ARRAY( unused1, FIELD_INTEGER, 5 ),
  1942. DEFINE_FIELD( animblock, FIELD_INTEGER ),
  1943. DEFINE_INDEX( animindex, FIELD_INTEGER ),
  1944. DEFINE_FIELD( numikrules, FIELD_INTEGER ),
  1945. DEFINE_INDEX( ikruleindex, FIELD_INTEGER ),
  1946. DEFINE_INDEX( animblockikruleindex, FIELD_INTEGER ),
  1947. DEFINE_FIELD( numlocalhierarchy, FIELD_INTEGER ),
  1948. DEFINE_INDEX( localhierarchyindex, FIELD_INTEGER ),
  1949. DEFINE_INDEX( sectionindex, FIELD_INTEGER ),
  1950. DEFINE_FIELD( sectionframes, FIELD_INTEGER ),
  1951. DEFINE_FIELD( zeroframespan, FIELD_SHORT ),
  1952. DEFINE_FIELD( zeroframecount, FIELD_SHORT ),
  1953. DEFINE_INDEX( zeroframeindex, FIELD_INTEGER ),
  1954. DEFINE_FIELD( zeroframestalltime, FIELD_FLOAT ),
  1955. END_BYTESWAP_DATADESC()
  1956. BEGIN_BYTESWAP_DATADESC( mstudio_rle_anim_t )
  1957. DEFINE_FIELD( bone, FIELD_CHARACTER ),
  1958. DEFINE_FIELD( flags, FIELD_CHARACTER ),
  1959. DEFINE_INDEX( nextoffset, FIELD_SHORT ),
  1960. END_BYTESWAP_DATADESC()
  1961. BEGIN_BYTESWAP_DATADESC( mstudio_frame_anim_t )
  1962. DEFINE_FIELD( constantsoffset, FIELD_INTEGER ),
  1963. DEFINE_FIELD( frameoffset, FIELD_INTEGER ),
  1964. DEFINE_FIELD( framelength, FIELD_INTEGER ),
  1965. DEFINE_ARRAY( unused, FIELD_INTEGER, 3 ),
  1966. END_BYTESWAP_DATADESC()
  1967. BEGIN_BYTESWAP_DATADESC( mstudioikerror_t )
  1968. DEFINE_FIELD( pos, FIELD_VECTOR ),
  1969. DEFINE_FIELD( q, FIELD_QUATERNION ),
  1970. END_BYTESWAP_DATADESC()
  1971. BEGIN_BYTESWAP_DATADESC( mstudiocompressedikerror_t )
  1972. DEFINE_ARRAY( scale, FIELD_FLOAT, 6 ),
  1973. DEFINE_ARRAY( offset, FIELD_SHORT, 6 ),
  1974. END_BYTESWAP_DATADESC()
  1975. BEGIN_BYTESWAP_DATADESC( mstudioikrule_t )
  1976. DEFINE_FIELD( index, FIELD_INTEGER ),
  1977. DEFINE_FIELD( type, FIELD_INTEGER ),
  1978. DEFINE_FIELD( chain, FIELD_INTEGER ),
  1979. DEFINE_FIELD( bone, FIELD_INTEGER ),
  1980. DEFINE_FIELD( slot, FIELD_INTEGER ),
  1981. DEFINE_FIELD( height, FIELD_FLOAT ),
  1982. DEFINE_FIELD( radius, FIELD_FLOAT ),
  1983. DEFINE_FIELD( floor, FIELD_FLOAT ),
  1984. DEFINE_FIELD( pos, FIELD_VECTOR ),
  1985. DEFINE_FIELD( q, FIELD_QUATERNION ),
  1986. DEFINE_INDEX( compressedikerrorindex, FIELD_INTEGER ),
  1987. DEFINE_FIELD( unused2, FIELD_INTEGER ),
  1988. DEFINE_FIELD( iStart, FIELD_INTEGER ),
  1989. DEFINE_INDEX( ikerrorindex, FIELD_INTEGER ),
  1990. DEFINE_FIELD( start, FIELD_FLOAT ),
  1991. DEFINE_FIELD( peak, FIELD_FLOAT ),
  1992. DEFINE_FIELD( tail, FIELD_FLOAT ),
  1993. DEFINE_FIELD( end, FIELD_FLOAT ),
  1994. DEFINE_FIELD( unused3, FIELD_FLOAT ),
  1995. DEFINE_FIELD( contact, FIELD_FLOAT ),
  1996. DEFINE_FIELD( drop, FIELD_FLOAT ),
  1997. DEFINE_FIELD( top, FIELD_FLOAT ),
  1998. DEFINE_FIELD( unused6, FIELD_INTEGER ),
  1999. DEFINE_FIELD( unused7, FIELD_INTEGER ),
  2000. DEFINE_FIELD( unused8, FIELD_INTEGER ),
  2001. DEFINE_INDEX( szattachmentindex, FIELD_INTEGER ),
  2002. DEFINE_ARRAY( unused, FIELD_INTEGER, 7 ),
  2003. END_BYTESWAP_DATADESC()
  2004. BEGIN_BYTESWAP_DATADESC( mstudiomovement_t )
  2005. DEFINE_FIELD( endframe, FIELD_INTEGER ),
  2006. DEFINE_FIELD( motionflags, FIELD_INTEGER ),
  2007. DEFINE_FIELD( v0, FIELD_FLOAT ),
  2008. DEFINE_FIELD( v1, FIELD_FLOAT ),
  2009. DEFINE_FIELD( angle, FIELD_FLOAT ),
  2010. DEFINE_FIELD( vector, FIELD_VECTOR ),
  2011. DEFINE_FIELD( position, FIELD_VECTOR ),
  2012. END_BYTESWAP_DATADESC()
  2013. BEGIN_BYTESWAP_DATADESC( mstudioactivitymodifier_t )
  2014. DEFINE_INDEX( sznameindex, FIELD_INTEGER ),
  2015. END_BYTESWAP_DATADESC()
  2016. BEGIN_BYTESWAP_DATADESC( mstudioseqdesc_t )
  2017. DEFINE_INDEX( baseptr, FIELD_INTEGER ),
  2018. DEFINE_INDEX( szlabelindex, FIELD_INTEGER ),
  2019. DEFINE_INDEX( szactivitynameindex, FIELD_INTEGER ),
  2020. DEFINE_FIELD( flags, FIELD_INTEGER ), // looping/non-looping flags
  2021. DEFINE_FIELD( activity, FIELD_INTEGER ), // initialized at loadtime to game DLL values
  2022. DEFINE_FIELD( actweight, FIELD_INTEGER ),
  2023. DEFINE_FIELD( numevents, FIELD_INTEGER ),
  2024. DEFINE_INDEX( eventindex, FIELD_INTEGER ),
  2025. DEFINE_FIELD( bbmin, FIELD_VECTOR ),
  2026. DEFINE_FIELD( bbmax, FIELD_VECTOR ),
  2027. DEFINE_FIELD( numblends, FIELD_INTEGER ),
  2028. DEFINE_INDEX( animindexindex, FIELD_INTEGER ),
  2029. DEFINE_INDEX( movementindex, FIELD_INTEGER ), // [blend] float array for blended movement
  2030. DEFINE_ARRAY( groupsize, FIELD_INTEGER, 2 ),
  2031. DEFINE_ARRAY( paramindex, FIELD_INTEGER, 2 ), // X, Y, Z, XR, YR, ZR
  2032. DEFINE_ARRAY( paramstart, FIELD_FLOAT, 2 ), // local (0..1) starting value
  2033. DEFINE_ARRAY( paramend, FIELD_FLOAT, 2 ), // local (0..1) ending value
  2034. DEFINE_FIELD( paramparent, FIELD_INTEGER ),
  2035. DEFINE_FIELD( fadeintime, FIELD_FLOAT ), // ideal cross fate in time (0.2 default)
  2036. DEFINE_FIELD( fadeouttime, FIELD_FLOAT ), // ideal cross fade out time (0.2 default)
  2037. DEFINE_FIELD( localentrynode, FIELD_INTEGER ), // transition node at entry
  2038. DEFINE_FIELD( localexitnode, FIELD_INTEGER ), // transition node at exit
  2039. DEFINE_FIELD( nodeflags, FIELD_INTEGER ), // transition rules
  2040. DEFINE_FIELD( entryphase, FIELD_FLOAT ), // used to match entry gait
  2041. DEFINE_FIELD( exitphase, FIELD_FLOAT ), // used to match exit gait
  2042. DEFINE_FIELD( lastframe, FIELD_FLOAT ), // frame that should generation EndOfSequence
  2043. DEFINE_FIELD( nextseq, FIELD_INTEGER ), // auto advancing sequences
  2044. DEFINE_FIELD( pose, FIELD_INTEGER ), // index of delta animation between end and nextseq
  2045. DEFINE_FIELD( numikrules, FIELD_INTEGER ),
  2046. DEFINE_FIELD( numautolayers, FIELD_INTEGER ),
  2047. DEFINE_INDEX( autolayerindex, FIELD_INTEGER ),
  2048. DEFINE_INDEX( weightlistindex, FIELD_INTEGER ),
  2049. DEFINE_INDEX( posekeyindex, FIELD_INTEGER ),
  2050. DEFINE_FIELD( numiklocks, FIELD_INTEGER ),
  2051. DEFINE_INDEX( iklockindex, FIELD_INTEGER ),
  2052. DEFINE_INDEX( keyvalueindex, FIELD_INTEGER ),
  2053. DEFINE_FIELD( keyvaluesize, FIELD_INTEGER ),
  2054. DEFINE_INDEX( cycleposeindex, FIELD_INTEGER ),
  2055. DEFINE_INDEX( activitymodifierindex, FIELD_INTEGER ),
  2056. DEFINE_FIELD( numactivitymodifiers, FIELD_INTEGER ),
  2057. DEFINE_ARRAY( unused, FIELD_INTEGER, 5 ), // remove/add as appropriate (grow back to 8 ints on version change!)
  2058. END_BYTESWAP_DATADESC()
  2059. BEGIN_BYTESWAP_DATADESC( mstudioevent_t )
  2060. DEFINE_FIELD( cycle, FIELD_FLOAT ),
  2061. DEFINE_FIELD( event, FIELD_INTEGER ),
  2062. DEFINE_FIELD( type, FIELD_INTEGER ),
  2063. DEFINE_ARRAY( options, FIELD_CHARACTER, 64 ),
  2064. DEFINE_INDEX( szeventindex, FIELD_INTEGER ),
  2065. END_BYTESWAP_DATADESC()
  2066. BEGIN_BYTESWAP_DATADESC( mstudioautolayer_t )
  2067. DEFINE_FIELD( iSequence, FIELD_SHORT ),
  2068. DEFINE_FIELD( iPose, FIELD_SHORT ),
  2069. DEFINE_FIELD( flags, FIELD_INTEGER ),
  2070. DEFINE_FIELD( start, FIELD_FLOAT ),
  2071. DEFINE_FIELD( peak, FIELD_FLOAT ),
  2072. DEFINE_FIELD( tail, FIELD_FLOAT ),
  2073. DEFINE_FIELD( end, FIELD_FLOAT ),
  2074. END_BYTESWAP_DATADESC()
  2075. BEGIN_BYTESWAP_DATADESC( mstudioiklock_t )
  2076. DEFINE_FIELD( chain, FIELD_INTEGER ),
  2077. DEFINE_FIELD( flPosWeight, FIELD_FLOAT ),
  2078. DEFINE_FIELD( flLocalQWeight, FIELD_FLOAT ),
  2079. DEFINE_FIELD( flags, FIELD_INTEGER ),
  2080. DEFINE_ARRAY( unused, FIELD_INTEGER, 4 ),
  2081. END_BYTESWAP_DATADESC()
  2082. BEGIN_BYTESWAP_DATADESC( mstudiobodyparts_t )
  2083. DEFINE_INDEX( sznameindex, FIELD_INTEGER ),
  2084. DEFINE_FIELD( nummodels, FIELD_INTEGER ),
  2085. DEFINE_FIELD( base, FIELD_INTEGER ),
  2086. DEFINE_INDEX( modelindex, FIELD_INTEGER ),
  2087. END_BYTESWAP_DATADESC()
  2088. BEGIN_BYTESWAP_DATADESC( mstudiomodel_t )
  2089. DEFINE_ARRAY( name, FIELD_CHARACTER, 64 ),
  2090. DEFINE_FIELD( type, FIELD_INTEGER ),
  2091. DEFINE_FIELD( boundingradius, FIELD_FLOAT ),
  2092. DEFINE_FIELD( nummeshes, FIELD_INTEGER ),
  2093. DEFINE_INDEX( meshindex, FIELD_INTEGER ),
  2094. DEFINE_FIELD( numvertices, FIELD_INTEGER ),
  2095. DEFINE_INDEX( vertexindex, FIELD_INTEGER ),
  2096. DEFINE_INDEX( tangentsindex, FIELD_INTEGER ),
  2097. DEFINE_FIELD( numattachments, FIELD_INTEGER ),
  2098. DEFINE_INDEX( attachmentindex, FIELD_INTEGER ),
  2099. DEFINE_FIELD( numeyeballs, FIELD_INTEGER ),
  2100. DEFINE_INDEX( eyeballindex, FIELD_INTEGER ),
  2101. DEFINE_EMBEDDED( vertexdata ),
  2102. DEFINE_ARRAY( unused, FIELD_INTEGER, 8 ),
  2103. END_BYTESWAP_DATADESC()
  2104. BEGIN_BYTESWAP_DATADESC( mstudio_modelvertexdata_t )
  2105. DEFINE_FIELD( pVertexData, FIELD_INTEGER ), // void*
  2106. DEFINE_FIELD( pTangentData, FIELD_INTEGER ), // void*
  2107. DEFINE_FIELD( pExtraData, FIELD_INTEGER), // void*
  2108. END_BYTESWAP_DATADESC()
  2109. BEGIN_BYTESWAP_DATADESC( mstudioflexdesc_t )
  2110. DEFINE_INDEX( szFACSindex, FIELD_INTEGER ),
  2111. END_BYTESWAP_DATADESC()
  2112. BEGIN_BYTESWAP_DATADESC( mstudioflexcontroller_t )
  2113. DEFINE_INDEX( sztypeindex, FIELD_INTEGER ),
  2114. DEFINE_INDEX( sznameindex, FIELD_INTEGER ),
  2115. DEFINE_FIELD( localToGlobal, FIELD_INTEGER ),
  2116. DEFINE_FIELD( min, FIELD_FLOAT ),
  2117. DEFINE_FIELD( max, FIELD_FLOAT ),
  2118. END_BYTESWAP_DATADESC()
  2119. BEGIN_BYTESWAP_DATADESC( mstudioflexcontrollerui_t )
  2120. DEFINE_INDEX( sznameindex, FIELD_INTEGER ),
  2121. DEFINE_INDEX( szindex0, FIELD_INTEGER ),
  2122. DEFINE_INDEX( szindex1, FIELD_INTEGER ),
  2123. DEFINE_INDEX( szindex2, FIELD_INTEGER ),
  2124. DEFINE_FIELD( remaptype, FIELD_CHARACTER ),
  2125. DEFINE_FIELD( stereo, FIELD_BOOLEAN ),
  2126. DEFINE_ARRAY( unused, FIELD_CHARACTER, 2 ),
  2127. END_BYTESWAP_DATADESC()
  2128. BEGIN_BYTESWAP_DATADESC( mstudioflexrule_t )
  2129. DEFINE_FIELD( flex, FIELD_INTEGER ),
  2130. DEFINE_FIELD( numops, FIELD_INTEGER ),
  2131. DEFINE_INDEX( opindex, FIELD_INTEGER ),
  2132. END_BYTESWAP_DATADESC()
  2133. BEGIN_BYTESWAP_DATADESC( mstudioflexop_t )
  2134. DEFINE_FIELD( op, FIELD_INTEGER ),
  2135. DEFINE_FIELD( d, FIELD_INTEGER ), // int/float union
  2136. END_BYTESWAP_DATADESC()
  2137. BEGIN_BYTESWAP_DATADESC( mstudioikchain_t )
  2138. DEFINE_INDEX( sznameindex, FIELD_INTEGER ),
  2139. DEFINE_FIELD( linktype, FIELD_INTEGER ),
  2140. DEFINE_FIELD( numlinks, FIELD_INTEGER ),
  2141. DEFINE_INDEX( linkindex, FIELD_INTEGER ),
  2142. END_BYTESWAP_DATADESC()
  2143. BEGIN_BYTESWAP_DATADESC( mstudioiklink_t )
  2144. DEFINE_FIELD( bone, FIELD_INTEGER ),
  2145. DEFINE_FIELD( kneeDir, FIELD_VECTOR ),
  2146. DEFINE_FIELD( unused0, FIELD_VECTOR ),
  2147. END_BYTESWAP_DATADESC()
  2148. BEGIN_BYTESWAP_DATADESC( mstudiomouth_t )
  2149. DEFINE_FIELD( bone, FIELD_INTEGER ),
  2150. DEFINE_FIELD( forward, FIELD_VECTOR ),
  2151. DEFINE_FIELD( flexdesc, FIELD_INTEGER ),
  2152. END_BYTESWAP_DATADESC()
  2153. BEGIN_BYTESWAP_DATADESC( mstudioposeparamdesc_t )
  2154. DEFINE_INDEX( sznameindex, FIELD_INTEGER ),
  2155. DEFINE_FIELD( flags, FIELD_INTEGER ),
  2156. DEFINE_FIELD( start, FIELD_FLOAT ),
  2157. DEFINE_FIELD( end, FIELD_FLOAT ),
  2158. DEFINE_FIELD( loop, FIELD_FLOAT ),
  2159. END_BYTESWAP_DATADESC()
  2160. BEGIN_BYTESWAP_DATADESC( mstudiomesh_t )
  2161. DEFINE_FIELD( material, FIELD_INTEGER ),
  2162. DEFINE_INDEX( modelindex, FIELD_INTEGER ),
  2163. DEFINE_FIELD( numvertices, FIELD_INTEGER ),
  2164. DEFINE_FIELD( vertexoffset, FIELD_INTEGER ),
  2165. DEFINE_FIELD( numflexes, FIELD_INTEGER ),
  2166. DEFINE_INDEX( flexindex, FIELD_INTEGER ),
  2167. DEFINE_FIELD( materialtype, FIELD_INTEGER ),
  2168. DEFINE_FIELD( materialparam, FIELD_INTEGER ),
  2169. DEFINE_FIELD( meshid, FIELD_INTEGER ),
  2170. DEFINE_FIELD( center, FIELD_VECTOR ),
  2171. DEFINE_EMBEDDED( vertexdata ),
  2172. DEFINE_ARRAY( unused, FIELD_INTEGER, 8 ),
  2173. END_BYTESWAP_DATADESC()
  2174. BEGIN_BYTESWAP_DATADESC( mstudio_meshvertexdata_t )
  2175. DEFINE_FIELD( unused_modelvertexdata, FIELD_INTEGER ),
  2176. DEFINE_ARRAY( numLODVertexes, FIELD_INTEGER, MAX_NUM_LODS ),
  2177. DEFINE_FIELD( modelvertexdata, FIELD_INTEGER64 ),
  2178. END_BYTESWAP_DATADESC()
  2179. BEGIN_BYTESWAP_DATADESC( mstudioeyeball_t )
  2180. DEFINE_INDEX( sznameindex, FIELD_INTEGER ),
  2181. DEFINE_FIELD( bone, FIELD_INTEGER ),
  2182. DEFINE_FIELD( org, FIELD_VECTOR ),
  2183. DEFINE_FIELD( zoffset, FIELD_FLOAT ),
  2184. DEFINE_FIELD( radius, FIELD_FLOAT ),
  2185. DEFINE_FIELD( up, FIELD_VECTOR ),
  2186. DEFINE_FIELD( forward, FIELD_VECTOR ),
  2187. DEFINE_FIELD( texture, FIELD_INTEGER ),
  2188. DEFINE_FIELD( unused1, FIELD_INTEGER ),
  2189. DEFINE_FIELD( iris_scale, FIELD_FLOAT ),
  2190. DEFINE_FIELD( unused2, FIELD_INTEGER ),
  2191. DEFINE_ARRAY( upperflexdesc, FIELD_INTEGER, 3 ),
  2192. DEFINE_ARRAY( lowerflexdesc, FIELD_INTEGER, 3 ),
  2193. DEFINE_ARRAY( uppertarget, FIELD_FLOAT, 3 ),
  2194. DEFINE_ARRAY( lowertarget, FIELD_FLOAT, 3 ),
  2195. DEFINE_FIELD( upperlidflexdesc, FIELD_INTEGER ),
  2196. DEFINE_FIELD( lowerlidflexdesc, FIELD_INTEGER ),
  2197. DEFINE_ARRAY( unused, FIELD_INTEGER, 4 ),
  2198. DEFINE_FIELD( m_bNonFACS, FIELD_BOOLEAN ),
  2199. DEFINE_ARRAY( unused3, FIELD_CHARACTER, 3 ),
  2200. DEFINE_ARRAY( unused4, FIELD_INTEGER, 7 ),
  2201. END_BYTESWAP_DATADESC()
  2202. BEGIN_BYTESWAP_DATADESC( mstudioflex_t )
  2203. DEFINE_FIELD( flexdesc, FIELD_INTEGER ),
  2204. DEFINE_FIELD( target0, FIELD_FLOAT ),
  2205. DEFINE_FIELD( target1, FIELD_FLOAT ),
  2206. DEFINE_FIELD( target2, FIELD_FLOAT ),
  2207. DEFINE_FIELD( target3, FIELD_FLOAT ),
  2208. DEFINE_FIELD( numverts, FIELD_INTEGER ),
  2209. DEFINE_INDEX( vertindex, FIELD_INTEGER ),
  2210. DEFINE_FIELD( flexpair, FIELD_INTEGER ),
  2211. DEFINE_FIELD( vertanimtype, FIELD_CHARACTER ),
  2212. DEFINE_ARRAY( unusedchar, FIELD_CHARACTER, 3 ),
  2213. DEFINE_ARRAY( unused, FIELD_INTEGER, 6 ),
  2214. END_BYTESWAP_DATADESC()
  2215. BEGIN_BYTESWAP_DATADESC( mstudiovertanim_t )
  2216. DEFINE_FIELD( index, FIELD_SHORT ),
  2217. DEFINE_FIELD( speed, FIELD_CHARACTER ),
  2218. DEFINE_FIELD( side, FIELD_CHARACTER ),
  2219. DEFINE_ARRAY( delta, FIELD_SHORT, 3 ), // short[3]/float16[3]union
  2220. DEFINE_ARRAY( ndelta, FIELD_SHORT, 3 ), // short[3]/float16[3] union
  2221. END_BYTESWAP_DATADESC()
  2222. BEGIN_BYTESWAP_DATADESC( mstudiovertanim_wrinkle_t )
  2223. DEFINE_FIELD( index, FIELD_SHORT ),
  2224. DEFINE_FIELD( speed, FIELD_CHARACTER ),
  2225. DEFINE_FIELD( side, FIELD_CHARACTER ),
  2226. DEFINE_ARRAY( delta, FIELD_SHORT, 3 ), // short[3]/float16[3]union
  2227. DEFINE_ARRAY( ndelta, FIELD_SHORT, 3 ), // short[3]/float16[3] union
  2228. DEFINE_FIELD( wrinkledelta, FIELD_SHORT ),
  2229. END_BYTESWAP_DATADESC()
  2230. BEGIN_BYTESWAP_DATADESC( mstudiomodelgroup_t )
  2231. DEFINE_INDEX( szlabelindex, FIELD_INTEGER ),
  2232. DEFINE_INDEX( sznameindex, FIELD_INTEGER ),
  2233. END_BYTESWAP_DATADESC()
  2234. BEGIN_BYTESWAP_DATADESC( mstudioanimblock_t )
  2235. DEFINE_INDEX( datastart, FIELD_INTEGER ),
  2236. DEFINE_INDEX( dataend, FIELD_INTEGER ),
  2237. END_BYTESWAP_DATADESC()
  2238. BEGIN_BYTESWAP_DATADESC( mstudiotexture_t )
  2239. DEFINE_INDEX( sznameindex, FIELD_INTEGER ),
  2240. DEFINE_FIELD( flags, FIELD_INTEGER ),
  2241. DEFINE_FIELD( used, FIELD_INTEGER ),
  2242. DEFINE_FIELD( unused1, FIELD_INTEGER ),
  2243. #ifdef PLATFORM_64BITS
  2244. DEFINE_ARRAY( unused, FIELD_INTEGER, 12 ),
  2245. #else
  2246. DEFINE_FIELD( material, FIELD_INTEGER ), // IMaterial*
  2247. DEFINE_FIELD( clientmaterial, FIELD_INTEGER ), // void*
  2248. DEFINE_ARRAY( unused, FIELD_INTEGER, 10 ),
  2249. #endif
  2250. END_BYTESWAP_DATADESC()
  2251. BEGIN_BYTESWAP_DATADESC( vertexFileHeader_t )
  2252. DEFINE_FIELD( id, FIELD_INTEGER ),
  2253. DEFINE_FIELD( version, FIELD_INTEGER ),
  2254. DEFINE_FIELD( checksum, FIELD_INTEGER ),
  2255. DEFINE_FIELD( numLODs, FIELD_INTEGER ),
  2256. DEFINE_ARRAY( numLODVertexes, FIELD_INTEGER, MAX_NUM_LODS ),
  2257. DEFINE_FIELD( numFixups, FIELD_INTEGER ),
  2258. DEFINE_FIELD( fixupTableStart, FIELD_INTEGER ),
  2259. DEFINE_FIELD( vertexDataStart, FIELD_INTEGER ),
  2260. DEFINE_FIELD( tangentDataStart, FIELD_INTEGER ),
  2261. END_BYTESWAP_DATADESC()
  2262. BEGIN_BYTESWAP_DATADESC( vertexFileFixup_t )
  2263. DEFINE_FIELD( lod, FIELD_INTEGER ),
  2264. DEFINE_FIELD( sourceVertexID, FIELD_INTEGER ),
  2265. DEFINE_FIELD( numVertexes, FIELD_INTEGER ),
  2266. END_BYTESWAP_DATADESC()
  2267. BEGIN_BYTESWAP_DATADESC( mstudioboneweight_t )
  2268. DEFINE_ARRAY( weight, FIELD_FLOAT, MAX_NUM_BONES_PER_VERT ),
  2269. DEFINE_ARRAY( bone, FIELD_CHARACTER, MAX_NUM_BONES_PER_VERT ),
  2270. DEFINE_FIELD( numbones, FIELD_CHARACTER ),
  2271. END_BYTESWAP_DATADESC()
  2272. BEGIN_BYTESWAP_DATADESC( mstudiovertex_t )
  2273. DEFINE_EMBEDDED( m_BoneWeights ),
  2274. DEFINE_FIELD( m_vecPosition, FIELD_VECTOR ),
  2275. DEFINE_FIELD( m_vecNormal, FIELD_VECTOR ),
  2276. DEFINE_ARRAY( m_vecTexCoord, FIELD_FLOAT, 2 ),
  2277. END_BYTESWAP_DATADESC()
  2278. // Data descriptions from OptimizedModel.h
  2279. namespace OptimizedModel
  2280. {
  2281. BEGIN_BYTESWAP_DATADESC( BoneStateChangeHeader_t )
  2282. DEFINE_FIELD( hardwareID, FIELD_INTEGER ),
  2283. DEFINE_FIELD( newBoneID, FIELD_INTEGER ),
  2284. END_BYTESWAP_DATADESC()
  2285. BEGIN_BYTESWAP_DATADESC( Vertex_t )
  2286. DEFINE_ARRAY( boneWeightIndex, FIELD_CHARACTER, MAX_NUM_BONES_PER_VERT ),
  2287. DEFINE_FIELD( numBones, FIELD_CHARACTER ),
  2288. DEFINE_FIELD( origMeshVertID, FIELD_SHORT ),
  2289. DEFINE_ARRAY( boneID, FIELD_CHARACTER, MAX_NUM_BONES_PER_VERT ),
  2290. END_BYTESWAP_DATADESC()
  2291. BEGIN_BYTESWAP_DATADESC( StripHeader_t )
  2292. DEFINE_FIELD( numIndices, FIELD_INTEGER ),
  2293. DEFINE_FIELD( indexOffset, FIELD_INTEGER ),
  2294. DEFINE_FIELD( numVerts, FIELD_INTEGER ),
  2295. DEFINE_FIELD( vertOffset, FIELD_INTEGER ),
  2296. DEFINE_FIELD( numBones, FIELD_SHORT ),
  2297. DEFINE_FIELD( flags, FIELD_CHARACTER ),
  2298. DEFINE_FIELD( numBoneStateChanges, FIELD_INTEGER ),
  2299. DEFINE_FIELD( boneStateChangeOffset, FIELD_INTEGER ),
  2300. DEFINE_FIELD( numTopologyIndices, FIELD_INTEGER ),
  2301. DEFINE_FIELD( topologyOffset, FIELD_INTEGER ),
  2302. END_BYTESWAP_DATADESC()
  2303. BEGIN_BYTESWAP_DATADESC( StripGroupHeader_t )
  2304. DEFINE_FIELD( numVerts, FIELD_INTEGER ),
  2305. DEFINE_FIELD( vertOffset, FIELD_INTEGER ),
  2306. DEFINE_FIELD( numIndices, FIELD_INTEGER ),
  2307. DEFINE_FIELD( indexOffset, FIELD_INTEGER ),
  2308. DEFINE_FIELD( numStrips, FIELD_INTEGER ),
  2309. DEFINE_FIELD( stripOffset, FIELD_INTEGER ),
  2310. DEFINE_FIELD( flags, FIELD_CHARACTER ),
  2311. DEFINE_FIELD( numTopologyIndices, FIELD_INTEGER ),
  2312. DEFINE_FIELD( topologyOffset, FIELD_INTEGER ),
  2313. END_BYTESWAP_DATADESC()
  2314. BEGIN_BYTESWAP_DATADESC( MeshHeader_t )
  2315. DEFINE_FIELD( numStripGroups, FIELD_INTEGER ),
  2316. DEFINE_FIELD( stripGroupHeaderOffset, FIELD_INTEGER ),
  2317. DEFINE_FIELD( flags, FIELD_CHARACTER ),
  2318. END_BYTESWAP_DATADESC()
  2319. BEGIN_BYTESWAP_DATADESC( ModelLODHeader_t )
  2320. DEFINE_FIELD( numMeshes, FIELD_INTEGER ),
  2321. DEFINE_FIELD( meshOffset, FIELD_INTEGER ),
  2322. DEFINE_FIELD( switchPoint, FIELD_FLOAT ),
  2323. END_BYTESWAP_DATADESC()
  2324. BEGIN_BYTESWAP_DATADESC( ModelHeader_t )
  2325. DEFINE_FIELD( numLODs, FIELD_INTEGER ),
  2326. DEFINE_FIELD( lodOffset, FIELD_INTEGER ),
  2327. END_BYTESWAP_DATADESC()
  2328. BEGIN_BYTESWAP_DATADESC( BodyPartHeader_t )
  2329. DEFINE_FIELD( numModels, FIELD_INTEGER ),
  2330. DEFINE_FIELD( modelOffset, FIELD_INTEGER ),
  2331. END_BYTESWAP_DATADESC()
  2332. BEGIN_BYTESWAP_DATADESC( MaterialReplacementHeader_t )
  2333. DEFINE_FIELD( materialID, FIELD_SHORT ),
  2334. DEFINE_FIELD( replacementMaterialNameOffset, FIELD_INTEGER ),
  2335. END_BYTESWAP_DATADESC()
  2336. BEGIN_BYTESWAP_DATADESC( MaterialReplacementListHeader_t )
  2337. DEFINE_FIELD( numReplacements, FIELD_INTEGER ),
  2338. DEFINE_FIELD( replacementOffset, FIELD_INTEGER ),
  2339. END_BYTESWAP_DATADESC()
  2340. BEGIN_BYTESWAP_DATADESC( FileHeader_t )
  2341. DEFINE_FIELD( version, FIELD_INTEGER ),
  2342. DEFINE_FIELD( vertCacheSize, FIELD_INTEGER ),
  2343. DEFINE_FIELD( maxBonesPerStrip, FIELD_SHORT ),
  2344. DEFINE_FIELD( maxBonesPerFace, FIELD_SHORT ),
  2345. DEFINE_FIELD( maxBonesPerVert, FIELD_INTEGER ),
  2346. DEFINE_FIELD( checkSum, FIELD_INTEGER ),
  2347. DEFINE_FIELD( numLODs, FIELD_INTEGER ),
  2348. DEFINE_FIELD( materialReplacementListOffset, FIELD_INTEGER ),
  2349. DEFINE_FIELD( numBodyParts, FIELD_INTEGER ),
  2350. DEFINE_FIELD( bodyPartOffset, FIELD_INTEGER ),
  2351. END_BYTESWAP_DATADESC()
  2352. } // namespace OptimizedModel
  2353. // Data descriptions from phyfile.h
  2354. BEGIN_BYTESWAP_DATADESC( phyheader_t )
  2355. DEFINE_FIELD( size, FIELD_INTEGER ),
  2356. DEFINE_FIELD( id, FIELD_INTEGER ),
  2357. DEFINE_FIELD( solidCount, FIELD_INTEGER ),
  2358. DEFINE_FIELD( checkSum, FIELD_INTEGER ),
  2359. END_BYTESWAP_DATADESC()