Esempio n. 1
0
        public static byte[] GetResourceFromCache(this IResourceBlock blockInfo, int index = 0)
        {
            Stream source          = null;
            var    resourcePointer = blockInfo.GetResourcePointer(index);
            var    resourceLength  = blockInfo.GetResourceLength(index);

            if (resourcePointer.Source == Halo2.ResourceSource.Local)
            {
                source = ActiveCache as CacheStream;
            }
            if (resourcePointer.Source == Halo2.ResourceSource.Shared)
            {
                source = (Stream)Index.Caches.FirstOrDefault(IsCacheCalled("shared"));
            }
            if (resourcePointer.Source == Halo2.ResourceSource.SinglePlayerShared)
            {
                source = (Stream)Index.Caches.FirstOrDefault(IsCacheCalled("single_player_shared"));
            }
            if (resourcePointer.Source == Halo2.ResourceSource.MainMenu)
            {
                source = (Stream)Index.Caches.FirstOrDefault(IsCacheCalled("mainmenu"));
            }

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

            source.Position = resourcePointer.Address;
            var buffer = new byte[resourceLength];

            source.Read(buffer, 0, resourceLength);
            return(buffer);
        }
Esempio n. 2
0
        private void CopyIndexedResource(Stream outputStream, IResourceBlock resourceBlock, int resourceCount)
        {
            for (var i = 0; i < resourceCount; i++)
            {
                var address = resourceBlock.GetResourcePointer(i);
                var length  = resourceBlock.GetResourceLength(i);
                switch (address.Source)
                {
                case Halo2.ResourceSource.Local:
                    CopyLocalResource(outputStream, resourceBlock, address, length, i);
                    break;

                default:
                    //  we don't need to do anything with external resources
                    continue;
                }
            }
        }