mirror of
https://github.com/focus-creative-games/hybridclr_unity.git
synced 2026-11-20 07:22:39 +08:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f5afc43625 | |||
| f8eee2ba49 | |||
| 07b52bed05 | |||
| 3139fbefa6 | |||
| fbeeb3d959 | |||
| 1f4e754adb | |||
| f63bbc8a52 | |||
| b17751b8a8 | |||
| 05e721cf02 | |||
| 29646f1294 | |||
| 3702411ac8 | |||
| d205f00a1b | |||
| 2894701063 | |||
| 1045538b40 | |||
| 8fd9b2ec82 | |||
| 0ccdd424ab | |||
| c083e4ada4 | |||
| 4c6dd1249a | |||
| b8b990bfc1 | |||
| 252e6add67 | |||
| 6e76b96f97 |
@@ -1,5 +0,0 @@
|
||||
# change logs
|
||||
|
||||
- 2022.8.30 创建
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f2a6638b09b52f4c9dc8906d090b710
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d104ab5da8136154899a40116dc88731
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -2,18 +2,18 @@
|
||||
"versions": [
|
||||
{
|
||||
"unity_version":"2019",
|
||||
"hybridclr" : { "branch":"v2.0.3"},
|
||||
"il2cpp_plus": { "branch":"v2019-2.0.1"}
|
||||
"hybridclr" : { "branch":"v2.3.1"},
|
||||
"il2cpp_plus": { "branch":"v2019-2.2.0"}
|
||||
},
|
||||
{
|
||||
"unity_version":"2020",
|
||||
"hybridclr" : { "branch":"v2.0.3"},
|
||||
"il2cpp_plus": { "branch":"v2020-2.0.2"}
|
||||
"hybridclr" : { "branch":"v2.3.1"},
|
||||
"il2cpp_plus": { "branch":"v2020-2.2.1"}
|
||||
},
|
||||
{
|
||||
"unity_version":"2021",
|
||||
"hybridclr" : { "branch":"v2.0.3"},
|
||||
"il2cpp_plus": { "branch":"v2021-2.0.2"}
|
||||
"hybridclr" : { "branch":"v2.3.1"},
|
||||
"il2cpp_plus": { "branch":"v2021-2.2.1"}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,277 +0,0 @@
|
||||
#if ENABLE_HOOK_TEST_CASE
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
namespace MonoHook.Test
|
||||
{
|
||||
// 有需求时可以打开,也可以手动按需注册Hook
|
||||
[InitializeOnLoad]
|
||||
public class BuildPipeline_StripDll_HookTest
|
||||
{
|
||||
/// <summary>
|
||||
/// 裁剪执行完毕的回调,可能会被调用多次,一般而言同一次打包只需要处理第一次回调
|
||||
/// </summary>
|
||||
public static Action<string, BuildPostProcessArgs, BeeDriverResult> OnAssemblyStripped;
|
||||
|
||||
// 尝试 Hook 4个函数,至少一个被调用就可以达到要求
|
||||
private static MethodHook _hook_PostprocessBuildPlayer_CompleteBuild;
|
||||
private static MethodHook _hook_Default_PostProcess;
|
||||
private static MethodHook _hook_ReportBuildResults;
|
||||
private static MethodHook _hook_StripAssembliesTo;
|
||||
|
||||
#region Fake Internal Structures
|
||||
public struct BuildPostProcessArgs
|
||||
{
|
||||
public BuildTarget target;
|
||||
public int subTarget;
|
||||
public string stagingArea;
|
||||
public string stagingAreaData;
|
||||
public string stagingAreaDataManaged;
|
||||
public string playerPackage;
|
||||
public string installPath;
|
||||
public string companyName;
|
||||
public string productName;
|
||||
public Guid productGUID;
|
||||
public BuildOptions options;
|
||||
public UnityEditor.Build.Reporting.BuildReport report;
|
||||
internal /*RuntimeClassRegistry*/object usedClassRegistry;
|
||||
}
|
||||
|
||||
public sealed class BeeDriverResult
|
||||
{
|
||||
public /*NodeResult*/object[] NodeResults { get; set; }
|
||||
public bool Success { get; set; }
|
||||
public /*Message*/object[] BeeDriverMessages { get; set; }
|
||||
public override string ToString() => Success.ToString();
|
||||
}
|
||||
#endregion
|
||||
|
||||
static BuildPipeline_StripDll_HookTest()
|
||||
{
|
||||
InstallHook();
|
||||
#if ENABLE_HOOK_TEST_CASE
|
||||
OnAssemblyStripped = DemoStripCallback;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 示例裁剪回调函数
|
||||
/// </summary>
|
||||
/// <param name="outputFolder"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <param name="result"></param>
|
||||
static void DemoStripCallback(string outputFolder, BuildPostProcessArgs args, BeeDriverResult result)
|
||||
{
|
||||
if (outputFolder != null)
|
||||
Debug.Log($"stripped outputFolder is:{outputFolder}");
|
||||
else if (args.stagingAreaDataManaged != null)
|
||||
Debug.Log($"stripped staging folder is:{args.stagingAreaDataManaged}");
|
||||
else if (result != null)
|
||||
Debug.Log($"stripped result is: {result.Success}");
|
||||
else
|
||||
Debug.Log("stripped test called");
|
||||
}
|
||||
|
||||
public static void InstallHook()
|
||||
{
|
||||
do
|
||||
{
|
||||
Type type = Type.GetType("UnityEditor.PostprocessBuildPlayer,UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
|
||||
if (type == null)
|
||||
{
|
||||
Debug.LogError($"can not find type: UnityEditor.PostprocessBuildPlayer");
|
||||
break;
|
||||
}
|
||||
|
||||
MethodInfo miTarget = type.GetMethod("PostProcessCompletedBuild", BindingFlags.Static | BindingFlags.Public);
|
||||
|
||||
if (miTarget == null)
|
||||
{
|
||||
Debug.LogError($"can not find method: UnityEditor.PostprocessBuildPlayer.PostProcessCompletedBuild");
|
||||
break;
|
||||
}
|
||||
|
||||
MethodInfo miReplace = typeof(BuildPipeline_StripDll_HookTest).GetMethod(nameof(PostprocessBuildPlayer_CompleteBuild_Replace), BindingFlags.Static | BindingFlags.NonPublic);
|
||||
MethodInfo miProxy = typeof(BuildPipeline_StripDll_HookTest).GetMethod(nameof(PostprocessBuildPlayer_CompleteBuild_Proxy), BindingFlags.Static | BindingFlags.NonPublic);
|
||||
|
||||
_hook_PostprocessBuildPlayer_CompleteBuild = new MethodHook(miTarget, miReplace, miProxy);
|
||||
_hook_PostprocessBuildPlayer_CompleteBuild.Install();
|
||||
|
||||
Debug.Log("Hook BuildPipeline_StripDll_HookTest.PostprocessBuildPlayer_CompleteBuild installed");
|
||||
} while (false);
|
||||
|
||||
do
|
||||
{
|
||||
Type type = Type.GetType("UnityEditor.Modules.DefaultBuildPostprocessor,UnityEditor.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
|
||||
if (type == null)
|
||||
{
|
||||
Debug.LogError($"can not find type: UnityEditor.Modules.DefaultBuildPostprocessor");
|
||||
break;
|
||||
}
|
||||
|
||||
MethodInfo[] miTargets = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
|
||||
MethodInfo miTarget = (from mi in miTargets where mi.Name == "PostProcess" && mi.GetParameters().Length == 2 select mi).FirstOrDefault();
|
||||
|
||||
if (miTarget == null)
|
||||
{
|
||||
Debug.LogError($"can not find method: UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess");
|
||||
break;
|
||||
}
|
||||
|
||||
MethodInfo miReplace = typeof(BuildPipeline_StripDll_HookTest).GetMethod(nameof(Default_PostProcess_Replace), BindingFlags.Static | BindingFlags.NonPublic);
|
||||
MethodInfo miProxy = typeof(BuildPipeline_StripDll_HookTest).GetMethod(nameof(Default_PostProcess_Proxy), BindingFlags.Static | BindingFlags.NonPublic);
|
||||
|
||||
_hook_Default_PostProcess = new MethodHook(miTarget, miReplace, miProxy);
|
||||
_hook_Default_PostProcess.Install();
|
||||
|
||||
Debug.Log("Hook BuildPipeline_StripDll_HookTest.PostProcess installed");
|
||||
} while (false);
|
||||
|
||||
do
|
||||
{
|
||||
Type type = Type.GetType("UnityEditor.Modules.BeeBuildPostprocessor,UnityEditor.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
|
||||
if (type == null)
|
||||
{
|
||||
Debug.LogError($"can not find type: UnityEditor.Modules.BeeBuildPostprocessor");
|
||||
break;
|
||||
}
|
||||
|
||||
MethodInfo miTarget = type.GetMethod("ReportBuildResults", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
if (miTarget == null)
|
||||
{
|
||||
Debug.LogError($"can not find method: UnityEditor.Modules.BeeBuildPostprocessor.ReportBuildResults");
|
||||
break;
|
||||
}
|
||||
|
||||
MethodInfo miReplace = typeof(BuildPipeline_StripDll_HookTest).GetMethod(nameof(ReportBuildResults_Replace), BindingFlags.Static | BindingFlags.NonPublic);
|
||||
MethodInfo miProxy = typeof(BuildPipeline_StripDll_HookTest).GetMethod(nameof(ReportBuildResults_Proxy), BindingFlags.Static | BindingFlags.NonPublic);
|
||||
|
||||
_hook_ReportBuildResults = new MethodHook(miTarget, miReplace, miProxy);
|
||||
_hook_ReportBuildResults.Install();
|
||||
|
||||
Debug.Log("Hook BuildPipeline_StripDll_HookTest.ReportBuildResults installed");
|
||||
} while (false);
|
||||
|
||||
do
|
||||
{
|
||||
Type type = Type.GetType("UnityEditorInternal.AssemblyStripper,UnityEditor.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
|
||||
if (type == null)
|
||||
{
|
||||
Debug.LogError($"can not find type: UnityEditorInternal.AssemblyStripper");
|
||||
break;
|
||||
}
|
||||
|
||||
MethodInfo miTarget = type.GetMethod("StripAssembliesTo", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
if (miTarget == null)
|
||||
{
|
||||
Debug.LogError($"can not find method: UnityEditorInternal.AssemblyStripper.StripAssembliesTo");
|
||||
break;
|
||||
}
|
||||
|
||||
MethodInfo miReplace = typeof(BuildPipeline_StripDll_HookTest).GetMethod(nameof(StripAssembliesTo_Replace), BindingFlags.Static | BindingFlags.NonPublic);
|
||||
MethodInfo miProxy = typeof(BuildPipeline_StripDll_HookTest).GetMethod(nameof(StripAssembliesTo_Proxy), BindingFlags.Static | BindingFlags.NonPublic);
|
||||
|
||||
_hook_StripAssembliesTo = new MethodHook(miTarget, miReplace, miProxy);
|
||||
_hook_StripAssembliesTo.Install();
|
||||
|
||||
Debug.Log("Hook BuildPipeline_StripDll_HookTest.StripAssembliesTo installed");
|
||||
} while (false);
|
||||
}
|
||||
|
||||
public static void UninstallHook()
|
||||
{
|
||||
_hook_PostprocessBuildPlayer_CompleteBuild?.Uninstall();
|
||||
_hook_Default_PostProcess?.Uninstall();
|
||||
_hook_ReportBuildResults?.Uninstall();
|
||||
_hook_StripAssembliesTo?.Uninstall();
|
||||
}
|
||||
|
||||
static void PostprocessBuildPlayer_CompleteBuild_Replace(BuildPostProcessArgs args)
|
||||
{
|
||||
Debug.Log("PostprocessBuildPlayer_CompleteBuild_Replace called");
|
||||
|
||||
OnAssemblyStripped?.Invoke(null, args, null);
|
||||
PostprocessBuildPlayer_CompleteBuild_Proxy(args);
|
||||
}
|
||||
|
||||
static void Default_PostProcess_Replace(object obj, BuildPostProcessArgs args, out /*BuildProperties*/ object outProperties)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 注意:此函数中途可能会被 Unity throw Exception
|
||||
Default_PostProcess_Proxy(obj, args, out outProperties);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Debug.Log("PostProcess_Replace called");
|
||||
OnAssemblyStripped?.Invoke(null, args, null);
|
||||
}
|
||||
}
|
||||
|
||||
static void ReportBuildResults_Replace(object obj, BeeDriverResult result)
|
||||
{
|
||||
// TODO: 可以在这里把 Library\Bee\artifacts\WinPlayerBuildProgram\ManagedStripped 目录下的文件复制出来
|
||||
Debug.Log("ReportBuildResults_Replace called");
|
||||
|
||||
OnAssemblyStripped?.Invoke(null, default(BuildPostProcessArgs), result);
|
||||
ReportBuildResults_Proxy(obj, result);
|
||||
}
|
||||
|
||||
static bool StripAssembliesTo_Replace(string outputFolder, out string output, out string error, IEnumerable<string> linkXmlFiles, /*UnityLinkerRunInformation*/ object runInformation)
|
||||
{
|
||||
bool ret = StripAssembliesTo_Proxy(outputFolder, out output, out error, linkXmlFiles, runInformation);
|
||||
|
||||
// TODO: 可以在这里把 Temp\StagingArea\Data\Managed\tempStrip 目录下的文件复制出来
|
||||
Debug.Log("StripAssembliesTo_Replace called");
|
||||
|
||||
OnAssemblyStripped?.Invoke(outputFolder, default(BuildPostProcessArgs), null);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#region Proxy Methods
|
||||
[MethodImpl(MethodImplOptions.NoOptimization)]
|
||||
static void PostprocessBuildPlayer_CompleteBuild_Proxy(BuildPostProcessArgs args)
|
||||
{
|
||||
Debug.Log("dummy code" + 200);
|
||||
Debug.Log(args.companyName);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoOptimization)]
|
||||
static void Default_PostProcess_Proxy(object obj, BuildPostProcessArgs args, out /*BuildProperties*/ object outProperties)
|
||||
{
|
||||
Debug.Log("dummy code" + 100);
|
||||
outProperties = null;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoOptimization)]
|
||||
static void ReportBuildResults_Proxy(object obj, /*BeeDriverResult*/ object result)
|
||||
{
|
||||
// dummy code
|
||||
Debug.Log("something" + obj.ToString() + result.ToString() + 2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoOptimization)]
|
||||
static bool StripAssembliesTo_Proxy(string outputFolder, out string output, out string error, IEnumerable<string> linkXmlFiles, /*UnityLinkerRunInformation*/ object runInformation)
|
||||
{
|
||||
Debug.Log("StripAssembliesTo_Proxy called");
|
||||
output = null;
|
||||
error = null;
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -48,6 +48,8 @@ namespace HybridCLR.MonoHook
|
||||
[MethodImpl(MethodImplOptions.NoOptimization)]
|
||||
private static string BuildMainWindowTitleProxy()
|
||||
{
|
||||
// 为满足MonoHook要求的最小代码长度而特地加入的无用填充代码,
|
||||
UnityEngine.Debug.Log(12345.ToString());
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace HybridCLR.Editor.ABI
|
||||
case ElementType.Module:
|
||||
case ElementType.Var:
|
||||
case ElementType.MVar:
|
||||
return GetNativeIntTypeInfo();
|
||||
return GetNativeIntTypeInfo();
|
||||
case ElementType.TypedByRef: return CreateValueType(type);
|
||||
case ElementType.ValueType:
|
||||
{
|
||||
@@ -105,7 +105,7 @@ namespace HybridCLR.Editor.ABI
|
||||
|
||||
private static bool IsNotHFAFastCheck(int typeSize)
|
||||
{
|
||||
return typeSize != 8 && typeSize != 12 && typeSize != 16 && typeSize != 24 && typeSize != 32;
|
||||
return typeSize % 4 != 0 || typeSize > 32;
|
||||
}
|
||||
|
||||
private static bool ComputHFATypeInfo0(TypeSig type, HFATypeInfo typeInfo)
|
||||
@@ -169,7 +169,7 @@ namespace HybridCLR.Editor.ABI
|
||||
return false;
|
||||
}
|
||||
bool ok = ComputHFATypeInfo0(type, typeInfo);
|
||||
if (ok && typeInfo.Count >= 2 && typeInfo.Count <= 4)
|
||||
if (ok && typeInfo.Count >= 1 && typeInfo.Count <= 4)
|
||||
{
|
||||
int fieldSize = typeInfo.Type.ElementType == ElementType.R4 ? 4 : 8;
|
||||
return typeSize == fieldSize * typeInfo.Count;
|
||||
@@ -261,7 +261,15 @@ namespace HybridCLR.Editor.ABI
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return fields.All(f => f.IsStatic);
|
||||
if (fields.All(f => f.IsStatic))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (typeDef.IsExplicitLayout && fields.Count(f => !f.IsStatic) > 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static TypeInfo CreateGeneralValueType(TypeSig type, int size, int aligment)
|
||||
@@ -285,6 +293,7 @@ namespace HybridCLR.Editor.ABI
|
||||
bool isFloat = hfaTypeInfo.Type.ElementType == ElementType.R4;
|
||||
switch (hfaTypeInfo.Count)
|
||||
{
|
||||
case 1: return isFloat ? TypeInfo.s_r4 : TypeInfo.s_r8;
|
||||
case 2: return isFloat ? TypeInfo.s_vf2 : TypeInfo.s_vd2;
|
||||
case 3: return isFloat ? TypeInfo.s_vf3 : TypeInfo.s_vd3;
|
||||
case 4: return isFloat ? TypeInfo.s_vf4 : TypeInfo.s_vd4;
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace HybridCLR.Editor.ABI
|
||||
{
|
||||
public override bool IsArch32 => false;
|
||||
|
||||
public override bool IsSupportHFA => true;
|
||||
public override bool IsSupportHFA => false;
|
||||
|
||||
protected override TypeInfo OptimizeSigType(TypeInfo type, bool returnType)
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine;
|
||||
@@ -40,10 +41,32 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (UnityEditor.PlayerSettings.gcIncremental)
|
||||
if (PlayerSettings.gcIncremental)
|
||||
{
|
||||
Debug.LogError($"[CheckSettings] HybridCLR不支持增量式GC,已经自动将该选项关闭");
|
||||
UnityEditor.PlayerSettings.gcIncremental = false;
|
||||
PlayerSettings.gcIncremental = false;
|
||||
}
|
||||
BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
|
||||
ScriptingImplementation curScriptingImplementation = PlayerSettings.GetScriptingBackend(buildTargetGroup);
|
||||
ScriptingImplementation targetScriptingImplementation = ScriptingImplementation.IL2CPP;
|
||||
if (curScriptingImplementation != targetScriptingImplementation)
|
||||
{
|
||||
Debug.LogError($"[CheckSettings] 当前ScriptingBackend是:{curScriptingImplementation},已经自动切换为:{targetScriptingImplementation}");
|
||||
PlayerSettings.SetScriptingBackend(buildTargetGroup, targetScriptingImplementation);
|
||||
}
|
||||
ApiCompatibilityLevel curApiCompatibilityLevel = PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup);
|
||||
#if UNITY_2021_1_OR_NEWER
|
||||
ApiCompatibilityLevel targetApiCompatibilityLevel = ApiCompatibilityLevel.NET_Unity_4_8;
|
||||
#else
|
||||
ApiCompatibilityLevel targetApiCompatibilityLevel = ApiCompatibilityLevel.NET_4_6;
|
||||
#endif
|
||||
|
||||
|
||||
if (curApiCompatibilityLevel != targetApiCompatibilityLevel)
|
||||
{
|
||||
Debug.LogError($"[CheckSettings] 当前ApiCompatibilityLevel是:{curApiCompatibilityLevel},已经自动切换为 {targetApiCompatibilityLevel}。由于下一次打包才生效,主动打断本次打包。");
|
||||
PlayerSettings.SetApiCompatibilityLevel(buildTargetGroup, ApiCompatibilityLevel.NET_4_6);
|
||||
throw new BuildFailedException("ApiCompatibilityLevel error");
|
||||
}
|
||||
|
||||
var installer = new Installer.InstallerController();
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
|
||||
public class MsvcStdextWorkaround : IPreprocessBuildWithReport
|
||||
{
|
||||
const string kWorkaroundFlag = "/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS";
|
||||
|
||||
public int callbackOrder => 0;
|
||||
|
||||
public void OnPreprocessBuild(BuildReport report)
|
||||
{
|
||||
var clEnv = Environment.GetEnvironmentVariable("_CL_");
|
||||
|
||||
if (string.IsNullOrEmpty(clEnv))
|
||||
{
|
||||
Environment.SetEnvironmentVariable("_CL_", kWorkaroundFlag);
|
||||
}
|
||||
else if (!clEnv.Contains(kWorkaroundFlag))
|
||||
{
|
||||
clEnv += " " + kWorkaroundFlag;
|
||||
Environment.SetEnvironmentVariable("_CL_", clEnv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // UNITY_EDITOR
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed8859610137d404e87f332b7082c19b
|
||||
guid: 8bff6cadf0b8db54b87ba51b24d080f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -19,8 +19,8 @@ namespace HybridCLR.Editor.Commands
|
||||
{
|
||||
UnityVersion = Application.unityVersion,
|
||||
HotUpdateAssemblies = SettingsUtil.HotUpdateAssemblyNamesIncludePreserved,
|
||||
OutputFile = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/il2cpp-config.h",
|
||||
OutputFile2 = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/hybridclr/Il2CppCompatibleDef.cpp",
|
||||
OutputFile = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/hybridclr/generated/UnityVersion.h",
|
||||
OutputFile2 = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/hybridclr/generated/AssemblyManifest.cpp",
|
||||
};
|
||||
|
||||
var g = new Il2CppDef.Il2CppDefGenerator(options);
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace HybridCLR.Editor.Commands
|
||||
BashUtil.RemoveDir(outputPath);
|
||||
|
||||
var buildOptions = BuildOptions.BuildScriptsOnly;
|
||||
#if UNITY_2021_1_OR_NEWER
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
buildOptions |= BuildOptions.CleanBuildCache;
|
||||
#endif
|
||||
|
||||
@@ -113,8 +113,7 @@ namespace HybridCLR.Editor.Commands
|
||||
|
||||
if (report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded)
|
||||
{
|
||||
Debug.LogError("GenerateStripedAOTDlls 失败");
|
||||
return;
|
||||
throw new Exception("GenerateStripedAOTDlls 失败");
|
||||
}
|
||||
Debug.Log($"GenerateStripedAOTDlls target:{target} group:{group} path:{outputPath}");
|
||||
}
|
||||
|
||||
@@ -88,6 +88,21 @@ namespace HybridCLR.Editor.Installer
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
private static void CopyWithCheckLongFile(string srcFile, string dstFile)
|
||||
{
|
||||
if (srcFile.Length > 255)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"srcFile:{srcFile} path is too long. copy ignore!");
|
||||
return;
|
||||
}
|
||||
if (dstFile.Length > 255)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"dstFile:{dstFile} path is too long. copy ignore!");
|
||||
return;
|
||||
}
|
||||
File.Copy(srcFile, dstFile);
|
||||
}
|
||||
|
||||
public static void CopyDir(string src, string dst, bool log = false)
|
||||
{
|
||||
if (log)
|
||||
@@ -98,7 +113,7 @@ namespace HybridCLR.Editor.Installer
|
||||
Directory.CreateDirectory(dst);
|
||||
foreach(var file in Directory.GetFiles(src))
|
||||
{
|
||||
File.Copy(file, $"{dst}/{Path.GetFileName(file)}");
|
||||
CopyWithCheckLongFile(file, $"{dst}/{Path.GetFileName(file)}");
|
||||
}
|
||||
foreach(var subDir in Directory.GetDirectories(src))
|
||||
{
|
||||
|
||||
@@ -166,10 +166,11 @@ namespace HybridCLR.Editor.Installer
|
||||
return $"{contentPath}/il2cpp";
|
||||
}
|
||||
|
||||
public string ApplicationIl2cppPath => GetIl2CppPathByContentPath(EditorApplication.applicationContentsPath);
|
||||
|
||||
public void InstallDefaultHybridCLR()
|
||||
{
|
||||
RunInitLocalIl2CppData(GetIl2CppPathByContentPath(EditorApplication.applicationContentsPath), _curVersion);
|
||||
InstallFromLocal(PrepareLibil2cppWithHybridclrFromGitRepo());
|
||||
}
|
||||
|
||||
public bool HasInstalledHybridCLR()
|
||||
@@ -202,7 +203,42 @@ namespace HybridCLR.Editor.Installer
|
||||
BashUtil.RunCommand(workDir, "git", new string[] {"clone", "-b", branch, "--depth", "1", repoUrl, repoDir});
|
||||
}
|
||||
|
||||
private void RunInitLocalIl2CppData(string editorIl2cppPath, UnityVersion version)
|
||||
private string PrepareLibil2cppWithHybridclrFromGitRepo()
|
||||
{
|
||||
string workDir = SettingsUtil.HybridCLRDataDir;
|
||||
Directory.CreateDirectory(workDir);
|
||||
//BashUtil.RecreateDir(workDir);
|
||||
|
||||
// clone hybridclr
|
||||
string hybridclrRepoURL = HybridCLRSettings.Instance.hybridclrRepoURL;
|
||||
string hybridclrRepoDir = $"{workDir}/{hybridclr_repo_path}";
|
||||
CloneBranch(workDir, hybridclrRepoURL, _curDefaultVersion.hybridclr.branch, hybridclrRepoDir);
|
||||
|
||||
if (!Directory.Exists(hybridclrRepoDir))
|
||||
{
|
||||
throw new Exception($"clone hybridclr fail. url: {hybridclrRepoURL}");
|
||||
}
|
||||
|
||||
// clone il2cpp_plus
|
||||
string il2cppPlusRepoURL = HybridCLRSettings.Instance.il2cppPlusRepoURL;
|
||||
string il2cppPlusRepoDir = $"{workDir}/{il2cpp_plus_repo_path}";
|
||||
CloneBranch(workDir, il2cppPlusRepoURL, _curDefaultVersion.il2cpp_plus.branch, il2cppPlusRepoDir);
|
||||
|
||||
if (!Directory.Exists(il2cppPlusRepoDir))
|
||||
{
|
||||
throw new Exception($"clone il2cpp_plus fail. url: {il2cppPlusRepoDir}");
|
||||
}
|
||||
|
||||
Directory.Move($"{hybridclrRepoDir}/hybridclr", $"{il2cppPlusRepoDir}/libil2cpp/hybridclr");
|
||||
return $"{il2cppPlusRepoDir}/libil2cpp";
|
||||
}
|
||||
|
||||
public void InstallFromLocal(string libil2cppWithHybridclrSourceDir)
|
||||
{
|
||||
RunInitLocalIl2CppData(ApplicationIl2cppPath, libil2cppWithHybridclrSourceDir, _curVersion);
|
||||
}
|
||||
|
||||
private void RunInitLocalIl2CppData(string editorIl2cppPath, string libil2cppWithHybridclrSourceDir, UnityVersion version)
|
||||
{
|
||||
if (!IsComaptibleVersion())
|
||||
{
|
||||
@@ -217,15 +253,6 @@ namespace HybridCLR.Editor.Installer
|
||||
BashUtil.RemoveDir(buildiOSDir);
|
||||
BashUtil.CopyDir($"{SettingsUtil.HybridCLRDataPathInPackage}/iOSBuild", buildiOSDir, true);
|
||||
|
||||
// clone hybridclr
|
||||
string hybridclrRepoURL = HybridCLRSettings.Instance.hybridclrRepoURL;
|
||||
string hybridclrRepoDir = $"{workDir}/{hybridclr_repo_path}";
|
||||
CloneBranch(workDir, hybridclrRepoURL, _curDefaultVersion.hybridclr.branch, hybridclrRepoDir);
|
||||
|
||||
// clone il2cpp_plus
|
||||
string il2cppPlusRepoURL = HybridCLRSettings.Instance.il2cppPlusRepoURL;
|
||||
string il2cppPlusRepoDir = $"{workDir}/{il2cpp_plus_repo_path}";
|
||||
CloneBranch(workDir, il2cppPlusRepoURL, _curDefaultVersion.il2cpp_plus.branch, il2cppPlusRepoDir);
|
||||
|
||||
// create LocalIl2Cpp
|
||||
string localUnityDataDir = SettingsUtil.LocalUnityDataDir;
|
||||
@@ -239,8 +266,7 @@ namespace HybridCLR.Editor.Installer
|
||||
|
||||
// replace libil2cpp
|
||||
string dstLibil2cppDir = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp";
|
||||
BashUtil.CopyDir($"{il2cppPlusRepoDir}/libil2cpp", dstLibil2cppDir, true);
|
||||
BashUtil.CopyDir($"{hybridclrRepoDir}/hybridclr", $"{dstLibil2cppDir}/hybridclr", true);
|
||||
BashUtil.CopyDir($"{libil2cppWithHybridclrSourceDir}", dstLibil2cppDir, true);
|
||||
|
||||
// clean Il2cppBuildCache
|
||||
BashUtil.RemoveDir($"{SettingsUtil.ProjectDir}/Library/Il2cppBuildCache", true);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
@@ -10,6 +11,10 @@ namespace HybridCLR.Editor.Installer
|
||||
{
|
||||
private InstallerController _controller;
|
||||
|
||||
private bool _installFromDir;
|
||||
|
||||
private string _installLibil2cppWithHybridclrSourceDir;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_controller = new InstallerController();
|
||||
@@ -66,6 +71,17 @@ namespace HybridCLR.Editor.Installer
|
||||
|
||||
private void GUIInstallButton(string content, string button)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
_installFromDir = EditorGUILayout.Toggle("从本地复制libil2cpp", _installFromDir);
|
||||
EditorGUI.BeginDisabledGroup(!_installFromDir);
|
||||
EditorGUILayout.TextField(_installLibil2cppWithHybridclrSourceDir, GUILayout.Width(400));
|
||||
if (GUILayout.Button("选择目录", GUILayout.Width(100)))
|
||||
{
|
||||
_installLibil2cppWithHybridclrSourceDir = EditorUtility.OpenFolderPanel("选择libil2cpp目录", Application.dataPath, "libil2cpp");
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField(content);
|
||||
if (GUILayout.Button(button, GUILayout.Width(100)))
|
||||
@@ -79,7 +95,24 @@ namespace HybridCLR.Editor.Installer
|
||||
|
||||
private void InstallLocalHybridCLR()
|
||||
{
|
||||
_controller.InstallDefaultHybridCLR();
|
||||
if (_installFromDir)
|
||||
{
|
||||
if (!Directory.Exists(_installLibil2cppWithHybridclrSourceDir))
|
||||
{
|
||||
Debug.LogError($"本地libil2cpp复制目录不存在. '{_installLibil2cppWithHybridclrSourceDir}'");
|
||||
return;
|
||||
}
|
||||
if (!File.Exists($"{_installLibil2cppWithHybridclrSourceDir}/il2cpp-config.h") || !File.Exists($"{_installLibil2cppWithHybridclrSourceDir}/hybridclr/RuntimeApi.cpp"))
|
||||
{
|
||||
Debug.LogError($"本地libil2cpp不是合法有效的源码目录. '{_installLibil2cppWithHybridclrSourceDir}'");
|
||||
return;
|
||||
}
|
||||
_controller.InstallFromLocal(_installLibil2cppWithHybridclrSourceDir);
|
||||
}
|
||||
else
|
||||
{
|
||||
_controller.InstallDefaultHybridCLR();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,14 @@ namespace HybridCLR.Editor.Meta
|
||||
}
|
||||
if (throwExIfNotFind)
|
||||
{
|
||||
#if UNITY_2021_1_OR_NEWER && UNITY_IOS
|
||||
throw new Exception($"resolve assembly:{assemblyName} 失败! 请按照Install文档正确替换了UnityEditor.CoreModule.dll或者升级hybridclr_unity到2.0.1及更高版本");
|
||||
#else
|
||||
throw new Exception($"resolve assembly:{assemblyName} 失败! 请参阅常见错误文档");
|
||||
#endif
|
||||
if (SettingsUtil.HotUpdateAssemblyNamesIncludePreserved.Contains(assemblyName))
|
||||
{
|
||||
throw new Exception($"resolve 热更新 dll:{assemblyName} 失败!请确保已经编译了热更新dll或者外部热更新路径中配置了正确的值。更多请参阅常见错误文档");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"resolve AOT dll:{assemblyName} 失败! 请确保主工程已经引用了该dll并且正确生成了裁剪后的AOT dll。更多请参阅常见错误文档");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ Unity Package for HybridCLR
|
||||
|
||||
## 改动日志
|
||||
|
||||
- v2.3.0 支持从本地目录直接复制hybridclr源码。轻微修复2019版本某些情况下路径过长导致安装失败的问题。
|
||||
- v2.2.0 支持2020.3.47及2021.3.23
|
||||
- v2.0.5 Installer使用tag而不是commit id,安装时不必拉取整个branch,大幅缩短安装时间
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
# 发布日志
|
||||
|
||||
## 2.4.2
|
||||
|
||||
### 改动
|
||||
|
||||
- 支持 2020.3.48,最后一个2020LTS版本
|
||||
- 支持 2021.3.25
|
||||
- hybridclr 升级到 v2.3.1
|
||||
- il2cpp_plus 升级到 v2020-2.2.1 、v2021-2.2.1
|
||||
|
||||
## 2.4.1
|
||||
|
||||
### 修复
|
||||
|
||||
- 修复遗漏 RELEASELOG.md.meta 文件的问题
|
||||
|
||||
## 2.4.0
|
||||
|
||||
### 改动
|
||||
|
||||
- CheckSettings中检查ScriptingBackend及ApiCompatibleLevel,切换为正确的值
|
||||
- hybridclr 升级到v2.3.0版本
|
||||
- il2cpp_plus 升级到v2019-2.2.0、v2020-2.2.0、v2021-2.2.0版本
|
||||
|
||||
### 修复
|
||||
|
||||
- 新增 MsvcStdextWorkaround.cs 解决2020 vs下stdext编译错误的问题
|
||||
- 修复当struct只包含一个float或double字段时,在arm64上计算桥接函数签名错误的bug
|
||||
|
||||
## 2.3.1
|
||||
|
||||
### 修复
|
||||
- 修复本地复制libil2cpp却仍然从仓库下载安装的bug
|
||||
|
||||
## 2.3.0
|
||||
|
||||
### 改动
|
||||
|
||||
- Installer支持从本地目录复制改造后的libil2cpp
|
||||
|
||||
### 修复
|
||||
|
||||
- 修复2019版本MonoBleedingEdge的子目录中包含了过长路径的文件导致Installer复制文件出错的问题
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b2d5d0a85ef3bf44be6cbe94ed5ed2a
|
||||
guid: 8e53ce54bd8e88c4785c625555308dba
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
+9
-7
@@ -1,21 +1,23 @@
|
||||
{
|
||||
"name": "com.focus-creative-games.hybridclr_unity",
|
||||
"version": "2.0.11",
|
||||
"version": "2.4.2",
|
||||
"displayName": "HybridCLR",
|
||||
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
|
||||
"description": "HybridCLR is a fully featured, zero-cost, high-performance, low-memory solution for Unity's all-platform native c# hotupdate.",
|
||||
"category": "Runtime",
|
||||
"documentationUrl": "https://focus-creative-games.github.io/hybridclr/index",
|
||||
"changelogUrl": "https://github.com/focus-creative-games/hybridclr/commits/main",
|
||||
"documentationUrl": "https://focus-creative-games.github.io/hybridclr-doc",
|
||||
"changelogUrl": "https://focus-creative-games.github.io/hybridclr-doc/#/other/changelog",
|
||||
"licensesUrl": "https://github.com/focus-creative-games/hybridclr/blob/main/LICENSE",
|
||||
"keywords": [
|
||||
"HybridCLR",
|
||||
"hotupdate",
|
||||
"hotfix",
|
||||
"code philosophy",
|
||||
"unity",
|
||||
"focus-creative-games"
|
||||
],
|
||||
"author": {
|
||||
"name": "focus-creative-games",
|
||||
"email": "hybridclr@focus-creative-games.com",
|
||||
"url": "https://github.com/focus-creative-games/"
|
||||
"name": "Code Philosophy",
|
||||
"email": "hybridclr@code-philosophy.com",
|
||||
"url": "https://code-philosophy.com"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user