Beispiel #1
0
        public static CNS_File Read(byte[] rawBytes)
        {
            List <byte> bytes = rawBytes.ToList();

            //Validation
            if (BitConverter.ToInt32(rawBytes, 0) != CNS_SIGNATURE)
            {
                throw new InvalidDataException("CNS_SIGNATURE not found at offset 0x0. Parse failed.");
            }

            int count  = BitConverter.ToInt32(rawBytes, 8);
            int offset = BitConverter.ToInt32(rawBytes, 16);

            //Parse file
            CNS_File cnsFile = new CNS_File()
            {
                CnsEntries = new List <CNS_Entry>()
            };

            cnsFile.Version = BitConverter.ToUInt16(rawBytes, 6);

            //Unknown values
            cnsFile.UnknownValues = BitConverter_Ex.ToUInt16Array(rawBytes, 20, 4);

            //Entries
            for (int i = 0; i < count; i++)
            {
                cnsFile.CnsEntries.Add(CNS_Entry.Read(rawBytes, bytes, offset));
                offset += 180;
            }

            return(cnsFile);
        }
Beispiel #2
0
        }                                    //Size 4

        public static UnkSkeletonData Read(byte[] rawBytes, int offset)
        {
            UnkSkeletonData data = new UnkSkeletonData();

            data.Values = BitConverter_Ex.ToUInt16Array(rawBytes, offset + 0, 4);
            return(data);
        }
Beispiel #3
0
        public byte[] SaveToBytes()
        {
            SortEntries();

            List <byte> bytes = new List <byte>();

            //Header
            bytes.AddRange(BitConverter.GetBytes(CNS_SIGNATURE));    //0
            bytes.AddRange(BitConverter.GetBytes((UInt16)65534));    //4
            bytes.AddRange(BitConverter.GetBytes(Version));          //6
            bytes.AddRange(BitConverter.GetBytes(CnsEntries.Count)); //8
            bytes.AddRange(BitConverter.GetBytes(20));               //12
            bytes.AddRange(BitConverter.GetBytes(28));               //16

            //Unknown values
            Assertion.AssertArraySize(UnknownValues, 4, "CNS", "UnknownValues");
            bytes.AddRange(BitConverter_Ex.GetBytes(UnknownValues));

            //Entries
            for (int i = 0; i < CnsEntries.Count; i++)
            {
                bytes.AddRange(CNS_Entry.Write(CnsEntries[i]));
            }

            return(bytes.ToArray());
        }
Beispiel #4
0
        public static List <byte> Write(CNS_Entry cnsEntry)
        {
            List <byte> bytes = new List <byte>();

            //Code
            if (cnsEntry.Str_00.Length > 8)
            {
                throw new Exception(String.Format("Dual_Code = {0} exceeds the maximum allowed length of 8. Load failed.", cnsEntry.Str_00));
            }
            bytes.AddRange(Encoding.ASCII.GetBytes(cnsEntry.Str_00));
            bytes.AddRange(new byte[8 - cnsEntry.Str_00.Length]);

            //Validate arrays
            Assertion.AssertArraySize(cnsEntry.I_10, 33, "CnsEntry", "I_10");
            Assertion.AssertArraySize(cnsEntry.I_76, 33, "CnsEntry", "I_76");
            Assertion.AssertArraySize(cnsEntry.I_146, 7, "CnsEntry", "I_146");
            Assertion.AssertArraySize(cnsEntry.I_162, 7, "CnsEntry", "I_162");

            //Remaining values
            bytes.AddRange(BitConverter.GetBytes(ushort.Parse(cnsEntry.Index)));
            bytes.AddRange(BitConverter_Ex.GetBytes(cnsEntry.I_10));
            bytes.AddRange(BitConverter_Ex.GetBytes(cnsEntry.I_76));
            bytes.AddRange(BitConverter.GetBytes(cnsEntry.I_142));
            bytes.AddRange(BitConverter.GetBytes(cnsEntry.I_144));
            bytes.AddRange(BitConverter_Ex.GetBytes(cnsEntry.I_146));
            bytes.AddRange(BitConverter.GetBytes(cnsEntry.I_160));
            bytes.AddRange(BitConverter_Ex.GetBytes(cnsEntry.I_162));
            bytes.AddRange(BitConverter.GetBytes(cnsEntry.I_176));
            bytes.AddRange(BitConverter.GetBytes(cnsEntry.I_178));

            return(bytes);
        }
Beispiel #5
0
        List <Type_5> GetType5(short count, int offset, List <Type_5> Type5, int idx)
        {
            if (Type5 == null)
            {
                Type5 = new List <Type_5>();
            }

            for (int i = 0; i < count; i++)
            {
                Type5.Add(new Type_5()
                {
                    Idx  = idx,
                    I_00 = BitConverter.ToUInt16(rawBytes, offset + 0),
                    I_02 = (ushort)(BitConverter.ToUInt16(rawBytes, offset + 2) - BitConverter.ToUInt16(rawBytes, offset + 0)),
                    I_04 = BitConverter.ToUInt16(rawBytes, offset + 4),
                    I_06 = BitConverter.ToUInt16(rawBytes, offset + 6),
                    I_08 = BitConverter.ToUInt16(rawBytes, offset + 8),
                    I_10 = BitConverter.ToUInt16(rawBytes, offset + 10),
                    I_12 = BitConverter.ToUInt16(rawBytes, offset + 12),
                    I_14 = BitConverter.ToUInt16(rawBytes, offset + 14),
                    I_16 = BitConverter_Ex.ToInt32Array(rawBytes, offset + 16, 12)
                });

                offset += 64;
            }

            return(Type5);
        }
Beispiel #6
0
 private void WriteEffect(IBD_Effect effect)
 {
     bytes.AddRange(BitConverter.GetBytes(effect.I_00));
     bytes.AddRange(BitConverter.GetBytes(effect.I_04));
     bytes.AddRange(BitConverter.GetBytes(effect.I_08));
     bytes.AddRange(BitConverter.GetBytes(effect.F_12));
     Assertion.AssertArraySize(effect.F_16, 6, "Effect", "Ability_Values");
     bytes.AddRange(BitConverter_Ex.GetBytes(effect.F_16));
     bytes.AddRange(BitConverter.GetBytes(effect.I_40));
     bytes.AddRange(BitConverter.GetBytes(effect.I_44));
     Assertion.AssertArraySize(effect.F_48, 6, "Effect", "Multipliers");
     bytes.AddRange(BitConverter_Ex.GetBytes(effect.F_48));
     Assertion.AssertArraySize(effect.I_72, 6, "Effect", "I_72");
     bytes.AddRange(BitConverter_Ex.GetBytes(effect.I_72));
     bytes.AddRange(BitConverter.GetBytes(effect.F_96));
     bytes.AddRange(BitConverter.GetBytes(effect.F_100));
     bytes.AddRange(BitConverter.GetBytes(effect.F_104));
     bytes.AddRange(BitConverter.GetBytes(effect.F_108));
     bytes.AddRange(BitConverter.GetBytes(effect.F_112));
     bytes.AddRange(BitConverter.GetBytes(effect.F_116));
     bytes.AddRange(BitConverter.GetBytes(effect.F_120));
     bytes.AddRange(BitConverter.GetBytes(effect.F_124));
     bytes.AddRange(BitConverter.GetBytes(effect.F_128));
     bytes.AddRange(BitConverter.GetBytes(effect.F_132));
     bytes.AddRange(BitConverter.GetBytes(effect.F_136));
     bytes.AddRange(BitConverter.GetBytes(effect.F_140));
     bytes.AddRange(BitConverter.GetBytes(effect.F_144));
     bytes.AddRange(BitConverter.GetBytes(effect.F_148));
     bytes.AddRange(BitConverter.GetBytes(effect.F_152));
     Assertion.AssertArraySize(effect.F_156, 17, "Effect", "F_156");
     bytes.AddRange(BitConverter_Ex.GetBytes(effect.F_156));
 }
Beispiel #7
0
 public static Unknown_Indexes Read(byte[] rawBytes, int offset)
 {
     return(new Unknown_Indexes()
     {
         Indexes = BitConverter_Ex.ToInt32Array(rawBytes, offset, FPF_File.UnknownIndexListCount).ToList()
     });
 }
Beispiel #8
0
        public void ParseBas()
        {
            int count  = BitConverter.ToInt32(rawBytes, 8);
            int offset = BitConverter.ToInt32(rawBytes, 12);

            if (count > 0)
            {
                basFile.Entries = new List <BAS_Entry>();

                for (int i = 0; i < count; i++)
                {
                    basFile.Entries.Add(new BAS_Entry());
                    basFile.Entries[i].I_00 = BitConverter.ToUInt32(rawBytes, offset + 0);
                    int subEntryCount  = BitConverter.ToInt32(rawBytes, offset + 4);
                    int subEntryOffset = BitConverter.ToInt32(rawBytes, offset + 8);

                    if (subEntryCount > 0)
                    {
                        basFile.Entries[i].SubEntries = new List <BAS_SubEntry>();

                        for (int a = 0; a < subEntryCount; a++)
                        {
                            basFile.Entries[i].SubEntries.Add(new BAS_SubEntry()
                            {
                                Name = Utils.GetString(rawBytes.ToList(), subEntryOffset, 8),
                                I_08 = BitConverter_Ex.ToBooleanFromInt32(rawBytes, subEntryOffset + 8),
                                I_12 = (BAS_SubEntry.ActivationConditionTarget)BitConverter.ToInt32(rawBytes, subEntryOffset + 12),
                                I_16 = (BAS_SubEntry.ActivationConditionTarget)BitConverter.ToInt32(rawBytes, subEntryOffset + 16),
                                I_20 = (BAS_SubEntry.ActivationConditionTarget)BitConverter.ToInt32(rawBytes, subEntryOffset + 20),
                                I_24 = BitConverter.ToInt32(rawBytes, subEntryOffset + 24),
                                I_28 = BitConverter.ToInt32(rawBytes, subEntryOffset + 28),
                                I_32 = BitConverter.ToInt32(rawBytes, subEntryOffset + 32),
                                I_36 = BitConverter.ToInt32(rawBytes, subEntryOffset + 36),
                                I_40 = BitConverter.ToInt32(rawBytes, subEntryOffset + 40),
                                I_44 = BitConverter.ToInt32(rawBytes, subEntryOffset + 44),
                                I_48 = BitConverter.ToInt32(rawBytes, subEntryOffset + 48),
                                I_52 = BitConverter.ToInt32(rawBytes, subEntryOffset + 52),
                                I_56 = BitConverter.ToInt32(rawBytes, subEntryOffset + 56),
                                I_60 = BitConverter.ToInt32(rawBytes, subEntryOffset + 60),
                                I_64 = BitConverter.ToInt32(rawBytes, subEntryOffset + 64),
                                F_68 = BitConverter.ToSingle(rawBytes, subEntryOffset + 68),
                                F_72 = BitConverter.ToSingle(rawBytes, subEntryOffset + 72),
                                F_76 = BitConverter.ToSingle(rawBytes, subEntryOffset + 76),
                                F_80 = BitConverter.ToSingle(rawBytes, subEntryOffset + 80),
                            });

                            subEntryOffset += 84;
                        }
                    }

                    offset += 12;
                }
            }
        }
