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 Components.MapHeaderEntry("BLF Length:", "0x" + _mapInfo.Stream.Length.ToString("X8"))); paneBLFInfo.Children.Insert(1, new Components.MapHeaderEntry("BLF Chunks:", _blf.BLFChunks.Count.ToString(CultureInfo.InvariantCulture))); // Load Languages LoadLanguages(_mapInfo.MapInformation.Game); // 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.Halo4: txtGameName.Text = "Halo 4"; break; } txtMapID.Text = _mapInfo.MapInformation.MapID.ToString(CultureInfo.InvariantCulture); lblBLFNameFooter.Text = lblBLFname.Text = txtMapInternalName.Text = _mapInfo.MapInformation.InternalName; txtMapPhysicalName.Text = _mapInfo.MapInformation.PhysicalName; // Update UI _startEditing = true; cbLanguages.SelectedIndex = 0; if (Settings.startpageHideOnLaunch) Settings.homeWindow.ExternalTabClose(Windows.Home.TabGenre.StartPage); RecentFiles.AddNewEntry(new FileInfo(_blfLocation).Name, _blfLocation, "Map Info", Settings.RecentFileType.MapInfo); })); } catch (Exception ex) { Dispatcher.Invoke(new Action(delegate { MetroMessageBox.Show("Unable to open MapInfo", ex.Message); Settings.homeWindow.ExternalTabClose((LayoutDocument)Parent); })); } }
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); } }
private void DoWork(BackgroundWorker worker, IEnumerable<MetaItem> items) { var rootFolder = Path.GetDirectoryName(Application.StartupPath); var metaOutput = new MetaContent() { GeneratedTimestamp = ConvertToTimestamp(DateTime.Now), Type = "cache_meta_content" }; foreach(var item in items) { var gameEntry = new MetaContent.GameEntry { Targets = item.Targets }; var gameTarget = item.Targets.Split('|')[0]; var files = Directory.GetFiles(item.MapInfoPath, "*.mapinfo"); foreach (var file in files) { var fi = new FileInfo(file); var continueProcessing = true; foreach (var block in blfBlockList.Where(block => fi.Name.StartsWith(block))) continueProcessing = false; if (!continueProcessing) continue; var mapInfo = new MapInfo(file); var metaEntry = new MetaContent.GameEntry.MetaDataEntry { English_Name = mapInfo.MapInformation.MapNames[0], English_Desc = mapInfo.MapInformation.MapDescriptions[0], InternalName = mapInfo.MapInformation.InternalName, PhysicalName = mapInfo.MapInformation.PhysicalName, MapId = mapInfo.MapInformation.MapID }; var extraSuffix = ""; if (gameTarget.StartsWith("Halo4")) extraSuffix = "_card"; var blfFile1 = new PureBLF(string.Format("{0}\\{1}{2}.blf", item.BlfPath, mapInfo.MapInformation.PhysicalName, extraSuffix)); var blfFile = new List<byte>(blfFile1.BLFChunks[1].ChunkData); blfFile1.Close(); blfFile.RemoveRange(0, 0x08); var blfFileSmall1 = new PureBLF(string.Format("{0}\\{1}_sm.blf", item.BlfPath, mapInfo.MapInformation.PhysicalName)); var blfFileSmall = new List<byte>(blfFileSmall1.BLFChunks[1].ChunkData); blfFileSmall1.Close(); blfFileSmall.RemoveRange(0, 0x08); if (!Directory.Exists(string.Format("{0}\\{1}\\maps\\", rootFolder, gameTarget))) Directory.CreateDirectory(string.Format("{0}\\{1}\\maps\\", rootFolder, gameTarget)); File.WriteAllBytes( string.Format("{0}\\{1}\\maps\\{2}.jpg", rootFolder, gameTarget, mapInfo.MapInformation.PhysicalName), blfFile.ToArray<byte>()); File.WriteAllBytes( string.Format("{0}\\{1}\\maps\\{2}_small.jpg", rootFolder, gameTarget, mapInfo.MapInformation.PhysicalName), blfFileSmall.ToArray<byte>()); metaEntry.ImageMetaData = new MetaContent.GameEntry.MetaDataEntry.ImageMetaDataEntry { Large = string.Format("{0}/maps/{1}.jpg", gameTarget, mapInfo.MapInformation.PhysicalName), Small = string.Format("{0}/maps/{1}_small.jpg", gameTarget, mapInfo.MapInformation.PhysicalName) }; gameEntry.MetaData.Add(metaEntry); } metaOutput.Games.Add(gameEntry); } File.WriteAllText(string.Format("{0}/content.aidf", rootFolder), JsonConvert.SerializeObject(metaOutput)); }
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(); })); } }
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(); })); } }
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("X8"))); 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); lblBLFNameFooter.Text = lblBLFname.Text = 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: cbDLC.Margin = new Thickness(112, 0, 0, 0); cbForgeOnly.Visibility = System.Windows.Visibility.Visible; break; default: cbDLC.Margin = new Thickness(150, 0, 0, 0); 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(); })); } }