private void LoadBipedPreview(TagFileName tfn)
        {
            TagBase tagdata = new TagBase();

            tagdata.LoadTagBuffer(tfn);
            BinaryReader br = new BinaryReader(tagdata.Stream);

            Biped obj = new Biped();

            obj.Read(br);
            obj.ReadChildData(br);
            LoadModelTag(new TagFileName(obj.ObjectValues.Model.Value, "mod2", tfn.Version));
            LoadAnimationTag(new TagFileName(obj.ObjectValues.AnimationGraph.Value, "antr", tfn.Version));
        }
        static public void LoadScenario(TagFileName tfn)
        {
            if (tfn.Version == MapfileVersion.XHALO2)
            {
            }
            else
            {
                m_ScenarioData = new TagBase();
                m_ScenarioData.LoadTagBuffer(tfn);
                BinaryReader br = new BinaryReader(m_ScenarioData.Stream);

                m_ScenarioTag = new Scenario();
                m_ScenarioTag.Read(br);
                m_ScenarioTag.ReadChildData(br);
                MapSpawnEditor.LoadHalo1Scenario(m_ScenarioTag, m_ScenarioData);
                Menus.UpdateMenuLists(m_ScenarioTag);
            }
        }
Beispiel #3
0
        private TagFileName GetDecalBitmap(TagFileName tfn)
        {
            TagFileName bitmap_name = null;

            if (tfn.Exists)
            {
                TagBase tagdata = new TagBase();
                tagdata.LoadTagBuffer(tfn);
                BinaryReader br = new BinaryReader(tagdata.Stream);

                Decal obj = new Decal();
                obj.Read(br);
                obj.ReadChildData(br);
                bitmap_name = new TagFileName(obj.DecalValues.Map.Value, "bitm", tfn.Version);
                //model_name = new TagFileName(obj.ObjectValues.Model.Value, "mod2", tfn.Version);
            }
            return(bitmap_name);
        }
        private void btnTestTagEditorGUI_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();

                // Load the XML Tag Definition
                //ofd.Filter = "Antenna Tag Definition|antenna.xml";
                ofd.Filter = "XML Tag Definition|*.xml";
                if (ofd.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }
                string      tdfFilename   = ofd.FileName;
                XmlDocument tagDefinition = new XmlDocument();
                tagDefinition.Load(tdfFilename);

                // Load the tag data
                string      tagDataFilename = @"vehicles\warthog\warthog antenna.antenna";
                TagFileName testTagFileName = new TagFileName(
                    tagDataFilename, MapfileVersion.HALOPC, TagSource.Archive);
                TagBase testTag = new TagBase();
                testTag.LoadTagBuffer(testTagFileName);
                BinaryReader br      = new BinaryReader(testTag.Stream);
                Antenna      antenna = new Antenna();
                antenna.Read(br);
                antenna.ReadChildData(br);

                Form test = new Form();
                test.Size = new Size(640, 480);
                TagEditorControl tagEditor = new TagEditorControl();
                tagEditor.Dock = DockStyle.Top;

                tagEditor.Create(tagDefinition, antenna);

                test.Controls.Add(tagEditor);
                test.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
        public DependencyBuilder(TagFileName tagFile)
        {
            // Load the proper tag definition.
            XmlDocument tagDefinition = TagDefinitionManager.GetTagDefinitionByName(tagFile.FileExtension);

            // Load the tag data
            TagBase tag = new TagBase();

            tag.LoadTagBuffer(tagFile);
            BinaryReader br = new BinaryReader(tag.Stream);

            // Create the appropriate type.
            XmlNode  nameNode      = tagDefinition.SelectSingleNode("//name");
            string   tagTypeString = "TagLibrary.Halo1." + nameNode.InnerText;
            Assembly a             = Assembly.GetAssembly(typeof(IField));
            IBlock   tagBlock      = (a.CreateInstance(tagTypeString) as IBlock);

            tagBlock.Read(br);
            tagBlock.ReadChildData(br);

            Dependencies = ProcessDependencies(tagBlock);
        }
        public void DoProcessMeta(ref TSFReader sr, MemoryStream FI, ref FileStream FO, ref FileStream VertsFile, ref FileStream IndFile, ref FileStream BSPFile, uint Count, string[] IndexStrings, StructInfo Info)
        {
            TabReplace += (char)TabByte;
            Name        = sr.GetUName();      //CMD[2];
            Size        = sr.GetSOC();

            TagBuff = new byte[Size * Count];
            FI.Read(TagBuff, 0, TagBuff.Length);
            //FixIntPosition(ref FO);
            long StructPosition = FO.Position;

            FO.Write(TagBuff, 0, TagBuff.Length);
            uint StartOfStruct = sr.Position;
            uint sc            = 0;

            bool ExitStruct = false;

            do
            {
                do
                {
                    //InLine = sr.Read();
                    //CMD = InLine.Replace(TabReplace,"").ToLower().Trim().Split(new char[]{' '},256);
                    sr.Read();
                    switch (sr.GetCMD())
                    {
                    case TSFReader.TSFStruct:                             // "struct":
                        uint ChildCount = GetUInt(TagBuff, (uint)(sr.GetOIP() + (sc * Size)));
                        if (ChildCount != 0)
                        {
                            PCMeta Child = new PCMeta();
                            PutUInt(ref TagBuff, (uint)(sr.GetOIP() + 4 + (sc * Size)), (uint)(FO.Position + Info.TagMagic));
                            Child.DoProcessMeta(ref sr, FI, ref FO, ref VertsFile, ref IndFile, ref BSPFile, ChildCount, IndexStrings, Info);
                            FixIntPosition(ref FO);
                        }
                        else
                        {
                            sr.SeekAheadTo(0xA7, sr.GetUName());

                            //sr.SeekAheadTo("end " + CMD[2]);
                            //sr.Seek(sr.Position + 1);
                        }
                        break;

                    case TSFReader.TSFBSPTagRef:                          // "bspstagref":
                    case TSFReader.TSFTagRef:                             // "tagref":
                        uint tStringSize = 0;
                        GetUInt(TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x08, ref tStringSize);
                        if (tStringSize != 0x00)
                        {
                            PutUInt(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x04, 0x00000000);
                            PutUInt(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x08, 0x00000000);
                            uint   TagClass       = GetUInt(TagBuff, (uint)(sr.GetOIP() + (sc * Size)));
                            string TagClassString = GetTagClassRev(BitConverter.GetBytes(TagClass), 0);
                            byte[] tmpStr         = new byte[tStringSize + 1];

                            FI.Read(tmpStr, 0, tmpStr.Length);
                            string tag = ReadString(tmpStr, 0);
                            int    t   = 0;
                            //string[] test;
                            bool con = false;
                            do
                            {
                                string[] test      = Info.Items[t].NameString.Split(new char[] { '.' }, 256);                               //IndexStrings[t].Split(new char[]{'.'},256);
                                string   testClass = GetTagClassRev(BitConverter.GetBytes(Info.Items[t].TagClass1), 0);
                                if (testClass == TagClassString && test[0] == tag)
                                {
                                    con = true;
                                }
                                else
                                {
                                    t += 1;
                                }
                            }while (con == false);                                    // testClass != TagClass);
                            PutUInt(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x04, Info.Items[t].StringOffset);
                            PutUShort(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x0C, (ushort)Info.Items[t].IndexID1);
                            PutUShort(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x0E, (ushort)Info.Items[t].IndexID2);
                            if (Name == 0x0468)
                            {
                                uint   SaveTagMagic = Info.TagMagic;
                                byte[] BspHeader    = new byte[0x18];
                                PutUInt(ref TagBuff, 0x00 + (sc * Size), (uint)(0x800 + BSPFile.Position));
                                uint CurrentPosition = (uint)BSPFile.Position;
                                Info.CurrentOffset = (uint)BSPFile.Position;

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

                                TSFReader tmpSTSF = new TSFReader();

                                //SwapInt(TagClasses,0);
                                tmpSTSF.TSF(ref mr, 0x70736273);                                        //   73627370);



                                //MAG tmpsr = new MAG(Info.StructurePath + "sbsp.mag");

                                //FileInfo BspMetaFile_info = new FileInfo(Info.TagsPath + tag + "." + tmpSTSF.Name);
                                //FileStream BspMetaFile;
                                //BspMetaFile = BspMetaFile_info.Open(FileMode.Open,FileAccess.Read);
                                //BspMetaFile.Seek(0x40,SeekOrigin.Begin);
                                TagFileName tfnTAG = new TagFileName(tag + "." + tmpSTSF.Name, MapfileVersion.HALOPC);
                                TagBase     tbTAG  = new TagBase();
                                tbTAG.LoadTagBuffer(tfnTAG);

                                string[] gh;
                                int      tt = -1;
                                do
                                {
                                    tt += 1;
                                }while((tag + "." + tmpSTSF.Name) != Info.Items[tt].NameString);
                                uint BSPFileSize = (0x800 - ((uint)(Info.Items[tt].MetaSize) % 0x800));
                                BSPFileSize += (uint)(Info.Items[tt].MetaSize);
                                uint tmpMagic = (uint)(0x41B40000 - BSPFileSize);
                                Info.TagMagic = tmpMagic;
                                PutUInt(ref TagBuff, 0x08 + (sc * Size), tmpMagic);
                                PutUInt(ref BspHeader, 0x00 + (sc * Size), 0x18 + tmpMagic);
                                PutUInt(ref BspHeader, 0x14 + (sc * Size), 0x73627370);
                                BSPFile.Write(BspHeader, 0, BspHeader.Length);
                                PCMeta BspMeta = new PCMeta();

                                BspMeta.DoProcessMeta(ref tmpSTSF, tbTAG.Stream, ref BSPFile, ref VertsFile, ref IndFile, ref BSPFile, 1, IndexStrings, Info);
                                FixIntPosition2K(ref BSPFile);
                                PutUInt(ref TagBuff, 0x04 + (sc * Size), (uint)(CurrentPosition + BSPFile.Position));
                                //BspMetaFile.Close();
                                tbTAG         = null;
                                Info.TagMagic = SaveTagMagic;
                                int a = 0;
                            }
                        }
                        break;

                    case TSFReader.TSFInternalRaw:                                          // "internalraw":
                        uint RawSize = GetUInt(TagBuff, (uint)(sr.GetOIP() + (sc * Size))); //Compile Mag.Map
                        if (RawSize == 0)
                        {
                            break;
                        }
                        uint RawOffset = GetUInt(TagBuff, (uint)(sr.GetOIP() + 0x0c + (sc * Size)));                                    //Tag Text
                        PutUInt(ref TagBuff, (uint)(sr.GetOIP()) + 0x0c + (sc * Size), ((uint)FO.Position + Info.TagMagic));
                        byte[] tmp = new byte[RawSize];
                        FI.Read(tmp, 0, tmp.Length);
                        FO.Write(tmp, 0, tmp.Length);
                        FixIntPosition(ref FO);
                        tmp = null;
                        break;

                    case TSFReader.TSFBitmapRaw:                             // "bitmapraw":
                        uint   TiffSize   = 0; GetUInt(TagBuff, 0x1C, ref TiffSize);
                        byte[] TiffBuffer = new byte[TiffSize];
                        FI.Read(TiffBuffer, 0, TiffBuffer.Length);
                        uint BitmapSize = GetUInt(TagBuff, 0x30);
                        TiffBuffer = new byte[BitmapSize];
                        FI.Read(TiffBuffer, 0, TiffBuffer.Length);
                        TiffBuffer = null;
                        break;

                    case TSFReader.TSFModelData:                             // "modeldata":
                        long   SaveMapFilePos     = (uint)FI.Position;
                        uint   TrueVerticesSize   = (GetUInt(TagBuff, (uint)(88 + (sc * Size)))) * 68;
                        uint   TrueIndicesSize    = (((GetUInt(TagBuff, (uint)(72 + (sc * Size)))) / 3) + 1) * 6;
                        uint   NewIndicesDataSize = (GetUInt(TagBuff, (uint)(72 + (sc * Size))) / 3) + 1;
                        byte[] RawModelBuffer     = new byte[TrueVerticesSize];
                        FI.Read(RawModelBuffer, 0, RawModelBuffer.Length);
                        PutUInt(ref TagBuff, (uint)(0x64 + (sc * Size)), (uint)VertsFile.Position);
                        PutUInt(ref TagBuff, (uint)(0x4C + (sc * Size)), (uint)IndFile.Position);
                        PutUInt(ref TagBuff, (uint)(0x50 + (sc * Size)), (uint)IndFile.Position);
                        VertsFile.Write(RawModelBuffer, 0, RawModelBuffer.Length);
                        RawModelBuffer = new byte[TrueIndicesSize];
                        FI.Read(RawModelBuffer, 0, RawModelBuffer.Length);
                        IndFile.Write(RawModelBuffer, 0, RawModelBuffer.Length);
                        byte[] TestBuffer = new byte[6];
                        FI.Read(TestBuffer, 0, 6);
                        if (TestBuffer[4] == 0xff)
                        {
                            IndFile.Write(TestBuffer, 0, TestBuffer.Length);
                        }
                        else
                        {
                            FI.Seek(FI.Position - 6, SeekOrigin.Begin);
                        }
                        FixIntPosition(ref IndFile);
                        break;

                    case TSFReader.TSFBSPModel:                             // "bspmodel":
                        uint UnCompressedVerts       = sr.GetOIP();
                        uint CompressedVerts         = sr.GetSOC();
                        uint UnCompressedVertsOffset = sr.GetOIP();
                        //uint VertsOffset = GetUInt(TagBuff,CompressedVerts);
                        uint TrueVertCount            = GetUInt(TagBuff, 180 + (sc * Size));
                        uint TrueLightMapDataCount    = GetUInt(TagBuff, 200 + (sc * Size));
                        uint UnCompressedLightMapData = (TrueLightMapDataCount * 20);
                        uint CompressedLightMapData   = (TrueLightMapDataCount * 8);
                        UnCompressedVerts = (TrueVertCount * 56);
                        CompressedVerts   = (TrueVertCount * 32);

                        byte[] BspVertsUnCompressed = new byte[UnCompressedVerts];
                        FI.Read(BspVertsUnCompressed, 0, BspVertsUnCompressed.Length);
                        PutUInt(ref TagBuff, 0xe4 + (sc * Size), (uint)(FO.Position + Info.TagMagic));
                        FO.Write(BspVertsUnCompressed, 0, BspVertsUnCompressed.Length);
                        //byte[] BspVertsCompressed = new byte[CompressedVerts];
                        byte[] BspLightMapDataUnCompressed = new byte[UnCompressedLightMapData];
                        FI.Read(BspLightMapDataUnCompressed, 0, BspLightMapDataUnCompressed.Length);
                        FO.Write(BspLightMapDataUnCompressed, 0, BspLightMapDataUnCompressed.Length);
                        //byte[] BspLightMapDataCompressed = new byte[CompressedLightMapData];

                        //viper told me to skip past compressed data as a quick fix to
                        // the crash problem - Grenadiac
                        FI.Seek(CompressedVerts, SeekOrigin.Current);        //gren added this
                        FI.Seek(CompressedLightMapData, SeekOrigin.Current); //gren added this
                        break;

                    case TSFReader.TSFResource:                             // "resources":
                        ushort rStringSize = GetUShort(TagBuff, 0x06 + (sc * Size));
                        if (rStringSize != 0x00)
                        {
                            uint   TagClassFlag   = GetUShort(TagBuff, 0x00 + (sc * Size));
                            string TagClassString = "";
                            switch (TagClassFlag)
                            {
                            case 0x00:
                                TagClassString = "bitm";
                                break;

                            case 0x01:
                                TagClassString = "snd!";
                                break;
                            }

                            //MAG tmpMR = new MAG(Info.StructurePath + TagClassString.Trim() + ".mag");
                            byte[] tmpStr = new byte[rStringSize + 1];



                            FI.Read(tmpStr, 0, tmpStr.Length);
                            string tag = ReadString(tmpStr, 0);
                            //tmpMR.Seek(0);
                            int t = 0;
                            //string[] test;
                            bool con = false;
                            do
                            {
                                string[] test      = Info.Items[t].GetString().Split(new char[] { '.' }, 256);                               //IndexStrings[t].Split(new char[]{'.'},256);
                                string   testClass = GetTagClassRev(BitConverter.GetBytes(Info.Items[t].TagClass1), 0);
                                if (testClass == TagClassString && test[0] == tag)
                                {
                                    con = true;
                                }
                                else
                                {
                                    t += 1;
                                }
                            }while (con == false);
                            PutUShort(ref TagBuff, (uint)(0x04 + (sc * Size)), (ushort)Info.Items[t].IndexID1);
                            PutUShort(ref TagBuff, (uint)(0x06 + (sc * Size)), (ushort)Info.Items[t].IndexID2);
                        }
                        break;

                    case TSFReader.TSFSoundData:                             // "sounddata":
                        uint   sRawSize   = GetUInt(TagBuff, (uint)(sr.GetOIP() + (sc * Size)));
                        uint   sRawOffset = GetUInt(TagBuff, (uint)(sr.GetUName() + (sc * Size)));
                        byte[] stmp       = new byte[sRawSize];
                        FI.Read(stmp, 0, stmp.Length);
                        stmp = null;
                        break;

                    case TSFReader.TSFEnd:                             // "end":
                        if (sr.GetOIP() == Name)
                        {
                            ExitStruct = true;
                        }
                        else
                        {
                            ExitStruct = false;
                        }
                        break;
                    }
                }while(ExitStruct == false);
                if (Count != 0)
                {
                    sc += 1;
                    if (sc != Count)
                    {
                        sr.Seek(StartOfStruct);
                        ExitStruct = false;
                    }
                }
            }while(sc != Count);
            long tmpPosSave = FO.Position;

            FO.Seek(StructPosition, SeekOrigin.Begin);
            FO.Write(TagBuff, 0, TagBuff.Length);
            FO.Seek(tmpPosSave, SeekOrigin.Begin);
        }
        public static void Build()
        {
            TagFileName scenario_tag = ProjectManager.ScenarioTagFileName;

            //IndexBuilder IndexBuild = new IndexBuilder();
            Compiler_Gren.DependencyBuilder IndexBuild = new Compiler_Gren.DependencyBuilder();
            //FileInfo TagFile_info = new FileInfo(scenario_tag.RelativePath);
            string BasFolder    = Application.StartupPath + @"\Extracted Tags\";
            string StructFolder = Application.StartupPath + @"\Tag Structures\PcHalo\";

            //string MapsFolder = Application.StartupPath + @"\Maps\";
            if (true)
            {
                //Create the index table
                //lbCurTag.Text = "Building Index Table....";
                Application.DoEvents();
                //string[] IndexList = IndexBuild.BuildIndex(scenario_tag.RelativePath, BasFolder, StructFolder);
                string[]         IndexList = IndexBuild.BuildIndex(scenario_tag);
                HaloPCMAP.HaloPC NewMap    = new HaloPCMAP.HaloPC();
                NewMap.PCIndexHeader.Create((uint)IndexList.Length);
                NewMap.PCIndexHeader.IndexMagic = 0x40440028;
                uint StringTableSize = 0;
                //Fixing index items
                ushort gt = 0xE174;
                //lbCurTag.Text = "Building Index Table Items....";
                Application.DoEvents();

                for (int sc = 0; sc < IndexList.Length; sc++)
                {
                    //FileInfo TagFile2_info = new FileInfo(BasFolder + IndexList[sc]);
                    //FileStream TagFile2;
                    //TagFile2 = TagFile2_info.Open(FileMode.Open,FileAccess.Read);
                    //byte[] tmp = new byte[0x40];
                    //TagFile2.Read(tmp,0x00,tmp.Length);
                    //TagFile2.Close();

                    TagFileName tfnTAG = new TagFileName(IndexList[sc], MapfileVersion.HALOPC);
                    TagBase     tbTAG  = new TagBase();
                    tbTAG.LoadTagBuffer(tfnTAG);

                    //uint TagClass1 = BitConverter.ToUInt32(tmp,0x24);
                    //uint TagClass2 = BitConverter.ToUInt32(tmp,0x28);
                    //uint TagClass3 = BitConverter.ToUInt32(tmp,0x2C);
                    NewMap.PCIndexHeader.IndexItems[sc].Create();
                    NewMap.PCIndexHeader.IndexItems[sc].TagClass1  = SwapUInt(tbTAG.Header.TagClass0); // TagClass1;
                    NewMap.PCIndexHeader.IndexItems[sc].TagClass2  = SwapUInt(tbTAG.Header.TagClass1); // TagClass2;
                    NewMap.PCIndexHeader.IndexItems[sc].TagClass3  = SwapUInt(tbTAG.Header.TagClass2); // TagClass3;
                    NewMap.PCIndexHeader.IndexItems[sc].IndexID1   = (ushort)sc;
                    NewMap.PCIndexHeader.IndexItems[sc].IndexID2   = gt;
                    NewMap.PCIndexHeader.IndexItems[sc].NameString = IndexList[sc];
                    if (tbTAG.Header.TagClass0 == 0x70736273 || tbTAG.Header.TagClass0 == 0x73627370)
                    {
                        NewMap.PCIndexHeader.IndexItems[sc].MetaSize = IndexBuild.BSPSizes[0];
                    }
                    else
                    {
                        NewMap.PCIndexHeader.IndexItems[sc].MetaSize = 0;
                    }
                    if (tbTAG.Header.TagClass0 == 0x7274656d || tbTAG.Header.TagClass0 == 0x6d657472)//  6d657472)
                    {
                        gt += 2;
                    }
                    else
                    {
                        gt += 1;
                    }
                    string[] RemoveExt = IndexList[sc].Split(new char[] { '.' }, 256);
                    NewMap.PCIndexHeader.IndexItems[sc].String = new byte[RemoveExt[0].Length + 1];
                    HaloPCMAP.StringToByteArray(ref NewMap.PCIndexHeader.IndexItems[sc].String, RemoveExt[0]);
                    StringTableSize += (uint)(IndexList[sc].Length + 1);
                    tbTAG            = null;
                }
                //Creating the temp files for map building
                FileInfo   VertsFile_info = new FileInfo(Application.StartupPath + "TempVerts.Map");
                FileStream VertsFile;
                VertsFile = VertsFile_info.Open(FileMode.Create, FileAccess.ReadWrite);

                FileInfo   IndicesFile_info = new FileInfo(Application.StartupPath + "TempIndices.Map");
                FileStream IndicesFile;
                IndicesFile = IndicesFile_info.Open(FileMode.Create, FileAccess.ReadWrite);

                FileInfo   MetaFile_info = new FileInfo(Application.StartupPath + "TempMeta.map");
                FileStream MetaFile;
                MetaFile = MetaFile_info.Open(FileMode.Create, FileAccess.ReadWrite);

                FileInfo   BSPFile_info = new FileInfo(Application.StartupPath + "TempBSP.map");
                FileStream BSPFile;
                BSPFile = BSPFile_info.Open(FileMode.Create, FileAccess.ReadWrite);

                //lbCurTag.Text = "Writeing Index Table....";
                Application.DoEvents();

                //writing the index table the temp files
                for (int sc = 0; sc < NewMap.PCIndexHeader.IndexItems.Length; sc++)
                {
                    NewMap.PCIndexHeader.IndexItems[sc].Write(ref MetaFile);
                }
                //Rewriting index items to temp file to fix string offsets.
                //lbCurTag.Text = "Rewriteing Index Table....";
                Application.DoEvents();

                for (int sc = 0; sc < NewMap.PCIndexHeader.IndexItems.Length; sc++)
                {
                    NewMap.PCIndexHeader.IndexItems[sc].StringOffset = (uint)MetaFile.Position + NewMap.PCIndexHeader.IndexMagic;
                    MetaFile.Write(NewMap.PCIndexHeader.IndexItems[sc].String, 0, NewMap.PCIndexHeader.IndexItems[sc].String.Length);
                }
                //save MetaFile position to return for meta writing.
                long TmpPosSave = MetaFile.Position;
                //lbCurTag.Text = "Writing Index Table with Srtring Offsets....";
                Application.DoEvents();

                for (int sc = 0; sc < NewMap.PCIndexHeader.IndexItems.Length; sc++)
                {
                    MetaFile.Seek(NewMap.PCIndexHeader.IndexItems[sc].Position, SeekOrigin.Begin);
                    NewMap.PCIndexHeader.IndexItems[sc].Write(ref MetaFile);
                }
                //restore position for meta writing
                MetaFile.Seek(TmpPosSave, SeekOrigin.Begin);

                //Add info to the Meta info struct
                PCMeta.StructInfo Info = new PCMeta.StructInfo();
                Info.MapMagic      = NewMap.PCIndexHeader.IndexMagic;
                Info.TagMagic      = NewMap.PCIndexHeader.IndexMagic;
                Info.StructurePath = StructFolder;
                Info.TagsPath      = BasFolder;
                Info.Items         = NewMap.PCIndexHeader.IndexItems;
                //Starts processing meta and writing it to the meta file
                //lbCurTag.Text = "Adding Tags to map....";
                Application.DoEvents();

                for (int sc = 0; sc < NewMap.PCIndexHeader.IndexItems.Length; sc++)
                {
                    if (NewMap.PCIndexHeader.IndexItems[sc].TagClass1 != 0x70736273) //   70736273)
                    {
                        PCMeta Meta = new PCMeta();
                        //FileInfo Tag_info = new FileInfo(BasFolder + IndexList[sc]);
                        //FileStream Tag;
                        //Tag = Tag_info.Open(FileMode.Open,FileAccess.Read);
                        //byte[] head = new byte[0x40];
                        //Tag.Read(head,0,head.Length);
                        TagFileName tfnTAG = new TagFileName(IndexList[sc], MapfileVersion.HALOPC);
                        TagBase     tbTAG  = new TagBase();
                        tbTAG.LoadTagBuffer(tfnTAG);

                        //string Class = Meta.GetTagClass(head,0x24);
                        //MAG sr = new MAG(StructFolder + Class.Trim() + ".mag");
                        //sr.Seek(1);
                        MTSFReader mr = new MTSFReader();
                        mr.MTSFRead("Core.Compiler.HALO_PC_SET.MTSF");

                        TSFReader STSF = new TSFReader();

                        //SwapInt(TagClasses,0);
                        STSF.TSF(ref mr, tbTAG.Header.TagClass0);



                        HaloPCMAP.FixIntPosition(ref MetaFile);
                        Info.CurrentOffset = (uint)MetaFile.Position;
                        NewMap.PCIndexHeader.IndexItems[sc].MetaOffset = (uint)(MetaFile.Position + NewMap.PCIndexHeader.IndexMagic);

                        Meta.DoProcessMeta(ref STSF, tbTAG.Stream, ref MetaFile, ref VertsFile, ref IndicesFile, ref BSPFile, 1, IndexList, Info);

                        tbTAG = null;
                        //Tag.Flush();
                        //Tag.Close();
                    }
                }
                //Create a new map header
                //lbCurTag.Text = "Creating New Map....";
                Application.DoEvents();

                NewMap.PCHeader.Create();
                string[] tmpName = scenario_tag.RelativePath.Split(new char[] { '\\' }, 256);
                tmpName = tmpName[tmpName.Length - 1].Split(new char[] { '.' }, 256);
                NewMap.PCHeader.MapName = tmpName[0];//otf.FileName.Split(new char[]{'/'},256   //"Cool";
                //NewMap.PCHeader.Write(ref HeadFile);
                //Rewrite indextable of meta offsets
                //lbCurTag.Text = "Fixing Meta Offsets in Index Table....";
                Application.DoEvents();

                TmpPosSave = MetaFile.Position;
                for (int sc = 0; sc < NewMap.PCIndexHeader.IndexItems.Length; sc++)
                {
                    MetaFile.Seek(NewMap.PCIndexHeader.IndexItems[sc].Position, SeekOrigin.Begin);
                    NewMap.PCIndexHeader.IndexItems[sc].Write(ref MetaFile);
                }
                MetaFile.Seek(TmpPosSave, SeekOrigin.Begin);

                //Create the new map file to begin construction of the new map.
                FileInfo   Map_info = new FileInfo(Application.StartupPath + NewMap.PCHeader.MapName + ".Map");
                FileStream Map;
                Map = Map_info.Open(FileMode.Create, FileAccess.ReadWrite);

                //lbCurTag.Text = "Copying Data to new map file....";
                Application.DoEvents();

                //Write the header to the new map file
                NewMap.PCHeader.Write(ref Map);
                //Flush the tmp BSPFile to get FileSize.
                BSPFile.Flush();
                uint BSPFileSize = (uint)BSPFile.Length;
                //Seek to the begining of the tmp bsp file
                BSPFile.Seek(0, SeekOrigin.Begin);
                //Copy the Tmp bsp file to the new map file
                for (int bc = 0; bc < BSPFileSize; bc += 4)
                {
                    byte[] copy = new byte[4];
                    BSPFile.Read(copy, 0, copy.Length);
                    Map.Write(copy, 0, copy.Length);
                }
                //Flush the Temp verts file to get File size;
                VertsFile.Flush();
                uint VertsFileSize = (uint)VertsFile.Length;
                //Put Current Map Position in the indexheader, this sets the position of the verts in the map.
                NewMap.PCIndexHeader.VertsOffset = (uint)Map.Position;
                //seek to begining of the Verts file for coping to the new map file
                VertsFile.Seek(0, SeekOrigin.Begin);
                //Copy the verts to the map file
                for (int bc = 0; bc < VertsFileSize; bc += 4)
                {
                    byte[] copy = new byte[4];
                    VertsFile.Read(copy, 0, copy.Length);
                    Map.Write(copy, 0, copy.Length);
                }
                //Flush Indeices file to get size
                IndicesFile.Flush();
                uint IndicesFileSize = (uint)IndicesFile.Length;
                //Put the Scnr index ID in the IndexHeader, you can move the scnr any were as long as you set this to the currect ID.
                NewMap.PCIndexHeader.ScnrID = (uint)((NewMap.PCIndexHeader.IndexItems[0].IndexID2 << 16) + NewMap.PCIndexHeader.IndexItems[0].IndexID1);
                //ajust the IndicesOffset with verts offset and map position
                NewMap.PCIndexHeader.IndicesOffset = (uint)Map.Position - NewMap.PCIndexHeader.VertsOffset;
                NewMap.PCIndexHeader.ModelAreaSize = VertsFileSize + IndicesFileSize;
                //Seek to begining of IndicesFile for coping
                IndicesFile.Seek(0, SeekOrigin.Begin);
                //Copy Indices to new map file
                for (int bc = 0; bc < IndicesFileSize; bc += 4)
                {
                    byte[] copy = new byte[4];
                    IndicesFile.Read(copy, 0, copy.Length);
                    Map.Write(copy, 0, copy.Length);
                }
                //put the Current map position in the header so we know where the index header will be
                NewMap.PCHeader.IndexOffset = (uint)Map.Position;
                //Now we write the Index header to the map.
                NewMap.PCIndexHeader.Write(ref Map);

                //Flush the temp meta file so we can get the size.
                MetaFile.Flush();
                uint MetaFileSize = (uint)MetaFile.Length;
                //seek to the begining of the temp meta file for coping to the new map file
                MetaFile.Seek(0, SeekOrigin.Begin);
                //Copy the meta file to the new map file.
                for (int bc = 0; bc < MetaFileSize; bc += 4)
                {
                    byte[] copy = new byte[4];
                    MetaFile.Read(copy, 0, copy.Length);
                    Map.Write(copy, 0, copy.Length);
                }
                //Now we fix the map version map size and rewrite it to the map.
                Map.Flush();
                NewMap.PCHeader.MapVersion = 0x07;
                NewMap.PCHeader.MapSize    = (uint)Map.Length;
                NewMap.PCHeader.MetaSize   = MetaFileSize + 0x28;
                Map.Seek(NewMap.PCHeader.Position, SeekOrigin.Begin);
                NewMap.PCHeader.Write(ref Map);


                //Now close the files and delete the temp files.
                VertsFile.Close();
                IndicesFile.Close();
                MetaFile.Flush();
                MetaFile.Close();
                BSPFile.Close();
                Map.Close();
                //FileStream TagFile;
                //TagFile = Tag
            }
        }
Beispiel #8
0
        //public void LoadTagData( shader_mgr)

        public void LoadTagData(string FileName)
        {
            int          i;
            BinaryReader br = new BinaryReader(m_stream);

            // Load the Header
            string[] SFileName = FileName.Split(new char[] { '.' }, 256);
            string   DirSep    = @"\";

            string[] NFileName = SFileName[0].Split(DirSep.ToCharArray(), 256);
            string   NewDir    = "";

            for (int dn = 1; dn < NFileName.Length - 1; dn++)
            {
                NewDir += @"\" + NFileName[dn];
            }
            NewDir += @"\" + NFileName[NFileName.Length - 2];
            string LtmpTag = NewDir + "_" + NFileName[NFileName.Length - 1] + "_lightmap.ltmp";
            //string LtmpTag = SFileName[0] + "_" + NFileName[NFileName.Length - 1] + "_lightmap.ltmp";
            string LightMapTag = NewDir + "_" + NFileName[NFileName.Length - 1] + "_lightmap_bitmaps.bitmap";
            //string LightMapTag = SFileName[0] + "_" + NFileName[NFileName.Length - 1] + "_lightmap_bitmaps.bitmap";

            TagFileName tfnLTMP     = new TagFileName(LtmpTag, MapfileVersion.XHALO2);
            TagFileName tfnLightMap = new TagFileName(LightMapTag, MapfileVersion.XHALO2);

            H2BitmTag.H2Bitmap bmp = new H2BitmTag.H2Bitmap();
            bmp.LoadTagBuffer(tfnLightMap);
            bmp.LoadTagData();

            if (tfnLTMP.Exists)
            {
                TagBase tbLTMP = new TagBase();
                tbLTMP.LoadTagBuffer(tfnLTMP);

                //fsin = fiin.Open(FileMode.Open,FileAccess.Read);
                //fsin.Seek(0x40,System.IO.SeekOrigin.Begin);
                byte[] ltmpheader = new byte[0x104];
                tbLTMP.Stream.Read(ltmpheader, 0, ltmpheader.Length);
                uint ltmpsub1Offset = BitConverter.ToUInt32(ltmpheader, 0x84);
                tbLTMP.Stream.Seek((long)ltmpsub1Offset, System.IO.SeekOrigin.Begin);
                byte[] ltmpsub1 = new byte[0xA4];
                tbLTMP.Stream.Read(ltmpsub1, 0, ltmpsub1.Length);
                uint ColorMapCount  = BitConverter.ToUInt32(ltmpsub1, 0x08);
                uint ColorMapOffset = BitConverter.ToUInt32(ltmpsub1, 0x0C);
                tbLTMP.Stream.Seek((long)ColorMapOffset, System.IO.SeekOrigin.Begin);
                uint   ColorMapSize = ColorMapCount * 0x400;
                byte[] ColorMaps    = new byte[ColorMapSize];
                tbLTMP.Stream.Read(ColorMaps, 0, ColorMaps.Length);
                uint bspLightMapCount   = BitConverter.ToUInt32(ltmpsub1, 0x28);
                uint bspLightMapOffset  = BitConverter.ToUInt32(ltmpsub1, 0x2C);
                uint ScenLightMapCount  = BitConverter.ToUInt32(ltmpsub1, 0x48);
                uint ScenLightMapOffset = BitConverter.ToUInt32(ltmpsub1, 0x4C);
                SbspLightMapIndex1 = new ushort[bspLightMapCount];
                ScenLightMapIndex1 = new ushort[ScenLightMapCount];
                SbspLightMapIndex2 = new ushort[bspLightMapCount];
                ScenLightMapIndex2 = new ushort[ScenLightMapCount];

                byte[] tmpin = new byte[0x04];
                tbLTMP.Stream.Seek(bspLightMapOffset, System.IO.SeekOrigin.Begin);
                for (int r = 0; r < bspLightMapCount; r++)
                {
                    tbLTMP.Stream.Read(tmpin, 0, tmpin.Length);
                    SbspLightMapIndex1[r] = BitConverter.ToUInt16(tmpin, 0);
                    SbspLightMapIndex2[r] = BitConverter.ToUInt16(tmpin, 2);
                }
                tbLTMP.Stream.Seek(ScenLightMapOffset, System.IO.SeekOrigin.Begin);
                for (int r = 0; r < ScenLightMapCount; r++)
                {
                    tbLTMP.Stream.Read(tmpin, 0, tmpin.Length);
                    ScenLightMapIndex1[r] = BitConverter.ToUInt16(tmpin, 0);
                    ScenLightMapIndex2[r] = BitConverter.ToUInt16(tmpin, 2);
                }
                m_ColorMapIndex = MdxRender.SM.m_TextureManager.RegisterTexture3("ColorMap", ref ColorMaps, ref SbspLightMapIndex1, ref SbspLightMapIndex2, ref bmp);
                m_ScMapIndex    = MdxRender.SM.m_TextureManager.RegisterTexture3("SColorMap", ref ColorMaps, ref ScenLightMapIndex1, ref ScenLightMapIndex2, ref bmp);
                tbLTMP          = null;
                tfnLTMP         = null;
            }

            b_Header.Load(ref br);
            //string LtmpName = br.BaseStream.
            m_LightmapIndex        = MdxRender.SM.LoadLightmaps2(LightMapTag);
            br.BaseStream.Position = b_Header.Geometry.Offset;
            //Load the Lightmap Sections
            b_Lightmaps = new H2_BSP_LIGHTMAPS[b_Header.Geometry.Count];
            for (i = 0; i < b_Header.Geometry.Count; i++)
            {
                b_Lightmaps[i] = new H2_BSP_LIGHTMAPS();
                b_Lightmaps[i].Load(ref br);
            }
            //Save File pos
            long RawDataOffset = br.BaseStream.Position;

            //Move File pointer ahead for somthing
            for (i = 0; i < b_Header.Geometry.Count; i++)
            {
                br.BaseStream.Position += b_Lightmaps[i].ModelResourceBlockSize;
            }

            for (i = 0; i < b_Header.Geometry.Count; i++)
            {
                b_Lightmaps[i].LoadRawDescriptors(ref br);
            }

            br.BaseStream.Position = RawDataOffset;

            for (i = 0; i < b_Header.Geometry.Count; i++)
            {
                b_Lightmaps[i].LoadRawData(ref br);
            }

            this.b_BSPLoaded = true;

            //br.BaseStream.Position = b_Header.Shaders.Offset;
            br.BaseStream.Seek(b_Header.Shaders.Offset, SeekOrigin.Begin);
            m_Shaders = new H2_BSP_SHADER[b_Header.Shaders.Count];
            for (i = 0; i < b_Header.Shaders.Count; i++)
            {
                br.BaseStream.Position += 8;
                m_Shaders[i]            = new H2_BSP_SHADER();
                m_Shaders[i].TagRef.Load(ref br);
                br.BaseStream.Position += 16;
            }

            for (i = 0; i < b_Header.Shaders.Count; i++)
            {
                m_Shaders[i].TagRef.ReadString(ref br);
                m_Shaders[i].ShaderManagerIndex = MdxRender.SM.RegisterShader(new TagFileName(m_Shaders[i].TagRef.data, "dahs", m_PromHeader.GameVersion));
            }

            for (i = 0; i < b_Header.Geometry.Count; i++)
            {
                for (int j = 0; j < b_Lightmaps[i].ResourceHeader.InfoChunkCount; j++)
                {
                    b_Lightmaps[i].ResourceInfo[j].ShaderIndex = (ushort)
                                                                 m_Shaders[b_Lightmaps[i].ResourceInfo[j].ShaderIndex].ShaderManagerIndex;
                }
            }


            br.BaseStream.Position = b_Header.Scenery.Offset;
            b_Scenery = new H2_BSP_SCENERY[b_Header.Scenery.Count];
            for (i = 0; i < b_Header.Scenery.Count; i++)
            {
                if (i == 21)
                {
                    int BreakPoint = 0;
                }
                b_Scenery[i] = new H2_BSP_SCENERY();
                b_Scenery[i].Load(ref br);
            }
            RawDataOffset = br.BaseStream.Position;
            //Move File pointer
            for (i = 0; i < b_Header.Geometry.Count; i++)
            {
                br.BaseStream.Position += b_Lightmaps[i].ModelResourceBlockSize;
            }

            for (i = 0; i < b_Header.Scenery.Count; i++)
            {
                b_Scenery[i].LoadRawDescriptors(ref br);
            }
            br.BaseStream.Position = RawDataOffset;

            for (i = 0; i < b_Header.Scenery.Count; i++)
            {
                b_Scenery[i].LoadRawData(ref br);
            }

            for (i = 0; i < b_Header.Scenery.Count; i++)
            {
                for (int j = 0; j < b_Scenery[i].ResourceHeader.InfoChunkCount; j++)
                {
                    b_Scenery[i].ResourceInfo[j].ShaderIndex = (ushort)
                                                               m_Shaders[b_Scenery[i].ResourceInfo[j].ShaderIndex].ShaderManagerIndex;
                }
            }
            b_SceneryPos           = new H2_BSP_SCENERY_POS[b_Header.SceneryPos.Count];
            br.BaseStream.Position = b_Header.SceneryPos.Offset;
            for (int h = 0; h < b_Header.SceneryPos.Count; h++)
            {
                b_SceneryPos[h] = new H2_BSP_SCENERY_POS();
                b_SceneryPos[h].Load(ref br);
            }
        }
Beispiel #9
0
        public void DoProcessMeta(ref TSFReader sr, MemoryStream FI, ref FileStream FO, ref FileStream BSPFile, uint Count, string[] IndexStrings, StructInfo Info, ref XBoxHaloMap.sXBoxHalo XBoxMap, ref IndexBuilder IndexBuild)
        {
            TabReplace += (char)TabByte;
            Name        = sr.GetUName();
            Size        = sr.GetSOC();

            TagBuff = new byte[Size * Count];
            FI.Read(TagBuff, 0, TagBuff.Length);
            long StructPosition = FO.Position;

            FO.Write(TagBuff, 0, TagBuff.Length);
            uint StartOfStruct = sr.Position;
            uint sc            = 0;

            bool ExitStruct = false;

            do
            {
                do
                {
                    sr.Read();
                    switch (sr.GetCMD())
                    {
                    case TSFReader.TSFStruct:                             // "struct":
                        #region Structure
                        uint ChildCount = CompUtil.GetUInt(TagBuff, (uint)(sr.GetOIP() + (sc * Size)));
                        if (ChildCount != 0)
                        {
                            XBoxMeta Child = new XBoxMeta();
                            CompUtil.PutUInt(ref TagBuff, (uint)(sr.GetOIP() + 4 + (sc * Size)), (uint)(FO.Position + Info.TagMagic));
                            Child.DoProcessMeta(ref sr, FI, ref FO, ref BSPFile, ChildCount, IndexStrings, Info, ref XBoxMap, ref IndexBuild);
                            CompUtil.FixIntPosition(ref FO);
                        }
                        else
                        {
                            sr.SeekAheadTo(0xA7, sr.GetUName());

                            //sr.SeekAheadTo("end " + CMD[2]);
                            //sr.Seek(sr.Position + 1);
                        }
                        break;

                        #endregion
                    case TSFReader.TSFBSPTagRef:                          // "bspstagref":
                    case TSFReader.TSFTagRef:                             // "tagref":
                        #region TagRefernce
                        uint tStringSize = 0;
                        CompUtil.GetUInt(TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x08, ref tStringSize);
                        if (tStringSize != 0x00)
                        {
                            CompUtil.PutUInt(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x04, 0x00000000);
                            CompUtil.PutUInt(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x08, 0x00000000);
                            uint   TagClass       = CompUtil.GetUInt(TagBuff, (uint)(sr.GetOIP() + (sc * Size)));
                            string TagClassString = CompUtil.GetTagClassRev(BitConverter.GetBytes(TagClass), 0);
                            byte[] tmpStr         = new byte[tStringSize + 1];

                            FI.Read(tmpStr, 0, tmpStr.Length);
                            string tag = CompUtil.ReadString(tmpStr, 0);
                            int    t   = 0;
                            //string[] test;
                            bool con = false;
                            do
                            {
                                string[] test      = Info.Items[t].NameString.Split(new char[] { '.' }, 256);                               //IndexStrings[t].Split(new char[]{'.'},256);
                                string   testClass = CompUtil.GetTagClassRev(BitConverter.GetBytes(Info.Items[t].TagClass1), 0);
                                if (testClass == TagClassString && test[0] == tag)
                                {
                                    con = true;
                                }
                                else
                                {
                                    t += 1;
                                }
                            }while (con == false);                                    // testClass != TagClass);
                            CompUtil.SwapInt(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x00);
                            CompUtil.PutUInt(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x04, Info.Items[t].StringOffset);
                            CompUtil.PutUShort(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x0C, (ushort)Info.Items[t].IndexID1);
                            CompUtil.PutUShort(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x0E, (ushort)Info.Items[t].IndexID2);
                            if (Name == 0x0468)
                            {
                                uint   SaveTagMagic = Info.TagMagic;
                                byte[] BspHeader    = new byte[0x18];
                                CompUtil.PutUInt(ref TagBuff, 0x00 + (sc * Size), (uint)(0x800 + BSPFile.Position));
                                uint CurrentPosition = (uint)BSPFile.Position;
                                Info.CurrentOffset = (uint)BSPFile.Position;

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

                                TSFReader tmpSTSF = new TSFReader();

                                //SwapInt(TagClasses,0);
                                tmpSTSF.TSF(ref mr, 0x70736273);                                        //   73627370);



                                //MAG tmpsr = new MAG(Info.StructurePath + "sbsp.mag");

                                //FileInfo BspMetaFile_info = new FileInfo(Info.TagsPath + tag + "." + tmpSTSF.Name);
                                //FileStream BspMetaFile;
                                //BspMetaFile = BspMetaFile_info.Open(FileMode.Open,FileAccess.Read);
                                //BspMetaFile.Seek(0x40,SeekOrigin.Begin);
                                Trace.WriteLine(tag + ".sbsp" + "   Hello I'm your bsp");
                                TagFileName tfnTAG = new TagFileName(tag + "." + tmpSTSF.Name, MapfileVersion.XHALO1);
                                TagBase     tbTAG  = new TagBase();
                                tbTAG.LoadTagBuffer(tfnTAG);

                                string[] gh;
                                int      tt = -1;
                                do
                                {
                                    tt += 1;
                                }while((tag + "." + tmpSTSF.Name) != Info.Items[tt].NameString);
                                uint BSPFileSize = (0x800 - ((uint)(Info.Items[tt].MetaSize) % 0x800));
                                BSPFileSize += (uint)(Info.Items[tt].MetaSize);
                                uint tmpMagic = (uint)(0x819a5800 - BSPFileSize);
                                Info.TagMagic = tmpMagic;
                                CompUtil.PutUInt(ref TagBuff, 0x08 + (sc * Size), tmpMagic);
                                //IndexBuild.XBoxMapData.XBSPVerts.Finish();
                                uint CompoundSize = (uint)IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets.Length + (uint)IndexBuild.XBoxMapData.XBSPVerts.LIndirectOffsets.Length + (uint)IndexBuild.XBoxMapData.XBSPVerts.ModelData.Length;
                                CompUtil.PutUInt(ref BspHeader, 0x00 + (sc * Size), 0x18 + CompoundSize + tmpMagic);
                                CompUtil.PutUInt(ref BspHeader, 0x04 + (sc * Size), IndexBuild.XBoxMapData.XBSPVerts.DataCount);
                                CompUtil.PutUInt(ref BspHeader, 0x08 + (sc * Size), 0x18 + tmpMagic);
                                CompUtil.PutUInt(ref BspHeader, 0x0C + (sc * Size), IndexBuild.XBoxMapData.XBSPVerts.DataCount);
                                CompUtil.PutUInt(ref BspHeader, 0x10 + (sc * Size), (uint)((IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets.Length + 0x18) + tmpMagic));
                                CompUtil.PutUInt(ref BspHeader, 0x14 + (sc * Size), 0x73627370);
                                long BSPHeaderPos = BSPFile.Position;
                                BSPFile.Write(BspHeader, 0, BspHeader.Length);

                                //IndexBuild.XBoxMapData.XBSPVerts.FixOffsets((uint)BSPFile.Position + (uint)IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets.Length + (uint)IndexBuild.XBoxMapData.XBSPVerts.LIndirectOffsets.Length,Info.TagMagic);
                                long savepos = BSPFile.Position;
                                BSPFile.Write(IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets, 0, IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets.Length);
                                BSPFile.Write(IndexBuild.XBoxMapData.XBSPVerts.LIndirectOffsets, 0, IndexBuild.XBoxMapData.XBSPVerts.LIndirectOffsets.Length);
                                CompUtil.Fix0x20Position(ref BSPFile);

                                IndexBuild.XBoxMapData.XBSPVerts.FixOffsets((uint)BSPFile.Position, Info.TagMagic);
                                BSPFile.Seek(savepos, SeekOrigin.Begin);
                                IndexBuild.XBoxMapData.XBSPVerts.VLMapOffset = (uint)BSPFile.Position + (uint)IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets.Length;
                                BSPFile.Write(IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets, 0, IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets.Length);
                                IndexBuild.XBoxMapData.XBSPVerts.ILMapOffset = (uint)BSPFile.Position + (uint)IndexBuild.XBoxMapData.XBSPVerts.LIndirectOffsets.Length;
                                BSPFile.Write(IndexBuild.XBoxMapData.XBSPVerts.LIndirectOffsets, 0, IndexBuild.XBoxMapData.XBSPVerts.LIndirectOffsets.Length);
                                CompUtil.Fix0x20Position(ref BSPFile);

                                BSPFile.Write(IndexBuild.XBoxMapData.XBSPVerts.ModelData, 0, IndexBuild.XBoxMapData.XBSPVerts.ModelData.Length);

                                long BSPSavPos = BSPFile.Position;
                                CompUtil.PutUInt(ref BspHeader, 0x00, (uint)(BSPFile.Position + tmpMagic));
                                BSPFile.Seek(BSPHeaderPos, SeekOrigin.Begin);
                                BSPFile.Write(BspHeader, 0, BspHeader.Length);
                                BSPFile.Seek(BSPSavPos, SeekOrigin.Begin);

                                XBoxMeta BspMeta = new XBoxMeta();

                                BspMeta.DoProcessMeta(ref tmpSTSF, tbTAG.Stream, ref BSPFile, ref BSPFile, 1, IndexStrings, Info, ref XBoxMap, ref IndexBuild);
                                CompUtil.FixIntPosition2K(ref BSPFile);

                                CompUtil.PutUInt(ref TagBuff, 0x04 + (sc * Size), (uint)(CurrentPosition + BSPFile.Position));
                                //BspMetaFile.Close();
                                tbTAG         = null;
                                Info.TagMagic = SaveTagMagic;
                                int a = 0;
                            }
                        }
                        break;

                        #endregion
                    case TSFReader.TSFInternalRaw:                                                   // "internalraw":
                        #region InternalRaw
                        uint RawSize = CompUtil.GetUInt(TagBuff, (uint)(sr.GetOIP() + (sc * Size))); //Compile Mag.Map
                        if (RawSize == 0)
                        {
                            break;
                        }
                        uint RawOffset = CompUtil.GetUInt(TagBuff, (uint)(sr.GetOIP() + 0x0c + (sc * Size)));                                    //Tag Text
                        CompUtil.PutUInt(ref TagBuff, (uint)(sr.GetOIP()) + 0x0c + (sc * Size), ((uint)FO.Position + Info.TagMagic));
                        byte[] tmp = new byte[RawSize];
                        FI.Read(tmp, 0, tmp.Length);
                        FO.Write(tmp, 0, tmp.Length);
                        CompUtil.FixIntPosition(ref FO);
                        tmp = null;
                        break;

                        #endregion
                    case TSFReader.TSFBitmapRaw:                             // "bitmapraw":
                        #region BitmapRaw
                        MemoryStream BMD;
                        uint         TiffSize   = 0; CompUtil.GetUInt(TagBuff, 0x1C, ref TiffSize);
                        byte[]       TiffBuffer = new byte[TiffSize];
                        FI.Read(TiffBuffer, 0, TiffBuffer.Length);
                        uint BitmapSize = CompUtil.GetUInt(TagBuff, 0x30);
                        TiffBuffer = new byte[BitmapSize];
                        FI.Read(TiffBuffer, 0, TiffBuffer.Length);
                        BMD = new MemoryStream(TiffBuffer);

                        uint   BitMapStructCount  = CompUtil.GetUInt(TagBuff, 0x60);
                        uint   BitMapStructOffset = CompUtil.GetUInt(TagBuff, 0x64);
                        byte[] tmpBMS             = new byte[BitMapStructCount * 0x30];
                        long   sv = FI.Position;
                        FI.Seek((long)BitMapStructOffset, SeekOrigin.Begin);
                        FI.Read(tmpBMS, 0, tmpBMS.Length);

                        for (int i = 0; i < BitMapStructCount; i++)
                        {
                            uint BitMapDataSize = CompUtil.GetUInt(tmpBMS, (uint)(0x1C + (i * 0x30)));
                            uint svBmPos        = (uint)BSPFile.Position + 0x800;
                            CompUtil.PutUInt(ref tmpBMS, (uint)(0x18 + (i * 0x30)), (uint)svBmPos);
                            byte[] tmpBuff = new byte[BitMapDataSize];
                            BMD.Read(tmpBuff, 0, tmpBuff.Length);
                            BSPFile.Write(tmpBuff, 0, tmpBuff.Length);
                            CompUtil.Fix0x100Position(ref BSPFile);
                            svBmPos += BitMapDataSize;
                        }
                        FI.Seek((long)BitMapStructOffset, SeekOrigin.Begin);
                        FI.Write(tmpBMS, 0, tmpBMS.Length);
                        FI.Seek(sv, SeekOrigin.Begin);
                        //BSPFile.Write(TiffBuffer,0,TiffBuffer.Length);
                        //Fix0x100Position(ref BSPFile);
                        TiffBuffer = null;
                        break;

                        #endregion
                    case TSFReader.TSFRawXModelData:                             // "XBoxModelData":
                        #region XModelData
                        uint   XTrueVerticesSize   = (CompUtil.GetUInt(TagBuff, 88 + (sc * Size))) * 32;
                        uint   XTrueIndicesSize    = (((CompUtil.GetUInt(TagBuff, 72 + (sc * Size))) / 3) + 1) * 6;
                        uint   XNewIndicesDataSize = (CompUtil.GetUInt(TagBuff, 72 + (sc * Size)) / 3) + 1;
                        uint   XTrueVerticesOffset = CompUtil.GetUInt(TagBuff, 100 + (sc * Size)) - Info.MapMagic;
                        uint   XSaveMapFilePos     = (uint)FI.Position;                          //MapFile.Position;
                        byte[] XModelHeader        = new byte[16];

                        //uint XTrueVerticesOffset = GetUInt(TagBuff,100 + (sc * Size)) - Info.MapMagic;
                        CompUtil.PutUInt(ref TagBuff, 100 + (sc * Size), XBoxMap.IndirectVerts + Info.MapMagic);
                        //uint XTrueIndicesOffset = GetUInt(TagBuff, 80+ (sc * Size)) - Info.MapMagic;
                        CompUtil.PutUInt(ref TagBuff, 80 + (sc * Size), XBoxMap.IndirectIndices + Info.MapMagic);
                        XBoxMap.IndirectVerts   += 0x0c;
                        XBoxMap.IndirectIndices += 0x0c;
                        CompUtil.PutUInt(ref TagBuff, 0x4c + (sc * Size), IndexBuild.XBoxMapData.XIndices.GetOffset());
                        byte[] RawXModelBuffer = new byte[XTrueVerticesSize];
                        FI.Read(RawXModelBuffer, 0, (int)XTrueVerticesSize);
                        byte[] XTestBuffer = new byte[6];
                        RawXModelBuffer = new byte[XTrueIndicesSize];
                        FI.Read(RawXModelBuffer, 0, RawXModelBuffer.Length);
                        FI.Read(XTestBuffer, 0, 6);
                        if (XTestBuffer[4] == 0xff)
                        {
                            XTrueIndicesSize += 6;
                        }
                        else
                        {
                            FI.Seek(FI.Position - 6, SeekOrigin.Begin);
                        }
                        break;

                        #endregion
                    case TSFReader.TSFBSPModel:                             // "bspmodel":
                        #region BspModel
                        uint UnCompressedVerts       = sr.GetOIP();
                        uint CompressedVerts         = sr.GetSOC();
                        uint UnCompressedVertsOffset = sr.GetOIP();
                        //uint VertsOffset = GetUInt(TagBuff,CompressedVerts);
                        uint TrueVertCount            = CompUtil.GetUInt(TagBuff, 180 + (sc * Size));
                        uint TrueLightMapDataCount    = CompUtil.GetUInt(TagBuff, 200 + (sc * Size));
                        uint UnCompressedLightMapData = (TrueLightMapDataCount * 20);
                        uint CompressedLightMapData   = (TrueLightMapDataCount * 8);
                        UnCompressedVerts = (TrueVertCount * 56);
                        CompressedVerts   = (TrueVertCount * 32);

                        byte[] BspVertsUnCompressed = new byte[UnCompressedVerts];
                        FI.Read(BspVertsUnCompressed, 0, BspVertsUnCompressed.Length);
                        //PutUInt(ref TagBuff,0xe4 + (sc * Size),(uint)(FO.Position + Info.TagMagic));
                        //FO.Write(BspVertsUnCompressed,0,BspVertsUnCompressed.Length);
                        //byte[] BspVertsCompressed = new byte[CompressedVerts];
                        byte[] BspLightMapDataUnCompressed = new byte[UnCompressedLightMapData];
                        FI.Read(BspLightMapDataUnCompressed, 0, BspLightMapDataUnCompressed.Length);
                        //FO.Write(BspLightMapDataUnCompressed,0,BspLightMapDataUnCompressed.Length);
                        //byte[] BspLightMapDataCompressed = new byte[CompressedLightMapData];
                        uint PotLuck  = IndexBuild.XBoxMapData.XBSPVerts.CurrentOffset;                         // + 0x800;
                        uint VOOffset = 0xB4;
                        uint LOOffset = 0xC8;
                        IndexBuild.XBoxMapData.XBSPVerts.VLMapOffset -= 0x0c;
                        CompUtil.PutUInt(ref TagBuff, VOOffset + 0x0c + (sc * Size), (uint)(IndexBuild.XBoxMapData.XBSPVerts.VLMapOffset + Info.TagMagic));
                        IndexBuild.XBoxMapData.XBSPVerts.ILMapOffset -= 0x0c;
                        CompUtil.PutUInt(ref TagBuff, LOOffset + 0x0c + (sc * Size), (uint)(IndexBuild.XBoxMapData.XBSPVerts.ILMapOffset + Info.TagMagic));
                        PotLuck += 0x0c;
                        IndexBuild.XBoxMapData.XBSPVerts.CurrentOffset = PotLuck;
                        CompUtil.PutUInt(ref TagBuff, 0xF8 + (sc * Size), IndexBuild.XBoxMapData.XBSPVerts.GetVOffset());
                        //viper told me to skip past compressed data as a quick fix to
                        // the crash problem - Grenadiac
                        FI.Seek(CompressedVerts, SeekOrigin.Current);                                 //gren added this
                        FI.Seek(CompressedLightMapData, SeekOrigin.Current);                          //gren added this
                        break;

                        #endregion
                    case TSFReader.TSFResource:                             // "resources":
                        #region Resources
                        ushort rStringSize = CompUtil.GetUShort(TagBuff, 0x06 + (sc * Size));
                        if (rStringSize != 0x00)
                        {
                            uint   TagClassFlag    = CompUtil.GetUShort(TagBuff, 0x00 + (sc * Size));
                            uint   TagResouceIndex = CompUtil.GetUShort(TagBuff, 0x02 + (sc * Size));
                            string TagClassString  = "";
                            switch (TagClassFlag)
                            {
                            case 0x00:
                                TagClassString = "bitm";
                                break;

                            case 0x01:
                                TagClassString = "snd!";
                                break;
                            }

                            //MAG tmpMR = new MAG(Info.StructurePath + TagClassString.Trim() + ".mag");
                            byte[] tmpStr = new byte[rStringSize + 1];



                            FI.Read(tmpStr, 0, tmpStr.Length);
                            string tag = CompUtil.ReadString(tmpStr, 0);
                            Trace.WriteLine(tag + "." + TagClassString + "      PRIndex" + Convert.ToString(TagResouceIndex, 10));
                            //tmpMR.Seek(0);
                            int t = 0;
                            //string[] test;
                            bool con = false;
                            do
                            {
                                string[] test      = Info.Items[t].GetString().Split(new char[] { '.' }, 256);                               //IndexStrings[t].Split(new char[]{'.'},256);
                                string   testClass = CompUtil.GetTagClass(BitConverter.GetBytes(Info.Items[t].TagClass1), 0);
                                if (testClass == TagClassString && test[0] == tag)
                                {
                                    con = true;
                                }
                                else
                                {
                                    t += 1;
                                }
                            }while (con == false);
                            CompUtil.PutUShort(ref TagBuff, (uint)(0x04 + (sc * Size)), (ushort)Info.Items[t].IndexID1);
                            CompUtil.PutUShort(ref TagBuff, (uint)(0x06 + (sc * Size)), (ushort)Info.Items[t].IndexID2);
                        }
                        break;

                        #endregion
                    case TSFReader.TSFSoundData:                             // "sounddata":
                        #region SoundData
                        uint   sRawSize   = CompUtil.GetUInt(TagBuff, (uint)(sr.GetOIP() + (sc * Size)));
                        uint   sRawOffset = CompUtil.GetUInt(TagBuff, (uint)(sr.GetUName() + 4 + (sc * Size)));
                        byte[] stmp       = new byte[sRawSize];
                        uint   svSndPos   = (uint)BSPFile.Position + 0x800;
                        CompUtil.PutUInt(ref TagBuff, (uint)(sr.GetUName() + 4 + (sc * Size)), svSndPos);
                        FI.Read(stmp, 0, stmp.Length);
                        BSPFile.Write(stmp, 0, stmp.Length);
                        CompUtil.Fix0x100Position(ref BSPFile);
                        stmp = null;
                        break;

                        #endregion
                    case TSFReader.TSFEnd:                             // "end":
                        #region EndStructure
                        if (sr.GetOIP() == Name)
                        {
                            ExitStruct = true;
                        }
                        else
                        {
                            ExitStruct = false;
                        }
                        break;
                        #endregion
                    }
                }while(ExitStruct == false);
                if (Count != 0)
                {
                    sc += 1;
                    if (sc != Count)
                    {
                        sr.Seek(StartOfStruct);
                        ExitStruct = false;
                    }
                }
            }while(sc != Count);
            long tmpPosSave = FO.Position;
            FO.Seek(StructPosition, SeekOrigin.Begin);
            FO.Write(TagBuff, 0, TagBuff.Length);
            FO.Seek(tmpPosSave, SeekOrigin.Begin);
        }
Beispiel #10
0
        public static void Build()
        {
            TagFileName  scenario_tag = ProjectManager.ScenarioTagFileName;           //new TagFileName(@"levels\test\beavercreek\beavercreek.scenario",MapfileVersion.XHALO1);
            IndexBuilder IndexBuild   = new IndexBuilder();
            string       BasFolder    = Application.StartupPath + @"\Extracted Tags\";
            string       StructFolder = Application.StartupPath + @"\Tag Structures\PcHalo\";

            if (true)
            {
                //Create the index table
                Application.DoEvents();
                string[] IndexList           = IndexBuild.BuildIndex(scenario_tag.RelativePath, BasFolder, StructFolder, MapfileVersion.XHALO1);
                XBoxHaloMap.sXBoxHalo NewMap = new XBoxHaloMap.sXBoxHalo();
                NewMap.XBoxIndexHeader.Create((uint)IndexList.Length);
                NewMap.XBoxIndexHeader.IndexMagic = 0x803a6024;                 //0x40440028;
                uint StringTableSize = 0;
                //Fixing index items
                ushort gt = 0xE174;
                Application.DoEvents();

                for (int sc = 0; sc < IndexList.Length; sc++)
                {
                    TagFileName tfnTAG = new TagFileName(IndexList[sc], MapfileVersion.XHALO1);
                    TagBase     tbTAG  = new TagBase();
                    tbTAG.LoadTagBuffer(tfnTAG);

                    NewMap.XBoxIndexHeader.IndexItems[sc].Create();
                    NewMap.XBoxIndexHeader.IndexItems[sc].TagClass1  = CompUtil.SwapUInt(tbTAG.Header.TagClass0);
                    NewMap.XBoxIndexHeader.IndexItems[sc].TagClass2  = CompUtil.SwapUInt(tbTAG.Header.TagClass1);
                    NewMap.XBoxIndexHeader.IndexItems[sc].TagClass3  = CompUtil.SwapUInt(tbTAG.Header.TagClass2);
                    NewMap.XBoxIndexHeader.IndexItems[sc].IndexID1   = (ushort)sc;
                    NewMap.XBoxIndexHeader.IndexItems[sc].IndexID2   = gt;
                    NewMap.XBoxIndexHeader.IndexItems[sc].NameString = IndexList[sc];
                    if (tbTAG.Header.TagClass0 == 0x70736273 || tbTAG.Header.TagClass0 == 0x73627370)
                    {
                        NewMap.XBoxIndexHeader.IndexItems[sc].MetaSize = IndexBuild.BSPSizes[0];
                    }
                    else
                    {
                        NewMap.XBoxIndexHeader.IndexItems[sc].MetaSize = 0;
                    }
                    if (tbTAG.Header.TagClass0 == 0x7274656d || tbTAG.Header.TagClass0 == 0x6d657472)                   //  6d657472)
                    {
                        gt += 2;
                    }
                    else
                    {
                        gt += 1;
                    }
                    string[] RemoveExt = IndexList[sc].Split(new char[] { '.' }, 256);
                    NewMap.XBoxIndexHeader.IndexItems[sc].String = new byte[RemoveExt[0].Length + 1];
                    HaloPCMAP.StringToByteArray(ref NewMap.XBoxIndexHeader.IndexItems[sc].String, RemoveExt[0]);
                    StringTableSize += (uint)(IndexList[sc].Length + 1);
                    tbTAG            = null;
                }
                //Creating the temp files for map building
                FileInfo   MetaFile_info = new FileInfo(Application.StartupPath + "TempMeta.map");
                FileStream MetaFile;
                MetaFile = MetaFile_info.Open(FileMode.Create, FileAccess.ReadWrite);

                FileInfo   BSPFile_info = new FileInfo(Application.StartupPath + "TempBSP.map");
                FileStream BSPFile;
                BSPFile = BSPFile_info.Open(FileMode.Create, FileAccess.ReadWrite);

                Application.DoEvents();

                //writing the index table the temp files
                for (int sc = 0; sc < NewMap.XBoxIndexHeader.IndexItems.Length; sc++)
                {
                    NewMap.XBoxIndexHeader.IndexItems[sc].Write(ref MetaFile);
                }
                //Rewriting index items to temp file to fix string offsets.
                Application.DoEvents();

                for (int sc = 0; sc < NewMap.XBoxIndexHeader.IndexItems.Length; sc++)
                {
                    NewMap.XBoxIndexHeader.IndexItems[sc].StringOffset = (uint)MetaFile.Position + NewMap.XBoxIndexHeader.IndexMagic;
                    MetaFile.Write(NewMap.XBoxIndexHeader.IndexItems[sc].String, 0, NewMap.XBoxIndexHeader.IndexItems[sc].String.Length);
                }
                CompUtil.FixIntPosition(ref MetaFile);
                //save MetaFile position to return for meta writing.
                long TmpPosSave = MetaFile.Position;
                Application.DoEvents();

                for (int sc = 0; sc < NewMap.XBoxIndexHeader.IndexItems.Length; sc++)
                {
                    MetaFile.Seek(NewMap.XBoxIndexHeader.IndexItems[sc].Position, SeekOrigin.Begin);
                    NewMap.XBoxIndexHeader.IndexItems[sc].Write(ref MetaFile);
                }
                //restore position for meta writing
                #region ModelData
                MetaFile.Seek(TmpPosSave, SeekOrigin.Begin);
                NewMap.XBoxIndexHeader.VertsOffset = (uint)MetaFile.Position + NewMap.XBoxIndexHeader.IndexMagic;
                NewMap.XBoxIndexHeader.ModelCount1 = (uint)IndexBuild.XBoxMapData.XVerts.ModelCount;
                NewMap.IndirectVerts = (uint)MetaFile.Position;
                IndexBuild.XBoxMapData.XVerts.FixOffsets((uint)MetaFile.Position, NewMap.XBoxIndexHeader.IndexMagic);
                MetaFile.Write(IndexBuild.XBoxMapData.XVerts.IndirectOffsets, 0, IndexBuild.XBoxMapData.XVerts.IndirectOffsets.Length);
                MetaFile.Write(IndexBuild.XBoxMapData.XVerts.Verts, 0, IndexBuild.XBoxMapData.XVerts.Verts.Length);
                NewMap.XBoxIndexHeader.ModelCount2   = (uint)IndexBuild.XBoxMapData.XIndices.ModelCount;
                NewMap.XBoxIndexHeader.IndicesOffset = (uint)MetaFile.Position + NewMap.XBoxIndexHeader.IndexMagic;
                NewMap.IndirectIndices = (uint)MetaFile.Position;
                IndexBuild.XBoxMapData.XIndices.FixOffsets((uint)MetaFile.Position, NewMap.XBoxIndexHeader.IndexMagic);
                MetaFile.Write(IndexBuild.XBoxMapData.XIndices.IndirectOffsets, 0, IndexBuild.XBoxMapData.XIndices.IndirectOffsets.Length);
                MetaFile.Write(IndexBuild.XBoxMapData.XIndices.Verts, 0, IndexBuild.XBoxMapData.XIndices.Verts.Length);
                #endregion
                //Add info to the Meta info struct
                XBoxMeta.StructInfo Info = new XBoxMeta.StructInfo();
                Info.MapMagic      = NewMap.XBoxIndexHeader.IndexMagic;
                Info.TagMagic      = NewMap.XBoxIndexHeader.IndexMagic;
                Info.StructurePath = StructFolder;
                Info.TagsPath      = BasFolder;
                Info.Items         = NewMap.XBoxIndexHeader.IndexItems;
                //Starts processing meta and writing it to the meta file
                Application.DoEvents();

                for (int sc = 0; sc < NewMap.XBoxIndexHeader.IndexItems.Length; sc++)
                {
                    if (NewMap.XBoxIndexHeader.IndexItems[sc].TagClass1 != 0x70736273)                     //   70736273)
                    {
                        XBoxMeta Meta = new XBoxMeta();
                        Trace.WriteLine("Meta Processor: " + IndexList[sc]);
                        TagFileName tfnTAG = new TagFileName(IndexList[sc], MapfileVersion.XHALO1);
                        TagBase     tbTAG  = new TagBase();
                        tbTAG.LoadTagBuffer(tfnTAG);

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

                        TSFReader STSF = new TSFReader();

                        STSF.TSF(ref mr, tbTAG.Header.TagClass0);

                        HaloPCMAP.FixIntPosition(ref MetaFile);
                        Info.CurrentOffset = (uint)MetaFile.Position;
                        NewMap.XBoxIndexHeader.IndexItems[sc].MetaOffset = (uint)(MetaFile.Position + NewMap.XBoxIndexHeader.IndexMagic);

                        Meta.DoProcessMeta(ref STSF, tbTAG.Stream, ref MetaFile, ref BSPFile, 1, IndexList, Info, ref NewMap, ref IndexBuild);

                        tbTAG = null;
                    }
                }
                //Create a new map header
                Application.DoEvents();

                NewMap.XBoxHeader.Create();
                string[] tmpName = scenario_tag.RelativePath.Split(new char[] { '\\' }, 256);
                tmpName = tmpName[tmpName.Length - 1].Split(new char[] { '.' }, 256);
                NewMap.XBoxHeader.MapName = tmpName[0];                //otf.FileName.Split(new char[]{'/'},256   //"Cool";
                //Rewrite indextable of meta offsets
                Application.DoEvents();

                TmpPosSave = MetaFile.Position;
                for (int sc = 0; sc < NewMap.XBoxIndexHeader.IndexItems.Length; sc++)
                {
                    MetaFile.Seek(NewMap.XBoxIndexHeader.IndexItems[sc].Position, SeekOrigin.Begin);
                    NewMap.XBoxIndexHeader.IndexItems[sc].Write(ref MetaFile);
                }
                MetaFile.Seek(TmpPosSave, SeekOrigin.Begin);

                //Create the new map file to begin construction of the new map.
                FileInfo   Map_info = new FileInfo(Application.StartupPath + NewMap.XBoxHeader.MapName + ".Map");
                FileStream Map;
                Map = Map_info.Open(FileMode.Create, FileAccess.ReadWrite);

                Application.DoEvents();

                //Write the header to the new map file
                NewMap.XBoxHeader.Write(ref Map);
                //Flush the tmp BSPFile to get FileSize.
                CompUtil.FixIntPosition2K(ref BSPFile);
                BSPFile.Flush();
                uint BSPFileSize = (uint)BSPFile.Length;
                //Seek to the begining of the tmp bsp file
                BSPFile.Seek(0, SeekOrigin.Begin);
                //Copy the Tmp bsp file to the new map file
                for (int bc = 0; bc < BSPFileSize; bc += 0x800)
                {
                    byte[] copy = new byte[0x800];
                    BSPFile.Read(copy, 0, copy.Length);
                    Map.Write(copy, 0, copy.Length);
                }
                //Put the Scnr index ID in the IndexHeader, you can move the scnr any were as long as you set this to the currect ID.
                NewMap.XBoxIndexHeader.ScnrID = (uint)((NewMap.XBoxIndexHeader.IndexItems[0].IndexID2 << 16) + NewMap.XBoxIndexHeader.IndexItems[0].IndexID1);
                //put the Current map position in the header so we know where the index header will be
                NewMap.XBoxHeader.IndexOffset = (uint)Map.Position;
                //Now we write the Index header to the map.
                NewMap.XBoxIndexHeader.Write(ref Map);

                //Flush the temp meta file so we can get the size.
                MetaFile.Flush();
                uint MetaFileSize = (uint)MetaFile.Length;
                //seek to the begining of the temp meta file for coping to the new map file
                MetaFile.Seek(0, SeekOrigin.Begin);
                //Copy the meta file to the new map file.
                for (int bc = 0; bc < MetaFileSize; bc += 0x800)
                {
                    byte[] copy = new byte[0x800];
                    MetaFile.Read(copy, 0, copy.Length);
                    Map.Write(copy, 0, copy.Length);
                }
                //Now we fix the map version map size and rewrite it to the map.
                Map.Flush();
                NewMap.XBoxHeader.MapVersion = 0x05;
                NewMap.XBoxHeader.MapSize    = (uint)Map.Length;
                NewMap.XBoxHeader.MetaSize   = MetaFileSize + 0x24;
                Map.Seek(NewMap.XBoxHeader.Position, SeekOrigin.Begin);
                NewMap.XBoxHeader.Write(ref Map);

                //Now close the files and delete the temp files.
                MetaFile.Flush();
                MetaFile.Close();
                File.Delete(MetaFile.Name);
                BSPFile.Close();
                File.Delete(BSPFile.Name);
                Map.Close();
            }
        }
