Пример #1
0
        private List <BSA_Type3> ParseType3(int hdrOffset, int offset, int count)
        {
            if (count > 0)
            {
                List <BSA_Type3> Type = new List <BSA_Type3>();

                for (int i = 0; i < count; i++)
                {
                    Type.Add(new BSA_Type3()
                    {
                        I_00         = BitConverter.ToUInt16(rawBytes, offset + 0),
                        I_02         = BitConverter.ToUInt16(rawBytes, offset + 2),
                        I_04         = BitConverter.ToUInt16(rawBytes, offset + 4),
                        I_06_a       = Int4Converter.ToInt4(rawBytes[offset + 6])[0],
                        I_06_b       = Int4Converter.ToInt4(rawBytes[offset + 6])[1],
                        I_06_c       = Int4Converter.ToInt4(rawBytes[offset + 7])[0],
                        I_06_d       = Int4Converter.ToInt4(rawBytes[offset + 7])[1],
                        F_08         = BitConverter.ToSingle(rawBytes, offset + 8),
                        F_12         = BitConverter.ToSingle(rawBytes, offset + 12),
                        F_16         = BitConverter.ToSingle(rawBytes, offset + 16),
                        F_20         = BitConverter.ToSingle(rawBytes, offset + 20),
                        F_24         = BitConverter.ToSingle(rawBytes, offset + 24),
                        F_28         = BitConverter.ToSingle(rawBytes, offset + 28),
                        F_32         = BitConverter.ToSingle(rawBytes, offset + 32),
                        F_36         = BitConverter.ToSingle(rawBytes, offset + 36),
                        F_40         = BitConverter.ToSingle(rawBytes, offset + 40),
                        F_44         = BitConverter.ToSingle(rawBytes, offset + 44),
                        I_48         = BitConverter.ToUInt16(rawBytes, offset + 48),
                        I_50         = BitConverter.ToUInt16(rawBytes, offset + 50),
                        I_52         = BitConverter.ToUInt16(rawBytes, offset + 52),
                        I_54         = BitConverter.ToUInt16(rawBytes, offset + 54),
                        I_56         = BitConverter.ToUInt16(rawBytes, offset + 56),
                        FirstHit     = BitConverter.ToUInt16(rawBytes, offset + 58),
                        MultipleHits = BitConverter.ToUInt16(rawBytes, offset + 60),
                        LastHit      = BitConverter.ToUInt16(rawBytes, offset + 62),
                        StartTime    = BitConverter.ToUInt16(rawBytes, hdrOffset + 0),
                        Duration     = GetTypeDuration(BitConverter.ToUInt16(rawBytes, hdrOffset + 0), BitConverter.ToUInt16(rawBytes, hdrOffset + 2)),
                    });
                    hdrOffset += 4;
                    offset    += 64;
                }

                return(Type);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        public void RemoveColorAnimations(List <IUndoRedo> undos = null)
        {
            if (undos == null)
            {
                undos = new List <IUndoRedo>();
            }
            //Parse the byte array and for all Type0 Animations that have Color Component R,G,B, change keyframes/floats to 0.

            int section1Count  = BitConverter.ToInt16(Bytes, 12);
            int section1Offset = BitConverter.ToInt32(Bytes, 16);

            for (int i = 0; i < section1Count; i++)
            {
                int type0Offset = BitConverter.ToInt32(Bytes, section1Offset + 172);
                int type0Count  = BitConverter.ToInt16(Bytes, section1Offset + 170);

                if (type0Count > 0 && type0Offset > 0)
                {
                    type0Offset += 168 + section1Offset;

                    for (int a = 0; a < type0Count; a++)
                    {
                        byte parameter = Bytes[type0Offset + 0];
                        byte component = Int4Converter.ToInt4(Bytes[type0Offset + 2])[0];

                        if (parameter == 0)
                        {
                            //Color Factor
                            if (component == 0 || component == 1 || component == 2)
                            {
                                //Create undoable steps
                                undos.Add(new UndoableArrayChange <byte>(Bytes, type0Offset + 6, Bytes[type0Offset + 6], 0));
                                undos.Add(new UndoableArrayChange <byte>(Bytes, type0Offset + 7, Bytes[type0Offset + 7], 0));

                                //Nullify keyframe count
                                Bytes[type0Offset + 6] = 0;
                                Bytes[type0Offset + 7] = 0;
                            }
                        }

                        type0Offset += 16;
                    }
                }

                section1Offset += 176;
            }
        }
Пример #3
0
        private void WriteType3(List <BSA.BSA_Type3> type, int hdrOffset, int dataOffset)
        {
            if (type != null)
            {
                //Hdr data
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - hdrOffset + 8), hdrOffset);

                for (int i = 0; i < type.Count(); i++)
                {
                    bytes.AddRange(BitConverter.GetBytes(type[i].StartTime));
                    bytes.AddRange(BitConverter.GetBytes(GetTypeEndTime(type[i].StartTime, type[i].Duration)));
                }

                //Main Type Data
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - dataOffset + 12), dataOffset);

                for (int i = 0; i < type.Count(); i++)
                {
                    bytes.AddRange(BitConverter.GetBytes(type[i].I_00));
                    bytes.AddRange(BitConverter.GetBytes(type[i].I_02));
                    bytes.AddRange(BitConverter.GetBytes(type[i].I_04));
                    bytes.Add(Int4Converter.GetByte(type[i].I_06_a, type[i].I_06_b, "Hitbox I_06 > a", "Hitbox I_06 > b"));
                    bytes.Add(Int4Converter.GetByte(type[i].I_06_c, type[i].I_06_d, "Hitbox I_06 > c", "Hitbox I_06 > d"));
                    bytes.AddRange(BitConverter.GetBytes(type[i].F_08));
                    bytes.AddRange(BitConverter.GetBytes(type[i].F_12));
                    bytes.AddRange(BitConverter.GetBytes(type[i].F_16));
                    bytes.AddRange(BitConverter.GetBytes(type[i].F_20));
                    bytes.AddRange(BitConverter.GetBytes(type[i].F_24));
                    bytes.AddRange(BitConverter.GetBytes(type[i].F_28));
                    bytes.AddRange(BitConverter.GetBytes(type[i].F_32));
                    bytes.AddRange(BitConverter.GetBytes(type[i].F_36));
                    bytes.AddRange(BitConverter.GetBytes(type[i].F_40));
                    bytes.AddRange(BitConverter.GetBytes(type[i].F_44));
                    bytes.AddRange(BitConverter.GetBytes(type[i].I_48));
                    bytes.AddRange(BitConverter.GetBytes(type[i].I_50));
                    bytes.AddRange(BitConverter.GetBytes(type[i].I_52));
                    bytes.AddRange(BitConverter.GetBytes(type[i].I_54));
                    bytes.AddRange(BitConverter.GetBytes(type[i].I_56));
                    bytes.AddRange(BitConverter.GetBytes(type[i].FirstHit));
                    bytes.AddRange(BitConverter.GetBytes(type[i].MultipleHits));
                    bytes.AddRange(BitConverter.GetBytes(type[i].LastHit));
                }
            }
        }
Пример #4
0
        public void RemoveColorAnimations()
        {
            //Parse the byte array and for all Type0 Animations that have Color Component R,G,B, change keyframes/floats to 0.

            int section1Count  = BitConverter.ToInt16(Bytes, 12);
            int section1Offset = BitConverter.ToInt32(Bytes, 16);

            for (int i = 0; i < section1Count; i++)
            {
                int type0Offset = BitConverter.ToInt32(Bytes, section1Offset + 172);
                int type0Count  = BitConverter.ToInt16(Bytes, section1Offset + 170);

                if (type0Count > 0 && type0Offset > 0)
                {
                    type0Offset += 168 + section1Offset;

                    for (int a = 0; a < type0Count; a++)
                    {
                        byte parameter = Bytes[type0Offset + 0];
                        byte component = Int4Converter.ToInt4(Bytes[type0Offset + 2])[0];

                        if (parameter == 0)
                        {
                            //Color Factor
                            if (component == 0 || component == 1 || component == 2)
                            {
                                //Nullify keyframe count
                                Bytes[type0Offset + 6] = 0;
                                Bytes[type0Offset + 7] = 0;
                            }
                        }

                        type0Offset += 16;
                    }
                }

                section1Offset += 176;
            }
        }
