Пример #1
0
 private void RegisterValueTypes(XContainer root, OpcodeLookup lookup)
 {
     foreach (XElement element in root.Element("valueTypes").Descendants("type"))
     {
         string name      = XMLUtil.GetStringAttribute(element, "name");
         var    opcode    = (ushort)XMLUtil.GetNumericAttribute(element, "opcode");
         int    size      = XMLUtil.GetNumericAttribute(element, "size");
         bool   quoted    = XMLUtil.GetBoolAttribute(element, "quoted", false);
         string tag       = XMLUtil.GetStringAttribute(element, "tag", null);
         var    valueType = new ScriptValueType(name, opcode, size, quoted, tag);
         lookup.RegisterValueType(valueType);
     }
 }
Пример #2
0
        /// <summary>
        ///     Loads an engine database from an XML container.
        /// </summary>
        /// <param name="container">The container to read engine elements from.</param>
        /// <returns>The built engine database.</returns>
        public static EngineDatabase LoadDatabase(XContainer container)
        {
            XMLSettingsGroupLoader loader = CreateSettingsGroupLoader();
            var result = new EngineDatabase();

            foreach (XElement elem in container.Elements("engine"))
            {
                string        name     = XMLUtil.GetStringAttribute(elem, "name");
                int           levlSize = (int)XMLUtil.GetNumericAttribute(elem, "levlSize");
                int           version  = (int)XMLUtil.GetNumericAttribute(elem, "version");
                SettingsGroup settings = loader.LoadSettingsGroup(elem);
                var           desc     = new EngineDescription(name, levlSize, version, settings);
                result.RegisterEngine(desc);
            }
            return(result);
        }
Пример #3
0
        private void RegisterGlobals(XContainer root, OpcodeLookup lookup)
        {
            foreach (XElement element in root.Element("globals").Descendants("global"))
            {
                string name = XMLUtil.GetStringAttribute(element, "name");
                if (name == "")
                {
                    continue;
                }

                ushort opcode     = (ushort)XMLUtil.GetNumericAttribute(element, "opcode");
                string returnType = XMLUtil.GetStringAttribute(element, "type");
                bool   isNull     = XMLUtil.GetBoolAttribute(element, "null", false);

                var info = new GlobalInfo(name, opcode, returnType, !isNull);
                lookup.RegisterGlobal(info);
            }
        }
Пример #4
0
        private void RegisterFunctions(XContainer root, OpcodeLookup lookup)
        {
            foreach (XElement element in root.Element("functions").Descendants("function"))
            {
                string name = XMLUtil.GetStringAttribute(element, "name");
                if (name == "")
                {
                    continue;
                }

                var      opcode         = (ushort)XMLUtil.GetNumericAttribute(element, "opcode");
                string   returnType     = XMLUtil.GetStringAttribute(element, "returnType", "void");
                var      flags          = (uint)XMLUtil.GetNumericAttribute(element, "flags", 0);
                string[] parameterTypes = element.Descendants("arg").Select(e => XMLUtil.GetStringAttribute(e, "type")).ToArray();

                var info = new ScriptFunctionInfo(name, opcode, returnType, flags, parameterTypes);
                lookup.RegisterFunction(info);
            }
        }
Пример #5
0
        /// <summary>
        ///     Parses an XML element and adds the field that it represents to a
        ///     structure layout.
        /// </summary>
        /// <param name="layout">The layout to add the parsed field to.</param>
        /// <param name="element">The element to parse.</param>
        private static void HandleElement(StructureLayout layout, XElement element)
        {
            // Every structure field at least has a name and an offset
            string name   = XMLUtil.GetStringAttribute(element, "name");
            int    offset = XMLUtil.GetNumericAttribute(element, "offset");

            if (IsArrayElement(element))
            {
                HandleArrayElement(layout, element, name, offset);
            }
            else if (IsRawElement(element))
            {
                HandleRawElement(layout, element, name, offset);
            }
            else
            {
                HandleBasicElement(layout, element, name, offset);
            }
        }
Пример #6
0
        private object LoadSetting(XElement elem)
        {
            // If the elem points to an external setting, then process it
            string type = XMLUtil.GetStringAttribute(elem, "type", null);

            if (type != null)
            {
                string path = XMLUtil.GetStringAttribute(elem, "path", null);
                if (path != null)
                {
                    IComplexSettingLoader loader;
                    if (!_settingLoaders.TryGetValue(type, out loader))
                    {
                        throw new InvalidOperationException("Unrecognized complex setting type \"" + type + "\"");
                    }
                    return(loader.LoadSetting(path));
                }
            }
            return(elem.Value);
        }
