private static HashSet <string> GenerateNativeClassList(RuntimeClassRegistry rcr, string directory, string[] rootAssemblies, StrippingInfo strippingInfo)
        {
            HashSet <string> hashSet = CodeStrippingUtils.CollectNativeClassListFromRoots(directory, rootAssemblies, strippingInfo);

            string[] nativeClassBlackList = CodeStrippingUtils.NativeClassBlackList;
            for (int i = 0; i < nativeClassBlackList.Length; i++)
            {
                string text = nativeClassBlackList[i];
                hashSet.Add(text);
                if (strippingInfo != null)
                {
                    strippingInfo.RegisterDependency(text, "Blacklisted");
                }
            }
            foreach (string current in CodeStrippingUtils.NativeClassDependencyBlackList.Keys)
            {
                if (hashSet.Contains(current))
                {
                    string text2 = CodeStrippingUtils.NativeClassDependencyBlackList[current];
                    hashSet.Add(text2);
                    if (strippingInfo != null)
                    {
                        strippingInfo.RegisterDependency(text2, string.Format("Blacklisted due to dependent class '{0}'", current));
                    }
                }
            }
            foreach (string current2 in rcr.GetAllNativeClassesIncludingManagersAsString())
            {
                int num = BaseObjectTools.StringToClassID(current2);
                if (num != -1 && !BaseObjectTools.IsBaseObject(num))
                {
                    hashSet.Add(current2);
                    if (strippingInfo != null && !BaseObjectTools.IsDerivedFromClassID(num, CodeStrippingUtils.gameManagerClassId))
                    {
                        strippingInfo.RegisterDependency(current2, "Used in Scenes");
                    }
                }
            }
            HashSet <string> hashSet2 = new HashSet <string>();

            foreach (string current3 in hashSet)
            {
                int iD = BaseObjectTools.StringToClassID(current3);
                while (!BaseObjectTools.IsBaseObject(iD))
                {
                    hashSet2.Add(BaseObjectTools.ClassIDToString(iD));
                    int superClassID = BaseObjectTools.GetSuperClassID(iD);
                    if (strippingInfo != null)
                    {
                        strippingInfo.RegisterDependency(BaseObjectTools.ClassIDToString(superClassID), BaseObjectTools.ClassIDToString(iD));
                    }
                    iD = BaseObjectTools.GetSuperClassID(iD);
                }
            }
            return(hashSet2);
        }
