Ejemplo n.º 1
0
 public int Compare(string stringA, string stringB)
 {
     return(ModuleMetadata.GetModuleDependencies(stringA).Contains(stringB) ? 1 : ModuleMetadata.GetModuleDependencies(stringB).Contains(stringA) ? -1 : 0);
 }
Ejemplo n.º 2
0
        public static void GenerateDependencies(string strippedAssemblyDir, string icallsListFile, RuntimeClassRegistry rcr, bool doStripping, out HashSet <UnityType> nativeClasses, out HashSet <string> nativeModules, IIl2CppPlatformProvider platformProvider)
        {
            if (AssemblyStripper.UseUnityLinkerEngineModuleStripping)
            {
                GenerateDependencies2(strippedAssemblyDir, doStripping, out nativeClasses, out nativeModules);
                return;
            }

            var strippingInfo  = platformProvider == null ? null : StrippingInfo.GetBuildReportData(platformProvider.buildReport);
            var userAssemblies = GetUserAssemblies(strippedAssemblyDir);

            // [1] Extract native classes from scene and scripts
            nativeClasses = doStripping ? GenerateNativeClassList(rcr, strippedAssemblyDir, userAssemblies, strippingInfo) : null;

            // Exclude module managers (GlobalGameManager) if no dependent classes are used.
            if (nativeClasses != null)
            {
                ExcludeModuleManagers(ref nativeClasses);
            }

            // [2] Prepare a list of modules to register
            nativeModules = GetNativeModulesToRegister(nativeClasses, strippingInfo);

            if (nativeClasses != null && icallsListFile != null)
            {
                // Get required modules from icall list file
                var icallModules = GetModulesFromICalls(icallsListFile);

                // Add GameManager classes for modules
                foreach (var module in icallModules)
                {
                    if (!nativeModules.Contains(module))
                    {
                        if (strippingInfo != null)
                        {
                            strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), StrippingInfo.RequiredByScripts);
                        }
                    }

                    var moduleClasses = ModuleMetadata.GetModuleTypes(module);
                    foreach (var klass in moduleClasses)
                    {
                        if (klass.IsDerivedFrom(GameManagerTypeInfo))
                        {
                            nativeClasses.Add(klass);
                        }
                    }
                }

                nativeModules.UnionWith(icallModules);
            }

            ApplyManualStrippingOverrides(nativeClasses, nativeModules, strippingInfo);

            bool didAdd = true;

            if (platformProvider != null)
            {
                while (didAdd)
                {
                    didAdd = false;
                    foreach (var module in nativeModules.ToList())
                    {
                        var dependecies = ModuleMetadata.GetModuleDependencies(module);
                        foreach (var dependentModule in dependecies)
                        {
                            if (!nativeModules.Contains(dependentModule))
                            {
                                nativeModules.Add(dependentModule);
                                didAdd = true;
                            }
                            if (strippingInfo != null)
                            {
                                var moduleName = StrippingInfo.ModuleName(module);
                                strippingInfo.RegisterDependency(StrippingInfo.ModuleName(dependentModule), "Required by " + moduleName);
                                strippingInfo.SetIcon("Required by " + moduleName, $"package/com.unity.modules.{module.ToLower()}");
                            }
                        }
                    }
                }
            }

            if (nativeClasses != null)
            {
                RemoveClassesFromRemovedModules(nativeClasses, nativeModules);
            }

            AssemblyReferenceChecker checker = new AssemblyReferenceChecker();

            checker.CollectReferencesFromRoots(strippedAssemblyDir, userAssemblies, true, 0.0f, true);

            if (strippingInfo != null)
            {
                foreach (var module in nativeModules)
                {
                    strippingInfo.AddModule(module);
                }
                strippingInfo.AddModule("Core");
            }

            if (nativeClasses != null && strippingInfo != null && platformProvider != null)
            {
                InjectCustomDependencies(platformProvider.target, strippingInfo, nativeClasses, nativeModules);
            }
        }
Ejemplo n.º 3
0
        private static HashSet <string> GetRequiredStrippableModules(HashSet <string> nativeClasses)
        {
            HashSet <string> stringSet = new HashSet <string>();

            foreach (string moduleName in ModuleMetadata.GetModuleNames())
            {
                if (ModuleMetadata.GetModuleStrippable(moduleName))
                {
                    HashSet <string> classNames = CodeStrippingUtils.GetClassNames((IEnumerable <int>)ModuleMetadata.GetModuleClasses(moduleName));
                    if (nativeClasses.Overlaps((IEnumerable <string>)classNames))
                    {
                        stringSet.Add(moduleName);
                    }
                }
            }
            return(stringSet);
        }
Ejemplo n.º 4
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);
            }
        }
 internal static bool IsExcludedClass(Object target)
 {
     return(ModuleMetadata.GetModuleIncludeSettingForObject(target) == ModuleIncludeSetting.ForceExclude);
 }
Ejemplo n.º 6
0
 public static UnityType[] GetModuleTypes(string moduleName)
 {
     uint[] moduleTypeIndices = ModuleMetadata.GetModuleTypeIndices(moduleName);
     return((from index in moduleTypeIndices
             select UnityType.GetTypeByRuntimeTypeIndex(index)).ToArray <UnityType>());
 }