Example #1
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            if (loader.IsSwitch)
            {
                if (loader.ResFile.VersionMajor2 == 9)
                {
                    _flags = loader.ReadUInt32();
                }
                else
                {
                    ((Switch.Core.ResFileSwitchLoader)loader).LoadHeaderBlock();
                }

                long BoneDictOffset  = loader.ReadOffset();
                long BoneArrayOffset = loader.ReadOffset();
                Bones = loader.LoadDictValues <Bone>(BoneDictOffset, BoneArrayOffset);

                uint MatrixToBoneListOffset     = loader.ReadOffset();
                uint InverseModelMatricesOffset = loader.ReadOffset();

                if (loader.ResFile.VersionMajor2 == 8)
                {
                    loader.Seek(16);
                }
                if (loader.ResFile.VersionMajor2 == 9)
                {
                    loader.Seek(8);
                }

                long userPointer = loader.ReadInt64();
                if (loader.ResFile.VersionMajor2 != 9)
                {
                    _flags = loader.ReadUInt32();
                }
                ushort numBone         = loader.ReadUInt16();
                ushort numSmoothMatrix = loader.ReadUInt16();
                ushort numRigidMatrix  = loader.ReadUInt16();
                loader.Seek(6);

                MatrixToBoneList     = loader.LoadCustom(() => loader.ReadUInt16s((numSmoothMatrix + numRigidMatrix)), MatrixToBoneListOffset);
                InverseModelMatrices = loader.LoadCustom(() => loader.ReadMatrix3x4s(numSmoothMatrix), InverseModelMatricesOffset)?.ToList();
            }
            else
            {
                _flags = loader.ReadUInt32();
                ushort numBone         = loader.ReadUInt16();
                ushort numSmoothMatrix = loader.ReadUInt16();
                ushort numRigidMatrix  = loader.ReadUInt16();
                loader.Seek(2);
                Bones = loader.LoadDict <Bone>();
                uint ofsBoneList = loader.ReadOffset(); // Only load dict.
                MatrixToBoneList = loader.LoadCustom(() => loader.ReadUInt16s((numSmoothMatrix + numRigidMatrix)));
                if (loader.ResFile.Version >= 0x03040000)
                {
                    InverseModelMatrices = loader.LoadCustom(() => loader.ReadMatrix3x4s(numSmoothMatrix))?.ToList();
                }
                uint userPointer = loader.ReadUInt32();
            }
        }
        // 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();
        }
Example #3
0
        void IResData.Load(ResFileLoader loader)
        {
            uint ofsData = loader.ReadOffset();
            uint sizData = loader.ReadSize();

            Data = loader.LoadCustom(() => loader.ReadBytes((int)sizData), ofsData);
        }
Example #4
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            if (loader.IsSwitch)
            {
                Switch.ModelParser.Read((Switch.Core.ResFileSwitchLoader)loader, this);
            }
            else
            {
                Name     = loader.LoadString();
                Path     = loader.LoadString();
                Skeleton = loader.Load <Skeleton>();
                uint ofsVertexBufferList = loader.ReadOffset();
                Shapes    = loader.LoadDict <Shape>();
                Materials = loader.LoadDict <Material>();
                UserData  = loader.LoadDict <UserData>();
                ushort numVertexBuffer  = loader.ReadUInt16();
                ushort numShape         = loader.ReadUInt16();
                ushort numMaterial      = loader.ReadUInt16();
                ushort numUserData      = loader.ReadUInt16();
                uint   totalVertexCount = loader.ReadUInt32();

                if (loader.ResFile.Version >= 0x03030000)
                {
                    uint userPointer = loader.ReadUInt32();
                }

                VertexBuffers = loader.LoadList <VertexBuffer>(numVertexBuffer, ofsVertexBufferList);
            }
        }
