Пример #1
0
        private static HashSet <string> CollectManagedTypeReferencesFromRoots(string directory, string[] rootAssemblies)
        {
            HashSet <string>         set     = new HashSet <string>();
            AssemblyReferenceChecker checker = new AssemblyReferenceChecker();
            bool withMethods      = false;
            bool ignoreSystemDlls = false;

            checker.CollectReferencesFromRoots(directory, rootAssemblies, withMethods, 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);
                    }
                }
            }
            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)
                {
                    IEnumerator <TypeReference> enumerator = definition4.MainModule.GetTypeReferences().GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            TypeReference current = enumerator.Current;
                            if (current.Namespace.StartsWith("UnityEngine"))
                            {
                                string item = current.Name;
                                set.Add(item);
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator == null)
                        {
                        }
                        enumerator.Dispose();
                    }
                }
            }
            return(set);
        }
Пример #2
0
 private static HashSet<string> CollectManagedTypeReferencesFromRoots(string directory, string[] rootAssemblies)
 {
     HashSet<string> set = new HashSet<string>();
     AssemblyReferenceChecker checker = new AssemblyReferenceChecker();
     bool withMethods = false;
     bool ignoreSystemDlls = false;
     checker.CollectReferencesFromRoots(directory, rootAssemblies, withMethods, 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);
             }
         }
     }
     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)
         {
             IEnumerator<TypeReference> enumerator = definition4.MainModule.GetTypeReferences().GetEnumerator();
             try
             {
                 while (enumerator.MoveNext())
                 {
                     TypeReference current = enumerator.Current;
                     if (current.Namespace.StartsWith("UnityEngine"))
                     {
                         string item = current.Name;
                         set.Add(item);
                     }
                 }
             }
             finally
             {
                 if (enumerator == null)
                 {
                 }
                 enumerator.Dispose();
             }
         }
     }
     return set;
 }
Пример #3
0
        private static HashSet <string> CollectManagedTypeReferencesFromRoots(string directory, string[] rootAssemblies)
        {
            HashSet <string>         stringSet        = new HashSet <string>();
            AssemblyReferenceChecker referenceChecker = new AssemblyReferenceChecker();
            bool withMethods      = false;
            bool ignoreSystemDlls = false;

            referenceChecker.CollectReferencesFromRoots(directory, (IEnumerable <string>)rootAssemblies, withMethods, 0.0f, ignoreSystemDlls);
            string[]             assemblyFileNames   = referenceChecker.GetAssemblyFileNames();
            AssemblyDefinition[] assemblyDefinitions = referenceChecker.GetAssemblyDefinitions();
            foreach (AssemblyDefinition assemblyDefinition in assemblyDefinitions)
            {
                using (Collection <TypeDefinition> .Enumerator enumerator = assemblyDefinition.get_MainModule().get_Types().GetEnumerator())
                {
                    // ISSUE: explicit reference operation
                    while (((Collection <TypeDefinition> .Enumerator)@enumerator).MoveNext())
                    {
                        // ISSUE: explicit reference operation
                        TypeDefinition current = ((Collection <TypeDefinition> .Enumerator)@enumerator).get_Current();
                        if (((TypeReference)current).get_Namespace().StartsWith("UnityEngine") && (current.get_Fields().get_Count() > 0 || current.get_Methods().get_Count() > 0 || current.get_Properties().get_Count() > 0))
                        {
                            string name = ((TypeReference)current).get_Name();
                            stringSet.Add(name);
                        }
                    }
                }
            }
            AssemblyDefinition assemblyDefinition1 = (AssemblyDefinition)null;

            for (int index = 0; index < assemblyFileNames.Length; ++index)
            {
                if (assemblyFileNames[index] == "UnityEngine.dll")
                {
                    assemblyDefinition1 = assemblyDefinitions[index];
                }
            }
            foreach (AssemblyDefinition assemblyDefinition2 in assemblyDefinitions)
            {
                if (assemblyDefinition2 != assemblyDefinition1)
                {
                    using (IEnumerator <TypeReference> enumerator = assemblyDefinition2.get_MainModule().GetTypeReferences().GetEnumerator())
                    {
                        while (((IEnumerator)enumerator).MoveNext())
                        {
                            TypeReference current = enumerator.Current;
                            if (current.get_Namespace().StartsWith("UnityEngine"))
                            {
                                string name = current.get_Name();
                                stringSet.Add(name);
                            }
                        }
                    }
                }
            }
            return(stringSet);
        }
        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);
        }
Пример #5
0
        private static HashSet <string> CollectManagedTypeReferencesFromRoots(string directory, string[] rootAssemblies)
        {
            HashSet <string>         hashSet = new HashSet <string>();
            AssemblyReferenceChecker assemblyReferenceChecker = new AssemblyReferenceChecker();
            bool withMethods      = false;
            bool ignoreSystemDlls = false;

            assemblyReferenceChecker.CollectReferencesFromRoots(directory, rootAssemblies, withMethods, 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") && (current.Fields.Count > 0 || current.Methods.Count > 0 || current.Properties.Count > 0))
                    {
                        string name = current.Name;
                        hashSet.Add(name);
                    }
                }
            }
            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.MainModule.GetTypeReferences())
                    {
                        if (current2.Namespace.StartsWith("UnityEngine"))
                        {
                            string name2 = current2.Name;
                            hashSet.Add(name2);
                        }
                    }
                }
            }
            return(hashSet);
        }
Пример #6
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);
        }
