/// <summary> /// The cycle elements. /// </summary> /// <param name="elements">The elements.</param> /// <param name="offset">The offset.</param> /// <param name="count">The count.</param> /// <param name="TagIndex">The TagIndex.</param> /// <param name="chunksize">The chunksize.</param> /// <param name="magic">The magic.</param> /// <param name="previousparsedtranslation">The previousparsedtranslation.</param> /// <returns></returns> /// <remarks></remarks> private string[] CycleElements( object[] elements, int offset, int count, int TagIndex, int chunksize, int magic, int previousparsedtranslation) { List <string> tempS = new List <string>(); // elements = all the listings in the .ENT file foreach (IFPIO.BaseObject tempbase in elements.Cast <IFPIO.BaseObject>()) { for (int x = 0; x < count; x++) { switch (tempbase.ObjectType) { // AKA Structs case IFPIO.ObjectEnum.Struct: IFPIO.Reflexive tempreflex = (IFPIO.Reflexive)tempbase; XReflex r = new XReflex(); meta.Map.BR.BaseStream.Position = offset + tempreflex.offset + (x * chunksize); r.mapOffset = (int)meta.Map.BR.BaseStream.Position; // Contains how many Reflexives are listed r.chunkcount = meta.Map.BR.ReadInt32(); if (r.chunkcount == 0) { continue; } r.chunksize = tempreflex.chunkSize; int tempshit = meta.Map.BR.ReadInt32(); r.translation = tempshit - meta.magic; r.pointstoTagIndex = meta.Map.Functions.ForMeta.FindMetaByOffset(r.translation); if (meta.type == "sbsp" && r.pointstoTagIndex != -1) { // r.translation = tempshit - magic; r.pointstoTagIndex = meta.TagIndex; } if (tempreflex.HasCount == false) { r.translation = r.chunkcount - magic; r.chunkcount = 1; r.pointstoTagIndex = meta.TagIndex; } r.description = tempreflex.name + " [" + x + "]"; if (r.pointstoTagIndex == -1) { continue; } if (meta.parsed) { meta.Map.BR.BaseStream.Position = r.translation; r.RealTranslation = r.translation - meta.Map.MetaInfo.Offset[r.pointstoTagIndex]; r.RealTagNumber = r.pointstoTagIndex; int messed = 0; // NEVER USED, ONLY INCREMENTED?? bool found = false; for (int h = 0; h < meta.items.Count; h++) { Meta.Item item = meta.items[h]; if (item.type != Meta.ItemType.Reflexive) { continue; } XReflex rr = (XReflex)meta.items[h]; if (r.RealTranslation == rr.RealTranslation && r.RealTagNumber == rr.RealTagNumber) { r.translation = rr.translation; r.pointstoTagIndex = meta.TagIndex; r.pointstotagtype = meta.type; r.pointstotagname = meta.name; r.offset = previousparsedtranslation + tempreflex.offset + (x * chunksize); r.intag = meta.TagIndex; r.intagtype = meta.type; r.intagname = meta.name; meta.items.Add(r); meta.reflexivecount++; found = true; break; } messed++; } if (found == false) { r.translation = meta.size; meta.MS.SetLength(meta.size + (r.chunksize * r.chunkcount)); meta.MS.Write( meta.Map.BR.ReadBytes(r.chunksize * r.chunkcount), 0, r.chunksize * r.chunkcount); /************************************************************/ // Shouldn't this just add the number of added chunks?? meta.size += r.chunksize * r.chunkcount; // if (tempreflex.adding != 0) // { // int temppadsize = meta.Map.Functions.Padding(r.chunksize * r.chunkcount, (int)s.Padding); // meta.MS.SetLength((long)(meta.size + (temppadsize))); // byte[] tempbytes = new byte[temppadsize]; // meta.MS.Write(tempbytes, 0, temppadsize); // meta.size += temppadsize; // } if (tempreflex.paddingAlign != 0) { int temppadsize = meta.size % tempreflex.paddingAlign == 0 ? 0 : tempreflex.paddingAlign - (meta.size % tempreflex.paddingAlign); meta.MS.SetLength((long)(meta.size + temppadsize)); byte[] tempbytes = new byte[temppadsize]; meta.MS.Write(tempbytes, 0, temppadsize); meta.size += temppadsize; } r.pointstoTagIndex = meta.TagIndex; r.pointstotagtype = meta.type; r.pointstotagname = meta.name; r.offset = previousparsedtranslation + tempreflex.offset + (x * chunksize); r.intag = meta.TagIndex; r.intagtype = meta.type; r.intagname = meta.name; meta.items.Add(r); meta.reflexivecount++; this.CycleElements( tempreflex.items, r.RealTranslation + meta.Map.MetaInfo.Offset[r.RealTagNumber], r.chunkcount, r.pointstoTagIndex, tempreflex.chunkSize, magic, r.translation); } else { found = false; } } #region unparsedReflexive else { r.pointstotagtype = meta.Map.MetaInfo.TagType[r.pointstoTagIndex]; r.pointstotagname = meta.Map.FileNames.Name[r.pointstoTagIndex]; r.translation = r.translation - meta.Map.MetaInfo.Offset[r.pointstoTagIndex]; r.offset = offset + tempreflex.offset + (x * chunksize); r.mapOffset = r.offset; r.offset -= meta.Map.MetaInfo.Offset[TagIndex]; r.intag = TagIndex; r.intagtype = meta.Map.MetaInfo.TagType[r.intag]; r.intagname = meta.Map.FileNames.Name[r.intag]; meta.items.Add(r); meta.reflexivecount++; this.CycleElements( tempreflex.items, meta.Map.MetaInfo.Offset[r.pointstoTagIndex] + r.translation, r.chunkcount, r.pointstoTagIndex, tempreflex.chunkSize, magic, 0); } #endregion break; case IFPIO.ObjectEnum.Ident: IFPIO.Ident tempident = (IFPIO.Ident)tempbase; Meta.Ident i = new Meta.Ident(); meta.Map.BR.BaseStream.Position = offset + tempident.offset + (x * chunksize); i.mapOffset = (int)meta.Map.BR.BaseStream.Position; i.ident = meta.Map.BR.ReadInt32(); i.intag = TagIndex; i.intagtype = meta.Map.MetaInfo.TagType[i.intag]; i.intagname = meta.Map.FileNames.Name[i.intag]; i.pointstoTagIndex = meta.Map.Functions.ForMeta.FindMetaByID(i.ident); if (i.pointstoTagIndex != -1) { // i.pointstoTagIndex = meta.Map.Functions.Meta.FindMetaByID(i.ident, meta.Map); i.pointstotagtype = meta.Map.MetaInfo.TagType[i.pointstoTagIndex]; i.pointstotagname = meta.Map.FileNames.Name[i.pointstoTagIndex]; } else { if (i.ident > 0) { int off = i.mapOffset - meta.Map.MetaInfo.Offset[TagIndex]; /********************************************************************* * Save errors to be displayed all at once. *********************************************************************/ tempS.Add( "Tag: [" + meta.Map.MetaInfo.TagType[TagIndex] + "] " + meta.Map.FileNames.Name[TagIndex] + " @ Offset: " + off.ToString().PadLeft(10) + " , Name: \"" + tempident.name + "\""); i.ident = -1; } i.pointstoTagIndex = -1; i.pointstotagname = "Null"; } //i.mapOffset = offset + tempident.offset + (x * chunksize); i.offset = i.mapOffset - meta.Map.MetaInfo.Offset[TagIndex]; if (meta.parsed) { i.offset = previousparsedtranslation + tempident.offset + (x * chunksize); } i.description = tempident.name + " [" + x + "]"; meta.items.Add(i); break; // If our object is a STRING, read the string info from the file, not just offset values case IFPIO.ObjectEnum.StringID: IFPIO.SID tempstringid = (IFPIO.SID)tempbase; Meta.String si = new Meta.String(); meta.Map.BR.BaseStream.Position = offset + tempstringid.offset + (x * chunksize); si.mapOffset = (int)meta.Map.BR.BaseStream.Position; si.id = meta.Map.BR.ReadUInt16(); if (si.id == 0 | si.id >= meta.Map.MapHeader.scriptReferenceCount) { continue; } meta.Map.BR.ReadByte(); int temp = meta.Map.BR.ReadByte(); if (temp != meta.Map.Strings.Length[si.id]) { continue; } // Finds offset for each subsection -> Chunksize = Size of whole Subsection si.mapOffset = offset + tempstringid.offset + (x * chunksize); si.offset = si.mapOffset - meta.Map.MetaInfo.Offset[TagIndex]; if (meta.parsed) { si.offset = previousparsedtranslation + tempstringid.offset + (x * chunksize); } si.name = meta.Map.Strings.Name[si.id]; si.intag = TagIndex; si.intagtype = meta.Map.MetaInfo.TagType[si.intag]; si.intagname = meta.Map.FileNames.Name[si.intag]; si.description = tempstringid.name + " [" + x + "]"; meta.items.Add(si); break; } } } return(tempS.ToArray()); }
/// <summary> /// The cycle elements. /// </summary> /// <param name="reflex">The reflex.</param> /// <param name="elements">The elements.</param> /// <param name="meta">The meta.</param> /// <param name="offset">The offset.</param> /// <param name="map">The map.</param> /// <param name="TagIndex">The TagIndex.</param> /// <param name="magic">The magic.</param> /// <remarks></remarks> private void CycleElements( ref SplitReflexive reflex, object[] elements, ref Meta meta, int offset, Map map, int TagIndex, int magic) { for (int x = 0; x < reflex.chunkcount; x++) { SplitReflexive chunkreflexive = new SplitReflexive(); map.BR.BaseStream.Position = reflex.realtranslation + (x * reflex.chunksize); chunkreflexive.MS = new MemoryStream(reflex.chunksize); chunkreflexive.MS.Write(map.BR.ReadBytes(reflex.chunksize), 0, reflex.chunksize); chunkreflexive.chunksize = reflex.chunksize; chunkreflexive.splitReflexiveType = SplitReflexive.SplitReflexiveType.Chunk; reflex.Chunks.Add(chunkreflexive); for (int xx = 0; xx < elements.Length; xx++) { IFPIO.BaseObject tempbase = (IFPIO.BaseObject)elements[xx]; switch (tempbase.ObjectType) { case IFPIO.ObjectEnum.Struct: IFPIO.Reflexive tempreflex = (IFPIO.Reflexive)tempbase; SplitReflexive r = new SplitReflexive(); map.BR.BaseStream.Position = offset + tempreflex.offset + (x * reflex.chunksize); r.mapOffset = (int)map.BR.BaseStream.Position; r.chunkcount = map.BR.ReadInt32(); if (r.chunkcount == 0) { continue; } r.chunksize = tempreflex.chunkSize; r.translation = map.BR.ReadInt32() - magic; r.pointstoTagIndex = map.Functions.ForMeta.FindMetaByOffset(r.translation); r.description = tempreflex.name; if (r.pointstoTagIndex == -1) { continue; } // r.parent = reflex.description;// parentname; r.realtranslation = r.translation; r.realTagIndex = r.pointstoTagIndex; r.label = tempreflex.label; r.pointstoTagIndex = meta.TagIndex; r.pointstotagtype = meta.type; r.pointstotagname = meta.name; r.offset = tempreflex.offset; r.intag = meta.TagIndex; r.intagtype = meta.type; r.intagname = meta.name; r.translation -= map.MetaInfo.Offset[r.realTagIndex]; r.inchunknumber = x; r.splitReflexiveType = SplitReflexive.SplitReflexiveType.Container; r.Chunks = new List <SplitReflexive>(); CycleElements( ref r, tempreflex.items, ref meta, r.realtranslation, map, r.pointstoTagIndex, magic); reflex.Chunks[x].ChunkResources.Add(r); meta.reflexivecount++; break; case IFPIO.ObjectEnum.Ident: IFPIO.Ident tempident = (IFPIO.Ident)tempbase; SplitIdent i = new SplitIdent(); map.BR.BaseStream.Position = offset + tempident.offset + (x * reflex.chunksize); i.mapOffset = (int)map.BR.BaseStream.Position; i.ident = map.BR.ReadInt32(); if (i.ident != -1) { try { i.pointstoTagIndex = map.Functions.ForMeta.FindMetaByID(i.ident); i.pointstotagtype = map.MetaInfo.TagType[i.pointstoTagIndex]; i.pointstotagname = map.FileNames.Name[i.pointstoTagIndex]; } catch { continue; } } else { continue; } i.mapOffset = offset + tempident.offset + (x * reflex.chunksize); i.offset = tempident.offset; i.inchunknumber = x; i.intag = TagIndex; i.intagtype = map.MetaInfo.TagType[i.intag]; i.intagname = map.FileNames.Name[i.intag]; i.description = tempident.name; reflex.Chunks[x].ChunkResources.Add(i); break; case IFPIO.ObjectEnum.StringID: IFPIO.SID tempstringid = (IFPIO.SID)tempbase; SplitString si = new SplitString(); map.BR.BaseStream.Position = offset + tempstringid.offset + (x * reflex.chunksize); si.mapOffset = (int)map.BR.BaseStream.Position; si.id = map.BR.ReadUInt16(); if (si.id == 0 | si.id >= map.MapHeader.scriptReferenceCount) { continue; } map.BR.ReadByte(); int temp = map.BR.ReadByte(); if (temp != map.Strings.Length[si.id]) { continue; } si.mapOffset = offset + tempstringid.offset + (x * reflex.chunksize); si.offset = si.mapOffset - map.MetaInfo.Offset[TagIndex]; si.offset = tempstringid.offset; si.inchunknumber = x; si.name = map.Strings.Name[si.id]; si.intag = TagIndex; si.intagtype = map.MetaInfo.TagType[si.intag]; si.intagname = map.FileNames.Name[si.intag]; si.description = tempstringid.name; reflex.Chunks[x].ChunkResources.Add(si); break; } } } return; }