示例#1
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            ShaderArchiveName = loader.LoadString();
            ShadingModelName  = loader.LoadString();

            if (loader.IsSwitch)
            {
                AttribAssigns  = loader.LoadDictValues <ResString>();
                SamplerAssigns = loader.LoadDictValues <ResString>();
                ShaderOptions  = loader.LoadDictValues <ResString>();
                Revision       = loader.ReadUInt32();
                byte   numAttribAssign  = loader.ReadByte();
                byte   numSamplerAssign = loader.ReadByte();
                ushort numShaderOption  = loader.ReadUInt16();
            }
            else
            {
                Revision = loader.ReadUInt32();
                byte   numAttribAssign  = loader.ReadByte();
                byte   numSamplerAssign = loader.ReadByte();
                ushort numShaderOption  = loader.ReadUInt16();
                AttribAssigns  = loader.LoadDict <ResString>();
                SamplerAssigns = loader.LoadDict <ResString>();
                ShaderOptions  = loader.LoadDict <ResString>();
            }
        }
示例#2
0
        // TODO: Methods to access ShaderParam variable values.

        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            Name  = loader.LoadString();
            Flags = loader.ReadEnum <MaterialFlags>(true);
            ushort idx                    = loader.ReadUInt16();
            ushort numRenderInfo          = loader.ReadUInt16();
            byte   numSampler             = loader.ReadByte();
            byte   numTextureRef          = loader.ReadByte();
            ushort numShaderParam         = loader.ReadUInt16();
            ushort numShaderParamVolatile = loader.ReadUInt16();
            ushort sizParamSource         = loader.ReadUInt16();
            ushort sizParamRaw            = loader.ReadUInt16();
            ushort numUserData            = loader.ReadUInt16();

            RenderInfos  = loader.LoadDict <RenderInfo>();
            RenderState  = loader.Load <RenderState>();
            ShaderAssign = loader.Load <ShaderAssign>();
            TextureRefs  = loader.LoadList <TextureRef>(numTextureRef);
            uint ofsSamplerList = loader.ReadOffset(); // Only use dict.

            Samplers = loader.LoadDict <Sampler>();
            uint ofsShaderParamList = loader.ReadOffset(); // Only use dict.

            ShaderParams    = loader.LoadDict <ShaderParam>();
            ShaderParamData = loader.LoadCustom(() => loader.ReadBytes(sizParamSource));
            UserData        = loader.LoadDict <UserData>();
            VolatileFlags   = loader.LoadCustom(() => loader.ReadBytes((int)Math.Ceiling(numShaderParam / 8f)));
            uint userPointer = loader.ReadUInt32();
        }
示例#3
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            _flags         = loader.ReadUInt32();
            Name           = loader.LoadString();
            BeginRotate    = loader.ReadByte();
            BeginTranslate = loader.ReadByte();
            byte numCurve = loader.ReadByte();

            BeginBaseTranslate = loader.ReadByte();
            BeginCurve         = loader.ReadInt32();
            Curves             = loader.LoadList <AnimCurve>(numCurve);
            BaseData           = loader.LoadCustom(() => new BoneAnimData(loader, FlagsBase));
        }
示例#4
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            if (loader.IsSwitch)
            {
                Switch.LightAnimParser.Read((Switch.Core.ResFileSwitchLoader)loader, this);
            }
            else
            {
                Flags = loader.ReadEnum <LightAnimFlags>(true);
                ushort numUserData = loader.ReadUInt16();
                FrameCount = loader.ReadInt32();
                byte numCurve = loader.ReadByte();
                LightTypeIndex        = loader.ReadSByte();
                DistanceAttnFuncIndex = loader.ReadSByte();
                AngleAttnFuncIndex    = loader.ReadSByte();
                BakedSize             = loader.ReadUInt32();
                Name                 = loader.LoadString();
                LightTypeName        = loader.LoadString();
                DistanceAttnFuncName = loader.LoadString();
                AngleAttnFuncName    = loader.LoadString();
                Curves               = loader.LoadList <AnimCurve>(numCurve);
                BaseData             = loader.LoadCustom(() => new LightAnimData(loader, AnimatedFields));
                UserData             = loader.LoadDict <UserData>();
            }
        }
        // TODO: Methods to retrieve the strongly-typed shader param value.

        // ---- METHODS ------------C:\Users\Nathan\Documents\GitHub\NintenTools.Bfres-master\NintenTools.Bfres\src\Syroot.NintenTools.Bfres\ExternalFile\------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            Type = loader.ReadEnum <ShaderParamType>(true);
            byte sizData = loader.ReadByte();

            if (sizData != (byte)DataSize && sizData > DataSize)
            {
                UsePadding    = true;
                PaddingLength = sizData - (byte)DataSize;
            }

            DataOffset = loader.ReadUInt16();
            offset     = loader.ReadInt32(); // Uniform variable offset.
            if (loader.ResFile.Version >= 0x03040000)
            {
                callbackPointer = loader.ReadUInt32();
                DependedIndex   = loader.ReadUInt16();
                DependIndex     = loader.ReadUInt16();
            }
            else if (loader.ResFile.Version >= 0x03030000 &&
                     loader.ResFile.Version < 0x03040000)
            {
                callbackPointer = loader.ReadUInt32();
                DependedIndex   = loader.ReadUInt16();
                DependIndex     = loader.ReadUInt16();
                uint FMATOffset = loader.ReadUInt32(); //Why does this have this????
            }
            Name = loader.LoadString();
        }
