/// <summary> /// The h 2 read. /// </summary> /// <param name="TagIndex">The TagIndex.</param> /// <param name="map">The map.</param> /// <param name="dontreadraw">The dontreadraw.</param> /// <remarks></remarks> public void H2Read(int TagIndex, Map map, bool dontreadraw) { int w = map.BSP.FindBSPNumberByLightMapIdent(map.MetaInfo.Ident[TagIndex]); // light map if (map.BSP.sbsp[w].lightmapident != -1) { int tempr = map.MetaInfo.Offset[TagIndex]; map.BR.BaseStream.Position = tempr + 128; int tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.BSP.sbsp[w].magic; map.BR.BaseStream.Position = tempr + 64; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.BSP.sbsp[w].magic; for (int x = 0; x < tempc; x++) { RawDataChunk Raw = new RawDataChunk(); Raw.rawDataType = RawDataType.ltmp; Raw.pointerMetaOffset = tempr + (x * 56) + 12 - map.MetaInfo.Offset[TagIndex]; map.BR.BaseStream.Position = tempr + (x * 56) + 12; Raw.offset = map.BR.ReadInt32(); Raw.size = map.BR.ReadInt32(); if (Raw.offset == -1) { this.rawChunks.Add(Raw); continue; } map.Functions.ParsePointer(ref Raw.offset, ref Raw.rawLocation); if (dontreadraw == false) { map.OpenMap(Raw.rawLocation); map.BR.BaseStream.Position = Raw.offset; Raw.MS = new MemoryStream(Raw.size); Raw.MS.Write(map.BR.ReadBytes(Raw.size), 0, Raw.size); map.OpenMap(MapTypes.Internal); } this.rawChunks.Add(Raw); } } }
/// <summary> /// The h 2 read. /// </summary> /// <param name="TagIndex">The TagIndex.</param> /// <param name="map">The map.</param> /// <param name="dontreadraw">The dontreadraw.</param> /// <remarks></remarks> public void H2Read(int TagIndex, Map map, bool dontreadraw) { int w = map.BSP.FindBSPNumberByBSPIdent(map.MetaInfo.Ident[TagIndex]); // bsp model 1 map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 172; int tempc = map.BR.ReadInt32(); int tempr = map.BR.ReadInt32() - map.BSP.sbsp[w].magic; for (int x = 0; x < tempc; x++) { RawDataChunk Raw = new RawDataChunk(); Raw.rawDataType = RawDataType.bsp1; Raw.pointerMetaOffset = tempr + (x * 176) + 40 - map.MetaInfo.Offset[TagIndex]; map.BR.BaseStream.Position = tempr + (x * 176) + 40; Raw.offset = map.BR.ReadInt32(); Raw.size = map.BR.ReadInt32(); if (Raw.offset == -1) { this.rawChunks.Add(Raw); continue; } map.Functions.ParsePointer(ref Raw.offset, ref Raw.rawLocation); if (dontreadraw == false) { map.OpenMap(Raw.rawLocation); map.BR.BaseStream.Position = Raw.offset; Raw.MS = new MemoryStream(Raw.size); Raw.MS.Write(map.BR.ReadBytes(Raw.size), 0, Raw.size); map.OpenMap(MapTypes.Internal); } this.rawChunks.Add(Raw); } // bsp model 2 map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 328; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.BSP.sbsp[w].magic; for (int x = 0; x < tempc; x++) { RawDataChunk Raw = new RawDataChunk(); Raw.rawDataType = RawDataType.bsp2; Raw.pointerMetaOffset = tempr + (x * 200) + 40 - map.MetaInfo.Offset[TagIndex]; map.BR.BaseStream.Position = tempr + (x * 200) + 40; Raw.offset = map.BR.ReadInt32(); Raw.size = map.BR.ReadInt32(); if (Raw.offset == -1) { this.rawChunks.Add(Raw); continue; } map.Functions.ParsePointer(ref Raw.offset, ref Raw.rawLocation); if (dontreadraw == false) { map.OpenMap(Raw.rawLocation); map.BR.BaseStream.Position = Raw.offset; Raw.MS = new MemoryStream(Raw.size); Raw.MS.Write(map.BR.ReadBytes(Raw.size), 0, Raw.size); map.OpenMap(MapTypes.Internal); } this.rawChunks.Add(Raw); } // light map if (map.BSP.sbsp[w].lightmapident != -1) { map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 8; tempr = map.BR.ReadInt32(); if (tempr == 0) { goto skiplightmap; } tempr -= map.BSP.sbsp[w].magic; map.BR.BaseStream.Position = tempr + 128; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.BSP.sbsp[w].magic; map.BR.BaseStream.Position = tempr + 64; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.BSP.sbsp[w].magic; for (int x = 0; x < tempc; x++) { RawDataChunk Raw = new RawDataChunk(); Raw.rawDataType = RawDataType.ltmp; Raw.pointerMetaOffset = tempr + (x * 56) + 12 - map.MetaInfo.Offset[TagIndex]; map.BR.BaseStream.Position = tempr + (x * 56) + 12; Raw.offset = map.BR.ReadInt32(); Raw.size = map.BR.ReadInt32(); if (Raw.offset == -1) { this.rawChunks.Add(Raw); continue; } map.Functions.ParsePointer(ref Raw.offset, ref Raw.rawLocation); if (dontreadraw == false) { map.OpenMap(Raw.rawLocation); map.BR.BaseStream.Position = Raw.offset; Raw.MS = new MemoryStream(Raw.size); Raw.MS.Write(map.BR.ReadBytes(Raw.size), 0, Raw.size); map.OpenMap(MapTypes.Internal); } this.rawChunks.Add(Raw); } } skiplightmap: // bsp model 3 map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 580; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.BSP.sbsp[w].magic; // if (tempc==0){return;} map.BR.BaseStream.Position = tempr + 16; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.BSP.sbsp[w].magic; for (int x = 0; x < tempc; x++) { RawDataChunk Raw = new RawDataChunk(); Raw.rawDataType = RawDataType.bsp3; Raw.pointerMetaOffset = tempr + (x * 44) - map.MetaInfo.Offset[TagIndex]; map.BR.BaseStream.Position = tempr + (x * 44); Raw.offset = map.BR.ReadInt32(); Raw.size = map.BR.ReadInt32(); if (Raw.offset == -1) { this.rawChunks.Add(Raw); continue; } map.Functions.ParsePointer(ref Raw.offset, ref Raw.rawLocation); if (dontreadraw == false) { map.OpenMap(Raw.rawLocation); map.BR.BaseStream.Position = Raw.offset; Raw.MS = new MemoryStream(Raw.size); Raw.MS.Write(map.BR.ReadBytes(Raw.size), 0, Raw.size); map.OpenMap(MapTypes.Internal); } this.rawChunks.Add(Raw); } // bsp model 4 map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 548; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.BSP.sbsp[w].magic; for (int x = 0; x < tempc; x++) { RawDataChunk Raw = new RawDataChunk(); Raw.rawDataType = RawDataType.bsp4; Raw.pointerMetaOffset = tempr + (x * 172) + 16 - map.MetaInfo.Offset[TagIndex]; map.BR.BaseStream.Position = tempr + (x * 172) + 16; Raw.offset = map.BR.ReadInt32(); if (Raw.offset == -1) { continue; } Raw.size = map.BR.ReadInt32(); map.Functions.ParsePointer(ref Raw.offset, ref Raw.rawLocation); if (dontreadraw == false) { map.OpenMap(Raw.rawLocation); map.BR.BaseStream.Position = Raw.offset; Raw.MS = new MemoryStream(Raw.size); Raw.MS.Write(map.BR.ReadBytes(Raw.size), 0, Raw.size); map.OpenMap(MapTypes.Internal); } this.rawChunks.Add(Raw); } }
/// <summary> /// The read. /// </summary> /// <param name="TagIndex">The TagIndex.</param> /// <param name="map">The map.</param> /// <param name="dontreadraw">The dontreadraw.</param> /// <remarks></remarks> public override void Read(int TagIndex, Map map, bool dontreadraw) { RawDataChunk Raw = new RawDataChunk(); Raw.rawDataType = RawDataType.DECR; Raw.pointerMetaOffset = 56; map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 56; Raw.offset = map.BR.ReadInt32(); Raw.size = map.BR.ReadInt32(); map.Functions.ParsePointer(ref Raw.offset, ref Raw.rawLocation); if (dontreadraw == false) { map.OpenMap(Raw.rawLocation); map.BR.BaseStream.Position = Raw.offset; Raw.MS = new MemoryStream(Raw.size); Raw.MS.Write(map.BR.ReadBytes(Raw.size), 0, Raw.size); map.OpenMap(MapTypes.Internal); } this.rawChunks.Add(Raw); }
/// <summary> /// The read. /// </summary> /// <param name="TagIndex">The TagIndex.</param> /// <param name="map">The map.</param> /// <param name="dontreadraw">The dontreadraw.</param> /// <remarks></remarks> public override void Read(int TagIndex, Map map, bool dontreadraw) { map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 172; int tempc = map.BR.ReadInt32(); int tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { RawDataChunk Raw = new RawDataChunk(); Raw.rawDataType = RawDataType.jmad; Raw.pointerMetaOffset = tempr + (x * 20) + 8 - map.MetaInfo.Offset[TagIndex]; map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + Raw.pointerMetaOffset - 4; Raw.size = map.BR.ReadInt32(); Raw.offset = map.BR.ReadInt32(); map.Functions.ParsePointer(ref Raw.offset, ref Raw.rawLocation); if (dontreadraw == false) { map.OpenMap(Raw.rawLocation); map.BR.BaseStream.Position = Raw.offset; Raw.MS = new MemoryStream(Raw.size); Raw.MS.Write(map.BR.ReadBytes(Raw.size), 0, Raw.size); map.OpenMap(MapTypes.Internal); } this.rawChunks.Add(Raw); } }
/// <summary> /// The read h 2 sound data. /// </summary> /// <param name="TagIndex">The TagIndex.</param> /// <param name="map">The map.</param> /// <param name="dontreadraw">The dontreadraw.</param> /// <remarks></remarks> public void ReadH2SoundData(int TagIndex, Map map, bool dontreadraw) { map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 8; index = map.BR.ReadInt16(); count = 1; // map.BR.ReadInt16(); Permutations = new ugh_.SoundPermutationChunk[count]; for (int x = 0; x < count; x++) { int currentindex = index + x; Permutations[x] = map.ugh.Permutations[currentindex]; for (int xx = 0; xx < map.ugh.Permutations[currentindex].choicecount; xx++) { int choiceindexx = map.ugh.Permutations[currentindex].choiceindex + xx; Permutations[x].Choices.Add(map.ugh.Choices[choiceindexx]); for (int xxx = 0; xxx < map.ugh.Choices[choiceindexx].soundcount; xxx++) { int soundindex = map.ugh.Choices[choiceindexx].soundindex + xxx; Permutations[x].Choices[xx].SoundChunks1.Add(map.ugh.SoundChunks1[soundindex]); RawDataChunk Raw = new RawDataChunk(); Raw.rawDataType = RawDataType.snd1; Raw.offset = map.ugh.SoundChunks1[soundindex].offset; Raw.size = map.ugh.SoundChunks1[soundindex].size & 0x3FFFFFFF; Raw.rawLocation = map.ugh.SoundChunks1[soundindex].rawLocation; if (dontreadraw == false) { map.OpenMap(Raw.rawLocation); map.BR.BaseStream.Position = Raw.offset; Raw.MS = new MemoryStream(Raw.size); Raw.MS.Write(map.BR.ReadBytes(Raw.size), 0, Raw.size); map.OpenMap(MapTypes.Internal); } this.rawChunks.Add(Raw); } } } }
/// <summary> /// The read h 1 sound data. /// </summary> /// <param name="TagIndex">The TagIndex.</param> /// <param name="map">The map.</param> /// <param name="dontreadraw">The dontreadraw.</param> /// <remarks></remarks> public void ReadH1SoundData(int TagIndex, Map map, bool dontreadraw) { map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 152; int tempc = map.BR.ReadInt32(); int tempr = map.BR.ReadInt32() - map.PrimaryMagic; map.BR.BaseStream.Position = tempr + 60; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.PrimaryMagic; for (int x = 0; x < tempc; x++) { RawDataChunk Raw = new RawDataChunk(); Raw.pointerMetaOffset = tempr + (x * 124) + 64 - map.MetaInfo.Offset[TagIndex]; map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + Raw.pointerMetaOffset; Raw.rawDataType = RawDataType.snd1; Raw.size = map.BR.ReadInt32(); map.BR.ReadInt32(); Raw.offset = map.BR.ReadInt32(); if (dontreadraw == false) { map.BR.BaseStream.Position = Raw.offset; Raw.MS = new MemoryStream(Raw.size); Raw.MS.Write(map.BR.ReadBytes(Raw.size), 0, Raw.size); } this.rawChunks.Add(Raw); } }
/// <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 h 1 model raw. /// </summary> /// <param name="TagIndex">The TagIndex.</param> /// <param name="map">The map.</param> /// <param name="dontreadraw">The dontreadraw.</param> /// <remarks></remarks> public void ReadH1ModelRaw(int TagIndex, Map map, bool dontreadraw) { map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 208; int tempc = map.BR.ReadInt32(); int tempr = map.BR.ReadInt32() - map.PrimaryMagic; for (int y = 0; y < tempc; y++) { map.BR.BaseStream.Position = tempr + (y * 48) + 36; int tempcc = map.BR.ReadInt32(); int temprc = map.BR.ReadInt32() - map.PrimaryMagic; for (int x = 0; x < tempcc; x++) { RawDataChunk Raw = new RawDataChunk(); map.BR.BaseStream.Position = temprc + (x * 104) + 4; Raw.shadernumber = map.BR.ReadInt16(); Raw.pointerMetaOffset = temprc + (x * 104) + 76 - map.MetaInfo.Offset[TagIndex]; map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + Raw.pointerMetaOffset - 4; Raw.rawDataType = RawDataType.HaloCEIndices; Raw.size = (map.BR.ReadInt32() + 2) * 2; Raw.offset = map.BR.ReadInt32() - map.PrimaryMagic; if (dontreadraw == false) { map.OpenMap(Raw.rawLocation); map.BR.BaseStream.Position = Raw.offset; Raw.MS = new MemoryStream(Raw.size); Raw.MS.Write(map.BR.ReadBytes(Raw.size), 0, Raw.size); map.OpenMap(MapTypes.Internal); } this.rawChunks.Add(Raw); Raw = new RawDataChunk(); Raw.rawDataType = RawDataType.HaloCEVertices; Raw.pointerMetaOffset = temprc + (x * 104) + 100 - map.MetaInfo.Offset[TagIndex]; map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + Raw.pointerMetaOffset - 12; Raw.size = map.BR.ReadInt32(); Raw.size *= 32; map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + Raw.pointerMetaOffset; this.IntermediatePointerOffset = map.BR.ReadInt32() - map.PrimaryMagic; map.BR.BaseStream.Position = this.IntermediatePointerOffset + 4; Raw.offset = map.BR.ReadInt32() - map.PrimaryMagic; if (dontreadraw == false) { map.OpenMap(Raw.rawLocation); map.BR.BaseStream.Position = Raw.offset; Raw.MS = new MemoryStream(Raw.size); Raw.MS.Write(map.BR.ReadBytes(Raw.size), 0, Raw.size); map.OpenMap(MapTypes.Internal); } this.rawChunks.Add(Raw); } } }