Exemple #2
0
        public static void InjectCustomDependencies(BuildTarget target, StrippingInfo strippingInfo, HashSet <UnityType> nativeClasses,
                                                    HashSet <string> nativeModules)
        {
            // This function can be used to inject user-readable dependency information for specific classes which would not be obvious otherwise.
            // Can also be used to set up dependencies to modules which cannot be derived by the build pipeline without custom rules
            const string connectSettingsName         = "UnityConnectSettings";
            var          connectSettings             = UnityType.FindTypeByName(connectSettingsName);
            const string cloudWebServicesManagerName = "CloudWebServicesManager";
            var          cloudWebServicesManager     = UnityType.FindTypeByName(cloudWebServicesManagerName);

            if (nativeClasses.Contains(connectSettings) || nativeClasses.Contains(cloudWebServicesManager))
            {
                if (PlayerSettings.submitAnalytics)
                {
                    const string requiredMessage = "Required by HW Statistics (See Player Settings)";
                    strippingInfo.RegisterDependency(connectSettingsName, requiredMessage);
                    strippingInfo.RegisterDependency(cloudWebServicesManagerName, requiredMessage);
                    strippingInfo.SetIcon(requiredMessage, "class/PlayerSettings");
                }
            }

            const string analyticsManagerName = "UnityAnalyticsManager";
            var          analyticsManager     = UnityType.FindTypeByName(analyticsManagerName);

            if (nativeClasses.Contains(analyticsManager))
            {
                if (UnityEditor.Analytics.AnalyticsSettings.enabled)
                {
                    const string requiredMessage = "Required by Unity Analytics (See Services Window)";
                    strippingInfo.RegisterDependency(analyticsManagerName, requiredMessage);
                    strippingInfo.SetIcon(requiredMessage, "class/PlayerSettings");
                }
            }

            if (UnityEditorInternal.VR.VRModule.ShouldInjectVRDependenciesForBuildTarget(target))
            {
                const string moduleName      = "VR";
                const string requiredMessage = "Required because VR is enabled in PlayerSettings";
                nativeModules.Add(moduleName);
                strippingInfo.RegisterDependency(StrippingInfo.ModuleName(moduleName), requiredMessage);
                strippingInfo.SetIcon(requiredMessage, "class/PlayerSettings");
            }

            foreach (string module in ModuleMetadata.GetModuleNames())
            {
                if (!ModuleMetadata.IsStrippableModule(module))
                {
                    string requiredMessage = module + " is always required";
                    nativeModules.Add(module);
                    strippingInfo.AddModule(module);
                    strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), requiredMessage);
                    strippingInfo.SetIcon(requiredMessage, "class/DefaultAsset");
                }
            }
        }
        private static HashSet <string> CollectManagedTypeReferencesFromRoots(string directory, string[] rootAssemblies, StrippingInfo strippingInfo)
        {
            HashSet <string>         set     = new HashSet <string>();
            AssemblyReferenceChecker checker = new AssemblyReferenceChecker();
            bool collectMethods   = false;
            bool ignoreSystemDlls = false;

            checker.CollectReferencesFromRoots(directory, rootAssemblies, collectMethods, 0f, ignoreSystemDlls);
            string[]             assemblyFileNames   = checker.GetAssemblyFileNames();
            AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
            foreach (AssemblyDefinition definition in assemblyDefinitions)
            {
                foreach (TypeDefinition definition2 in definition.MainModule.Types)
                {
                    if (definition2.Namespace.StartsWith("UnityEngine") && (((definition2.Fields.Count > 0) || (definition2.Methods.Count > 0)) || (definition2.Properties.Count > 0)))
                    {
                        string name = definition2.Name;
                        set.Add(name);
                        if ((strippingInfo != null) && !AssemblyReferenceChecker.IsIgnoredSystemDll(definition.Name.Name))
                        {
                            strippingInfo.RegisterDependency(name, "Required by Scripts");
                        }
                    }
                }
            }
            AssemblyDefinition definition3 = null;

            for (int i = 0; i < assemblyFileNames.Length; i++)
            {
                if (assemblyFileNames[i] == "UnityEngine.dll")
                {
                    definition3 = assemblyDefinitions[i];
                }
            }
            foreach (AssemblyDefinition definition4 in assemblyDefinitions)
            {
                if (definition4 != definition3)
                {
                    foreach (TypeReference reference in definition4.MainModule.GetTypeReferences())
                    {
                        if (reference.Namespace.StartsWith("UnityEngine"))
                        {
                            string item = reference.Name;
                            set.Add(item);
                            if ((strippingInfo != null) && !AssemblyReferenceChecker.IsIgnoredSystemDll(definition4.Name.Name))
                            {
                                strippingInfo.RegisterDependency(item, "Required by Scripts");
                            }
                        }
                    }
                }
            }
            return(set);
        }
        public static void GenerateDependencies(string strippedAssemblyDir, string icallsListFile, RuntimeClassRegistry rcr, out HashSet <string> nativeClasses, out HashSet <string> nativeModules, BuildReport buildReport)
        {
            StrippingInfo buildReportData = StrippingInfo.GetBuildReportData(buildReport);

            string[] userAssemblies = CodeStrippingUtils.GetUserAssemblies(strippedAssemblyDir);
            nativeClasses = ((!PlayerSettings.stripEngineCode) ? null : CodeStrippingUtils.GenerateNativeClassList(rcr, strippedAssemblyDir, userAssemblies, buildReportData));
            if (nativeClasses != null)
            {
                CodeStrippingUtils.ExcludeModuleManagers(ref nativeClasses);
            }
            nativeModules = CodeStrippingUtils.GetNativeModulesToRegister(nativeClasses, buildReportData);
            if (nativeClasses != null && icallsListFile != null)
            {
                HashSet <string> modulesFromICalls = CodeStrippingUtils.GetModulesFromICalls(icallsListFile);
                foreach (string current in modulesFromICalls)
                {
                    if (!nativeModules.Contains(current) && buildReportData != null)
                    {
                        buildReportData.RegisterDependency(current, "Required by Scripts");
                    }
                    int[] moduleClasses = ModuleMetadata.GetModuleClasses(current);
                    int[] array         = moduleClasses;
                    for (int i = 0; i < array.Length; i++)
                    {
                        int num = array[i];
                        if (BaseObjectTools.IsDerivedFromClassID(num, CodeStrippingUtils.gameManagerClassId))
                        {
                            string text = BaseObjectTools.ClassIDToString(num);
                            nativeClasses.Add(text);
                            if (buildReportData != null)
                            {
                                buildReportData.RegisterDependency(text, "Required by Module");
                            }
                        }
                    }
                }
                nativeModules.UnionWith(modulesFromICalls);
            }
            AssemblyReferenceChecker assemblyReferenceChecker = new AssemblyReferenceChecker();

            assemblyReferenceChecker.CollectReferencesFromRoots(strippedAssemblyDir, userAssemblies, true, 0f, true);
            if (buildReportData != null)
            {
                foreach (string current2 in nativeModules)
                {
                    buildReportData.AddModule(current2);
                }
                buildReportData.AddModule("Core");
            }
        }
 public static void ApplyManualStrippingOverrides(HashSet <UnityType> nativeClasses, HashSet <string> nativeModules, StrippingInfo strippingInfo)
 {
     string[] moduleNames = ModuleMetadata.GetModuleNames();
     for (int i = 0; i < moduleNames.Length; i++)
     {
         string text = moduleNames[i];
         ModuleIncludeSetting moduleIncludeSettingForModule = ModuleMetadata.GetModuleIncludeSettingForModule(text);
         if (moduleIncludeSettingForModule == ModuleIncludeSetting.ForceInclude)
         {
             nativeModules.Add(text);
             UnityType[] moduleTypes = ModuleMetadata.GetModuleTypes(text);
             UnityType[] array       = moduleTypes;
             for (int j = 0; j < array.Length; j++)
             {
                 UnityType unityType = array[j];
                 nativeClasses.Add(unityType);
                 if (strippingInfo != null)
                 {
                     strippingInfo.RegisterDependency(unityType.name, "Force included module");
                     strippingInfo.RegisterDependency(StrippingInfo.ModuleName(text), unityType.name);
                 }
             }
             if (strippingInfo != null)
             {
                 strippingInfo.RegisterDependency(StrippingInfo.ModuleName(text), "Force included module");
             }
         }
         else if (moduleIncludeSettingForModule == ModuleIncludeSetting.ForceExclude)
         {
             if (nativeModules.Contains(text))
             {
                 nativeModules.Remove(text);
                 UnityType[] moduleTypes2 = ModuleMetadata.GetModuleTypes(text);
                 UnityType[] array2       = moduleTypes2;
                 for (int k = 0; k < array2.Length; k++)
                 {
                     UnityType item = array2[k];
                     if (nativeClasses.Contains(item))
                     {
                         nativeClasses.Remove(item);
                     }
                 }
                 if (strippingInfo != null)
                 {
                     strippingInfo.modules.Remove(StrippingInfo.ModuleName(text));
                 }
             }
         }
     }
 }