示例#6
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            Name   = loader.LoadString();
            Path   = loader.LoadString();
            _flags = loader.ReadUInt16();
            ushort numUserData = loader.ReadUInt16();

            FrameCount = loader.ReadInt32();
            ushort numAnim  = loader.ReadUInt16();
            ushort numCurve = loader.ReadUInt16();

            BakedSize    = loader.ReadUInt32();
            BindModel    = loader.Load <Model>();
            BindIndices  = loader.LoadCustom(() => loader.ReadUInt16s(numAnim));
            Names        = loader.LoadCustom(() => loader.LoadStrings(numAnim)); // Offset to name list.
            Curves       = loader.LoadList <AnimCurve>(numCurve);
            BaseDataList = loader.LoadCustom(() =>
            {
                bool[] baseData = new bool[numAnim];
                int i           = 0;
                while (i < numAnim)
                {
                    byte b = loader.ReadByte();
                    for (int j = 0; j < 8 && i < numAnim; j++)
                    {
                        baseData[i++] = b.GetBit(j);
                    }
                }
                return(baseData);
            });
            UserData = loader.LoadDict <UserData>();
        }
示例#7
0
        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            byte   numVertexAttrib = loader.ReadByte();
            byte   numBuffer       = loader.ReadByte();
            ushort idx             = loader.ReadUInt16();
            uint   vertexCount     = loader.ReadUInt32();

            VertexSkinCount = loader.ReadByte();
            loader.Seek(3);
            uint ofsVertexAttribList = loader.ReadOffset(); // Only load dict.

            Attributes = loader.LoadDict <VertexAttrib>();
            Buffers    = loader.LoadList <Buffer>(numBuffer);
            uint userPointer = loader.ReadUInt32();
        }
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            Name        = loader.LoadString();
            BufferIndex = loader.ReadByte();
            loader.Seek(1);
            Offset = loader.ReadUInt16();
            Format = loader.ReadEnum <GX2AttribFormat>(true);
        }
示例#9
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            TexSampler = new TexSampler(loader.ReadUInt32s(3));
            uint handle = loader.ReadUInt32();

            Name = loader.LoadString();
            byte idx = loader.ReadByte();

            loader.Seek(3);
        }
示例#10
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            if (loader.IsSwitch)
            {
                Switch.VisibilityAnimParser.Read((Switch.Core.ResFileSwitchLoader)loader, this);
            }
            else
            {
                Name   = loader.LoadString();
                Path   = loader.LoadString();
                _flags = loader.ReadUInt16();
                ushort numAnim  = 0;
                ushort numCurve = 0;
                if (loader.ResFile.Version >= 0x03040000)
                {
                    ushort numUserData = loader.ReadUInt16();
                    FrameCount = loader.ReadInt32();
                    numAnim    = loader.ReadUInt16();
                    numCurve   = loader.ReadUInt16();
                    BakedSize  = loader.ReadUInt32();
                }
                else
                {
                    FrameCount = loader.ReadInt16();
                    numAnim    = loader.ReadUInt16();
                    numCurve   = loader.ReadUInt16();
                    ushort numUserData = loader.ReadUInt16();
                    BakedSize = loader.ReadUInt32();
                    int padding2 = loader.ReadInt16();
                }
                BindModel     = loader.Load <Model>();
                BindIndices   = loader.LoadCustom(() => loader.ReadUInt16s(numAnim));
                Names         = loader.LoadCustom(() => loader.LoadStrings(numAnim)); // Offset to name list.
                Curves        = loader.LoadList <AnimCurve>(numCurve);
                baseDataBytes = new List <byte>();
                BaseDataList  = loader.LoadCustom(() =>
                {
                    bool[] baseData = new bool[numAnim];
                    int i           = 0;
                    while (i < numAnim)
                    {
                        byte b = loader.ReadByte();
                        baseDataBytes.Add(b);
                        for (int j = 0; j < 8 && i < numAnim; j++)
                        {
                            baseData[i] = b.GetBit(j);
                        }
                        i++;
                    }
                    return(baseData);
                });
                UserData = loader.LoadDict <UserData>();
            }
        }
