コード例 #1
0
        private void ExtractTag(int index)
        {
            FileStream fsBitmap = OptionsManager.GetBitmapStream(m_MapVersion);
            FileStream fsSound  = OptionsManager.GetSoundStream(m_MapVersion);

            string TagClass = GetTagClass(BitConverter.GetBytes(HaloMap.IndexItems[index].Type1), 0);

            //Loading Tag Long name and seting the map version folder
            string ProcessTagFile  = TagClass.Trim() + ".mag";
            string MagfilePathRoot = "";
            string OutputPathRoot  = "";

            switch (m_MapVersion)
            {
            case MapfileVersion.HALOPC:
                MagfilePathRoot = Application.StartupPath + @"\Tag Structures\PcHalo\";
                OutputPathRoot  = Application.StartupPath + @"\Games\Pc\Halo\";
                break;

            case MapfileVersion.HALOCE:
                MagfilePathRoot = Application.StartupPath + @"\Tag Structures\CeHalo\";
                OutputPathRoot  = Application.StartupPath + @"\Games\Pc\Halo\";
                break;

            case MapfileVersion.XHALO1:
                MagfilePathRoot = Application.StartupPath + @"\Tag Structures\XHalo\";
                OutputPathRoot  = Application.StartupPath + @"\Games\Xbox\Halo\";
                break;
            }

            //Creating Directorys for extracted tags;
            string[] Directorys = new string[256];
            string   DirSep     = @"\";

            Directorys = HaloMap.IndexItemStringList[index].Split(DirSep.ToCharArray(), 256);
            uint   Dircount = (uint)Directorys.Length - 1;
            string NewDirectoryStructure = "";

            for (uint Count = 0; Count < Dircount; Count += 1)
            {
                if (Directory.Exists(OutputPathRoot + NewDirectoryStructure + Directorys[Count]) == false)
                {
                    Directory.CreateDirectory(OutputPathRoot + NewDirectoryStructure + Directorys[Count]);
                    NewDirectoryStructure += Directorys[Count] + @"\";
                }
                else
                {
                    NewDirectoryStructure += Directorys[Count] + @"\";
                }
            }

            StreamReader MagReader = new StreamReader(MagfilePathRoot + ProcessTagFile);
            string       InLine    = MagReader.ReadLine();

            FileInfo     fiout = new FileInfo(OutputPathRoot + HaloMap.IndexItemStringList[index]);
            MemoryStream msout = new MemoryStream();

            //msout = fiout.Open(FileMode.Create,FileAccess.ReadWrite);  //Grenadiac changed this to RW for archive hack
            TagHeader.SeekToTagDataStart(ref msout);

            fsin.Seek(HaloMap.IndexItems[index].MetaOffset, System.IO.SeekOrigin.Begin);

            byte   TabByte    = 0x09;
            string TabReplace = "";

            TabReplace += (char)TabByte;

            string[] MagArray = new string[256];
            int      MagIndex = 0;

            do
            {
                InLine = MagReader.ReadLine();
                //MagArray[Count] = InLine.Split(new char[]{' '},256);
                MagArray[MagIndex] = InLine.Replace(TabReplace, "").ToLower().Trim();
                MagIndex           = MagIndex + 1;
            }while (MagReader.Peek() != -1);
            MagReader.Close();

            Structure2 MainStruct = new Structure2();

            MainStruct.StructureCS(HaloMap.IndexItems[index].MetaOffset, (uint)MagIndex, HaloMap.IndexItems[index].MetaMagic, HaloMap.Map_Magic, MagArray, 1, fsin, msout, fsBitmap, fsSound, HaloMap.IndexHeader.Verts_Offset, HaloMap.IndexHeader.Index_Offset, HaloMap.MapHeader.Map_Version);
            //public void StructureCS(uint MetaOffset,uint MagIndex,uint OffsetMagic,uint MapMagic,string[] StructureArray,uint ChunkCount,FileStream MapFile,FileStream TagFile,FileStream BitmapFile,FileStream SoundFile,uint VerticesOffset,uint IndicesOffset,StreamWriter ObjFile,uint MapVersion)

            // Initialize and write out the PROM tag header
            TagHeader tag_hdr = new TagHeader();

            tag_hdr.TagClass0   = TagClass;
            tag_hdr.GameVersion = (MapfileVersion)m_MapVersion;
            tag_hdr.TagSize     = (int)msout.Position - TagHeader.PROM_HEADER_SIZE;
            tag_hdr.Write(ref msout);

            //Write out a zero-attachment header
            tag_hdr.SeekToAttachStart(ref msout);
            AttachmentHeader attach_hdr = new AttachmentHeader();

            attach_hdr.Write(ref msout);

            //GRENADIAC HACK to put tagfile into archive
            if (m_OutputArchive != null)
            {
                m_OutputArchive.AddTagfileToArchive(HaloMap.IndexItemStringList[index], msout.GetBuffer(), (int)msout.Position);
            }


            msout.Close();
            fsBitmap.Close();
            fsSound.Close();
        }
