ReadMetaFromMap() публичный Метод

The read meta from map.
public ReadMetaFromMap ( int tagIndex, bool dontReadRaw ) : void
tagIndex int The tagIndex.
dontReadRaw bool
Результат void
Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MetaItemComparer"/> class.
        /// </summary>
        /// <param name="currentForm">The current form.</param>
        /// <remarks></remarks>
        public MetaItemComparer(MapForm currentForm)
        {
            Map map = currentForm.map;

            int counter = 0;
            for (counter = 0; counter < map.MapHeader.fileCount; counter++)
            {
                currentForm.SetProgressBar(counter * 100 / map.MapHeader.fileCount);

                ifpMeta = new Meta(map);
                manualMeta = new Meta(map);
                manualMeta.ReadMetaFromMap(counter, false);
                ifpMeta.ReadMetaFromMap(counter, false);

                // parse ifp and scan meta with it
                try
                {
                    IFPIO io = IFPHashMap.GetIfp(ifpMeta.type, map.HaloVersion);

                    ifpMeta.headersize = io.headerSize;
                    manualMeta.headersize = io.headerSize;
                    try
                    {
                        ifpMeta.scanner.ScanWithIFP(ref io);
                    }
                    catch (Exception ex)
                    {
                        Global.ShowErrorMsg("Broken IFP - " + ifpMeta.type, ex);
                    }

                    manualMeta.scanner.ScanManually();
                    check(map);
                }
                catch (Exception ex)
                {
                    Globals.Global.ShowErrorMsg(string.Empty, ex);
                }

            }

            currentForm.SetProgressBar(0);
        }
Пример #2
0
        public void Populate(int iOffset, int iIndexedReflexiveOffset)
        {
            this.isNulledOutReflexive = false;
            System.IO.BinaryReader BR = new System.IO.BinaryReader(meta.MS);

            int mapMetaOffset = meta.offset;

            if (this._EntIndex.reflexiveTagType + this._EntIndex.reflexiveTagName != string.Empty)
            {
                int tagNum = map.Functions.ForMeta.FindByNameAndTagType(this._EntIndex.reflexiveTagType, this._EntIndex.reflexiveTagName);
                if (tagNum != -1)
                {
                    Meta meta2 = new Meta(map);
                    map.OpenMap(MapTypes.Internal);
                    meta2.ReadMetaFromMap(tagNum, true);
                    map.CloseMap();
                    mapMetaOffset = meta2.offset;
                    this._EntIndex.reflexiveLayer = "root";
                }
            }

            if (this._EntIndex.reflexiveLayer.ToLower() == "root")
                this._IndexedReflexiveOffset = mapMetaOffset + this._EntIndex.ReflexiveOffset;
            else if (this._EntIndex.reflexiveLayer.ToLower() == "oneup")
                this._IndexedReflexiveOffset = iIndexedReflexiveOffset + this._EntIndex.ReflexiveOffset;

            /*
            bool openedMap = false;
            if (map.isOpen == false)
            {
                map.OpenMap(MapTypes.Internal);
                openedMap = true;
            }
            map.BA.Position = iOffset + this.chunkOffset;
            */
            BR.BaseStream.Position = iOffset + this.chunkOffset;
            this.offsetInMap = meta.offset + iOffset + this.chunkOffset;

            switch (_ValueType)
            {
                case IFPIO.ObjectEnum.Short:
                    {
                        this.Value = (int)BR.ReadInt16();
                        break;
                    }
                case IFPIO.ObjectEnum.Int:
                    {
                        this.Value = BR.ReadInt32();
                        break;
                    }
                case IFPIO.ObjectEnum.UShort:
                    {
                        this.Value = (int)BR.ReadUInt16();
                        break;
                    }
                case IFPIO.ObjectEnum.UInt:
                    {
                        this.Value = (int)BR.ReadUInt32();
                        break;
                    }
                case IFPIO.ObjectEnum.Byte:
                    {
                        this.Value = (int)BR.ReadByte();
                        break;
                    }
            }
            UpdateSelectionList(false);
            /*
            if (openedMap == true)
                map.CloseMap();
            */
        }
Пример #3
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();
        }
Пример #4
0
        /// <summary>
        /// The save recursive function.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <param name="metas">The metas.</param>
        /// <param name="parsed">The parsed.</param>
        /// <param name="pb">The pb.</param>
        /// <param name="percent">The percent.</param>
        /// <param name="percentsize">The percentsize.</param>
        /// <remarks></remarks>
        private void SaveRecursiveFunction(
            Meta meta,
            ref ArrayList metas,
            bool parsed,
            ToolStripProgressBar pb,
            float percent,
            float percentsize)
        {
            int wtf = metas.Count;

            if (meta.items.Count == 0)
            {
                return;
            }

            float test = meta.items.Count;

            float currentpercentsize = percentsize / test;

            Item i = null;

            try
            {
                for (int x = 0; x < meta.items.Count; x++)
                {
                    i = meta.items[x];
                    if (i.type != ItemType.Ident)
                    {
                        continue;
                    }

                    float currentpercentage = percent + (currentpercentsize * x);
                    pb.Value = (int)currentpercentage;
                    Application.DoEvents();

                    Ident id = (Ident)i;

                    if (id.ident == -1)
                    {
                        continue;
                    }

                    if (id.ident == 0)
                    {
                        int tagIndex = Map.Functions.ForMeta.FindByNameAndTagType("sbsp", i.intagname);
                        id.ident = Map.MetaInfo.Ident[tagIndex];
                    }

                    bool exists = false;

                    for (int e = 0; e < metas.Count; e++)
                    {
                        Meta tempmeta = (Meta)metas[e];

                        // if (id.pointstotagtype  ==tempmeta.type&&id.pointstotagname ==tempmeta.name )
                        if (id.ident == tempmeta.ident)
                        {
                            exists = true;
                            break;
                        }
                    }

                    if (exists)
                    {
                        continue;
                    }

                    // Drag & drop w/ recursive locks up. num == -1
                    int num = Map.Functions.ForMeta.FindMetaByID(id.ident);
                    if (num < 0)
                    {
                        MessageBox.Show("ERROR! Not Found!");
                    }

                    Meta m = new Meta(Map);
                    if (parsed)
                    {
                        m.parsed = true;
                    }

                    m.ReadMetaFromMap(num, false);
                    if (m.type == "ltmp" | m.type == "matg")
                    {
                        continue;
                    }

                    if (m.type == "phmo" | m.type == "coll" | m.type == "jmad")
                    {
                        m.parsed = false;
                    }

                    if (m.type != "jmad")
                    {
                        IFPIO ifp = IFPHashMap.GetIfp(m.type, Map.HaloVersion);
                        m.headersize = ifp.headerSize;

                        m.scanner.ScanWithIFP(ref ifp);
                    }
                    else
                    {
                        m.scanner.ScanManually();
                    }

                    m.SortItemsByOffset();

                    metas.Add(m);

                    Application.DoEvents();
                    SaveRecursiveFunction(m, ref metas, parsed, pb, currentpercentage, currentpercentsize);
                }
            }
            catch (Exception e)
            {
                string addOn = "\nin [" + meta.type + "] " + meta.name;
                if (i.type == ItemType.Ident)
                {
                    addOn = "\n" + i.description + ", Ident: " + ((Ident)i).ident + addOn;
                }
                throw new Exception(e.Message + addOn, e.InnerException);
            }
        }
Пример #5
0
        /// <summary>
        /// The map rebuilder.
        /// </summary>
        /// <param name="layout">The layout.</param>
        /// <remarks></remarks>
        public void MapRebuilder(ref MapLayout layout)
        {
            int totalshift = 0;

            // find new strings
            ///
            ///
            ArrayList strings = new ArrayList();
            foreach (string s in map.Strings.Name)
            {
                strings.Add(s);
            }

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[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 (strings.IndexOf(iii.name) == -1)
                        {
                            strings.Add(iii.name);
                        }
                    }
                }
            }

            ///read ugh to meta
            ///
            ///
            map.OpenMap(MapTypes.Internal);
            Meta ughmeta = new Meta(map);
            ughmeta.ReadMetaFromMap(map.IndexHeader.metaCount - 1, false);
            IFPIO ifp = IFPHashMap.GetIfp("ugh!", map.HaloVersion);

            ughmeta.headersize = ifp.headerSize;
            ughmeta.scanner.ScanWithIFP(ref ifp);
            MetaList.Add(ughmeta);

            string temps = string.Empty;

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

            //////////////////////////////////////
            ///model raw data
            ///
            int modeshift = 0;

            loc.startoffset += totalshift;

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[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];

                        if (r.rawLocation != MapTypes.Internal)
                        {
                            int tempintxx = r.offset;
                            if (r.rawLocation == MapTypes.MPShared)
                            {
                                tempintxx |= int.Parse("80000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.SPShared)
                            {
                                tempintxx |= int.Parse("C0000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.MainMenu)
                            {
                                tempintxx |= int.Parse("40000000", NumberStyles.HexNumber);
                            }

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

                        int tempintx = loc.startoffset + 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;
                    }

                    MetaList[x] = m;
                }
            }

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

            layout.chunks[tempint] = loc;

            int curroffset = loc.endoffset;

            /////////////////////////////////////
            /// bsp raw
            ///

            int bspcount = 0;
            int[] bspmagic = new int[20];
            int[] bspmagicreflexive = new int[20];
            int[] bsprawoffset = new int[20];
            int[] bsprawsize = new int[20];
            int totalbsprawsize = 0;
            bool found = false;

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[x];
                if (m.type == "sbsp")
                {
                    BinaryWriter BW = new BinaryWriter(m.MS);
                    int[] tempoff = new int[m.raw.rawChunks.Count];
                    int thisbsprawsize = 0;
                    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] = curroffset + thisbsprawsize;

                        // 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 = curroffset + thisbsprawsize;
                        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);
                        thisbsprawsize += r.size + tempinty;
                        totalbsprawsize += r.size + tempinty;
                    }

                    bsprawsize[bspcount] = thisbsprawsize;
                    bspmagic[bspcount] = m.magic;
                    bspmagicreflexive[bspcount] = m.magic + m.offset;

                    curroffset += bsprawsize[bspcount];

                    // bspmagic=m.magic;
                    // newmagicreflexive=bspmagic+m.offset;
                    bspcount += 1;
                    MetaList[x] = m;
                }
            }

            //////////////////////////////////////
            ///weather raw data
            ///
            int weathershift = 0;
            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[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];
                        if (r.rawLocation != MapTypes.Internal)
                        {
                            int tempintxx = r.offset;
                            if (r.rawLocation == MapTypes.MPShared)
                            {
                                tempintxx |= int.Parse("80000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.SPShared)
                            {
                                tempintxx |= int.Parse("C0000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.MainMenu)
                            {
                                tempintxx |= int.Parse("40000000", NumberStyles.HexNumber);
                            }

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

                        int tempintx = curroffset + 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;
                    }

                    MetaList[x] = m;
                }
            }

            curroffset += weathershift;

            //////////////////////////////////////
            ///decr raw data
            ///
            int decrshift = 0;
            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[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];
                        if (r.rawLocation != MapTypes.Internal)
                        {
                            int tempintxx = r.offset;
                            if (r.rawLocation == MapTypes.MPShared)
                            {
                                tempintxx |= int.Parse("80000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.SPShared)
                            {
                                tempintxx |= int.Parse("C0000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.MainMenu)
                            {
                                tempintxx |= int.Parse("40000000", NumberStyles.HexNumber);
                            }

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

                        int tempintx = curroffset + 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;
                    }

                    MetaList[x] = m;
                }
            }

            curroffset += decrshift;

            //////////////////////////////////////
            ///prtm raw data
            ///
            int prtmshift = 0;

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[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];
                        if (r.rawLocation != MapTypes.Internal)
                        {
                            int tempintxx = r.offset;
                            if (r.rawLocation == MapTypes.MPShared)
                            {
                                tempintxx |= int.Parse("80000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.SPShared)
                            {
                                tempintxx |= int.Parse("C0000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.MainMenu)
                            {
                                tempintxx |= int.Parse("40000000", NumberStyles.HexNumber);
                            }

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

                        int tempintx = curroffset + 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;
                    }

                    MetaList[x] = m;
                }
            }

            curroffset += prtmshift;

            //////////////////////////////////////
            ///jmad raw data
            ///
            int jmadshift = 0;

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[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];
                        if (r.rawLocation != MapTypes.Internal)
                        {
                            int tempintxx = r.offset;
                            if (r.rawLocation == MapTypes.MPShared)
                            {
                                tempintxx |= int.Parse("80000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.SPShared)
                            {
                                tempintxx |= int.Parse("C0000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.MainMenu)
                            {
                                tempintxx |= int.Parse("40000000", NumberStyles.HexNumber);
                            }

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

                        int tempintx = curroffset + 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;
                    }

                    MetaList[x] = m;
                }
            }

            curroffset += jmadshift;

            //////////////////////////////////////
            ///bsp meta data
            ///

            int[] bspmetaoffset = new int[20];
            int[] bspmetasize = new int[20];

            int tempcount = 0;
            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[x];
                if (m.type == "sbsp")
                {
                    Meta mm = (Meta)MetaList[3];
                    if (mm.type == "scnr")
                    {
                        BinaryWriter BWX = new BinaryWriter(mm.MS);
                        int tempoffx = map.BSP.sbsp[tempcount].pointerOffset;
                        BWX.BaseStream.Position = tempoffx;

                        BWX.Write(curroffset);
                        BWX.Write(m.size);
                        BWX.Write(bspmagicreflexive[tempcount]);
                        MetaList[3] = mm;
                    }

                    map.BW.BaseStream.Position = curroffset;
                    map.BW.BaseStream.Write(m.MS.ToArray(), 0, m.size);
                    bspmetasize[tempcount] = m.size;
                    bspmetaoffset[tempcount] = curroffset;
                    curroffset += m.size;
                    tempcount++;
                }
            }

            ////stringnames1
            ///

            byte[] tempb = new byte[strings.Count * 128];
            map.BW.BaseStream.Position = curroffset;
            map.BW.BaseStream.Write(tempb, 0, strings.Count * 128);
            for (int x = 0; x < strings.Count; x++)
            {
                map.BW.BaseStream.Position = curroffset + (x * 128);
                char[] tempc = ((String)strings[x]).ToCharArray();
                map.BW.Write(tempc);
            }

            map.BW.BaseStream.Position = 352;
            map.BW.Write(curroffset);
            int newcount = strings.Count;
            map.BW.Write(newcount);

            curroffset += strings.Count * 128;

            int padding = map.Functions.Padding(curroffset, 512);
            tempb = new byte[padding];
            map.BW.BaseStream.Position = curroffset;
            map.BW.BaseStream.Write(tempb, 0, padding);
            curroffset += padding;

            ////stringsindex
            ///

            int tempnewsrsize = strings.Count * 4;
            map.BW.BaseStream.Position = curroffset;

            int temporary = 0;
            for (int x = 0; x < strings.Count; x++)
            {
                map.BW.BaseStream.Position = curroffset + (x * 4);
                map.BW.Write(temporary);
                temporary += ((String)strings[x]).Length + 1;
            }

            map.BW.BaseStream.Position = 364;
            map.BW.Write(curroffset);
            curroffset += tempnewsrsize;

            padding = map.Functions.Padding(curroffset, 512);
            tempb = new byte[padding];
            map.BW.BaseStream.Position = curroffset;
            map.BW.BaseStream.Write(tempb, 0, padding);
            curroffset += padding;

            ////strings2
            ///

            temporary = 0;
            byte zero = 0;
            for (int x = 0; x < strings.Count; x++)
            {
                map.BW.BaseStream.Position = curroffset + temporary;
                char[] h = ((String)strings[x]).ToCharArray();
                map.BW.Write(h);
                map.BW.Write(zero);
                temporary += ((String)strings[x]).Length + 1;
            }

            map.BW.BaseStream.Position = 360;
            map.BW.Write(temporary);
            map.BW.BaseStream.Position = 368;
            map.BW.Write(curroffset);
            curroffset += temporary;

            padding = map.Functions.Padding(curroffset, 512);
            tempb = new byte[padding];
            map.BW.BaseStream.Position = curroffset;
            map.BW.BaseStream.Write(tempb, 0, padding);
            curroffset += padding;

            ////file names
            ///

            temporary = 0;
            for (int x = 0; x < MetaList.Count; x++)
            {
                map.BW.BaseStream.Position = curroffset + temporary;
                char[] h = ((Meta)MetaList[x]).name.ToCharArray();
                map.BW.Write(h);
                map.BW.Write(zero);
                temporary += ((Meta)MetaList[x]).name.Length + 1;
            }

            map.BW.BaseStream.Position = 704;
            newcount = MetaList.Count;
            map.BW.Write(newcount);
            map.BW.Write(curroffset);
            map.BW.Write(temporary);
            curroffset += temporary;

            padding = map.Functions.Padding(curroffset, 512);
            tempb = new byte[padding];
            map.BW.BaseStream.Position = curroffset;
            map.BW.BaseStream.Write(tempb, 0, padding);
            curroffset += padding;

            ////files index
            ///
            temporary = 0;
            for (int x = 0; x < MetaList.Count; x++)
            {
                map.BW.BaseStream.Position = curroffset + (x * 4);
                map.BW.Write(temporary);
                temporary += ((Meta)MetaList[x]).name.Length + 1;
            }

            map.BW.BaseStream.Position = 716;
            map.BW.Write(curroffset);

            curroffset += MetaList.Count * 4;
            padding = map.Functions.Padding(curroffset, 512);
            tempb = new byte[padding];
            map.BW.BaseStream.Position = curroffset;
            map.BW.BaseStream.Write(tempb, 0, padding);
            curroffset += padding;

            tempint = layout.FindByType(RawDataContainerType.UnicodeNamesIndex);
            for (int x = 0; x < 9; x++)
            {
                map.Unicode.ut[x].indexOffset = curroffset;
                if (x != 8)
                {
                    loc = (LayOutChunk)layout.chunks[tempint + (x * 2)];
                    loc.startoffset = curroffset;
                    loc.endoffset = loc.startoffset + loc.size;
                    map.BW.BaseStream.Position = loc.startoffset;
                    map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);
                    layout.chunks[tempint + (x * 2)] = loc;
                    curroffset += loc.size;
                }

                map.Unicode.ut[x].tableOffset = curroffset;
                if (x != 8)
                {
                    LayOutChunk loc2 = (LayOutChunk)layout.chunks[tempint + (x * 2) + 1];
                    loc2.startoffset = curroffset;
                    loc2.endoffset = loc2.startoffset + loc.size;
                    map.BW.BaseStream.Position = loc2.startoffset;
                    map.BW.BaseStream.Write(loc2.MS.ToArray(), 0, loc2.size);
                    layout.chunks[tempint + (x * 2) + 1] = loc2;

                    curroffset += loc2.size;
                }
            }

            Meta tempmatg = (Meta)MetaList[0];
            BinaryWriter BWXX = new BinaryWriter(tempmatg.MS);
            for (int x = 0; x < 9; x++)
            {
                BWXX.BaseStream.Position = map.Unicode.ut[x].indexPointerOffset;
                BWXX.Write(map.Unicode.ut[x].indexOffset);
                BWXX.Write(map.Unicode.ut[x].tableOffset);
            }

            MetaList[0] = tempmatg;

            tempint = layout.FindByType(RawDataContainerType.Crazy);
            loc = (LayOutChunk)layout.chunks[tempint];
            loc.startoffset = curroffset;

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

            curroffset += loc.size;

            //////////////////////////////////////
            ///bitmap raw data
            ///
            int bitmshift = 0;
            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[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];
                        if (r.rawLocation != MapTypes.Internal)
                        {
                            int tempintxx = r.offset;
                            if (r.rawLocation == MapTypes.MPShared)
                            {
                                tempintxx |= int.Parse("80000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.SPShared)
                            {
                                tempintxx |= int.Parse("C0000000", NumberStyles.HexNumber);
                            }
                            else if (r.rawLocation == MapTypes.MainMenu)
                            {
                                tempintxx |= int.Parse("40000000", NumberStyles.HexNumber);
                            }

                            // writes new pointer to loaded meta
                            BW.BaseStream.Position = r.pointerMetaOffset;
                            BW.Write(tempintxx);
                            BW.BaseStream.Position = r.pointerMetaOffset + 24;
                            BW.Write(r.size);
                            continue;
                        }

                        int tempintx = curroffset + bitmshift;

                        // writes new pointer to loaded meta
                        BW.BaseStream.Position = r.pointerMetaOffset;
                        BW.Write(tempintx);
                        BW.BaseStream.Position = r.pointerMetaOffset + 24;
                        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;
                    }

                    MetaList[x] = m;
                }
            }

            curroffset += bitmshift;

            tempint = layout.FindByType(RawDataContainerType.MetaIndex);

            loc = (LayOutChunk)layout.chunks[tempint];
            loc.startoffset = curroffset;

            map.BW.BaseStream.Position = loc.startoffset;
            map.BW.BaseStream.Write(loc.MS.ToArray(), 0, loc.size);
            map.BW.BaseStream.Position = 16;
            map.BW.Write(loc.startoffset);
            newcount = MetaList.Count;
            map.BW.BaseStream.Position = loc.startoffset + 24;
            map.BW.Write(newcount);

            int tagsoff = map.IndexHeader.tagsOffset - map.MapHeader.indexOffset;
            map.PrimaryMagic = map.IndexHeader.constant - (curroffset + 32);
            map.SecondaryMagic = map.PrimaryMagic + bspmetasize[0];

            // map.SecondaryMagic=map.BR.ReadInt32()-(loc.startoffset+map.MapHeader.metaStart);
            int where = curroffset + map.MapHeader.metaStart;
            tempcount = 0;
            int howfar = 0;
            int[] newoffset = new int[MetaList.Count];
            int[] newident = new int[MetaList.Count];

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[x];
                int f**k = curroffset + tagsoff + (x * 16);

                char[] metatype = m.type.ToCharArray();
                Array.Reverse(metatype);
                int ident = map.MetaInfo.Ident[0] + (x * 65537);
                int offset = where + howfar;

                if (x == MetaList.Count - 1)
                {
                    int wherex = curroffset + map.MapHeader.metaStart + 756;
                    map.BW.BaseStream.Position = wherex;
                    map.BW.Write(ident);
                }

                if (m.type == "phmo" | m.type == "coll" | m.type == "spas")
                {
                    int tempoffset = offset;
                    do
                    {
                        string tempss = tempoffset.ToString("X");
                        char[] tempc = tempss.ToCharArray();
                        int xxx = tempc.Length;
                        if (m.padding == tempc[xxx - 1])
                        {
                            int diff = tempoffset - offset;
                            tempb = new byte[diff];
                            map.BW.BaseStream.Position = offset;
                            map.BW.Write(tempb);

                            int tempsize = ((Meta)MetaList[x - 1]).size;
                            tempsize += diff;
                            int temploc = f**k - 4;
                            map.BW.BaseStream.Position = temploc;
                            map.BW.Write(tempsize);

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

                        tempoffset++;
                    }
                    while (temps != null);
                }

                newoffset[x] = offset;
                newident[x] = ident;
                int offsetwithmagic = offset + map.SecondaryMagic;
                int size = m.size;

                map.BW.BaseStream.Position = f**k;
                map.BW.Write(metatype);
                map.BW.Write(ident);

                if (m.type != "sbsp" && m.type != "ltmp")
                {
                    map.BW.Write(offsetwithmagic);
                    map.BW.Write(size);
                    howfar += m.size;
                    map.BW.BaseStream.Position = offset;
                    map.BW.BaseStream.Write(m.MS.ToArray(), 0, m.size);
                }
                else
                {
                    int zeroi = 0;
                    map.BW.Write(zeroi);
                    map.BW.Write(zeroi);
                    if (m.type == "sbsp")
                    {
                        offset = bspmetaoffset[tempcount];
                        newoffset[x] = offset;
                        tempcount++;
                    }
                    else
                    {
                        continue;
                    }
                }
            }

            for (int x = 0; x < MetaList.Count; x++)
            {
                Meta m = (Meta)MetaList[x];
                for (int xx = 0; xx < m.items.Count; xx++)
                {
                    Meta.Item i = m.items[xx];
                    for (int e = 0; e < MetaList.Count; e++)
                    {
                        Meta tempm = (Meta)MetaList[e];
                        if (tempm.name == i.intagname && tempm.type == i.intagtype)
                        {
                            i.intag = e;
                            break;
                        }
                    }

                    if (i.intag != x)
                    {
                        continue;
                    }

                    switch (i.type)
                    {
                        case Meta.ItemType.Ident:
                            Meta.Ident id = (Meta.Ident)i;
                            id.ident = -1;
                            for (int e = 0; e < MetaList.Count; e++)
                            {
                                Meta tempm = (Meta)MetaList[e];
                                if (tempm.name == id.pointstotagname && tempm.type == id.pointstotagtype)
                                {
                                    id.ident = newident[e];
                                    break;
                                }
                            }

                            map.BW.BaseStream.Position = newoffset[x] + id.offset;
                            map.BW.Write(id.ident);
                            break;
                        case Meta.ItemType.Reflexive:
                            if (m.type != "sbsp")
                            {
                                Meta.Reflexive reflex = (Meta.Reflexive)i;
                                for (int e = 0; e < MetaList.Count; e++)
                                {
                                    Meta tempm = (Meta)MetaList[e];
                                    if (reflex.pointstotagname == tempm.name && reflex.pointstotagtype == tempm.type)
                                    {
                                        reflex.pointstoTagIndex = e;
                                        break;
                                    }
                                }

                                int newreflex = reflex.translation + newoffset[reflex.pointstoTagIndex] +
                                                map.SecondaryMagic;
                                map.BW.BaseStream.Position = newoffset[x] + 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 < strings.Count; e++)
                            {
                                if (s.name == (string)strings[e])
                                {
                                    stringnum = (short)e;
                                    stringlength = (byte)((string)strings[e]).Length;
                                    break;
                                }
                            }

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

            // totalshift+=howfar;
            int tempfilesize = curroffset + map.MapHeader.metaStart + howfar;

            // 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 = tempfilesize - (curroffset + map.MapHeader.metaStart);

            int combined = bspmetasize[0] + (tempfilesize - curroffset);

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

            map.CloseMap();
        }
Пример #6
0
        /// <summary>
        /// The load scenery.
        /// </summary>
        /// <param name="SceneryList">The scenery list.</param>
        /// <remarks></remarks>
        public void LoadScenery(ref List<SceneryInfo> SceneryList)
        {
            if (SceneryList == null)
            {
                SceneryList = new List<SceneryInfo>();
            }
            else
            {
                SceneryList.Clear();
            }

            map.OpenMap(MapTypes.Internal);

            // Lists all Scenery
            for (int i = 0; i < map.MapHeader.fileCount; i++)
            {
                if (map.MetaInfo.TagType[i] == "scnr")
                {
                    Meta m = new Meta(map);

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

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

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

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

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

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

                            if (Scenery.ModelTagNumber != -1)
                            {
                                m.ReadMetaFromMap(Scenery.ModelTagNumber, false);
                                Scenery.Model = new ParsedModel(ref m);
                            }
                            else
                            {
                                Scenery.Model = null;
                            }

                            ParsedModel.DisplayedInfo.LoadDirectXTexturesAndBuffers(ref device, ref Scenery.Model);

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

                    break;
                }
            }

            map.CloseMap();
        }
Пример #7
0
        private void tsExternalReferenceAdd_Click(object sender, EventArgs e)
        {
            TreeNode tn = treeViewTagReflexives.SelectedNode;
            reflexiveData rd = (reflexiveData)tn.Tag;
            if (rd.reflexive == null)
            {
                MessageBox.Show("Not a reflexive!");
                return;
            }

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

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

            // Always add to top of list
            refList.Insert(0, refs);
        }
Пример #8
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];
            }
        }
Пример #9
0
        /// <summary>
        /// The get map bitmap meta.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static Meta GetMapBitmapMeta(Map map)
        {
            Meta m = null;
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 920;
            int tempc2 = map.BR.ReadInt32();
            int tempr2 = map.BR.ReadInt32() - map.SecondaryMagic;
            map.BR.BaseStream.Position = tempr2 + 16;
            int tempc = map.BR.ReadInt32();
            int tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            if (tempc != 0)
            {
                map.BR.BaseStream.Position = tempr + 8;
                int temptag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                m = new Meta(map);
                m.ReadMetaFromMap(temptag, false);
            }
            else
            {
                map.BR.BaseStream.Position = tempr2 + 8;
                tempc = map.BR.ReadInt32();
                if (tempc != 0)
                {
                    tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                    map.BR.BaseStream.Position = tempr + 12;
                    int temptag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    m = new Meta(map);
                    m.ReadMetaFromMap(temptag, false);
                }
            }

            return m;
        }
Пример #10
0
        /// <summary>
        /// The fix system link tool strip menu item_ click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        /// <remarks></remarks>
        private void fixSystemLinkToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int count = 0;
            List<int> ids = new List<int>();
            for (int x = 0; x < map.IndexHeader.metaCount; x++)
            {
                switch (map.MetaInfo.TagType[x])
                {
                    case "bipd":
                    case "bloc":
                    case "ctrl":

                    case "jpt!":
                    case "mach":

                    case "scen":
                    case "ssce":
                    case "vehi":
                        ids.Add(map.MetaInfo.Ident[x]);
                        count++;
                        break;
                    case "eqip":
                    case "garb":
                    case "proj":
                        ids.Add(map.MetaInfo.Ident[x]);
                        ids.Add(map.MetaInfo.Ident[x]);
                        count += 2;
                        break;
                    case "weap":
                        ids.Add(map.MetaInfo.Ident[x]);
                        ids.Add(map.MetaInfo.Ident[x]);
                        ids.Add(map.MetaInfo.Ident[x]);
                        count += 3;
                        break;
                }
            }

            map.OpenMap(MapTypes.Internal);
            Meta m = new Meta(map);
            m.ReadMetaFromMap(3, true);

            try
            {
                IFPIO io = IFPHashMap.GetIfp("scnr", map.HaloVersion);
                m.headersize = io.headerSize;
                m.scanner.ScanWithIFP(ref io);

                MetaSplitter metasplit = new MetaSplitter();
                metasplit.SplitWithIFP(ref io, ref m, map);

                for (int x = 0; x < metasplit.Header.Chunks[0].ChunkResources.Count; x++)
                {
                    // Offset 984 = [SCNR] Predicted Resources
                    if (metasplit.Header.Chunks[0].ChunkResources[x].offset == 984)
                    {
                        MetaSplitter.SplitReflexive reflex =
                            (MetaSplitter.SplitReflexive)metasplit.Header.Chunks[0].ChunkResources[x];

                        // count = # of chunks incl. added/removed
                        // reflex.Chunks.Count = # of chunks listed in Predicted Resources (?)
                        int diff = count - reflex.Chunks.Count;

                        // Add/Remove chunks to match the difference
                        for (int y = 0; y < diff; y++)
                        {
                            MetaSplitter.SplitReflexive MetaChunk = new MetaSplitter.SplitReflexive();
                            MetaChunk.splitReflexiveType = MetaSplitter.SplitReflexive.SplitReflexiveType.Chunk;
                            MetaChunk.chunksize = 4;

                            MetaChunk.MS = new MemoryStream(4);
                            reflex.Chunks.Add(MetaChunk);
                        }

                        for (int y = 0; y < reflex.Chunks.Count; y++)
                        {
                            BinaryWriter BW = new BinaryWriter(reflex.Chunks[y].MS);
                            BW.Write(ids[y]);
                        }

                        metasplit.Header.Chunks[0].ChunkResources[x] = reflex;
                        break;
                    }
                }

                Meta newmeta = MetaBuilder.BuildMeta(metasplit, map);

                map.OpenMap(MapTypes.Internal);

                map.ChunkTools.Add(newmeta);
                map.CloseMap();

                // info.OpenMap(MapTypes.Internal);
                // info.BW.BaseStream.Position = m.offset + r.translation;
                // for (int x = 0; x < count; x++)
                // {
                // info.BW.Write(ids[x]);
                // }
                // info.CloseMap();
                map = Map.Refresh(map);
                MessageBox.Show("Done");
            }
            catch (Exception ex)
            {
                Global.ShowErrorMsg(string.Empty, ex);
            }
        }
Пример #11
0
        /// <summary>
        /// The load spawns.
        /// </summary>
        /// <remarks></remarks>
        public void LoadSpawns()
        {
            spawns = new SpawnLoads(map, bsp, render.device);
            SpawnModel = new List<ParsedModel>();
            spawnmodelindex = new int[bsp.Spawns.Spawn.Count];
            BoundingBoxModel = new Mesh[bsp.Spawns.Spawn.Count];

            map.OpenMap(MapTypes.Internal);

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

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

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

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

                #region LightSpawn

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

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

                    HaloLightCount++;

                    continue;
                }

                #endregion

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

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

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

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

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

                if (found)
                {
                    continue;
                }
                #endregion

                #region ReadSpawnMeta

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

                m.ReadMetaFromMap(tempspawn.ModelTagNumber, false);

                #endregion

                #region DirectXModel

                ParsedModel pm = new ParsedModel(ref m);

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

                #endregion

                #region BoundingBox

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

                #endregion
            }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            string[] s = map.FileNames.Name[Obstacle.ScenTagNumber].Split('\\');
                            Obstacle.Name = s[s.Length - 1];
                            Obstacle.TagPath = map.FileNames.Name[Obstacle.ScenTagNumber];
                            Obstacle.TagType = map.MetaInfo.TagType[Obstacle.ScenTagNumber];
                            ObstacleList.Add(Obstacle);
                        }
                    }
                    #endregion
                    break;
                }
            }
            #endregion
            */
            map.CloseMap();
        }