Beispiel #9
0
        public List <byte> Write()
        {
            if (Values.Length != 4)
            {
                throw new InvalidDataException("UnkSkeletonData > Values must have 4 values.");
            }

            List <byte> bytes = new List <byte>();

            bytes.AddRange(BitConverter_Ex.GetBytes(Values));
            return(bytes);
        }
Beispiel #10
0
        public List <byte> Write()
        {
            List <byte> bytes = new List <byte>();

            bytes.AddRange(BitConverter_Ex.GetBytes(Indexes.ToArray()));

            if (bytes.Count != FPF_File.UnknownIndexListCount * 4)
            {
                throw new InvalidDataException("UnknownIndexes is an invalid size.");
            }
            return(bytes);
        }
Beispiel #11
0
        private void WriteUnk3(List <Unk3> unk3, int offsetToFill, int relativeOffset)
        {
            if (unk3 != null)
            {
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - relativeOffset), offsetToFill);

                for (int i = 0; i < unk3.Count(); i++)
                {
                    Assertion.AssertArraySize(unk3[i].I_00, 6, "Unk3", "values");
                    bytes.AddRange(BitConverter_Ex.GetBytes(unk3[i].I_00));
                }
            }
        }
Beispiel #12
0
        //Skeleton

        private void ParseSkeleton(int offset)
        {
            //Init
            boneCount = BitConverter.ToInt16(rawBytes, offset);
            int unk1Offset = BitConverter.ToInt32(rawBytes, offset + 20) + offset;
            int unk2Offset = BitConverter.ToInt32(rawBytes, offset + 24) + offset;

            //Skeleton init
            eanFile.Skeleton = new ESK_Skeleton()
            {
                I_02     = BitConverter.ToInt16(rawBytes, offset + 2),
                I_28     = BitConverter_Ex.ToInt32Array(rawBytes, offset + 28, 2),
                Unk1     = ESK_Unk1.Read(rawBytes, unk1Offset),
                UseUnk2  = (unk2Offset != 0) ? true : false,
                ESKBones = new ObservableCollection <ESK_Bone>()
            };

            //Setting the offsets for the initial loop to use
            int[] offsets               = GetBoneOffset(0, offset);
            int   boneIndexOffset       = offsets[0];
            int   nameOffset            = offsets[1];
            int   skinningMatrixOffset  = offsets[2];
            int   transformMatrixOffset = offsets[3];

            while (true)
            {
                int idx = eanFile.Skeleton.ESKBones.Count;
                eanFile.Skeleton.ESKBones.Add(ESK_Bone.Read(bytes, rawBytes, offsets));
                if (BitConverter.ToInt16(rawBytes, boneIndexOffset + 2) != -1)
                {
                    eanFile.Skeleton.ESKBones[idx].ESK_Bones = ParseChildrenBones(BitConverter.ToInt16(rawBytes, boneIndexOffset + 2), offset);
                }

                //Loop management
                if (BitConverter.ToInt16(rawBytes, boneIndexOffset + 4) != -1)
                {
                    //There is a sibling
                    offsets              = GetBoneOffset(BitConverter.ToInt16(rawBytes, boneIndexOffset + 4), offset);
                    boneIndexOffset      = offsets[0];
                    nameOffset           = offsets[1];
                    skinningMatrixOffset = offsets[2];
                    //transformMatrixOffset = offsets[3];
                }
                else
                {
                    //There is no sibling. End loop.
                    break;
                }
            }
        }
Beispiel #13
0
 public static CNS_Entry Read(byte[] rawBytes, List <byte> bytes, int offset)
 {
     return(new CNS_Entry()
     {
         Str_00 = Utils.GetString(bytes, offset),
         Index = BitConverter.ToUInt16(rawBytes, offset + 8).ToString(),
         I_10 = BitConverter_Ex.ToUInt16Array(rawBytes, offset + 10, 33),
         I_76 = BitConverter_Ex.ToUInt16Array(rawBytes, offset + 76, 33),
         I_142 = BitConverter.ToUInt16(rawBytes, offset + 142),
         I_144 = BitConverter.ToUInt16(rawBytes, offset + 144),
         I_146 = BitConverter_Ex.ToUInt16Array(rawBytes, offset + 146, 7),
         I_160 = BitConverter.ToUInt16(rawBytes, offset + 160),
         I_162 = BitConverter_Ex.ToUInt16Array(rawBytes, offset + 162, 7),
         I_176 = BitConverter.ToUInt16(rawBytes, offset + 176),
         I_178 = BitConverter.ToUInt16(rawBytes, offset + 178),
     });
 }
Beispiel #14
0
        private int ParseSection2(int currentOffset)
        {
            while (EndOfSectionCheck(currentOffset) == false)
            {
                int _pos        = tsd_File.Events.Count();
                int addedOffset = 0;

                tsd_File.Events.Add(new TSD_Event());

                tsd_File.Events[_pos].Index = BitConverter.ToInt32(rawBytes, currentOffset + 0).ToString();
                tsd_File.Events[_pos].I_04  = BitConverter.ToInt32(rawBytes, currentOffset + 4);
                addedOffset += 12;


                int stringSize = BitConverter.ToInt32(rawBytes, currentOffset + addedOffset - 4);

                tsd_File.Events[_pos].Str1 = StringEx.GetString(rawBytes, currentOffset + addedOffset, false, StringEx.EncodingType.UTF8, BitConverter.ToInt32(rawBytes, currentOffset + addedOffset - 4), false);
                addedOffset += stringSize + 4;

                stringSize = BitConverter.ToInt32(rawBytes, currentOffset + addedOffset - 4);
                tsd_File.Events[_pos].Str2 = StringEx.GetString(rawBytes, currentOffset + addedOffset, false, StringEx.EncodingType.UTF8, BitConverter.ToInt32(rawBytes, currentOffset + addedOffset - 4), false);
                addedOffset += stringSize + 4;

                stringSize = BitConverter.ToInt32(rawBytes, currentOffset + addedOffset - 4);
                tsd_File.Events[_pos].Str3 = StringEx.GetString(rawBytes, currentOffset + addedOffset, false, StringEx.EncodingType.UTF8, BitConverter.ToInt32(rawBytes, currentOffset + addedOffset - 4), false);
                addedOffset += stringSize + 4;

                stringSize = BitConverter.ToInt32(rawBytes, currentOffset + addedOffset - 4);
                tsd_File.Events[_pos].Str4 = StringEx.GetString(rawBytes, currentOffset + addedOffset, false, StringEx.EncodingType.UTF8, BitConverter.ToInt32(rawBytes, currentOffset + addedOffset - 4), false);
                addedOffset += stringSize + 4;

                stringSize = BitConverter.ToInt32(rawBytes, currentOffset + addedOffset - 4);
                string args = StringEx.GetString(rawBytes, currentOffset + addedOffset, false, StringEx.EncodingType.UTF8, BitConverter.ToInt32(rawBytes, currentOffset + addedOffset - 4), false);
                tsd_File.Events[_pos].Arguments = EventArguments.Read(args);
                addedOffset += stringSize + 4;

                //Read TNL ID array
                int        count  = BitConverter.ToInt32(rawBytes, currentOffset + addedOffset - 4);
                List <int> tnlIds = BitConverter_Ex.ToInt32Array(rawBytes, currentOffset + addedOffset, count).ToList();
                addedOffset += (4 * count);
                tsd_File.Events[_pos].TNL_IDs = ArrayConvert.ConvertToStringList(tnlIds);

                currentOffset += addedOffset;
            }
            return(currentOffset);
        }
Beispiel #15
0
        private List <Unk3> ParseUnk3(int offset, int count)
        {
            if (count > 0)
            {
                List <Unk3> unk3 = new List <Unk3>();

                for (int i = 0; i < count; i++)
                {
                    unk3.Add(new Unk3()
                    {
                        I_00 = BitConverter_Ex.ToInt16Array(rawBytes, offset, 6)
                    });
                    offset += 12;
                }

                return(unk3);
            }
            else
            {
                return(null);
            }
        }
Beispiel #16
0
        private List <IBD_Effect> ParseEffect(int offset)
        {
            List <IBD_Effect> effects = new List <IBD_Effect>();

            for (int i = 0; i < 3; i++)
            {
                effects.Add(new IBD_Effect()
                {
                    I_00  = BitConverter.ToInt32(rawBytes, offset + 0),
                    I_04  = BitConverter.ToInt32(rawBytes, offset + 4),
                    I_08  = BitConverter.ToInt32(rawBytes, offset + 8),
                    F_12  = BitConverter.ToSingle(rawBytes, offset + 12),
                    F_16  = BitConverter_Ex.ToFloat32Array(rawBytes, offset + 16, 6),
                    I_40  = BitConverter.ToInt32(rawBytes, offset + 40),
                    I_44  = BitConverter.ToInt32(rawBytes, offset + 44),
                    F_48  = BitConverter_Ex.ToFloat32Array(rawBytes, offset + 48, 6),
                    I_72  = BitConverter_Ex.ToInt32Array(rawBytes, offset + 72, 6),
                    F_96  = BitConverter.ToSingle(rawBytes, offset + 96),
                    F_100 = BitConverter.ToSingle(rawBytes, offset + 100),
                    F_104 = BitConverter.ToSingle(rawBytes, offset + 104),
                    F_108 = BitConverter.ToSingle(rawBytes, offset + 108),
                    F_112 = BitConverter.ToSingle(rawBytes, offset + 112),
                    F_116 = BitConverter.ToSingle(rawBytes, offset + 116),
                    F_120 = BitConverter.ToSingle(rawBytes, offset + 120),
                    F_124 = BitConverter.ToSingle(rawBytes, offset + 124),
                    F_128 = BitConverter.ToSingle(rawBytes, offset + 128),
                    F_132 = BitConverter.ToSingle(rawBytes, offset + 132),
                    F_136 = BitConverter.ToSingle(rawBytes, offset + 136),
                    F_140 = BitConverter.ToSingle(rawBytes, offset + 140),
                    F_144 = BitConverter.ToSingle(rawBytes, offset + 144),
                    F_148 = BitConverter.ToSingle(rawBytes, offset + 148),
                    F_152 = BitConverter.ToSingle(rawBytes, offset + 152),
                    F_156 = BitConverter_Ex.ToFloat32Array(rawBytes, offset + 156, 17)
                });
                offset += 224;
            }

            return(effects);
        }