Пример #5
0
        private void ParseBsa()
        {
            int count  = BitConverter.ToInt16(rawBytes, 18);
            int offset = BitConverter.ToInt32(rawBytes, 20);

            bsaFile.I_08        = BitConverter.ToInt64(rawBytes, 8);
            bsaFile.I_16        = BitConverter.ToInt16(rawBytes, 16);
            bsaFile.BSA_Entries = new List <BSA_Entry>();


            for (int i = 0; i < count; i++)
            {
                int entryOffset = BitConverter.ToInt32(rawBytes, offset);

                if (entryOffset != 0)
                {
                    bsaFile.BSA_Entries.Add(new BSA_Entry()
                    {
                        Index            = i.ToString(),
                        I_00             = BitConverter.ToInt32(rawBytes, entryOffset + 0),
                        I_16_a           = Int4Converter.ToInt4(rawBytes[entryOffset + 16])[0],
                        I_16_b           = Int4Converter.ToInt4(rawBytes[entryOffset + 16])[1],
                        I_17             = rawBytes[entryOffset + 17],
                        I_18             = BitConverter.ToInt32(rawBytes, entryOffset + 18),
                        I_22             = BitConverter.ToUInt16(rawBytes, entryOffset + 22),
                        I_24             = BitConverter.ToUInt16(rawBytes, entryOffset + 24),
                        Expires          = BitConverter.ToUInt16(rawBytes, entryOffset + 26),
                        ImpactProjectile = BitConverter.ToUInt16(rawBytes, entryOffset + 28),
                        ImpactEnemy      = BitConverter.ToUInt16(rawBytes, entryOffset + 30),
                        ImpactGround     = BitConverter.ToUInt16(rawBytes, entryOffset + 32),
                        I_40             = BitConverter_Ex.ToInt32Array(rawBytes, entryOffset + 40, 3)
                    });
                    int thisEntry = bsaFile.BSA_Entries.Count() - 1;
                    int Unk1Count = BitConverter.ToInt16(rawBytes, entryOffset + 4);
                    int Unk2Count = BitConverter.ToInt16(rawBytes, entryOffset + 6);

                    if (Unk1Count != 0 || Unk2Count != 0)
                    {
                        bsaFile.BSA_Entries[thisEntry].SubEntries = new BSA_SubEntries()
                        {
                            CollisionEntries  = ParseUnk1(BitConverter.ToInt16(rawBytes, entryOffset + 8) + entryOffset, BitConverter.ToInt16(rawBytes, entryOffset + 4)),
                            ExpirationEntries = ParseUnk2(BitConverter.ToInt16(rawBytes, entryOffset + 12) + entryOffset, BitConverter.ToInt16(rawBytes, entryOffset + 6))
                        };
                    }

                    //Types
                    int typesOffset = BitConverter.ToInt16(rawBytes, entryOffset + 36) + entryOffset;
                    int typesCount  = BitConverter.ToInt16(rawBytes, entryOffset + 34);

                    if (typesCount > 0)
                    {
                        for (int a = 0; a < typesCount; a++)
                        {
                            int type       = BitConverter.ToInt16(rawBytes, typesOffset + 0);
                            int hdrOffset  = BitConverter.ToInt32(rawBytes, typesOffset + 8) + typesOffset;
                            int dataOffset = BitConverter.ToInt32(rawBytes, typesOffset + 12) + typesOffset;

                            switch (type)
                            {
                            case 0:
                                bsaFile.BSA_Entries[thisEntry].Type0 = ParseType0(hdrOffset, dataOffset, BitConverter.ToInt16(rawBytes, typesOffset + 6));
                                break;

                            case 1:
                                bsaFile.BSA_Entries[thisEntry].Type1 = ParseType1(hdrOffset, dataOffset, BitConverter.ToInt16(rawBytes, typesOffset + 6));
                                break;

                            case 2:
                                bsaFile.BSA_Entries[thisEntry].Type2 = ParseType2(hdrOffset, dataOffset, BitConverter.ToInt16(rawBytes, typesOffset + 6));
                                break;

                            case 3:
                                bsaFile.BSA_Entries[thisEntry].Type3 = ParseType3(hdrOffset, dataOffset, BitConverter.ToInt16(rawBytes, typesOffset + 6));
                                break;

                            case 4:
                                bsaFile.BSA_Entries[thisEntry].Type4 = ParseType4(hdrOffset, dataOffset, BitConverter.ToInt16(rawBytes, typesOffset + 6));
                                break;

                            case 6:
                                bsaFile.BSA_Entries[thisEntry].Type6 = ParseType6(hdrOffset, dataOffset, BitConverter.ToInt16(rawBytes, typesOffset + 6));
                                break;

                            case 7:
                                bsaFile.BSA_Entries[thisEntry].Type7 = ParseType7(hdrOffset, dataOffset, BitConverter.ToInt16(rawBytes, typesOffset + 6));
                                break;

                            case 8:
                                bsaFile.BSA_Entries[thisEntry].Type8 = ParseType8(hdrOffset, dataOffset, BitConverter.ToInt16(rawBytes, typesOffset + 6));
                                break;

                            default:
                                Console.WriteLine(String.Format("Undefined BSA Type encountered: {0}, at offset: {1}", type, typesOffset));
                                Console.ReadLine();
                                break;
                            }

                            typesOffset += 16;
                        }
                    }
                }
                offset += 4;
            }
        }
Пример #6
0
        private void Write()
        {
            //offsets
            List <int>    StrOffsets    = new List <int>();
            List <string> StrToWrite    = new List <string>();
            List <int>    Type0_Offsets = new List <int>();

            bytes.AddRange(BitConverter.GetBytes((ushort)37568));
            bytes.AddRange(BitConverter.GetBytes((ushort)65535));
            bytes.AddRange(BitConverter.GetBytes(ecfFile.I_12));
            bytes.AddRange(new byte[12]);

            if (ecfFile.Entries != null)
            {
                bytes.AddRange(BitConverter.GetBytes((short)ecfFile.Entries.Count()));
                bytes.AddRange(BitConverter.GetBytes(32));


                for (int i = 0; i < ecfFile.Entries.Count(); i++)
                {
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].F_00));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].F_04));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].F_08));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].F_12));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].F_16));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].F_20));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].F_24));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].F_28));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].F_32));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].F_36));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].F_40));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].F_44));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].F_48));
                    bytes.AddRange(BitConverter.GetBytes((ushort)ecfFile.Entries[i].I_52));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].I_54));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].I_56));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].I_58));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].I_60));
                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].I_62));

                    foreach (UInt16 value in ecfFile.Entries[i].I_64)
                    {
                        bytes.AddRange(BitConverter.GetBytes(value));
                    }

                    if (!String.IsNullOrWhiteSpace(ecfFile.Entries[i].Unk_Str))
                    {
                        StrOffsets.Add(bytes.Count());
                        StrToWrite.Add(ecfFile.Entries[i].Unk_Str);
                    }

                    bytes.AddRange(new byte[4]);

                    bytes.AddRange(BitConverter.GetBytes(ecfFile.Entries[i].I_96));
                    if (ecfFile.Entries[i].Type0 != null)
                    {
                        bytes.AddRange(BitConverter.GetBytes((short)ecfFile.Entries[i].Type0.Count()));
                        Type0_Offsets.Add(bytes.Count());
                        bytes.AddRange(BitConverter.GetBytes(8));
                    }
                    else
                    {
                        Type0_Offsets.Add(bytes.Count());
                        bytes.AddRange(new byte[6]);
                    }
                }


                //Writing Type0s
                for (int i = 0; i < ecfFile.Entries.Count(); i++)
                {
                    if (ecfFile.Entries[i].Type0 != null)
                    {
                        bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - Type0_Offsets[i] + 4), Type0_Offsets[i]);

                        List <int> Type0EntryOffsets = new List <int>();

                        foreach (var e in ecfFile.Entries[i].Type0)
                        {
                            int I_01_b = (e.I_01_b == true) ? 1 : 0;
                            int I_02   = (e.I_02 == true) ? 1 : 0;
                            bytes.AddRange(new byte[4] {
                                (byte)e.I_00, Int4Converter.GetByte((byte)e.GetComponent(), (byte)I_01_b, "Animation: Component", "Animation: Interpolated"), (byte)I_02, e.I_03
                            });
                            bytes.AddRange(BitConverter.GetBytes(e.I_04));
                            bytes.AddRange(BitConverter.GetBytes((short)e.Keyframes.Count()));
                            Type0EntryOffsets.Add(bytes.Count());
                            bytes.AddRange(new byte[8]);

                            //Sort keyframes
                            if (e.Keyframes != null)
                            {
                                e.Keyframes = Sorting.SortEntries2(e.Keyframes);
                            }
                        }

                        for (int a = 0; a < ecfFile.Entries[i].Type0.Count(); a++)
                        {
                            int entryOffset = Type0EntryOffsets[a] - 8;
                            bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - entryOffset), Type0EntryOffsets[a]);

                            int floatListOffset = WriteKeyframe(ecfFile.Entries[i].Type0[a].Keyframes);

                            bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(floatListOffset - entryOffset), Type0EntryOffsets[a] + 4);
                        }
                    }
                }



                //Writing Strings
                for (int i = 0; i < StrToWrite.Count(); i++)
                {
                    int entryOffset = StrOffsets[i] - 92;
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - entryOffset), StrOffsets[i]);
                    bytes.AddRange(Encoding.ASCII.GetBytes(StrToWrite[i]));
                    bytes.Add(0);
                }
            }
            else
            {
                bytes.AddRange(new byte[8]);
            }



            if (writeToDisk)
            {
                File.WriteAllBytes(saveLocation, bytes.ToArray());
            }
        }
