Skip to content

Commit d7ef9bf

Browse files
authored
Merge branch 'focus-creative-games:main' into main
2 parents 761b416 + 4df417e commit d7ef9bf

16 files changed

Lines changed: 203 additions & 114 deletions

Data~/hybridclr_version.json

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,43 @@
22
"versions": [
33
{
44
"unity_version":"2019",
5-
"hybridclr" : { "branch":"v8.4.0"},
5+
"hybridclr" : { "branch":"v8.8.0"},
66
"il2cpp_plus": { "branch":"v2019-8.1.0"}
77
},
88
{
99
"unity_version":"2020",
10-
"hybridclr" : { "branch":"v8.4.0"},
10+
"hybridclr" : { "branch":"v8.8.0"},
1111
"il2cpp_plus": { "branch":"v2020-8.1.0"}
1212
},
1313
{
1414
"unity_version":"2021",
15-
"hybridclr" : { "branch":"v8.4.0"},
15+
"hybridclr" : { "branch":"v8.8.0"},
1616
"il2cpp_plus": { "branch":"v2021-8.1.0"}
1717
},
1818
{
1919
"unity_version":"2022",
20-
"hybridclr" : { "branch":"v8.4.0"},
20+
"hybridclr" : { "branch":"v8.8.0"},
2121
"il2cpp_plus": { "branch":"v2022-8.2.0"}
2222
},
2323
{
2424
"unity_version":"2022-tuanjie",
25-
"hybridclr" : { "branch":"v8.4.0"},
26-
"il2cpp_plus": { "branch":"v2022-tuanjie-8.3.0"}
25+
"hybridclr" : { "branch":"v8.8.0"},
26+
"il2cpp_plus": { "branch":"v2022-tuanjie-8.8.0"}
2727
},
2828
{
2929
"unity_version":"2023",
30-
"hybridclr" : { "branch":"v8.4.0"},
30+
"hybridclr" : { "branch":"v8.8.0"},
3131
"il2cpp_plus": { "branch":"v2023-8.1.0"}
3232
},
3333
{
3434
"unity_version":"6000",
35-
"hybridclr" : { "branch":"v8.4.0"},
36-
"il2cpp_plus": { "branch":"v6000-8.1.0"}
35+
"hybridclr" : { "branch":"v8.8.0"},
36+
"il2cpp_plus": { "branch":"v6000-8.7.0"}
37+
},
38+
{
39+
"unity_version":"6000.3.x",
40+
"hybridclr" : { "branch":"v6000.3.x-8.8.0"},
41+
"il2cpp_plus": { "branch":"v6000.3.x-8.8.0"}
3742
}
3843
]
3944
}

Editor/ABI/ABIUtil.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

Editor/ABI/ABIUtil.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Editor/BuildProcessors/CheckSettings.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,21 @@ public void OnPreprocessBuild(BuildReport report)
4646
return;
4747
}
4848
BuildTargetGroup buildTargetGroup = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget);
49+
#if UNITY_6000_0_OR_NEWER
50+
NamedBuildTarget namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup);
51+
ScriptingImplementation curScriptingImplementation = PlayerSettings.GetScriptingBackend(namedBuildTarget);
52+
#else
4953
ScriptingImplementation curScriptingImplementation = PlayerSettings.GetScriptingBackend(buildTargetGroup);
54+
#endif
5055
ScriptingImplementation targetScriptingImplementation = ScriptingImplementation.IL2CPP;
5156
if (curScriptingImplementation != targetScriptingImplementation)
5257
{
5358
Debug.LogError($"[CheckSettings] current ScriptingBackend:{curScriptingImplementation},have been switched to:{targetScriptingImplementation} automatically");
59+
#if UNITY_6000_0_OR_NEWER
60+
PlayerSettings.SetScriptingBackend(namedBuildTarget, targetScriptingImplementation);
61+
#else
5462
PlayerSettings.SetScriptingBackend(buildTargetGroup, targetScriptingImplementation);
63+
#endif
5564
}
5665

5766
var installer = new Installer.InstallerController();

Editor/Commands/StripAOTDllCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using System.Threading.Tasks;
1010
using UnityEditor;
1111
using UnityEngine;
12-
using static UnityEngine.Networking.UnityWebRequest;
1312