Exemple #6
0
        public static void InjectCustomDependencies(BuildTarget target, StrippingInfo strippingInfo, HashSet <UnityType> nativeClasses,
                                                    HashSet <string> nativeModules)
        {
            if (AssemblyStripper.UseUnityLinkerEngineModuleStripping)
            {
                throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used");
            }

            // This function can be used to inject user-readable dependency information for specific classes which would not be obvious otherwise.
            // Can also be used to set up dependencies to modules which cannot be derived by the build pipeline without custom rules
            if (UnityEngine.Connect.UnityConnectSettings.enabled || UnityEditor.CrashReporting.CrashReportingSettings.enabled || UnityEngine.Analytics.PerformanceReporting.enabled || UnityEngine.Analytics.Analytics.enabled)
            {
                string       requiredMessage = "Required by HW Statistics (See Player Settings)";
                const string icon            = "class/PlayerSettings";
                if (UnityEngine.Analytics.Analytics.enabled || UnityEngine.Analytics.PerformanceReporting.enabled)
                {
                    requiredMessage = "Required by Analytics Performance Reporting (See Analytics Services Window)";
                    AddNativeModuleInStrippingInfo("PerformanceReporting", requiredMessage, strippingInfo, nativeModules, icon);
                }
                requiredMessage = "Required by UnityAnalytics (See Services Window)";
                AddNativeModuleInStrippingInfo("UnityAnalytics", requiredMessage, strippingInfo, nativeModules, icon);

                AddNativeModuleInStrippingInfo("UnityConnect", requiredMessage, strippingInfo, nativeModules, icon);
                strippingInfo.RegisterDependency("UnityConnectSettings", "Required by UnityAnalytics");
            }

            if (CrashReporting.CrashReportingSettings.enabled)
            {
                AddNativeModuleInStrippingInfo("CrashReporting", "Required by Crash Reporting Service (See Services Window)", strippingInfo, nativeModules, "class/PlayerSettings");
            }

            if (UnityEditorInternal.VR.VRModule.ShouldInjectVRDependenciesForBuildTarget(target))
            {
                const string moduleName      = "VR";
                const string requiredMessage = "Required because VR is enabled in PlayerSettings";
                nativeModules.Add(moduleName);
                strippingInfo.RegisterDependency(StrippingInfo.ModuleName(moduleName), requiredMessage);
                strippingInfo.SetIcon(requiredMessage, "class/PlayerSettings");
            }

            foreach (string module in ModuleMetadata.GetModuleNames())
            {
                if (!ModuleMetadata.IsStrippableModule(module))
                {
                    string requiredMessage = module + " is always required";
                    AddNativeModuleInStrippingInfo(module, requiredMessage, strippingInfo, nativeModules, "class/DefaultAsset");
                }
            }
        }
        private static bool AddWhiteListsForModules(IEnumerable <string> nativeModules, ref IEnumerable <string> blacklists, string moduleStrippingInformationFolder, BuildReport buildReport)
        {
            StrippingInfo buildReportData = StrippingInfo.GetBuildReportData(buildReport);
            bool          flag            = false;

            foreach (string current in nativeModules)
            {
                string moduleWhitelist = AssemblyStripper.GetModuleWhitelist(current, moduleStrippingInformationFolder);
                if (File.Exists(moduleWhitelist))
                {
                    if (!blacklists.Contains(moduleWhitelist))
                    {
                        blacklists = blacklists.Concat(new string[]
                        {
                            moduleWhitelist
                        });
                        flag = true;
                    }
                    List <string> dependentModules = AssemblyStripper.GetDependentModules(moduleWhitelist);
                    if (buildReportData != null)
                    {
                        foreach (string current2 in dependentModules)
                        {
                            buildReportData.RegisterDependency(current2, current);
                        }
                    }
                    flag = (flag || AssemblyStripper.AddWhiteListsForModules(dependentModules, ref blacklists, moduleStrippingInformationFolder, buildReport));
                }
            }
            return(flag);
        }
Exemple #8
0
 private static void AddNativeModuleInStrippingInfo(string moduleName, string requiredMessage, StrippingInfo strippingInfo, HashSet <string> nativeModules, string icon)
 {
     nativeModules.Add(moduleName);
     strippingInfo.AddModule(moduleName);
     strippingInfo.RegisterDependency(StrippingInfo.ModuleName(moduleName), requiredMessage);
     strippingInfo.SetIcon(requiredMessage, icon);
 }
Exemple #9
0
        public static void ApplyManualStrippingOverrides(HashSet <UnityType> nativeClasses, HashSet <string> nativeModules, StrippingInfo strippingInfo)
        {
            if (AssemblyStripper.UseUnityLinkerEngineModuleStripping)
            {
                throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used");
            }

            // Apply manual stripping overrides
            foreach (var module in ModuleMetadata.GetModuleNames())
            {
                var includeSetting = ModuleMetadata.GetModuleIncludeSettingForModule(module);
                if (includeSetting == ModuleIncludeSetting.ForceInclude)
                {
                    nativeModules.Add(module);
                    if (nativeClasses != null)
                    {
                        var moduleClasses = ModuleMetadata.GetModuleTypes(module);
                        foreach (var klass in moduleClasses)
                        {
                            nativeClasses.Add(klass);
                            if (strippingInfo != null)
                            {
                                strippingInfo.RegisterDependency(klass.name, "Force included module");
                                strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), klass.name);
                            }
                        }
                    }

                    if (strippingInfo != null)
                    {
                        strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), "Force included module");
                    }
                }
                else if (includeSetting == ModuleIncludeSetting.ForceExclude)
                {
                    if (nativeModules.Contains(module))
                    {
                        nativeModules.Remove(module);

                        if (strippingInfo != null)
                        {
                            strippingInfo.modules.Remove(StrippingInfo.ModuleName(module));
                        }
                    }
                }
            }
        }
