コード例 #1
0
        private void RegisterComponentsFromAssemblies()
        {
#if !XB1 // XB1_ALLINONEASSEMBLY
            var execAssembly = Assembly.GetExecutingAssembly();
            var refs         = execAssembly.GetReferencedAssemblies();
#endif // !XB1

            // Prepare final session component lists
            m_componentsToLoad = new HashSet <string>();
            m_componentsToLoad.UnionWith(GameDefinition.SessionComponents.Keys);
            m_componentsToLoad.RemoveWhere(x => SessionComponentDisabled.Contains(x));
            m_componentsToLoad.UnionWith(SessionComponentEnabled);

#if XB1 // XB1_ALLINONEASSEMBLY
            RegisterComponentsFromAssembly(MyAssembly.AllInOneAssembly);
#else // !XB1
            foreach (var assemblyName in refs)
            {
                try
                {
                    // TODO: Re-gig this awful code
                    if (assemblyName.Name.Contains("Sandbox") || assemblyName.Name.Equals("VRage.Game"))
                    {
                        Assembly assembly   = Assembly.Load(assemblyName);
                        object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                        if (attributes.Length > 0)
                        {
                            AssemblyProductAttribute product = attributes[0] as AssemblyProductAttribute;
                            if (product.Product == "Sandbox" || product.Product == "VRage.Game")
                            {
                                RegisterComponentsFromAssembly(assembly);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    MyLog.Default.WriteLine("Error while resolving session components assemblies");
                    MyLog.Default.WriteLine(e.ToString());
                }
            }

            try
            {
                foreach (var assembly in ScriptManager.Scripts.Values)
                {
                    RegisterComponentsFromAssembly(assembly, true);
                }
            }
            catch (Exception e)
            {
                MyLog.Default.WriteLine("Error while loading modded session components");
                MyLog.Default.WriteLine(e.ToString());
            }

            try
            {
                foreach (var plugin in MyPlugins.Plugins)
                {
                    RegisterComponentsFromAssembly(plugin.GetType().Assembly, true);
                }
            }
            catch (Exception e)
            { }

            try { RegisterComponentsFromAssembly(MyPlugins.GameAssembly); }
            catch (Exception e)
            {
                MyLog.Default.WriteLine("Error while resolving session components MOD assemblies");
                MyLog.Default.WriteLine(e.ToString());
            }
            try { RegisterComponentsFromAssembly(MyPlugins.UserAssembly); }
            catch (Exception e)
            {
                MyLog.Default.WriteLine("Error while resolving session components MOD assemblies");
                MyLog.Default.WriteLine(e.ToString());
            }

            RegisterComponentsFromAssembly(execAssembly);
#endif // !XB1
        }
コード例 #2
0
        private void RegisterComponentsFromAssemblies()
        {
            var execAssembly = Assembly.GetExecutingAssembly();
            var refs         = execAssembly.GetReferencedAssemblies();

            // Prepare final session component lists
            Static.m_componentsToLoad = new HashSet <string>();
            m_componentsToLoad.UnionWith(GameDefinition.SessionComponents);
            m_componentsToLoad.RemoveWhere(x => SessionComponentDisabled.Contains(x));
            m_componentsToLoad.UnionWith(SessionComponentEnabled);

            foreach (var assemblyName in refs)
            {
                try
                {
                    //MySandboxGame.Log.WriteLine("a:" + assemblyName.Name);

                    if (assemblyName.Name.Contains("Sandbox") || assemblyName.Name.Equals("VRage.Game"))
                    {
                        //MySandboxGame.Log.WriteLine("b:" + assemblyName.Name);

                        Assembly assembly   = Assembly.Load(assemblyName);
                        object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                        if (attributes.Length > 0)
                        {
                            //MySandboxGame.Log.WriteLine("c:" + assemblyName.Name);

                            AssemblyProductAttribute product = attributes[0] as AssemblyProductAttribute;
                            if (product.Product == "Sandbox" || product.Product == "VRage.Game")
                            {
                                //MySandboxGame.Log.WriteLine("d:" + assemblyName.Name);
                                RegisterComponentsFromAssembly(assembly);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    MyLog.Default.WriteLine("Error while resolving session components assemblies");
                    MyLog.Default.WriteLine(e.ToString());
                }
            }

            try
            {
                foreach (var plugin in MyPlugins.Plugins)
                {
                    RegisterComponentsFromAssembly(plugin.GetType().Assembly, true);
                }
            }
            catch (Exception e)
            { }

            try { RegisterComponentsFromAssembly(MyPlugins.GameAssembly); }
            catch (Exception e)
            {
                MyLog.Default.WriteLine("Error while resolving session components MOD assemblies");
                MyLog.Default.WriteLine(e.ToString());
            }
            try { RegisterComponentsFromAssembly(MyPlugins.UserAssembly); }
            catch (Exception e)
            {
                MyLog.Default.WriteLine("Error while resolving session components MOD assemblies");
                MyLog.Default.WriteLine(e.ToString());
            }

            RegisterComponentsFromAssembly(execAssembly);
        }