Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "Extension.h"
- #include "Stream.h"
- #include "RwTypes.h"
- #include "StdInc.h"
- struct gtaRwUVAnim : public gtaRwExtension
- {
- union{
- gtaRwUInt32 animSlotsMap;
- struct{
- gtaRwUInt32 animSlots1Used : 1;
- gtaRwUInt32 animSlots2Used : 1;
- gtaRwUInt32 animSlots3Used : 1;
- gtaRwUInt32 animSlots4Used : 1;
- gtaRwUInt32 animSlots5Used : 1;
- gtaRwUInt32 animSlots6Used : 1;
- gtaRwUInt32 animSlots7Used : 1;
- gtaRwUInt32 animSlots8Used : 1;
- };
- };
- gtaRwChar *animNames;
- gtaRwUInt32 numAnimNames;
- gtaRwUInt32 currentSlot;
- gtaRwUVAnim()
- {
- memset(this, 0, sizeof(gtaRwUVAnim));
- }
- void Initialise(gtaRwUInt32 NumSlots)
- {
- enabled = true;
- currentSlot = 0;
- if(animNames)
- free(animNames);
- if(NumSlots > 8)
- NumSlots = 8;
- numAnimNames = NumSlots;
- if(NumSlots > 0)
- {
- animNames = (gtaRwChar *)malloc(NumSlots * 32);
- memset(animNames, 0, NumSlots * 32);
- }
- }
- void SetupAnim(gtaRwUInt32 Slot, gtaRwChar *AnimName)
- {
- animSlotsMap |= (1 << Slot);
- strcpy(&animNames[32 * currentSlot], AnimName);
- currentSlot++;
- }
- void Destroy()
- {
- if(animNames)
- free(animNames);
- }
- bool StreamWrite(gtaRwStream *stream)
- {
- if(enabled)
- {
- if(!gtaRwStreamWriteVersionedChunkHeader(stream, rwID_UVANIM, GetStreamSize() - 12, gtaRwVersion, gtaRwBuild))
- return false;
- if(!gtaRwStreamWriteVersionedChunkHeader(stream, rwID_STRUCT, GetStreamSize() - 24, gtaRwVersion, gtaRwBuild))
- return false;
- if(!gtaRwStreamWrite(stream, &animSlotsMap, 4))
- return false;
- if(animNames)
- {
- if(!gtaRwStreamWrite(stream, animNames, numAnimNames * 32))
- return false;
- }
- }
- return true;
- }
- bool StreamRead(gtaRwStream *stream)
- {
- if(animNames)
- free(animNames);
- numAnimNames = 0;
- currentSlot = 0;
- if(!gtaRwStreamFindChunk(stream, rwID_STRUCT, NULL, NULL))
- return false;
- if(gtaRwStreamRead(stream, &animSlotsMap, 4) != 4)
- return false;
- for(gtaRwInt32 i = 0; i < 8; i++)
- {
- if(animSlotsMap & (1 << i))
- numAnimNames++;
- }
- if(numAnimNames > 0)
- {
- animNames = (gtaRwChar *)malloc(numAnimNames * 32);
- if(gtaRwStreamRead(stream, animNames, numAnimNames * 32) != numAnimNames * 32)
- return false;
- }
- enabled = true;
- return true;
- }
- unsigned int GetStreamSize()
- {
- if(enabled)
- return 28 + numAnimNames * 32;
- return 0;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement