Ejemplo n.º 1
0
        public void WriteXML(XElement ele, ElderScrollsPlugin master)
        {
            XElement subEle;

            ele.TryPathTo("Type", true, out subEle);
            subEle.Value = Type.ToString();

            ele.TryPathTo(Arg1Label, true, out subEle);
            if (Arg1Type == null)
            {
                subEle.Value = ((byte[])Argument1).ToHex();
            }
            else if (Arg1Type == typeof(FormID))
            {
                Argument1.WriteXML(subEle, master);
            }
            else if (Arg1Type.IsEnum)
            {
                subEle.Value = Argument1.ToString();
            }
            else
            {
                throw new ArgumentException(Arg1Type.ToString() + " is not handled.");
            }

            ele.TryPathTo(Arg2Label, true, out subEle);
            if (Arg2Type == null)
            {
                subEle.Value = ((byte[])Argument2).ToHex();
            }
            else if (Arg2Type == typeof(FormID))
            {
                Argument2.WriteXML(subEle, master);
            }
            else if (Arg2Type.IsEnum)
            {
                subEle.Value = Argument2.ToString();
            }
            else if (Arg2Type == typeof(uint))
            {
                subEle.Value = Argument2.ToString();
            }
            else
            {
                throw new ArgumentException(Arg2Type.ToString() + " is not handled.");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Formats the instruction as string.
        /// <example>
        /// ADD (x), x, 2
        /// </example>
        /// </summary>
        /// <returns>A string representing the instruction</returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(Mnemonic);
            sb.Append(' ');
            sb.Append(Argument1.ToString());
            if (Argument2.Type != ArgumentType.None)
            {
                sb.Append(", ");
                sb.Append(Argument2.ToString());
            }
            if (Argument3.Type != ArgumentType.None)
            {
                sb.Append(", ");
                sb.Append(Argument3.ToString());
            }
            return(sb.ToString());
        }
Ejemplo n.º 3
0
        public void ReadXML(XElement ele, ElderScrollsPlugin master)
        {
            XElement subEle;

            if (ele.TryPathTo("Type", false, out subEle))
            {
                Type = subEle.ToEnum <FunctionType>();
            }

            TypeStringArgData data;

            if (Metadata.TryGetValue(Type, out data))
            {
                Arg1Label = data.Arg1Label;
                Arg2Label = data.Arg2Label;
                Arg1Type  = data.Arg1Type;
                Arg2Type  = data.Arg2Type;

                if (ele.TryPathTo(Arg1Label, false, out subEle))
                {
                    if (Arg1Type == null)
                    {
                        Argument1 = subEle.ToBytes();
                    }
                    else if (Arg1Type == typeof(FormID))
                    {
                        Argument1 = new FormID();
                        Argument1.ReadXML(subEle, master);
                    }
                    else if (Arg1Type == typeof(VATSValue))
                    {
                        Argument1 = subEle.ToEnum <VATSValue>();

                        TypeStringArgData tempData;

                        if (VATSMetadata.TryGetValue(Argument1, out tempData))
                        {
                            Arg2Type  = tempData.Arg1Type;
                            Arg2Label = tempData.Arg1Label;
                        }
                        else
                        {
                            throw new ArgumentException("VATSValue " + Argument1.ToString() + " is not handled.");
                        }
                    }
                    else if (Arg1Type.IsEnum)
                    {
                        Argument1 = Enum.Parse(Arg1Type, subEle.Value);
                    }
                    else
                    {
                        throw new ArgumentException(Arg1Type.ToString() + " is not handled.");
                    }
                }

                if (ele.TryPathTo(Arg2Label, false, out subEle))
                {
                    if (Arg2Type == null)
                    {
                        Argument2 = subEle.ToBytes();
                    }
                    else if (Arg2Type == typeof(FormID))
                    {
                        Argument2 = new FormID();
                        Argument2.ReadXML(subEle, master);
                    }
                    else if (Arg2Type.IsEnum)
                    {
                        Argument2 = Enum.Parse(Arg2Type, subEle.Value);
                    }
                    else if (Arg2Type == typeof(uint))
                    {
                        Argument2 = subEle.ToUInt32();
                    }
                    else
                    {
                        throw new ArgumentException(Arg2Type.ToString() + " is not handled.");
                    }
                }
            }
            else
            {
                throw new Exception(Type.ToString() + " was not in the dictionary.");
            }
        }