Beispiel #11
0
        private TagFileName GetModelName(TagFileName tfn)
        {
            TagFileName model_name = null;
            string      model_type;

            if (tfn.Version == MapfileVersion.XHALO1)
            {
                model_type = "mode";
            }
            else
            {
                model_type = "mod2";
            }

            if (tfn.Exists)
            {
                TagBase tagdata = new TagBase();
                tagdata.LoadTagBuffer(tfn);
                BinaryReader br = new BinaryReader(tagdata.Stream);

                switch (tfn.TagClass)
                {
                case "scen":
                {
                    Scenery obj = new Scenery();
                    obj.Read(br);
                    obj.ReadChildData(br);
                    model_name = new TagFileName(obj.ObjectValues.Model.Value, model_type, tfn.Version);
                }
                break;

                case "vehi":
                {
                    Vehicle obj = new Vehicle();
                    obj.Read(br);
                    obj.ReadChildData(br);
                    model_name = new TagFileName(obj.ObjectValues.Model.Value, model_type, tfn.Version);
                }
                break;

                case "weap":
                {
                    Weapon obj = new Weapon();
                    obj.Read(br);
                    obj.ReadChildData(br);
                    model_name = new TagFileName(obj.ObjectValues.Model.Value, model_type, tfn.Version);
                }
                break;

                case "itmc":
                {
                    ItemCollection obj = new ItemCollection();
                    obj.Read(br);
                    obj.ReadChildData(br);

                    if (obj.ItemCollectionValues.ItemPermutations.Count > 0)
                    {
                        string      tagclass = obj.ItemCollectionValues.ItemPermutations[0].Item.TagGroup;
                        TagFileName itmc_tfn = new TagFileName(obj.ItemCollectionValues.ItemPermutations[0].Item.Value, tagclass, tfn.Version);
                        model_name = GetModelName(itmc_tfn);
                    }
                    int i = 0;
                    //model_name = new TagFileName(obj.Item_collectionValues.Value, "mod2", tfn.Version);
                }
                break;

                case "eqip":
                {
                    Equipment obj = new Equipment();
                    obj.Read(br);
                    obj.ReadChildData(br);
                    model_name = new TagFileName(obj.ObjectValues.Model.Value, model_type, tfn.Version);
                }
                break;
                }

                Trace.WriteLine("model_name = " + model_name.RelativePath);
            }

            return(model_name);
        }