Пример #12
0
        /// <summary>
        /// The add.
        /// </summary>
        /// <param name="tagIndex">Index of the tag.</param>
        /// <param name="metasplit">The metasplit.</param>
        /// <remarks></remarks>
        public void Add(int tagIndex, MetaSplitter metasplit)
        {
            // TagIndex - Global Variable
            this.TagIndex = tagIndex;

            ArrayList metas = new ArrayList(0);

            for (int x = 0; x < map.IndexHeader.metaCount; x++)
            {
                // sender.setProgressBar(x / map.IndexHeader.metaCount);
                Meta m = new Meta(map);
                m.ReadMetaFromMap(x, true);

                // Read meta layout of TAG from .ENT file
                IFPIO ifpx = IFPHashMap.GetIfp(m.type, map.HaloVersion);

                m.headersize = ifpx.headerSize;

                if (m.type == "sbsp")
                {
                }
                else
                {
                    // anything but "sbsp"
                    m.scanner.ScanWithIFP(ref ifpx);

                    // metaScanner.ScanManually(ref m, ref map);
                }

                metas.Add(m);
            }

            // sender.setProgressBar(0);
            Meta targetTag = (Meta)metas[tagIndex];

            Meta tempm = MetaBuilder.BuildMeta(metasplit, map); // (Meta) metas[TagIndex];
            metas[tagIndex] = tempm;

            // ((Meta)metas[TagIndex]).RelinkReferences(map);
            SizeOfShift = tempm.size - targetTag.size;

            // Map IS already open? I guess it's a safety check.
            map.OpenMap(MapTypes.Internal);
            FixReflexives(metas);

            map.CloseMap();
        }
