Пример #1
0
        /// <summary>
        /// Internalizes a bitmap by passing raw data. This was primarily written for the bitmap internalization
        /// in the mainmenu editor.
        /// </summary>
        /// <param name="raw">Entity.RawDataContainer</param>
        /// <param name="map">Map to add data to</param>
        /// <remarks></remarks>
        public static void bitmapInternalizeRaw(ref RawDataContainer raw, Map map)
        {
            map.OpenMap(MapTypes.Internal, false);
            long rawSize = biGetRawTotalSize(raw, false);
            shift(map.FS, map.MapHeader.indexOffset, rawSize);

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

            // loop for each tag
            //int tempRawSize;

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

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

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

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

            biUpdateMapInfo(map, (int)rawSize);

            map.CloseMap();
        }
Пример #2
0
        /// <summary>
        /// The load raw from file.
        /// </summary>
        /// <param name="inputFilePath">The input file path.</param>
        /// <param name="meta">The meta.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public RawDataContainer LoadRawFromFile(string inputFilePath, Meta.Meta meta)
        {
            RawDataContainer raw = new RawDataContainer();
            int x = inputFilePath.LastIndexOf('.');
            string temp = inputFilePath.Substring(0, x + 1) + meta.type + "raw";

            XmlTextReader xtr = new XmlTextReader(temp + ".xml");
            xtr.WhitespaceHandling = WhitespaceHandling.None;

            FileStream FS = new FileStream(temp, FileMode.Open);
            BinaryReader BR = new BinaryReader(FS);

            while (xtr.Read())
            {
                switch (xtr.NodeType)
                {
                    case XmlNodeType.Element:
                        if (xtr.Name == "RawData")
                        {
                            string oi = xtr.GetAttribute("RawType");

                            switch (oi)
                            {
                                case "Model":
                                    raw = new Model();
                                    break;
                                case "Bitmap":
                                    raw = new BitmapRaw();
                                    break;
                                case "Animation":
                                    raw = new Animation();
                                    break;
                                case "DECR":
                                    raw = new DECR();
                                    break;
                                case "PRTM":
                                    raw = new PRTM();
                                    break;
                                case "Weather":
                                    raw = new Weather();
                                    break;
                                case "Sound":
                                    raw = new Sound();
                                    break;
                                case "BSP":
                                    raw = new BSPRaw();
                                    break;
                            }
                        }
                        else if (xtr.Name == "RawChunk")
                        {
                            RawDataChunk r = new RawDataChunk();
                            string temps = xtr.GetAttribute("RawDataType");
                            switch (temps)
                            {
                                case "bitm":
                                    r.rawDataType = RawDataType.bitm;
                                    break;
                                case "bsp1":
                                    r.rawDataType = RawDataType.bsp1;
                                    break;
                                case "bsp2":
                                    r.rawDataType = RawDataType.bsp2;
                                    break;
                                case "bsp3":
                                    r.rawDataType = RawDataType.bsp3;
                                    break;
                                case "bsp4":
                                    r.rawDataType = RawDataType.bsp4;
                                    break;
                                case "DECR":
                                    r.rawDataType = RawDataType.DECR;
                                    break;
                                case "jmad":
                                    r.rawDataType = RawDataType.jmad;
                                    break;
                                case "ltmp":
                                    r.rawDataType = RawDataType.ltmp;
                                    break;
                                case "mode1":
                                    r.rawDataType = RawDataType.mode1;
                                    break;
                                case "mode2":
                                    r.rawDataType = RawDataType.mode2;
                                    break;
                                case "PRTM":
                                    r.rawDataType = RawDataType.PRTM;
                                    break;
                                case "snd1":
                                    r.rawDataType = RawDataType.snd1;
                                    break;
                                case "snd2":
                                    r.rawDataType = RawDataType.snd2;
                                    break;
                            }

                            r.offset = Convert.ToInt32(xtr.GetAttribute("PointsToOffset"));
                            r.pointerMetaOffset = Convert.ToInt32(xtr.GetAttribute("PointerMetaOffset"));
                            r.size = Convert.ToInt32(xtr.GetAttribute("ChunkSize"));
                            int rawdataspot = Convert.ToInt32(xtr.GetAttribute("RawDataOffset"));
                            BR.BaseStream.Position = rawdataspot;
                            r.MS = new MemoryStream(r.size);
                            r.MS.Write(BR.ReadBytes(r.size), 0, r.size);

                            raw.rawChunks.Add(r);
                        }

                        break;
                }
            }

            BR.Close();
            FS.Close();
            xtr.Close();

            if (meta.type == "snd!")
            {
                Stream s = File.Open(temp + "layout", FileMode.Open);

                #region attempt to convert v1.0.0.0 files to v1.1.0.0 format
                {
                    StreamReader sr = new StreamReader(s);
                    string convertOldVersion = sr.ReadToEnd();
                    if (convertOldVersion.Contains("Version=1.0.0.0"))
                    {
                        int xx = -1;
                        while ((xx = convertOldVersion.IndexOf("entity.MetaContainers")) > -1)
                        {
                            if (convertOldVersion[xx] == '[')
                                convertOldVersion = convertOldVersion.Substring(0, xx) +
                                                "HaloMap.H2MetaContainers" +
                                                convertOldVersion.Substring(xx + "entity.MetaContainers".Length);
                            else
                                convertOldVersion = convertOldVersion.Substring(0, xx - 1) +
                                                (char)((byte)convertOldVersion[xx - 1] + 3) +   // string is 3 bytes longer
                                                "HaloMap.H2MetaContainers" +
                                                convertOldVersion.Substring(xx + "entity.MetaContainers".Length);
                        }
                        while ((xx = convertOldVersion.IndexOf("entity.MapTypes")) > -1)
                        {
                            convertOldVersion = convertOldVersion.Substring(0, xx - 1) +
                                                (char)((byte)convertOldVersion[xx - 1] + 5) +  // string is 5 bytes longer
                                                "HaloMap.Map.MapTypes" +
                                                convertOldVersion.Substring(xx + "entity.MapTypes".Length);
                        }

                        // Convert the modified string into a stream
                        StreamWriter sw = new StreamWriter(s);
                        sw.BaseStream.Position = 0;
                        char[] ca = convertOldVersion.ToCharArray();
                        byte[] ba = Encoding.Default.GetBytes(ca);
                        sw.BaseStream.Write(ba, 0, ba.Length);

            #if DEBUG
                        // Write an output file for testing
                        Stream s2 = File.Create(temp + "layout_test");
                        sw = new StreamWriter(s2);
                        sw.BaseStream.Write(ba, 0, ba.Length);
                        s2.Close();
            #endif
                    }

                    s.Position = 0;
                }
                #endregion
                BinaryFormatter b = new BinaryFormatter();
                Sound temps = (Sound)raw;
                temps.Permutations = (ugh_.SoundPermutationChunk[])b.Deserialize(s);
                meta.raw = temps;
                s.Close();
            }

            return raw;
        }
