支持2020构建流程
parent
15007eeb72
commit
b9351e5066
|
@ -18,29 +18,40 @@ namespace Obfuz
|
|||
#if UNITY_2021 || UNITY_2020_1_OR_NEWER
|
||||
internal class ObfuzProcess2021 : IPreprocessBuildWithReport, IPostprocessBuildWithReport
|
||||
{
|
||||
private static bool s_inBuild = false;
|
||||
private static bool s_obfuscated = false;
|
||||
|
||||
public int callbackOrder => 10000;
|
||||
|
||||
[InitializeOnLoadMethod]
|
||||
private static void Init()
|
||||
{
|
||||
CompilationPipeline.compilationFinished += OnCompilationFinished;
|
||||
}
|
||||
|
||||
public void OnPreprocessBuild(BuildReport report)
|
||||
{
|
||||
s_inBuild = true;
|
||||
s_obfuscated = false;
|
||||
|
||||
CompilationPipeline.compilationFinished += OnCompilationFinished;
|
||||
}
|
||||
|
||||
private static string GetScriptAssembliesPath(object obj)
|
||||
{
|
||||
#if UNITY_2021
|
||||
object settings = obj.GetType().GetProperty("settings").GetValue(obj);
|
||||
string path = (string)settings.GetType().GetProperty("OutputDirectory").GetValue(settings);
|
||||
return path;
|
||||
#elif UNITY_2020
|
||||
return "Library/PlayerScriptAssemblies";
|
||||
#else
|
||||
throw new Exception();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnCompilationFinished(object obj)
|
||||
private static void OnCompilationFinished(object obj)
|
||||
{
|
||||
if (s_inBuild && !s_obfuscated)
|
||||
if (!BuildPipeline.isBuildingPlayer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!s_obfuscated)
|
||||
{
|
||||
RunObfuscate(GetScriptAssembliesPath(obj));
|
||||
s_obfuscated = true;
|
||||
|
@ -49,9 +60,7 @@ namespace Obfuz
|
|||
|
||||
public void OnPostprocessBuild(BuildReport report)
|
||||
{
|
||||
s_inBuild = false;
|
||||
s_obfuscated = false;
|
||||
CompilationPipeline.compilationFinished -= OnCompilationFinished;
|
||||
}
|
||||
|
||||
private static void RunObfuscate(string scriptAssembliesPath)
|
||||
|
@ -76,8 +85,15 @@ namespace Obfuz
|
|||
{
|
||||
AssemblySearchDirs = new List<string>
|
||||
{
|
||||
#if UNITY_2021_1_OR_NEWER
|
||||
Path.Combine(applicationContentsPath, "UnityReferenceAssemblies/unity-4.8-api/Facades"),
|
||||
Path.Combine(applicationContentsPath, "UnityReferenceAssemblies/unity-4.8-api"),
|
||||
#elif UNITY_2020
|
||||
Path.Combine(applicationContentsPath, "MonoBleedingEdge/lib/mono/4.7.1-api/Facades"),
|
||||
Path.Combine(applicationContentsPath, "MonoBleedingEdge/lib/mono/4.7.1-api"),
|
||||
#else
|
||||
#error "Unsupported Unity version"
|
||||
#endif
|
||||
Path.Combine(applicationContentsPath, "Managed/UnityEngine"),
|
||||
backupPlayerScriptAssembliesPath,
|
||||
},
|
||||
|
@ -100,4 +116,4 @@ namespace Obfuz
|
|||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace Obfuz
|
|||
}
|
||||
}
|
||||
|
||||
public static V GetValueOrDefault<K, V>(IDictionary<K, V> dic, K key)
|
||||
public static V GetValueOrDefault<K, V>(this IDictionary<K, V> dic, K key)
|
||||
{
|
||||
return dic.TryGetValue(key, out V v) ? v : default(V);
|
||||
}
|
||||
|
|
|
@ -259,7 +259,7 @@ namespace Obfuz
|
|||
{
|
||||
return type;
|
||||
}
|
||||
return type.IsClassSig ? new ClassSig(typeDef) : new ValueTypeSig(typeDef);
|
||||
return type.IsClassSig ? (TypeSig)new ClassSig(typeDef) : new ValueTypeSig(typeDef);
|
||||
}
|
||||
case ElementType.Array:
|
||||
{
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace Obfuz
|
|||
nameOrPattern = "*";
|
||||
}
|
||||
_str = nameOrPattern;
|
||||
_regex = nameOrPattern.Contains('*') || nameOrPattern.Contains('?') ? new Regex(WildcardToRegex(nameOrPattern)) : null;
|
||||
_regex = nameOrPattern.Contains("*") || nameOrPattern.Contains("?") ? new Regex(WildcardToRegex(nameOrPattern)) : null;
|
||||
}
|
||||
|
||||
public static string WildcardToRegex(string pattern)
|
||||
|
|
|
@ -307,7 +307,7 @@ namespace Obfuz
|
|||
rule.typeRuleSpecs = new List<TypeRuleSpec>();
|
||||
foreach (XmlNode node in element.ChildNodes)
|
||||
{
|
||||
if (node is not XmlElement childElement)
|
||||
if (!(node is XmlElement childElement))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -337,7 +337,7 @@ namespace Obfuz
|
|||
rule.eventRuleSpecs = new List<EventRuleSpec>();
|
||||
foreach (XmlNode node in element.ChildNodes)
|
||||
{
|
||||
if (node is not XmlElement childElement)
|
||||
if (!(node is XmlElement childElement))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -423,7 +423,7 @@ namespace Obfuz
|
|||
|
||||
foreach (XmlNode node in element.ChildNodes)
|
||||
{
|
||||
if (node is not XmlElement childElement)
|
||||
if (!(node is XmlElement childElement))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -461,7 +461,7 @@ namespace Obfuz
|
|||
|
||||
foreach (XmlNode node in element.ChildNodes)
|
||||
{
|
||||
if (node is not XmlElement childElement)
|
||||
if (!(node is XmlElement childElement))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -577,7 +577,7 @@ namespace Obfuz
|
|||
}
|
||||
foreach (XmlNode node in root.ChildNodes)
|
||||
{
|
||||
if (node is not XmlElement element)
|
||||
if (!(node is XmlElement element))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -252,7 +252,7 @@ namespace Obfuz
|
|||
var root = doc.DocumentElement;
|
||||
foreach (XmlNode node in root.ChildNodes)
|
||||
{
|
||||
if (node is not XmlElement element)
|
||||
if (!(node is XmlElement element))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -273,11 +273,11 @@ namespace Obfuz
|
|||
{
|
||||
oldAssName = assemblyName,
|
||||
newAssName = newAssemblyName,
|
||||
status = System.Enum.Parse<RenameStatus>(ele.Attributes["status"].Value),
|
||||
status = (RenameStatus)System.Enum.Parse(typeof(RenameStatus), ele.Attributes["status"].Value),
|
||||
};
|
||||
foreach (XmlNode node in ele.ChildNodes)
|
||||
{
|
||||
if (node is not XmlElement element)
|
||||
if (!(node is XmlElement element))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -298,11 +298,11 @@ namespace Obfuz
|
|||
{
|
||||
oldFullName = typeName,
|
||||
newFullName = newTypeName,
|
||||
status = System.Enum.Parse<RenameStatus>(ele.Attributes["status"].Value),
|
||||
status = (RenameStatus)System.Enum.Parse(typeof(RenameStatus), ele.Attributes["status"].Value),
|
||||
};
|
||||
foreach (XmlNode node in ele.ChildNodes)
|
||||
{
|
||||
if (node is not XmlElement c)
|
||||
if (!(node is XmlElement c))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ namespace Obfuz
|
|||
};
|
||||
foreach (XmlNode node in ele.ChildNodes)
|
||||
{
|
||||
if (node is not XmlElement c)
|
||||
if (!(node is XmlElement c))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue