Compare commits

..

40 Commits

Author SHA1 Message Date
walon a5238bcd29 [merge] 从main分支合并assembly resolver改动,修复计算桥接函数使用editor dll造成的签名错误的问题 2023-01-05 11:28:31 +08:00
walon 12dd5d8685 [fix] 修复Installer不同的Unity年度版本仍然读取相同的hybridclr及il2cpp_plus版本号配置,导致切换Unity版本时有可能发生默认显示的版本号错误的问题 2022-12-29 20:45:29 +08:00
walon feb8ed3206 [opt] installer安装成功后会记录 安装的版本,并且显示。 2022-12-21 12:46:15 +08:00
walon 6939d16b6c [refactor] 重构Installer,不再支持从其他版本安装HybridCLR,极大简化了代码。 2022-12-21 12:43:12 +08:00
walon ca143691aa [change] 移除HybridCLR.Runtime中DHE相关代码 2022-12-21 12:19:24 +08:00
walon f62a2fedb0 [change] 移除DHE相关代码 2022-12-21 12:18:47 +08:00
walon 2effa79f6d [change] 禁用HybridCLR时不再复制裁剪后的AOT dll
[new] SettingsUtil.Enable 支持setter,允许代码中修改开启状态。
2022-12-21 12:17:51 +08:00
walon 00cedc166f [fix] 修复macOS下的编译bug 2022-12-16 11:23:37 +08:00
walon 0e04a66c91 [new] 新增菜单命令 HybridCLR/Generate/AOTDlls 快捷生成裁剪后的AOT dlls 2022-12-16 11:03:03 +08:00
walon 00f94335c3 [refactor] 重构并且修复了Generate相关Assembly Resolve潜在的bug。
[opt] 优化 PrebuildCommand.Build 中多次编译热更新dll的问题,大幅缩短了时间。
2022-12-14 14:11:32 +08:00
walon 1a23268b03 [fix] 修复StructLayout中只指定LayoutKind参数时,struct的ClassLayout为空,计算type size和aligment错误的bug 2022-12-14 10:44:49 +08:00
walon 947b15e7d9 [fix] 修复StructLayout中只指定LayoutKind参数时,struct的ClassLayout为空,计算type size和aligment错误的bug 2022-12-14 10:21:31 +08:00
walon b40d62e16e [opt] 优化link.xml生成,只加载热更新dll,不再加载它们依赖的其他dll 2022-12-13 18:10:20 +08:00
walon c8acfef61d [fix] 修复 externalHotUpdateAssembliyDirs 无法正确工作的bug 2022-12-13 11:40:18 +08:00
walon e5c3bfa184 [fix] 修复 ReversePInvokeWrap生成代码的bug 2022-12-12 21:37:29 +08:00
walon 8afdcb985d [fix] 修复 ReversePInvokeWrap生成代码的bug 2022-12-12 21:36:41 +08:00
walon 9bb1b6054e [fix] 修复生成N2M桥接函数Stub时,失误将末尾项的sinature填成""的bug,正确应该是nullptr 2022-12-12 12:02:42 +08:00
walon a107f43173 [fix] 修复生成N2M桥接函数Stub时,失误将末尾项的sinature填成""的bug,正确应该是nullptr 2022-12-12 12:01:02 +08:00
walon ef0db32fc1 [fix] 修复生成桥接函数时不必要地多次调用 CleanIl2CppBuildCache,并有可能因并发清除而抛出异常的问题 2022-12-09 18:21:08 +08:00
walon f0230149ce [fix] 修复macOS下项目Unity版本与HybridCLR要求版本不兼容时尝试扫描兼容版本的目录层级错误的bug 2022-12-09 18:17:42 +08:00
walon 0edd822101 [fix] 修复生成桥接函数时不必要地多次调用 CleanIl2CppBuildCache,并有可能因并发清除而抛出异常的问题 2022-12-08 22:19:27 +08:00
walon 419c3a98f6 [opt] installer安装成功后会记录 安装的版本,并且显示。 2022-12-06 18:57:48 +08:00
walon 0401d638a1 [fix] 修复installer中未填hybridclr及il2cpp_plus版本号时hybridclr取main分支最新版本,而il2cpp_plus取1.0分支版本,导致版本不匹配而崩溃的bug 2022-12-06 14:32:54 +08:00
walon 4ea1798700 [change] il2cpp_plus启动新的分支名 2019-main、2020-main、2021-main,相应调整代码
[opt] 优化installer的显示
2022-12-06 14:19:17 +08:00
walon 6be8b2671e [refactor] 重构Installer,不再支持从其他版本安装HybridCLR,极大简化了代码。 2022-12-06 11:52:47 +08:00
walon 38615500fb [change] 移除HybridCLR.Runtime中DHE相关代码 2022-12-04 21:37:17 +08:00
walon e7fac5b0b8 [change] 移除DHE相关代码 2022-12-03 11:56:36 +08:00
walon bc6e285b92 [change] 禁用HybridCLR时不再复制裁剪后的AOT dll
[new] SettingsUtil.Enable 支持setter,允许代码中修改开启状态。
2022-12-02 13:14:06 +08:00
walon abc70a7ffc [new] 支持自定义外部热更新dll的搜索路径 externalHotUpdateAssembliyDirs 2022-12-02 10:33:13 +08:00
walon eee3dbaa69 [fix] 修复??=语法在2019下编译出错的bug 2022-12-01 08:50:40 +08:00
walon 45d97d758f [change] 桥接函数生成时,新增跟旧版本一样的托底AssemblyResolver,避免初始项目第一次 generate/all 失败的情况 2022-11-30 17:31:11 +08:00
walon b066cc50fa [fix] 修复??=语法在2019下编译出错的bug 2022-11-30 09:21:25 +08:00
walon 93f855f8ae [fix] 修复生成桥接函数时错误使用editor环境的dll,导致NativeArray之类的类型与打包的aot dll不一致,进而生成桥接签名错误的bug。目前直接从裁剪后的AOT dll目录读取,但缺点是需要先build一次生成AOT dll,再生成桥接函数。 2022-11-29 17:11:25 +08:00
walon 5270f307b9 [change] il2cpp_plus启动新的分支名 2019-main、2020-main、2021-main,相应调整代码
[opt] 优化installer的显示
2022-11-29 09:23:24 +08:00
walon f36da3529a [new] 支持按版本号安装hybridclr和il2cpp_plus代码 2022-11-28 12:20:52 +08:00
walon 521db6e38c [new] 创建1.0.0版本 2022-11-28 11:11:28 +08:00
walon c85adbe65b [refactor] UNITY_VERSION 相关定义从 Il2CppCompatibleDef.h 移到 il2cpp-config.h 2022-11-24 12:09:04 +08:00
walon b9ea9b21f3 [fix] 修复扫描Plugin assembly时未忽略~结尾的目录的bug 2022-11-18 19:38:21 +08:00
walon 429845bf9e [new] installer支持使用自定义仓库地址
[opt] 优化installer的显示
2022-11-09 11:28:09 +08:00
walon c95b7eaf3b [new] 为测试openupm而升到0.10.3 2022-11-07 15:27:38 +08:00
48 changed files with 534 additions and 879 deletions
+5
View File
@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace HybridCLR.Editor.ABI
{
@@ -74,6 +75,10 @@ namespace HybridCLR.Editor.ABI
case ElementType.ValueType:
{
TypeDef typeDef = type.ToTypeDefOrRef().ResolveTypeDef();
if (typeDef == null)
{
throw new Exception($"type:{type} 未能找到定义。请尝试 `HybridCLR/Genergate/LinkXml`,然后Build一次生成AOT dll,再重新生成桥接函数");
}
if (typeDef.IsEnum)
{
return CreateTypeInfo(typeDef.GetEnumUnderlyingType());
@@ -74,11 +74,11 @@ namespace HybridCLR.Editor.ABI
{
continue;
}
if (sa != null && typeDef.Layout.HasFlag(dnlib.DotNet.TypeAttributes.ExplicitLayout))
if (typeDef.Layout.HasFlag(dnlib.DotNet.TypeAttributes.ExplicitLayout))
{
int offset = (int)field.FieldOffset.Value;
totalSize = Math.Max(totalSize, offset + fs);
if (offset > sa.ClassSize)
if (sa != null && offset > sa.ClassSize)
{
useSLSize = false;
}
@@ -90,7 +90,7 @@ namespace HybridCLR.Editor.ABI
totalSize = (totalSize + fa - 1) / fa * fa;
}
totalSize += fs;
if (sa != null && typeDef.Layout.HasFlag(dnlib.DotNet.TypeAttributes.SequentialLayout) && totalSize > sa.ClassSize)
if (sa != null && totalSize > sa.ClassSize)
{
useSLSize = false;
}
@@ -57,6 +57,11 @@ namespace HybridCLR.Editor.BuildProcessors
public static void CopyStripDlls(string srcStripDllPath, BuildTarget target)
{
if (!SettingsUtil.Enable)
{
Debug.Log($"[CopyStrippedAOTAssemblies] disabled");
return;
}
Debug.Log($"[CopyStrippedAOTAssemblies] CopyScripDlls. src:{srcStripDllPath} target:{target}");
var dstPath = SettingsUtil.GetAssembliesPostIl2CppStripDir(target);
@@ -1,4 +1,5 @@
using System;
using HybridCLR.Editor.Meta;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -23,11 +24,12 @@ namespace HybridCLR.Editor.BuildProcessors
Debug.Log($"[FilterHotFixAssemblies] disabled");
return assemblies;
}
List<string> allHotUpdateDllFiles = SettingsUtil.HotUpdateAssemblyFiles;
List<string> allHotUpdateDllNames = SettingsUtil.HotUpdateAssemblyNames;
List<string> allHotupdateDllFiles = SettingsUtil.HotUpdateAssemblyFiles;
// 检查是否重复填写
var hotUpdateDllSet = new HashSet<string>();
foreach(var hotUpdateDll in allHotUpdateDllFiles)
foreach(var hotUpdateDll in allHotUpdateDllNames)
{
if (!hotUpdateDllSet.Add(hotUpdateDll))
{
@@ -35,18 +37,20 @@ namespace HybridCLR.Editor.BuildProcessors
}
}
var assResolver = MetaUtil.CreateHotUpdateAssemblyResolver(EditorUserBuildSettings.activeBuildTarget, allHotUpdateDllNames);
// 检查是否填写了正确的dll名称
foreach (var hotUpdateDll in allHotUpdateDllFiles)
foreach (var hotUpdateDllName in allHotUpdateDllNames)
{
if (assemblies.All(ass => !ass.EndsWith(hotUpdateDll)))
string hotUpdateDllFile = hotUpdateDllName + ".dll";
if (assemblies.All(ass => !ass.EndsWith(hotUpdateDllFile)) && string.IsNullOrEmpty(assResolver.ResolveAssembly(hotUpdateDllName, false)))
{
throw new Exception($"热更新 assembly:{hotUpdateDll} 不存在,请检查拼写错误");
throw new Exception($"热更新 assembly:{hotUpdateDllFile} 不存在,请检查拼写错误");
}
Debug.Log($"[FilterHotFixAssemblies] 过滤热更新assembly:{hotUpdateDll}");
Debug.Log($"[FilterHotFixAssemblies] 过滤热更新assembly:{hotUpdateDllFile}");
}
// 将热更dll从打包列表中移除
return assemblies.Where(ass => allHotUpdateDllFiles.All(dll => !ass.EndsWith(dll, StringComparison.OrdinalIgnoreCase))).ToArray();
return assemblies.Where(ass => allHotupdateDllFiles.All(dll => !ass.EndsWith(dll, StringComparison.OrdinalIgnoreCase))).ToArray();
}
}
}
@@ -14,23 +14,19 @@ namespace HybridCLR.Editor.Commands
{
[MenuItem("HybridCLR/Generate/AOTGenericReference", priority = 102)]
public static void GenerateAOTGenericReference()
public static void CompileAndGenerateAOTGenericReference()
{
GenerateAOTGenericReference(true);
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
CompileDllCommand.CompileDll(target);
GenerateAOTGenericReference(target);
}
public static void GenerateAOTGenericReference(bool compileDll)
public static void GenerateAOTGenericReference(BuildTarget target)
{
// 此处理论会有点问题,打每个平台的时候,都得针对当前平台生成桥接函数
// 但影响不大,先这样吧
if (compileDll)
{
CompileDllCommand.CompileDllActiveBuildTarget();
}
var gs = SettingsUtil.HybridCLRSettings;
List<string> hotUpdateDllNames = SettingsUtil.HotUpdateAssemblyNames;
using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), SettingsUtil.HotUpdateAssemblyNames))
using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotUpdateDllNames), hotUpdateDllNames))
{
var analyzer = new Analyzer(new Analyzer.Options
{
@@ -1,56 +0,0 @@
using HybridCLR.Editor.DHE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
namespace HybridCLR.Editor.Commands
{
public static class DifferentialHybridExecutionCommand
{
[MenuItem("HybridCLR/Generate/DHEAssemblyList", priority = 110)]
public static void GenerateAssemblyList()
{
var options = new AssemblyListGenerator.Options()
{
DifferentialHybridAssembyList = (HybridCLRSettings.Instance.differentialHybridAssemblies ?? Array.Empty<string>()).ToList(),
OutputFile = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/hybridclr/Il2CppCompatibleDef.cpp",
};
var g = new AssemblyListGenerator(options);
g.Generate();
}
[MenuItem("HybridCLR/Generate/DHEAssemblyOptionDatas", priority = 111)]
public static void GenerateAssemblyOptionDatas()
{
GenerateAssemblyOptionDatas(true);
}
public static void GenerateAssemblyOptionDatas(bool compileDll)
{
if (compileDll)
{
CompileDllCommand.CompileDllActiveBuildTarget();
}
string[] differentialHybridAssemblyList = HybridCLRSettings.Instance.differentialHybridAssemblies;
if (differentialHybridAssemblyList == null || differentialHybridAssemblyList.Length == 0)
{
Debug.Log("[DifferentialHybridExecutionCommand.GenerateAssemblyOptionDatas] differentialHybridAssemblies is empty. skip generation.");
return;
}
var options = new AssemblyOptionDataGenerator.Options()
{
DifferentialHybridAssembyList = differentialHybridAssemblyList.ToList(),
OutputDir = $"{SettingsUtil.ProjectDir}/{HybridCLRSettings.Instance.differentialHybridOptionOutputDir}",
};
var g = new AssemblyOptionDataGenerator(options);
g.Generate();
}
}
}
+2 -2
View File
@@ -17,8 +17,8 @@ namespace HybridCLR.Editor.Commands
{
var options = new Il2CppDef.Il2CppDefGenerator.Options()
{
UnityVersion = UnityEngine.Application.unityVersion,
OutputFile = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/hybridclr/Il2CppCompatibleDef.h",
UnityVersion = Application.unityVersion,
OutputFile = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/il2cpp-config.h",
};
var g = new Il2CppDef.Il2CppDefGenerator(options);
+9 -28
View File
@@ -1,4 +1,5 @@
using HybridCLR.Editor.Link;
using HybridCLR.Editor.Meta;
using System;
using System.Collections.Generic;
using System.Reflection;
@@ -14,41 +15,21 @@ namespace HybridCLR.Editor.Commands
[MenuItem("HybridCLR/Generate/LinkXml", priority = 100)]
public static void GenerateLinkXml()
{
GenerateLinkXml(true);
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
CompileDllCommand.CompileDll(target);
GenerateLinkXml(target);
}
public static void GenerateLinkXml(bool compileDll)
public static void GenerateLinkXml(BuildTarget target)
{
if (compileDll)
{
CompileDllCommand.CompileDllActiveBuildTarget();
}
var ls = SettingsUtil.HybridCLRSettings;
var allAssByNames = new Dictionary<string, Assembly>();
foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())
{
allAssByNames[ass.GetName().Name] = ass;
}
List<string> hotfixAssemblies = SettingsUtil.HotUpdateAssemblyNames;
var hotfixAssembles = new List<Assembly>();
foreach(var assName in SettingsUtil.HotUpdateAssemblyNames)
{
if (allAssByNames.TryGetValue(assName, out var ass))
{
hotfixAssembles.Add(ass);
}
else
{
throw new Exception($"assembly:{assName} 不存在");
}
}
var analyzer = new Analyzer(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotfixAssemblies), HybridCLRSettings.Instance.collectAssetReferenceTypes);
var refTypes = analyzer.CollectRefs(hotfixAssemblies);
var analyzer = new Analyzer(Meta.MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), HybridCLRSettings.Instance.collectAssetReferenceTypes);
var refTypes = analyzer.CollectRefs(hotfixAssembles);
Debug.Log($"[LinkGeneratorCommand] hotfix assembly count:{hotfixAssembles.Count}, ref type count:{refTypes.Count} output:{Application.dataPath}/{ls.outputLinkFile}");
Debug.Log($"[LinkGeneratorCommand] hotfix assembly count:{hotfixAssemblies.Count}, ref type count:{refTypes.Count} output:{Application.dataPath}/{ls.outputLinkFile}");
var linkXmlWriter = new LinkXmlWriter();
linkXmlWriter.Write($"{Application.dataPath}/{ls.outputLinkFile}", refTypes);
AssetDatabase.Refresh();
@@ -42,25 +42,20 @@ namespace HybridCLR.Editor.Commands
g.PrepareMethods();
g.Generate();
Debug.LogFormat("== output:{0} ==", outputFile);
CleanIl2CppBuildCache();
}
[MenuItem("HybridCLR/Generate/MethodBridge", priority = 101)]
public static void GenerateMethodBridge()
public static void CompileAndGenerateMethodBridge()
{
GenerateMethodBridge(true);
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
CompileDllCommand.CompileDll(target);
GenerateMethodBridge(target);
}
public static void GenerateMethodBridge(bool compileDll)
public static void GenerateMethodBridge(BuildTarget target)
{
// 此处理论会有点问题,打每个平台的时候,都得针对当前平台生成桥接函数
// 但影响不大,先这样吧
if (compileDll)
{
CompileDllCommand.CompileDllActiveBuildTarget();
}
using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), SettingsUtil.HotUpdateAssemblyNames))
List<string> hotUpdateDllNames = SettingsUtil.HotUpdateAssemblyNames;
using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotUpdateDllNames), hotUpdateDllNames))
{
var analyzer = new Analyzer(new Analyzer.Options
{
@@ -83,6 +78,7 @@ namespace HybridCLR.Editor.Commands
Task.WaitAll(tasks.ToArray());
}
CleanIl2CppBuildCache();
}
}
}
+11 -9
View File
@@ -15,18 +15,20 @@ namespace HybridCLR.Editor.Commands
[MenuItem("HybridCLR/Generate/All", priority = 200)]
public static void GenerateAll()
{
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
CompileDllCommand.CompileDll(target);
Il2CppDefGeneratorCommand.GenerateIl2CppDef();
DifferentialHybridExecutionCommand.GenerateAssemblyList();
DifferentialHybridExecutionCommand.GenerateAssemblyOptionDatas();
// 顺序随意
ReversePInvokeWrapperGeneratorCommand.GenerateReversePInvokeWrapper();
// AOTReferenceGeneratorCommand 涉及到代码生成,必须在MethodBridgeGeneratorCommand之前
AOTReferenceGeneratorCommand.GenerateAOTGenericReference();
MethodBridgeGeneratorCommand.GenerateMethodBridge();
// 这几个生成依赖HotUpdateDlls
LinkGeneratorCommand.GenerateLinkXml(target);
// 顺序随意,只要保证 GenerateLinkXml之前有调用过CompileDll即可
LinkGeneratorCommand.GenerateLinkXml(false);
// 生成裁剪后的aot dll
StripAOTDllCommand.GenerateStripedAOTDlls(target, EditorUserBuildSettings.selectedBuildTargetGroup);
// 桥接函数生成依赖于AOT dll,必须保证已经build过,生成AOT dll
MethodBridgeGeneratorCommand.GenerateMethodBridge(target);
ReversePInvokeWrapperGeneratorCommand.GenerateReversePInvokeWrapper(target);
AOTReferenceGeneratorCommand.GenerateAOTGenericReference(target);
}
}
}
@@ -19,12 +19,20 @@ namespace HybridCLR.Editor.Commands
{
[MenuItem("HybridCLR/Generate/ReversePInvokeWrapper", priority = 103)]
public static void GenerateReversePInvokeWrapper()
public static void CompileAndGenerateReversePInvokeWrapper()
{
CompileDllCommand.CompileDllActiveBuildTarget();
using (var cache = new AssemblyCache(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget)))
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
CompileDllCommand.CompileDll(target);
GenerateReversePInvokeWrapper(target);
}
public static void GenerateReversePInvokeWrapper(BuildTarget target)
{
List<string> hotUpdateDlls = SettingsUtil.HotUpdateAssemblyNames;
using (var cache = new AssemblyCache(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotUpdateDlls)))
{
var analyzer = new ReversePInvokeWrap.Analyzer(cache, SettingsUtil.HotUpdateAssemblyNames);
var analyzer = new ReversePInvokeWrap.Analyzer(cache, hotUpdateDlls);
analyzer.Run();
+119
View File
@@ -0,0 +1,119 @@
using HybridCLR.Editor.Installer;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
namespace HybridCLR.Editor.Commands
{
public static class StripAOTDllCommand
{
[MenuItem("HybridCLR/Generate/AOTDlls", priority = 105)]
public static void GenerateStripedAOTDlls()
{
GenerateStripedAOTDlls(EditorUserBuildSettings.activeBuildTarget, EditorUserBuildSettings.selectedBuildTargetGroup);
}
private static string GetLocationPathName(string buildDir, BuildTarget target)
{
switch(target)
{
case BuildTarget.StandaloneWindows:
case BuildTarget.StandaloneWindows64: return $"{buildDir}/{target}";
case BuildTarget.StandaloneOSX: return buildDir;
case BuildTarget.iOS: return buildDir;
case BuildTarget.Android: return buildDir;
case BuildTarget.StandaloneLinux64: return buildDir;
default: return buildDir;
}
}
public static void GenerateStripedAOTDlls(BuildTarget target, BuildTargetGroup group)
{
string outputPath = $"{SettingsUtil.HybridCLRDataDir}/StrippedAOTDllsTempProj/{target}";
BashUtil.RemoveDir(outputPath);
var buildOptions = BuildOptions.BuildScriptsOnly;
bool oldExportAndroidProj = EditorUserBuildSettings.exportAsGoogleAndroidProject;
#if UNITY_EDITOR_OSX
bool oldCreateSolution = UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject;
#elif UNITY_EDITOR_WIN
bool oldCreateSolution = UnityEditor.WindowsStandalone.UserBuildSettings.createSolution;
#endif
bool oldBuildScriptsOnly = EditorUserBuildSettings.buildScriptsOnly;
EditorUserBuildSettings.buildScriptsOnly = true;
switch (target)
{
case BuildTarget.StandaloneWindows:
case BuildTarget.StandaloneWindows64:
{
#if UNITY_EDITOR_WIN
UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = true;
#endif
break;
}
case BuildTarget.StandaloneOSX:
{
#if UNITY_EDITOR_OSX
UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject = true;
#endif
break;
}
case BuildTarget.Android:
{
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
break;
}
}
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions()
{
scenes = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(),
locationPathName = GetLocationPathName(outputPath, target),
options = buildOptions,
target = target,
targetGroup = group,
};
var report = BuildPipeline.BuildPlayer(buildPlayerOptions);
EditorUserBuildSettings.buildScriptsOnly = oldBuildScriptsOnly;
switch (target)
{
case BuildTarget.StandaloneWindows:
case BuildTarget.StandaloneWindows64:
{
#if UNITY_EDITOR_WIN
UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = oldCreateSolution;
#endif
break;
}
case BuildTarget.StandaloneOSX:
{
#if UNITY_EDITOR_OSX
UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject = oldCreateSolution;
#endif
break;
}
case BuildTarget.Android:
{
EditorUserBuildSettings.exportAsGoogleAndroidProject = oldExportAndroidProj;
break;
}
}
if (report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded)
{
Debug.LogError("GenerateStripedAOTDlls 失败");
return;
}
Debug.Log($"GenerateStripedAOTDlls target:{target} group:{group} path:{outputPath}");
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: d6be260bc9a8a40468a82b9ea49b89a1
guid: 21fb0a02f23185141a4a3df67fe61789
MonoImporter:
externalObjects: {}
serializedVersion: 2
-8
View File
@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 1e6e11530acf7134796d0a439a6bbe61
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
-44
View File
@@ -1,44 +0,0 @@
using HybridCLR.Editor.Template;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using UnityEngine;
namespace HybridCLR.Editor.DHE
{
public class AssemblyListGenerator
{
public class Options
{
public string OutputFile { get; set; }
public List<string> DifferentialHybridAssembyList { get; set; }
}
private readonly Options _options;
public AssemblyListGenerator(Options options)
{
_options = options;
}
public void Generate()
{
var frr = new FileRegionReplace(File.ReadAllText(_options.OutputFile));
List<string> lines = new List<string>();
foreach (var ass in _options.DifferentialHybridAssembyList)
{
lines.Add($"\t\t\"{ass}\",");
}
frr.Replace("DHE", string.Join("\n", lines));
frr.Commit(_options.OutputFile);
Debug.Log($"output:{_options.OutputFile}");
}
}
}
-68
View File
@@ -1,68 +0,0 @@
using dnlib.DotNet;
using HybridCLR.Editor.Commands;
using HybridCLR.Editor.Meta;
using HybridCLR.Runtime;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
namespace HybridCLR.Editor.DHE
{
public class AssemblyOptionDataGenerator
{
public class Options
{
public string OutputDir { get; set; }
public List<string> DifferentialHybridAssembyList { get; set; }
}
private readonly Options _options;
public AssemblyOptionDataGenerator(Options options)
{
_options = options;
}
public void Generate()
{
foreach(string assName in _options.DifferentialHybridAssembyList)
{
using (var assCollector = new AssemblyCache(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget)))
{
var ass = assCollector.LoadModule(assName);
var dhaOptions = new DifferentialHybridAssemblyOptions()
{
notChangeMethodTokens = new List<uint>(),
};
foreach (var type in ass.GetTypes())
{
foreach (var method in type.Methods)
{
var attr = method.CustomAttributes.Where(a => a.AttributeType.FullName == "HybridCLR.Runtime.UnchangedAttribute").FirstOrDefault();
if (attr != null)
{
if ((bool)attr.ConstructorArguments[0].Value)
{
dhaOptions.notChangeMethodTokens.Add(method.MDToken.Raw);
Debug.Log($"Unchanged method:{method.MDToken.Raw} {method}");
}
}
}
}
string outOptionFile = $"{_options.OutputDir}/{assName}.dhao.bytes";
File.WriteAllBytes(outOptionFile, dhaOptions.Marshal());
Debug.Log($"[AssemblyOptionDataGenerator] assembly:{ass} output:{outOptionFile}");
}
}
}
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 4a4eda50e51d72d499b439da236a8371
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+1 -1
View File
@@ -50,7 +50,7 @@ namespace HybridCLR.Editor.Il2CppDef
}
}
frr.Replace("UNITY_CONFIG", string.Join("\n", lines));
frr.Replace("UNITY_VERSION", string.Join("\n", lines));
frr.Commit(_options.OutputFile);
Debug.Log($"[HybridCLR.Editor.Il2CppDef.Generator] output:{_options.OutputFile}");
+10 -4
View File
@@ -10,7 +10,7 @@ namespace HybridCLR.Editor.Installer
{
public static class BashUtil
{
public static int RunCommand(string workingDir, string program, string[] args)
public static int RunCommand(string workingDir, string program, string[] args, bool log = true)
{
using (Process p = new Process())
{
@@ -20,7 +20,10 @@ namespace HybridCLR.Editor.Installer
p.StartInfo.CreateNoWindow = true;
string argsStr = string.Join(" ", args.Select(arg => "\"" + arg + "\""));
p.StartInfo.Arguments = argsStr;
UnityEngine.Debug.Log($"[BashUtil] run => {program} {argsStr}");
if (log)
{
UnityEngine.Debug.Log($"[BashUtil] run => {program} {argsStr}");
}
p.Start();
p.WaitForExit();
return p.ExitCode;
@@ -28,7 +31,7 @@ namespace HybridCLR.Editor.Installer
}
public static (int ExitCode, string StdOut, string StdErr) RunCommand2(string workingDir, string program, string[] args)
public static (int ExitCode, string StdOut, string StdErr) RunCommand2(string workingDir, string program, string[] args, bool log = true)
{
using (Process p = new Process())
{
@@ -40,7 +43,10 @@ namespace HybridCLR.Editor.Installer
p.StartInfo.RedirectStandardError = true;
string argsStr = string.Join(" ", args.Select(arg => "\"" + arg + "\""));
p.StartInfo.Arguments = argsStr;
UnityEngine.Debug.Log($"[BashUtil] run => {program} {argsStr}");
if (log)
{
UnityEngine.Debug.Log($"[BashUtil] run => {program} {argsStr}");
}
p.Start();
p.WaitForExit();
+130 -180
View File
@@ -18,59 +18,35 @@ namespace HybridCLR.Editor.Installer
public enum InstallErrorCode
{
Ok,
InvalidUnityInstallPath,
Il2CppInstallPathNotMatchIl2CppBranch,
Il2CppInstallPathNotExists,
NotIl2CppPath,
}
public partial class InstallerController
{
private const string hybridclr_repo_path = "hybridclr_repo";
private const string hybridclr_url = "hybridclr";
private const string il2cpp_plus_repo_path = "il2cpp_plus_repo";
private const string il2cpp_plus_url = "il2cpp_plus";
private string m_Il2CppInstallDirectory;
public string Il2CppInstallDirectory
{
get
{
return m_Il2CppInstallDirectory;
}
set
{
m_Il2CppInstallDirectory = value?.Replace('\\', '/');
if (!string.IsNullOrEmpty(m_Il2CppInstallDirectory))
{
EditorPrefs.SetString("UnityInstallDirectory", m_Il2CppInstallDirectory);
}
}
}
private string GetIl2CppPlusBranchByUnityVersion(string unityVersion)
{
if (unityVersion.Contains("2019."))
{
return "2019.4.40";
}
if (unityVersion.Contains("2020."))
{
return "2020.3.33";
}
if (unityVersion.Contains("2021."))
{
return "2021.3.1";
}
return "not support";
}
public int MajorVersion => _curVersion.major;
public string Il2CppBranch => GetIl2CppPlusBranchByUnityVersion(Application.unityVersion);
private UnityVersion _curVersion;
public InstallerController()
{
PrepareIl2CppInstallPath();
_curVersion = ParseUnityVersion(Application.unityVersion);
}
public class UnityVersion
{
public int major;
public int minor1;
public int minor2;
public override string ToString()
{
return $"{major}.{minor1}.{minor2}";
}
}
private static readonly Regex s_unityVersionPat = new Regex(@"(\d+)\.(\d+)\.(\d+)");
@@ -79,145 +55,143 @@ namespace HybridCLR.Editor.Installer
public const int min2020_3_CompatibleMinorVersion = 21;
public const int min2021_3_CompatibleMinorVersion = 0;
private bool TryParseMinorVersion(string installDir, out (int Major, int Minor1, int Minor2) unityVersion)
private UnityVersion ParseUnityVersion(string versionStr)
{
var matches = s_unityVersionPat.Matches(installDir);
var matches = s_unityVersionPat.Matches(versionStr);
if (matches.Count == 0)
{
unityVersion = default;
return false;
return null;
}
// 找最后一个匹配的,有的人居然会把Unity安装目录放到其他安装版本下。无语!
// 找最后一个匹配的
Match match = matches[matches.Count - 1];
// Debug.Log($"capture count:{match.Groups.Count} {match.Groups[1].Value} {match.Groups[2].Value}");
int major = int.Parse(match.Groups[1].Value);
int minor1 = int.Parse(match.Groups[2].Value);
int minor2 = int.Parse(match.Groups[3].Value);
unityVersion = (major, minor1, minor2);
return true;
return new UnityVersion { major = major, minor1 = minor1, minor2 = minor2 };
}
public string GetCurVersionStr(string installDir)
public string GetCurrentUnityVersionMinCompatibleVersionStr()
{
if (TryParseMinorVersion(installDir, out var version))
{
return $"{version.Major}.{version.Minor1}.{version.Minor2}";
}
throw new Exception($"not support version:{installDir}");
return GetMinCompatibleVersion(MajorVersion);
}
public string GetMinCompatibleVersion(string branch)
public string GetMinCompatibleVersion(int majorVersion)
{
switch(branch)
switch(majorVersion)
{
case "2019.4.40": return $"2019.4.{min2019_4_CompatibleMinorVersion}";
case "2020.3.33": return $"2020.3.{min2020_3_CompatibleMinorVersion}";
case "2021.3.1": return $"2021.3.{min2021_3_CompatibleMinorVersion}";
default: throw new Exception($"not support version:{branch}");
case 2019: return $"2019.4.{min2019_4_CompatibleMinorVersion}";
case 2020: return $"2020.3.{min2020_3_CompatibleMinorVersion}";
case 2021: return $"2021.3.{min2021_3_CompatibleMinorVersion}";
default: throw new Exception($"not support version:{majorVersion}");
}
}
private bool IsComaptibleWithIl2CppPlusBranch(string branch, string installDir)
public bool IsComaptibleVersion()
{
if (!TryParseMinorVersion(installDir, out var unityVersion))
UnityVersion version = _curVersion;
switch (version.major)
{
return false;
}
switch(branch)
{
case "2019.4.40":
case 2019:
{
if (unityVersion.Major != 2019 || unityVersion.Minor1 != 4)
if (version.major != 2019 || version.minor1 != 4)
{
return false;
}
return unityVersion.Minor2 >= min2019_4_CompatibleMinorVersion;
return version.minor2 >= min2019_4_CompatibleMinorVersion;
}
case "2020.3.33":
case 2020:
{
if (unityVersion.Major != 2020 || unityVersion.Minor1 != 3)
if (version.major != 2020 || version.minor1 != 3)
{
return false;
}
return unityVersion.Minor2 >= min2020_3_CompatibleMinorVersion;
return version.minor2 >= min2020_3_CompatibleMinorVersion;
}
case "2021.3.1":
case 2021:
{
if (unityVersion.Major != 2021 || unityVersion.Minor1 != 3)
if (version.major != 2021 || version.minor1 != 3)
{
return false;
}
return unityVersion.Minor2 >= min2021_3_CompatibleMinorVersion;
return version.minor2 >= min2021_3_CompatibleMinorVersion;
}
default: throw new Exception($"not support il2cpp_plus branch:{branch}");
default: throw new Exception($"not support il2cpp_plus branch:{version.major}");
}
}
void PrepareIl2CppInstallPath()
private string _hybridclrLocalVersion;
public string HybridclrLocalVersion => _hybridclrLocalVersion != null ? _hybridclrLocalVersion : _hybridclrLocalVersion = GetHybridCLRLocalVersion();
public string HybridCLRRepoInstalledVersion
{
#if UNITY_EDITOR_WIN
m_Il2CppInstallDirectory = EditorPrefs.GetString("Il2CppInstallDirectory");
if (CheckValidIl2CppInstallDirectory(Il2CppBranch, m_Il2CppInstallDirectory) == InstallErrorCode.Ok)
{
return;
}
var il2cppBranch = Il2CppBranch;
var curAppInstallPath = EditorApplication.applicationPath;
if (IsComaptibleWithIl2CppPlusBranch(il2cppBranch, curAppInstallPath))
{
Il2CppInstallDirectory = $"{Directory.GetParent(curAppInstallPath)}/Data/il2cpp";
return;
}
string unityHubRootDir = Directory.GetParent(curAppInstallPath).Parent.Parent.ToString();
// Debug.Log("unity hub root dir:" + unityHubRootDir);
foreach (var unityInstallDir in Directory.GetDirectories(unityHubRootDir, "*", SearchOption.TopDirectoryOnly))
{
// Debug.Log("Unity install dir:" + unityInstallDir);
if (IsComaptibleWithIl2CppPlusBranch(il2cppBranch, unityInstallDir))
{
Il2CppInstallDirectory = $"{unityInstallDir}/Editor/Data/il2cpp";
return;
}
}
Il2CppInstallDirectory = $"{Directory.GetParent(curAppInstallPath)}/Data/il2cpp";
#else
m_Il2CppInstallDirectory = EditorPrefs.GetString("Il2CppInstallDirectory");
if (CheckValidIl2CppInstallDirectory(Il2CppBranch, m_Il2CppInstallDirectory) == InstallErrorCode.Ok)
{
return;
}
var il2cppBranch = Il2CppBranch;
var curAppInstallPath = EditorApplication.applicationPath;
if (IsComaptibleWithIl2CppPlusBranch(il2cppBranch, curAppInstallPath))
{
Il2CppInstallDirectory = $"{curAppInstallPath}/Contents/il2cpp";
return;
}
string unityHubRootDir = Directory.GetParent(curAppInstallPath).Parent.Parent.ToString();
foreach (var unityInstallDir in Directory.GetDirectories(unityHubRootDir, "*", SearchOption.TopDirectoryOnly))
{
Debug.Log("nity install dir:" + unityInstallDir);
if (IsComaptibleWithIl2CppPlusBranch(il2cppBranch, unityInstallDir))
{
Il2CppInstallDirectory = $"{unityInstallDir}/Unity.app/Contents/il2cpp";
return;
}
}
Il2CppInstallDirectory = $"{curAppInstallPath}/Contents/il2cpp";
#endif
get { return EditorPrefs.GetString($"hybridclr_repo#{MajorVersion}"); }
set { EditorPrefs.SetString($"hybridclr_repo#{MajorVersion}", value); }
}
public void InitHybridCLR(string il2cppBranch, string il2cppInstallPath)
public string Il2CppRepoInstalledVersion
{
if (CheckValidIl2CppInstallDirectory(il2cppBranch, il2cppInstallPath) != InstallErrorCode.Ok)
get { return EditorPrefs.GetString($"il2cpp_plus_repo#{MajorVersion}"); }
set { EditorPrefs.SetString($"il2cpp_plus_repo#{MajorVersion}", value); }
}
private string GetHybridCLRLocalVersion()
{
string workDir = SettingsUtil.HybridCLRDataDir;
string hybridclrRepoDir = $"{workDir}/{hybridclr_repo_path}";
if (Directory.Exists(hybridclrRepoDir))
{
Debug.LogError($"请正确设置 il2cpp 安装目录");
return;
var ret = BashUtil.RunCommand2(hybridclrRepoDir, "git",
new string[] { "log", "HEAD", "-n", "1", "--pretty=format:\"%H\"", },
false);
if (ret.ExitCode == 0)
{
return ret.StdOut.Trim();
}
else
{
return "ERROR";
}
}
RunInitLocalIl2CppData(il2cppBranch, il2cppInstallPath);
return "";
}
private string _il2cppPlusLocalVersion;
public string Il2cppPlusLocalVersion => _il2cppPlusLocalVersion != null ? _il2cppPlusLocalVersion : _il2cppPlusLocalVersion = GetIl2cppPlusLocalVersion();
private string GetIl2cppPlusLocalVersion()
{
string workDir = SettingsUtil.HybridCLRDataDir;
string il2cppPlusRepoDir = $"{workDir}/{il2cpp_plus_repo_path}";
if (Directory.Exists(il2cppPlusRepoDir))
{
var ret = BashUtil.RunCommand2(il2cppPlusRepoDir, "git",
new string[] { "log", "HEAD", "-n", "1", "--pretty=format:\"%H\"", },
false);
if (ret.ExitCode == 0)
{
return ret.StdOut.Trim();
}
else
{
return "ERROR";
}
}
return "";
}
private string GetIl2CppPathByContentPath(string contentPath)
{
return $"{contentPath}/il2cpp";
}
public void InstallLocalHybridCLR(string hybridclrVer, string il2cppPlusVer)
{
RunInitLocalIl2CppData(GetIl2CppPathByContentPath(EditorApplication.applicationContentsPath), _curVersion, hybridclrVer, il2cppPlusVer);
}
public bool HasInstalledHybridCLR()
@@ -225,34 +199,6 @@ namespace HybridCLR.Editor.Installer
return Directory.Exists($"{SettingsUtil.LocalIl2CppDir}/libil2cpp/hybridclr");
}
public InstallErrorCode CheckValidIl2CppInstallDirectory(string il2cppBranch, string installDir)
{
installDir = installDir.Replace('\\', '/');
if (!Directory.Exists(installDir))
{
return InstallErrorCode.Il2CppInstallPathNotExists;
}
if (!IsComaptibleWithIl2CppPlusBranch(il2cppBranch, installDir))
{
return TryParseMinorVersion(installDir, out _) ?
InstallErrorCode.Il2CppInstallPathNotMatchIl2CppBranch
: InstallErrorCode.InvalidUnityInstallPath;
}
if (!installDir.EndsWith("/il2cpp"))
{
return InstallErrorCode.NotIl2CppPath;
}
return InstallErrorCode.Ok;
}
public bool IsUnity2019(string branch)
{
return branch.Contains("2019.");
}
private string GetUnityIl2CppDllInstallLocation()
{
@@ -272,13 +218,7 @@ namespace HybridCLR.Editor.Installer
#endif
}
private static string GetRepoUrl(string repoName)
{
string repoProvider = SettingsUtil.HybridCLRSettings.cloneFromGitee ? "gitee" : "github";
return $"https://{repoProvider}.com/focus-creative-games/{repoName}";
}
private void RunInitLocalIl2CppData(string il2cppBranch, string il2cppInstallPath)
private void RunInitLocalIl2CppData(string editorIl2cppPath, UnityVersion version, string hybridclrVer, string il2cppPlusVer)
{
#if UNITY_EDITOR_WIN
if (!BashUtil.ExistProgram("git"))
@@ -296,16 +236,20 @@ namespace HybridCLR.Editor.Installer
BashUtil.CopyDir($"{SettingsUtil.HybridCLRDataPathInPackage}/iOSBuild", buildiOSDir, true);
// clone hybridclr
string hybridclrRepoURL = HybridCLRSettings.Instance.hybridclrRepoURL;
string hybridclrRepoDir = $"{workDir}/{hybridclr_repo_path}";
{
BashUtil.RemoveDir(hybridclrRepoDir);
var ret = BashUtil.RunCommand(workDir, "git", new string[]
string[] args = new string[]
{
"clone",
"--depth=1",
GetRepoUrl(hybridclr_url),
"-b",
hybridclrVer,
hybridclrRepoURL,
hybridclrRepoDir,
});
};
var ret = BashUtil.RunCommand(workDir, "git", args);
//if (ret != 0)
//{
// throw new Exception($"git clone 失败");
@@ -313,18 +257,20 @@ namespace HybridCLR.Editor.Installer
}
// clone il2cpp_plus
string il2cppPlusRepoURL = HybridCLRSettings.Instance.il2cppPlusRepoURL;
string il2cppPlusRepoDir = $"{workDir}/{il2cpp_plus_repo_path}";
{
BashUtil.RemoveDir(il2cppPlusRepoDir);
var ret = BashUtil.RunCommand(workDir, "git", new string[]
string[] args = new string[]
{
"clone",
"--depth=1",
"-b",
il2cppBranch,
GetRepoUrl(il2cpp_plus_url),
il2cppPlusVer,
il2cppPlusRepoURL,
il2cppPlusRepoDir,
});
};
var ret = BashUtil.RunCommand(workDir, "git", args);
//if (ret != 0)
//{
// throw new Exception($"git clone 失败");
@@ -336,10 +282,10 @@ namespace HybridCLR.Editor.Installer
BashUtil.RecreateDir(localUnityDataDir);
// copy MonoBleedingEdge
BashUtil.CopyDir($"{Directory.GetParent(il2cppInstallPath)}/MonoBleedingEdge", $"{localUnityDataDir}/MonoBleedingEdge", true);
BashUtil.CopyDir($"{Directory.GetParent(editorIl2cppPath)}/MonoBleedingEdge", $"{localUnityDataDir}/MonoBleedingEdge", true);
// copy il2cpp
BashUtil.CopyDir(Il2CppInstallDirectory, SettingsUtil.LocalIl2CppDir, true);
BashUtil.CopyDir(editorIl2cppPath, SettingsUtil.LocalIl2CppDir, true);
// replace libil2cpp
string dstLibil2cppDir = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp";
@@ -349,9 +295,9 @@ namespace HybridCLR.Editor.Installer
// clean Il2cppBuildCache
BashUtil.RemoveDir($"{SettingsUtil.ProjectDir}/Library/Il2cppBuildCache", true);
if (IsUnity2019(il2cppBranch))
if (version.major == 2019)
{
string curVersionStr = GetCurVersionStr(il2cppInstallPath);
string curVersionStr = version.ToString();
string srcIl2CppDll = GetUnityIl2CppDllModifiedPath(curVersionStr);
if (File.Exists(srcIl2CppDll))
{
@@ -367,6 +313,10 @@ namespace HybridCLR.Editor.Installer
if (HasInstalledHybridCLR())
{
Debug.Log("安装成功!");
_hybridclrLocalVersion = null;
_il2cppPlusLocalVersion = null;
HybridCLRRepoInstalledVersion = hybridclrVer;
Il2CppRepoInstalledVersion = il2cppPlusVer;
}
else
{
+48 -83
View File
@@ -8,11 +8,24 @@ namespace HybridCLR.Editor.Installer
{
public class InstallerWindow : EditorWindow
{
private InstallerController m_Controller;
private InstallerController _controller;
string _hybridclrVersion;
string _il2cppPlusVersion;
private void OnEnable()
{
m_Controller = new InstallerController();
_controller = new InstallerController();
_hybridclrVersion = _controller.HybridCLRRepoInstalledVersion;
if (string.IsNullOrWhiteSpace(_hybridclrVersion))
{
_hybridclrVersion = "1.0";
}
_il2cppPlusVersion = _controller.Il2CppRepoInstalledVersion;
if (string.IsNullOrWhiteSpace(_il2cppPlusVersion))
{
_il2cppPlusVersion = $"{_controller.MajorVersion}-1.0";
}
}
private void OnGUI()
@@ -30,118 +43,70 @@ namespace HybridCLR.Editor.Installer
{
SettingsService.OpenProjectSettings("Project/HybridCLR Settings");
}
string minCompatibleVersion = m_Controller.GetMinCompatibleVersion(m_Controller.Il2CppBranch);
GUI.enabled = true;
GUILayout.Space(10f);
EditorGUILayout.LabelField("=======================说明====================");
EditorGUILayout.LabelField(
$"你所在项目的Unity版本可以与il2cpp_plus版本:{m_Controller.Il2CppBranch} 不一样。\n"
+ $"如果你的Unity的版本号 >= {minCompatibleVersion}, 可以直接安装。\n"
+ $"如果你的Unity的版本号 < {minCompatibleVersion}, \n"
+ $"由于安装HybridCLR时需要从il2cpp_plus兼容版本{m_Controller.Il2CppBranch}(而不是你项目版本)拷贝il2cpp目录,\n"
+ $"你必须同时安装兼容版本 {m_Controller.Il2CppBranch} 才能完成安装", EditorStyles.wordWrappedLabel);
EditorGUILayout.LabelField("==============================================");
GUILayout.Space(10f);
EditorGUILayout.BeginVertical("box");
bool hasInstall = m_Controller.HasInstalledHybridCLR();
bool hasInstall = _controller.HasInstalledHybridCLR();
EditorGUILayout.LabelField($"安装状态:{(hasInstall ? "已安装" : "未安装")}", EditorStyles.boldLabel);
if (hasInstall)
{
GUIInstallButton("检查更新", "检查", UpdateHybridCLR);
EditorGUILayout.LabelField($"HybridCLR 版本: {_controller.HybridclrLocalVersion}");
GUILayout.Space(5f);
EditorGUILayout.LabelField($"il2cpp_plus 版本: {_controller.Il2cppPlusLocalVersion}");
GUILayout.Space(5f);
//GUIInstallButton("检查更新", "检查", UpdateHybridCLR);
//GUILayout.Space(40f);
}
GUILayout.Space(5f);
EditorGUILayout.LabelField($"当前Unity版本: {Application.unityVersion},匹配的il2cpp_plus分支: {m_Controller.Il2CppBranch}");
GUISelectUnityDirectory($"il2cpp_plus分支对应的Unity兼容版本的il2cpp路径", "Select");
GUILayout.Space(10f);
GUIInstallButton("安装最新HybridCLR插件代码到本项目", "安装", InitHybridCLR);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("待安装的 hybridclr 仓库版本号(或branch或tag)(默认取最新版本):", GUILayout.MaxWidth(400));
_hybridclrVersion = EditorGUILayout.TextField(_hybridclrVersion);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField($"待安装的 il2cpp_plus 仓库版本号(或branch或tag)(默认取{_controller.MajorVersion}-main分支最新版本):", GUILayout.MaxWidth(400));
_il2cppPlusVersion = EditorGUILayout.TextField(_il2cppPlusVersion);
EditorGUILayout.EndHorizontal();
GUIInstallButton("安装hybridclr+il2cpp_plus代码到本地目录", "安装");
EditorGUILayout.EndVertical();
}
private void GUIInstallButton(string content, string button, Action onClick)
private void GUIInstallButton(string content, string button)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(content);
GUI.enabled = m_Controller.CheckValidIl2CppInstallDirectory(m_Controller.Il2CppBranch, m_Controller.Il2CppInstallDirectory) == InstallErrorCode.Ok;
if (GUILayout.Button(button, GUILayout.Width(100)))
{
onClick?.Invoke();
InstallLocalHybridCLR();
GUIUtility.ExitGUI();
}
GUI.enabled = true;
EditorGUILayout.EndHorizontal();
}
private void GUISelectUnityDirectory(string content, string selectButton)
private void InstallLocalHybridCLR()
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(content, GUILayout.MaxWidth(300));
string il2cppInstallDirectory = m_Controller.Il2CppInstallDirectory = EditorGUILayout.TextField(m_Controller.Il2CppInstallDirectory);
if (GUILayout.Button(selectButton, GUILayout.Width(100)))
if (!_controller.IsComaptibleVersion())
{
string temp = EditorUtility.OpenFolderPanel(content, m_Controller.Il2CppInstallDirectory, string.Empty);
if (!string.IsNullOrEmpty(temp))
{
il2cppInstallDirectory = m_Controller.Il2CppInstallDirectory = temp;
}
Debug.LogError($"il2cpp 版本不兼容,最小版本为 {_controller.GetCurrentUnityVersionMinCompatibleVersionStr()}");
return;
}
EditorGUILayout.EndHorizontal();
InstallErrorCode err = m_Controller.CheckValidIl2CppInstallDirectory(m_Controller.Il2CppBranch, il2cppInstallDirectory);
switch (err)
if (string.IsNullOrWhiteSpace(_hybridclrVersion))
{
case InstallErrorCode.Ok:
{
break;
}
case InstallErrorCode.Il2CppInstallPathNotExists:
{
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;
}
case InstallErrorCode.NotIl2CppPath:
{
EditorGUILayout.HelpBox($"当前选择的路径不是il2cpp目录(必须类似 xxx/il2cpp)", MessageType.Error);
break;
}
default: throw new Exception($"not support {err}");
_hybridclrVersion = "main";
}
}
private void InitHybridCLR()
{
m_Controller.InitHybridCLR(m_Controller.Il2CppBranch, m_Controller.Il2CppInstallDirectory);
}
private void UpdateHybridCLR()
{
bool hasUpdateIl2Cpp = m_Controller.HasUpdateIl2Cpp(m_Controller.Il2CppBranch);
if (hasUpdateIl2Cpp)
if (string.IsNullOrWhiteSpace(_il2cppPlusVersion))
{
bool ret = EditorUtility.DisplayDialog("检查更新", "版本不一致", "更新","取消");
if (ret)
{
InitHybridCLR();
}
}
else
{
EditorUtility.DisplayDialog("检查更新", "暂无更新", "确定");
_il2cppPlusVersion = $"{_controller.MajorVersion}-main";
}
_controller.InstallLocalHybridCLR(_hybridclrVersion, _il2cppPlusVersion);
}
}
}
-39
View File
@@ -1,39 +0,0 @@
namespace HybridCLR.Editor.Installer
{
public partial class InstallerController
{
public bool HasUpdateIl2Cpp(string il2cppBranch)
{
string workDir = SettingsUtil.HybridCLRDataDir;
// last hash hybridclr
{
string hybridclrRepoDir = $"{workDir}/{hybridclr_repo_path}";
var ret1 = BashUtil.RunCommand2(hybridclrRepoDir, "git",
new string[] { "log", "HEAD", "-n", "1", "--pretty=format:\"%H\"", });
BashUtil.RunCommand2(hybridclrRepoDir, "git",
new string[] { "fetch", "--depth=1" });
var ret2 = BashUtil.RunCommand2(hybridclrRepoDir, "git",
new string[] { "log", "remotes/origin/HEAD", "-n", "1", "--pretty=format:\"%H\"", });
if (ret1.StdOut != ret2.StdOut)
{
return true;
}
}
// last hash il2cpp_plus
{
string il2cppPlusRepoDir = $"{workDir}/{il2cpp_plus_repo_path}";
var ret1 = BashUtil.RunCommand2(il2cppPlusRepoDir, "git",
new string[] { "log", $"{il2cppBranch}", "-n", "1", "--pretty=format:\"%H\"", });
BashUtil.RunCommand2(il2cppPlusRepoDir, "git",
new string[] { "fetch", "--depth=1" });
var ret2 = BashUtil.RunCommand2(il2cppPlusRepoDir, "git",
new string[] { "log", $"remotes/origin/{il2cppBranch}", "-n", "1", "--pretty=format:\"%H\"", });
if (ret1.StdOut != ret2.StdOut)
{
return true;
}
}
return false;
}
}
}
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 91454a4f0a354d11830642b4d4474d7e
timeCreated: 1665546286
+5 -12
View File
@@ -22,26 +22,19 @@ namespace HybridCLR.Editor.Link
_analyzeAssetType = analyzeAssetType;
}
public HashSet<TypeRef> CollectRefs(List<Assembly> rootAssemblies)
public HashSet<TypeRef> CollectRefs(List<string> rootAssemblies)
{
using (var assCollector = new AssemblyCache(_resolver))
{
var rootAssemblyName = new HashSet<string>();
foreach (var ass in rootAssemblies)
{
if (!rootAssemblyName.Add(ass.GetName().Name))
{
throw new Exception($"assembly:{ass.GetName().Name} 重复");
}
}
var rootAssemblyNames = new HashSet<string>(rootAssemblies);
var typeRefs = new HashSet<TypeRef>(TypeEqualityComparer.Instance);
foreach (var rootAss in rootAssemblies)
{
var dnAss = assCollector.LoadModule(rootAss.GetName().Name);
var dnAss = assCollector.LoadModule(rootAss, _analyzeAssetType);
foreach (var type in dnAss.GetTypeRefs())
{
if (!rootAssemblyName.Contains(type.DefinitionAssembly.Name))
if (!rootAssemblyNames.Contains(type.DefinitionAssembly.Name.ToString()))
{
typeRefs.Add(type);
}
@@ -51,7 +44,7 @@ namespace HybridCLR.Editor.Link
if (_analyzeAssetType)
{
var modsExludeRoots = assCollector.LoadedModules
.Where(e => !rootAssemblyName.Contains(e.Key))
.Where(e => !rootAssemblyNames.Contains(e.Key))
.ToDictionary(e => e.Key, e => e.Value);
CollectObjectTypeInAssets(modsExludeRoots, typeRefs);
}
+7 -3
View File
@@ -27,7 +27,7 @@ namespace HybridCLR.Editor.Meta
_asmResolver.UseGAC = false;
}
public ModuleDefMD LoadModule(string moduleName)
public ModuleDefMD LoadModule(string moduleName, bool loadReferenceAssemblies = true)
{
// Debug.Log($"load module:{moduleName}");
if (LoadedModules.TryGetValue(moduleName, out var mod))
@@ -37,10 +37,14 @@ namespace HybridCLR.Editor.Meta
mod = DoLoadModule(_assemblyPathResolver.ResolveAssembly(moduleName, true));
LoadedModules.Add(moduleName, mod);
foreach (var refAsm in mod.GetAssemblyRefs())
if (loadReferenceAssemblies)
{
LoadModule(refAsm.Name);
foreach (var refAsm in mod.GetAssemblyRefs())
{
LoadModule(refAsm.Name);
}
}
return mod;
}
+26
View File
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HybridCLR.Editor.Meta
{
public abstract class AssemblyResolverBase : IAssemblyResolver
{
public string ResolveAssembly(string assemblyName, bool throwExIfNotFind)
{
if (TryResolveAssembly(assemblyName, out string assemblyPath))
{
return assemblyPath;
}
if (throwExIfNotFind)
{
throw new Exception($"resolve assembly:{assemblyName} 失败! 如果是热更新dll找不到,请先运行`HybridCLR/CompileDll/ActiveBuildTarget`编译生成热更新dll。如果是AOT dll找不到,请先运行`HybridCLR/Generate/LinkXml`,接着在`Build Settings`中打包或者导出工程来生成AOT dll");
}
return null;
}
protected abstract bool TryResolveAssembly(string assemblyName, out string assemblyPath);
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 998b5f512dc60924e953a558ed250e15
guid: 5f8d48774b790364cbd36f1f68fd6614
MonoImporter:
externalObjects: {}
serializedVersion: 2
+6 -8
View File
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace HybridCLR.Editor.Meta
{
public class CombinedAssemblyResolver : IAssemblyResolver
public class CombinedAssemblyResolver : AssemblyResolverBase
{
private readonly IAssemblyResolver[] _resolvers;
@@ -15,21 +15,19 @@ namespace HybridCLR.Editor.Meta
_resolvers = resolvers;
}
public string ResolveAssembly(string assemblyName, bool throwExIfNotFind)
protected override bool TryResolveAssembly(string assemblyName, out string assemblyPath)
{
foreach(var resolver in _resolvers)
{
var assembly = resolver.ResolveAssembly(assemblyName, false);
if (assembly != null)
{
return assembly;
assemblyPath = assembly;
return true;
}
}
if (throwExIfNotFind)
{
throw new Exception($"resolve assembly:{assemblyName} fail");
}
return null;
assemblyPath = null;
return false;
}
}
}
+37
View File
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace HybridCLR.Editor.Meta
{
public class FixedSetAssemblyResolver : AssemblyResolverBase
{
private readonly string _rootDir;
private readonly HashSet<string> _fileNames;
public FixedSetAssemblyResolver(string rootDir, IEnumerable<string> fileNameNotExts)
{
_rootDir = rootDir;
_fileNames = new HashSet<string>(fileNameNotExts);
}
protected override bool TryResolveAssembly(string assemblyName, out string assemblyPath)
{
if (_fileNames.Contains(assemblyName))
{
assemblyPath = $"{_rootDir}/{assemblyName}.dll";
if (File.Exists(assemblyPath))
{
Debug.Log($"[FixedSetAssemblyResolver] resolve:{assemblyName} path:{assemblyPath}");
return true;
}
}
assemblyPath = null;
return false;
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 029bc0368e1ada342aa29a18d4fae879
guid: f135accd10f42c64b9735c3aa8cb1e77
MonoImporter:
externalObjects: {}
serializedVersion: 2
+33 -6
View File
@@ -6,6 +6,7 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
namespace HybridCLR.Editor.Meta
{
@@ -119,13 +120,39 @@ namespace HybridCLR.Editor.Meta
return typeSigs.Select(s => ToShareTypeSig(s)).ToList();
}
public static IAssemblyResolver CreateBuildTargetAssemblyResolver(UnityEditor.BuildTarget target)
public static IAssemblyResolver CreateHotUpdateAssemblyResolver(BuildTarget target, List<string> hotUpdateDlls)
{
return new CombinedAssemblyResolver(new PathAssemblyResolver(
SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target)),
new UnityPluginAssemblyResolver(),
new UnityAOTAssemblyResolver(),
new UnityEditorAssemblyResolver());
var externalDirs = HybridCLRSettings.Instance.externalHotUpdateAssembliyDirs;
var defaultHotUpdateOutputDir = SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target);
IAssemblyResolver defaultHotUpdateResolver = new FixedSetAssemblyResolver(defaultHotUpdateOutputDir, hotUpdateDlls);
if (externalDirs == null || externalDirs.Length == 0)
{
return defaultHotUpdateResolver;
}
else
{
var resolvers = new List<IAssemblyResolver>();
foreach (var dir in externalDirs)
{
resolvers.Add(new FixedSetAssemblyResolver($"{dir}/{target}", hotUpdateDlls));
resolvers.Add(new FixedSetAssemblyResolver(dir, hotUpdateDlls));
}
resolvers.Add(defaultHotUpdateResolver);
return new CombinedAssemblyResolver(resolvers.ToArray());
}
}
public static IAssemblyResolver CreateAOTAssemblyResolver(BuildTarget target)
{
return new PathAssemblyResolver(SettingsUtil.GetAssembliesPostIl2CppStripDir(target));
}
public static IAssemblyResolver CreateHotUpdateAndAOTAssemblyResolver(BuildTarget target, List<string> hotUpdateDlls)
{
return new CombinedAssemblyResolver(
CreateHotUpdateAssemblyResolver(target, hotUpdateDlls),
CreateAOTAssemblyResolver(target)
);
}
}
}
+6 -8
View File
@@ -8,7 +8,7 @@ using UnityEngine;
namespace HybridCLR.Editor.Meta
{
public class PathAssemblyResolver : IAssemblyResolver
public class PathAssemblyResolver : AssemblyResolverBase
{
private readonly string[] _searchPaths;
public PathAssemblyResolver(params string[] searchPaths)
@@ -16,7 +16,7 @@ namespace HybridCLR.Editor.Meta
_searchPaths = searchPaths;
}
public string ResolveAssembly(string assemblyName, bool throwExIfNotFind)
protected override bool TryResolveAssembly(string assemblyName, out string assemblyPath)
{
foreach(var path in _searchPaths)
{
@@ -24,14 +24,12 @@ namespace HybridCLR.Editor.Meta
if (File.Exists(assPath))
{
Debug.Log($"resolve {assemblyName} at {assPath}");
return assPath;
assemblyPath = assPath;
return true;
}
}
if (throwExIfNotFind)
{
throw new Exception($"resolve assembly:{assemblyName} fail");
}
return null;
assemblyPath = null;
return false;
}
}
}
-30
View File
@@ -1,30 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace HybridCLR.Editor.Meta
{
public class UnityAOTAssemblyResolver : IAssemblyResolver
{
public string ResolveAssembly(string assemblyName, bool throwExIfNotFind)
{
//
var assemblyFile = $"{UnityEditor.EditorApplication.applicationContentsPath}/MonoBleedingEdge/lib/mono/unityaot/{assemblyName}.dll";
if (File.Exists(assemblyFile))
{
Debug.Log($"UnityAOTAssemblyResolver.ResolveAssembly:{assemblyFile}");
return assemblyFile;
}
if (throwExIfNotFind)
{
throw new Exception($"resolve assembly:{assemblyName} fail");
}
return null;
}
}
}
@@ -1,22 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace HybridCLR.Editor.Meta
{
public class UnityEditorAssemblyResolver : IAssemblyResolver
{
public string ResolveAssembly(string assemblyName, bool throwExIfNotFind)
{
var refAss = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name == assemblyName);
if (refAss != null)
{
return refAss.Location;
}
return Assembly.Load(assemblyName).Location;
}
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 78d06a3ad750c0b4b80b583188b02df3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,44 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace HybridCLR.Editor.Meta
{
public class UnityPluginAssemblyResolver : IAssemblyResolver
{
private static readonly HashSet<string> s_ignoreDirs = new HashSet<string>
{
"Editor",
"StreamingAssets",
"Resources",
};
private bool IsPluginDll(string dllPath)
{
var fileOrDirs = new HashSet<string>(dllPath.Split('\\', '/'));
return !fileOrDirs.Intersect(s_ignoreDirs).Any();
}
public string ResolveAssembly(string assemblyName, bool throwExIfNotFind)
{
foreach(var dll in Directory.GetFiles(UnityEngine.Application.dataPath, "*.dll", SearchOption.AllDirectories))
{
if (Path.GetFileNameWithoutExtension(dll) == assemblyName && IsPluginDll(dll))
{
Debug.Log($"UnityPluginAssemblyResolver.ResolveAssembly:{dll}");
return dll;
}
}
if (throwExIfNotFind)
{
throw new Exception($"resolve assembly:{assemblyName} fail");
}
return null;
}
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 6c235be11c219a74fa5eb55ed54e7662
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+1 -1
View File
@@ -36,7 +36,7 @@ Managed2NativeMethodInfo hybridclr::interpreter::g_managed2nativeStub[] =
lines.Add($"\t{{\"{method.CreateInvokeSigName()}\", __M2N_{method.CreateInvokeSigName()}}},");
}
lines.Add($"\t{{\"\", nullptr}},");
lines.Add($"\t{{nullptr, nullptr}},");
lines.Add("};");
}
+1 -1
View File
@@ -29,7 +29,7 @@ namespace HybridCLR.Editor.ReversePInvokeWrap
codes.Add($@"
{method.ReturnInfo.Type.GetTypeName()} __ReversePInvokeMethod_{methodIndex}({paramDeclaringListWithoutMethodInfoStr})
{{
const MethodInfo* method = MetadataModule::GetMethodInfoByReversePInvokeWrapperIndex({i});
const MethodInfo* method = MetadataModule::GetMethodInfoByReversePInvokeWrapperIndex({methodIndex});
{methodTypeDef};
{(method.ReturnInfo.IsVoid ? "" : "return ")}((Callback)(method->methodPointerCallByInterp))({paramNameListWithoutMethodInfoStr});
}}
+9 -9
View File
@@ -11,15 +11,15 @@ namespace HybridCLR.Editor
private SerializedObject _serializedObject;
private SerializedProperty _enable;
private SerializedProperty _useGlobalIl2cpp;
private SerializedProperty _cloneFromGitee;
private SerializedProperty _hybridclrRepoURL;
private SerializedProperty _il2cppPlusRepoURL;
private SerializedProperty _hotUpdateAssemblyDefinitions;
private SerializedProperty _hotUpdateAssemblies;
private SerializedProperty _preserveHotUpdateAssemblies;
private SerializedProperty _hotUpdateDllCompileOutputRootDir;
private SerializedProperty _externalHotUpdateAssembliyDirs;
private SerializedProperty _strippedAOTDllOutputRootDir;
private SerializedProperty _patchAOTAssemblies;
private SerializedProperty _differentialHybridAssemblies;
private SerializedProperty _differentialHybridOptionOutputDir;
private SerializedProperty _collectAssetReferenceTypes;
private SerializedProperty _outputLinkFile;
private SerializedProperty _outputAOTGenericReferenceFile;
@@ -39,15 +39,15 @@ namespace HybridCLR.Editor
_serializedObject = new SerializedObject(setting);
_enable = _serializedObject.FindProperty("enable");
_useGlobalIl2cpp = _serializedObject.FindProperty("useGlobalIl2cpp");
_cloneFromGitee = _serializedObject.FindProperty("cloneFromGitee");
_hybridclrRepoURL = _serializedObject.FindProperty("hybridclrRepoURL");
_il2cppPlusRepoURL = _serializedObject.FindProperty("il2cppPlusRepoURL");
_hotUpdateAssemblyDefinitions = _serializedObject.FindProperty("hotUpdateAssemblyDefinitions");
_hotUpdateAssemblies = _serializedObject.FindProperty("hotUpdateAssemblies");
_preserveHotUpdateAssemblies = _serializedObject.FindProperty("preserveHotUpdateAssemblies");
_hotUpdateDllCompileOutputRootDir = _serializedObject.FindProperty("hotUpdateDllCompileOutputRootDir");
_externalHotUpdateAssembliyDirs = _serializedObject.FindProperty("externalHotUpdateAssembliyDirs");
_strippedAOTDllOutputRootDir = _serializedObject.FindProperty("strippedAOTDllOutputRootDir");
_patchAOTAssemblies = _serializedObject.FindProperty("patchAOTAssemblies");
_differentialHybridAssemblies = _serializedObject.FindProperty("differentialHybridAssemblies");
_differentialHybridOptionOutputDir = _serializedObject.FindProperty("differentialHybridOptionOutputDir");
_collectAssetReferenceTypes = _serializedObject.FindProperty("collectAssetReferenceTypes");
_outputLinkFile = _serializedObject.FindProperty("outputLinkFile");
_outputAOTGenericReferenceFile = _serializedObject.FindProperty("outputAOTGenericReferenceFile");
@@ -127,16 +127,16 @@ namespace HybridCLR.Editor
_serializedObject.Update();
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(_enable);
EditorGUILayout.PropertyField(_cloneFromGitee);
EditorGUILayout.PropertyField(_hybridclrRepoURL);
EditorGUILayout.PropertyField(_il2cppPlusRepoURL);
EditorGUILayout.PropertyField(_useGlobalIl2cpp);
EditorGUILayout.PropertyField(_hotUpdateAssemblyDefinitions);
EditorGUILayout.PropertyField(_hotUpdateAssemblies);
EditorGUILayout.PropertyField(_preserveHotUpdateAssemblies);
EditorGUILayout.PropertyField(_hotUpdateDllCompileOutputRootDir);
EditorGUILayout.PropertyField(_externalHotUpdateAssembliyDirs);
EditorGUILayout.PropertyField(_strippedAOTDllOutputRootDir);
EditorGUILayout.PropertyField(_patchAOTAssemblies);
EditorGUILayout.PropertyField(_differentialHybridAssemblies);
EditorGUILayout.PropertyField(_differentialHybridOptionOutputDir);
EditorGUILayout.PropertyField(_collectAssetReferenceTypes);
EditorGUILayout.PropertyField(_outputLinkFile);
EditorGUILayout.PropertyField(_outputAOTGenericReferenceFile);
+8 -11
View File
@@ -11,8 +11,11 @@ namespace HybridCLR.Editor
[Header("使用全局安装的il2cpp")]
public bool useGlobalIl2cpp;
[Header("从gitee clone插件代码")]
public bool cloneFromGitee = true; // false 则从github上拉取
[Header("hybridclr 仓库 URL")]
public string hybridclrRepoURL = "https://gitee.com/focus-creative-games/hybridclr";
[Header("il2cpp_plus 仓库 URL")]
public string il2cppPlusRepoURL = "https://gitee.com/focus-creative-games/il2cpp_plus";
[Header("热更新Assembly Definitions")]
public AssemblyDefinitionAsset[] hotUpdateAssemblyDefinitions;
@@ -26,18 +29,15 @@ namespace HybridCLR.Editor
[Header("热更新dll编译输出根目录")]
public string hotUpdateDllCompileOutputRootDir = "HybridCLRData/HotUpdateDlls";
[Header("外部热更新dll搜索路径")]
public string[] externalHotUpdateAssembliyDirs;
[Header("裁减后AOT dll输出根目录")]
public string strippedAOTDllOutputRootDir = "HybridCLRData/AssembliesPostIl2CppStrip";
[Header("补充元数据AOT dlls")]
public string[] patchAOTAssemblies;
[Header("差分混合热更新 dlls")]
public string[] differentialHybridAssemblies;
[Header("差分混合热更新配置数据输出目录")]
public string differentialHybridOptionOutputDir = "Assets/StreamingAssets";
[Header("生成link.xml时扫描asset中引用的类型")]
public bool collectAssetReferenceTypes;
@@ -50,9 +50,6 @@ namespace HybridCLR.Editor
[Header("AOT泛型实例化搜索迭代次数")]
public int maxGenericReferenceIteration = 10;
//[Header("预留MonoPInvokeCallbackAttribute函数个数")]
//public int ReversePInvokeWrapperCount = 10;
[Header("MethodBridge泛型搜索迭代次数")]
public int maxMethodBridgeGenericIteration = 10;
}
+9 -1
View File
@@ -11,7 +11,15 @@ namespace HybridCLR.Editor
{
public static class SettingsUtil
{
public static bool Enable => HybridCLRSettings.Instance.enable;
public static bool Enable
{
get => HybridCLRSettings.Instance.enable;
set
{
HybridCLRSettings.Instance.enable = value;
HybridCLRSettings.Save();
}
}
public static string PackageName { get; } = "com.focus-creative-games.hybridclr_unity";
@@ -1,33 +0,0 @@
using System.Collections.Generic;
using System.IO;
using UnityEngine;
namespace HybridCLR.Runtime
{
public class DifferentialHybridAssemblyOptions
{
public const uint Signature = 0xABCDABCD;
public List<uint> notChangeMethodTokens;
public byte[] Marshal()
{
var stream = new MemoryStream();
var writer = new BinaryWriter(stream);
writer.Write(Signature);
writer.Write((uint)notChangeMethodTokens.Count);
foreach (uint token in notChangeMethodTokens)
{
writer.Write(token);
}
writer.Flush();
stream.Flush();
byte[] result = new byte[stream.Length];
stream.Position = 0;
stream.Read(result, 0, result.Length);
Debug.Log($"HotPatchAssemblyConfig. options bytes:{result.Length}");
return result;
}
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 3394055921ccce643b09466544ea3634
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
-50
View File
@@ -46,56 +46,6 @@ namespace HybridCLR
public static extern unsafe int LoadMetadataForAOTAssembly(byte* dllBytes, int dllSize, int mode);
//[DllImport(dllName, EntryPoint = "RuntimeApi_UseDifferentialHybridAOTAssembly")]
//public static unsafe LoadImageErrorCode UseDifferentialHybridAOTAssembly(string assemblyName)
//{
// byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(assemblyName);
// fixed(byte* namePtr = nameBytes)
// {
// }
//}
/// <summary>
/// 指示混合执行assembly使用原始的AOT代码。当assembly没有发生变化时必须调用此接口。
/// </summary>
/// <param name="assemblyName"></param>
/// <returns></returns>
#if UNITY_EDITOR
public static LoadImageErrorCode UseDifferentialHybridAOTAssembly(string assemblyName)
{
return LoadImageErrorCode.OK;
}
#else
[DllImport(dllName, EntryPoint = "RuntimeApi_UseDifferentialHybridAOTAssembly")]
public static extern LoadImageErrorCode UseDifferentialHybridAOTAssembly(string assemblyName);
#endif
/// <summary>
/// 加载差分混合执行 assembly
/// </summary>
/// <param name="dllBytes"></param>
/// <param name="optionBytes"></param>
/// <returns></returns>
public static unsafe LoadImageErrorCode LoadDifferentialHybridAssembly(byte[] dllBytes, byte[] optionBytes)
{
#if UNITY_EDITOR
return LoadImageErrorCode.OK;
#else
fixed(byte* dllBytesPtr = dllBytes)
{
fixed(byte* optionBytesPtr = optionBytes)
{
return (LoadImageErrorCode)LoadDifferentialHybridAssembly(dllBytesPtr, dllBytes.Length, optionBytesPtr, optionBytes.Length);
}
}
#endif
}
[DllImport(dllName, EntryPoint = "RuntimeApi_LoadDifferentialHybridAssembly")]
public static extern unsafe int LoadDifferentialHybridAssembly(byte* dllBytes, int dllSize, byte* optionBytesPtr, int optionBytesLength);
/// <summary>
/// 获取解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小)
/// </summary>
-18
View File
@@ -1,18 +0,0 @@
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HybridCLR.Runtime
{
[AttributeUsage(AttributeTargets.Method)]
public class UnchangedAttribute : Attribute
{
public bool Unchanged { get; }
public UnchangedAttribute(bool unchanged = true)
{
Unchanged = unchanged;
}
}
}
-11
View File
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 704603a2a0551f247a30e331ca476870
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "com.focus-creative-games.hybridclr_unity",
"version": "0.10.1",
"version": "1.0.12",
"displayName": "HybridCLR",
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
"category": "Runtime",