The prtm.
Inheritance: RawDataContainer
Exemple #1
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;
        }
            /// <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;
            }