private void AB_SelectionChanged(object sender, SelectionChangedEventArgs e) { var list = sender as ListView; if (list.SelectedIndex == -1) { return; // Return if no item is selected } // Check if files should not be loaded if (!_game.EnableResourceLoading) { return; } string path = (list.SelectedItem as STSCFileDatabase.ArtBookPageEntry).PagePathData; if (_novelTextureArchive.GetFileData($"{path}.tex") is byte[] data) { var tex = new TEXFile(); using (var stream = new MemoryStream(data)) tex.Load(stream); AB_PG = ImageTools.ConvertToSource(tex.CreateBitmap()); tex.Dispose(); } }
private void CG_ExportThumbButton_Click(object sender, RoutedEventArgs e) { // Show error if DAL: RR is not installed as its needed to export if (!_game.EnableResourceLoading) { MessageBox.Show("This feature requires DATE A LIVE: Rio Reincarnation to be installed!", "DAL: RR not found!", MessageBoxButton.OK, MessageBoxImage.Error); return; } var sfd = new SaveFileDialog(); sfd.Filter = "Portable Network Graphics (*.png)|*.png"; if (sfd.ShowDialog(this) == true) { if (CG_ListView.SelectedIndex == -1) { return; // Return if no item is selected } int id = (CG_ListView.SelectedItem as STSCFileDatabase.CGEntry).CGID; var game = (CG_ListView.SelectedItem as STSCFileDatabase.CGEntry).GameID; if (_CGThumbnailTextureArchive.GetFileData($"{Consts.GAMEDIRNAME[(int)game]}/MA{id:D6}.tex") is byte[] data) { // Change Character Image var tex = new TEXFile(); using (var stream = new MemoryStream(data)) tex.Load(stream); tex.SaveSheetImage(sfd.FileName); } } }
private void CG_ListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { var list = sender as ListView; if (list.SelectedIndex == -1) { return; // Return if no item is selected } // Check if files should not be loaded if (!_game.EnableResourceLoading) { return; } int id = (list.SelectedItem as STSCFileDatabase.CGEntry).CGID; var game = (list.SelectedItem as STSCFileDatabase.CGEntry).GameID; string filepath = Path.Combine(_game.GamePath, $"Data\\Data\\Ma\\{Consts.GAMEDIRNAME[(int)game]}\\MA{id:D6}.pck"); if (_CGThumbnailTextureArchive.GetFileData($"{Consts.GAMEDIRNAME[(int)game]}/MA{id:D6}.tex") is byte[] data) { // Change Character Image var tex = new TEXFile(); using (var stream = new MemoryStream(data)) tex.Load(stream); CG_IM = ImageTools.ConvertToSource(tex.CreateBitmap()); } }
private void UI_LoadTextureButton_Click(object sender, RoutedEventArgs e) { var ofd = new OpenFileDialog(); ofd.Filter = "All Supported Files|*.tex|Texture|*.tex"; if (ofd.ShowDialog() == true) { // Load Font TEX FontImageTexFile.Load(ofd.FileName); UI_FontImage.Source = ImageTools.ConvertToSource(FontImageTexFile.CreateBitmap()); } }
public void LoadFile(string path) { if (path == null) { return; } // Check if its a PCK if (path.ToLowerInvariant().Contains(".pck")) { LoadFontPCK(path); return; } // Check if file is valid and make sure FilePath is the .code if (path.ToLowerInvariant().Contains("_data.tex") || path.ToLowerInvariant().Contains(".code")) { FilePath = path.Replace("_data.tex", ".code"); } else { MessageBox.Show($"Unknown file type\n{path}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } // Recreate Objects FontImageTexFile = new TEXFile(); FontCodeFile = new FontFile(); FontCodeFile.MonospaceOnly = MonospaceOnly; try { // Load Font TEX FontImageTexFile.Load(FilePath.Replace(".code", "_data.tex")); UI_FontImage.Source = ImageTools.ConvertToSource(FontImageTexFile.CreateBitmap()); } catch { MessageBox.Show("Failed to load Texture!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } LastIndex = -1; HoverIndex = -1; // Load FontCode FontCodeFile.Load(FilePath); // Reload ReloadUI(); UI_SaveButton.IsEnabled = true; }
public void LoadFontPCK(string path) { FilePath = path; PCKFontArchive = new PCKFile(); PCKFontArchive.Load(path); var textureFilePath = PCKFontArchive.SearchForFile(".tex"); var fontCodeFilePath = PCKFontArchive.SearchForFile(".code"); FontImageTexFile = new TEXFile(); FontCodeFile = new FontFile(); FontCodeFile.MonospaceOnly = MonospaceOnly; // Load Font Code if (fontCodeFilePath != null) { FontCodeFile.Load(PCKFontArchive.GetFileStream(fontCodeFilePath)); } else { MessageBox.Show("Failed to load Code File!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } if (textureFilePath != null) { // Load Texture FontImageTexFile.Load(PCKFontArchive.GetFileStream(textureFilePath)); // Set Texture UI_FontImage.Source = ImageTools.ConvertToSource(FontImageTexFile.CreateBitmap()); } else { MessageBox.Show("Failed to load Texture!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } LastIndex = -1; HoverIndex = -1; // Reload ReloadUI(); UI_SaveButton.IsEnabled = true; }
private void UI_ImportTextureButton_Click(object sender, RoutedEventArgs e) { var ofd = new OpenFileDialog(); ofd.Filter = "All Supported Files|*.tex;*.png|Texture|*.tex|Supported Image Files|*.png"; if (ofd.ShowDialog() == true) { if (ofd.FileName.ToLower(CultureInfo.GetCultureInfo("en-US")).EndsWith(".tex")) { var textureFilePath = PCKFontArchive.SearchForFile(".tex"); var newTexture = new TEXFile(); // Set Sigless newTexture.Sigless = true; // Load new Texture newTexture.Load(ofd.FileName); // Check Dimensions if (FontImageTexFile.SheetData != null && (newTexture.SheetWidth != FontImageTexFile.SheetWidth || newTexture.SheetHeight != FontImageTexFile.SheetHeight)) { if (MessageBox.Show("Texture dimensions do not match!\n" + "FontEditor currently does not support rescaling, Do you want to continue?", "WARNING", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { return; } } // Import Texture into PCK PCKFontArchive.ReplaceFile(textureFilePath, File.ReadAllBytes(ofd.FileName)); // Set Texture UI_FontImage.Source = ImageTools.ConvertToSource((FontImageTexFile = newTexture).CreateBitmap()); } else { var textureFilePath = PCKFontArchive.SearchForFile(".tex"); var newTexture = new TEXFile(); // Set Sigless newTexture.Sigless = true; // Load Image to Texture newTexture.LoadSheetImage(ofd.FileName); // Check Dimensions if (FontImageTexFile.SheetData != null && (newTexture.SheetWidth != FontImageTexFile.SheetWidth || newTexture.SheetHeight != FontImageTexFile.SheetHeight)) { if (MessageBox.Show("Texture dimensions do not match!\n" + "FontEditor currently does not support rescaling, Do you want to continue?", "WARNING", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { return; } } // Save Texture to PCK using (var stream = new MemoryStream()) { newTexture.Save(stream); PCKFontArchive.ReplaceFile(textureFilePath, stream.ToArray()); } // Set Texture UI_FontImage.Source = ImageTools.ConvertToSource((FontImageTexFile = newTexture).CreateBitmap()); } } }
// TODO: Needs Rewriting private void CG_ExportImage_Click(object sender, RoutedEventArgs e) { // Show error if DAL: RR is not installed as its needed to export if (!_game.EnableResourceLoading) { MessageBox.Show("Resource loading is currently disabled. Make sure DAL: RR is installed correctly", "Resource Loading Error!", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (CG_ListView.SelectedIndex == -1) { return; // Return if no item is selected } int id = (CG_ListView.SelectedItem as STSCFileDatabase.CGEntry).CGID; var game = (CG_ListView.SelectedItem as STSCFileDatabase.CGEntry).GameID; var sfd = new SaveFileDialog(); sfd.FileName = $"{id}.png"; sfd.Filter = "Portable Network Graphics (*.png)|*.png"; if (sfd.ShowDialog(this) == true) { try { string filepath = Path.Combine(_game.GamePath, $"Data\\Data\\Ma\\{Consts.GAMEDIRNAME[(int)game]}\\MA{id:D6}.pck"); var pck = new PCKFile(); var ma = new MAFile(); pck.Load(filepath, true); using (var stream = new MemoryStream(pck.GetFileData(0))) ma.Load(stream); int width = (int)(ma.Layers[0].Verts[3].DestinX * ma.Layers[0].LayerWidth); int height = (int)(ma.Layers[0].Verts[3].DestinY * ma.Layers[0].LayerHeight); if (ma.Layers[0].Verts[3].DestinX == ma.Layers[0].LayerWidth) { width = (int)ma.Layers[0].LayerWidth; height = (int)ma.Layers[0].LayerHeight; } var bytes = new byte[width * height * 4]; for (int i = 0; i < ma.Layers.Count; ++i) { var layer = ma.Layers[i]; var tex = new TEXFile(); using (var stream = new MemoryStream(pck.GetFileData(layer.TextureID + 1))) tex.Load(stream); int sx = (int)(layer.Verts[0].SourceX * ma.Layers[i].LayerWidth); int dx = (int)(layer.Verts[0].DestinX * ma.Layers[i].LayerWidth + layer.LayerOffX); int sy = (int)(layer.Verts[0].SourceY * ma.Layers[i].LayerHeight); int dy = (int)(layer.Verts[0].DestinY * ma.Layers[i].LayerHeight + layer.LayerOffY); int sw = (int)(layer.Verts[3].SourceX * ma.Layers[i].LayerWidth); int sh = (int)(layer.Verts[3].SourceY * ma.Layers[i].LayerHeight); for (int y = 0; y < (sh - sy); ++y) { for (int x = 0; x < (sw - sx); ++x) { if ((y + sy) >= tex.SheetHeight || (x + sx) >= tex.SheetWidth) { break; } int index = ((y + sy) * tex.SheetWidth + (x + sx)) * 4; if (tex.SheetData[index + 3] != 255) { continue; } bytes[((y + dy) * width + x + dx) * 4 + 3] = tex.SheetData[index + 3]; bytes[((y + dy) * width + x + dx) * 4 + 0] = tex.SheetData[index + 0]; bytes[((y + dy) * width + x + dx) * 4 + 1] = tex.SheetData[index + 1]; bytes[((y + dy) * width + x + dx) * 4 + 2] = tex.SheetData[index + 2]; } } DALLib.Imaging.ImageTools.SaveImage(Path.Combine(Path.GetDirectoryName(sfd.FileName), Path.GetFileNameWithoutExtension(sfd.FileName) + $"_{i}.png"), width, height, bytes); } pck.Dispose(); } catch (Exception ex) { new ExceptionWindow(ex, "Failed to export CG frames").ShowDialog(); } } }
public static void Main(string[] args) { var tex = new TEXFile(); if (args.Length == 0) { ShowHelp("Not Enough Arguments!"); return; } // Preprocess if (args.Length > 1) { string path = ""; for (int i = 0; i < args.Length; ++i) { if (args[i].StartsWith("-") && args[i].Length > 1) { switch (args[i][1]) { case 'z': tex.UseSmallSig = true; break; case 'e': tex.UseBigEndian = true; break; case 'c': CheckOverwrite = false; break; case 'o': path = args[i + 1]; break; default: break; } continue; } } // Actions for (int i = args.Length - 1; i >= 0; --i) { if (args[i].StartsWith("-") && args[i].Length > 1) { switch (args[i][1]) { case 'p': tex.Load(args[args.Length - 1]); if (string.IsNullOrEmpty(path)) { path = RemoveExtension(args[args.Length - 1]); } Directory.CreateDirectory(path); for (int ii = 0; ii < tex.Frames.Count; ++ii) { SaveFrame(tex, ii, Path.Combine(path, $"frame{ii:d2}.png")); } break; case 's': tex.Load(args[args.Length - 1]); if (string.IsNullOrEmpty(path)) { path = Path.ChangeExtension(args[args.Length - 1], ".png"); } if (CheckForOverwrite(path)) { tex.SaveSheetImage(path); } break; case 'i': tex.Load(args[args.Length - 1]); if (string.IsNullOrEmpty(path)) { path = Path.ChangeExtension(args[args.Length - 1], ".xml"); } SaveAllFrameInformation(tex, path); break; case 'f': tex.Load(args[args.Length - 1]); if (CheckForOverwrite(path)) { SaveFrame(tex, int.Parse(args[i + 1]), path); } break; case 'b': BuildTEX(ref tex, args[i + 1], args[i + 2]); if (string.IsNullOrEmpty(path)) { path = Path.ChangeExtension(args[args.Length - 1], ".tex"); } if (CheckForOverwrite(path)) { tex.Save(path); } break; case 'm': BuildTEX(ref tex, args[i + 1]); if (string.IsNullOrEmpty(path)) { path = Path.ChangeExtension(args[args.Length - 1], ".tex"); } if (CheckForOverwrite(path)) { tex.Save(path); } break; } } } } else { if (Path.GetExtension(args[0]) == ".png" || Path.GetExtension(args[0]) == ".xml" || Directory.Exists(args[0])) { Console.WriteLine("Building Files detected, Building..."); BuildTEX(ref tex, args[0]); string path = Path.ChangeExtension(args[0], ".tex"); if (CheckForOverwrite(path)) { tex.Save(path); } } else { tex.Load(args[0]); tex.SaveSheetImage(Path.ChangeExtension(args[0], ".png")); SaveAllFrameInformation(tex, Path.ChangeExtension(args[0], ".xml")); } } }