Dispose() public method

The dispose.
public Dispose ( ) : void
return void
        private void tsExternalReferenceAdd_Click(object sender, EventArgs e)
        {
            TreeNode tn = treeViewTagReflexives.SelectedNode;
            reflexiveData rd = (reflexiveData)tn.Tag;
            if (rd.reflexive == null)
            {
                MessageBox.Show("Not a reflexive!");
                return;
            }

            WinMetaEditor.references refs = new WinMetaEditor.references();
            if (rd.inTagNumber == this.meta.TagIndex)
            {
                refs.ident = this.meta.offset + rd.baseOffset + this.meta.magic;
                refs.offset = rd.baseOffset;
                refs.tagIndex = this.meta.TagIndex;
                refs.tagName = this.meta.name;
                refs.tagType = this.meta.type;
            }
            else
            {
                refs.tagIndex = map.Functions.ForMeta.FindMetaByOffset(rd.baseOffset);
                Meta m = new Meta(map);
                map.OpenMap(MapTypes.Internal);
                m.ReadMetaFromMap(refs.tagIndex, true);
                map.CloseMap();
                refs.ident = rd.baseOffset + m.magic;
                refs.offset = rd.baseOffset;
                refs.tagName = m.name;
                refs.tagType = m.type;
                m.Dispose();
            }
            refs.chunkCount = rd.chunkCount;
            refs.size = rd.reflexive.chunkSize;
            refs.name = rd.reflexive.name;

            // Check for duplicates & remove
            List<WinMetaEditor.references> refList = ((WinMetaEditor)this.ParentForm).reflexiveReferences;
            for (int i = 0; i < refList.Count; i++)
            {
                if (refList[i].ident == refs.ident)
                    refList.RemoveAt(i--);
            }

            // Always add to top of list
            refList.Insert(0, refs);
        }
Example #2
0
        /// <summary>
        /// The load bsp. The BSP is loaded into memory.
        /// </summary>
        /// <param name="BSPNum">The bsp num.</param>
        /// <remarks></remarks>
        private void loadBSP(int BSPId)
        {
            this.Cursor = Cursors.WaitCursor;
            //// Load the BSP viewer
            Meta meta = new Meta(map);
            meta.TagIndex = BSPId; // load BSP into MemoryStream (MS)
            meta.ScanMetaItems(true, false);
            BSPModel bsp = new BSPModel(ref meta);
            this.Cursor = Cursors.Arrow;
            if (bsp.BspNumber != -1)
            {
                BSPViewer bv = new BSPViewer(bsp, map);
                bv.Dispose();
                bv = null;
            }

            meta.Dispose();
            GC.Collect();
        }
Example #3
0
        /// <summary>
        /// Reloads the map.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <returns>Returns the reloaded Map</returns>
        /// <remarks>This needs to use a return value, because the loaded map changes were not being saved. They would be
        /// lost when the function returned and we ?cannot pass Map as a ref?.</remarks>
        public static Map Refresh(Map map)
        {
            map.CloseMap();
            Meta tempmeta = new Meta(map);
            if (map.SelectedMeta != null)
            {
                tempmeta = map.SelectedMeta;
            }

            map = LoadFromFile(map.filePath);

            if (tempmeta.MS != null)
            {
                int tagIndex = map.Functions.ForMeta.FindByNameAndTagType(tempmeta.type, tempmeta.name);
                // SelectedMeta belongs to map above, so keeps original map "locked"
                Meta meta = Map.GetMetaFromTagIndex(tagIndex, map, tempmeta.scannedwithent, tempmeta.parsed);
                map.SelectedMeta = meta;
                tempmeta.Dispose();
            }
            return map;
        }
