/// <summary> /// Initializes a new instance of the <see cref="BSPConvert"/> class. /// </summary> /// <param name="map">The map.</param> /// <param name="test">The test.</param> /// <remarks></remarks> public H1BSPConvert(Map map, ref PropertyGrid test) { switch (map.HaloVersion) { case HaloVersionEnum.Halo1: case HaloVersionEnum.HaloCE: map.OpenMap(MapTypes.Internal); H1SBSP h1bsp = new H1SBSP(map.BSP.sbsp[0].TagIndex, map); test.SelectedObject = h1bsp.Header; map.CloseMap(); break; case HaloVersionEnum.Halo2: case HaloVersionEnum.Halo2Vista: MessageBox.Show("Open an H1 Map first"); break; } // OpenFileDialog open = new OpenFileDialog(); // open.Filter = "*.map|*.map"; // if (open.ShowDialog() == DialogResult.Cancel) return; // int h2map=Maps.Add(open.FileName); // Halo2BSP h2bsp = new Halo2BSP(h2map); // Maps.Remove(h2map); }
/// <summary> /// The halo ce container. /// </summary> /// <param name="map">The map.</param> /// <remarks></remarks> public void HaloCEContainer(Map map) { map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[0] + 1444; bspcount = map.BR.ReadInt32(); int tempr = map.BR.ReadInt32() - map.PrimaryMagic; sbsp = new BSPInfo[bspcount]; for (int x = 0; x < bspcount; x++) { sbsp[x] = new BSPInfo(); sbsp[x].pointerOffset = tempr + (x * 32) - map.MetaInfo.Offset[0]; map.BR.BaseStream.Position = tempr + (x * 32); sbsp[x].offset = map.BR.ReadInt32(); sbsp[x].size = map.BR.ReadInt32(); sbsp[x].magic = map.BR.ReadInt32() - sbsp[x].offset; map.BR.BaseStream.Position = tempr + (x * 32) + 28; sbsp[x].ident = map.BR.ReadInt32(); sbsp[x].TagIndex = map.Functions.ForMeta.FindMetaByID(sbsp[x].ident); map.MetaInfo.Offset[sbsp[x].TagIndex] = sbsp[x].offset; map.MetaInfo.Size[sbsp[x].TagIndex] = sbsp[x].size; map.BR.BaseStream.Position = sbsp[x].offset + 4; sbsp[x].Halo1VerticeCount = map.BR.ReadInt32(); sbsp[x].lightmapoffset = 24; map.BR.BaseStream.Position = sbsp[x].lightmapoffset + 12; sbsp[x].lightmapident = map.BR.ReadInt32(); sbsp[x].lightmapTagIndex = map.Functions.ForMeta.FindMetaByID(sbsp[x].ident); } map.CloseMap(); }
/// <summary> /// Loads a .map file and returns it as /// a map object /// </summary> /// <param name="fileName">The file Name.</param> /// <returns></returns> /// <remarks></remarks> public static Map LoadFromFile(string fileName) { // create the map object and give it the map filename Map map = new Map(fileName); // open the map map.OpenMap(MapTypes.Internal); // if the open failed, nothing we can do further if (!map.isOpen) { return(null); } // Get map version, (what halo this is) map.BR.BaseStream.Position = 4; int version = map.BR.ReadInt32(); // set the halo game type in the map object switch (version) { case 609: map.HaloVersion = HaloVersionEnum.HaloCE; break; case 8: map.HaloVersion = HaloVersionEnum.Halo2; map.BR.BaseStream.Position = 0x24; switch (map.BR.ReadInt32()) { case -1: map.HaloVersion = HaloVersionEnum.Halo2Vista; break; case 0: map.HaloVersion = HaloVersionEnum.Halo2; break; } break; case 5: map.HaloVersion = HaloVersionEnum.Halo1; break; // if we dont support the map, dont open it default: MessageBox.Show("This is not a supported map type."); map.CloseMap(); return(null); } // read from the map map.LoadMap(); // close file and return map obj map.CloseMap(); return(map); }
/// <summary> /// The get meta from tag index. /// </summary> /// <param name="tag">The tag.</param> /// <param name="map">The map.</param> /// <param name="manualScan">The manual scan.</param> /// <param name="parse">The parse.</param> /// <returns></returns> /// <remarks></remarks> public static Meta GetMetaFromTagIndex(int tag, Map map, bool manualScan, bool parse) { map.OpenMap(MapTypes.Internal); Meta meta = new Meta(map); meta.TagIndex = tag; meta.ScanMetaItems(manualScan, parse); map.CloseMap(); meta.SortItemsByOffset(); return(meta); }
/// <summary> /// Initializes a new instance of the <see cref="Scripts"/> class. /// </summary> /// <param name="map">The map.</param> /// <remarks></remarks> public Scripts(Map map) { map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 568; int tempc = map.BR.ReadInt32(); int tempr = map.BR.ReadInt32() - map.SecondaryMagic; syntaxes = new Syntax[tempc]; map.BR.BaseStream.Position = tempr; for (int x = 0; x < tempc; x++) { syntaxes[x] = new Syntax(ref map.BR); } map.CloseMap(); }
/// <summary> /// The write palettes. /// </summary> /// <param name="map">The map.</param> /// <remarks></remarks> public void WritePalettes(Map map) { map.OpenMap(MapTypes.Internal); map.BW.BaseStream.Position = palettesoffset; foreach (BSPContainer.Palette_Color[] palette in LightMap_Palettes) { for (int x = 0; x < 256; x++) { map.BW.Write((byte)palette[x].r); map.BW.Write((byte)palette[x].g); map.BW.Write((byte)palette[x].b); map.BW.Write((byte)palette[x].a); } } map.CloseMap(); }
/// <summary> /// Initializes a new instance of the <see cref="BitmapControl"/> class. /// </summary> /// <param name="map">The map.</param> /// <remarks></remarks> public BitmapControl(Map map) { InitializeComponent(); this.map = map; map.OpenMap(MapTypes.Internal); pm = new ParsedBitmap(ref map.SelectedMeta, map); for (int x = 0; x < pm.Properties.Length; x++) { TreeNode tn = new TreeNode("Bitmap #" + x); tn.Tag = "BITMAP"; for (int i = 0; i < map.SelectedMeta.raw.rawChunks.Count; i++) { int count = pm.Properties[x].mipMapCount; BitmapRawDataChunk bmRaw = (BitmapRawDataChunk)map.SelectedMeta.raw.rawChunks[i]; if (bmRaw.inchunk == x) { TreeNode chunknode = new TreeNode("Chunk #" + bmRaw.num); chunknode.Tag = "CHUNK"; int chunkWidth = pm.Properties[x].width >> bmRaw.num; int mipcount = 0; while (chunkWidth > 1 && count > 0) { TreeNode mipnode = new TreeNode("Mipmap #" + (mipcount++)); mipnode.Tag = "MIPMAP"; chunknode.Nodes.Add(mipnode); chunkWidth >>= 1; count--; } tn.Nodes.Add(chunknode); } } treeView1.Nodes.Add(tn); } map.CloseMap(); DisplayBitmap(0, 0, 0); }
/// <summary> /// Initializes a new instance of the <see cref="hlmtContainer"/> class. /// </summary> /// <param name="tagIndex">Index of the tag.</param> /// <param name="map">The map.</param> /// <remarks></remarks> public hlmtContainer(int tagIndex, Map map) { bool alreadyOpen = true; if (!(map.isOpen && map.openMapType == MapTypes.Internal)) { map.OpenMap(MapTypes.Internal); alreadyOpen = false; } this.TagIndex = tagIndex; Permutations = new PermutationInfo(); Permutations.Name = map.FileNames.Name[TagIndex]; map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 112; int tempc = map.BR.ReadInt32(); int tempr = map.BR.ReadInt32() - map.SecondaryMagic; Permutations.Piece = new PermutationInfo.PermutationPiece[tempc]; for (int x = 0; x < tempc; x++) { Permutations.Piece[x] = new PermutationInfo.PermutationPiece(); map.BR.BaseStream.Position = tempr + (x * 16); Permutations.Piece[x].PieceName = map.Strings.Name[map.BR.ReadInt16()]; map.BR.BaseStream.Position = tempr + (x * 16) + 8; int tempc2 = map.BR.ReadInt32(); int tempr2 = map.BR.ReadInt32() - map.SecondaryMagic; Permutations.Piece[x].Permutation = new PermutationInfo.PermutationPiece.PermutationVariation[tempc2]; for (int xx = 0; xx < tempc2; xx++) { Permutations.Piece[x].Permutation[xx] = new PermutationInfo.PermutationPiece.PermutationVariation(); map.BR.BaseStream.Position = tempr2 + (xx * 8); string temps2 = map.Strings.Name[map.BR.ReadInt16()]; Permutations.Piece[x].Permutation[xx].PermutationNameX = temps2; } } if (!alreadyOpen) { map.CloseMap(); } }
/// <summary> /// Loads the strings from "stringListIdent" into "strings" /// </summary> /// <param name="map"></param> /// <returns></returns> public bool getStrings(Map map) { if (!isPopulated | stringsListIdent == -1) return false; Meta m = Map.GetMetaFromTagIndex(map.Functions.ForMeta.FindMetaByID(stringsListIdent), map, false, false); BinaryReader br = new BinaryReader(m.MS); br.BaseStream.Position = 16; // English only... int offset = br.ReadUInt16(); int count = br.ReadUInt16(); int uiOffset = map.Unicode.ut[0].indexOffset; int utOffset = map.Unicode.ut[0].tableOffset; if (map.Unicode.ut[0].SIDs == null) map.Unicode.ut[0].Read(); map.OpenMap(MapTypes.Internal); br = new BinaryReader(map.FS); for (int i = 0; i < count; i++) { br.BaseStream.Position = utOffset + map.Unicode.ut[0].US[offset + i].offset; strings.Add( new entity.MetaFuncs.MEStringsSelector.Unicode( offset + i, map.Unicode.ut[0].US[offset + i].uString, map.Unicode.ut[0].US[offset + i].size, map.Unicode.ut[0].US[offset + i].offset, null)); } //new string(br.ReadChars(map.Unicode.ut[0].US[offset + i].size)); map.CloseMap(); return true; }
/// <summary> /// The halo 2 bsp container. /// </summary> /// <param name="map">The map.</param> /// <remarks></remarks> public void Halo2BSPContainer(Map map) { map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 528; bspcount = map.BR.ReadInt32(); int tempr = map.BR.ReadInt32() - map.SecondaryMagic; sbsp = new BSPInfo[bspcount]; for (int x = 0; x < bspcount; x++) { sbsp[x] = new BSPInfo(); sbsp[x].pointerOffset = tempr + (x * 68) - map.MetaInfo.Offset[3]; map.BR.BaseStream.Position = tempr + (x * 68); sbsp[x].offset = map.BR.ReadInt32(); map.Functions.ParsePointer(ref sbsp[x].offset, ref sbsp[x].location); sbsp[x].size = map.BR.ReadInt32(); sbsp[x].magic = map.BR.ReadInt32() - sbsp[x].offset; map.BR.BaseStream.Position = tempr + (x * 68) + 20; sbsp[x].ident = map.BR.ReadInt32(); // MessageBox.Show(sbsp[x].ident.ToString("X")); sbsp[x].TagIndex = map.Functions.ForMeta.FindMetaByID(sbsp[x].ident); map.MetaInfo.Offset[sbsp[x].TagIndex] = sbsp[x].offset; map.MetaInfo.Size[sbsp[x].TagIndex] = sbsp[x].size; map.BR.BaseStream.Position = tempr + (x * 68) + 28; sbsp[x].lightmapident = map.BR.ReadInt32(); sbsp[x].lightmapTagIndex = map.Functions.ForMeta.FindMetaByID(sbsp[x].lightmapident); if (sbsp[x].lightmapTagIndex == -1) { continue; } map.BR.BaseStream.Position = sbsp[x].offset + 8; sbsp[x].lightmapoffset = map.BR.ReadInt32(); if (sbsp[x].lightmapoffset == 0) { sbsp[x].lightmapident = -1; sbsp[x].lightmapTagIndex = -1; if ( MessageBox.Show( "There is no lightmap for this bsp and the scenario is currently linked to a broken ID.\n Would you like Entity to fix it?", "Error", MessageBoxButtons.YesNo) == DialogResult.Yes) { map.BW.BaseStream.Position = tempr + (x * 68) + 28; map.BW.Write(int.Parse("FFFFFFFF", NumberStyles.HexNumber)); } continue; } sbsp[x].lightmapoffset += -sbsp[x].magic; sbsp[x].lightmapsize = sbsp[x].size + sbsp[x].offset - sbsp[x].lightmapoffset; map.MetaInfo.Offset[sbsp[x].lightmapTagIndex] = sbsp[x].lightmapoffset; map.MetaInfo.Size[sbsp[x].lightmapTagIndex] = sbsp[x].lightmapsize; // light map bitmap map.BR.BaseStream.Position = sbsp[x].lightmapoffset + 128; int tempc = map.BR.ReadInt32(); int temprx = map.BR.ReadInt32() - sbsp[x].magic; map.BR.BaseStream.Position = temprx + 28; sbsp[x].LightMap_TagNumber = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); ///light map palettes map.BR.BaseStream.Position = temprx + 8; int tempc2 = map.BR.ReadInt32(); int tempr2 = map.BR.ReadInt32() - sbsp[x].magic; sbsp[x].palettesoffset = tempr2; for (int y = 0; y < tempc2; y++) { map.BR.BaseStream.Position = tempr2 + (y * 1024); Palette_Color[] pc = new Palette_Color[256]; for (int z = 0; z < 256; z++) { pc[z] = new Palette_Color(); pc[z].r = map.BR.ReadByte(); pc[z].g = map.BR.ReadByte(); pc[z].b = map.BR.ReadByte(); pc[z].a = map.BR.ReadByte(); } sbsp[x].LightMap_Palettes.Add(pc); } map.BR.BaseStream.Position = temprx + 40; tempc2 = map.BR.ReadInt32(); tempr2 = map.BR.ReadInt32() - sbsp[x].magic; sbsp[x].VisualChunk_Bitmap_Index = new int[tempc2]; sbsp[x].VisualChunk_LightMap_Index = new int[tempc2]; if (tempc2 != 0) { map.BR.BaseStream.Position = tempr2; for (int y = 0; y < tempc2; y++) { sbsp[x].VisualChunk_Bitmap_Index[y] = map.BR.ReadInt16(); sbsp[x].VisualChunk_LightMap_Index[y] = map.BR.ReadInt16(); } } map.BR.BaseStream.Position = temprx + 72; tempc2 = map.BR.ReadInt32(); tempr2 = map.BR.ReadInt32() - sbsp[x].magic; sbsp[x].SceneryChunk_Bitmap_Index = new int[tempc2]; sbsp[x].SceneryChunk_LightMap_Index = new int[tempc2]; if (tempc2 > 0) { map.BR.BaseStream.Position = tempr2; for (int y = 0; y < tempc2; y++) { sbsp[x].SceneryChunk_Bitmap_Index[y] = map.BR.ReadInt16(); sbsp[x].SceneryChunk_LightMap_Index[y] = map.BR.ReadInt16(); } } } map.CloseMap(); }
/// <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(); }
/// <summary> /// The build meta. /// </summary> /// <param name="metasplit">The metasplit.</param> /// <param name="map">The map.</param> /// <returns></returns> /// <remarks></remarks> public static Meta BuildMeta(MetaSplitter metasplit, Map map) { metasize = 0; MetaStream = new MemoryStream(metasplit.Header.chunksize); BinaryWriter BW = new BinaryWriter(MetaStream); // BW.BaseStream.Position = 0; // BW.Write(metasplit.Header.MS.ToArray(), 0, metasplit.Header.chunksize); metasize += metasplit.Header.chunksize; TagIndex = metasplit.TagIndex; Meta m = new Meta(map); List<Meta.Item> NewItems = new List<Meta.Item>(); // Major error here! Size is not calculated right! RecursivelyAddPiecesToMeta(metasplit.Header, ref NewItems, ref BW); m.items = NewItems; if (MetaStream.Length % 4 != 0) { metasize += (int)MetaStream.Length % 4; MetaStream.SetLength(MetaStream.Length + MetaStream.Length % 4); } m.MS = MetaStream; m.size = metasize; m.type = metasplit.type; m.name = metasplit.name; m.rawType = metasplit.rawtype; m.raw = metasplit.raw; m.magic = metasplit.magic; m.offset = metasplit.offset; m.TagIndex = TagIndex; m.RelinkReferences(); m.WriteReferences(); // m.items.Clear(); // MetaScanner Ms = new MetaScanner(); if (m.rawType != RawDataContainerType.Empty) { map.OpenMap(MapTypes.Internal); m.raw = map.Functions.ForMeta.ReadRaw(m.TagIndex, false); map.CloseMap(); } // map.OpenMap(MapTypes.Internal); // IFPIO ifp=IFP.IFPHashMap.GetIfp(m.type); // m.parsed = true; // Ms.ScanWithIFP(ref ifp, ref m, map) ; // map.CloseMap(); return m; }
/// <summary> /// The h 2 spawn info. /// </summary> /// <param name="map">The map.</param> /// <remarks></remarks> public void H2SpawnInfo(Map map) { map.OpenMap(MapTypes.Internal); // find default mc model map.BR.BaseStream.Position = map.MetaInfo.Offset[0] + 308; int tempr = map.BR.ReadInt32() - map.SecondaryMagic; map.BR.BaseStream.Position = tempr + 4; int tempbipdtag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); //map.CloseMap(); int bipdmodeltag = map.Functions.FindModelByBaseClass(tempbipdtag); // Find objective models //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[ map.Functions.ForMeta.FindByNameAndTagType("mulg", "multiplayer\\multiplayer_globals")] + 12; tempr = map.BR.ReadInt32(); int ctfmodeltag = -1; int ballmodeltag = -1; int juggernautdmodeltag = -1; int assultmodeltag = -1; if (tempr != 0) { tempr -= map.SecondaryMagic; map.BR.BaseStream.Position = tempr + 4; int tempCtftag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); map.BR.BaseStream.Position = tempr + 12; int tempBalltag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); map.BR.BaseStream.Position = tempr + 36; int tempHillShader = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); // I believe the Hill Shader above is not used, but just in case. Otherwise, load the usual one below if (tempHillShader == -1) { map.BR.BaseStream.Position = tempr + 1332; int tempr2 = map.BR.ReadInt32(); if (tempr2 != 0) { tempr2 -= map.SecondaryMagic; map.BR.BaseStream.Position = tempr2 + 196; tempHillShader = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); } } map.BR.BaseStream.Position = tempr + 52; int tempJuggernauttag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); map.BR.BaseStream.Position = tempr + 60; int tempAssaulttag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); //map.CloseMap(); ctfmodeltag = map.Functions.FindModelByBaseClass(tempCtftag); ballmodeltag = map.Functions.FindModelByBaseClass(tempBalltag); // *** This is not right. It's a shader, not a model. But I don't know how to display a shader... hillshadertag = map.Functions.ForMeta.FindMetaByID(tempHillShader); juggernautdmodeltag = map.Functions.FindModelByBaseClass(tempJuggernauttag); assultmodeltag = map.Functions.FindModelByBaseClass(tempAssaulttag); } #region //// Player Spawns //// //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 256; int tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { map.BR.BaseStream.Position = tempr + (52 * x); PlayerSpawn ps = new PlayerSpawn(); ps.offset = tempr + (52 * x); ps.X = map.BR.ReadSingle(); ps.Y = map.BR.ReadSingle(); ps.Z = map.BR.ReadSingle(); ps.RotationDirection = map.BR.ReadSingle(); ps.ModelTagNumber = bipdmodeltag; ps.ModelName = map.FileNames.Name[ps.ModelTagNumber]; Spawn.Add(ps); } #endregion #region //// death zones //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 264; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { DeathZone ps = new DeathZone(); // Load the deathzone name map.BR.BaseStream.Position = tempr + (68 * x); ps.Name = map.Strings.Name[map.BR.ReadInt16()]; // We set the offset to 36 b/c we don't care about saving the name... right now anyways. ps.offset = tempr + (68 * x) + 36; // Load the deathzone coordinates map.BR.BaseStream.Position = tempr + (68 * x) + 36; ps.X = map.BR.ReadSingle(); ps.Y = map.BR.ReadSingle(); ps.Z = map.BR.ReadSingle(); // Use ABS() to make sure our sizes are always positive ps.width = Math.Abs(map.BR.ReadSingle()); ps.height = Math.Abs(map.BR.ReadSingle()); ps.length = Math.Abs(map.BR.ReadSingle()); // Deathzones are saved with a centre point and Width, Length, Height ps.X += ps.width / 2; ps.Y += ps.height / 2; ps.Z += ps.length / 2; Spawn.Add(ps); } #endregion #region //// lights //// //// palette //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 240; int[] temppalette = new int[map.BR.ReadInt32()]; int[] temppalette2 = new int[temppalette.Length]; tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < temppalette.Length; x++) { map.BR.BaseStream.Position = tempr + (x * 40) + 4; int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); temppalette2[x] = tempbase; temppalette[x] = tempbase; } //// placement //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 232; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { map.BR.BaseStream.Position = tempr + (108 * x); short tempshort = map.BR.ReadInt16(); if (tempshort == -1) { continue; } map.BR.BaseStream.Position = tempr + (108 * x) + 8; LightSpawn vs = new LightSpawn(); vs.offset = tempr + (108 * x) + 8; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); vs.Roll = map.BR.ReadSingle(); vs.Pitch = map.BR.ReadSingle(); vs.Yaw = map.BR.ReadSingle(); vs.Scale = map.BR.ReadSingle(); vs.TagPath = map.FileNames.Name[temppalette2[tempshort]]; vs.ModelTagNumber = temppalette[tempshort]; if (vs.ModelTagNumber == -1) { continue; } vs.ModelName = map.FileNames.Name[vs.ModelTagNumber]; Spawn.Add(vs); } #endregion #region //// sounds //// //// Sound Scenery palette //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 224; // temppalette variables declared in Lights section above temppalette = new int[map.BR.ReadInt32()]; temppalette2 = new int[temppalette.Length]; tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < temppalette.Length; x++) { map.BR.BaseStream.Position = tempr + (x * 40) + 4; int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); temppalette2[x] = tempbase; temppalette[x] = tempbase; } //// placement //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 216; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { map.BR.BaseStream.Position = tempr + (80 * x); short tempshort = map.BR.ReadInt16(); if (tempshort == -1) { continue; } SoundSpawn vs = new SoundSpawn(); map.BR.BaseStream.Position = tempr + (80 * x) + 8; vs.offset = tempr + (80 * x) + 8; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); vs.Roll = map.BR.ReadSingle(); vs.Pitch = map.BR.ReadSingle(); vs.Yaw = map.BR.ReadSingle(); vs.Scale = map.BR.ReadSingle(); map.BR.BaseStream.Position = tempr + (80 * x) + 54; vs.VolumeType = map.BR.ReadInt16(); vs.Height = map.BR.ReadSingle(); vs.DistanceBoundsLower = map.BR.ReadSingle(); vs.DistanceBoundsUpper = map.BR.ReadSingle(); vs.ConeAngleLower = map.BR.ReadSingle(); vs.ConeAngleUpper = map.BR.ReadSingle(); vs.OuterConeGain = map.BR.ReadSingle(); if (temppalette2[tempshort] == -1) { vs.TagPath = "Nulled Out"; } else { vs.TagPath = map.FileNames.Name[temppalette2[tempshort]]; } vs.ModelTagNumber = temppalette[tempshort]; if (vs.ModelTagNumber == -1) { // { continue; } vs.ModelName = null; } else { vs.ModelName = map.FileNames.Name[vs.ModelTagNumber]; } Spawn.Add(vs); } #endregion #region //// objectives //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 280; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { ObjectiveSpawn ps = new ObjectiveSpawn(); ps.offset = tempr + (32 * x); map.BR.BaseStream.Position = tempr + (32 * x); ps.X = map.BR.ReadSingle(); ps.Y = map.BR.ReadSingle(); ps.Z = map.BR.ReadSingle(); ps.RotationDirection = map.BR.ReadSingle(); ps.ObjectiveType = (ObjectiveSpawn.ObjectiveTypeEnum)map.BR.ReadInt16(); ps.Team = (ObjectiveSpawn.TeamType)map.BR.ReadInt16(); ps.number = map.BR.ReadInt16(); if (ps.ObjectiveType == ObjectiveSpawn.ObjectiveTypeEnum.OddballSpawn && ballmodeltag != -1) { ps.ModelTagNumber = ballmodeltag; } else if (ps.ObjectiveType == ObjectiveSpawn.ObjectiveTypeEnum.CTFRespawn && ctfmodeltag != -1) { ps.ModelTagNumber = ctfmodeltag; } else if ( ps.ObjectiveType.ToString().StartsWith( ObjectiveSpawn.ObjectiveTypeEnum.KingOfTheHill_1.ToString().Substring(0, 13)) && ctfmodeltag != -1) { ps.ModelTagNumber = ctfmodeltag; } else if (ps.ObjectiveType == ObjectiveSpawn.ObjectiveTypeEnum.AssaultRespawn && assultmodeltag != -1) { ps.ModelTagNumber = assultmodeltag; } else { ps.ModelTagNumber = bipdmodeltag; } ps.ModelName = map.FileNames.Name[ps.ModelTagNumber]; Spawn.Add(ps); } #endregion #region //// vehicles //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 120; temppalette = new int[map.BR.ReadInt32()]; temppalette2 = new int[temppalette.Length]; tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < temppalette.Length; x++) { //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = tempr + (x * 40) + 4; int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); //map.CloseMap(); temppalette2[x] = tempbase; temppalette[x] = map.Functions.FindModelByBaseClass(tempbase); } //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 112; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { map.BR.BaseStream.Position = tempr + (84 * x); short tempshort = map.BR.ReadInt16(); if (tempshort == -1) { continue; } map.BR.BaseStream.Position = tempr + (84 * x) + 8; VehicleSpawn vs = new VehicleSpawn(); vs.offset = tempr + (84 * x) + 8; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); vs.Roll = map.BR.ReadSingle(); vs.Pitch = map.BR.ReadSingle(); vs.Yaw = map.BR.ReadSingle(); vs.Scale = map.BR.ReadSingle(); vs.TagPath = map.FileNames.Name[temppalette2[tempshort]]; vs.ModelTagNumber = temppalette[tempshort]; if (vs.ModelTagNumber == -1) { continue; } vs.ModelName = map.FileNames.Name[vs.ModelTagNumber]; Spawn.Add(vs); } #endregion #region //// equipment //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 136; temppalette = new int[map.BR.ReadInt32()]; temppalette2 = new int[temppalette.Length]; tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < temppalette.Length; x++) { //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = tempr + (x * 40) + 4; int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); //map.CloseMap(); temppalette2[x] = tempbase; temppalette[x] = map.Functions.FindModelByBaseClass(tempbase); } //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 128; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { map.BR.BaseStream.Position = tempr + (56 * x); short tempshort = map.BR.ReadInt16(); if (tempshort == -1) { continue; } map.BR.BaseStream.Position = tempr + (56 * x) + 8; EquipmentSpawn vs = new EquipmentSpawn(); vs.offset = tempr + (56 * x) + 8; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); // vs.RotationDirection = map.BR.ReadSingle(); vs.Roll = map.BR.ReadSingle(); vs.Pitch = map.BR.ReadSingle(); vs.Yaw = map.BR.ReadSingle(); vs.Scale = map.BR.ReadSingle(); vs.TagPath = map.FileNames.Name[temppalette2[tempshort]]; vs.ModelTagNumber = temppalette[tempshort]; if (vs.ModelTagNumber == -1) { continue; } vs.ModelName = map.FileNames.Name[vs.ModelTagNumber]; Spawn.Add(vs); } #endregion #region //// bipeds //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 104; temppalette = new int[map.BR.ReadInt32()]; temppalette2 = new int[temppalette.Length]; tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < temppalette.Length; x++) { //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = tempr + (x * 40) + 4; int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); //map.CloseMap(); temppalette2[x] = tempbase; temppalette[x] = map.Functions.FindModelByBaseClass(tempbase); } //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 96; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { map.BR.BaseStream.Position = tempr + (84 * x); short tempshort = map.BR.ReadInt16(); if (tempshort == -1) { continue; } map.BR.BaseStream.Position = tempr + (84 * x) + 8; BipedSpawn vs = new BipedSpawn(); vs.offset = tempr + (84 * x) + 8; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); vs.Roll = map.BR.ReadSingle(); vs.Pitch = map.BR.ReadSingle(); vs.Yaw = map.BR.ReadSingle(); vs.Scale = map.BR.ReadSingle(); vs.TagPath = map.FileNames.Name[temppalette2[tempshort]]; vs.ModelTagNumber = temppalette[tempshort]; if (vs.ModelTagNumber == -1) { continue; } vs.ModelName = map.FileNames.Name[vs.ModelTagNumber]; Spawn.Add(vs); } #endregion #region //// control //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 192; temppalette = new int[map.BR.ReadInt32()]; temppalette2 = new int[temppalette.Length]; tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < temppalette.Length; x++) { //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = tempr + (x * 40) + 4; int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); //map.CloseMap(); temppalette2[x] = tempbase; temppalette[x] = map.Functions.FindModelByBaseClass(tempbase); } //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 184; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { map.BR.BaseStream.Position = tempr + (68 * x); short tempshort = map.BR.ReadInt16(); if (tempshort == -1) { continue; } map.BR.BaseStream.Position = tempr + (68 * x) + 8; ControlSpawn vs = new ControlSpawn(); vs.offset = tempr + (68 * x) + 8; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); // vs.RotationDirection = map.BR.ReadSingle(); vs.Roll = map.BR.ReadSingle(); vs.Pitch = map.BR.ReadSingle(); vs.Yaw = map.BR.ReadSingle(); vs.Scale = map.BR.ReadSingle(); vs.TagPath = map.FileNames.Name[temppalette2[tempshort]]; vs.ModelTagNumber = temppalette[tempshort]; if (vs.ModelTagNumber == -1) { continue; } vs.ModelName = map.FileNames.Name[vs.ModelTagNumber]; Spawn.Add(vs); } #endregion #region //// machines //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 176; temppalette = new int[map.BR.ReadInt32()]; temppalette2 = new int[temppalette.Length]; tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < temppalette.Length; x++) { //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = tempr + (x * 40) + 4; int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); //map.CloseMap(); temppalette2[x] = tempbase; temppalette[x] = map.Functions.FindModelByBaseClass(tempbase); } //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 168; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { map.BR.BaseStream.Position = tempr + (72 * x); short tempshort = map.BR.ReadInt16(); if (tempshort == -1) { continue; } map.BR.BaseStream.Position = tempr + (72 * x) + 8; MachineSpawn vs = new MachineSpawn(); vs.offset = tempr + (72 * x) + 8; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); vs.Roll = map.BR.ReadSingle(); vs.Pitch = map.BR.ReadSingle(); vs.Yaw = map.BR.ReadSingle(); vs.Scale = map.BR.ReadSingle(); if (temppalette2[tempshort] == -1 || temppalette[tempshort] == -1) { continue; } vs.TagPath = map.FileNames.Name[temppalette2[tempshort]]; vs.ModelTagNumber = temppalette[tempshort]; if (vs.ModelTagNumber == -1) { continue; } vs.ModelName = map.FileNames.Name[vs.ModelTagNumber]; Spawn.Add(vs); } #endregion #region //// scenery //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 88; temppalette = new int[map.BR.ReadInt32()]; temppalette2 = new int[temppalette.Length]; tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < temppalette.Length; x++) { //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = tempr + (x * 40) + 4; int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); //map.CloseMap(); temppalette2[x] = tempbase; temppalette[x] = map.Functions.FindModelByBaseClass(tempbase); } //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 80; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { map.BR.BaseStream.Position = tempr + (92 * x); short tempshort = map.BR.ReadInt16(); if (tempshort == -1) { continue; } map.BR.BaseStream.Position = tempr + (92 * x) + 8; ScenerySpawn vs = new ScenerySpawn(); vs.offset = tempr + (92 * x) + 8; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); vs.Roll = map.BR.ReadSingle(); vs.Pitch = map.BR.ReadSingle(); vs.Yaw = map.BR.ReadSingle(); vs.Scale = map.BR.ReadSingle(); if (temppalette2[tempshort] == -1 || temppalette[tempshort] == -1) { continue; } vs.TagPath = map.FileNames.Name[temppalette2[tempshort]]; vs.ModelTagNumber = temppalette[tempshort]; if (vs.ModelTagNumber == -1) { continue; } vs.ModelName = map.FileNames.Name[vs.ModelTagNumber]; Spawn.Add(vs); } #endregion #region //// weapons //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 152; temppalette = new int[map.BR.ReadInt32()]; temppalette2 = new int[temppalette.Length]; tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < temppalette.Length; x++) { //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = tempr + (x * 40) + 4; int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); //map.CloseMap(); temppalette2[x] = tempbase; temppalette[x] = map.Functions.FindModelByBaseClass(tempbase); } //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 144; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { map.BR.BaseStream.Position = tempr + (84 * x); short tempshort = map.BR.ReadInt16(); if (tempshort == -1) { continue; } map.BR.BaseStream.Position = tempr + (84 * x) + 8; WeaponSpawn vs = new WeaponSpawn(); vs.offset = tempr + (84 * x) + 8; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); vs.Roll = map.BR.ReadSingle(); vs.Pitch = map.BR.ReadSingle(); vs.Yaw = map.BR.ReadSingle(); vs.Scale = map.BR.ReadSingle(); vs.TagPath = map.FileNames.Name[temppalette2[tempshort]]; vs.ModelTagNumber = temppalette[tempshort]; if (vs.ModelTagNumber == -1) { continue; } vs.ModelName = map.FileNames.Name[vs.ModelTagNumber]; Spawn.Add(vs); } #endregion #region //// obstacles //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 816; temppalette = new int[map.BR.ReadInt32()]; temppalette2 = new int[temppalette.Length]; tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < temppalette.Length; x++) { //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = tempr + (x * 40) + 4; int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); //map.CloseMap(); temppalette2[x] = tempbase; temppalette[x] = map.Functions.FindModelByBaseClass(tempbase); } //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 808; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { map.BR.BaseStream.Position = tempr + (76 * x); short tempshort = map.BR.ReadInt16(); if (tempshort == -1) { continue; } map.BR.BaseStream.Position = tempr + (76 * x) + 8; ObstacleSpawn vs = new ObstacleSpawn(); vs.offset = tempr + (76 * x) + 8; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); vs.Roll = map.BR.ReadSingle(); vs.Pitch = map.BR.ReadSingle(); vs.Yaw = map.BR.ReadSingle(); vs.Scale = map.BR.ReadSingle(); if (temppalette2[tempshort] == -1) { continue; } vs.TagPath = map.FileNames.Name[temppalette2[tempshort]]; vs.ModelTagNumber = temppalette[tempshort]; if (vs.ModelTagNumber == -1) { continue; } vs.ModelName = map.FileNames.Name[vs.ModelTagNumber]; Spawn.Add(vs); } #endregion #region //// collections //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 288; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { //map.OpenMap(MapTypes.Internal); Collection vs = new Collection(); map.BR.BaseStream.Position = tempr + (144 * x) + 4; vs.SpawnsInMode = (Collection.SpawnsInEnum)map.BR.ReadInt32(); // Why do they make the offset + 64? That just confuses stuff!! map.BR.BaseStream.Position = tempr + (144 * x) + 64; vs.offset = tempr + (144 * x) + 64; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); vs.Roll = map.BR.ReadSingle(); vs.Pitch = map.BR.ReadSingle(); vs.Yaw = map.BR.ReadSingle(); // test // if (vs.Pitch > 0) { vs.Pitch = -vs.Pitch; vs.isWeird = true; } else { vs.isWeird = false; } map.BR.BaseStream.Position = tempr + (144 * x) + 88; // ID Type char[] c = map.BR.ReadChars(4); vs.TagType = c[3].ToString() + c[2] + c[1] + c[0]; // Tag Path ID int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); if (tempbase == -1) { continue; } //map.CloseMap(); vs.TagPath = map.FileNames.Name[tempbase]; vs.ModelTagNumber = map.Functions.FindModelByBaseClass(tempbase); if (vs.ModelTagNumber == -1) { continue; } vs.ModelName = map.FileNames.Name[vs.ModelTagNumber]; Spawn.Add(vs); } #endregion #region //// cameras //// //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 488; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { //map.OpenMap(MapTypes.Internal); CameraSpawn vs = new CameraSpawn(); map.BR.BaseStream.Position = tempr + (64 * x) + 36; vs.offset = tempr + (64 * x) + 36; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); vs.Roll = map.BR.ReadSingle(); vs.Pitch = map.BR.ReadSingle(); vs.Yaw = map.BR.ReadSingle(); vs.fov = map.BR.ReadSingle(); vs.ModelTagNumber = -1; Spawn.Add(vs); } #endregion #region //// AI_Squads //// map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 376; temppalette = new int[map.BR.ReadInt32()]; temppalette2 = new int[temppalette.Length]; tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < temppalette.Length; x++) { map.BR.BaseStream.Position = tempr + (x * 8) + 4; int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); temppalette2[x] = tempbase; temppalette[x] = map.Functions.FindModelByBaseClass(tempbase); } // Reading ai squads reflexive map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 352; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { // Reads AI Squad palette chunk map.BR.BaseStream.Position = tempr + (x * 116) + 54; short charNum = map.BR.ReadInt16(); // Reading locations sub reflexive map.BR.BaseStream.Position = tempr + 72; int locc = map.BR.ReadInt32(); int locr = map.BR.ReadInt32() - map.SecondaryMagic; AI_Squads vs = new AI_Squads(); // chunk size * x and starting position map.BR.BaseStream.Position = locr + (100 * x); vs.offset = tempr + (100 * x); vs.ModelName = map.Strings.Name[(Int16)map.BR.ReadInt32()]; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); // facing direction map.BR.BaseStream.Position = locr + (100 * x) + 20; vs.RotationDirection = map.BR.ReadSingle(); if (charNum != -1) { vs.TagPath = map.FileNames.Name[temppalette2[charNum]]; vs.ModelTagNumber = temppalette[charNum]; if (vs.ModelTagNumber == -1) { continue; } // vs.ModelName = map.FileNames.Name[vs.ModelTagNumber]; Spawn.Add(vs); } } #endregion map.CloseMap(); }
/// <summary> /// Loads a .map file and returns it as /// a map object /// </summary> /// <param name="fileName">The file Name.</param> /// <returns></returns> /// <remarks></remarks> public static Map LoadFromFile(string fileName) { // create the map object and give it the map filename Map map = new Map(fileName); // open the map map.OpenMap(MapTypes.Internal); // if the open failed, nothing we can do further if (!map.isOpen) { return null; } // Get map version, (what halo this is) map.BR.BaseStream.Position = 4; int version = map.BR.ReadInt32(); // set the halo game type in the map object switch (version) { case 609: map.HaloVersion = HaloVersionEnum.HaloCE; break; case 8: map.HaloVersion = HaloVersionEnum.Halo2; map.BR.BaseStream.Position = 0x24; switch (map.BR.ReadInt32()) { case -1: map.HaloVersion = HaloVersionEnum.Halo2Vista; break; case 0: map.HaloVersion = HaloVersionEnum.Halo2; break; } break; case 5: map.HaloVersion = HaloVersionEnum.Halo1; break; // if we dont support the map, dont open it default: MessageBox.Show("This is not a supported map type."); map.CloseMap(); return null; } // read from the map map.LoadMap(); // close file and return map obj map.CloseMap(); return map; }
/// <summary> /// The scan map for lay out. /// </summary> /// <param name="map">The map.</param> /// <param name="addexternalchunks">The addexternalchunks.</param> /// <returns></returns> /// <remarks></remarks> public MapLayout ScanMapForLayOut(Map map, bool addexternalchunks) { MapLayout layout = new MapLayout(); for (int x = 0; x < map.BSP.sbsp.Length; x++) { LayOutChunk l = new LayOutChunk(0); l.rawType = RawDataContainerType.BSPMeta; l.startoffset = map.BSP.sbsp[x].offset; l.endoffset = map.BSP.sbsp[x].offset + map.BSP.sbsp[x].size; l.size = map.BSP.sbsp[x].size; layout.chunks.Add(l); } LayOutChunk lo = new LayOutChunk(0); lo.rawType = RawDataContainerType.Header; lo.startoffset = 0; lo.size = 2048; lo.endoffset = lo.startoffset + lo.size; layout.chunks.Add(lo); if (map.HaloVersion == HaloVersionEnum.Halo2 || map.HaloVersion == HaloVersionEnum.Halo2Vista) { lo = new LayOutChunk(0); lo.rawType = RawDataContainerType.StringsIndex; lo.startoffset = map.MapHeader.offsetToStringIndex; lo.size = map.MapHeader.scriptReferenceCount * 4; lo.size += map.Functions.Padding(lo.size, 512); lo.endoffset = lo.startoffset + lo.size; layout.chunks.Add(lo); lo = new LayOutChunk(0); lo.rawType = RawDataContainerType.Strings1; lo.startoffset = map.MapHeader.offsetToStringNames1; lo.size = map.MapHeader.scriptReferenceCount * 128; lo.size += map.Functions.Padding(lo.size, 512); lo.endoffset = lo.startoffset + lo.size; layout.chunks.Add(lo); lo = new LayOutChunk(0); lo.rawType = RawDataContainerType.Strings2; lo.startoffset = map.MapHeader.offsetToStringNames2; lo.size = map.MapHeader.sizeOfScriptReference; lo.size += map.Functions.Padding(lo.size, 512); lo.endoffset = lo.startoffset + lo.size; layout.chunks.Add(lo); lo = new LayOutChunk(0); lo.rawType = RawDataContainerType.Crazy; lo.startoffset = map.MapHeader.offsetToCrazy; lo.size = map.MapHeader.sizeOfCrazy; lo.size += map.Functions.Padding(lo.size, 512); lo.endoffset = lo.startoffset + lo.size; layout.chunks.Add(lo); lo = new LayOutChunk(0); lo.rawType = RawDataContainerType.FileNamesIndex; lo.startoffset = map.MapHeader.offsetTofileIndex; lo.size = map.MapHeader.fileCount * 4; lo.size += map.Functions.Padding(lo.size, 512); lo.endoffset = lo.startoffset + lo.size; layout.chunks.Add(lo); } lo = new LayOutChunk(0); lo.rawType = RawDataContainerType.FileNames; lo.startoffset = map.MapHeader.offsetTofileNames; lo.size = map.MapHeader.fileNamesSize; if (map.HaloVersion == HaloVersionEnum.Halo2 || map.HaloVersion == HaloVersionEnum.Halo2Vista) { lo.size += map.Functions.Padding(lo.size, 512); } lo.endoffset = lo.startoffset + lo.size; layout.chunks.Add(lo); lo = new LayOutChunk(0); lo.rawType = RawDataContainerType.MetaIndex; lo.startoffset = map.MapHeader.indexOffset; if (map.HaloVersion == HaloVersionEnum.Halo2 || map.HaloVersion == HaloVersionEnum.Halo2Vista) { lo.size = map.MapHeader.metaStart; lo.size += map.Functions.Padding(lo.size, 512); // map.MapHeader.fileSize - map.MapHeader.indexOffset; } else { lo.size = map.MapHeader.offsetTofileNames - map.MapHeader.indexOffset; // map.MetaInfo.Offset[map.IndexHeader.metaCount - 1] + map.MetaInfo.Size[map.IndexHeader.metaCount-1]; } lo.endoffset = lo.startoffset + lo.size; layout.chunks.Add(lo); lo = new LayOutChunk(0); lo.rawType = RawDataContainerType.MetaData; lo.startoffset = map.MetaInfo.Offset[0]; // How can you adjust for padding past the end of the file??? lo.size = map.MapHeader.fileSize - lo.startoffset; if (map.HaloVersion == HaloVersionEnum.Halo2 || map.HaloVersion == HaloVersionEnum.Halo2Vista) { int padding = map.Functions.Padding(lo.startoffset + lo.size, 4096); lo.size += padding; } lo.endoffset = lo.startoffset + lo.size; layout.chunks.Add(lo); if (map.HaloVersion == HaloVersionEnum.Halo2 || map.HaloVersion == HaloVersionEnum.Halo2Vista) { for (int x = 0; x < map.Unicode.ut.Length; x++) { lo = new LayOutChunk(0); lo.rawType = RawDataContainerType.UnicodeNamesIndex; lo.startoffset = map.Unicode.ut[x].indexOffset; lo.size = map.Unicode.ut[x].count * 8; lo.size += map.Functions.Padding(lo.size, 512); lo.endoffset = lo.startoffset + lo.size; layout.chunks.Add(lo); lo = new LayOutChunk(0); lo.rawType = RawDataContainerType.UnicodeNames; lo.startoffset = map.Unicode.ut[x].tableOffset; lo.size = map.Unicode.ut[x].tableSize; lo.size += map.Functions.Padding(lo.size, 512); lo.endoffset = lo.startoffset + lo.size; layout.chunks.Add(lo); } } map.OpenMap(MapTypes.Internal); for (int x = 0; x < map.IndexHeader.metaCount; x++) { if (map.HaloVersion == HaloVersionEnum.Halo2 || map.HaloVersion == HaloVersionEnum.Halo2Vista) { if (map.MetaInfo.TagType[x] == "snd!" | map.MetaInfo.TagType[x] == "ltmp") { continue; } Application.DoEvents(); } Meta m = new Meta(map); m.offset = map.MetaInfo.Offset[x]; // checks if type has raw data m.rawType = map.Functions.ForMeta.CheckForRaw(map.MetaInfo.TagType[x]); if (m.rawType != RawDataContainerType.Empty) { m.raw = map.Functions.ForMeta.ReadRaw(x, true); LayOutChunk l = new LayOutChunk(map.MapHeader.fileSize); int tempint = layout.FindByType(m.rawType); if (tempint == -1) { l = new LayOutChunk(map.MapHeader.fileSize); l.rawType = m.rawType; layout.chunks.Add(l); tempint = layout.FindByType(m.rawType); } else { l = (LayOutChunk)layout.chunks[tempint]; } for (int y = 0; y < m.raw.rawChunks.Count; y++) { RawDataChunk r = m.raw.rawChunks[y]; if (r.offset == -1) { continue; } if (r.rawLocation == MapTypes.Internal) { RawInfoChunk tempr = new RawInfoChunk(); tempr.offset = (uint)r.offset; tempr.size = r.size; tempr.rawType = r.rawDataType; tempr.location = r.rawLocation; tempr.offsetOfPointer = m.offset + r.pointerMetaOffset; l.rawPieces.Add(tempr); } else if (addexternalchunks) { RawInfoChunk tempr = new RawInfoChunk(); tempr.offset = (uint)r.offset; tempr.size = r.size; tempr.rawType = r.rawDataType; tempr.location = r.rawLocation; tempr.offsetOfPointer = m.offset + r.pointerMetaOffset; l.rawPieces.Add(tempr); } if (r.offset < l.startoffset && r.rawLocation == MapTypes.Internal) { l.startoffset = r.offset; l.size = l.endoffset - l.startoffset; layout.chunks[tempint] = l; } if (r.offset + r.size > l.endoffset && r.rawLocation == MapTypes.Internal) { l.endoffset = r.offset + r.size; l.endoffset += map.Functions.Padding(l.endoffset, 512); l.size = l.endoffset - l.startoffset; layout.chunks[tempint] = l; } } } m = null; GC.WaitForPendingFinalizers(); // GC.Collect(); } map.CloseMap(); if (map.HaloVersion == HaloVersionEnum.Halo2 || map.HaloVersion == HaloVersionEnum.Halo2Vista) { lo = new LayOutChunk(0); LayOutChunk templo = (LayOutChunk)layout.chunks[layout.FindByType(RawDataContainerType.Model)]; lo.rawType = RawDataContainerType.Sound; lo.startoffset = 2048; lo.size = templo.startoffset - 2048; lo.size += map.Functions.Padding(lo.size, 512); lo.endoffset = lo.startoffset + lo.size; layout.chunks.Add(lo); } for (int y = 0; y < layout.chunks.Count; y++) { LayOutChunk l = (LayOutChunk)layout.chunks[y]; if (l.size == 0) { layout.chunks.RemoveAt(y); y--; } } layout.SortChunksByOffset(); layout.SortRawByOffset(); return layout; }
/// <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 2 bitmap raw. /// </summary> /// <param name="TagIndex">The TagIndex.</param> /// <param name="map">The map.</param> /// <param name="dontreadraw">The dontreadraw.</param> /// <remarks></remarks> public void ReadH2BitmapRaw(int TagIndex, Map map, bool dontreadraw) { // 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; for (int x = 0; x < tempc; x++) { // Bitmap Data reflexive is 116 bytes large // Offset 4 in BD reflexive is (short) width map.BR.BaseStream.Position = tempr + (x * 116) + 4; int width = map.BR.ReadInt16(); // Offset 6 in BD reflexive is (short) width int height = map.BR.ReadInt16(); // Offset 8 in BD reflexive is (short) width int depth = map.BR.ReadInt16(); // Offset 10 in BD reflexive is (short) type int type = map.BR.ReadInt16(); // Offset 12 in BD reflexive is (short) format int format = map.BR.ReadInt16(); // Offset 20 in BD reflexive is (short) mipmap Count map.BR.BaseStream.Position = tempr + (x * 116) + 20; int mipmapCount = map.BR.ReadInt16(); for (int xx = 0; xx < 6; xx++) { BitmapRawDataChunk Raw = new BitmapRawDataChunk(); Raw.inchunk = x; Raw.num = xx; Raw.pointerMetaOffset = tempr + (x * 116) + 28 + (xx * 4) - map.MetaInfo.Offset[TagIndex]; Raw.rawDataType = RawDataType.bitm; map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + Raw.pointerMetaOffset; Raw.offset = map.BR.ReadInt32(); if (Raw.offset == -1) { break; } map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + Raw.pointerMetaOffset + 24; 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); #region mipmap loading section int offset = 0; int Bpp = 4; // 32 bit switch (format) { case 0: case 1: case 2: case 17: Bpp = 1; // 8 bit break; case 3: case 6: case 8: case 9: case 22: Bpp = 2; // 16 bit break; } for (int xxx = xx; xxx < mipmapCount; xxx++) { mipmapDataChunk mipmapDC = new mipmapDataChunk(); mipmapDC.width = width >> xxx; mipmapDC.height = height >> xxx; mipmapDC.depth = depth >> xxx != 0 ? depth >> xxx : 1; mipmapDC.offset = offset; mipmapDC.size = mipmapDC.width * mipmapDC.height * mipmapDC.depth * Bpp; // if (type == 2) // Cubemap, 6 sides // mipmapDC.size *= 6; switch (format) { case 14: // DXT1 mipmapDC.size /= 8; break; case 15: // DXT3 case 16: // DXT5 mipmapDC.size /= 4; break; } offset += mipmapDC.size; Raw.mipmaps.Add(mipmapDC); } #endregion 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 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(); } }
/// <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(); }
/// <summary> /// The save to xml. /// </summary> /// <param name="path">The path.</param> /// <param name="map">The map.</param> /// <remarks></remarks> public void SaveToXml(string path, Map map) { XmlTextWriter xtw = new XmlTextWriter(path, Encoding.Default); xtw.Formatting = Formatting.Indented; xtw.WriteStartElement("MapLayOut"); xtw.WriteAttributeString("Map", map.filePath); int tempindex = path.LastIndexOf("\\"); string tempfilepath = path.Substring(0, tempindex) + "\\" + path.Substring(tempindex + 1, path.Length - tempindex - 1) + " - Meta Chunks\\"; Directory.CreateDirectory(tempfilepath); map.OpenMap(MapTypes.Internal); for (int x = 0; x < chunks.Count; x++) { LayOutChunk c = (LayOutChunk)chunks[x]; // c.Read(map); FileStream FS = new FileStream( tempfilepath + "MapMetaChunk[" + x + "] - " + c.rawType + ".meta", FileMode.Create); BinaryWriter BW = new BinaryWriter(FS); // BW.Write(c.MS.ToArray()); // c.Write(BW, 0); map.BR.BaseStream.Position = c.startoffset; map.BufferReadWrite(ref map.BR, ref BW, c.size); BW.Close(); FS.Close(); xtw.WriteStartElement("LayOutChunk"); xtw.WriteAttributeString("Type", c.rawType.ToString()); xtw.WriteAttributeString("StartOffset", c.startoffset.ToString("X")); xtw.WriteAttributeString("EndOffset", c.endoffset.ToString("X")); xtw.WriteAttributeString("Size", c.size.ToString("X")); for (int xx = 0; xx < c.rawPieces.Count; xx++) { RawInfoChunk cc = (RawInfoChunk)c.rawPieces[xx]; xtw.WriteStartElement("RawDataPiece"); xtw.WriteAttributeString("Type", cc.rawType.ToString()); xtw.WriteAttributeString("Offset", cc.offset.ToString("X")); xtw.WriteAttributeString("Size", cc.size.ToString("X")); xtw.WriteAttributeString("PointerOffset", cc.offsetOfPointer.ToString("X")); xtw.WriteEndElement(); } xtw.WriteEndElement(); } xtw.WriteEndElement(); xtw.Close(); map.CloseMap(); }
/// <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); } } }
/// <summary> /// The get ugh container info. /// </summary> /// <param name="map">The map.</param> /// <remarks></remarks> public static void GetUghContainerInfo(Map map) { Meta.Meta tempughmeta = new Meta.Meta(map); map.OpenMap(MapTypes.Internal); tempughmeta.ReadMetaFromMap(map.IndexHeader.metaCount - 1, true); map.ugh = new ugh_(ref tempughmeta); map.CloseMap(); }
/// <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 h 1 spawn info. /// </summary> /// <param name="map">The map.</param> /// <remarks></remarks> public void H1SpawnInfo(Map map) { map.OpenMap(MapTypes.Internal); // collections map.BR.BaseStream.Position = map.MetaInfo.Offset[0] + 900; int tempc = map.BR.ReadInt32(); int tempr = map.BR.ReadInt32() - map.PrimaryMagic; for (int x = 0; x < tempc; x++) { //map.OpenMap(MapTypes.Internal); H1Collection vs = new H1Collection(); map.BR.BaseStream.Position = tempr + (144 * x) + 4; vs.SpawnsInMode = (H1Collection.H1CollectionTypeEnum)map.BR.ReadInt32(); map.BR.BaseStream.Position = tempr + (144 * x) + 64; vs.offset = tempr + (144 * x) + 64; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); vs.RotationDirection = Renderer.DegreeToRadian(map.BR.ReadSingle()); map.BR.BaseStream.Position = tempr + (144 * x) + 92; int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); if (tempbase == -1) { continue; } //map.CloseMap(); vs.TagPath = map.FileNames.Name[tempbase]; vs.ModelTagNumber = map.Functions.FindModelByBaseClass(tempbase); if (vs.ModelTagNumber == -1) { continue; } vs.ModelName = map.FileNames.Name[vs.ModelTagNumber]; Spawn.Add(vs); } // vehicle //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[0] + 588; int[] temppalette = new int[map.BR.ReadInt32()]; int[] temppalette2 = new int[temppalette.Length]; tempr = map.BR.ReadInt32() - map.PrimaryMagic; for (int x = 0; x < temppalette.Length; x++) { //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = tempr + (x * 48) + 12; int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); //map.CloseMap(); temppalette2[x] = tempbase; temppalette[x] = map.Functions.FindModelByBaseClass(tempbase); } //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[0] + 576; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.PrimaryMagic; for (int x = 0; x < tempc; x++) { map.BR.BaseStream.Position = tempr + (120 * x); short tempshort = map.BR.ReadInt16(); if (tempshort == -1) { continue; } map.BR.BaseStream.Position = tempr + (120 * x) + 8; VehicleSpawn vs = new VehicleSpawn(); vs.offset = tempr + (120 * x) + 8; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); vs.Yaw = Renderer.DegreeToRadian(map.BR.ReadSingle()); vs.Pitch = Renderer.DegreeToRadian(map.BR.ReadSingle()); vs.Roll = Renderer.DegreeToRadian(map.BR.ReadSingle()); vs.ModelTagNumber = temppalette[tempshort]; if (vs.ModelTagNumber == -1) { continue; } vs.TagPath = map.FileNames.Name[temppalette2[tempshort]]; vs.ModelName = map.FileNames.Name[vs.ModelTagNumber]; Spawn.Add(vs); } //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[0] + 540; temppalette = new int[map.BR.ReadInt32()]; temppalette2 = new int[temppalette.Length]; tempr = map.BR.ReadInt32() - map.PrimaryMagic; for (int x = 0; x < temppalette.Length; x++) { //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = tempr + (x * 48) + 12; int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32()); //map.CloseMap(); temppalette2[x] = tempbase; temppalette[x] = map.Functions.FindModelByBaseClass(tempbase); } //map.OpenMap(MapTypes.Internal); map.BR.BaseStream.Position = map.MetaInfo.Offset[0] + 528; tempc = map.BR.ReadInt32(); tempr = map.BR.ReadInt32() - map.PrimaryMagic; for (int x = 0; x < tempc; x++) { map.BR.BaseStream.Position = tempr + (72 * x); short tempshort = map.BR.ReadInt16(); if (tempshort == -1) { continue; } map.BR.BaseStream.Position = tempr + (72 * x) + 8; ScenerySpawn vs = new ScenerySpawn(); vs.offset = tempr + (72 * x) + 8; vs.X = map.BR.ReadSingle(); vs.Y = map.BR.ReadSingle(); vs.Z = map.BR.ReadSingle(); vs.Yaw = Renderer.DegreeToRadian(map.BR.ReadSingle()); vs.Pitch = Renderer.DegreeToRadian(map.BR.ReadSingle()); vs.Roll = Renderer.DegreeToRadian(map.BR.ReadSingle()); vs.ModelTagNumber = temppalette[tempshort]; if (vs.ModelTagNumber == -1) { continue; } vs.TagPath = map.FileNames.Name[temppalette2[tempshort]]; vs.ModelName = map.FileNames.Name[vs.ModelTagNumber]; Spawn.Add(vs); } }
/// <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 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]; } }
/// <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 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(); } }
/// <summary> /// The read chunks. /// </summary> /// <param name="map">The map.</param> /// <remarks></remarks> public void ReadChunks(Map map) { map.OpenMap(MapTypes.Internal); for (int x = 0; x < chunks.Count; x++) { LayOutChunk l = (LayOutChunk)chunks[x]; l.Read(map); GC.Collect(0); GC.WaitForPendingFinalizers(); } map.CloseMap(); }
/// <summary> /// The get meta from tag index. /// </summary> /// <param name="tag">The tag.</param> /// <param name="map">The map.</param> /// <param name="manualScan">The manual scan.</param> /// <param name="parse">The parse.</param> /// <returns></returns> /// <remarks></remarks> public static Meta GetMetaFromTagIndex(int tag, Map map, bool manualScan, bool parse) { map.OpenMap(MapTypes.Internal); Meta meta = new Meta(map); meta.TagIndex = tag; meta.ScanMetaItems(manualScan, parse); map.CloseMap(); meta.SortItemsByOffset(); return meta; }
/// <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(); }