示例#11
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            if (loader.IsSwitch)
            {
                Name = loader.LoadString();
                uint   CurveOffset             = loader.ReadOffset();
                uint   BaseDataOffset          = loader.ReadOffset();
                uint   KeyShapeAnimInfosOffset = loader.ReadOffset();
                ushort numCurve        = loader.ReadUInt16();
                ushort numKeyShapeAnim = loader.ReadUInt16();
                BeginCurve        = loader.ReadInt32();
                BeginKeyShapeAnim = loader.ReadInt32();
                loader.Seek(4); //Padding

                KeyShapeAnimInfos = loader.LoadList <KeyShapeAnimInfo>(numKeyShapeAnim, KeyShapeAnimInfosOffset);
                Curves            = loader.LoadList <AnimCurve>(numCurve, CurveOffset);
                BaseDataList      = loader.LoadCustom(() => loader.ReadSingles(numKeyShapeAnim - 1), BaseDataOffset); // Without base shape.
            }
            else
            {
                ushort numCurve;
                ushort numKeyShapeAnim;
                if (loader.ResFile.Version >= 0x03040000)
                {
                    numCurve        = loader.ReadUInt16();
                    numKeyShapeAnim = loader.ReadUInt16();
                }
                else
                {
                    numCurve        = loader.ReadByte();
                    numKeyShapeAnim = loader.ReadByte();
                    unk             = loader.ReadUInt16();
                }

                BeginCurve        = loader.ReadInt32();
                BeginKeyShapeAnim = loader.ReadInt32();
                Name = loader.LoadString();
                KeyShapeAnimInfos = loader.LoadList <KeyShapeAnimInfo>(numKeyShapeAnim);
                Curves            = loader.LoadList <AnimCurve>(numCurve);
                BaseDataList      = loader.LoadCustom(() => loader.ReadSingles(numKeyShapeAnim - 1)); // Without base shape.
            }
        }
示例#12
0
 void IResData.Load(ResFileLoader loader)
 {
     loader.CheckSignature(_signature);
     if (loader.IsSwitch)
     {
         Switch.VertexBufferParser.Load((Switch.Core.ResFileSwitchLoader)loader, this);
     }
     else
     {
         byte   numVertexAttrib = loader.ReadByte();
         byte   numBuffer       = loader.ReadByte();
         ushort idx             = loader.ReadUInt16();
         uint   vertexCount     = loader.ReadUInt32();
         VertexSkinCount = loader.ReadByte();
         loader.Seek(3);
         uint ofsVertexAttribList = loader.ReadOffset(); // Only load dict.
         Attributes = loader.LoadDict <VertexAttrib>();
         Buffers    = loader.LoadList <Buffer>(numBuffer);
         uint userPointer = loader.ReadUInt32();
     }
 }
示例#13
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            Name  = loader.LoadString();
            Flags = loader.ReadEnum <ShapeFlags>(true);
            ushort idx = loader.ReadUInt16();

            MaterialIndex     = loader.ReadUInt16();
            BoneIndex         = loader.ReadUInt16();
            VertexBufferIndex = loader.ReadUInt16();
            ushort numSkinBoneIndex = loader.ReadUInt16();

            VertexSkinCount = loader.ReadByte();
            byte numMesh     = loader.ReadByte();
            byte numKeyShape = loader.ReadByte();

            TargetAttribCount = loader.ReadByte();
            ushort numSubMeshBoundingNodes = loader.ReadUInt16(); // Padding in engine.

            Radius          = loader.ReadSingle();
            VertexBuffer    = loader.Load <VertexBuffer>();
            Meshes          = loader.LoadList <Mesh>(numMesh);
            SkinBoneIndices = loader.LoadCustom(() => loader.ReadUInt16s(numSkinBoneIndex));
            KeyShapes       = loader.LoadDict <KeyShape>();
            // TODO: At least BotW has more data following the Boundings, or that are no boundings at all.
            if (numSubMeshBoundingNodes == 0)
            {
                // Compute the count differently if the node count was padding.
                SubMeshBoundings = loader.LoadCustom(() => loader.ReadBoundings(Meshes[0].SubMeshes.Count + 1));
            }
            else
            {
                SubMeshBoundingNodes   = loader.LoadList <BoundingNode>(numSubMeshBoundingNodes);
                SubMeshBoundings       = loader.LoadCustom(() => loader.ReadBoundings(numSubMeshBoundingNodes));
                SubMeshBoundingIndices = loader.LoadCustom(() => loader.ReadUInt16s(numSubMeshBoundingNodes));
            }
            uint userPointer = loader.ReadUInt32();
        }
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            ushort numCurve;
            ushort numKeyShapeAnim;

            if (loader.ResFile.Version >= 0x03040000)
            {
                numCurve        = loader.ReadUInt16();
                numKeyShapeAnim = loader.ReadUInt16();
            }
            else
            {
                numCurve        = loader.ReadByte();
                numKeyShapeAnim = loader.ReadByte();
                unk             = loader.ReadUInt16();
            }

            BeginCurve        = loader.ReadInt32();
            BeginKeyShapeAnim = loader.ReadInt32();
            Name = loader.LoadString();
            KeyShapeAnimInfos = loader.LoadList <KeyShapeAnimInfo>(numKeyShapeAnim);
            Curves            = loader.LoadList <AnimCurve>(numCurve);
            BaseDataList      = loader.LoadCustom(() => loader.ReadSingles(numKeyShapeAnim - 1)); // Without base shape.
        }