Example #5
0
        public static void Load(ResFileLoader loader, ResFile resFile)
        {
            loader.CheckSignature("FRES");
            resFile.Version = loader.ReadUInt32();
            resFile.SetVersionInfo(resFile.Version);
            resFile.ByteOrder = loader.ReadByteOrder();
            ushort sizHeader = loader.ReadUInt16();
            uint   sizFile   = loader.ReadUInt32();

            resFile.Alignment = loader.ReadUInt32();
            resFile.Name      = loader.LoadString();
            uint sizStringPool = loader.ReadUInt32();
            uint ofsStringPool = loader.ReadOffset();

            resFile.Models = loader.LoadDict <Model>();
            var textures = loader.LoadDict <Texture>();

            resFile.SkeletalAnims       = loader.LoadDict <SkeletalAnim>();
            resFile.ShaderParamAnims    = loader.LoadDict <MaterialAnim>();
            resFile.ColorAnims          = loader.LoadDict <MaterialAnim>();
            resFile.TexSrtAnims         = loader.LoadDict <MaterialAnim>();
            resFile.TexPatternAnims     = loader.LoadDict <MaterialAnim>();
            resFile.BoneVisibilityAnims = loader.LoadDict <VisibilityAnim>();
            loader.LoadDict <VisibilityAnim>();
            resFile.ShapeAnims = loader.LoadDict <ShapeAnim>();

            resFile.Textures = new ResDict <TextureShared>();
            foreach (var tex in textures)
            {
                resFile.Textures.Add(tex.Key, tex.Value);
            }

            if (loader.ResFile.Version >= 0x02040000)
            {
                resFile.SceneAnims    = loader.LoadDict <SceneAnim>();
                resFile.ExternalFiles = loader.LoadDict <ExternalFile>();
                ushort numModel              = loader.ReadUInt16();
                ushort numTexture            = loader.ReadUInt16();
                ushort numSkeletalAnim       = loader.ReadUInt16();
                ushort numShaderParamAnim    = loader.ReadUInt16();
                ushort numColorAnim          = loader.ReadUInt16();
                ushort numTexSrtAnim         = loader.ReadUInt16();
                ushort numTexPatternAnim     = loader.ReadUInt16();
                ushort numBoneVisibilityAnim = loader.ReadUInt16();
                ushort numMatVisibilityAnim  = loader.ReadUInt16();
                ushort numShapeAnim          = loader.ReadUInt16();
                ushort numSceneAnim          = loader.ReadUInt16();
                ushort numExternalFile       = loader.ReadUInt16();
                uint   userPointer           = loader.ReadUInt32();
            }
            else //Note very old versions have no counts and is mostly unkown atm
            {
                uint userPointer  = loader.ReadUInt32();
                uint userPointer2 = loader.ReadUInt32();

                resFile.SceneAnims    = loader.LoadDict <SceneAnim>();
                resFile.ExternalFiles = loader.LoadDict <ExternalFile>();
            }
        }
Example #6
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            if (loader.ResFile.Version >= 0x02040000)
            {
                uint ofsData = loader.ReadOffset();
                uint sizData = loader.ReadUInt32();
                Data = loader.LoadCustom(() => loader.ReadBytes((int)sizData), ofsData);
            }
        }
Example #7
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.
            }
        }
Example #8
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            if (loader.IsSwitch)
            {
                Name = loader.LoadString();
                long   DataOffset = loader.ReadOffset();
                ushort count      = loader.ReadUInt16();
                Type = loader.ReadEnum <RenderInfoType>(true);
                loader.Seek(5);

                switch (Type)
                {
                case RenderInfoType.Int32:
                    _value = loader.LoadCustom(() => loader.ReadInt32s(count), (uint)DataOffset);
                    break;

                case RenderInfoType.Single:
                    _value = loader.LoadCustom(() => loader.ReadSingles(count), (uint)DataOffset);
                    break;

                case RenderInfoType.String:
                    if (DataOffset == 0)     //Some games have empty data offset and no strings
                    {
                        _value = new string[0];
                    }
                    else
                    {
                        _value = loader.LoadCustom(() => loader.LoadStrings(count), (uint)DataOffset);
                    }
                    break;
                }
            }
            else
            {
                ushort count = loader.ReadUInt16();
                Type = loader.ReadEnum <RenderInfoType>(true);
                loader.Seek(1);
                Name = loader.LoadString();
                switch (Type)
                {
                case RenderInfoType.Int32:
                    _value = loader.ReadInt32s(count);
                    break;

                case RenderInfoType.Single:
                    _value = loader.ReadSingles(count);
                    break;

                case RenderInfoType.String:
                    _value = loader.LoadStrings(count);
                    break;
                }
            }
        }