Beispiel #17
0
        private void WriteFile()
        {
            //Section 1
            bytes.Add(1);

            for (int i = 0; i < tsd_File.Triggers.Count(); i++)
            {
                bytes.AddRange(BitConverter.GetBytes(int.Parse(tsd_File.Triggers[i].Index)));
                bytes.AddRange(BitConverter.GetBytes(tsd_File.Triggers[i].I_04));
                bytes.AddRange(BitConverter.GetBytes(tsd_File.Triggers[i].I_08));
                bytes.AddRange(BitConverter.GetBytes(tsd_File.Triggers[i].I_12));
                bytes.AddRange(BitConverter.GetBytes(int.Parse(tsd_File.Triggers[i].I_16)));
                bytes.AddRange(BitConverter.GetBytes(tsd_File.Triggers[i].I_20));

                bytes.AddRange(BitConverter.GetBytes(int.Parse(tsd_File.Triggers[i].I_24)));
                bytes.AddRange(BitConverter.GetBytes(tsd_File.Triggers[i].I_28));
                bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Triggers[i].Condition)));
                bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Triggers[i].Condition));
            }



            //Section 2
            bytes.AddRange(BitConverter.GetBytes(magicNumber));
            bytes.Add(2);
            for (int i = 0; i < tsd_File.Events.Count(); i++)
            {
                bytes.AddRange(BitConverter.GetBytes(int.Parse(tsd_File.Events[i].Index)));
                bytes.AddRange(BitConverter.GetBytes(tsd_File.Events[i].I_04));

                bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Events[i].Str1)));
                bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Events[i].Str1));
                bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Events[i].Str2)));
                bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Events[i].Str2));
                bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Events[i].Str3)));
                bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Events[i].Str3));
                bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Events[i].Str4)));
                bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Events[i].Str4));

                string args = tsd_File.Events[i].Arguments.Write();
                bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(args)));
                bytes.AddRange(Encoding.UTF8.GetBytes(args));

                bytes.AddRange(BitConverter.GetBytes(tsd_File.Events[i].TNL_IDs.Count()));
                List <int> tnlIds = ArrayConvert.ConvertToInt32List(tsd_File.Events[i].TNL_IDs);
                bytes.AddRange(BitConverter_Ex.GetBytes(tnlIds.ToArray()));
            }


            //Section 3
            bytes.AddRange(BitConverter.GetBytes(magicNumber));
            bytes.Add(3);
            for (int i = 0; i < tsd_File.Globals.Count(); i++)
            {
                bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Globals[i].Index)));
                bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Globals[i].Index));
                bytes.AddRange(BitConverter.GetBytes(tsd_File.Globals[i].Type));
                bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Globals[i].Str)));
                bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Globals[i].Str));
            }


            //Section 4
            bytes.AddRange(BitConverter.GetBytes(magicNumber));
            bytes.Add(4);
            for (int i = 0; i < tsd_File.Constants.Count(); i++)
            {
                bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Constants[i].Index)));
                bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Constants[i].Index));
                bytes.AddRange(BitConverter.GetBytes(tsd_File.Constants[i].Type));
                bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Constants[i].Str)));
                bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Constants[i].Str));
            }


            //Section 5
            bytes.AddRange(BitConverter.GetBytes(magicNumber));
            bytes.Add(5);
            for (int i = 0; i < tsd_File.Zones.Count(); i++)
            {
                bytes.AddRange(BitConverter.GetBytes(int.Parse(tsd_File.Zones[i].Index)));
                bytes.AddRange(BitConverter.GetBytes(tsd_File.Zones[i].I_04));
                bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Zones[i].Str)));
                bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Zones[i].Str));
            }
        }
Beispiel #18
0
        private void Parse()
        {
            //counts
            int partsetCount    = BitConverter.ToInt16(rawBytes, 12);
            int partcolorsCount = BitConverter.ToInt16(rawBytes, 14);
            int bodyCount       = BitConverter.ToInt16(rawBytes, 16);

            //offsets
            int partsetOffset    = BitConverter.ToInt32(rawBytes, 24);
            int partcolorsOffset = BitConverter.ToInt32(rawBytes, 28);
            int bodyOffset       = BitConverter.ToInt32(rawBytes, 32);
            int skeleton2Offset  = BitConverter.ToInt32(rawBytes, 36);
            int skeleton1Offset  = BitConverter.ToInt32(rawBytes, 40);

            //Header
            byte[] _I_44 = rawBytes.GetRange(44, 4);
            bcsFile.Race = _I_44[0];
            bcsFile.Sex  = Convert.ToBoolean(_I_44[1]);
            bcsFile.F_48 = BitConverter_Ex.ToFloat32Array(rawBytes, 48, 7);

            //PartSets
            int actualIndex = 0;

            if (partsetCount > 0)
            {
                bcsFile.PartSets = new List <PartSet>();
                for (int i = 0; i < partsetCount; i++)
                {
                    int thisPartsetOffset = BitConverter.ToInt32(rawBytes, partsetOffset);
                    if (thisPartsetOffset != 0)
                    {
                        bcsFile.PartSets.Add(new PartSet()
                        {
                            Index = i.ToString()
                        });
                        if (BitConverter.ToInt32(rawBytes, thisPartsetOffset + 20) != 10)
                        {
                            throw new Exception(string.Format("Part count mismatch on PartSet {0} (Expected 10, but found {1})\nThis BCS file cannot be parsed.", i, BitConverter.ToInt32(rawBytes, thisPartsetOffset + 20)));
                        }

                        int tableOffset = thisPartsetOffset + BitConverter.ToInt32(rawBytes, thisPartsetOffset + 24);

                        bcsFile.PartSets[actualIndex].FaceBase     = ParsePart(BitConverter.ToInt32(rawBytes, tableOffset + 0), thisPartsetOffset);
                        bcsFile.PartSets[actualIndex].FaceForehead = ParsePart(BitConverter.ToInt32(rawBytes, tableOffset + 4), thisPartsetOffset);
                        bcsFile.PartSets[actualIndex].FaceEye      = ParsePart(BitConverter.ToInt32(rawBytes, tableOffset + 8), thisPartsetOffset);
                        bcsFile.PartSets[actualIndex].FaceNose     = ParsePart(BitConverter.ToInt32(rawBytes, tableOffset + 12), thisPartsetOffset);
                        bcsFile.PartSets[actualIndex].FaceEar      = ParsePart(BitConverter.ToInt32(rawBytes, tableOffset + 16), thisPartsetOffset);
                        bcsFile.PartSets[actualIndex].Hair         = ParsePart(BitConverter.ToInt32(rawBytes, tableOffset + 20), thisPartsetOffset);
                        bcsFile.PartSets[actualIndex].Bust         = ParsePart(BitConverter.ToInt32(rawBytes, tableOffset + 24), thisPartsetOffset);
                        bcsFile.PartSets[actualIndex].Pants        = ParsePart(BitConverter.ToInt32(rawBytes, tableOffset + 28), thisPartsetOffset);
                        bcsFile.PartSets[actualIndex].Rist         = ParsePart(BitConverter.ToInt32(rawBytes, tableOffset + 32), thisPartsetOffset);
                        bcsFile.PartSets[actualIndex].Boots        = ParsePart(BitConverter.ToInt32(rawBytes, tableOffset + 36), thisPartsetOffset);

                        actualIndex++;
                    }
                    partsetOffset += 4;
                }
            }

            //PartColors
            if (partcolorsCount > 0)
            {
                bcsFile.Part_Colors = new List <PartColor>();

                for (int i = 0; i < partcolorsCount; i++)
                {
                    int thisPartColorOffset = BitConverter.ToInt32(rawBytes, partcolorsOffset);

                    if (thisPartColorOffset != 0)
                    {
                        bcsFile.Part_Colors.Add(new PartColor()
                        {
                            Index   = i.ToString(),
                            Str_00  = Utils.GetString(bytes, BitConverter.ToInt32(rawBytes, thisPartColorOffset + 0) + thisPartColorOffset),
                            _Colors = ParseColors(BitConverter.ToInt32(rawBytes, thisPartColorOffset + 12) + thisPartColorOffset, BitConverter.ToInt16(rawBytes, thisPartColorOffset + 10))
                        });
                    }

                    partcolorsOffset += 4;
                }
            }


            //BodyScales
            if (bodyCount > 0)
            {
                bcsFile.Bodies = new List <Body>();

                for (int i = 0; i < bodyCount; i++)
                {
                    int thisBodyScaleOffset = BitConverter.ToInt32(rawBytes, bodyOffset);
                    if (thisBodyScaleOffset != 0)
                    {
                        bcsFile.Bodies.Add(ParseBody(thisBodyScaleOffset, i));
                    }
                    bodyOffset += 4;
                }
            }

            if (skeleton1Offset != 0)
            {
                bcsFile.SkeletonData1 = ParseSkeleton(BitConverter.ToInt32(rawBytes, skeleton1Offset));
            }
            if (skeleton2Offset != 0)
            {
                bcsFile.SkeletonData2 = ParseSkeleton(BitConverter.ToInt32(rawBytes, skeleton2Offset));
            }
        }