Пример #13
0
        /// <summary>
        /// The add.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <remarks></remarks>
        public void Add(Meta meta)
        {
            TagIndex = meta.TagIndex;

            ArrayList metas = new ArrayList(0);
            for (int x = 0; x < meta.Map.IndexHeader.metaCount; x++)
            {
                if (TagIndex == x)
                {
                    metas.Add(meta);
                    continue;
                }

                Meta m = new Meta(meta.Map);
                m.ReadMetaFromMap(x, true);

                IFPIO ifpx = IFPHashMap.GetIfp(m.type, meta.Map.HaloVersion);
                m.headersize = ifpx.headerSize;

                if (m.type == "sbsp")
                {
                }
                else
                {
                    m.scanner.ScanWithIFP(ref ifpx);
                }

                // metaScanner.ScanManually(ref m, ref meta.Map);
                metas.Add(m);
            }

            int diff = meta.size - meta.Map.MetaInfo.Size[TagIndex];
            SizeOfShift = diff;
            meta.Map.OpenMap(MapTypes.Internal);
            FixReflexives(metas);
            meta.Map.CloseMap();
        }
Пример #14
0
        /// <summary>
        /// The to dir.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="path">The path.</param>
        /// <remarks></remarks>
        public static void ToDir(Map map, string path)
        {
            if (path[path.Length - 1] != '\\')
            {
                path += "\\";
            }

            Results = new Hashtable();
            List<Meta> metas = new List<Meta>();
            for (int x = 0; x < map.IndexHeader.metaCount; x++)
            {
                Meta m = new Meta(map);
                m.ReadMetaFromMap(x, true);
                m.scanner.ScanManually();

                metas.Add(m);
            }

            for (int x = 0; x < metas.Count; x++)
            {
                Meta m = metas[x];
                DissectMeta(ref m);
                metas[x] = m;
            }
        }
