From 0ac4b7df87c62eadcb131efaab4d7cf629191f0a Mon Sep 17 00:00:00 2001 From: Elmegaard Date: Tue, 27 Aug 2024 18:17:16 +0200 Subject: [PATCH 1/3] Fix c# code generation --- .../CodeGenerator/CSharpCodeGenerator.cs | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/ReClass.NET/CodeGenerator/CSharpCodeGenerator.cs b/ReClass.NET/CodeGenerator/CSharpCodeGenerator.cs index c46bb836..815a8dc7 100644 --- a/ReClass.NET/CodeGenerator/CSharpCodeGenerator.cs +++ b/ReClass.NET/CodeGenerator/CSharpCodeGenerator.cs @@ -38,7 +38,11 @@ public class CSharpCodeGenerator : ICodeGenerator [typeof(Vector2Node)] = "Vector2", [typeof(Vector3Node)] = "Vector3", - [typeof(Vector4Node)] = "Vector4" + [typeof(Vector4Node)] = "Vector4", + + [typeof(Matrix3x3Node)] = "Matrix3x3", + [typeof(Matrix3x4Node)] = "Matrix3x4", + [typeof(Matrix4x4Node)] = "Matrix4x4" }; public Language Language => Language.CSharp; @@ -128,7 +132,7 @@ private static void WriteEnum(IndentedTextWriter writer, EnumDescription @enum) Contract.Requires(writer != null); Contract.Requires(@enum != null); - writer.Write($"enum {@enum.Name} : "); + writer.Write($"public enum {@enum.Name} : "); switch (@enum.Size) { case EnumDescription.UnderlyingTypeSize.OneByte: @@ -242,12 +246,39 @@ private static (string typeName, string attribute) GetTypeDefinition(BaseNode no return (type, null); } - return node switch + switch (node) { - EnumNode enumNode => (enumNode.Enum.Name, null), - Utf8TextNode utf8TextNode => ("string", $"[MarshalAs(UnmanagedType.ByValTStr, SizeConst = {utf8TextNode.Length})]"), - Utf16TextNode utf16TextNode => (GetUnicodeStringClassName(utf16TextNode.Length), "[MarshalAs(UnmanagedType.Struct)]"), - _ => (null, null) + case EnumNode enumNode: + return (enumNode.Enum.Name, null); + + case Utf8TextNode utf8TextNode: + return ("char[]", $"[MarshalAs(UnmanagedType.ByValTStr, SizeConst = {utf8TextNode.Length})]"); + + case Utf16TextNode utf16TextNode: + return (GetUnicodeStringClassName(utf16TextNode.Length), "[MarshalAs(UnmanagedType.Struct)]"); + + case ArrayNode arrayNode: + var typeName = GetTypeDefinition(arrayNode.InnerNode).typeName; + if (string.IsNullOrEmpty(typeName)) + { + typeName = "byte"; + } + + return (typeName + "[]", $"[MarshalAs(UnmanagedType.ByValArray, SizeConst = {arrayNode.Count})]"); + + case ClassInstanceNode classInstanceNode: + var innerNodeName = classInstanceNode.InnerNode.Name; + return (innerNodeName, null); + var innerNode = GetTypeDefinition(classInstanceNode.InnerNode); + var innerNodeType = innerNode.typeName; + if (string.IsNullOrEmpty(innerNodeType)) + { + innerNode = (classInstanceNode.Name, null); + } + return innerNode; + + default: + return (null, null); }; } From 79f51068c98f69601a03ac8ebf24fce1b76acd7a Mon Sep 17 00:00:00 2001 From: Elmegaard Date: Tue, 27 Aug 2024 18:18:16 +0200 Subject: [PATCH 2/3] Ignore unix compile errors --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 3a3e6d33..990fb880 100644 --- a/.gitignore +++ b/.gitignore @@ -252,3 +252,5 @@ paket-files/ *.sln.iml /ReClass.NET/Resources/BuildDate.txt + +**/__par_compile_fail \ No newline at end of file From a8cb5d464731e1e308d3c80d19bcd5e36c9ffa04 Mon Sep 17 00:00:00 2001 From: Elmegaard Date: Wed, 28 Aug 2024 22:49:14 +0200 Subject: [PATCH 3/3] fix char arrays --- ReClass.NET/CodeGenerator/CSharpCodeGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReClass.NET/CodeGenerator/CSharpCodeGenerator.cs b/ReClass.NET/CodeGenerator/CSharpCodeGenerator.cs index 815a8dc7..09a9e629 100644 --- a/ReClass.NET/CodeGenerator/CSharpCodeGenerator.cs +++ b/ReClass.NET/CodeGenerator/CSharpCodeGenerator.cs @@ -252,7 +252,7 @@ private static (string typeName, string attribute) GetTypeDefinition(BaseNode no return (enumNode.Enum.Name, null); case Utf8TextNode utf8TextNode: - return ("char[]", $"[MarshalAs(UnmanagedType.ByValTStr, SizeConst = {utf8TextNode.Length})]"); + return ("char[]", $"[MarshalAs(UnmanagedType.ByValArray, SizeConst = {utf8TextNode.Length})]"); case Utf16TextNode utf16TextNode: return (GetUnicodeStringClassName(utf16TextNode.Length), "[MarshalAs(UnmanagedType.Struct)]");