/// <summary> /// Reloads the tags contained in the map using the <see cref="HaloIO"/> stream data. /// </summary> /// <param name="io">The <see cref="HaloIO"/> instance containing a map file.</param> public void LoadTagsInfo(HaloIO io) { //Prepare tags = new TAGHIERARCHY[index.TagCount]; tagAddresses = new int[index.TagCount]; //Open? bool open = io.Open; if (!open) { io.OpenIO(); } //Loop for (int i = 0; i < index.TagCount; i++) { tagAddresses[i] = header.IndexOffset + INDEX.Length + (i * TAGHIERARCHY.Length); io.Position = tagAddresses[i]; tags[i] = io.In.ReadStructure <TAGHIERARCHY>(); } //Close? if (!open) { io.CloseIO(); } }
/// <summary> /// Reloads the file names contained in the map using the <see cref="HaloIO"/> stream data. /// </summary> /// <param name="io">The <see cref="HaloIO"/> instance containing a map file.</param> public void LoadFileNamesInfo(HaloIO io) { //Prepare fileIndices = new int[header.FileCount]; fileList = new string[header.FileCount]; //Open? bool open = io.Open; if (!open) { io.OpenIO(); } //Read Files Index io.Position = header.FilesIndex; for (int i = 0; i < header.FileCount; i++) { fileIndices[i] = io.In.ReadInt32(); } //Read File List for (int i = 0; i < header.FileCount; i++) { io.Position = fileIndices[i] + header.FilesOffset; fileList[i] = io.In.ReadUTF8NullTerminated(); } //Close? if (!open) { io.CloseIO(); } }
/// <summary> /// Loads a Halo 2 Map file using the specified <see cref="HaloIO"/> instance. /// </summary> /// <param name="io">The <see cref="HaloIO"/> used to access the map file.</param> private void LoadMap(HaloIO io) { //Open io.OpenIO(); //Read Header io.Position = 0; header = io.In.ReadStructure <HEADER>(); //Prepare Index Table Header io.Position = header.IndexOffset; index = io.In.ReadStructure <INDEX>(); //Load File Names LoadFileNamesInfo(io); //Load Tag Objects LoadTagsInfo(io); //Load Index Objects LoadObjectInfo(io); //Load Strings LoadStringsInfo(io); //Fix SBSPs and LTMPs FixSpecialEntries(io); //Close Map io.CloseIO(); }
/// <summary> /// Loads a Halo 2 Map file using the specified file. /// </summary> /// <param name="fileLocation">The location of the file.</param> public void LoadMap(string fileLocation) { //Check if Nulled... if (io != null) { io.CloseIO(); io.Dispose(); } //Prepare new IO Handler io = new HaloIO(fileLocation); LoadMap(io); }
/// <summary> /// Reloads the strings contained in the map using the <see cref="HaloIO"/> stream data. /// </summary> /// <param name="io">The <see cref="HaloIO"/> instance containing a map file.</param> public void LoadStringsInfo(HaloIO io) { //Prepare stringIndices = new int[header.StringCount]; stringIDs = new string[header.StringCount]; string128s = new string[header.StringCount]; //Open? bool open = io.Open; if (!open) { io.OpenIO(); } //Read String Index io.Position = header.StringsIndexOffset; for (int i = 0; i < header.StringCount; i++) { stringIndices[i] = io.In.ReadInt32(); } //Read String IDs for (int i = 0; i < header.StringCount; i++) { io.Position = stringIndices[i] + header.StringsOffset; stringIDs[i] = io.In.ReadUTF8NullTerminated(); } //Read String 128s for (int i = 0; i < header.StringCount; i++) { io.Position = (128 * i) + header.Strings128Offset; string128s[i] = io.In.ReadUTF8(128).Replace("/0", string.Empty); } //Close? if (!open) { io.CloseIO(); } }
/// <summary> /// Fixes any special index entries in the map using <see cref="HaloIO"/> stream data. /// </summary> /// <param name="io">The <see cref="HaloIO"/> instance containing a map file.</param> public void FixSpecialEntries(HaloIO io) { //Open? bool open = io.Open; if (!open) { io.OpenIO(); } //Prepare uint sbspOffset; int sbspLength, sbspIdIndex, sbspId; int ltmpOffset, ltmpLength, ltmpId; uint bspMagic; //Obtain SBSP and LTMP data io.Position = scenario.Offset + 528; TAGBLOCK bsp = io.In.ReadUInt64(); for (int i = 0; i < bsp.Count; i++) { //Go to Position io.Position = bsp.Translate(magic) + (i * 68); //Get SBSP Data sbspOffset = io.In.ReadUInt32(); sbspLength = io.In.ReadInt32(); bspMagic = io.In.ReadUInt32() - sbspOffset; io.Position += 8; sbspId = io.In.ReadInt32(); //Set SBSP Entry if (sbspId != -1) { sbspIdIndex = GetIndexByIdent(sbspId); entries[sbspIdIndex] = IndexEntry.Create(this, entries[sbspIdIndex].FileName, entries[sbspIdIndex].Class, entries[sbspIdIndex].Ident, sbspOffset + bspMagic, (int)bspMagic, (uint)sbspLength); } //Get LTMP Ident io.Position = bsp.Translate(magic) + (i * 68) + 28; ltmpId = io.In.ReadInt32(); io.Position = sbspOffset + 8; //Get LTMP Data ltmpOffset = 0; ltmpLength = 0; if (sbspOffset > 0) { ltmpOffset = (int)(io.In.ReadInt32() - bspMagic); ltmpLength = (int)(sbspLength + sbspOffset - ltmpOffset); } //Set LTMP Entry if (ltmpId != -1) { int LtmpIdIndex = GetIndexByIdent(ltmpId); entries[LtmpIdIndex] = IndexEntry.Create(this, entries[LtmpIdIndex].FileName, entries[LtmpIdIndex].Class, entries[LtmpIdIndex].Ident, (uint)ltmpOffset + bspMagic, (int)bspMagic, (uint)ltmpLength); } } //Close? if (!open) { io.CloseIO(); } }