private void Import_Click(object sender, RoutedEventArgs e) { UndertaleEmbeddedAudio target = DataContext as UndertaleEmbeddedAudio; OpenFileDialog dlg = new OpenFileDialog(); dlg.DefaultExt = ".wav"; dlg.Filter = "WAV files (.wav)|*.wav|All files|*"; if (dlg.ShowDialog() == true) { try { byte[] data = File.ReadAllBytes(dlg.FileName); // TODO: Make sure it's valid WAV target.Data = data; } catch (Exception ex) { mainWindow.ShowError("Failed to import file: " + ex.Message, "Failed to import file"); } } }
private void Details_Click(object sender, RoutedEventArgs e) { if (ObjectReference is null) { MainWindow mainWindow = Application.Current.MainWindow as MainWindow; if (mainWindow.Selected is null) { mainWindow.ShowError("Nothing currently selected! This is currently unsupported."); return; } else if (mainWindow.Selected is UndertaleGameObject gameObject) { // Generate the code entry UndertaleCode code = gameObject.EventHandlerFor(ObjectEventType, ObjectEventSubtype, mainWindow.Data.Strings, mainWindow.Data.Code, mainWindow.Data.CodeLocals); ObjectReference = code; } else { mainWindow.ShowError("Adding to non-objects is currently unsupported."); return; } } else { (Application.Current.MainWindow as MainWindow).ChangeSelection(ObjectReference); } }
private void Import_Click(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.DefaultExt = ".png"; dlg.Filter = "PNG files (.png)|*.png|All files|*"; if (!(dlg.ShowDialog() ?? false)) { return; } try { Bitmap image = TextureWorker.ReadImageFromFile(dlg.FileName); image.SetResolution(96.0F, 96.0F); (this.DataContext as UndertaleTexturePageItem).ReplaceTexture(image); // Refresh the image of "ItemDisplay" if (ItemDisplay.FindName("RenderAreaBorder") is not Border border) { return; } if (border.Background is not ImageBrush brush) { return; } BindingOperations.GetBindingExpression(brush, ImageBrush.ImageSourceProperty)?.UpdateTarget(); } catch (Exception ex) { mainWindow.ShowError(ex.Message, "Failed to import image"); } }
private void Import_Click(object sender, RoutedEventArgs e) { UndertaleEmbeddedTexture target = DataContext as UndertaleEmbeddedTexture; OpenFileDialog dlg = new OpenFileDialog(); dlg.DefaultExt = ".png"; dlg.Filter = "PNG files (.png)|*.png|All files|*"; if (dlg.ShowDialog() == true) { try { Bitmap bmp; using (var ms = new MemoryStream(TextureWorker.ReadTextureBlob(dlg.FileName))) { bmp = new Bitmap(ms); } bmp.SetResolution(96.0F, 96.0F); var width = (uint)bmp.Width; var height = (uint)bmp.Height; if ((width & (width - 1)) != 0 || (height & (height - 1)) != 0) { mainWindow.ShowWarning("WARNING: texture page dimensions are not powers of 2. Sprite blurring is very likely in game.", "Unexpected texture dimensions"); } using (var stream = new MemoryStream()) { bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png); target.TextureData.TextureBlob = stream.ToArray(); TexWidth.GetBindingExpression(TextBox.TextProperty)?.UpdateTarget(); TexHeight.GetBindingExpression(TextBox.TextProperty)?.UpdateTarget(); } } catch (Exception ex) { mainWindow.ShowError("Failed to import file: " + ex.Message, "Failed to import file"); } } }
private void ExportAllSpine(SaveFileDialog dlg, UndertaleSprite sprite) { mainWindow.ShowWarning("This seems to be a Spine sprite, .json and .atlas files will be exported together with the frames. " + "PLEASE EDIT THEM CAREFULLY! SOME MANUAL EDITING OF THE JSON MAY BE REQUIRED! THE DATA IS EXPORTED AS-IS.", "Spine warning"); if (dlg.ShowDialog() == true) { try { string dir = System.IO.Path.GetDirectoryName(dlg.FileName); string name = System.IO.Path.GetFileNameWithoutExtension(dlg.FileName); string path = System.IO.Path.Combine(dir, name); string ext = System.IO.Path.GetExtension(dlg.FileName); if (sprite.SpineTextures.Count > 0) { Directory.CreateDirectory(path); // textures foreach (var tex in sprite.SpineTextures.Select((tex, id) => new { id, tex })) { try { File.WriteAllBytes(System.IO.Path.Combine(path, tex.id + ext), tex.tex.PNGBlob); } catch (Exception ex) { mainWindow.ShowError("Failed to export file: " + ex.Message, "Failed to export file"); } } // json and atlas File.WriteAllText(System.IO.Path.Combine(path, "spine.json"), sprite.SpineJSON); File.WriteAllText(System.IO.Path.Combine(path, "spine.atlas"), sprite.SpineAtlas); } } catch (Exception ex) { mainWindow.ShowError("Failed to export: " + ex.Message, "Failed to export sprite"); } } }
private void Play_Click(object sender, RoutedEventArgs e) { UndertaleSound sound = DataContext as UndertaleSound; if ((sound.Flags & UndertaleSound.AudioEntryFlags.IsEmbedded) != UndertaleSound.AudioEntryFlags.IsEmbedded && (sound.Flags & UndertaleSound.AudioEntryFlags.IsCompressed) != UndertaleSound.AudioEntryFlags.IsCompressed) { try { string filename; if (!sound.File.Content.Contains(".")) { filename = sound.File.Content + ".ogg"; } else { filename = sound.File.Content; } string audioPath = Path.Combine(Path.GetDirectoryName((Application.Current.MainWindow as MainWindow).FilePath), filename); if (File.Exists(audioPath)) { switch (Path.GetExtension(filename).ToLower()) { case ".wav": wavReader = new WaveFileReader(audioPath); InitAudio(); waveOut.Init(wavReader); waveOut.Play(); break; case ".ogg": oggReader = new VorbisWaveReader(audioPath); InitAudio(); waveOut.Init(oggReader); waveOut.Play(); break; case ".mp3": mp3Reader = new Mp3FileReader(audioPath); InitAudio(); waveOut.Init(mp3Reader); waveOut.Play(); break; default: throw new Exception("Unknown file type."); } } else { throw new Exception("Failed to find audio file."); } } catch (Exception ex) { waveOut = null; mainWindow.ShowError("Failed to play audio!\r\n" + ex.Message, "Audio failure"); } return; } UndertaleEmbeddedAudio target; if (sound.GroupID != 0 && sound.AudioID != -1) { try { string path = Path.Combine(Path.GetDirectoryName((Application.Current.MainWindow as MainWindow).FilePath), "audiogroup" + sound.GroupID + ".dat"); if (File.Exists(path)) { if (loadedPath != path) { loadedPath = path; using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { audioGroupData = UndertaleIO.Read(stream, warning => { throw new Exception(warning); }); } } target = audioGroupData.EmbeddedAudio[sound.AudioID]; } else { throw new Exception("Failed to find audio group file."); } } catch (Exception ex) { waveOut = null; mainWindow.ShowError("Failed to play audio!\r\n" + ex.Message, "Audio failure"); return; } } else { target = sound.AudioFile; } if (target != null) { if (target.Data.Length > 4) { try { if (target.Data[0] == 'R' && target.Data[1] == 'I' && target.Data[2] == 'F' && target.Data[3] == 'F') { wavReader = new WaveFileReader(new MemoryStream(target.Data)); InitAudio(); waveOut.Init(wavReader); waveOut.Play(); } else if (target.Data[0] == 'O' && target.Data[1] == 'g' && target.Data[2] == 'g' && target.Data[3] == 'S') { oggReader = new VorbisWaveReader(new MemoryStream(target.Data)); InitAudio(); waveOut.Init(oggReader); waveOut.Play(); } else { mainWindow.ShowError("Failed to play audio!\r\nNot a WAV or OGG.", "Audio failure"); } } catch (Exception ex) { waveOut = null; mainWindow.ShowError("Failed to play audio!\r\n" + ex.Message, "Audio failure"); } } } else { mainWindow.ShowError("Failed to play audio!\r\nNo options for playback worked.", "Audio failure"); } }