Beispiel #1
0
 /// <summary>
 /// Returns a byte array representing the bytes of a specific CASC file. Used to create new MemoryStreams.
 /// </summary>
 /// <param name="file">This CASCFile should come from the CASCFiles List.</param>
 /// <returns></returns>
 public byte[] CascFileBytes(CASCFile file)
 {
     try {
         var input = storage.OpenFile(file.FullPath);
         using (var output = new MemoryStream()) {
             System.IntPtr pspanPointer;
             CASCFunc.CASC_FILE_FULL_INFO fileInfo;
             if (input.GetInfo(out fileInfo, out pspanPointer))
             {
                 for (int i = 0; i < fileInfo.SpanCount; i++)
                 {
                     var pspan      = Marshal.PtrToStructure <CASCFunc.CASC_FILE_SPAN_INFO>(IntPtr.Add(pspanPointer, i * Marshal.SizeOf(typeof(CASCFunc.CASC_FILE_SPAN_INFO))));
                     int cbFileSpan = (int)(pspan.EndOffset - pspan.StartOffset);
                     if (cbFileSpan == 0)
                     {
                         continue;
                     }
                     byte[] buffer;
                     int    bytesRead;
                     bool   readOK = input.Read(out buffer, cbFileSpan, out bytesRead);
                     if (readOK)
                     {
                         output.Write(buffer, 0, bytesRead);
                         if (bytesRead < cbFileSpan)
                         {
                             break;
                         }
                     }
                     else
                     {
                         break;
                     }
                 }
             }
             output.Position = 0;
             byte[] bytes = output.ToArray();
             return(bytes);
         }
     }
     catch (Exception ex) {
         Debug.LogError(ex);
         return(null);
     }
 }