Example #9
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            Version = loader.ReadUInt32();
            SetVersionInfo(Version);

            ByteOrder = loader.ReadEnum <ByteOrder>(true);
            ushort sizHeader = loader.ReadUInt16();
            uint   sizFile   = loader.ReadUInt32();

            Alignment = loader.ReadUInt32();
            Name      = loader.LoadString();
            uint sizStringPool = loader.ReadUInt32();
            uint ofsStringPool = loader.ReadOffset();

            Models              = loader.LoadDict <Model>();
            Textures            = loader.LoadDict <Texture>();
            SkeletalAnims       = loader.LoadDict <SkeletalAnim>();
            ShaderParamAnims    = loader.LoadDict <ShaderParamAnim>();
            ColorAnims          = loader.LoadDict <ShaderParamAnim>();
            TexSrtAnims         = loader.LoadDict <ShaderParamAnim>();
            TexPatternAnims     = loader.LoadDict <TexPatternAnim>();
            BoneVisibilityAnims = loader.LoadDict <VisibilityAnim>();
            MatVisibilityAnims  = loader.LoadDict <VisibilityAnim>();
            ShapeAnims          = loader.LoadDict <ShapeAnim>();

            if (loader.ResFile.Version >= 0x02040000)
            {
                SceneAnims    = loader.LoadDict <SceneAnim>();
                ExternalFiles = loader.LoadDict <ExternalFile>();
                ushort numModel              = loader.ReadUInt16();
                ushort numTexture            = loader.ReadUInt16();
                ushort numSkeletalAnim       = loader.ReadUInt16();
                ushort numShaderParamAnim    = loader.ReadUInt16();
                ushort numColorAnim          = loader.ReadUInt16();
                ushort numTexSrtAnim         = loader.ReadUInt16();
                ushort numTexPatternAnim     = loader.ReadUInt16();
                ushort numBoneVisibilityAnim = loader.ReadUInt16();
                ushort numMatVisibilityAnim  = loader.ReadUInt16();
                ushort numShapeAnim          = loader.ReadUInt16();
                ushort numSceneAnim          = loader.ReadUInt16();
                ushort numExternalFile       = loader.ReadUInt16();
                uint   userPointer           = loader.ReadUInt32();
            }
            else //Note very old versions have no counts and is mostly unkown atm
            {
                uint userPointer  = loader.ReadUInt32();
                uint userPointer2 = loader.ReadUInt32();

                SceneAnims    = loader.LoadDict <SceneAnim>();
                ExternalFiles = loader.LoadDict <ExternalFile>();
            }
        }
Example #10
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            if (loader.IsSwitch)
            {
                uint SubMeshArrayOffset = loader.ReadOffset();
                MemoryPool = loader.Load <MemoryPool>();
                long Buffer           = loader.ReadOffset();
                var  bufferSize       = loader.Load <BufferSize>();
                uint FaceBufferOffset = loader.ReadUInt32();
                PrimitiveType = PrimitiveTypeList[loader.ReadEnum <SwitchPrimitiveType>(true)];
                IndexFormat   = IndexList[loader.ReadEnum <SwitchIndexFormat>(true)];
                uint indexCount = loader.ReadUInt32();
                FirstVertex = loader.ReadUInt32();
                ushort numSubMesh = loader.ReadUInt16();
                ushort padding    = loader.ReadUInt16();
                SubMeshes = loader.LoadList <SubMesh>(numSubMesh, SubMeshArrayOffset).ToList();

                uint DataOffset = (uint)BufferInfo.BufferOffset + FaceBufferOffset;

                //Load buffer data from mem block
                IndexBuffer         = new Buffer();
                IndexBuffer.Flags   = bufferSize.Flag;
                IndexBuffer.Data    = new byte[1][];
                IndexBuffer.Data[0] = loader.LoadCustom(() => loader.ReadBytes((int)bufferSize.Size), DataOffset);
            }
            else
            {
                PrimitiveType = loader.ReadEnum <GX2PrimitiveType>(true);
                IndexFormat   = loader.ReadEnum <GX2IndexFormat>(true);
                uint   indexCount = loader.ReadUInt32();
                ushort numSubMesh = loader.ReadUInt16();
                loader.Seek(2);
                SubMeshes   = loader.LoadList <SubMesh>(numSubMesh).ToList();
                IndexBuffer = loader.Load <Buffer>();
                FirstVertex = loader.ReadUInt32();
            }
        }
