三国卡牌客户端基础资源仓库
yyl
2025-08-25 214fe94eaf7f09741a7857775dfffe8c3b83c75c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
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 || UNITY_WEIXINMINIGAME)
    [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()
        {
        var cacheDir = $"{Application.dataPath}/../Library/PlayerDataCache";
        if (Directory.Exists(cacheDir))
            {
                foreach (var tempJsonPath in Directory.GetDirectories(cacheDir, "*", SearchOption.TopDirectoryOnly))
                {
                    string dirName = Path.GetFileName(tempJsonPath);
 #if UNITY_WEIXINMINIGAME
                    if (!dirName.Contains("WeixinMiniGame"))
                    {
                        continue;
                    }
#else
                    if (!dirName.Contains("WebGL"))
                    {
                        continue;
                    }
#endif
 
                    var patcher = new PatchScriptingAssemblyList();
                    patcher.PathScriptingAssembilesFile(tempJsonPath);
                }
            }
 
            string newTitle = BuildMainWindowTitleProxy();
            return newTitle;
        }
 
        [MethodImpl(MethodImplOptions.NoOptimization)]
        private static string BuildMainWindowTitleProxy()
        {
            // 为满足MonoHook要求的最小代码长度而特地加入的无用填充代码,
            UnityEngine.Debug.Log(12345.ToString());
            return string.Empty;
        }
    }
#endif
}