mirror of
https://github.com/focus-creative-games/hybridclr_unity.git
synced 2026-11-20 07:22:39 +08:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e76b96f97 | |||
| dd18ecdba5 | |||
| 2ff3e276d2 | |||
| 1d5f2a953c | |||
| 75cb53cb19 | |||
| c84f575a2e | |||
| 3beb788baa | |||
| 6909c32a0c |
@@ -1,5 +1,6 @@
|
||||
# change logs
|
||||
|
||||
- 2023.03.28 `HybridCLR/Generate/Il2CppDef`生成的代码位置移到`hybridclr/generated`下
|
||||
- 2022.8.30 创建
|
||||
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,277 @@
|
||||
#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
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed8859610137d404e87f332b7082c19b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,55 @@
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Runtime.CompilerServices;
|
||||
using MonoHook;
|
||||
using HybridCLR.Editor.BuildProcessors;
|
||||
using System.IO;
|
||||
|
||||
namespace HybridCLR.MonoHook
|
||||
{
|
||||
#if UNITY_2021_1_OR_NEWER && UNITY_WEBGL
|
||||
[InitializeOnLoad]
|
||||
public class PatchScriptingAssembliesJsonHook
|
||||
{
|
||||
private static MethodHook _hook;
|
||||
|
||||
static PatchScriptingAssembliesJsonHook()
|
||||
{
|
||||
if (_hook == null)
|
||||
{
|
||||
Type type = typeof(UnityEditor.EditorApplication);
|
||||
MethodInfo miTarget = type.GetMethod("BuildMainWindowTitle", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
|
||||
MethodInfo miReplacement = new Func<string>(BuildMainWindowTitle).Method;
|
||||
MethodInfo miProxy = new Func<string>(BuildMainWindowTitleProxy).Method;
|
||||
|
||||
_hook = new MethodHook(miTarget, miReplacement, miProxy);
|
||||
_hook.Install();
|
||||
}
|
||||
}
|
||||
|
||||
private static string BuildMainWindowTitle()
|
||||
{
|
||||
string tempJsonPath = $"{Application.dataPath}/../Library/PlayerDataCache/WebGL/Data/ScriptingAssemblies.json";
|
||||
if (File.Exists(tempJsonPath))
|
||||
{
|
||||
var patcher = new PatchScriptingAssemblyList();
|
||||
patcher.PathScriptingAssembilesFile(Path.GetDirectoryName(tempJsonPath));
|
||||
}
|
||||
string newTitle = BuildMainWindowTitleProxy();
|
||||
return newTitle;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoOptimization)]
|
||||
private static string BuildMainWindowTitleProxy()
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc89a9041ab48ac41975fbd1e00b9b98
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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,7 +358,7 @@ namespace MonoHook
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
#if UNITY_EDITOR && !UNITY_2020_3_OR_NEWER
|
||||
private void OnEditorUpdate()
|
||||
{
|
||||
if (s_fi_GUISkin_current.GetValue(null) != null)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82346623158bae349a8347ae74662b12
|
||||
guid: 16b9dc031f67b4fe5ad79c230f75768c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
|
||||
@@ -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}");
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
#endif
|
||||
}
|
||||
|
||||
private void PathScriptingAssembilesFile(string path)
|
||||
public void PathScriptingAssembilesFile(string path)
|
||||
{
|
||||
if (!SettingsUtil.Enable)
|
||||
{
|
||||
|
||||
@@ -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,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
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "com.focus-creative-games.hybridclr_unity",
|
||||
"version": "2.0.8",
|
||||
"version": "2.1.0",
|
||||
"displayName": "HybridCLR",
|
||||
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
|
||||
"category": "Runtime",
|
||||
|
||||
Reference in New Issue
Block a user