Пример #1
0
        public void Init(XmlNode xml)
        {
            var kdxml = xml.SelectSingleNode("keyData");

            numKeyEntries = Xml.GetChildIntAttribute(kdxml, "numKeyEntries", "value");

            string kestr = Xml.GetChildInnerText(kdxml, "keyEntryData").Trim();

            string[] kearr = kestr.Split('\n');
            keyEntryData = new Dictionary <float, Vector4>();
            for (int i = 0; i < kearr.Length; i++)
            {
                string   kvstr = kearr[i].Trim();
                string[] kvarr = kvstr.Split('\t');
                float    key   = 0.0f;
                Vector4  val   = Vector4.Zero;
                if (kvarr.Length >= 5)
                {
                    FloatUtil.TryParse(kvarr[0].Trim(), out key);
                    FloatUtil.TryParse(kvarr[1].Trim(), out val.X);
                    FloatUtil.TryParse(kvarr[2].Trim(), out val.Y);
                    FloatUtil.TryParse(kvarr[3].Trim(), out val.Z);
                    FloatUtil.TryParse(kvarr[4].Trim(), out val.W);
                }
                else
                {
                }
                keyEntryData[key] = val;
            }
        }
Пример #2
0
        private void EntityScaleZTextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (CurrentEntity == null)
            {
                return;
            }
            float sz = 0;

            FloatUtil.TryParse(EntityScaleZTextBox.Text, out sz);
            lock (ProjectForm.ProjectSyncRoot)
            {
                if (CurrentEntity.Scale.Z != sz)
                {
                    Vector3 newscale = new Vector3(CurrentEntity.Scale.X, CurrentEntity.Scale.Y, sz);
                    CurrentEntity.SetScale(newscale);
                    ProjectForm.SetYmapHasChanged(true);
                    var wf = ProjectForm.WorldForm;
                    if (wf != null)
                    {
                        wf.BeginInvoke(new Action(() =>
                        {
                            wf.SetWidgetScale(newscale, true);
                        }));
                    }
                }
            }
        }
Пример #3
0
        public void Init(XmlElement xml)
        {
            string kftstr = Xml.GetChildInnerText(xml, "KeyframeTimes").Trim();

            string[] kftarr = kftstr.Split('\n');
            KeyframeTimes = new float[kftarr.Length];
            for (int i = 0; i < kftarr.Length; i++)
            {
                FloatUtil.TryParse(kftarr[i].Trim(), out KeyframeTimes[i]);
            }


            SettingsMap = new Dictionary <string, CloudSettingsMapItem>();
            XmlNodeList mapxml = xml.SelectNodes("SettingsMap/Item");

            foreach (XmlNode node in mapxml)
            {
                XmlElement itemel = node as XmlElement;
                if (itemel != null)
                {
                    CloudSettingsMapItem item = new CloudSettingsMapItem();
                    item.Init(itemel);
                    SettingsMap[item.Name] = item;
                }
            }
        }
Пример #4
0
        private void EntityChildLodDistTextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (CurrentEntity == null)
            {
                return;
            }
            float childLodDist = 0;

            FloatUtil.TryParse(EntityChildLodDistTextBox.Text, out childLodDist);
            lock (ProjectForm.ProjectSyncRoot)
            {
                if (CurrentEntity._CEntityDef.childLodDist != childLodDist)
                {
                    CurrentEntity._CEntityDef.childLodDist = childLodDist;
                    if (CurrentMCEntity != null)
                    {
                        CurrentMCEntity._Data.childLodDist = childLodDist;
                    }
                    ProjectItemChanged();
                }
            }
        }
Пример #5
0
        private float[] GetFloatArray(XmlNode node, string childName, char delimiter)
        {
            var ldastr = Xml.GetChildInnerText(node, childName);
            var ldarr  = ldastr?.Split(delimiter);

            if (ldarr == null)
            {
                return(null);
            }
            getFloatArrayList.Clear();
            foreach (var ldstr in ldarr)
            {
                var ldt = ldstr?.Trim();
                if (!string.IsNullOrEmpty(ldt))
                {
                    float f;
                    if (FloatUtil.TryParse(ldt, out f))
                    {
                        getFloatArrayList.Add(f);
                    }
                }
            }
            if (getFloatArrayList.Count == 0)
            {
                return(null);
            }
            return(getFloatArrayList.ToArray());
        }