Пример #7
0
        private void Write()
        {
            bytes.AddRange(BitConverter.GetBytes(bsaFile.I_08));
            bytes.AddRange(BitConverter.GetBytes(bsaFile.I_16));
            bytes.AddRange(BitConverter.GetBytes((short)EntryCount));
            bytes.AddRange(BitConverter.GetBytes(24));

            //MainEntry pointer list
            for (int a = 0; a < EntryCount; a++)
            {
                for (int i = 0; i < bsaFile.BSA_Entries.Count(); i++)
                {
                    if (a == bsaFile.BSA_Entries[i].Index)
                    {
                        //Entry exists
                        MainEntryOffsets.Add(bytes.Count());
                        bytes.AddRange(new byte[4]);
                        break;
                    }
                    if (i == bsaFile.BSA_Entries.Count() - 1)
                    {
                        //Null entry
                        bytes.AddRange(new byte[4]);
                        break;
                    }
                }
            }

            for (int i = 0; i < bsaFile.BSA_Entries.Count(); i++)
            {
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), MainEntryOffsets[i]);

                int Unk1_Count = 0;
                int Unk2_Count = 0;
                if (bsaFile.BSA_Entries[i].SubEntries != null)
                {
                    Unk1_Count = (bsaFile.BSA_Entries[i].SubEntries.Unk1 != null) ? bsaFile.BSA_Entries[i].SubEntries.Unk1.Count() : 0;
                    Unk2_Count = (bsaFile.BSA_Entries[i].SubEntries.Unk2 != null) ? bsaFile.BSA_Entries[i].SubEntries.Unk2.Count() : 0;
                }


                bytes.AddRange(BitConverter.GetBytes(bsaFile.BSA_Entries[i].I_00));
                bytes.AddRange(BitConverter.GetBytes((short)Unk1_Count));
                bytes.AddRange(BitConverter.GetBytes((short)Unk2_Count));
                int Unk1_Offset = bytes.Count();
                bytes.AddRange(new byte[4]);
                int Unk2_Offset = bytes.Count();
                bytes.AddRange(new byte[4]);
                bytes.Add(Int4Converter.GetByte(bsaFile.BSA_Entries[i].I_16_a, bsaFile.BSA_Entries[i].I_16_b, "BSA_Entry: I_16 > a", "BSA_Entry: I_16 > b"));
                bytes.Add(bsaFile.BSA_Entries[i].I_17);
                bytes.AddRange(BitConverter.GetBytes(bsaFile.BSA_Entries[i].I_18));
                bytes.AddRange(BitConverter.GetBytes(bsaFile.BSA_Entries[i].I_22));
                bytes.AddRange(BitConverter.GetBytes(bsaFile.BSA_Entries[i].I_24));
                bytes.AddRange(BitConverter.GetBytes(bsaFile.BSA_Entries[i].I_26));
                bytes.AddRange(BitConverter.GetBytes(bsaFile.BSA_Entries[i].I_28));
                bytes.AddRange(BitConverter.GetBytes(bsaFile.BSA_Entries[i].I_30));
                bytes.AddRange(BitConverter.GetBytes(bsaFile.BSA_Entries[i].I_32));
                bytes.AddRange(BitConverter.GetBytes((short)BsaTypeCount(bsaFile.BSA_Entries[i])));
                int SubEntries_Offset = bytes.Count();
                bytes.AddRange(new byte[4]);

                if (bsaFile.BSA_Entries[i].SubEntries != null)
                {
                    WriteUnk1(bsaFile.BSA_Entries[i].SubEntries.Unk1, Unk1_Offset);
                    WriteUnk2(bsaFile.BSA_Entries[i].SubEntries.Unk2, Unk2_Offset);
                }

                WriteTypes(bsaFile.BSA_Entries[i], SubEntries_Offset);
            }
        }
Пример #8
0
        public static EMA_Command Read(byte[] rawBytes, int offset, float[] values, EMA_File emaFile, EmaType _emaType)
        {
            EMA_Command command = new EMA_Command();

            command.emaType = _emaType;

            if (emaFile.HasSkeleton)
            {
                command.BoneName = emaFile.GetBoneName(BitConverter.ToUInt16(rawBytes, offset + 0));
            }
            else
            {
                //This ema has no skeleton, thus no bones
                command.BoneName = null;
            }

            command.I_02 = rawBytes[offset + 2];

            BitArray flags_b = new BitArray(new byte[1] {
                Int4Converter.ToInt4(rawBytes[offset + 3])[1]
            });
            BitArray flags_a = new BitArray(new byte[1] {
                Int4Converter.ToInt4(rawBytes[offset + 3])[0]
            });

            command.I_03_b1 = flags_b[0];
            command.I_03_b2_Int16ForTime       = flags_b[1];
            command.I_03_b3_Int16ForValueIndex = flags_b[2];
            command.I_03_b4 = flags_b[3];
            command.I_03_a4 = flags_a[3];
            flags_a[3]      = false;
            command.I_03_a  = Int4Converter.GetByte(Utils.ConvertToByte(flags_a), 0);


            command.Keyframes = new ObservableCollection <EMA_Keyframe>();

            ushort keyframeCount = BitConverter.ToUInt16(rawBytes, offset + 4);
            ushort indexOffset   = BitConverter.ToUInt16(rawBytes, offset + 6);

            for (int i = 0; i < keyframeCount; i++)
            {
                ushort        time;
                float         value;
                string        value2 = null;
                string        value3 = null;
                string        value4 = null;
                KeyframeFlags flags;

                if (command.I_03_b2_Int16ForTime)
                {
                    time = BitConverter.ToUInt16(rawBytes, offset + 8 + (i * 2));
                }
                else
                {
                    time = rawBytes[offset + 8 + i];
                }

                if (command.I_03_b3_Int16ForValueIndex)
                {
                    value = values[BitConverter.ToUInt16(rawBytes, offset + indexOffset + (i * 4))];
                    flags = (KeyframeFlags)BitConverter.ToUInt16(rawBytes, offset + indexOffset + 2 + (i * 4));
                    int extraOffset = 0;

                    if (flags.HasFlag(KeyframeFlags.QuadraticBezier))
                    {
                        ushort idx = (ushort)(BitConverter.ToUInt16(rawBytes, offset + indexOffset + (i * 4)) + 1);

                        //idx might be out of range due to a bug with an older version of the parser... so in that case set it to value
                        if (idx <= values.Length - 1)
                        {
                            value2 = values[idx].ToString();
                        }
                        else
                        {
                            value2 = value.ToString();
                        }

                        extraOffset++;
                    }

                    if (flags.HasFlag(KeyframeFlags.CubicBezier))
                    {
                        ushort idx = (ushort)(BitConverter.ToUInt16(rawBytes, offset + indexOffset + (i * 4)) + 1 + extraOffset);

                        //idx might be out of range due to a bug with an older version of the parser... so in that case set it to value
                        if (idx + 1 <= values.Length - 1)
                        {
                            value3 = values[idx].ToString();
                            value4 = values[idx + 1].ToString();
                        }
                        else
                        {
                            value3 = value.ToString();
                            value4 = value.ToString();
                        }

                        extraOffset++;
                    }
                }
                else
                {
                    value = values[rawBytes[offset + indexOffset + (i * 2)]];
                    flags = (KeyframeFlags)rawBytes[offset + indexOffset + 1 + (i * 2)];
                    int extraOffset = 0;

                    if (flags.HasFlag(KeyframeFlags.QuadraticBezier))
                    {
                        byte idx = (byte)(rawBytes[offset + indexOffset + (i * 2)] + 1);

                        if (idx <= values.Length - 1)
                        {
                            value2 = values[idx].ToString();
                        }
                        else
                        {
                            value2 = value.ToString();
                        }
                    }

                    if (flags.HasFlag(KeyframeFlags.CubicBezier))
                    {
                        byte idx = (byte)(rawBytes[offset + indexOffset + (i * 2)] + 1 + extraOffset);

                        if (idx + 1 <= values.Length - 1)
                        {
                            value3 = values[idx].ToString();
                            value4 = values[idx + 1].ToString();
                        }
                        else
                        {
                            value3 = value.ToString();
                            value4 = value.ToString();
                        }
                    }
                }

                command.Keyframes.Add(new EMA_Keyframe()
                {
                    Time          = time,
                    Value         = value,
                    Flags         = flags,
                    Value2        = value2,
                    CubicBezier_1 = value3,
                    CubicBezier_2 = value4
                });
            }

            return(command);
        }
Пример #9
0
        public byte[] Write()
        {
            List <byte> bytes = new List <byte>();

            int        animCount       = GetIndexedAnimationCount();
            List <int> animNameOffsets = new List <int>();

            //Header
            bytes.AddRange(BitConverter.GetBytes(EMA_SIGNATURE));
            bytes.AddRange(BitConverter.GetBytes((ushort)65534));
            bytes.AddRange(BitConverter.GetBytes((ushort)32));
            bytes.AddRange(BitConverter.GetBytes((int)Version));
            bytes.AddRange(new byte[4]); //Skeleton offset
            bytes.AddRange(BitConverter.GetBytes((ushort)animCount));
            bytes.AddRange(BitConverter.GetBytes(I_18));
            bytes.AddRange(BitConverter.GetBytes(I_20));
            bytes.AddRange(BitConverter.GetBytes(I_24));
            bytes.AddRange(BitConverter.GetBytes(I_28));

            //Animation pointers
            bytes.AddRange(new byte[4 * animCount]);

            //Animations
            foreach (var anim in Animations)
            {
                int animStartOffset = bytes.Count;
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), 32 + (anim.Index * 4));

                List <float> values = anim.GetValues();

                bytes.AddRange(BitConverter.GetBytes(anim.I_00));
                bytes.AddRange(BitConverter.GetBytes((ushort)anim.CommandCount));
                bytes.AddRange(BitConverter.GetBytes((int)values.Count));
                bytes.AddRange(BitConverter.GetBytes((ushort)anim.I_08));
                bytes.AddRange(BitConverter.GetBytes((ushort)anim.I_10));
                animNameOffsets.Add(bytes.Count);
                bytes.AddRange(new byte[4]); //Name offset
                bytes.AddRange(new byte[4]); //value offset
                bytes.AddRange(new byte[4 * anim.CommandCount]);

                //Commands
                for (int i = 0; i < anim.CommandCount; i++)
                {
                    int startCommandOffset = bytes.Count;
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count - animStartOffset), animStartOffset + 20 + (i * 4));

                    anim.Commands[i].SetFlags(); //Calculate the known flags

                    if (HasSkeleton)
                    {
                        bytes.AddRange(BitConverter.GetBytes((ushort)GetBoneIndex(anim.Commands[i].BoneName)));
                    }
                    else
                    {
                        bytes.AddRange(new byte[2]);
                    }

                    bytes.Add(anim.Commands[i].I_02);

                    var bitArray_b = new BitArray(new bool[8] {
                        anim.Commands[i].I_03_b1, anim.Commands[i].I_03_b2_Int16ForTime, anim.Commands[i].I_03_b3_Int16ForValueIndex, anim.Commands[i].I_03_b4, false, false, false, false
                    });
                    var bitArray_a = new BitArray(new byte[1] {
                        anim.Commands[i].I_03_a
                    });

                    bitArray_a[3] = anim.Commands[i].I_03_a4;
                    bytes.Add((byte)Int4Converter.GetByte(Utils.ConvertToByte(bitArray_a), Utils.ConvertToByte(bitArray_b)));
                    bytes.AddRange(BitConverter.GetBytes((ushort)anim.Commands[i].KeyframeCount));
                    bytes.AddRange(new byte[2]);

                    //Sort keyframes
                    if (anim.Commands[i].KeyframeCount > 0)
                    {
                        var sortedList = anim.Commands[i].Keyframes.ToList();
                        sortedList.Sort((x, y) => x.Time - y.Time);
                        anim.Commands[i].Keyframes = new ObservableCollection <EMA_Keyframe>(sortedList);
                    }

                    //Write Time
                    for (int a = 0; a < anim.Commands[i].KeyframeCount; a++)
                    {
                        if (anim.Commands[i].I_03_b2_Int16ForTime)
                        {
                            bytes.AddRange(BitConverter.GetBytes(anim.Commands[i].Keyframes[a].Time));
                        }
                        else
                        {
                            bytes.Add((byte)anim.Commands[i].Keyframes[a].Time);
                        }
                    }

                    //Add padding
                    bytes.AddRange(new byte[Utils.CalculatePadding(bytes.Count - startCommandOffset, 4)]);

                    //Write value/index
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes((ushort)(bytes.Count - startCommandOffset)), startCommandOffset + 6);
                    for (int a = 0; a < anim.Commands[i].KeyframeCount; a++)
                    {
                        if (anim.Commands[i].I_03_b3_Int16ForValueIndex)
                        {
                            bytes.AddRange(BitConverter.GetBytes((ushort)anim.Commands[i].Keyframes[a].index));
                            bytes.AddRange(BitConverter.GetBytes((ushort)anim.Commands[i].Keyframes[a].Flags));
                        }
                        else
                        {
                            bytes.Add((byte)anim.Commands[i].Keyframes[a].index);
                            bytes.Add((byte)anim.Commands[i].Keyframes[a].Flags);
                        }
                    }

                    //Add padding
                    bytes.AddRange(new byte[Utils.CalculatePadding(bytes.Count - startCommandOffset, 4)]);
                }

                //Values
                int valuesStartOffset = bytes.Count;
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count - animStartOffset), animStartOffset + 16);
                foreach (var value in values)
                {
                    if (anim.I_10 == ValueType.Float16)
                    {
                        bytes.AddRange(Half.GetBytes((Half)value));
                    }
                    else if (anim.I_10 == ValueType.Float32 || anim.I_10 == ValueType.Float32_2)
                    {
                        bytes.AddRange(BitConverter.GetBytes(value));
                    }
                    else
                    {
                        throw new InvalidDataException("Unknown ValueType. Cannot continue.");
                    }
                }
                bytes.AddRange(new byte[Utils.CalculatePadding(bytes.Count - valuesStartOffset, 4)]);
            }

            //Skeleton
            if (HasSkeleton)
            {
                bytes.AddRange(new byte[Utils.CalculatePadding(bytes.Count, 16)]);
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), 12);
                bytes.AddRange(skeleton.Write());
            }

            //Strings (animations)
            for (int i = 0; i < Animations.Count; i++)
            {
                if (!String.IsNullOrWhiteSpace(Animations[i].Name))
                {
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count - animNameOffsets[i] + 12), animNameOffsets[i]);
                    bytes.AddRange(new byte[10]);
                    bytes.Add((byte)Animations[i].Name.Length);
                    bytes.AddRange(Encoding.ASCII.GetBytes(Animations[i].Name));
                    bytes.Add(0);
                }
            }

            return(bytes.ToArray());
        }
Пример #10
0
        private void Parse()
        {
            ecfFile.I_12 = BitConverter.ToUInt16(rawBytes, 12);



            if (totalMainEntries > 0)
            {
                ecfFile.Entries = new List <ECF_Entry>();

                for (int i = 0; i < totalMainEntries; i++)
                {
                    ecfFile.Entries.Add(new ECF_Entry());

                    ecfFile.Entries[i].I_52 = (PlayMode)BitConverter.ToInt16(rawBytes, mainEntryOffset + 52);
                    ecfFile.Entries[i].F_00 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 0);
                    ecfFile.Entries[i].F_04 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 4);
                    ecfFile.Entries[i].F_08 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 8);
                    ecfFile.Entries[i].F_12 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 12);
                    ecfFile.Entries[i].F_16 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 16);
                    ecfFile.Entries[i].F_20 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 20);
                    ecfFile.Entries[i].F_24 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 24);
                    ecfFile.Entries[i].F_28 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 28);
                    ecfFile.Entries[i].F_32 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 32);
                    ecfFile.Entries[i].F_36 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 36);
                    ecfFile.Entries[i].F_40 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 40);
                    ecfFile.Entries[i].F_44 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 44);
                    ecfFile.Entries[i].F_48 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 48);
                    ecfFile.Entries[i].I_54 = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 54);
                    ecfFile.Entries[i].I_56 = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 56);
                    ecfFile.Entries[i].I_58 = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 58);
                    ecfFile.Entries[i].I_60 = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 60);
                    ecfFile.Entries[i].I_62 = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 62);
                    ecfFile.Entries[i].I_64 = new UInt16[14];

                    for (int a = 0; a < 28; a += 2)
                    {
                        ecfFile.Entries[i].I_64[a / 2] = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 64 + a);
                    }

                    ecfFile.Entries[i].I_96 = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 96);

                    //Type0 data
                    int Type0_Offset = BitConverter.ToInt32(rawBytes, mainEntryOffset + 100) + 96 + mainEntryOffset;
                    int Type0_Count  = BitConverter.ToInt16(rawBytes, mainEntryOffset + 98);

                    if (Type0_Count > 0)
                    {
                        ecfFile.Entries[i].Type0 = new List <Type0>();

                        for (int a = 0; a < Type0_Count; a++)
                        {
                            int startOffset = BitConverter.ToInt32(rawBytes, Type0_Offset + 8) + Type0_Offset;
                            int floatOffset = BitConverter.ToInt32(rawBytes, Type0_Offset + 12) + Type0_Offset;

                            ecfFile.Entries[i].Type0.Add(new Type0()
                            {
                                I_00      = (ECF.Type0.Parameter)rawBytes[Type0_Offset + 0],
                                I_01_a    = Type0.GetComponent((ECF.Type0.Parameter)rawBytes[Type0_Offset + 0], Int4Converter.ToInt4(rawBytes[Type0_Offset + 1])[0]),
                                I_01_b    = BitConverter_Ex.ToBoolean(Int4Converter.ToInt4(rawBytes[Type0_Offset + 1])[1]),
                                I_02      = (rawBytes[Type0_Offset + 2] == 0)? false : true,
                                I_03      = rawBytes[Type0_Offset + 3],
                                I_04      = BitConverter.ToUInt16(rawBytes, Type0_Offset + 4),
                                Keyframes = ParseKeyframes(BitConverter.ToInt16(rawBytes, Type0_Offset + 6), startOffset, floatOffset)
                            });


                            Type0_Offset += 16;
                        }
                    }

                    //Unk_Str
                    int Str_Offset = BitConverter.ToInt32(rawBytes, mainEntryOffset + 92) + mainEntryOffset;

                    if (Str_Offset != 0)
                    {
                        ecfFile.Entries[i].Unk_Str = Utils.GetString(bytes, Str_Offset);
                    }
                    else
                    {
                        ecfFile.Entries[i].Unk_Str = String.Empty;
                    }

                    mainEntryOffset += 104;
                }
            }
        }