示例#15
0
        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            Flags = loader.ReadEnum <CameraAnimFlags>(true);
            loader.Seek(2);
            FrameCount = loader.ReadInt32();
            byte numCurve = loader.ReadByte();

            loader.Seek(1);
            ushort numUserData = loader.ReadUInt16();

            BakedSize = loader.ReadUInt32();
            Name      = loader.LoadString();
            Curves    = loader.LoadList <AnimCurve>(numCurve);
            BaseData  = loader.LoadCustom(() => new CameraAnimData(loader));
            UserData  = loader.LoadDict <UserData>();
        }
示例#16
0
 void IResData.Load(ResFileLoader loader)
 {
     if (loader.IsSwitch)
     {
         sampler = new SamplerSwitch();
         ((IResData)sampler).Load(loader);
         TexSampler = sampler.ToTexSampler();
     }
     else
     {
         TexSampler = new TexSampler(loader.ReadUInt32s(3));
         uint handle = loader.ReadUInt32();
         Name = loader.LoadString();
         byte idx = loader.ReadByte();
         loader.Seek(3);
     }
 }
示例#17
0
        void IResData.Load(ResFileLoader loader)
        {
            if (loader.IsSwitch)
            {
                Name = loader.LoadString();
                uint CurveOffset    = loader.ReadOffset();
                uint BaseDataOffset = loader.ReadOffset();
                if (loader.ResFile.VersionMajor2 == 9)
                {
                    long unk1 = loader.ReadInt64();
                    long unk2 = loader.ReadInt64();
                }
                _flags         = loader.ReadUInt32();
                BeginRotate    = loader.ReadByte();
                BeginTranslate = loader.ReadByte();
                byte numCurve = loader.ReadByte();
                BeginBaseTranslate = loader.ReadByte();
                BeginCurve         = loader.ReadInt32();
                int padding = loader.ReadInt32();

                BaseData = loader.LoadCustom(() => new BoneAnimData(loader, FlagsBase), BaseDataOffset);
                Curves   = loader.LoadList <AnimCurve>(numCurve, CurveOffset);
            }
            else
            {
                _flags         = loader.ReadUInt32();
                Name           = loader.LoadString();
                BeginRotate    = loader.ReadByte();
                BeginTranslate = loader.ReadByte();
                byte numCurve = loader.ReadByte();
                BeginBaseTranslate = loader.ReadByte();
                BeginCurve         = loader.ReadByte();
                loader.Seek(3);
                Curves   = loader.LoadList <AnimCurve>(numCurve);
                BaseData = loader.LoadCustom(() => new BoneAnimData(loader, FlagsBase));
            }
        }
示例#18
0
 void IResData.Load(ResFileLoader loader)
 {
     WrapModeU       = (TexClamp)loader.ReadByte();
     WrapModeV       = (TexClamp)loader.ReadByte();
     WrapModeW       = (TexClamp)loader.ReadByte();
     CompareFunc     = (CompareFunction)loader.ReadByte();
     BorderColorType = (TexBorderType)loader.ReadByte();
     Anisotropic     = (MaxAnisotropic)loader.ReadByte();
     _filterFlags    = loader.ReadUInt16();
     MinLOD          = loader.ReadSingle();
     MaxLOD          = loader.ReadSingle();
     LODBias         = loader.ReadSingle();
     loader.Seek(12);
 }
