internal void AssertValue(BinaryReaderEx br)
                {
                    switch (Type)
                    {
                    case ParamType.aob:
                        var assertAob = (byte[])ValueToAssert;
                        for (int i = 0; i < AobLength; i++)
                        {
                            br.AssertByte(assertAob[i]);
                        }
                        break;

                    case ParamType.b: br.AssertBoolean((bool)ValueToAssert); break;

                    case ParamType.u8:
                    case ParamType.x8: br.AssertByte((byte)ValueToAssert); break;

                    case ParamType.s8: br.AssertSByte((sbyte)ValueToAssert); break;

                    case ParamType.u16:
                    case ParamType.x16: br.AssertUInt16((ushort)ValueToAssert); break;

                    case ParamType.s16: br.AssertInt16((short)ValueToAssert); break;

                    case ParamType.u32:
                    case ParamType.x32: br.AssertUInt32((uint)ValueToAssert); break;

                    case ParamType.s32: br.AssertInt32((int)ValueToAssert); break;

                    case ParamType.u64:
                    case ParamType.x64: br.AssertUInt64((ulong)ValueToAssert); break;

                    case ParamType.s64: br.AssertInt64((long)ValueToAssert); break;

                    case ParamType.f32: br.AssertSingle((float)ValueToAssert); break;

                    case ParamType.f64: br.AssertDouble((double)ValueToAssert); break;

                    default: throw new Exception($"Invalid ParamTemplate ParamType: {Type.ToString()}");
                    }
                }
Esempio n. 2
0
        protected override void Read(BinaryReaderEx br)
        {
            br.BigEndian  = false;
            br.VarintLong = false;

            br.AssertASCII("TAE ");

            bool isBigEndian = br.AssertByte(0, 1) == 1;

            br.BigEndian = isBigEndian;

            br.AssertByte(0);
            br.AssertByte(0);

            bool is64Bit = br.AssertByte(0, 0xFF) == 0xFF;

            br.VarintLong = is64Bit;

            // 0x1000B: DeS, DS1(R)
            // 0x1000C: DS2, DS2 SOTFS, BB, DS3
            // 0x1000D: SDT
            int version = br.AssertInt32(0x1000B, 0x1000C, 0x1000D);

            if (version == 0x1000B && !is64Bit)
            {
                Format = TAEFormat.DS1;
            }
            else if (version == 0x1000C && !is64Bit)
            {
                throw new NotImplementedException("Dark Souls II 32-Bit original release not supported. Only Scholar of the First Sin.");
            }
            else if (version == 0x1000C && is64Bit)
            {
                Format = TAEFormat.DS3;
            }
            else if (version == 0x1000D)
            {
                Format = TAEFormat.SDT;
            }
            else
            {
                throw new System.IO.InvalidDataException("Invalid combination of TAE header values: " +
                                                         $"IsBigEndian={isBigEndian}, Is64Bit={is64Bit}, Version={version}");
            }

            br.ReadInt32(); // File size
            br.AssertVarint(0x40);
            br.AssertVarint(1);
            br.AssertVarint(0x50);

            if (is64Bit)
            {
                br.AssertVarint(0x80);
            }
            else
            {
                br.AssertVarint(0x70);
            }

            if (Format == TAEFormat.DS1)
            {
                br.AssertInt16(2);
                br.AssertInt16(1);
            }
            else
            {
                EventBank = br.ReadVarint();
            }

            br.AssertVarint(0);

            if (Format == TAEFormat.DS1)
            {
                br.AssertInt64(0);
                br.AssertInt64(0);
                br.AssertInt64(0);
            }

            Flags = br.ReadBytes(8);

            var unkFlagA = br.ReadBoolean();
            var unkFlagB = br.ReadBoolean();

            if (!unkFlagA && unkFlagB)
            {
                Format = TAEFormat.SOTFS;
            }
            else if ((unkFlagA && unkFlagB) || (!unkFlagA && !unkFlagB))
            {
                throw new System.IO.InvalidDataException("Invalid unknown flags at 0x48.");
            }

            for (int i = 0; i < 6; i++)
            {
                br.AssertByte(0);
            }

            ID = br.ReadInt32();

            int  animCount   = br.ReadInt32();
            long animsOffset = br.ReadVarint();

            br.ReadVarint(); // Anim groups offset

            br.AssertVarint(Format == TAEFormat.DS1 ? 0x90 : 0xA0);
            br.AssertVarint(animCount);
            br.ReadVarint(); // First anim offset
            if (Format == TAEFormat.DS1)
            {
                br.AssertInt32(0);
            }
            br.AssertVarint(1);
            br.AssertVarint(Format == TAEFormat.DS1 ? 0x80 : 0x90);
            if (Format == TAEFormat.DS1)
            {
                br.AssertInt64(0);
            }
            br.AssertInt32(ID);
            br.AssertInt32(ID);
            br.AssertVarint(0x50);
            br.AssertInt64(0);
            br.AssertVarint(Format == TAEFormat.DS1 ? 0x98 : 0xB0);

            long skeletonNameOffset = br.ReadVarint();
            long sibNameOffset      = br.ReadVarint();

            if (Format != TAEFormat.SOTFS)
            {
                br.AssertVarint(0);
                br.AssertVarint(0);
            }

            if (Format != TAEFormat.SOTFS)
            {
                SkeletonName = br.GetUTF16(skeletonNameOffset);
                SibName      = br.GetUTF16(sibNameOffset);
            }

            br.StepIn(animsOffset);
            {
                Animations = new List <Animation>(animCount);
                bool previousAnimNeedsParamGen = false;
                long previousAnimParamStart    = 0;
                for (int i = 0; i < animCount; i++)
                {
                    Animations.Add(new Animation(br, Format,
                                                 out bool lastEventNeedsParamGen,
                                                 out long animFileOffset, out long lastEventParamOffset));

                    if (previousAnimNeedsParamGen)
                    {
                        br.StepIn(previousAnimParamStart);
                        Animations[i - 1].Events[Animations[i - 1].Events.Count - 1].ReadParameters(br, (int)(animFileOffset - previousAnimParamStart));
                        br.StepOut();
                    }

                    previousAnimNeedsParamGen = lastEventNeedsParamGen;
                    previousAnimParamStart    = lastEventParamOffset;
                }

                // Read from very last anim's very last event's parameters offset to end of file lul
                if (previousAnimNeedsParamGen)
                {
                    br.StepIn(previousAnimParamStart);
                    Animations[Animations.Count - 1].Events[Animations[Animations.Count - 1].Events.Count - 1].ReadParameters(br, (int)(br.Length - previousAnimParamStart));
                    br.StepOut();
                }
            }
            br.StepOut();

            // Don't bother reading anim groups.
        }
Esempio n. 3
0
        protected override void Read(BinaryReaderEx br)
        {
            br.BigEndian = false;

            br.ReadInt32(); // File size
            br.AssertASCII("MDL ");
            br.AssertInt16(1);
            br.AssertInt16(1);
            Unk0C = br.ReadInt32();
            Unk10 = br.ReadInt32();
            Unk14 = br.ReadInt32();

            int meshCount     = br.ReadInt32();
            int indexCount    = br.ReadInt32();
            int vertexCountA  = br.ReadInt32();
            int vertexCountB  = br.ReadInt32();
            int vertexCountC  = br.ReadInt32();
            int vertexCountD  = br.ReadInt32();
            int count7        = br.ReadInt32();
            int materialCount = br.ReadInt32();
            int textureCount  = br.ReadInt32();

            int meshesOffset    = br.ReadInt32();
            int indicesOffset   = br.ReadInt32();
            int verticesOffsetA = br.ReadInt32();
            int verticesOffsetB = br.ReadInt32();
            int verticesOffsetC = br.ReadInt32();
            int verticesOffsetD = br.ReadInt32();
            int offset7         = br.ReadInt32();
            int materialsOffset = br.ReadInt32();
            int texturesOffset  = br.ReadInt32();

            br.Position = meshesOffset;
            Meshes      = new List <Bone>();
            for (int i = 0; i < meshCount; i++)
            {
                Meshes.Add(new Bone(br));
            }

            Indices = br.GetUInt16s(indicesOffset, indexCount);

            br.Position = verticesOffsetA;
            VerticesA   = new List <Vertex>(vertexCountA);
            for (int i = 0; i < vertexCountA; i++)
            {
                VerticesA.Add(new Vertex(br, VertexFormat.A));
            }

            br.Position = verticesOffsetB;
            VerticesB   = new List <Vertex>(vertexCountB);
            for (int i = 0; i < vertexCountB; i++)
            {
                VerticesB.Add(new Vertex(br, VertexFormat.B));
            }

            br.Position = verticesOffsetC;
            VerticesC   = new List <Vertex>(vertexCountC);
            for (int i = 0; i < vertexCountC; i++)
            {
                VerticesC.Add(new Vertex(br, VertexFormat.C));
            }

            br.Position = verticesOffsetD;
            VerticesD   = new List <VertexD>(vertexCountD);
            for (int i = 0; i < vertexCountD; i++)
            {
                VerticesD.Add(new VertexD(br));
            }

            br.Position = offset7;
            Struct7s    = new List <Struct7>(count7);
            for (int i = 0; i < count7; i++)
            {
                Struct7s.Add(new Struct7(br));
            }

            br.Position = materialsOffset;
            Materials   = new List <Material>(materialCount);
            for (int i = 0; i < materialCount; i++)
            {
                Materials.Add(new Material(br));
            }

            br.Position = texturesOffset;
            Textures    = new List <string>(textureCount);
            for (int i = 0; i < textureCount; i++)
            {
                Textures.Add(br.ReadShiftJIS());
            }
        }