From 17a6e68fbdbf1ec1e55cf6ae340d0ae1e525967b Mon Sep 17 00:00:00 2001 From: goodguy Date: Tue, 26 Sep 2023 02:25:52 +0800 Subject: [PATCH 1/2] Support for custom type --- ReClass.NET/CodeGenerator/CppCodeGenerator.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/ReClass.NET/CodeGenerator/CppCodeGenerator.cs b/ReClass.NET/CodeGenerator/CppCodeGenerator.cs index b6495aab..bdddb6be 100644 --- a/ReClass.NET/CodeGenerator/CppCodeGenerator.cs +++ b/ReClass.NET/CodeGenerator/CppCodeGenerator.cs @@ -437,9 +437,16 @@ private void WriteNode(IndentedTextWriter writer, BaseNode node, ILogger logger) if (simpleType != null) { //$"{type} {node.Name}; //0x{node.Offset.ToInt32():X04} {node.Comment}".Trim(); - writer.Write(simpleType); - writer.Write(" "); - writer.Write(node.Name); + if (node.Name[0] == '#') + { + writer.Write(node.Name.Substring(1)); + } + else + { + writer.Write(simpleType); + writer.Write(" "); + writer.Write(node.Name); + } writer.Write("; //0x"); writer.Write($"{node.Offset:X04}"); if (!string.IsNullOrEmpty(node.Comment)) @@ -451,7 +458,14 @@ private void WriteNode(IndentedTextWriter writer, BaseNode node, ILogger logger) } else if (node is BaseWrapperNode) { - writer.Write(ResolveWrappedType(node, false, logger)); + if (node.Name[0] == '#') + { + writer.Write(node.Name.Substring(1)); + } + else + { + writer.Write(ResolveWrappedType(node, false, logger)); + } writer.Write("; //0x"); writer.Write($"{node.Offset:X04}"); if (!string.IsNullOrEmpty(node.Comment)) From f2d76c9977702ca892f9c1f581ca5f067cc66d3f Mon Sep 17 00:00:00 2001 From: goodguy Date: Tue, 26 Sep 2023 03:39:11 +0800 Subject: [PATCH 2/2] Add highlight for custom type --- ReClass.NET/CodeGenerator/CppCodeGenerator.cs | 8 +++--- ReClass.NET/Nodes/BaseNode.cs | 26 +++++++++++++++++++ ReClass.NET/Nodes/BaseNumericNode.cs | 5 ++++ ReClass.NET/Nodes/BaseWrapperArrayNode.cs | 5 ++++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/ReClass.NET/CodeGenerator/CppCodeGenerator.cs b/ReClass.NET/CodeGenerator/CppCodeGenerator.cs index bdddb6be..543e5f6f 100644 --- a/ReClass.NET/CodeGenerator/CppCodeGenerator.cs +++ b/ReClass.NET/CodeGenerator/CppCodeGenerator.cs @@ -437,9 +437,9 @@ private void WriteNode(IndentedTextWriter writer, BaseNode node, ILogger logger) if (simpleType != null) { //$"{type} {node.Name}; //0x{node.Offset.ToInt32():X04} {node.Comment}".Trim(); - if (node.Name[0] == '#') + if (node.IsCustomType) { - writer.Write(node.Name.Substring(1)); + writer.Write(node.GetCustomTypeName()); } else { @@ -458,9 +458,9 @@ private void WriteNode(IndentedTextWriter writer, BaseNode node, ILogger logger) } else if (node is BaseWrapperNode) { - if (node.Name[0] == '#') + if (node.IsCustomType) { - writer.Write(node.Name.Substring(1)); + writer.Write(node.GetCustomTypeName()); } else { diff --git a/ReClass.NET/Nodes/BaseNode.cs b/ReClass.NET/Nodes/BaseNode.cs index adef39e5..f2513ea9 100644 --- a/ReClass.NET/Nodes/BaseNode.cs +++ b/ReClass.NET/Nodes/BaseNode.cs @@ -520,6 +520,32 @@ protected void DrawInvalidMemoryIndicatorIcon(DrawContext context, int y) AddIcon(context, 0, y, Properties.Resources.B16x16_Error, HotSpot.NoneId, HotSpotType.None); } } + + /// + /// + public bool IsCustomType { get => (Name.Length > 0 && Name[0] == '#'); } + + /// + /// + public string GetCustomTypeName() + { + return Name.Substring(1); + } + + /// + /// + public string GetCustomType() + { + string name = Name; + int len; + if (name.IndexOf('*') != -1) + len = name.LastIndexOf('*') + 1; + else + len = name.LastIndexOf(' '); + if (len == -1) + return Name; + return name.Substring(0, len); + } } [ContractClassFor(typeof(BaseNode))] diff --git a/ReClass.NET/Nodes/BaseNumericNode.cs b/ReClass.NET/Nodes/BaseNumericNode.cs index 61782ca6..41928bb7 100644 --- a/ReClass.NET/Nodes/BaseNumericNode.cs +++ b/ReClass.NET/Nodes/BaseNumericNode.cs @@ -40,7 +40,12 @@ protected Size DrawNumeric(DrawContext context, int x, int y, Image icon, string x = AddText(context, x, y, context.Settings.TypeColor, HotSpot.NoneId, type) + context.Font.Width; if (!IsWrapped) { + int xx = x; x = AddText(context, x, y, context.Settings.NameColor, HotSpot.NameId, Name) + context.Font.Width; + if (IsCustomType) + { + AddText(context, xx, y, context.Settings.IndexColor, HotSpot.NoneId, GetCustomType()); + } } x = AddText(context, x, y, context.Settings.NameColor, HotSpot.NoneId, "=") + context.Font.Width; x = AddText(context, x, y, context.Settings.ValueColor, 0, value) + context.Font.Width; diff --git a/ReClass.NET/Nodes/BaseWrapperArrayNode.cs b/ReClass.NET/Nodes/BaseWrapperArrayNode.cs index ee042751..b9186af5 100644 --- a/ReClass.NET/Nodes/BaseWrapperArrayNode.cs +++ b/ReClass.NET/Nodes/BaseWrapperArrayNode.cs @@ -48,7 +48,12 @@ protected Size Draw(DrawContext context, int x, int y, string type) x = AddText(context, x, y, context.Settings.TypeColor, HotSpot.NoneId, type) + context.Font.Width; if (!IsWrapped) { + int xx = x; x = AddText(context, x, y, context.Settings.NameColor, HotSpot.NameId, Name); + if (IsCustomType) + { + AddText(context, xx, y, context.Settings.IndexColor, HotSpot.NoneId, GetCustomType()); + } } x = AddText(context, x, y, context.Settings.IndexColor, HotSpot.NoneId, "["); x = AddText(context, x, y, context.Settings.IndexColor, IsReadOnly ? HotSpot.NoneId : 0, Count.ToString());