Esempio n. 1
0
        private TagResourceReference ConvertBitmap(Bitmap bitmap, Dictionary <ResourceLocation, Stream> resourceStreams, int imageIndex, string tagName)
        {
            BaseBitmap baseBitmap = BitmapConverter.ConvertGen3Bitmap(BlamCache, bitmap, imageIndex);

            if (baseBitmap == null)
            {
                return(null);
            }

            BitmapUtils.SetBitmapImageData(baseBitmap, bitmap.Images[imageIndex]);
            var bitmapResourceDefinition = BitmapUtils.CreateBitmapTextureInteropResource(baseBitmap);
            var resourceReference        = CacheContext.ResourceCache.CreateBitmapResource(bitmapResourceDefinition);

            return(resourceReference);
        }
Esempio n. 2
0
 public static DDSFile ExtractBitmap(GameCache cache, Bitmap bitmap, int imageIndex)
 {
     if (cache is GameCacheHaloOnlineBase)
     {
         byte[]    data   = ExtractBitmapData(cache, bitmap, imageIndex);
         DDSHeader header = new DDSHeader(bitmap.Images[imageIndex]);
         return(new DDSFile(header, data));
     }
     else if (cache.GetType() == typeof(GameCacheGen3))
     {
         var baseBitmap = BitmapConverter.ConvertGen3Bitmap(cache, bitmap, imageIndex, true);
         if (baseBitmap == null)
         {
             return(null);
         }
         return(new DDSFile(baseBitmap));
     }
     else
     {
         return(null);
     }
 }
        private PageableResource ConvertBitmap(Bitmap bitmap, Dictionary <ResourceLocation, Stream> resourceStreams, int imageIndex, string tagName)
        {
            var        image      = bitmap.Images[imageIndex];
            BaseBitmap baseBitmap = BitmapConverter.ConvertGen3Bitmap(BlamCache, bitmap, imageIndex, BlamCache.Version);

            if (baseBitmap == null)
            {
                return(null);
            }

            // fix type enum
            if (baseBitmap.Type == BitmapType.Array)
            {
                baseBitmap.Type = BitmapType.Texture3D;
            }

            SetTagData(baseBitmap, image);
            var dataSize = baseBitmap.Data.Length;

            var resource = new PageableResource
            {
                Page     = new RawPage(),
                Resource = new TagResourceGen3
                {
                    ResourceFixups           = new List <TagResourceGen3.ResourceFixup>(),
                    ResourceDefinitionFixups = new List <TagResourceGen3.ResourceDefinitionFixup>(),
                    ResourceType             = TagResourceTypeGen3.Bitmap,
                    Unknown2 = 1
                }
            };

            using (var dataStream = new MemoryStream(baseBitmap.Data))
            {
                var bitmapResource = new Bitmap.BitmapResource
                {
                    Resource = resource,
                    Unknown4 = 0
                };
                var resourceContext = new ResourceSerializationContext(CacheContext, resource);

                // Create new definition
                var resourceDefinition = new BitmapTextureInteropResource
                {
                    Texture = new TagStructureReference <BitmapTextureInteropResource.BitmapDefinition>
                    {
                        Definition = new BitmapTextureInteropResource.BitmapDefinition
                        {
                            Data        = new TagData(),
                            UnknownData = new TagData(),
                        }
                    }
                };

                SetResourceDefinitionData(baseBitmap, image, resourceDefinition.Texture.Definition);

                //
                // Serialize the new resource definition
                //

                var location = bitmap.Usage == 2 ?
                               ResourceLocation.TexturesB : // bump maps
                               ResourceLocation.Textures;   // everything else

                resource.ChangeLocation(location);

                if (resource == null)
                {
                    throw new ArgumentNullException("resource");
                }

                if (!dataStream.CanRead)
                {
                    throw new ArgumentException("The input stream is not open for reading", "dataStream");
                }

                var cache = CacheContext.GetResourceCache(location);

                if (!resourceStreams.ContainsKey(location))
                {
                    resourceStreams[location] = FlagIsSet(PortingFlags.Memory) ?
                                                new MemoryStream() :
                                                (Stream)CacheContext.OpenResourceCacheReadWrite(location);

                    if (FlagIsSet(PortingFlags.Memory))
                    {
                        using (var resourceStream = CacheContext.OpenResourceCacheRead(location))
                            resourceStream.CopyTo(resourceStreams[location]);
                    }
                }

                dataSize = (int)(dataStream.Length - dataStream.Position);
                var data = new byte[dataSize];
                dataStream.Read(data, 0, dataSize);

                resource.Page.Index = cache.Add(resourceStreams[location], data, out uint compressedSize);
                resource.Page.CompressedBlockSize   = compressedSize;
                resource.Page.UncompressedBlockSize = (uint)dataSize;
                resource.DisableChecksum();

                CacheContext.Serializer.Serialize(resourceContext, resourceDefinition);
            }

            return(resource);
        }
Esempio n. 4
0
 private BaseBitmap ExtractBitmapData(Bitmap bitmap, int index)
 {
     return(BitmapConverter.ConvertGen3Bitmap(BlamCache, bitmap, index, BlamCache.Version));
 }