private void btnExtractImage_Click(object sender, RoutedEventArgs e) { try { _blf = new PureBLF(_blfLocation); var sfd = new SaveFileDialog { Title = "Save the extracted BLF Image", Filter = "JPEG Image (*.jpg)|*.jpg", FileName = lblBLFname.Text.Replace(".blf", "") }; if (!((bool)sfd.ShowDialog())) { Close(); return; } var imageToExtract = new List <byte>(_blf.BLFChunks[1].ChunkData); imageToExtract.RemoveRange(0, 0x08); File.WriteAllBytes(sfd.FileName, imageToExtract.ToArray <byte>()); MetroMessageBox.Show("Exracted!", "The BLF Image has been extracted."); Close(); } catch (Exception ex) { Close(); MetroMessageBox.Show("Extraction Failed!", "The BLF Image failed to be extracted: \n " + ex.Message); } }
private void StartupDetermineType(string path) { try { if (File.Exists(path)) { // Magic Check string magic; using (var stream = new EndianReader(File.OpenRead(path), Endian.BigEndian)) magic = stream.ReadAscii(0x04).ToLower(); switch (magic) { case "head": case "daeh": // Map File AddCacheTabModule(path); return; case "asmp": // Patch File AddPatchTabModule(path); return; case "_blf": // BLF Container, needs more checking var blf = new PureBLF(path); blf.Close(); if (blf.BLFChunks.Count > 2) { switch (blf.BLFChunks[1].ChunkMagic) { case "levl": AddInfooTabModule(path); return; case "mapi": AddImageTabModule(path); return; } } MetroMessageBox.Show("Unsupported BLF Type", "The selected BLF file is not supported in assembly."); return; default: MetroMessageBox.Show("Unsupported file type", "The selected file is not supported in assembly."); return; } } MetroMessageBox.Show("Unable to find file", "The selected file could no longer be found"); } catch (Exception ex) { MetroException.Show(ex); } }
public void LoadCampaign() { try { // Just a lazy way to validate the BLF file _blf = new PureBLF(_blfLocation); if (_blf.BLFChunks[1].ChunkMagic != "cmpn") { throw new Exception("The selected Campaign BLF is not a valid Campaign BLF file."); } _blf.Close(); _campaign = new Campaign(_blfLocation); Dispatcher.Invoke(new Action(delegate { // Add BLF Info paneBLFInfo.Children.Insert(0, new MapHeaderEntry("BLF Length:", "0x" + _campaign.Stream.Length.ToString("X"))); paneBLFInfo.Children.Insert(1, new MapHeaderEntry("BLF Chunks:", _blf.BLFChunks.Count.ToString(CultureInfo.InvariantCulture))); // Load Languages LoadLanguages(); // Load Map IDs LoadMapIDs(); // Load Unlock Bytes LoadUnlockBytes(); // Update UI _startEditing = true; cbLanguages.SelectedIndex = 0; if (App.AssemblyStorage.AssemblySettings.StartpageHideOnLaunch) { App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose(Home.TabGenre.StartPage); } RecentFiles.AddNewEntry(new FileInfo(_blfLocation).Name, _blfLocation, "Campaign", Settings.RecentFileType.Campaign); Close(); })); } catch (Exception ex) { Dispatcher.Invoke(new Action(delegate { MetroMessageBox.Show("Unable to open Campaign", ex.Message); App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose(_tab); Close(); })); } }
private void btnExtractImage_Click(object sender, RoutedEventArgs e) { try { _blf = new PureBLF(_blfLocation); var sfd = new SaveFileDialog { Title = "Save the extracted BLF Image", FileName = lblBLFname.Text.Replace(".blf", "") }; //Check if the blf image is a not JPG and set the filter accordingly switch (blfImageFormat) { case "PNG": sfd.Filter = "PNG Image (*.png)|*.png"; break; case "BMP": sfd.Filter = "BMP Image (*.bmp)|*.bmp"; break; default: sfd.Filter = "JPEG Image (*.jpg)|*.jpg"; break; } if (!((bool)sfd.ShowDialog())) { Close(); return; } var imageToExtract = new List <byte>(_blf.BLFChunks[1].ChunkData); imageToExtract.RemoveRange(0, 0x08); File.WriteAllBytes(sfd.FileName, imageToExtract.ToArray <byte>()); MetroMessageBox.Show("Exracted!", "The BLF Image has been extracted."); Close(); } catch (Exception ex) { Close(); MetroMessageBox.Show("Extraction Failed!", "The BLF Image failed to be extracted: \n " + ex.Message); } }
private void loadBLF() { try { _blf = new PureBLF(_blfLocation); var imgChunkData = new List <byte>(_blf.BLFChunks[1].ChunkData); imgChunkData.RemoveRange(0, 0x08); Dispatcher.Invoke(new Action(delegate { var image = new BitmapImage(); image.BeginInit(); image.StreamSource = new MemoryStream(imgChunkData.ToArray()); image.EndInit(); imgBLF.Source = image; // Add Image Info paneImageInfo.Children.Insert(0, new MapHeaderEntry("Image Width:", image.PixelWidth + "px")); paneImageInfo.Children.Insert(1, new MapHeaderEntry("Image Height", image.PixelHeight + "px")); // Add BLF Info paneBLFInfo.Children.Insert(0, new MapHeaderEntry("BLF Length:", "0x" + _blf.BLFStream.Length.ToString("X"))); paneBLFInfo.Children.Insert(1, new MapHeaderEntry("BLF Chunks:", _blf.BLFChunks.Count.ToString(CultureInfo.InvariantCulture))); if (App.AssemblyStorage.AssemblySettings.StartpageHideOnLaunch) { App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose(Home.TabGenre.StartPage); } RecentFiles.AddNewEntry(new FileInfo(_blfLocation).Name, _blfLocation, "BLF Image", Settings.RecentFileType.Blf); Close(); })); } catch (Exception ex) { Close(); Dispatcher.Invoke(new Action(delegate { MetroMessageBox.Show("Unable to open BLF", ex.Message.ToString(CultureInfo.InvariantCulture)); App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose((LayoutDocument)Parent); })); } }
private void loadBLF() { try { _blf = new PureBLF(_blfLocation); var imgChunkData = new List <byte>(_blf.BLFChunks[1].ChunkData); imgChunkData.RemoveRange(0, 0x08); Dispatcher.Invoke(new Action(delegate { var image = new BitmapImage(); image.BeginInit(); image.StreamSource = new MemoryStream(imgChunkData.ToArray()); image.EndInit(); imgBLF.Source = image; var stream = new EndianStream(new MemoryStream(imgChunkData.ToArray <byte>()), Endian.BigEndian); stream.SeekTo(0x0); ushort imageMagic = stream.ReadUInt16(); switch (imageMagic) { case 0xFFD8: blfImageFormat = "JPEG"; break; case 0x8950: blfImageFormat = "PNG"; break; case 0x424D: blfImageFormat = "BMP"; break; default: blfImageFormat = "Unknown"; break; } // Add Image Info paneImageInfo.Children.Insert(0, new MapHeaderEntry("Image Format:", blfImageFormat)); paneImageInfo.Children.Insert(1, new MapHeaderEntry("Image Width:", image.PixelWidth + "px")); paneImageInfo.Children.Insert(2, new MapHeaderEntry("Image Height", image.PixelHeight + "px")); // Add BLF Info paneBLFInfo.Children.Insert(0, new MapHeaderEntry("BLF Length:", "0x" + _blf.BLFStream.Length.ToString("X"))); paneBLFInfo.Children.Insert(1, new MapHeaderEntry("BLF Chunks:", _blf.BLFChunks.Count.ToString(CultureInfo.InvariantCulture))); if (App.AssemblyStorage.AssemblySettings.StartpageHideOnLaunch) { App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose(Home.TabGenre.StartPage); } RecentFiles.AddNewEntry(new FileInfo(_blfLocation).Name, _blfLocation, "BLF Image", Settings.RecentFileType.Blf); Close(); })); } catch (Exception ex) { Close(); Dispatcher.Invoke(new Action(delegate { MetroMessageBox.Show("Unable to open BLF", ex.Message.ToString(CultureInfo.InvariantCulture)); App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose((LayoutDocument)Parent); })); } }
private void btnInjectImage_Click(object sender, RoutedEventArgs e) { try { _blf = new PureBLF(_blfLocation); var ofd = new OpenFileDialog { Title = "Open an image to be injected", Filter = "JPEG Image (*.jpg,*.jpeg,)|*.jpg;*.jpeg|PNG Image [H3/ODST]|*.png|BMP Image [H3/ODST]|*.bmp" }; if (!((bool)ofd.ShowDialog())) { Close(); return; } byte[] newImage = File.ReadAllBytes(ofd.FileName); var stream = new EndianStream(new MemoryStream(newImage), Endian.BigEndian); // Check if it's a supported image stream.SeekTo(0x0); ushort imageMagic = stream.ReadUInt16(); if (imageMagic != 0xFFD8 && imageMagic != 0x8950 && imageMagic != 0x424D) { throw new Exception("Invalid image type. Only JPEG, PNG, and BMP are supported."); } // Check for size and dimension differences var imageSize = new FileInfo(ofd.FileName).Length; var image = new BitmapImage(); image.BeginInit(); image.StreamSource = new MemoryStream(newImage); image.EndInit(); string sizeMessage = ""; string dimensionMessage = ""; if (new FileInfo(ofd.FileName).Length >= 0x1C000) { sizeMessage = String.Format("- The size of the new image (0x{0}) exceeds Halo 3/ODST's modified limit of 0x1C000. This image will not display in those games as a result. Can be ignored otherwise.\n", imageSize.ToString("X")); } if (image.PixelWidth != ((BitmapImage)imgBLF.Source).PixelWidth || image.PixelHeight != ((BitmapImage)imgBLF.Source).PixelHeight) { dimensionMessage = String.Format("- The dimensions of the new image ({0}x{1}) are not the same as the dimensions of the original image ({2}x{3}). This blf may appear stretched or not appear at all as a result.\n", image.PixelWidth, image.PixelHeight, ((BitmapImage)imgBLF.Source).PixelWidth, ((BitmapImage)imgBLF.Source).PixelHeight); } if (dimensionMessage != "" || sizeMessage != "") { if (MetroMessageBox.Show("Warning", "There were some potential issue(s) found with your new image;\n\n" + String.Format("{0}{1}", sizeMessage, dimensionMessage) + "\nInject anyway?", MetroMessageBox.MessageBoxButtons.OkCancel) != MetroMessageBox.MessageBoxResult.OK) { Close(); return; } } // It's the right everything! Let's inject var newImageChunkData = new List <byte>(); newImageChunkData.AddRange(new byte[] { 0x00, 0x00, 0x00, 0x00 }); byte[] imageLength = BitConverter.GetBytes(newImage.Length); Array.Reverse(imageLength); newImageChunkData.AddRange(imageLength); newImageChunkData.AddRange(newImage); // Write data to chunk file _blf.BLFChunks[1].ChunkData = newImageChunkData.ToArray <byte>(); _blf.RefreshRelativeChunkData(); _blf.UpdateChunkTable(); // Update eof offset value var eofstream = new EndianStream(new MemoryStream(_blf.BLFChunks[2].ChunkData), Endian.BigEndian); uint eofFixup = (uint)_blf.BLFStream.Length - 0x111; //real cheap but hey it works and is always the same in all games eofstream.SeekTo(0); eofstream.WriteUInt32(eofFixup); _blf.RefreshRelativeChunkData(); _blf.UpdateChunkTable(); Close(); MetroMessageBox.Show("Injected!", "The BLF Image has been injected. This image tab will now close."); App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose(_tab); } catch (Exception ex) { Close(); MetroMessageBox.Show("Inject Failed!", "The BLF Image failed to be injected: \n " + ex.Message); } }
public void LoadMapInfo() { try { // Just a lazy way to validate the BLF file _blf = new PureBLF(_blfLocation); if (_blf.BLFChunks[1].ChunkMagic != "levl") { throw new Exception("The selected Map Info BLF is not a valid Map Info BLF file."); } _blf.Close(); _mapInfo = new MapInfo(_blfLocation, App.AssemblyStorage.AssemblySettings.DefaultMapInfoDatabase); Dispatcher.Invoke(new Action(delegate { // Add BLF Info paneBLFInfo.Children.Insert(0, new MapHeaderEntry("MapInfo Version:", _mapInfo.Engine.Version.ToString(CultureInfo.InvariantCulture))); paneBLFInfo.Children.Insert(1, new MapHeaderEntry("BLF Length:", "0x" + _mapInfo.Stream.Length.ToString("X"))); paneBLFInfo.Children.Insert(2, new MapHeaderEntry("BLF Chunks:", _blf.BLFChunks.Count.ToString(CultureInfo.InvariantCulture))); // Hide unused elements if (_mapInfo.Engine.MaxTeamCollection == null) { tiMaxTeams.Visibility = Visibility.Collapsed; } if (_mapInfo.Engine.MultiplayerObjectCollection == null) { tiMPObjects.Visibility = Visibility.Collapsed; } if (!_mapInfo.Engine.UsesDefaultAuthor) { lblDefaultAuthor.Visibility = Visibility.Collapsed; txtDefaultAuthor.Visibility = Visibility.Collapsed; } // Load Languages LoadLanguages(); // Load Map Info txtGameName.Text = _mapInfo.Engine.Name; txtMapID.Text = _mapInfo.MapInformation.MapID.ToString(CultureInfo.InvariantCulture); txtMapInternalName.Text = _mapInfo.MapInformation.InternalName; txtMapPhysicalName.Text = _mapInfo.MapInformation.PhysicalName; // Load Default Author & change margin if necessary txtDefaultAuthor.Text = _mapInfo.MapInformation.DefaultAuthor; if (_mapInfo.Engine.UsesDefaultAuthor && _mapInfo.Engine.Version <= 8) { lblDefaultAuthor.Margin = new Thickness(0, 37, 0, 3); } // Set up the Type combo box // TODO: Add flags to formats? cbType_Cine.Visibility = cbType_FF.Visibility = _mapInfo.Engine.Version < 5 ? Visibility.Collapsed : Visibility.Visible; cbType_Cine.IsEnabled = cbType_FF.IsEnabled = _mapInfo.Engine.Version >= 5; cbType_FF.Content = _mapInfo.Engine.Version < 8 ? "Firefight" : "Spartan Ops"; if (_mapInfo.MapInformation.Flags.HasFlag(LevelFlags.IsMainMenu)) { cbType.SelectedIndex = 0; } if (_mapInfo.MapInformation.Flags.HasFlag(LevelFlags.IsMultiplayer)) { cbType.SelectedIndex = 1; } if (_mapInfo.MapInformation.Flags.HasFlag(LevelFlags.IsCampaign)) { cbType.SelectedIndex = 2; } if (_mapInfo.MapInformation.Flags.HasFlag(LevelFlags.IsCinematic)) { cbType.SelectedIndex = 3; } if (_mapInfo.MapInformation.Flags.HasFlag(LevelFlags.IsFirefight)) { cbType.SelectedIndex = 4; } // Set up the Checkboxes cbForgeOnly.Visibility = _mapInfo.Engine.Version < 9 ? Visibility.Collapsed : Visibility.Visible; cbVisible.IsChecked = _mapInfo.MapInformation.Flags.HasFlag(LevelFlags.Visible); cbGeneratesFilm.IsChecked = _mapInfo.MapInformation.Flags.HasFlag(LevelFlags.GeneratesFilm); cbDLC.IsChecked = _mapInfo.MapInformation.Flags.HasFlag(LevelFlags.IsDLC); cbForgeOnly.IsChecked = _mapInfo.MapInformation.Flags.HasFlag(LevelFlags.IsForgeOnly); // Load Max Teams if (_mapInfo.Engine.MaxTeamCollection != null) { LoadMaxTeams(); } // Load MP Objects if (_mapInfo.Engine.MultiplayerObjectCollection != null) { LoadMultiplayerObjects(); } // Load Insertion Points LoadInsertionPoints(); // Update UI _startEditing = true; cbLanguages.SelectedIndex = 0; cbInsertIndex.SelectedIndex = 0; cbInsertLanguages.SelectedIndex = 0; if (App.AssemblyStorage.AssemblySettings.StartpageHideOnLaunch) { App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose(Home.TabGenre.StartPage); } RecentFiles.AddNewEntry(new FileInfo(_blfLocation).Name, _blfLocation, "Map Info", Settings.RecentFileType.MapInfo); Close(); })); } catch (Exception ex) { Dispatcher.Invoke(new Action(delegate { MetroMessageBox.Show("Unable to open MapInfo", ex.Message); App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose(_tab); Close(); })); } }
private void btnInjectImage_Click(object sender, RoutedEventArgs e) { try { _blf = new PureBLF(_blfLocation); var ofd = new OpenFileDialog { Title = "Opem an image to be injected", Filter = "JPEG Image (*.jpg)|*.jpg|JPEG Image (*.jpeg)|*.jpeg" }; if (!((bool)ofd.ShowDialog())) { Close(); return; } byte[] newImage = File.ReadAllBytes(ofd.FileName); var stream = new EndianStream(new MemoryStream(newImage), Endian.BigEndian); // To-do: Allow PNGs // Check if it's a JIFI stream.SeekTo(0x0); ushort imageMagic = stream.ReadUInt16(); if (imageMagic != 0xFFD8) { throw new Exception("Invalid image type, it has to be a JPEG (JFIF in the header)."); } // Check if it's the right size var image = new BitmapImage(); image.BeginInit(); image.StreamSource = new MemoryStream(newImage); image.EndInit(); if (image.PixelWidth != ((BitmapImage)imgBLF.Source).PixelWidth || image.PixelHeight != ((BitmapImage)imgBLF.Source).PixelHeight) { throw new Exception(string.Format("Image isn't the right size. It must be {0}x{1}", ((BitmapImage)imgBLF.Source).PixelWidth, ((BitmapImage)imgBLF.Source).PixelHeight)); } // It's the right everything! Let's inject var newImageChunkData = new List <byte>(); newImageChunkData.AddRange(new byte[] { 0x00, 0x00, 0x00, 0x00 }); byte[] imageLength = BitConverter.GetBytes(newImage.Length); Array.Reverse(imageLength); newImageChunkData.AddRange(imageLength); newImageChunkData.AddRange(newImage); // Write data to chunk file _blf.BLFChunks[1].ChunkData = newImageChunkData.ToArray <byte>(); _blf.RefreshRelativeChunkData(); _blf.UpdateChunkTable(); imgBLF.Source = image; MetroMessageBox.Show("Injected!", "The BLF Image has been injected."); Close(); } catch (Exception ex) { Close(); MetroMessageBox.Show("Inject Failed!", "The BLF Image failed to be injected: \n " + ex.Message); } }
public void LoadMapInfo() { try { // Just a lazy way to validate the BLF file _blf = new PureBLF(_blfLocation); if (_blf.BLFChunks[1].ChunkMagic != "levl") { throw new Exception("The selected Map Info BLF is not a valid Map Info BLF file."); } _blf.Close(); _mapInfo = new MapInfo(_blfLocation); Dispatcher.Invoke(new Action(delegate { // Add BLF Info paneBLFInfo.Children.Insert(0, new MapHeaderEntry("BLF Length:", "0x" + _mapInfo.Stream.Length.ToString("X"))); paneBLFInfo.Children.Insert(1, new MapHeaderEntry("BLF Chunks:", _blf.BLFChunks.Count.ToString(CultureInfo.InvariantCulture))); // Load Languages LoadLanguages(); // Add Map Info switch (_mapInfo.MapInformation.Game) { case MapInfo.GameIdentifier.Halo3: txtGameName.Text = "Halo 3"; break; case MapInfo.GameIdentifier.Halo3ODST: txtGameName.Text = "Halo 3: ODST"; break; case MapInfo.GameIdentifier.HaloReach: txtGameName.Text = "Halo Reach"; break; case MapInfo.GameIdentifier.HaloReachBetas: txtGameName.Text = "Halo Reach Pre/Beta"; break; case MapInfo.GameIdentifier.Halo4: txtGameName.Text = "Halo 4"; break; } txtMapID.Text = _mapInfo.MapInformation.MapID.ToString(CultureInfo.InvariantCulture); txtMapInternalName.Text = _mapInfo.MapInformation.InternalName; txtMapPhysicalName.Text = _mapInfo.MapInformation.PhysicalName; // Set up the Type combo box switch (_mapInfo.MapInformation.Game) { case MapInfo.GameIdentifier.Halo3: case MapInfo.GameIdentifier.Halo3ODST: cbType_Cine.Visibility = System.Windows.Visibility.Collapsed; cbType_Cine.IsEnabled = false; cbType_FF.Visibility = System.Windows.Visibility.Collapsed; cbType_FF.IsEnabled = false; break; case MapInfo.GameIdentifier.HaloReach: case MapInfo.GameIdentifier.HaloReachBetas: cbType_Cine.Visibility = System.Windows.Visibility.Visible; cbType_Cine.IsEnabled = true; cbType_FF.Visibility = System.Windows.Visibility.Visible; cbType_FF.IsEnabled = true; cbType_FF.Content = "Firefight"; break; case MapInfo.GameIdentifier.Halo4: cbType_Cine.Visibility = System.Windows.Visibility.Visible; cbType_Cine.IsEnabled = true; cbType_FF.Visibility = System.Windows.Visibility.Visible; cbType_FF.IsEnabled = true; cbType_FF.Content = "Spartan Ops"; break; } if (_mapInfo.MapInformation.Flags.HasFlag(LevelFlags.IsMainMenu)) { cbType.SelectedIndex = 0; } if (_mapInfo.MapInformation.Flags.HasFlag(LevelFlags.IsMultiplayer)) { cbType.SelectedIndex = 1; } if (_mapInfo.MapInformation.Flags.HasFlag(LevelFlags.IsCampaign)) { cbType.SelectedIndex = 2; } if (_mapInfo.MapInformation.Flags.HasFlag(LevelFlags.IsCinematic)) { cbType.SelectedIndex = 3; } if (_mapInfo.MapInformation.Flags.HasFlag(LevelFlags.IsFirefight)) { cbType.SelectedIndex = 4; } // Set up the Checkboxes switch (_mapInfo.MapInformation.Game) { case MapInfo.GameIdentifier.Halo4: cbForgeOnly.Visibility = System.Windows.Visibility.Visible; break; default: cbForgeOnly.Visibility = System.Windows.Visibility.Collapsed; break; } if (_mapInfo.MapInformation.Flags.HasFlag(LevelFlags.Visible)) { cbVisible.IsChecked = true; } if (_mapInfo.MapInformation.Flags.HasFlag(LevelFlags.GeneratesFilm)) { cbGeneratesFilm.IsChecked = true; } if (_mapInfo.MapInformation.Flags.HasFlag(LevelFlags.IsDLC)) { cbDLC.IsChecked = true; } if (_mapInfo.MapInformation.Flags.HasFlag(LevelFlags.IsForgeOnly)) { cbForgeOnly.IsChecked = true; } // Update UI _startEditing = true; cbLanguages.SelectedIndex = 0; if (App.AssemblyStorage.AssemblySettings.StartpageHideOnLaunch) { App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose(Home.TabGenre.StartPage); } RecentFiles.AddNewEntry(new FileInfo(_blfLocation).Name, _blfLocation, "Map Info", Settings.RecentFileType.MapInfo); Close(); })); } catch (Exception ex) { Dispatcher.Invoke(new Action(delegate { MetroMessageBox.Show("Unable to open MapInfo", ex.Message); App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose(_tab); Close(); })); } }