Beispiel #12
0
        public void LoadScenario(Scenario st, TagBase scenario_data)
        {
            this.version = scenario_data.Header.GameVersion;
            int i;

            instanceCollection.Clear();

            //Process palettes
            scenarioTag = st;

            //load bipeds
            for (i = 0; i < st.ScenarioValues.Bipeds.Count; i++)
            {
                CreateInstance(st.ScenarioValues.Bipeds[i]);
            }

            //load decals
            //for(i=0; i<st.ScenarioValues.Decals.Count; i++)
            //  CreateInstance(st.ScenarioValues.Decals[i]);

            //load light fixtures
            for (i = 0; i < st.ScenarioValues.LightFixtures.Count; i++)
            {
                CreateInstance(st.ScenarioValues.LightFixtures[i]);
            }

            //load scenery
            for (i = 0; i < st.ScenarioValues.Scenery.Count; i++)
            {
                CreateInstance(st.ScenarioValues.Scenery[i]);
            }

            //load vehicles
            for (i = 0; i < st.ScenarioValues.Vehicles.Count; i++)
            {
                CreateInstance(st.ScenarioValues.Vehicles[i]);
            }

            //load netgame equipment
            for (i = 0; i < st.ScenarioValues.NetgameEquipment.Count; i++)
            {
                CreateInstance(st.ScenarioValues.NetgameEquipment[i]);
            }

            //load sound scenery
            for (i = 0; i < st.ScenarioValues.SoundScenery.Count; i++)
            {
                CreateInstance(st.ScenarioValues.SoundScenery[i]);
            }

            //load player spawns
            for (i = 0; i < st.ScenarioValues.PlayerStartingLocations.Count; i++)
            {
                CreateInstance(st.ScenarioValues.PlayerStartingLocations[i]);
            }

            //load netgame flags
            for (i = 0; i < st.ScenarioValues.NetgameFlags.Count; i++)
            {
                CreateInstance(st.ScenarioValues.NetgameFlags[i]);
            }


            if (st.ScenarioValues.StructureBsps.Count >= 1)
            {
                //get BSP filename
                TagFileName bsp_filename = new TagFileName(st.ScenarioValues.StructureBsps[0].StructureBsp.Value,
                                                           "sbsp", scenario_data.Header.GameVersion);

                //get Sky filename
                TagFileName sky_filename = new TagFileName(st.ScenarioValues.Skies[0].Sky.Value, "sky ", scenario_data.Header.GameVersion);
                TagBase     sky_data     = new TagBase();
                sky_data.LoadTagBuffer(sky_filename);
                BinaryReader sky_br  = new BinaryReader(sky_data.Stream);
                Sky          sky_tag = new Sky();
                sky_tag.Read(sky_br);
                sky_tag.ReadChildData(sky_br);

                MdxRender.RGB fog = new MdxRender.RGB();
                fog.R = sky_tag.SkyValues.OutdoorFogColor.R;
                fog.G = sky_tag.SkyValues.OutdoorFogColor.G;
                fog.B = sky_tag.SkyValues.OutdoorFogColor.B;
                MdxRender.FogColor = fog;

                /// Not sure how these units equate to d3d units - * 2.5 seems to be pretty good.
                MdxRender.FogStart   = sky_tag.SkyValues.OutdoorFogStartDistance.Value * 2.5f;
                MdxRender.FogEnd     = sky_tag.SkyValues.OutdoorFogOpaqueDistance.Value * 2.5f;
                MdxRender.FogDensity = sky_tag.SkyValues.OutdoorFogMaximumDensity.Value;

                MdxRender.ClearColor = Color.FromArgb(
                    (int)(sky_tag.SkyValues.OutdoorAmbientRadiosityColor.R * 255),
                    (int)(sky_tag.SkyValues.OutdoorAmbientRadiosityColor.G * 255),
                    (int)(sky_tag.SkyValues.OutdoorAmbientRadiosityColor.B * 255));

                MdxRender.FogEnabled = true;

                TagFileName sky_model_tfn;

                if (this.version == MapfileVersion.XHALO1)
                {
                    sky_model_tfn = new TagFileName(sky_tag.SkyValues.Model.Value, "mode", scenario_data.Header.GameVersion);
                }
                else
                {
                    sky_model_tfn = new TagFileName(sky_tag.SkyValues.Model.Value, "mod2", scenario_data.Header.GameVersion);
                }

                MdxRender.LoadBsp(bsp_filename, sky_model_tfn);

                //Load up them thar lights for Radiosity
                ProjectManager.RadiosityLights.Clear();
                //sky_tag
                for (int l = 0; l < sky_tag.SkyValues.Lights.Count; l++)
                {
                    RadiosityLight rl = new RadiosityLight();
                    rl.color[0] = sky_tag.SkyValues.Lights[l].Color.R;
                    rl.color[1] = sky_tag.SkyValues.Lights[l].Color.G;
                    rl.color[2] = sky_tag.SkyValues.Lights[l].Color.B;
                    rl.power    = sky_tag.SkyValues.Lights[l].Power.Value;

                    //don't know how this is turned into a vector, but we'll figure it out
                    //for now get x,y from yaw and z component from pitch (make sure Z component is negative)
                    rl.direction.Z = -1;
                    double y, p;
                    y = sky_tag.SkyValues.Lights[l].Direction.Y;
                    p = sky_tag.SkyValues.Lights[l].Direction.P;
                    rl.direction.X = -(float)Math.Cos(y);
                    rl.direction.Y = -(float)Math.Sin(y);
                    rl.direction.Z = -(float)Math.Sin(p);
                    ProjectManager.RadiosityLights.Add(rl);
                    MdxRender.AddGlobalLight(0, rl);
                }
            }

            instanceCollection.UpdateObjectColors();
        }