From 95a0420f4035dfc1c620c7576fde081ffc76a4e1 Mon Sep 17 00:00:00 2001 From: factubsio <65080026+factubsio@users.noreply.github.com> Date: Sun, 22 May 2022 21:25:20 +0100 Subject: [PATCH] spell/buff descriptor enum flags to string --- BlueprintExplorer/BlueprintControl.cs | 45 +++++++++++++++++++++++ BlueprintExplorer/BlueprintDB.cs | 51 ++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/BlueprintExplorer/BlueprintControl.cs b/BlueprintExplorer/BlueprintControl.cs index 4b5b129..f4013f0 100644 --- a/BlueprintExplorer/BlueprintControl.cs +++ b/BlueprintExplorer/BlueprintControl.cs @@ -487,9 +487,54 @@ private void ValidateBlueprint(bool scroll) row.TypeFull = e.MaybeType.FullName; } + if (e.isObj && !e.HasType) + { + var parent = stack.Peek(); + if (!parent.IsObj) + { + row.TypeFull = parent.TypeFull; + row.Type = parent.Type; + } + else + { + var type = BlueprintDB.Instance.TypeForField(parent.TypeFull, e.key); + if (type != null) + { + row.TypeFull = type.FullName; + row.Type = type.Name; + } + } + } + + if (e.levelDelta > 0 && !e.isObj) + { + var parent = stack.Peek(); + var type = BlueprintDB.Instance.TypeForField(parent.TypeFull, e.key); + + if (type != null) + { + if (type.GenericTypeArguments.Length == 1) + type = type.GenericTypeArguments[0]; + else if (type.HasElementType) + type = type.GetElementType(); + + row.TypeFull = type.FullName; + row.Type = type.Name; + } + } + + if (row.key == "m_IntValue" && row.Parent.TypeFull == "Kingmaker.Blueprints.Classes.Spells.SpellDescriptorWrapper") + { + List spans = new(); + spans.Add(new(row.value + " - ", StyleFlags.Bold)); + spans.Add(new(Enum.Parse(BubblePrints.Wrath.GetType("Kingmaker.Blueprints.Classes.Spells.SpellDescriptor"), row.value).ToString(), 0)); + row.ValueStyled = new(spans); + } + if (row.key == "$type" && row.Parent != null) continue; + if (e.levelDelta == 0 && row.Parent != null) { row.Default = BlueprintDB.Instance.DefaultForField(row.Parent?.TypeFull, e.key); diff --git a/BlueprintExplorer/BlueprintDB.cs b/BlueprintExplorer/BlueprintDB.cs index f143331..a96dac8 100644 --- a/BlueprintExplorer/BlueprintDB.cs +++ b/BlueprintExplorer/BlueprintDB.cs @@ -123,7 +123,7 @@ public int CompareTo(GameVersion other) public List Available = new() { }; - private readonly GameVersion LastKnown = new(1, 3, 2, 'c', 0); + private readonly GameVersion LastKnown = new(1, 3, 4, 'e', 0); private readonly string filenameRoot = "blueprints_raw"; private readonly string extension = "binz"; @@ -220,6 +220,55 @@ public GoingToLoad GetLoadType() } private Dictionary> defaults = new(); + private Dictionary> fieldTypes = new(); + private Dictionary nullDict = new(); + + private IEnumerable<(string name, Type type)> FieldTypes(Type of) + { + if (of.BaseType != null) + foreach (var t in FieldTypes(of.BaseType)) + yield return t; + + foreach (var f in of.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)) + yield return (f.Name, f.FieldType); + } + + public Type TypeForField(string typename, string field) + { + if (BubblePrints.Wrath == null || typename == null) + return null; + + if (fieldTypes.TryGetValue(typename, out var fields)) + { + if (fields.TryGetValue(field, out var fieldType)) + return fieldType; + return null; + } + else + { + var t = BubblePrints.Wrath.GetType(typename); + if (t == null) + { + fieldTypes[typename] = nullDict; + return null; + } + + var fieldTypeDict = new Dictionary(); + + foreach (var prop in t.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) + fieldTypeDict[prop.Name] = prop.PropertyType; + + foreach (var (fname, ftype) in FieldTypes(t)) + fieldTypeDict[fname] = ftype; + + fieldTypes[typename] = fieldTypeDict; + + if (fieldTypeDict.TryGetValue(field, out var fieldType)) + return fieldType; + + return null; + } + } public string DefaultForField(string typename, string field) { if (typename == null || !defaults.TryGetValue(typename, out var map))