Exemplo n.º 1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Gets the model data from the tag. </summary>
        ///
        /// <param name="tagIndex">     The parent tag index. </param>
        /// <param name="tagManager">   The tags' manager. </param>
        ///
        /// <returns>   The model data. </returns>
        private ModelData GetModelData(TagIndexBase tagIndex, BlamLib.Managers.TagManager tagManager)
        {
            var data = new ModelData();

            data.CollectData(tagIndex, tagManager);

            return(data);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Gets the shader data from the tag. </summary>
        ///
        /// <param name="tagIndex">     The parent tag index. </param>
        /// <param name="tagManager">   The tags' manager. </param>
        ///
        /// <returns>   The shader data. </returns>
        private StructureBSPShaderData GetShaderData(TagIndexBase tagIndex, BlamLib.Managers.TagManager tagManager)
        {
            var data = new StructureBSPShaderData();

            data.CollectData(tagIndex, tagManager);

            return(data);
        }
Exemplo n.º 3
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Gets the scenario data from the tag. </summary>
        ///
        /// <param name="tagIndex">     Zero-based index of the tag. </param>
        /// <param name="tagManager">   The tag's manager. </param>
        ///
        /// <returns>   The scenario data. </returns>
        private ScenarioData GetScenarioData(TagIndexBase tagIndex, BlamLib.Managers.TagManager tagManager)
        {
            var data = new ScenarioData();

            data.MessageSent += MessageRedirect;

            data.CollectData(tagIndex, tagManager);

            data.MessageSent -= MessageRedirect;

            return(data);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Gets the BSP data from the tag. </summary>
        ///
        /// <param name="tagIndex">     The parent tag index. </param>
        /// <param name="tagManager">   The tag's manager. </param>
        ///
        /// <returns>   The bsp data. </returns>
        private StructureBSPData GetBSPData(TagIndexBase tagIndex, BlamLib.Managers.TagManager tagManager)
        {
            var data = new StructureBSPData()
            {
                IncludeRenderMesh = mBspData.ExportRenderMesh,
                IncludePortals    = mBspData.ExportPortals,
                IncludeFogPlanes  = mBspData.ExportFogPlanes,
                IncludeBSPMarkers = mBspData.ExportBSPMarkers
            };

            data.CollectData(tagIndex, tagManager);

            return(data);
        }
        /// <summary>Extract an existing tag to a file</summary>
        /// <param name="tag_datum">index of tag to extract</param>
        /// <param name="base_directory">Root directory to extract the tag to</param>
        /// <param name="name_override">Optional, if not null, this is the name of the file we store the tag in</param>
        /// <returns>false if it can't save the tag</returns>
        public bool Extract(Blam.DatumIndex tag_datum, string base_directory, string name_override)
        {
            Blam.DatumIndex handle = Open(tag_datum);
            if (handle != Blam.DatumIndex.Null)
            {
                TagManager tm = Array[handle];
                try {
                    tm.OpenForExtract(base_directory, name_override);
                    tm.Extract();
                }
                catch (Exception ex) { extractionTrace.WriteLine("Couldn't extract tag: '{0}'{1}{2}", tm.Name, Program.NewLine, ex); return(false); }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
        public bool Export(ScenarioData scenarioData
                           , BlamLib.Managers.TagManager tagManager
                           , string outputFile)
        {
            // Create the COLLADA exporter
            var extractor = new ColladaScenarioExporter(mColladaSettings,
                                                        TagIndex,
                                                        tagManager);

            extractor.MessageSent +=
                (sender, args) =>
            {
                mMessageHandler.SendMessage("Exporter Error: {0}", args.Message);
            };

            extractor.AddDataProvider(scenarioData);

            if (extractor.BuildColladaInstance())
            {
                extractor.SaveDAE(outputFile);
                return(true);
            }
            return(false);
        }
Exemplo n.º 7
0
 public TagIndexEventArgs(TagIndexBase index, TagManager tag)
 {
     tagIndex = index;
     tagMan   = tag;
 }
        bool Extract(Blam.CacheExtractionInfo cei, Blam.DatumIndex tag_datum, bool remove_from_state)
        {
            if (remove_from_state)
            {
                // don't process it if it's already been done
                if (cacheFile.ExtractionState.Processed(tag_datum))
                {
                    return(true);
                }
                cacheFile.ExtractionState.Dequeue(tag_datum);
            }
            cacheFile.ExtractionState.CurrentTag = tag_datum;

            Blam.CacheIndex.Item ci = cacheFile.Index.Tags[tag_datum.Index];

            bool error = false;

            Blam.DatumIndex handle = Open(tag_datum);
            if (handle != Blam.DatumIndex.Null)
            {
                // we're about to extract, update our depth level
                cei.ExtractionDepth++;
                TagManager tm = Array[handle];

                #region read the tag from the cache
                try { tm.OpenForExtract(cei.Arguments.OutputDirectory, null); }
                catch (Exception ex) { extractionTrace.WriteLine("Failed to read tag, aborting extraction...'{0}.{1}'{2}{3}", tm.Name, tm.GroupTag.Name, Program.NewLine, ex); error = true; }
                #endregion

                #region if no errors
                if (!error)
                {
                    try { tm.Extract(); }
                    catch (Exception ex) { extractionTrace.WriteLine("Failed to write tag, aborting extraction...'{0}.{1}'{2}{3}", tm.Name, tm.GroupTag.Name, Program.NewLine, ex); error = true; }

                    tm.Close();
                }

                // something bad happened, so make sure we don't keep any bad tags
                if (error)
                {
                    System.IO.File.Delete(Path.Combine(cei.Arguments.OutputDirectory, tm.Name));
                }

                // process dependents if we want to
                if (!error && cei.Arguments.WithDependents)
                {
                    error = !ExtractWithDependents(cei, tm);
                }
                #endregion

                // we're done with the extraction process, update depth level
                cei.ExtractionDepth--;

                // create and write database
                if (cei.Arguments.OutputDatabase && cei.ExtractionDepth == 0)
                {
                    ExtractWriteTagDatabases(cei, tm);
                }

                Unload(handle);
            }
            else
            {
                error = true;
            }

            return(!error);
        }
        /// <summary>
        /// Open a tag in the cache file
        /// </summary>
        /// <param name="tag_datum">index of tag</param>
        /// <returns>
        /// The tag_index handle associated to the <see cref="TagManager"/> object used to open the tag,
        /// or <see cref="Blam.DatumIndex.Null"/> if this operations fails
        /// </returns>
        public Blam.DatumIndex Open(Blam.DatumIndex tag_datum)
        {
            if (tag_datum == Blam.DatumIndex.Null)
            {
                return(Blam.DatumIndex.Null);
            }


            Blam.CacheIndex.Item i = cacheFile.Index.Tags[tag_datum.Index];

            if (i.IsEmpty)
            {
                throw new ArgumentNullException("tag_datum", string.Format("The tag handle {0} references an empty tag. We can't open this!", tag_datum.ToString()));
            }

            // How can we open it if we don't know where it F*****G IS YOU C**T??
            if (i.Location != Blam.CacheIndex.ItemLocation.Internal && !i.IsFeignItem)
            {
                return(Blam.DatumIndex.Null);
            }

            // Is this tag already loaded? if so, reuse handle
            Blam.DatumIndex di = IsLoaded(i);
            if (di != Blam.DatumIndex.Null)
            {
                Array.IncrementReference(di);
                return(di);
            }

            TagManager tm = new TagManager(this);

            tm.ReferenceName = i.ReferenceName;             // sync the tag manager's name with the cache item's

            bool      group_tag_hack = false;
            BlamBuild build          = Engine.ToBuild();

            // HACK: Halo1 PC uses gbx's variant of the model tag
            if (Engine == BlamVersion.Halo1_CE && i.GroupTag == Blam.Halo1.TagGroups.mode)
            {
                tm.Manage(Blam.Halo1.TagGroups.mod2);
                group_tag_hack = true;
            }
            else
            // HACK: Halo 2/3 use a the 'sound' group tag for their 'cache_file_sound' definitions
#if !NO_HALO2
            if (build == BlamBuild.Halo2 && i.GroupTag == Blam.Halo2.TagGroups.snd_)
            {
                tm.Manage(Blam.Halo2.TagGroups.shit);
                group_tag_hack = true;
            }
            else
#endif
#if !NO_HALO3
            if (build == BlamBuild.Halo3 && i.GroupTag == Blam.Halo3.TagGroups.snd_)
            {
                tm.Manage(Blam.Halo3.TagGroups.shit);
                group_tag_hack = true;
            }
            else
#endif
#if !NO_HALO_ODST
            if (build == BlamBuild.HaloOdst && i.GroupTag == Blam.Halo3.TagGroups.snd_)
            {
                tm.Manage(Blam.Halo3.TagGroups.shit);
                group_tag_hack = true;
            }
            else
#endif
#if !NO_HALO_REACH
            if (build == BlamBuild.HaloReach && i.GroupTag == Blam.HaloReach.TagGroups.snd_)
            {
                tm.Manage(Blam.HaloReach.TagGroups.shit);
                group_tag_hack = true;
            }
            else
#endif
#if !NO_HALO4
            if (build == BlamBuild.Halo4 && i.GroupTag == Blam.Halo4.TagGroups.snd_)
            {
                tm.Manage(Blam.Halo4.TagGroups.shit);
                group_tag_hack = true;
            }
            else
#endif
            { tm.Manage(i.GroupTag); }

            if (!i.IsFeignItem)
            {
                // We don't care about this shit when extracting or opening from a cache file
                const uint k_open_flags = IO.ITagStreamFlags.DontTrackTagManagerReferences |
                                          IO.ITagStreamFlags.DontTrackTagReferencers;

                tm.Flags.Add(k_open_flags);

                try { tm.Read(i, cacheFile, group_tag_hack); }
                catch (Exception ex)
                {
                    indexTrace.WriteLine("Cache Index: Failed to open tag from cache: {0}{1}'{2}.{3}'{4}{5}",
                                         cacheFile.InputStream.FileName, Program.NewLine,
                                         cacheFile.GetReferenceName(i), i.GroupTag.Name, Program.NewLine, ex);
                    return(Blam.DatumIndex.Null);
                }

                // Remove the flag we set before reading
                tm.Flags.Remove(k_open_flags);
            }

            tm.TagIndex = Array.Add(tm);
            base.OnEventOpen(new TagIndexEventArgs(this, tm));
            return(tm.TagIndex);
        }
Exemplo n.º 10
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Exports the provided bsp's lightmap sizes with a multiplier. </summary>
        ///
        /// <param name="tagIndex">         Tag index the bsp belongs to. </param>
        /// <param name="tagManager">       The bsp tag's manager. </param>
        /// <param name="sizeMultiplier">   The lightmap size multiplier. </param>
        /// <param name="outputFile">       The bsp's output file. </param>
        public void Export(TagIndexBase tagIndex, BlamLib.Managers.TagManager tagManager, int sizeMultiplier, string outputFile)
        {
            // Collect the necessary data
            var structureBSP = tagManager.TagDefinition as BlamLib.Blam.Halo1.Tags.structure_bsp_group;

            if (!TagIndex.IsValid(structureBSP.LightmapBitmaps.Datum))
            {
                mMessageHandler.SendMessage("Failed to open lightmap bitmap {0}", structureBSP.LightmapBitmaps.ToString());
                return;
            }

            var bitmapManager = tagIndex[structureBSP.LightmapBitmaps.Datum];

            if (bitmapManager == null)
            {
                mMessageHandler.SendMessage("Failed to open lightmap bitmap {0}", structureBSP.LightmapBitmaps.ToString());
                return;
            }

            if (structureBSP.Lightmaps.Count == 0)
            {
                mMessageHandler.SendMessage("BSP has no lightmaps {0}", tagManager.Name);
                return;
            }

            var bitmap = bitmapManager.TagDefinition as BlamLib.Blam.Halo1.Tags.bitmap_group;

            if (bitmap == null)
            {
                mMessageHandler.SendMessage("Failed to open lightmap bitmap {0}", structureBSP.LightmapBitmaps.ToString());
                return;
            }

            // Build the lightmap size list
            var lightmapSizeList = new List <string>();
            var bspName          = Path.GetFileNameWithoutExtension(tagManager.Name);

            foreach (var lightmap in structureBSP.Lightmaps)
            {
                if (lightmap.Bitmap.Value == -1)
                {
                    continue;
                }

                if (lightmap.Bitmap.Value >= bitmap.Bitmaps.Count)
                {
                    mMessageHandler.SendMessage("Failed to export lightmap sizes. A lightmap bitmap and bsp do not have matching lightmap counts {0}", tagManager.Name);
                    return;
                }

                var bitmapInfo = bitmap.Bitmaps[lightmap.Bitmap.Value];

                lightmapSizeList.Add(String.Format("{0}_{1}\t[{2},{3}]"
                                                   , bspName
                                                   , lightmap.Bitmap.Value
                                                   , bitmapInfo.Width * sizeMultiplier
                                                   , bitmapInfo.Height * sizeMultiplier));
            }

            // Save the sizes to file
            var sizeFileName = Path.ChangeExtension(outputFile, "lmsz");

            try
            {
                using (var outputStream = File.OpenWrite(sizeFileName))
                {
                    var writer = new StreamWriter(outputStream);
                    writer.Write(String.Join("\r\n", lightmapSizeList));
                    writer.Flush();
                }
                mMessageHandler.SendMessage("BSP lightmap sizes saved");
            }
            catch (IOException)
            {
                mMessageHandler.SendMessage("Failed to open the lightmap sizes file");
            }
        }