Пример #11
0
        private ParticleEffect ParseEffect(int mainEntryOffset)
        {
            ParticleEffect newEffect = ParticleEffect.GetNew((parserMode == ParserMode.Tool) ? true : false);

            //Flags and Offsets for extra data
            int FLAG_36      = rawBytes[mainEntryOffset + 36];
            int FLAG_37      = rawBytes[mainEntryOffset + 37];
            int Type0_Count  = BitConverter.ToInt16(rawBytes, mainEntryOffset + 138);
            int Type0_Offset = BitConverter.ToInt32(rawBytes, mainEntryOffset + 140) + 136 + mainEntryOffset;
            int Type1_Count  = BitConverter.ToInt16(rawBytes, mainEntryOffset + 144);
            int Type1_Offset = BitConverter.ToInt32(rawBytes, mainEntryOffset + 148) + mainEntryOffset;

            //Main Entry values
            newEffect.Component_Type = ParticleEffect.GetComponentType(new int[2] {
                FLAG_36, FLAG_37
            });
            newEffect.Name = Utils.GetString(rawBytes.ToList(), mainEntryOffset, 32);

            BitArray compositeBits_I_32 = new BitArray(new byte[1] {
                rawBytes[mainEntryOffset + 32]
            });
            BitArray compositeBits_I_33 = new BitArray(new byte[1] {
                rawBytes[mainEntryOffset + 33]
            });
            BitArray compositeBits_I_34 = new BitArray(new byte[1] {
                rawBytes[mainEntryOffset + 34]
            });


            newEffect.I_32_0 = compositeBits_I_32[0];
            newEffect.I_32_1 = compositeBits_I_32[1];
            newEffect.I_32_2 = compositeBits_I_32[2];
            newEffect.I_32_3 = compositeBits_I_32[3];
            newEffect.I_32_4 = compositeBits_I_32[4];
            newEffect.I_32_5 = compositeBits_I_32[5];
            newEffect.I_32_6 = compositeBits_I_32[6];
            newEffect.I_32_7 = compositeBits_I_32[7];
            newEffect.I_33_0 = compositeBits_I_33[0];
            newEffect.I_33_1 = compositeBits_I_33[1];
            newEffect.I_33_2 = compositeBits_I_33[2];
            newEffect.I_33_3 = compositeBits_I_33[3];
            newEffect.I_33_4 = compositeBits_I_33[4];
            newEffect.I_33_5 = compositeBits_I_33[5];
            newEffect.I_33_6 = compositeBits_I_33[6];
            newEffect.I_33_7 = compositeBits_I_33[7];
            newEffect.I_34_0 = compositeBits_I_34[0];
            newEffect.I_34_1 = compositeBits_I_34[1];
            newEffect.I_34_2 = compositeBits_I_34[2];
            newEffect.I_34_3 = compositeBits_I_34[3];
            newEffect.I_34_4 = compositeBits_I_34[4];
            newEffect.I_34_5 = compositeBits_I_34[5];
            newEffect.I_34_6 = compositeBits_I_34[6];
            newEffect.I_34_7 = compositeBits_I_34[7];
            newEffect.I_35   = (ParticleEffect.AutoOrientationType)rawBytes[mainEntryOffset + 35];
            newEffect.I_38   = BitConverter.ToInt16(rawBytes, mainEntryOffset + 38);
            newEffect.I_40   = BitConverter.ToInt16(rawBytes, mainEntryOffset + 40);
            newEffect.I_42   = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 42);
            newEffect.I_44   = rawBytes[mainEntryOffset + 44];
            newEffect.I_45   = rawBytes[mainEntryOffset + 45];
            newEffect.I_46   = rawBytes[mainEntryOffset + 46];
            newEffect.I_47   = rawBytes[mainEntryOffset + 47];
            newEffect.I_48   = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 48);
            newEffect.I_50   = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 50);
            newEffect.I_52   = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 52);
            newEffect.I_54   = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 54);
            newEffect.I_56   = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 56);
            newEffect.I_58   = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 58);
            newEffect.I_60   = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 60);
            newEffect.I_62   = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 62);

            newEffect.F_64  = BitConverter.ToSingle(rawBytes, mainEntryOffset + 64);
            newEffect.F_68  = BitConverter.ToSingle(rawBytes, mainEntryOffset + 68);
            newEffect.F_72  = BitConverter.ToSingle(rawBytes, mainEntryOffset + 72);
            newEffect.F_76  = BitConverter.ToSingle(rawBytes, mainEntryOffset + 76);
            newEffect.F_80  = BitConverter.ToSingle(rawBytes, mainEntryOffset + 80);
            newEffect.F_84  = BitConverter.ToSingle(rawBytes, mainEntryOffset + 84);
            newEffect.F_88  = BitConverter.ToSingle(rawBytes, mainEntryOffset + 88);
            newEffect.F_92  = BitConverter.ToSingle(rawBytes, mainEntryOffset + 92);
            newEffect.F_96  = BitConverter.ToSingle(rawBytes, mainEntryOffset + 96);
            newEffect.F_100 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 100);
            newEffect.F_104 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 104);
            newEffect.F_108 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 108);
            newEffect.F_112 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 112);
            newEffect.F_116 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 116);
            newEffect.F_120 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 120);
            newEffect.F_124 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 124);
            newEffect.F_128 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 128);
            newEffect.F_132 = BitConverter.ToSingle(rawBytes, mainEntryOffset + 132);

            newEffect.I_136 = BitConverter.ToUInt16(rawBytes, mainEntryOffset + 136);

            if (Type0_Count > 0 || Type1_Count > 0)
            {
                //Type0
                if (Type0_Count > 0)
                {
                    newEffect.Type_0 = new ObservableCollection <Type0>();

                    for (int a = 0; a < Type0_Count; a++)
                    {
                        int idx = newEffect.Type_0.Count();

                        newEffect.Type_0.Add(new Type0()
                        {
                            I_01_b    = BitConverter_Ex.ToBoolean(Int4Converter.ToInt4(rawBytes[Type0_Offset + 1])[1]),
                            I_02      = BitConverter_Ex.ToBoolean(rawBytes, Type0_Offset + 2),
                            I_03      = rawBytes[Type0_Offset + 3],
                            F_04      = BitConverter.ToSingle(rawBytes, Type0_Offset + 4),
                            I_08      = BitConverter.ToInt16(rawBytes, Type0_Offset + 8),
                            Keyframes = ParseKeyframes <Type0_Keyframe>(BitConverter.ToInt16(rawBytes, Type0_Offset + 10), BitConverter.ToInt32(rawBytes, Type0_Offset + 12) + Type0_Offset)
                        });

                        newEffect.Type_0[idx].SetParameters(rawBytes[Type0_Offset + 0], Int4Converter.ToInt4(rawBytes[Type0_Offset + 1])[0], newEffect.IsScale2Enabled());

                        Type0_Offset += 16;
                    }
                }

                //Type1
                if (Type1_Count > 0)
                {
                    newEffect.Type_1 = new ObservableCollection <Type1_Header>();

                    for (int a = 0; a < Type1_Count; a++)
                    {
                        int entryCount  = BitConverter.ToInt16(rawBytes, Type1_Offset + 2);
                        int entryOffset = BitConverter.ToInt32(rawBytes, Type1_Offset + 4) + Type1_Offset;

                        newEffect.Type_1.Add(new Type1_Header());
                        newEffect.Type_1[a].I_00    = rawBytes[Type1_Offset];
                        newEffect.Type_1[a].I_01    = rawBytes[Type1_Offset + 1];
                        newEffect.Type_1[a].Entries = new ObservableCollection <Type0>();

                        for (int d = 0; d < entryCount; d++)
                        {
                            int subEntryCount = BitConverter.ToInt16(rawBytes, entryOffset + 10);

                            newEffect.Type_1[a].Entries.Add(new Type0());

                            newEffect.Type_1[a].Entries[d].SetParameters(rawBytes[entryOffset + 0], Int4Converter.ToInt4(rawBytes[entryOffset + 1])[0], newEffect.IsScale2Enabled());
                            newEffect.Type_1[a].Entries[d].I_01_b = BitConverter_Ex.ToBoolean(Int4Converter.ToInt4(rawBytes[entryOffset + 1])[1]);
                            newEffect.Type_1[a].Entries[d].I_02   = BitConverter_Ex.ToBoolean(rawBytes, entryOffset + 2);
                            newEffect.Type_1[a].Entries[d].I_03   = rawBytes[entryOffset + 3];
                            newEffect.Type_1[a].Entries[d].F_04   = BitConverter.ToSingle(rawBytes, entryOffset + 4);

                            newEffect.Type_1[a].Entries[d].I_08      = BitConverter.ToInt16(rawBytes, entryOffset + 8);
                            newEffect.Type_1[a].Entries[d].Keyframes = ParseKeyframes <Type0_Keyframe>(BitConverter.ToInt16(rawBytes, entryOffset + 10), BitConverter.ToInt32(rawBytes, entryOffset + 12) + entryOffset);

                            entryOffset += 16;
                        }

                        Type1_Offset += 8;
                    }
                }
            }
            //Extra Parts
            //If no extra parts exist, this code wont execute
            if (FLAG_37 != 0)
            {
                switch (FLAG_37)
                {
                case 1:
                    switch (FLAG_36)
                    {
                    case 0:
                        newEffect.FloatPart_00_01 = ParseFloatPart8 <FloatPart_0_1>(mainEntryOffset + 160);
                        break;

                    case 1:
                        newEffect.FloatPart_01_01 = ParseFloatPart4 <FloatPart_1_1>(mainEntryOffset + 160);
                        break;

                    case 2:
                        newEffect.FloatPart_02_01 = ParseFloatPart_2_1(mainEntryOffset + 160);
                        break;

                    case 3:
                        newEffect.FloatPart_03_01 = ParseFloatPart_3_1(mainEntryOffset + 160);
                        break;
                    }
                    break;

                case 2:
                    switch (FLAG_36)
                    {
                    case 0:
                        newEffect.Type_Texture    = ParseTexturePart(mainEntryOffset + 160, mainEntryOffset, textureEntryOffset);
                        newEffect.FloatPart_00_02 = ParseFloatPart4 <FloatPart_0_2>(mainEntryOffset + 160 + 112);
                        break;

                    case 1:
                        newEffect.Type_Texture = ParseTexturePart(mainEntryOffset + 160, mainEntryOffset, textureEntryOffset);
                        break;

                    case 2:
                        newEffect.Type_Texture    = ParseTexturePart(mainEntryOffset + 160, mainEntryOffset, textureEntryOffset);
                        newEffect.FloatPart_02_02 = ParseFloatPart8 <FloatPart_2_2>(mainEntryOffset + 160 + 112);
                        break;

                    case 3:
                        newEffect.Type_Texture = ParseTexturePart(mainEntryOffset + 160, mainEntryOffset, textureEntryOffset);
                        newEffect.Type_Struct3 = ParseStruct3(mainEntryOffset + 160 + 112, mainEntryOffset);
                        break;

                    case 4:
                        newEffect.Type_Texture = ParseTexturePart(mainEntryOffset + 160, mainEntryOffset, textureEntryOffset);
                        newEffect.Type_Model   = ParseModelStruct(mainEntryOffset + 160 + 112, mainEntryOffset);
                        break;

                    case 5:
                        newEffect.Type_Texture = ParseTexturePart(mainEntryOffset + 160, mainEntryOffset, textureEntryOffset);
                        newEffect.Type_Struct5 = ParseStruct5(mainEntryOffset + 160 + 112, mainEntryOffset);
                        break;
                    }
                    break;
                }
            }


            return(newEffect);
        }