Example #11
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));
            }
        }
Example #12
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            _flags = loader.ReadUInt32();
            ushort numBone         = loader.ReadUInt16();
            ushort numSmoothMatrix = loader.ReadUInt16();
            ushort numRigidMatrix  = loader.ReadUInt16();

            loader.Seek(2);
            Bones = loader.LoadDict <Bone>();
            uint ofsBoneList = loader.ReadOffset(); // Only load dict.

            MatrixToBoneList     = loader.LoadCustom(() => loader.ReadUInt16s((numSmoothMatrix + numRigidMatrix)));
            InverseModelMatrices = loader.LoadCustom(() => loader.ReadMatrix3x4s(numSmoothMatrix));
            uint userPointer = loader.ReadUInt32();
        }
Example #13
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();
        }
Example #14
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            Name     = loader.LoadString();
            Path     = loader.LoadString();
            Skeleton = loader.Load <Skeleton>();
            uint ofsVertexBufferList = loader.ReadOffset();

            Shapes    = loader.LoadDict <Shape>();
            Materials = loader.LoadDict <Material>();
            UserData  = loader.LoadDict <UserData>();
            ushort numVertexBuffer  = loader.ReadUInt16();
            ushort numShape         = loader.ReadUInt16();
            ushort numMaterial      = loader.ReadUInt16();
            ushort numUserData      = loader.ReadUInt16();
            uint   totalVertexCount = loader.ReadUInt32();
            uint   userPointer      = loader.ReadUInt32();

            VertexBuffers = loader.LoadList <VertexBuffer>(numVertexBuffer, ofsVertexBufferList);
        }
Example #15
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();
     }
 }
Example #16
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            Version   = loader.ReadUInt32();
            ByteOrder = loader.ReadEnum <ByteOrder>(true);
            ushort sizHeader = loader.ReadUInt16();
            uint   sizFile   = loader.ReadUInt32();

            Alignment = loader.ReadUInt32();
            Name      = loader.LoadString();
            uint sizStringPool = loader.ReadUInt32();
            uint ofsStringPool = loader.ReadOffset();

            Models              = loader.LoadDict <Model>();
            Textures            = loader.LoadDict <Texture>();
            SkeletalAnims       = loader.LoadDict <SkeletalAnim>();
            ShaderParamAnims    = loader.LoadDict <ShaderParamAnim>();
            ColorAnims          = loader.LoadDict <ShaderParamAnim>();
            TexSrtAnims         = loader.LoadDict <ShaderParamAnim>();
            TexPatternAnims     = loader.LoadDict <TexPatternAnim>();
            BoneVisibilityAnims = loader.LoadDict <VisibilityAnim>();
            MatVisibilityAnims  = loader.LoadDict <VisibilityAnim>();
            ShapeAnims          = loader.LoadDict <ShapeAnim>();
            SceneAnims          = loader.LoadDict <SceneAnim>();
            ExternalFiles       = loader.LoadDict <ExternalFile>();
            ushort numModel              = loader.ReadUInt16();
            ushort numTexture            = loader.ReadUInt16();
            ushort numSkeletalAnim       = loader.ReadUInt16();
            ushort numShaderParamAnim    = loader.ReadUInt16();
            ushort numColorAnim          = loader.ReadUInt16();
            ushort numTexSrtAnim         = loader.ReadUInt16();
            ushort numTexPatternAnim     = loader.ReadUInt16();
            ushort numBoneVisibilityAnim = loader.ReadUInt16();
            ushort numMatVisibilityAnim  = loader.ReadUInt16();
            ushort numShapeAnim          = loader.ReadUInt16();
            ushort numSceneAnim          = loader.ReadUInt16();
            ushort numExternalFile       = loader.ReadUInt16();
            uint   userPointer           = loader.ReadUInt32();
        }