Пример #7
0
        public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker, string stagingAreaDataManaged)
        {
            HashSet <UnityType> set;
            HashSet <string>    set2;
            string str  = Path.Combine(stagingAreaDataManaged, "ICallSummary.txt");
            string exe  = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe");
            string args = $"-assembly=" { Path.Combine(stagingAreaDataManaged, "UnityEngine.dll") } " -summary=" { str } "";

            Runner.RunManagedProgram(exe, args);
            CodeStrippingUtils.GenerateDependencies(Path.GetFullPath(stagingAreaDataManaged), str, usedClassRegistry, stripping, out set, out set2, null);
            using (TextWriter writer = new StreamWriter(file))
            {
                string[]             assemblyFileNames   = checker.GetAssemblyFileNames();
                AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
                bool      flag = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic;
                ArrayList list = BuildNativeMethodList(assemblyDefinitions);
                if (buildTarget == BuildTarget.iOS)
                {
                    writer.WriteLine("#include \"RegisterMonoModules.h\"");
                    writer.WriteLine("#include <stdio.h>");
                }
                writer.WriteLine("");
                writer.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
                writer.WriteLine("    #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
                writer.WriteLine(@"    #define REGISTER_USER_FUNC(f)\");
                writer.WriteLine(@"        do {\");
                writer.WriteLine(@"        if(f != NULL)\");
                writer.WriteLine(@"            mono_dl_register_symbol(#f, (void*)f);\");
                writer.WriteLine(@"        else\");
                writer.WriteLine("            ::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
                writer.WriteLine("        }while(0)");
                writer.WriteLine("#else");
                writer.WriteLine("    #define DECL_USER_FUNC(f) void f() ");
                writer.WriteLine("    #if !defined(__arm64__)");
                writer.WriteLine("    #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
                writer.WriteLine("    #else");
                writer.WriteLine("        #define REGISTER_USER_FUNC(f)");
                writer.WriteLine("    #endif");
                writer.WriteLine("#endif");
                writer.WriteLine("extern \"C\"\n{");
                writer.WriteLine("    typedef void* gpointer;");
                writer.WriteLine("    typedef int gboolean;");
                if (buildTarget == BuildTarget.iOS)
                {
                    writer.WriteLine("    const char*         UnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion);
                    writer.WriteLine("    void                mono_dl_register_symbol (const char* name, void *addr);");
                    writer.WriteLine("#if !defined(__arm64__)");
                    writer.WriteLine("    extern int          mono_ficall_flag;");
                    writer.WriteLine("#endif");
                }
                writer.WriteLine("    void                mono_aot_register_module(gpointer *aot_info);");
                writer.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2");
                writer.WriteLine("#define DLL_EXPORT __declspec(dllexport)");
                writer.WriteLine("#else");
                writer.WriteLine("#define DLL_EXPORT");
                writer.WriteLine("#endif");
                writer.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
                writer.WriteLine("    extern gboolean     mono_aot_only;");
                for (int i = 0; i < assemblyFileNames.Length; i++)
                {
                    string str4 = assemblyFileNames[i];
                    string str5 = assemblyDefinitions[i].Name.Name.Replace(".", "_").Replace("-", "_").Replace(" ", "_");
                    writer.WriteLine("    extern gpointer*    mono_aot_module_{0}_info; // {1}", str5, str4);
                }
                writer.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
                IEnumerator enumerator = list.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        string current = (string)enumerator.Current;
                        writer.WriteLine("    DECL_USER_FUNC({0});", current);
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
                writer.WriteLine("}");
                writer.WriteLine("DLL_EXPORT void RegisterMonoModules()");
                writer.WriteLine("{");
                writer.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                writer.WriteLine("    mono_aot_only = true;");
                if (buildTarget == BuildTarget.iOS)
                {
                    writer.WriteLine("    mono_ficall_flag = {0};", !flag ? "false" : "true");
                }
                foreach (AssemblyDefinition definition in assemblyDefinitions)
                {
                    string str7 = definition.Name.Name.Replace(".", "_").Replace("-", "_").Replace(" ", "_");
                    writer.WriteLine("    mono_aot_register_module(mono_aot_module_{0}_info);", str7);
                }
                writer.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                writer.WriteLine("");
                if (buildTarget == BuildTarget.iOS)
                {
                    IEnumerator enumerator2 = list.GetEnumerator();
                    try
                    {
                        while (enumerator2.MoveNext())
                        {
                            string str8 = (string)enumerator2.Current;
                            writer.WriteLine("    REGISTER_USER_FUNC({0});", str8);
                        }
                    }
                    finally
                    {
                        IDisposable disposable2 = enumerator2 as IDisposable;
                        if (disposable2 != null)
                        {
                            disposable2.Dispose();
                        }
                    }
                }
                writer.WriteLine("}");
                writer.WriteLine("");
                AssemblyDefinition unityEngine = null;
                for (int j = 0; j < assemblyFileNames.Length; j++)
                {
                    if (assemblyFileNames[j] == "UnityEngine.dll")
                    {
                        unityEngine = assemblyDefinitions[j];
                    }
                }
                if (buildTarget == BuildTarget.iOS)
                {
                    AssemblyDefinition[] assemblies = new AssemblyDefinition[] { unityEngine };
                    GenerateRegisterInternalCalls(assemblies, writer);
                    ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry);
                    ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, unityEngine, usedClassRegistry);
                    GenerateRegisterModules(set, set2, writer, stripping);
                    if (stripping && (usedClassRegistry != null))
                    {
                        GenerateRegisterClassesForStripping(set, writer);
                    }
                    else
                    {
                        GenerateRegisterClasses(set, writer);
                    }
                }
                writer.Close();
            }
        }
 private static HashSet<string> CollectManagedTypeReferencesFromRoots(string directory, string[] rootAssemblies)
 {
   HashSet<string> stringSet = new HashSet<string>();
   AssemblyReferenceChecker referenceChecker = new AssemblyReferenceChecker();
   bool withMethods = false;
   bool ignoreSystemDlls = false;
   referenceChecker.CollectReferencesFromRoots(directory, (IEnumerable<string>) rootAssemblies, withMethods, 0.0f, ignoreSystemDlls);
   string[] assemblyFileNames = referenceChecker.GetAssemblyFileNames();
   AssemblyDefinition[] assemblyDefinitions = referenceChecker.GetAssemblyDefinitions();
   foreach (AssemblyDefinition assemblyDefinition in assemblyDefinitions)
   {
     using (Collection<TypeDefinition>.Enumerator enumerator = assemblyDefinition.get_MainModule().get_Types().GetEnumerator())
     {
       // ISSUE: explicit reference operation
       while (((Collection<TypeDefinition>.Enumerator) @enumerator).MoveNext())
       {
         // ISSUE: explicit reference operation
         TypeDefinition current = ((Collection<TypeDefinition>.Enumerator) @enumerator).get_Current();
         if (((TypeReference) current).get_Namespace().StartsWith("UnityEngine") && (current.get_Fields().get_Count() > 0 || current.get_Methods().get_Count() > 0 || current.get_Properties().get_Count() > 0))
         {
           string name = ((TypeReference) current).get_Name();
           stringSet.Add(name);
         }
       }
     }
   }
   AssemblyDefinition assemblyDefinition1 = (AssemblyDefinition) null;
   for (int index = 0; index < assemblyFileNames.Length; ++index)
   {
     if (assemblyFileNames[index] == "UnityEngine.dll")
       assemblyDefinition1 = assemblyDefinitions[index];
   }
   foreach (AssemblyDefinition assemblyDefinition2 in assemblyDefinitions)
   {
     if (assemblyDefinition2 != assemblyDefinition1)
     {
       using (IEnumerator<TypeReference> enumerator = assemblyDefinition2.get_MainModule().GetTypeReferences().GetEnumerator())
       {
         while (((IEnumerator) enumerator).MoveNext())
         {
           TypeReference current = enumerator.Current;
           if (current.get_Namespace().StartsWith("UnityEngine"))
           {
             string name = current.get_Name();
             stringSet.Add(name);
           }
         }
       }
     }
   }
   return stringSet;
 }
Пример #9
0
 public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker)
 {
     using (TextWriter writer = new StreamWriter(file))
     {
         string[]             assemblyFileNames   = checker.GetAssemblyFileNames();
         AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
         bool      flag = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic;
         ArrayList list = BuildNativeMethodList(assemblyDefinitions);
         if (buildTarget == BuildTarget.iOS)
         {
             writer.WriteLine("#include \"RegisterMonoModules.h\"");
             writer.WriteLine("#include <stdio.h>");
         }
         writer.WriteLine(string.Empty);
         writer.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
         writer.WriteLine("\t#define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
         writer.WriteLine("\t#define REGISTER_USER_FUNC(f)\\");
         writer.WriteLine("\t\tdo {\\");
         writer.WriteLine("\t\tif(f != NULL)\\");
         writer.WriteLine("\t\t\tmono_dl_register_symbol(#f, (void*)f);\\");
         writer.WriteLine("\t\telse\\");
         writer.WriteLine("\t\t\t::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
         writer.WriteLine("\t\t}while(0)");
         writer.WriteLine("#else");
         writer.WriteLine("\t#define DECL_USER_FUNC(f) void f() ");
         writer.WriteLine("\t#if !defined(__arm64__)");
         writer.WriteLine("\t#define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
         writer.WriteLine("\t#else");
         writer.WriteLine("\t\t#define REGISTER_USER_FUNC(f)");
         writer.WriteLine("\t#endif");
         writer.WriteLine("#endif");
         writer.WriteLine("extern \"C\"\n{");
         writer.WriteLine("\ttypedef void* gpointer;");
         writer.WriteLine("\ttypedef int gboolean;");
         if (buildTarget == BuildTarget.iOS)
         {
             writer.WriteLine("\tconst char*\t\t\tUnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion);
             writer.WriteLine("\tvoid\t\t\t\tmono_dl_register_symbol (const char* name, void *addr);");
             writer.WriteLine("#if !defined(__arm64__)");
             writer.WriteLine("\textern int\t\t\tmono_ficall_flag;");
             writer.WriteLine("#endif");
         }
         writer.WriteLine("\tvoid\t\t\t\tmono_aot_register_module(gpointer *aot_info);");
         writer.WriteLine("#if !(__ORBIS__)");
         writer.WriteLine("#define DLL_EXPORT");
         writer.WriteLine("#else");
         writer.WriteLine("#define DLL_EXPORT __declspec(dllexport)");
         writer.WriteLine("#endif");
         writer.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
         writer.WriteLine("\textern gboolean\t\tmono_aot_only;");
         for (int i = 0; i < assemblyFileNames.Length; i++)
         {
             string str  = assemblyFileNames[i];
             string str2 = assemblyDefinitions[i].Name.Name.Replace(".", "_").Replace("-", "_").Replace(" ", "_");
             writer.WriteLine("\textern gpointer*\tmono_aot_module_{0}_info; // {1}", str2, str);
         }
         writer.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
         IEnumerator enumerator = list.GetEnumerator();
         try
         {
             while (enumerator.MoveNext())
             {
                 string current = (string)enumerator.Current;
                 writer.WriteLine("\tDECL_USER_FUNC({0});", current);
             }
         }
         finally
         {
             IDisposable disposable = enumerator as IDisposable;
             if (disposable == null)
             {
             }
             disposable.Dispose();
         }
         writer.WriteLine("}");
         writer.WriteLine("DLL_EXPORT void RegisterMonoModules()");
         writer.WriteLine("{");
         writer.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
         writer.WriteLine("\tmono_aot_only = true;");
         if (buildTarget == BuildTarget.iOS)
         {
             writer.WriteLine("\tmono_ficall_flag = {0};", !flag ? "false" : "true");
         }
         foreach (AssemblyDefinition definition in assemblyDefinitions)
         {
             string str4 = definition.Name.Name.Replace(".", "_").Replace("-", "_").Replace(" ", "_");
             writer.WriteLine("\tmono_aot_register_module(mono_aot_module_{0}_info);", str4);
         }
         writer.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
         writer.WriteLine(string.Empty);
         if (buildTarget == BuildTarget.iOS)
         {
             IEnumerator enumerator2 = list.GetEnumerator();
             try
             {
                 while (enumerator2.MoveNext())
                 {
                     string str5 = (string)enumerator2.Current;
                     writer.WriteLine("\tREGISTER_USER_FUNC({0});", str5);
                 }
             }
             finally
             {
                 IDisposable disposable2 = enumerator2 as IDisposable;
                 if (disposable2 == null)
                 {
                 }
                 disposable2.Dispose();
             }
         }
         writer.WriteLine("}");
         writer.WriteLine(string.Empty);
         AssemblyDefinition unityEngine = null;
         for (int j = 0; j < assemblyFileNames.Length; j++)
         {
             if (assemblyFileNames[j] == "UnityEngine.dll")
             {
                 unityEngine = assemblyDefinitions[j];
             }
         }
         if (buildTarget == BuildTarget.iOS)
         {
             AssemblyDefinition[] assemblies = new AssemblyDefinition[] { unityEngine };
             GenerateRegisterInternalCalls(assemblies, writer);
             ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry);
             ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, unityEngine, usedClassRegistry);
             GenerateRegisterModules(usedClassRegistry, writer, stripping);
             if (stripping && (usedClassRegistry != null))
             {
                 GenerateRegisterClassesForStripping(usedClassRegistry, writer);
             }
             else
             {
                 GenerateRegisterClasses(usedClassRegistry, writer);
             }
         }
         writer.Close();
     }
 }
 public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker)
 {
     using (TextWriter output = (TextWriter) new StreamWriter(file))
     {
         string[]             assemblyFileNames   = checker.GetAssemblyFileNames();
         AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
         bool      flag      = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic;
         ArrayList arrayList = MonoAOTRegistration.BuildNativeMethodList(assemblyDefinitions);
         if (buildTarget == BuildTarget.iOS)
         {
             output.WriteLine("#include \"RegisterMonoModules.h\"");
             output.WriteLine("#include <stdio.h>");
         }
         output.WriteLine(string.Empty);
         output.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
         output.WriteLine("    #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
         output.WriteLine("    #define REGISTER_USER_FUNC(f)\\");
         output.WriteLine("        do {\\");
         output.WriteLine("        if(f != NULL)\\");
         output.WriteLine("            mono_dl_register_symbol(#f, (void*)f);\\");
         output.WriteLine("        else\\");
         output.WriteLine("            ::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
         output.WriteLine("        }while(0)");
         output.WriteLine("#else");
         output.WriteLine("    #define DECL_USER_FUNC(f) void f() ");
         output.WriteLine("    #if !defined(__arm64__)");
         output.WriteLine("    #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
         output.WriteLine("    #else");
         output.WriteLine("        #define REGISTER_USER_FUNC(f)");
         output.WriteLine("    #endif");
         output.WriteLine("#endif");
         output.WriteLine("extern \"C\"\n{");
         output.WriteLine("    typedef void* gpointer;");
         output.WriteLine("    typedef int gboolean;");
         if (buildTarget == BuildTarget.iOS)
         {
             output.WriteLine("    const char*         UnityIPhoneRuntimeVersion = \"{0}\";", (object)Application.unityVersion);
             output.WriteLine("    void                mono_dl_register_symbol (const char* name, void *addr);");
             output.WriteLine("#if !defined(__arm64__)");
             output.WriteLine("    extern int          mono_ficall_flag;");
             output.WriteLine("#endif");
         }
         output.WriteLine("    void                mono_aot_register_module(gpointer *aot_info);");
         output.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2");
         output.WriteLine("#define DLL_EXPORT __declspec(dllexport)");
         output.WriteLine("#else");
         output.WriteLine("#define DLL_EXPORT");
         output.WriteLine("#endif");
         output.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
         output.WriteLine("    extern gboolean     mono_aot_only;");
         for (int index = 0; index < assemblyFileNames.Length; ++index)
         {
             string str1 = assemblyFileNames[index];
             string str2 = ((AssemblyNameReference)assemblyDefinitions[index].get_Name()).get_Name().Replace(".", "_").Replace("-", "_").Replace(" ", "_");
             output.WriteLine("    extern gpointer*    mono_aot_module_{0}_info; // {1}", (object)str2, (object)str1);
         }
         output.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
         foreach (string str in arrayList)
         {
             output.WriteLine("    DECL_USER_FUNC({0});", (object)str);
         }
         output.WriteLine("}");
         output.WriteLine("DLL_EXPORT void RegisterMonoModules()");
         output.WriteLine("{");
         output.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
         output.WriteLine("    mono_aot_only = true;");
         if (buildTarget == BuildTarget.iOS)
         {
             output.WriteLine("    mono_ficall_flag = {0};", !flag ? (object)"false" : (object)"true");
         }
         foreach (AssemblyDefinition assemblyDefinition in assemblyDefinitions)
         {
             string str = ((AssemblyNameReference)assemblyDefinition.get_Name()).get_Name().Replace(".", "_").Replace("-", "_").Replace(" ", "_");
             output.WriteLine("    mono_aot_register_module(mono_aot_module_{0}_info);", (object)str);
         }
         output.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
         output.WriteLine(string.Empty);
         if (buildTarget == BuildTarget.iOS)
         {
             foreach (string str in arrayList)
             {
                 output.WriteLine("    REGISTER_USER_FUNC({0});", (object)str);
             }
         }
         output.WriteLine("}");
         output.WriteLine(string.Empty);
         AssemblyDefinition unityEngine = (AssemblyDefinition)null;
         for (int index = 0; index < assemblyFileNames.Length; ++index)
         {
             if (assemblyFileNames[index] == "UnityEngine.dll")
             {
                 unityEngine = assemblyDefinitions[index];
             }
         }
         if (buildTarget == BuildTarget.iOS)
         {
             AssemblyDefinition[] assemblies = new AssemblyDefinition[1] {
                 unityEngine
             };
             MonoAOTRegistration.GenerateRegisterInternalCalls(assemblies, output);
             MonoAOTRegistration.ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry);
             MonoAOTRegistration.ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, unityEngine, usedClassRegistry);
             MonoAOTRegistration.GenerateRegisterModules(usedClassRegistry, output, stripping);
             if (stripping && usedClassRegistry != null)
             {
                 MonoAOTRegistration.GenerateRegisterClassesForStripping(usedClassRegistry, output);
             }
             else
             {
                 MonoAOTRegistration.GenerateRegisterClasses(usedClassRegistry, output);
             }
         }
         output.Close();
     }
 }
Пример #11
0
        public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker, string stagingAreaDataManaged, IIl2CppPlatformProvider platformProvider)
        {
            string text = Path.Combine(stagingAreaDataManaged, "ICallSummary.txt");
            string exe  = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe");
            string args = string.Format("-assembly=\"{0}\" -summary=\"{1}\"", Path.Combine(stagingAreaDataManaged, "UnityEngine.dll"), text);

            Runner.RunManagedProgram(exe, args);
            HashSet <UnityType> hashSet;
            HashSet <string>    nativeModules;

            CodeStrippingUtils.GenerateDependencies(Path.GetDirectoryName(stagingAreaDataManaged), text, usedClassRegistry, stripping, out hashSet, out nativeModules, platformProvider);
            using (TextWriter textWriter = new StreamWriter(file))
            {
                string[]             assemblyFileNames   = checker.GetAssemblyFileNames();
                AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
                bool      flag      = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic;
                ArrayList arrayList = MonoAOTRegistration.BuildNativeMethodList(assemblyDefinitions);
                if (buildTarget == BuildTarget.iOS)
                {
                    textWriter.WriteLine("#include \"RegisterMonoModules.h\"");
                    textWriter.WriteLine("#include <stdio.h>");
                }
                textWriter.WriteLine("");
                textWriter.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
                textWriter.WriteLine("    #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
                textWriter.WriteLine("    #define REGISTER_USER_FUNC(f)\\");
                textWriter.WriteLine("        do {\\");
                textWriter.WriteLine("        if(f != NULL)\\");
                textWriter.WriteLine("            mono_dl_register_symbol(#f, (void*)f);\\");
                textWriter.WriteLine("        else\\");
                textWriter.WriteLine("            ::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
                textWriter.WriteLine("        }while(0)");
                textWriter.WriteLine("#else");
                textWriter.WriteLine("    #define DECL_USER_FUNC(f) void f() ");
                textWriter.WriteLine("    #if !defined(__arm64__)");
                textWriter.WriteLine("    #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
                textWriter.WriteLine("    #else");
                textWriter.WriteLine("        #define REGISTER_USER_FUNC(f)");
                textWriter.WriteLine("    #endif");
                textWriter.WriteLine("#endif");
                textWriter.WriteLine("extern \"C\"\n{");
                textWriter.WriteLine("    typedef void* gpointer;");
                textWriter.WriteLine("    typedef int gboolean;");
                if (buildTarget == BuildTarget.iOS)
                {
                    textWriter.WriteLine("    const char*         UnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion);
                    textWriter.WriteLine("    void                mono_dl_register_symbol (const char* name, void *addr);");
                    textWriter.WriteLine("#if !defined(__arm64__)");
                    textWriter.WriteLine("    extern int          mono_ficall_flag;");
                    textWriter.WriteLine("#endif");
                }
                textWriter.WriteLine("    void                mono_aot_register_module(gpointer *aot_info);");
                textWriter.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2");
                textWriter.WriteLine("#define DLL_EXPORT __declspec(dllexport)");
                textWriter.WriteLine("#else");
                textWriter.WriteLine("#define DLL_EXPORT");
                textWriter.WriteLine("#endif");
                textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
                textWriter.WriteLine("    extern gboolean     mono_aot_only;");
                for (int i = 0; i < assemblyFileNames.Length; i++)
                {
                    string arg   = assemblyFileNames[i];
                    string text2 = assemblyDefinitions[i].Name.Name;
                    text2 = text2.Replace(".", "_");
                    text2 = text2.Replace("-", "_");
                    text2 = text2.Replace(" ", "_");
                    textWriter.WriteLine("    extern gpointer*    mono_aot_module_{0}_info; // {1}", text2, arg);
                }
                textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
                IEnumerator enumerator = arrayList.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        string arg2 = (string)enumerator.Current;
                        textWriter.WriteLine("    DECL_USER_FUNC({0});", arg2);
                    }
                }
                finally
                {
                    IDisposable disposable;
                    if ((disposable = (enumerator as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
                textWriter.WriteLine("}");
                textWriter.WriteLine("DLL_EXPORT void RegisterMonoModules()");
                textWriter.WriteLine("{");
                textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                textWriter.WriteLine("    mono_aot_only = true;");
                if (buildTarget == BuildTarget.iOS)
                {
                    textWriter.WriteLine("    mono_ficall_flag = {0};", (!flag) ? "false" : "true");
                }
                AssemblyDefinition[] array = assemblyDefinitions;
                for (int j = 0; j < array.Length; j++)
                {
                    AssemblyDefinition assemblyDefinition = array[j];
                    string             text3 = assemblyDefinition.Name.Name;
                    text3 = text3.Replace(".", "_");
                    text3 = text3.Replace("-", "_");
                    text3 = text3.Replace(" ", "_");
                    textWriter.WriteLine("    mono_aot_register_module(mono_aot_module_{0}_info);", text3);
                }
                textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                textWriter.WriteLine("");
                if (buildTarget == BuildTarget.iOS)
                {
                    IEnumerator enumerator2 = arrayList.GetEnumerator();
                    try
                    {
                        while (enumerator2.MoveNext())
                        {
                            string arg3 = (string)enumerator2.Current;
                            textWriter.WriteLine("    REGISTER_USER_FUNC({0});", arg3);
                        }
                    }
                    finally
                    {
                        IDisposable disposable2;
                        if ((disposable2 = (enumerator2 as IDisposable)) != null)
                        {
                            disposable2.Dispose();
                        }
                    }
                }
                textWriter.WriteLine("}");
                textWriter.WriteLine("");
                AssemblyDefinition assemblyDefinition2 = null;
                for (int k = 0; k < assemblyFileNames.Length; k++)
                {
                    if (assemblyFileNames[k] == "UnityEngine.dll")
                    {
                        assemblyDefinition2 = assemblyDefinitions[k];
                    }
                }
                if (buildTarget == BuildTarget.iOS)
                {
                    AssemblyDefinition[] assemblies = new AssemblyDefinition[]
                    {
                        assemblyDefinition2
                    };
                    MonoAOTRegistration.GenerateRegisterInternalCalls(assemblies, textWriter);
                    MonoAOTRegistration.GenerateRegisterModules(hashSet, nativeModules, textWriter, stripping);
                    if (stripping && usedClassRegistry != null)
                    {
                        MonoAOTRegistration.GenerateRegisterClassesForStripping(hashSet, textWriter);
                    }
                    else
                    {
                        MonoAOTRegistration.GenerateRegisterClasses(hashSet, textWriter);
                    }
                }
                textWriter.Close();
            }
        }
        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);
        }
 public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker, string stagingAreaDataManaged)
 {
     HashSet<UnityType> set;
     HashSet<string> set2;
     string str = Path.Combine(stagingAreaDataManaged, "ICallSummary.txt");
     string exe = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe");
     string args = string.Format("-assembly=\"{0}\" -summary=\"{1}\"", Path.Combine(stagingAreaDataManaged, "UnityEngine.dll"), str);
     Runner.RunManagedProgram(exe, args);
     CodeStrippingUtils.GenerateDependencies(Path.GetDirectoryName(stagingAreaDataManaged), str, usedClassRegistry, stripping, out set, out set2, null);
     using (TextWriter writer = new StreamWriter(file))
     {
         string[] assemblyFileNames = checker.GetAssemblyFileNames();
         AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
         bool flag = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic;
         ArrayList list = BuildNativeMethodList(assemblyDefinitions);
         if (buildTarget == BuildTarget.iOS)
         {
             writer.WriteLine("#include \"RegisterMonoModules.h\"");
             writer.WriteLine("#include <stdio.h>");
         }
         writer.WriteLine("");
         writer.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
         writer.WriteLine("    #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
         writer.WriteLine(@"    #define REGISTER_USER_FUNC(f)\");
         writer.WriteLine(@"        do {\");
         writer.WriteLine(@"        if(f != NULL)\");
         writer.WriteLine(@"            mono_dl_register_symbol(#f, (void*)f);\");
         writer.WriteLine(@"        else\");
         writer.WriteLine("            ::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
         writer.WriteLine("        }while(0)");
         writer.WriteLine("#else");
         writer.WriteLine("    #define DECL_USER_FUNC(f) void f() ");
         writer.WriteLine("    #if !defined(__arm64__)");
         writer.WriteLine("    #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
         writer.WriteLine("    #else");
         writer.WriteLine("        #define REGISTER_USER_FUNC(f)");
         writer.WriteLine("    #endif");
         writer.WriteLine("#endif");
         writer.WriteLine("extern \"C\"\n{");
         writer.WriteLine("    typedef void* gpointer;");
         writer.WriteLine("    typedef int gboolean;");
         if (buildTarget == BuildTarget.iOS)
         {
             writer.WriteLine("    const char*         UnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion);
             writer.WriteLine("    void                mono_dl_register_symbol (const char* name, void *addr);");
             writer.WriteLine("#if !defined(__arm64__)");
             writer.WriteLine("    extern int          mono_ficall_flag;");
             writer.WriteLine("#endif");
         }
         writer.WriteLine("    void                mono_aot_register_module(gpointer *aot_info);");
         writer.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2");
         writer.WriteLine("#define DLL_EXPORT __declspec(dllexport)");
         writer.WriteLine("#else");
         writer.WriteLine("#define DLL_EXPORT");
         writer.WriteLine("#endif");
         writer.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
         writer.WriteLine("    extern gboolean     mono_aot_only;");
         for (int i = 0; i < assemblyFileNames.Length; i++)
         {
             string str4 = assemblyFileNames[i];
             string str5 = assemblyDefinitions[i].Name.Name.Replace(".", "_").Replace("-", "_").Replace(" ", "_");
             writer.WriteLine("    extern gpointer*    mono_aot_module_{0}_info; // {1}", str5, str4);
         }
         writer.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
         IEnumerator enumerator = list.GetEnumerator();
         try
         {
             while (enumerator.MoveNext())
             {
                 string current = (string) enumerator.Current;
                 writer.WriteLine("    DECL_USER_FUNC({0});", current);
             }
         }
         finally
         {
             IDisposable disposable = enumerator as IDisposable;
             if (disposable != null)
             {
                 disposable.Dispose();
             }
         }
         writer.WriteLine("}");
         writer.WriteLine("DLL_EXPORT void RegisterMonoModules()");
         writer.WriteLine("{");
         writer.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
         writer.WriteLine("    mono_aot_only = true;");
         if (buildTarget == BuildTarget.iOS)
         {
             writer.WriteLine("    mono_ficall_flag = {0};", !flag ? "false" : "true");
         }
         foreach (AssemblyDefinition definition in assemblyDefinitions)
         {
             string str7 = definition.Name.Name.Replace(".", "_").Replace("-", "_").Replace(" ", "_");
             writer.WriteLine("    mono_aot_register_module(mono_aot_module_{0}_info);", str7);
         }
         writer.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
         writer.WriteLine("");
         if (buildTarget == BuildTarget.iOS)
         {
             IEnumerator enumerator2 = list.GetEnumerator();
             try
             {
                 while (enumerator2.MoveNext())
                 {
                     string str8 = (string) enumerator2.Current;
                     writer.WriteLine("    REGISTER_USER_FUNC({0});", str8);
                 }
             }
             finally
             {
                 IDisposable disposable2 = enumerator2 as IDisposable;
                 if (disposable2 != null)
                 {
                     disposable2.Dispose();
                 }
             }
         }
         writer.WriteLine("}");
         writer.WriteLine("");
         AssemblyDefinition unityEngine = null;
         for (int j = 0; j < assemblyFileNames.Length; j++)
         {
             if (assemblyFileNames[j] == "UnityEngine.dll")
             {
                 unityEngine = assemblyDefinitions[j];
             }
         }
         if (buildTarget == BuildTarget.iOS)
         {
             AssemblyDefinition[] assemblies = new AssemblyDefinition[] { unityEngine };
             GenerateRegisterInternalCalls(assemblies, writer);
             ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry);
             ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, unityEngine, usedClassRegistry);
             GenerateRegisterModules(set, set2, writer, stripping);
             if (stripping && (usedClassRegistry != null))
             {
                 GenerateRegisterClassesForStripping(set, writer);
             }
             else
             {
                 GenerateRegisterClasses(set, writer);
             }
         }
         writer.Close();
     }
 }
		private static HashSet<string> CollectManagedTypeReferencesFromRoots(string directory, string[] rootAssemblies)
		{
			HashSet<string> hashSet = new HashSet<string>();
			AssemblyReferenceChecker assemblyReferenceChecker = new AssemblyReferenceChecker();
			bool withMethods = false;
			bool ignoreSystemDlls = false;
			assemblyReferenceChecker.CollectReferencesFromRoots(directory, rootAssemblies, withMethods, 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") && (current.Fields.Count > 0 || current.Methods.Count > 0 || current.Properties.Count > 0))
					{
						string name = current.Name;
						hashSet.Add(name);
					}
				}
			}
			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.MainModule.GetTypeReferences())
					{
						if (current2.Namespace.StartsWith("UnityEngine"))
						{
							string name2 = current2.Name;
							hashSet.Add(name2);
						}
					}
				}
			}
			return hashSet;
		}
        static public void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file,
                                                                            CrossCompileOptions crossCompileOptions,
                                                                            bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry,
                                                                            AssemblyReferenceChecker checker, string stagingAreaDataManaged, IIl2CppPlatformProvider platformProvider)
        {
            // generate the Interal Call Summary file
            var icallSummaryPath = Path.Combine(stagingAreaDataManaged, "ICallSummary.txt");
            var dlls             = Directory.GetFiles(stagingAreaDataManaged, "UnityEngine.*Module.dll").Concat(new[] { Path.Combine(stagingAreaDataManaged, "UnityEngine.dll") });
            var exe  = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe");
            var args = string.Format("-assembly=\"{0}\" -summary=\"{1}\"",
                                     dlls.Aggregate((dllArg, next) => dllArg + ";" + next), icallSummaryPath
                                     );

            Runner.RunManagedProgram(exe, args);

            HashSet <UnityType> nativeClasses;
            HashSet <string>    nativeModules;

            CodeStrippingUtils.GenerateDependencies(Path.GetDirectoryName(stagingAreaDataManaged), icallSummaryPath, usedClassRegistry, stripping, out nativeClasses, out nativeModules, platformProvider);

            using (TextWriter w = new StreamWriter(file))
            {
                string[]             fileNames  = checker.GetAssemblyFileNames();
                AssemblyDefinition[] assemblies = checker.GetAssemblyDefinitions();

                bool fastICall = (crossCompileOptions & CrossCompileOptions.FastICall) != 0;

                ArrayList nativeMethods = BuildNativeMethodList(assemblies);

                if (buildTarget == BuildTarget.iOS)
                {
                    w.WriteLine("#include \"RegisterMonoModules.h\"");
                    w.WriteLine("#include <stdio.h>");
                }

                w.WriteLine("");
                w.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
                w.WriteLine("    #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
                w.WriteLine("    #define REGISTER_USER_FUNC(f)\\");
                w.WriteLine("        do {\\");
                w.WriteLine("        if(f != NULL)\\");
                w.WriteLine("            mono_dl_register_symbol(#f, (void*)f);\\");
                w.WriteLine("        else\\");
                w.WriteLine("            ::printf_console(\"Symbol \'%s\' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
                w.WriteLine("        }while(0)");
                w.WriteLine("#else");
                w.WriteLine("    #define DECL_USER_FUNC(f) void f() ");
                w.WriteLine("    #if !defined(__arm64__)");
                w.WriteLine("    #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
                w.WriteLine("    #else");
                w.WriteLine("        #define REGISTER_USER_FUNC(f)");
                w.WriteLine("    #endif");
                w.WriteLine("#endif");
                w.WriteLine("extern \"C\"\n{");

                w.WriteLine("    typedef void* gpointer;");
                w.WriteLine("    typedef int gboolean;");

                if (buildTarget == BuildTarget.iOS)
                {
                    w.WriteLine("    const char*         UnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion);
                    w.WriteLine("    void                mono_dl_register_symbol (const char* name, void *addr);");

                    w.WriteLine("#if !defined(__arm64__)");
                    w.WriteLine("    extern int          mono_ficall_flag;");
                    w.WriteLine("#endif");
                }

                w.WriteLine("    void                mono_aot_register_module(gpointer *aot_info);");

                w.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2");
                w.WriteLine("#define DLL_EXPORT __declspec(dllexport)"); // ps4 and psp2 need dllexport.
                w.WriteLine("#else");
                w.WriteLine("#define DLL_EXPORT");
                w.WriteLine("#endif");

                w.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
                w.WriteLine("    extern gboolean     mono_aot_only;");

                for (int q = 0; q < fileNames.Length; ++q)
                {
                    string fileName     = fileNames[q];
                    string assemblyName = assemblies[q].Name.Name;
                    assemblyName = assemblyName.Replace(".", "_");
                    assemblyName = assemblyName.Replace("-", "_");
                    assemblyName = assemblyName.Replace(" ", "_");

                    w.WriteLine("    extern gpointer*    mono_aot_module_{0}_info; // {1}", assemblyName, fileName);
                }
                w.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
                foreach (string nmethod in nativeMethods)
                {
                    w.WriteLine("    DECL_USER_FUNC({0});", nmethod);
                }
                w.WriteLine("}");

                w.WriteLine("DLL_EXPORT void RegisterMonoModules()");
                w.WriteLine("{");

                w.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                w.WriteLine("    mono_aot_only = true;");

                if (buildTarget == BuildTarget.iOS)
                {
                    w.WriteLine("    mono_ficall_flag = {0};", fastICall ? "true" : "false");
                }

                foreach (AssemblyDefinition definition in assemblies)
                {
                    string assemblyName = definition.Name.Name;
                    assemblyName = assemblyName.Replace(".", "_");
                    assemblyName = assemblyName.Replace("-", "_");
                    assemblyName = assemblyName.Replace(" ", "_");
                    w.WriteLine("    mono_aot_register_module(mono_aot_module_{0}_info);", assemblyName);
                }

                w.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                w.WriteLine("");

                if (buildTarget == BuildTarget.iOS)
                {
                    foreach (string nmethod in nativeMethods)
                    {
                        w.WriteLine("    REGISTER_USER_FUNC({0});", nmethod);
                    }
                }
                w.WriteLine("}");
                w.WriteLine("");


                if (buildTarget == BuildTarget.iOS)
                {
                    var inputAssemblies = new List <AssemblyDefinition>();

                    for (int i = 0; i < assemblies.Length; i++)
                    {
                        if (AssemblyHelper.IsUnityEngineModule(assemblies[i]))
                        {
                            inputAssemblies.Add(assemblies[i]);
                        }
                    }

                    GenerateRegisterInternalCalls(inputAssemblies.ToArray(), w);

                    GenerateRegisterModules(nativeClasses, nativeModules, w, stripping);

                    if (stripping && usedClassRegistry != null)
                    {
                        GenerateRegisterClassesForStripping(nativeClasses, w);
                    }
                    else
                    {
                        GenerateRegisterClasses(nativeClasses, w);
                    }
                }

                w.Close();
            }
        }
Пример #16
0
 public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker)
 {
     using (TextWriter textWriter = new StreamWriter(file))
     {
         string[]             assemblyFileNames   = checker.GetAssemblyFileNames();
         AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
         bool      flag      = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic;
         ArrayList arrayList = MonoAOTRegistration.BuildNativeMethodList(assemblyDefinitions);
         if (buildTarget == BuildTarget.iOS)
         {
             textWriter.WriteLine("#include \"RegisterMonoModules.h\"");
             textWriter.WriteLine("#include <stdio.h>");
         }
         textWriter.WriteLine(string.Empty);
         textWriter.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
         textWriter.WriteLine("\t#define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
         textWriter.WriteLine("\t#define REGISTER_USER_FUNC(f)\\");
         textWriter.WriteLine("\t\tdo {\\");
         textWriter.WriteLine("\t\tif(f != NULL)\\");
         textWriter.WriteLine("\t\t\tmono_dl_register_symbol(#f, (void*)f);\\");
         textWriter.WriteLine("\t\telse\\");
         textWriter.WriteLine("\t\t\t::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
         textWriter.WriteLine("\t\t}while(0)");
         textWriter.WriteLine("#else");
         textWriter.WriteLine("\t#define DECL_USER_FUNC(f) void f() ");
         textWriter.WriteLine("\t#if !defined(__arm64__)");
         textWriter.WriteLine("\t#define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
         textWriter.WriteLine("\t#else");
         textWriter.WriteLine("\t\t#define REGISTER_USER_FUNC(f)");
         textWriter.WriteLine("\t#endif");
         textWriter.WriteLine("#endif");
         textWriter.WriteLine("extern \"C\"\n{");
         textWriter.WriteLine("\ttypedef void* gpointer;");
         textWriter.WriteLine("\ttypedef int gboolean;");
         if (buildTarget == BuildTarget.iOS)
         {
             textWriter.WriteLine("\tconst char*\t\t\tUnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion);
             textWriter.WriteLine("\tvoid\t\t\t\tmono_dl_register_symbol (const char* name, void *addr);");
             textWriter.WriteLine("#if !defined(__arm64__)");
             textWriter.WriteLine("\textern int\t\t\tmono_ficall_flag;");
             textWriter.WriteLine("#endif");
         }
         textWriter.WriteLine("\tvoid\t\t\t\tmono_aot_register_module(gpointer *aot_info);");
         textWriter.WriteLine("#if !(__ORBIS__)");
         textWriter.WriteLine("#define DLL_EXPORT");
         textWriter.WriteLine("#else");
         textWriter.WriteLine("#define DLL_EXPORT __declspec(dllexport)");
         textWriter.WriteLine("#endif");
         textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
         textWriter.WriteLine("\textern gboolean\t\tmono_aot_only;");
         for (int i = 0; i < assemblyFileNames.Length; i++)
         {
             string arg  = assemblyFileNames[i];
             string text = assemblyDefinitions[i].Name.Name;
             text = text.Replace(".", "_");
             text = text.Replace("-", "_");
             text = text.Replace(" ", "_");
             textWriter.WriteLine("\textern gpointer*\tmono_aot_module_{0}_info; // {1}", text, arg);
         }
         textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
         foreach (string arg2 in arrayList)
         {
             textWriter.WriteLine("\tDECL_USER_FUNC({0});", arg2);
         }
         textWriter.WriteLine("}");
         textWriter.WriteLine("DLL_EXPORT void RegisterMonoModules()");
         textWriter.WriteLine("{");
         textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
         textWriter.WriteLine("\tmono_aot_only = true;");
         if (buildTarget == BuildTarget.iOS)
         {
             textWriter.WriteLine("\tmono_ficall_flag = {0};", (!flag) ? "false" : "true");
         }
         AssemblyDefinition[] array = assemblyDefinitions;
         for (int j = 0; j < array.Length; j++)
         {
             AssemblyDefinition assemblyDefinition = array[j];
             string             text2 = assemblyDefinition.Name.Name;
             text2 = text2.Replace(".", "_");
             text2 = text2.Replace("-", "_");
             text2 = text2.Replace(" ", "_");
             textWriter.WriteLine("\tmono_aot_register_module(mono_aot_module_{0}_info);", text2);
         }
         textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
         textWriter.WriteLine(string.Empty);
         if (buildTarget == BuildTarget.iOS)
         {
             foreach (string arg3 in arrayList)
             {
                 textWriter.WriteLine("\tREGISTER_USER_FUNC({0});", arg3);
             }
         }
         textWriter.WriteLine("}");
         textWriter.WriteLine(string.Empty);
         AssemblyDefinition assemblyDefinition2 = null;
         for (int k = 0; k < assemblyFileNames.Length; k++)
         {
             if (assemblyFileNames[k] == "UnityEngine.dll")
             {
                 assemblyDefinition2 = assemblyDefinitions[k];
             }
         }
         if (buildTarget == BuildTarget.iOS)
         {
             AssemblyDefinition[] assemblies = new AssemblyDefinition[]
             {
                 assemblyDefinition2
             };
             MonoAOTRegistration.GenerateRegisterInternalCalls(assemblies, textWriter);
             MonoAOTRegistration.ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry);
             MonoAOTRegistration.ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, assemblyDefinition2, usedClassRegistry);
             if (stripping && usedClassRegistry != null)
             {
                 MonoAOTRegistration.GenerateRegisterClassesForStripping(usedClassRegistry, textWriter);
             }
             else
             {
                 MonoAOTRegistration.GenerateRegisterClasses(usedClassRegistry, textWriter);
             }
         }
         textWriter.Close();
     }
 }
 public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker)
 {
   using (TextWriter output = (TextWriter) new StreamWriter(file))
   {
     string[] assemblyFileNames = checker.GetAssemblyFileNames();
     AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
     bool flag = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic;
     ArrayList arrayList = MonoAOTRegistration.BuildNativeMethodList(assemblyDefinitions);
     if (buildTarget == BuildTarget.iOS)
     {
       output.WriteLine("#include \"RegisterMonoModules.h\"");
       output.WriteLine("#include <stdio.h>");
     }
     output.WriteLine(string.Empty);
     output.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
     output.WriteLine("    #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
     output.WriteLine("    #define REGISTER_USER_FUNC(f)\\");
     output.WriteLine("        do {\\");
     output.WriteLine("        if(f != NULL)\\");
     output.WriteLine("            mono_dl_register_symbol(#f, (void*)f);\\");
     output.WriteLine("        else\\");
     output.WriteLine("            ::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
     output.WriteLine("        }while(0)");
     output.WriteLine("#else");
     output.WriteLine("    #define DECL_USER_FUNC(f) void f() ");
     output.WriteLine("    #if !defined(__arm64__)");
     output.WriteLine("    #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
     output.WriteLine("    #else");
     output.WriteLine("        #define REGISTER_USER_FUNC(f)");
     output.WriteLine("    #endif");
     output.WriteLine("#endif");
     output.WriteLine("extern \"C\"\n{");
     output.WriteLine("    typedef void* gpointer;");
     output.WriteLine("    typedef int gboolean;");
     if (buildTarget == BuildTarget.iOS)
     {
       output.WriteLine("    const char*         UnityIPhoneRuntimeVersion = \"{0}\";", (object) Application.unityVersion);
       output.WriteLine("    void                mono_dl_register_symbol (const char* name, void *addr);");
       output.WriteLine("#if !defined(__arm64__)");
       output.WriteLine("    extern int          mono_ficall_flag;");
       output.WriteLine("#endif");
     }
     output.WriteLine("    void                mono_aot_register_module(gpointer *aot_info);");
     output.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2");
     output.WriteLine("#define DLL_EXPORT __declspec(dllexport)");
     output.WriteLine("#else");
     output.WriteLine("#define DLL_EXPORT");
     output.WriteLine("#endif");
     output.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
     output.WriteLine("    extern gboolean     mono_aot_only;");
     for (int index = 0; index < assemblyFileNames.Length; ++index)
     {
       string str1 = assemblyFileNames[index];
       string str2 = ((AssemblyNameReference) assemblyDefinitions[index].get_Name()).get_Name().Replace(".", "_").Replace("-", "_").Replace(" ", "_");
       output.WriteLine("    extern gpointer*    mono_aot_module_{0}_info; // {1}", (object) str2, (object) str1);
     }
     output.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
     foreach (string str in arrayList)
       output.WriteLine("    DECL_USER_FUNC({0});", (object) str);
     output.WriteLine("}");
     output.WriteLine("DLL_EXPORT void RegisterMonoModules()");
     output.WriteLine("{");
     output.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
     output.WriteLine("    mono_aot_only = true;");
     if (buildTarget == BuildTarget.iOS)
       output.WriteLine("    mono_ficall_flag = {0};", !flag ? (object) "false" : (object) "true");
     foreach (AssemblyDefinition assemblyDefinition in assemblyDefinitions)
     {
       string str = ((AssemblyNameReference) assemblyDefinition.get_Name()).get_Name().Replace(".", "_").Replace("-", "_").Replace(" ", "_");
       output.WriteLine("    mono_aot_register_module(mono_aot_module_{0}_info);", (object) str);
     }
     output.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
     output.WriteLine(string.Empty);
     if (buildTarget == BuildTarget.iOS)
     {
       foreach (string str in arrayList)
         output.WriteLine("    REGISTER_USER_FUNC({0});", (object) str);
     }
     output.WriteLine("}");
     output.WriteLine(string.Empty);
     AssemblyDefinition unityEngine = (AssemblyDefinition) null;
     for (int index = 0; index < assemblyFileNames.Length; ++index)
     {
       if (assemblyFileNames[index] == "UnityEngine.dll")
         unityEngine = assemblyDefinitions[index];
     }
     if (buildTarget == BuildTarget.iOS)
     {
       AssemblyDefinition[] assemblies = new AssemblyDefinition[1]{ unityEngine };
       MonoAOTRegistration.GenerateRegisterInternalCalls(assemblies, output);
       MonoAOTRegistration.ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry);
       MonoAOTRegistration.ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, unityEngine, usedClassRegistry);
       MonoAOTRegistration.GenerateRegisterModules(usedClassRegistry, output, stripping);
       if (stripping && usedClassRegistry != null)
         MonoAOTRegistration.GenerateRegisterClassesForStripping(usedClassRegistry, output);
       else
         MonoAOTRegistration.GenerateRegisterClasses(usedClassRegistry, output);
     }
     output.Close();
   }
 }
Пример #18
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);
        }
		public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker)
		{
			using (TextWriter textWriter = new StreamWriter(file))
			{
				string[] assemblyFileNames = checker.GetAssemblyFileNames();
				AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
				bool flag = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic;
				ArrayList arrayList = MonoAOTRegistration.BuildNativeMethodList(assemblyDefinitions);
				if (buildTarget == BuildTarget.iOS)
				{
					textWriter.WriteLine("#include \"RegisterMonoModules.h\"");
					textWriter.WriteLine("#include <stdio.h>");
				}
				textWriter.WriteLine(string.Empty);
				textWriter.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
				textWriter.WriteLine("\t#define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
				textWriter.WriteLine("\t#define REGISTER_USER_FUNC(f)\\");
				textWriter.WriteLine("\t\tdo {\\");
				textWriter.WriteLine("\t\tif(f != NULL)\\");
				textWriter.WriteLine("\t\t\tmono_dl_register_symbol(#f, (void*)f);\\");
				textWriter.WriteLine("\t\telse\\");
				textWriter.WriteLine("\t\t\t::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
				textWriter.WriteLine("\t\t}while(0)");
				textWriter.WriteLine("#else");
				textWriter.WriteLine("\t#define DECL_USER_FUNC(f) void f() ");
				textWriter.WriteLine("\t#if !defined(__arm64__)");
				textWriter.WriteLine("\t#define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
				textWriter.WriteLine("\t#else");
				textWriter.WriteLine("\t\t#define REGISTER_USER_FUNC(f)");
				textWriter.WriteLine("\t#endif");
				textWriter.WriteLine("#endif");
				textWriter.WriteLine("extern \"C\"\n{");
				textWriter.WriteLine("\ttypedef void* gpointer;");
				textWriter.WriteLine("\ttypedef int gboolean;");
				if (buildTarget == BuildTarget.iOS)
				{
					textWriter.WriteLine("\tconst char*\t\t\tUnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion);
					textWriter.WriteLine("\tvoid\t\t\t\tmono_dl_register_symbol (const char* name, void *addr);");
					textWriter.WriteLine("#if !defined(__arm64__)");
					textWriter.WriteLine("\textern int\t\t\tmono_ficall_flag;");
					textWriter.WriteLine("#endif");
				}
				textWriter.WriteLine("\tvoid\t\t\t\tmono_aot_register_module(gpointer *aot_info);");
				textWriter.WriteLine("#if !(__ORBIS__)");
				textWriter.WriteLine("#define DLL_EXPORT");
				textWriter.WriteLine("#else");
				textWriter.WriteLine("#define DLL_EXPORT __declspec(dllexport)");
				textWriter.WriteLine("#endif");
				textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
				textWriter.WriteLine("\textern gboolean\t\tmono_aot_only;");
				for (int i = 0; i < assemblyFileNames.Length; i++)
				{
					string arg = assemblyFileNames[i];
					string text = assemblyDefinitions[i].Name.Name;
					text = text.Replace(".", "_");
					text = text.Replace("-", "_");
					text = text.Replace(" ", "_");
					textWriter.WriteLine("\textern gpointer*\tmono_aot_module_{0}_info; // {1}", text, arg);
				}
				textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
				foreach (string arg2 in arrayList)
				{
					textWriter.WriteLine("\tDECL_USER_FUNC({0});", arg2);
				}
				textWriter.WriteLine("}");
				textWriter.WriteLine("DLL_EXPORT void RegisterMonoModules()");
				textWriter.WriteLine("{");
				textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
				textWriter.WriteLine("\tmono_aot_only = true;");
				if (buildTarget == BuildTarget.iOS)
				{
					textWriter.WriteLine("\tmono_ficall_flag = {0};", (!flag) ? "false" : "true");
				}
				AssemblyDefinition[] array = assemblyDefinitions;
				for (int j = 0; j < array.Length; j++)
				{
					AssemblyDefinition assemblyDefinition = array[j];
					string text2 = assemblyDefinition.Name.Name;
					text2 = text2.Replace(".", "_");
					text2 = text2.Replace("-", "_");
					text2 = text2.Replace(" ", "_");
					textWriter.WriteLine("\tmono_aot_register_module(mono_aot_module_{0}_info);", text2);
				}
				textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
				textWriter.WriteLine(string.Empty);
				if (buildTarget == BuildTarget.iOS)
				{
					foreach (string arg3 in arrayList)
					{
						textWriter.WriteLine("\tREGISTER_USER_FUNC({0});", arg3);
					}
				}
				textWriter.WriteLine("}");
				textWriter.WriteLine(string.Empty);
				AssemblyDefinition assemblyDefinition2 = null;
				for (int k = 0; k < assemblyFileNames.Length; k++)
				{
					if (assemblyFileNames[k] == "UnityEngine.dll")
					{
						assemblyDefinition2 = assemblyDefinitions[k];
					}
				}
				if (buildTarget == BuildTarget.iOS)
				{
					AssemblyDefinition[] assemblies = new AssemblyDefinition[]
					{
						assemblyDefinition2
					};
					MonoAOTRegistration.GenerateRegisterInternalCalls(assemblies, textWriter);
					MonoAOTRegistration.ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry);
					MonoAOTRegistration.ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, assemblyDefinition2, usedClassRegistry);
					if (stripping && usedClassRegistry != null)
					{
						MonoAOTRegistration.GenerateRegisterClassesForStripping(usedClassRegistry, textWriter);
					}
					else
					{
						MonoAOTRegistration.GenerateRegisterClasses(usedClassRegistry, textWriter);
					}
				}
				textWriter.Close();
			}
		}