示例#19
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            if (loader.IsSwitch)
            {
                Name             = loader.LoadString();
                loader.ByteOrder = ByteOrder.BigEndian;
                Format           = ConvertToGX2(loader.ReadEnum <SwitchAttribFormat>(true));
                loader.ByteOrder = ByteOrder.LittleEndian;
                loader.Seek(2); //padding
                Offset      = loader.ReadUInt16();
                BufferIndex = (byte)loader.ReadUInt16();
            }
            else
            {
                Name        = loader.LoadString();
                BufferIndex = loader.ReadByte();
                loader.Seek(1);
                Offset = loader.ReadUInt16();
                Format = loader.ReadEnum <GX2AttribFormat>(true);
            }
        }
        // TODO: Methods to retrieve the strongly-typed shader param value.

        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            Type = loader.ReadEnum <ShaderParamType>(true);
            if (loader.ResFile.Version >= 0x03030000)
            {
                byte sizData = loader.ReadByte();
                DataOffset = loader.ReadUInt16();
                int  offset          = loader.ReadInt32(); // Uniform variable offset.
                uint callbackPointer = loader.ReadUInt32();
                DependedIndex = loader.ReadUInt16();
                DependIndex   = loader.ReadUInt16();
                Name          = loader.LoadString();
            }
            else
            {
                // GUESS
                loader.Seek(1);
                DataOffset = loader.ReadUInt16();
                int offset = loader.ReadInt32(); // Uniform variable offset.
                Name = loader.LoadString();
            }
        }
示例#21
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            if (loader.IsSwitch)
            {
                Switch.CameraAnimParser.Read((Switch.Core.ResFileSwitchLoader)loader, this);
            }
            else
            {
                Flags = loader.ReadEnum <CameraAnimFlags>(false);
                loader.Seek(2);
                FrameCount = loader.ReadInt32();
                byte numCurve = loader.ReadByte();
                loader.Seek(1);
                ushort numUserData = loader.ReadUInt16();
                BakedSize = loader.ReadUInt32();
                Name      = loader.LoadString();
                Curves    = loader.LoadList <AnimCurve>(numCurve);
                BaseData  = loader.LoadCustom(() => new CameraAnimData(loader));
                UserData  = loader.LoadDict <UserData>();
            }
        }
示例#22
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            _flags = loader.ReadUInt16();
            ushort numKey = loader.ReadUInt16();

            AnimDataOffset = loader.ReadUInt32();
            StartFrame     = loader.ReadSingle();
            EndFrame       = loader.ReadSingle();
            Scale          = loader.ReadSingle();
            Offset         = loader.ReadSingle();
            if (loader.ResFile.Version >= 0x03040000)
            {
                Delta = loader.ReadSingle();
            }
            Frames = loader.LoadCustom(() =>
            {
                switch (FrameType)
                {
                case AnimCurveFrameType.Single:
                    return(loader.ReadSingles(numKey));

                case AnimCurveFrameType.Decimal10x5:
                    float[] dec10x5Frames = new float[numKey];
                    for (int i = 0; i < numKey; i++)
                    {
                        dec10x5Frames[i] = (float)loader.ReadDecimal10x5();
                    }
                    return(dec10x5Frames);

                case AnimCurveFrameType.Byte:
                    float[] byteFrames = new float[numKey];
                    for (int i = 0; i < numKey; i++)
                    {
                        byteFrames[i] = loader.ReadByte();
                    }
                    return(byteFrames);

                default:
                    throw new ResException($"Invalid {nameof(FrameType)}.");
                }
            });
            Keys = loader.LoadCustom(() =>
            {
                int elementsPerKey = ElementsPerKey;
                float[,] keys      = new float[numKey, elementsPerKey];
                switch (KeyType)
                {
                case AnimCurveKeyType.Single:
                    for (int i = 0; i < numKey; i++)
                    {
                        keys[i, 0] = loader.ReadSingle();
                    }
                    break;

                case AnimCurveKeyType.Int16:
                    for (int i = 0; i < numKey; i++)
                    {
                        for (int j = 0; j < elementsPerKey; j++)
                        {
                            keys[i, j] = loader.ReadUInt16();
                        }
                    }
                    break;

                case AnimCurveKeyType.SByte:
                    for (int i = 0; i < numKey; i++)
                    {
                        for (int j = 0; j < elementsPerKey; j++)
                        {
                            keys[i, j] = loader.ReadSByte();
                        }
                    }
                    break;

                default:
                    throw new ResException($"Invalid {nameof(KeyType)}.");
                }
                return(keys);
            });
        }
