Guest User

Untitled

a guest
May 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. HRESULT ContentResource::AddResource( _CONTENT_ASSET assetType, ContentAssetPack * assetPack, BYTE * fileData, DWORD fileSize, IMAGE_TYPE imageType, DWORD screenshotIndex = 0 )
  2. {
  3.     // First thing we need to do is convert our incoming file to raw image data
  4.     if( S_FALSE == CreateRawResource( fileData, fileSize, imageType ) ) return S_FALSE;
  5.  
  6.     // If successful, let's fill out our struct that describes our raw image
  7.     TEXTURE_SOURCE texSource;
  8.     texSource.ImageData = resourceData;
  9.     texSource.ImageFormat = resourceFormat;
  10.     texSource.ImageHeight = resourceHeight;
  11.     texSource.ImageWidth = resourceWidth;
  12.     texSource.ImagePitch = resourcePitch;
  13.     texSource.ImageSize = resourceSize;
  14.  
  15.     // Pass struct to the conversion class, and if it fails, we fail
  16.     CTexture2D texConvert( texSource );
  17.     if( S_FALSE == texConvert.CreateTexture()) return S_FALSE;
  18.  
  19.     // Next let's grab pointers to our converted data, this is the information stored in our file
  20.     BYTE * headerData = NULL; DWORD headerDataSize = 0;
  21.     BYTE * videoData = NULL; DWORD videoDataSize = 0;
  22.     headerData = texConvert.GetHeaderPtr( &headerDataSize );
  23.     videoData = texConvert.GetVideoDataPtr( &videoDataSize );
  24.  
  25.     // Let's do a quick compability test on the header size (if not size 0x34, let's bail)
  26.     if( headerDataSize != 0x34 ) {
  27.         LOG("ContentResource", "Asset Conversion Failure- Mismatched Header Sizes.  0x%X =/= 0x34", headerDataSize );
  28.         return S_FALSE;
  29.     }
  30.        
  31.     // Next let's analyze the asset type and see if it exists in our current assetPack
  32.     BOOL bAssetExists = assetPack->EntryExists( assetType, screenshotIndex );
  33.  
  34.     // Now we add / modify our assetPack depending on above result
  35.     if( bAssetExists == TRUE )
  36.     {
  37.         if( assetType == ASSET_SCREENSHOT ) {
  38.             return assetPack->ModifyScreenshotEntry( screenshotIndex, headerData, videoData, videoDataSize );
  39.         } else {
  40.             return assetPack->ModifyAssetEntry( assetType, headerData, videoData, videoDataSize );
  41.         }
  42.     }
  43.     else
  44.     {
  45.         return assetPack->AddEntry( assetType, headerData, videoData, videoDataSize );
  46.     }
  47.  
  48.     // if we got here, there something went way wrong
  49.     return S_FALSE;
  50. }
Add Comment
Please, Sign In to add comment