コード例 #1
0
        /// <inheritdoc />
        public IEnumerator Load()
        {
            // Using PluginCompilerModule.CompiledPlugins we have to be sure that it has been created
            // TODO: Better way to reference cross-module or don't reference it at all.

            Debug.Log("Loading plugin assemblies...");

            foreach (var compiledPlugin in PluginCompilerModule.CompiledPlugins)
            {
                // TODO: Prevent from loading local addons

                Debug.Log($"Loading plugin assembly '{compiledPlugin.AssemblyFile}'");
                LoadPlugin(compiledPlugin.AddonName, compiledPlugin.AssemblyFile);
                yield return(new WaitForEndOfFrame());
            }

            // Load debug assemblies if debugging is enabled
            if (LoaderManager.Instance.IsDebuggingEnabled)
            {
                var localModAssemblies = LocalMods.GetLocalModDebugAssemblies();

                foreach (var debugAssembly in localModAssemblies)
                {
                    Debug.Log($"Loading plugin debug assembly '{debugAssembly}'");

                    var fileName = Path.GetFileNameWithoutExtension(debugAssembly);
                    LoadPlugin(fileName, debugAssembly);
                }
            }

            Debug.Log($"Loaded {_plugins.Count} plugins");
        }
コード例 #2
0
        public IEnumerator Load()
        {
            Debug.Log("Loading custom content bundles...");

            if (!LoaderManager.IsDedicatedServer) // Load from workshop (if not dedicated server)
            {
                foreach (var workshopItemID in WorkshopManager.Instance.SubscribedItems)
                {
                    // TODO: Read XML file and get the real addon name to show

                    if (SteamUGC.GetItemInstallInfo(workshopItemID, out _, out var pchFolder, 1024U, out _))
                    {
                        // TODO: Prevent from loading local addons

                        var modDirectory = pchFolder;
                        yield return(LoadBundleFromModDirectory(modDirectory));
                    }
                }
            }

            foreach (var localModDirectory in LocalMods.GetLocalModDirectories())
            {
                yield return(LoadBundleFromModDirectory(localModDirectory));
            }
        }
コード例 #3
0
        public IEnumerator Load()
        {
            Debug.Log("Loading custom content bundles...");

            foreach (var workshopItemID in WorkshopManager.Instance.SubscribedItems)
            {
                // TODO: Read XML file and get the real addon name to show

                if (SteamUGC.GetItemInstallInfo(workshopItemID, out _, out var pchFolder, 1024U, out _))
                {
                    // TODO: Prevent from loading local addons

                    var modDirectory = pchFolder;
                    yield return(LoadBundleFromModDirectory(modDirectory));
                }
            }

            // Load debug assemblies if debugging is enabled
            if (LoaderManager.Instance.IsDebuggingEnabled)
            {
                var localModDirectories = LocalMods.GetLocalModDirectories();

                foreach (var localModDirectory in localModDirectories)
                {
                    yield return(LoadBundleFromModDirectory(localModDirectory));
                }
            }
        }
コード例 #4
0
        public IEnumerator Load()
        {
            Debug.Log("Loading custom content bundles...");

            if (!LoaderManager.IsDedicatedServer) // Load from workshop (if not dedicated server)
            {
                var query = NetManager.GetLocalAndWorkshopItems(SteamTransport.WorkshopType.Mod).GetAwaiter();

                while (!query.IsCompleted) // This is not how UniTask should be used, but it works for now.
                {
                    yield return(null);
                }

                var result = query.GetResult();

                foreach (var itemWrap in result)
                {
                    var modDirectory = itemWrap.DirectoryPath;
                    yield return(LoadBundleFromModDirectory(modDirectory));
                }
            }

            foreach (var localModDirectory in LocalMods.GetLocalModDirectories())
            {
                yield return(LoadBundleFromModDirectory(localModDirectory));
            }
        }
