コード例 #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] + @"\";
                }
            }

            MTSFReader mr;

            mr = new MTSFReader();
            mr.MTSFRead("Core.Compiler.HALO_PC_SET.MTSF");
            TSFReader STSF = new TSFReader();

            STSF.TSF(ref mr, CompUtil.RevUInt(HaloMap.IndexItems[index].Type1));
            //string ExtName = STSF.Name;

            //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;

            Struct.StructInfo TagInfo = new Struct.StructInfo();
            TagInfo.MapMagic       = HaloMap.Map_Magic;
            TagInfo.MapVersion     = HaloMap.MapHeader.Map_Version;
            TagInfo.SoundsFile     = fsSound;
            TagInfo.BitmapsFile    = fsBitmap;
            TagInfo.IndexItems     = HaloMap.IndexItems;
            TagInfo.TagMagic       = HaloMap.IndexItems[index].MetaMagic;
            TagInfo.IndicesOffset  = HaloMap.IndexHeader.Index_Offset;
            TagInfo.VerticesOffset = HaloMap.IndexHeader.Verts_Offset;
            TagInfo.CurrentIndex   = (uint)index;
            TagInfo.TagHeaderSize  = 0x40;
            // Create a new struct processor
            Struct MainStruct = new Struct();

            string[] Tags = null;
            MainStruct.DoProcessStruct(ref STSF, ref fsin, ref msout, 1, STSF.GetUName(), ref TagInfo, ref Tags, ref Tags);
            //******FIX ME ******//  Structure2 MainStruct = new Structure2();
            //******FIX ME ******//  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   = HaloMap.IndexItems[index].Type1;
            tag_hdr.TagClass1   = HaloMap.IndexItems[index].Type2;
            tag_hdr.TagClass2   = HaloMap.IndexItems[index].Type3;
            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);

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


            msout.Close();
            fsBitmap.Close();
            fsSound.Close();
        }