Пример #3
0
        /// <summary>
        /// The bi get raw total size.
        /// </summary>
        /// <param name="raw">The raw.</param>
        /// <param name="ignoreInternal">The ignore internal.</param>
        /// <returns>The bi get raw total size.</returns>
        /// <remarks></remarks>
        private static long biGetRawTotalSize(RawDataContainer raw, bool ignoreInternal)
        {
            long rawSize = 0;
            for (int i = 0; i < raw.rawChunks.Count; i++)
            {
                if (raw.rawChunks[i].rawLocation != MapTypes.Internal || !ignoreInternal)
                {
                    {
                        rawSize += raw.rawChunks[i].size;
                        rawSize += genPaddingSize(raw.rawChunks[i].size /*.lods.get(k).rawSize*/, 512);
                    }
                }
            }

            return rawSize;
        }
Пример #4
0
            /// <summary>
            /// The read raw.
            /// </summary>
            /// <param name="tagIndex">Index of the tag.</param>
            /// <param name="dontreadraw">The dontreadraw.</param>
            /// <returns></returns>
            /// <remarks></remarks>
            public RawDataContainer ReadRaw(int tagIndex, bool dontreadraw)
            {
                RawDataContainer tempcontainer = new RawDataContainer();

                switch (CheckForRaw(map.MetaInfo.TagType[tagIndex]))
                {
                    case RawDataContainerType.PRTM:
                        tempcontainer = new PRTM();
                        break;
                    case RawDataContainerType.DECR:
                        tempcontainer = new DECR();
                        break;
                    case RawDataContainerType.Animation:
                        tempcontainer = new Animation();
                        break;
                    case RawDataContainerType.Model:
                        tempcontainer = new Model();
                        break;
                    case RawDataContainerType.Bitmap:
                        tempcontainer = new BitmapRaw();
                        break;
                    case RawDataContainerType.BSP:
                        tempcontainer = new BSPRaw();
                        break;

                    case RawDataContainerType.Weather:
                        tempcontainer = new Weather();
                        break;
                    case RawDataContainerType.Sound:
                        tempcontainer = new Sound();
                        break;
                    case RawDataContainerType.CoconutsModel:
                        tempcontainer = new UghRawContainer();
                        break;
                    case RawDataContainerType.LightMap:
                        tempcontainer = new LightmapRaw();
                        break;
                    default:
                        break;
                }

                tempcontainer.Read(tagIndex, map, dontreadraw);
                return tempcontainer;
            }
