Ejemplo n.º 1
0
        public void Awake()
        {
            Instance = this;

            Logger = base.Logger;

            ModManager = new DetourModManager();
            AddHookLogging();

            CheckForIncompatibleAssemblies();

            if (Environment.GetEnvironmentVariable("R2API_DEBUG") == "true")
            {
                EnableDebug();
            }

            var pluginScanner    = new PluginScanner();
            var submoduleHandler = new APISubmoduleHandler(Logger);

            LoadedSubmodules = submoduleHandler.LoadRequested(pluginScanner);
            pluginScanner.ScanPlugins();

            var networkCompatibilityHandler = new NetworkCompatibilityHandler();

            networkCompatibilityHandler.BuildModList();

            On.RoR2.RoR2Application.Awake += CheckIfUsedOnRightGameVersion;

            R2APIContentPackProvider.Init();
        }
Ejemplo n.º 2
0
        public R2API()
        {
            Logger     = base.Logger;
            ModManager = new DetourModManager();
            AddHookLogging();
            CheckForIncompatibleAssemblies();
            CheckR2APIMonomodPatch();

            Environment.SetEnvironmentVariable("MONOMOD_DMD_TYPE", "Cecil");

            On.RoR2.UnitySystemConsoleRedirector.Redirect += orig => { };

            var pluginScanner    = new PluginScanner();
            var submoduleHandler = new APISubmoduleHandler(GameBuild, Logger);

            LoadedSubmodules = submoduleHandler.LoadRequested(pluginScanner);
            pluginScanner.ScanPlugins();

            var networkCompatibilityHandler = new NetworkCompatibilityHandler();

            networkCompatibilityHandler.BuildModList();

            RoR2Application.isModded = true;

            SteamworksClientManager.onLoaded += CheckIfUsedOnRightGameVersion;

            VanillaFixes();
        }
Ejemplo n.º 3
0
        private static IRhetosRuntime CreateRhetosRuntimeInstance(ILogProvider logProvider, string rhetosRuntimePath)
        {
            var assemblyResolver = AssemblyResolver.GetResolveEventHandler(new[] { rhetosRuntimePath }, logProvider, true);

            AppDomain.CurrentDomain.AssemblyResolve += assemblyResolver;

            try
            {
                var pluginScanner      = new PluginScanner(new[] { rhetosRuntimePath }, Path.GetDirectoryName(rhetosRuntimePath), logProvider, new PluginScannerOptions());
                var rhetosRuntimeTypes = pluginScanner.FindPlugins(typeof(IRhetosRuntime)).Select(x => x.Type).ToList();

                if (rhetosRuntimeTypes.Count == 0)
                {
                    throw new FrameworkException($"No implementation of interface {nameof(IRhetosRuntime)} found with Export attribute.");
                }

                if (rhetosRuntimeTypes.Count > 1)
                {
                    throw new FrameworkException($"Found multiple implementation of the type {nameof(IRhetosRuntime)}.");
                }

                var rhetosRuntimeInstance = (IRhetosRuntime)Activator.CreateInstance(rhetosRuntimeTypes.Single());
                return(rhetosRuntimeInstance);
            }
            finally
            {
                AppDomain.CurrentDomain.AssemblyResolve -= assemblyResolver;
            }
        }
Ejemplo n.º 4
0
 internal static IDownlinkBuilder AddLocalPlugins(this IDownlinkBuilder builder, bool forceEnable = false)
 {
     if (forceEnable)
     {
         try
         {
             var scanner = new PluginScanner();
             var root    = new DirectoryInfo(Directory.GetCurrentDirectory());
             var dlls    = root.GetFiles("Downlink.Extensions.*.dll").ToList();
             if (Directory.Exists("Downlink.Extensions"))
             {
                 var extDir = new DirectoryInfo(Path.Combine(root.FullName, "Downlink.Extensions"));
                 dlls.AddRange(extDir.GetFiles("Downlink.Extensions.*.dll", SearchOption.AllDirectories));
             }
             var assemblies = dlls.Select(f => Assembly.LoadFile(f.FullName));
             var modules    = scanner.LoadModulesFromAssemblies(assemblies);
             foreach (var plugin in modules)
             {
                 builder.AddPlugin(plugin);
             }
         }
         catch (System.Exception)
         {
             // ignored
         }
     }
     return(builder);
 }
Ejemplo n.º 5
0
        public void AnalyzeAndReportTypeLoadException()
        {
            var incompatibleAssemblies = new[] { GetIncompatibleAssemblyPath() };
            var pluginsScanner         = new PluginScanner(incompatibleAssemblies, ".", new ConsoleLogProvider(), new PluginScannerOptions());

            TestUtility.ShouldFail <FrameworkException>(
                () => pluginsScanner.FindPlugins(typeof(IGenerator)),
                "Please check if the assembly is missing or has a different version.",
                "'Rhetos.RestGenerator.dll' throws FileNotFoundException: Could not load file or assembly 'Autofac, Version=3.5.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The system cannot find the file specified.");
        }