Exemple #10
0
        private static HashSet <string> GetRequiredStrippableModules(HashSet <UnityType> nativeClasses, StrippingInfo strippingInfo)
        {
            if (AssemblyStripper.UseUnityLinkerEngineModuleStripping)
            {
                throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used");
            }

            HashSet <UnityType> nativeClassesUsedInModules = new HashSet <UnityType>();
            HashSet <string>    nativeModules = new HashSet <string>();

            foreach (string module in ModuleMetadata.GetModuleNames())
            {
                if (ModuleMetadata.IsStrippableModule(module)) // Only handle strippable modules. Others are listed in RegisterStaticallyLinkedModulesGranular()
                {
                    var moduleClasses = new HashSet <UnityType>(ModuleMetadata.GetModuleTypes(module));
                    if (nativeClasses.Overlaps(moduleClasses)) // Include module if at least one of its classes is present
                    {
                        nativeModules.Add(module);
                        if (strippingInfo != null)
                        {
                            foreach (var klass in moduleClasses)
                            {
                                if (nativeClasses.Contains(klass))
                                {
                                    strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), klass.name);
                                    // Don't list GlobalGameManagers in a module will automatically be added if the module is added.
                                    nativeClassesUsedInModules.Add(klass);
                                }
                            }
                        }
                    }
                }
            }

            // Classes which have not been registered as belonging to a module belong to the Core module.
            if (strippingInfo != null)
            {
                foreach (var klass in nativeClasses)
                {
                    if (!nativeClassesUsedInModules.Contains(klass))
                    {
                        strippingInfo.RegisterDependency(StrippingInfo.ModuleName("Core"), klass.name);
                    }
                }
            }
            return(nativeModules);
        }
        public static void ApplyManualStrippingOverrides(HashSet <UnityType> nativeClasses, HashSet <string> nativeModules, StrippingInfo strippingInfo)
        {
            // Apply manual stripping overrides
            foreach (var module in ModuleMetadata.GetModuleNames())
            {
                var includeSetting = ModuleMetadata.GetModuleIncludeSettingForModule(module);
                if (includeSetting == ModuleIncludeSetting.ForceInclude)
                {
                    nativeModules.Add(module);
                    var moduleClasses = ModuleMetadata.GetModuleTypes(module);
                    foreach (var klass in moduleClasses)
                    {
                        nativeClasses.Add(klass);
                        if (strippingInfo != null)
                        {
                            strippingInfo.RegisterDependency(klass.name, "Force included module");
                            strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), klass.name);
                        }
                    }

                    if (strippingInfo != null)
                    {
                        strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), "Force included module");
                    }
                }
                else if (includeSetting == ModuleIncludeSetting.ForceExclude)
                {
                    if (nativeModules.Contains(module))
                    {
                        nativeModules.Remove(module);
                        var moduleClasses = ModuleMetadata.GetModuleTypes(module);
                        foreach (var klass in moduleClasses)
                        {
                            if (nativeClasses.Contains(klass))
                            {
                                nativeClasses.Remove(klass);
                            }
                        }

                        if (strippingInfo != null)
                        {
                            strippingInfo.modules.Remove(StrippingInfo.ModuleName(module));
                        }
                    }
                }
            }
        }
        private static HashSet <string> GetRequiredStrippableModules(HashSet <string> nativeClasses, StrippingInfo strippingInfo)
        {
            HashSet <string> hashSet  = new HashSet <string>();
            HashSet <string> hashSet2 = new HashSet <string>();

            string[] moduleNames = ModuleMetadata.GetModuleNames();
            for (int i = 0; i < moduleNames.Length; i++)
            {
                string text = moduleNames[i];
                if (ModuleMetadata.GetModuleStrippable(text))
                {
                    HashSet <string> classNames = CodeStrippingUtils.GetClassNames(ModuleMetadata.GetModuleClasses(text));
                    if (nativeClasses.Overlaps(classNames))
                    {
                        hashSet2.Add(text);
                        if (strippingInfo != null)
                        {
                            foreach (string current in classNames)
                            {
                                if (nativeClasses.Contains(current))
                                {
                                    strippingInfo.RegisterDependency(text, current);
                                    if (BaseObjectTools.IsDerivedFromClassID(BaseObjectTools.StringToClassID(current), CodeStrippingUtils.gameManagerClassId))
                                    {
                                        strippingInfo.RegisterDependency(current, "Required by Module");
                                    }
                                    hashSet.Add(current);
                                }
                            }
                        }
                    }
                }
            }
            if (strippingInfo != null)
            {
                foreach (string current2 in nativeClasses)
                {
                    if (!hashSet.Contains(current2))
                    {
                        strippingInfo.RegisterDependency("Core", current2);
                    }
                }
            }
            return(hashSet2);
        }
        public static void InjectCustomDependencies(StrippingInfo strippingInfo, HashSet <UnityType> nativeClasses)
        {
            UnityType item = UnityType.FindTypeByName("UnityAnalyticsManager");

            if (nativeClasses.Contains(item))
            {
                if (PlayerSettings.submitAnalytics)
                {
                    strippingInfo.RegisterDependency("UnityAnalyticsManager", "Required by HW Statistics (See Player Settings)");
                    strippingInfo.SetIcon("Required by HW Statistics (See Player Settings)", "class/PlayerSettings");
                }
                if (AnalyticsSettings.enabled)
                {
                    strippingInfo.RegisterDependency("UnityAnalyticsManager", "Required by Unity Analytics (See Services Window)");
                    strippingInfo.SetIcon("Required by Unity Analytics (See Services Window)", "class/PlayerSettings");
                }
            }
        }
        public static void InjectCustomDependencies(BuildTarget target, StrippingInfo strippingInfo, HashSet <UnityType> nativeClasses, HashSet <string> nativeModules)
        {
            UnityType item  = UnityType.FindTypeByName("UnityConnectSettings");
            UnityType item2 = UnityType.FindTypeByName("CloudWebServicesManager");

            if (nativeClasses.Contains(item) || nativeClasses.Contains(item2))
            {
                if (PlayerSettings.submitAnalytics)
                {
                    strippingInfo.RegisterDependency("UnityConnectSettings", "Required by HW Statistics (See Player Settings)");
                    strippingInfo.RegisterDependency("CloudWebServicesManager", "Required by HW Statistics (See Player Settings)");
                    strippingInfo.SetIcon("Required by HW Statistics (See Player Settings)", "class/PlayerSettings");
                }
            }
            UnityType item3 = UnityType.FindTypeByName("UnityAnalyticsManager");

            if (nativeClasses.Contains(item3))
            {
                if (AnalyticsSettings.enabled)
                {
                    strippingInfo.RegisterDependency("UnityAnalyticsManager", "Required by Unity Analytics (See Services Window)");
                    strippingInfo.SetIcon("Required by Unity Analytics (See Services Window)", "class/PlayerSettings");
                }
            }
            if (VRModule.ShouldInjectVRDependenciesForBuildTarget(target))
            {
                nativeModules.Add("VR");
                strippingInfo.RegisterDependency(StrippingInfo.ModuleName("VR"), "Required because VR is enabled in PlayerSettings");
                strippingInfo.SetIcon("Required because VR is enabled in PlayerSettings", "class/PlayerSettings");
            }
            string[] moduleNames = ModuleMetadata.GetModuleNames();
            for (int i = 0; i < moduleNames.Length; i++)
            {
                string text = moduleNames[i];
                if (!ModuleMetadata.IsStrippableModule(text))
                {
                    string text2 = text + " is always required";
                    nativeModules.Add(text);
                    strippingInfo.AddModule(text, true);
                    strippingInfo.RegisterDependency(StrippingInfo.ModuleName(text), text2);
                    strippingInfo.SetIcon(text2, "class/DefaultAsset");
                }
            }
        }