Пример #15
0
        /// <summary>
        /// The recursively check metas.
        /// </summary>
        /// <param name="tn">The tn.</param>
        /// <remarks></remarks>
        private void RecursivelyCheckMetas(TreeNode tn)
        {
            foreach (TreeNode n in tn.Nodes)
            {
                if (n.Checked == false)
                {
                    continue;
                }

                if (n.Text.IndexOf('.') == -1)
                {
                    RecursivelyCheckMetas(n);
                    continue;
                }

                StatusLabel1.Text = "Processing: " + n.Text + "...";
                Application.DoEvents();
                int id = 0;
                for (int xx = 0; xx < map.IndexHeader.metaCount; xx++)
                {
                    string[] tempn = map.FileNames.Name[xx].Split('\\');

                    string tempi = tempn[tempn.Length - 1] + "." + map.MetaInfo.TagType[xx];
                    int i = map.FileNames.Name[xx].LastIndexOf('\\');
                    string tempp = string.Empty;
                    if (i != -1)
                    {
                        tempp = map.FileNames.Name[xx].Substring(0, i) + "\\";
                    }

                    if (n.Text == tempi && n.Tag.ToString() == map.FileNames.Name[xx] + "." + map.MetaInfo.TagType[xx])
                    {
                        id = xx;
                        break;
                    }
                }

                if (map.MetaInfo.TagType[id] == "ltmp")
                {
                    Meta templtmp = new Meta(map);
                    templtmp.TagIndex = id;
                    templtmp.type = map.MetaInfo.TagType[id];
                    templtmp.name = map.FileNames.Name[id];
                    templtmp.offset = 0;
                    templtmp.size = 0;
                    templtmp.ident = map.MetaInfo.Ident[id];
                    templtmp.MS = new MemoryStream(0);
                    templtmp.rawType = RawDataContainerType.Empty;
                    templtmp.items = new List<Meta.Item>();
                    MetaList.Add(templtmp);
                    continue;
                }

                if (map.MetaInfo.TagType[id] == "ugh!")
                {
                    continue;
                }

                if (map.MetaInfo.TagType[id] == "snd!")
                {
                    // dontscanraw = true;
                }

                Meta m = new Meta(map);
                m.ReadMetaFromMap(id, false);
                if (m.type != "sbsp" && m.type != "jmad")
                {
                    IFPIO ifp = IFPHashMap.GetIfp(m.type, map.HaloVersion);

                    // m.parsed = true;
                    m.headersize = ifp.headerSize;
                    m.scanner.ScanWithIFP(ref ifp);
                }
                else
                {
                    m.scanner.ScanManually();
                }

                switch (m.type.Trim())
                {
                    case "matg":
                        matg = m;

                        break;
                    case "sncl":
                        sncl = m;
                        break;
                    case "spk!":
                        spk = m;

                        break;
                    case "scnr":
                        scnr = m;

                        break;

                    case "sky":
                        this.Skies.Add(m);
                        skycount++;
                        break;
                    default:
                        MetaList.Add(m);
                        count++;
                        break;
                }

                RecursivelyCheckMetas(n);
            }
        }