Пример #5
0
        /// <summary>
        /// The read meta from map.
        /// </summary>
        /// <param name="tagIndex">The tagIndex.</param>
        /// <param name="dontreadraw">The dontreadraw.</param>
        /// <remarks></remarks>
        public void ReadMetaFromMap(int tagIndex, bool dontReadRaw)
        {
            // set meta properties
            this.Map = Map;
            this.TagIndex = tagIndex;
            this.type = Map.MetaInfo.TagType[tagIndex];
            this.name = Map.FileNames.Name[tagIndex];
            this.offset = Map.MetaInfo.Offset[tagIndex];
            this.size = Map.MetaInfo.Size[tagIndex];
            this.ident = Map.MetaInfo.Ident[tagIndex];

            string temps = this.offset.ToString("X");
            char[] tempc = temps.ToCharArray();
            int xxx = tempc.Length;
            this.padding = tempc[xxx - 1];

            // THIS = Currently Selected Tag
            // Find current Tag Meta and read into memory stream (MS)
            this.MS = new MemoryStream(this.size);
            Map.BR.BaseStream.Position = this.offset;
            this.MS.Write(Map.BR.ReadBytes(this.size), 0, this.size);

            // Checks if type has raw data
            this.rawType = Map.Functions.ForMeta.CheckForRaw(this.type);
            if (dontReadRaw == false)
            {
                if (rawType != RawDataContainerType.Empty)
                {
                    this.raw = Map.Functions.ForMeta.ReadRaw(this.TagIndex, dontReadRaw);
                }
            }

            if (this.type == "sbsp")
            {
                int h = Map.BSP.FindBSPNumberByBSPIdent(this.ident);
                this.magic = Map.BSP.sbsp[h].magic;
            }
            else if (this.type == "ltmp")
            {
                int h = Map.BSP.FindBSPNumberByLightMapIdent(this.ident);
                this.magic = Map.BSP.sbsp[h].magic;
            }
            else
            {
                // Not "sbsp" or "ltmp"
                // For Halo 1 or Halo CE
                if (Map.HaloVersion == HaloVersionEnum.HaloCE || Map.HaloVersion == HaloVersionEnum.Halo1)
                {
                    this.magic = Map.PrimaryMagic;
                }
                else
                {
                    // For Halo 2
                    this.magic = Map.SecondaryMagic;
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Load meta from an XML file.
        /// </summary>
        /// <param name="inputFileName">The XML file name.</param>
        /// <remarks></remarks>
        public void LoadMetaFromFile(string inputFileName)
        {
            // write memorysteam of meta to file
            FileStream FS = new FileStream(inputFileName, FileMode.Open);
            BinaryReader BR = new BinaryReader(FS);
            this.size = (int)FS.Length;
            this.MS = new MemoryStream(this.size);
            BR.BaseStream.Position = 0;
            this.MS.Write(BR.ReadBytes(this.size), 0, this.size);
            BR.Close();
            FS.Close();

            // write idents,strings,reflexives
            XmlTextReader xtr = new XmlTextReader(inputFileName + ".xml");
            xtr.WhitespaceHandling = WhitespaceHandling.None;

            while (xtr.Read())
            {
                // MessageBox.Show(xtr.Name);
                switch (xtr.NodeType)
                {
                    case XmlNodeType.Element:
                        if (xtr.Name == "Meta")
                        {
                            this.type = xtr.GetAttribute("TagType");
                            this.name = xtr.GetAttribute("TagName");
                            this.parsed = xtr.GetAttribute("Parsed") == "True" ? true : false;
                            this.size = Convert.ToInt32(xtr.GetAttribute("Size"));
                            this.magic = Convert.ToInt32(xtr.GetAttribute("Magic"));
                            this.padding = Convert.ToChar(xtr.GetAttribute("Padding"));
                            this.offset = Convert.ToInt32(xtr.GetAttribute("Offset"));
                        }
                        else if (xtr.Name == "Reflexive")
                        {
                            Reflexive r = new Reflexive();
                            r.description = xtr.GetAttribute("Description");
                            r.offset = Convert.ToInt32(xtr.GetAttribute("Offset"));
                            r.chunkcount = Convert.ToInt32(xtr.GetAttribute("ChunkCount"));
                            r.chunksize = Convert.ToInt32(xtr.GetAttribute("ChunkSize"));
                            r.translation = Convert.ToInt32(xtr.GetAttribute("Translation"));
                            r.pointstotagtype = xtr.GetAttribute("PointsToTagType");
                            r.pointstotagname = xtr.GetAttribute("PointsToTagName");
                            r.pointstoTagIndex = Map.Functions.ForMeta.FindByNameAndTagType(
                                r.pointstotagtype, r.pointstotagname);
                            r.intagtype = xtr.GetAttribute("TagType");
                            r.intagname = xtr.GetAttribute("TagName");
                            r.intag = Map.Functions.ForMeta.FindByNameAndTagType(r.intagtype, r.intagname);
                            this.items.Add(r);
                        }
                        else if (xtr.Name == "Ident")
                        {
                            Ident id = new Ident();

                            id.description = xtr.GetAttribute("Description");
                            id.offset = Convert.ToInt32(xtr.GetAttribute("Offset"));
                            id.pointstotagtype = xtr.GetAttribute("PointsToTagType");
                            id.pointstotagname = xtr.GetAttribute("PointsToTagName");
                            id.pointstoTagIndex = Map.Functions.ForMeta.FindByNameAndTagType(
                                id.pointstotagtype, id.pointstotagname);
                            id.intagtype = xtr.GetAttribute("TagType");
                            id.intagname = xtr.GetAttribute("TagName");
                            id.intag = Map.Functions.ForMeta.FindByNameAndTagType(id.intagtype, id.intagname);
                            this.items.Add(id);
                        }
                        else if (xtr.Name == "String")
                        {
                            String s = new String();
                            s.description = xtr.GetAttribute("Description");
                            s.offset = Convert.ToInt32(xtr.GetAttribute("Offset"));
                            s.name = xtr.GetAttribute("StringName");
                            s.intagtype = xtr.GetAttribute("TagType");
                            s.intagname = xtr.GetAttribute("TagName");
                            s.intag = Map.Functions.ForMeta.FindByNameAndTagType(s.intagtype, s.intagname);
                            this.items.Add(s);
                        }

                        break;
                    default:
                        break;
                }
            }

            xtr.Close();

            //
            ///check for raw
            this.rawType = Map.Functions.ForMeta.CheckForRaw(this.type);
            if (this.rawType != RawDataContainerType.Empty)
            {
                this.raw = new RawDataContainer();
                this.raw = this.raw.LoadRawFromFile(inputFileName, this);
            }
        }
Пример #7
0
        /// <summary>
        /// The split with ifp.
        /// </summary>
        /// <param name="ifp">The ifp.</param>
        /// <param name="meta">The meta.</param>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void SplitWithIFP(ref IFPIO ifp, ref Meta meta, Map map)
        {
            this.type = meta.type;
            this.TagIndex = meta.TagIndex;
            this.name = meta.name;
            this.offset = meta.offset;
            this.magic = meta.magic;
            this.raw = meta.raw;
            this.rawtype = meta.rawType;
            map.OpenMap(MapTypes.Internal);
            if (ifp.items != null)
            {
                map.BR.BaseStream.Position = meta.offset;
                Header = new SplitReflexive();
                Header.offset = 0;
                Header.Chunks = new List<SplitReflexive>();
                Header.translation = 0;

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

            map.CloseMap();
        }
Пример #8
0
        /// <summary>
        /// The save bitmaps.
        /// </summary>
        /// <remarks></remarks>
        private void saveBitmaps()
        {
            Map thisMap = map;

            // Save Map Bitmap & RawChunk for Campaign
            /*
            for (int i = 0; i < campaignLevels.Count; i++)
            {
                for (int j = 0; j < map.IndexHeader.metaCount; j++)
                {
                    char[] temp = (char[])campaignLevels[i].Preview_Image_Tag.Clone();
                    Array.Reverse(temp);
                    if (thisMap.MetaInfo.TagType[j] == new string(temp) &&
                        thisMap.MetaInfo.Ident[j] == campaignLevels[i].Preview_Image_Ident)
                    {
                        MMMap.loadmeta(j);
                        Meta m = thisMap.SelectedMeta;
                        campaignLevels[i].screenShotRaw = m.raw.rawChunks[0];
                        campaignLevels[i].screenShotOffset = m.raw.rawChunks[0].offset;
                        Raw.ParsedBitmap pm = new Raw.ParsedBitmap(ref m, map);
                        campaignLevels[i].screenShot = pm.FindChunkAndDecode(0, 0, 0, ref m, map, 0, 0);

                        break;
                    }
                }
            }
            */
            // Save Map Bitmap & RawChunk for MP
            for (int i = 0; i < MPLevels.Count; i++)
            {
                // Only save bitmaps for actual levels
                if (MPLevels[i].mapID == -1)
                {
                    continue;
                }

                int TagIndex = map.Functions.ForMeta.FindMetaByID(MPLevels[i].Preview_Image_Ident);
                if (TagIndex != -1)
                {
                    Meta m = Map.GetMetaFromTagIndex(TagIndex, map, false, false);

                    m.raw.rawChunks[0].MS = MPLevels[i].screenShotRaw.MS;

                    // If we are using a shared image, insert a new
                    if (!MPLevels[i].screenShotOriginal)
                    {
                        RawDataContainer rdc = new RawDataContainer();
                        rdc.rawChunks.Add(MPLevels[i].screenShotRaw);
                        ParsedBitmap.bitmapInternalizeRaw(ref rdc, thisMap);
                        MPLevels[i].screenShotOffset = MPLevels[i].screenShotRaw.offset;
                        MPLevels[i].screenShotOriginal = true;
                    }

                    map.OpenMap(MapTypes.Internal);

                    // Write Raw Data to map file
                    map.BW.BaseStream.Position = MPLevels[i].screenShotOffset;
                    map.BW.Write(
                        m.raw.rawChunks[0].MS.ToArray(),
                        0,
                        (int)Math.Min(m.raw.rawChunks[0].size, m.raw.rawChunks[0].MS.Length));
                    string s = map.FileNames.Name[TagIndex];

                    // Write offset to map file
                    // Offset 68 = Bitmap Data reflexive
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 68;
                    int tempc = map.BR.ReadInt32();
                    int tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                    // int offsetToOffset = tempr + 28 - map.MetaInfo.Offset[TagIndex];
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] +
                                                 MPLevels[i].screenShotRaw.pointerMetaOffset;
                    map.BW.Write(MPLevels[i].screenShotOffset);
                    map.CloseMap();
                }
            }
        }