コード例 #2
0
        private void CombinedExtractTag(int index)
        {
            FileStream fsBitmap             = null;
            FileStream fsSound              = null;
            FileStream fsShared             = null;
            FileStream fsSinglePlayerShared = null;
            FileStream fsMainMenu           = null;

            switch (m_MapVersion)
            {
            case MapfileVersion.HALOPC:
            case MapfileVersion.HALOCE:
                fsBitmap = OptionsManager.GetBitmapStream(m_MapVersion);
                fsSound  = OptionsManager.GetSoundStream(m_MapVersion);
                break;

            case MapfileVersion.XHALO2:
                fsShared             = OptionsManager.GetHalo2SharedStream();
                fsSinglePlayerShared = OptionsManager.GetHalo2SinglePlayerSharedStream();
                fsMainMenu           = OptionsManager.GetHalo2MainMenuStream();
                break;
            }

            string TagClass;

            if (m_MapVersion == MapfileVersion.XHALO2)
            {
                TagClass = GetTagClass(BitConverter.GetBytes(Halo2Map.IndexItem[index].TagType), 0);
            }
            else
            {
                TagClass = GetTagClass(BitConverter.GetBytes(HaloMap.IndexItems[index].Type1), 0);
            }

            if (TagClass == "<fx>")
            {
                TagClass = "FXFX";
            }

            //byte[] TagHeaderBuffer = new byte[64];
            //OptionsManager.GetGuerillaHeader(m_MapVersion, TagClass, TagHeaderBuffer);

            //Loading Tag Long name and seting the map version folder
            string MagfilePathRoot = OptionsManager.GetMagfilePath(m_MapVersion);
            string OutputPathRoot  = OptionsManager.GetExtractPath(m_MapVersion);

            //Creating Directorys for extracted tags;
            string[] Directorys = new string[256];
            string   DirSep     = @"\";

            if (m_MapVersion == MapfileVersion.XHALO2)
            {
                Directorys = Halo2Map.StringTable.TagStrings[index].Split(DirSep.ToCharArray(), 256);
            }
            else
            {
                Directorys = HaloMap.IndexItemStringList[index].Split(DirSep.ToCharArray(), 256);
            }

            //Create tag directory if it doesn't exist
            uint   Dircount = (uint)Directorys.Length - 1;
            string NewDirectoryStructure = "";

            for (uint Count = 0; Count < Dircount; Count += 1)
            {
                if (Directory.Exists(OutputPathRoot + NewDirectoryStructure + Directorys[Count]) == false)
                {
                    Directory.CreateDirectory(OutputPathRoot + NewDirectoryStructure + Directorys[Count]);
                    NewDirectoryStructure += Directorys[Count] + @"\";
                }
                else
                {
                    NewDirectoryStructure += Directorys[Count] + @"\";
                }
            }

            //Parse mag file
            string       ProcessTagFile = TagClass.Trim() + ".mag";
            StreamReader MagReader      = new StreamReader(MagfilePathRoot + ProcessTagFile);
            string       InLine         = MagReader.ReadLine();
            string       TagExtension   = InLine;
            byte         TabByte        = 0x09;
            string       TabReplace     = "";

            TabReplace += (char)TabByte;

            string[] MagArray = new string[256];
            int      MagIndex = 0;

            do
            {
                InLine             = MagReader.ReadLine();
                MagArray[MagIndex] = InLine.Replace(TabReplace, "").ToLower().Trim();
                MagIndex++;
            }while(MagReader.Peek() != -1);
            MagReader.Close();

            //Create output tag stream/file
            FileInfo fiout;

            if (m_MapVersion == MapfileVersion.XHALO2)
            {
                string   SplitChar  = ".";
                string[] FixTagName = Halo2Map.StringTable.TagStrings[index].Split(SplitChar.ToCharArray(), 2);
                fiout = new FileInfo(OutputPathRoot + FixTagName[0] + "." + TagExtension.Trim());
            }
            else
            {
                fiout = new FileInfo(OutputPathRoot + HaloMap.IndexItemStringList[index]);
            }

            MemoryStream msout = new MemoryStream();

            //msout = fiout.Open(FileMode.Create,FileAccess.ReadWrite);  //Grenadiac changed this to RW for archive hack
            //msout.Seek(0,System.IO.SeekOrigin.Begin);
            TagHeader.SeekToTagDataStart(ref msout);
            //msout.Write(TagHeaderBuffer,0,64);

            //Parse the meta and reformat output tag according to Magfile rules
            if (m_MapVersion == MapfileVersion.XHALO2)
            {
                // Create debug stream writer
                StreamWriter DebugFile;
                DebugFile = null;//new StreamWriter(Application.StartupPath + @"\TagDebug.txt");
                byte[] TagTable = new byte[TagCount * 16];
                fsin.Seek(Halo2Map.IndexHeader.OffsetToTags, System.IO.SeekOrigin.Begin);
                fsin.Read(TagTable, 0, TagTable.Length);
                Halo2Structure MainStruct = new Halo2Structure();
                if (TagClass == "sbsp")
                {
                    MainStruct.StructureCS((uint)MagIndex, Halo2Map.IndexItem[index].TagOffsetMagic, Halo2Map.IndexItem[index].TagMagic, MagArray, 1, fsin, msout, fsShared, 0, 0, Halo2Map.StringTable.StringBuffer, Halo2Map.StringTable.OffsetsBuffer, fsSinglePlayerShared, fsMainMenu, fsShared, Halo2Map.MapHeader.MetaStart, Halo2Map.MapHeader.FileSize, DebugFile, TagTable, Halo2Map.MapHeader.ScriptStringArray);
                }
                fsShared.Close();
                fsSinglePlayerShared.Close();
                fsMainMenu.Close();
            }
            else
            {
                fsin.Seek(HaloMap.IndexItems[index].MetaOffset, System.IO.SeekOrigin.Begin);
                Structure2 MainStruct = new Structure2();
                MainStruct.StructureCS(HaloMap.IndexItems[index].MetaOffset, (uint)MagIndex, HaloMap.IndexItems[index].MetaMagic, HaloMap.Map_Magic, MagArray, 1, fsin, msout, fsBitmap, fsSound, HaloMap.IndexHeader.Verts_Offset, HaloMap.IndexHeader.Index_Offset, HaloMap.MapHeader.Map_Version);
                fsBitmap.Close();
                fsSound.Close();
            }

            // Initialize and write out the PROM tag header
            TagHeader tag_hdr = new TagHeader();

            tag_hdr.TagClass0   = TagClass;
            tag_hdr.GameVersion = (MapfileVersion)m_MapVersion;
            tag_hdr.TagSize     = (int)msout.Position - TagHeader.PROM_HEADER_SIZE;
            tag_hdr.Write(ref msout);

            //Write out a zero-attachment header
            AttachmentHeader attach_hdr = new AttachmentHeader();

            attach_hdr.Write(ref msout);

            if (m_OutputArchive != null)
            {
                m_OutputArchive.AddTagfileToArchive(HaloMap.IndexItemStringList[index], msout.GetBuffer(), (int)msout.Position);
            }

            msout.Close();
        }