Beispiel #19
0
        private void WriteDem()
        {
            //init
            int unkValueCount  = (demFile.DEM_UnkValues != null) ? demFile.DEM_UnkValues.Count : 0;
            int section2Count  = (demFile.Section2Entries != null) ? demFile.Section2Entries.Count : 0;
            int actorCount     = (demFile.Settings.Characters != null) ? demFile.Settings.Characters.Count : 0;
            int charaOffsetPos = 0;

            //Header
            bytes.AddRange(BitConverter.GetBytes(DEM_File.DEM_SIGNATURE)); //Signature
            bytes.AddRange(BitConverter.GetBytes((ushort)65534));          //Endianess
            bytes.AddRange(BitConverter.GetBytes((ushort)64));             //Header size
            bytes.AddRange(BitConverter.GetBytes(demFile.I_08));           //Version?
            bytes.AddRange(BitConverter.GetBytes(section2Count));          //Count
            bytes.AddRange(BitConverter.GetBytes(unkValueCount));          //UnkValues Count
            bytes.AddRange(new byte[12]);                                  //Padding
            bytes.AddRange(BitConverter.GetBytes((UInt64)64));             //Offset to name
            bytes.AddRange(BitConverter.GetBytes((UInt64)0));              //Offset to Section 2 (fill in later)
            bytes.AddRange(BitConverter.GetBytes((UInt64)80));             //Offset to DemoSettings
            bytes.AddRange(BitConverter.GetBytes((UInt64)0));              //File size (fill in later)

            //Name
            Assertion.AssertStringSize(demFile.Name, 16, "DEM", "Name");
            bytes.AddRange(Utils.GetStringBytes(demFile.Name, 16));

            //DemoSettings
            stringInfo.Add(new StringWriter.StringInfo()
            {
                StringToWrite = demFile.Settings.Str_00, Offset = bytes.Count, RelativeOffset = 0
            });
            bytes.AddRange(new byte[8]); //0
            stringInfo.Add(new StringWriter.StringInfo()
            {
                StringToWrite = demFile.Settings.Str_08, Offset = bytes.Count, RelativeOffset = 0
            });
            bytes.AddRange(new byte[8]); //8
            stringInfo.Add(new StringWriter.StringInfo()
            {
                StringToWrite = demFile.Settings.Str_16, Offset = bytes.Count, RelativeOffset = 0
            });
            bytes.AddRange(new byte[8]); //16
            stringInfo.Add(new StringWriter.StringInfo()
            {
                StringToWrite = demFile.Settings.Str_24, Offset = bytes.Count, RelativeOffset = 0
            });
            bytes.AddRange(new byte[8]); //24
            stringInfo.Add(new StringWriter.StringInfo()
            {
                StringToWrite = demFile.Settings.Str_32, Offset = bytes.Count, RelativeOffset = 0
            });
            bytes.AddRange(new byte[8]); //32
            stringInfo.Add(new StringWriter.StringInfo()
            {
                StringToWrite = demFile.Settings.Str_40, Offset = bytes.Count, RelativeOffset = 0
            });
            bytes.AddRange(new byte[8]); //40
            stringInfo.Add(new StringWriter.StringInfo()
            {
                StringToWrite = demFile.Settings.Str_48, Offset = bytes.Count, RelativeOffset = 0
            });
            bytes.AddRange(new byte[8]); //48
            stringInfo.Add(new StringWriter.StringInfo()
            {
                StringToWrite = demFile.Settings.Str_56, Offset = bytes.Count, RelativeOffset = 0
            });
            bytes.AddRange(new byte[8]); //56
            stringInfo.Add(new StringWriter.StringInfo()
            {
                StringToWrite = demFile.Settings.Str_64, Offset = bytes.Count, RelativeOffset = 0
            });
            bytes.AddRange(new byte[8]); //64
            stringInfo.Add(new StringWriter.StringInfo()
            {
                StringToWrite = demFile.Settings.Str_72, Offset = bytes.Count, RelativeOffset = 0
            });
            bytes.AddRange(new byte[8]); //72
            stringInfo.Add(new StringWriter.StringInfo()
            {
                StringToWrite = demFile.Settings.Str_80, Offset = bytes.Count, RelativeOffset = 0
            });
            bytes.AddRange(new byte[8]); //80
            stringInfo.Add(new StringWriter.StringInfo()
            {
                StringToWrite = demFile.Settings.Str_88, Offset = bytes.Count, RelativeOffset = 0
            });
            bytes.AddRange(new byte[8]); //88
            stringInfo.Add(new StringWriter.StringInfo()
            {
                StringToWrite = demFile.Settings.Str_96, Offset = bytes.Count, RelativeOffset = 0
            });
            bytes.AddRange(new byte[8]); //96
            stringInfo.Add(new StringWriter.StringInfo()
            {
                StringToWrite = demFile.Settings.Str_104, Offset = bytes.Count, RelativeOffset = 0
            });
            bytes.AddRange(new byte[12]); //104
            bytes.AddRange(BitConverter.GetBytes(actorCount));
            charaOffsetPos = bytes.Count;
            bytes.AddRange(BitConverter.GetBytes(208)); //Offset to actors, fill in later
            bytes.AddRange(new byte[4]);

            //Actors/charactors
            if (actorCount > 0)
            {
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), charaOffsetPos);

                for (int i = 0; i < actorCount; i++)
                {
                    stringInfo.Add(new StringWriter.StringInfo()
                    {
                        StringToWrite = demFile.Settings.Characters[i].Str_00, Offset = bytes.Count, RelativeOffset = 0
                    });
                    bytes.AddRange(new byte[8]);                                                //0
                    bytes.AddRange(BitConverter.GetBytes(demFile.Settings.Characters[i].I_08)); //8
                    bytes.AddRange(new byte[4]);                                                //12
                    stringInfo.Add(new StringWriter.StringInfo()
                    {
                        StringToWrite = demFile.Settings.Characters[i].Str_16, Offset = bytes.Count, RelativeOffset = 0
                    });
                    bytes.AddRange(new byte[48]); //16
                }
            }

            //Pad the file (it must be in 16-byte blocks before string section starts)
            FilePad();

            //Write strings
            bytes = StringWriter.WritePointerStrings(stringInfo, bytes);

            //Pad the file (it must be in 16-byte blocks before Section2 starts)
            bytes.Add(0);
            FilePad();

            //Section2
            bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), 40); //Filling in header offset
            List <int> section2Offsets = new List <int>();

            //Section2 main entries
            for (int i = 0; i < section2Count; i++)
            {
                bytes.AddRange(BitConverter.GetBytes(demFile.Section2Entries[i].I_00));
                bytes.AddRange(BitConverter.GetBytes((demFile.Section2Entries[i].SubEntries != null) ? demFile.Section2Entries[i].SubEntries.Count : 0));
                section2Offsets.Add(bytes.Count);
                bytes.AddRange(new byte[24]);
            }

            //Section2 subentries
            for (int i = 0; i < section2Count; i++)
            {
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), section2Offsets[i]);
                int subEntryCount = (demFile.Section2Entries[i].SubEntries != null) ? demFile.Section2Entries[i].SubEntries.Count : 0;
                demFile.Section2Entries[i].SubEntries = demFile.Section2Entries[i].SubEntries.OrderBy(o => o.I_00).ToList();

                for (int a = 0; a < subEntryCount; a++)
                {
                    bytes.AddRange(BitConverter.GetBytes(demFile.Section2Entries[i].SubEntries[a].I_00));

                    //Type
                    int[] type = demFile.Section2Entries[i].SubEntries[a].GetDemoType();
                    bytes.AddRange(BitConverter.GetBytes((ushort)type[0])); //Type1
                    bytes.AddRange(BitConverter.GetBytes((ushort)type[1])); //Type2
                    bytes.AddRange(new byte[4]);                            //Padding
                    demFile.Section2Entries[i].SubEntries[a].ValueCount = type[2];
                    bytes.AddRange(BitConverter.GetBytes(type[2]));         //Count
                    demFile.Section2Entries[i].SubEntries[a].PointerOffset = bytes.Count;
                    bytes.AddRange(new byte[16]);                           //Offset and padding
                }
            }

            //Types (pointer list)
            for (int i = 0; i < section2Count; i++)
            {
                int subEntryCount = (demFile.Section2Entries[i].SubEntries != null) ? demFile.Section2Entries[i].SubEntries.Count : 0;
                for (int a = 0; a < subEntryCount; a++)
                {
                    if (demFile.Section2Entries[i].SubEntries[a].ValueCount > 0)
                    {
                        bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), demFile.Section2Entries[i].SubEntries[a].PointerOffset);
                    }

                    for (int z = 0; z < demFile.Section2Entries[i].SubEntries[a].ValueCount; z++)
                    {
                        demFile.Section2Entries[i].SubEntries[a].ValueOffsets.Add(bytes.Count);
                        bytes.AddRange(new byte[8]);
                    }
                }
            }

            //Types (values)
            for (int i = 0; i < section2Count; i++)
            {
                int subEntryCount = (demFile.Section2Entries[i].SubEntries != null) ? demFile.Section2Entries[i].SubEntries.Count : 0;
                for (int a = 0; a < subEntryCount; a++)
                {
                    DEM_Type.DemoDataTypes type = demFile.Section2Entries[i].SubEntries[a].GetDemoDataType();

                    switch (type)
                    {
                    case DEM_Type.DemoDataTypes.Type0_1_6:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type0_1_6.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.FadeInOut:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type0_2_7.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type0_3_8:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type0_3_8.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type0_16_1:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type0_16_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type0_19_1:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type0_19_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type0_20_2:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type0_20_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type0_21_2:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type0_21_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_1_5:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_1_5.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_1_9:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_1_9.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_2_3:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_2_3.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_2_5:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_2_5.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Transformation:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_4_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_6_4:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_6_4.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_7_1:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_7_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_8_6:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_8_6.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_11_2:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_11_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_12_2:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_12_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_13_10:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_13_10.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_14_1:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_14_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_16_2:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_16_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_20_12:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_20_12.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_26_2:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_26_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_27_2:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_27_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.AnimationSmall:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_0_9.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Animation:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_0_10.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.ActorVisibility:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_3_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.ActorDamage:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_9_5.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_10_8:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_10_8.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_17_6:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_17_6.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type1_19_3:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type1_19_3.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type2_6_3:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type2_6_3.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type2_7_5:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type2_7_5.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type2_9_2:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type2_9_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type2_10_2:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type2_10_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type2_11_1:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type2_11_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type3_0_1:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type3_0_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type3_1_1:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type3_1_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Camera:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type2_0_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type2_7_8:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type2_7_8.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type3_2_1:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type3_2_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type3_3_1:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type3_3_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type3_4_2:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type3_4_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Effect:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type4_0_12.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.ScreenEffect:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type4_1_8.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type4_2_3:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type4_2_3.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type4_3_5:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type4_3_5.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type4_4_1:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type4_4_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Sound:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type5_0_3.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Music:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type5_2_3.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type5_0_2:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type5_0_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type5_1_2:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type5_1_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type5_3_2:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type5_3_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type5_4_3:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type5_4_3.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type6_0_1:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type6_0_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.DistanceFocus:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type6_16_6.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.SpmControl:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type6_17_19.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type6_18_7:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type6_18_7.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type6_19_15:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type6_19_15.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type6_20_2:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type6_20_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type7_0_5:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type7_0_5.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.YearDisplay:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type9_0_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type9_1_5:
                        bytes = demFile.Section2Entries[i].SubEntries[a].Type9_1_5.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets);
                        break;

                    case DEM_Type.DemoDataTypes.Type0_16_0:
                    case DEM_Type.DemoDataTypes.Type0_17_0:
                    case DEM_Type.DemoDataTypes.Type9_8_0:
                        //No values
                        break;

                    default:
                        throw new Exception(String.Format("Unrecognized DEM_Type: {0}", type));
                    }
                }
            }

            //Pad file before UnkValues
            bytes.Add(0);
            FilePad();
            bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), 56);

            //UnkValues
            for (int i = 0; i < unkValueCount; i++)
            {
                Assertion.AssertArraySize(demFile.DEM_UnkValues[i].Values, 40, "DEM_UnknownValues", "uint16s");
                bytes.AddRange(BitConverter_Ex.GetBytes(demFile.DEM_UnkValues[i].Values));
            }
        }
Beispiel #20
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;
                }
            }
        }