Example #4
0
        /// <summary>
        /// The load spawns.
        /// </summary>
        /// <remarks></remarks>
        public void LoadSpawns()
        {
            spawns = new SpawnLoads(map, bsp, render.device);
            SpawnModel = new List<ParsedModel>();
            spawnmodelindex = new int[bsp.Spawns.Spawn.Count];
            BoundingBoxModel = new Mesh[bsp.Spawns.Spawn.Count];

            map.OpenMap(MapTypes.Internal);

            int blockCount = 0;
            int scenCount = 0;
            for (int x = 0; x < bsp.Spawns.Spawn.Count; x++)
            {
                // Display loading information
                if (x % 7 == 0)
                {
                    this.label3.Text = ".:Loading Spawns [" + x.ToString() + "/" + bsp.Spawns.Spawn.Count.ToString() + "]:.";
                    // Every 5 updates, refresh whole window, otherwise just update the label
                    if (x % 35 == 0)
                        Application.DoEvents();
                    else
                        this.label3.Refresh();
                }

                // This is the only way I could think of doing it right now...
                // Used for saving Obstacle & Scenery to their original places
                if (bsp.Spawns.Spawn[x] is SpawnInfo.ObstacleSpawn)
                {
                    ((SpawnInfo.ObstacleSpawn)bsp.Spawns.Spawn[x]).BlocNumber = blockCount++;
                }
                else if (bsp.Spawns.Spawn[x] is SpawnInfo.ScenerySpawn)
                {
                    ((SpawnInfo.ScenerySpawn)bsp.Spawns.Spawn[x]).ScenNumber = scenCount++;
                }

                if (bsp.Spawns.Spawn[x] is SpawnInfo.BoundingBoxSpawn)
                {
                    BoundingBoxModel[x] = loadBoundingBoxSpawn(bsp.Spawns.Spawn[x]);
                    continue;
                }

                #region CameraSpawn
                if (bsp.Spawns.Spawn[x] is SpawnInfo.CameraSpawn)
                {
                    BoundingBoxModel[x] = loadCameraSpawn(bsp.Spawns.Spawn[x]);
                    continue;
                }
                #endregion

                #region LightSpawn

                if (bsp.Spawns.Spawn[x] is SpawnInfo.LightSpawn)
                {
                    SpawnInfo.LightSpawn tempbox;
                    tempbox = bsp.Spawns.Spawn[x] as SpawnInfo.LightSpawn;
                    tempbox.LightInfo = new HaloLight(tempbox.ModelTagNumber, map);
                    bsp.Spawns.Spawn[x] = tempbox;
                    BoundingBoxModel[x] = Mesh.Cylinder(render.device, 0.5f, 0.0f, 1f, 10, 10);
                    if (render.lighting)
                    {
                        render.device.Lights[HaloLightCount].Type = LightType.Point;
                        render.device.Lights[HaloLightCount].Position = new Vector3(tempbox.X, tempbox.Y, tempbox.Z);
                        render.device.Lights[HaloLightCount].Direction = new Vector3(
                            -tempbox.Yaw, -tempbox.Pitch, -tempbox.Roll);
                        render.device.Lights[HaloLightCount].Range = 10f;

                        // render.device.Lights[HaloLightCount].=0.5f;
                        // render.device.Lights[HaloLightCount].p = 1.0f;
                        render.device.Lights[HaloLightCount].Falloff = 1.0f;
                        render.device.Lights[HaloLightCount].Attenuation0 = 1.0f;
                        render.device.Lights[HaloLightCount].Diffuse = Color.FromArgb(
                            tempbox.LightInfo.r, tempbox.LightInfo.g, tempbox.LightInfo.b);
                        render.device.Lights[HaloLightCount].Update();
                        render.device.Lights[HaloLightCount].Enabled = true;
                    }

                    HaloLightCount++;

                    continue;
                }

                #endregion

                #region SoundSpawn
                if (bsp.Spawns.Spawn[x] is SpawnInfo.SoundSpawn)
                {
                    BoundingBoxModel[x] = loadSoundSpawn(bsp.Spawns.Spawn[x]);
                    continue;
                }
                #endregion

                #region SpawnZone
                if (bsp.Spawns.Spawn[x] is SpawnInfo.SpawnZone)
                {
                    BoundingBoxModel[x] = loadSpawnZone(bsp.Spawns.Spawn[x]);
                    continue;
                }
                #endregion

                SpawnInfo.RotationSpawn tempspawn = bsp.Spawns.Spawn[x] as SpawnInfo.RotationSpawn;

                #region ScanForExistingModels
                bool found = false;
                for (int xx = 0; xx < x; xx++)
                {
                    SpawnInfo.RotationSpawn tempspawn2 = bsp.Spawns.Spawn[xx] as SpawnInfo.RotationSpawn;
                    if (bsp.Spawns.Spawn[xx] is SpawnInfo.BoundingBoxSpawn)
                    {
                        continue;
                    }

                    if (tempspawn.ModelTagNumber == tempspawn2.ModelTagNumber)
                    {
                        BoundingBoxModel[x] = BoundingBoxModel[xx];
                        spawnmodelindex[x] = spawnmodelindex[xx];
                        bsp.Spawns.Spawn[x].bbXDiff = bsp.Spawns.Spawn[xx].bbXDiff;
                        bsp.Spawns.Spawn[x].bbYDiff = bsp.Spawns.Spawn[xx].bbYDiff;
                        bsp.Spawns.Spawn[x].bbZDiff = bsp.Spawns.Spawn[xx].bbZDiff;
                        found = true;
                        break;
                    }
                }

                if (found)
                {
                    continue;
                }
                #endregion

                #region ReadSpawnMeta

                Meta m = new Meta(map);
                if (tempspawn.ModelTagNumber == -1)
                {
                    MessageBox.Show("Test");
                }

                m.ReadMetaFromMap(tempspawn.ModelTagNumber, false);

                #endregion

                #region DirectXModel

                ParsedModel pm = new ParsedModel(ref m);

                // pm.PermutationString=pm.hlmt.Permutations[pm.hlmt.FindPermutationByBaseClass,
                ParsedModel.DisplayedInfo.LoadDirectXTexturesAndBuffers(ref render.device, ref pm);
                SpawnModel.Add(pm);
                spawnmodelindex[x] = SpawnModel.Count - 1;
                m.Dispose();

                #endregion

                #region BoundingBox

                float boxwidth = pm.BoundingBox.MaxX - pm.BoundingBox.MinX;
                float boxheight = pm.BoundingBox.MaxY - pm.BoundingBox.MinY;
                float boxdepth = pm.BoundingBox.MaxZ - pm.BoundingBox.MinZ;
                try
                {
                    BoundingBoxModel[x] = Mesh.Box(render.device, boxwidth, boxheight, boxdepth);
                }
                catch (Exception ex)
                {
                    Global.ShowErrorMsg("Failure to create Bounding Box Mesh for " + pm.name +
                        "\nWidth : " + boxwidth.ToString() +
                        "\nHeight: " + boxheight.ToString() +
                        "\nLength: " + boxdepth.ToString(),
                        ex);
                }
                // Used for fixing position of bounding boxes
                bsp.Spawns.Spawn[x].bbXDiff = pm.BoundingBox.MaxX + pm.BoundingBox.MinX;
                bsp.Spawns.Spawn[x].bbYDiff = pm.BoundingBox.MaxY + pm.BoundingBox.MinY;
                bsp.Spawns.Spawn[x].bbZDiff = pm.BoundingBox.MaxZ + pm.BoundingBox.MinZ;

                #endregion
            }

            if (render.device.DeviceCaps.RasterCaps.SupportsFogTable && bsp.sky.fogenabled &&
                bsp.sky.fog.FogThickness != 0)
            {
                int a = (int)(bsp.sky.fog.A * 255);
                int r = (int)(bsp.sky.fog.R * 255);
                int g = (int)(bsp.sky.fog.G * 255);
                int b = (int)(bsp.sky.fog.B * 255);
                render.device.RenderState.FogColor = Color.FromArgb(a, r, g, b);
                render.device.RenderState.FogStart = bsp.sky.fog.Start;
                render.device.RenderState.FogEnd = bsp.sky.fog.End;
                render.device.RenderState.FogDensity = bsp.sky.fog.FogThickness; // bsp.sky.fog.FogThickness;

                render.device.RenderState.FogTableMode = FogMode.Linear;
                render.device.RenderState.FogEnable = true;
            }

            // render.device.RenderState.FogVertexMode = FogMode.Linear;

            /*
            this.label3.Text = ".:Loading Weapons Collection:.";
            this.ResumeLayout();
            this.SuspendLayout();
            #region LoadAllWeaponsForCollectionChangeBox
            WeaponsList.Clear();
            // Lists all weapons
            for (int i = 0; i < map.MetaInfo.TagType.Length; i++)
                if ((map.MetaInfo.TagType[i] == "itmc") ||
                    (map.MetaInfo.TagType[i] == "vehc"))
                {
                    CollectionInfo Weapon = new CollectionInfo();
                    Meta m = new Meta(map);
                    m.ReadMetaFromMap(i, map, false);

                    Weapon.ItmcTagNumber = i;
                    // Base address of ITMC tag, offset of WEAP pointer (+20)
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[Weapon.ItmcTagNumber] + 20;
                    Weapon.WeapTagNumber = map.Functions.Meta.FindMetaByID(map.BR.ReadInt32(), map);
                    if (Weapon.WeapTagNumber == -1) { continue; }

                    // Base address of WEAP tag, offset of HLMT pointer (+56)
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[Weapon.WeapTagNumber] + 56;
                    Weapon.HlmtTagNumber = map.Functions.Meta.FindMetaByID(map.BR.ReadInt32(), map);
                    if (Weapon.HlmtTagNumber != -1)
                    {
                        // Base address of HLMT tag, offset of MODE pointer (+4)
                        map.BR.BaseStream.Position = map.MetaInfo.Offset[Weapon.HlmtTagNumber] + 4;
                        Weapon.ModelTagNumber = map.Functions.Meta.FindMetaByID(map.BR.ReadInt32(), map);
                        m.ReadMetaFromMap(Weapon.ModelTagNumber, map, false);
                        Weapon.Model = new ParsedModel(ref m, map);
                        Raw.ParsedModel.DisplayedInfo.LoadDirectXTexturesAndBuffers(ref render.device, ref Weapon.Model);

                        // Store names into Weapon
                        Weapon.TagPath = map.FileNames.Name[i];
                        Weapon.TagType = map.MetaInfo.TagType[i];
                        int xx = map.Functions.Meta.FindByNameAndTagType(Weapon.TagType, Weapon.TagPath, map);
                        string[] NameSplit = map.FileNames.Name[xx].Split('\\');
                        Weapon.Name = NameSplit[NameSplit.Length - 1];
                        Weapon.Name = Weapon.Name.Replace('_', ' ');
                        WeaponsList.Add(Weapon);
                    }
                }
            #endregion
            #region LoadAllObjectsForObstacleAndSceneryChangeBox
            SceneryList.Clear();
            ObstacleList.Clear();
            // Lists all Scenery & Obstacles
            for (int i = 0; i < map.MapHeader.fileCount; i++)
            {
                if ((map.MetaInfo.TagType[i] == "scnr"))
                {
                    Meta m = new Meta(map);
                    //m.ReadMetaFromMap(i, map, false);

                    // Base address of SCNR tag, offset of Scenery Palette pointer (+88)
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[i] + 88;
                    int chunkCount = map.BR.ReadInt32();
                    int chunkOffset = map.BR.ReadInt32() - map.SecondaryMagic;

                    #region Scenery Palette Objects
                    // Scenery Palette Objects
                    for (int a = 0; a < chunkCount; a++)
                    {
                        SceneryInfo Scenery = new SceneryInfo();

                        // The Palette Chunk #
                        Scenery.ScenPalNumber = a;

                        // Each chunk is 40 bytes apart
                        map.BR.BaseStream.Position = chunkOffset + a * 40;
                        char[] tagName = map.BR.ReadChars(4);
                        Scenery.ScenTagNumber = map.Functions.Meta.FindMetaByID(map.BR.ReadInt32(), map);

                        try
                        {
                            // Retrieve the Model HLMT tag from the Scenery tag (+56)
                            map.BR.BaseStream.Position = map.MetaInfo.Offset[Scenery.ScenTagNumber] + 56;
                            Scenery.HlmtTagNumber = map.Functions.Meta.FindMetaByID(map.BR.ReadInt32(), map);

                            // Base address of HLMT tag, offset of MODE pointer (+4)
                            map.BR.BaseStream.Position = map.MetaInfo.Offset[Scenery.HlmtTagNumber] + 4;
                            Scenery.ModelTagNumber = map.Functions.Meta.FindMetaByID(map.BR.ReadInt32(), map);

                            if (Scenery.ModelTagNumber != -1)
                            {
                                m.ReadMetaFromMap(Scenery.ModelTagNumber, map, false);
                                Scenery.Model = new ParsedModel(ref m, map);
                            }
                            else
                                Scenery.Model = null;
                            Raw.ParsedModel.DisplayedInfo.LoadDirectXTexturesAndBuffers(ref render.device, ref Scenery.Model);

                            string[] s = map.FileNames.Name[Scenery.ScenTagNumber].Split('\\');
                            Scenery.Name = s[s.Length - 1];
                            Scenery.TagPath = map.FileNames.Name[Scenery.ScenTagNumber];
                            Scenery.TagType = map.MetaInfo.TagType[Scenery.ScenTagNumber];
                            SceneryList.Add(Scenery);
                        }
                        catch { }
                    }
                    #endregion

                    // Base address of SCNR tag, offset of Sound Scenery Palette pointer (+224)
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[i] + 224;
                    chunkCount = map.BR.ReadInt32();
                    chunkOffset = map.BR.ReadInt32() - map.SecondaryMagic;

                    #region Sound Scenery Palette Objects
                    // Scenery Palette Objects
                    for (int a = 0; a < chunkCount; a++)
                    {
                        SceneryInfo Sound = new SceneryInfo();

                        // The Palette Chunk #
                        Sound.ScenPalNumber = a;

                        // Each chunk is 40 bytes apart
                        map.BR.BaseStream.Position = chunkOffset + a * 40;
                        char[] tagName = map.BR.ReadChars(4);
                        Sound.ScenTagNumber = map.Functions.Meta.FindMetaByID(map.BR.ReadInt32(), map);

                        if (Sound.ScenTagNumber != -1)
                        {
                            string[] s = map.FileNames.Name[Sound.ScenTagNumber].Split('\\');
                            Sound.Name = s[s.Length - 1];
                            Sound.TagPath = map.FileNames.Name[Sound.ScenTagNumber];
                            Sound.TagType = map.MetaInfo.TagType[Sound.ScenTagNumber];
                            SoundsList.Add(Sound);
                        }
                    }
                    #endregion

                    // Base address of SCNR tag, offset of Crate Palette pointer (+816)
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[i] + 816;
                    chunkCount = map.BR.ReadInt32();
                    chunkOffset = map.BR.ReadInt32() - map.SecondaryMagic;

                    #region Crate Palette Objects
                    // Crate (Obstacle) Palette Objects
                    for (int a = 0; a < chunkCount; a++)
                    {
                        SceneryInfo Obstacle = new SceneryInfo();

                        // The Palette Chunk #
                        Obstacle.ScenPalNumber = a;

                        // Each chunk is 40 bytes apart
                        map.BR.BaseStream.Position = chunkOffset + a * 40;
                        char[] tagName = map.BR.ReadChars(4);
                        Obstacle.ScenTagNumber = map.Functions.Meta.FindMetaByID(map.BR.ReadInt32(), map);
                        if (Obstacle.ScenTagNumber != -1)
                        {
                            // Retrieve the Model HLMT tag from the Scenery tag (+56)
                            map.BR.BaseStream.Position = map.MetaInfo.Offset[Obstacle.ScenTagNumber] + 56;
                            Obstacle.HlmtTagNumber = map.Functions.Meta.FindMetaByID(map.BR.ReadInt32(), map);

                            // Base address of HLMT tag, offset of MODE pointer (+4)
                            map.BR.BaseStream.Position = map.MetaInfo.Offset[Obstacle.HlmtTagNumber] + 4;
                            Obstacle.ModelTagNumber = map.Functions.Meta.FindMetaByID(map.BR.ReadInt32(), map);

                            m.ReadMetaFromMap(Obstacle.ModelTagNumber, map, false);
                            Obstacle.Model = new ParsedModel(ref m, map);
                            Raw.ParsedModel.DisplayedInfo.LoadDirectXTexturesAndBuffers(ref render.device, ref Obstacle.Model);

                            string[] s = map.FileNames.Name[Obstacle.ScenTagNumber].Split('\\');
                            Obstacle.Name = s[s.Length - 1];
                            Obstacle.TagPath = map.FileNames.Name[Obstacle.ScenTagNumber];
                            Obstacle.TagType = map.MetaInfo.TagType[Obstacle.ScenTagNumber];
                            ObstacleList.Add(Obstacle);
                        }
                    }
                    #endregion
                    break;
                }
            }
            #endregion
            */
            map.CloseMap();
        }