コード例 #3
0
        private void ExtractH2Tag(int index)
        {
            //Load Shared Map streams
            FileStream fsShared             = OptionsManager.GetHalo2SharedStream();
            FileStream fsSinglePlayerShared = OptionsManager.GetHalo2SinglePlayerSharedStream();
            FileStream fsMainMenu           = OptionsManager.GetHalo2MainMenuStream();

            //Tag Header loader start
            string TagClass = GetTagClass(BitConverter.GetBytes(Halo2Map.IndexItem[index].TagType), 0);

            if (TagClass == "<fx>")
            {
                TagClass = "FXFX";
            }

            byte[] TagHeaderBuffer = new byte[64];
            OptionsManager.GetGuerillaHeader(m_MapVersion, TagClass, TagHeaderBuffer);

            string MagfilePathRoot = Application.StartupPath + @"\Tag Structures\Halo2\";
            string OutputPathRoot  = Application.StartupPath + @"\Games\Xbox\Halo2\";


            //Creating Directorys for extacted tag
            string[] Directorys = new string[256];
            string   DirSep     = @"\";

            Directorys = Halo2Map.StringTable.TagStrings[index].Split(DirSep.ToCharArray(), 256);
            uint   Dircount = (uint)Directorys.Length - 1;
            string NewDirectoryStructure = "";

            for (uint Count = 0; Count < Dircount; Count += 1)
            {
                if (Directory.Exists(OutputPathRoot + NewDirectoryStructure + Directorys[Count]) == false)
                {
                    Directory.CreateDirectory(OutputPathRoot + NewDirectoryStructure + Directorys[Count]);
                    NewDirectoryStructure += Directorys[Count] + @"\";
                }
                else
                {
                    NewDirectoryStructure += Directorys[Count] + @"\";
                }
            }

            //Loading Tag Long name from mag file
            string       ProcessTagFile = TagClass.Trim() + ".mag";
            StreamReader MagReader      = new StreamReader(MagfilePathRoot + ProcessTagFile);
            string       InLine         = MagReader.ReadLine();

            //Create the Tag on disk
            string SplitChar = ".";

            string[]     FixTagName = Halo2Map.StringTable.TagStrings[index].Split(SplitChar.ToCharArray(), 2);
            FileInfo     fiout      = new FileInfo(OptionsManager.GetExtractPath(m_MapVersion) + FixTagName[0] + "." + InLine.Trim());
            MemoryStream msout      = new MemoryStream();

            TagHeader.SeekToTagDataStart(ref msout);

            // Create a tag table for
            byte[] TagTable = new byte[TagCount * 16];
            fsin.Seek(Halo2Map.IndexHeader.OffsetToTags, System.IO.SeekOrigin.Begin);
            fsin.Read(TagTable, 0, TagTable.Length);

            // Move File pointer to start of tag
            fsin.Seek(Halo2Map.IndexItem[index].TagOffset, System.IO.SeekOrigin.Begin);

            // Create the Tab char to provent errors
            byte   TabByte    = 0x09;
            string TabReplace = "";

            TabReplace += (char)TabByte;

            // Read the Structure from the mag file
            string[] MagArray = new string[256];
            int      MagIndex = 0;

            do
            {
                InLine             = MagReader.ReadLine();
                MagArray[MagIndex] = InLine.Replace(TabReplace, "").ToLower().Trim();
                MagIndex           = MagIndex + 1;
            }while(MagReader.Peek() != -1);
            MagReader.Close();

            // Create debug stream writer
            //StreamWriter DebugFile;
            //DebugFile = new StreamWriter(msout.Name + ".txt" );

            // Start the Tags extraction
            Halo2Structure MainStruct = new Halo2Structure();

            //if(TagClass == "sbsp")
            MainStruct.StructureCS((uint)MagIndex, Halo2Map.IndexItem[index].TagOffsetMagic, Halo2Map.IndexItem[index].TagMagic, MagArray, 1, fsin, msout, fsShared, 0, 0, Halo2Map.StringTable.StringBuffer, Halo2Map.StringTable.OffsetsBuffer, fsSinglePlayerShared, fsMainMenu, fsShared, Halo2Map.MapHeader.MetaStart, Halo2Map.MapHeader.FileSize, null, TagTable, Halo2Map.MapHeader.ScriptStringArray);
            //DebugFile.Flush();
            //DebugFile.Close();
            //For Refernce only
            //public void StructureCS(uint MagIndex,uint OffsetMagic,uint MapMagic,string[] StructureArray,uint ChunkCount,FileStream MapFile,FileStream TagFile,FileStream BitmapFile,uint VerticesOffset,uint IndicesOffset,byte[] StringTable,byte[] StringTableOffsetList,FileStream single_player_shared_map,FileStream mainmenu_map,FileStream shared_map,uint StartOfTags,uint MapSize,StreamWriter DebugFile,byte[] TagTable,string[] ScriptStringArray)

            // Initialize and write out the PROM tag header
            TagHeader tag_hdr = new TagHeader();

            tag_hdr.TagClass0   = TagClass;
            tag_hdr.GameVersion = (MapfileVersion)m_MapVersion;
            tag_hdr.TagSize     = (int)msout.Position - TagHeader.PROM_HEADER_SIZE;
            tag_hdr.Write(ref msout);

            //Write out a zero-attachment header
            tag_hdr.SeekToAttachStart(ref msout);
            AttachmentHeader attach_hdr = new AttachmentHeader();

            attach_hdr.Write(ref msout);

            msout.Close();
            fsShared.Close();
            fsSinglePlayerShared.Close();
            fsMainMenu.Close();
        }