Beispiel #21
0
        private void ParseDem()
        {
            //Validation
            if (BitConverter.ToInt16(rawBytes, 6) == 32)
            {
                throw new Exception("Xenoverse 1 DEM format not supported.");
            }
            if (BitConverter.ToInt16(rawBytes, 6) != 64 || BitConverter.ToInt32(rawBytes, 0) != DEM_File.DEM_SIGNATURE)
            {
                throw new Exception("DEM header validation failed.");
            }

            //Header
            demFile.I_08 = BitConverter.ToInt32(rawBytes, 8);
            int unkValuesCount  = BitConverter.ToInt32(rawBytes, 16);
            int unkValuesOffset = BitConverter.ToInt32(rawBytes, 56);
            int nameOffset      = BitConverter.ToInt32(rawBytes, 32);
            int defineOffset    = BitConverter.ToInt32(rawBytes, 48);
            int section2Count   = BitConverter.ToInt32(rawBytes, 12);
            int section2Offset  = BitConverter.ToInt32(rawBytes, 40);

            //Name
            demFile.Name = Utils.GetString(bytes, nameOffset, 16);

            //Define Section
            demFile.Settings = new DemoSettings()
            {
                Str_00     = Utils.GetString(bytes, BitConverter.ToInt32(rawBytes, defineOffset + 0)),
                Str_08     = Utils.GetString(bytes, BitConverter.ToInt32(rawBytes, defineOffset + 8)),
                Str_16     = Utils.GetString(bytes, BitConverter.ToInt32(rawBytes, defineOffset + 16)),
                Str_24     = Utils.GetString(bytes, BitConverter.ToInt32(rawBytes, defineOffset + 24)),
                Str_32     = Utils.GetString(bytes, BitConverter.ToInt32(rawBytes, defineOffset + 32)),
                Str_40     = Utils.GetString(bytes, BitConverter.ToInt32(rawBytes, defineOffset + 40)),
                Str_48     = Utils.GetString(bytes, BitConverter.ToInt32(rawBytes, defineOffset + 48)),
                Str_56     = Utils.GetString(bytes, BitConverter.ToInt32(rawBytes, defineOffset + 56)),
                Str_64     = Utils.GetString(bytes, BitConverter.ToInt32(rawBytes, defineOffset + 64)),
                Str_72     = Utils.GetString(bytes, BitConverter.ToInt32(rawBytes, defineOffset + 72)),
                Str_80     = Utils.GetString(bytes, BitConverter.ToInt32(rawBytes, defineOffset + 80)),
                Str_88     = Utils.GetString(bytes, BitConverter.ToInt32(rawBytes, defineOffset + 88)),
                Str_96     = Utils.GetString(bytes, BitConverter.ToInt32(rawBytes, defineOffset + 96)),
                Str_104    = Utils.GetString(bytes, BitConverter.ToInt32(rawBytes, defineOffset + 104)),
                Characters = ParseCharacters(BitConverter.ToInt32(rawBytes, defineOffset + 120), BitConverter.ToInt32(rawBytes, defineOffset + 116))
            };

            //Section 2
            demFile.Section2Entries = new List <Section2Entry>();
            for (int i = 0; i < section2Count; i++)
            {
                demFile.Section2Entries.Add(new Section2Entry()
                {
                    I_00       = BitConverter.ToInt32(rawBytes, section2Offset + 0),
                    SubEntries = ParseSection2SubEntry(BitConverter.ToInt32(rawBytes, section2Offset + 8), BitConverter.ToInt32(rawBytes, section2Offset + 4))
                });
                section2Offset += 32;
            }

            //UnkValues
            if (unkValuesCount > 0)
            {
                demFile.DEM_UnkValues = new List <DEM_UnknownValues>();

                for (int i = 0; i < unkValuesCount; i++)
                {
                    demFile.DEM_UnkValues.Add(new DEM_UnknownValues()
                    {
                        Values = BitConverter_Ex.ToUInt16Array(rawBytes, unkValuesOffset, 40)
                    });
                    unkValuesOffset += 80;
                }
            }
        }
Beispiel #22
0
        private void WriteBac()
        {
            SortEntries();

            int                count           = (bacFile.BacEntries != null) ? bacFile.BacEntries.Count() : 0;
            List <int>         BacEntryOffsets = new List <int>();
            List <List <int> > TypeOffsets     = new List <List <int> >();

            //Header
            bytes.AddRange(BitConverter.GetBytes(count));
            bytes.AddRange(new byte[4]);
            bytes.AddRange(BitConverter.GetBytes(96));
            bytes.AddRange(BitConverter_Ex.GetBytes(bacFile.I_20));
            bytes.AddRange(BitConverter_Ex.GetBytes(bacFile.F_32));
            bytes.AddRange(BitConverter_Ex.GetBytes(bacFile.I_80));

            //Bac_Entries
            for (int i = 0; i < count; i++)
            {
                if (bacFile.BacEntries[i].TypeDummy == null)
                {
                    bacFile.BacEntries[i].TypeDummy = new List <int>();
                }

                bytes.AddRange(BitConverter.GetBytes((uint)bacFile.BacEntries[i].Flag));
                bytes.AddRange(BitConverter.GetBytes((short)GetSubEntryCount(bacFile.BacEntries[i])));
                bytes.AddRange(BitConverter.GetBytes((short)0));
                BacEntryOffsets.Add(bytes.Count());
                bytes.AddRange(new byte[8]);
            }

            //Bac_SubEntries
            for (int i = 0; i < count; i++)
            {
                TypeOffsets.Add(new List <int>());
                int   subEntryCount = GetSubEntryCount(bacFile.BacEntries[i]);
                int[] types         = GetSubEntryTypes(bacFile.BacEntries[i]);

                if (subEntryCount > 0)
                {
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), BacEntryOffsets[i]);

                    for (int a = 0; a < subEntryCount; a++)
                    {
                        bytes.AddRange(BitConverter.GetBytes((short)types[a]));
                        bytes.AddRange(BitConverter.GetBytes((short)GetTypeCount(bacFile.BacEntries[i], types[a])));
                        bytes.AddRange(new byte[4]);
                        TypeOffsets[i].Add(bytes.Count());
                        bytes.AddRange(new byte[8]);
                    }
                }
            }

            //Bac Types
            for (int i = 0; i < count; i++)
            {
                int   subEntryCount = GetSubEntryCount(bacFile.BacEntries[i]);
                int[] types         = GetSubEntryTypes(bacFile.BacEntries[i]);

                for (int a = 0; a < subEntryCount; a++)
                {
                    if (bacFile.BacEntries[i].TypeDummy.IndexOf(types[a]) == -1)
                    {
                        bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), TypeOffsets[i][a]);

                        switch (types[a])
                        {
                        case 0:
                            bytes.AddRange(BAC_Type0.Write(bacFile.BacEntries[i].Type0));
                            break;

                        case 1:
                            bytes.AddRange(BAC_Type1.Write(bacFile.BacEntries[i].Type1));
                            break;

                        case 2:
                            bytes.AddRange(BAC_Type2.Write(bacFile.BacEntries[i].Type2));
                            break;

                        case 3:
                            bytes.AddRange(BAC_Type3.Write(bacFile.BacEntries[i].Type3));
                            break;

                        case 4:
                            bytes.AddRange(BAC_Type4.Write(bacFile.BacEntries[i].Type4));
                            break;

                        case 5:
                            bytes.AddRange(BAC_Type5.Write(bacFile.BacEntries[i].Type5));
                            break;

                        case 6:
                            bytes.AddRange(BAC_Type6.Write(bacFile.BacEntries[i].Type6));
                            break;

                        case 7:
                            bytes.AddRange(BAC_Type7.Write(bacFile.BacEntries[i].Type7));
                            break;

                        case 8:
                            bytes.AddRange(BAC_Type8.Write(bacFile.BacEntries[i].Type8));
                            break;

                        case 9:
                            bytes.AddRange(BAC_Type9.Write(bacFile.BacEntries[i].Type9));
                            break;

                        case 10:
                            bytes.AddRange(BAC_Type10.Write(bacFile.BacEntries[i].Type10));
                            break;

                        case 11:
                            bytes.AddRange(BAC_Type11.Write(bacFile.BacEntries[i].Type11));
                            break;

                        case 12:
                            bytes.AddRange(BAC_Type12.Write(bacFile.BacEntries[i].Type12));
                            break;

                        case 13:
                            bytes.AddRange(BAC_Type13.Write(bacFile.BacEntries[i].Type13));
                            break;

                        case 14:
                            bytes.AddRange(BAC_Type14.Write(bacFile.BacEntries[i].Type14));
                            break;

                        case 15:
                            bytes.AddRange(BAC_Type15.Write(bacFile.BacEntries[i].Type15));
                            break;

                        case 16:
                            bytes.AddRange(BAC_Type16.Write(bacFile.BacEntries[i].Type16));
                            break;

                        case 17:
                            bytes.AddRange(BAC_Type17.Write(bacFile.BacEntries[i].Type17));
                            break;

                        case 18:
                            bytes.AddRange(BAC_Type18.Write(bacFile.BacEntries[i].Type18));
                            break;

                        case 19:
                            bytes.AddRange(BAC_Type19.Write(bacFile.BacEntries[i].Type19));
                            break;

                        case 20:
                            bytes.AddRange(BAC_Type20.Write(bacFile.BacEntries[i].Type20));
                            break;

                        case 21:
                            bytes.AddRange(BAC_Type21.Write(bacFile.BacEntries[i].Type21));
                            break;

                        case 22:
                            bytes.AddRange(BAC_Type22.Write(bacFile.BacEntries[i].Type22));
                            break;

                        case 23:
                            bytes.AddRange(BAC_Type23.Write(bacFile.BacEntries[i].Type23));
                            break;

                        case 24:
                            bytes.AddRange(BAC_Type24.Write(bacFile.BacEntries[i].Type24));
                            break;

                        case 25:
                            bytes.AddRange(BAC_Type25.Write(bacFile.BacEntries[i].Type25));
                            break;

                        case 26:
                            bytes.AddRange(BAC_Type26.Write(bacFile.BacEntries[i].Type26));
                            break;

                        case 27:
                            bytes.AddRange(BAC_Type27.Write(bacFile.BacEntries[i].Type27));
                            break;
                        }
                    }
                }
            }
        }
Beispiel #23
0
        private void WriteSkeleton(ESK_Skeleton skeleton, int offsetToReplace)
        {
            List <ESK_BoneNonHierarchal> bones = eskFile.Skeleton.GetNonHierarchalBoneList();

            bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), offsetToReplace);

            int startOffset = bytes.Count();
            int count       = (bones != null) ? bones.Count() : 0;

            bytes.AddRange(BitConverter.GetBytes((short)count));
            bytes.AddRange(BitConverter.GetBytes(skeleton.I_02));
            bytes.AddRange(new byte[24]);
            bytes.AddRange(BitConverter_Ex.GetBytes(skeleton.I_28));

            if (count > 0)
            {
                //Writing Index List
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - startOffset), startOffset + 4);

                for (int i = 0; i < count; i++)
                {
                    bytes.AddRange(BitConverter.GetBytes(bones[i].Index1));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].Index2));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].Index3));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].Index4));
                }

                //Writing Name Table and List
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - startOffset), startOffset + 8);
                List <StringWriter.StringInfo> stringInfo = new List <StringWriter.StringInfo>();

                for (int i = 0; i < count; i++)
                {
                    stringInfo.Add(new StringWriter.StringInfo()
                    {
                        StringToWrite  = bones[i].Name,
                        Offset         = bytes.Count(),
                        RelativeOffset = startOffset
                    });
                    bytes.AddRange(new byte[4]);
                }

                for (int i = 0; i < count; i++)
                {
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - stringInfo[i].RelativeOffset), stringInfo[i].Offset);
                    bytes.AddRange(Encoding.ASCII.GetBytes(stringInfo[i].StringToWrite));
                    bytes.Add(0);
                }

                //Writing RelativeTransform
                StartNewLine();
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - startOffset), startOffset + 12);

                for (int i = 0; i < count; i++)
                {
                    bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_00));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_04));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_08));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_12));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_16));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_20));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_24));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_28));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_32));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_36));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_40));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_44));
                }

                //Writing AbsoluteTransform (esk only)
                StartNewLine();
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - startOffset), startOffset + 16);

                for (int i = 0; i < count; i++)
                {
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_00));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_04));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_08));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_12));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_16));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_20));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_24));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_28));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_32));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_36));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_40));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_44));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_48));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_52));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_56));
                    bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_60));
                }

                //Writing Unk1
                if (skeleton.Unk1 != null)
                {
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - startOffset), startOffset + 20);
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_00));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_04));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_08));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_12));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_16));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_20));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_24));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_28));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_32));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_36));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_40));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_44));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_48));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_52));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_56));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_60));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_64));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_68));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_72));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_76));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_80));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_84));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_88));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_92));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_96));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_100));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_104));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_108));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_112));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_116));
                    bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_120));
                }

                //Writing Unk2
                if (skeleton.UseUnk2 == true && count > 0)
                {
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - startOffset), startOffset + 24);

                    for (int i = 0; i < count; i++)
                    {
                        bytes.AddRange(BitConverter.GetBytes(281470681743360));
                    }
                }
            }
        }
