static void ProcessXml(Stream stream) { XElement root = XElement.Load(stream); foreach (var elem in root.Elements("Ground")) { short type = (short)Utils.FromString(elem.Attribute("type").Value); string id = elem.Attribute("id").Value; TypeToId[type] = id; IdToType[id] = type; TypeToElement[type] = elem; TileDescs[type] = new TileDesc(elem); } foreach (var elem in root.Elements("Object")) { if (elem.Element("Class") == null) continue; string cls = elem.Element("Class").Value; short type = (short)Utils.FromString(elem.Attribute("type").Value); string id = elem.Attribute("id").Value; TypeToId[type] = id; IdToType[id] = type; TypeToElement[type] = elem; if (cls == "Equipment") ItemDescs[type] = new Item(elem); else if (cls == "Character" || cls == "GameObject" || cls == "Wall" || cls == "ConnectedWall" || cls == "CaveWall") ObjectDescs[type] = new ObjectDesc(elem); } }
static void ProcessXml(Stream stream) { XElement root = XElement.Load(stream); foreach (var elem in root.Elements("Ground")) { short type = (short)Utils.FromString(elem.Attribute("type").Value); string id = elem.Attribute("id").Value; TypeToId[type] = id; IdToType[id] = type; TypeToElement[type] = elem; TileDescs[type] = new TileDesc(elem); } foreach (var elem in root.Elements("Object")) { if (elem.Element("Class") == null) continue; string cls = elem.Element("Class").Value; short type = (short)Utils.FromString(elem.Attribute("type").Value); string id = elem.Attribute("id").Value; TypeToId[type] = id; IdToType[id] = type; TypeToElement[type] = elem; if (cls == "Equipment") ItemDescs[type] = new Item(elem); else if (cls == "Character" || cls == "GameObject" || cls == "Wall" || cls == "ConnectedWall" || cls == "CaveWall") ObjectDescs[type] = new ObjectDesc(elem); else if (cls == "Portal") { try { PortalDescs[type] = new PortalDesc(elem); } catch (Exception e) { Console.WriteLine("Error for portal: " + type + " id: " + id); /*3392,1792,1795,1796,1805,1806,1810,1825 -- no location, assume nexus?* * Tomb Portal of Cowardice, Dungeon Portal, Portal of Cowardice, Realm Portal, Glowing Portal of Cowardice, Glowing Realm Portal, Nexus Portal, Locked Wine Cellar Portal*/ } } } }
static void ProcessXml(Stream stream) { XElement root = XElement.Load(stream); foreach (var elem in root.Elements("Ground")) { short type = (short)Utils.FromString(elem.Attribute("type").Value); string id = elem.Attribute("id").Value; TypeToId[type] = id; IdToType[id] = type; TypeToElement[type] = elem; TileDescs[type] = new TileDesc(elem); } foreach (var elem in root.Elements("Object")) { if (elem.Element("Class") == null) continue; string cls = elem.Element("Class").Value; short type = (short)Utils.FromString(elem.Attribute("type").Value); string id = elem.Attribute("id").Value; TypeToId[type] = id; IdToType[id] = type; TypeToElement[type] = elem; if (cls == "Equipment" || cls == "Dye" || cls == "Pet") { ItemDescs[type] = new Item(elem); if (elem.Element("Shop") != null) { XElement shop = elem.Element("Shop"); ItemShops[type] = shop.Element("Name").Value; ItemPrices[type] = Utils.FromString(shop.Element("Price").Value); } } if (cls == "Character" || cls == "GameObject" || cls == "Wall" || cls == "ConnectedWall" || cls == "CaveWall" || cls == "Portal") ObjectDescs[type] = new ObjectDesc(elem); if (cls == "Portal") { try { PortalDescs[type] = new PortalDesc(elem); } catch (Exception e) { Console.WriteLine("Error for portal: " + type + " id: " + id); /*3392,1792,1795,1796,1805,1806,1810,1825 -- no location, assume nexus?* * Tomb Portal of Cowardice, Dungeon Portal, Portal of Cowardice, Realm Portal, Glowing Portal of Cowardice, Glowing Realm Portal, Nexus Portal, Locked Wine Cellar Portal*/ } } XElement key = elem.Element("Key"); if (key != null) { Keys.Add(type); KeyPrices[type] = Utils.FromString(key.Value); } } foreach (var elem in root.Elements("Dungeon")) { string name = elem.Attribute("name").Value; short portalid = (short)Utils.FromString(elem.Attribute("type").Value); IdToDungeon[portalid] = name; DungeonDescs[name] = new DungeonDesc(elem); } }
private static void AddGround(XElement root) { foreach (var elem in root.XPathSelectElements("//Ground")) { var type = (short)Utils.FromString(elem.Attribute("type").Value); var id = elem.Attribute("id").Value; ObjectTypeToId[type] = id; TypeToIdGround[type] = id; IdToObjectType[id] = type; TypeToElement[type] = elem; Tiles[type] = new TileDesc(elem); } }
private static void ProcessXml(Stream stream) { XElement root = XElement.Load(stream); foreach (XElement elem in root.Elements("Ground")) { var type = (short) Utils.FromString(elem.Attribute("type").Value); string id = elem.Attribute("id").Value; TypeToId[type] = id; TypeToIdGround[type] = id; IdToType[id] = type; TypeToElement[type] = elem; TileDescs[type] = new TileDesc(elem); } foreach (XElement elem in root.Elements("Object")) { if (elem.Element("Class") == null) continue; string cls = elem.Element("Class").Value; var type = (short) Utils.FromString(elem.Attribute("type").Value); string id = elem.Attribute("id").Value; TypeToId[type] = id; IdToType[id] = type; TypeToElement[type] = elem; if (cls == "Equipment" || cls == "Dye" || cls == "Pet") { ItemDescs[type] = new Item(elem); if (elem.Element("Shop") != null) { XElement shop = elem.Element("Shop"); ItemShops[type] = shop.Element("Name").Value; ItemPrices[type] = Utils.FromString(shop.Element("Price").Value); } } if (cls == "Character" || cls == "GameObject" || cls == "Wall" || cls == "ConnectedWall" || cls == "CaveWall" || cls == "Portal") ObjectDescs[type] = new ObjectDesc(elem); if (cls == "Portal") { try { PortalDescs[type] = new PortalDesc(elem); } catch { Console.WriteLine(@"Error for portal: " + type + @" id: " + id); /*3392,1792,1795,1796,1805,1806,1810,1825 -- no location, assume nexus?* * Tomb Portal of Cowardice, Dungeon Portal, Portal of Cowardice, Realm Portal, Glowing Portal of Cowardice, Glowing Realm Portal, Nexus Portal, Locked Wine Cellar Portal*/ } } if (elem.Element("RemoteTexture") != null) { XElement rtElem = elem.Element("RemoteTexture"); if (rtElem.Element("Id") != null) { string rtId = rtElem.Element("Id").Value; if (!RemoteTextures.ContainsKey(rtId)) if (rtId.StartsWith("draw:")) RemoteTextures.Add(rtId, new WebClient().DownloadData("http://realmofthemadgod.appspot.com/picture/get?id=" + new String(rtId.Skip(5).ToArray()))); else if (rtId.StartsWith("tdraw:")) RemoteTextures.Add(rtId, new WebClient().DownloadData("http://rotmgtesting.appspot.com/picture/get?id=" + new String(rtId.Skip(5).ToArray()))); else if (rtId.StartsWith("file:")) RemoteTextures.Add(rtId, File.ReadAllBytes("texture/" + new String(rtId.Skip(5).ToArray()) + ".png")); } } XElement key = elem.Element("Key"); if (key != null) { Keys.Add(type); KeyPrices[type] = Utils.FromString(key.Value); } } foreach (XElement elem in root.Elements("Dungeon")) { string name = elem.Attribute("name").Value; var portalid = (short) Utils.FromString(elem.Attribute("type").Value); IdToDungeon[portalid] = name; DungeonDescs[name] = new DungeonDesc(elem); } }
public void AddGrounds(XElement root) { foreach (XElement elem in root.XPathSelectElements("//Ground")) { string id = elem.Attribute("id").Value; ushort type; XAttribute typeAttr = elem.Attribute("type"); if (typeAttr == null) type = (ushort)assign.Assign(id, elem); else type = (ushort)Utils.FromString(typeAttr.Value); if (type2id_tile.ContainsKey(type)) log.WarnFormat("'{0}' and '{1}' has the same ID of 0x{2:x4}!", id, type2id_tile[type], type); if (id2type_tile.ContainsKey(id)) log.WarnFormat("0x{0:x4} and 0x{1:x4} has the same name of {2}!", type, id2type_tile[id], id); type2id_tile[type] = id; id2type_tile[id] = type; type2elem_tile[type] = elem; tiles[type] = new TileDesc(type, elem); XAttribute extAttr = elem.Attribute("ext"); bool ext; if (extAttr != null && bool.TryParse(extAttr.Value, out ext) && ext) { addition.Add(elem); updateCount++; } } }
public static string ProcessModXml(Stream stream, string dir) { XElement root = XElement.Load(stream); foreach (var elem in root.Elements("Ground")) { short type = 0x3000; string id = elem.Attribute("id").Value; if (!ItemIds.ContainsKey(id)) for (var i = 0x3001; i < 0xffff; i++) if (!UsedIds.Contains((short)i)) { ItemIds.Add(id, (short)i); UsedIds.Add((short)i); } type = ItemIds[id]; elem.SetAttributeValue("type", type); TypeToId[type] = id; IdToType[id] = type; TypeToElement[type] = elem; TileDescs[type] = new TileDesc(elem); } foreach (var elem in root.Elements("Object")) { if (elem.Element("Class") == null) continue; string cls = elem.Element("Class").Value; short type = 0x4000; string id = elem.Attribute("id").Value; if (!ItemIds.ContainsKey(id)) for (var i = 0x4001; i < 0xffff; i++) if (!UsedIds.Contains((short)i)) { ItemIds.Add(id, (short)i); UsedIds.Add((short)i); break; } type = ItemIds[id]; Console.Out.WriteLine("(" + new DirectoryInfo(dir).Name + ") Adding mod object: " + id + " (" + type.ToString() + ")"); if (File.Exists(dir + ds + id + ".png")) { Console.Out.WriteLine("(" + new DirectoryInfo(dir).Name + ") Adding mod texture: " + id); if (elem.Element("RemoteTexture") != null) elem.Element("RemoteTexture").Remove(); if (elem.Element("Texture") != null) elem.Element("Texture").Remove(); XElement texElem = new XElement("RemoteTexture", new XElement("Instance", new XText("production") ), new XElement("Id", new XText("mod:" + id) ) ); elem.Add(texElem); try { ModTextures.Add(id, File.ReadAllBytes(dir + ds + id + ".png")); } catch { Console.Out.WriteLine("(" + new DirectoryInfo(dir).Name + ") Error adding texture: " + id); } } elem.SetAttributeValue("type", type); TypeToId[type] = id; IdToType[id] = type; TypeToElement[type] = elem; if (cls == "Equipment" || cls == "Dye" || cls == "Pet") { ItemDescs[type] = new Item(elem); if (elem.Element("Shop") != null) { XElement shop = elem.Element("Shop"); ItemShops[type] = shop.Element("Name").Value; ItemPrices[type] = Utils.FromString(shop.Element("Price").Value); } } if (cls == "Character" || cls == "GameObject" || cls == "Wall" || cls == "ConnectedWall" || cls == "CaveWall" || cls == "Portal" || cls == "NPC") ObjectDescs[type] = new ObjectDesc(elem); if (cls == "Portal") { try { PortalDescs[type] = new PortalDesc(elem); } catch (Exception e) { Console.WriteLine("Error for portal: " + type + " id: " + id); /*3392,1792,1795,1796,1805,1806,1810,1825 -- no location, assume nexus?* * Tomb Portal of Cowardice, Dungeon Portal, Portal of Cowardice, Realm Portal, Glowing Portal of Cowardice, Glowing Realm Portal, Nexus Portal, Locked Wine Cellar Portal*/ } } XElement key = elem.Element("Key"); if (key != null) { Keys.Add(type); KeyPrices[type] = Utils.FromString(key.Value); } } foreach (var elem in root.Elements("Dungeon")) { string name = elem.Attribute("name").Value; short portalid = (short)Utils.FromString(elem.Attribute("type").Value); IdToDungeon[portalid] = name; DungeonDescs[name] = new DungeonDesc(elem); } using (StringWriter sw = new StringWriter()) { root.Save(sw); return sw.ToString(); } }