public MaterialMaterialEntry FIllMatMatEntryPropertiesPart1(MaterialMaterialEntry MME, MaterialEntry ParentMat, BinaryReader bnr, int OffsetToStart, int ID)
        {
            MME.Index    = ID;
            MME.TypeHash = ByteUtilitarian.BytesToStringL2R(bnr.ReadBytes(4).ToList(), MME.TypeHash);

            //Gets the Material type.
            MME.MatType = CFGHandler.ArchiveHashToName(MME.MatType, MME.TypeHash);

            MME.UnknownField04 = bnr.ReadInt32();
            byte[] NameHashBytes = bnr.ReadBytes(4);
            MME.NameHash = ByteUtilitarian.BytesToStringL2R(NameHashBytes.ToList(), MME.TypeHash);
            NameTemp     = BitConverter.ToUInt32(NameHashBytes, 0);

            //ShaderObjects.
            MME.BlendState        = new MatShaderObject();
            MME.DepthStencilState = new MatShaderObject();
            MME.RasterizerState   = new MatShaderObject();
            MME.CmdBufferSize     = bnr.ReadInt32();

            byte[] ShadeTemp = new byte[4];
            ShadeTemp = bnr.ReadBytes(4);
            uint ShadeUInt = BitConverter.ToUInt32(ShadeTemp, 0);

            MME.BlendState.Index = ShadeUInt & 0x00000FFF;
            MME.BlendState.Hash  = "";
            MME.BlendState.Hash  = CFGHandler.ShaderHashToName(MME.BlendState.Hash, Convert.ToInt32(MME.BlendState.Index));

            ShadeTemp = bnr.ReadBytes(4);
            ShadeUInt = BitConverter.ToUInt32(ShadeTemp, 0);
            MME.DepthStencilState.Index = ShadeUInt & 0x00000FFF;
            MME.DepthStencilState.Hash  = "";
            MME.DepthStencilState.Hash  = CFGHandler.ShaderHashToName(MME.DepthStencilState.Hash, Convert.ToInt32(MME.DepthStencilState.Index));


            ShadeTemp = bnr.ReadBytes(4);
            ShadeUInt = BitConverter.ToUInt32(ShadeTemp, 0);
            MME.RasterizerState.Index   = (ShadeUInt & 0x00000FFF);
            MME.RasterizerState.Hash    = "";
            MME.RasterizerState.Hash    = CFGHandler.ShaderHashToName(MME.RasterizerState.Hash, Convert.ToInt32(MME.RasterizerState.Index));
            MME.MaterialCommandListInfo = new MaterialCmdListInfo();

            //The Material Command List Info.
            ShadeTemp = bnr.ReadBytes(4);
            ShadeUInt = BitConverter.ToUInt32(ShadeTemp, 0);
            MME.MaterialCommandListInfo.Count   = Convert.ToInt32(ShadeUInt & 0xFFF);
            MME.MaterialCommandListInfo.Unknown = Convert.ToInt32(ShadeUInt & 0xFFFF000);
            MME.MaterialinfoFlags = ByteUtilitarian.BytesToStringL2R(bnr.ReadBytes(4).ToList(), MME.MaterialinfoFlags);
            MME.UnknownField24    = bnr.ReadInt32();
            MME.UnknownField28    = bnr.ReadInt32();
            MME.UnknownField2C    = bnr.ReadInt32();
            MME.UnknownField30    = bnr.ReadInt32();
            MME.AnimDataSize      = bnr.ReadInt32();
            MME.CmdListOffset     = Convert.ToInt32(bnr.ReadInt64());
            MME.AnimDataOffset    = Convert.ToInt32(bnr.ReadInt64());
            OffsetToStart         = Convert.ToInt32(bnr.BaseStream.Position);

            return(MME);
        }
        public MaterialMaterialEntry FIllMatMatEntryPropertiesPart2(MaterialMaterialEntry MME, MaterialEntry ParentMat, BinaryReader bnr, int OffsetToStart, int ID)
        {
            bnr.BaseStream.Position = MME.CmdListOffset;
            MME.MaterialCommands    = new List <MatCmd>();
            ulong ShadeUInt  = 0;
            long  UnionUTemp = 0;

            byte[] ShadeTemp = new byte[4];
            byte[] UnionTemp = new byte[8];


            for (int i = 0; i < MME.MaterialCommandListInfo.Count; i++)
            {
                MatCmd Command = new MatCmd();

                //For the Command Info.
                ShadeTemp = bnr.ReadBytes(4);
                uint CmdInfoTemp = BitConverter.ToUInt32(ShadeTemp, 0);
                Command.MCInfo                   = new MatCmdInfo();
                Command.MCInfo.CmdFlag           = ((ENumerators.IMatType)Convert.ToInt32(ShadeUInt & 0x1f)).ToString();
                Command.MCInfo.SomeValue         = Convert.ToInt32(ShadeUInt & 0x0000FFF0);
                Command.MCInfo.ShaderObjectIndex = Convert.ToInt32((ShadeUInt >> 20) & 0x1fff);

                Command.SomeField04 = bnr.ReadInt32();

                //For the Union. Uggggh.
                //0x0000000F
                UnionTemp  = bnr.ReadBytes(8);
                UnionUTemp = BitConverter.ToInt64(UnionTemp, 0);
                Command.MaterialCommandValue = new MatCmdData();
                Command.MaterialCommandValue.ConstantBufferDataOffset = Convert.ToUInt64(UnionUTemp);
                Command.MaterialCommandValue.VShaderObjectID          = new MatShaderObject();
                Command.MaterialCommandValue.VShaderObjectID.Index    = (BitConverter.ToUInt64(UnionTemp, 0) & 0x00000FFF);
                Command.MaterialCommandValue.VShaderObjectID.Hash     = "";
                Command.MaterialCommandValue.VShaderObjectID.Hash     = CFGHandler.ShaderHashToName(Command.MaterialCommandValue.VShaderObjectID.Hash, Convert.ToInt32(Command.MaterialCommandValue.VShaderObjectID.Index));
                Command.MaterialCommandValue.TextureIndex             = BitConverter.ToInt32(UnionTemp, 0);

                Command.MaterialCommandValue.VShaderObjectID = new MatShaderObject();
                ShadeTemp = bnr.ReadBytes(4);
                Command.MaterialCommandValue.VShaderObjectID.Index = (BitConverter.ToUInt32(ShadeTemp, 0) & 0x00000FFF);
                Command.MaterialCommandValue.VShaderObjectID.Hash  = "";
                Command.MaterialCommandValue.VShaderObjectID.Hash  = CFGHandler.ShaderHashToName(MME.DepthStencilState.Hash, Convert.ToInt32(MME.DepthStencilState.Index));

                Command.SomeField14 = bnr.ReadInt32();

                MME.MaterialCommands.Add(Command);
            }

            MME.ConstantBufferData = bnr.ReadBytes(MME.CmdBufferSize);

            return(MME);
        }
