From d90faed922468a5cb810eb906fa62ecc0435ff8d Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 10 Nov 2023 13:35:53 +0800 Subject: [PATCH] =?UTF-8?q?[change]=20=E5=88=A0=E9=99=A4=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84Datas~/Templates=E7=9B=AE=E5=BD=95=EF=BC=8C?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E4=BB=A5=E5=8E=9F=E5=A7=8B=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=BA=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Data~/Templates/MethodBridgeStub.cpp | 18 ----------- Data~/Templates/ReversePInvokeMethodStub.cpp | 30 ------------------- .../Commands/MethodBridgeGeneratorCommand.cs | 8 ++--- .../ReversePInvokeWrapperGeneratorCommand.cs | 4 +-- Editor/ReversePInvokeWrap/Generator.cs | 5 +++- Editor/Settings/MenuProvider.cs | 2 +- 6 files changed, 11 insertions(+), 56 deletions(-) delete mode 100644 Data~/Templates/MethodBridgeStub.cpp delete mode 100644 Data~/Templates/ReversePInvokeMethodStub.cpp diff --git a/Data~/Templates/MethodBridgeStub.cpp b/Data~/Templates/MethodBridgeStub.cpp deleted file mode 100644 index 8829430..0000000 --- a/Data~/Templates/MethodBridgeStub.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include "vm/ClassInlines.h" -#include "vm/Object.h" -#include "vm/Class.h" - -#include "../metadata/MetadataModule.h" -#include "../metadata/MetadataUtil.h" - -#include "../interpreter/MethodBridge.h" -#include "../interpreter/Interpreter.h" -#include "../interpreter/MemoryUtil.h" -#include "../interpreter/InstrinctDef.h" - -using namespace hybridclr::interpreter; - -//!!!{{CODE - -//!!!}}CODE diff --git a/Data~/Templates/ReversePInvokeMethodStub.cpp b/Data~/Templates/ReversePInvokeMethodStub.cpp deleted file mode 100644 index 0252d57..0000000 --- a/Data~/Templates/ReversePInvokeMethodStub.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "../metadata/ReversePInvokeMethodStub.h" -#include "../metadata/MetadataModule.h" - -namespace hybridclr -{ -namespace metadata -{ - - //!!!{{CODE - - void __ReversePInvokeMethod_0(void* xState) - { - CallLuaFunction(xState, 0); - } - - void __ReversePInvokeMethod_1(void* xState) - { - CallLuaFunction(xState, 1); - } - - Il2CppMethodPointer s_ReversePInvokeMethodStub[] - { - (Il2CppMethodPointer)__ReversePInvokeMethod_0, - (Il2CppMethodPointer)__ReversePInvokeMethod_1, - nullptr, - }; - - //!!!}}CODE -} -} \ No newline at end of file diff --git a/Editor/Commands/MethodBridgeGeneratorCommand.cs b/Editor/Commands/MethodBridgeGeneratorCommand.cs index de83cb7..fde1084 100644 --- a/Editor/Commands/MethodBridgeGeneratorCommand.cs +++ b/Editor/Commands/MethodBridgeGeneratorCommand.cs @@ -30,8 +30,9 @@ namespace HybridCLR.Editor.Commands Directory.Delete(il2cppBuildCachePath, true); } - private static void GenerateMethodBridgeCppFile(Analyzer analyzer, string templateCode, string outputFile) + private static void GenerateMethodBridgeCppFile(Analyzer analyzer, string outputFile) { + string templateCode = File.ReadAllText(outputFile, Encoding.UTF8); var g = new Generator(new Generator.Options() { TemplateCode = templateCode, @@ -41,7 +42,7 @@ namespace HybridCLR.Editor.Commands g.PrepareMethods(); g.Generate(); - Debug.LogFormat("== output:{0} ==", outputFile); + Debug.LogFormat("[MethodBridgeGeneratorCommand] output:{0}", outputFile); } [MenuItem("HybridCLR/Generate/MethodBridge", priority = 101)] @@ -70,9 +71,8 @@ namespace HybridCLR.Editor.Commands }); analyzer.Run(); - string templateCode = File.ReadAllText($"{SettingsUtil.TemplatePathInPackage}/MethodBridgeStub.cpp"); string outputFile = $"{SettingsUtil.GeneratedCppDir}/MethodBridge.cpp"; - GenerateMethodBridgeCppFile(analyzer, templateCode, outputFile); + GenerateMethodBridgeCppFile(analyzer, outputFile); } CleanIl2CppBuildCache(); diff --git a/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs b/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs index f047c0c..706e748 100644 --- a/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs +++ b/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs @@ -35,13 +35,13 @@ namespace HybridCLR.Editor.Commands var analyzer = new ReversePInvokeWrap.Analyzer(cache, hotUpdateDlls); analyzer.Run(); - string templateCode = File.ReadAllText($"{SettingsUtil.TemplatePathInPackage}/ReversePInvokeMethodStub.cpp"); string outputFile = $"{SettingsUtil.GeneratedCppDir}/ReversePInvokeMethodStub.cpp"; List methods = analyzer.BuildABIMethods(); Debug.Log($"GenerateReversePInvokeWrapper. wraperCount:{methods.Sum(m => m.Count)} output:{outputFile}"); var generator = new Generator(); - generator.Generate(templateCode, methods, outputFile); + generator.Generate(methods, outputFile); + Debug.LogFormat("[ReversePInvokeWrapperGeneratorCommand] output:{0}", outputFile); } MethodBridgeGeneratorCommand.CleanIl2CppBuildCache(); } diff --git a/Editor/ReversePInvokeWrap/Generator.cs b/Editor/ReversePInvokeWrap/Generator.cs index b72afc2..fdf6df5 100644 --- a/Editor/ReversePInvokeWrap/Generator.cs +++ b/Editor/ReversePInvokeWrap/Generator.cs @@ -2,15 +2,18 @@ using HybridCLR.Editor.Template; using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Text; using UnityEngine; namespace HybridCLR.Editor.ReversePInvokeWrap { public class Generator { - public void Generate(string template, List methods, string outputFile) + public void Generate(List methods, string outputFile) { + string template = File.ReadAllText(outputFile, Encoding.UTF8); var frr = new FileRegionReplace(template); var codes = new List(); diff --git a/Editor/Settings/MenuProvider.cs b/Editor/Settings/MenuProvider.cs index 3149cf3..c21c46d 100644 --- a/Editor/Settings/MenuProvider.cs +++ b/Editor/Settings/MenuProvider.cs @@ -7,7 +7,7 @@ namespace HybridCLR.Editor.Settings public static class MenuProvider { - [MenuItem("HybridCLR/About HybridCLR", priority = 0)] + [MenuItem("HybridCLR/About", priority = 0)] public static void OpenAbout() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/intro"); [MenuItem("HybridCLR/Installer...", priority = 60)]