Esempio n. 1
0
        public static LoopRegisterMapping Parse(BytecodeReader reader)
        {
            var result = new LoopRegisterMapping();

            result.Buffer    = reader.ReadUInt16();
            result.SourceReg = reader.ReadUInt16();
            result.Component = reader.ReadUInt16();
            result.TargetReg = reader.ReadUInt16();
            return(result);
        }
Esempio n. 2
0
        internal static BytecodeChunk Parse(BytecodeReader chunkContentReader, uint chunkSize)
        {
            var  result     = new Level9ShaderChunk();
            uint chunkSize2 = chunkContentReader.ReadUInt32();

            result.Version = ShaderVersion.ParseAon9(chunkContentReader);
            uint shaderSize                   = chunkContentReader.ReadUInt32();
            var  shaderOffset                 = chunkContentReader.ReadUInt32();
            var  cbMappingCount               = chunkContentReader.ReadUInt16();
            var  cbMappingOffset              = chunkContentReader.ReadUInt16();
            var  loopRegisterMappingCount     = chunkContentReader.ReadUInt16();
            var  loopRegisterMappingOffset    = chunkContentReader.ReadUInt16();
            var  unk0MappingCount             = chunkContentReader.ReadUInt16();
            var  unk0MappingOffset            = chunkContentReader.ReadUInt16();
            var  samplerMappingCount          = chunkContentReader.ReadUInt16();
            var  samplerMappingOffset         = chunkContentReader.ReadUInt16();
            var  runtimeConstantMappingCount  = chunkContentReader.ReadUInt16();
            var  runtimeConstantMappingOffset = chunkContentReader.ReadUInt16();

            if (cbMappingCount > 0)
            {
                var mappingReader = chunkContentReader.CopyAtOffset(cbMappingOffset);
                for (int i = 0; i < cbMappingCount; i++)
                {
                    result.ConstantBufferMappings.Add(ConstantBufferMapping.Parse(mappingReader));
                }
            }
            if (loopRegisterMappingCount > 0)
            {
                var mappingReader = chunkContentReader.CopyAtOffset(loopRegisterMappingOffset);
                for (int i = 0; i < loopRegisterMappingCount; i++)
                {
                    result.LoopRegisterMappings.Add(LoopRegisterMapping.Parse(mappingReader));
                }
            }
            if (unk0MappingCount > 0)
            {
                Debug.Assert(false, "Unknown Level9 Mapping");
                var mappingReader = chunkContentReader.CopyAtOffset(unk0MappingOffset);
                for (int i = 0; i < unk0MappingCount; i++)
                {
                    result.Unknown0Mappings.Add(Unknown1Mapping.Parse(mappingReader));
                }
            }
            if (samplerMappingCount > 0)
            {
                var mappingReader = chunkContentReader.CopyAtOffset(samplerMappingOffset);
                for (int i = 0; i < samplerMappingCount; i++)
                {
                    result.SamplerMappings.Add(SamplerMapping.Parse(mappingReader));
                }
                // FXC dissassembly sorts sampler mappings
                result.SamplerMappings = result.SamplerMappings
                                         .OrderBy(s => s.TargetSampler)
                                         .ToList();
            }
            if (runtimeConstantMappingCount > 0)
            {
                var mappingReader = chunkContentReader.CopyAtOffset(runtimeConstantMappingOffset);
                for (int i = 0; i < runtimeConstantMappingCount; i++)
                {
                    result.RuntimeConstantMappings.Add(RuntimeConstantMapping.Parse(mappingReader));
                }
            }
            var shaderChunkReader = chunkContentReader.CopyAtOffset((int)shaderOffset);
            var byteCode          = shaderChunkReader.ReadBytes((int)shaderSize);

            using (var memoryStream = new MemoryStream(byteCode))
            {
                result.ShaderModel = DX9Shader.ShaderReader.ReadShader(memoryStream);
            }
            return(result);
        }