Exemple #15
0
        private static HashSet <UnityType> GenerateNativeClassList(RuntimeClassRegistry rcr, string directory, string[] rootAssemblies, StrippingInfo strippingInfo)
        {
            if (AssemblyStripper.UseUnityLinkerEngineModuleStripping)
            {
                throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used");
            }

            HashSet <UnityType> nativeClasses = CollectNativeClassListFromRoots(directory, rootAssemblies, strippingInfo);

            // List native classes found in scenes
            foreach (string klassName in rcr.GetAllNativeClassesIncludingManagersAsString())
            {
                UnityType klass = UnityType.FindTypeByName(klassName);
                if (klass != null && klass.baseClass != null)
                {
                    nativeClasses.Add(klass);
                    if (strippingInfo != null)
                    {
                        if (!klass.IsDerivedFrom(GameManagerTypeInfo))
                        {
                            var scenes = rcr.GetScenesForClass(klass.persistentTypeID);
                            if (scenes != null)
                            {
                                foreach (var scene in scenes)
                                {
                                    strippingInfo.RegisterDependency(klassName, scene);
                                    if (scene.EndsWith(".unity"))
                                    {
                                        strippingInfo.SetIcon(scene, "class/SceneAsset");
                                    }
                                    else
                                    {
                                        strippingInfo.SetIcon(scene, "class/AssetBundle");
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Always include base classes of derived native classes.
            HashSet <UnityType> nativeClassesAndBaseClasses = new HashSet <UnityType>();

            foreach (var klass in nativeClasses)
            {
                var current = klass;
                while (current.baseClass != null)
                {
                    nativeClassesAndBaseClasses.Add(current);
                    current = current.baseClass;
                }
            }

            return(nativeClassesAndBaseClasses);
        }
Exemple #16
0
        private static HashSet <string> GetRequiredStrippableModules(HashSet <UnityType> nativeClasses, StrippingInfo strippingInfo)
        {
            HashSet <UnityType> hashSet  = new HashSet <UnityType>();
            HashSet <string>    hashSet2 = new HashSet <string>();

            string[] moduleNames = ModuleMetadata.GetModuleNames();
            for (int i = 0; i < moduleNames.Length; i++)
            {
                string text = moduleNames[i];
                if (ModuleMetadata.GetModuleStrippable(text))
                {
                    HashSet <UnityType> hashSet3 = new HashSet <UnityType>(ModuleMetadata.GetModuleTypes(text));
                    if (nativeClasses.Overlaps(hashSet3))
                    {
                        hashSet2.Add(text);
                        if (strippingInfo != null)
                        {
                            foreach (UnityType current in hashSet3)
                            {
                                if (nativeClasses.Contains(current))
                                {
                                    strippingInfo.RegisterDependency(StrippingInfo.ModuleName(text), current.name);
                                    hashSet.Add(current);
                                }
                            }
                        }
                    }
                }
            }
            if (strippingInfo != null)
            {
                foreach (UnityType current2 in nativeClasses)
                {
                    if (!hashSet.Contains(current2))
                    {
                        strippingInfo.RegisterDependency(StrippingInfo.ModuleName("Core"), current2.name);
                    }
                }
            }
            return(hashSet2);
        }
Exemple #17
0
        private static void AddNativeModuleInStrippingInfo(string moduleName, string requiredMessage, StrippingInfo strippingInfo, HashSet <string> nativeModules, string icon)
        {
            if (AssemblyStripper.UseUnityLinkerEngineModuleStripping)
            {
                throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used");
            }

            nativeModules.Add(moduleName);
            strippingInfo.AddModule(moduleName);
            strippingInfo.RegisterDependency(StrippingInfo.ModuleName(moduleName), requiredMessage);
            strippingInfo.SetIcon(requiredMessage, icon);
        }
        internal static void UpdateBuildReport(LinkerToEditorData dataFromLinker, StrippingInfo strippingInfo)
        {
            foreach (var moduleInfo in dataFromLinker.report.modules)
            {
                strippingInfo.AddModule(moduleInfo.name);
                foreach (var moduleDependency in moduleInfo.dependencies)
                {
                    strippingInfo.RegisterDependency(StrippingInfo.ModuleName(moduleInfo.name), moduleDependency.name);

                    if (!string.IsNullOrEmpty(moduleDependency.icon))
                    {
                        strippingInfo.SetIcon(moduleDependency.name, moduleDependency.icon);
                    }

                    // Hacky way to match the existing behavior
                    if (moduleDependency.name == "UnityConnectSettings")
                    {
                        strippingInfo.RegisterDependency(moduleDependency.name, "Required by UnityAnalytics");
                    }

                    foreach (var scene in moduleDependency.scenes)
                    {
                        strippingInfo.RegisterDependency(moduleDependency.name, scene);

                        var klass = UnityType.FindTypeByName(moduleDependency.name);
                        if (klass != null && !klass.IsDerivedFrom(CodeStrippingUtils.GameManagerTypeInfo))
                        {
                            if (scene.EndsWith(".unity"))
                            {
                                strippingInfo.SetIcon(scene, "class/SceneAsset");
                            }
                            else
                            {
                                strippingInfo.SetIcon(scene, "class/AssetBundle");
                            }
                        }
                    }
                }
            }
        }
Exemple #19
0
        public static void InjectCustomDependencies(BuildTarget target, StrippingInfo strippingInfo, HashSet <UnityType> nativeClasses, HashSet <string> nativeModules)
        {
            UnityType item = UnityType.FindTypeByName("UnityAnalyticsManager");

            if (nativeClasses.Contains(item))
            {
                if (PlayerSettings.submitAnalytics)
                {
                    strippingInfo.RegisterDependency("UnityAnalyticsManager", "Required by HW Statistics (See Player Settings)");
                    strippingInfo.SetIcon("Required by HW Statistics (See Player Settings)", "class/PlayerSettings");
                }
                if (AnalyticsSettings.enabled)
                {
                    strippingInfo.RegisterDependency("UnityAnalyticsManager", "Required by Unity Analytics (See Services Window)");
                    strippingInfo.SetIcon("Required by Unity Analytics (See Services Window)", "class/PlayerSettings");
                }
            }
            if (CodeStrippingUtils.IsVRModuleUsed(target))
            {
                nativeModules.Add("VR");
                strippingInfo.RegisterDependency("VR", "Required by Scripts");
                strippingInfo.SetIcon("Required because VR is enabled in PlayerSettings", "class/PlayerSettings");
            }
        }
Exemple #20
0
        public static void GenerateDependencies(string strippedAssemblyDir, string icallsListFile, RuntimeClassRegistry rcr, bool doStripping, out HashSet <UnityType> nativeClasses, out HashSet <string> nativeModules, IIl2CppPlatformProvider platformProvider)
        {
            StrippingInfo strippingInfo = (platformProvider != null) ? StrippingInfo.GetBuildReportData(platformProvider.buildReport) : null;

            string[] userAssemblies = CodeStrippingUtils.GetUserAssemblies(strippedAssemblyDir);
            nativeClasses = ((!doStripping) ? null : CodeStrippingUtils.GenerateNativeClassList(rcr, strippedAssemblyDir, userAssemblies, strippingInfo));
            if (nativeClasses != null)
            {
                CodeStrippingUtils.ExcludeModuleManagers(ref nativeClasses);
            }
            nativeModules = CodeStrippingUtils.GetNativeModulesToRegister(nativeClasses, strippingInfo);
            if (nativeClasses != null && icallsListFile != null)
            {
                HashSet <string> modulesFromICalls = CodeStrippingUtils.GetModulesFromICalls(icallsListFile);
                foreach (string current in modulesFromICalls)
                {
                    if (!nativeModules.Contains(current))
                    {
                        if (strippingInfo != null)
                        {
                            strippingInfo.RegisterDependency(StrippingInfo.ModuleName(current), "Required by Scripts");
                        }
                    }
                    UnityType[] moduleTypes = ModuleMetadata.GetModuleTypes(current);
                    UnityType[] array       = moduleTypes;
                    for (int i = 0; i < array.Length; i++)
                    {
                        UnityType unityType = array[i];
                        if (unityType.IsDerivedFrom(CodeStrippingUtils.GameManagerTypeInfo))
                        {
                            nativeClasses.Add(unityType);
                        }
                    }
                }
                nativeModules.UnionWith(modulesFromICalls);
            }
            bool flag = true;

            if (platformProvider != null)
            {
                while (flag)
                {
                    flag = false;
                    foreach (string current2 in nativeModules.ToList <string>())
                    {
                        string moduleWhitelist = CodeStrippingUtils.GetModuleWhitelist(current2, platformProvider.moduleStrippingInformationFolder);
                        if (File.Exists(moduleWhitelist))
                        {
                            foreach (string current3 in CodeStrippingUtils.GetDependentModules(moduleWhitelist))
                            {
                                if (!nativeModules.Contains(current3))
                                {
                                    nativeModules.Add(current3);
                                    flag = true;
                                }
                                if (strippingInfo != null)
                                {
                                    string text = StrippingInfo.ModuleName(current2);
                                    strippingInfo.RegisterDependency(StrippingInfo.ModuleName(current3), "Required by " + text);
                                    if (strippingInfo.icons.ContainsKey(text))
                                    {
                                        strippingInfo.SetIcon("Required by " + text, strippingInfo.icons[text]);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            AssemblyReferenceChecker assemblyReferenceChecker = new AssemblyReferenceChecker();

            assemblyReferenceChecker.CollectReferencesFromRoots(strippedAssemblyDir, userAssemblies, true, 0f, true);
            if (strippingInfo != null)
            {
                foreach (string current4 in nativeModules)
                {
                    strippingInfo.AddModule(StrippingInfo.ModuleName(current4));
                }
                strippingInfo.AddModule(StrippingInfo.ModuleName("Core"));
            }
            if (nativeClasses != null && strippingInfo != null)
            {
                CodeStrippingUtils.InjectCustomDependencies(platformProvider.target, strippingInfo, nativeClasses, nativeModules);
            }
        }
Exemple #21
0
        // Collects all types from managed assemblies.
        // Follows assembly references from given root assemblies.
        // Assemblies should be already stripped.
        private static HashSet <string> CollectManagedTypeReferencesFromRoots(string directory, string[] rootAssemblies, StrippingInfo strippingInfo)
        {
            if (AssemblyStripper.UseUnityLinkerEngineModuleStripping)
            {
                throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used");
            }

            HashSet <string> foundTypes = new HashSet <string>();

            AssemblyReferenceChecker checker = new AssemblyReferenceChecker();
            bool collectMethods   = false;
            bool ignoreSystemDlls = false;

            checker.CollectReferencesFromRoots(directory, rootAssemblies, collectMethods, 0.0f, ignoreSystemDlls);
            {
                string[]             fileNames  = checker.GetAssemblyFileNames();
                AssemblyDefinition[] assemblies = checker.GetAssemblyDefinitions();

                foreach (AssemblyDefinition definition in assemblies)
                {
                    foreach (TypeDefinition typeDefinition in definition.MainModule.Types)
                    {
                        if (typeDefinition.Namespace.StartsWith("UnityEngine"))
                        {
                            // Skip blank types
                            if (typeDefinition.Fields.Count > 0 || typeDefinition.Methods.Count > 0 || typeDefinition.Properties.Count > 0)
                            {
                                string className = typeDefinition.Name;
                                foundTypes.Add(className);
                                if (strippingInfo != null)
                                {
                                    if (!AssemblyReferenceChecker.IsIgnoredSystemDll(definition))
                                    {
                                        strippingInfo.RegisterDependency(className, StrippingInfo.RequiredByScripts);
                                    }
                                }
                            }
                        }
                    }
                }

                AssemblyDefinition unityEngineAssemblyDefinition   = null;
                AssemblyDefinition unityEngineUIAssemblyDefinition = null;
                for (int i = 0; i < fileNames.Length; i++)
                {
                    if (fileNames[i] == "UnityEngine.dll")
                    {
                        unityEngineAssemblyDefinition = assemblies[i];
                    }

                    // UnityEngine.UI references UnityEngine.Collider, which causes the inclusion of Physics and Physics2D modules if
                    // UnityEngine.UI is referenced. UnityEngine.UI code is designed to only actually access Colliders if these modules
                    // are used, so don't include references from UnityEngine.UI here.
                    if (fileNames[i] == "Unity.ugui.dll")
                    {
                        unityEngineUIAssemblyDefinition = assemblies[i];
                    }
                }

                foreach (AssemblyDefinition definition in assemblies)
                {
                    if (definition != unityEngineAssemblyDefinition && definition != unityEngineUIAssemblyDefinition)
                    {
                        foreach (TypeReference typeReference in definition.MainModule.GetTypeReferences())
                        {
                            if (typeReference.Namespace.StartsWith("UnityEngine"))
                            {
                                string className = typeReference.Name;
                                foundTypes.Add(className);
                                if (strippingInfo != null)
                                {
                                    if (!AssemblyReferenceChecker.IsIgnoredSystemDll(definition))
                                    {
                                        strippingInfo.RegisterDependency(className, StrippingInfo.RequiredByScripts);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(foundTypes);
        }
        private static HashSet <string> CollectManagedTypeReferencesFromRoots(string directory, string[] rootAssemblies, StrippingInfo strippingInfo)
        {
            HashSet <string>         hashSet = new HashSet <string>();
            AssemblyReferenceChecker assemblyReferenceChecker = new AssemblyReferenceChecker();
            bool collectMethods   = false;
            bool ignoreSystemDlls = false;

            assemblyReferenceChecker.CollectReferencesFromRoots(directory, rootAssemblies, collectMethods, 0f, ignoreSystemDlls);
            string[]             assemblyFileNames   = assemblyReferenceChecker.GetAssemblyFileNames();
            AssemblyDefinition[] assemblyDefinitions = assemblyReferenceChecker.GetAssemblyDefinitions();
            AssemblyDefinition[] array = assemblyDefinitions;
            for (int i = 0; i < array.Length; i++)
            {
                AssemblyDefinition assemblyDefinition = array[i];
                using (Collection <TypeDefinition> .Enumerator enumerator = assemblyDefinition.get_MainModule().get_Types().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        TypeDefinition current = enumerator.get_Current();
                        if (current.get_Namespace().StartsWith("UnityEngine"))
                        {
                            if (current.get_Fields().get_Count() > 0 || current.get_Methods().get_Count() > 0 || current.get_Properties().get_Count() > 0)
                            {
                                string name = current.get_Name();
                                hashSet.Add(name);
                                if (strippingInfo != null)
                                {
                                    string name2 = assemblyDefinition.get_Name().get_Name();
                                    if (!AssemblyReferenceChecker.IsIgnoredSystemDll(name2))
                                    {
                                        strippingInfo.RegisterDependency(name, "Required by Scripts");
                                    }
                                }
                            }
                        }
                    }
                }
            }
            AssemblyDefinition assemblyDefinition2 = null;

            for (int j = 0; j < assemblyFileNames.Length; j++)
            {
                if (assemblyFileNames[j] == "UnityEngine.dll")
                {
                    assemblyDefinition2 = assemblyDefinitions[j];
                }
            }
            AssemblyDefinition[] array2 = assemblyDefinitions;
            for (int k = 0; k < array2.Length; k++)
            {
                AssemblyDefinition assemblyDefinition3 = array2[k];
                if (assemblyDefinition3 != assemblyDefinition2)
                {
                    foreach (TypeReference current2 in assemblyDefinition3.get_MainModule().GetTypeReferences())
                    {
                        if (current2.get_Namespace().StartsWith("UnityEngine"))
                        {
                            string name3 = current2.get_Name();
                            hashSet.Add(name3);
                            if (strippingInfo != null)
                            {
                                string name4 = assemblyDefinition3.get_Name().get_Name();
                                if (!AssemblyReferenceChecker.IsIgnoredSystemDll(name4))
                                {
                                    strippingInfo.RegisterDependency(name3, "Required by Scripts");
                                }
                            }
                        }
                    }
                }
            }
            return(hashSet);
        }
        private static HashSet <UnityType> GenerateNativeClassList(RuntimeClassRegistry rcr, string directory, string[] rootAssemblies, StrippingInfo strippingInfo)
        {
            HashSet <UnityType> nativeClasses = CollectNativeClassListFromRoots(directory, rootAssemblies, strippingInfo);

            // Inject blacklisted native types
            foreach (var klass in BlackListNativeClasses)
            {
                nativeClasses.Add(klass);
            }

            foreach (var dependent in BlackListNativeClassesDependency.Keys)
            {
                if (nativeClasses.Contains(dependent))
                {
                    var provider = BlackListNativeClassesDependency[dependent];
                    nativeClasses.Add(provider);
                }
            }

            // List native classes found in scenes
            foreach (string klassName in rcr.GetAllNativeClassesIncludingManagersAsString())
            {
                UnityType klass = UnityType.FindTypeByName(klassName);
                if (klass != null && klass.baseClass != null)
                {
                    nativeClasses.Add(klass);
                    if (strippingInfo != null)
                    {
                        if (!klass.IsDerivedFrom(GameManagerTypeInfo))
                        {
                            var scenes = rcr.GetScenesForClass(klass.persistentTypeID);
                            if (scenes != null)
                            {
                                foreach (var scene in scenes)
                                {
                                    strippingInfo.RegisterDependency(klassName, scene);
                                    if (scene.EndsWith(".unity"))
                                    {
                                        strippingInfo.SetIcon(scene, "class/SceneAsset");
                                    }
                                    else
                                    {
                                        strippingInfo.SetIcon(scene, "class/AssetBundle");
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Always include base classes of derived native classes.
            HashSet <UnityType> nativeClassesAndBaseClasses = new HashSet <UnityType>();

            foreach (var klass in nativeClasses)
            {
                var current = klass;
                while (current.baseClass != null)
                {
                    nativeClassesAndBaseClasses.Add(current);
                    current = current.baseClass;
                }
            }

            return(nativeClassesAndBaseClasses);
        }
Exemple #24
0
        private static HashSet <string> CollectManagedTypeReferencesFromRoots(string directory, string[] rootAssemblies, StrippingInfo strippingInfo)
        {
            HashSet <string>         hashSet = new HashSet <string>();
            AssemblyReferenceChecker assemblyReferenceChecker = new AssemblyReferenceChecker();
            bool collectMethods   = false;
            bool ignoreSystemDlls = false;

            assemblyReferenceChecker.CollectReferencesFromRoots(directory, rootAssemblies, collectMethods, 0f, ignoreSystemDlls);
            string[]             assemblyFileNames   = assemblyReferenceChecker.GetAssemblyFileNames();
            AssemblyDefinition[] assemblyDefinitions = assemblyReferenceChecker.GetAssemblyDefinitions();
            AssemblyDefinition[] array = assemblyDefinitions;
            for (int i = 0; i < array.Length; i++)
            {
                AssemblyDefinition assemblyDefinition = array[i];
                foreach (TypeDefinition current in assemblyDefinition.MainModule.Types)
                {
                    if (current.Namespace.StartsWith("UnityEngine"))
                    {
                        if (current.Fields.Count > 0 || current.Methods.Count > 0 || current.Properties.Count > 0)
                        {
                            string name = current.Name;
                            hashSet.Add(name);
                            if (strippingInfo != null)
                            {
                                string name2 = assemblyDefinition.Name.Name;
                                if (!AssemblyReferenceChecker.IsIgnoredSystemDll(name2))
                                {
                                    strippingInfo.RegisterDependency(name, "Required by Scripts");
                                }
                            }
                        }
                    }
                }
            }
            AssemblyDefinition assemblyDefinition2 = null;
            AssemblyDefinition assemblyDefinition3 = null;

            for (int j = 0; j < assemblyFileNames.Length; j++)
            {
                if (assemblyFileNames[j] == "UnityEngine.dll")
                {
                    assemblyDefinition2 = assemblyDefinitions[j];
                }
                if (assemblyFileNames[j] == "UnityEngine.UI.dll")
                {
                    assemblyDefinition3 = assemblyDefinitions[j];
                }
            }
            AssemblyDefinition[] array2 = assemblyDefinitions;
            for (int k = 0; k < array2.Length; k++)
            {
                AssemblyDefinition assemblyDefinition4 = array2[k];
                if (assemblyDefinition4 != assemblyDefinition2 && assemblyDefinition4 != assemblyDefinition3)
                {
                    foreach (TypeReference current2 in assemblyDefinition4.MainModule.GetTypeReferences())
                    {
                        if (current2.Namespace.StartsWith("UnityEngine"))
                        {
                            string name3 = current2.Name;
                            hashSet.Add(name3);
                            if (strippingInfo != null)
                            {
                                string name4 = assemblyDefinition4.Name.Name;
                                if (!AssemblyReferenceChecker.IsIgnoredSystemDll(name4))
                                {
                                    strippingInfo.RegisterDependency(name3, "Required by Scripts");
                                }
                            }
                        }
                    }
                }
            }
            return(hashSet);
        }
Exemple #25
0
        private static HashSet <UnityType> GenerateNativeClassList(RuntimeClassRegistry rcr, string directory, string[] rootAssemblies, StrippingInfo strippingInfo)
        {
            HashSet <UnityType> hashSet = CodeStrippingUtils.CollectNativeClassListFromRoots(directory, rootAssemblies, strippingInfo);

            UnityType[] blackListNativeClasses = CodeStrippingUtils.BlackListNativeClasses;
            for (int i = 0; i < blackListNativeClasses.Length; i++)
            {
                UnityType item = blackListNativeClasses[i];
                hashSet.Add(item);
            }
            foreach (UnityType current in CodeStrippingUtils.BlackListNativeClassesDependency.Keys)
            {
                if (hashSet.Contains(current))
                {
                    UnityType item2 = CodeStrippingUtils.BlackListNativeClassesDependency[current];
                    hashSet.Add(item2);
                }
            }
            foreach (string current2 in rcr.GetAllNativeClassesIncludingManagersAsString())
            {
                UnityType unityType = UnityType.FindTypeByName(current2);
                if (unityType != null && unityType.baseClass != null)
                {
                    hashSet.Add(unityType);
                    if (strippingInfo != null)
                    {
                        if (!unityType.IsDerivedFrom(CodeStrippingUtils.GameManagerTypeInfo))
                        {
                            List <string> scenesForClass = rcr.GetScenesForClass(unityType.persistentTypeID);
                            if (scenesForClass != null)
                            {
                                foreach (string current3 in scenesForClass)
                                {
                                    strippingInfo.RegisterDependency(current2, current3);
                                    if (current3.EndsWith(".unity"))
                                    {
                                        strippingInfo.SetIcon(current3, "class/SceneAsset");
                                    }
                                    else
                                    {
                                        strippingInfo.SetIcon(current3, "class/AssetBundle");
                                    }
                                }
                            }
                        }
                    }
                }
            }
            HashSet <UnityType> hashSet2 = new HashSet <UnityType>();

            foreach (UnityType current4 in hashSet)
            {
                UnityType unityType2 = current4;
                while (unityType2.baseClass != null)
                {
                    hashSet2.Add(unityType2);
                    unityType2 = unityType2.baseClass;
                }
            }
            return(hashSet2);
        }