Пример #12
0
        void EffectParser()
        {
            eepkFile.Effects = new List <Effect>();
            List <ushort> effectIds         = new List <ushort>(); //all lists are in sync with each other
            List <int>    effectOffsets     = new List <int>();
            List <short>  effectSize        = new List <short>();
            List <int>    effectInfoOffsets = new List <int>();

            for (int i = 0; i < totalEffects * 4; i += 4)
            {
                //Getting ID List data
                int current = BitConverter.ToInt32(rawBytes, i + pointerSectionLocation);
                if (current != 0)
                {
                    effectIds.Add((Convert.ToUInt16(i / 4)));
                    effectOffsets.Add(BitConverter.ToInt32(rawBytes, i + pointerSectionLocation));
                }
            }

            for (int i = 0; i < effectIds.Count(); i++)
            {
                //Getting EffectInfo data, and making the representation instances
                effectSize.Add(BitConverter.ToInt16(rawBytes, effectOffsets[i] + 10));
                effectInfoOffsets.Add(BitConverter.ToInt32(rawBytes, effectOffsets[i] + 12));

                eepkFile.Effects.Add(new Effect());
                eepkFile.Effects[i].EffectParts = new ObservableCollection <EffectPart>();
                eepkFile.Effects[i].IndexNum    = effectIds[i];
                eepkFile.Effects[i].I_02        = BitConverter.ToUInt16(rawBytes, effectOffsets[i] + 2);

                int addedOffset = 0;
                for (int a = 0; a < effectSize[i]; a++)
                {
                    //Fill in the Effect Info fields, adding a new entry per size
                    BitArray composite_I_32 = new BitArray(new byte[1] {
                        rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 32]
                    });
                    BitArray composite_I_39 = new BitArray(new byte[1] {
                        rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 39]
                    });
                    BitArray composite_I_36 = new BitArray(new byte[1] {
                        rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 36]
                    });
                    BitArray composite_I_37 = new BitArray(new byte[1] {
                        rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 37]
                    });

                    eepkFile.Effects[i].EffectParts.Add(new EffectPart());
                    eepkFile.Effects[i].EffectParts[a].I_00       = BitConverter.ToUInt16(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset);
                    eepkFile.Effects[i].EffectParts[a].I_02       = (AssetType)rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 2];
                    eepkFile.Effects[i].EffectParts[a].I_03       = (EffectPart.Attachment)rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 3];
                    eepkFile.Effects[i].EffectParts[a].I_04       = rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 4];
                    eepkFile.Effects[i].EffectParts[a].I_05       = (EffectPart.DeactivationMode)rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 5];
                    eepkFile.Effects[i].EffectParts[a].I_06       = rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 6];
                    eepkFile.Effects[i].EffectParts[a].I_07       = rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 7];
                    eepkFile.Effects[i].EffectParts[a].I_08       = BitConverter.ToInt32(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 8);
                    eepkFile.Effects[i].EffectParts[a].I_12       = BitConverter.ToInt32(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 12);
                    eepkFile.Effects[i].EffectParts[a].I_16       = BitConverter.ToInt32(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 16);
                    eepkFile.Effects[i].EffectParts[a].I_20       = BitConverter.ToInt32(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 20);
                    eepkFile.Effects[i].EffectParts[a].F_24       = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 24);
                    eepkFile.Effects[i].EffectParts[a].I_28       = BitConverter.ToUInt16(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 28);
                    eepkFile.Effects[i].EffectParts[a].I_30       = BitConverter.ToUInt16(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 30);
                    eepkFile.Effects[i].EffectParts[a].I_32_0     = composite_I_32[0];
                    eepkFile.Effects[i].EffectParts[a].I_32_1     = composite_I_32[1];
                    eepkFile.Effects[i].EffectParts[a].I_32_2     = composite_I_32[2];
                    eepkFile.Effects[i].EffectParts[a].I_32_3     = composite_I_32[3];
                    eepkFile.Effects[i].EffectParts[a].I_32_4     = composite_I_32[4];
                    eepkFile.Effects[i].EffectParts[a].I_32_5     = composite_I_32[5];
                    eepkFile.Effects[i].EffectParts[a].I_32_6     = composite_I_32[6];
                    eepkFile.Effects[i].EffectParts[a].I_32_7     = composite_I_32[7];
                    eepkFile.Effects[i].EffectParts[a].I_34       = BitConverter.ToInt16(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 34);
                    eepkFile.Effects[i].EffectParts[a].I_36_0     = composite_I_36[0];
                    eepkFile.Effects[i].EffectParts[a].I_36_1     = composite_I_36[1];
                    eepkFile.Effects[i].EffectParts[a].I_36_2     = composite_I_36[2];
                    eepkFile.Effects[i].EffectParts[a].I_36_3     = composite_I_36[3];
                    eepkFile.Effects[i].EffectParts[a].I_36_4     = composite_I_36[4];
                    eepkFile.Effects[i].EffectParts[a].I_36_5     = composite_I_36[5];
                    eepkFile.Effects[i].EffectParts[a].I_36_6     = composite_I_36[6];
                    eepkFile.Effects[i].EffectParts[a].I_36_7     = composite_I_36[7];
                    eepkFile.Effects[i].EffectParts[a].I_37_0     = composite_I_37[0];
                    eepkFile.Effects[i].EffectParts[a].I_37_1     = composite_I_37[1];
                    eepkFile.Effects[i].EffectParts[a].I_37_2     = composite_I_37[2];
                    eepkFile.Effects[i].EffectParts[a].I_37_3     = composite_I_37[3];
                    eepkFile.Effects[i].EffectParts[a].I_37_4     = composite_I_37[4];
                    eepkFile.Effects[i].EffectParts[a].I_37_5     = composite_I_37[5];
                    eepkFile.Effects[i].EffectParts[a].I_37_6     = composite_I_37[6];
                    eepkFile.Effects[i].EffectParts[a].I_37_7     = composite_I_37[7];
                    eepkFile.Effects[i].EffectParts[a].I_38_a     = HexConverter.GetHexString(Int4Converter.ToInt4(rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 38])[0]);
                    eepkFile.Effects[i].EffectParts[a].I_38_b     = HexConverter.GetHexString(Int4Converter.ToInt4(rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 38])[1]);
                    eepkFile.Effects[i].EffectParts[a].I_39_0     = composite_I_39[0];
                    eepkFile.Effects[i].EffectParts[a].I_39_1     = composite_I_39[1];
                    eepkFile.Effects[i].EffectParts[a].I_39_2     = composite_I_39[2];
                    eepkFile.Effects[i].EffectParts[a].I_39_3     = composite_I_39[3];
                    eepkFile.Effects[i].EffectParts[a].I_39_4     = composite_I_39[4];
                    eepkFile.Effects[i].EffectParts[a].I_39_5     = composite_I_39[5];
                    eepkFile.Effects[i].EffectParts[a].I_39_6     = composite_I_39[6];
                    eepkFile.Effects[i].EffectParts[a].I_39_7     = composite_I_39[7];
                    eepkFile.Effects[i].EffectParts[a].POSITION_X = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 40);
                    eepkFile.Effects[i].EffectParts[a].POSITION_Y = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 44);
                    eepkFile.Effects[i].EffectParts[a].POSITION_Z = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 48);

                    eepkFile.Effects[i].EffectParts[a].F_52 = (float)Utils.ConvertRadiansToDegrees(BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 52));
                    eepkFile.Effects[i].EffectParts[a].F_56 = (float)Utils.ConvertRadiansToDegrees(BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 56));
                    eepkFile.Effects[i].EffectParts[a].F_60 = (float)Utils.ConvertRadiansToDegrees(BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 60));
                    eepkFile.Effects[i].EffectParts[a].F_64 = (float)Utils.ConvertRadiansToDegrees(BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 64));
                    eepkFile.Effects[i].EffectParts[a].F_68 = (float)Utils.ConvertRadiansToDegrees(BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 68));
                    eepkFile.Effects[i].EffectParts[a].F_72 = (float)Utils.ConvertRadiansToDegrees(BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 72));

                    eepkFile.Effects[i].EffectParts[a].SIZE_1 = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 76);
                    eepkFile.Effects[i].EffectParts[a].SIZE_2 = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 80);
                    eepkFile.Effects[i].EffectParts[a].F_84   = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 84);
                    eepkFile.Effects[i].EffectParts[a].F_88   = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 88);
                    eepkFile.Effects[i].EffectParts[a].I_92   = BitConverter.ToUInt16(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 92);
                    eepkFile.Effects[i].EffectParts[a].I_94   = BitConverter.ToUInt16(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 94);
                    int eskOffset = BitConverter.ToInt32(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 96);
                    if (eskOffset != 0)
                    {
                        //Get ESK string if it exists, otherwise put it as "NULL"
                        try
                        {
                            eepkFile.Effects[i].EffectParts[a].ESK = Utils.GetString(bytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + eskOffset);
                        }
                        catch
                        {
                            throw new ArgumentOutOfRangeException("Unable to get string!");
                        }
                    }
                    else
                    {
                        eepkFile.Effects[i].EffectParts[a].ESK = "NULL";
                    }
                    addedOffset += 100;
                }
            }
        }