Пример #16
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();
            }
        }
Пример #17
0
        /// <summary>
        /// The load weapons.
        /// </summary>
        /// <param name="WeaponsList">The weapons list.</param>
        /// <remarks></remarks>
        public void LoadWeapons(ref List<CollectionInfo> WeaponsList)
        {
            if (WeaponsList == null)
            {
                WeaponsList = new List<CollectionInfo>();
            }
            else
            {
                WeaponsList.Clear();
            }

            map.OpenMap(MapTypes.Internal);

            // Lists all weapons
            for (int i = 0; i < map.MetaInfo.TagType.Length; i++)
            {
                if ((map.MetaInfo.TagType[i] == "itmc") || (map.MetaInfo.TagType[i] == "vehc"))
                {
                    CollectionInfo Weapon = new CollectionInfo();
                    Meta m = new Meta(map);
                    m.ReadMetaFromMap(i, false);

                    Weapon.ModelTagNumber = map.Functions.FindModelByBaseClass(i);
                    if (Weapon.ModelTagNumber != -1)
                    {
                        m.ReadMetaFromMap(Weapon.ModelTagNumber, false);
                        Weapon.Model = new ParsedModel(ref m);
                        ParsedModel.DisplayedInfo.LoadDirectXTexturesAndBuffers(ref device, ref Weapon.Model);

                        // Store names into Weapon
                        Weapon.TagPath = map.FileNames.Name[i];
                        Weapon.TagType = map.MetaInfo.TagType[i];
                        int xx = map.Functions.ForMeta.FindByNameAndTagType(Weapon.TagType, Weapon.TagPath);
                        string[] NameSplit = map.FileNames.Name[xx].Split('\\');
                        Weapon.Name = NameSplit[NameSplit.Length - 1];
                        Weapon.Name = Weapon.Name.Replace('_', ' ');
                        WeaponsList.Add(Weapon);
                    }
                }
            }

            map.CloseMap();
        }