Example #17
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);
        }
Example #18
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            signature = loader.ReadString(4, Encoding.ASCII);
            uint   materialAnimOffset = 0;
            ushort materialCount      = 0;

            if (signature == "FMAA")
            {
                if (loader.ResFile.VersionMajor2 == 9)
                {
                    Flags = loader.ReadEnum <MaterialAnimFlags>(true);
                    loader.ReadUInt16();
                }
                else
                {
                    ((Switch.Core.ResFileSwitchLoader)loader).LoadHeaderBlock();
                }

                Name      = loader.LoadString();
                Path      = loader.LoadString();
                BindModel = loader.Load <Model>(true);
                uint BindIndicesOffset = loader.ReadOffset();
                materialAnimOffset = loader.ReadOffset();
                uint unk = loader.ReadOffset(); //Empty section. Maybe set at runtime
                uint TextureNameArrayOffset = loader.ReadOffset();
                UserData = loader.LoadDictValues <UserData>();
                uint TextureBindArrayOffset = loader.ReadOffset();

                if (loader.ResFile.VersionMajor2 != 9)
                {
                    Flags = loader.ReadEnum <MaterialAnimFlags>(true);
                }

                ushort numUserData = 0;
                ushort CurveCount  = 0;

                if (loader.ResFile.VersionMajor2 == 9)
                {
                    FrameCount    = loader.ReadInt32();
                    BakedSize     = loader.ReadUInt32();
                    numUserData   = loader.ReadUInt16();
                    materialCount = loader.ReadUInt16();
                    CurveCount    = loader.ReadUInt16();
                }
                else
                {
                    numUserData   = loader.ReadUInt16();
                    materialCount = loader.ReadUInt16();
                    CurveCount    = loader.ReadUInt16();
                    FrameCount    = loader.ReadInt32();
                    BakedSize     = loader.ReadUInt32();
                }

                ushort ShaderParamAnimCount    = loader.ReadUInt16();
                ushort TexturePatternAnimCount = loader.ReadUInt16();
                ushort VisabiltyAnimCount      = loader.ReadUInt16();
                ushort TextureCount            = loader.ReadUInt16();

                if (loader.ResFile.VersionMajor2 == 9)
                {
                    loader.ReadUInt16(); //padding
                }
                BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(materialCount), BindIndicesOffset);
                var textureList = loader.LoadCustom(() => loader.LoadStrings(TextureCount), TextureNameArrayOffset);
                TextureBindArray = loader.LoadCustom(() => loader.ReadInt64s(TextureCount), TextureBindArrayOffset);

                if (textureList == null)
                {
                    textureList = new List <string>();
                }

                foreach (var tex in textureList)
                {
                    TextureNames.Add(tex, new TextureRef()
                    {
                        Name = tex
                    });
                }
            }
            else if (signature == "FSHU")
            {
                if (loader.ResFile.Version >= 0x02040000)
                {
                    Name  = loader.LoadString();
                    Path  = loader.LoadString();
                    Flags = (MaterialAnimFlags)loader.ReadUInt32();

                    if (loader.ResFile.Version >= 0x03040000)
                    {
                        FrameCount    = loader.ReadInt32();
                        materialCount = loader.ReadUInt16();
                        ushort numUserData  = loader.ReadUInt16();
                        int    numParamAnim = loader.ReadInt32();
                        int    numCurve     = loader.ReadInt32();
                        BakedSize = loader.ReadUInt32();
                    }
                    else
                    {
                        FrameCount    = loader.ReadUInt16();
                        materialCount = loader.ReadUInt16();
                        UnknownValue  = loader.ReadUInt32();
                        int numCurve = loader.ReadInt32();
                        BakedSize = loader.ReadUInt32();
                        int padding2 = loader.ReadInt32();
                    }
                    BindModel          = loader.Load <Model>();
                    BindIndices        = loader.LoadCustom(() => loader.ReadUInt16s(materialCount));
                    materialAnimOffset = loader.ReadOffset();
                    UserData           = loader.LoadDict <UserData>();
                }
                else
                {
                    Flags         = (MaterialAnimFlags)loader.ReadUInt32();
                    FrameCount    = loader.ReadInt16();
                    materialCount = loader.ReadUInt16();
                    ushort numUserData = loader.ReadUInt16();
                    ushort unk         = loader.ReadUInt16();
                    BakedSize          = loader.ReadUInt32();
                    Name               = loader.LoadString();
                    Path               = loader.LoadString();
                    BindModel          = loader.Load <Model>();
                    BindIndices        = loader.LoadCustom(() => loader.ReadUInt16s(materialCount));
                    materialAnimOffset = loader.ReadOffset();
                }
            }
            else if (signature == "FTXP")
            {
                Name  = loader.LoadString();
                Path  = loader.LoadString();
                Flags = loader.ReadEnum <MaterialAnimFlags>(true);
                ushort numTextureRef = 0;
                if (loader.ResFile.Version >= 0x03040000)
                {
                    ushort numUserData = loader.ReadUInt16();
                    FrameCount    = loader.ReadInt32();
                    numTextureRef = loader.ReadUInt16();
                    materialCount = loader.ReadUInt16();
                    int numPatAnim = loader.ReadInt32();
                    int numCurve   = loader.ReadInt32();
                    BakedSize = loader.ReadUInt32();
                }
                else
                {
                    FrameCount    = loader.ReadUInt16();
                    numTextureRef = loader.ReadUInt16();
                    materialCount = loader.ReadUInt16();
                    ushort numUserData = loader.ReadUInt16();
                    int    numPatAnim  = loader.ReadInt16();
                    int    numCurve    = loader.ReadInt32();
                    BakedSize = loader.ReadUInt32();
                    loader.Seek(4); //padding
                }


                BindModel          = loader.Load <Model>();
                BindIndices        = loader.LoadCustom(() => loader.ReadUInt16s(materialCount));
                materialAnimOffset = loader.ReadOffset();
                if (loader.ResFile.Version >= 0x03040000)
                {
                    TextureNames = loader.LoadDict <TextureRef>();
                }
                else
                {
                    int TextureCount = 0;
                    foreach (var patternAnim in MaterialAnimDataList)
                    {
                        foreach (var curve in patternAnim.Curves)
                        {
                            List <uint> frames = new List <uint>();
                            foreach (float key in curve.Keys)
                            {
                                frames.Add((uint)key);
                            }
                            TextureCount = (short)frames.Max();
                        }
                    }
                    var TextureRefNames = loader.LoadList <TextureRef>(numTextureRef);
                    foreach (var texRef in TextureRefNames)
                    {
                        TextureNames.Add(texRef.Name, texRef);
                    }
                }
                UserData = loader.LoadDict <UserData>();
            }

            //Load materials and parse based on the signature of the section
            MaterialAnimDataList = loader.LoadCustom(() =>
            {
                List <MaterialAnimData> materialAnims = new List <MaterialAnimData>();
                for (int i = 0; i < materialCount; i++)
                {
                    materialAnims.Add(new MaterialAnimData(loader, signature));
                }
                return(materialAnims);
            }, materialAnimOffset);
        }
