/// <summary> /// Adds data from the specified <c>ident</c> or <c>rdg</c> element. /// The <see cref="Idents"/> list contains <c>ident</c>'s values with /// their <c>n</c> attribute, eventually followed by the value of the /// <c>n</c> attribute of the parent <c>rdg</c> element. /// This in turn comes from merging an overlapping <c>app</c> element /// into another one, and preserves the original from-to location of /// the overlapping <c>app</c>. /// </summary> /// <param name="identElem">The ident element.</param> /// <exception cref="ArgumentNullException">identElem</exception> public void AddIdent(XElement identElem) { if (identElem == null) { throw new ArgumentNullException(nameof(identElem)); } if (identElem.Name.LocalName != "ident" && identElem.Name.LocalName != "rdg") { return; } string identValue = identElem.Name.LocalName == "rdg" ? $"@{identElem.Attribute("n")?.Value}" : $"{identElem.Value.Trim()}#{identElem.Attribute("n")!.Value}"; if (string.IsNullOrEmpty(identValue) || identValue == "@") { return; } string?rdgLoc = Idents.FirstOrDefault( i => i.StartsWith("@", StringComparison.Ordinal)); if (rdgLoc != null) { if (identValue.StartsWith("@", StringComparison.Ordinal)) { // this should never happen Logger?.LogError("Duplicate rdg@n attribute in idents list"); Idents.Add(identValue); } else { Idents.Insert(Idents.IndexOf(rdgLoc), identValue); } } else { Idents.Add(identValue); } }
private void ParseRecursively(List <mValue> ValueList, int chunkOffset, int chunkNumber) { for (int i = 0; i < ValueList.Count; i++) { object name; switch (ValueList[i].Attributes) { case mValue.ObjectAttributes.TagBlock: { if ((chunkOffset + ValueList[i].Offset) <= ((int)Map.IO.In.BaseStream.Length)) { break; } continue; } case mValue.ObjectAttributes.TagData: { if ((chunkOffset + ValueList[i].Offset) <= ((int)Map.IO.In.BaseStream.Length)) { goto Label_0224; } continue; } case mValue.ObjectAttributes.TagReference: { if ((chunkOffset + ValueList[i].Offset) <= ((int)Map.IO.In.BaseStream.Length)) { goto Label_03B7; } continue; } case mValue.ObjectAttributes.StringID: { if ((chunkOffset + ValueList[i].Offset) <= ((int)Map.IO.In.BaseStream.Length)) { goto Label_05E5; } continue; } default: { continue; } } Map.IO.In.BaseStream.Position = chunkOffset + ValueList[i].Offset; mTagBlock block = (mTagBlock)ValueList[i]; Structure item = new Structure { Name = block.Name }; if (chunkNumber != -1) { name = item.Name; item.Name = string.Concat(new object[] { name, " [", chunkNumber, "]" }); } item.Size = block.Size; item.Count = Map.IO.In.ReadInt32(); item.Pointer = Map.IO.In.ReadInt32() - Map.Map_Header.mapMagic; if (!(((item.Count <= 0) | (item.Pointer <= 0)) | (item.Count > 0x186a0))) { item.Offset = chunkOffset + block.Offset; Structures.Add(item); for (int j = 0; j < item.Count; j++) { ParseRecursively(block.Values, item.Pointer + (j * item.Size), j); } } continue; Label_0224: Map.IO.In.BaseStream.Position = chunkOffset + ValueList[i].Offset; mTagData data = (mTagData)ValueList[i]; TagData data2 = new TagData { Name = data.Name }; if (chunkNumber != -1) { name = data2.Name; data2.Name = string.Concat(new object[] { name, " [", chunkNumber, "]" }); } data2.Size = Map.IO.In.ReadInt32(); Stream baseStream = Map.IO.In.BaseStream; baseStream.Position += 8L; data2.Pointer = Map.IO.In.ReadInt32() - Map.Map_Header.mapMagic; if (!((data2.Size <= 0) | (data2.Pointer <= 0))) { data2.Offset = chunkOffset + data.Offset; Tag_Data_Blocks.Add(data2); } continue; Label_03B7: Map.IO.In.BaseStream.Position = (chunkOffset + ValueList[i].Offset) + 12; mTagReference reference = (mTagReference)ValueList[i]; Ident ident = new Ident { Name = reference.Name }; if (chunkNumber != -1) { name = ident.Name; ident.Name = string.Concat(new object[] { name, " [", chunkNumber, "]" }); } ident.Offset = chunkOffset + reference.Offset; ident.ID = Map.IO.In.ReadInt32(); int tagIndexByIdent = Map.GetTagIndexByIdent(ident.ID); if (tagIndexByIdent != -1) { ident.TagClass = Map.Index_Items[tagIndexByIdent].Class; } else { ident.TagClass = "Null"; } if (tagIndexByIdent != -1) { int key = Map.Index_Items[tagIndexByIdent].Ident; string str = Map.Index_Items[tagIndexByIdent].Name; if (Map.tagNameList.TagPaths.ContainsKey(key)) { try { str = Map.tagNameList.TagPaths[key]; } catch { } } ident.TagName = str + "." + Map.Index_Items[tagIndexByIdent].Class; } else { ident.TagName = "Null"; } Idents.Add(ident); continue; Label_05E5: Map.IO.In.BaseStream.Position = chunkOffset + ValueList[i].Offset; mStringID gid = (mStringID)ValueList[i]; StringIdentifier identifier = new StringIdentifier { Name = gid.Name }; if (chunkNumber != -1) { name = identifier.Name; identifier.Name = string.Concat(new object[] { name, " [", chunkNumber, "]" }); } identifier.Offset = chunkOffset + gid.Offset; identifier.Identifier = Map.IO.In.ReadInt32(); tagIndexByIdent = Map.String_Table.GetStringItemIndexByID(Map, identifier.Identifier); identifier.StringIndex = tagIndexByIdent; try { identifier.StringName = Map.String_Table.StringItems[tagIndexByIdent].Name; } catch { identifier.StringName = "<<invalid sid>>"; } Strings.Add(identifier); } }
private void ParseRecursively(List <mValue> ValueList, int chunkOffset, int chunkNumber) { //Loop through values for (int i = 0; i < ValueList.Count; i++) { //Determine the value type switch (ValueList[i].Attributes) { case mValue.ObjectAttributes.Reflexive: { //If the offset is rediculous.. if (chunkOffset + ValueList[i].Offset > (int)Map.IO.In.BaseStream.Length) { break; } //Go to the reflexive offset Map.IO.In.BaseStream.Position = chunkOffset + ValueList[i].Offset; //Get the reflexive mReflexive mreflexive = (mReflexive)ValueList[i]; //Initialize our instance of structure Structure structure = new Structure(); //Assign the name structure.Name = mreflexive.Name; //Add chunk modifier if (chunkNumber != -1) { structure.Name += " [" + chunkNumber + "]"; } //Assign the size structure.Size = mreflexive.Size; //Read the count structure.Count = Map.IO.In.ReadInt32(); //Read the pointer structure.Pointer = Map.IO.In.ReadInt32() - Map.MapHeader.mapMagic; //If the count or pointer are bad, break out and dont add it to the list if (structure.Count <= 0 | structure.Pointer <= 0 | structure.Count > 100000) { break; } //Assign the offset structure.Offset = chunkOffset + mreflexive.Offset; //Add it to the list Structures.Add(structure); //Loop through all the chunks for (int z = 0; z < structure.Count; z++) { //Parse recursively ParseRecursively(mreflexive.Values, structure.Pointer + (z * structure.Size), z); } break; } case mValue.ObjectAttributes.Ident: { //If the offset is rediculous.. if (chunkOffset + ValueList[i].Offset > (int)Map.IO.In.BaseStream.Length) { break; } //Go to the ident offset Map.IO.In.BaseStream.Position = chunkOffset + ValueList[i].Offset; //Get the ident instance mIdent mident = (mIdent)ValueList[i]; //Initialize our instance of the ident Ident ident = new Ident(); //Assign the name ident.Name = mident.Name; if (chunkNumber != -1) { ident.Name += " [" + chunkNumber + "]"; } //Assign the offset ident.Offset = chunkOffset + mident.Offset - 12; //Assign the Ident ident.ID = Map.IO.In.ReadInt32(); //Get the tag index int index = Map.GetTagIndexByIdent(ident.ID); //Assign the class if (index != -1) { ident.TagClass = Map.IndexItems[index].Class; } else { ident.TagClass = "Null"; } //Assign the name if (index != -1) { ident.TagName = Map.IndexItems[index].Name; } else { ident.TagName = "Null"; } //Add to the ident to the list Idents.Add(ident); break; } case mValue.ObjectAttributes.StringID: { //If the offset is rediculous.. if (chunkOffset + ValueList[i].Offset > (int)Map.IO.In.BaseStream.Length) { break; } //Go to the ident offset Map.IO.In.BaseStream.Position = chunkOffset + ValueList[i].Offset; //Get the ident instance mStringID mstringid = (mStringID)ValueList[i]; //Initialize our instance of the string id. StringIdentifier str = new StringIdentifier(); //Assign the name str.Name = mstringid.Name; if (chunkNumber != -1) { str.Name += " [" + chunkNumber + "]"; } //Assign the offset str.Offset = chunkOffset + mstringid.Offset; //Assign the Ident str.Identifier = Map.IO.In.ReadInt32(); //Get the string index int index = Map.StringTable.GetStringItemIndexByID(Map, str.Identifier); //Assign the string index str.StringIndex = index; //Try to.. try { //Assign the string name str.StringName = Map.StringTable.StringItems[index].Name; } catch { //Assign our invalid name str.StringName = "<<invalid sid>>"; } //Add to the string to the list Strings.Add(str); break; } } } }