From 2aaf54c6611398498e9f417e3aeef66557916f9e Mon Sep 17 00:00:00 2001 From: LongerWarrior Date: Fri, 7 Apr 2023 22:20:38 +0300 Subject: [PATCH] Adding Kismet --- .gitmodules | 3 +- CUE4Parse | 2 +- FModel/App.xaml.cs | 3 +- FModel/Extensions/StringExtensions.cs | 36 +++++++++++++++++-- FModel/Settings/UserSettings.cs | 7 ++++ FModel/ViewModels/CUE4ParseViewModel.cs | 1 + FModel/ViewModels/SettingsViewModel.cs | 15 ++++++++ .../Controls/Aed/GamePathVisualLineText.cs | 20 +++++++++-- FModel/Views/SettingsView.xaml | 22 ++++++++---- NOTICE | 3 +- 10 files changed, 96 insertions(+), 16 deletions(-) diff --git a/.gitmodules b/.gitmodules index 959570f6..1fa5d337 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,7 @@ [submodule "CUE4Parse"] path = CUE4Parse url = https://github.com/FabianFG/CUE4Parse + branch = Kismet [submodule "EpicManifestParser"] path = EpicManifestParser - url = https://github.com/FModel/EpicManifestParser \ No newline at end of file + url = https://github.com/FModel/EpicManifestParser diff --git a/CUE4Parse b/CUE4Parse index 269bfa7a..05c2e4db 160000 --- a/CUE4Parse +++ b/CUE4Parse @@ -1 +1 @@ -Subproject commit 269bfa7afcc23021ee3667f2f98ec6a8cd354d2c +Subproject commit 05c2e4dbdcf07cf056a80cf0990c27a69724d6c6 diff --git a/FModel/App.xaml.cs b/FModel/App.xaml.cs index f889e0f4..01617c91 100644 --- a/FModel/App.xaml.cs +++ b/FModel/App.xaml.cs @@ -1,4 +1,4 @@ -using AdonisUI.Controls; +using AdonisUI.Controls; using Microsoft.Win32; using Serilog; using System; @@ -41,6 +41,7 @@ public partial class App { UserSettings.Default = JsonConvert.DeserializeObject( File.ReadAllText(UserSettings.FilePath), JsonNetSerializer.SerializerSettings); + ApplicationService.ApplicationView.CUE4Parse.Provider.ReadScriptData = UserSettings.Default.ReadScriptData; } catch { diff --git a/FModel/Extensions/StringExtensions.cs b/FModel/Extensions/StringExtensions.cs index cbfa8ddd..67dec4ba 100644 --- a/FModel/Extensions/StringExtensions.cs +++ b/FModel/Extensions/StringExtensions.cs @@ -1,6 +1,7 @@ -using System; +using System; using System.IO; using System.Runtime.CompilerServices; +using System.Text.RegularExpressions; namespace FModel.Extensions; @@ -112,6 +113,37 @@ public static class StringExtensions return 1; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int GetKismetLineNumber(this string s, string input) + { + var match = Regex.Match(input, @"^(.+)\[(\d+)\]$"); + var name = match.Groups[1].Value; + int index = int.Parse(match.Groups[2].Value); + var lineToFind = $" \"Name\": \"{name}\","; + var offset = $"\"StatementIndex\": {index}"; + using var reader = new StringReader(s); + var lineNum = 0; + string line; + + while ((line = reader.ReadLine()) != null) + { + lineNum++; + if (line.Equals(lineToFind, StringComparison.OrdinalIgnoreCase)) + { + var objectLine = lineNum; + while ((line = reader.ReadLine()) != null) + { + lineNum++; + if (line.Contains(offset, StringComparison.OrdinalIgnoreCase)) + return lineNum; + } + return objectLine; + } + } + + return 1; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static int GetLineNumber(this string s, int index) { @@ -130,4 +162,4 @@ public static class StringExtensions return 1; } -} \ No newline at end of file +} diff --git a/FModel/Settings/UserSettings.cs b/FModel/Settings/UserSettings.cs index 8dd6b3cb..86a6c533 100644 --- a/FModel/Settings/UserSettings.cs +++ b/FModel/Settings/UserSettings.cs @@ -226,6 +226,13 @@ namespace FModel.Settings set => SetProperty(ref _imageMergerMargin, value); } + private bool _readScriptData; + public bool ReadScriptData + { + get => _readScriptData; + set => SetProperty(ref _readScriptData, value); + } + // // can't refactor to use this data layout for everything // because it will wipe old user settings that relies on FGame diff --git a/FModel/ViewModels/CUE4ParseViewModel.cs b/FModel/ViewModels/CUE4ParseViewModel.cs index 64e7edeb..07134bce 100644 --- a/FModel/ViewModels/CUE4ParseViewModel.cs +++ b/FModel/ViewModels/CUE4ParseViewModel.cs @@ -391,6 +391,7 @@ public class CUE4ParseViewModel : ViewModel } else if (endpoint.IsValid) { + if(string.IsNullOrEmpty(endpoint.Path)) return; var mappingsFolder = Path.Combine(UserSettings.Default.OutputDirectory, ".data"); var mappings = _apiEndpointView.DynamicApi.GetMappings(cancellationToken, endpoint.Url, endpoint.Path); if (mappings is { Length: > 0 }) diff --git a/FModel/ViewModels/SettingsViewModel.cs b/FModel/ViewModels/SettingsViewModel.cs index e74a96fb..306d4835 100644 --- a/FModel/ViewModels/SettingsViewModel.cs +++ b/FModel/ViewModels/SettingsViewModel.cs @@ -167,6 +167,17 @@ public class SettingsViewModel : ViewModel set => SetProperty(ref _selectedTextureExportFormat, value); } + private bool _selectedReadScriptData; + public bool SelectedReadScriptData + { + get => _selectedReadScriptData; + set + { + SetProperty(ref _selectedReadScriptData, value); + ApplicationService.ApplicationView.CUE4Parse.Provider.ReadScriptData = value; + } + } + public ReadOnlyObservableCollection UpdateModes { get; private set; } public ObservableCollection Presets { get; private set; } public ReadOnlyObservableCollection UeGames { get; private set; } @@ -208,6 +219,7 @@ public class SettingsViewModel : ViewModel private ELodFormat _lodExportFormatSnapshot; private EMaterialFormat _materialExportFormatSnapshot; private ETextureFormat _textureExportFormatSnapshot; + private bool _readScriptDataSnapshot; private bool _mappingsUpdate = false; @@ -262,6 +274,7 @@ public class SettingsViewModel : ViewModel _lodExportFormatSnapshot = UserSettings.Default.LodExportFormat; _materialExportFormatSnapshot = UserSettings.Default.MaterialExportFormat; _textureExportFormatSnapshot = UserSettings.Default.TextureExportFormat; + _readScriptDataSnapshot = UserSettings.Default.ReadScriptData; SelectedUpdateMode = _updateModeSnapshot; SelectedPreset = _presetSnapshot; @@ -278,6 +291,7 @@ public class SettingsViewModel : ViewModel SelectedLodExportFormat = _lodExportFormatSnapshot; SelectedMaterialExportFormat = _materialExportFormatSnapshot; SelectedTextureExportFormat = _textureExportFormatSnapshot; + SelectedReadScriptData = _readScriptDataSnapshot; SelectedAesReload = UserSettings.Default.AesReload; SelectedDiscordRpc = UserSettings.Default.DiscordRpc; @@ -394,6 +408,7 @@ public class SettingsViewModel : ViewModel UserSettings.Default.LodExportFormat = SelectedLodExportFormat; UserSettings.Default.MaterialExportFormat = SelectedMaterialExportFormat; UserSettings.Default.TextureExportFormat = SelectedTextureExportFormat; + UserSettings.Default.ReadScriptData = SelectedReadScriptData; UserSettings.Default.AesReload = SelectedAesReload; UserSettings.Default.DiscordRpc = SelectedDiscordRpc; diff --git a/FModel/Views/Resources/Controls/Aed/GamePathVisualLineText.cs b/FModel/Views/Resources/Controls/Aed/GamePathVisualLineText.cs index dd323ca6..426891a0 100644 --- a/FModel/Views/Resources/Controls/Aed/GamePathVisualLineText.cs +++ b/FModel/Views/Resources/Controls/Aed/GamePathVisualLineText.cs @@ -1,10 +1,12 @@ -using System; +using System; +using System.Text.RegularExpressions; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.TextFormatting; using FModel.Extensions; using FModel.Services; using FModel.ViewModels; +using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Rendering; namespace FModel.Views.Resources.Controls; @@ -68,8 +70,20 @@ public class GamePathVisualLineText : VisualLineText var fullPath = _applicationView.CUE4Parse.Provider.FixPath(package, StringComparison.Ordinal); if (a.ParentVisualLine.Document.FileName.Equals(fullPath.SubstringBeforeLast('.'), StringComparison.OrdinalIgnoreCase)) { - var lineNumber = a.ParentVisualLine.Document.Text.GetLineNumber(obj); - var line = a.ParentVisualLine.Document.GetLineByNumber(lineNumber); + int lineNumber; + DocumentLine line; + + if (Regex.IsMatch(obj, @"^(.+)\[(\d+)\]$")) + { + lineNumber = a.ParentVisualLine.Document.Text.GetKismetLineNumber(obj); + line = a.ParentVisualLine.Document.GetLineByNumber(lineNumber); + } + else + { + lineNumber = a.ParentVisualLine.Document.Text.GetLineNumber(obj); + line = a.ParentVisualLine.Document.GetLineByNumber(lineNumber); + } + AvalonEditor.YesWeEditor.Select(line.Offset, line.Length); AvalonEditor.YesWeEditor.ScrollToLine(lineNumber); } diff --git a/FModel/Views/SettingsView.xaml b/FModel/Views/SettingsView.xaml index c10ad6ff..589ff037 100644 --- a/FModel/Views/SettingsView.xaml +++ b/FModel/Views/SettingsView.xaml @@ -42,6 +42,7 @@ + @@ -209,24 +210,31 @@ - - + + + + - - - - -