Exemple #1
0
 public void Serialize(Stream s, DAIEbx EbxFile)
 {
     FieldName       = EbxFile.KeywordDict[Tools.ReadInt(s)];
     FieldStartIndex = Tools.ReadInt(s);
     FieldCount      = s.ReadByte();
     Alignment       = s.ReadByte();
     FieldType       = Tools.ReadShort(s);
     FieldSize       = Tools.ReadShort(s);
     SecondarySize   = Tools.ReadShort(s);
 }
Exemple #2
0
        public static DAIEbx ReadFromFile(String Filename)
        {
            FileStream file = new FileStream(Filename, FileMode.Open);
            DAIEbx     ebx  = new DAIEbx();

            ebx.Serialize(file);
            file.Close();

            return(ebx);
        }
Exemple #3
0
        public void Serialize(Stream s, DAIEbx EbxFile)
        {
            FieldName        = EbxFile.KeywordDict[Tools.ReadInt(s)];
            FieldType        = Tools.ReadShort(s);
            ComplexReference = Tools.ReadShort(s);
            PayloadOffset    = Tools.ReadInt(s);
            SecondaryOffset  = Tools.ReadInt(s);

            if (FieldName == "$")
            {
                PayloadOffset -= 8;
            }
        }
        public static byte[] ExtractEbx(MemoryStream EbxBuffer)
        {
            MemoryStream OutputStream = new MemoryStream();

            DAIEbx EbxFile = new DAIEbx();

            EbxFile.Serialize(EbxBuffer);

            StreamWriter Writer = new StreamWriter(OutputStream);

            Writer.Write(EbxFile.GetString());
            Writer.Close();

            return(OutputStream.ToArray());
        }
Exemple #5
0
        public void WriteToXmlWriter(XmlWriter xmlWriter, DAIEbx EbxFile)
        {
            if (Descriptor.FieldName != "array")
            {
                xmlWriter.WriteStartElement(Descriptor.FieldName);
            }

            foreach (DAIField CurField in Fields)
            {
                CurField.WriteToXMLWriter(xmlWriter, EbxFile);
            }

            if (Descriptor.FieldName != "array")
            {
                xmlWriter.WriteEndElement();
            }
        }
Exemple #6
0
        public string GetString(DAIEbx EbxFile, ref int TabCount, bool bPrintDescriptor = true)
        {
            String RetVal = "";

            if (Descriptor.FieldName != "array")
            {
                if (bPrintDescriptor)
                {
                    TabCount++;
                    RetVal += DAIEbx.Tabs(TabCount) + "<" + Descriptor.FieldName + ">\n";
                    TabCount++;
                }
            }
            else
            {
                TabCount++;
            }

            foreach (DAIField CurField in Fields)
            {
                RetVal += CurField.GetString(EbxFile, ref TabCount);
            }

            if (Descriptor.FieldName != "array")
            {
                if (bPrintDescriptor)
                {
                    TabCount--;
                    RetVal += DAIEbx.Tabs(TabCount) + "</" + Descriptor.FieldName + ">\n";
                    TabCount--;
                }
            }
            else
            {
                TabCount--;
            }

            return(RetVal);
        }
