Exemplo n.º 1
0
        private static void DumpPrecomputedTerrainXml()
        {
            var reader = new M2dReader(PRECOMPUTED_TERRAIN_PATH);

            Directory.CreateDirectory("PrecomputedTerrain");
            foreach (PackFileEntry file in reader.Files)
            {
                if (!file.Name.EndsWith(".tok"))
                {
                    continue;
                }

                byte[] bytes     = reader.GetBytes(file);
                var    tokReader = new TokReader(bytes);
                Mesh   mesh      = tokReader.Parse();

                var serializer      = new XmlSerializer(typeof(Mesh));
                var emptyNamespaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });
                var settings        = new XmlWriterSettings {
                    Indent = true, OmitXmlDeclaration = true
                };

                using var strWriter = new StringWriter();
                using var xmlWriter = XmlWriter.Create(strWriter, settings);
                serializer.Serialize(xmlWriter, mesh, emptyNamespaces);


                string xml      = strWriter.ToString();
                string fileName = Path.GetFileNameWithoutExtension(file.Name);
                System.IO.File.WriteAllText($"PrecomputedTerrain\\{fileName}.xml", xml);
                Console.WriteLine($"Completed: {file.Name}");
            }
        }
Exemplo n.º 2
0
    public MetadataResources()
    {
        string xmlPath      = $"{Paths.RESOURCES_INPUT_DIR}/Xml.m2d";
        string exportedPath = $"{Paths.RESOURCES_INPUT_DIR}/Exported.m2d";

        XmlReader      = new(xmlPath);
        ExportedReader = new(exportedPath);
    }
        public MetadataResources()
        {
            string xmlPath      = $"{Paths.INPUT}/Xml.m2d";
            string exportedPath = $"{Paths.INPUT}/Exported.m2d";

            XmlReader      = new M2dReader(xmlPath);
            ExportedReader = new M2dReader(exportedPath);
        }
Exemplo n.º 4
0
        public XBlockParser(M2dReader reader, FlatTypeIndex index = null)
        {
            this.reader = reader;
            this.index  = index ?? new FlatTypeIndex(reader);

            serializer   = new XmlSerializer(typeof(GameXBlock));
            lookup       = new XBlockClassLookup(index);
            keepEntities = new HashSet <Type>();
        }
Exemplo n.º 5
0
    public MetadataResources()
    {
        string xmlPath                = $"{Paths.RESOURCES_INPUT_DIR}/Xml.m2d";
        string exportedPath           = $"{Paths.RESOURCES_INPUT_DIR}/Exported.m2d";
        string precomputedTerrainPath = $"{Paths.RESOURCES_INPUT_DIR}/PrecomputedTerrain.m2d";

        XmlReader      = new(xmlPath);
        ExportedReader = new(exportedPath);
        TokReader      = new(precomputedTerrainPath);
    }
Exemplo n.º 6
0
        public FlatTypeIndex(M2dReader reader, string root = "flat")
        {
            this.root = root;
            Hierarchy = new HierarchyMap <FlatType>();
            typeNodes = ReadTypeNodes(reader);

            foreach (FlatTypeNode typeNode in typeNodes.Values)
            {
                foreach (FlatType mixin in typeNode.Value.Mixin)
                {
                    typeNodes[mixin.Name.ToLower()].Children.Add(typeNode);
                }
            }
        }