Пример #6
0
        public static double ParseValue(Token firstToken, string fullValue)
        {
            double value;

            if (!FloatUtil.TryParse(fullValue, out value))
            {
                throw new ParserException(firstToken, "Invalid float literal.");
            }
            return(value);
        }
Пример #7
0
 public void Init(XmlNode node)
 {
     //read data node
     Name = node.Name;
     string[] strvals = node.InnerText.Trim().Split(' ');
     Values = new float[strvals.Length];
     for (int i = 0; i < strvals.Length; i++)
     {
         if (!FloatUtil.TryParse(strvals[i], out Values[i]))
         {
             //System.Windows.Forms.MessageBox.Show("Error parsing float value: " + strvals[i] + "\n" +
             //    "Node: " + node.OuterXml.ToString());
             //throw new Exception();
         }
     }
 }
Пример #8
0
 private static IRbfType CreateValueNode(string name, string val)
 {
     if (val == "True")
     {
         return(new RbfBoolean()
         {
             Name = name,
             Value = true
         });
     }
     else if (val == "False")
     {
         return(new RbfBoolean()
         {
             Name = name,
             Value = false
         });
     }
     else if (val.StartsWith("0x"))
     {
         uint.TryParse(val.Substring(2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint u);
         return(new RbfUint32()
         {
             Name = name,
             Value = u
         });
     }
     else if (FloatUtil.TryParse(val, out float f))
     {
         return(new RbfFloat()
         {
             Name = name,
             Value = f
         });
     }
     else
     {
         return(new RbfString()
         {
             Name = name,
             Value = val
         });
     }
 }
Пример #9
0
        private void BlendTextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (CurrentRoom == null)
            {
                return;
            }

            FloatUtil.TryParse(BlendTextBox.Text, out float blend);
            lock (ProjectForm.ProjectSyncRoot)
            {
                if (CurrentRoom._Data.blend != blend)
                {
                    CurrentRoom._Data.blend = blend;
                    ProjectForm.SetYtypHasChanged(true);
                }
            }
        }
Пример #10
0
        private void EntityLodDistTextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (CurrentEntity == null)
            {
                return;
            }
            float lodDist = 0;

            FloatUtil.TryParse(EntityLodDistTextBox.Text, out lodDist);
            lock (ProjectForm.ProjectSyncRoot)
            {
                if (CurrentEntity._CEntityDef.lodDist != lodDist)
                {
                    CurrentEntity._CEntityDef.lodDist = lodDist;
                    ProjectForm.SetYmapHasChanged(true);
                }
            }
        }
        private void Unk12TextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (CurrentRoom == null)
            {
                return;
            }

            float val = 0;

            if (FloatUtil.TryParse(Unk12TextBox.Text, out val))
            {
                if (CurrentRoom.Unk12 != val)
                {
                    CurrentRoom.Unk12 = val;

                    ProjectItemChanged();
                }
            }
        }