示例#23
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            Dim      = loader.ReadEnum <GX2SurfaceDim>(true);
            Width    = loader.ReadUInt32();
            Height   = loader.ReadUInt32();
            Depth    = loader.ReadUInt32();
            MipCount = loader.ReadUInt32();
            Format   = loader.ReadEnum <GX2SurfaceFormat>(true);
            AAMode   = loader.ReadEnum <GX2AAMode>(true);
            Use      = loader.ReadEnum <GX2SurfaceUse>(true);
            uint sizData      = loader.ReadUInt32();
            uint imagePointer = loader.ReadUInt32();
            uint sizMipData   = loader.ReadUInt32();
            uint mipPointer   = loader.ReadUInt32();

            TileMode       = loader.ReadEnum <GX2TileMode>(true);
            Swizzle        = loader.ReadUInt32();
            Alignment      = loader.ReadUInt32();
            Pitch          = loader.ReadUInt32();
            MipOffsets     = loader.ReadUInt32s(13);
            ViewMipFirst   = loader.ReadUInt32();
            ViewMipCount   = loader.ReadUInt32();
            ViewSliceFirst = loader.ReadUInt32();
            ViewSliceCount = loader.ReadUInt32();
            CompSelR       = loader.ReadEnum <GX2CompSel>(true);
            CompSelG       = loader.ReadEnum <GX2CompSel>(true);
            CompSelB       = loader.ReadEnum <GX2CompSel>(true);
            CompSelA       = loader.ReadEnum <GX2CompSel>(true);
            Regs           = loader.ReadUInt32s(5);
            uint handle = loader.ReadUInt32();

            ArrayLength = loader.ReadByte(); // Possibly just a byte.
            loader.Seek(3, System.IO.SeekOrigin.Current);
            Name = loader.LoadString();
            Path = loader.LoadString();

            // Load texture data.
            bool?isMainTextureFile
                = loader.ResFile.Name.Contains(".Tex1") ? new bool?(true)
                : loader.ResFile.Name.Contains(".Tex2") ? new bool?(false)
                : null;

            switch (isMainTextureFile)
            {
            case true:
                Data = loader.LoadCustom(() => loader.ReadBytes((int)sizData));
                loader.ReadOffset();     // MipData not used.
                break;

            case false:
                MipData = loader.LoadCustom(() => loader.ReadBytes((int)sizMipData));
                loader.ReadOffset();     // Data not used.
                break;

            default:
                Data    = loader.LoadCustom(() => loader.ReadBytes((int)sizData));
                MipData = loader.LoadCustom(() => loader.ReadBytes((int)sizMipData));
                break;
            }

            UserData = loader.LoadDict <UserData>();
            ushort numUserData = loader.ReadUInt16();

            loader.Seek(2);
        }