Пример #7
0
        /// <summary>
        ///     Loads all of the structure layouts defined in an XML document.
        /// </summary>
        /// <param name="layoutDocument">The XML document to load structure layouts from.</param>
        /// <returns>The layouts that were loaded.</returns>
        private StructureLayoutCollection LoadLayouts(XDocument layoutDocument)
        {
            // Make sure there is a root <layouts> tag
            XContainer layoutContainer = layoutDocument.Element("layouts");

            if (layoutContainer == null)
            {
                throw new ArgumentException("Invalid layout document");
            }

            // Layout tags have the format:
            // <layout for="(layout's purpose)">(structure fields)</layout>
            var result = new StructureLayoutCollection();

            foreach (XElement layout in layoutContainer.Elements("layout"))
            {
                string name = XMLUtil.GetStringAttribute(layout, "for");
                int    size = (int)XMLUtil.GetNumericAttribute(layout, "size", 0);
                result.AddLayout(name, LoadLayout(layout, size));
            }
            return(result);
        }
Пример #8
0
        /// <summary>
        ///     Loads all of the class names defined in an XML document.
        /// </summary>
        /// <param name="layoutDocument">The XML document to load class names from.</param>
        /// <returns>The names that were loaded.</returns>
        public static ClassNameCollection LoadClassNames(XDocument namesDocument)
        {
            // Make sure there is a root <symbols> tag
            XContainer container = namesDocument.Element("classes");

            if (container == null)
            {
                throw new ArgumentException("Invalid class names document");
            }

            // Class tags have the format:
            // <class magic="(the magic as a string)" name="(class name)" />
            var result = new ClassNameCollection();

            foreach (XElement cl in container.Elements("class"))
            {
                string magic = XMLUtil.GetStringAttribute(cl, "magic");
                string name  = XMLUtil.GetStringAttribute(cl, "name");

                result.AddName(magic, name);
            }
            return(result);
        }
Пример #9
0
        /// <summary>
        ///     Loads an engine database from an XML container.
        /// </summary>
        /// <param name="container">The container to read engine elements from.</param>
        /// <returns>The built engine database.</returns>
        public static EngineDatabase LoadDatabase(XContainer container)
        {
            XMLSettingsGroupLoader loader = CreateSettingsGroupLoader();
            var result = new EngineDatabase();

            foreach (XElement elem in container.Elements("engine"))
            {
                string        name     = XMLUtil.GetStringAttribute(elem, "name");
                string        version  = XMLUtil.GetStringAttribute(elem, "version");
                string        inherits = XMLUtil.GetStringAttribute(elem, "inherits", null);
                SettingsGroup settings = loader.LoadSettingsGroup(elem);
                if (!string.IsNullOrWhiteSpace(inherits))
                {
                    // Clone the base engine's settings and then import the new settings on top of it
                    SettingsGroup baseSettings = result.FindEngineByName(inherits).Settings.DeepClone();
                    baseSettings.Import(settings);
                    settings = baseSettings;
                }
                var desc = new EngineDescription(name, version, settings);
                result.RegisterEngine(desc);
            }
            return(result);
        }
Пример #10
0
        /// <summary>
        ///     Loads all of the group names defined in an XML document.
        /// </summary>
        /// <param name="layoutDocument">The XML document to load group names from.</param>
        /// <returns>The names that were loaded.</returns>
        public static GroupNameCollection LoadGroupNames(XDocument namesDocument)
        {
            // Make sure there is a root <tagGroups> tag
            XContainer container = namesDocument.Element("tagGroups");

            if (container == null)
            {
                throw new ArgumentException("Invalid group names document");
            }

            // Group tags have the format:
            // <group magic="(the magic as a string)" name="(group name)" />
            var result = new GroupNameCollection();

            foreach (XElement gr in container.Elements("group"))
            {
                string magic = XMLUtil.GetStringAttribute(gr, "magic");
                string name  = XMLUtil.GetStringAttribute(gr, "name");

                result.AddName(magic, name);
            }
            return(result);
        }
Пример #11
0
        /// <summary>
        ///     Parses an XML element and adds the field that it represents to a
        ///     structure layout.
        /// </summary>
        /// <param name="layout">The layout to add the parsed field to.</param>
        /// <param name="element">The element to parse.</param>
        private void HandleElement(StructureLayout layout, XElement element)
        {
            // Every structure field at least has a name and an offset
            string name   = XMLUtil.GetStringAttribute(element, "name");
            int    offset = (int)XMLUtil.GetNumericAttribute(element, "offset");

            switch (element.Name.LocalName)
            {
            case "array":
                HandleArrayElement(layout, element, name, offset);
                break;

            case "raw":
                HandleRawElement(layout, element, name, offset);
                break;

            case "struct":
                HandleStructElement(layout, element, name, offset);
                break;

            case "tagblock":
                HandleTagBlockElement(layout, element, name, offset);
                break;

            case "stringId":
                HandleStringIDElement(layout, element, name, offset);
                break;

            case "tagRef":
                HandleTagReferenceElement(layout, element, name, offset);
                break;

            default:
                HandleBasicElement(layout, element, name, offset);
                break;
            }
        }