Beispiel #24
0
        void ParseCharacters()
        {
            int offset = chara1Offset;

            for (int i = 0; i < chara1Count; i++)
            {
                qxd_File.Characters1.Add(new Quest_Characters()
                {
                    Index          = BitConverter.ToInt32(rawBytes, offset).ToString(),
                    CharaShortName = StringEx.GetString(bytes, offset + 4, false, StringEx.EncodingType.ASCII, 3),
                    I_08           = BitConverter.ToInt32(rawBytes, offset + 8),
                    I_12           = BitConverter.ToInt32(rawBytes, offset + 12),
                    I_16           = BitConverter.ToInt32(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),
                    F_48           = BitConverter.ToSingle(rawBytes, offset + 48),
                    F_52           = BitConverter.ToSingle(rawBytes, offset + 52),
                    F_56           = BitConverter.ToSingle(rawBytes, offset + 56),
                    F_60           = BitConverter.ToSingle(rawBytes, offset + 60),
                    F_64           = BitConverter.ToSingle(rawBytes, offset + 64),
                    F_68           = BitConverter.ToSingle(rawBytes, offset + 68),
                    F_72           = BitConverter.ToSingle(rawBytes, offset + 72),
                    F_76           = BitConverter.ToSingle(rawBytes, offset + 76),
                    F_80           = BitConverter.ToSingle(rawBytes, offset + 80),
                    I_84           = BitConverter.ToInt32(rawBytes, offset + 84).ToString(),
                    _Skills        = new Skills
                    {
                        I_00 = BitConverter.ToUInt16(rawBytes, offset + 88).ToString(),
                        I_02 = BitConverter.ToUInt16(rawBytes, offset + 90).ToString(),
                        I_04 = BitConverter.ToUInt16(rawBytes, offset + 92).ToString(),
                        I_06 = BitConverter.ToUInt16(rawBytes, offset + 94).ToString(),
                        I_08 = BitConverter.ToUInt16(rawBytes, offset + 96).ToString(),
                        I_10 = BitConverter.ToUInt16(rawBytes, offset + 98).ToString(),
                        I_12 = BitConverter.ToUInt16(rawBytes, offset + 100).ToString(),
                        I_14 = BitConverter.ToUInt16(rawBytes, offset + 102).ToString(),
                        I_16 = BitConverter.ToUInt16(rawBytes, offset + 104).ToString(),
                    },
                    I_106 = BitConverter_Ex.ToInt16Array(rawBytes, offset + 106, 7),
                    I_120 = BitConverter.ToInt16(rawBytes, offset + 120),
                    I_122 = BitConverter.ToUInt16(rawBytes, offset + 122).ToString()
                });
                offset += 124;
            }

            offset = chara2Offset;

            for (int i = 0; i < chara2Count; i++)
            {
                qxd_File.Characters2.Add(new Quest_Characters()
                {
                    Index          = BitConverter.ToInt32(rawBytes, offset).ToString(),
                    CharaShortName = StringEx.GetString(bytes, offset + 4, false, StringEx.EncodingType.ASCII),
                    I_08           = BitConverter.ToInt32(rawBytes, offset + 8),
                    I_12           = BitConverter.ToInt32(rawBytes, offset + 12),
                    I_16           = BitConverter.ToInt32(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),
                    F_48           = BitConverter.ToSingle(rawBytes, offset + 48),
                    F_52           = BitConverter.ToSingle(rawBytes, offset + 52),
                    F_56           = BitConverter.ToSingle(rawBytes, offset + 56),
                    F_60           = BitConverter.ToSingle(rawBytes, offset + 60),
                    F_64           = BitConverter.ToSingle(rawBytes, offset + 64),
                    F_68           = BitConverter.ToSingle(rawBytes, offset + 68),
                    F_72           = BitConverter.ToSingle(rawBytes, offset + 72),
                    F_76           = BitConverter.ToSingle(rawBytes, offset + 76),
                    F_80           = BitConverter.ToSingle(rawBytes, offset + 80),
                    I_84           = BitConverter.ToInt32(rawBytes, offset + 84).ToString(),
                    _Skills        = new Skills
                    {
                        I_00 = BitConverter.ToUInt16(rawBytes, offset + 88).ToString(),
                        I_02 = BitConverter.ToUInt16(rawBytes, offset + 90).ToString(),
                        I_04 = BitConverter.ToUInt16(rawBytes, offset + 92).ToString(),
                        I_06 = BitConverter.ToUInt16(rawBytes, offset + 94).ToString(),
                        I_08 = BitConverter.ToUInt16(rawBytes, offset + 96).ToString(),
                        I_10 = BitConverter.ToUInt16(rawBytes, offset + 98).ToString(),
                        I_12 = BitConverter.ToUInt16(rawBytes, offset + 100).ToString(),
                        I_14 = BitConverter.ToUInt16(rawBytes, offset + 102).ToString(),
                        I_16 = BitConverter.ToUInt16(rawBytes, offset + 104).ToString(),
                    },
                    I_106 = BitConverter_Ex.ToInt16Array(rawBytes, offset + 106, 7),
                    I_120 = BitConverter.ToInt16(rawBytes, offset + 120),
                    I_122 = BitConverter.ToUInt16(rawBytes, offset + 122).ToString()
                });
                offset += 124;
            }
        }
Beispiel #25
0
        private void ParseBac()
        {
            int offset = BitConverter.ToInt32(rawBytes, 16);
            int count  = BitConverter.ToInt32(rawBytes, 8);

            bacFile.I_20       = BitConverter_Ex.ToInt32Array(rawBytes, 20, 3);
            bacFile.F_32       = BitConverter_Ex.ToFloat32Array(rawBytes, 32, 12);
            bacFile.I_80       = BitConverter_Ex.ToInt32Array(rawBytes, 80, 4);
            bacFile.BacEntries = AsyncObservableCollection <BAC_Entry> .Create();

            for (int i = 0; i < count; i++)
            {
                int typeListOffset = BitConverter.ToInt32(rawBytes, offset + 8);
                int typeListCount  = BitConverter.ToInt16(rawBytes, offset + 4);

                bacFile.BacEntries.Add(new BAC_Entry()
                {
                    Flag  = (BAC_Entry.Flags)BitConverter.ToUInt32(rawBytes, offset + 0),
                    Index = i.ToString()
                });

                for (int a = 0; a < typeListCount; a++)
                {
                    int thisType       = BitConverter.ToInt16(rawBytes, typeListOffset + 0);
                    int thisTypeCount  = BitConverter.ToInt16(rawBytes, typeListOffset + 2);
                    int thisTypeOffset = BitConverter.ToInt32(rawBytes, typeListOffset + 8);


                    if (thisTypeOffset != 0)
                    {
                        switch (thisType)
                        {
                        case 0:
                            bacFile.BacEntries[i].Type0 = BAC_Type0.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 1:
                            bacFile.BacEntries[i].Type1 = BAC_Type1.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 2:
                            bacFile.BacEntries[i].Type2 = BAC_Type2.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 3:
                            bacFile.BacEntries[i].Type3 = BAC_Type3.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 4:
                            bacFile.BacEntries[i].Type4 = BAC_Type4.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 5:
                            bacFile.BacEntries[i].Type5 = BAC_Type5.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 6:
                            bacFile.BacEntries[i].Type6 = BAC_Type6.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 7:
                            bacFile.BacEntries[i].Type7 = BAC_Type7.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 8:
                            bacFile.BacEntries[i].Type8 = BAC_Type8.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 9:
                            bacFile.BacEntries[i].Type9 = BAC_Type9.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 10:
                            bacFile.BacEntries[i].Type10 = BAC_Type10.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 11:
                            bacFile.BacEntries[i].Type11 = BAC_Type11.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 12:
                            bacFile.BacEntries[i].Type12 = BAC_Type12.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 13:
                            bacFile.BacEntries[i].Type13 = BAC_Type13.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 14:
                            bacFile.BacEntries[i].Type14 = BAC_Type14.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 15:
                            bacFile.BacEntries[i].Type15 = BAC_Type15.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 16:
                            bacFile.BacEntries[i].Type16 = BAC_Type16.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 17:
                            bacFile.BacEntries[i].Type17 = BAC_Type17.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount, IsType17Small(thisTypeOffset, thisTypeCount, i));
                            break;

                        case 18:
                            bacFile.BacEntries[i].Type18 = BAC_Type18.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 19:
                            bacFile.BacEntries[i].Type19 = BAC_Type19.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 20:
                            bacFile.BacEntries[i].Type20 = BAC_Type20.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 21:
                            bacFile.BacEntries[i].Type21 = BAC_Type21.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 22:
                            bacFile.BacEntries[i].Type22 = BAC_Type22.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 23:
                            bacFile.BacEntries[i].Type23 = BAC_Type23.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 24:
                            bacFile.BacEntries[i].Type24 = BAC_Type24.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 25:
                            bacFile.BacEntries[i].Type25 = BAC_Type25.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 26:
                            bacFile.BacEntries[i].Type26 = BAC_Type26.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 27:
                            bacFile.BacEntries[i].Type27 = BAC_Type27.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        default:
                            throw new InvalidDataException(String.Format("Parse failed. Unknown BacType encountered ({0})\nOffset: {1}\nCount: {2}.", thisType, thisTypeOffset, thisTypeCount));
                        }
                    }
                    else
                    {
                        if (bacFile.BacEntries[i].TypeDummy == null)
                        {
                            bacFile.BacEntries[i].TypeDummy = new List <int>();
                        }
                        bacFile.BacEntries[i].TypeDummy.Add(thisType);
                    }


                    typeListOffset += 16;
                }


                offset += 16;
            }
        }
