public void LoadListEntries <T>(List <T> list, Reflexive target, Action <T, byte[]> method, uint entrySize) where T : new() { byte[] tagChunk = GetChunk(target.Offset, target.Count * entrySize); for (int i = 0; i < target.Count; i++) { byte[] entryData = new byte[entrySize]; Buffer.BlockCopy(tagChunk, (int)(i * entrySize), entryData, 0, (int)entrySize); T obj = new T(); method(obj, entryData); list.Add(obj); } }
/// <summary> /// The write references. /// </summary> /// <remarks></remarks> public void WriteReferences() { BinaryWriter BW = new BinaryWriter(this.MS); for (int xx = 0; xx < this.items.Count; xx++) { Item i = this.items[xx]; if (i.intag != this.TagIndex) { continue; } switch (i.type) { case ItemType.Reflexive: Reflexive reflex = (Reflexive)i; int newreflex = this.offset + reflex.translation + this.magic; if (reflex.pointstoTagIndex != this.TagIndex) { newreflex = this.Map.MetaInfo.Offset[reflex.pointstoTagIndex] + reflex.translation + this.magic; } BW.BaseStream.Position = reflex.offset; BW.Write(reflex.chunkcount); BW.Write(newreflex); break; case ItemType.Ident: Ident id = (Ident)i; BW.BaseStream.Position = id.offset; BW.Write(id.ident); break; case ItemType.String: String ss = (String)i; byte bleh = 0; BW.BaseStream.Position = ss.offset; BW.Write((short)ss.id); BW.Write(bleh); BW.Write((byte)ss.name.Length); break; default: MessageBox.Show(i.type.ToString()); break; } } }
/// <summary> /// Load meta from an XML file. /// </summary> /// <param name="inputFileName">The XML file name.</param> /// <remarks></remarks> public void LoadMetaFromFile(string inputFileName) { // write memorysteam of meta to file FileStream FS = new FileStream(inputFileName, FileMode.Open); BinaryReader BR = new BinaryReader(FS); this.size = (int)FS.Length; this.MS = new MemoryStream(this.size); BR.BaseStream.Position = 0; this.MS.Write(BR.ReadBytes(this.size), 0, this.size); BR.Close(); FS.Close(); // write idents,strings,reflexives XmlTextReader xtr = new XmlTextReader(inputFileName + ".xml"); xtr.WhitespaceHandling = WhitespaceHandling.None; while (xtr.Read()) { // MessageBox.Show(xtr.Name); switch (xtr.NodeType) { case XmlNodeType.Element: if (xtr.Name == "Meta") { this.type = xtr.GetAttribute("TagType"); this.name = xtr.GetAttribute("TagName"); this.parsed = xtr.GetAttribute("Parsed") == "True" ? true : false; this.size = Convert.ToInt32(xtr.GetAttribute("Size")); this.magic = Convert.ToInt32(xtr.GetAttribute("Magic")); this.padding = Convert.ToChar(xtr.GetAttribute("Padding")); this.offset = Convert.ToInt32(xtr.GetAttribute("Offset")); } else if (xtr.Name == "Reflexive") { Reflexive r = new Reflexive(); r.description = xtr.GetAttribute("Description"); r.offset = Convert.ToInt32(xtr.GetAttribute("Offset")); r.chunkcount = Convert.ToInt32(xtr.GetAttribute("ChunkCount")); r.chunksize = Convert.ToInt32(xtr.GetAttribute("ChunkSize")); r.translation = Convert.ToInt32(xtr.GetAttribute("Translation")); r.pointstotagtype = xtr.GetAttribute("PointsToTagType"); r.pointstotagname = xtr.GetAttribute("PointsToTagName"); r.pointstoTagIndex = Map.Functions.ForMeta.FindByNameAndTagType( r.pointstotagtype, r.pointstotagname); r.intagtype = xtr.GetAttribute("TagType"); r.intagname = xtr.GetAttribute("TagName"); r.intag = Map.Functions.ForMeta.FindByNameAndTagType(r.intagtype, r.intagname); this.items.Add(r); } else if (xtr.Name == "Ident") { Ident id = new Ident(); id.description = xtr.GetAttribute("Description"); id.offset = Convert.ToInt32(xtr.GetAttribute("Offset")); id.pointstotagtype = xtr.GetAttribute("PointsToTagType"); id.pointstotagname = xtr.GetAttribute("PointsToTagName"); id.pointstoTagIndex = Map.Functions.ForMeta.FindByNameAndTagType( id.pointstotagtype, id.pointstotagname); id.intagtype = xtr.GetAttribute("TagType"); id.intagname = xtr.GetAttribute("TagName"); id.intag = Map.Functions.ForMeta.FindByNameAndTagType(id.intagtype, id.intagname); this.items.Add(id); } else if (xtr.Name == "String") { String s = new String(); s.description = xtr.GetAttribute("Description"); s.offset = Convert.ToInt32(xtr.GetAttribute("Offset")); s.name = xtr.GetAttribute("StringName"); s.intagtype = xtr.GetAttribute("TagType"); s.intagname = xtr.GetAttribute("TagName"); s.intag = Map.Functions.ForMeta.FindByNameAndTagType(s.intagtype, s.intagname); this.items.Add(s); } break; default: break; } } xtr.Close(); // ///check for raw this.rawType = Map.Functions.ForMeta.CheckForRaw(this.type); if (this.rawType != RawDataContainerType.Empty) { this.raw = new RawDataContainer(); this.raw = this.raw.LoadRawFromFile(inputFileName, this); } }
/// <summary> /// Used to export the current meta to a file. /// </summary> /// <param name="outputFileName">The filename to save the Meta to.</param> /// <param name="renameTag">The rename tag.</param> /// <remarks></remarks> public string SaveMetaToFile(string outputFileName, bool renameTag) { string[] splitOut = outputFileName.Split('\\'); // if the filename contains an extension, remove it from the split list if (splitOut[splitOut.Length - 1].Contains(".")) { splitOut[splitOut.Length - 1] = splitOut[splitOut.Length - 1].Substring(0, splitOut[splitOut.Length - 1].IndexOf('.')); } string[] splitOrig = this.name.Split('\\'); // use the starting path for the tag name... string tempName = string.Empty; for (int i = 0; i < splitOrig.Length; i++) { if (splitOrig[i] != splitOrig[splitOrig.Length - 1]) { tempName += splitOrig[i]; } else { tempName += splitOut[splitOut.Length - 1]; } if (i < splitOrig.Length - 1) { tempName += "\\"; } } if (renameTag) { tempName = askForTagName(tempName); if (tempName == string.Empty) { return(this.name); } } outputFileName = outputFileName.Replace("<", "_"); outputFileName = outputFileName.Replace(">", "_"); // write memorysteam of meta to file BinaryWriter BW = new BinaryWriter(new FileStream(outputFileName, FileMode.Create)); BW.BaseStream.Position = 0; BW.BaseStream.Write(this.MS.ToArray(), 0, this.size); BW.Flush(); BW.Close(); XmlTextWriter xtw = new XmlTextWriter(outputFileName + ".xml", Encoding.Default); xtw.Formatting = Formatting.Indented; xtw.WriteStartElement("Meta"); xtw.WriteAttributeString("TagType", this.type); xtw.WriteAttributeString("TagName", tempName); xtw.WriteAttributeString("Offset", this.offset.ToString()); xtw.WriteAttributeString("Size", this.size.ToString()); xtw.WriteAttributeString("Magic", this.magic.ToString()); xtw.WriteAttributeString("Parsed", this.parsed.ToString()); xtw.WriteAttributeString("Date", DateTime.Today.ToShortDateString()); xtw.WriteAttributeString("Time", DateTime.Now.ToShortTimeString()); xtw.WriteAttributeString("EntityVersion", "0.1"); xtw.WriteAttributeString("Padding", this.padding.ToString()); // xtw. for (int x = 0; x < this.items.Count; x++) { Item i = this.items[x]; if (i.intagname == this.name) { i.intagname = tempName; } switch (i.type) { case ItemType.Reflexive: Reflexive r = (Reflexive)i; xtw.WriteStartElement("Reflexive"); xtw.WriteAttributeString("Description", r.description); xtw.WriteAttributeString("Offset", r.offset.ToString()); xtw.WriteAttributeString("ChunkCount", r.chunkcount.ToString()); xtw.WriteAttributeString("ChunkSize", r.chunksize.ToString()); xtw.WriteAttributeString("Translation", r.translation.ToString()); xtw.WriteAttributeString("PointsToTagType", r.pointstotagtype); xtw.WriteAttributeString("PointsToTagName", r.pointstotagname); xtw.WriteAttributeString("TagType", r.intagtype); xtw.WriteAttributeString("TagName", r.intagname); xtw.WriteEndElement(); break; case ItemType.Ident: Ident id = (Ident)i; xtw.WriteStartElement("Ident"); xtw.WriteAttributeString("Description", id.description); xtw.WriteAttributeString("Offset", id.offset.ToString()); xtw.WriteAttributeString("PointsToTagType", id.pointstotagtype); xtw.WriteAttributeString("PointsToTagName", id.pointstotagname); xtw.WriteAttributeString("TagType", id.intagtype); xtw.WriteAttributeString("TagName", id.intagname); xtw.WriteEndElement(); break; case ItemType.String: String s = (String)i; xtw.WriteStartElement("String"); xtw.WriteAttributeString("Description", s.description); xtw.WriteAttributeString("Offset", s.offset.ToString()); xtw.WriteAttributeString("StringName", s.name); xtw.WriteAttributeString("TagType", s.intagtype); xtw.WriteAttributeString("TagName", s.intagname); xtw.WriteEndElement(); break; } if (i.intagname == tempName) { i.intagname = this.name; } } xtw.WriteEndElement(); xtw.Flush(); xtw.Close(); if (this.rawType != RawDataContainerType.Empty) { this.raw.SaveRawToFile(outputFileName, this); } return(tempName); }