少年修仙传客户端基础资源
hch
2024-05-11 cc9183fd3d8888d533197e6351e99a2cca6b1ada
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * Copyright (c) 2015-2019 Beebyte Limited. All rights reserved.
 */
#if !BEEBYTE_OBFUSCATOR_DISABLE
 
using System;
using System.IO;
using System.Net;
using UnityEditor;
using UnityEngine;
using UnityEditor.Callbacks;
#if UNITY_5_6_OR_NEWER
using UnityEditor.Build;
#endif
#if UNITY_2018_1_OR_NEWER
using UnityEditor.Build.Reporting;
#endif
 
namespace Beebyte.Obfuscator
{
    /**
     * Hooks into the Unity build pipeline and delegates to perform obfuscation / restoration if requested.
     */
#if UNITY_2018_2_OR_NEWER
    public class PipelineHook : IPreprocessBuildWithReport, IPostBuildPlayerScriptDLLs, IFilterBuildAssemblies
#elif UNITY_2018_1_OR_NEWER
    public class PipelineHook : IPreprocessBuildWithReport, IPostprocessBuildWithReport
#elif UNITY_5_6_OR_NEWER
    public class PipelineHook : IPreprocessBuild, IPostprocessBuild
#else
    public class PipelineHook
#endif
    {
        private static Project _project = new Project(false);
 
#if UNITY_5_6_OR_NEWER
        public int callbackOrder
        {
            get { return 1; }
        }
#endif
 
        [PostProcessBuild(2)]
        public static void PostProcessBuild(BuildTarget target, string pathToBuildProject)
        {
            _project.ObfuscateAssets(target, pathToBuildProject);
        }
 
#if UNITY_2018_2_OR_NEWER
        public void OnPostBuildPlayerScriptDLLs(BuildReport report)
#elif UNITY_2018_1_OR_NEWER
        public void OnPostprocessBuild(BuildReport report)
#elif UNITY_5_6_OR_NEWER
        public void OnPostprocessBuild(BuildTarget target, string path)
#else
        [PostProcessBuild(1)]
        private static void PostBuildHook(BuildTarget buildTarget, string pathToBuildProject)
#endif
        {
            if (_project.HasMonoBehaviourAssetsThatNeedReverting()) RestoreUtils.RestoreMonobehaviourSourceFiles();
            RestoreUtils.RestoreOriginalDlls();
            
            try
            {
#if UNITY_2018_1_OR_NEWER
                if ((report.summary.options & BuildOptions.BuildScriptsOnly) != 0 &&
                    (report.summary.options & BuildOptions.Development) != 0 && // BuildScriptsOnly is only applied in development builds
                    _project.ShouldObfuscate())
                {
                    Debug.LogError("Obfuscation is not supported for the \"Scripts Only Build\" option");
                    return;
                }
#endif
                if (_project.IsSuccess()) return;
                
                if (_project.HasCSharpScripts())
                {
                    Debug.LogError("Failed to obfuscate");
#if UNITY_5_6_OR_NEWER
                    throw new BuildFailedException("Failed to obfuscate");
#else
                    throw new OperationCanceledException("Failed to obfuscate");
#endif
                }
                    
                Debug.LogWarning("No obfuscation required because no C# scripts were found");
            }
            finally
            {
                Clear();
            }
        }
 
#if UNITY_2018_1_OR_NEWER
        public void OnPreprocessBuild(BuildReport report)
        {
            _project = new Project((report.summary.options & BuildOptions.Development) != 0);
        }
#elif UNITY_5_6_OR_NEWER
        public void OnPreprocessBuild(BuildTarget target, string path)
        {
            _project = new Project(Debug.isDebugBuild);
        }
#endif
        
#if UNITY_2018_2_OR_NEWER
        public string[] OnFilterAssemblies(BuildOptions buildOptions, string[] assemblies)
        {
            _project.ObfuscateIfNeeded();
            return assemblies;
        }
#else
        [PostProcessScene(1)]
        public static void Obfuscate()
        {
            _project.ObfuscateIfNeeded();
        }
#endif
        
        public static void ClearProjectViaUpdate()
        {
            Clear();
            EditorApplication.update -= ClearProjectViaUpdate;
        }
 
        private static void Clear()
        {
            _project = new Project(false);
        }
    }
    
    [InitializeOnLoad]
    public static class RestorationStatic
    {
        /*
         * Often Unity's EditorApplication.update delegate is reset. Because it's so important to restore
         * renamed MonoBehaviour assets we assign here where it will be called after scripts are compiled.
         */ 
        static RestorationStatic()
        {
#if UNITY_2018_2_OR_NEWER
#else
            EditorApplication.update += RestoreUtils.RestoreMonobehaviourSourceFiles;
#endif
            EditorApplication.update += RestoreUtils.RestoreOriginalDlls;
        }
    }
}
#endif