示例#24
0
        void IResData.Load(ResFileLoader loader)
        {
            long   FrameArrayOffset = 0;
            long   KeyArrayOffset   = 0;
            ushort numKey           = 0;

            if (loader.IsSwitch)
            {
                FrameArrayOffset = loader.ReadOffset();
                KeyArrayOffset   = loader.ReadOffset();
                _flags           = loader.ReadUInt16();
                numKey           = loader.ReadUInt16();
                AnimDataOffset   = loader.ReadUInt32();
                StartFrame       = loader.ReadSingle();
                EndFrame         = loader.ReadSingle();
                Scale            = loader.ReadSingle();
                Offset           = loader.ReadSingle();
                Delta            = loader.ReadSingle();
                int padding = loader.ReadInt32();
            }
            else
            {
                _flags         = loader.ReadUInt16();
                numKey         = loader.ReadUInt16();
                AnimDataOffset = loader.ReadUInt32();
                StartFrame     = loader.ReadSingle();
                EndFrame       = loader.ReadSingle();
                Scale          = loader.ReadSingle();
                Offset         = loader.ReadSingle();
                if (loader.ResFile.Version >= 0x03040000)
                {
                    Delta = loader.ReadSingle();
                }
                FrameArrayOffset = loader.ReadOffset();
                KeyArrayOffset   = loader.ReadOffset();
            }

            Frames = loader.LoadCustom(() =>
            {
                switch (FrameType)
                {
                case AnimCurveFrameType.Single:
                    return(loader.ReadSingles(numKey));

                case AnimCurveFrameType.Decimal10x5:
                    float[] dec10x5Frames = new float[numKey];
                    for (int i = 0; i < numKey; i++)
                    {
                        dec10x5Frames[i] = (float)loader.ReadDecimal10x5();
                    }
                    return(dec10x5Frames);

                case AnimCurveFrameType.Byte:
                    float[] byteFrames = new float[numKey];
                    for (int i = 0; i < numKey; i++)
                    {
                        byteFrames[i] = loader.ReadByte();
                    }
                    return(byteFrames);

                default:
                    throw new ResException($"Invalid {nameof(FrameType)}.");
                }
            }, (uint)FrameArrayOffset);
            Keys = loader.LoadCustom(() =>
            {
                int elementsPerKey = ElementsPerKey;
                float[,] keys      = new float[numKey, elementsPerKey];
                switch (KeyType)
                {
                case AnimCurveKeyType.Single:
                    for (int i = 0; i < numKey; i++)
                    {
                        for (int j = 0; j < elementsPerKey; j++)
                        {
                            if (CurveType == AnimCurveType.StepInt || CurveType == AnimCurveType.StepBool)
                            {
                                keys[i, j] = loader.ReadUInt32();
                            }
                            else
                            {
                                keys[i, j] = loader.ReadSingle();
                            }
                        }
                    }
                    break;

                case AnimCurveKeyType.Int16:
                    for (int i = 0; i < numKey; i++)
                    {
                        for (int j = 0; j < elementsPerKey; j++)
                        {
                            keys[i, j] = loader.ReadInt16();
                        }
                    }
                    break;

                case AnimCurveKeyType.SByte:
                    for (int i = 0; i < numKey; i++)
                    {
                        for (int j = 0; j < elementsPerKey; j++)
                        {
                            keys[i, j] = loader.ReadSByte();
                        }
                    }
                    break;

                default:
                    throw new ResException($"Invalid {nameof(KeyType)}.");
                }
                return(keys);
            }, (uint)KeyArrayOffset);

            //Bools use bits to store values.
            if (CurveType == AnimCurveType.StepBool)
            {
                int keyIndex = 0;

                KeyStepBoolData = new bool[numKey];
                for (int i = 0; i < Keys.Length; i++)
                {
                    if (numKey <= keyIndex)
                    {
                        break;
                    }

                    int value = (int)Keys[i, 0];

                    //Bit shift each key value
                    for (int j = 0; j < 32; j++)
                    {
                        if (numKey <= keyIndex)
                        {
                            break;
                        }

                        bool set = (value & 0x1) != 0;
                        value >>= 1;

                        KeyStepBoolData[keyIndex] = set;
                        keyIndex++;
                    }
                }
            }
        }
示例#25
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            if (loader.IsSwitch)
            {
                Switch.ShapeParser.Read((Switch.Core.ResFileSwitchLoader)loader, this);
            }
            else
            {
                Name  = loader.LoadString();
                Flags = loader.ReadEnum <ShapeFlags>(true);
                ushort idx = loader.ReadUInt16();
                MaterialIndex     = loader.ReadUInt16();
                BoneIndex         = loader.ReadUInt16();
                VertexBufferIndex = loader.ReadUInt16();
                ushort numSkinBoneIndex = loader.ReadUInt16();
                VertexSkinCount = loader.ReadByte();
                byte numMesh     = loader.ReadByte();
                byte numKeyShape = loader.ReadByte();
                TargetAttribCount = loader.ReadByte();
                ushort numSubMeshBoundingNodes = loader.ReadUInt16(); // Padding in engine.

                if (loader.ResFile.Version >= 0x04050000)
                {
                    RadiusArray = loader.LoadCustom(() => loader.ReadSingles(numMesh))?.ToList();
                }
                else
                {
                    RadiusArray = loader.ReadSingles(1).ToList();
                }
                VertexBuffer    = loader.Load <VertexBuffer>();
                Meshes          = loader.LoadList <Mesh>(numMesh).ToList();
                SkinBoneIndices = loader.LoadCustom(() => loader.ReadUInt16s(numSkinBoneIndex))?.ToList();
                KeyShapes       = loader.LoadDict <KeyShape>();

                // TODO: At least BotW has more data following the Boundings, or that are no boundings at all.
                if (numSubMeshBoundingNodes == 0)
                {
                    if (loader.ResFile.Version >= 0x04050000)
                    {
                        numSubMeshBoundingNodes = (ushort)(Meshes.Count + Meshes.Sum(x => x.SubMeshes.Count));
                    }
                    else
                    {
                        numSubMeshBoundingNodes = (ushort)(1 + Meshes[0].SubMeshes.Count + 1);
                    }
                    SubMeshBoundings = loader.LoadCustom(() => loader.ReadBoundings(numSubMeshBoundingNodes))?.ToList();
                }
                else
                {
                    SubMeshBoundingNodes   = loader.LoadList <BoundingNode>(numSubMeshBoundingNodes)?.ToList();
                    SubMeshBoundings       = loader.LoadCustom(() => loader.ReadBoundings(numSubMeshBoundingNodes))?.ToList();
                    SubMeshBoundingIndices = loader.LoadCustom(() => loader.ReadUInt16s(numSubMeshBoundingNodes))?.ToList();
                }

                if (SubMeshBoundingNodes == null)
                {
                    SubMeshBoundingNodes = new List <BoundingNode>();
                }
                if (SubMeshBoundings == null)
                {
                    SubMeshBoundings = new List <Bounding>();
                }
                if (SubMeshBoundingIndices == null)
                {
                    SubMeshBoundingIndices = new List <ushort>();
                }

                uint userPointer = loader.ReadUInt32();
            }
        }