Beispiel #26
0
        private void Write()
        {
            //Header
            int I_18 = (bcsFile.SkeletonData2 != null) ? 1 : 0;

            byte[] _i_44 = { bcsFile.Race, Convert.ToByte(bcsFile.Sex), 0, 0 };
            bytes.AddRange(BitConverter.GetBytes((short)PartSetCount));
            bytes.AddRange(BitConverter.GetBytes((short)PartColorCount));
            bytes.AddRange(BitConverter.GetBytes((short)BodyCount));
            bytes.AddRange(BitConverter.GetBytes((short)I_18));
            bytes.AddRange(new byte[24]);
            bytes.AddRange(_i_44);
            Assertion.AssertArraySize(bcsFile.F_48, 7, "BCS", "F_48");
            bytes.AddRange(BitConverter_Ex.GetBytes(bcsFile.F_48));


            //PartSet Table
            if (bcsFile.PartSets != null)
            {
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), 24);
                for (int i = 0; i < PartSetCount; i++)
                {
                    for (int a = 0; a < bcsFile.PartSets.Count; a++)
                    {
                        if (int.Parse(bcsFile.PartSets[a].Index) == i)
                        {
                            PartSetTable.Add(bytes.Count());
                            bytes.AddRange(new byte[4]);
                            break;
                        }
                        else if (a == bcsFile.PartSets.Count() - 1)
                        {
                            //Null entry
                            bytes.AddRange(new byte[4]);
                            break;
                        }
                    }
                }
            }

            //PartColor Table
            if (bcsFile.Part_Colors != null)
            {
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), 28);
                for (int i = 0; i < PartColorCount; i++)
                {
                    for (int a = 0; a < bcsFile.Part_Colors.Count(); a++)
                    {
                        if (int.Parse(bcsFile.Part_Colors[a].Index) == i)
                        {
                            PartColorTable.Add(bytes.Count());
                            bytes.AddRange(new byte[4]);
                            break;
                        }
                        else if (a == bcsFile.Part_Colors.Count() - 1)
                        {
                            //Null entry
                            bytes.AddRange(new byte[4]);
                            break;
                        }
                    }
                }
            }

            //Body Table
            if (bcsFile.Bodies != null)
            {
                bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), 32);
                for (int i = 0; i < BodyCount; i++)
                {
                    for (int a = 0; a < bcsFile.Bodies.Count(); a++)
                    {
                        if (int.Parse(bcsFile.Bodies[a].Index) == i)
                        {
                            BodyTable.Add(bytes.Count());
                            bytes.AddRange(new byte[4]);
                            break;
                        }
                        else if (a == bcsFile.Bodies.Count() - 1)
                        {
                            //Null entry
                            bytes.AddRange(new byte[4]);
                            break;
                        }
                    }
                }
            }

            //Skeleton1 Table
            if (bcsFile.SkeletonData1 != null)
            {
                bytes          = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), 40);
                Skeleton1Table = bytes.Count();
                bytes.AddRange(new byte[4]);
            }

            //Skeleton2 Table
            if (bcsFile.SkeletonData2 != null)
            {
                bytes          = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), 36);
                Skeleton2Table = bytes.Count();
                bytes.AddRange(new byte[4]);
            }

            //PartSets
            if (bcsFile.PartSets != null)
            {
                for (int i = 0; i < bcsFile.PartSets.Count(); i++)
                {
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), PartSetTable[i]);
                    int PartSetStart = bytes.Count();

                    bytes.AddRange(new byte[20]);
                    bytes.AddRange(BitConverter.GetBytes(10));
                    bytes.AddRange(BitConverter.GetBytes(32));
                    bytes.AddRange(new byte[4]);
                    int[] PartSetSubTable = new int[10] {
                        bytes.Count() + 0, bytes.Count() + 4, bytes.Count() + 8, bytes.Count() + 12, bytes.Count() + 16, bytes.Count() + 20, bytes.Count() + 24, bytes.Count() + 28, bytes.Count() + 32, bytes.Count() + 36
                    };
                    bytes.AddRange(new byte[40]);

                    //Parts
                    WritePart(bcsFile.PartSets[i].FaceBase, PartSetSubTable[0], PartSetStart);
                    WritePart(bcsFile.PartSets[i].FaceForehead, PartSetSubTable[1], PartSetStart);
                    WritePart(bcsFile.PartSets[i].FaceEye, PartSetSubTable[2], PartSetStart);
                    WritePart(bcsFile.PartSets[i].FaceNose, PartSetSubTable[3], PartSetStart);
                    WritePart(bcsFile.PartSets[i].FaceEar, PartSetSubTable[4], PartSetStart);
                    WritePart(bcsFile.PartSets[i].Hair, PartSetSubTable[5], PartSetStart);
                    WritePart(bcsFile.PartSets[i].Bust, PartSetSubTable[6], PartSetStart);
                    WritePart(bcsFile.PartSets[i].Pants, PartSetSubTable[7], PartSetStart);
                    WritePart(bcsFile.PartSets[i].Rist, PartSetSubTable[8], PartSetStart);
                    WritePart(bcsFile.PartSets[i].Boots, PartSetSubTable[9], PartSetStart);
                }
            }

            //PartColors
            if (bcsFile.Part_Colors != null)
            {
                List <int> PartColorOffsets = new List <int>();

                for (int i = 0; i < bcsFile.Part_Colors.Count(); i++)
                {
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), PartColorTable[i]);
                    int PartColorStart = bytes.Count();
                    int colorCount     = (bcsFile.Part_Colors[i]._Colors != null) ? bcsFile.Part_Colors[i]._Colors.Count() : 0;

                    stringInfo.Add(new StringWriter.StringInfo()
                    {
                        Offset         = bytes.Count(),
                        RelativeOffset = PartColorStart,
                        StringToWrite  = bcsFile.Part_Colors[i].Str_00
                    });
                    bytes.AddRange(new byte[10]);
                    bytes.AddRange(BitConverter.GetBytes((short)colorCount));
                    PartColorOffsets.Add(bytes.Count());
                    bytes.AddRange(new byte[4]);
                }

                for (int i = 0; i < bcsFile.Part_Colors.Count(); i++)
                {
                    if (bcsFile.Part_Colors[i]._Colors != null)
                    {
                        bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - PartColorOffsets[i] + 12), PartColorOffsets[i]);
                        for (int a = 0; a < bcsFile.Part_Colors[i]._Colors.Count(); a++)
                        {
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_00));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_04));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_08));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_12));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_16));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_20));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_24));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_28));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_32));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_36));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_40));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_44));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_48));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_52));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_56));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_60));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_64));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_68));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_72));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_76));
                        }
                    }
                }
            }

            //Bodies
            if (bcsFile.Bodies != null)
            {
                List <int> BodyOffsets = new List <int>();

                for (int i = 0; i < bcsFile.Bodies.Count(); i++)
                {
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), BodyTable[i]);

                    int bodyScalesCount = (bcsFile.Bodies[i].BodyScales != null) ? bcsFile.Bodies[i].BodyScales.Count() : 0;
                    bytes.AddRange(new byte[2]);
                    bytes.AddRange(BitConverter.GetBytes((short)bodyScalesCount));
                    BodyOffsets.Add(bytes.Count());
                    bytes.AddRange(new byte[4]);
                }

                for (int i = 0; i < bcsFile.Bodies.Count(); i++)
                {
                    if (bcsFile.Bodies[i].BodyScales != null)
                    {
                        bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - BodyOffsets[i] + 4), BodyOffsets[i]);

                        for (int a = 0; a < bcsFile.Bodies[i].BodyScales.Count(); a++)
                        {
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Bodies[i].BodyScales[a].F_00));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Bodies[i].BodyScales[a].F_04));
                            bytes.AddRange(BitConverter.GetBytes(bcsFile.Bodies[i].BodyScales[a].F_08)); stringInfo.Add(new StringWriter.StringInfo()
                            {
                                Offset         = bytes.Count(),
                                RelativeOffset = bytes.Count() - 12,
                                StringToWrite  = bcsFile.Bodies[i].BodyScales[a].Str_12
                            });
                            bytes.AddRange(new byte[4]);
                        }
                    }
                }
            }

            //Skeleton1
            WriteSkeleton(bcsFile.SkeletonData1, Skeleton1Table);

            //Skeleton2
            WriteSkeleton(bcsFile.SkeletonData2, Skeleton2Table);

            //Strings
            bytes = StringWriter.WritePointerStrings(stringInfo, bytes);
        }
Beispiel #27
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;
            }
        }
Beispiel #28
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);
        }
Beispiel #29
0
        public void WriteBai()
        {
            List <int> EntryOffsets = new List <int>();

            int count = (baiFile.Entries != null) ? baiFile.Entries.Count() : 0;

            bytes.AddRange(BitConverter.GetBytes(count));
            bytes.AddRange(BitConverter.GetBytes(16));

            if (baiFile.Entries != null)
            {
                for (int i = 0; i < baiFile.Entries.Count(); i++)
                {
                    int subEntryCount = (baiFile.Entries[i].SubEntries != null) ? baiFile.Entries[i].SubEntries.Count() : 0;
                    bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].I_00));
                    bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].I_04));
                    bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].I_08));
                    bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].I_12));
                    bytes.AddRange(BitConverter.GetBytes(subEntryCount));
                    EntryOffsets.Add(bytes.Count());
                    bytes.AddRange(new byte[4]);
                }

                for (int i = 0; i < baiFile.Entries.Count(); i++)
                {
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), EntryOffsets[i]);
                    if (baiFile.Entries[i].SubEntries != null)
                    {
                        for (int a = 0; a < baiFile.Entries[i].SubEntries.Count(); a++)
                        {
                            //Name Str
                            if (baiFile.Entries[i].SubEntries[a].Name.Count() > 8)
                            {
                                Console.WriteLine(String.Format("The name \"{0}\" exceeds the maximum length of 8!", baiFile.Entries[i].SubEntries[a].Name));
                                Utils.WaitForInputThenQuit();
                            }
                            bytes.AddRange(Encoding.ASCII.GetBytes(baiFile.Entries[i].SubEntries[a].Name));
                            int remainingSpace = 8 - baiFile.Entries[i].SubEntries[a].Name.Count();
                            for (int z = 0; z < remainingSpace; z++)
                            {
                                bytes.Add(0);
                            }

                            //Data
                            bytes.AddRange(BitConverter_Ex.GetBytes_Bool32(baiFile.Entries[i].SubEntries[a].I_08));
                            bytes.AddRange(BitConverter.GetBytes((int)baiFile.Entries[i].SubEntries[a].I_12));
                            bytes.AddRange(BitConverter.GetBytes((int)baiFile.Entries[i].SubEntries[a].I_16));
                            bytes.AddRange(BitConverter.GetBytes((int)baiFile.Entries[i].SubEntries[a].I_20));
                            bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].SubEntries[a].I_24));
                            bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].SubEntries[a].I_28));
                            bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].SubEntries[a].I_32));
                            bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].SubEntries[a].I_36));
                            bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].SubEntries[a].I_40));
                            bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].SubEntries[a].I_44));
                            bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].SubEntries[a].I_48));
                            bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].SubEntries[a].I_52));
                            bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].SubEntries[a].I_56));
                            bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].SubEntries[a].I_60));
                            bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].SubEntries[a].I_64));
                            bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].SubEntries[a].F_68));
                            bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].SubEntries[a].F_72));
                            bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].SubEntries[a].F_76));
                            bytes.AddRange(BitConverter.GetBytes(baiFile.Entries[i].SubEntries[a].F_80));
                        }
                    }
                }
            }
        }