Example #19
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            loader.CheckSignature(_signature);
            if (loader.IsSwitch)
            {
                if (loader.ResFile.VersionMajor2 == 9)
                {
                    _flags = loader.ReadUInt32();
                }
                else
                {
                    ((Switch.Core.ResFileSwitchLoader)loader).LoadHeaderBlock();
                }

                Name         = loader.LoadString();
                Path         = loader.LoadString();
                BindSkeleton = loader.Load <Skeleton>();
                uint BindIndexArray      = loader.ReadOffset();
                uint BoneAnimArrayOffset = loader.ReadOffset();
                UserData = loader.LoadDictValues <UserData>();
                if (loader.ResFile.VersionMajor2 != 9)
                {
                    _flags = loader.ReadUInt32();
                }

                FrameCount = loader.ReadInt32();
                int numCurve = loader.ReadInt32();
                BakedSize = loader.ReadUInt32();
                ushort numBoneAnim = loader.ReadUInt16();
                ushort numUserData = loader.ReadUInt16();

                if (loader.ResFile.VersionMajor2 != 9)
                {
                    loader.ReadUInt32(); //Padding
                }
                BoneAnims   = loader.LoadList <BoneAnim>(numBoneAnim, BoneAnimArrayOffset).ToList();
                BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(numBoneAnim), BindIndexArray);
            }
            else
            {
                ushort numBoneAnim = 0;
                if (loader.ResFile.Version >= 0x02040000)
                {
                    Name   = loader.LoadString();
                    Path   = loader.LoadString();
                    _flags = loader.ReadUInt32();

                    if (loader.ResFile.Version >= 0x03040000)
                    {
                        FrameCount  = loader.ReadInt32();
                        numBoneAnim = loader.ReadUInt16();
                        ushort numUserData = loader.ReadUInt16();
                        int    numCurve    = loader.ReadInt32();
                        BakedSize = loader.ReadUInt32();
                    }
                    else
                    {
                        FrameCount  = loader.ReadUInt16();
                        numBoneAnim = loader.ReadUInt16();
                        ushort numUserData = loader.ReadUInt16();
                        ushort numCurve    = loader.ReadUInt16();
                        BakedSize = loader.ReadUInt32();
                        loader.Seek(4); //padding
                    }

                    BoneAnims    = loader.LoadList <BoneAnim>(numBoneAnim).ToList();
                    BindSkeleton = loader.Load <Skeleton>();
                    BindIndices  = loader.LoadCustom(() => loader.ReadUInt16s(numBoneAnim));
                    UserData     = loader.LoadDict <UserData>();
                }
                else
                {
                    _flags      = loader.ReadUInt32();
                    FrameCount  = loader.ReadUInt16();
                    numBoneAnim = loader.ReadUInt16();
                    ushort numUserData = loader.ReadUInt16();
                    ushort numCurve    = loader.ReadUInt16();
                    Name         = loader.LoadString();
                    Path         = loader.LoadString();
                    BoneAnims    = loader.LoadList <BoneAnim>(numBoneAnim).ToList();
                    BindSkeleton = loader.Load <Skeleton>();
                    BindIndices  = loader.LoadCustom(() => loader.ReadUInt16s(numBoneAnim));
                }
            }
        }