コード例 #5
0
        private IEnumerator LoadLocalPlugins(PluginCompiler pluginCompiler)
        {
            var localPluginDirectories = LocalMods.GetLocalModDirectories(false, true);

            foreach (var localPluginDirectory in localPluginDirectories)
            {
                try
                {
                    var addonDirectory = localPluginDirectory;

                    var addonName    = "local-" + new DirectoryInfo(localPluginDirectory).Name;
                    var assemblyName =
                        addonName + "-Assembly"; // TODO: Make some shared project for string constants etc.
                    var assemblyFile = "AddonManager/AddonsCache/" + assemblyName + ".dll";

                    if (!Directory.Exists(addonDirectory))
                    {
                        Debug.LogWarning(
                            $"Could not load addon plugin '{addonName}' because directory '{addonDirectory}' does not exist!");
                        continue;
                    }

                    var addonScripts = Directory.GetFiles(addonDirectory, "*.cs", SearchOption.AllDirectories);

                    if (addonScripts.Length == 0)
                    {
                        continue;
                    }

                    if (File.Exists(assemblyFile))
                    {
                        Debug.Log($"Removing old plugin assembly file '{assemblyFile}'");
                        File.Delete(assemblyFile);
                    }

                    pluginCompiler.CompileScripts(addonName, addonDirectory, addonScripts);

                    CompiledPlugins.Add(new AddonPlugin(addonName, assemblyFile));
                }
                catch (Exception ex)
                {
                    Debug.LogError($"Failed to compile plugin from '{localPluginDirectory}'. Exception:\n{ex}");
                }

                yield return(new WaitForEndOfFrame());
            }
        }
コード例 #6
0
        private IEnumerator LoadLocalPlugins(PluginCompiler pluginCompiler)
        {
            var localPluginDirectories = LocalMods.GetLocalModDirectories(false, true);

            foreach (var localPluginDirectory in localPluginDirectories)
            {
                try
                {
                    var addonDirectory = localPluginDirectory;

                    var addonName    = "local-" + new DirectoryInfo(localPluginDirectory).Name;
                    var assemblyName = addonName + "-Assembly"; // TODO: Make some shared project for string constants etc.
                    var assemblyFile = "AddonManager/AddonsCache/" + assemblyName + ".dll";

                    if (!Directory.Exists(addonDirectory))
                    {
                        Debug.LogWarning(
                            $"Could not load addon plugin '{addonName}' because directory '{addonDirectory}' does not exist!");
                        continue;
                    }

                    var addonScripts = Directory.GetFiles(addonDirectory, "*.cs", SearchOption.AllDirectories);

                    // Prevent mods that include the following files from defining duplicate attributes and screwing up compile.
                    // */Properties/*
                    // */bin/*
                    // */obj/*
                    List <string> sourceFilesList = new List <string>(addonScripts);

                    sourceFilesList.RemoveAll(x => x.Contains(Path.DirectorySeparatorChar + "Properties" + Path.DirectorySeparatorChar));
                    sourceFilesList.RemoveAll(x => x.Contains(Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar));
                    sourceFilesList.RemoveAll(x => x.Contains(Path.DirectorySeparatorChar + "obj" + Path.DirectorySeparatorChar));

                    addonScripts = sourceFilesList.ToArray();

                    if (addonScripts.Length == 0)
                    {
                        continue;
                    }

                    if (File.Exists(assemblyFile))
                    {
                        Debug.Log($"Removing old plugin assembly file '{assemblyFile}'");
                        File.Delete(assemblyFile);
                    }

                    pluginCompiler.CompileScripts(addonName, addonDirectory, addonScripts, out var isSuccess);

                    if (isSuccess)
                    {
                        CompiledPlugins.Add(new AddonPlugin(addonName, assemblyFile));
                    }
                    else
                    {
                        throw new Exception(
                                  $"Addon's plugin ('{addonName}') failed to compile. Checks game logs for more info.");
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogError($"Failed to compile plugin from '{localPluginDirectory}'. Exception:\n{ex}");
                }

                yield return(new WaitForEndOfFrame());
            }
        }