diff --git a/FModel/Enums.cs b/FModel/Enums.cs index 0713bd58..197f0310 100644 --- a/FModel/Enums.cs +++ b/FModel/Enums.cs @@ -106,7 +106,8 @@ public enum EBulkType Meshes = 1 << 3, Skeletons = 1 << 4, Animations = 1 << 5, - Audio = 1 << 6 + Audio = 1 << 6, + Code = 1 << 7 } public enum EAssetCategory : uint diff --git a/FModel/MainWindow.xaml b/FModel/MainWindow.xaml index 82da6143..9a57110e 100644 --- a/FModel/MainWindow.xaml +++ b/FModel/MainWindow.xaml @@ -348,6 +348,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { _applicationView.CUE4Parse.SaveDecompiled(cancellationToken, folder); }); + FLogger.Append(ELog.Information, () => + { + FLogger.Text("Successfully saved ", Constants.WHITE); + FLogger.Link(folder.PathAtThisPoint, UserSettings.Default.PropertiesDirectory, true); + }); + } + } private void OnAssetsTreeSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e) { diff --git a/FModel/ViewModels/CUE4ParseViewModel.cs b/FModel/ViewModels/CUE4ParseViewModel.cs index aeba0307..7096513f 100644 --- a/FModel/ViewModels/CUE4ParseViewModel.cs +++ b/FModel/ViewModels/CUE4ParseViewModel.cs @@ -584,7 +584,8 @@ public void ExtractFolder(CancellationToken cancellationToken, TreeItem folder) public void SaveFolder(CancellationToken cancellationToken, TreeItem folder) => BulkFolder(cancellationToken, folder, asset => Extract(cancellationToken, asset, TabControl.HasNoTabs, EBulkType.Properties | EBulkType.Auto)); - + public void SaveDecompiled(CancellationToken cancellationToken, TreeItem folder) + => BulkFolder(cancellationToken, folder, asset => Extract(cancellationToken, asset, TabControl.HasNoTabs, EBulkType.Code | EBulkType.Auto)); public void TextureFolder(CancellationToken cancellationToken, TreeItem folder) => BulkFolder(cancellationToken, folder, asset => Extract(cancellationToken, asset, TabControl.HasNoTabs, EBulkType.Textures | EBulkType.Auto)); @@ -610,6 +611,7 @@ public void Extract(CancellationToken cancellationToken, GameFile entry, bool ad var saveProperties = HasFlag(bulk, EBulkType.Properties); var saveTextures = HasFlag(bulk, EBulkType.Textures); var saveAudio = HasFlag(bulk, EBulkType.Audio); + var saveDecompiled = HasFlag(bulk, EBulkType.Code); switch (entry.Extension) { case "uasset": @@ -623,8 +625,13 @@ public void Extract(CancellationToken cancellationToken, GameFile entry, bool ad TabControl.SelectedTab.SetDocumentText(JsonConvert.SerializeObject(result.GetDisplayData(saveProperties), Formatting.Indented), saveProperties, updateUi); if (saveProperties) break; // do not search for viewable exports if we are dealing with jsons } + if (saveDecompiled || updateUi) + { + Decompile(entry, false); + TabControl.SelectedTab.SaveDecompiled(updateUi); + } - for (var i = result.InclusiveStart; i < result.ExclusiveEnd; i++) + for (var i = result.InclusiveStart; i < result.ExclusiveEnd; i++) { if (CheckExport(cancellationToken, result.Package, i, bulk)) break; @@ -1198,7 +1205,7 @@ public void ShowMetadata(GameFile entry) TabControl.SelectedTab.SetDocumentText(JsonConvert.SerializeObject(package, Formatting.Indented), false, false); } - + public void FindReferences(GameFile entry) { var refs = Provider.ScanForPackageRefs(entry); @@ -1210,12 +1217,9 @@ public void FindReferences(GameFile entry) }); } - - public void Decompile(GameFile entry) + public void Decompile(GameFile entry, bool AddTab = true) { - ApplicationService.ApplicationView.IsAssetsExplorerVisible = false; - - if (TabControl.CanAddTabs) TabControl.AddTab(entry); + if (TabControl.CanAddTabs && AddTab) TabControl.AddTab(entry); else TabControl.SelectedTab.SoftReset(entry); TabControl.SelectedTab.TitleExtra = "Decompiled"; diff --git a/FModel/ViewModels/TabControlViewModel.cs b/FModel/ViewModels/TabControlViewModel.cs index 9131169a..31e579e7 100644 --- a/FModel/ViewModels/TabControlViewModel.cs +++ b/FModel/ViewModels/TabControlViewModel.cs @@ -407,7 +407,17 @@ public void SaveProperty(bool updateUi) Application.Current.Dispatcher.Invoke(() => File.WriteAllText(directory, Document.Text)); SaveCheck(directory, fileName, updateUi); } + public void SaveDecompiled(bool updateUi) + { + var fileName = Path.ChangeExtension(Entry.Name, ".cpp"); + var directory = Path.Combine(UserSettings.Default.PropertiesDirectory, + UserSettings.Default.KeepDirectoryStructure ? Entry.Directory : "", fileName).Replace('\\', '/'); + + Directory.CreateDirectory(directory.SubstringBeforeLast('/')); + Application.Current.Dispatcher.Invoke(() => File.WriteAllText(directory, Document.Text)); + SaveCheck(directory, fileName, updateUi); + } private void SaveCheck(string path, string fileName, bool updateUi) { if (File.Exists(path))