protected override List <MapMetadata> Parse() { MapsList = new List <MapMetadata>(); // Parse map names MapNames = new Dictionary <int, string>(); PackFileEntry file = Resources.XmlReader.Files.FirstOrDefault(x => x.Name.StartsWith("string/en/mapname.xml")); XmlDocument document = Resources.XmlReader.GetXmlDocument(file); foreach (XmlNode node in document.DocumentElement.ChildNodes) { int id = int.Parse(node.Attributes["id"].Value); string name = node.Attributes["name"].Value; MapNames[id] = name; } // Parse every block for each map FlatTypeIndex index = new FlatTypeIndex(Resources.ExportedReader); XBlockParser parser = new XBlockParser(Resources.ExportedReader, index); parser.Include(typeof(IMS2CubeProp)); // We only care about cubes here parser.Parse(AddMetadata); return(MapsList); }
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>(); }
public XBlockClassLookup(FlatTypeIndex index) { cache = new Dictionary <string, Type>(); this.index = index; // Create a dynamic assembly and module. var assemblyName = new AssemblyName("Maple2.File.Flat.Runtime"); if (string.IsNullOrEmpty(assemblyName.Name)) { throw new ArgumentException("Maple2.File.Flat.Runtime assembly not defined."); } moduleBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndCollect) .DefineDynamicModule(assemblyName.Name); }
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; } } }
public LibraryGenerator(FlatTypeIndex index) { this.index = index; }