CloseMap() public method

The close map.
public CloseMap ( ) : void
return void
Ejemplo n.º 1
0
        /// <summary>
        /// Loads a .map file and returns it as
        /// a map object
        /// </summary>
        /// <param name="fileName">The file Name.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static Map LoadFromFile(string fileName)
        {
            // create the map object and give it the map filename
            Map map = new Map(fileName);

            // open the map
            map.OpenMap(MapTypes.Internal);

            // if the open failed, nothing we can do further
            if (!map.isOpen)
            {
                return(null);
            }

            // Get map version, (what halo this is)
            map.BR.BaseStream.Position = 4;
            int version = map.BR.ReadInt32();

            // set the halo game type in the map object
            switch (version)
            {
            case 609:
                map.HaloVersion = HaloVersionEnum.HaloCE;
                break;

            case 8:
                map.HaloVersion            = HaloVersionEnum.Halo2;
                map.BR.BaseStream.Position = 0x24;
                switch (map.BR.ReadInt32())
                {
                case -1:
                    map.HaloVersion = HaloVersionEnum.Halo2Vista;
                    break;

                case 0:
                    map.HaloVersion = HaloVersionEnum.Halo2;
                    break;
                }
                break;

            case 5:
                map.HaloVersion = HaloVersionEnum.Halo1;
                break;

            // if we dont support the map, dont open it
            default:
                MessageBox.Show("This is not a supported map type.");
                map.CloseMap();
                return(null);
            }

            // read from the map
            map.LoadMap();

            // close file and return map obj
            map.CloseMap();
            return(map);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The halo ce container.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void HaloCEContainer(Map map)
        {
            map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[0] + 1444;
            bspcount = map.BR.ReadInt32();
            int tempr = map.BR.ReadInt32() - map.PrimaryMagic;

            sbsp = new BSPInfo[bspcount];
            for (int x = 0; x < bspcount; x++)
            {
                sbsp[x] = new BSPInfo();
                sbsp[x].pointerOffset      = tempr + (x * 32) - map.MetaInfo.Offset[0];
                map.BR.BaseStream.Position = tempr + (x * 32);
                sbsp[x].offset             = map.BR.ReadInt32();
                sbsp[x].size  = map.BR.ReadInt32();
                sbsp[x].magic = map.BR.ReadInt32() - sbsp[x].offset;
                map.BR.BaseStream.Position = tempr + (x * 32) + 28;
                sbsp[x].ident    = map.BR.ReadInt32();
                sbsp[x].TagIndex = map.Functions.ForMeta.FindMetaByID(sbsp[x].ident);
                map.MetaInfo.Offset[sbsp[x].TagIndex] = sbsp[x].offset;
                map.MetaInfo.Size[sbsp[x].TagIndex]   = sbsp[x].size;
                map.BR.BaseStream.Position            = sbsp[x].offset + 4;
                sbsp[x].Halo1VerticeCount             = map.BR.ReadInt32();

                sbsp[x].lightmapoffset     = 24;
                map.BR.BaseStream.Position = sbsp[x].lightmapoffset + 12;

                sbsp[x].lightmapident    = map.BR.ReadInt32();
                sbsp[x].lightmapTagIndex = map.Functions.ForMeta.FindMetaByID(sbsp[x].ident);
            }

            map.CloseMap();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BSPConvert"/> class.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="test">The test.</param>
        /// <remarks></remarks>
        public H1BSPConvert(Map map, ref PropertyGrid test)
        {
            switch (map.HaloVersion)
            {
                case HaloVersionEnum.Halo1:
                case HaloVersionEnum.HaloCE:
                    map.OpenMap(MapTypes.Internal);
                    H1SBSP h1bsp = new H1SBSP(map.BSP.sbsp[0].TagIndex, map);
                    test.SelectedObject = h1bsp.Header;
                    map.CloseMap();
                    break;
                case HaloVersionEnum.Halo2:
                case HaloVersionEnum.Halo2Vista:
                    MessageBox.Show("Open an H1 Map first");
                    break;
            }

            // OpenFileDialog open = new OpenFileDialog();
            // open.Filter = "*.map|*.map";
            // if (open.ShowDialog() == DialogResult.Cancel)  return;
            // int h2map=Maps.Add(open.FileName);
            // Halo2BSP h2bsp = new Halo2BSP(h2map);

            // Maps.Remove(h2map);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The get meta from tag index.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <param name="map">The map.</param>
        /// <param name="manualScan">The manual scan.</param>
        /// <param name="parse">The parse.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static Meta GetMetaFromTagIndex(int tag, Map map, bool manualScan, bool parse)
        {
            map.OpenMap(MapTypes.Internal);

            Meta meta = new Meta(map);

            meta.TagIndex = tag;
            meta.ScanMetaItems(manualScan, parse);

            map.CloseMap();

            meta.SortItemsByOffset();

            return(meta);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Scripts"/> class.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public Scripts(Map map)
        {
            map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 568;
            int tempc = map.BR.ReadInt32();
            int tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            syntaxes = new Syntax[tempc];
            map.BR.BaseStream.Position = tempr;
            for (int x = 0; x < tempc; x++)
            {
                syntaxes[x] = new Syntax(ref map.BR);
            }

            map.CloseMap();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// The write palettes.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void WritePalettes(Map map)
        {
            map.OpenMap(MapTypes.Internal);
            map.BW.BaseStream.Position = palettesoffset;
            foreach (BSPContainer.Palette_Color[] palette in LightMap_Palettes)
            {
                for (int x = 0; x < 256; x++)
                {
                    map.BW.Write((byte)palette[x].r);
                    map.BW.Write((byte)palette[x].g);
                    map.BW.Write((byte)palette[x].b);
                    map.BW.Write((byte)palette[x].a);
                }
            }

            map.CloseMap();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="hlmtContainer"/> class.
        /// </summary>
        /// <param name="tagIndex">Index of the tag.</param>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public hlmtContainer(int tagIndex, Map map)
        {
            bool alreadyOpen = true;
            if (!(map.isOpen && map.openMapType == MapTypes.Internal))
            {
                map.OpenMap(MapTypes.Internal);
                alreadyOpen = false;
            }

            this.TagIndex = tagIndex;

            Permutations = new PermutationInfo();
            Permutations.Name = map.FileNames.Name[TagIndex];
            map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 112;
            int tempc = map.BR.ReadInt32();
            int tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            Permutations.Piece = new PermutationInfo.PermutationPiece[tempc];
            for (int x = 0; x < tempc; x++)
            {
                Permutations.Piece[x] = new PermutationInfo.PermutationPiece();
                map.BR.BaseStream.Position = tempr + (x * 16);
                Permutations.Piece[x].PieceName = map.Strings.Name[map.BR.ReadInt16()];
                map.BR.BaseStream.Position = tempr + (x * 16) + 8;
                int tempc2 = map.BR.ReadInt32();
                int tempr2 = map.BR.ReadInt32() - map.SecondaryMagic;
                Permutations.Piece[x].Permutation = new PermutationInfo.PermutationPiece.PermutationVariation[tempc2];
                for (int xx = 0; xx < tempc2; xx++)
                {
                    Permutations.Piece[x].Permutation[xx] = new PermutationInfo.PermutationPiece.PermutationVariation();
                    map.BR.BaseStream.Position = tempr2 + (xx * 8);
                    string temps2 = map.Strings.Name[map.BR.ReadInt16()];
                    Permutations.Piece[x].Permutation[xx].PermutationNameX = temps2;
                }
            }

            if (!alreadyOpen)
            {
                map.CloseMap();
            }
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Loads the strings from "stringListIdent" into "strings"
        /// </summary>
        /// <param name="map"></param>
        /// <returns></returns>
        public bool getStrings(Map map)
        {
            if (!isPopulated | stringsListIdent == -1)
                return false;
            Meta m = Map.GetMetaFromTagIndex(map.Functions.ForMeta.FindMetaByID(stringsListIdent), map, false, false);
            BinaryReader br = new BinaryReader(m.MS);
            br.BaseStream.Position = 16;    // English only...
            int offset = br.ReadUInt16();
            int count = br.ReadUInt16();

            int uiOffset = map.Unicode.ut[0].indexOffset;
            int utOffset = map.Unicode.ut[0].tableOffset;
            if (map.Unicode.ut[0].SIDs == null)
                map.Unicode.ut[0].Read();

            map.OpenMap(MapTypes.Internal);
            br = new BinaryReader(map.FS);
            for (int i = 0; i < count; i++)
            {
                br.BaseStream.Position = utOffset + map.Unicode.ut[0].US[offset + i].offset;
                strings.Add(
                    new entity.MetaFuncs.MEStringsSelector.Unicode(
                        offset + i,
                        map.Unicode.ut[0].US[offset + i].uString,
                        map.Unicode.ut[0].US[offset + i].size,
                        map.Unicode.ut[0].US[offset + i].offset,
                        null));
            }
            //new string(br.ReadChars(map.Unicode.ut[0].US[offset + i].size));
            map.CloseMap();
            return true;
        }
Ejemplo n.º 10
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;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// The split with ifp.
        /// </summary>
        /// <param name="ifp">The ifp.</param>
        /// <param name="meta">The meta.</param>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void SplitWithIFP(ref IFPIO ifp, ref Meta meta, Map map)
        {
            this.type = meta.type;
            this.TagIndex = meta.TagIndex;
            this.name = meta.name;
            this.offset = meta.offset;
            this.magic = meta.magic;
            this.raw = meta.raw;
            this.rawtype = meta.rawType;
            map.OpenMap(MapTypes.Internal);
            if (ifp.items != null)
            {
                map.BR.BaseStream.Position = meta.offset;
                Header = new SplitReflexive();
                Header.offset = 0;
                Header.Chunks = new List<SplitReflexive>();
                Header.translation = 0;

                // Header.MS = new MemoryStream(ifp.headerSize);
                // Header.MS.Write(map.BR.ReadBytes(ifp.headerSize), 0, ifp.headerSize);
                Header.chunksize = ifp.headerSize;
                Header.chunkcount = 1;
                Header.splitReflexiveType = SplitReflexive.SplitReflexiveType.Container;
                Header.realtranslation = meta.offset;
                if (meta.type == "sbsp")
                {
                    int p = map.BSP.FindBSPNumberByBSPIdent(meta.ident);
                    CycleElements(
                        ref Header, ifp.items, ref meta, meta.offset, map, meta.TagIndex, map.BSP.sbsp[p].magic);
                }
                else if (meta.type == "ltmp")
                {
                    int p = map.BSP.FindBSPNumberByLightMapIdent(meta.ident);
                    CycleElements(
                        ref Header, ifp.items, ref meta, meta.offset, map, meta.TagIndex, map.BSP.sbsp[p].magic);
                }
                else
                {
                    // not "sbsp" or "ltmp"
                    CycleElements(ref Header, ifp.items, ref meta, meta.offset, map, meta.TagIndex, map.SecondaryMagic);
                }
            }

            map.CloseMap();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// The get meta from tag index.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <param name="map">The map.</param>
        /// <param name="manualScan">The manual scan.</param>
        /// <param name="parse">The parse.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static Meta GetMetaFromTagIndex(int tag, Map map, bool manualScan, bool parse)
        {
            map.OpenMap(MapTypes.Internal);

            Meta meta = new Meta(map);

            meta.TagIndex = tag;
            meta.ScanMetaItems(manualScan, parse);

            map.CloseMap();

            meta.SortItemsByOffset();

            return meta;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Loads a .map file and returns it as
        /// a map object
        /// </summary>
        /// <param name="fileName">The file Name.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static Map LoadFromFile(string fileName)
        {
            // create the map object and give it the map filename
            Map map = new Map(fileName);

            // open the map
            map.OpenMap(MapTypes.Internal);

            // if the open failed, nothing we can do further
            if (!map.isOpen)
            {
                return null;
            }

            // Get map version, (what halo this is)
            map.BR.BaseStream.Position = 4;
            int version = map.BR.ReadInt32();

            // set the halo game type in the map object
            switch (version)
            {
                case 609:
                    map.HaloVersion = HaloVersionEnum.HaloCE;
                    break;
                case 8:
                    map.HaloVersion = HaloVersionEnum.Halo2;
                    map.BR.BaseStream.Position = 0x24;
                    switch (map.BR.ReadInt32())
                    {
                        case -1:
                            map.HaloVersion = HaloVersionEnum.Halo2Vista;
                            break;
                        case 0:
                            map.HaloVersion = HaloVersionEnum.Halo2;
                            break;
                    }
                    break;
                case 5:
                    map.HaloVersion = HaloVersionEnum.Halo1;
                    break;

                    // if we dont support the map, dont open it
                default:
                    MessageBox.Show("This is not a supported map type.");
                    map.CloseMap();
                    return null;
            }

            // read from the map
            map.LoadMap();

            // close file and return map obj
            map.CloseMap();
            return map;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// The build meta.
        /// </summary>
        /// <param name="metasplit">The metasplit.</param>
        /// <param name="map">The map.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static Meta BuildMeta(MetaSplitter metasplit, Map map)
        {
            metasize = 0;
            MetaStream = new MemoryStream(metasplit.Header.chunksize);
            BinaryWriter BW = new BinaryWriter(MetaStream);

            // BW.BaseStream.Position = 0;
            // BW.Write(metasplit.Header.MS.ToArray(), 0, metasplit.Header.chunksize);
            metasize += metasplit.Header.chunksize;

            TagIndex = metasplit.TagIndex;

            Meta m = new Meta(map);

            List<Meta.Item> NewItems = new List<Meta.Item>();

            // Major error here! Size is not calculated right!
            RecursivelyAddPiecesToMeta(metasplit.Header, ref NewItems, ref BW);

            m.items = NewItems;
            if (MetaStream.Length % 4 != 0)
            {
                metasize += (int)MetaStream.Length % 4;
                MetaStream.SetLength(MetaStream.Length + MetaStream.Length % 4);
            }

            m.MS = MetaStream;
            m.size = metasize;
            m.type = metasplit.type;
            m.name = metasplit.name;
            m.rawType = metasplit.rawtype;
            m.raw = metasplit.raw;
            m.magic = metasplit.magic;
            m.offset = metasplit.offset;

            m.TagIndex = TagIndex;
            m.RelinkReferences();
            m.WriteReferences();

            // m.items.Clear();
            // MetaScanner Ms = new MetaScanner();
            if (m.rawType != RawDataContainerType.Empty)
            {
                map.OpenMap(MapTypes.Internal);
                m.raw = map.Functions.ForMeta.ReadRaw(m.TagIndex, false);
                map.CloseMap();
            }

            // map.OpenMap(MapTypes.Internal);
            // IFPIO ifp=IFP.IFPHashMap.GetIfp(m.type);
            // m.parsed = true;
            // Ms.ScanWithIFP(ref ifp, ref m, map) ;
            // map.CloseMap();
            return m;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// reads info from the current open map file and
        /// stores in it this map object
        /// </summary>
        /// <remarks></remarks>
        private void LoadMap()
        {
            switch (HaloVersion)
            {
            case HaloVersionEnum.Halo2:
            {
                MapHeader   = new MapHeaderInfo(ref BR, HaloVersion);
                IndexHeader = new IndexHeaderInfo(ref BR, this);
                MetaInfo    = new ObjectIndexInfo(ref BR, this);
                #region Added for loading of obfuscated maps

                System.Collections.Generic.List <int> offsets = new System.Collections.Generic.List <int>();
                System.Collections.Generic.List <int> indexes = new System.Collections.Generic.List <int>();

                // Obfuscated maps set filename offset to 0 and change all listings to spaces.
                // This point is back to the correct place for starters.
                if (MapHeader.offsetTofileNames == 0)
                {
                    MapHeader.offsetTofileNames = MapHeader.offsetTofileIndex - MapHeader.fileNamesSize;
                    MapHeader.offsetTofileNames = MapHeader.offsetTofileNames - (MapHeader.offsetTofileNames % 64);

                    // All sizes get set to maximum length
                    if (MetaInfo.Size[0] == Int32.MaxValue)
                    {
                        // Sort our meta by offset to start
                        for (int x = 0; x < MapHeader.fileCount; x++)
                        {
                            if (x == 0 || MetaInfo.Offset[x] >= offsets[x - 1])
                            {
                                offsets.Add(MetaInfo.Offset[x]);
                                indexes.Add(x);
                            }
                            else
                            {
                                for (int y = 0; y < x; y++)
                                {
                                    if (MetaInfo.Offset[x] < offsets[y])
                                    {
                                        offsets.Insert(y, MetaInfo.Offset[x]);
                                        indexes.Insert(y, x);
                                        break;
                                    }
                                }
                            }
                        }
                        for (int x = 0; x < MapHeader.fileCount; x++)
                        {
                            if (offsets[x] < 0)
                            {
                                continue;
                            }
                            if (indexes[x] < MapHeader.fileCount - 1)
                            {
                                MetaInfo.Size[indexes[x]] = offsets[x + 1] - offsets[x];
                            }
                            else
                            {
                                MetaInfo.Size[indexes[x]] = this.MapHeader.fileSize - offsets[x];
                            }
                        }
                    }
                }
                #endregion
                FileNames = new FileNamesInfo(ref BR, this);
                Strings   = new StringsInfo(ref BR, this);
                CloseMap();

                Unicode = new UnicodeTableReader(this.filePath, this.MetaInfo.Offset[0]);

                #region Attempt to detect and recover meta tag names from a known good base map

                // If the first two entries both start with our default # sign and offsets has a count, map is probably obfuscated
                if (FileNames.Name[0].StartsWith("#") && FileNames.Name[1].StartsWith("#") && offsets.Count > 0)
                {
                    if (MessageBox.Show("This map may have been obfuscated. Would you like to try to recover names from a map(s)?", "Decode from map(s)?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        OpenFileDialog ofd = new OpenFileDialog();
                        ofd.Filter      = "Map Files|*.map";
                        ofd.Multiselect = true;
                        ofd.Title       = "Select the Clean Base Map for this Map (" + MapHeader.mapName.TrimEnd((char)0) + ")";

                        do
                        {
                            if (ofd.ShowDialog() == DialogResult.OK)
                            {
                                #region Information Form (f) Creation
                                Form f = new Form();
                                f.ControlBox      = false;
                                f.MinimizeBox     = false;
                                f.MaximizeBox     = false;
                                f.FormBorderStyle = FormBorderStyle.FixedSingle;
                                f.Size            = new System.Drawing.Size(700, 60);
                                f.StartPosition   = FormStartPosition.CenterScreen;
                                Label lbl = new Label();
                                lbl.Dock      = DockStyle.Fill;
                                lbl.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                                #endregion
                                f.Show();
                                f.Controls.Add(lbl);

                                foreach (string filename in ofd.FileNames)
                                {
                                    f.Text   = filename;
                                    lbl.Text = "Unknowns remaining: " + indexes.Count.ToString();
                                    f.Focus();
                                    f.Refresh();

                                    // Load clean base map
                                    Map tempMap = Map.LoadFromFile(filename);
                                    if (tempMap == null)
                                    {
                                        continue;
                                    }

                                    /*
                                     * // Match all Idents and use original name
                                     * for (int z = 0; z < tempMap.MetaInfo.Ident.Length; z++)
                                     *  for (int y = 0; y < indexes.Count; y++)
                                     *      if (tempMap.MetaInfo.Ident[z] == MetaInfo.Ident[indexes[y]])
                                     *      {
                                     *          FileNames.Name[indexes[y]] = tempMap.FileNames.Name[z];
                                     *          // No longer need these, so remove to speed up future searches.
                                     *          indexes.RemoveAt(y);
                                     *          offsets.RemoveAt(y);
                                     *          break;
                                     *      }
                                     */

                                    // Match all tags with same length, tag type & name lengths
                                    for (int z = 0; z < tempMap.MetaInfo.Size.Length; z++)
                                    {
                                        for (int y = 0; y < indexes.Count; y++)
                                        {
                                            if (tempMap.MetaInfo.Size[z] == MetaInfo.Size[indexes[y]] &&
                                                tempMap.MetaInfo.TagType[z] == MetaInfo.TagType[indexes[y]] &&
                                                tempMap.FileNames.Name[z].Length == FileNames.Name[indexes[y]].Length)
                                            {
                                                FileNames.Name[indexes[y]] = tempMap.FileNames.Name[z];
                                                // No longer need these, so remove to speed up future searches.
                                                indexes.RemoveAt(y);
                                                offsets.RemoveAt(y);
                                                break;
                                            }
                                        }
                                    }

                                    tempMap.CloseMap();
                                }
                                f.Hide();
                                f.Dispose();
                            }
                            if (indexes.Count > 0)
                            {
                                if (MessageBox.Show("There are still " + indexes.Count.ToString() + " unknowns.\n Would you like to try retrieving data from another map?", "Check another base map?", MessageBoxButtons.YesNo) == DialogResult.No)
                                {
                                    break;
                                }
                            }
                        } while (indexes.Count > 0);

                        // For left-over tags, try something else
                        for (int y = 0; y < indexes.Count; y++)
                        {
                            // Models store the name inside the tag, so at least show that much
                            if (MetaInfo.TagType[indexes[y]] == "mode")
                            {
                                Meta         m  = Map.GetMetaFromTagIndex(indexes[y], this, false, false);
                                BinaryReader br = new BinaryReader(m.MS);
                                br.BaseStream.Position = 0;
                                int SID = br.ReadInt16();
                                br.BaseStream.Position += 1;
                                byte SIDLen = br.ReadByte();
                                if (this.Strings.Length[SID] == SIDLen)
                                {
                                    string name = this.Strings.Name[SID] + "__";
                                    FileNames.Name[indexes[y]] =
                                        FileNames.Name[indexes[y]].Substring(0, 6)
                                        + name
                                        + FileNames.Name[indexes[y]].Remove(0, 6 + name.Length);
                                }
                                m.Dispose();
                                indexes.RemoveAt(y);
                                offsets.RemoveAt(y);
                            }
                        }
                        if (MessageBox.Show("Do you wish to save changes into map now?", "Save changes?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            this.OpenMap(MapTypes.Internal);
                            // Write the proper offset location to the header
                            this.BW.BaseStream.Position = 708;
                            BW.Write(this.MapHeader.offsetTofileNames);
                            // Write the meta tag sizes
                            for (int x = 0; x < this.IndexHeader.metaCount; x++)
                            {
                                BW.BaseStream.Position = this.IndexHeader.tagsOffset + x * 16 + 12;
                                BW.Write(this.MetaInfo.Size[x]);
                            }
                            // Write the names into the file
                            for (int x = 0; x < this.IndexHeader.metaCount; x++)
                            {
                                BW.BaseStream.Position = this.MapHeader.offsetTofileNames + this.FileNames.Offset[x];
                                BW.Write(this.FileNames.Name[x].PadRight(this.FileNames.Length[x], '\0').ToCharArray(), 0, this.FileNames.Length[x]);
                            }
                            this.CloseMap();
                        }
                    }
                }
                #endregion
                break;
            }

            case HaloVersionEnum.Halo2Vista:
            {
                MapHeader   = new MapHeaderInfo(ref BR, HaloVersion);
                IndexHeader = new IndexHeaderInfo(ref BR, this);
                MetaInfo    = new ObjectIndexInfo(ref BR, this);
                FileNames   = new FileNamesInfo(ref BR, this);
                Strings     = new StringsInfo(ref BR, this);
                CloseMap();

                Unicode = new UnicodeTableReader(this.filePath, this.MetaInfo.Offset[0]);

                break;
            }

            case HaloVersionEnum.HaloCE:
            {
                BitmapLibary = new BitmapLibraryLayout(this);
                MapHeader    = new MapHeaderInfo(ref BR, HaloVersion);
                IndexHeader  = new IndexHeaderInfo(ref BR, this);
                MetaInfo     = new ObjectIndexInfo(ref BR, this);
                FileNames    = new FileNamesInfo(ref BR, this);
                this.MapHeader.fileNamesSize     = FileNames.FileNameStringsSize;
                this.MapHeader.offsetTofileNames = FileNames.FileNameStringsOffset;
                break;
            }

            case HaloVersionEnum.Halo1:
            {
                // BitmapLibary = new BitmapLibraryLayout(this);
                MapHeader   = new MapHeaderInfo(ref BR, HaloVersion);
                IndexHeader = new IndexHeaderInfo(ref BR, this);
                MetaInfo    = new ObjectIndexInfo(ref BR, this);
                FileNames   = new FileNamesInfo(ref BR, this);
                this.MapHeader.fileNamesSize     = FileNames.FileNameStringsSize;
                this.MapHeader.offsetTofileNames = FileNames.FileNameStringsOffset;
                break;
            }
            }

            switch (HaloVersion)
            {
            case HaloVersionEnum.Halo2:
            case HaloVersionEnum.Halo2Vista:
                ugh_.GetUghContainerInfo(this);
                this.BSP = new BSPContainer(this);

                break;

            case HaloVersionEnum.Halo1:
            case HaloVersionEnum.HaloCE:
                this.BSP = new BSPContainer(this);
                break;
            }

            DisplayType = Meta.ItemType.Reflexive;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// The save to xml.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void SaveToXml(string path, Map map)
        {
            XmlTextWriter xtw = new XmlTextWriter(path, Encoding.Default);
            xtw.Formatting = Formatting.Indented;
            xtw.WriteStartElement("MapLayOut");
            xtw.WriteAttributeString("Map", map.filePath);
            int tempindex = path.LastIndexOf("\\");
            string tempfilepath = path.Substring(0, tempindex) + "\\" +
                                  path.Substring(tempindex + 1, path.Length - tempindex - 1) + " - Meta Chunks\\";
            Directory.CreateDirectory(tempfilepath);
            map.OpenMap(MapTypes.Internal);
            for (int x = 0; x < chunks.Count; x++)
            {
                LayOutChunk c = (LayOutChunk)chunks[x];

                // c.Read(map);
                FileStream FS = new FileStream(
                    tempfilepath + "MapMetaChunk[" + x + "] - " + c.rawType + ".meta", FileMode.Create);
                BinaryWriter BW = new BinaryWriter(FS);

                // BW.Write(c.MS.ToArray());
                // c.Write(BW, 0);
                map.BR.BaseStream.Position = c.startoffset;
                map.BufferReadWrite(ref map.BR, ref BW, c.size);
                BW.Close();
                FS.Close();

                xtw.WriteStartElement("LayOutChunk");
                xtw.WriteAttributeString("Type", c.rawType.ToString());
                xtw.WriteAttributeString("StartOffset", c.startoffset.ToString("X"));
                xtw.WriteAttributeString("EndOffset", c.endoffset.ToString("X"));
                xtw.WriteAttributeString("Size", c.size.ToString("X"));

                for (int xx = 0; xx < c.rawPieces.Count; xx++)
                {
                    RawInfoChunk cc = (RawInfoChunk)c.rawPieces[xx];
                    xtw.WriteStartElement("RawDataPiece");
                    xtw.WriteAttributeString("Type", cc.rawType.ToString());
                    xtw.WriteAttributeString("Offset", cc.offset.ToString("X"));
                    xtw.WriteAttributeString("Size", cc.size.ToString("X"));
                    xtw.WriteAttributeString("PointerOffset", cc.offsetOfPointer.ToString("X"));
                    xtw.WriteEndElement();
                }

                xtw.WriteEndElement();
            }

            xtw.WriteEndElement();
            xtw.Close();
            map.CloseMap();
        }
Ejemplo n.º 17
0
        private bool loadMainMenuData(string mainmenuFileName)
        {
            this.Cursor = Cursors.WaitCursor;
            if (map != null)
            {
                map.CloseMap();
                map = null;
            }
            map = Map.LoadFromFile(mainmenuFileName);
            if (map == null)
            {
                this.Cursor = Cursors.Arrow;
                MessageBox.Show("Load failed! Map not found or inaccessible.\n" + mainmenuFileName);
                return false;
            }

            cbBitmapIdent.DataSource = null;
            cbBitmapIdent.Items.Clear();
            cbBitmapIdent.Items.Add(new baseData(0));
            ((baseData)cbBitmapIdent.Items[0]).title = "<null>";
            int orderCount = 0;
            for (int i = 0; i < map.FileNames.Name.Length; i++)
            {
                if (map.MetaInfo.TagType[i] == "bitm")
                {
                    baseData sd = new baseData(++orderCount);
                    sd.offset = i;
                    sd.title = map.FileNames.Name[i];
                    cbBitmapIdent.Items.Add(sd);
                }
            }

            Meta meta;
            
            // Get the tag index for [matg] globals\\globals
            int matgIndex = map.Functions.ForMeta.FindByNameAndTagType("matg", "globals\\globals");
            meta = Map.GetMetaFromTagIndex(matgIndex, map, false, true);
            br = new BinaryReader(meta.MS);

            br.BaseStream.Position = 272;
            int interfaceItemCount = br.ReadInt32();
            int interfaceItemOffset = br.ReadInt32() - map.SecondaryMagic - meta.offset;

            br.BaseStream.Position = interfaceItemOffset + 128;
            // Mainmenu Menus (Exists in Mainmenu.map)
            char[] wgtzMMTag = br.ReadChars(4);
            int wgtzMMIdent = br.ReadInt32();
            // Single Player Menus (Exists in Shared / SPShared.map)
            char[] wgtzSPTag = br.ReadChars(4);
            int wgtzSPIdent = br.ReadInt32();
            // Multiplayer Menus (Exists in Shared / SPShared.map)
            char[] wgtzMPTag = br.ReadChars(4);
            int wgtzMPIdent = br.ReadInt32();

            int tagIndex = -1;
            // Get the tag index for [wgtz] ui\\main_menu
            if (wgtzMMIdent != -1)
                tagIndex = (int)map.MetaInfo.identHT[wgtzMMIdent];
            else if (wgtzSPIdent != -1)
                tagIndex = (int)map.MetaInfo.identHT[wgtzSPIdent];
            else if (wgtzMPIdent != -1)
                tagIndex = (int)map.MetaInfo.identHT[wgtzMPIdent];
            //int tagIndex = map.Functions.ForMeta.FindByNameAndTagType("wgtz", "ui\\main_menu");
            if (tagIndex == -1)
            {
                map.CloseMap();
                map = null;
                this.Cursor = Cursors.Arrow;
                MessageBox.Show("Load failed! Not a MAINMENU.MAP / SHARED.MAP / SPSHARED.MAP file.\n" + mainmenuFileName);
                return false;
            }

            // [wgzt] ui\\main_menu meta
            meta = Map.GetMetaFromTagIndex(tagIndex, map, false, true);
            br = new BinaryReader(meta.MS);

            #region Skins List Loading Section
            br.BaseStream.Position = 0;
            char[] wiglTag = br.ReadChars(4); 
            int wiglIdent = br.ReadInt32();

            // Should be "ui\ui_shared_globals" by default
            int tagNum = (int)map.MetaInfo.identHT[wiglIdent];
            Meta metaSG = Map.GetMetaFromTagIndex(tagNum, map, false, true);
            BinaryReader brSG = new BinaryReader(metaSG.MS);

            // Get the default header font number
            brSG.BaseStream.Position = 352;
            defaultHeaderFont = brSG.ReadInt16();
            
            // Get the default position of the header text
            brSG.BaseStream.Position = 376;
            short dhTop = brSG.ReadInt16();
            short dhLeft = brSG.ReadInt16();
            short dhBottom = brSG.ReadInt16();
            short dhRight = brSG.ReadInt16();
            defaultHeaderPos = new Rectangle(dhLeft, dhTop, dhRight-dhLeft, dhBottom-dhTop);

            // Get the skin data
            brSG.BaseStream.Position = 312;
            int listItemCount = brSG.ReadInt32();
            int listItemOffset = brSG.ReadInt32() - map.SecondaryMagic - metaSG.offset;

            for (int list = 0; list < listItemCount; list++)
            {
                brSG.BaseStream.Position = listItemOffset + list * 8;
                char[] skinTag = brSG.ReadChars(4);
                int skinIdent = brSG.ReadInt32();

                tagNum = (int)map.MetaInfo.identHT[skinIdent];
                string[] tagData = map.FileNames.Name[tagNum].Split('\\');

                skinData sd = new skinData();
                sd.offset = 0;
                sd.title = "[" + list.ToString("00") + "] " + tagData[tagData.Length - 1];
                sd.meta = Map.GetMetaFromTagIndex(tagNum, map, false, true);
                
                sd.skin  = new Skin(map, skinIdent);

                cbLBSkinIdent.Items.Add(sd);
            }

            #endregion

            #region Graphics Loading Section

            // Load Mainmenu screens tag
            // Offset 8 = Screen Widgets refelxive
            br.BaseStream.Position = 8;
            int screenCount = br.ReadInt32(); // Number of screen widgets
            int screenOffset = br.ReadInt32() - map.SecondaryMagic - meta.offset;

            // Release any memory from previously loaded menus (if any)
            //foreach(screenData sd in lbScreensList.Items)
            //    sd.meta.Dispose();
            //lbScreensList.Items.Clear();

            foreach (screenData sd in screens)
                sd.meta.Dispose();
            screens.Clear();

            // For each tag/ident screen widget entry in [wgzt] ui\\main_menu...
            for (int screen = 0; screen < screenCount; screen++)
            {
                // Offset 0 in each reflexive listing points to screen widget
                br.BaseStream.Position = screenOffset + screen * 8;
                char[] wgitTag = br.ReadChars(4);
                int wgitIdent = br.ReadInt32();

                // Retrieve the screen widget Tag Index & name and read in the [wigt] meta
                // These are all stored into the lbScreenList list box items
                tagNum = (int)map.MetaInfo.identHT[wgitIdent];
                string[] tagData = map.FileNames.Name[tagNum].Split('\\');
                screenData sd = new screenData(screen);
                sd.offset = 0;
                sd.title = tagData[tagData.Length - 1];
                sd.meta = Map.GetMetaFromTagIndex(tagNum, map, false, true);
                sd.meta.MS.Position = 0;
                sd.Read(new BinaryReader(sd.meta.MS));
                sd.getStrings(map);

                //lbScreensList.Items.Add(sd);
                screens.Add(sd);
            }

            //screens.Sort();
            
            lbScreensList.DataSource = screens;
            // Actually update ListBox with data source
            ((CurrencyManager)lbScreensList.BindingContext[lbScreensList.DataSource]).Refresh();
            if (lbScreensList.Items.Count > 0)
            {
                lbScreensList.SelectedIndex = 0;
                // Make sure this is called to update the Panes ListBox on reload
                lbScreensList_SelectedIndexChanged(this, null);
            }
            #endregion

            //br.Close();        

            this.Cursor = Cursors.Arrow;
            return true;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// The halo 2 bsp container.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void Halo2BSPContainer(Map map)
        {
            map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 528;
            bspcount = map.BR.ReadInt32();
            int tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            sbsp = new BSPInfo[bspcount];
            for (int x = 0; x < bspcount; x++)
            {
                sbsp[x] = new BSPInfo();
                sbsp[x].pointerOffset = tempr + (x * 68) - map.MetaInfo.Offset[3];
                map.BR.BaseStream.Position = tempr + (x * 68);
                sbsp[x].offset = map.BR.ReadInt32();
                map.Functions.ParsePointer(ref sbsp[x].offset, ref sbsp[x].location);
                sbsp[x].size = map.BR.ReadInt32();
                sbsp[x].magic = map.BR.ReadInt32() - sbsp[x].offset;
                map.BR.BaseStream.Position = tempr + (x * 68) + 20;
                sbsp[x].ident = map.BR.ReadInt32();

                // 	MessageBox.Show(sbsp[x].ident.ToString("X"));
                sbsp[x].TagIndex = map.Functions.ForMeta.FindMetaByID(sbsp[x].ident);
                map.MetaInfo.Offset[sbsp[x].TagIndex] = sbsp[x].offset;
                map.MetaInfo.Size[sbsp[x].TagIndex] = sbsp[x].size;
                map.BR.BaseStream.Position = tempr + (x * 68) + 28;
                sbsp[x].lightmapident = map.BR.ReadInt32();
                sbsp[x].lightmapTagIndex = map.Functions.ForMeta.FindMetaByID(sbsp[x].lightmapident);
                if (sbsp[x].lightmapTagIndex == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = sbsp[x].offset + 8;
                sbsp[x].lightmapoffset = map.BR.ReadInt32();
                if (sbsp[x].lightmapoffset == 0)
                {
                    sbsp[x].lightmapident = -1;
                    sbsp[x].lightmapTagIndex = -1;
                    if (
                        MessageBox.Show(
                            "There is no lightmap for this bsp and the scenario is currently linked to a broken ID.\n Would you like Entity to fix it?",
                            "Error",
                            MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        map.BW.BaseStream.Position = tempr + (x * 68) + 28;
                        map.BW.Write(int.Parse("FFFFFFFF", NumberStyles.HexNumber));
                    }

                    continue;
                }

                sbsp[x].lightmapoffset += -sbsp[x].magic;
                sbsp[x].lightmapsize = sbsp[x].size + sbsp[x].offset - sbsp[x].lightmapoffset;

                map.MetaInfo.Offset[sbsp[x].lightmapTagIndex] = sbsp[x].lightmapoffset;
                map.MetaInfo.Size[sbsp[x].lightmapTagIndex] = sbsp[x].lightmapsize;

                // light map bitmap
                map.BR.BaseStream.Position = sbsp[x].lightmapoffset + 128;
                int tempc = map.BR.ReadInt32();
                int temprx = map.BR.ReadInt32() - sbsp[x].magic;
                map.BR.BaseStream.Position = temprx + 28;
                sbsp[x].LightMap_TagNumber = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                ///light map palettes
                map.BR.BaseStream.Position = temprx + 8;
                int tempc2 = map.BR.ReadInt32();
                int tempr2 = map.BR.ReadInt32() - sbsp[x].magic;
                sbsp[x].palettesoffset = tempr2;
                for (int y = 0; y < tempc2; y++)
                {
                    map.BR.BaseStream.Position = tempr2 + (y * 1024);
                    Palette_Color[] pc = new Palette_Color[256];
                    for (int z = 0; z < 256; z++)
                    {
                        pc[z] = new Palette_Color();
                        pc[z].r = map.BR.ReadByte();
                        pc[z].g = map.BR.ReadByte();
                        pc[z].b = map.BR.ReadByte();
                        pc[z].a = map.BR.ReadByte();
                    }

                    sbsp[x].LightMap_Palettes.Add(pc);
                }

                map.BR.BaseStream.Position = temprx + 40;
                tempc2 = map.BR.ReadInt32();
                tempr2 = map.BR.ReadInt32() - sbsp[x].magic;
                sbsp[x].VisualChunk_Bitmap_Index = new int[tempc2];
                sbsp[x].VisualChunk_LightMap_Index = new int[tempc2];

                if (tempc2 != 0)
                {
                    map.BR.BaseStream.Position = tempr2;
                    for (int y = 0; y < tempc2; y++)
                    {
                        sbsp[x].VisualChunk_Bitmap_Index[y] = map.BR.ReadInt16();
                        sbsp[x].VisualChunk_LightMap_Index[y] = map.BR.ReadInt16();
                    }
                }

                map.BR.BaseStream.Position = temprx + 72;
                tempc2 = map.BR.ReadInt32();
                tempr2 = map.BR.ReadInt32() - sbsp[x].magic;
                sbsp[x].SceneryChunk_Bitmap_Index = new int[tempc2];
                sbsp[x].SceneryChunk_LightMap_Index = new int[tempc2];

                if (tempc2 > 0)
                {
                    map.BR.BaseStream.Position = tempr2;
                    for (int y = 0; y < tempc2; y++)
                    {
                        sbsp[x].SceneryChunk_Bitmap_Index[y] = map.BR.ReadInt16();
                        sbsp[x].SceneryChunk_LightMap_Index[y] = map.BR.ReadInt16();
                    }
                }
            }

            map.CloseMap();
        }
Ejemplo n.º 19
0
        /// <summary>
        /// The scan map for lay out.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="addexternalchunks">The addexternalchunks.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public MapLayout ScanMapForLayOut(Map map, bool addexternalchunks)
        {
            MapLayout layout = new MapLayout();

            for (int x = 0; x < map.BSP.sbsp.Length; x++)
            {
                LayOutChunk l = new LayOutChunk(0);
                l.rawType = RawDataContainerType.BSPMeta;
                l.startoffset = map.BSP.sbsp[x].offset;
                l.endoffset = map.BSP.sbsp[x].offset + map.BSP.sbsp[x].size;
                l.size = map.BSP.sbsp[x].size;
                layout.chunks.Add(l);
            }

            LayOutChunk lo = new LayOutChunk(0);
            lo.rawType = RawDataContainerType.Header;
            lo.startoffset = 0;
            lo.size = 2048;
            lo.endoffset = lo.startoffset + lo.size;
            layout.chunks.Add(lo);

            if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                map.HaloVersion == HaloVersionEnum.Halo2Vista)
            {
                lo = new LayOutChunk(0);
                lo.rawType = RawDataContainerType.StringsIndex;
                lo.startoffset = map.MapHeader.offsetToStringIndex;
                lo.size = map.MapHeader.scriptReferenceCount * 4;
                lo.size += map.Functions.Padding(lo.size, 512);
                lo.endoffset = lo.startoffset + lo.size;
                layout.chunks.Add(lo);

                lo = new LayOutChunk(0);
                lo.rawType = RawDataContainerType.Strings1;
                lo.startoffset = map.MapHeader.offsetToStringNames1;
                lo.size = map.MapHeader.scriptReferenceCount * 128;
                lo.size += map.Functions.Padding(lo.size, 512);
                lo.endoffset = lo.startoffset + lo.size;
                layout.chunks.Add(lo);

                lo = new LayOutChunk(0);
                lo.rawType = RawDataContainerType.Strings2;
                lo.startoffset = map.MapHeader.offsetToStringNames2;
                lo.size = map.MapHeader.sizeOfScriptReference;
                lo.size += map.Functions.Padding(lo.size, 512);
                lo.endoffset = lo.startoffset + lo.size;
                layout.chunks.Add(lo);

                lo = new LayOutChunk(0);
                lo.rawType = RawDataContainerType.Crazy;
                lo.startoffset = map.MapHeader.offsetToCrazy;
                lo.size = map.MapHeader.sizeOfCrazy;
                lo.size += map.Functions.Padding(lo.size, 512);
                lo.endoffset = lo.startoffset + lo.size;
                layout.chunks.Add(lo);

                lo = new LayOutChunk(0);
                lo.rawType = RawDataContainerType.FileNamesIndex;
                lo.startoffset = map.MapHeader.offsetTofileIndex;
                lo.size = map.MapHeader.fileCount * 4;
                lo.size += map.Functions.Padding(lo.size, 512);
                lo.endoffset = lo.startoffset + lo.size;
                layout.chunks.Add(lo);
            }

            lo = new LayOutChunk(0);
            lo.rawType = RawDataContainerType.FileNames;
            lo.startoffset = map.MapHeader.offsetTofileNames;
            lo.size = map.MapHeader.fileNamesSize;
            if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                map.HaloVersion == HaloVersionEnum.Halo2Vista)
            {
                lo.size += map.Functions.Padding(lo.size, 512);
            }

            lo.endoffset = lo.startoffset + lo.size;
            layout.chunks.Add(lo);

            lo = new LayOutChunk(0);
            lo.rawType = RawDataContainerType.MetaIndex;
            lo.startoffset = map.MapHeader.indexOffset;
            if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                map.HaloVersion == HaloVersionEnum.Halo2Vista)
            {
                lo.size = map.MapHeader.metaStart;
                lo.size += map.Functions.Padding(lo.size, 512);

                // map.MapHeader.fileSize - map.MapHeader.indexOffset;
            }
            else
            {
                lo.size = map.MapHeader.offsetTofileNames - map.MapHeader.indexOffset;

                // map.MetaInfo.Offset[map.IndexHeader.metaCount - 1] + map.MetaInfo.Size[map.IndexHeader.metaCount-1];
            }

            lo.endoffset = lo.startoffset + lo.size;
            layout.chunks.Add(lo);

            lo = new LayOutChunk(0);
            lo.rawType = RawDataContainerType.MetaData;
            lo.startoffset = map.MetaInfo.Offset[0];

            // How can you adjust for padding past the end of the file???
            lo.size = map.MapHeader.fileSize - lo.startoffset;
            if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                map.HaloVersion == HaloVersionEnum.Halo2Vista)
            {
                int padding = map.Functions.Padding(lo.startoffset + lo.size, 4096);
                lo.size += padding;
            }

            lo.endoffset = lo.startoffset + lo.size;
            layout.chunks.Add(lo);

            if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                map.HaloVersion == HaloVersionEnum.Halo2Vista)
            {
                for (int x = 0; x < map.Unicode.ut.Length; x++)
                {
                    lo = new LayOutChunk(0);
                    lo.rawType = RawDataContainerType.UnicodeNamesIndex;
                    lo.startoffset = map.Unicode.ut[x].indexOffset;
                    lo.size = map.Unicode.ut[x].count * 8;
                    lo.size += map.Functions.Padding(lo.size, 512);
                    lo.endoffset = lo.startoffset + lo.size;
                    layout.chunks.Add(lo);

                    lo = new LayOutChunk(0);
                    lo.rawType = RawDataContainerType.UnicodeNames;
                    lo.startoffset = map.Unicode.ut[x].tableOffset;
                    lo.size = map.Unicode.ut[x].tableSize;
                    lo.size += map.Functions.Padding(lo.size, 512);
                    lo.endoffset = lo.startoffset + lo.size;
                    layout.chunks.Add(lo);
                }
            }

            map.OpenMap(MapTypes.Internal);
            for (int x = 0; x < map.IndexHeader.metaCount; x++)
            {
                if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                    map.HaloVersion == HaloVersionEnum.Halo2Vista)
                {
                    if (map.MetaInfo.TagType[x] == "snd!" | map.MetaInfo.TagType[x] == "ltmp")
                    {
                        continue;
                    }

                    Application.DoEvents();
                }

                Meta m = new Meta(map);
                m.offset = map.MetaInfo.Offset[x];

                // checks if type has raw data
                m.rawType = map.Functions.ForMeta.CheckForRaw(map.MetaInfo.TagType[x]);

                if (m.rawType != RawDataContainerType.Empty)
                {
                    m.raw = map.Functions.ForMeta.ReadRaw(x, true);
                    LayOutChunk l = new LayOutChunk(map.MapHeader.fileSize);

                    int tempint = layout.FindByType(m.rawType);
                    if (tempint == -1)
                    {
                        l = new LayOutChunk(map.MapHeader.fileSize);
                        l.rawType = m.rawType;
                        layout.chunks.Add(l);
                        tempint = layout.FindByType(m.rawType);
                    }
                    else
                    {
                        l = (LayOutChunk)layout.chunks[tempint];
                    }

                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        RawDataChunk r = m.raw.rawChunks[y];
                        if (r.offset == -1)
                        {
                            continue;
                        }

                        if (r.rawLocation == MapTypes.Internal)
                        {
                            RawInfoChunk tempr = new RawInfoChunk();
                            tempr.offset = (uint)r.offset;
                            tempr.size = r.size;
                            tempr.rawType = r.rawDataType;
                            tempr.location = r.rawLocation;
                            tempr.offsetOfPointer = m.offset + r.pointerMetaOffset;
                            l.rawPieces.Add(tempr);
                        }
                        else if (addexternalchunks)
                        {
                            RawInfoChunk tempr = new RawInfoChunk();
                            tempr.offset = (uint)r.offset;
                            tempr.size = r.size;
                            tempr.rawType = r.rawDataType;
                            tempr.location = r.rawLocation;
                            tempr.offsetOfPointer = m.offset + r.pointerMetaOffset;
                            l.rawPieces.Add(tempr);
                        }

                        if (r.offset < l.startoffset && r.rawLocation == MapTypes.Internal)
                        {
                            l.startoffset = r.offset;
                            l.size = l.endoffset - l.startoffset;
                            layout.chunks[tempint] = l;
                        }

                        if (r.offset + r.size > l.endoffset && r.rawLocation == MapTypes.Internal)
                        {
                            l.endoffset = r.offset + r.size;
                            l.endoffset += map.Functions.Padding(l.endoffset, 512);
                            l.size = l.endoffset - l.startoffset;
                            layout.chunks[tempint] = l;
                        }
                    }
                }

                m = null;
                GC.WaitForPendingFinalizers();

                // GC.Collect();
            }

            map.CloseMap();

            if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                map.HaloVersion == HaloVersionEnum.Halo2Vista)
            {
                lo = new LayOutChunk(0);
                LayOutChunk templo = (LayOutChunk)layout.chunks[layout.FindByType(RawDataContainerType.Model)];
                lo.rawType = RawDataContainerType.Sound;
                lo.startoffset = 2048;
                lo.size = templo.startoffset - 2048;
                lo.size += map.Functions.Padding(lo.size, 512);
                lo.endoffset = lo.startoffset + lo.size;
                layout.chunks.Add(lo);
            }

            for (int y = 0; y < layout.chunks.Count; y++)
            {
                LayOutChunk l = (LayOutChunk)layout.chunks[y];
                if (l.size == 0)
                {
                    layout.chunks.RemoveAt(y);
                    y--;
                }
            }

            layout.SortChunksByOffset();
            layout.SortRawByOffset();

            return layout;
        }
Ejemplo n.º 20
0
        /// <summary>
        /// The over write.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="tagIndex">Index of the tag.</param>
        /// <param name="newMeta">The new meta.</param>
        /// <remarks></remarks>
        public static void OverWrite(Map map, int tagIndex, ref Meta newMeta)
        {
            TagIndex = tagIndex;
            if (map.MetaInfo.TagType[tagIndex] == "sbsp")
            {
                MessageBox.Show("Can't OverWrite The Bsp");
                return;
            }

            newMeta.RelinkReferences();
            ArrayList metas = new ArrayList(0);
            map.OpenMap(MapTypes.Internal);
            for (int x = 0; x < map.IndexHeader.metaCount; x++)
            {
                if (tagIndex == x)
                {
                    newMeta.type = map.MetaInfo.TagType[x];
                    newMeta.name = map.FileNames.Name[x];
                    SizeOfShift = newMeta.size - map.MetaInfo.Size[x];
                    metas.Add(newMeta);
                    continue;
                }

                Meta m = new Meta(map);
                m.ReadMetaFromMap(x, true);
                try
                {
                    IFPIO ifpx = IFPHashMap.GetIfp(m.type, map.HaloVersion);

                    m.headersize = ifpx.headerSize;
                    m.scanner.ScanWithIFP(ref ifpx);

                    // metaScanner.ScanManually(ref m, ref map);
                    metas.Add(m);
                }
                catch (System.Exception ex)
                {
                    Globals.Global.ShowErrorMsg(string.Empty, ex);
                }

            }

            FixReflexives(metas, map);
            map.CloseMap();
        }
Ejemplo n.º 21
0
        /// <summary>
        /// The h 2 spawn info.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void H2SpawnInfo(Map map)
        {
            map.OpenMap(MapTypes.Internal);

            // find default mc model
            map.BR.BaseStream.Position = map.MetaInfo.Offset[0] + 308;
            int tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            map.BR.BaseStream.Position = tempr + 4;
            int tempbipdtag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
            //map.CloseMap();
            int bipdmodeltag = map.Functions.FindModelByBaseClass(tempbipdtag);

            // Find objective models
            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position =
                map.MetaInfo.Offset[
                    map.Functions.ForMeta.FindByNameAndTagType("mulg", "multiplayer\\multiplayer_globals")] + 12;
            tempr = map.BR.ReadInt32();
            int ctfmodeltag = -1;
            int ballmodeltag = -1;
            int juggernautdmodeltag = -1;
            int assultmodeltag = -1;
            if (tempr != 0)
            {
                tempr -= map.SecondaryMagic;
                map.BR.BaseStream.Position = tempr + 4;
                int tempCtftag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                map.BR.BaseStream.Position = tempr + 12;
                int tempBalltag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                map.BR.BaseStream.Position = tempr + 36;
                int tempHillShader = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                // I believe the Hill Shader above is not used, but just in case. Otherwise, load the usual one below
                if (tempHillShader == -1)
                {
                    map.BR.BaseStream.Position = tempr + 1332;
                    int tempr2 = map.BR.ReadInt32();
                    if (tempr2 != 0)
                    {
                        tempr2 -= map.SecondaryMagic;
                        map.BR.BaseStream.Position = tempr2 + 196;
                        tempHillShader = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    }
                }

                map.BR.BaseStream.Position = tempr + 52;
                int tempJuggernauttag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                map.BR.BaseStream.Position = tempr + 60;
                int tempAssaulttag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();

                ctfmodeltag = map.Functions.FindModelByBaseClass(tempCtftag);
                ballmodeltag = map.Functions.FindModelByBaseClass(tempBalltag);

                // *** This is not right. It's a shader, not a model. But I don't know how to display a shader...
                hillshadertag = map.Functions.ForMeta.FindMetaByID(tempHillShader);

                juggernautdmodeltag = map.Functions.FindModelByBaseClass(tempJuggernauttag);
                assultmodeltag = map.Functions.FindModelByBaseClass(tempAssaulttag);
            }

            #region //// Player Spawns ////

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 256;
            int tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (52 * x);

                PlayerSpawn ps = new PlayerSpawn();
                ps.offset = tempr + (52 * x);
                ps.X = map.BR.ReadSingle();
                ps.Y = map.BR.ReadSingle();
                ps.Z = map.BR.ReadSingle();
                ps.RotationDirection = map.BR.ReadSingle();
                ps.ModelTagNumber = bipdmodeltag;
                ps.ModelName = map.FileNames.Name[ps.ModelTagNumber];

                Spawn.Add(ps);
            }

            #endregion

            #region //// death zones ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 264;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < tempc; x++)
            {
                DeathZone ps = new DeathZone();

                // Load the deathzone name
                map.BR.BaseStream.Position = tempr + (68 * x);
                ps.Name = map.Strings.Name[map.BR.ReadInt16()];

                // We set the offset to 36 b/c we don't care about saving the name... right now anyways.
                ps.offset = tempr + (68 * x) + 36;

                // Load the deathzone coordinates
                map.BR.BaseStream.Position = tempr + (68 * x) + 36;
                ps.X = map.BR.ReadSingle();
                ps.Y = map.BR.ReadSingle();
                ps.Z = map.BR.ReadSingle();

                // Use ABS() to make sure our sizes are always positive
                ps.width = Math.Abs(map.BR.ReadSingle());
                ps.height = Math.Abs(map.BR.ReadSingle());
                ps.length = Math.Abs(map.BR.ReadSingle());

                // Deathzones are saved with a centre point and Width, Length, Height
                ps.X += ps.width / 2;
                ps.Y += ps.height / 2;
                ps.Z += ps.length / 2;

                Spawn.Add(ps);
            }

            #endregion

            #region //// lights ////

            //// palette ////
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 240;
            int[] temppalette = new int[map.BR.ReadInt32()];
            int[] temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                temppalette2[x] = tempbase;
                temppalette[x] = tempbase;
            }

            //// placement ////
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 232;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (108 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (108 * x) + 8;
                LightSpawn vs = new LightSpawn();
                vs.offset = tempr + (108 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// sounds ////

            //// Sound Scenery palette ////
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 224;

            // temppalette variables declared in Lights section above
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                temppalette2[x] = tempbase;
                temppalette[x] = tempbase;
            }

            //// placement ////
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 216;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (80 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                SoundSpawn vs = new SoundSpawn();

                map.BR.BaseStream.Position = tempr + (80 * x) + 8;
                vs.offset = tempr + (80 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                map.BR.BaseStream.Position = tempr + (80 * x) + 54;
                vs.VolumeType = map.BR.ReadInt16();
                vs.Height = map.BR.ReadSingle();
                vs.DistanceBoundsLower = map.BR.ReadSingle();
                vs.DistanceBoundsUpper = map.BR.ReadSingle();
                vs.ConeAngleLower = map.BR.ReadSingle();
                vs.ConeAngleUpper = map.BR.ReadSingle();
                vs.OuterConeGain = map.BR.ReadSingle();

                if (temppalette2[tempshort] == -1)
                {
                    vs.TagPath = "Nulled Out";
                }
                else
                {
                    vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                }

                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    // { continue; }
                    vs.ModelName = null;
                }
                else
                {
                    vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                }

                Spawn.Add(vs);
            }

            #endregion

            #region //// objectives ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 280;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < tempc; x++)
            {
                ObjectiveSpawn ps = new ObjectiveSpawn();
                ps.offset = tempr + (32 * x);
                map.BR.BaseStream.Position = tempr + (32 * x);
                ps.X = map.BR.ReadSingle();
                ps.Y = map.BR.ReadSingle();
                ps.Z = map.BR.ReadSingle();
                ps.RotationDirection = map.BR.ReadSingle();
                ps.ObjectiveType = (ObjectiveSpawn.ObjectiveTypeEnum)map.BR.ReadInt16();
                ps.Team = (ObjectiveSpawn.TeamType)map.BR.ReadInt16();
                ps.number = map.BR.ReadInt16();

                if (ps.ObjectiveType == ObjectiveSpawn.ObjectiveTypeEnum.OddballSpawn && ballmodeltag != -1)
                {
                    ps.ModelTagNumber = ballmodeltag;
                }
                else if (ps.ObjectiveType == ObjectiveSpawn.ObjectiveTypeEnum.CTFRespawn && ctfmodeltag != -1)
                {
                    ps.ModelTagNumber = ctfmodeltag;
                }
                else if (
                    ps.ObjectiveType.ToString().StartsWith(
                        ObjectiveSpawn.ObjectiveTypeEnum.KingOfTheHill_1.ToString().Substring(0, 13)) &&
                    ctfmodeltag != -1)
                {
                    ps.ModelTagNumber = ctfmodeltag;
                }
                else if (ps.ObjectiveType == ObjectiveSpawn.ObjectiveTypeEnum.AssaultRespawn && assultmodeltag != -1)
                {
                    ps.ModelTagNumber = assultmodeltag;
                }
                else
                {
                    ps.ModelTagNumber = bipdmodeltag;
                }

                ps.ModelName = map.FileNames.Name[ps.ModelTagNumber];
                Spawn.Add(ps);
            }

            #endregion

            #region //// vehicles ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 120;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 112;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (84 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (84 * x) + 8;
                VehicleSpawn vs = new VehicleSpawn();
                vs.offset = tempr + (84 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// equipment ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 136;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 128;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (56 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (56 * x) + 8;
                EquipmentSpawn vs = new EquipmentSpawn();
                vs.offset = tempr + (56 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();

                // vs.RotationDirection = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// bipeds ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 104;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 96;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (84 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (84 * x) + 8;
                BipedSpawn vs = new BipedSpawn();
                vs.offset = tempr + (84 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// control ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 192;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 184;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (68 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (68 * x) + 8;
                ControlSpawn vs = new ControlSpawn();
                vs.offset = tempr + (68 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();

                // vs.RotationDirection = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// machines ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 176;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 168;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (72 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (72 * x) + 8;
                MachineSpawn vs = new MachineSpawn();
                vs.offset = tempr + (72 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                if (temppalette2[tempshort] == -1 || temppalette[tempshort] == -1)
                {
                    continue;
                }

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// scenery ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 88;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 80;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (92 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (92 * x) + 8;
                ScenerySpawn vs = new ScenerySpawn();
                vs.offset = tempr + (92 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                if (temppalette2[tempshort] == -1 || temppalette[tempshort] == -1)
                {
                    continue;
                }

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// weapons ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 152;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 144;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (84 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (84 * x) + 8;
                WeaponSpawn vs = new WeaponSpawn();
                vs.offset = tempr + (84 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// obstacles ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 816;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 808;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (76 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (76 * x) + 8;
                ObstacleSpawn vs = new ObstacleSpawn();
                vs.offset = tempr + (76 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                if (temppalette2[tempshort] == -1)
                {
                    continue;
                }

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// collections ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 288;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                Collection vs = new Collection();
                map.BR.BaseStream.Position = tempr + (144 * x) + 4;
                vs.SpawnsInMode = (Collection.SpawnsInEnum)map.BR.ReadInt32();

                // Why do they make the offset + 64? That just confuses stuff!!
                map.BR.BaseStream.Position = tempr + (144 * x) + 64;
                vs.offset = tempr + (144 * x) + 64;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();

                // test
                // if (vs.Pitch > 0) { vs.Pitch = -vs.Pitch; vs.isWeird = true; } else { vs.isWeird = false; }
                map.BR.BaseStream.Position = tempr + (144 * x) + 88;

                // ID Type
                char[] c = map.BR.ReadChars(4);
                vs.TagType = c[3].ToString() + c[2] + c[1] + c[0];

                // Tag Path ID
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                if (tempbase == -1)
                {
                    continue;
                }

                //map.CloseMap();
                vs.TagPath = map.FileNames.Name[tempbase];
                vs.ModelTagNumber = map.Functions.FindModelByBaseClass(tempbase);
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// cameras ////

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 488;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                CameraSpawn vs = new CameraSpawn();
                map.BR.BaseStream.Position = tempr + (64 * x) + 36;
                vs.offset = tempr + (64 * x) + 36;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.fov = map.BR.ReadSingle();
                vs.ModelTagNumber = -1;

                Spawn.Add(vs);
            }

            #endregion

            #region //// AI_Squads ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 376;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                map.BR.BaseStream.Position = tempr + (x * 8) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            // Reading ai squads reflexive
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 352;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                // Reads AI Squad palette chunk
                map.BR.BaseStream.Position = tempr + (x * 116) + 54;
                short charNum = map.BR.ReadInt16();

                // Reading locations sub reflexive
                map.BR.BaseStream.Position = tempr + 72;
                int locc = map.BR.ReadInt32();
                int locr = map.BR.ReadInt32() - map.SecondaryMagic;

                AI_Squads vs = new AI_Squads();

                // chunk size * x and starting position
                map.BR.BaseStream.Position = locr + (100 * x);
                vs.offset = tempr + (100 * x);
                vs.ModelName = map.Strings.Name[(Int16)map.BR.ReadInt32()];
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();

                // facing direction
                map.BR.BaseStream.Position = locr + (100 * x) + 20;
                vs.RotationDirection = map.BR.ReadSingle();

                if (charNum != -1)
                {
                    vs.TagPath = map.FileNames.Name[temppalette2[charNum]];
                    vs.ModelTagNumber = temppalette[charNum];
                    if (vs.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    // vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                    Spawn.Add(vs);
                }
            }

            #endregion

            map.CloseMap();
        }
Ejemplo n.º 22
0
        /// <summary>
        /// The write palettes.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void WritePalettes(Map map)
        {
            map.OpenMap(MapTypes.Internal);
            map.BW.BaseStream.Position = palettesoffset;
            foreach (BSPContainer.Palette_Color[] palette in LightMap_Palettes)
            {
                for (int x = 0; x < 256; x++)
                {
                    map.BW.Write((byte)palette[x].r);
                    map.BW.Write((byte)palette[x].g);
                    map.BW.Write((byte)palette[x].b);
                    map.BW.Write((byte)palette[x].a);
                }
            }

            map.CloseMap();
        }
Ejemplo n.º 23
0
        /// <summary>
        /// The h 2 spawn info.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void H2SpawnInfo(Map map)
        {
            map.OpenMap(MapTypes.Internal);

            // find default mc model
            map.BR.BaseStream.Position = map.MetaInfo.Offset[0] + 308;
            int tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            map.BR.BaseStream.Position = tempr + 4;
            int tempbipdtag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
            //map.CloseMap();
            int bipdmodeltag = map.Functions.FindModelByBaseClass(tempbipdtag);

            int ctfmodeltag = -1;
            int ballmodeltag = -1;
            int juggernautdmodeltag = -1;
            int assultmodeltag = -1;

            #region  //// Find objective models ////

            try
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position =
                    map.MetaInfo.Offset[
                        map.Functions.ForMeta.FindByNameAndTagType("mulg", "multiplayer\\multiplayer_globals")] + 12;
                tempr = map.BR.ReadInt32();
                if (tempr != 0)
                {
                    tempr -= map.SecondaryMagic;
                    map.BR.BaseStream.Position = tempr + 4;
                    int tempCtftag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    map.BR.BaseStream.Position = tempr + 12;
                    int tempBalltag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                    map.BR.BaseStream.Position = tempr + 36;
                    int tempHillShader = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                    // I believe the Hill Shader above is not used, but just in case. Otherwise, load the usual one below
                    if (tempHillShader == -1)
                    {
                        map.BR.BaseStream.Position = tempr + 1332;
                        int tempr2 = map.BR.ReadInt32();
                        if (tempr2 != 0)
                        {
                            tempr2 -= map.SecondaryMagic;
                            map.BR.BaseStream.Position = tempr2 + 196;
                            tempHillShader = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                        }
                    }

                    map.BR.BaseStream.Position = tempr + 52;
                    int tempJuggernauttag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    map.BR.BaseStream.Position = tempr + 60;
                    int tempAssaulttag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();

                    ctfmodeltag = map.Functions.FindModelByBaseClass(tempCtftag);
                    ballmodeltag = map.Functions.FindModelByBaseClass(tempBalltag);

                    // *** This is not right. It's a shader, not a model. But I don't know how to display a shader...
                    hillshadertag = map.Functions.ForMeta.FindMetaByID(tempHillShader);

                    juggernautdmodeltag = map.Functions.FindModelByBaseClass(tempJuggernauttag);
                    assultmodeltag = map.Functions.FindModelByBaseClass(tempAssaulttag);
                }
            }
            catch (Exception e)
            {
               System.Windows.Forms.MessageBox.Show("Error loading an objective model (CTF/Juggernaut/Assault/Bomb)\n" + e.Message);
            }

            #endregion

            #region //// Player Spawns ////

            try
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 256;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < tempc; x++)
                {
                    map.BR.BaseStream.Position = tempr + (52 * x);
                    PlayerSpawn ps = new PlayerSpawn();
                    ps.Read(map);

                    ps.ModelTagNumber = bipdmodeltag;
                    ps.ModelName = map.FileNames.Name[ps.ModelTagNumber];

                    Spawn.Add(ps);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading player spawns", e);
            }

            #endregion

            #region //// trigger volumes / death zones ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 264;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < tempc; x++)
                {
                    DeathZone tv = new DeathZone();
                    map.BR.BaseStream.Position = tempr + (68 * x);
                    tv.Read(map);

                    Spawn.Add(tv);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading death zones", e);
            }

            #endregion

            #region //// lights ////

            try
            {
                //// palette ////
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 240;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    temppalette2[x] = tempbase;
                    temppalette[x] = tempbase;
                }

                //// placement ////
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 232;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < tempc; x++)
                {
                    map.BR.BaseStream.Position = tempr + (108 * x);
                    short tempshort = map.BR.ReadInt16();

                    LightSpawn ls = new LightSpawn();
                    map.BR.BaseStream.Position = tempr + (108 * x);
                    ls.Read(map);

                    if (ls.PaletteIndex == -1)
                    {
                        continue;
                    }

                    int nameIndex = temppalette2[tempshort];
                    if (nameIndex >= 0)
                        ls.TagPath = map.FileNames.Name[nameIndex];
                    ls.ModelTagNumber = temppalette[tempshort];
                    if (ls.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    ls.ModelName = map.FileNames.Name[ls.ModelTagNumber];
                    Spawn.Add(ls);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Lights", e);
            }

            #endregion

            #region //// sounds ////

            try
            {
                //// Sound Scenery palette ////
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 224;

                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    temppalette2[x] = tempbase;
                    temppalette[x] = tempbase;
                }

                //// placement ////
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 216;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < tempc; x++)
                {
                    SoundSpawn ss = new SoundSpawn();
                    map.BR.BaseStream.Position = tempr + (80 * x);
                    ss.Read(map);

                    if (ss.PaletteIndex == -1 || temppalette2[ss.PaletteIndex] == -1)
                    {
                        ss.TagPath = NullTags;
                    }
                    else
                    {
                        ss.TagPath = map.FileNames.Name[temppalette2[ss.PaletteIndex]];
                    }

                    ss.ModelTagNumber = temppalette[ss.PaletteIndex];
                    if (ss.ModelTagNumber == -1)
                    {
                        // { continue; }
                        ss.ModelName = null;
                    }
                    else
                    {
                        ss.ModelName = map.FileNames.Name[ss.ModelTagNumber];
                    }

                    Spawn.Add(ss);
                }

            }
            catch (Exception e)
            {
                throw new Exception("Error loading sounds", e);
            }

            #endregion

            #region //// objectives ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 280;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < tempc; x++)
                {
                    ObjectiveSpawn os = new ObjectiveSpawn();
                    map.BR.BaseStream.Position = tempr + (32 * x);
                    os.Read(map);

                    if (os.ObjectiveType == ObjectiveSpawn.ObjectiveTypeEnum.OddballSpawn && ballmodeltag != -1)
                    {
                        os.ModelTagNumber = ballmodeltag;
                    }
                    else if (os.ObjectiveType == ObjectiveSpawn.ObjectiveTypeEnum.CTFRespawn && ctfmodeltag != -1)
                    {
                        os.ModelTagNumber = ctfmodeltag;
                    }
                    else if (
                        os.ObjectiveType.ToString().StartsWith(
                            ObjectiveSpawn.ObjectiveTypeEnum.KingOfTheHill_1.ToString().Substring(0, 13)) &&
                        ctfmodeltag != -1)
                    {
                        os.ModelTagNumber = ctfmodeltag;
                    }
                    else if (os.ObjectiveType == ObjectiveSpawn.ObjectiveTypeEnum.AssaultRespawn && assultmodeltag != -1)
                    {
                        os.ModelTagNumber = assultmodeltag;
                    }
                    else
                    {
                        os.ModelTagNumber = bipdmodeltag;
                    }

                    os.ModelName = map.FileNames.Name[os.ModelTagNumber];
                    Spawn.Add(os);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading lights", e);
            }
            #endregion

            #region //// vehicles ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 120;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 112;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    VehicleSpawn vs = new VehicleSpawn();
                    map.BR.BaseStream.Position = tempr + (84 * x);
                    vs.Read(map);

                    if (vs.PaletteIndex == -1)
                    {
                        continue;
                    }

                    vs.TagPath = map.FileNames.Name[temppalette2[vs.PaletteIndex]];
                    vs.ModelTagNumber = temppalette[vs.PaletteIndex];
                    if (vs.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                    Spawn.Add(vs);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading vehicles", e);
            }

            #endregion

            #region //// equipment ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 136;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 128;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    EquipmentSpawn es = new EquipmentSpawn();
                    map.BR.BaseStream.Position = tempr + (56 * x);
                    es.Read(map);

                    if (es.PaletteIndex == -1)
                    {
                        continue;
                    }

                    es.TagPath = map.FileNames.Name[temppalette2[es.PaletteIndex]];
                    es.ModelTagNumber = temppalette[es.PaletteIndex];
                    if (es.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    es.ModelName = map.FileNames.Name[es.ModelTagNumber];
                    Spawn.Add(es);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading equipment", e);
            }

            #endregion

            #region //// bipeds ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 104;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 96;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    BipedSpawn bs = new BipedSpawn();
                    map.BR.BaseStream.Position = tempr + (84 * x);
                    bs.Read(map);

                    if (bs.PaletteIndex == -1)
                    {
                        continue;
                    }

                    bs.TagPath = map.FileNames.Name[temppalette2[bs.PaletteIndex]];
                    bs.ModelTagNumber = temppalette[bs.PaletteIndex];
                    if (bs.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    bs.ModelName = map.FileNames.Name[bs.ModelTagNumber];
                    Spawn.Add(bs);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Bipeds", e);
            }

            #endregion

            #region //// control ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 192;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 184;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    ControlSpawn cs = new ControlSpawn();
                    map.BR.BaseStream.Position = tempr + (68 * x);
                    cs.Read(map);

                    if (cs.PaletteIndex == -1)
                    {
                        continue;
                    }

                    cs.TagPath = map.FileNames.Name[temppalette2[cs.PaletteIndex]];
                    cs.ModelTagNumber = temppalette[cs.PaletteIndex];
                    if (cs.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    cs.ModelName = map.FileNames.Name[cs.ModelTagNumber];
                    Spawn.Add(cs);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Control", e);
            }

            #endregion

            #region //// machines ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 176;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 168;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    MachineSpawn ms = new MachineSpawn();
                    map.BR.BaseStream.Position = tempr + (72 * x);
                    ms.Read(map);

                    if (ms.PaletteIndex == -1)
                    {
                        continue;
                    }

                    if (temppalette2[ms.PaletteIndex] == -1 || temppalette[ms.PaletteIndex] == -1)
                    {
                        continue;
                    }

                    ms.TagPath = map.FileNames.Name[temppalette2[ms.PaletteIndex]];
                    ms.ModelTagNumber = temppalette[ms.PaletteIndex];
                    if (ms.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    ms.ModelName = map.FileNames.Name[ms.ModelTagNumber];
                    Spawn.Add(ms);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Machines", e);
            }

            #endregion

            #region //// scenery ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 88;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 80;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    ScenerySpawn ss = new ScenerySpawn();
                    map.BR.BaseStream.Position = tempr + (92 * x);
                    ss.Read(map);

                    if (ss.PaletteIndex == -1)
                    {
                        continue;
                    }

                    if (temppalette2[ss.PaletteIndex] == -1 || temppalette[ss.PaletteIndex] == -1)
                    {
                        continue;
                    }

                    ss.TagPath = map.FileNames.Name[temppalette2[ss.PaletteIndex]];
                    ss.ModelTagNumber = temppalette[ss.PaletteIndex];
                    if (ss.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    ss.ModelName = map.FileNames.Name[ss.ModelTagNumber];
                    Spawn.Add(ss);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Scenery", e);
            }

            #endregion

            #region //// weapons ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 152;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 144;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    WeaponSpawn ws = new WeaponSpawn();
                    map.BR.BaseStream.Position = tempr + (84 * x);
                    ws.Read(map);

                    if (ws.PaletteIndex == -1)
                    {
                        continue;
                    }

                    ws.TagPath = map.FileNames.Name[temppalette2[ws.PaletteIndex]];
                    ws.ModelTagNumber = temppalette[ws.PaletteIndex];
                    if (ws.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    ws.ModelName = map.FileNames.Name[ws.ModelTagNumber];
                    Spawn.Add(ws);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Weapons", e);
            }

            #endregion

            #region //// obstacles ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 816;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 808;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    ObstacleSpawn os = new ObstacleSpawn();
                    map.BR.BaseStream.Position = tempr + (76 * x);
                    os.Read(map);

                    if (os.PaletteIndex == -1)
                    {
                        continue;
                    }

                    if (temppalette2[os.PaletteIndex] == -1)
                    {
                        continue;
                    }

                    os.TagPath = map.FileNames.Name[temppalette2[os.PaletteIndex]];
                    os.ModelTagNumber = temppalette[os.PaletteIndex];
                    if (os.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    os.ModelName = map.FileNames.Name[os.ModelTagNumber];
                    Spawn.Add(os);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Obstacles", e);
            }

            #endregion

            #region //// collections ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 288;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    Collection collect = new Collection();
                    map.BR.BaseStream.Position = tempr + (144 * x);
                    collect.Read(map);

                    // ID Type
                    if (collect.TagPath == NullTags)
                    {
                        continue;
                    }

                    if (collect.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    collect.ModelName = map.FileNames.Name[collect.ModelTagNumber];
                    Spawn.Add(collect);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Collections", e);
            }

            #endregion

            #region //// cameras ////

            try
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 488;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    CameraSpawn cs = new CameraSpawn();
                    map.BR.BaseStream.Position = tempr + (64 * x);
                    cs.Read(map);

                    Spawn.Add(cs);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Collections", e);
            }

            #endregion

            #region //// AI_Squads ////

            try
            {
                // Reading Character Palette
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 376;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    map.BR.BaseStream.Position = tempr + (x * 8) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                // Reading ai squads reflexive
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 352;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    // Reads AI Squad character index
                    map.BR.BaseStream.Position = tempr + (x * 116) + 54;
                    short charIndex = map.BR.ReadInt16();

                    // Reading locations sub reflexive
                    map.BR.BaseStream.Position = tempr + (x * 116) + 72;
                    int locc = map.BR.ReadInt32();
                    int locr = map.BR.ReadInt32() - map.SecondaryMagic;

                    for (int y = 0; y < locc; y++)
                    {
                        AI_Squads ai = new AI_Squads(x);
                        map.BR.BaseStream.Position = locr + (100 * y);
                        ai.Read(map);

                        if (charIndex != -1)
                        {
                            ai.TagPath = map.FileNames.Name[temppalette2[charIndex]];
                            ai.ModelTagNumber = temppalette[charIndex];
                            if (ai.ModelTagNumber == -1)
                            {
                                continue;
                            }

                            // ai.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                            Spawn.Add(ai);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading AI Squads", e);
            }

            #endregion

            #region //// Spawn Zones ////

            try
            {
                // Reading Spawn Zone Section
                // 792 = Spawn Data
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 792;
                int SpawnDataCount = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                #region //// Inital Spawn Zones ////
                // 88 = Static Initial Spawn Zones
                map.BR.BaseStream.Position = tempr + 88;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int initialR = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < temppalette.Length; x++)
                {
                    // Each Initial Spawn Zone chunk = 48 bytes
                    map.BR.BaseStream.Position = initialR + (x * 48);
                    SpawnZone spawnZone = new SpawnZone(SpawnZoneType.Inital);
                    spawnZone.Read(map);

                    Spawn.Add(spawnZone);
                }
                #endregion

                #region //// Respawn Zones ////
                // 80 = Static Respawn Zones
                map.BR.BaseStream.Position = tempr + 80;
                temppalette = new int[map.BR.ReadInt32()];
                int respawnR = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < temppalette.Length; x++)
                {
                    // Each Respawn Zone chunk = 48 bytes
                    map.BR.BaseStream.Position = respawnR + (x * 48);
                    SpawnZone spawnZone = new SpawnZone(SpawnZoneType.Respawn);
                    spawnZone.Read(map);

                    Spawn.Add(spawnZone);
                }
                #endregion
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Spawn Zones (Initial)", e);
            }
            #endregion

            map.CloseMap();
        }
Ejemplo n.º 24
0
        /// <summary>
        /// The h 2 shader info.
        /// </summary>
        /// <param name="TagIndex">The TagIndex.</param>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void H2ShaderInfo(int TagIndex, Map map)
        {
            bool alreadyOpen = true;
            if (!(map.isOpen && map.openMapType == MapTypes.Internal))
            {
                map.OpenMap(MapTypes.Internal);
                alreadyOpen = false;
            }

            this.TagIndex = TagIndex;
            if (this.TagIndex == -1)
            {
                return;
            }

            this.shaderName = map.FileNames.Name[this.TagIndex];
            map.BR.BaseStream.Position = map.MetaInfo.Offset[this.TagIndex] + 4;
            int tempstem = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
            if (tempstem != -1)
            {
                if (map.FileNames.Name[tempstem].IndexOf("alphatest") != -1)
                {
                    this.Alpha = AlphaType.AlphaTest;
                }
                else if (map.FileNames.Name[tempstem].IndexOf("alpha") != -1)
                {
                    this.Alpha = AlphaType.AlphaBlend;
                }
                else if (map.FileNames.Name[tempstem].IndexOf("water") != -1)
                {
                    this.Alpha = AlphaType.AlphaBlend;
                }
                else
                {
                    this.Alpha = AlphaType.None;
                }
            }
            else
            {
                this.Alpha = AlphaType.None;
            }

            map.BR.BaseStream.Position = map.MetaInfo.Offset[this.TagIndex] + 12;
            int tempc2 = map.BR.ReadInt32();
            int tempr2 = map.BR.ReadInt32() - map.SecondaryMagic;
            if (tempc2 != 0)
            {
                map.BR.BaseStream.Position = tempr2 + 4;
                int tempcrap = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                if (tempcrap != -1)
                {
                    Meta tempmeta = new Meta(map);
                    tempmeta.ReadMetaFromMap(tempcrap, false);
                    ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
                    this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                    this.MainName = map.FileNames.Name[tempcrap];
                    this.levels = pm.Properties[0].mipMapCount;
                }
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[this.TagIndex] + 32;
            tempc2 = map.BR.ReadInt32();
            tempr2 = map.BR.ReadInt32() - map.SecondaryMagic;

            map.BR.BaseStream.Position = tempr2 + 24;
            int fuckr = map.BR.ReadInt32();
            if (fuckr != 0)
            {
                fuckr -= map.SecondaryMagic;
                map.BR.BaseStream.Position = fuckr;
                this.primarydetailuscale = map.BR.ReadSingle();
                this.primarydetailvscale = map.BR.ReadSingle();
                this.primarydetailwscale = map.BR.ReadSingle();
                map.BR.ReadSingle();
                this.secondarydetailuscale = map.BR.ReadSingle();
                this.secondarydetailvscale = map.BR.ReadSingle();
                this.secondarydetailwscale = map.BR.ReadSingle();
            }

            map.BR.BaseStream.Position = tempr2 + 4;
            tempc2 = map.BR.ReadInt32();
            tempr2 = map.BR.ReadInt32() - map.SecondaryMagic;

            /*

            for (int x = 0; x < tempc2; x++)
            {
                map.BR.BaseStream.Position = tempr2 + (x * 12);
                int tempcrap = map.Functions.Meta.FindMetaByID(map.BR.ReadInt32(), map);
                if (tempcrap == -1) { continue; }
                Meta tempmeta = new Meta(map);
                tempmeta.ReadMetaFromMap(tempcrap, map, false);
                Raw.ParsedBitmap pm = new Raw.ParsedBitmap(ref tempmeta, map);
                Bitmaps.Add(pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0));
               BitmapNames.Add(map.FileNames.Name[tempcrap]);
            }

            */
            // map.BR.BaseStream.Position = tempr + 20;
            // tempc2 = map.BR.ReadInt32();
            // tempr2 = map.BR.ReadInt32() - map.SecondaryMagic;

            // tempc2 = tempc;
            // tempr2 = tempr;
            if (tempc2 != 0)
            {
                map.BR.BaseStream.Position = tempr2;
                int tempcrap = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                if (tempcrap != -1)
                {
                    int test = map.FileNames.Name[tempcrap].IndexOf("reflection_maps");
                    if (map.FileNames.Name[tempcrap].IndexOf("_bump") != -1)
                    {
                        Meta tempmeta = new Meta(map);
                        tempmeta.ReadMetaFromMap(tempcrap, false);
                        ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
                      //  this.BumpMapBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                        this.BumpMapName = map.FileNames.Name[tempcrap];
                    }
                    else if (map.FileNames.Name[tempcrap].IndexOf("_cube_map") != -1)
                    {
                        Meta tempmeta = new Meta(map);
                        tempmeta.ReadMetaFromMap(tempcrap, false);
                        ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
                      //  this.CubeMapBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                        this.CubeMapName = map.FileNames.Name[tempcrap];
                    }
                    else if (map.FileNames.Name[tempcrap].IndexOf("default_") == -1 && this.MainBitmap == null &&
                             test == -1)
                    {
                        Meta tempmeta = new Meta(map);
                        tempmeta.ReadMetaFromMap(tempcrap, false);
                        ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);

                        // Try to load LOD2-MIP3 if that fails, load LOD2-MIP0, otherwise LOD0-MIP0
                        this.MainBitmap = pm.FindChunkAndDecode(0, 2, 3, ref tempmeta, map, 0, 0);
                        if (this.MainBitmap == null)
                        {
                            this.MainBitmap = pm.FindChunkAndDecode(0, 2, 0, ref tempmeta, map, 0, 0);
                            if (this.MainBitmap == null)
                                this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                        }

                        this.MainName = map.FileNames.Name[tempcrap];
                        this.levels = pm.Properties[0].mipMapCount;
                    }
                    else if (test != -1)
                    {
                        map.BR.BaseStream.Position += 8;
                        tempcrap = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                        Meta tempmeta = new Meta(map);
                        tempmeta.ReadMetaFromMap(tempcrap, false);
                        ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);

                        // this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map);
                        // this.MainName = map.FileNames.Name[tempcrap];
                    }
                }

                map.BR.BaseStream.Position = tempr2 + 24;
                tempcrap = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                if (tempcrap != -1 && this.MainBitmap == null)
                {
                    Meta tempmeta = new Meta(map);
                    tempmeta.ReadMetaFromMap(tempcrap, false);
                    ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
                    this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                    this.MainName = map.FileNames.Name[tempcrap];
                    this.levels = pm.Properties[0].mipMapCount;
                }
                else if (this.MainBitmap == null)
                {
                    map.BR.BaseStream.Position = tempr2 + 12;
                    tempcrap = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    if (tempcrap != -1)
                    {
                        Meta tempmeta = new Meta(map);
                        tempmeta.ReadMetaFromMap(tempcrap, false);
                        ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
                        this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                        this.MainName = map.FileNames.Name[tempcrap];
                        this.levels = pm.Properties[0].mipMapCount;
                    }
                }
            }

            if (!alreadyOpen)
            {
                map.CloseMap();
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// The map builder.
        /// </summary>
        /// <param name="metas">The metas.</param>
        /// <param name="layout">The layout.</param>
        /// <param name="map">The map.</param>
        /// <param name="addsounds">The addsounds.</param>
        /// <remarks></remarks>
        public void MapBuilder(ArrayList metas, ref MapLayout layout, Map map, bool addsounds)
        {
            string[] filestofix = new string[0];
            if (map.MapHeader.mapType != MapTypes.Internal)
            {
                if (
                    MessageBox.Show(
                        "This map is an external resource and updating it will effect all the other maps. Continue?", 
                        string.Empty, 
                        MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                {
                    return;
                }

                OpenFileDialog openfiles = new OpenFileDialog();
                openfiles.Multiselect = true;
                openfiles.Filter = "Halo 2 Map (*.map)| *.map";
                openfiles.ShowDialog();

                filestofix = openfiles.FileNames;
            }

            if (addsounds == false)
            {
                for (int x = 0; x < metas.Count; x++)
                {
                    if (((Meta)metas[x]).type == "snd!")
                    {
                        metas.RemoveAt(x);
                        x--;
                    }
                }
            }

            int totalshift = 0;

            ArrayList strings = new ArrayList();
            for (int x = 0; x < metas.Count; x++)
            {
                Meta m = (Meta)metas[x];
                for (int y = 0; y < m.items.Count; y++)
                {
                    Meta.Item ii = m.items[y];
                    if (ii.type == Meta.ItemType.String)
                    {
                        Meta.String iii = (Meta.String)ii;
                        if (Array.IndexOf(map.Strings.Name, iii.name) == -1)
                        {
                            if (strings.IndexOf(iii.name) == -1)
                            {
                                strings.Add(iii.name);
                            }
                        }
                    }
                }
            }

            

            map.OpenMap(MapTypes.Internal);
            Meta ughmeta = new Meta(map);
            ughmeta.ReadMetaFromMap(map.IndexHeader.metaCount - 1, true);
            IFPIO ifp = IFPHashMap.GetIfp("ugh!", map.HaloVersion);
            ughmeta.rawType = RawDataContainerType.Empty;
            ughmeta.headersize = ifp.headerSize;

            ughmeta.scanner.ScanWithIFP(ref ifp);

            

            #region get model info

            int tempint = layout.FindByType(RawDataContainerType.Model);
            LayOutChunk loc = (LayOutChunk)layout.chunks[tempint];

            #endregion

            #region sound raw data

            int sndshift = 0;
            int sndpermcount = 0;
            int sndchoicecount = 0;
            int sndchunk1count = 0;
            int addedsoundnames = 0;

            MetaSplitter metasplit = new MetaSplitter();
            metasplit.SplitWithIFP(ref ifp, ref ughmeta, map);
            map.OpenMap(MapTypes.Internal);
            int soundnameindex = 0;
            int soundpermutationindex = 0;
            int soundchoiceindex = 0;
            int soundchunk1index = 0;
            for (int x = 0; x < metasplit.Header.Chunks[0].ChunkResources.Count; x++)
            {
                if (metasplit.Header.Chunks[0].ChunkResources[x].type == Meta.ItemType.Reflexive)
                {
                    Meta.Reflexive r = (Meta.Reflexive)metasplit.Header.Chunks[0].ChunkResources[x];
                    if (r.offset == 16)
                    {
                        soundnameindex = x;
                    }

                    if (r.offset == 32)
                    {
                        soundpermutationindex = x;
                    }

                    if (r.offset == 40)
                    {
                        soundchoiceindex = x;
                    }

                    if (r.offset == 64)
                    {
                        soundchunk1index = x;
                    }
                }
            }

            MetaSplitter.SplitReflexive soundnamereflexive =
                metasplit.Header.Chunks[0].ChunkResources[soundnameindex] as MetaSplitter.SplitReflexive;
            MetaSplitter.SplitReflexive soundpermutationreflexive =
                metasplit.Header.Chunks[0].ChunkResources[soundpermutationindex] as MetaSplitter.SplitReflexive;
            MetaSplitter.SplitReflexive soundchoicereflexive =
                metasplit.Header.Chunks[0].ChunkResources[soundchoiceindex] as MetaSplitter.SplitReflexive;
            MetaSplitter.SplitReflexive soundchunk1reflexive =
                metasplit.Header.Chunks[0].ChunkResources[soundchunk1index] as MetaSplitter.SplitReflexive;
            for (int x = 0; x < metas.Count; x++)
            {
                Meta m = (Meta)metas[x];
                if (m.rawType == RawDataContainerType.Sound)
                {
                    Sound tempsound = (Sound)m.raw;
                    BinaryWriter BW = new BinaryWriter(m.MS);
                    int y = 0;

                    // writes new index to meta
                    BW.BaseStream.Position = 8;
                    ushort temppermindex = (ushort)(map.ugh.Permutations.Count + sndpermcount);
                    BW.Write(temppermindex);

                    for (int e = 0; e < tempsound.Permutations.Length; e++)
                    {
                        for (int ee = 0; ee < tempsound.Permutations[e].choicecount; ee++)
                        {
                            int nindex = map.ugh.SoundNames.IndexOf(tempsound.Permutations[e].Choices[ee].Name);
                            if (nindex == -1)
                            {
                                int nindex2 = strings.IndexOf(tempsound.Permutations[e].Choices[ee].Name);
                                if (nindex2 == -1)
                                {
                                    strings.Add(tempsound.Permutations[e].Choices[ee].Name);
                                    nindex2 = strings.Count - 1;
                                }

                                nindex2 += map.Strings.Name.Length;
                                map.ugh.SoundNames.Add(tempsound.Permutations[e].Choices[ee].Name);
                                tempsound.Permutations[e].Choices[ee].NameIndex = (ushort)(map.ugh.SoundNames.Count - 1);

                                MetaSplitter.SplitReflexive tempss = new MetaSplitter.SplitReflexive();
                                tempss.chunksize = soundnamereflexive.Chunks[0].chunksize;
                                tempss.MS = new MemoryStream(tempss.chunksize);
                                BinaryWriter soundnameBW = new BinaryWriter(tempss.MS);
                                soundnameBW.BaseStream.Position = 0;
                                byte z = 0;
                                soundnameBW.Write((ushort)nindex2);
                                soundnameBW.Write(z);
                                soundnameBW.Write((byte)tempsound.Permutations[e].Choices[ee].Name.Length);
                                soundnamereflexive.Chunks.Add(tempss);
                                addedsoundnames++;
                            }
                            else
                            {
                                tempsound.Permutations[e].Choices[ee].NameIndex = (ushort)nindex;
                            }
                        }
                    }

                    // cycle through permutations and write them
                    for (int e = 0; e < tempsound.Permutations.Length; e++)
                    {
                        MetaSplitter.SplitReflexive tempss = new MetaSplitter.SplitReflexive();
                        tempss.chunksize = soundpermutationreflexive.Chunks[0].chunksize;
                        tempss.MS = new MemoryStream(tempss.chunksize);
                        BinaryWriter permBW = new BinaryWriter(tempss.MS);
                        permBW.BaseStream.Position = 0;

                        permBW.Write(tempsound.Permutations[e].unknown1);
                        permBW.Write(tempsound.Permutations[e].unknown2);
                        tempsound.Permutations[e].choiceindex = (ushort)(map.ugh.Choices.Count + sndchoicecount);
                        permBW.Write(tempsound.Permutations[e].choiceindex);
                        permBW.Write(tempsound.Permutations[e].choicecount);
                        soundpermutationreflexive.Chunks.Add(tempss);
                        for (int ee = 0; ee < tempsound.Permutations[e].choicecount; ee++)
                        {
                            MetaSplitter.SplitReflexive tempsss = new MetaSplitter.SplitReflexive();
                            tempsss.chunksize = soundchoicereflexive.Chunks[0].chunksize;
                            tempsss.MS = new MemoryStream(tempsss.chunksize);
                            BinaryWriter choiceBW = new BinaryWriter(tempsss.MS);
                            choiceBW.BaseStream.Position = 0;

                            choiceBW.Write(tempsound.Permutations[e].Choices[ee].NameIndex);
                            choiceBW.Write(tempsound.Permutations[e].Choices[ee].unknown1);
                            choiceBW.Write(tempsound.Permutations[e].Choices[ee].unknown2);

                            choiceBW.Write(tempsound.Permutations[e].Choices[ee].unknown3);
                            tempsound.Permutations[e].Choices[ee].soundindex =
                                (ushort)(map.ugh.SoundChunks1.Count + sndchunk1count);
                            choiceBW.Write(tempsound.Permutations[e].Choices[ee].soundindex);
                            choiceBW.Write(tempsound.Permutations[e].Choices[ee].soundcount);
                            soundchoicereflexive.Chunks.Add(tempsss);

                            for (int eee = 0; eee < tempsound.Permutations[e].Choices[ee].soundcount; eee++)
                            {
                                RawDataChunk r = m.raw.rawChunks[y];

                                // write raw to map
                                int tempintx = loc.startoffset + sndshift;
                                map.BW.BaseStream.Position = tempintx;
                                map.BW.BaseStream.Write(r.MS.ToArray(), 0, r.size);

                                // write padding
                                int tempinty = map.Functions.Padding(r.size, 512);
                                byte[] tempbytes = new byte[tempinty];
                                map.BW.Write(tempbytes);
                                sndshift += r.size + tempinty;
                                y++;

                                MetaSplitter.SplitReflexive tempssss = new MetaSplitter.SplitReflexive();
                                tempssss.chunksize = soundchoicereflexive.Chunks[0].chunksize;
                                tempssss.MS = new MemoryStream(tempssss.chunksize);
                                BinaryWriter sndchnk1BW = new BinaryWriter(tempssss.MS);
                                sndchnk1BW.BaseStream.Position = 0;
                                sndchnk1BW.Write(tempintx);
                                sndchnk1BW.Write(tempsound.Permutations[e].Choices[ee].SoundChunks1[eee].size);
                                sndchnk1BW.Write(tempsound.Permutations[e].Choices[ee].SoundChunks1[eee].unknown1);
                                sndchnk1BW.Write(tempsound.Permutations[e].Choices[ee].SoundChunks1[eee].unknown2);
                                soundchunk1reflexive.Chunks.Add(tempssss);
                                sndchunk1count++;
                            }

                            sndchoicecount++;
                        }

                        sndpermcount++;
                    }

                    metas[x] = m;
                }
            }

            totalshift += sndshift;
            if (sndshift > 0)
            {
                metasplit.Header.Chunks[0].ChunkResources[soundnameindex] = soundnamereflexive;
                metasplit.Header.Chunks[0].ChunkResources[soundpermutationindex] = soundpermutationreflexive;
                metasplit.Header.Chunks[0].ChunkResources[soundchoiceindex] = soundchoicereflexive;
                metasplit.Header.Chunks[0].ChunkResources[soundchunk1index] = soundchunk1reflexive;

                ughmeta = MetaBuilder.BuildMeta(metasplit, map);
            }

            metas.Add(ughmeta);

            #endregion

            #region model raw data

            int modeshift = 0;

            loc.startoffset += totalshift;
            loc.endoffset = loc.startoffset + loc.size;
            map.BW.BaseStream.Position = loc.startoffset;
            map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);
            for (int x = 0; x < metas.Count; x++)
            {
                Meta m = (Meta)metas[x];
                if (m.rawType == RawDataContainerType.Model)
                {
                    BinaryWriter BW = new BinaryWriter(m.MS);
                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        RawDataChunk r = m.raw.rawChunks[y];
                        int tempintx = loc.endoffset + modeshift;

                        // writes new pointer to loaded meta
                        BW.BaseStream.Position = r.pointerMetaOffset;
                        BW.Write(tempintx);
                        BW.Write(r.size);

                        // writes raw to map file
                        map.BW.BaseStream.Position = tempintx;
                        map.BW.BaseStream.Write(r.MS.ToArray(), 0, r.size);

                        // write padding
                        int tempinty = map.Functions.Padding(r.size, 512);
                        byte[] tempbytes = new byte[tempinty];
                        map.BW.Write(tempbytes);
                        modeshift += r.size + tempinty;
                    }

                    metas[x] = m;
                }
            }

            loc.size += modeshift;
            loc.endoffset = loc.startoffset + loc.size;

            layout.chunks[tempint] = loc;
            totalshift += modeshift;

            #endregion

            #region bsp raw

            tempint = layout.FindByType(RawDataContainerType.BSP);
            loc = (LayOutChunk)layout.chunks[tempint];
            loc.startoffset += totalshift;
            int tempint2 = layout.FindByType(RawDataContainerType.BSPMeta);
            LayOutChunk loc2 = (LayOutChunk)layout.chunks[tempint2];
            uint bsprawsize = (uint)loc.size;
            uint oldbspsize = (uint)loc.size;
            int bspshift = 0;
            int bspmagic = map.BSP.sbsp[0].magic;
            int newmagicreflexive = bspmagic + loc2.startoffset;
            bool found = false;
            Meta tempbspmeta = new Meta(map);
            bool foundbsptoimport = false;
            for (int x = 0; x < metas.Count; x++)
            {
                Meta m = (Meta)metas[x];
                if (m.type == "sbsp")
                {
                    foundbsptoimport = true;
                    bsprawsize = 0;
                    BinaryWriter BW = new BinaryWriter(m.MS);
                    int[] tempoff = new int[m.raw.rawChunks.Count];

                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        found = false;
                        RawDataChunk r = m.raw.rawChunks[y];
                        for (int yy = 0; yy < y; yy++)
                        {
                            RawDataChunk rr = m.raw.rawChunks[yy];
                            if (rr.offset == r.offset && rr.rawLocation == r.rawLocation)
                            {
                                tempoff[y] = tempoff[yy];

                                // writes new pointer to loaded meta
                                BW.BaseStream.Position = r.pointerMetaOffset;
                                BW.Write(tempoff[y]);
                                BW.Write(r.size);
                                found = true;
                                break;
                            }
                        }

                        if (found)
                        {
                            continue;
                        }

                        tempoff[y] = loc.startoffset + (int)bsprawsize;

                        // MessageBox.Show("Test");
                        // writes new pointer to loaded meta
                        BW.BaseStream.Position = r.pointerMetaOffset;
                        BW.Write(tempoff[y]);
                        BW.Write(r.size);

                        // writes raw to map file
                        map.BW.BaseStream.Position = loc.startoffset + bsprawsize;
                        map.BW.BaseStream.Write(r.MS.ToArray(), 0, r.size);

                        // write padding
                        int tempinty = map.Functions.Padding(r.size, 512);
                        byte[] tempbytes = new byte[tempinty];
                        map.BW.Write(tempbytes);
                        bsprawsize += (uint)(r.size + tempinty);
                    }

                    totalshift += (int)(bsprawsize - oldbspsize);
                    bspshift += (int)(bsprawsize - oldbspsize);

                    loc.size = (int)bsprawsize;
                    loc.endoffset = (int)(loc.startoffset + bsprawsize);
                    layout.chunks[tempint] = loc;
                    loc2.MS = m.MS;
                    loc2.size = m.size;
                    loc2.endoffset = loc2.startoffset + m.size;
                    layout.chunks[tempint2] = loc2;
                    bspmagic = m.magic;
                    newmagicreflexive = bspmagic + m.offset;
                    tempbspmeta = m;
                    metas.RemoveAt(x);
                    break;
                }

                if (x == metas.Count - 1)
                {
                    map.BW.BaseStream.Position = loc.startoffset;
                    map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);
                    loc.endoffset = loc.startoffset + loc.size;
                    layout.chunks[tempint] = loc;
                }
            }

            #endregion

            #region weather raw data

            int weathershift = 0;
            tempint = layout.FindByType(RawDataContainerType.Weather);
            if (tempint != -1)
            {
                loc = (LayOutChunk)layout.chunks[tempint];
                loc.startoffset += totalshift;
                map.BW.BaseStream.Position = loc.startoffset;
                map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);
            }
            else
            {
                loc = new LayOutChunk(0);
                loc.rawType = RawDataContainerType.Weather;
                int tx = layout.FindByType(RawDataContainerType.BSP);
                loc.startoffset = ((LayOutChunk)layout.chunks[tx]).endoffset;
                loc.size = 0;
            }

            for (int x = 0; x < metas.Count; x++)
            {
                Meta m = (Meta)metas[x];
                if (m.rawType == RawDataContainerType.Weather)
                {
                    BinaryWriter BW = new BinaryWriter(m.MS);
                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        RawDataChunk r = m.raw.rawChunks[y];
                        int tempintx = loc.startoffset + loc.size + weathershift;

                        // writes new pointer to loaded meta
                        BW.BaseStream.Position = r.pointerMetaOffset;
                        BW.Write(tempintx);
                        BW.Write(r.size);

                        // writes raw to map file
                        map.BW.BaseStream.Position = tempintx;
                        map.BW.BaseStream.Write(r.MS.ToArray(), 0, r.size);

                        // write padding
                        int tempinty = map.Functions.Padding(r.size, 512);
                        byte[] tempbytes = new byte[tempinty];
                        map.BW.Write(tempbytes);
                        weathershift += r.size + tempinty;
                    }

                    metas[x] = m;
                }
            }

            loc.size += weathershift;
            loc.endoffset = loc.startoffset + loc.size;
            if (tempint == -1)
            {
                if (weathershift > 0)
                {
                    layout.chunks.Add(loc);
                }

                ;
            }
            else
            {
                layout.chunks[tempint] = loc;
            }

            totalshift += weathershift;

            #endregion

            #region decr raw data

            int decrshift = 0;
            tempint = layout.FindByType(RawDataContainerType.DECR);
            if (tempint != -1)
            {
                loc = (LayOutChunk)layout.chunks[tempint];
                loc.startoffset += totalshift;
                map.BW.BaseStream.Position = loc.startoffset;
                map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);
            }
            else
            {
                loc = new LayOutChunk(0);
                loc.rawType = RawDataContainerType.DECR;
                int tx = layout.FindByType(RawDataContainerType.Weather);
                if (tx == -1)
                {
                    tx = layout.FindByType(RawDataContainerType.BSP);
                }

                loc.startoffset = ((LayOutChunk)layout.chunks[tx]).endoffset;
                loc.size = 0;
            }

            for (int x = 0; x < metas.Count; x++)
            {
                Meta m = (Meta)metas[x];
                if (m.rawType == RawDataContainerType.DECR)
                {
                    BinaryWriter BW = new BinaryWriter(m.MS);
                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        RawDataChunk r = m.raw.rawChunks[y];
                        int tempintx = loc.startoffset + loc.size + decrshift;

                        // writes new pointer to loaded meta
                        BW.BaseStream.Position = r.pointerMetaOffset;
                        BW.Write(tempintx);
                        BW.Write(r.size);

                        // writes raw to map file
                        map.BW.BaseStream.Position = tempintx;
                        map.BW.BaseStream.Write(r.MS.ToArray(), 0, r.size);

                        // write padding
                        int tempinty = map.Functions.Padding(r.size, 512);
                        byte[] tempbytes = new byte[tempinty];
                        map.BW.Write(tempbytes);
                        decrshift += r.size + tempinty;
                    }

                    metas[x] = m;
                }
            }

            loc.size += decrshift;
            loc.endoffset = loc.startoffset + loc.size;
            if (tempint == -1)
            {
                if (decrshift > 0)
                {
                    layout.chunks.Add(loc);
                }

                ;
            }
            else
            {
                layout.chunks[tempint] = loc;
            }

            totalshift += decrshift;

            #endregion

            #region prtm raw data

            int prtmshift = 0;
            tempint = layout.FindByType(RawDataContainerType.PRTM);
            if (tempint != -1)
            {
                loc = (LayOutChunk)layout.chunks[tempint];
                loc.startoffset += totalshift;
                map.BW.BaseStream.Position = loc.startoffset;
                map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);
            }
            else
            {
                loc = new LayOutChunk(0);
                loc.rawType = RawDataContainerType.PRTM;
                int tx = layout.FindByType(RawDataContainerType.DECR);
                if (tx == -1)
                {
                    tx = layout.FindByType(RawDataContainerType.Weather);
                    if (tx == -1)
                    {
                        tx = layout.FindByType(RawDataContainerType.BSP);
                    }
                }

                loc.startoffset = ((LayOutChunk)layout.chunks[tx]).endoffset;
                loc.size = 0;
            }

            for (int x = 0; x < metas.Count; x++)
            {
                Meta m = (Meta)metas[x];
                if (m.rawType == RawDataContainerType.PRTM)
                {
                    BinaryWriter BW = new BinaryWriter(m.MS);
                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        RawDataChunk r = m.raw.rawChunks[y];
                        int tempintx = loc.startoffset + loc.size + prtmshift;

                        // writes new pointer to loaded meta
                        BW.BaseStream.Position = r.pointerMetaOffset;
                        BW.Write(tempintx);
                        BW.Write(r.size);

                        // writes raw to map file
                        map.BW.BaseStream.Position = tempintx;
                        map.BW.BaseStream.Write(r.MS.ToArray(), 0, r.size);

                        // write padding
                        int tempinty = map.Functions.Padding(r.size, 512);
                        byte[] tempbytes = new byte[tempinty];
                        map.BW.Write(tempbytes);
                        prtmshift += r.size + tempinty;
                    }

                    metas[x] = m;
                }
            }

            loc.size += prtmshift;
            loc.endoffset = loc.startoffset + loc.size;
            if (tempint == -1)
            {
                if (prtmshift > 0)
                {
                    layout.chunks.Add(loc);
                }

                ;
            }
            else
            {
                layout.chunks[tempint] = loc;
            }

            totalshift += prtmshift;

            #endregion

            #region jmad raw data

            int jmadshift = 0;
            tempint = layout.FindByType(RawDataContainerType.Animation);
            if (tempint != -1)
            {
                loc = (LayOutChunk)layout.chunks[tempint];
                loc.startoffset += totalshift;
                map.BW.BaseStream.Position = loc.startoffset;
                map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);
            }
            else
            {
                loc = new LayOutChunk(0);
                loc.rawType = RawDataContainerType.Animation;
                int tx = layout.FindByType(RawDataContainerType.PRTM);
                if (tx == -1)
                {
                    tx = layout.FindByType(RawDataContainerType.DECR);
                    if (tx == -1)
                    {
                        tx = layout.FindByType(RawDataContainerType.Weather);
                        if (tx == -1)
                        {
                            tx = layout.FindByType(RawDataContainerType.BSP);
                        }
                    }
                }

                loc.startoffset = ((LayOutChunk)layout.chunks[tx]).endoffset;
                loc.size = 0;
            }

            for (int x = 0; x < metas.Count; x++)
            {
                Meta m = (Meta)metas[x];
                if (m.rawType == RawDataContainerType.Animation)
                {
                    BinaryWriter BW = new BinaryWriter(m.MS);
                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        RawDataChunk r = m.raw.rawChunks[y];
                        int tempintx = loc.startoffset + loc.size + jmadshift;

                        // writes new pointer to loaded meta
                        BW.BaseStream.Position = r.pointerMetaOffset - 4;
                        BW.Write(r.size);
                        BW.Write(tempintx);

                        // writes raw to map file
                        map.BW.BaseStream.Position = tempintx;
                        map.BW.BaseStream.Write(r.MS.ToArray(), 0, r.size);

                        // write padding
                        int tempinty = map.Functions.Padding(r.size, 512);
                        byte[] tempbytes = new byte[tempinty];
                        map.BW.Write(tempbytes);
                        jmadshift += r.size + tempinty;
                    }

                    metas[x] = m;
                }
            }

            loc.size += jmadshift;
            loc.endoffset = loc.startoffset + loc.size;
            if (tempint == -1)
            {
                if (jmadshift > 0)
                {
                    layout.chunks.Add(loc);
                }

                ;
            }
            else
            {
                layout.chunks[tempint] = loc;
            }

            totalshift += jmadshift;

            #endregion

            #region bsp meta data

            uint bspmetasize = 0;
            int bspmetashift = 0;
            uint oldbspmetasize = (uint)map.BSP.sbsp[0].size;
            tempint = layout.FindByType(RawDataContainerType.BSPMeta);
            loc = (LayOutChunk)layout.chunks[tempint];
            loc.startoffset += totalshift;
            loc.endoffset += totalshift;
            bspmetasize = (uint)loc.size;
            int tempinteger = layout.FindByType(RawDataContainerType.MetaData);
            loc2 = (LayOutChunk)layout.chunks[tempinteger];
            int tempintxx = loc.startoffset;

            if (foundbsptoimport == false)
            {
                int tempint3 = layout.FindByType(RawDataContainerType.BSP);
                LayOutChunk loc3 = (LayOutChunk)layout.chunks[tempint3];
                BinaryWriter BWZ = new BinaryWriter(loc.MS);
                for (int w = 0; w < loc3.rawPieces.Count; w++)
                {
                    RawInfoChunk r = (RawInfoChunk)loc3.rawPieces[w];
                    BWZ.BaseStream.Position = r.offsetOfPointer - map.BSP.sbsp[0].offset;
                    r.offset += (uint)(modeshift + sndshift);
                    BWZ.Write(r.offset);
                }

                layout.chunks[tempint3] = loc3;
            }

            #endregion Should this be here or lower, didn't really look ????

            // writes new pointer and magic and size to scenario meta
            BinaryWriter BWX = new BinaryWriter(loc2.MS);
            int tempoffx = map.MetaInfo.Offset[3] - map.MapHeader.metaStart - map.MapHeader.indexOffset +
                           map.BSP.sbsp[0].pointerOffset;
            BWX.BaseStream.Position = tempoffx;

            BWX.Write(tempintxx);
            BWX.Write(loc.size);
            BWX.Write(newmagicreflexive);

            // writes raw to map file
            int bspoffset = tempintxx;
            map.BW.BaseStream.Position = tempintxx;
            map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);

            // write padding
            layout.chunks[tempint] = loc;
            totalshift += (int)(bspmetasize - oldbspmetasize);
            bspmetashift = (int)(bspmetasize - oldbspmetasize);
            if (bspmetashift < 0)
            {
                bspmetashift = 0;
            }
            else
            {
                byte[] tempbytesxxxx = new byte[bspmetashift];
                map.BW.Write(tempbytesxxxx);
                totalshift += bspmetashift;
            }

            #region stringnames1

            tempint = layout.FindByType(RawDataContainerType.Strings1);
            loc = (LayOutChunk)layout.chunks[tempint];
            loc.startoffset += totalshift;
            int tempoldsize = map.MapHeader.scriptReferenceCount * 128;
            int oldpadding = map.Functions.Padding(tempoldsize, 512);
            int tempnewsrsize = strings.Count * 128;
            map.BW.BaseStream.Position = loc.startoffset;
            map.BW.BaseStream.Write(loc.MS.ToArray(), 0, tempoldsize);
            byte[] tempb = new byte[tempnewsrsize];
            map.BW.BaseStream.Write(tempb, 0, tempnewsrsize);
            int padding = map.Functions.Padding(tempoldsize + tempnewsrsize, 512);
            tempb = new byte[padding];
            map.BW.BaseStream.Write(tempb, 0, padding);
            for (int x = 0; x < strings.Count; x++)
            {
                map.BW.BaseStream.Position = loc.startoffset + tempoldsize + (x * 128);
                char[] tempc = ((String)strings[x]).ToCharArray();
                map.BW.Write(tempc);
            }

            loc.size += -oldpadding + tempnewsrsize + padding;
            loc.endoffset = loc.startoffset + loc.size;
            totalshift += -oldpadding + tempnewsrsize + padding;
            map.BW.BaseStream.Position = 352;
            map.BW.Write(loc.startoffset);
            int newcount = map.MapHeader.scriptReferenceCount + strings.Count;
            map.BW.Write(newcount);
            layout.chunks[tempint] = loc;

            #endregion

            // MessageBox.Show("Test");
            #region stringsindex

            tempint = layout.FindByType(RawDataContainerType.StringsIndex);
            loc = (LayOutChunk)layout.chunks[tempint];
            loc.startoffset += totalshift;
            tempoldsize = map.MapHeader.scriptReferenceCount * 4;
            oldpadding = map.Functions.Padding(tempoldsize, 512);
            tempnewsrsize = strings.Count * 4;
            map.BW.BaseStream.Position = loc.startoffset;
            map.BW.BaseStream.Write(loc.MS.ToArray(), 0, tempoldsize);
            tempb = new byte[tempnewsrsize];
            map.BW.BaseStream.Write(tempb, 0, tempnewsrsize);
            padding = map.Functions.Padding(tempoldsize + tempnewsrsize, 512);
            tempb = new byte[padding];
            map.BW.BaseStream.Write(tempb, 0, padding);
            int temporary = map.MapHeader.sizeOfScriptReference;
            for (int x = 0; x < strings.Count; x++)
            {
                map.BW.BaseStream.Position = loc.startoffset + tempoldsize + (x * 4);
                map.BW.Write(temporary);
                temporary += ((String)strings[x]).Length + 1;
            }

            loc.size += -oldpadding + tempnewsrsize + padding;
            loc.endoffset = loc.startoffset + loc.size;
            totalshift += -oldpadding + tempnewsrsize + padding;

            map.BW.BaseStream.Position = 364;
            map.BW.Write(loc.startoffset);

            layout.chunks[tempint] = loc;

            #endregion

            #region strings2

            tempint = layout.FindByType(RawDataContainerType.Strings2);
            loc = (LayOutChunk)layout.chunks[tempint];
            loc.startoffset += totalshift;
            tempoldsize = map.MapHeader.sizeOfScriptReference;
            oldpadding = map.Functions.Padding(tempoldsize, 512);
            tempnewsrsize = temporary - map.MapHeader.sizeOfScriptReference;
            map.BW.BaseStream.Position = loc.startoffset;
            map.BW.BaseStream.Write(loc.MS.ToArray(), 0, tempoldsize);
            tempb = new byte[tempnewsrsize];
            map.BW.BaseStream.Write(tempb, 0, tempnewsrsize);
            padding = map.Functions.Padding(tempoldsize + tempnewsrsize, 512);
            tempb = new byte[padding];
            map.BW.BaseStream.Write(tempb, 0, padding);
            temporary = loc.startoffset + map.MapHeader.sizeOfScriptReference;
            byte zero = 0;
            for (int x = 0; x < strings.Count; x++)
            {
                map.BW.BaseStream.Position = temporary;
                char[] h = ((String)strings[x]).ToCharArray();
                map.BW.Write(h);
                map.BW.Write(zero);
                temporary += ((String)strings[x]).Length + 1;
            }

            loc.size += -oldpadding + tempnewsrsize + padding;
            loc.endoffset = loc.startoffset + loc.size;
            totalshift += -oldpadding + tempnewsrsize + padding;
            int bleh = loc.size - padding;
            map.BW.BaseStream.Position = 360;
            map.BW.Write(bleh);
            map.BW.BaseStream.Position = 368;
            map.BW.Write(loc.startoffset);
            layout.chunks[tempint] = loc;

            #endregion

            #region file names

            tempint = layout.FindByType(RawDataContainerType.FileNames);
            loc = (LayOutChunk)layout.chunks[tempint];
            loc.startoffset += totalshift;
            tempoldsize = map.MapHeader.fileNamesSize;
            oldpadding = map.Functions.Padding(tempoldsize, 512);

            map.BW.BaseStream.Position = loc.startoffset;
            map.BW.BaseStream.Write(
                loc.MS.ToArray(), 0, tempoldsize - map.FileNames.Length[map.IndexHeader.metaCount - 1] - 1);

            temporary = loc.startoffset + tempoldsize - map.FileNames.Length[map.IndexHeader.metaCount - 1] - 1;
            zero = 0;
            for (int x = 0; x < metas.Count; x++)
            {
                map.BW.BaseStream.Position = temporary;
                char[] h = ((Meta)metas[x]).name.ToCharArray();
                map.BW.Write(h);
                map.BW.Write(zero);
                temporary += ((Meta)metas[x]).name.Length + 1;
            }

            tempnewsrsize = temporary - loc.startoffset - tempoldsize;
            padding = map.Functions.Padding(tempoldsize + tempnewsrsize, 512);
            tempb = new byte[padding];
            map.BW.BaseStream.Write(tempb, 0, padding);

            loc.size += -oldpadding + tempnewsrsize + padding;
            loc.endoffset = loc.startoffset + loc.size;
            totalshift += -oldpadding + tempnewsrsize + padding;
            map.BW.BaseStream.Position = 704;
            newcount = map.MapHeader.fileCount + metas.Count - 1;
            map.BW.Write(newcount);
            map.BW.Write(loc.startoffset);
            int hhh = temporary - loc.startoffset;
            map.BW.Write(hhh);
            layout.chunks[tempint] = loc;

            #endregion

            #region files index

            tempint = layout.FindByType(RawDataContainerType.FileNamesIndex);
            loc = (LayOutChunk)layout.chunks[tempint];
            loc.startoffset += totalshift;
            tempoldsize = map.MapHeader.fileCount * 4;
            oldpadding = map.Functions.Padding(tempoldsize, 512);
            tempnewsrsize = (metas.Count * 4) - 4;
            map.BW.BaseStream.Position = loc.startoffset;
            map.BW.BaseStream.Write(loc.MS.ToArray(), 0, tempoldsize);
            tempb = new byte[tempnewsrsize];
            map.BW.BaseStream.Write(tempb, 0, tempnewsrsize);
            padding = map.Functions.Padding(tempoldsize + tempnewsrsize, 512);
            tempb = new byte[padding];
            map.BW.BaseStream.Write(tempb, 0, padding);
            temporary = map.MapHeader.fileNamesSize - map.FileNames.Length[map.IndexHeader.metaCount - 1] - 1;
            for (int x = 0; x < metas.Count; x++)
            {
                map.BW.BaseStream.Position = loc.startoffset + tempoldsize + (x * 4) - 4;
                map.BW.Write(temporary);
                temporary += ((Meta)metas[x]).name.Length + 1;
            }

            loc.size += -oldpadding + tempnewsrsize + padding;
            loc.endoffset = loc.startoffset + loc.size;

            totalshift += -oldpadding + tempnewsrsize + padding;
            map.BW.BaseStream.Position = 716;
            map.BW.Write(loc.startoffset);
            layout.chunks[tempint] = loc;

            tempint = layout.FindByType(RawDataContainerType.UnicodeNamesIndex);
            for (int x = 0; x < 8; x++)
            {
                loc = (LayOutChunk)layout.chunks[tempint + (x * 2)];
                loc.startoffset += totalshift;
                loc.endoffset += totalshift;
                map.BW.BaseStream.Position = loc.startoffset;
                map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);
                layout.chunks[tempint + (x * 2)] = loc;
                loc2 = (LayOutChunk)layout.chunks[tempint + (x * 2) + 1];
                loc2.startoffset += totalshift;
                loc2.endoffset += totalshift;
                map.BW.BaseStream.Position = loc2.startoffset;
                map.BW.BaseStream.Write(loc2.MS.ToArray(), 0, loc2.size);
                layout.chunks[tempint + (x * 2) + 1] = loc2;
            }

            tempint = layout.FindByType(RawDataContainerType.MetaData);
            for (int x = 0; x < 9; x++)
            {
                loc = (LayOutChunk)layout.chunks[tempint];
                BinaryWriter BW = new BinaryWriter(loc.MS);
                BW.BaseStream.Position = map.MetaInfo.Offset[0] - map.MapHeader.metaStart - map.MapHeader.indexOffset +
                                         map.Unicode.ut[x].indexPointerOffset;
                map.Unicode.ut[x].indexOffset += totalshift;
                map.Unicode.ut[x].tableOffset += totalshift;
                BW.Write(map.Unicode.ut[x].indexOffset);
                BW.Write(map.Unicode.ut[x].tableOffset);
                layout.chunks[tempint] = loc;
            }

            tempint = layout.FindByType(RawDataContainerType.Crazy);
            loc = (LayOutChunk)layout.chunks[tempint];
            loc.startoffset += totalshift;
            loc.endoffset += totalshift;
            map.BW.BaseStream.Position = loc.startoffset;
            map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);
            map.BW.BaseStream.Position = 344;
            map.BW.Write(loc.startoffset);
            layout.chunks[tempint] = loc;

            #endregion

            int bitmshift = 0;
            tempint = layout.FindByType(RawDataContainerType.Bitmap);
            loc = (LayOutChunk)layout.chunks[tempint];
            loc.startoffset += totalshift;
            map.BW.BaseStream.Position = loc.startoffset;
            map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);
            int bitmappad = 0;
            for (int x = 0; x < metas.Count; x++)
            {
                Meta m = (Meta)metas[x];
                if (m.rawType == RawDataContainerType.Bitmap)
                {
                    BinaryWriter BW = new BinaryWriter(m.MS);
                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        RawDataChunk r = m.raw.rawChunks[y];
                        int tempintx = loc.startoffset + loc.size + bitmshift;

                        // writes new pointer to loaded meta
                        BW.BaseStream.Position = r.pointerMetaOffset;
                        BW.Write(tempintx);

                        // BW.Write(r.size);
                        // writes raw to map file
                        map.BW.BaseStream.Position = tempintx;
                        map.BW.BaseStream.Write(r.MS.ToArray(), 0, r.size);

                        // write padding
                        int tempinty = map.Functions.Padding(r.size, 512);
                        byte[] tempbytes = new byte[tempinty];
                        map.BW.Write(tempbytes);
                        bitmshift += r.size + tempinty;

                        bitmappad = tempinty;
                    }

                    metas[x] = m;
                }
            }

            totalshift += bitmshift;
            loc.size += bitmshift;
            loc.endoffset = loc.startoffset + loc.size;
            layout.chunks[tempint] = loc;

            tempint = layout.FindByType(RawDataContainerType.MetaIndex);

            loc = (LayOutChunk)layout.chunks[tempint];
            loc.startoffset += totalshift;
            loc.endoffset += totalshift;

            tempint = layout.FindByType(RawDataContainerType.MetaData);

            loc2 = (LayOutChunk)layout.chunks[tempint];
            loc2.startoffset += totalshift;
            loc2.endoffset += totalshift;

            map.BW.BaseStream.Position = loc.startoffset;
            map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);
            map.BW.BaseStream.Position = loc2.startoffset;
            // Changed this line to include Min(MS.Length) as it would pad past end of file. ???
            map.BW.BaseStream.Write(loc2.MS.ToArray(), 0, Math.Min(loc2.size, (int)loc2.MS.Length));
            map.BW.BaseStream.Position = 16;
            map.BW.Write(loc.startoffset);
            newcount = metas.Count + map.IndexHeader.metaCount - 1;
            map.BW.BaseStream.Position = loc.startoffset + 24;
            map.BW.Write(newcount);

            map.BR.BaseStream.Position = map.IndexHeader.tagsOffset + totalshift + 8;
            map.SecondaryMagic = map.BR.ReadInt32() - (loc.startoffset + map.MapHeader.metaStart);

            int where = map.MetaInfo.Offset[map.IndexHeader.metaCount - 1] + totalshift;

            int howfar = 0;

            // Recreate Meta Table Index
            int metaTableStart = map.IndexHeader.tagsOffset + ((map.IndexHeader.metaCount - 1) * 16);
            for (int x = 0; x < metas.Count; x++)
            {
                Meta m = (Meta)metas[x];

                int metaOffset = metaTableStart + totalshift + (x * 16);

                char[] metatype = m.type.ToCharArray();
                Array.Reverse(metatype);

                // Create Ident Values?
                int ident = map.MetaInfo.Ident[map.IndexHeader.metaCount - 1] + (x * 65537);
                int offset = where + howfar;

                if (x == metas.Count - 1)
                {
                    int wherex = map.MetaInfo.Offset[0] + totalshift + 756;
                    map.BW.BaseStream.Position = wherex;
                    map.BW.Write(ident);
                }

                // I believe this aligns the folowing tags on a boundry of 16 as is
                // very important for all HAVOK tags & data
                #region alignment fix

                if (m.type == "phmo" | m.type == "coll" | m.type == "spas")
                {
                    int tempoffset = offset;
                    do
                    {
                        // convert our 'tempoffset', which is our offset increased until the padding lines up, to a hex
                        string tempss = tempoffset.ToString("X");
                        char[] tempc = tempss.ToCharArray();

                        // We use the last hex digit to see if our padding is right (0-15) for 16 byte alignment?
                        if (m.padding == tempc[tempc.Length - 1])
                        {
                            // If we had to add bytes to get our offset to line up, figure out how many and pad
                            // the end of the last tag
                            int diff = tempoffset - offset;
                            tempb = new byte[diff];
                            map.BW.BaseStream.Position = offset;
                            map.BW.Write(tempb);
                            int tempsize;

                            if (x == 0)
                            {
                                // The first tag has no tag before it, so we pad the MetaInfo instead
                                tempsize = map.MetaInfo.Size[map.IndexHeader.metaCount - 2];

                                // int temploc = map.IndexHeader.tagsOffset + ((map.IndexHeader.metaCount - 2) * 16) + totalshift + 12;
                            }
                            else
                            {
                                // Retrieve the last tags size and add the difference onto it
                                tempsize = ((Meta)metas[x - 1]).size;

                                // int temploc = metaTableStart + totalshift + ((x - 1) * 16) + 12;
                            }

                            // Update the size of previous tag
                            int temploc = metaTableStart + totalshift + ((x - 1) * 16) + 12;
                            tempsize += diff;
                            map.BW.BaseStream.Position = temploc;
                            map.BW.Write(tempsize);

                            offset = tempoffset;
                            howfar += diff;
                            break;
                        }

                        tempoffset++;
                    }
                    while (0 != 1);
                }

                #endregion

                int offsetwithmagic = offset + map.SecondaryMagic;

                // each record 16 bytes
                map.BW.BaseStream.Position = metaOffset;
                map.BW.Write(metatype); // Offset  0
                map.BW.Write(ident); // Offset  4
                map.BW.Write(offsetwithmagic); // Offset  8
                map.BW.Write(m.size); // Offset 12
                howfar += m.size;

                map.BW.BaseStream.Position = offset;
                map.BW.BaseStream.Write(m.MS.ToArray(), 0, m.size);

                for (int xx = 0; xx < m.items.Count; xx++)
                {
                    Meta.Item i = m.items[xx];
                    switch (i.type)
                    {
                        case Meta.ItemType.Ident:
                            Meta.Ident id = (Meta.Ident)i;
                            if (id.pointstoTagIndex == -1 | x == metas.Count - 1)
                            {
                                for (int e = 0; e < metas.Count; e++)
                                {
                                    Meta tempm = (Meta)metas[e];
                                    if (tempm.name == id.pointstotagname && tempm.type == id.pointstotagtype)
                                    {
                                        id.ident = map.MetaInfo.Ident[map.IndexHeader.metaCount - 1] + (e * 65537);
                                        break;
                                    }

                                    if (e == metas.Count - 1)
                                    {
                                        if (id.pointstotagname != "Null")
                                        {
                                            int sss = Array.IndexOf(map.MetaInfo.TagType, id.pointstotagtype);
                                            id.ident = sss != -1 ? map.MetaInfo.Ident[sss] : -1;

                                            // id.ident=-1;
                                        }
                                        else
                                        {
                                            id.ident = -1;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                id.ident = map.MetaInfo.Ident[id.pointstoTagIndex];
                            }

                            map.BW.BaseStream.Position = offset + id.offset;
                            map.BW.Write(id.ident);
                            break;

                        case Meta.ItemType.Reflexive:
                            Meta.Reflexive reflex = (Meta.Reflexive)i;
                            int newreflex = reflex.translation + offset + map.SecondaryMagic;
                            // Handle referenced reflexives
                            if (reflex.pointstoTagIndex != m.TagIndex)
                            {
                                newreflex = totalshift + reflex.translation + map.MetaInfo.Offset[reflex.pointstoTagIndex] + map.SecondaryMagic;
                            }
                            map.BW.BaseStream.Position = offset + reflex.offset;
                            map.BW.Write(reflex.chunkcount);
                            map.BW.Write(newreflex);
                            break;

                        case Meta.ItemType.String:
                            Meta.String s = (Meta.String)i;
                            short stringnum = 0;
                            byte stringlength = 0;
                            for (int e = 0; e < map.MapHeader.scriptReferenceCount; e++)
                            {
                                if (s.name == map.Strings.Name[e])
                                {
                                    stringnum = (short)e;
                                    stringlength = (byte)map.Strings.Length[e];
                                }
                            }

                            for (int e = 0; e < strings.Count; e++)
                            {
                                if (((string)strings[e]) == s.name)
                                {
                                    stringnum = (short)(map.MapHeader.scriptReferenceCount + e);
                                    stringlength = (byte)s.name.Length;
                                }
                            }

                            map.BW.BaseStream.Position = offset + s.offset;
                            map.BW.Write(stringnum);
                            map.BW.Write(zero);
                            map.BW.Write(stringlength);
                            break;
                    }
                }
            }

            // totalshift+=howfar;
            int tempfilesize = map.MapHeader.fileSize + totalshift + howfar -
                               map.MetaInfo.Size[map.IndexHeader.metaCount - 1]; // (int)map.BW.BaseStream.Length;

            // map.MapHeader.fileSize+totalshift+howfar-map.MetaInfo.Size [map.IndexHeader.metaCount-1];
            padding = map.Functions.Padding(tempfilesize, 512);
            tempb = new byte[padding];
            map.BW.BaseStream.Position = tempfilesize;
            map.BW.Write(tempb);
            tempfilesize += padding;

            int olddifference = map.MapHeader.fileSize - map.MapHeader.indexOffset;
            int difference = tempfilesize - (map.MapHeader.indexOffset + totalshift);
            int metasize = map.MapHeader.metaSize + howfar - map.MetaInfo.Size[map.IndexHeader.metaCount - 1] + padding;

            // int combined = map.MapHeader.combinedSize + difference;
            int combined = map.MapHeader.combinedSize - olddifference + difference;

            // (int)bspmetasize + difference;
            // MessageBox.Show("test");
            // combined
            // metasize -= bspmetashift;
            // map.MapHeader.combinedSize + howfar - map.MetaInfo.Size[map.IndexHeader.metaCount - 1] + padding;
            // (int)bspmetasize + difference - bspmetashift;
            map.BW.BaseStream.Position = 8;
            map.BW.Write(tempfilesize);
            map.BW.BaseStream.Position = 24;
            map.BW.Write(metasize);
            map.BW.Write(combined);

            map.BW.BaseStream.SetLength(tempfilesize);

            if (bspmagic == map.BSP.sbsp[0].magic)
            {
            }
            else
            {
                int tempbspmagic = map.BSP.sbsp[0].magic + map.BSP.sbsp[0].offset - bspoffset;

                for (int xx = 0; xx < tempbspmeta.items.Count; xx++)
                {
                    Meta.Item i = tempbspmeta.items[xx];
                    switch (i.type)
                    {
                        case Meta.ItemType.Ident:
                            Meta.Ident id = (Meta.Ident)i;
                            if (id.pointstoTagIndex == -1)
                            {
                                for (int e = 0; e < metas.Count; e++)
                                {
                                    Meta tempm = (Meta)metas[e];
                                    if (tempbspmeta.name == id.pointstotagname && tempbspmeta.type == id.pointstotagtype)
                                    {
                                        id.ident = map.BSP.sbsp[0].ident;
                                        break;
                                    }
                                    else if (tempm.name == id.pointstotagname && tempm.type == id.pointstotagtype)
                                    {
                                        id.ident = map.MetaInfo.Ident[map.IndexHeader.metaCount - 1] + (e * 65537);
                                        break;
                                    }

                                    if (e == metas.Count - 1)
                                    {
                                        int sss = Array.IndexOf(map.MetaInfo.TagType, id.intagtype);
                                        id.ident = sss != -1 ? map.MetaInfo.Ident[sss] : -1;
                                    }
                                }
                            }
                            else
                            {
                                id.ident = map.MetaInfo.Ident[id.pointstoTagIndex];
                            }

                            map.BW.BaseStream.Position = bspoffset + id.offset;
                            map.BW.Write(id.ident);
                            break;
                        case Meta.ItemType.String:
                            Meta.String s = (Meta.String)i;
                            short stringnum = 0;
                            byte stringlength = 0;
                            for (int e = 0; e < map.MapHeader.scriptReferenceCount; e++)
                            {
                                if (s.name == map.Strings.Name[e])
                                {
                                    stringnum = (short)e;
                                    stringlength = (byte)map.Strings.Length[e];
                                }
                            }

                            for (int e = 0; e < strings.Count; e++)
                            {
                                if (((string)strings[e]) == s.name)
                                {
                                    stringnum = (short)(map.MapHeader.scriptReferenceCount + e);
                                    stringlength = (byte)s.name.Length;
                                }
                            }

                            map.BW.BaseStream.Position = bspoffset + s.offset;
                            map.BW.Write(stringnum);
                            map.BW.Write(new byte());
                            map.BW.Write(stringlength);
                            break;

                        case Meta.ItemType.Reflexive:
                            Meta.Reflexive rr = (Meta.Reflexive)i;
                            int newreflex = bspoffset + rr.translation + tempbspmagic;
                            map.BW.BaseStream.Position = bspoffset + rr.offset + 4;

                            // map.BW.Write(newreflex);
                            break;
                    }
                }
            }

            for (int x = 0; x < layout.chunks.Count; x++)
            {
                loc = (LayOutChunk)layout.chunks[x];
                for (int xx = 0; xx < loc.rawPieces.Count; xx++)
                {
                    RawInfoChunk r = (RawInfoChunk)loc.rawPieces[xx];
                    r.offsetOfPointer += totalshift;
                    map.BW.BaseStream.Position = r.offsetOfPointer;
                    switch (r.rawType)
                    {
                        case RawDataType.bitm:
                            r.offset += (uint)(totalshift - bitmshift);
                            map.BW.Write(r.offset);
                            break;
                        case RawDataType.DECR:
                            r.offset += (uint)(sndshift + modeshift + bspshift + weathershift);
                            map.BW.Write(r.offset);
                            break;

                            // case RawDataType.snd2:
                        case RawDataType.jmad:
                            r.offset += (uint)(sndshift + modeshift + bspshift + weathershift + decrshift + prtmshift);
                            map.BW.Write(r.offset);
                            break;
                        case RawDataType.mode1:
                            r.offset += (uint)sndshift;
                            map.BW.Write(r.offset);
                            break;
                        case RawDataType.mode2:
                            r.offset += (uint)sndshift;
                            map.BW.Write(r.offset);
                            break;
                        case RawDataType.PRTM:
                            r.offset += (uint)(sndshift + modeshift + bspshift + weathershift + decrshift);
                            map.BW.Write(r.offset);
                            break;
                        case RawDataType.weat:
                            r.offset += (uint)(sndshift + modeshift + bspshift);
                            map.BW.Write(r.offset);
                            break;
                    }
                }
            }

            layout.chunks[tempint] = loc;

            // 	layout.SortChunksByOffset();
            map.CloseMap();

            for (int y = 0; y < filestofix.Length; y++)
            {
                Map mapid = Map.LoadFromFile(filestofix[y]);
                MapAnalyzer analyze = new MapAnalyzer();
                MapLayout lo = analyze.ScanMapForLayOut(mapid, true);

                mapid.OpenMap(MapTypes.Internal);

                for (int x = 0; x < lo.chunks.Count; x++)
                {
                    loc = (LayOutChunk)lo.chunks[x];
                    for (int xx = 0; xx < loc.rawPieces.Count; xx++)
                    {
                        RawInfoChunk r = (RawInfoChunk)loc.rawPieces[xx];
                        if (r.location != map.MapHeader.mapType)
                        {
                            continue;
                        }

                        mapid.BW.BaseStream.Position = r.offsetOfPointer;
                        switch (r.rawType)
                        {
                            case RawDataType.bitm:
                                r.offset += (uint)(totalshift - bitmshift);
                                r.offset |= 0X40000000;
                                mapid.BW.Write(r.offset);
                                break;
                            case RawDataType.DECR:
                                r.offset += (uint)(sndshift + modeshift + bspshift + weathershift);
                                r.offset |= 0X40000000;
                                mapid.BW.Write(r.offset);
                                break;
                            case RawDataType.snd2:
                            case RawDataType.jmad:
                                r.offset +=
                                    (uint)(sndshift + modeshift + bspshift + weathershift + decrshift + prtmshift);
                                r.offset |= 0X40000000;
                                mapid.BW.Write(r.offset);
                                break;
                            case RawDataType.mode1:
                                r.offset += (uint)sndshift;
                                r.offset |= 0X40000000;
                                mapid.BW.Write(r.offset);
                                break;
                            case RawDataType.mode2:
                                r.offset += (uint)sndshift;
                                r.offset |= 0X40000000;
                                mapid.BW.Write(r.offset);
                                break;
                            case RawDataType.PRTM:
                                r.offset += (uint)(sndshift + modeshift + bspshift + weathershift + decrshift);
                                r.offset |= 0X40000000;
                                mapid.BW.Write(r.offset);
                                break;
                            case RawDataType.weat:
                                r.offset += (uint)(sndshift + modeshift + bspshift);
                                r.offset |= 0X40000000;
                                mapid.BW.Write(r.offset);
                                break;
                        }
                    }
                }

                mapid.CloseMap();
                mapid.Sign();
            }
        }
Ejemplo n.º 26
0
 /// <summary>
 /// The get ugh container info.
 /// </summary>
 /// <param name="map">The map.</param>
 /// <remarks></remarks>
 public static void GetUghContainerInfo(Map map)
 {
     Meta.Meta tempughmeta = new Meta.Meta(map);
     map.OpenMap(MapTypes.Internal);
     tempughmeta.ReadMetaFromMap(map.IndexHeader.metaCount - 1, true);
     map.ugh = new ugh_(ref tempughmeta);
     map.CloseMap();
 }
Ejemplo n.º 27
0
        /// <summary>
        /// The halo ce container.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void HaloCEContainer(Map map)
        {
            map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[0] + 1444;
            bspcount = map.BR.ReadInt32();
            int tempr = map.BR.ReadInt32() - map.PrimaryMagic;
            sbsp = new BSPInfo[bspcount];
            for (int x = 0; x < bspcount; x++)
            {
                sbsp[x] = new BSPInfo();
                sbsp[x].pointerOffset = tempr + (x * 32) - map.MetaInfo.Offset[0];
                map.BR.BaseStream.Position = tempr + (x * 32);
                sbsp[x].offset = map.BR.ReadInt32();
                sbsp[x].size = map.BR.ReadInt32();
                sbsp[x].magic = map.BR.ReadInt32() - sbsp[x].offset;
                map.BR.BaseStream.Position = tempr + (x * 32) + 28;
                sbsp[x].ident = map.BR.ReadInt32();
                sbsp[x].TagIndex = map.Functions.ForMeta.FindMetaByID(sbsp[x].ident);
                map.MetaInfo.Offset[sbsp[x].TagIndex] = sbsp[x].offset;
                map.MetaInfo.Size[sbsp[x].TagIndex] = sbsp[x].size;
                map.BR.BaseStream.Position = sbsp[x].offset + 4;
                sbsp[x].Halo1VerticeCount = map.BR.ReadInt32();

                sbsp[x].lightmapoffset = 24;
                map.BR.BaseStream.Position = sbsp[x].lightmapoffset + 12;

                sbsp[x].lightmapident = map.BR.ReadInt32();
                sbsp[x].lightmapTagIndex = map.Functions.ForMeta.FindMetaByID(sbsp[x].ident);
            }

            map.CloseMap();
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BitmapControl"/> class.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public BitmapControl(Map map)
        {
            InitializeComponent();
            this.map = map;

            map.OpenMap(MapTypes.Internal);

            pm = new ParsedBitmap(ref map.SelectedMeta, map);

            for (int x = 0; x < pm.Properties.Length; x++)
            {
                TreeNode tn = new TreeNode("Bitmap #" + x);
                tn.Tag = "BITMAP";

                for (int i = 0; i < map.SelectedMeta.raw.rawChunks.Count; i++)
                {
                    int count = pm.Properties[x].mipMapCount;
                    BitmapRawDataChunk bmRaw = (BitmapRawDataChunk)map.SelectedMeta.raw.rawChunks[i];
                    if (bmRaw.inchunk == x)
                    {
                        TreeNode chunknode = new TreeNode("Chunk #" + bmRaw.num);
                        chunknode.Tag = "CHUNK";

                        int chunkWidth = pm.Properties[x].width >> bmRaw.num;
                        int mipcount = 0;
                        while (chunkWidth > 1 && count > 0)
                        {
                            TreeNode mipnode = new TreeNode("Mipmap #" + (mipcount++));
                            mipnode.Tag = "MIPMAP";
                            chunknode.Nodes.Add(mipnode);
                            chunkWidth >>= 1;
                            count--;
                        }

                        tn.Nodes.Add(chunknode);
                    }
                }

                treeView1.Nodes.Add(tn);
            }

            map.CloseMap();

            DisplayBitmap(0, 0, 0);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// The read chunks.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void ReadChunks(Map map)
        {
            map.OpenMap(MapTypes.Internal);
            for (int x = 0; x < chunks.Count; x++)
            {
                LayOutChunk l = (LayOutChunk)chunks[x];
                l.Read(map);
                GC.Collect(0);
                GC.WaitForPendingFinalizers();
            }

            map.CloseMap();
        }
Ejemplo n.º 30
0
        /// <summary>
        /// The ce shader info.
        /// </summary>
        /// <param name="TagIndex">The TagIndex.</param>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void CEShaderInfo(int TagIndex, Map map)
        {
            this.TagIndex = TagIndex;
            if (this.TagIndex == -1)
            {
                return;
            }

            this.shaderName = map.FileNames.Name[this.TagIndex];

            map.OpenMap(MapTypes.Internal);
            int mainid = 0;
            int primarydetail = -1;
            int secondarydetail = -1;
            int micro = -1;
            switch (map.MetaInfo.TagType[TagIndex])
            {
                case "schi":
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 228;
                    mainid = map.BR.ReadInt32();
                    break;
                case "soso":
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 176;
                    mainid = map.BR.ReadInt32();
                    break;
                case "sgla":
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 356;
                    mainid = map.BR.ReadInt32();
                    break;
                case "scex":
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 900;
                    mainid = map.BR.ReadInt32();
                    break;
                case "senv":
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 148;
                    mainid = map.BR.ReadInt32();
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 180;
                    this.primarydetailuscale = map.BR.ReadSingle();
                    this.primarydetailvscale = this.primarydetailuscale;
                    this.primarydetailwscale = 1;
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 196;
                    primarydetail = map.BR.ReadInt32();

                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 200;
                    this.secondarydetailuscale = map.BR.ReadSingle();
                    this.secondarydetailvscale = this.secondarydetailuscale;
                    this.secondarydetailwscale = 1;
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 216;
                    secondarydetail = map.BR.ReadInt32();

                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 248;
                    this.microdetailuscale = map.BR.ReadSingle();
                    this.microdetailvscale = this.secondarydetailuscale;
                    this.microdetailwscale = 1;
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 264;
                    micro = map.BR.ReadInt32();

                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 40;
                    byte alphatest = map.BR.ReadByte();
                    int test = alphatest & 1;
                    if (test != 0)
                    {
                        this.Alpha = AlphaType.AlphaTest;
                    }

                    break;
                case "swat":
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 88;
                    mainid = map.BR.ReadInt32();
                    break;
                case "smet":
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 88;
                    mainid = map.BR.ReadInt32();
                    break;
            }

            map.CloseMap();

            mainid = map.Functions.ForMeta.FindMetaByID(mainid);
            primarydetail = map.Functions.ForMeta.FindMetaByID(primarydetail);
            secondarydetail = map.Functions.ForMeta.FindMetaByID(secondarydetail);
            micro = map.Functions.ForMeta.FindMetaByID(micro);
            if (mainid == -1)
            {
                return;
            }

            if (map.MetaInfo.external[mainid])
            {
                map.OpenMap(MapTypes.Bitmaps);
            }
            else
            {
                map.OpenMap(MapTypes.Internal);
            }

            Meta tempmeta = new Meta(map);
            tempmeta.ReadMetaFromMap(mainid, false);

            map.CloseMap();
            ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
            // Attempt to load LOD2, if that fails, load LOD0
            try
            {
                this.MainBitmap = pm.FindChunkAndDecode(0, 2, 0, ref tempmeta, map, 0, 0);
            }
            catch
            {
                this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
            }
            this.MainName = map.FileNames.Name[mainid];

            if (primarydetail != -1)
            {
                if (map.MetaInfo.external[primarydetail])
                {
                    map.OpenMap(MapTypes.Bitmaps);
                }
                else
                {
                    map.OpenMap(MapTypes.Internal);
                }

                tempmeta = new Meta(map);
                tempmeta.ReadMetaFromMap(primarydetail, false);

                map.CloseMap();
                pm = new ParsedBitmap(ref tempmeta, map);
                this.primarydetailBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                this.primarydetailName = map.FileNames.Name[primarydetail];
            }

            if (secondarydetail != -1)
            {
                if (map.MetaInfo.external[secondarydetail])
                {
                    map.OpenMap(MapTypes.Bitmaps);
                }
                else
                {
                    map.OpenMap(MapTypes.Internal);
                }

                tempmeta = new Meta(map);
                tempmeta.ReadMetaFromMap(secondarydetail, false);

                map.CloseMap();
                pm = new ParsedBitmap(ref tempmeta, map);
                this.secondarydetailBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                this.secondarydetailName = map.FileNames.Name[secondarydetail];
            }

            if (micro != -1)
            {
                if (map.MetaInfo.external[micro])
                {
                    map.OpenMap(MapTypes.Bitmaps);
                }
                else
                {
                    map.OpenMap(MapTypes.Internal);
                }

                tempmeta = new Meta(map);
                tempmeta.ReadMetaFromMap(micro, false);

                map.CloseMap();
                pm = new ParsedBitmap(ref tempmeta, map);
                this.microdetailBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                this.microdetailName = map.FileNames.Name[micro];
            }
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Internalizes a bitmap by passing raw data. This was primarily written for the bitmap internalization
        /// in the mainmenu editor.
        /// </summary>
        /// <param name="raw">Entity.RawDataContainer</param>
        /// <param name="map">Map to add data to</param>
        /// <remarks></remarks>
        public static void bitmapInternalizeRaw(ref RawDataContainer raw, Map map)
        {
            map.OpenMap(MapTypes.Internal, false);
            long rawSize = biGetRawTotalSize(raw, false);
            shift(map.FS, map.MapHeader.indexOffset, rawSize);

            //long offsetInShared;
            long offsetToWrite = map.MapHeader.indexOffset;
            map.BW.BaseStream.Position = offsetToWrite;
            //byte[] rawData;

            // loop for each tag
            //int tempRawSize;

            // loop for each chunk
            for (int j = 0; j < raw.rawChunks.Count; j++)
            {
                // loop for each LOD
                {
                    // for (int k = 0; k < bitmapMeta.raw.rawChunks.lod.Count; k++)
                    raw.rawChunks[j].offset = (int)map.BW.BaseStream.Position;
                    raw.rawChunks[j].rawLocation = MapTypes.Internal;

                    map.BW.Write(raw.rawChunks[j].MS.ToArray(), 0, raw.rawChunks[j].size);

                    // writes padding after chunk
                    int paddingSize = genPaddingSize(raw.rawChunks[j].size, 512);
                    map.BW.Write(genPadding(paddingSize, 0));

                    offsetToWrite += raw.rawChunks[j].size + paddingSize;
                }
            }

            biUpdateMapInfo(map, (int)rawSize);

            map.CloseMap();
        }
Ejemplo n.º 32
0
        /// <summary>
        /// The halo 2 bsp container.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void Halo2BSPContainer(Map map)
        {
            map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 528;
            bspcount = map.BR.ReadInt32();
            int tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            sbsp = new BSPInfo[bspcount];
            for (int x = 0; x < bspcount; x++)
            {
                sbsp[x] = new BSPInfo();
                sbsp[x].pointerOffset      = tempr + (x * 68) - map.MetaInfo.Offset[3];
                map.BR.BaseStream.Position = tempr + (x * 68);
                sbsp[x].offset             = map.BR.ReadInt32();
                map.Functions.ParsePointer(ref sbsp[x].offset, ref sbsp[x].location);
                sbsp[x].size  = map.BR.ReadInt32();
                sbsp[x].magic = map.BR.ReadInt32() - sbsp[x].offset;
                map.BR.BaseStream.Position = tempr + (x * 68) + 20;
                sbsp[x].ident = map.BR.ReadInt32();

                //  MessageBox.Show(sbsp[x].ident.ToString("X"));
                sbsp[x].TagIndex = map.Functions.ForMeta.FindMetaByID(sbsp[x].ident);
                map.MetaInfo.Offset[sbsp[x].TagIndex] = sbsp[x].offset;
                map.MetaInfo.Size[sbsp[x].TagIndex]   = sbsp[x].size;
                map.BR.BaseStream.Position            = tempr + (x * 68) + 28;
                sbsp[x].lightmapident    = map.BR.ReadInt32();
                sbsp[x].lightmapTagIndex = map.Functions.ForMeta.FindMetaByID(sbsp[x].lightmapident);
                if (sbsp[x].lightmapTagIndex == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = sbsp[x].offset + 8;
                sbsp[x].lightmapoffset     = map.BR.ReadInt32();
                if (sbsp[x].lightmapoffset == 0)
                {
                    sbsp[x].lightmapident    = -1;
                    sbsp[x].lightmapTagIndex = -1;
                    if (
                        MessageBox.Show(
                            "There is no lightmap for this bsp and the scenario is currently linked to a broken ID.\n Would you like Entity to fix it?",
                            "Error",
                            MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        map.BW.BaseStream.Position = tempr + (x * 68) + 28;
                        map.BW.Write(int.Parse("FFFFFFFF", NumberStyles.HexNumber));
                    }

                    continue;
                }

                sbsp[x].lightmapoffset += -sbsp[x].magic;
                sbsp[x].lightmapsize    = sbsp[x].size + sbsp[x].offset - sbsp[x].lightmapoffset;

                map.MetaInfo.Offset[sbsp[x].lightmapTagIndex] = sbsp[x].lightmapoffset;
                map.MetaInfo.Size[sbsp[x].lightmapTagIndex]   = sbsp[x].lightmapsize;

                // light map bitmap
                map.BR.BaseStream.Position = sbsp[x].lightmapoffset + 128;
                int tempc  = map.BR.ReadInt32();
                int temprx = map.BR.ReadInt32() - sbsp[x].magic;
                map.BR.BaseStream.Position = temprx + 28;
                sbsp[x].LightMap_TagNumber = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                ///light map palettes
                map.BR.BaseStream.Position = temprx + 8;
                int tempc2 = map.BR.ReadInt32();
                int tempr2 = map.BR.ReadInt32() - sbsp[x].magic;
                sbsp[x].palettesoffset = tempr2;
                for (int y = 0; y < tempc2; y++)
                {
                    map.BR.BaseStream.Position = tempr2 + (y * 1024);
                    Palette_Color[] pc = new Palette_Color[256];
                    for (int z = 0; z < 256; z++)
                    {
                        pc[z]   = new Palette_Color();
                        pc[z].r = map.BR.ReadByte();
                        pc[z].g = map.BR.ReadByte();
                        pc[z].b = map.BR.ReadByte();
                        pc[z].a = map.BR.ReadByte();
                    }

                    sbsp[x].LightMap_Palettes.Add(pc);
                }

                map.BR.BaseStream.Position = temprx + 40;
                tempc2 = map.BR.ReadInt32();
                tempr2 = map.BR.ReadInt32() - sbsp[x].magic;
                sbsp[x].VisualChunk_Bitmap_Index   = new int[tempc2];
                sbsp[x].VisualChunk_LightMap_Index = new int[tempc2];

                if (tempc2 != 0)
                {
                    map.BR.BaseStream.Position = tempr2;
                    for (int y = 0; y < tempc2; y++)
                    {
                        sbsp[x].VisualChunk_Bitmap_Index[y]   = map.BR.ReadInt16();
                        sbsp[x].VisualChunk_LightMap_Index[y] = map.BR.ReadInt16();
                    }
                }

                map.BR.BaseStream.Position = temprx + 72;
                tempc2 = map.BR.ReadInt32();
                tempr2 = map.BR.ReadInt32() - sbsp[x].magic;
                sbsp[x].SceneryChunk_Bitmap_Index   = new int[tempc2];
                sbsp[x].SceneryChunk_LightMap_Index = new int[tempc2];

                if (tempc2 > 0)
                {
                    map.BR.BaseStream.Position = tempr2;
                    for (int y = 0; y < tempc2; y++)
                    {
                        sbsp[x].SceneryChunk_Bitmap_Index[y]   = map.BR.ReadInt16();
                        sbsp[x].SceneryChunk_LightMap_Index[y] = map.BR.ReadInt16();
                    }
                }
            }

            map.CloseMap();
        }