From 864ed91753408b2508fe0ae1a535cabb57112a10 Mon Sep 17 00:00:00 2001 From: glassfish777 Date: Thu, 3 Aug 2023 19:17:44 -0700 Subject: [PATCH 1/8] fix: Allow use of 'name' type in custom class variable declarations --- WolvenKit.CR2W/Reflection/REDReflection.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WolvenKit.CR2W/Reflection/REDReflection.cs b/WolvenKit.CR2W/Reflection/REDReflection.cs index e92784bc7..6643cddc1 100644 --- a/WolvenKit.CR2W/Reflection/REDReflection.cs +++ b/WolvenKit.CR2W/Reflection/REDReflection.cs @@ -1,4 +1,4 @@ -using DotNetHelper.FastMember.Extension.Extension; +using DotNetHelper.FastMember.Extension.Extension; using FastMember; using System; using System.Collections.Generic; @@ -123,6 +123,8 @@ public static string GetWKitBaseTypeFromREDBaseType(string typename) case "float": return "CFloat"; case "String": return "CString"; case "string": return "CString"; + case "Name": return "CName"; + case "name": return "CName"; case "Color": return "CColor"; case "Matrix": return "CMatrix"; default: From 8b3ed4f89f87b120c9a804d3a1d8aa4e3083a95d Mon Sep 17 00:00:00 2001 From: glassfish777 Date: Thu, 3 Aug 2023 19:20:08 -0700 Subject: [PATCH 2/8] fix: Vanilla enums can be used custom class variable declarations WolvenKit would refuse to compile custom class with vanilla enum variables. This is because the compiler was fed an enum class that did not properly extend the vanilla enum class. This is because the vanilla enum calss is in WolvenKit.CR2W and not WolvenKit.CR2W.Types. This is stop gap fix that puts the enum class in the WolvenKit.CR2W namespace however in the future the namespace of the vanilla enums should be corrected. --- WolvenKit.CR2W/CR2WManager.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/WolvenKit.CR2W/CR2WManager.cs b/WolvenKit.CR2W/CR2WManager.cs index 937633fd7..0fd328bf8 100644 --- a/WolvenKit.CR2W/CR2WManager.cs +++ b/WolvenKit.CR2W/CR2WManager.cs @@ -174,13 +174,17 @@ public static Type GetEnumByName(string typeName) - private const string header = @" + private const string header1 = @" using System.IO; using FastMember; using WolvenKit.CR2W.Reflection; using static WolvenKit.CR2W.Types.Enums; +namespace WolvenKit.CR2W +{ +"; + private const string header2 = @" namespace WolvenKit.CR2W.Types { "; @@ -210,7 +214,7 @@ private static (int, string) InterpretScriptClasses() using (StringWriter sw = new StringWriter()) { // usings and namespace - sw.WriteLine(header); + sw.WriteLine(header1); FileInfo[] projectScriptFiles = m_projectinfo.GetFiles("*.ws", SearchOption.AllDirectories); @@ -289,6 +293,8 @@ private static (int, string) InterpretScriptClasses() } #endregion sw.WriteLine("\t}\r\n"); + sw.WriteLine("}\r\n"); + sw.WriteLine(header2); // interpret classes #region Classes From 4221435793b4ac4aa7fbd411194789fbaa1333cb Mon Sep 17 00:00:00 2001 From: glassfish777 Date: Thu, 3 Aug 2023 19:20:44 -0700 Subject: [PATCH 3/8] fix: Add custom classes to Add Chunk dialog They were not being included before making it impossible to add custom class chunks(since 7.2) --- WolvenKit/Forms/Dialog/frmAddChunk.cs | 30 +++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/WolvenKit/Forms/Dialog/frmAddChunk.cs b/WolvenKit/Forms/Dialog/frmAddChunk.cs index 8a2a73bf0..8c157c5f2 100644 --- a/WolvenKit/Forms/Dialog/frmAddChunk.cs +++ b/WolvenKit/Forms/Dialog/frmAddChunk.cs @@ -9,8 +9,12 @@ namespace WolvenKit { public partial class frmAddChunk : Form { - private string[] classTypes = null; - private string[] enumTypes = null; + //private string[] classTypes = null; + //private string[] enumTypes = null; + private List vanillaClasses = null; + private List customClasses = null; + private List vanillaEnums = null; + private List customEnums = null; public frmAddChunk(List list = null, bool isVariant = false, bool allowEditName = false) { InitializeComponent(); @@ -24,16 +28,20 @@ public frmAddChunk(List list = null, bool isVariant = false, bool allowE { txName.Enabled = false; } - if (list == null) + if (vanillaClasses == null) { - list = AssemblyDictionary.TypeNames; + vanillaClasses = AssemblyDictionary.TypeNames; } - list.Sort(); - classTypes = list.ToArray(); + vanillaClasses.Sort(); - list = AssemblyDictionary.EnumNames; - list.Sort(); - enumTypes = list.ToArray(); + customClasses = CR2WManager.TypeNames; + customClasses.Sort(); + + + vanillaEnums = AssemblyDictionary.EnumNames; + vanillaEnums.Sort(); + customEnums = CR2WManager.EnumNames; + customEnums.Sort(); UpdateTypeChoices(); } @@ -42,11 +50,11 @@ private void UpdateTypeChoices() txType.Items.Clear(); if (checkEnum.Checked) { - txType.Items.AddRange(enumTypes); + txType.Items.AddRange(vanillaEnums.Concat(customEnums).Distinct().ToArray()); } else { - txType.Items.AddRange(classTypes); + txType.Items.AddRange(vanillaClasses.Concat(customClasses).Distinct().ToArray()); } if (txType.SelectedIndex < 0 && txType.Items.Count > 0) txType.SelectedIndex = 0; From a7d0f6fcb2573cd99e07ad9375d76422f3984186 Mon Sep 17 00:00:00 2001 From: glassfish777 Date: Thu, 3 Aug 2023 19:21:16 -0700 Subject: [PATCH 4/8] feat: Enable flow diagram in Wkit 7.x Enables the flow diagram that was missing since 7.0. --- WolvenKit/Forms/MVVM/frmCR2WDocument.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/WolvenKit/Forms/MVVM/frmCR2WDocument.cs b/WolvenKit/Forms/MVVM/frmCR2WDocument.cs index 96f645099..79e69b392 100644 --- a/WolvenKit/Forms/MVVM/frmCR2WDocument.cs +++ b/WolvenKit/Forms/MVVM/frmCR2WDocument.cs @@ -518,12 +518,12 @@ public void PostLoadFile(string filename = "", bool openrenderer = false) case ".w2quest": case ".w2phase": { - //this.flowDiagram = new frmChunkFlowDiagram(); - //this.flowDiagram.OnOutput += MainController.LogString; - //this.flowDiagram.File = this.File; - //this.flowDiagram.DockAreas = DockAreas.Document; - //this.flowDiagram.OnSelectChunk += this.frmCR2WDocument_OnSelectChunk; - //this.flowDiagram.Show(this.FormPanel, DockState.Document); + this.flowDiagram = new frmChunkFlowDiagram(); + this.flowDiagram.OnOutput += MainController.LogString; + this.flowDiagram.File = this.File; + this.flowDiagram.DockAreas = DockAreas.Document; + this.flowDiagram.OnSelectChunk += this.frmCR2WDocument_OnSelectChunk; + this.flowDiagram.Show(this.FormPanel, DockState.Document); break; } From 1d306513608ad43bb1293b40bf00cf7ba3ee2eda Mon Sep 17 00:00:00 2001 From: glassfish777 Date: Thu, 3 Aug 2023 19:22:12 -0700 Subject: [PATCH 5/8] fix: Chunks now show up in flow diagram Flow diagram was broken due to ReferenceType not returning the REDType from Reference. This fixes that bug enabling use of the flow diagram in Wkit 7.x. --- WolvenKit.CR2W/Types/Generic/CPtr.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WolvenKit.CR2W/Types/Generic/CPtr.cs b/WolvenKit.CR2W/Types/Generic/CPtr.cs index 9bb2361b4..3704c9cbe 100644 --- a/WolvenKit.CR2W/Types/Generic/CPtr.cs +++ b/WolvenKit.CR2W/Types/Generic/CPtr.cs @@ -23,7 +23,7 @@ public CPtr(CR2WFile cr2w, CVariable parent, string name) : base(cr2w, parent, n #region Properties public CR2WExportWrapper Reference { get; set; } - public string ReferenceType => REDType.Split(':').Last(); + public string ReferenceType => Reference.REDType.Split(':').Last(); #endregion #region Methods From 22ec4ea8b6fba471f05d8d3f0b3ed4e4c7ebbcad Mon Sep 17 00:00:00 2001 From: glassfish777 Date: Thu, 3 Aug 2023 19:24:29 -0700 Subject: [PATCH 6/8] fix: Try to improve flow diagram performance The flow diagram in WolvenKit is very slow when viewing big phases as it loops over thousands of chunks everytime the user zoom/pans redrawing them over and over. Windows Forms is not a suitable interface for such as system and it needs to be rebuilt with a package more suitable for this application. In the meantime, I have tried to improve performance by not drawing the connections when the user is panning but results are still not that great. --- WolvenKit/Forms/frmChunkFlowDiagram.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/WolvenKit/Forms/frmChunkFlowDiagram.cs b/WolvenKit/Forms/frmChunkFlowDiagram.cs index 267200589..ae4c3b5c8 100644 --- a/WolvenKit/Forms/frmChunkFlowDiagram.cs +++ b/WolvenKit/Forms/frmChunkFlowDiagram.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; @@ -51,7 +51,6 @@ public partial class frmChunkFlowDiagram : DockContent public frmChunkFlowDiagram() { InitializeComponent(); - selectionBackground = new SolidBrush(Color.FromArgb(100, SystemColors.Highlight)); selectionBorder = new Pen(Color.FromArgb(200, SystemColors.Highlight)); selectionItemHighlight = new Pen(Color.Green, 2.0f); @@ -292,7 +291,7 @@ private void frmChunkFlowView_Paint(object sender, PaintEventArgs e) // eat the exception, allready logging the exception when creating the node editor } - if (conns != null) + if (conns != null && !isMoving) { foreach (var conn in conns) { @@ -590,4 +589,4 @@ private void copyDisplayTextToolStripMenuItem_Click(object sender, EventArgs e) } } } -} \ No newline at end of file +} From c6b9a5a086fcfbeceb6e43eff51099f593645994 Mon Sep 17 00:00:00 2001 From: glassfish777 Date: Thu, 3 Aug 2023 21:58:17 -0700 Subject: [PATCH 7/8] Fix: Revise fix for flow diagram restoration Redoes the fix by commenting in old function rather than editing existing one which breaks chunk editing. --- WolvenKit.CR2W/Types/Generic/CPtr.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/WolvenKit.CR2W/Types/Generic/CPtr.cs b/WolvenKit.CR2W/Types/Generic/CPtr.cs index 3704c9cbe..2aa71e931 100644 --- a/WolvenKit.CR2W/Types/Generic/CPtr.cs +++ b/WolvenKit.CR2W/Types/Generic/CPtr.cs @@ -23,23 +23,23 @@ public CPtr(CR2WFile cr2w, CVariable parent, string name) : base(cr2w, parent, n #region Properties public CR2WExportWrapper Reference { get; set; } - public string ReferenceType => Reference.REDType.Split(':').Last(); + public string ReferenceType => REDType.Split(':').Last(); #endregion #region Methods public string GetPtrTargetType() { - return ReferenceType; - //try - //{ - // if (Reference == null) - // return "NULL"; - // return Reference.REDType; - //} - //catch (Exception ex) - //{ - // throw new InvalidPtrException(ex.Message); - //} + //return ReferenceType; + try + { + if (Reference == null) + return "NULL"; + return Reference.REDType; + } + catch (Exception ex) + { + throw new InvalidPtrException(ex.Message); + } } /// From ed21b237d3157dcf2739c75244661d26277f0b5d Mon Sep 17 00:00:00 2001 From: glassfish777 Date: Fri, 4 Aug 2023 15:03:23 -0700 Subject: [PATCH 8/8] fix: Revise fix for missing custom class chunks in AddChunk Dialog The previous version of this fix broke vanilla chunk filtering. This revised version corrects that however custom class chunks do not feature filtering and will always appears in the add chunk drop down. --- WolvenKit/Forms/Dialog/frmAddChunk.cs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/WolvenKit/Forms/Dialog/frmAddChunk.cs b/WolvenKit/Forms/Dialog/frmAddChunk.cs index 8c157c5f2..f3c31e462 100644 --- a/WolvenKit/Forms/Dialog/frmAddChunk.cs +++ b/WolvenKit/Forms/Dialog/frmAddChunk.cs @@ -1,16 +1,17 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using WolvenKit.CR2W; using WolvenKit.CR2W.Types; using WolvenKit.CR2W.Reflection; +using System.Windows.Documents; namespace WolvenKit { public partial class frmAddChunk : Form { - //private string[] classTypes = null; - //private string[] enumTypes = null; + private string[] classTypes = null; + private string[] enumTypes = null; private List vanillaClasses = null; private List customClasses = null; private List vanillaEnums = null; @@ -28,20 +29,24 @@ public frmAddChunk(List list = null, bool isVariant = false, bool allowE { txName.Enabled = false; } - if (vanillaClasses == null) + if (list == null) { - vanillaClasses = AssemblyDictionary.TypeNames; + list = AssemblyDictionary.TypeNames; } - vanillaClasses.Sort(); + list.Sort(); customClasses = CR2WManager.TypeNames; customClasses.Sort(); + classTypes = list.Concat(customClasses).Distinct().ToArray(); vanillaEnums = AssemblyDictionary.EnumNames; vanillaEnums.Sort(); customEnums = CR2WManager.EnumNames; customEnums.Sort(); + + enumTypes = vanillaEnums.Concat(customEnums).Distinct().ToArray(); + UpdateTypeChoices(); } @@ -50,11 +55,11 @@ private void UpdateTypeChoices() txType.Items.Clear(); if (checkEnum.Checked) { - txType.Items.AddRange(vanillaEnums.Concat(customEnums).Distinct().ToArray()); + txType.Items.AddRange(enumTypes); } else { - txType.Items.AddRange(vanillaClasses.Concat(customClasses).Distinct().ToArray()); + txType.Items.AddRange(classTypes); } if (txType.SelectedIndex < 0 && txType.Items.Count > 0) txType.SelectedIndex = 0;