Example #20
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++;
                    }
                }
            }
        }
Example #21
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        internal void Load(ResFileLoader loader, string signature)
        {
            ParamAnimInfos   = new List <ParamAnimInfo>();
            PatternAnimInfos = new List <PatternAnimInfo>();
            Constants        = new List <AnimConstant>();
            Curves           = new List <AnimCurve>();

            if (signature == "FSHU")
            {
                ushort numAnimParam = loader.ReadUInt16();
                ushort numCurve     = loader.ReadUInt16();
                ushort numConstant  = loader.ReadUInt16();
                loader.Seek(2);
                ShaderParamCurveIndex = loader.ReadInt32();
                InfoIndex             = loader.ReadInt32();
                Name           = loader.LoadString();
                ParamAnimInfos = loader.LoadList <ParamAnimInfo>(numAnimParam);
                Curves         = loader.LoadList <AnimCurve>(numCurve);
                Constants      = loader.LoadCustom(() => loader.ReadAnimConstants(numConstant));
            }
            else if (signature == "FTXP")
            {
                ushort numPatAnim = loader.ReadUInt16();
                ushort numCurve   = loader.ReadUInt16();
                TexturePatternCurveIndex = loader.ReadInt32();
                InfoIndex        = loader.ReadInt32();
                Name             = loader.LoadString();
                PatternAnimInfos = loader.LoadList <PatternAnimInfo>(numPatAnim);
                Curves           = loader.LoadList <AnimCurve>(numCurve);
                BaseDataList     = loader.LoadCustom(() => loader.ReadUInt16s(numPatAnim));
            }
            else if (signature == "FMAA")
            {
                Name = loader.LoadString();
                uint ShaderParamAnimOffset    = loader.ReadOffset();
                uint TexturePatternAnimOffset = loader.ReadOffset();
                uint CurveOffset             = loader.ReadOffset();
                uint ConstantAnimArrayOffset = loader.ReadOffset();
                ShaderParamCurveIndex    = loader.ReadUInt16();
                TexturePatternCurveIndex = loader.ReadUInt16();
                VisualConstantIndex      = loader.ReadUInt16();
                VisalCurveIndex          = loader.ReadUInt16();
                BeginVisalConstantIndex  = loader.ReadUInt16();
                ushort ShaderParamAnimCount    = loader.ReadUInt16();
                ushort TexutrePatternAnimCount = loader.ReadUInt16();
                ushort ConstantAnimCount       = loader.ReadUInt16();
                ushort CurveCount = loader.ReadUInt16();
                loader.Seek(6);

                Curves           = loader.LoadList <AnimCurve>(CurveCount, CurveOffset);
                ParamAnimInfos   = loader.LoadList <ParamAnimInfo>(ShaderParamAnimCount, ShaderParamAnimOffset);
                PatternAnimInfos = loader.LoadList <PatternAnimInfo>(TexutrePatternAnimCount, TexturePatternAnimOffset);
                Constants        = loader.LoadCustom(() => loader.ReadAnimConstants(ConstantAnimCount), ConstantAnimArrayOffset);

                //Set base data list for texture patterns
                //Get the first value from either constants or curves
                BaseDataList = new ushort[PatternAnimInfos.Count];
                for (int i = 0; i < PatternAnimInfos.Count; i++)
                {
                    if (PatternAnimInfos[i].BeginConstant != ushort.MaxValue)
                    {
                        BaseDataList[i] = (ushort)((int)Constants[PatternAnimInfos[i].BeginConstant].Value);
                    }
                    else if (PatternAnimInfos[i].CurveIndex != ushort.MaxValue)
                    {
                        BaseDataList[i] = (ushort)Curves[PatternAnimInfos[i].CurveIndex].Keys[0, 0];
                    }
                }
            }
        }