Ejemplo n.º 6
0
        public MainRequestHandler(ISecurityCheck security)
        {
            _security = security;


            ExternalEndpoint = AnySetting("PrimaryCallbackAddress");

            var settingValid = bool.TryParse(AnySetting("UpgradeHttp"), out var httpUpgradeSetting);

            UpgradeHttp = HttpsAvailable && httpUpgradeSetting && settingValid;

            var timer = new Stopwatch();

            timer.Start();
            _versionTable = new VersionTable <SiteHost>();

            _baseFolder = AppDomain.CurrentDomain.BaseDirectory;
            if (Directory.Exists(AnySetting("HostedSitesRootDirectory")))
            {
                // use directly specified folder
                _watchFolder = AnySetting("HostedSitesRootDirectory");
            }
            else
            {
                // use general working folder (best for Azure?)
                _watchFolder = Path.Combine(_baseFolder, "uploads");
                Directory.CreateDirectory(_watchFolder);
            }

            AvailableAppScanner = new PluginScanner(_watchFolder);
            AvailableAppScanner.PluginsChanged += AvailableAppWatcher_PluginsChanged;

            // Load initial versions out-of-band so we don't appear dead at start-up
            new Thread(() =>
            {
                try
                {
                    _firstScan = true;
                    Trace.TraceInformation("Initial scan started");
                    AvailableAppScanner.RefreshPlugins();
                    Trace.TraceInformation("Initial scan complete");
                }
                finally
                {
                    _firstScan = false;
                    timer.Stop();
                    _warmUp = timer.Elapsed;
                    Console.WriteLine("Ready");
                }
            })
            {
                IsBackground = true
            }.Start();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Called when the application is loaded
        /// </summary>
        /// <param name="sender">Not used.</param>
        /// <param name="e">Not used.</param>
        private void Master_Load(object sender, EventArgs e)
        {
            ConfigController controller = new ConfigController(this);

            controller.LoadAllValues();
            controller.ValidateWoWLocation();
            PluginScanner scanner = new PluginScanner(this);

            scanner.Scan();
            UpdateRealmSelectionToDefault();
        }
Ejemplo n.º 8
0
        private void testSourceButton_Click(object sender, EventArgs e)
        {
            var scan = new PluginScanner(sourceFolderTxt.Text);

            scan.RefreshPlugins();
            var table = new VersionTable <string>();

            sourceTestResult.Text = "Scanning";
            sourceTestResult.Refresh();

            string[] all   = null;
            var      task1 = new Thread(() =>
            {
                all = scan.CurrentlyAvailable.ToArray();
            });

            task1.Start();
            while (task1.IsAlive)
            {
                Application.DoEvents();
            }

            if (!all.Any())
            {
                sourceTestResult.Text = "No binaries found";
                return;
            }

            List <string> versions = null;
            var           task2    = new Thread(() =>
            {
                foreach (var path in all)
                {
                    table.SubmitVersion(path, (typePath, versionName, major) => versionName.Replace("_", "."));
                }

                versions = table.AllVersions().ToList();
            });

            task2.Start();
            while (task2.IsAlive)
            {
                Application.DoEvents();
            }

            if (!versions.Any())
            {
                sourceFolderTxt.Text = "No versioned entry points found";
                return;
            }

            sourceTestResult.Text = "Found: " + string.Join("; ", versions);
        }
        private ContainerBuilder CreateBuildComponentsContainer()
        {
            var pluginScanner = new PluginScanner(
                _pluginAssemblies,
                _configuration.GetOptions <RhetosBuildEnvironment>(),
                _logProvider,
                _configuration.GetOptions <PluginScannerOptions>());

            var builder = RhetosContainerBuilder.Create(_configuration, _logProvider, pluginScanner);

            builder.Register(context => new PluginInfoCollection(pluginScanner.FindAllPlugins()));
            builder.RegisterModule(new CoreModule());
            builder.RegisterModule(new CorePluginsModule());
            builder.RegisterModule(new BuildModule());
            builder.AddRhetosPluginModules();
            builder.RegisterType <NullUserInfo>().As <IUserInfo>(); // Override runtime IUserInfo plugins. This container should not execute the application's business features.
            builder.RegisterInstance(_installedPackages);
            return(builder);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes a container with specified <see cref="IConfiguration"/>.
        /// Registers <see cref="IConfiguration"/> instance to newly created container.
        /// <see cref="ILogProvider"/> is not registered and is meant to be used during the lifetime of registration and container building process.
        /// <see cref="LegacyUtilities"/> will also be initialized with the given configuration.
        /// </summary>
        /// <param name="pluginAssemblies">List of assemblies (DLL file paths) that will be used for plugins search when using the <see cref="ContainerBuilderPluginRegistration"/></param>
        public RhetosContainerBuilder(IConfiguration configuration, ILogProvider logProvider, IEnumerable <string> pluginAssemblies)
        {
            this.RegisterInstance(configuration);

            var pluginScanner = new PluginScanner(
                pluginAssemblies,
                PluginScanner.GetCacheFolder(configuration),
                logProvider,
                configuration.GetOptions <PluginScannerOptions>());

            // make properties accessible to modules which are provided with new/unique instance of ContainerBuilder
            this.Properties.Add(nameof(IPluginScanner), pluginScanner);
            this.Properties.Add(nameof(ILogProvider), logProvider);

            // this is a patch/mock to provide backward compatibility for all usages of old static classes
            LegacyUtilities.Initialize(configuration);

            Plugins.Initialize(builder => builder.GetPluginRegistration());
        }
Ejemplo n.º 11
0
        public void AnalyzeAndReportTypeLoadException()
        {
            // The "TestReference" project is used because it has dependencies to libraries that are not available in the current project.
            string incompatibleAssemblyPath = FindIncompatibleAssemblyPath("Rhetos.Extensibility.TestReference");

            // Copying the "TestReference" assembly to local folder, to avoid automatic detection of dependency libraries that exist in its original location.
            // The goal is to try loading the test assembly without dependencies available.
            CopyAssemblyToLocalFolder(ref incompatibleAssemblyPath);

            // Searching for plugins in the "TestReference" assembly should fail because is references dependency that is not available.
            var pluginsScanner = new PluginScanner(new[] { incompatibleAssemblyPath }, new RhetosBuildEnvironment {
                CacheFolder = "."
            }, new ConsoleLogProvider(), new PluginScannerOptions());

            TestUtility.ShouldFail <FrameworkException>(
                () => pluginsScanner.FindPlugins(typeof(ICloneable)),
                "Please check if the assembly is missing or has a different version.",
                // The error shout report: (1) the assembly that causes the error, and (2) the missing assembly that is required for the first one to load.
                "'Rhetos.Extensibility.TestReference.dll' throws FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.Primitives, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.");
        }
Ejemplo n.º 12
0
        public void Awake()
        {
            Instance = this;

            Logger     = base.Logger;
            ModManager = new DetourModManager();
            AddHookLogging();
            CheckForIncompatibleAssemblies();

            Environment.SetEnvironmentVariable("MONOMOD_DMD_TYPE", "Cecil");

            if (Environment.GetEnvironmentVariable("R2API_DEBUG") == "true")
            {
                EnableDebug();
            }

            On.RoR2.UnitySystemConsoleRedirector.Redirect += orig => { };

            LoadRoR2ContentEarly.Init();

            var pluginScanner    = new PluginScanner();
            var submoduleHandler = new APISubmoduleHandler(GameBuild, Logger);

            LoadedSubmodules = submoduleHandler.LoadRequested(pluginScanner);
            pluginScanner.ScanPlugins();

            var networkCompatibilityHandler = new NetworkCompatibilityHandler();

            networkCompatibilityHandler.BuildModList();

            RoR2Application.isModded = true;

            SteamworksClientManager.onLoaded += CheckIfUsedOnRightGameVersion;

            VanillaFixes();

            R2APIContentPackProvider.Init();
        }
Ejemplo n.º 13
0
        public void Awake()
        {
            Logger     = base.Logger;
            ModManager = new DetourModManager();
            AddHookLogging();
            CheckForIncompatibleAssemblies();
            CheckR2APIPatch();

            Environment.SetEnvironmentVariable("MONOMOD_DMD_TYPE", "Cecil");

            On.RoR2.UnitySystemConsoleRedirector.Redirect += orig => { };

            var pluginScanner    = new PluginScanner();
            var submoduleHandler = new APISubmoduleHandler(GameBuild, Logger);

            LoadedSubmodules = submoduleHandler.LoadRequested(pluginScanner);
            pluginScanner.ScanPlugins();

            var networkCompatibilityHandler = new NetworkCompatibilityHandler();

            networkCompatibilityHandler.BuildModList();

            RoR2Application.isModded = true;

            SteamworksClientManager.onLoaded += CheckIfUsedOnRightGameVersion;

            VanillaFixes();

            // Load RoR2Content early so that modders
            // can take prefabs refs from the fields directly.
            RoR2Content = new RoR2Content();

            // We dont want the game code to remake the RoR2Content instance again
            IL.RoR2.RoR2Application.OnLoad += TakeOurInstanceInstead;

            R2APIContentPackProvider.Init();
        }
        internal PluginManager(PluginScanner <TInput, TOutput> scanner)
        {
            this.scanner = scanner;

            this.plugins = new List <IPlugin <TInput, TOutput> >();
        }