Exemple #7
0
        public DAISkeleton(DAIEbx Ebx)
        {
            Bones = new List <DAIBone>();

            DAIComplex BoneNamesArray = Ebx.RootInstance.GetFieldByName("BoneNames").GetComplexValue();

            foreach (DAIField BoneNameArrayMember in BoneNamesArray.Fields)
            {
                string BoneName = BoneNameArrayMember.GetStringValue();
                Bones.Add(new DAIBone(BoneName));
            }

            int        BoneIdx        = 0;
            DAIComplex HierarchyArray = Ebx.RootInstance.GetFieldByName("Hierarchy").GetComplexValue();

            foreach (DAIField HierarchyMember in HierarchyArray.Fields)
            {
                DAIBone Bone = Bones[BoneIdx];
                Bone.ParentIndex = HierarchyMember.GetIntValue();
                BoneIdx++;
            }

            BoneIdx = 0;
            DAIComplex LocalPoseArray = Ebx.RootInstance.GetFieldByName("LocalPose").GetComplexValue();

            foreach (DAIField LocalPoseMember in LocalPoseArray.Fields)
            {
                DAIBone    Bone            = Bones[BoneIdx];
                DAIComplex LinearTransform = LocalPoseMember.GetComplexValue();
                DAIComplex Right           = LinearTransform.GetFieldByName("right").GetComplexValue();
                DAIComplex Up      = LinearTransform.GetFieldByName("up").GetComplexValue();
                DAIComplex Forward = LinearTransform.GetFieldByName("forward").GetComplexValue();
                DAIComplex Trans   = LinearTransform.GetFieldByName("trans").GetComplexValue();

                Bone.Right   = new Vector3();
                Bone.Right.X = Right.GetFieldByName("x").GetFloatValue();
                Bone.Right.Y = Right.GetFieldByName("y").GetFloatValue();
                Bone.Right.Z = Right.GetFieldByName("z").GetFloatValue();

                Bone.Up   = new Vector3();
                Bone.Up.X = Up.GetFieldByName("x").GetFloatValue();
                Bone.Up.Y = Up.GetFieldByName("y").GetFloatValue();
                Bone.Up.Z = Up.GetFieldByName("z").GetFloatValue();

                Bone.Forward   = new Vector3();
                Bone.Forward.X = Forward.GetFieldByName("x").GetFloatValue();
                Bone.Forward.Y = Forward.GetFieldByName("y").GetFloatValue();
                Bone.Forward.Z = Forward.GetFieldByName("z").GetFloatValue();

                Bone.Location   = new Vector3();
                Bone.Location.X = Trans.GetFieldByName("x").GetFloatValue();
                Bone.Location.Y = Trans.GetFieldByName("y").GetFloatValue();
                Bone.Location.Z = Trans.GetFieldByName("z").GetFloatValue();

                BoneIdx++;
            }

            DAIComplex ModelPoseArray = Ebx.RootInstance.GetFieldByName("ModelPose").GetComplexValue();

            for (int i = 0; i < Bones.Count; i++)
            {
                Bones[i].Children = new List <DAIBone>();
                for (int j = 0; j < Bones.Count; j++)
                {
                    if (Bones[j].ParentIndex == i)
                    {
                        Bones[i].Children.Add(Bones[j]);
                    }
                }

                if (Bones[i].ParentIndex == -1 && RootBone == null)
                {
                    RootBone = Bones[i];
                }
            }
        }
Exemple #8
0
 public void Serialize(Stream s, DAIEbx EbxFile)
 {
     Offset = Tools.ReadInt(s);
     Count  = Tools.ReadInt(s);
     ComplexDescriptorIndex = Tools.ReadInt(s);
 }
Exemple #9
0
        public void WriteToXMLWriter(XmlWriter xmlWriter, DAIEbx EbxFile)
        {
            if (Descriptor.FieldName == "$")
            {
                ComplexValue.WriteToXmlWriter(xmlWriter, EbxFile);
                return;
            }

            xmlWriter.WriteStartElement(Descriptor.FieldName);

            switch (ValueType)
            {
            case DAIFieldType.DAI_Complex:
            case DAIFieldType.DAI_Array:
                if (ComplexValue != null)
                {
                    ComplexValue.WriteToXmlWriter(xmlWriter, EbxFile);
                }
                break;

            case DAIFieldType.DAI_String:
                xmlWriter.WriteString(XmlConvert.EncodeNmToken(GetStringValue()));
                break;

            case DAIFieldType.DAI_Int:
                xmlWriter.WriteValue(GetIntValue().ToString("X8"));
                break;

            case DAIFieldType.DAI_UInt:
                xmlWriter.WriteValue(GetUIntValue().ToString("X8"));
                break;

            case DAIFieldType.DAI_Float:
                xmlWriter.WriteValue(GetFloatValue().ToString("F3"));
                break;

            case DAIFieldType.DAI_Short:
                xmlWriter.WriteValue(GetShortValue().ToString("X4"));
                break;

            case DAIFieldType.DAI_UShort:
                xmlWriter.WriteValue(GetUShortValue().ToString("X4"));
                break;

            case DAIFieldType.DAI_Byte:
                xmlWriter.WriteValue(GetByteValue().ToString("X2"));
                break;

            case DAIFieldType.DAI_Long:
                xmlWriter.WriteValue(GetLongValue().ToString("X16"));
                break;

            case DAIFieldType.DAI_LongLong:
                for (int i = 0; i < Value.Length; i++)
                {
                    xmlWriter.WriteValue(Value[i].ToString("X2"));
                }
                break;

            case DAIFieldType.DAI_Enum:
                xmlWriter.WriteString(XmlConvert.EncodeNmToken(GetEnumValue()));
                break;

            case DAIFieldType.DAI_Guid:
            {
                uint UIntValue = GetUIntValue();
                if ((UIntValue >> 31) == 1)
                {
                    /* External Guid */
                    DAIExternalGuid Guid = EbxFile.ExternalGuids.ElementAt((int)(UIntValue & 0x7fffffff));
                    xmlWriter.WriteValue(Guid.ToString());
                }
                else if (UIntValue == 0)
                {
                    /* NULL Guid */
                    xmlWriter.WriteValue("00");
                }
                else
                {
                    /* Internal Guid */
                    byte[] Guid = EbxFile.InternalGuids[(int)(UIntValue - 1)];
                    for (int i = 0; i < Guid.Length; i++)
                    {
                        xmlWriter.WriteValue(Guid[i].ToString("X2"));
                    }
                }
            }
            break;
            }

            xmlWriter.WriteEndElement();
        }