1413
namespace HybridCLR.Editor.Commands
1514
{

Editor/Installer/BashUtil.cs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -102,42 +102,23 @@ public static void RecreateDir(string dir)
102102
}
103103
Directory.CreateDirectory(dir);
104104
}
105-
106-
private static void CopyWithCheckLongFile(string srcFile, string dstFile)
107-
{
108-
var maxPathLength = 255;
109-
#if UNITY_EDITOR_OSX
110-
maxPathLength = 1024;
111-
#endif
112-
if (srcFile.Length > maxPathLength)
113-
{
114-
UnityEngine.Debug.LogError($"srcFile:{srcFile} path is too long. skip copy!");
115-
return;
116-
}
117-
if (dstFile.Length > maxPathLength)
118-
{
119-
UnityEngine.Debug.LogError($"dstFile:{dstFile} path is too long. skip copy!");
120-
return;
121-
}
122-
File.Copy(srcFile, dstFile);
123-
}
124-
125105
public static void CopyDir(string src, string dst, bool log = false)
126106
{
127107
if (log)
128108
{
129109
UnityEngine.Debug.Log($"[BashUtil] CopyDir {src} => {dst}");
130110
}
131-
RemoveDir(dst);
132-
Directory.CreateDirectory(dst);
133-
foreach(var file in Directory.GetFiles(src))
111+
if (Directory.Exists(dst))
134112
{
135-
CopyWithCheckLongFile(file, $"{dst}/{Path.GetFileName(file)}");
113+
RemoveDir(dst);
136114
}
137-
foreach(var subDir in Directory.GetDirectories(src))
115+
else
138116
{
139-
CopyDir(subDir, $"{dst}/{Path.GetFileName(subDir)}");
117+
string parentDir = Path.GetDirectoryName(Path.GetFullPath(dst));
118+
Directory.CreateDirectory(parentDir);
140119
}
120+
121+
UnityEditor.FileUtil.CopyFileOrDirectory(src, dst);
141122
}
142123
}
143124
}

Editor/Installer/InstallerController.cs

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#if UNITY_6000_3_OR_NEWER && UNITY_EDITOR_OSX
2+
#define NEW_IL2CPP_PATH
3+
#endif
14
using System;
25
using System.Collections.Generic;
36
using System.IO;
@@ -8,6 +11,7 @@
811
using System.Text.RegularExpressions;
912
using System.Linq;
1013
using HybridCLR.Editor.Settings;
14+
using System.Runtime.InteropServices;
1115

1216
namespace HybridCLR.Editor.Installer
1317
{
@@ -33,7 +37,15 @@ public InstallerController()
3337
{
3438
_curVersion = ParseUnityVersion(Application.unityVersion);
3539
_versionManifest = GetHybridCLRVersionManifest();
36-
_curDefaultVersion = _versionManifest.versions.FirstOrDefault(v => _curVersion.isTuanjieEngine ? v.unity_version == $"{_curVersion.major}-tuanjie" : v.unity_version == _curVersion.major.ToString());
40+
_curDefaultVersion = _versionManifest.versions.FirstOrDefault(v => {
41+
return _curVersion.isTuanjieEngine? v.unity_version == $"{_curVersion.major}-tuanjie"
42+
#if UNITY_6000_3_OR_NEWER
43+
: v.unity_version == "6000.3.x"
44+
#else
45+
: v.unity_version == _curVersion.major.ToString()
46+
#endif
47+
;
48+
});
3749
PackageVersion = LoadPackageInfo().version;
3850
InstalledLibil2cppVersion = ReadLocalVersion();
3951
}
@@ -127,7 +139,11 @@ public string GetMinCompatibleVersion(int majorVersion)
127139
case 2021: return "2021.3.0";
128140
case 2022: return "2022.3.0";
129141
case 2023: return "2023.2.0";
142+
#if UNITY_6000_3_OR_NEWER
143+
case 6000: return "6000.3.0";
144+
#else
130145
case 6000: return "6000.0.0";
146+
#endif
131147
default: return $"2020.3.0";
132148
}
133149
}
@@ -158,14 +174,28 @@ public CompatibleType GetCompatibleType()
158174

159175
public string Il2cppPlusLocalVersion => _curDefaultVersion?.il2cpp_plus?.branch;
160176

161-
162-
private string GetIl2CppPathByContentPath(string contentPath)
177+
public string ApplicationIl2cppPath
163178
{
164-
return $"{contentPath}/il2cpp";
179+
get
180+
{
181+
Debug.Log($"application path:{EditorApplication.applicationPath} {EditorApplication.applicationContentsPath}");
182+
#if NEW_IL2CPP_PATH
183+
#if UNITY_IOS
184+
string platformDirName = "iOSSupport";
185+
#elif UNITY_TVOS
186+
string platformDirName = "AppleTVSupport";
187+
#elif UNITY_VISIONOS
188+
string platformDirName = "VisionOSPlayer";
189+
#else
190+
string platformDirName = "iOSSupport";
191+
#endif
192+
return $"{EditorApplication.applicationContentsPath}/../../PlaybackEngines/{platformDirName}/il2cpp";
193+
#else
194+
return $"{EditorApplication.applicationContentsPath}/il2cpp";
195+
#endif
196+
}
165197
}
166198

167-
public string ApplicationIl2cppPath => GetIl2CppPathByContentPath(EditorApplication.applicationContentsPath);
168-
169199
public string LocalVersionFile => $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/hybridclr/generated/libil2cpp-version.txt";
170200

