From f810ac53baa7c968830db203d044527cc29068c5 Mon Sep 17 00:00:00 2001 From: walon Date: Wed, 28 Sep 2022 21:48:09 +0800 Subject: [PATCH] =?UTF-8?q?[opt]=20=E5=BD=93Installer=E4=B8=ADil2cpp?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E4=B8=8D=E5=8C=85=E5=90=AB=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=E6=97=B6=EF=BC=8C=E7=BB=99=E5=87=BA=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=20[opt]=20=E6=96=B0=E5=A2=9E=20LoadMetadataForAOTAssembly(byte?= =?UTF-8?q?[])=E5=87=BD=E6=95=B0=EF=BC=8C=E7=AE=80=E5=8C=96=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E3=80=82=E5=90=8C=E6=97=B6=E5=9C=A8Editor=E4=B8=8B?= =?UTF-8?q?=E8=A2=AB=E6=84=8F=E5=A4=96=E8=B0=83=E7=94=A8=E6=97=B6=E7=BB=99?= =?UTF-8?q?=E5=87=BA=E6=9B=B4=E6=B8=85=E6=99=B0=E7=9A=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/Installer/InstallerController.cs | 5 +++- Editor/Installer/InstallerWindow.cs | 35 ++++++++++++++----------- Runtime/RuntimeApi.cs | 12 +++++++++ package.json | 2 +- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Editor/Installer/InstallerController.cs b/Editor/Installer/InstallerController.cs index e67793c..72730f2 100644 --- a/Editor/Installer/InstallerController.cs +++ b/Editor/Installer/InstallerController.cs @@ -18,6 +18,7 @@ namespace HybridCLR.Editor.Installer public enum InstallErrorCode { Ok, + InvalidUnityInstallPath, Il2CppInstallPathNotMatchIl2CppBranch, Il2CppInstallPathNotExists, NotIl2CppPath, @@ -233,7 +234,9 @@ namespace HybridCLR.Editor.Installer if (!IsComaptibleWithIl2CppPlusBranch(il2cppBranch, installDir)) { - return InstallErrorCode.Il2CppInstallPathNotMatchIl2CppBranch; + return TryParseMinorVersion(installDir, out _) ? + InstallErrorCode.Il2CppInstallPathNotMatchIl2CppBranch + : InstallErrorCode.InvalidUnityInstallPath; } if (!installDir.EndsWith("/il2cpp")) diff --git a/Editor/Installer/InstallerWindow.cs b/Editor/Installer/InstallerWindow.cs index d5fd6ac..07ff58b 100644 --- a/Editor/Installer/InstallerWindow.cs +++ b/Editor/Installer/InstallerWindow.cs @@ -79,24 +79,29 @@ namespace HybridCLR.Editor.Installer switch (err) { case InstallErrorCode.Ok: - { - break; - } + { + break; + } case InstallErrorCode.Il2CppInstallPathNotExists: - { - EditorGUILayout.HelpBox("li2cpp 路径不存在", MessageType.Error); - break; - } + { + EditorGUILayout.HelpBox("li2cpp 路径不存在", MessageType.Error); + break; + } + case InstallErrorCode.InvalidUnityInstallPath: + { + EditorGUILayout.HelpBox($"Unity安装目录必须包含版本号,否则无法识别版本", MessageType.Error); + break; + } case InstallErrorCode.Il2CppInstallPathNotMatchIl2CppBranch: - { - EditorGUILayout.HelpBox($"il2cpp 版本不兼容,最小版本为 {m_Controller.GetMinCompatibleVersion(m_Controller.Il2CppBranch)}", MessageType.Error); - break; - } + { + EditorGUILayout.HelpBox($"il2cpp 版本不兼容,最小版本为 {m_Controller.GetMinCompatibleVersion(m_Controller.Il2CppBranch)}", MessageType.Error); + break; + } case InstallErrorCode.NotIl2CppPath: - { - EditorGUILayout.HelpBox($"当前选择的路径不是il2cpp目录(必须类似 xxx/il2cpp)", MessageType.Error); - break; - } + { + EditorGUILayout.HelpBox($"当前选择的路径不是il2cpp目录(必须类似 xxx/il2cpp)", MessageType.Error); + break; + } default: throw new Exception($"not support {err}"); } } diff --git a/Runtime/RuntimeApi.cs b/Runtime/RuntimeApi.cs index 417c737..84552c8 100644 --- a/Runtime/RuntimeApi.cs +++ b/Runtime/RuntimeApi.cs @@ -18,6 +18,18 @@ namespace HybridCLR private const string dllName = "il2cpp"; #endif + public static unsafe LoadImageErrorCode LoadMetadataForAOTAssembly(byte[] dllBytes) + { +#if UNITY_EDITOR + throw new NotSupportedException("LoadMetadataForAOTAssembly can only be invoked in il2cpp"); +#else + fixed(byte* data = dllBytes) + { + return (LoadImageErrorCode)LoadMetadataForAOTAssembly((IntPtr)data, dllBytes.Length); + } +#endif + } + [DllImport(dllName, EntryPoint = "RuntimeApi_LoadMetadataForAOTAssembly")] public static extern int LoadMetadataForAOTAssembly(IntPtr dllBytes, int dllSize); diff --git a/package.json b/package.json index 1261e6a..a94c781 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.focus-creative-games.hybridclr_unity", - "version": "0.3.3", + "version": "0.3.4", "displayName": "HybridCLR", "description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR", "category": "Runtime",