Beispiel #30
0
        void ParseQuestData()
        {
            int offset = questsOffset;

            for (int i = 0; i < questsCount; i++)
            {
                //counts & offsets
                int msgEntryCount       = BitConverter.ToInt32(rawBytes, offset + 32);
                int equipRewardCount    = BitConverter.ToInt32(rawBytes, offset + 160);
                int skillRewardCount    = BitConverter.ToInt32(rawBytes, offset + 168);
                int unk1count           = BitConverter.ToInt32(rawBytes, offset + 88);
                int unk2Count           = BitConverter.ToInt32(rawBytes, offset + 96);
                int charaUnlockCount    = BitConverter.ToInt32(rawBytes, offset + 176);
                int stagePortraitCount  = BitConverter.ToInt32(rawBytes, offset + 184);
                int qedFileCount        = BitConverter.ToInt32(rawBytes, offset + 112);
                int msgEntryOffset      = BitConverter.ToInt32(rawBytes, offset + 36);
                int equipRewardOffset   = BitConverter.ToInt32(rawBytes, offset + 164);
                int skillRewardOffset   = BitConverter.ToInt32(rawBytes, offset + 172);
                int unk1Offset          = BitConverter.ToInt32(rawBytes, offset + 92);
                int unk2Offset          = BitConverter.ToInt32(rawBytes, offset + 100);
                int charaUnlockOffset   = BitConverter.ToInt32(rawBytes, offset + 180);
                int stagePortraitOffset = BitConverter.ToInt32(rawBytes, offset + 188);
                int qedFileOffset       = BitConverter.ToInt32(rawBytes, offset + 116);

                qxd_File.Quests.Add(new Quest_Data());
                qxd_File.Quests[i].Name = StringEx.GetString(bytes, offset, false, StringEx.EncodingType.ASCII, 16);

                qxd_File.Quests[i].Index = BitConverter.ToInt32(rawBytes, offset + 16).ToString();
                qxd_File.Quests[i].I_20  = BitConverter.ToInt32(rawBytes, offset + 20);
                qxd_File.Quests[i].I_24  = BitConverter.ToInt32(rawBytes, offset + 24);
                qxd_File.Quests[i].I_28  = BitConverter.ToInt32(rawBytes, offset + 28);
                qxd_File.Quests[i].I_40  = BitConverter.ToInt16(rawBytes, offset + 40);
                qxd_File.Quests[i].I_42  = BitConverter.ToInt16(rawBytes, offset + 42);
                qxd_File.Quests[i].I_44  = BitConverter.ToInt16(rawBytes, offset + 44);
                qxd_File.Quests[i].I_46  = BitConverter.ToInt16(rawBytes, offset + 46);
                qxd_File.Quests[i].I_64  = BitConverter.ToInt32(rawBytes, offset + 64);
                qxd_File.Quests[i].I_104 = BitConverter.ToInt16(rawBytes, offset + 104);
                qxd_File.Quests[i].I_106 = BitConverter.ToInt16(rawBytes, offset + 106);
                qxd_File.Quests[i].I_108 = BitConverter.ToInt16(rawBytes, offset + 108);
                qxd_File.Quests[i].I_110 = BitConverter.ToInt16(rawBytes, offset + 110);
                qxd_File.Quests[i].I_120 = BitConverter.ToInt32(rawBytes, offset + 120);
                qxd_File.Quests[i].I_124 = BitConverter.ToInt32(rawBytes, offset + 124);
                qxd_File.Quests[i].I_128 = BitConverter.ToInt32(rawBytes, offset + 128);
                qxd_File.Quests[i].I_132 = BitConverter.ToInt32(rawBytes, offset + 132);
                qxd_File.Quests[i].I_136 = BitConverter.ToInt32(rawBytes, offset + 136);
                qxd_File.Quests[i].I_140 = BitConverter.ToInt32(rawBytes, offset + 140);
                qxd_File.Quests[i].I_144 = BitConverter.ToInt32(rawBytes, offset + 144);
                qxd_File.Quests[i].I_148 = BitConverter.ToInt32(rawBytes, offset + 148);
                qxd_File.Quests[i].I_152 = BitConverter.ToInt32(rawBytes, offset + 152);
                qxd_File.Quests[i].I_156 = BitConverter.ToInt32(rawBytes, offset + 156);
                qxd_File.Quests[i].I_192 = BitConverter.ToInt32(rawBytes, offset + 192);
                qxd_File.Quests[i].I_248 = BitConverter.ToInt32(rawBytes, offset + 248);
                qxd_File.Quests[i].I_252 = BitConverter.ToInt32(rawBytes, offset + 252);
                qxd_File.Quests[i].I_256 = (QxdUpdate)BitConverter.ToInt32(rawBytes, offset + 256);
                qxd_File.Quests[i].I_260 = (QxdDlc)BitConverter.ToInt32(rawBytes, offset + 260);
                qxd_File.Quests[i].I_264 = BitConverter.ToInt32(rawBytes, offset + 264);
                qxd_File.Quests[i].I_268 = BitConverter.ToInt16(rawBytes, offset + 268);
                qxd_File.Quests[i].I_270 = BitConverter.ToInt16(rawBytes, offset + 270);
                qxd_File.Quests[i].I_272 = BitConverter.ToInt16(rawBytes, offset + 272);
                qxd_File.Quests[i].I_274 = BitConverter.ToInt16(rawBytes, offset + 274);
                qxd_File.Quests[i].F_276 = BitConverter.ToSingle(rawBytes, offset + 276);
                qxd_File.Quests[i].I_280 = BitConverter.ToInt32(rawBytes, offset + 280);


                qxd_File.Quests[i].I_48 = BitConverter_Ex.ToInt32Array(rawBytes, offset + 48, 4);
                qxd_File.Quests[i].I_68 = BitConverter_Ex.ToInt32Array(rawBytes, offset + 68, 5);

                qxd_File.Quests[i].I_232 = BitConverter_Ex.ToInt16Array(rawBytes, offset + 232, 8);

                if (unk1count > 0)
                {
                    int tempOffset = unk1Offset;
                    qxd_File.Quests[i].UnknownNum1 = new List <UnkNum1>();
                    for (int a = 0; a < unk1count; a++)
                    {
                        qxd_File.Quests[i].UnknownNum1.Add(new UnkNum1()
                        {
                            I_00 = BitConverter_Ex.ToInt16Array(rawBytes, tempOffset, 16)
                        });

                        tempOffset += 32;
                    }
                }
                if (unk2Count > 0)
                {
                    int tempOffset = unk2Offset;
                    qxd_File.Quests[i].UnknownNum2 = new List <UnkNum2>();
                    for (int a = 0; a < unk2Count; a++)
                    {
                        qxd_File.Quests[i].UnknownNum2.Add(new UnkNum2()
                        {
                            I_00 = BitConverter_Ex.ToInt16Array(rawBytes, tempOffset, 16)
                        });

                        tempOffset += 32;
                    }
                }

                if (equipRewardCount > 0)
                {
                    qxd_File.Quests[i].EquipReward = new List <EquipmentReward>();
                    int equipOffset = equipRewardOffset;
                    for (int b = 0; b < equipRewardCount; b++)
                    {
                        qxd_File.Quests[i].EquipReward.Add(new EquipmentReward()
                        {
                            I_00 = (QxdItemType)BitConverter.ToInt32(rawBytes, equipOffset),
                            I_04 = BitConverter.ToInt32(rawBytes, equipOffset + 4),
                            I_08 = BitConverter.ToInt32(rawBytes, equipOffset + 8),
                            I_12 = BitConverter.ToInt32(rawBytes, equipOffset + 12),
                            I_16 = BitConverter.ToInt32(rawBytes, equipOffset + 16),
                            I_20 = BitConverter.ToInt16(rawBytes, equipOffset + 20),
                            F_24 = BitConverter.ToSingle(rawBytes, equipOffset + 24),
                            I_28 = BitConverter.ToInt32(rawBytes, equipOffset + 28)
                        });

                        equipOffset += 32;
                    }
                }

                if (skillRewardCount > 0)
                {
                    qxd_File.Quests[i].Skill_Reward = new List <SkillReward>();
                    int skillOffset = skillRewardOffset;
                    for (int b = 0; b < skillRewardCount; b++)
                    {
                        qxd_File.Quests[i].Skill_Reward.Add(new SkillReward()
                        {
                            I_00 = (QxdSkillType)BitConverter.ToInt32(rawBytes, skillOffset + 0),
                            I_04 = BitConverter.ToInt32(rawBytes, skillOffset + 4),
                            I_08 = BitConverter.ToInt32(rawBytes, skillOffset + 8),
                            I_12 = BitConverter.ToInt32(rawBytes, skillOffset + 12),
                            F_16 = BitConverter.ToSingle(rawBytes, skillOffset + 16)
                        });
                        skillOffset += 20;
                    }
                }



                if (charaUnlockCount > 0)
                {
                    qxd_File.Quests[i].Chara_Unlock = new List <CharaUnlock>();
                    int charaOffset = charaUnlockOffset;
                    for (int b = 0; b < charaUnlockCount; b++)
                    {
                        qxd_File.Quests[i].Chara_Unlock.Add(new CharaUnlock()
                        {
                            ShortName    = StringEx.GetString(bytes, charaOffset, false, StringEx.EncodingType.ASCII, 3),
                            CostumeIndex = BitConverter.ToInt16(rawBytes, charaOffset + 4),
                            I_06         = BitConverter.ToInt16(rawBytes, charaOffset + 6)
                        });
                        charaOffset += 8;
                    }
                }

                int portraitOffset = 196;
                qxd_File.Quests[i].EnemyPortraitDisplay = new List <EnemyPortrait>();
                for (int b = 0; b < 6; b++)
                {
                    qxd_File.Quests[i].EnemyPortraitDisplay.Add(new EnemyPortrait());
                    qxd_File.Quests[i].EnemyPortraitDisplay[b].CharaID      = BitConverter.ToInt16(rawBytes, offset + portraitOffset);
                    qxd_File.Quests[i].EnemyPortraitDisplay[b].CostumeIndex = BitConverter.ToInt16(rawBytes, offset + portraitOffset + 2);
                    qxd_File.Quests[i].EnemyPortraitDisplay[b].State        = BitConverter.ToInt16(rawBytes, offset + portraitOffset + 4);
                    portraitOffset += 6;
                }

                if (stagePortraitCount > 0)
                {
                    qxd_File.Quests[i].StageDisplay = new List <short>();
                    for (int j = 0; j < 32; j += 2)
                    {
                        qxd_File.Quests[i].StageDisplay.Add(BitConverter.ToInt16(rawBytes, stagePortraitOffset + j));
                    }
                }

                if (msgEntryCount > 0)
                {
                    qxd_File.Quests[i].MsgFiles = new List <string>();
                    int msgOffset = msgEntryOffset;
                    for (int j = 0; j < msgEntryCount; j++)
                    {
                        qxd_File.Quests[i].MsgFiles.Add(StringEx.GetString(bytes, msgOffset, false, StringEx.EncodingType.ASCII, 32));
                        msgOffset += 32;
                    }
                }

                if (qedFileCount > 0)
                {
                    qxd_File.Quests[i].QedFiles = new List <string>();
                    int qedOffset = qedFileOffset;
                    for (int j = 0; j < qedFileCount; j++)
                    {
                        qxd_File.Quests[i].QedFiles.Add(StringEx.GetString(bytes, qedOffset, false, StringEx.EncodingType.ASCII, 32));
                        qedOffset += 32;
                    }
                }
                offset += 284;
            }
        }