Exemplo n.º 3
0
        public static MaterialEntry BuildMatEntry(BinaryReader MBR, MaterialEntry MATEntry)
        {
            //Header variables.
            MATEntry.Magic          = ByteUtilitarian.BytesToStringL2R(MBR.ReadBytes(4).ToList(), MATEntry.Magic);
            MATEntry.SomethingCount = MBR.ReadInt32();
            MATEntry.MaterialCount  = MBR.ReadInt32();
            MATEntry.TextureCount   = MBR.ReadInt32();
            MATEntry.WeirdHash      = ByteUtilitarian.BytesToStringL2R(MBR.ReadBytes(4).ToList(), MATEntry.Magic);
            MATEntry.Field14        = MBR.ReadInt32();
            MATEntry.TextureOffset  = MBR.ReadInt32();
            MBR.BaseStream.Position = MBR.BaseStream.Position + 4;
            MATEntry.MaterialOffset = MBR.ReadInt32();
            MBR.BaseStream.Position = MBR.BaseStream.Position + 4;

            //For the Texture References.
            MATEntry.Textures       = new List <MaterialTextureReference>();
            MBR.BaseStream.Position = MATEntry.TextureOffset;
            for (int i = 0; i < MATEntry.TextureCount; i++)
            {
                MaterialTextureReference TexTemp = new MaterialTextureReference();
                TexTemp = TexTemp.FillMaterialTexReference(MATEntry, i, MBR, TexTemp);
                MATEntry.Textures.Add(TexTemp);
            }

            //Now for the Materials themselves.

            MATEntry.Materials = new List <MaterialMaterialEntry>();
            byte[] ShadeTemp  = new byte[4];
            int    PrevOffset = Convert.ToInt32(MBR.BaseStream.Position);

            //uint ShadeUInt;
            //byte[] NameHashBytes;
            //uint NameTemp;


            //Part 1 of Materials.
            for (int i = 0; i < MATEntry.MaterialCount; i++)
            {
                MaterialMaterialEntry MMEntry = new MaterialMaterialEntry();
                MMEntry = MMEntry.FIllMatMatEntryPropertiesPart1(MMEntry, MATEntry, MBR, PrevOffset, i);
                MMEntry = MMEntry.FIllMatMatEntryPropertiesPart2(MMEntry, MATEntry, MBR, PrevOffset, i);

                MATEntry.Materials.Add(MMEntry);
                PrevOffset = PrevOffset + 72;
                MBR.BaseStream.Position = PrevOffset;
            }

            return(MATEntry);
        }