From 8f0a5bc0f27dcfa2d1b705b2131b1458a56499ce Mon Sep 17 00:00:00 2001 From: walon Date: Tue, 27 May 2025 20:06:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=BB=98=E8=AE=A4=E6=B7=B7?= =?UTF-8?q?=E6=B7=86=E4=BA=86DOTS=E7=94=9F=E6=88=90=E7=9A=84Unity.Entities?= =?UTF-8?q?.CodeGeneratedRegistry.AssemblyTypeRegistry=E7=B1=BB=E5=90=8D?= =?UTF-8?q?=EF=BC=8C=E5=AF=BC=E8=87=B4DOTS=E7=B1=BB=E5=9E=8B=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E5=A4=B1=E8=B4=A5=E7=9A=84Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SymbolObfus/Policies/UnityRenamePolicy.cs | 24 +++++++++++++++ .../Editor/Utils/MetaUtil.cs | 30 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/com.code-philosophy.obfuz/Editor/ObfusPasses/SymbolObfus/Policies/UnityRenamePolicy.cs b/com.code-philosophy.obfuz/Editor/ObfusPasses/SymbolObfus/Policies/UnityRenamePolicy.cs index e98fd4e..e3990b4 100644 --- a/com.code-philosophy.obfuz/Editor/ObfusPasses/SymbolObfus/Policies/UnityRenamePolicy.cs +++ b/com.code-philosophy.obfuz/Editor/ObfusPasses/SymbolObfus/Policies/UnityRenamePolicy.cs @@ -132,6 +132,18 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies { return true; } + if (typeDef.FullName == "Unity.Entities.CodeGeneratedRegistry.AssemblyTypeRegistry") + { + return true; + } + if (typeDef.Name.StartsWith("__JobReflectionRegistrationOutput")) + { + return true; + } + if (typeDef.CustomAttributes.Find("Unity.Jobs.DOTSCompilerGeneratedAttribute") != null) + { + return true; + } if (typeDef.DeclaringType != null) { return IsUnitySourceGeneratedAssemblyType(typeDef.DeclaringType); @@ -145,6 +157,10 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies { return false; } + if (MetaUtil.IsInheritFromDOTSTypes(typeDef)) + { + return false; + } if (typeDef.Methods.Any(m => MetaUtil.HasRuntimeInitializeOnLoadMethodAttribute(m))) { return false; @@ -167,6 +183,10 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies { return false; } + if (MetaUtil.IsInheritFromDOTSTypes(typeDef)) + { + return false; + } if (MetaUtil.HasRuntimeInitializeOnLoadMethodAttribute(methodDef)) { return false; @@ -185,6 +205,10 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies { return !MetaUtil.IsSerializableField(fieldDef); } + if (MetaUtil.IsInheritFromDOTSTypes(typeDef)) + { + return false; + } if (typeDef.IsEnum && MetaUtil.HasBlackboardEnumAttribute(typeDef)) { return false; diff --git a/com.code-philosophy.obfuz/Editor/Utils/MetaUtil.cs b/com.code-philosophy.obfuz/Editor/Utils/MetaUtil.cs index 470c943..0da450a 100644 --- a/com.code-philosophy.obfuz/Editor/Utils/MetaUtil.cs +++ b/com.code-philosophy.obfuz/Editor/Utils/MetaUtil.cs @@ -116,6 +116,36 @@ namespace Obfuz.Utils return null; } + public static bool IsInheritFromDOTSTypes(TypeDef typeDef) + { + TypeDef cur = typeDef; + while (true) + { + if (cur.Namespace.StartsWith("Unity.Entities") || + //cur.Namespace.StartsWith("Unity.Jobs") || + cur.Namespace.StartsWith("Unity.Burst")) + { + return true; + } + foreach (var interfaceType in cur.Interfaces) + { + TypeDef interfaceTypeDef = interfaceType.Interface.ResolveTypeDef(); + if (interfaceTypeDef != null && (interfaceTypeDef.Namespace.StartsWith("Unity.Entities") || + //interfaceTypeDef.Namespace.StartsWith("Unity.Jobs") || + interfaceTypeDef.Namespace.StartsWith("Unity.Burst"))) + { + return true; + } + } + + cur = GetBaseTypeDef(cur); + if (cur == null) + { + return false; + } + } + } + public static bool IsInheritFromMonoBehaviour(TypeDef typeDef) { TypeDef cur = typeDef;