Example #22
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IResData.Load(ResFileLoader loader)
        {
            if (loader.IsSwitch)
            {
                Name = loader.LoadString();
                uint DataOffset = loader.ReadOffset();
                uint count      = 0;
                if (loader.ResFile.VersionMajor2 <= 2 && loader.ResFile.VersionMajor == 0)
                {
                    char[] Reserved = loader.ReadChars(8);
                    count = loader.ReadUInt32();
                    Type  = (UserDataType)loader.ReadUInt32();
                }
                else
                {
                    count = loader.ReadUInt32();
                    Type  = loader.ReadEnum <UserDataType>(true);
                    char[] Reserved = loader.ReadChars(43);
                }

                switch (Type)
                {
                case UserDataType.Byte:
                    _value = loader.LoadCustom(() => loader.ReadSBytes((int)count), DataOffset);
                    break;

                case UserDataType.Int32:
                    _value = loader.LoadCustom(() => loader.ReadInt32s((int)count), DataOffset);
                    break;

                case UserDataType.Single:
                    _value = loader.LoadCustom(() => loader.ReadSingles((int)count), DataOffset);
                    break;

                case UserDataType.String:
                    _value = loader.LoadCustom(() => loader.LoadStrings((int)count, Encoding.UTF8), DataOffset);
                    break;

                case UserDataType.WString:
                    _value = loader.LoadCustom(() => loader.LoadStrings((int)count, Encoding.Unicode), DataOffset);
                    break;
                }
            }
            else
            {
                Name = loader.LoadString();
                ushort count = loader.ReadUInt16();
                Type = loader.ReadEnum <UserDataType>(true);
                loader.Seek(1);
                switch (Type)
                {
                case UserDataType.Int32:
                    _value = loader.ReadInt32s(count);
                    break;

                case UserDataType.Single:
                    _value = loader.ReadSingles(count);
                    break;

                case UserDataType.String:
                    _value = loader.LoadStrings(count, Encoding.UTF8);
                    break;

                case UserDataType.WString:
                    _value = loader.LoadStrings(count, Encoding.Unicode);
                    break;

                case UserDataType.Byte:
                    _value = loader.ReadBytes(count);
                    break;
                }
            }
        }