public bool BuildResourcesVersion19(XmlDocument document, XmlDocument xmlDoc, XmlNode rootNode, string sdsFolder) { XPathNavigator nav = document.CreateNavigator(); var nodes = nav.Select("/SDSResource/ResourceEntry"); Dictionary <string, List <ResourceEntry> > entries = new Dictionary <string, List <ResourceEntry> >(); while (nodes.MoveNext() == true) { nodes.Current.MoveToFirstChild(); string resourceType = nodes.Current.Value; if (!entries.ContainsKey(resourceType)) { ResourceType resource = new ResourceType(); resource.Name = nodes.Current.Value; resource.Id = (uint)entries.Count; //TODO if (resource.Name == "IndexBufferPool" || resource.Name == "PREFAB") { resource.Parent = 3; } else if (resource.Name == "VertexBufferPool" || resource.Name == "NAV_OBJ_DATA") { resource.Parent = 2; } else if (resource.Name == "NAV_HPD_DATA") { resource.Parent = 1; } ResourceTypes.Add(resource); entries.Add(resourceType, new List <ResourceEntry>()); } XmlNode resourceNode = xmlDoc.CreateElement("ResourceInfo"); XmlNode typeNameNode = xmlDoc.CreateElement("TypeName"); typeNameNode.InnerText = resourceType; XmlNode sddescNode = xmlDoc.CreateElement("SourceDataDescription"); ResourceEntry resourceEntry = new ResourceEntry(); switch (resourceType) { case "FrameResource": case "Effects": case "PREFAB": case "ItemDesc": case "FrameNameTable": case "Actors": case "NAV_AIWORLD_DATA": case "NAV_OBJ_DATA": case "NAV_HPD_DATA": case "Cutscene": case "FxActor": case "FxAnimSet": case "Translokator": case "Speech": case "SoundTable": case "AnimalTrafficPaths": resourceEntry = WriteBasicEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "AudioSectors": resourceEntry = WriteAudioSectorEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Animated Texture": resourceEntry = WriteAnimatedTextureEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Collisions": resourceEntry = WriteCollisionEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "IndexBufferPool": case "VertexBufferPool": resourceEntry = WriteBufferEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "EntityDataStorage": resourceEntry = WriteEntityDataEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Animation2": resourceEntry = WriteAnimationEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Texture": resourceEntry = WriteTextureEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Mipmap": resourceEntry = WriteMipmapEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Sound": resourceEntry = WriteSoundEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "XML": resourceEntry = WriteXMLEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "MemFile": resourceEntry = WriteMemFileEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Script": resourceEntry = WriteScriptEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Table": resourceEntry = WriteTableEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; default: MessageBox.Show("Did not pack type: " + resourceType, "Toolkit", MessageBoxButtons.OK, MessageBoxIcon.Information); break; } resourceNode.AppendChild(typeNameNode); resourceNode.AppendChild(sddescNode); resourceNode.AppendChild(AddRamElement(xmlDoc, "SlotRamRequired", (int)resourceEntry.SlotRamRequired)); resourceNode.AppendChild(AddRamElement(xmlDoc, "SlotVRamRequired", (int)resourceEntry.SlotVramRequired)); resourceNode.AppendChild(AddRamElement(xmlDoc, "OtherRamRequired", (int)resourceEntry.OtherRamRequired)); resourceNode.AppendChild(AddRamElement(xmlDoc, "OtherVramRequired", (int)resourceEntry.OtherVramRequired)); rootNode.AppendChild(resourceNode); SlotRamRequired += resourceEntry.SlotRamRequired; SlotVramRequired += resourceEntry.SlotVramRequired; OtherRamRequired += resourceEntry.OtherRamRequired; OtherVramRequired += resourceEntry.OtherVramRequired; // Find TypeId then add to the big list of resources resourceEntry.TypeId = (int)ResourceTypes.Find(s => s.Name.Equals(resourceType)).Id; _ResourceEntries.Add(resourceEntry); } // Update Meta-Info or 'Outer-XML' ResourceInfoXml = xmlDoc.OuterXml; return(true); }
public bool BuildResourcesVersion20(XmlDocument document, XmlDocument xmlDoc, XmlNode rootNode, string sdsFolder) { XPathNavigator nav = document.CreateNavigator(); var nodes = nav.Select("/SDSResource/ResourceEntry"); Dictionary <string, List <ResourceEntry> > entries = new Dictionary <string, List <ResourceEntry> >(); int index = 0; while (nodes.MoveNext() == true) { nodes.Current.MoveToFirstAttribute(); uint SlotVramRequired = uint.Parse(nodes.Current.Value); nodes.Current.MoveToNextAttribute(); uint SlotRamRequired = uint.Parse(nodes.Current.Value); nodes.Current.MoveToParent(); nodes.Current.MoveToFirstChild(); string resourceType = nodes.Current.Value; if (!entries.ContainsKey(resourceType)) { ResourceType resource = new ResourceType(); resource.Name = nodes.Current.Value; resource.Id = (uint)entries.Count; //TODO if (resource.Name == "NAV_PATH_DATA") { resource.Parent = 1; } ResourceTypes.Add(resource); entries.Add(resourceType, new List <ResourceEntry>()); } XmlNode resourceNode = xmlDoc.CreateElement("ResourceInfo"); XmlNode typeNameNode = xmlDoc.CreateElement("TypeName"); typeNameNode.InnerText = resourceType; XmlNode sddescNode = xmlDoc.CreateElement("SourceDataDescription"); ResourceEntry resourceEntry = new ResourceEntry() { SlotRamRequired = SlotRamRequired, SlotVramRequired = SlotVramRequired, }; if (index == 36) { Console.WriteLine(""); } switch (resourceType) { case "Texture": resourceEntry = WriteTextureEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "hkAnimation": resourceEntry = WriteHavokEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Generic": resourceEntry = WriteGenericEntry(resourceEntry, nodes, sdsFolder, sddescNode); resourceEntry.SlotRamRequired = SlotRamRequired; resourceEntry.SlotVramRequired = SlotVramRequired; break; case "NAV_PATH_DATA": case "NAV_AIWORLD_DATA": case "RoadMap": case "EnlightenResource": resourceEntry = WriteBasicEntry(resourceEntry, nodes, sdsFolder, sddescNode); resourceEntry.OtherRamRequired += (uint)(resourceEntry.Data.Length); break; case "MemFile": resourceEntry = WriteMemFileEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "SystemObjectDatabase": resourceEntry = WriteXBinEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "XML": resourceEntry = WriteXMLEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Script": resourceEntry = WriteScriptEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Flash": resourceEntry = WriteFlashEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; default: MessageBox.Show("Did not pack type: " + resourceType, "Toolkit", MessageBoxButtons.OK, MessageBoxIcon.Information); break; } resourceNode.AppendChild(typeNameNode); resourceNode.AppendChild(sddescNode); resourceNode.AppendChild(AddRamElement(xmlDoc, "SlotRamRequired", (int)resourceEntry.SlotRamRequired)); resourceNode.AppendChild(AddRamElement(xmlDoc, "SlotVRamRequired", (int)resourceEntry.SlotVramRequired)); resourceNode.AppendChild(AddRamElement(xmlDoc, "OtherRamRequired", (int)resourceEntry.OtherRamRequired)); resourceNode.AppendChild(AddRamElement(xmlDoc, "OtherVramRequired", (int)resourceEntry.OtherVramRequired)); rootNode.AppendChild(resourceNode); this.SlotVramRequired += resourceEntry.OtherVramRequired; this.SlotRamRequired += resourceEntry.OtherRamRequired; resourceEntry.TypeId = (int)ResourceTypes.Find(s => s.Name.Equals(resourceType)).Id; entries[resourceType].Add(resourceEntry); index++; } _ResourceTypes.Reverse(); for (int i = 0; i < _ResourceTypes.Count; i++) { var entry = _ResourceTypes[i]; entry.Id = (uint)i; _ResourceTypes[i] = entry; } foreach (var collection in entries) { var key = collection.Key; foreach (var entry in collection.Value) { entry.TypeId = (int)ResourceTypes.Find(s => s.Name.Equals(key)).Id; } } foreach (var pair in entries) { _ResourceEntries.AddRange(pair.Value); } ResourceInfoXml = xmlDoc.OuterXml; return(true); }
/// <summary> /// Build resources from given folder. /// </summary> /// <param name="folder"></param> public void BuildResources(string folder) { //TODO: MAKE THIS CLEANER string sdsFolder = folder; XmlDocument document = new XmlDocument(); XmlDocument xmlDoc = new XmlDocument(); XmlNode rootNode; if (!File.Exists(sdsFolder + "/SDSContent.xml")) { MessageBox.Show("Could not find 'SDSContent.xml'. Folder Path: " + sdsFolder + "/SDSContent.xml", "Game Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { document = new XmlDocument(); document.Load(sdsFolder + "/SDSContent.xml"); xmlDoc = new XmlDocument(); rootNode = xmlDoc.CreateElement("xml"); } catch (Exception ex) { MessageBox.Show(string.Format("Error while parsing SDSContent.XML. \n{0}", ex.Message)); return; } xmlDoc.AppendChild(rootNode); XPathNavigator nav = document.CreateNavigator(); var nodes = nav.Select("/SDSResource/ResourceEntry"); Dictionary <string, List <ResourceEntry> > entries = new Dictionary <string, List <ResourceEntry> >(); while (nodes.MoveNext() == true) { nodes.Current.MoveToFirstChild(); string resourceType = nodes.Current.Value; if (!entries.ContainsKey(resourceType)) { ResourceType resource = new ResourceType(); resource.Name = nodes.Current.Value; resource.Id = (uint)entries.Count; //TODO if (resource.Name == "IndexBufferPool" || resource.Name == "PREFAB") { resource.Parent = 3; } else if (resource.Name == "VertexBufferPool" || resource.Name == "NAV_OBJ_DATA") { resource.Parent = 2; } else if (resource.Name == "NAV_HPD_DATA") { resource.Parent = 1; } ResourceTypes.Add(resource); entries.Add(resourceType, new List <ResourceEntry>()); } XmlNode resourceNode = xmlDoc.CreateElement("ResourceInfo"); XmlNode typeNameNode = xmlDoc.CreateElement("TypeName"); typeNameNode.InnerText = resourceType; XmlNode sddescNode = xmlDoc.CreateElement("SourceDataDescription"); ResourceEntry resourceEntry = new ResourceEntry(); switch (resourceType) { case "FrameResource": case "Effects": case "PREFAB": case "ItemDesc": case "FrameNameTable": case "Actors": case "NAV_AIWORLD_DATA": case "NAV_OBJ_DATA": case "NAV_HPD_DATA": case "Cutscene": case "FxActor": case "FxAnimSet": case "Translokator": case "Speech": case "SoundTable": case "AnimalTrafficPaths": resourceEntry = WriteBasicEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "AudioSectors": resourceEntry = WriteAudioSectorEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Animated Texture": resourceEntry = WriteAnimatedTextureEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Collisions": resourceEntry = WriteCollisionEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "IndexBufferPool": case "VertexBufferPool": resourceEntry = WriteBufferEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "EntityDataStorage": resourceEntry = WriteEntityDataEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Animation2": resourceEntry = WriteAnimationEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Texture": resourceEntry = WriteTextureEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Mipmap": resourceEntry = WriteMipmapEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Sound": resourceEntry = WriteSoundEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "XML": resourceEntry = WriteXMLEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "MemFile": resourceEntry = WriteMemFileEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Script": resourceEntry = WriteScriptEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; case "Table": resourceEntry = WriteTableEntry(resourceEntry, nodes, sdsFolder, sddescNode); break; default: MessageBox.Show("Did not pack type: " + resourceType, "Toolkit", MessageBoxButtons.OK, MessageBoxIcon.Information); break; } resourceNode.AppendChild(typeNameNode); resourceNode.AppendChild(sddescNode); resourceNode.AppendChild(AddRamElement(xmlDoc, "SlotRamRequired", (int)resourceEntry.SlotRamRequired)); resourceNode.AppendChild(AddRamElement(xmlDoc, "SlotVRamRequired", (int)resourceEntry.SlotVramRequired)); resourceNode.AppendChild(AddRamElement(xmlDoc, "OtherRamRequired", (int)resourceEntry.OtherRamRequired)); resourceNode.AppendChild(AddRamElement(xmlDoc, "OtherVramRequired", (int)resourceEntry.OtherVramRequired)); rootNode.AppendChild(resourceNode); SlotRamRequired += resourceEntry.SlotRamRequired; SlotVramRequired += resourceEntry.SlotVramRequired; OtherRamRequired += resourceEntry.OtherRamRequired; OtherVramRequired += resourceEntry.OtherVramRequired; resourceEntry.TypeId = (int)ResourceTypes.Find(s => s.Name.Equals(resourceType)).Id; entries[resourceType].Add(resourceEntry); } foreach (var pair in entries) { _ResourceEntries.AddRange(pair.Value); } ResourceInfoXml = xmlDoc.OuterXml; }