Esempio n. 1
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 = CompUtil.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());
            string       FileName = 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   = Halo2Map.IndexItem[index].TagType;
            tag_hdr.GameVersion = 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);

            if (m_OutputArchive != null)
            {
                //m_OutputArchive.AddTagfileToArchive(HaloMap.IndexItemStringList[index], msout.GetBuffer(), (int)msout.Position);
                m_OutputArchive.AddFile(FileName, GetSubArray(msout.GetBuffer(), 0, (int)msout.Position - 12));
            }

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