示例#26
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            _flags = loader.ReadUInt16();
            ushort numKey = loader.ReadUInt16();

            AnimDataOffset = loader.ReadUInt32();
            StartFrame     = loader.ReadSingle();
            EndFrame       = loader.ReadSingle();
            Scale          = loader.ReadSingle();
            Offset         = loader.ReadSingle();
            if (loader.ResFile.Version >= 0x03040000)
            {
                Delta = loader.ReadSingle();
            }

            Frames = loader.LoadCustom(() =>
            {
                switch (FrameType)
                {
                case AnimCurveFrameType.Single:
                    if (CurveType == AnimCurveType.StepInt)
                    {
                        float[] dec10x5Frame = new float[numKey];
                        for (int i = 0; i < numKey; i++)
                        {
                            dec10x5Frame[i] = loader.ReadUInt32();
                        }
                        return(dec10x5Frame);
                    }
                    else
                    {
                        return(loader.ReadSingles(numKey));
                    }

                case AnimCurveFrameType.Decimal10x5:
                    float[] dec10x5Frames = new float[numKey];
                    for (int i = 0; i < numKey; i++)
                    {
                        dec10x5Frames[i] = (float)loader.ReadDecimal10x5();
                    }
                    return(dec10x5Frames);

                case AnimCurveFrameType.Byte:
                    float[] byteFrames = new float[numKey];
                    for (int i = 0; i < numKey; i++)
                    {
                        byteFrames[i] = loader.ReadByte();
                    }
                    return(byteFrames);

                default:
                    throw new ResException($"Invalid {nameof(FrameType)}.");
                }
            });

            //Bools use bits to store values.
            if (CurveType == AnimCurveType.StepBool)
            {
                int KeyBool = 0;

                if (KeyType == AnimCurveKeyType.Single) //Read them as a int instead of a float
                {
                    KeyBool = loader.LoadCustom(() => loader.ReadInt32());
                }
                else if (KeyType == AnimCurveKeyType.Int16)
                {
                    KeyBool = loader.LoadCustom(() => loader.ReadInt16());
                }
                else if (KeyType == AnimCurveKeyType.SByte)
                {
                    KeyBool = loader.LoadCustom(() => loader.ReadSByte());
                }

                KeyStepBoolData = new bool[numKey];

                for (int i = 0; i < numKey; i++)
                {
                    bool set = (KeyBool & 0x1) != 0;
                    KeyBool >>= 1;

                    KeyStepBoolData[i] = set;
                }
            }
            else
            {
                Keys = loader.LoadCustom(() =>
                {
                    int elementsPerKey = ElementsPerKey;
                    float[,] keys      = new float[numKey, elementsPerKey];
                    switch (KeyType)
                    {
                    case AnimCurveKeyType.Single:
                        for (int i = 0; i < numKey; i++)
                        {
                            for (int j = 0; j < elementsPerKey; j++)
                            {
                                if (CurveType == AnimCurveType.StepInt)
                                {
                                    keys[i, j] = loader.ReadUInt32();
                                }
                                else
                                {
                                    keys[i, j] = loader.ReadSingle();
                                }
                            }
                        }
                        break;

                    case AnimCurveKeyType.Int16:
                        for (int i = 0; i < numKey; i++)
                        {
                            for (int j = 0; j < elementsPerKey; j++)
                            {
                                keys[i, j] = loader.ReadInt16();
                            }
                        }
                        break;

                    case AnimCurveKeyType.SByte:
                        for (int i = 0; i < numKey; i++)
                        {
                            for (int j = 0; j < elementsPerKey; j++)
                            {
                                keys[i, j] = loader.ReadSByte();
                            }
                        }
                        break;

                    default:
                        throw new ResException($"Invalid {nameof(KeyType)}.");
                    }
                    return(keys);
                });
            }
        }