Пример #13
0
        void WriteBinaryEEPK()
        {
            int    totalEffects         = 0;
            ushort totalAssetContainers = 0;

            if (eepk_File.Effects != null)
            {
                if (eepk_File.Effects.Count > 0)
                {
                    totalEffects = eepk_File.Effects[eepk_File.Effects.Count() - 1].IndexNum;
                    totalEffects++;
                }
            }
            if (eepk_File.Assets != null)
            {
                totalAssetContainers = (ushort)eepk_File.Assets.Count;
            }

            //Effect ID related Pointers
            List <int>    effectIdPointers       = new List <int>(); //Pointer Section entries - All of these lists will be synced up in entries
            List <int>    effectIdActualPosition = new List <int>(); //Offsets to the Effect ID entry (the "ID List")
            List <string> eskStringsToWrite      = new List <string>();
            List <int>    eskStringPointers      = new List <int>();

            //Asset Section lists and values
            List <int>    containerOneOffset         = new List <int>();//Asset container for asset header block data
            List <int>    containerTwoOffset         = new List <int>();
            List <int>    containerThreeOffset       = new List <int>();
            List <int>    assetDataBlockOffset       = new List <int>();
            List <int>    pointerToStringPointerList = new List <int>();    //the long list of pointers which point to the strings at end of file
            List <int>    unkNumberPointer           = new List <int>();    //pointer just before pointerToStringPointerList
            List <int>    stringPointerListOffsets   = new List <int>();    //the actual list of pointers to the strings (pointerToStringPointerList points to this)
            List <string> fileStringsToWrite         = new List <string>(); //All asset entry strings to write at end of file

            //Initial header data
            bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(totalAssetContainers), 12);
            bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(totalEffects), 14);

            //Effect ID Pointer Section (creates a pointer list and fills each entry with 4 empty bytes for now. The relevant entries will be filled with pointers when that data is written.
            int actualIds = 0;

            if (totalEffects > 0)
            {
                for (int i = 0; i < totalEffects; i++)
                {
                    bytes.AddRange(new List <byte> {
                        0, 0, 0, 0
                    });
                    if (i == eepk_File.Effects[actualIds].IndexNum)
                    {
                        effectIdPointers.Add(bytes.Count() - 4);
                        actualIds++;
                    }
                }
            }

            if (totalAssetContainers > 0)
            {
                for (int i = 0; i < totalAssetContainers; i++)
                {
                    ushort assetCount = (ushort)((eepk_File.Assets[i].AssetEntries != null) ? eepk_File.Assets[i].AssetEntries.Count() : 0);

                    bytes.AddRange(BitConverter.GetBytes(HexConverter.ToInt32(eepk_File.Assets[i].I_00)));
                    bytes.AddRange(new byte[4] {
                        HexConverter.ToInt8(eepk_File.Assets[i].I_04), HexConverter.ToInt8(eepk_File.Assets[i].I_05), HexConverter.ToInt8(eepk_File.Assets[i].I_06), HexConverter.ToInt8(eepk_File.Assets[i].I_07)
                    });
                    bytes.AddRange(BitConverter.GetBytes(HexConverter.ToInt32(eepk_File.Assets[i].I_08)));
                    bytes.AddRange(BitConverter.GetBytes(HexConverter.ToInt32(eepk_File.Assets[i].I_12)));
                    bytes.AddRange(BitConverter.GetBytes((ushort)eepk_File.Assets[i].I_16));
                    bytes.AddRange(new byte[12]);
                    bytes.AddRange(BitConverter.GetBytes(assetCount));
                    assetDataBlockOffset.Add(bytes.Count());
                    bytes.AddRange(new List <byte> {
                        0, 0, 0, 0
                    });
                    containerOneOffset.Add(bytes.Count());
                    bytes.AddRange(new List <byte> {
                        0, 0, 0, 0
                    });
                    containerTwoOffset.Add(bytes.Count());
                    bytes.AddRange(new List <byte> {
                        0, 0, 0, 0
                    });
                    containerThreeOffset.Add(bytes.Count());
                    bytes.AddRange(new List <byte> {
                        0, 0, 0, 0
                    });
                }



                for (int i = 0; i < totalAssetContainers; i++)
                {
                    //Asset Entry data

                    if (eepk_File.Assets[i].AssetEntries != null)
                    {
                        bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() + 32 - assetDataBlockOffset[i]), assetDataBlockOffset[i]);

                        for (int a = 0; a < eepk_File.Assets[i].AssetEntries.Count(); a++)
                        {
                            //Adds the container entries, and placeholder data for the eventual pointers to the string section
                            bytes.AddRange(BitConverter.GetBytes(eepk_File.Assets[i].AssetEntries[a].I_00));
                            bytes.Add((byte)eepk_File.Assets[i].I_16);
                            int actualCountOfFiles = eepk_File.Assets[i].AssetEntries[a].FILES.Where(p => p.Path != "NULL").Count();
                            bytes.Add((byte)actualCountOfFiles);
                            unkNumberPointer.Add(bytes.Count());
                            bytes.AddRange(new List <byte> {
                                0, 0, 0, 0
                            });
                            pointerToStringPointerList.Add(bytes.Count());
                            bytes.AddRange(new List <byte> {
                                0, 0, 0, 0
                            });
                        }
                    }
                }

                int assetContainerIteration = 0;
                for (int i = 0; i < totalAssetContainers; i++)
                {//String pointer section (between Asset Container Entries and ID List)
                    if (eepk_File.Assets[i].AssetEntries != null)
                    {
                        for (int a = 0; a < eepk_File.Assets[i].AssetEntries.Count(); a++)
                        {
                            //Iterating over the Asset Entries of a Main Container
                            int actualCountOfFiles = eepk_File.Assets[i].AssetEntries[a].FILES.Where(p => p.Path != "NULL").Count();

                            bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() + 8 - pointerToStringPointerList[assetContainerIteration]), pointerToStringPointerList[assetContainerIteration]);
                            assetContainerIteration++;
                            for (int e = 0; e < actualCountOfFiles; e++)
                            {
                                //Looping for each number in I_03
                                //eepk_File.Assets[i].AssetEntries[a].FILES[e] = eepk_File.Assets[i].AssetEntries[a].FILES[e].Replace("*", " ");//bug fix for white space in file names, here the white space is restored
                                fileStringsToWrite.Add(eepk_File.Assets[i].AssetEntries[a].FILES[e].Path);
                                stringPointerListOffsets.Add(bytes.Count());
                                bytes.AddRange(new List <byte> {
                                    0, 0, 0, 0
                                });
                            }
                        }
                    }
                }
            }

            if (totalEffects > 0)
            {
                for (int i = 0; i < actualIds; i++)
                {
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), effectIdPointers[i]); //Setting the offsets in the initial Effect ID pointer section
                    effectIdActualPosition.Add(bytes.Count());
                    bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].IndexNum));
                    bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].I_02));
                    bytes.AddRange(new List <byte> {
                        0, 0, 0, 0, 0, 0
                    });
                    bytes.AddRange(BitConverter.GetBytes((short)eepk_File.Effects[i].EffectParts.Count()));
                    bytes.AddRange(new List <byte> {
                        0, 0, 0, 0
                    });
                }

                for (int i = 0; i < actualIds; i++)
                {//Each effect
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - effectIdActualPosition[i]), effectIdActualPosition[i] + 12);
                    //Above line: setting offset to Effect Entry Start in the Effect ID Entry
                    for (int a = 0; a < eepk_File.Effects[i].EffectParts.Count(); a++)
                    {//Each entry/size
                        BitArray compositeBits_I_32 = new BitArray(new bool[8] {
                            eepk_File.Effects[i].EffectParts[a].I_32_0, eepk_File.Effects[i].EffectParts[a].I_32_1, eepk_File.Effects[i].EffectParts[a].I_32_2, eepk_File.Effects[i].EffectParts[a].I_32_3, eepk_File.Effects[i].EffectParts[a].I_32_4, eepk_File.Effects[i].EffectParts[a].I_32_5, eepk_File.Effects[i].EffectParts[a].I_32_6, eepk_File.Effects[i].EffectParts[a].I_32_7
                        });
                        BitArray compositeBits_I_39 = new BitArray(new bool[8] {
                            eepk_File.Effects[i].EffectParts[a].I_39_0, eepk_File.Effects[i].EffectParts[a].I_39_1, eepk_File.Effects[i].EffectParts[a].I_39_2, eepk_File.Effects[i].EffectParts[a].I_39_3, eepk_File.Effects[i].EffectParts[a].I_39_4, eepk_File.Effects[i].EffectParts[a].I_39_5, eepk_File.Effects[i].EffectParts[a].I_39_6, eepk_File.Effects[i].EffectParts[a].I_39_7
                        });
                        BitArray compositeBits_I_36 = new BitArray(new bool[8] {
                            eepk_File.Effects[i].EffectParts[a].I_36_0, eepk_File.Effects[i].EffectParts[a].I_36_1, eepk_File.Effects[i].EffectParts[a].I_36_2, eepk_File.Effects[i].EffectParts[a].I_36_3, eepk_File.Effects[i].EffectParts[a].I_36_4, eepk_File.Effects[i].EffectParts[a].I_36_5, eepk_File.Effects[i].EffectParts[a].I_36_6, eepk_File.Effects[i].EffectParts[a].I_36_6
                        });
                        BitArray compositeBits_I_37 = new BitArray(new bool[8] {
                            eepk_File.Effects[i].EffectParts[a].I_37_0, eepk_File.Effects[i].EffectParts[a].I_37_1, eepk_File.Effects[i].EffectParts[a].I_37_2, eepk_File.Effects[i].EffectParts[a].I_37_3, eepk_File.Effects[i].EffectParts[a].I_37_4, eepk_File.Effects[i].EffectParts[a].I_37_5, eepk_File.Effects[i].EffectParts[a].I_37_6, eepk_File.Effects[i].EffectParts[a].I_37_6
                        });


                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].I_00));
                        bytes.Add((byte)eepk_File.Effects[i].EffectParts[a].I_02);
                        bytes.Add((byte)eepk_File.Effects[i].EffectParts[a].I_03);
                        bytes.Add(eepk_File.Effects[i].EffectParts[a].I_04);
                        bytes.Add((byte)eepk_File.Effects[i].EffectParts[a].I_05);
                        bytes.Add(eepk_File.Effects[i].EffectParts[a].I_06);
                        bytes.Add(eepk_File.Effects[i].EffectParts[a].I_07);
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].I_08));
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].I_12));
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].I_16));
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].I_20));
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].F_24));
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].I_28));
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].I_30));
                        bytes.Add(Utils.ConvertToByte(compositeBits_I_32));
                        bytes.Add(0);
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].I_34));
                        bytes.Add(Utils.ConvertToByte(compositeBits_I_36));
                        bytes.Add(Utils.ConvertToByte(compositeBits_I_37));
                        bytes.Add(Int4Converter.GetByte(HexConverter.ToInt8(eepk_File.Effects[i].EffectParts[a].I_38_a), HexConverter.ToInt8(eepk_File.Effects[i].EffectParts[a].I_38_b), "Flag_38 a", "Flag_38 b"));
                        bytes.Add(Utils.ConvertToByte(compositeBits_I_39));
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].POSITION_X));
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].POSITION_Y));
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].POSITION_Z));

                        bytes.AddRange(BitConverter.GetBytes((float)Utils.ConvertDegreesToRadians(eepk_File.Effects[i].EffectParts[a].F_52)));
                        bytes.AddRange(BitConverter.GetBytes((float)Utils.ConvertDegreesToRadians(eepk_File.Effects[i].EffectParts[a].F_56)));
                        bytes.AddRange(BitConverter.GetBytes((float)Utils.ConvertDegreesToRadians(eepk_File.Effects[i].EffectParts[a].F_60)));
                        bytes.AddRange(BitConverter.GetBytes((float)Utils.ConvertDegreesToRadians(eepk_File.Effects[i].EffectParts[a].F_64)));
                        bytes.AddRange(BitConverter.GetBytes((float)Utils.ConvertDegreesToRadians(eepk_File.Effects[i].EffectParts[a].F_68)));
                        bytes.AddRange(BitConverter.GetBytes((float)Utils.ConvertDegreesToRadians(eepk_File.Effects[i].EffectParts[a].F_72)));

                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].SIZE_1));
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].SIZE_2));
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].F_84));
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].F_88));
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].I_92));
                        bytes.AddRange(BitConverter.GetBytes(eepk_File.Effects[i].EffectParts[a].I_94));
                        eskStringPointers.Add(bytes.Count());
                        eskStringsToWrite.Add(eepk_File.Effects[i].EffectParts[a].ESK);
                        bytes.AddRange(new List <byte> {
                            0, 0, 0, 0
                        });
                    }
                }
            }

            if (totalAssetContainers > 0)
            {
                int strIteration2      = 0;
                int unkNumberIteration = 0;
                int strIteration       = 0;
                for (int i = 0; i < totalAssetContainers; i++)
                {//Writing string section
                    if (eepk_File.Assets[i].FILES[0] != "NULL")
                    {
                        bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() + 36 - containerOneOffset[i]), containerOneOffset[i]);
                        bytes.AddRange(Encoding.ASCII.GetBytes(eepk_File.Assets[i].FILES[0])); bytes.Add(0);
                    }
                    if (eepk_File.Assets[i].FILES[1] != "NULL")
                    {
                        bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() + 40 - containerTwoOffset[i]), containerTwoOffset[i]);
                        bytes.AddRange(Encoding.ASCII.GetBytes(eepk_File.Assets[i].FILES[1])); bytes.Add(0);
                    }
                    if (eepk_File.Assets[i].FILES[2] != "NULL")
                    {
                        bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() + 44 - containerThreeOffset[i]), containerThreeOffset[i]);
                        bytes.AddRange(Encoding.ASCII.GetBytes(eepk_File.Assets[i].FILES[2])); bytes.Add(0);
                    }

                    if (eepk_File.Assets[i].AssetEntries != null)
                    {
                        for (int a = 0; a < eepk_File.Assets[i].AssetEntries.Count(); a++)
                        {
                            int actualCountFile = eepk_File.Assets[i].AssetEntries[a].FILES.Where(p => p.Path != "NULL").Count();

                            bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() + 4 - unkNumberPointer[unkNumberIteration]), unkNumberPointer[unkNumberIteration]);
                            unkNumberIteration++;
                            for (int s = 0; s < actualCountFile; s++)
                            {
                                //Set number offset here
                                if (eepk_File.Assets[i].AssetEntries[a].FILES[s].Path == "NULL")
                                {
                                    bytes.Add(255);
                                }
                                else
                                {
                                    bytes.Add(Convert.ToByte(Utils.GetEepkFileTypeNumber(eepk_File.Assets[i].AssetEntries[a].FILES[s].Path)));
                                }
                            }

                            for (int s = 0; s < actualCountFile; s++)
                            {
                                //Set string offset here
                                if (eepk_File.Assets[i].AssetEntries[a].FILES[s].Path != "NULL")
                                {
                                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() + 8 - pointerToStringPointerList[strIteration2]), stringPointerListOffsets[strIteration]);
                                    bytes.AddRange(Encoding.ASCII.GetBytes(eepk_File.Assets[i].AssetEntries[a].FILES[s].Path)); bytes.Add(0);
                                }
                                strIteration++;
                            }
                            strIteration2++;
                        }
                    }
                }
            }

            if (totalEffects > 0)
            {
                for (int i = 0; i < eskStringsToWrite.Count(); i++)
                {
                    if (eskStringsToWrite[i] != "NULL" && !String.IsNullOrWhiteSpace(eskStringsToWrite[i]))
                    {
                        bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() + 96 - eskStringPointers[i]), eskStringPointers[i]);
                        bytes.AddRange(Encoding.ASCII.GetBytes(eskStringsToWrite[i])); bytes.Add(0);
                    }
                }
            }

            if (totalAssetContainers > 0)
            {
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(assetDataBlockOffset[0] - 32), 16); //Pointer to Asset Section
            }
            if (totalEffects > 0)
            {
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(24), 20);        //Pointer to Effect Pointer List
            }
            bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(eepk_File.I_08), 8); //Unknown data in header
        }