Пример #1
0
        /// <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();
            }
        }
Пример #2
0
        /// <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();
            }
        }
Пример #3
0
        /// <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();
        }
Пример #4
0
        /// <summary>
        /// Loads a Halo 2 Map file using the specified stream.
        /// </summary>
        /// <param name="stream">The stream containing the map data.</param>
        public void LoadMap(Stream stream)
        {
            //Check if Nulled...
            if (io != null)
            {
                io.CloseIO();
                io.Dispose();
            }

            //Prepare new IO Handler
            io = new HaloIO(stream);
            LoadMap(io);
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
        /// <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();
            }
        }
Пример #7
0
        /// <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();
            }
        }
Пример #8
0
        /// <summary>
        /// Reloads the objects 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 LoadObjectInfo(HaloIO io)
        {
            //Prepare
            objectAddresses = new int[index.ObjectCount];
            objects         = new OBJECT[index.ObjectCount];
            entries         = new IndexEntry[index.ObjectCount];

            //Open?
            bool open = io.Open;

            if (!open)
            {
                io.OpenIO();
            }

            //Prepare
            StringBuilder fileName = null;

            //Determine Magic
            io.Position = ObjectStart + 8;    //Goto Globals Offset
            magic       = io.In.ReadInt32() - (header.IndexOffset + header.IndexLength);

            //Loop
            for (int i = 0; i < index.ObjectCount; i++)
            {
                //Get Address
                objectAddresses[i] = ObjectStart + (i * 16);
                io.Position        = objectAddresses[i];

                //Read
                objects[i] = io.In.ReadStructure <OBJECT>();

                //Get File Name
                fileName = new StringBuilder();
                if (header.FileCount > i)
                {
                    fileName.Append(fileList[i]);
                }
                else
                {
                    fileName.AppendFormat("Unknown ({0})", i);
                }

                //Create Index Entry
                if (objects[i].Offset != 0)
                {
                    entries[i] = new IndexEntry(this, objects[i], magic, fileName.ToString());
                }
                else
                {
                    entries[i] = new IndexEntry(this, objects[i], fileName.ToString());
                }
            }

            //Get Scenario and Globals
            scenario = GetEntryByIdent(index.ScenarioID);
            globals  = GetEntryByIdent(index.GlobalsID);

            //Close?
            if (!open)
            {
                IO.CloseIO();
            }
        }