public static List <ResourceChunk> ReadChunks(byte[] tocBuffer)
        {
            List <ResourceChunk> chunks = new List <ResourceChunk>();

            int i = 0;

            // TODO: Might still get out of range maybe... (14 bytes per chunk, but name length is variable)
            while (i < tocBuffer.Length - 14)
            {
                byte   type = tocBuffer[i];
                string name = BinaryUtils.ReadNullTerminatedString(tocBuffer, i + 2);

                i += name.Length + 1;                 // + 1 to include null terminator.
                uint startOffset = BitConverter.ToUInt32(tocBuffer, i + 2);
                uint size        = BitConverter.ToUInt32(tocBuffer, i + 6);
                i += 14;

                AssetType?assetType = type.GetAssetType();
                if (assetType.HasValue)
                {
                    ResourceChunk chunk = assetType switch
                    {
                        AssetType.Model => new ModelChunk(name, startOffset, size),
                        AssetType.Shader => new ShaderChunk(name, startOffset, size),
                        AssetType.Texture => new TextureChunk(name, startOffset, size),
                        _ => new ResourceChunk(assetType.Value, name, startOffset, size),
                    };
                    chunks.Add(chunk);
                }
            }

            return(chunks);
        }
        private static List <ResourceChunk> CreateChunksFromAssets(List <AbstractAsset> allAssets, ProgressWrapper progress)
        {
            StringBuilder loudness = new StringBuilder();

            List <ResourceChunk> chunks = new List <ResourceChunk>();

            foreach (AbstractAsset asset in allAssets)
            {
                progress.Report($"Generating {asset.AssetType} chunk \"{asset.AssetName}\".", chunks.Count / (float)allAssets.Count / 2);

                if (asset is AudioAsset audioAsset)
                {
                    loudness.AppendLine($"{audioAsset.AssetName} = {audioAsset.Loudness:0.0}");
                }

                ResourceChunk chunk = asset.AssetType switch
                {
                    AssetType.Model => new ModelChunk(asset.AssetName, 0, 0),
                    AssetType.Shader => new ShaderChunk(asset.AssetName, 0, 0),
                    AssetType.Texture => new TextureChunk(asset.AssetName, 0, 0),
                    _ => new ResourceChunk(asset.AssetType, asset.AssetName, 0, 0),
                };
                chunk.MakeBinary(asset.EditorPath);

                chunks.Add(chunk);
            }

            if (loudness.Length != 0)
            {
                progress.Report("Generating Loudness chunk.");
                byte[] fileBuffer;
                using (MemoryStream ms = new MemoryStream())
                {
                    byte[] fileContents = Encoding.Default.GetBytes(loudness.ToString());
                    ms.Write(fileContents, 0, fileContents.Length);
                    fileBuffer = ms.ToArray();
                }

                chunks.Add(new ResourceChunk(AssetType.Audio, "loudness", 0U, (uint)fileBuffer.Length)
                {
                    Buffer = fileBuffer
                });
            }

            return(chunks);
        }
Exemplo n.º 3
0
 public FoundResourceMessage(Unit sender, ResourceChunk chunk)
     : base(sender)
 {
     this.chunk = chunk;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Blang file entry constructor
 /// </summary>
 /// <param name="blangFile">deserialized .blang file</param>
 /// <param name="chunk">resource chunk</param>
 public BlangFileEntry(BlangFile blangFile, ResourceChunk chunk)
 {
     BlangFile = blangFile;
     Chunk     = chunk;
 }
Exemplo n.º 5
0
 public FoundResourcesMessage(Unit sender, ResourceChunk chunk)
     : base(sender)
 {
     this.pos = chunk.GetBounds().Center;
     amount = chunk.GetAmount();
 }