171201
private string ReadLocalVersion()
@@ -266,12 +296,23 @@ private void RunInitLocalIl2CppData(string editorIl2cppPath, string libil2cppWit
266296
// create LocalIl2Cpp
267297
string localUnityDataDir = SettingsUtil.LocalUnityDataDir;
268298
BashUtil.RecreateDir(localUnityDataDir);
269-
299+
#if !NEW_IL2CPP_PATH
270300
// copy MonoBleedingEdge
271301
BashUtil.CopyDir($"{Directory.GetParent(editorIl2cppPath)}/MonoBleedingEdge", $"{localUnityDataDir}/MonoBleedingEdge", true);
272-
302+
#endif
273303
// copy il2cpp
274304
BashUtil.CopyDir(editorIl2cppPath, SettingsUtil.LocalIl2CppDir, true);
305+
#if NEW_IL2CPP_PATH
306+
string buildDir = $"{SettingsUtil.LocalIl2CppDir}/build";
307+
if (RuntimeInformation.ProcessArchitecture == Architecture.Arm || RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
308+
{
309+
BashUtil.CopyDir($"{buildDir}/deploy_arm64", $"{buildDir}/deploy", false);
310+
}
311+
else
312+
{
313+
BashUtil.CopyDir($"{buildDir}/deploy_x86_64", $"{buildDir}/deploy", false);
314+
}
315+
#endif
275316

276317
// replace libil2cpp
277318
string dstLibil2cppDir = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp";

Editor/MethodBridge/CallNativeMethodSignatureInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ namespace HybridCLR.Editor.MethodBridge
55
public class CallNativeMethodSignatureInfo
66
{
77
public MethodSig MethodSig { get; set; }
8+
9+
public CallingConvention? Callvention { get; set; }
810
}
911
}

Editor/MethodBridge/Generator.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,11 @@ private static CallingConvention GetCallingConvention(MethodDef method)
559559
{
560560
return CallingConvention.Winapi;
561561
}
562+
if (monoPInvokeCallbackAttr.ConstructorArguments.Count == 0)
563+
{
564+
Debug.LogError($"MonoPInvokeCallbackAttribute on method {method.FullName} has no constructor arguments. Using CallingConvention.Winapi as default.");
565+
return CallingConvention.Winapi;
566+
}
562567
object delegateTypeSig = monoPInvokeCallbackAttr.ConstructorArguments[0].Value;
563568

564569
TypeDef delegateTypeDef;
@@ -580,7 +585,7 @@ private static CallingConvention GetCallingConvention(MethodDef method)
580585
throw new NotSupportedException($"Unsupported delegate type: {delegateTypeSig}");
581586
}
582587
var attr = delegateTypeDef.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.FullName == "System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute");
583-
if (attr == null)
588+
if (attr == null || attr.ConstructorArguments.Count == 0)
584589
{
585590
return CallingConvention.Winapi;
586591
}
@@ -638,7 +643,7 @@ private List<CalliMethodInfo> BuildCalliMethods(List<CallNativeMethodSignatureIn
638643
sharedMethod.Init();
639644
sharedMethod = ToIsomorphicMethod(sharedMethod);
640645

641-
CallingConvention callingConv = (CallingConvention)((int)(method.MethodSig.CallingConvention & dnlib.DotNet.CallingConvention.Mask) + 1);
646+
CallingConvention callingConv = (CallingConvention)((int)((method.Callvention ?? method.MethodSig.CallingConvention) & dnlib.DotNet.CallingConvention.Mask) + 1);
642647
string signature = MakeCalliSignature(sharedMethod, callingConv);
643648

644649
if (!methodsBySig.TryGetValue(signature, out var arm))

Editor/MethodBridge/PInvokeAnalyzer.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
6+
using System.Runtime.CompilerServices;
67
using System.Text;
78
using System.Threading.Tasks;
89
using UnityEngine;
@@ -26,6 +27,19 @@ public PInvokeAnalyzer(AssemblyCache cache, List<string> assemblyNames)
2627
}
2728
}
2829

30+
private CallingConvention GetCallingConvention(MethodDef method)
31+
{
32+
switch (method.ImplMap.CallConv)
33+
{
34+
case PInvokeAttributes.CallConvWinapi: return CallingConvention.Default;
35+
case PInvokeAttributes.CallConvCdecl: return CallingConvention.C;
36+
case PInvokeAttributes.CallConvStdCall: return CallingConvention.StdCall;
37+
case PInvokeAttributes.CallConvThiscall: return CallingConvention.ThisCall;
38+
case PInvokeAttributes.CallConvFastcall: return CallingConvention.FastCall;
39+
default: return CallingConvention.Default;
40+
}
41+
}
42+
2943
public void Run()
3044
{
3145
foreach (var mod in _rootModules)
@@ -40,7 +54,11 @@ public void Run()
4054
{
4155
Debug.LogError($"PInvoke method {method.FullName} has unsupported parameter or return type. Please check the method signature.");
4256
}
43-
_pinvokeMethodSignatures.Add(new CallNativeMethodSignatureInfo { MethodSig = method.MethodSig });
57+
_pinvokeMethodSignatures.Add(new CallNativeMethodSignatureInfo
58+
{
59+
MethodSig = method.MethodSig,
60+
Callvention = method.HasImplMap? GetCallingConvention(method) : (CallingConvention?)null,
61+
});
4462
}
4563
}
4664
}

0 commit comments

Comments
 (0)