Exemple #10
0
        public string GetString(DAIEbx EbxFile, ref int TabCount)
        {
            String RetVal = "";

            if (Descriptor.FieldName == "$")
            {
                TabCount--;
                RetVal += ComplexValue.GetString(EbxFile, ref TabCount);
                TabCount++;
                return(RetVal);
            }

            RetVal += DAIEbx.Tabs(TabCount) + "<" + Descriptor.FieldName + ">";

            switch (ValueType)
            {
            case DAIFieldType.DAI_Complex:
            case DAIFieldType.DAI_Array:
                RetVal += "\n" + ComplexValue.GetString(EbxFile, ref TabCount);
                RetVal += DAIEbx.Tabs(TabCount) + "</" + Descriptor.FieldName + ">\n";
                return(RetVal);

            case DAIFieldType.DAI_String:
                RetVal += GetStringValue();
                break;

            case DAIFieldType.DAI_Int:
                RetVal += GetIntValue().ToString("X8");
                break;

            case DAIFieldType.DAI_UInt:
                RetVal += GetUIntValue().ToString("X8");
                break;

            case DAIFieldType.DAI_Float:
                RetVal += GetFloatValue().ToString("F3");
                break;

            case DAIFieldType.DAI_Short:
                RetVal += GetShortValue().ToString("X4");
                break;

            case DAIFieldType.DAI_UShort:
                RetVal += GetUShortValue().ToString("X4");
                break;

            case DAIFieldType.DAI_Byte:
                RetVal += GetByteValue().ToString("X2");
                break;

            case DAIFieldType.DAI_Long:
                RetVal += GetLongValue().ToString("X16");
                break;

            case DAIFieldType.DAI_LongLong:
                for (int i = 0; i < Value.Length; i++)
                {
                    RetVal += Value[i].ToString("X2");
                }
                break;

            case DAIFieldType.DAI_Enum:
                RetVal += GetEnumValue();
                break;

            case DAIFieldType.DAI_Guid:
            {
                uint UIntValue = GetUIntValue();
                if ((UIntValue >> 31) == 1)
                {
                    /* External Guid */
                    DAIExternalGuid Guid = EbxFile.ExternalGuids.ElementAt((int)(UIntValue & 0x7fffffff));
                    RetVal += Guid.ToString();
                }
                else if (UIntValue == 0)
                {
                    /* NULL Guid */
                    RetVal += "00";
                }
                else
                {
                    /* Internal Guid */
                    byte[] Guid = EbxFile.InternalGuids[(int)(UIntValue - 1)];
                    for (int i = 0; i < Guid.Length; i++)
                    {
                        RetVal += Guid[i].ToString("X2");
                    }
                }
            }
            break;
            }

            RetVal += "</" + Descriptor.FieldName + ">\n";
            return(RetVal);
        }