mirror of
https://github.com/focus-creative-games/hybridclr_unity.git
synced 2026-11-20 07:22:39 +08:00
Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 51da1d4c43 | |||
| 71ad34d7ac | |||
| 7c29ab804b | |||
| 9b269ea4c2 | |||
| c9ad6880cb | |||
| 372fa9e06e | |||
| 3df95d138d | |||
| 410bb9b542 | |||
| 15155b9a46 | |||
| f810ede6d7 | |||
| 63d9e7f4c3 | |||
| 3cea936aa4 | |||
| d90faed922 | |||
| febff1c658 | |||
| 94a329a522 | |||
| 84ed2e6b9d | |||
| 47fbd443c1 | |||
| d5b52cc8db | |||
| d9ed27abfb | |||
| f51c2803c1 | |||
| 05a34d4d12 | |||
| 216d09f7b6 | |||
| 8d441a02d2 | |||
| de2bc21f20 | |||
| 4aba5c2a5e | |||
| b573e61504 | |||
| 69de3d733d | |||
| a77ed7369a | |||
| 1bd27a3e22 | |||
| 4da7c1a524 | |||
| 5c750e9c02 | |||
| cc09487671 |
Binary file not shown.
Binary file not shown.
@@ -1,18 +0,0 @@
|
||||
#include <codegen/il2cpp-codegen-metadata.h>
|
||||
#include "vm/ClassInlines.h"
|
||||
#include "vm/Object.h"
|
||||
#include "vm/Class.h"
|
||||
|
||||
#include "../metadata/MetadataModule.h"
|
||||
#include "../metadata/MetadataUtil.h"
|
||||
|
||||
#include "../interpreter/MethodBridge.h"
|
||||
#include "../interpreter/Interpreter.h"
|
||||
#include "../interpreter/MemoryUtil.h"
|
||||
#include "../interpreter/InstrinctDef.h"
|
||||
|
||||
using namespace hybridclr::interpreter;
|
||||
|
||||
//!!!{{CODE
|
||||
|
||||
//!!!}}CODE
|
||||
@@ -1,30 +0,0 @@
|
||||
#include "../metadata/ReversePInvokeMethodStub.h"
|
||||
#include "../metadata/MetadataModule.h"
|
||||
|
||||
namespace hybridclr
|
||||
{
|
||||
namespace metadata
|
||||
{
|
||||
|
||||
//!!!{{CODE
|
||||
|
||||
void __ReversePInvokeMethod_0(void* xState)
|
||||
{
|
||||
CallLuaFunction(xState, 0);
|
||||
}
|
||||
|
||||
void __ReversePInvokeMethod_1(void* xState)
|
||||
{
|
||||
CallLuaFunction(xState, 1);
|
||||
}
|
||||
|
||||
Il2CppMethodPointer s_ReversePInvokeMethodStub[]
|
||||
{
|
||||
(Il2CppMethodPointer)__ReversePInvokeMethod_0,
|
||||
(Il2CppMethodPointer)__ReversePInvokeMethod_1,
|
||||
nullptr,
|
||||
};
|
||||
|
||||
//!!!}}CODE
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,18 @@
|
||||
"versions": [
|
||||
{
|
||||
"unity_version":"2020",
|
||||
"hybridclr" : { "branch":"v4.0.4"},
|
||||
"il2cpp_plus": { "branch":"v2020-4.0.2"}
|
||||
"hybridclr" : { "branch":"v4.0.10"},
|
||||
"il2cpp_plus": { "branch":"v2020-4.0.8"}
|
||||
},
|
||||
{
|
||||
"unity_version":"2021",
|
||||
"hybridclr" : { "branch":"v4.0.4"},
|
||||
"il2cpp_plus": { "branch":"v2021-4.0.2"}
|
||||
"hybridclr" : { "branch":"v4.0.10"},
|
||||
"il2cpp_plus": { "branch":"v2021-4.0.8"}
|
||||
},
|
||||
{
|
||||
"unity_version":"2022",
|
||||
"hybridclr" : { "branch":"v4.0.4"},
|
||||
"il2cpp_plus": { "branch":"v2022-4.0.2"}
|
||||
"hybridclr" : { "branch":"v4.0.10"},
|
||||
"il2cpp_plus": { "branch":"v2022-4.0.8"}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -48,7 +48,7 @@ namespace HybridCLR.Editor.ABI
|
||||
|
||||
public bool Equals(TypeInfo other)
|
||||
{
|
||||
return PorType == other.PorType && object.Equals(Klass, other.Klass);
|
||||
return PorType == other.PorType && TypeEqualityComparer.Instance.Equals(Klass, other.Klass);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
@@ -58,7 +58,7 @@ namespace HybridCLR.Editor.ABI
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return (int)PorType * 23 + (Klass?.GetHashCode() ?? 0);
|
||||
return (int)PorType * 23 + (Klass != null ? TypeEqualityComparer.Instance.GetHashCode(Klass) : 0);
|
||||
}
|
||||
|
||||
public bool NeedExpandValue()
|
||||
|
||||
@@ -6,13 +6,14 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using System.Reflection;
|
||||
using HybridCLR.Editor.Settings;
|
||||
#if (UNITY_2020 || UNITY_2021) && UNITY_IOS
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEditor.iOS.Xcode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor
|
||||
namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
public static class AddLil2cppSourceCodeToXcodeproj2021OrOlder
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using HybridCLR.Editor.Installer;
|
||||
using HybridCLR.Editor.Settings;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
@@ -8,7 +9,7 @@ using UnityEngine;
|
||||
|
||||
#if UNITY_2022_2_OR_NEWER && UNITY_IOS
|
||||
|
||||
namespace HybridCLR.Editor
|
||||
namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
public static class AddLil2cppSourceCodeToXcodeproj2022OrNewer
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using HybridCLR.Editor.Settings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -55,6 +56,11 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
throw new BuildFailedException($"You have not initialized HybridCLR, please install it via menu 'HybridCLR/Installer'");
|
||||
}
|
||||
|
||||
if (installer.PackageVersion != installer.InstalledLibil2cppVersion)
|
||||
{
|
||||
throw new BuildFailedException($"You must run `HybridCLR/Installer` after upgrading package");
|
||||
}
|
||||
|
||||
HybridCLRSettings gs = SettingsUtil.HybridCLRSettings;
|
||||
if (((gs.hotUpdateAssemblies?.Length + gs.hotUpdateAssemblyDefinitions?.Length) ?? 0) == 0)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using HybridCLR.Editor.Installer;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -13,7 +14,7 @@ using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
internal class CopyStrippedAOTAssemblies : IPostprocessBuildWithReport
|
||||
internal class CopyStrippedAOTAssemblies : IPostprocessBuildWithReport, IPreprocessBuildWithReport
|
||||
#if !UNITY_2021_1_OR_NEWER
|
||||
, IIl2CppProcessor
|
||||
#endif
|
||||
@@ -95,5 +96,12 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void OnPreprocessBuild(BuildReport report)
|
||||
{
|
||||
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
|
||||
var dstPath = SettingsUtil.GetAssembliesPostIl2CppStripDir(target);
|
||||
BashUtil.RecreateDir(dstPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,24 +3,28 @@ using System;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
|
||||
public class MsvcStdextWorkaround : IPreprocessBuildWithReport
|
||||
namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
const string kWorkaroundFlag = "/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS";
|
||||
|
||||
public int callbackOrder => 0;
|
||||
|
||||
public void OnPreprocessBuild(BuildReport report)
|
||||
public class MsvcStdextWorkaround : IPreprocessBuildWithReport
|
||||
{
|
||||
var clEnv = Environment.GetEnvironmentVariable("_CL_");
|
||||
const string kWorkaroundFlag = "/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS";
|
||||
|
||||
if (string.IsNullOrEmpty(clEnv))
|
||||
public int callbackOrder => 0;
|
||||
|
||||
public void OnPreprocessBuild(BuildReport report)
|
||||
{
|
||||
Environment.SetEnvironmentVariable("_CL_", kWorkaroundFlag);
|
||||
}
|
||||
else if (!clEnv.Contains(kWorkaroundFlag))
|
||||
{
|
||||
clEnv += " " + kWorkaroundFlag;
|
||||
Environment.SetEnvironmentVariable("_CL_", clEnv);
|
||||
var clEnv = Environment.GetEnvironmentVariable("_CL_");
|
||||
|
||||
if (string.IsNullOrEmpty(clEnv))
|
||||
{
|
||||
Environment.SetEnvironmentVariable("_CL_", kWorkaroundFlag);
|
||||
}
|
||||
else if (!clEnv.Contains(kWorkaroundFlag))
|
||||
{
|
||||
clEnv += " " + kWorkaroundFlag;
|
||||
Environment.SetEnvironmentVariable("_CL_", clEnv);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,13 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
#endif
|
||||
IPostprocessBuildWithReport
|
||||
#if !UNITY_2021_1_OR_NEWER && UNITY_WEBGL
|
||||
, IIl2CppProcessor
|
||||
, IIl2CppProcessor
|
||||
#endif
|
||||
|
||||
#if UNITY_PS5
|
||||
, IUnityLinkerProcessor
|
||||
#endif
|
||||
|
||||
{
|
||||
public int callbackOrder => 0;
|
||||
|
||||
@@ -45,11 +50,22 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
// 如果target为Android,由于已经在OnPostGenerateGradelAndroidProject中处理过,
|
||||
// 这里不再重复处理
|
||||
#if !UNITY_ANDROID && !UNITY_WEBGL
|
||||
|
||||
PathScriptingAssembilesFile(report.summary.outputPath);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UNITY_PS5
|
||||
/// <summary>
|
||||
/// 打包模式如果是 Package 需要在这个阶段提前处理 .json , PC Hosted 和 GP5 模式不受影响
|
||||
/// </summary>
|
||||
|
||||
public string GenerateAdditionalLinkXmlFile(UnityEditor.Build.Reporting.BuildReport report, UnityEditor.UnityLinker.UnityLinkerBuildPipelineData data)
|
||||
{
|
||||
string path = $"{SettingsUtil.ProjectDir}/Library/PlayerDataCache/PS5/Data";
|
||||
PathScriptingAssembilesFile(path);
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
public void PathScriptingAssembilesFile(string path)
|
||||
{
|
||||
if (!SettingsUtil.Enable)
|
||||
@@ -78,7 +94,7 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
|
||||
if (jsonFiles.Length == 0)
|
||||
{
|
||||
//Debug.LogError($"can not find file {SettingsUtil.ScriptingAssembliesJsonFile}");
|
||||
Debug.LogWarning($"can not find file {SettingsUtil.ScriptingAssembliesJsonFile}");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor.Commands
|
||||
@@ -29,8 +30,9 @@ namespace HybridCLR.Editor.Commands
|
||||
Directory.Delete(il2cppBuildCachePath, true);
|
||||
}
|
||||
|
||||
private static void GenerateMethodBridgeCppFile(Analyzer analyzer, string templateCode, string outputFile)
|
||||
private static void GenerateMethodBridgeCppFile(Analyzer analyzer, string outputFile)
|
||||
{
|
||||
string templateCode = File.ReadAllText(outputFile, Encoding.UTF8);
|
||||
var g = new Generator(new Generator.Options()
|
||||
{
|
||||
TemplateCode = templateCode,
|
||||
@@ -40,21 +42,27 @@ namespace HybridCLR.Editor.Commands
|
||||
|
||||
g.PrepareMethods();
|
||||
g.Generate();
|
||||
Debug.LogFormat("== output:{0} ==", outputFile);
|
||||
Debug.LogFormat("[MethodBridgeGeneratorCommand] output:{0}", outputFile);
|
||||
}
|
||||
|
||||
[MenuItem("HybridCLR/Generate/MethodBridge", priority = 101)]
|
||||
public static void CompileAndGenerateMethodBridge()
|
||||
{
|
||||
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
|
||||
CompileDllCommand.CompileDll(target);
|
||||
GenerateMethodBridge(target);
|
||||
}
|
||||
|
||||
public static void GenerateMethodBridge(BuildTarget target)
|
||||
{
|
||||
List<string> hotUpdateDllNames = SettingsUtil.HotUpdateAssemblyNamesExcludePreserved;
|
||||
using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotUpdateDllNames), hotUpdateDllNames))
|
||||
string aotDllDir = SettingsUtil.GetAssembliesPostIl2CppStripDir(target);
|
||||
List<string> aotAssemblyNames = Directory.Exists(aotDllDir) ?
|
||||
Directory.GetFiles(aotDllDir, "*.dll", SearchOption.TopDirectoryOnly).Select(Path.GetFileNameWithoutExtension).ToList()
|
||||
: new List<string>();
|
||||
if (aotAssemblyNames.Count == 0)
|
||||
{
|
||||
throw new Exception($"no aot assembly found. please run `HybridCLR/Generate/All` or `HybridCLR/Generate/AotDlls` to generate aot dlls before runing `HybridCLR/Generate/MethodBridge`");
|
||||
}
|
||||
using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateAOTAssemblyResolver(target), aotAssemblyNames))
|
||||
{
|
||||
var analyzer = new Analyzer(new Analyzer.Options
|
||||
{
|
||||
@@ -63,9 +71,8 @@ namespace HybridCLR.Editor.Commands
|
||||
});
|
||||
|
||||
analyzer.Run();
|
||||
string templateCode = File.ReadAllText($"{SettingsUtil.TemplatePathInPackage}/MethodBridgeStub.cpp");
|
||||
string outputFile = $"{SettingsUtil.GeneratedCppDir}/MethodBridge.cpp";
|
||||
GenerateMethodBridgeCppFile(analyzer, templateCode, outputFile);
|
||||
GenerateMethodBridgeCppFile(analyzer, outputFile);
|
||||
}
|
||||
|
||||
CleanIl2CppBuildCache();
|
||||
|
||||
@@ -35,13 +35,13 @@ namespace HybridCLR.Editor.Commands
|
||||
var analyzer = new ReversePInvokeWrap.Analyzer(cache, hotUpdateDlls);
|
||||
analyzer.Run();
|
||||
|
||||
string templateCode = File.ReadAllText($"{SettingsUtil.TemplatePathInPackage}/ReversePInvokeMethodStub.cpp");
|
||||
string outputFile = $"{SettingsUtil.GeneratedCppDir}/ReversePInvokeMethodStub.cpp";
|
||||
|
||||
List<ABIReversePInvokeMethodInfo> methods = analyzer.BuildABIMethods();
|
||||
Debug.Log($"GenerateReversePInvokeWrapper. wraperCount:{methods.Sum(m => m.Count)} output:{outputFile}");
|
||||
var generator = new Generator();
|
||||
generator.Generate(templateCode, methods, outputFile);
|
||||
generator.Generate(methods, outputFile);
|
||||
Debug.LogFormat("[ReversePInvokeWrapperGeneratorCommand] output:{0}", outputFile);
|
||||
}
|
||||
MethodBridgeGeneratorCommand.CleanIl2CppBuildCache();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace HybridCLR.Editor.Commands
|
||||
|
||||
static BuildOptions GetBuildPlayerOptions(BuildTarget buildTarget)
|
||||
{
|
||||
BuildOptions options = BuildOptions.BuildScriptsOnly;
|
||||
BuildOptions options = BuildOptions.None;
|
||||
bool development = EditorUserBuildSettings.development;
|
||||
if (development)
|
||||
{
|
||||
@@ -84,6 +84,10 @@ namespace HybridCLR.Editor.Commands
|
||||
bool oldBuildScriptsOnly = EditorUserBuildSettings.buildScriptsOnly;
|
||||
EditorUserBuildSettings.buildScriptsOnly = true;
|
||||
|
||||
string location = GetLocationPathName(outputPath, target);
|
||||
string oldBuildLocation = EditorUserBuildSettings.GetBuildLocation(target);
|
||||
EditorUserBuildSettings.SetBuildLocation(target, location);
|
||||
|
||||
switch (target)
|
||||
{
|
||||
case BuildTarget.StandaloneWindows:
|
||||
@@ -113,7 +117,7 @@ namespace HybridCLR.Editor.Commands
|
||||
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions()
|
||||
{
|
||||
scenes = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(),
|
||||
locationPathName = GetLocationPathName(outputPath, target),
|
||||
locationPathName = location,
|
||||
options = buildOptions,
|
||||
target = target,
|
||||
targetGroup = BuildPipeline.GetBuildTargetGroup(target),
|
||||
@@ -122,6 +126,8 @@ namespace HybridCLR.Editor.Commands
|
||||
var report = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||
|
||||
EditorUserBuildSettings.buildScriptsOnly = oldBuildScriptsOnly;
|
||||
EditorUserBuildSettings.SetBuildLocation(target, oldBuildLocation);
|
||||
|
||||
switch (target)
|
||||
{
|
||||
case BuildTarget.StandaloneWindows:
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HybridCLR.Editor.Installer
|
||||
@@ -63,20 +64,34 @@ namespace HybridCLR.Editor.Installer
|
||||
{
|
||||
UnityEngine.Debug.Log($"[BashUtil] RemoveDir dir:{dir}");
|
||||
}
|
||||
if (!Directory.Exists(dir))
|
||||
|
||||
int maxTryCount = 5;
|
||||
for (int i = 0; i < maxTryCount; ++i)
|
||||
{
|
||||
return;
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (var file in Directory.GetFiles(dir))
|
||||
{
|
||||
File.SetAttributes(file, FileAttributes.Normal);
|
||||
File.Delete(file);
|
||||
}
|
||||
foreach (var subDir in Directory.GetDirectories(dir))
|
||||
{
|
||||
RemoveDir(subDir);
|
||||
}
|
||||
Directory.Delete(dir);
|
||||
break;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"[BashUtil] RemoveDir:{dir} with exception:{e}. try count:{i}");
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
foreach (var file in Directory.GetFiles(dir))
|
||||
{
|
||||
File.SetAttributes(file, FileAttributes.Normal);
|
||||
File.Delete(file);
|
||||
}
|
||||
foreach (var subDir in Directory.GetDirectories(dir))
|
||||
{
|
||||
RemoveDir(subDir);
|
||||
}
|
||||
Directory.Delete(dir);
|
||||
}
|
||||
|
||||
public static void RecreateDir(string dir)
|
||||
@@ -90,12 +105,16 @@ namespace HybridCLR.Editor.Installer
|
||||
|
||||
private static void CopyWithCheckLongFile(string srcFile, string dstFile)
|
||||
{
|
||||
if (srcFile.Length > 255)
|
||||
var maxPathLength = 255;
|
||||
#if UNITY_EDITOR_OSX
|
||||
maxPathLength = 1024;
|
||||
#endif
|
||||
if (srcFile.Length > maxPathLength)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"srcFile:{srcFile} path is too long. copy ignore!");
|
||||
return;
|
||||
}
|
||||
if (dstFile.Length > 255)
|
||||
if (dstFile.Length > maxPathLength)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"dstFile:{dstFile} path is too long. copy ignore!");
|
||||
return;
|
||||
|
||||
@@ -7,6 +7,7 @@ using UnityEngine;
|
||||
using Debug = UnityEngine.Debug;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
using HybridCLR.Editor.Settings;
|
||||
|
||||
namespace HybridCLR.Editor.Installer
|
||||
{
|
||||
@@ -26,12 +27,15 @@ namespace HybridCLR.Editor.Installer
|
||||
|
||||
public string PackageVersion { get; private set; }
|
||||
|
||||
public string InstalledLibil2cppVersion { get; private set; }
|
||||
|
||||
public InstallerController()
|
||||
{
|
||||
_curVersion = ParseUnityVersion(Application.unityVersion);
|
||||
_versionManifest = GetHybridCLRVersionManifest();
|
||||
_curDefaultVersion = _versionManifest.versions.FirstOrDefault(v => v.unity_version == _curVersion.major.ToString());
|
||||
PackageVersion = LoadPackageInfo().version;
|
||||
InstalledLibil2cppVersion = ReadLocalVersion();
|
||||
}
|
||||
|
||||
private HybridclrVersionManifest GetHybridCLRVersionManifest()
|
||||
@@ -156,6 +160,24 @@ namespace HybridCLR.Editor.Installer
|
||||
|
||||
public string ApplicationIl2cppPath => GetIl2CppPathByContentPath(EditorApplication.applicationContentsPath);
|
||||
|
||||
public string LocalVersionFile => $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/hybridclr/generated/libil2cpp-version.txt";
|
||||
|
||||
private string ReadLocalVersion()
|
||||
{
|
||||
if (!File.Exists(LocalVersionFile))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return File.ReadAllText(LocalVersionFile, Encoding.UTF8);
|
||||
}
|
||||
|
||||
public void WriteLocalVersion()
|
||||
{
|
||||
InstalledLibil2cppVersion = PackageVersion;
|
||||
File.WriteAllText(LocalVersionFile, PackageVersion, Encoding.UTF8);
|
||||
Debug.Log($"Write installed version:'{PackageVersion}' to {LocalVersionFile}");
|
||||
}
|
||||
|
||||
public void InstallDefaultHybridCLR()
|
||||
{
|
||||
InstallFromLocal(PrepareLibil2cppWithHybridclrFromGitRepo());
|
||||
@@ -236,6 +258,7 @@ namespace HybridCLR.Editor.Installer
|
||||
|
||||
if (HasInstalledHybridCLR())
|
||||
{
|
||||
WriteLocalVersion();
|
||||
Debug.Log("Install Sucessfully");
|
||||
}
|
||||
else
|
||||
|
||||
@@ -46,7 +46,9 @@ namespace HybridCLR.Editor.Installer
|
||||
|
||||
EditorGUILayout.LabelField($"Package Version: v{_controller.PackageVersion}");
|
||||
GUILayout.Space(5f);
|
||||
|
||||
EditorGUILayout.LabelField($"Installed Version: {_controller.InstalledLibil2cppVersion ?? "Unknown"}");
|
||||
GUILayout.Space(5f);
|
||||
|
||||
GUILayout.Space(10f);
|
||||
|
||||
InstallerController.CompatibleType compatibleType = _controller.GetCompatibleType();
|
||||
|
||||
@@ -9,73 +9,12 @@ using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor.Meta
|
||||
{
|
||||
public class AssemblyCache : IDisposable
|
||||
public class AssemblyCache : AssemblyCacheBase
|
||||
{
|
||||
private readonly IAssemblyResolver _assemblyPathResolver;
|
||||
private readonly ModuleContext _modCtx;
|
||||
private readonly AssemblyResolver _asmResolver;
|
||||
private bool disposedValue;
|
||||
|
||||
public Dictionary<string, ModuleDefMD> LoadedModules { get; } = new Dictionary<string, ModuleDefMD>();
|
||||
|
||||
public AssemblyCache(IAssemblyResolver assemblyResolver)
|
||||
public AssemblyCache(IAssemblyResolver assemblyResolver) : base(assemblyResolver)
|
||||
{
|
||||
_assemblyPathResolver = assemblyResolver;
|
||||
_modCtx = ModuleDef.CreateModuleContext();
|
||||
_asmResolver = (AssemblyResolver)_modCtx.AssemblyResolver;
|
||||
_asmResolver.EnableTypeDefCache = true;
|
||||
_asmResolver.UseGAC = false;
|
||||
}
|
||||
|
||||
public ModuleDefMD LoadModule(string moduleName, bool loadReferenceAssemblies = true)
|
||||
{
|
||||
// Debug.Log($"load module:{moduleName}");
|
||||
if (LoadedModules.TryGetValue(moduleName, out var mod))
|
||||
{
|
||||
return mod;
|
||||
}
|
||||
mod = DoLoadModule(_assemblyPathResolver.ResolveAssembly(moduleName, true));
|
||||
LoadedModules.Add(moduleName, mod);
|
||||
|
||||
if (loadReferenceAssemblies)
|
||||
{
|
||||
foreach (var refAsm in mod.GetAssemblyRefs())
|
||||
{
|
||||
LoadModule(refAsm.Name);
|
||||
}
|
||||
}
|
||||
|
||||
return mod;
|
||||
}
|
||||
|
||||
private ModuleDefMD DoLoadModule(string dllPath)
|
||||
{
|
||||
//Debug.Log($"do load module:{dllPath}");
|
||||
ModuleDefMD mod = ModuleDefMD.Load(dllPath, _modCtx);
|
||||
_asmResolver.AddToCache(mod);
|
||||
return mod;
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
foreach(var mod in LoadedModules.Values)
|
||||
{
|
||||
mod.Dispose();
|
||||
}
|
||||
LoadedModules.Clear();
|
||||
}
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
using dnlib.DotNet;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HybridCLR.Editor.Meta
|
||||
{
|
||||
public abstract class AssemblyCacheBase : IDisposable
|
||||
{
|
||||
private readonly IAssemblyResolver _assemblyPathResolver;
|
||||
private readonly ModuleContext _modCtx;
|
||||
private readonly AssemblyResolver _asmResolver;
|
||||
private bool disposedValue;
|
||||
private bool _loadedNetstandard;
|
||||
|
||||
public Dictionary<string, ModuleDefMD> LoadedModules { get; } = new Dictionary<string, ModuleDefMD>();
|
||||
|
||||
private readonly List<ModuleDefMD> _loadedModulesIncludeNetstandard = new List<ModuleDefMD>();
|
||||
|
||||
protected AssemblyCacheBase(IAssemblyResolver assemblyResolver)
|
||||
{
|
||||
_assemblyPathResolver = assemblyResolver;
|
||||
_modCtx = ModuleDef.CreateModuleContext();
|
||||
_asmResolver = (AssemblyResolver)_modCtx.AssemblyResolver;
|
||||
_asmResolver.EnableTypeDefCache = true;
|
||||
_asmResolver.UseGAC = false;
|
||||
}
|
||||
|
||||
public ModuleDefMD LoadModule(string moduleName, bool loadReferenceAssemblies = true)
|
||||
{
|
||||
// Debug.Log($"load module:{moduleName}");
|
||||
if (LoadedModules.TryGetValue(moduleName, out var mod))
|
||||
{
|
||||
return mod;
|
||||
}
|
||||
if (moduleName == "netstandard")
|
||||
{
|
||||
if (!_loadedNetstandard)
|
||||
{
|
||||
LoadNetStandard();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
mod = DoLoadModule(_assemblyPathResolver.ResolveAssembly(moduleName, true));
|
||||
LoadedModules.Add(moduleName, mod);
|
||||
|
||||
if (loadReferenceAssemblies)
|
||||
{
|
||||
foreach (var refAsm in mod.GetAssemblyRefs())
|
||||
{
|
||||
LoadModule(refAsm.Name);
|
||||
}
|
||||
}
|
||||
|
||||
return mod;
|
||||
}
|
||||
|
||||
private void LoadNetStandard()
|
||||
{
|
||||
string netstandardDllPath = _assemblyPathResolver.ResolveAssembly("netstandard", false);
|
||||
if (!string.IsNullOrEmpty(netstandardDllPath))
|
||||
{
|
||||
DoLoadModule(netstandardDllPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
DoLoadModule(MetaUtil.ResolveNetStandardAssemblyPath("netstandard2.0"));
|
||||
DoLoadModule(MetaUtil.ResolveNetStandardAssemblyPath("netstandard2.1"));
|
||||
}
|
||||
_loadedNetstandard = true;
|
||||
}
|
||||
|
||||
private ModuleDefMD DoLoadModule(string dllPath)
|
||||
{
|
||||
//Debug.Log($"do load module:{dllPath}");
|
||||
ModuleDefMD mod = ModuleDefMD.Load(dllPath, _modCtx);
|
||||
_asmResolver.AddToCache(mod);
|
||||
_loadedModulesIncludeNetstandard.Add(mod);
|
||||
return mod;
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
foreach (var mod in _loadedModulesIncludeNetstandard)
|
||||
{
|
||||
mod.Dispose();
|
||||
}
|
||||
_loadedModulesIncludeNetstandard.Clear();
|
||||
LoadedModules.Clear();
|
||||
}
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b01fa99119e72141bfee5628c0ffce1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -9,17 +9,10 @@ using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor.Meta
|
||||
{
|
||||
public class AssemblyReferenceDeepCollector : IDisposable
|
||||
public class AssemblyReferenceDeepCollector : AssemblyCacheBase
|
||||
{
|
||||
private readonly IAssemblyResolver _assemblyPathResolver;
|
||||
private readonly List<string> _rootAssemblies;
|
||||
|
||||
private readonly ModuleContext _modCtx;
|
||||
private readonly AssemblyResolver _asmResolver;
|
||||
private bool disposedValue;
|
||||
|
||||
public Dictionary<string, ModuleDefMD> LoadedModules { get; } = new Dictionary<string, ModuleDefMD>();
|
||||
|
||||
public IReadOnlyList<string> GetRootAssemblyNames()
|
||||
{
|
||||
return _rootAssemblies;
|
||||
@@ -30,19 +23,19 @@ namespace HybridCLR.Editor.Meta
|
||||
return LoadedModules.Where(e => !_rootAssemblies.Contains(e.Key)).Select(e => e.Value).ToList();
|
||||
}
|
||||
|
||||
public List<ModuleDefMD> GetLoadedModules()
|
||||
{
|
||||
return LoadedModules.Select(e => e.Value).ToList();
|
||||
}
|
||||
|
||||
public List<ModuleDefMD> GetLoadedModulesOfRootAssemblies()
|
||||
{
|
||||
return _rootAssemblies.Select(ass => LoadedModules[ass]).ToList();
|
||||
}
|
||||
|
||||
public AssemblyReferenceDeepCollector(IAssemblyResolver assemblyResolver, List<string> rootAssemblies)
|
||||
public AssemblyReferenceDeepCollector(IAssemblyResolver assemblyResolver, List<string> rootAssemblies) : base(assemblyResolver)
|
||||
{
|
||||
_assemblyPathResolver = assemblyResolver;
|
||||
_rootAssemblies = rootAssemblies;
|
||||
_modCtx = ModuleDef.CreateModuleContext();
|
||||
_asmResolver = (AssemblyResolver)_modCtx.AssemblyResolver;
|
||||
_asmResolver.EnableTypeDefCache = true;
|
||||
_asmResolver.UseGAC = false;
|
||||
LoadAllAssembiles();
|
||||
}
|
||||
|
||||
@@ -53,52 +46,5 @@ namespace HybridCLR.Editor.Meta
|
||||
LoadModule(asm);
|
||||
}
|
||||
}
|
||||
|
||||
private ModuleDefMD LoadModule(string moduleName)
|
||||
{
|
||||
// Debug.Log($"load module:{moduleName}");
|
||||
if (LoadedModules.TryGetValue(moduleName, out var mod))
|
||||
{
|
||||
return mod;
|
||||
}
|
||||
mod = DoLoadModule(_assemblyPathResolver.ResolveAssembly(moduleName, true));
|
||||
LoadedModules.Add(moduleName, mod);
|
||||
|
||||
foreach (var refAsm in mod.GetAssemblyRefs())
|
||||
{
|
||||
LoadModule(refAsm.Name);
|
||||
}
|
||||
return mod;
|
||||
}
|
||||
|
||||
private ModuleDefMD DoLoadModule(string dllPath)
|
||||
{
|
||||
//Debug.Log($"do load module:{dllPath}");
|
||||
ModuleDefMD mod = ModuleDefMD.Load(dllPath, _modCtx);
|
||||
_asmResolver.AddToCache(mod);
|
||||
return mod;
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
foreach(var mod in LoadedModules.Values)
|
||||
{
|
||||
mod.Dispose();
|
||||
}
|
||||
}
|
||||
LoadedModules.Clear();
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using dnlib.DotNet;
|
||||
using HybridCLR.Editor.Meta;
|
||||
using HybridCLR.Editor.Settings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -173,6 +174,10 @@ namespace HybridCLR.Editor.Meta
|
||||
);
|
||||
}
|
||||
|
||||
public static string ResolveNetStandardAssemblyPath(string assemblyName)
|
||||
{
|
||||
return $"{SettingsUtil.HybridCLRDataPathInPackage}/NetStandard/{assemblyName}.dll";
|
||||
}
|
||||
|
||||
|
||||
public static List<TypeSig> CreateDefaultGenericParams(ModuleDef module, int genericParamCount)
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
{
|
||||
// 将所有非泛型函数全部加入函数列表,同时立马walk这些method。
|
||||
// 后续迭代中将只遍历MethodSpec
|
||||
foreach (var ass in _assemblyCollector.GetLoadedModulesExcludeRootAssemblies())
|
||||
foreach (var ass in _assemblyCollector.GetLoadedModules())
|
||||
{
|
||||
foreach (TypeDef typeDef in ass.GetTypes())
|
||||
{
|
||||
|
||||
@@ -52,6 +52,23 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
_typeCreator = new TypeCreator();
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, TypeInfo> _sig2Types = new Dictionary<string, TypeInfo>();
|
||||
|
||||
private TypeInfo GetSharedTypeInfo(TypeSig type)
|
||||
{
|
||||
var typeInfo = _typeCreator.CreateTypeInfo(type);
|
||||
if (!typeInfo.IsStruct)
|
||||
{
|
||||
return typeInfo;
|
||||
}
|
||||
string sigName = ToFullName(typeInfo.Klass);
|
||||
if (!_sig2Types.TryGetValue(sigName, out var sharedTypeInfo))
|
||||
{
|
||||
sharedTypeInfo = typeInfo;
|
||||
_sig2Types.Add(sigName, sharedTypeInfo);
|
||||
}
|
||||
return sharedTypeInfo;
|
||||
}
|
||||
|
||||
private MethodDesc CreateMethodDesc(MethodDef methodDef, bool forceRemoveThis, TypeSig returnType, List<TypeSig> parameters)
|
||||
{
|
||||
@@ -70,12 +87,12 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
{
|
||||
throw new Exception($"[PreservedMethod] method:{methodDef} has generic parameters");
|
||||
}
|
||||
paramInfos.Add(new ParamInfo() { Type = _typeCreator.CreateTypeInfo(paramInfo) });
|
||||
paramInfos.Add(new ParamInfo() { Type = GetSharedTypeInfo(paramInfo) });
|
||||
}
|
||||
var mbs = new MethodDesc()
|
||||
{
|
||||
MethodDef = methodDef,
|
||||
ReturnInfo = new ReturnInfo() { Type = returnType != null ? _typeCreator.CreateTypeInfo(returnType) : TypeInfo.s_void },
|
||||
ReturnInfo = new ReturnInfo() { Type = returnType != null ? GetSharedTypeInfo(returnType) : TypeInfo.s_void },
|
||||
ParamInfos = paramInfos,
|
||||
};
|
||||
return mbs;
|
||||
@@ -158,32 +175,222 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
}
|
||||
}
|
||||
|
||||
public void Generate()
|
||||
static void CheckUnique(IEnumerable<string> names)
|
||||
{
|
||||
var set = new HashSet<string>();
|
||||
foreach (var name in names)
|
||||
{
|
||||
if (!set.Add(name))
|
||||
{
|
||||
throw new Exception($"[CheckUnique] duplicate name:{name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<MethodDesc> _managed2NativeMethodList0;
|
||||
private List<MethodDesc> _native2ManagedMethodList0;
|
||||
private List<MethodDesc> _adjustThunkMethodList0;
|
||||
|
||||
private List<TypeInfo> _structTypes0;
|
||||
|
||||
private void CollectTypesAndMethods()
|
||||
{
|
||||
_managed2NativeMethodList0 = _managed2nativeMethodSet.ToList();
|
||||
_managed2NativeMethodList0.Sort((a, b) => string.CompareOrdinal(a.Sig, b.Sig));
|
||||
|
||||
_native2ManagedMethodList0 = _native2managedMethodSet.ToList();
|
||||
_native2ManagedMethodList0.Sort((a, b) => string.CompareOrdinal(a.Sig, b.Sig));
|
||||
|
||||
_adjustThunkMethodList0 = _adjustThunkMethodSet.ToList();
|
||||
_adjustThunkMethodList0.Sort((a, b) => string.CompareOrdinal(a.Sig, b.Sig));
|
||||
|
||||
|
||||
var structTypeSet = new HashSet<TypeInfo>();
|
||||
CollectStructDefs(_managed2NativeMethodList0, structTypeSet);
|
||||
CollectStructDefs(_native2ManagedMethodList0, structTypeSet);
|
||||
CollectStructDefs(_adjustThunkMethodList0, structTypeSet);
|
||||
_structTypes0 = structTypeSet.ToList();
|
||||
_structTypes0.Sort((a, b) => a.TypeId - b.TypeId);
|
||||
|
||||
CheckUnique(_structTypes0.Select(t => ToFullName(t.Klass)));
|
||||
CheckUnique(_structTypes0.Select(t => t.CreateSigName()));
|
||||
|
||||
Debug.LogFormat("== before optimization struct:{3} managed2native:{0} native2managed:{1} adjustThunk:{2}",
|
||||
_managed2NativeMethodList0.Count, _native2ManagedMethodList0.Count, _adjustThunkMethodList0.Count, _structTypes0.Count);
|
||||
}
|
||||
|
||||
private class AnalyzeTypeInfo
|
||||
{
|
||||
public TypeInfo toSharedType;
|
||||
public List<TypeInfo> fields;
|
||||
public string signature;
|
||||
}
|
||||
|
||||
private readonly Dictionary<TypeInfo, AnalyzeTypeInfo> _analyzeTypeInfos = new Dictionary<TypeInfo, AnalyzeTypeInfo>();
|
||||
|
||||
private readonly Dictionary<string, TypeInfo> _signature2Type = new Dictionary<string, TypeInfo>();
|
||||
|
||||
private AnalyzeTypeInfo CalculateAnalyzeTypeInfoBasic(TypeInfo typeInfo)
|
||||
{
|
||||
TypeSig type = typeInfo.Klass;
|
||||
TypeDef typeDef = type.ToTypeDefOrRef().ResolveTypeDefThrow();
|
||||
|
||||
List<TypeSig> klassInst = type.ToGenericInstSig()?.GenericArguments?.ToList();
|
||||
GenericArgumentContext ctx = klassInst != null ? new GenericArgumentContext(klassInst, null) : null;
|
||||
|
||||
ClassLayout sa = typeDef.ClassLayout;
|
||||
var analyzeTypeInfo = new AnalyzeTypeInfo();
|
||||
|
||||
// don't share type with explicit layout
|
||||
if (sa != null)
|
||||
{
|
||||
analyzeTypeInfo.toSharedType = typeInfo;
|
||||
analyzeTypeInfo.signature = typeInfo.CreateSigName();
|
||||
_signature2Type.Add(analyzeTypeInfo.signature, typeInfo);
|
||||
return analyzeTypeInfo;
|
||||
}
|
||||
|
||||
var fields = analyzeTypeInfo.fields = new List<TypeInfo>();
|
||||
|
||||
foreach (FieldDef field in typeDef.Fields)
|
||||
{
|
||||
if (field.IsStatic)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
TypeSig fieldType = ctx != null ? MetaUtil.Inflate(field.FieldType, ctx) : field.FieldType;
|
||||
fields.Add(GetSharedTypeInfo(fieldType));
|
||||
}
|
||||
return analyzeTypeInfo;
|
||||
}
|
||||
|
||||
private string GetOrCalculateTypeInfoSignature(TypeInfo typeInfo)
|
||||
{
|
||||
if (!typeInfo.IsStruct)
|
||||
{
|
||||
return typeInfo.CreateSigName();
|
||||
}
|
||||
|
||||
var ati = _analyzeTypeInfos[typeInfo];
|
||||
|
||||
//if (_analyzeTypeInfos.TryGetValue(typeInfo, out var ati))
|
||||
//{
|
||||
// return ati.signature;
|
||||
//}
|
||||
//ati = CalculateAnalyzeTypeInfoBasic(typeInfo);
|
||||
//_analyzeTypeInfos.Add(typeInfo, ati);
|
||||
if (ati.signature != null)
|
||||
{
|
||||
return ati.signature;
|
||||
}
|
||||
|
||||
var sigBuf = new StringBuilder();
|
||||
foreach (var field in ati.fields)
|
||||
{
|
||||
sigBuf.Append(GetOrCalculateTypeInfoSignature(ToIsomorphicType(field)));
|
||||
}
|
||||
return ati.signature = sigBuf.ToString();
|
||||
}
|
||||
|
||||
private TypeInfo ToIsomorphicType(TypeInfo type)
|
||||
{
|
||||
if (!type.IsStruct)
|
||||
{
|
||||
return type;
|
||||
}
|
||||
if (!_analyzeTypeInfos.TryGetValue(type, out var ati))
|
||||
{
|
||||
ati = CalculateAnalyzeTypeInfoBasic(type);
|
||||
_analyzeTypeInfos.Add(type, ati);
|
||||
}
|
||||
if (ati.toSharedType == null)
|
||||
{
|
||||
string signature = GetOrCalculateTypeInfoSignature(type);
|
||||
Debug.Assert(signature == ati.signature);
|
||||
if (_signature2Type.TryGetValue(signature, out var sharedType))
|
||||
{
|
||||
// Debug.Log($"[ToIsomorphicType] type:{type.Klass} ==> sharedType:{sharedType.Klass} signature:{signature} ");
|
||||
ati.toSharedType = sharedType;
|
||||
}
|
||||
else
|
||||
{
|
||||
ati.toSharedType = type;
|
||||
_signature2Type.Add(signature, type);
|
||||
}
|
||||
}
|
||||
return ati.toSharedType;
|
||||
}
|
||||
|
||||
private MethodDesc ToIsomorphicMethod(MethodDesc method)
|
||||
{
|
||||
var paramInfos = new List<ParamInfo>();
|
||||
foreach (var paramInfo in method.ParamInfos)
|
||||
{
|
||||
paramInfos.Add(new ParamInfo() { Type = ToIsomorphicType(paramInfo.Type) });
|
||||
}
|
||||
var mbs = new MethodDesc()
|
||||
{
|
||||
MethodDef = method.MethodDef,
|
||||
ReturnInfo = new ReturnInfo() { Type = ToIsomorphicType(method.ReturnInfo.Type) },
|
||||
ParamInfos = paramInfos,
|
||||
};
|
||||
mbs.Init();
|
||||
return mbs;
|
||||
}
|
||||
|
||||
private List<MethodDesc> _managed2NativeMethodList;
|
||||
private List<MethodDesc> _native2ManagedMethodList;
|
||||
private List<MethodDesc> _adjustThunkMethodList;
|
||||
|
||||
private List<TypeInfo> structTypes;
|
||||
|
||||
private void BuildAnalyzeTypeInfos()
|
||||
{
|
||||
foreach (var type in _structTypes0)
|
||||
{
|
||||
ToIsomorphicType(type);
|
||||
}
|
||||
structTypes = _signature2Type.Values.ToList();
|
||||
structTypes.Sort((a, b) => a.TypeId - b.TypeId);
|
||||
}
|
||||
|
||||
private List<MethodDesc> ToUniqueOrderedList(List<MethodDesc> methods)
|
||||
{
|
||||
var methodMap = new SortedDictionary<string, MethodDesc>();
|
||||
foreach (var method in methods)
|
||||
{
|
||||
var sharedMethod = ToIsomorphicMethod(method);
|
||||
var sig = sharedMethod.Sig;
|
||||
if (!methodMap.TryGetValue(sig, out var _))
|
||||
{
|
||||
methodMap.Add(sig, sharedMethod);
|
||||
}
|
||||
}
|
||||
return methodMap.Values.ToList();
|
||||
}
|
||||
|
||||
private void BuildOptimizedMethods()
|
||||
{
|
||||
_managed2NativeMethodList = ToUniqueOrderedList(_managed2NativeMethodList0);
|
||||
_native2ManagedMethodList = ToUniqueOrderedList(_native2ManagedMethodList0);
|
||||
_adjustThunkMethodList = ToUniqueOrderedList(_adjustThunkMethodList0);
|
||||
}
|
||||
|
||||
private void OptimizationTypesAndMethods()
|
||||
{
|
||||
BuildAnalyzeTypeInfos();
|
||||
BuildOptimizedMethods();
|
||||
Debug.LogFormat("== after optimization struct:{3} managed2native:{0} native2managed:{1} adjustThunk:{2}",
|
||||
_managed2NativeMethodList.Count, _native2ManagedMethodList.Count, _adjustThunkMethodList.Count, structTypes.Count);
|
||||
}
|
||||
|
||||
private void GenerateCode()
|
||||
{
|
||||
var frr = new FileRegionReplace(_templateCode);
|
||||
|
||||
List<string> lines = new List<string>(20_0000);
|
||||
|
||||
List<MethodDesc> managed2NativeMethodList = _managed2nativeMethodSet.ToList();
|
||||
managed2NativeMethodList.Sort((a, b) => string.CompareOrdinal(a.Sig, b.Sig));
|
||||
|
||||
List<MethodDesc> native2ManagedMethodList = _native2managedMethodSet.ToList();
|
||||
native2ManagedMethodList.Sort((a, b) => string.CompareOrdinal(a.Sig, b.Sig));
|
||||
|
||||
List<MethodDesc> adjustThunkMethodList = _adjustThunkMethodSet.ToList();
|
||||
adjustThunkMethodList.Sort((a, b) => string.CompareOrdinal(a.Sig, b.Sig));
|
||||
|
||||
Debug.LogFormat("== managed2native:{0} native2managed:{1} adjustThunk:{2}",
|
||||
managed2NativeMethodList.Count, native2ManagedMethodList.Count, adjustThunkMethodList.Count);
|
||||
|
||||
|
||||
var structTypeSet = new HashSet<TypeInfo>();
|
||||
CollectStructDefs(managed2NativeMethodList, structTypeSet);
|
||||
CollectStructDefs(native2ManagedMethodList, structTypeSet);
|
||||
CollectStructDefs(adjustThunkMethodList, structTypeSet);
|
||||
List<TypeInfo> structTypes = structTypeSet.ToList();
|
||||
structTypes.Sort((a, b) => a.TypeId - b.TypeId);
|
||||
|
||||
var classInfos = new List<ClassInfo>();
|
||||
var classTypeSet = new HashSet<TypeInfo>();
|
||||
foreach (var type in structTypes)
|
||||
@@ -192,28 +399,30 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
}
|
||||
|
||||
GenerateStructDefines(classInfos, lines);
|
||||
GenerateStructureSignatureStub(structTypes, lines);
|
||||
|
||||
foreach(var method in managed2NativeMethodList)
|
||||
// use structTypes0 to generate signature
|
||||
GenerateStructureSignatureStub(_structTypes0, lines);
|
||||
|
||||
foreach (var method in _managed2NativeMethodList)
|
||||
{
|
||||
GenerateManaged2NativeMethod(method, lines);
|
||||
}
|
||||
|
||||
GenerateManaged2NativeStub(managed2NativeMethodList, lines);
|
||||
GenerateManaged2NativeStub(_managed2NativeMethodList, lines);
|
||||
|
||||
foreach (var method in native2ManagedMethodList)
|
||||
foreach (var method in _native2ManagedMethodList)
|
||||
{
|
||||
GenerateNative2ManagedMethod(method, lines);
|
||||
}
|
||||
|
||||
GenerateNative2ManagedStub(native2ManagedMethodList, lines);
|
||||
GenerateNative2ManagedStub(_native2ManagedMethodList, lines);
|
||||
|
||||
foreach (var method in adjustThunkMethodList)
|
||||
foreach (var method in _adjustThunkMethodList)
|
||||
{
|
||||
GenerateAdjustThunkMethod(method, lines);
|
||||
}
|
||||
|
||||
GenerateAdjustThunkStub(adjustThunkMethodList, lines);
|
||||
GenerateAdjustThunkStub(_adjustThunkMethodList, lines);
|
||||
|
||||
frr.Replace("CODE", string.Join("\n", lines));
|
||||
|
||||
@@ -222,6 +431,13 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
frr.Commit(_outputFile);
|
||||
}
|
||||
|
||||
public void Generate()
|
||||
{
|
||||
CollectTypesAndMethods();
|
||||
OptimizationTypesAndMethods();
|
||||
GenerateCode();
|
||||
}
|
||||
|
||||
private void CollectStructDefs(List<MethodDesc> methods, HashSet<TypeInfo> structTypes)
|
||||
{
|
||||
foreach (var method in methods)
|
||||
@@ -292,7 +508,7 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
}
|
||||
TypeSig fieldType = ctx != null ? MetaUtil.Inflate(field.FieldType, ctx) : field.FieldType;
|
||||
fieldType = MetaUtil.ToShareTypeSig(corLibTypes, fieldType);
|
||||
var fieldTypeInfo = _typeCreator.CreateTypeInfo(fieldType);
|
||||
var fieldTypeInfo = ToIsomorphicType(_typeCreator.CreateTypeInfo(fieldType));
|
||||
if (fieldTypeInfo.IsStruct)
|
||||
{
|
||||
GenerateClassInfo(fieldTypeInfo, typeSet, classInfos);
|
||||
@@ -325,11 +541,12 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
foreach (var field in ci.fields)
|
||||
{
|
||||
uint offset = field.field.FieldOffset.Value;
|
||||
string fieldName = $"__{field.field.Name.Replace('<', '_').Replace('>', '_')}_{index}";
|
||||
string fieldName = $"__{index}";
|
||||
string commentFieldName = $"{field.field.Name}";
|
||||
lines.Add("\t#pragma pack(push, 1)");
|
||||
lines.Add($"\tstruct {{ {(offset > 0 ? $"char {fieldName}_offsetPadding[{offset}];" : "")} {field.type.GetTypeName()} {fieldName};}};");
|
||||
lines.Add($"\tstruct {{ {(offset > 0 ? $"char {fieldName}_offsetPadding[{offset}];" : "")} {field.type.GetTypeName()} {fieldName};}}; // {commentFieldName}");
|
||||
lines.Add($"\t#pragma pack(pop)");
|
||||
lines.Add($"\tstruct {{ {field.type.GetTypeName()} {fieldName}_forAlignmentOnly;}};");
|
||||
lines.Add($"\tstruct {{ {field.type.GetTypeName()} {fieldName}_forAlignmentOnly;}}; // {commentFieldName}");
|
||||
++index;
|
||||
}
|
||||
}
|
||||
@@ -344,8 +561,9 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
int index = 0;
|
||||
foreach (var field in ci.fields)
|
||||
{
|
||||
string fieldName = $"__{field.field.Name.Replace('<', '_').Replace('>', '_')}_{index}";
|
||||
lines.Add($"\t{field.type.GetTypeName()} {fieldName};");
|
||||
string fieldName = $"__{index}";
|
||||
string commentFieldName = $"{field.field.Name}";
|
||||
lines.Add($"\t{field.type.GetTypeName()} {fieldName}; // {commentFieldName}");
|
||||
++index;
|
||||
}
|
||||
if (classSize > 0)
|
||||
@@ -463,7 +681,8 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
lines.Add("FullName2Signature hybridclr::interpreter::g_fullName2SignatureStub[] = {");
|
||||
foreach (var type in types)
|
||||
{
|
||||
lines.Add($"\t{{\"{ToFullName(type.Klass)}\", \"{type.CreateSigName()}\"}},");
|
||||
TypeInfo isoType = ToIsomorphicType(type);
|
||||
lines.Add($"\t{{\"{ToFullName(type.Klass)}\", \"{isoType.CreateSigName()}\"}},");
|
||||
}
|
||||
lines.Add("\t{ nullptr, nullptr},");
|
||||
lines.Add("};");
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace HybridCLR.Editor.ReversePInvokeWrap
|
||||
|
||||
public Analyzer(AssemblyCache cache, List<string> assemblyNames)
|
||||
{
|
||||
foreach(var assemblyName in assemblyNames)
|
||||
foreach (var assemblyName in assemblyNames)
|
||||
{
|
||||
_rootModules.Add(cache.LoadModule(assemblyName));
|
||||
}
|
||||
|
||||
@@ -2,15 +2,18 @@
|
||||
using HybridCLR.Editor.Template;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor.ReversePInvokeWrap
|
||||
{
|
||||
public class Generator
|
||||
{
|
||||
public void Generate(string template, List<ABIReversePInvokeMethodInfo> methods, string outputFile)
|
||||
public void Generate(List<ABIReversePInvokeMethodInfo> methods, string outputFile)
|
||||
{
|
||||
string template = File.ReadAllText(outputFile, Encoding.UTF8);
|
||||
var frr = new FileRegionReplace(template);
|
||||
var codes = new List<string>();
|
||||
|
||||
|
||||
@@ -3,25 +3,30 @@ using System;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
|
||||
/// <summary>
|
||||
/// 监听编辑器状态,当编辑器重新 focus 时,重新加载实例,避免某些情景下 svn 、git 等外部修改了数据却无法同步的异常。
|
||||
/// </summary>
|
||||
[InitializeOnLoad]
|
||||
public static class EditorStatusWatcher
|
||||
namespace HybridCLR.Editor.Settings
|
||||
{
|
||||
public static Action OnEditorFocused;
|
||||
static bool isFocused;
|
||||
static EditorStatusWatcher() => EditorApplication.update += Update;
|
||||
static void Update()
|
||||
|
||||
/// <summary>
|
||||
/// 监听编辑器状态,当编辑器重新 focus 时,重新加载实例,避免某些情景下 svn 、git 等外部修改了数据却无法同步的异常。
|
||||
/// </summary>
|
||||
[InitializeOnLoad]
|
||||
public static class EditorStatusWatcher
|
||||
{
|
||||
if (isFocused != InternalEditorUtility.isApplicationActive)
|
||||
public static Action OnEditorFocused;
|
||||
static bool isFocused;
|
||||
static EditorStatusWatcher() => EditorApplication.update += Update;
|
||||
static void Update()
|
||||
{
|
||||
isFocused = InternalEditorUtility.isApplicationActive;
|
||||
if (isFocused)
|
||||
if (isFocused != InternalEditorUtility.isApplicationActive)
|
||||
{
|
||||
HybridCLRSettings.LoadOrCreate();
|
||||
OnEditorFocused?.Invoke();
|
||||
isFocused = InternalEditorUtility.isApplicationActive;
|
||||
if (isFocused)
|
||||
{
|
||||
HybridCLRSettings.LoadOrCreate();
|
||||
OnEditorFocused?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,8 @@ using UnityEditor;
|
||||
using UnityEditor.Presets;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
namespace HybridCLR.Editor
|
||||
|
||||
namespace HybridCLR.Editor.Settings
|
||||
{
|
||||
public class HybridCLRSettingsProvider : SettingsProvider
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
namespace HybridCLR.Editor
|
||||
|
||||
namespace HybridCLR.Editor.Settings
|
||||
{
|
||||
[FilePath("ProjectSettings/HybridCLRSettings.asset")]
|
||||
public class HybridCLRSettings : ScriptableSingleton<HybridCLRSettings>
|
||||
|
||||
@@ -2,35 +2,38 @@ using HybridCLR.Editor.Installer;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public static class MenuProvider
|
||||
namespace HybridCLR.Editor.Settings
|
||||
{
|
||||
|
||||
[MenuItem("HybridCLR/About HybridCLR", priority = 0)]
|
||||
public static void OpenAbout() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/intro");
|
||||
|
||||
[MenuItem("HybridCLR/Installer...", priority = 60)]
|
||||
private static void Open()
|
||||
public static class MenuProvider
|
||||
{
|
||||
InstallerWindow window = EditorWindow.GetWindow<InstallerWindow>("HybridCLR Installer", true);
|
||||
window.minSize = new Vector2(800f, 500f);
|
||||
|
||||
[MenuItem("HybridCLR/About", priority = 0)]
|
||||
public static void OpenAbout() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/intro");
|
||||
|
||||
[MenuItem("HybridCLR/Installer...", priority = 60)]
|
||||
private static void Open()
|
||||
{
|
||||
InstallerWindow window = EditorWindow.GetWindow<InstallerWindow>("HybridCLR Installer", true);
|
||||
window.minSize = new Vector2(800f, 500f);
|
||||
}
|
||||
|
||||
[MenuItem("HybridCLR/Settings...", priority = 61)]
|
||||
public static void OpenSettings() => SettingsService.OpenProjectSettings("Project/HybridCLR Settings");
|
||||
|
||||
[MenuItem("HybridCLR/Documents/Quick Start")]
|
||||
public static void OpenQuickStart() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/beginner/quickstart");
|
||||
|
||||
[MenuItem("HybridCLR/Documents/Performance")]
|
||||
public static void OpenPerformance() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/basic/performance");
|
||||
|
||||
[MenuItem("HybridCLR/Documents/FAQ")]
|
||||
public static void OpenFAQ() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/help/faq");
|
||||
|
||||
[MenuItem("HybridCLR/Documents/Common Errors")]
|
||||
public static void OpenCommonErrors() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/help/commonerrors");
|
||||
|
||||
[MenuItem("HybridCLR/Documents/Bug Report")]
|
||||
public static void OpenBugReport() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/help/issue");
|
||||
}
|
||||
|
||||
[MenuItem("HybridCLR/Settings...", priority = 61)]
|
||||
public static void OpenSettings() => SettingsService.OpenProjectSettings("Project/HybridCLR Settings");
|
||||
|
||||
[MenuItem("HybridCLR/Documents/Quick Start")]
|
||||
public static void OpenQuickStart() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/beginner/quickstart");
|
||||
|
||||
[MenuItem("HybridCLR/Documents/Performance")]
|
||||
public static void OpenPerformance() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/basic/performance");
|
||||
|
||||
[MenuItem("HybridCLR/Documents/FAQ")]
|
||||
public static void OpenFAQ() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/help/faq");
|
||||
|
||||
[MenuItem("HybridCLR/Documents/Common Errors")]
|
||||
public static void OpenCommonErrors() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/help/commonerrors");
|
||||
|
||||
[MenuItem("HybridCLR/Documents/Bug Report")]
|
||||
public static void OpenBugReport() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/help/issue");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor
|
||||
namespace HybridCLR.Editor.Settings
|
||||
{
|
||||
public class ScriptableSingleton<T> : ScriptableObject where T : ScriptableObject
|
||||
{
|
||||
@@ -59,9 +59,10 @@ namespace HybridCLR.Editor
|
||||
protected static string GetFilePath()
|
||||
{
|
||||
return typeof(T).GetCustomAttributes(inherit: true)
|
||||
.Cast<FilePathAttribute>()
|
||||
.FirstOrDefault(v => v != null)
|
||||
?.filepath;
|
||||
.Where(v => v is FilePathAttribute)
|
||||
.Cast<FilePathAttribute>()
|
||||
.FirstOrDefault()
|
||||
?.filepath;
|
||||
}
|
||||
}
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
|
||||
@@ -2,7 +2,7 @@ using UnityEditor;
|
||||
using UnityEditor.Presets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor
|
||||
namespace HybridCLR.Editor.Settings
|
||||
{
|
||||
public class SettingsPresetReceiver : PresetSelectorReceiver
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using HybridCLR.Editor.Settings;
|
||||
|
||||
|
||||
namespace HybridCLR.Editor
|
||||
|
||||
+134
@@ -1,5 +1,139 @@
|
||||
# 发布日志
|
||||
|
||||
## 4.0.15
|
||||
|
||||
发布日期 2024年1月2日.
|
||||
|
||||
### Runtime
|
||||
|
||||
- [fix] 修复计算未完全实例化的泛型类时将VAR和MVAR类型参数大小计算成sizeof(void*),导致计算出无效且过大的instance,在执行LayoutFieldsLocked过程中调用UpdateInstanceSizeForGenericClass错误地使用泛型基类instance覆盖设置了实例类型的instance值的严重bug
|
||||
- [change] 支持打印热更新栈,虽然顺序不太正确
|
||||
- [change] 使用HYBRIDCLR_MALLOC之类分配函数替换IL2CPP_MALLOC
|
||||
- [refactor] 重构Config接口,统一通过GetRuntimeOption和SetRuntimeOption获取和设置选项
|
||||
- [opt] 删除NewValueTypeVar和NewValueTypeInterpVar指令不必要的对结构memset操作
|
||||
|
||||
### Editor
|
||||
|
||||
- [fix] 修复Additional Compiler Arguments中输入 -nullable:enable 之后,Editor抛出InvalidCastException的bug。来自报告 https://github.com/focus-creative-games/hybridclr/issues/116
|
||||
- [fix] 修复某些情况下报错:BuildFailedException: Build path contains a project previously built without the "Create Visual Studio Solution"
|
||||
- [opt] 优化桥接函数生成,将同构的struct映射到同一个结构,减少了30-35%的桥接函数数量
|
||||
- [change] StripAOTDllCommand导出时不再设置BuildScriptsOnly选项
|
||||
- [change] 调整Installer窗口的显示内容
|
||||
- [refactor] RuntimeApi中设置hybridclr参数的功能统一通过GetRuntimeOption和SetRuntimeOption函数
|
||||
|
||||
## 4.0.14
|
||||
|
||||
发布日期 2023.12.11.
|
||||
|
||||
### Runtime
|
||||
|
||||
- [fix] 修复优化 box; brtrue|brfalse序列时,当类型为class或nullable类型时,无条件转换为无条件branch语句的bug
|
||||
- [fix] 修复 ClassFieldLayoutCalculator未释放 _classMap的每个key-value对中value对象,造成内存泄露的bug
|
||||
- [fix] 修复计算 ExplicitLayout的struct的native_size的bug
|
||||
- [fix] 修复当出现签名完全相同的虚函数与虚泛型函数时,计算override未考虑泛型签名,错误地返回了不匹配的函数,导致虚表错误的bug
|
||||
- [fix][2021] 修复开启faster(smaller) build选项后某些情况下完全泛型共享AOT函数未使用补充元数据来设置函数指针,导致调用时出错的bug
|
||||
|
||||
## 4.0.13
|
||||
|
||||
发布日期 2023.11.27.
|
||||
|
||||
### Runtime
|
||||
|
||||
- [fix] 修复ConvertInvokeArgs有可能传递了非对齐args,导致CopyStackObject在armv7这种要求内存对齐的平台发生崩溃的bug
|
||||
- [fix] 修复通过StructLayout指定size时,计算ClassFieldLayout的严重bug
|
||||
- [fix] 修复bgt之类指令未取双重取反进行判断,导致当浮点数与Nan比较时由于不满足对称性执行了错误的分支的bug
|
||||
- [fix] 修复Class::FromGenericParameter错误地设置了thread_static_fields_size=-1,导致为其分配ThreadStatic内存的严重bug
|
||||
- [opt] Il2CppGenericInst分配统一使用MetadataCache::GetGenericInst分配唯一池对象,优化内存分配
|
||||
- [opt] 由于Interpreter部分Il2CppGenericInst统一使用MetadataCache::GetGenericInst,比较 Il2CppGenericContext时直接比较 class_inst和method_inst指针
|
||||
|
||||
### Editor
|
||||
|
||||
- [fix] 修复裁剪aot dll中出现netstandard时,生成桥接函数异常的bug
|
||||
- [fix] 修复当出现非常规字段名时生成的桥接函数代码文件有编译错误的bug
|
||||
- [change] 删除不必要的Datas~/Templates目录,直接以原始文件为模板
|
||||
- [refactor] 重构 AssemblyCache和 AssemblyReferenceDeepCollector,消除冗余代码
|
||||
|
||||
## 4.0.12
|
||||
|
||||
发布日期 2023.11.02.
|
||||
|
||||
### Editor
|
||||
|
||||
- [fix] 修复BashUtil.RemoveDir的bug导致Installer安装失败的bug
|
||||
|
||||
## 4.0.11
|
||||
|
||||
发布日期 2023.11.02.
|
||||
|
||||
### Runtime
|
||||
|
||||
- [fix] 修复开启完全泛型共享后, 对于某些MethodInfo,由于methodPointer与virtualMethodPointer使用补充元数据后的解释器函数,而invoker_method仍然为支持完全泛型共享的调用形式,导致invoker_method与methodPointer及virtualMethodPointer不匹配的bug
|
||||
- [fix] 修复Il2CppGenericContextCompare比较时仅仅对比inst指针的bug,造成热更新模块大量泛型函数重复
|
||||
- [fix] 修复完全泛型共享时未正确设置MethodInfo的bug
|
||||
|
||||
### Editor
|
||||
|
||||
- [new] 检查当前安装的libil2cpp版本是否与package版本匹配,避免升级package后未重新install的问题
|
||||
- [new] Generate支持 netstandard
|
||||
- [fix] 修复 ReversePInvokeWrap生成不必要地解析referenced dll,导致如果有aot dll引用了netstandard会出现解析错误的bug
|
||||
- [fix] 修复BashUtil.RemoveDir在偶然情况下出现删除目录失败的问题。新增多次重试
|
||||
- [fix] 修复桥接函数计算时未归结函数参数类型,导致出现多个同名签名的bug
|
||||
|
||||
|
||||
## 4.0.10
|
||||
|
||||
发布日期 2023.10.12.
|
||||
|
||||
### Runtime
|
||||
|
||||
- [merge][il2cpp] 合并2022.3.10-2022.3.11f1的il2cpp改动,修复2022.3.11版本不兼容的问题
|
||||
|
||||
## 4.0.9
|
||||
|
||||
发布日期 2023.10.11.
|
||||
|
||||
### Runtime
|
||||
|
||||
- [merge][il2cpp][fix] 合并2021.3.29-2021.3.31f1的il2cpp改动,修复在2021.3.31版本的不兼容问题
|
||||
- [merge][il2cpp] 合并2022.3.7-2022.3.10f1的il2cpp改动
|
||||
|
||||
### Editor
|
||||
|
||||
- [fix] 修复2022版本iOS平台AddLil2cppSourceCodeToXcodeproj2022OrNewer的编译错误
|
||||
|
||||
## 4.0.8
|
||||
|
||||
发布日期 2023.10.10.
|
||||
|
||||
### Runtime
|
||||
|
||||
- [fix] 修复计算值类型泛型桥接函数签名时,错误地将值类型泛型参数类型也换成签名,导致与Editor计算的签名不一致的bug
|
||||
- [fix][refactor] RuntimeApi相关函数由PInvoke改为InternalCall,解决Android平台调用RuntimeApi时触发重新加载libil2cpp.a的问题
|
||||
|
||||
### Editor
|
||||
|
||||
- [refactor] RuntimeApi相关函数由PInvoke改为InternalCall
|
||||
- [refactor] 调整HybridCLR.Editor模块一些不规范的命名空间
|
||||
|
||||
## 4.0.7
|
||||
|
||||
发布日期 2023.10.09.
|
||||
|
||||
### Runtime
|
||||
|
||||
- [fix] 修复initobj调用了CopyN,但CopyN未考虑对象的内存对齐的情况,在32位这种的平台可能发生未对齐访问异常的bug
|
||||
- [fix] 修复计算未完全实例化的泛型函数的桥接函数签名时崩溃的bug
|
||||
- [fix] 修复Il2cpp代码生成选项为faster(smaller)时,2021和2022版本GenericMethod::CreateMethodLocked的bug
|
||||
- [remove] 移除所有array相关指令中index为int64_t的指令,简化代码
|
||||
- [remove] 移除ldfld_xxx_ref系列指令
|
||||
|
||||
### Editor
|
||||
|
||||
- [fix] 修复生成桥接函数时,如果热更新程序集未包含任何代码直接引用了某个aot程序集,则没有为该aot程序集生成桥接函数,导致出现NotSupportNative2Managed异常的bug
|
||||
- [fix] 修复mac下面路径过长导致拷贝文件失败的bug
|
||||
- [fix] 修复发布PS5目标时未处理ScriptingAssemblies.json的bug
|
||||
- [change] 打包时清空裁减aot dll目录
|
||||
|
||||
## 4.0.6
|
||||
|
||||
发布日期 2023.09.26.
|
||||
|
||||
+38
-54
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -10,102 +11,85 @@ namespace HybridCLR
|
||||
{
|
||||
public static class RuntimeApi
|
||||
{
|
||||
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX
|
||||
private const string dllName = "GameAssembly";
|
||||
#elif UNITY_ANDROID
|
||||
private const string dllName = "il2cpp";
|
||||
#else
|
||||
private const string dllName = "__Internal";
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// 加载补充元数据assembly
|
||||
/// </summary>
|
||||
/// <param name="dllBytes"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotSupportedException"></exception>
|
||||
#if UNITY_EDITOR
|
||||
public static unsafe LoadImageErrorCode LoadMetadataForAOTAssembly(byte[] dllBytes, HomologousImageMode mode)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
return LoadImageErrorCode.OK;
|
||||
#else
|
||||
fixed(byte* data = dllBytes)
|
||||
{
|
||||
return (LoadImageErrorCode)LoadMetadataForAOTAssembly(data, dllBytes.Length, (int)mode);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载补充元数据assembly
|
||||
/// </summary>
|
||||
/// <param name="dllBytes"></param>
|
||||
/// <param name="dllSize"></param>
|
||||
/// <returns></returns>
|
||||
#if UNITY_EDITOR
|
||||
public static unsafe int LoadMetadataForAOTAssembly(byte* dllBytes, int dllSize, int mode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
[DllImport(dllName, EntryPoint = "RuntimeApi_LoadMetadataForAOTAssembly")]
|
||||
public static extern unsafe int LoadMetadataForAOTAssembly(byte* dllBytes, int dllSize, int mode);
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
public static extern LoadImageErrorCode LoadMetadataForAOTAssembly(byte[] dllBytes, HomologousImageMode mode);
|
||||
#endif
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
#if UNITY_EDITOR
|
||||
public static int GetInterpreterThreadObjectStackSize()
|
||||
{
|
||||
return 0;
|
||||
return GetRuntimeOption(RuntimeOptionId.InterpreterThreadObjectStackSize);
|
||||
}
|
||||
#else
|
||||
[DllImport(dllName, EntryPoint = "RuntimeApi_GetInterpreterThreadObjectStackSize")]
|
||||
public static extern int GetInterpreterThreadObjectStackSize();
|
||||
#endif
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小)
|
||||
/// </summary>
|
||||
/// <param name="size"></param>
|
||||
#if UNITY_EDITOR
|
||||
public static void SetInterpreterThreadObjectStackSize(int size)
|
||||
{
|
||||
|
||||
SetRuntimeOption(RuntimeOptionId.InterpreterThreadObjectStackSize, size);
|
||||
}
|
||||
#else
|
||||
[DllImport(dllName, EntryPoint = "RuntimeApi_SetInterpreterThreadObjectStackSize")]
|
||||
public static extern void SetInterpreterThreadObjectStackSize(int size);
|
||||
#endif
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
#if UNITY_EDITOR
|
||||
public static int GetInterpreterThreadFrameStackSize()
|
||||
{
|
||||
return 0;
|
||||
return GetRuntimeOption(RuntimeOptionId.InterpreterThreadFrameStackSize);
|
||||
}
|
||||
#else
|
||||
[DllImport(dllName, EntryPoint = "RuntimeApi_GetInterpreterThreadFrameStackSize")]
|
||||
public static extern int GetInterpreterThreadFrameStackSize();
|
||||
#endif
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小)
|
||||
/// </summary>
|
||||
/// <param name="size"></param>
|
||||
#if UNITY_EDITOR
|
||||
public static void SetInterpreterThreadFrameStackSize(int size)
|
||||
{
|
||||
|
||||
SetRuntimeOption(RuntimeOptionId.InterpreterThreadFrameStackSize, size);
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
private static readonly Dictionary<RuntimeOptionId, int> s_runtimeOptions = new Dictionary<RuntimeOptionId, int>();
|
||||
|
||||
public static void SetRuntimeOption(RuntimeOptionId optionId, int value)
|
||||
{
|
||||
s_runtimeOptions[optionId] = value;
|
||||
}
|
||||
#else
|
||||
[DllImport(dllName, EntryPoint = "RuntimeApi_SetInterpreterThreadFrameStackSize")]
|
||||
public static extern void SetInterpreterThreadFrameStackSize(int size);
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
public static extern void SetRuntimeOption(RuntimeOptionId optionId, int value);
|
||||
#endif
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public static int GetRuntimeOption(RuntimeOptionId optionId)
|
||||
{
|
||||
if (s_runtimeOptions.TryGetValue(optionId, out var value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
public static extern int GetRuntimeOption(RuntimeOptionId optionId);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace HybridCLR
|
||||
{
|
||||
public enum RuntimeOptionId
|
||||
{
|
||||
InterpreterThreadObjectStackSize = 1,
|
||||
InterpreterThreadFrameStackSize = 2,
|
||||
ThreadExceptionFlowSize = 3,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64be598b47302644a96013c74d945653
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "com.code-philosophy.hybridclr",
|
||||
"version": "4.0.6",
|
||||
"version": "4.0.15",
|
||||
"displayName": "HybridCLR",
|
||||
"description": "HybridCLR is a fully featured, zero-cost, high-performance, low-memory solution for Unity's all-platform native c# hotupdate.",
|
||||
"category": "Runtime",
|
||||
|
||||
Reference in New Issue
Block a user