Esempio n. 1
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);
        }
Esempio n. 2
0
 private static void ExcludeModuleManagers(ref HashSet <UnityType> nativeClasses)
 {
     string[] moduleNames = ModuleMetadata.GetModuleNames();
     string[] array       = moduleNames;
     for (int i = 0; i < array.Length; i++)
     {
         string moduleName = array[i];
         if (ModuleMetadata.GetModuleStrippable(moduleName))
         {
             UnityType[]         moduleTypes = ModuleMetadata.GetModuleTypes(moduleName);
             HashSet <UnityType> hashSet     = new HashSet <UnityType>();
             HashSet <UnityType> hashSet2    = new HashSet <UnityType>();
             UnityType[]         array2      = moduleTypes;
             for (int j = 0; j < array2.Length; j++)
             {
                 UnityType unityType = array2[j];
                 if (unityType.IsDerivedFrom(CodeStrippingUtils.GameManagerTypeInfo))
                 {
                     hashSet.Add(unityType);
                 }
                 else
                 {
                     hashSet2.Add(unityType);
                 }
             }
             if (hashSet2.Count != 0)
             {
                 if (!nativeClasses.Overlaps(hashSet2))
                 {
                     foreach (UnityType current in hashSet)
                     {
                         nativeClasses.Remove(current);
                     }
                 }
                 else
                 {
                     foreach (UnityType current2 in hashSet)
                     {
                         nativeClasses.Add(current2);
                     }
                 }
             }
         }
     }
 }
        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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
            }
        }