Пример #18
0
        /// <summary>
        /// The tree view 1_ before expand.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        /// <remarks></remarks>
        private void treeView1_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            if (metaView != FormFunctions.MetaView.InfoView)
            {
                return;
            }

            string[] mReflex = e.Node.Text.Split('.');
            if (mReflex.Length != 3)
            {
                return;
            }

            for (int x = 0; x < map.IndexHeader.metaCount; x++)
            {
                if ((mReflex[2] == map.FileNames.Name[x]) && (mReflex[1] == "[" + map.MetaInfo.TagType[x] + "]"))
                {
                    map.OpenMap(MapTypes.Internal);
                    Meta m = new Meta(map);
                    m.ReadMetaFromMap(x, false);

                    try
                    {
                    IFPIO ifpx = IFPHashMap.GetIfp(m.type, map.HaloVersion);
                    m.headersize = ifpx.headerSize;

                    // Scans IFP and loads IDENTS, REFLEXIVES & STRINGS into "m" for Reference List
                    m.scanner.ScanWithIFP(ref ifpx);
                    MetaSplitter metasplit = new MetaSplitter();
                    metasplit.SplitWithIFP(ref ifpx, ref m, map);

                    e.Node.Nodes.Clear();

                    if (map.MetaInfo.TagType[x] != "sbsp")
                    {
                        DisplaySplit(metasplit.Header, e.Node);
                    }
                    }
                    catch (Exception ex)
                    {
                        Global.ShowErrorMsg(string.Empty, ex);
                    }

                    map.CloseMap();
                }
            }
        }
Пример #19
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();
            }
        }
Пример #20
0
        /// <summary>
        /// The split ifp.
        /// </summary>
        /// <remarks></remarks>
        private void SplitIFP()
        {
            Meta m = new Meta(map);

            // Reads the current TAGNumber Meta
            m.ReadMetaFromMap(TagNumber, false);

            try
            {
                IFPIO ifpx = IFPHashMap.GetIfp(m.type, map.HaloVersion);
                m.headersize = ifpx.headerSize;

                // Scans IFP and loads IDENTS, REFLEXIVES & STRINGS into "m" for Reference List
                m.scanner.ScanWithIFP(ref ifpx);
                metasplit = new MetaSplitter();
                metasplit.SplitWithIFP(ref ifpx, ref m, map);

            }
            catch (Exception ex)
            {
                Globals.Global.ShowErrorMsg(string.Empty, ex);
            }
        }
