Exemple #1
0
        public static void Read(ResFileSwitchLoader loader, VisibilityAnim visibilityAnim)
        {
            if (loader.ResFile.VersionMajor2 == 9)
            {
                visibilityAnim._flags = loader.ReadUInt16();
                loader.ReadUInt16(); //Padding
            }
            else
            {
                loader.LoadHeaderBlock();
            }
            visibilityAnim.Name      = loader.LoadString();
            visibilityAnim.Path      = loader.LoadString();
            visibilityAnim.BindModel = loader.Load <Model>();
            long BindIndicesOffset   = loader.ReadInt64();
            long CurveArrayOffset    = loader.ReadInt64();
            long BaseDataArrayOffset = loader.ReadInt64();
            long NameArrayOffset     = loader.ReadInt64();

            visibilityAnim.UserData = loader.LoadDictValues <UserData>();

            if (loader.ResFile.VersionMajor2 != 9)
            {
                visibilityAnim._flags = loader.ReadUInt16();
            }
            else
            {
                loader.ReadUInt16(); //Idk what this is
            }
            ushort numUserData = loader.ReadUInt16();

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

            visibilityAnim.BakedSize = loader.ReadUInt32();

            visibilityAnim.BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(numAnim), (uint)BindIndicesOffset);
            visibilityAnim.Names       = loader.LoadCustom(() => loader.LoadStrings(numAnim), (uint)NameArrayOffset); // Offset to name list.
            visibilityAnim.Curves      = loader.LoadList <AnimCurve>(numCurve, (uint)CurveArrayOffset);

            visibilityAnim.baseDataBytes = new List <byte>();
            visibilityAnim.BaseDataList  = loader.LoadCustom(() =>
            {
                bool[] baseData = new bool[numAnim];
                int i           = 0;
                while (i < numAnim)
                {
                    byte b = loader.ReadByte();
                    visibilityAnim.baseDataBytes.Add(b);
                    for (int j = 0; j < 8 && i < numAnim; j++)
                    {
                        baseData[i] = b.GetBit(j);
                    }
                    i++;
                }
                return(baseData);
            }, (uint)BaseDataArrayOffset);
        }
        public static void Read(ResFileSwitchLoader loader, VisibilityAnim visibilityAnim)
        {
            if (loader.ResFile.VersionMajor2 == 9)
            {
                visibilityAnim._flags = loader.ReadUInt16();
                loader.ReadUInt16(); //Padding
            }
            else
            {
                loader.LoadHeaderBlock();
            }
            visibilityAnim.Name      = loader.LoadString();
            visibilityAnim.Path      = loader.LoadString();
            visibilityAnim.BindModel = loader.Load <Model>();
            long BindIndicesOffset   = loader.ReadInt64();
            long CurveArrayOffset    = loader.ReadInt64();
            long BaseDataArrayOffset = loader.ReadInt64();
            long NameArrayOffset     = loader.ReadInt64();

            visibilityAnim.UserData = loader.LoadDictValues <UserData>();

            if (loader.ResFile.VersionMajor2 != 9)
            {
                visibilityAnim._flags = loader.ReadUInt16();
            }
            else
            {
                loader.ReadUInt16(); //Idk what this is
            }
            ushort numUserData = loader.ReadUInt16();

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

            visibilityAnim.BakedSize = loader.ReadUInt32();

            visibilityAnim.BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(numAnim), (uint)BindIndicesOffset);
            visibilityAnim.Names       = loader.LoadCustom(() => loader.LoadStrings(numAnim), (uint)NameArrayOffset); // Offset to name list.
            visibilityAnim.Curves      = loader.LoadList <AnimCurve>(numCurve, (uint)CurveArrayOffset);

            visibilityAnim.baseDataBytes = new List <byte>();
            visibilityAnim.BaseDataList  = loader.LoadCustom(() =>
            {
                bool[] baseData = new bool[numAnim];
                int keyIndex    = 0;
                for (int i = 0; i < numAnim; i++)
                {
                    if (numAnim <= keyIndex)
                    {
                        break;
                    }

                    int value = loader.ReadInt32();

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

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

                        baseData[keyIndex] = set;
                        keyIndex++;
                    }
                }
                return(baseData);
            }, (uint)BaseDataArrayOffset);
        }
Exemple #3
0
        public static void Load(ResFileSwitchLoader loader, Material mat)
        {
            if (loader.ResFile.VersionMajor2 == 9)
            {
                mat.Flags = loader.ReadEnum <MaterialFlags>(true);
            }
            else
            {
                loader.LoadHeaderBlock();
            }

            mat.Name         = loader.LoadString();
            mat.RenderInfos  = loader.LoadDictValues <RenderInfo>();
            mat.ShaderAssign = loader.Load <ShaderAssign>();
            long TextureArrayOffset = loader.ReadInt64();
            long TextureNameArray   = loader.ReadInt64();
            long SamplerArrayOffset = loader.ReadInt64();

            mat.Samplers     = loader.LoadDictValues <Sampler>();
            mat.ShaderParams = loader.LoadDictValues <ShaderParam>();
            long SourceParamOffset = loader.ReadInt64();

            mat.UserData = loader.LoadDictValues <UserData>();
            long VolatileFlagsOffset    = loader.ReadInt64();
            long userPointer            = loader.ReadInt64();
            long SamplerSlotArrayOffset = loader.ReadInt64();
            long TexSlotArrayOffset     = loader.ReadInt64();

            if (loader.ResFile.VersionMajor2 != 9)
            {
                mat.Flags = loader.ReadEnum <MaterialFlags>(true);
            }
            ushort idx                    = loader.ReadUInt16();
            ushort numRenderInfo          = loader.ReadUInt16();
            byte   numTextureRef          = loader.ReadByte();
            byte   numSampler             = loader.ReadByte();
            ushort numShaderParam         = loader.ReadUInt16();
            ushort numShaderParamVolatile = loader.ReadUInt16();
            ushort sizParamSource         = loader.ReadUInt16();
            ushort sizParamRaw            = loader.ReadUInt16();
            ushort numUserData            = loader.ReadUInt16();

            if (loader.ResFile.VersionMajor2 != 9)
            {
                loader.ReadUInt32(); //Padding
            }
            var textures = loader.LoadCustom(() => loader.LoadStrings(numTextureRef), (uint)TextureNameArray);

            mat.TextureRefs = new List <TextureRef>();
            if (textures != null)
            {
                foreach (var tex in textures)
                {
                    mat.TextureRefs.Add(new TextureRef()
                    {
                        Name = tex
                    });
                }
            }

            //Add names to the value as switch does not store any
            foreach (var sampler in mat.Samplers)
            {
                sampler.Value.Name = sampler.Key;
            }

            mat.ShaderParamData = loader.LoadCustom(() => loader.ReadBytes(sizParamSource), (uint)SourceParamOffset);

            mat.VolatileFlags    = loader.LoadCustom(() => loader.ReadBytes((int)Math.Ceiling(numShaderParam / 8f)), (uint)VolatileFlagsOffset);
            mat.TextureSlotArray = loader.LoadCustom(() => loader.ReadInt64s(numTextureRef), (uint)SamplerSlotArrayOffset);
            mat.SamplerSlotArray = loader.LoadCustom(() => loader.ReadInt64s(numSampler), (uint)TexSlotArrayOffset);
        }