Compare commits

...

7 Commits

Author SHA1 Message Date
walon 6e76b96f97 [version] 升级到2.1.0 2023-03-28 22:35:44 +08:00
walon dd18ecdba5 [version] 升级到2.0.11版本 2023-03-28 16:03:37 +08:00
walon 2ff3e276d2 [revert] 回滚版本"6909c32a0c8fcf11d4b573af890a0232c1525afe [new] 支持 2021 WebGL资源上挂载脚本" 引入的MonoHook的bug 2023-03-28 13:25:53 +08:00
Jonson 1d5f2a953c [fix] 修复MonoHook在2020.3.x系列编辑器compile的时候,有可能发生hook没有及时注入从而导致打iOS包失败
[fix]  较高版本的Unity GetFunctionPointer不再依赖GUISkin.current,反而高版本unity的GUISkin.current这个值不会立即有值,导致在编辑器compile等时候,hook没有及时注入从而导致打iOS包失败

---------

Co-authored-by: liaoqiang <liaoqiang@nibirutech.com>
2023-03-28 13:25:32 +08:00
walon 75cb53cb19 [opt] 优化AOTGenericReferences生成,包含assembly列表及美化后的泛型类型及函数名 2023-03-20 17:30:05 +08:00
walon c84f575a2e [change] 对2019修改data.unity3d文件时不再备份data.unity32.bak 2023-03-16 08:39:47 +08:00
walon 3beb788baa [fix] 修复 StripAOTDllCommand由于缓存原因,有些情况下生成失败的问题。通过添加BuildOptions.CleanBuildCache选项解决。此选项在Unity 2021及更高版本新增。 2023-03-13 12:17:39 +08:00
9 changed files with 97 additions and 34 deletions
+1
View File
@@ -1,5 +1,6 @@
# change logs
- 2023.03.28 `HybridCLR/Generate/Il2CppDef`生成的代码位置移到`hybridclr/generated`下
- 2022.8.30 创建
+6 -6
View File
@@ -2,18 +2,18 @@
"versions": [
{
"unity_version":"2019",
"hybridclr" : { "branch":"v2.0.3"},
"il2cpp_plus": { "branch":"v2019-2.0.1"}
"hybridclr" : { "branch":"v2.1.0"},
"il2cpp_plus": { "branch":"v2019-2.1.0"}
},
{
"unity_version":"2020",
"hybridclr" : { "branch":"v2.0.3"},
"il2cpp_plus": { "branch":"v2020-2.0.2"}
"hybridclr" : { "branch":"v2.1.0"},
"il2cpp_plus": { "branch":"v2020-2.1.0"}
},
{
"unity_version":"2021",
"hybridclr" : { "branch":"v2.0.3"},
"il2cpp_plus": { "branch":"v2021-2.0.2"}
"hybridclr" : { "branch":"v2.1.0"},
"il2cpp_plus": { "branch":"v2021-2.1.0"}
}
]
}
@@ -42,11 +42,11 @@ namespace HybridCLR.Editor.UnityBinFileReader
writer.Write(new EndianBinaryWriter(output));
Debug.Log($"patch file:{dataunity3dFile} size:{output.Length}");
string bakFile = dataunity3dFile + ".bak";
if (!File.Exists(bakFile))
{
File.Copy(dataunity3dFile, bakFile);
}
//string bakFile = dataunity3dFile + ".bak";
//if (!File.Exists(bakFile))
//{
// File.Copy(dataunity3dFile, bakFile);
//}
File.WriteAllBytes(dataunity3dFile, output.ToArray());
}
}
+3 -9
View File
@@ -1,4 +1,5 @@
using System;
using System.Runtime.InteropServices;
namespace DotNetDetour
{
@@ -641,15 +642,8 @@ namespace DotNetDetour
if(s_isArm.HasValue)
return s_isArm.Value;
string processorType = UnityEngine.SystemInfo.processorType;
/*
* appple M 系列
* SystemInfo.processorType 返回值为: Apple M1 Max, Apple M2 等
* SystemInfo.operatingSystem 返回值为: Mac OS X xx.x.x
*
*/
s_isArm = processorType.Contains("ARM") || processorType.Contains("Apple M");
var arch = RuntimeInformation.ProcessArchitecture;
s_isArm = arch == Architecture.Arm || arch == Architecture.Arm64;
return s_isArm.Value;
}
+14 -8
View File
@@ -1,4 +1,4 @@
/*
/*
Desc: 一个可以运行时 Hook Mono 方法的工具,让你可以无需修改 UnityEditor.dll 等文件就可以重写其函数功能
Author: Misaka Mikoto
Github: https://github.com/Misaka-Mikoto-Tech/MonoHook
@@ -85,7 +85,7 @@ namespace MonoHook
private CodePatcher _codePatcher;
#if UNITY_EDITOR
#if UNITY_EDITOR && !UNITY_2020_3_OR_NEWER
/// <summary>
/// call `MethodInfo.MethodHandle.GetFunctionPointer()`
/// will visit static class `UnityEditor.IMGUI.Controls.TreeViewGUI.Styles` and invoke its static constructor,
@@ -97,7 +97,7 @@ namespace MonoHook
static MethodHook()
{
#if UNITY_EDITOR
#if UNITY_EDITOR && !UNITY_2020_3_OR_NEWER
s_fi_GUISkin_current = typeof(GUISkin).GetField("current", BindingFlags.Static | BindingFlags.NonPublic);
#endif
}
@@ -126,7 +126,7 @@ namespace MonoHook
if (isHooked)
return;
#if UNITY_EDITOR
#if UNITY_EDITOR && !UNITY_2020_3_OR_NEWER
if (s_fi_GUISkin_current.GetValue(null) != null)
DoInstall();
else
@@ -191,7 +191,7 @@ namespace MonoHook
if (targetMethod.IsAbstract)
throw new Exception($"WRANING: you can not hook abstract method [{methodName}]");
#if UNITY_EDITOR
#if UNITY_EDITOR && !UNITY_2020_3_OR_NEWER
int minMethodBodySize = 10;
{
@@ -358,13 +358,19 @@ namespace MonoHook
}
}
#if UNITY_EDITOR
#if UNITY_EDITOR && !UNITY_2020_3_OR_NEWER
private void OnEditorUpdate()
{
if (s_fi_GUISkin_current.GetValue(null) != null)
{
DoInstall();
EditorApplication.update -= OnEditorUpdate;
try
{
DoInstall();
}
finally
{
EditorApplication.update -= OnEditorUpdate;
}
}
}
#endif
+62 -3
View File
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using UnityEngine;
@@ -11,6 +12,52 @@ namespace HybridCLR.Editor.AOT
{
public class GenericReferenceWriter
{
private static readonly Dictionary<Type, string> _typeNameMapping = new Dictionary<Type, string>
{
{typeof(bool), "bool" },
{typeof(byte), "byte" },
{typeof(sbyte), "sbyte" },
{typeof(short), "short" },
{typeof(ushort), "ushort" },
{typeof(int), "int" },
{typeof(uint), "uint" },
{typeof(long), "long" },
{typeof(ulong), "ulong" },
{typeof(float), "float" },
{typeof(double), "double" },
{typeof(object), "object" },
{typeof(string), "string" },
};
private readonly Dictionary<string, string> _typeSimpleNameMapping = new Dictionary<string, string>();
private readonly Regex _systemTypePattern;
private readonly Regex _genericPattern = new Regex(@"`\d+");
public GenericReferenceWriter()
{
foreach (var e in _typeNameMapping)
{
_typeSimpleNameMapping.Add(e.Key.FullName, e.Value);
}
_systemTypePattern = new Regex(string.Join("|", _typeSimpleNameMapping.Keys.Select (k => $@"\b{k}\b")));
}
public string PrettifyTypeSig(string typeSig)
{
string s = _genericPattern.Replace(typeSig, "").Replace('/', '.');
return _systemTypePattern.Replace(s, m => _typeSimpleNameMapping[m.Groups[0].Value]);
}
public string PrettifyMethodSig(string methodSig)
{
string s = PrettifyTypeSig(methodSig).Replace("::", ".");
if (s.Contains(".ctor("))
{
s = "new " + s.Replace(".ctor(", "(");
}
return s;
}
public void Write(List<GenericClass> types, List<GenericMethod> methods, string outputFile)
{
string parentDir = Directory.GetParent(outputFile).FullName;
@@ -20,18 +67,30 @@ namespace HybridCLR.Editor.AOT
codes.Add("public class AOTGenericReferences : UnityEngine.MonoBehaviour");
codes.Add("{");
codes.Add("");
codes.Add("\t// {{ AOT assemblies");
List<dnlib.DotNet.ModuleDef> modules = new HashSet<dnlib.DotNet.ModuleDef>(
types.Select(t => t.Type.Module).Concat(methods.Select(m => m.Method.Module))).ToList();
modules.Sort((a, b) => a.Name.CompareTo(b.Name));
foreach (dnlib.DotNet.ModuleDef module in modules)
{
codes.Add($"\t// {module.Name}");
}
codes.Add("\t// }}");
codes.Add("");
codes.Add("\t// {{ constraint implement type");
codes.Add("\t// }} ");
codes.Add("");
codes.Add("\t// {{ AOT generic type");
codes.Add("\t// {{ AOT generic types");
types.Sort((a, b) => a.Type.FullName.CompareTo(b.Type.FullName));
foreach(var type in types)
{
codes.Add($"\t//{type.ToTypeSig()}");
codes.Add($"\t// {PrettifyTypeSig(type.ToTypeSig().ToString())}");
}
codes.Add("\t// }}");
@@ -51,7 +110,7 @@ namespace HybridCLR.Editor.AOT
});
foreach(var method in methods)
{
codes.Add($"\t\t// {method.ToMethodSpec()}");
codes.Add($"\t\t// {PrettifyMethodSig(method.ToMethodSpec().ToString())}");
}
codes.Add("\t}");
+2 -2
View File
@@ -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);
+3
View File
@@ -38,6 +38,9 @@ namespace HybridCLR.Editor.Commands
BashUtil.RemoveDir(outputPath);
var buildOptions = BuildOptions.BuildScriptsOnly;
#if UNITY_2021_1_OR_NEWER
buildOptions |= BuildOptions.CleanBuildCache;
#endif
bool oldExportAndroidProj = EditorUserBuildSettings.exportAsGoogleAndroidProject;
#if UNITY_EDITOR_OSX
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "com.focus-creative-games.hybridclr_unity",
"version": "2.0.9",
"version": "2.1.0",
"displayName": "HybridCLR",
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
"category": "Runtime",