2023-03-13 09:55:26 +08:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2024-05-30 19:22:52 +08:00
|
|
|
|
#if UNITY_2021_1_OR_NEWER && (UNITY_WEBGL || UNITY_WEIXINMINIGAME)
|
2023-03-13 09:55:26 +08:00
|
|
|
|
[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()
|
|
|
|
|
{
|
2024-07-02 17:00:05 +08:00
|
|
|
|
#if UNITY_WEIXINMINIGAME
|
|
|
|
|
Debug.Assert(EditorUserBuildSettings.activeBuildTarget == BuildTarget.WeixinMiniGame);
|
2024-05-30 19:22:52 +08:00
|
|
|
|
string tempJsonPath = $"{Application.dataPath}/../Library/PlayerDataCache/WeixinMiniGame/Data/ScriptingAssemblies.json";
|
2024-07-02 17:00:05 +08:00
|
|
|
|
#else
|
|
|
|
|
Debug.Assert(EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebGL);
|
|
|
|
|
string tempJsonPath = $"{Application.dataPath}/../Library/PlayerDataCache/WebGL/Data/ScriptingAssemblies.json";
|
2024-01-04 11:48:30 +08:00
|
|
|
|
#endif
|
2023-03-13 09:55:26 +08:00
|
|
|
|
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()
|
|
|
|
|
{
|
2023-03-31 00:22:48 +08:00
|
|
|
|
// 为满足MonoHook要求的最小代码长度而特地加入的无用填充代码,
|
|
|
|
|
UnityEngine.Debug.Log(12345.ToString());
|
2023-03-13 09:55:26 +08:00
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|