Пример #12
0
        public void Init(XmlElement xml)
        {
            Position = Xml.GetChildVector3Attributes(xml, "mPosition");
            Rotation = Xml.GetChildVector3Attributes(xml, "mRotation");
            Scale    = Xml.GetChildVector3Attributes(xml, "mScale");
            Name     = Xml.GetChildInnerText(xml, "mName");

            List <CloudHatFragLayer> layerlist = new List <CloudHatFragLayer>();
            XmlNodeList layersxml = xml.SelectNodes("mLayers/Item");

            foreach (XmlNode node in layersxml)
            {
                XmlElement layerel = node as XmlElement;
                if (layerel != null)
                {
                    CloudHatFragLayer layer = new CloudHatFragLayer();
                    layer.Init(layerel);
                    layerlist.Add(layer);
                }
            }
            Layers = layerlist.ToArray();

            TransitionAlphaRange = Xml.GetChildFloatAttribute(xml, "mTransitionAlphaRange", "value");
            TransitionMidPoint   = Xml.GetChildFloatAttribute(xml, "mTransitionMidPoint", "value");
            Enabled          = Xml.GetChildBoolAttribute(xml, "mEnabled", "value");
            AngularVelocity  = Xml.GetChildVector3Attributes(xml, "mAngularVelocity");
            AnimBlendWeights = Xml.GetChildVector3Attributes(xml, "mAnimBlendWeights");

            string uvvelocitystr = Xml.GetChildInnerText(xml, "mUVVelocity").Trim();

            string[] uvvelocities = uvvelocitystr.Split('\n');
            UVVelocity = new Vector2[uvvelocities.Length];
            for (int i = 0; i < uvvelocities.Length; i++)
            {
                Vector2  vel    = Vector2.Zero;
                string   uvvel  = uvvelocities[i].Trim();
                string[] uvvelc = uvvel.Split('\t');
                if (uvvelc.Length == 2)
                {
                    FloatUtil.TryParse(uvvelc[0].Trim(), out vel.X);
                    FloatUtil.TryParse(uvvelc[1].Trim(), out vel.Y);
                }
                UVVelocity[i] = vel;
            }

            string animmodestr = Xml.GetChildInnerText(xml, "mAnimMode").Trim();

            string[] animmodes = animmodestr.Split('\n');
            AnimMode = new byte[animmodes.Length];
            for (int i = 0; i < animmodes.Length; i++)
            {
                byte.TryParse(animmodes[i].Trim(), out AnimMode[i]);
            }


            //string showlayerstr = Xml.GetChildInnerText(xml, "mShowLayer").Trim();
            XmlNodeList showlayersxml = xml.SelectNodes("mShowLayer/Item");

            ShowLayer = new bool[showlayersxml.Count];
            for (int i = 0; i < showlayersxml.Count; i++)
            {
                XmlNode slnode = showlayersxml[i];
                if (slnode is XmlElement)
                {
                    ShowLayer[i] = Xml.GetBoolAttribute(slnode, "value");
                }
            }


            EnableAnimations = Xml.GetChildBoolAttribute(xml, "mEnableAnimations", "value");
        }
Пример #13
0
        private static void GetParsedArrayOfBytes(XmlNode node, byte[] data, MetaStructureEntryInfo_s entry, MetaStructureEntryInfo_s arrEntry)
        {
            int offset = entry.DataOffset;

            var ns    = NumberStyles.Any;
            var ic    = CultureInfo.InvariantCulture;
            var sa    = new[] { ' ' };
            var so    = StringSplitOptions.RemoveEmptyEntries;
            var split = node.InnerText.Trim().Split(sa, so); //split = Split(node.InnerText, 2); to read as unsplitted HEX

            switch (arrEntry.DataType)
            {
            default:     //expecting hex string.
                split = Split(node.InnerText, 2);
                for (int j = 0; j < split.Length; j++)
                {
                    byte val = Convert.ToByte(split[j], 16);
                    data[offset] = val;
                    offset      += sizeof(byte);
                }
                break;

            case MetaStructureEntryDataType.SignedByte:     //expecting space-separated array.
                for (int j = 0; j < split.Length; j++)
                {
                    sbyte val;    // = Convert.ToSByte(split[j], 10);
                    if (sbyte.TryParse(split[j].Trim(), ns, ic, out val))
                    {
                        data[offset] = (byte)val;
                        offset      += sizeof(sbyte);
                    }
                }
                break;

            case MetaStructureEntryDataType.UnsignedByte:     //expecting space-separated array.
                for (int j = 0; j < split.Length; j++)
                {
                    byte val;    // = Convert.ToByte(split[j], 10);
                    if (byte.TryParse(split[j].Trim(), ns, ic, out val))
                    {
                        data[offset] = val;
                        offset      += sizeof(byte);
                    }
                }
                break;

            case MetaStructureEntryDataType.SignedShort:     //expecting space-separated array.
                for (int j = 0; j < split.Length; j++)
                {
                    short val;    // = Convert.ToInt16(split[j], 10);
                    if (short.TryParse(split[j].Trim(), ns, ic, out val))
                    {
                        Write(val, data, offset);
                        offset += sizeof(short);
                    }
                }
                break;

            case MetaStructureEntryDataType.UnsignedShort:     //expecting space-separated array.
                for (int j = 0; j < split.Length; j++)
                {
                    ushort val;    // = Convert.ToUInt16(split[j], 10);
                    if (ushort.TryParse(split[j].Trim(), ns, ic, out val))
                    {
                        Write(val, data, offset);
                        offset += sizeof(ushort);
                    }
                }
                break;

            case MetaStructureEntryDataType.SignedInt:     //expecting space-separated array.
                for (int j = 0; j < split.Length; j++)
                {
                    int val;    // = Convert.ToInt32(split[j], 10);
                    if (int.TryParse(split[j].Trim(), ns, ic, out val))
                    {
                        Write(val, data, offset);
                        offset += sizeof(int);
                    }
                }
                break;

            case MetaStructureEntryDataType.UnsignedInt:     //expecting space-separated array.
                for (int j = 0; j < split.Length; j++)
                {
                    uint val;    // = Convert.ToUInt32(split[j], 10);
                    if (uint.TryParse(split[j].Trim(), ns, ic, out val))
                    {
                        Write(val, data, offset);
                        offset += sizeof(uint);
                    }
                }
                break;

            case MetaStructureEntryDataType.Float:     //expecting space-separated array.
                for (int j = 0; j < split.Length; j++)
                {
                    float val;    // = FloatUtil.Parse(split[j]);
                    if (FloatUtil.TryParse(split[j].Trim(), out val))
                    {
                        Write(val, data, offset);
                        offset += sizeof(float);
                    }
                }
                break;
            }
        }
