Advertisement
Dimitri_UA

Untitled

Jun 15th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "Extension.h"
  4. #include "Stream.h"
  5. #include "RwTypes.h"
  6. #include "StdInc.h"
  7.  
  8. struct gtaRwUVAnim : public gtaRwExtension
  9. {
  10.     union{
  11.         gtaRwUInt32 animSlotsMap;
  12.         struct{
  13.             gtaRwUInt32 animSlots1Used : 1;
  14.             gtaRwUInt32 animSlots2Used : 1;
  15.             gtaRwUInt32 animSlots3Used : 1;
  16.             gtaRwUInt32 animSlots4Used : 1;
  17.             gtaRwUInt32 animSlots5Used : 1;
  18.             gtaRwUInt32 animSlots6Used : 1;
  19.             gtaRwUInt32 animSlots7Used : 1;
  20.             gtaRwUInt32 animSlots8Used : 1;
  21.         };
  22.     };
  23.     gtaRwChar *animNames;
  24.     gtaRwUInt32 numAnimNames;
  25.     gtaRwUInt32 currentSlot;
  26.  
  27.     gtaRwUVAnim()
  28.     {
  29.         memset(this, 0, sizeof(gtaRwUVAnim));
  30.     }
  31.  
  32.     void Initialise(gtaRwUInt32 NumSlots)
  33.     {
  34.         enabled = true;
  35.         currentSlot = 0;
  36.         if(animNames)
  37.             free(animNames);
  38.         if(NumSlots > 8)
  39.             NumSlots = 8;
  40.         numAnimNames = NumSlots;
  41.         if(NumSlots > 0)
  42.         {
  43.             animNames = (gtaRwChar *)malloc(NumSlots * 32);
  44.             memset(animNames, 0, NumSlots * 32);
  45.         }
  46.     }
  47.  
  48.     void SetupAnim(gtaRwUInt32 Slot, gtaRwChar *AnimName)
  49.     {
  50.         animSlotsMap |= (1 << Slot);
  51.         strcpy(&animNames[32 * currentSlot],  AnimName);
  52.         currentSlot++;
  53.     }
  54.  
  55.     void Destroy()
  56.     {
  57.         if(animNames)
  58.             free(animNames);
  59.     }
  60.  
  61.     bool StreamWrite(gtaRwStream *stream)
  62.     {
  63.         if(enabled)
  64.         {
  65.             if(!gtaRwStreamWriteVersionedChunkHeader(stream, rwID_UVANIM, GetStreamSize() - 12, gtaRwVersion, gtaRwBuild))
  66.                 return false;
  67.             if(!gtaRwStreamWriteVersionedChunkHeader(stream, rwID_STRUCT, GetStreamSize() - 24, gtaRwVersion, gtaRwBuild))
  68.                 return false;
  69.             if(!gtaRwStreamWrite(stream, &animSlotsMap, 4))
  70.                 return false;
  71.             if(animNames)
  72.             {
  73.                 if(!gtaRwStreamWrite(stream, animNames, numAnimNames * 32))
  74.                     return false;
  75.             }
  76.         }
  77.         return true;
  78.     }
  79.  
  80.     bool StreamRead(gtaRwStream *stream)
  81.     {
  82.         if(animNames)
  83.             free(animNames);
  84.         numAnimNames = 0;
  85.         currentSlot = 0;
  86.         if(!gtaRwStreamFindChunk(stream, rwID_STRUCT, NULL, NULL))
  87.             return false;
  88.         if(gtaRwStreamRead(stream, &animSlotsMap, 4) != 4)
  89.             return false;
  90.         for(gtaRwInt32 i = 0; i < 8; i++)
  91.         {
  92.             if(animSlotsMap & (1 << i))
  93.                 numAnimNames++;
  94.         }
  95.         if(numAnimNames > 0)
  96.         {
  97.             animNames = (gtaRwChar *)malloc(numAnimNames * 32);
  98.             if(gtaRwStreamRead(stream, animNames, numAnimNames * 32) != numAnimNames * 32)
  99.                 return false;
  100.         }
  101.         enabled = true;
  102.         return true;
  103.     }
  104.    
  105.     unsigned int GetStreamSize()
  106.     {
  107.         if(enabled)
  108.             return 28 + numAnimNames * 32;
  109.         return 0;
  110.     }
  111. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement