/// <summary> /// Gets and returns a display string from a specified node type, stream, address, and map file. /// </summary> /// <param name="itemType">The item type.</param> /// <param name="dataStream">The data stream.</param> /// <param name="address">The address of the data.</param> /// <param name="map">The map file.</param> /// <returns>A string.</returns> private static string GetNodeDisplayName(IfpNodeType itemType, VirtualStream dataStream, long address, MapFile map) { //Goto dataStream.Seek(address, SeekOrigin.Begin); using (BinaryReader reader = dataStream.CreateReader()) try { switch (itemType) { case IfpNodeType.Byte: return(reader.ReadByte().ToString()); case IfpNodeType.SignedByte: return(reader.ReadSByte().ToString()); case IfpNodeType.Short: return(reader.ReadInt16().ToString()); case IfpNodeType.UnsignedShort: return(reader.ReadUInt16().ToString()); case IfpNodeType.Int: return(reader.ReadInt32().ToString()); case IfpNodeType.UnsignedInt: return(reader.ReadUInt32().ToString()); case IfpNodeType.Long: return(reader.ReadInt64().ToString()); case IfpNodeType.UnsignedLong: return(reader.ReadUInt64().ToString()); case IfpNodeType.Single: return(reader.ReadSingle().ToString()); case IfpNodeType.Double: return(reader.ReadDouble().ToString()); case IfpNodeType.String32: return(reader.ReadUTF8(32).Trim('\0')); case IfpNodeType.String64: return(reader.ReadUTF8(64).Trim('\0')); case IfpNodeType.Unicode128: return(reader.ReadUTF8(128).Trim('\0')); case IfpNodeType.Unicode256: return(reader.ReadUTF8(256).Trim('\0')); case IfpNodeType.TagId: IndexEntry entry = map.IndexEntries[reader.Read <TagId>()]; if (entry == null) { return("Null"); } else { return($"{entry.Filename}.{entry.Root}"); } case IfpNodeType.StringId: return(map.Strings[reader.Read <StringId>().Index]); } } catch { } return(string.Empty); }
/// <summary> /// Gets and returns the display name(s) of the data object using the supplied map file. /// </summary> /// <returns>An array of string elements.</returns> /// <param name="map">The map file.</param> public string[] GetDisplayNames(MapFile map) { //Prepare List <string> names = new List <string>(); string name = node.Name; //Check if (IsTagBlock && value is TagBlock tagBlock) { //Check Label if (!string.IsNullOrEmpty(node.Label)) { //Check Count if (tagBlock.Count > 0) { //Get Node IfpNode[] labelNodes = node.Nodes[node.Label]; //Loop if (labelNodes.Length > 0) { using (BinaryReader reader = dataStream.CreateReader()) for (int i = 0; i < tagBlock.Count; i++) { //Hacky IfpNode hack = labelNodes[0]; //Set name... name = GetNodeDisplayName(hack.Type, dataStream, tagBlock.Offset + (uint)(i * node.Length) + hack.FieldOffset, map); //Check if (!string.IsNullOrEmpty(name)) { names.Add(name); } else { names.Add(node.Name); } } } } } else { //Add names... for (int i = 0; i < tagBlock.Count; i++) { names.Add(name); } } } //Add element name once if no names are retrieved if (names.Count == 0) { names.Add(name); } //Return return(names.ToArray()); }
/// <summary> /// Reads and returns the value of this data object. /// </summary> /// <returns>The value of the data object.</returns> public object ReadValue() { //Check if (!IsValid) { return(null); } //Goto dataStream.Seek(address, SeekOrigin.Begin); using (BinaryReader reader = dataStream.CreateReader()) switch (node.Type) { case IfpNodeType.Single: value = reader.ReadSingle(); break; case IfpNodeType.Double: value = reader.ReadDouble(); break; case IfpNodeType.SignedByte: value = reader.ReadSByte(); break; case IfpNodeType.Byte: case IfpNodeType.Enumerator8: case IfpNodeType.Bitfield8: value = reader.ReadByte(); break; case IfpNodeType.Short: value = reader.ReadInt16(); break; case IfpNodeType.UnsignedShort: case IfpNodeType.Enumerator16: case IfpNodeType.Bitfield16: value = reader.ReadUInt16(); break; case IfpNodeType.Int: value = reader.ReadInt32(); break; case IfpNodeType.UnsignedInt: case IfpNodeType.Enumerator32: case IfpNodeType.Bitfield32: value = reader.ReadUInt32(); break; case IfpNodeType.Long: reader.ReadInt64(); break; case IfpNodeType.UnsignedLong: case IfpNodeType.Enumerator64: case IfpNodeType.Bitfield64: value = reader.ReadUInt64(); break; case IfpNodeType.String32: value = reader.ReadUTF8(32).Trim('\0'); break; case IfpNodeType.String64: value = reader.ReadUTF8(64).Trim('\0'); break; case IfpNodeType.Unicode128: value = reader.ReadUTF8(128).Trim('\0'); break; case IfpNodeType.Unicode256: value = reader.ReadUTF8(256).Trim('\0'); break; case IfpNodeType.Tag: value = reader.Read <TagFourCc>(); break; case IfpNodeType.TagId: value = reader.Read <TagId>(); break; case IfpNodeType.StringId: value = reader.Read <StringId>(); break; case IfpNodeType.TagBlock: value = reader.Read <TagBlock>(); break; } //Return return(value); }
private void FixSystemLinkButton_Click(object sender, EventArgs e) { /* * Heh I guess Entity is good for something :P */ //Prepare ITagGroup tagGroup = null; ITagGroup scenario = new Scenario(); ITagBlock scenarioBlock = null, simulationDefinitionTableElementBlock = null; BlockField simulationDefinitionTableField = null; List <IndexEntry> simulationDefinitionEntries = new List <IndexEntry>(); bool success = false; //Build table foreach (IndexEntry entry in Map.IndexEntries) { switch (entry.Root) { case "bipd": case "bloc": case "ctrl": case "jpt!": case "mach": case "scen": case "ssce": case "vehi": simulationDefinitionEntries.Add(entry); break; case "eqip": case "garb": case "proj": simulationDefinitionEntries.Add(entry); simulationDefinitionEntries.Add(entry); break; case "weap": simulationDefinitionEntries.Add(entry); simulationDefinitionEntries.Add(entry); simulationDefinitionEntries.Add(entry); break; } } //Read scenario using (BinaryReader reader = Map.Scenario.TagData.CreateReader()) { reader.BaseStream.Seek((uint)Map.Scenario.PostProcessedOffset, SeekOrigin.Begin); scenario.Read(reader); } //Re-create simulation definition table scenarioBlock = scenario[0]; simulationDefinitionTableField = (BlockField)scenarioBlock[143]; simulationDefinitionTableField.BlockList.Clear(); foreach (IndexEntry entry in simulationDefinitionEntries) { //Attempt to add tag block simulationDefinitionTableElementBlock = simulationDefinitionTableField.Add(out success); if (success) { simulationDefinitionTableElementBlock[0].Value = entry.Id; } } //Rebuild map using (VirtualStream tagDataStream = new VirtualStream(Map.TagDataStream.MemoryAddress)) using (BinaryWriter writer = tagDataStream.CreateWriter()) using (BinaryReader reader = Map.TagDataStream.CreateReader()) { //Loop foreach (IndexEntry entry in Map.IndexEntries.Where(ie => ie.Offset > 0 && ie.Size > 0)) { //Read (unless it's our modified scenario) if (entry != Map.Scenario) { tagGroup = TagLookup.CreateTagGroup(entry.Root); reader.BaseStream.Seek(entry.Offset, SeekOrigin.Begin); tagGroup.Read(reader); } else { tagGroup = scenario; } //Create buffer using (VirtualStream stream = new VirtualStream(tagDataStream.Position)) using (BinaryWriter tagWriter = stream.CreateWriter()) using (BinaryReader tagReader = stream.CreateReader()) { //Write tagGroup.Write(tagWriter); //Recalculate raw addresses Helper.RecalculateRawAddresses(entry.Raws, entry.Root, stream, tagReader, tagWriter); //Setup tag entry.Offset = (uint)stream.MemoryAddress; entry.Size = (int)stream.Length; //Write to tag data stream writer.Write(stream.ToArray()); } } //Align tagDataStream.Align(4096); //Swap Map.SwapTagBuffer(tagDataStream.ToArray(), tagDataStream.MemoryAddress); } }