Exemplo n.º 7
0
        private static void FlatIndexExplorer()
        {
            using var reader = new M2dReader(EXPORTED_PATH);
            var index = new FlatTypeIndex(reader);

            Console.WriteLine("Index is ready!");

            while (true)
            {
                string[] input = (Console.ReadLine() ?? string.Empty).Split(" ", 2);

                switch (input[0])
                {
                case "quit":
                    return;

                case "type":
                case "prop":
                case "properties":
                    if (input.Length < 2)
                    {
                        Console.WriteLine("Invalid input.");
                    }
                    else
                    {
                        string   name = input[1];
                        FlatType type = index.GetType(name);
                        if (type == null)
                        {
                            Console.WriteLine($"Invalid type: {name}");
                            continue;
                        }

                        Console.WriteLine(type);
                        foreach (FlatProperty prop in type.GetProperties())
                        {
                            Console.WriteLine($"{prop.Type,22}{prop.Name,30}: {prop.ValueString()}");
                        }

                        Console.WriteLine("----------------------Inherited------------------------");
                        foreach (FlatProperty prop in type.GetInheritedProperties())
                        {
                            Console.WriteLine($"{prop.Type,22}{prop.Name,30}: {prop.ValueString()}");
                        }
                    }
                    break;

                case "sub":
                case "children":
                    if (input.Length < 2)
                    {
                        Console.WriteLine("Invalid input.");
                    }
                    else
                    {
                        string   name = input[1];
                        FlatType type = index.GetType(name);
                        if (type == null)
                        {
                            Console.WriteLine($"Invalid type: {name}");
                            continue;
                        }

                        Console.WriteLine(type);
                        foreach (FlatType subType in index.GetSubTypes(name))
                        {
                            Console.WriteLine($"{subType.Name,30} : {string.Join(',', subType.Mixin.Select(sub => sub.Name))}");
                        }
                    }
                    break;

                case "ls":
                    try {
                        bool   recursive = input.Contains("-r");
                        string path      = input.FirstOrDefault(arg => arg != "ls" && arg != "-r");
                        Console.WriteLine(string.Join(", ", index.Hierarchy.List(path, recursive).Select(type => type.Name)));
                    } catch (DirectoryNotFoundException e) {
                        Console.WriteLine(e.Message);
                    }
                    break;

                case "lsdir":
                    try {
                        string path = input.FirstOrDefault(arg => arg != "lsdir");
                        Console.WriteLine(string.Join(", ", index.Hierarchy.ListDirectories(path)));
                    } catch (DirectoryNotFoundException e) {
                        Console.WriteLine(e.Message);
                    }
                    break;

                default:
                    Console.WriteLine($"Unknown command: {string.Join(' ', input)}");
                    break;
                }
            }
        }
Exemplo n.º 8
0
        // Builds Index
        private Dictionary <string, FlatTypeNode> ReadTypeNodes(M2dReader reader)
        {
            Dictionary <string, XmlNode>      xmlNodes = new Dictionary <string, XmlNode>();
            Dictionary <string, FlatTypeNode> types    = new Dictionary <string, FlatTypeNode>();

            foreach (PackFileEntry entry in reader.Files)
            {
                if (!entry.Name.StartsWith(root))
                {
                    continue;
                }

                XmlDocument xmlDocument = reader.GetXmlDocument(entry);
                XmlNode     node        = xmlDocument.SelectSingleNode("model");
                if (node == null)
                {
                    Console.WriteLine($"Missing model node for: {entry.Name}");
                    continue;
                }

                if (node.Attributes?["name"] == null)
                {
                    Console.WriteLine($"Missing name for: {entry.Name}");
                    continue;
                }

                string name = node.Attributes["name"].Value;
                xmlNodes[name] = node;
                var type = new FlatType(name);
                Hierarchy.Add(entry.Name, type);
                types[name.ToLower()] = new FlatTypeNode(type);
                //Console.WriteLine($"Created type: {type.Name}");
            }

            // Populate Mixin and Property for Types.
            foreach ((string name, XmlNode node) in xmlNodes)
            {
                FlatType    type       = types[name.ToLower()].Value;
                XmlNodeList mixinNodes = node.SelectNodes("mixin");
                foreach (XmlNode mixinNode in mixinNodes)
                {
                    string mixinName = mixinNode.Attributes["name"].Value;
                    type.Mixin.Add(types[mixinName.ToLower()].Value);
                }

                XmlNodeList propNodes = node.SelectNodes("property");
                foreach (XmlNode propNode in propNodes)
                {
                    if (propNode?.Attributes == null)
                    {
                        throw new ConstraintException("Null value found for property node");
                    }

                    FlatProperty property;

                    XmlNodeList setNodes = propNode.SelectNodes("set");
                    string      propName = propNode.Attributes["name"].Value;
                    string      propType = propNode.Attributes["type"].Value;
                    string      propId   = propNode.Attributes["id"].Value;

                    if (propType.StartsWith("Assoc"))
                    {
                        List <(string, string)> values = new List <(string, string)>();
                        foreach (XmlNode setNode in setNodes)
                        {
                            values.Add((setNode.Attributes["index"].Value, setNode.Attributes["value"].Value));
                        }

                        property = new FlatProperty {
                            Name  = propName,
                            Type  = propType,
                            Id    = propId,
                            Value = FlatProperty.ParseAssocType(propType, values),
                        };
                    }
                    else
                    {
                        string value = setNodes[0].Attributes["value"].Value;
                        property = new FlatProperty {
                            Name  = propName,
                            Type  = propType,
                            Id    = propId,
                            Value = FlatProperty.ParseType(propType, value),
                        };
                    }

                    type.Properties.Add(property.Name, property);
                }
            }

            return(types);
        }
Exemplo n.º 9
0
 public ItemMapper(M2dReader xmlReader)
 {
     parser = new ItemParser(xmlReader);
 }