Пример #21
0
        /// <summary>
        /// The save recursive function.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <param name="metas">The metas.</param>
        /// <param name="parsed">The parsed.</param>
        /// <param name="pb">The pb.</param>
        /// <param name="percent">The percent.</param>
        /// <param name="percentsize">The percentsize.</param>
        /// <remarks></remarks>
        private void SaveRecursiveFunction(
            Meta meta, 
            ref ArrayList metas, 
            bool parsed, 
            ToolStripProgressBar pb, 
            float percent, 
            float percentsize)
        {
            int wtf = metas.Count;
            if (meta.items.Count == 0)
            {
                return;
            }

            float test = meta.items.Count;

            float currentpercentsize = percentsize / test;

            Item i = null;

            try
            {
                for (int x = 0; x < meta.items.Count; x++)
                {
                    i = meta.items[x];
                    if (i.type != ItemType.Ident)
                    {
                        continue;
                    }

                    float currentpercentage = percent + (currentpercentsize * x);
                    pb.Value = (int)currentpercentage;
                    Application.DoEvents();

                    Ident id = (Ident)i;

                    if (id.ident == -1)
                    {
                        continue;
                    }

                    if (id.ident == 0)
                    {
                        int tagIndex = Map.Functions.ForMeta.FindByNameAndTagType("sbsp", i.intagname);
                        id.ident = Map.MetaInfo.Ident[tagIndex];
                    }

                    bool exists = false;

                    for (int e = 0; e < metas.Count; e++)
                    {
                        Meta tempmeta = (Meta)metas[e];

                        // if (id.pointstotagtype  ==tempmeta.type&&id.pointstotagname ==tempmeta.name )
                        if (id.ident == tempmeta.ident)
                        {
                            exists = true;
                            break;
                        }
                    }

                    if (exists)
                    {
                        continue;
                    }

                    // Drag & drop w/ recursive locks up. num == -1
                    int num = Map.Functions.ForMeta.FindMetaByID(id.ident);
                    if (num < 0)
                    {
                        MessageBox.Show("ERROR! Not Found!");
                    }

                    Meta m = new Meta(Map);
                    if (parsed)
                    {
                        m.parsed = true;
                    }

                    m.ReadMetaFromMap(num, false);
                    if (m.type == "ltmp" | m.type == "matg")
                    {
                        continue;
                    }

                    if (m.type == "phmo" | m.type == "coll" | m.type == "jmad")
                    {
                        m.parsed = false;
                    }

                    if (m.type != "jmad")
                    {
                        IFPIO ifp = IFPHashMap.GetIfp(m.type, Map.HaloVersion);
                        m.headersize = ifp.headerSize;

                        m.scanner.ScanWithIFP(ref ifp);
                    }
                    else
                    {
                        m.scanner.ScanManually();
                    }

                    m.SortItemsByOffset();

                    metas.Add(m);

                    Application.DoEvents();
                    SaveRecursiveFunction(m, ref metas, parsed, pb, currentpercentage, currentpercentsize);
                }
            }
            catch (Exception e)
            {
                string addOn = "\nin [" + meta.type + "] " + meta.name;
                if (i.type == ItemType.Ident)
                    addOn = "\n" + i.description + ", Ident: " + ((Ident)i).ident + addOn;
                throw new Exception(e.Message + addOn, e.InnerException);
            }
        }
Пример #22
0
        /// <summary>
        /// The load lightmaps.
        /// </summary>
        /// <remarks></remarks>
        public void LoadLightmaps()
        {
            if (map.BSP.sbsp[this.BspNumber].LightMap_TagNumber == -1)
            {
                LightMapBitmap = new Bitmap[this.BSPRawDataMetaChunks.Length];
                SceneryLightMapBitmap = new Bitmap[this.PermutationInfo.Length];
                return;
            }

            map.OpenMap(MapTypes.Internal);
            Meta m = new Meta(map);
            m.ReadMetaFromMap(map.BSP.sbsp[this.BspNumber].LightMap_TagNumber, false);

            ParsedBitmap pb = new ParsedBitmap(ref m, map);
            LightMapBitmap = new Bitmap[this.BSPRawDataMetaChunks.Length];
            for (int x = 0; x < this.BSPRawDataMetaChunks.Length; x++)
            {
                int visualchunk = map.BSP.sbsp[this.BspNumber].VisualChunk_Bitmap_Index[x];
                if (visualchunk == -1)
                {
                    LightMapBitmap[x] = null;
                    continue;
                }

                LightMapBitmap[x] = pb.FindChunkAndDecode(visualchunk, 0, 0, ref m, m.Map, x, this.BspNumber);
            }

            SceneryLightMapBitmap = new Bitmap[this.PermutationInfo.Length];
            for (int x = 0; x < this.PermutationInfo.Length; x++)
            {
                int visualchunk = map.BSP.sbsp[this.BspNumber].SceneryChunk_Bitmap_Index[x];
                if (visualchunk == -1)
                {
                    SceneryLightMapBitmap[x] = null;
                    continue;
                }

                SceneryLightMapBitmap[x] = pb.FindChunkAndDecode(
                    visualchunk, 0, 0, ref m, m.Map, -x - 1, this.BspNumber);
            }

            map.CloseMap();
        }
Пример #23
0
        /// <summary>
        /// The load weapons.
        /// </summary>
        /// <param name="WeaponsList">The weapons list.</param>
        /// <remarks></remarks>
        public void LoadWeapons(ref List<CollectionInfo> WeaponsList)
        {
            if (WeaponsList == null)
            {
                WeaponsList = new List<CollectionInfo>();
            }
            else
            {
                WeaponsList.Clear();
            }

            map.OpenMap(MapTypes.Internal);

            // Lists all weapons
            for (int i = 0; i < map.MetaInfo.TagType.Length; i++)
            {
                if ((map.MetaInfo.TagType[i] == "itmc") || (map.MetaInfo.TagType[i] == "vehc"))
                {
                    CollectionInfo Weapon = new CollectionInfo();
                    Meta m = new Meta(map);
                    m.ReadMetaFromMap(i, false);

                    Weapon.ItmcTagNumber = i;

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

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

                        // Store names into Weapon
                        Weapon.TagPath = map.FileNames.Name[i];
                        Weapon.TagType = map.MetaInfo.TagType[i];
                        int xx = map.Functions.ForMeta.FindByNameAndTagType(Weapon.TagType, Weapon.TagPath);
                        string[] NameSplit = map.FileNames.Name[xx].Split('\\');
                        Weapon.Name = NameSplit[NameSplit.Length - 1];
                        Weapon.Name = Weapon.Name.Replace('_', ' ');
                        WeaponsList.Add(Weapon);
                    }
                }
            }

            map.CloseMap();
        }
Пример #24
0
        /// <summary>
        /// The load sky.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <remarks></remarks>
        public void LoadSky(ref Meta meta)
        {
            map.OpenMap(MapTypes.Internal);

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 8;
            int tempc = map.BR.ReadInt32();
            int tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            if (tempc == 0)
            {
                return;
            }

            map.BR.BaseStream.Position = tempr + 4;

            int tempident = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

            if (tempident != -1)
            {
                sky = new Sky(tempident, map);

                map.BR.BaseStream.Position = map.MetaInfo.Offset[tempident] + 4;
                tempident = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                if (tempident != -1)
                {
                    Meta tempmeta = new Meta(map);
                    tempmeta.ReadMetaFromMap(tempident, false);
                    SkyBox = new ParsedModel(ref tempmeta);
                }
            }

            map.CloseMap();
        }