public string GetMapIconTable() { StringBuilder s = new StringBuilder(); var table = "| {0,-3} | {1,-10} | {2,-20} |"; s.AppendLine(String.Format(table, "On", "Icon", "Description")); var tableDashLine = String.Format(table, GetDashLine(3), GetDashLine(10), GetDashLine(20)); s.AppendLine(tableDashLine); var vanilla = false; foreach (var row in VanillaDatabase.getMapIconTable().Rows) { var dataRow = (DataRow)row; var mapIcon = dataRow.Field <string>("Map Icon"); var desc = dataRow.Field <string>("Description"); var on = " "; if (md.MapIcon == mapIcon) { vanilla = true; on = ":o:"; } s.AppendLine(String.Format(table, on, mapIcon, desc)); } if (!vanilla) { s.AppendLine(String.Format(table, ":o:", md.MapIcon, "")); } RemoveTrailingLineEnding(s); return(s.ToString()); }
public string GetVentureCardTable() { StringBuilder s = new StringBuilder(); var table = "| {0,3} | {1,3} | {2,-112} |"; s.AppendLine(String.Format(table, "ID", "On", "Description")); var tableDashLine = String.Format(table, GetDashLine(3), GetDashLine(3), GetDashLine(112)); s.AppendLine(tableDashLine); foreach (var row in VanillaDatabase.getVentureCardTable().Rows) { var dataRow = (DataRow)row; var ventureCardId = dataRow.Field <byte>("Id"); var desc = dataRow.Field <string>("Description"); var on = " "; if (md.VentureCard[ventureCardId - 1] != 0) { on = ":o:"; } s.AppendLine(String.Format(table, ventureCardId, on, desc)); } RemoveTrailingLineEnding(s); return(s.ToString()); }
public static Optional <string> getVanillaTpl(string mapIcon) { try { var result = from row in VanillaDatabase.getMapTable().AsEnumerable() where row.Field <string>("Map Icon") == mapIcon select row.Field <string>("Map Tpl"); if (result.Any() && result.Distinct().Single() != null) { return(Optional <string> .Create(result.Distinct().Single())); } } catch (IndexOutOfRangeException e) { } return(Optional <string> .CreateEmpty()); }
public static Optional <UInt32> getBgmIdFromVanillaBackground(string background) { try { var result = from row in VanillaDatabase.getMapTable().AsEnumerable() where row.Field <string>("Background") == background select row.Field <UInt32>("Bgm Id"); if (result.Any()) { return(Optional <UInt32> .Create(result.Distinct().Single())); } } catch (IndexOutOfRangeException e) { } return(Optional <UInt32> .CreateEmpty()); }
public static sbyte getVanillaOrder(int mapId) { try { var result = from row in VanillaDatabase.getMapSetZoneOrdering().AsEnumerable() where row.Field <int>("Map Id") == mapId select row.Field <sbyte>("Order"); if (result.Any()) { return(result.Distinct().Single()); } } catch (IndexOutOfRangeException e) { } return(-1); }
private void setVanillaMapSetZoneOrder(List <MapDescriptor> mapDescriptors) { for (int i = 0; i < mapDescriptors.Count; i++) { var mapDescriptor = mapDescriptors[i]; mapDescriptor.MapSet = VanillaDatabase.getVanillaMapSet(i); mapDescriptor.Zone = VanillaDatabase.getVanillaZone(i); if (mapDescriptor.Zone == 0) { mapDescriptor.Zone = 1; } else if (mapDescriptor.Zone == 1) { mapDescriptor.Zone = 0; } mapDescriptor.Order = VanillaDatabase.getVanillaOrder(i); } }
public string GetBackgroundMusicTable() { StringBuilder s = new StringBuilder(); var table = "| {0,3} | {1,3} | {2,5} | {3,-24} | {4,-20} |"; s.AppendLine(String.Format(table, "On", "BGM", "Brsar", "Filename", "Description")); var tableDashLine = String.Format(table, GetDashLine(3), GetDashLine(3), GetDashLine(5), GetDashLine(24), GetDashLine(20)); s.AppendLine(tableDashLine); var vanilla = false; foreach (var row in VanillaDatabase.getBgmTable().Rows) { var dataRow = (DataRow)row; var bgmId = dataRow.Field <uint>("Bgm Id"); var brsarMario = dataRow.Field <uint>("Brsar Mario"); var brsarDQ = dataRow.Field <uint>("Brsar DragonQuest"); string brsar = brsarMario + ""; if (brsarDQ != brsarMario) { brsar += "/" + brsarDQ; } var filename = dataRow.Field <string>("Filename"); var desc = dataRow.Field <string>("Description"); var on = " "; if (md.BGMID == bgmId) { vanilla = true; on = ":o:"; } s.AppendLine(String.Format(table, on, bgmId, brsar, filename, desc)); } if (!vanilla) { // TODO read out brsar table and filename s.AppendLine(String.Format(table, ":o:", md.BGMID, "", "", "", "")); } RemoveTrailingLineEnding(s); return(s.ToString()); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); dataGridViewCellStyle1.BackColor = System.Drawing.Color.Lavender; System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); dataGridViewCellStyle2.BackColor = System.Drawing.Color.White; this.cancelButton = new System.Windows.Forms.Button(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.ventureCardId = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ventureCardEnabled = new System.Windows.Forms.DataGridViewCheckBoxColumn(); this.ventureCardDesc = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.SuspendLayout(); // // cancelButton // this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.cancelButton.Dock = System.Windows.Forms.DockStyle.Bottom; this.cancelButton.Location = new System.Drawing.Point(0, 365); this.cancelButton.Margin = new System.Windows.Forms.Padding(1); this.cancelButton.Name = "cancelButton"; this.cancelButton.Size = new System.Drawing.Size(820, 37); this.cancelButton.TabIndex = 1; this.cancelButton.Text = "Close"; this.cancelButton.UseVisualStyleBackColor = true; this.cancelButton.Click += CancelButton_Click; // // venturecard id // this.ventureCardId.HeaderText = "ID"; this.ventureCardId.Name = "ID"; this.ventureCardId.ReadOnly = true; this.ventureCardId.DataPropertyName = "Id"; // // venturecard enabled // this.ventureCardEnabled.HeaderText = "Enabled"; this.ventureCardEnabled.Name = "Enabled"; this.ventureCardEnabled.ReadOnly = true; // // venturecard description // this.ventureCardDesc.HeaderText = "Description"; this.ventureCardDesc.Name = "Description"; this.ventureCardDesc.ReadOnly = true; this.ventureCardDesc.DataPropertyName = "Description"; // // dataGridView1 // this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; this.dataGridView1.Location = new System.Drawing.Point(0, 0); this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.ReadOnly = true; this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader; this.dataGridView1.AllowUserToResizeColumns = false; this.dataGridView1.AllowUserToResizeRows = false; this.dataGridView1.AllowUserToAddRows = false; this.dataGridView1.AllowUserToDeleteRows = false; this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; this.dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; this.dataGridView1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1; this.dataGridView1.RowsDefaultCellStyle = dataGridViewCellStyle2; this.dataGridView1.AutoGenerateColumns = false; var SBind = new BindingSource(); SBind.DataSource = VanillaDatabase.getVentureCardTable(); this.dataGridView1.DataSource = SBind; this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.ventureCardId, this.ventureCardEnabled, this.ventureCardDesc }); // // VentureCardBox // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.cancelButton; this.ClientSize = new System.Drawing.Size(800, 900); this.Controls.Add(this.dataGridView1); this.Controls.Add(this.cancelButton); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; this.Margin = new System.Windows.Forms.Padding(1); this.MaximizeBox = false; this.Name = "VentureCardBox"; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Activated Venture Cards"; this.Shown += VentureCardBox_Shown; this.ResumeLayout(false); }
private static async Task <bool> InjectMapIcons(List <MapDescriptor> mapDescriptors, DataFileSet cacheFileSet, DataFileSet tmpFileSet, DataFileSet riivFileSet, IProgress <ProgressInfo> progress, CancellationToken ct) { // first check if we need to inject any map icons in the first place. We do not need to if only vanilla map icons are used. bool allMapIconsVanilla = true; foreach (var mapDescriptor in mapDescriptors) { var mapIcon = mapDescriptor.MapIcon; if (string.IsNullOrEmpty(mapIcon)) { continue; } if (!VanillaDatabase.getVanillaTpl(mapIcon).Any()) { allMapIconsVanilla = false; break; } } if (allMapIconsVanilla) { return(true); } progress.Report("Extract game_sequence files..."); // setup the directories for the game sequence files /** maps the path of the various variants of the game_sequenceXXXXXXXX.arc files to their respective extraction path in the tmp directory */ var gameSequenceExtractPaths = new Dictionary <string, string>(); /** maps the path of the various variants of the game_sequenceXXXXXXXX.arc files to their respective temporary path for the converted xmlyt base path */ var gameSequenceToXmlytBasePaths = new Dictionary <string, string>(); /** maps the path of the various variants of the game_sequenceXXXXXXXX.arc files to their target path where they will be packed again */ var gameSequencePackPaths = new Dictionary <string, string>(); foreach (var entry in cacheFileSet.game_sequence_arc) { var locale = entry.Key; var gameSequencePath = entry.Value; var extractPath = Path.Combine(tmpFileSet.rootDir, Path.GetFileNameWithoutExtension(gameSequencePath)); Directory.CreateDirectory(Path.GetDirectoryName(extractPath)); gameSequenceExtractPaths.Add(gameSequencePath, extractPath); var xmlytPath = Path.Combine(tmpFileSet.rootDir, Path.GetFileNameWithoutExtension(gameSequencePath) + "."); Directory.CreateDirectory(Path.GetDirectoryName(xmlytPath)); gameSequenceToXmlytBasePaths.Add(gameSequencePath, xmlytPath); var packPath = riivFileSet.game_sequence_arc[locale]; Directory.CreateDirectory(Path.GetDirectoryName(packPath)); gameSequencePackPaths.Add(gameSequencePath, packPath); } foreach (var entry in cacheFileSet.game_sequence_wifi_arc) { var locale = entry.Key; var gameSequencePath = entry.Value; var extractPath = Path.Combine(tmpFileSet.rootDir, Path.GetFileNameWithoutExtension(gameSequencePath)); Directory.CreateDirectory(Path.GetDirectoryName(extractPath)); gameSequenceExtractPaths.Add(gameSequencePath, extractPath); var xmlytPath = Path.Combine(tmpFileSet.rootDir, Path.GetFileNameWithoutExtension(gameSequencePath) + "."); Directory.CreateDirectory(Path.GetDirectoryName(xmlytPath)); gameSequenceToXmlytBasePaths.Add(gameSequencePath, xmlytPath); var packPath = riivFileSet.game_sequence_wifi_arc[locale]; Directory.CreateDirectory(Path.GetDirectoryName(packPath)); gameSequencePackPaths.Add(gameSequencePath, packPath); } using (CancellationTokenSource source = new CancellationTokenSource()) { // start fake progress var fakeProgressTask = ProgressInfo.makeFakeProgress(ProgressInfo.makeSubProgress(progress, 2, 33), source.Token); // extract the arc files List <Task <string> > extractArcFileTasks = new List <Task <string> >(); foreach (var entry in gameSequenceExtractPaths) { string gameSequencePath = entry.Key; string gameSequenceExtractPath = entry.Value; extractArcFileTasks.Add(ExeWrapper.extractArcFile(gameSequencePath, gameSequenceExtractPath, ct, ProgressInfo.makeNoProgress(progress))); } await Task.WhenAll(extractArcFileTasks).ConfigureAwait(false); source.Cancel(); await fakeProgressTask.ConfigureAwait(false); } progress.Report("Convert map icons and inject them..."); using (CancellationTokenSource source = new CancellationTokenSource()) { // start fake progress var fakeProgressTask = ProgressInfo.makeFakeProgress(ProgressInfo.makeSubProgress(progress, 33, 66), source.Token); // convert the png files to tpl and copy them to the correct location Dictionary <string, string> mapIconToTplName = new Dictionary <string, string>(); List <Task> convertPngFileTasks = new List <Task>(); foreach (var mapDescriptor in mapDescriptors) { var mapIcon = mapDescriptor.MapIcon; if (string.IsNullOrEmpty(mapIcon)) { continue; } if (VanillaDatabase.getVanillaTpl(mapIcon).Any()) { // its a vanilla map icon -> dont convert and inject it VanillaDatabase.getVanillaTpl(mapIcon).IfPresent(value => mapIconToTplName[mapIcon] = value); } else { var mapIconPng = Path.Combine(tmpFileSet.param_folder, mapIcon + ".png"); var mapIconTpl = Path.ChangeExtension(mapIconPng, ".tpl"); var tplName = Ui_menu_19_00a.constructMapIconTplName(mapIcon); if (!mapIconToTplName.ContainsKey(mapIcon)) { mapIconToTplName.Add(mapIcon, tplName); } if (File.Exists(mapIconPng)) { Task task1 = ExeWrapper.convertPngToTpl(mapIconPng, mapIconTpl, ct, ProgressInfo.makeNoProgress(progress)); Task task2 = task1.ContinueWith(async(t1) => { await t1.ConfigureAwait(false); foreach (var entry in gameSequenceExtractPaths) { string gameSequencePath = entry.Key; string gameSequenceExtractPath = entry.Value; var mapIconTplCopy = Path.Combine(gameSequenceExtractPath, "arc", "timg", tplName); File.Copy(mapIconTpl, mapIconTplCopy, true); } }); convertPngFileTasks.Add(task2); } } } // convert the brlyt files to xmlyt, inject the map icons and convert it back List <Task> injectMapIconsInBrlytTasks = new List <Task>(); foreach (var entry in gameSequenceExtractPaths) { string gameSequencePath = entry.Key; string gameSequenceExtractPath = entry.Value; var brlytFile = Path.Combine(gameSequenceExtractPath, "arc", "blyt", "ui_menu_19_00a.brlyt"); string xmlytFile = gameSequenceToXmlytBasePaths[gameSequencePath] + Path.GetFileNameWithoutExtension(brlytFile) + ".xmlyt"; Task task1 = ExeWrapper.convertBryltToXmlyt(brlytFile, xmlytFile, ct, ProgressInfo.makeNoProgress(progress)); Task task2 = task1.ContinueWith(async(t1) => { await t1.ConfigureAwait(false); Ui_menu_19_00a.injectMapIconsLayout(xmlytFile, mapIconToTplName); }); Task task3 = task2.ContinueWith(async(t2) => { await t2.ConfigureAwait(false); await ExeWrapper.convertXmlytToBrylt(xmlytFile, brlytFile, ct, ProgressInfo.makeNoProgress(progress)); }); Task task4 = task3.ContinueWith(async(t3) => { await t3; // strange phenomenon: when converting the xmlyt files back to brlyt using benzin, sometimes the first byte is not correctly written. This fixes it as the first byte must be an 'R'. await Task.Delay(500); using (var stream = File.OpenWrite(brlytFile)) { stream.Seek(0, SeekOrigin.Begin); stream.WriteByte((byte)'R'); } // wait till the handle has been disposed properly await Task.Delay(500); }); injectMapIconsInBrlytTasks.Add(task4); } // convert the brlan files to xmlan, inject the map icons and convert it back List <Task> injectMapIconsInBrlanTasks = new List <Task>(); foreach (var entry in gameSequenceExtractPaths) { string gameSequencePath = entry.Key; string gameSequenceExtractPath = entry.Value; foreach (var brlanFile in Directory.GetFiles(Path.Combine(gameSequenceExtractPath, "arc", "anim"), "ui_menu_19_00a_Tag_*.brlan")) { string xmlanFile = gameSequenceToXmlytBasePaths[gameSequencePath] + Path.GetFileNameWithoutExtension(brlanFile) + ".xmlan"; Task task1 = ExeWrapper.convertBryltToXmlyt(brlanFile, xmlanFile, ct, ProgressInfo.makeNoProgress(progress)); Task task2 = task1.ContinueWith(async(t1) => { await t1.ConfigureAwait(false); Ui_menu_19_00a.injectMapIconsAnimation(xmlanFile, mapIconToTplName); }); Task task3 = task2.ContinueWith(async(t2) => { await t2.ConfigureAwait(false); await ExeWrapper.convertXmlytToBrylt(xmlanFile, brlanFile, ct, ProgressInfo.makeNoProgress(progress)); }); Task task4 = task3.ContinueWith(async(t3) => { await t3; // strange phenomenon: when converting the xmlyt files back to brlyt using benzin, sometimes the first byte is not correctly written. This fixes it as the first byte must be an 'R'. await Task.Delay(500); using (var stream = File.OpenWrite(brlanFile)) { stream.Seek(0, SeekOrigin.Begin); stream.WriteByte((byte)'R'); } // wait till the handle has been disposed properly await Task.Delay(500); }); injectMapIconsInBrlanTasks.Add(task4); } } await Task.WhenAll(injectMapIconsInBrlytTasks).ConfigureAwait(false); await Task.WhenAll(injectMapIconsInBrlanTasks).ConfigureAwait(false); await Task.WhenAll(convertPngFileTasks).ConfigureAwait(false); source.Cancel(); await fakeProgressTask.ConfigureAwait(false); } await Task.Delay(1000); progress.Report("Pack game_sequence files..."); using (CancellationTokenSource source = new CancellationTokenSource()) { // start fake progress var fakeProgressTask = ProgressInfo.makeFakeProgress(ProgressInfo.makeSubProgress(progress, 66, 100), source.Token); // pack the arc files List <Task <string> > packArcFileTasks = new List <Task <string> >(); foreach (var entry in gameSequenceExtractPaths) { string gameSequencePath = entry.Key; string gameSequenceExtractPath = entry.Value; string gameSequencePackPath = gameSequencePackPaths[gameSequencePath]; packArcFileTasks.Add(ExeWrapper.packDfolderToArc(gameSequenceExtractPath, gameSequencePackPath, ct, ProgressInfo.makeNoProgress(progress))); } await Task.WhenAll(packArcFileTasks).ConfigureAwait(false); source.Cancel(); await fakeProgressTask.ConfigureAwait(false); } await Task.Delay(1000); progress.Report(100); return(true); }
public static MapDescriptor ImportMd(string mapDescriptorImportFile, IProgress <ProgressInfo> progress, CancellationToken ct, string riivPath = null, string tmpPath = null) { var riivFileSet = new DataFileSet(GetDefaultRiivPath(riivPath)); var tmpFileSet = new DataFileSet(GetDefaultTmpPath(tmpPath)); MapDescriptor mapDescriptorImport = new MapDescriptor(); progress.Report(new ProgressInfo(0, "Parse Map Descriptor File...")); var dir = Path.GetDirectoryName(mapDescriptorImportFile); var internalName = Path.GetFileNameWithoutExtension(mapDescriptorImportFile); if (internalName.ToLower() == "readme") { internalName = Path.GetFileName(dir); } mapDescriptorImport.readMapDescriptorFromFile(mapDescriptorImportFile, internalName); progress.Report(new ProgressInfo(20, "Imported " + mapDescriptorImportFile)); var usedSquareTypes = mapDescriptorImport.readFrbFileInfo(dir, ProgressInfo.makeSubProgress(progress, 20, 60), ct); if (mapDescriptorImport.VentureCardActiveCount == 0) { progress.Report("The map " + internalName + " does not have a venture card table specified. A default venture card table will be used."); mapDescriptorImport.VentureCard = VanillaDatabase.getDefaultVentureCardTable(mapDescriptorImport.RuleSet, usedSquareTypes); } else if (mapDescriptorImport.VentureCardActiveCount < 64) { progress.Report("Warning: The map " + internalName + " has a venture card count smaller than 64. The behavior is undefined and glitchy."); } else if (mapDescriptorImport.VentureCardActiveCount > 64) { progress.Report("Warning: The map " + internalName + " has a venture card count larger than 64. Only the first 64 venture cards will be used."); } int problematicVentureCard = VanillaDatabase.hasProblemWithVentureCardMissingNeededSquareType(mapDescriptorImport.VentureCard, usedSquareTypes); if (problematicVentureCard != -1) { progress.Report("The map " + internalName + " uses venture card " + problematicVentureCard + ". This venture card needs certain square types which have not been placed on the map."); mapDescriptorImport.VentureCard = VanillaDatabase.getDefaultVentureCardTable(mapDescriptorImport.RuleSet, usedSquareTypes); } progress.Report(new ProgressInfo(60, "Copy frb file(s) to tmp...")); var frbFileName = mapDescriptorImport.FrbFile1; var importFile = Path.Combine(dir, frbFileName + ".frb"); var destFile = Path.Combine(riivFileSet.param_folder, frbFileName + ".frb"); Directory.CreateDirectory(riivFileSet.param_folder); File.Copy(importFile, destFile, true); progress.Report("Imported " + importFile); frbFileName = mapDescriptorImport.FrbFile2; if (frbFileName != null) { importFile = Path.Combine(dir, frbFileName + ".frb"); destFile = Path.Combine(riivFileSet.param_folder, frbFileName + ".frb"); File.Copy(importFile, destFile, true); progress.Report("Imported " + importFile); } frbFileName = mapDescriptorImport.FrbFile3; if (frbFileName != null) { importFile = Path.Combine(dir, frbFileName + ".frb"); destFile = Path.Combine(riivFileSet.param_folder, frbFileName + ".frb"); File.Copy(importFile, destFile, true); progress.Report("Imported " + importFile); } frbFileName = mapDescriptorImport.FrbFile4; if (frbFileName != null) { importFile = Path.Combine(dir, frbFileName + ".frb"); destFile = Path.Combine(riivFileSet.param_folder, frbFileName + ".frb"); File.Copy(importFile, destFile, true); progress.Report("Imported " + importFile); } var mapIcon = mapDescriptorImport.MapIcon; // only import the png if it is not a vanilla map icon if (mapIcon != null && !VanillaDatabase.getVanillaTpl(mapIcon).Any()) { importFile = Path.Combine(dir, mapIcon + ".png"); destFile = Path.Combine(tmpFileSet.param_folder, mapIcon + ".png"); Directory.CreateDirectory(tmpFileSet.param_folder); if (File.Exists(destFile)) { File.Delete(destFile); } // we have a map icon for the tutorial map ready, we can use it if (mapIcon == "p_bg_901") { WriteResourceToFile("CustomStreetMapManager.Images.p_bg_901.png", destFile); } else { File.Copy(importFile, destFile); progress.Report("Imported " + importFile); } } mapDescriptorImport.Dirty = true; progress.Report(new ProgressInfo(100, "Done.")); return(mapDescriptorImport); }