Пример #14
0
        private static IRbfType Traverse(XNode node)
        {
            if (node is XElement element)
            {
                if (element.Attribute("value") != null)
                {
                    var val = element.Attribute("value").Value;
                    if (!string.IsNullOrEmpty(val))
                    {
                        var rval = CreateValueNode(element.Name.LocalName, val);
                        if (rval != null)
                        {
                            return(rval);
                        }
                    }
                }
                else if ((element.Attributes().Count() == 3) && (element.Attribute("x") != null) && (element.Attribute("y") != null) && (element.Attribute("z") != null))
                {
                    FloatUtil.TryParse(element.Attribute("x").Value, out float x);
                    FloatUtil.TryParse(element.Attribute("y").Value, out float y);
                    FloatUtil.TryParse(element.Attribute("z").Value, out float z);
                    return(new RbfFloat3()
                    {
                        Name = element.Name.LocalName,
                        X = x,
                        Y = y,
                        Z = z
                    });
                }
                else if ((element.Elements().Count() == 0) && (element.Attributes().Count() == 0) && (!element.IsEmpty)) //else if (element.Name == "type" || element.Name == "key" || element.Name == "platform")
                {
                    var bytearr   = Encoding.ASCII.GetBytes(element.Value);
                    var bytearrnt = new byte[bytearr.Length + 1];
                    Buffer.BlockCopy(bytearr, 0, bytearrnt, 0, bytearr.Length);
                    var bytes = new RbfBytes()
                    {
                        Value = bytearrnt
                    };
                    var struc = new RbfStructure()
                    {
                        Name = element.Name.LocalName
                    };
                    struc.Children.Add(bytes);
                    return(struc);
                }

                var n = new RbfStructure();
                n.Name     = element.Name.LocalName;
                n.Children = element.Nodes().Select(c => Traverse(c)).ToList();

                foreach (var attr in element.Attributes())
                {
                    var val  = attr.Value;
                    var aval = CreateValueNode(attr.Name.LocalName, val);
                    if (aval != null)
                    {
                        n.Attributes.Add(aval);
                    }
                }

                return(n);
            }
            else if (node is XText text)
            {
                byte[] bytes       = null;
                var    contentAttr = node.Parent?.Attribute("content");
                if (contentAttr != null)
                {
                    if (contentAttr.Value == "char_array")
                    {
                        bytes = GetByteArray(text.Value);
                    }
                    else if (contentAttr.Value == "short_array")
                    {
                        bytes = GetUshortArray(text.Value);
                    }
                    else
                    {
                    }
                }
                else
                {
                    bytes = Encoding.ASCII.GetBytes(text.Value).Concat(new byte[] { 0x00 }).ToArray();
                }
                if (bytes != null)
                {
                    return(new RbfBytes()
                    {
                        Name = "",
                        Value = bytes
                    });
                }
            }

            return(null);
        }