Browse Source

Minor changes to initialization sequence

pull/46/head
Anairkoen Schno 4 years ago
parent
commit
068d7f4775
9 changed files with 77 additions and 58 deletions
  1. +31
    -32
      IPA.Loader/Loader/Composite/CompositeBSPlugin.cs
  2. +17
    -10
      IPA.Loader/Loader/PluginComponent.cs
  3. +2
    -3
      IPA.Loader/Loader/PluginLoader.cs
  4. +8
    -9
      IPA.Loader/Loader/PluginManager.cs
  5. +2
    -2
      IPA.Loader/PluginInterfaces/IPA/IPlugin.cs
  6. +1
    -1
      IPA.Loader/Updating/BeatMods/ApiEndpoint.cs
  7. +1
    -1
      IPA.Loader/Updating/BeatMods/Updater.cs
  8. +14
    -0
      Net3-Proxy/CompilerServices.cs
  9. +1
    -0
      Net3-Proxy/Net3-Proxy.csproj

+ 31
- 32
IPA.Loader/Loader/Composite/CompositeBSPlugin.cs View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine.SceneManagement;
using Logger = IPA.Logging.Logger;
@ -11,59 +12,57 @@ namespace IPA.Loader.Composite
private delegate void CompositeCall(PluginLoader.PluginInfo plugin);
public CompositeBSPlugin(IEnumerable<PluginLoader.PluginInfo> plugins) {
public CompositeBSPlugin(IEnumerable<PluginLoader.PluginInfo> plugins)
{
this.plugins = plugins;
}
public void OnApplicationQuit() {
Invoke(plugin => plugin.Plugin.OnApplicationQuit());
}
public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode) {
Invoke(plugin => plugin.Plugin.OnSceneLoaded(scene, sceneMode));
}
public void OnSceneUnloaded(Scene scene) {
Invoke(plugin => plugin.Plugin.OnSceneUnloaded(scene));
}
public void OnActiveSceneChanged(Scene prevScene, Scene nextScene) {
Invoke(plugin => plugin.Plugin.OnActiveSceneChanged(prevScene, nextScene));
}
private void Invoke(CompositeCall callback) {
foreach (var plugin in plugins) {
try {
private void Invoke(CompositeCall callback, [CallerMemberName] string method = "")
{
foreach (var plugin in plugins)
{
try
{
if (plugin.Plugin != null)
callback(plugin);
}
catch (Exception ex) {
Logger.log.Error($"{plugin.Metadata.Name}: {ex}");
catch (Exception ex)
{
Logger.log.Error($"{plugin.Metadata.Name} {method}: {ex}");
}
}
}
public void OnEnable()
=> Invoke(plugin => plugin.Plugin.OnEnable());
public void OnApplicationQuit()
=> Invoke(plugin => plugin.Plugin.OnApplicationQuit());
public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
=> Invoke(plugin => plugin.Plugin.OnSceneLoaded(scene, sceneMode));
public void OnSceneUnloaded(Scene scene)
=> Invoke(plugin => plugin.Plugin.OnSceneUnloaded(scene));
public void OnActiveSceneChanged(Scene prevScene, Scene nextScene)
=> Invoke(plugin => plugin.Plugin.OnActiveSceneChanged(prevScene, nextScene));
public void OnUpdate()
{
Invoke(plugin => {
=> Invoke(plugin => {
if (plugin.Plugin is IEnhancedPlugin saberPlugin)
saberPlugin.OnUpdate();
});
}
public void OnFixedUpdate()
{
Invoke(plugin => {
=> Invoke(plugin => {
if (plugin.Plugin is IEnhancedPlugin saberPlugin)
saberPlugin.OnFixedUpdate();
});
}
public void OnLateUpdate() {
Invoke(plugin => {
public void OnLateUpdate()
=> Invoke(plugin => {
if (plugin.Plugin is IEnhancedPlugin saberPlugin)
saberPlugin.OnLateUpdate();
});
}
}
}

+ 17
- 10
IPA.Loader/Loader/PluginComponent.cs View File

@ -13,6 +13,7 @@ namespace IPA.Loader
private CompositeBSPlugin bsPlugins;
private CompositeIPAPlugin ipaPlugins;
private bool quitting;
private static bool initialized = false;
internal static PluginComponent Create()
{
@ -23,22 +24,28 @@ namespace IPA.Loader
{
DontDestroyOnLoad(gameObject);
PluginManager.Load();
if (!initialized)
{
PluginManager.Load();
bsPlugins = new CompositeBSPlugin(PluginManager.BSMetas);
bsPlugins = new CompositeBSPlugin(PluginManager.BSMetas);
#pragma warning disable 618
ipaPlugins = new CompositeIPAPlugin(PluginManager.Plugins);
ipaPlugins = new CompositeIPAPlugin(PluginManager.Plugins);
#pragma warning restore 618
#if NET4
gameObject.AddComponent<Updating.BeatMods.Updater>();
#if BeatSaber
gameObject.AddComponent<Updating.BeatMods.Updater>();
#endif
ipaPlugins.OnApplicationStart();
SceneManager.activeSceneChanged += OnActiveSceneChanged;
SceneManager.sceneLoaded += OnSceneLoaded;
SceneManager.sceneUnloaded += OnSceneUnloaded;
bsPlugins.OnEnable();
ipaPlugins.OnApplicationStart();
SceneManager.activeSceneChanged += OnActiveSceneChanged;
SceneManager.sceneLoaded += OnSceneLoaded;
SceneManager.sceneUnloaded += OnSceneUnloaded;
initialized = true;
}
}
void Update()


+ 2
- 3
IPA.Loader/Loader/PluginLoader.cs View File

@ -360,7 +360,6 @@ namespace IPA.Loader
}
// keep track of these for the updater; it should still be able to update mods not loaded
// TODO: add ignore reason
// the thing -> the reason
internal static Dictionary<PluginMetadata, IgnoreReason> ignoredPlugins = new Dictionary<PluginMetadata, IgnoreReason>();
@ -744,7 +743,7 @@ namespace IPA.Loader
Logger.loader.Critical($"Feature errored in {nameof(Feature.AfterInit)}: {e}");
}
try // TODO: move this out to after all plugins have been inited
/*try // TODO: move this out to after all plugins have been inited
{
instance.OnEnable();
}
@ -753,7 +752,7 @@ namespace IPA.Loader
Logger.loader.Error($"Error occurred trying to enable {meta.Name}");
Logger.loader.Error(e);
return null; // is enable failure a full load failure?
}
}*/
}
catch (AmbiguousMatchException)
{


+ 8
- 9
IPA.Loader/Loader/PluginManager.cs View File

@ -352,9 +352,8 @@ namespace IPA.Loader
{ // fix type references
if (@ref.FullName == "IllusionPlugin.IPlugin") @ref.Namespace = "IPA.Old"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.IEnhancedPlugin") @ref.Namespace = "IPA.Old"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.IBeatSaberPlugin") @ref.Namespace = "IPA"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.IEnhancedBeatSaberPlugin") @ref.Namespace = "IPA"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.BeatSaber.ModsaberModInfo") @ref.Namespace = "IPA"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.IBeatSaberPlugin") { @ref.Namespace = "IPA"; @ref.Name = nameof(IPlugin); }
if (@ref.FullName == "IllusionPlugin.IEnhancedBeatSaberPlugin") { @ref.Namespace = "IPA"; @ref.Name = nameof(IEnhancedPlugin); }
if (@ref.FullName == "IllusionPlugin.IniFile") @ref.Namespace = "IPA.Config"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.IModPrefs") @ref.Namespace = "IPA.Config"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.ModPrefs") @ref.Namespace = "IPA.Config"; //@ref.Name = "";
@ -371,7 +370,6 @@ namespace IPA.Loader
if (@ref.FullName == "IllusionInjector.Updating.Backup.BackupUnit") @ref.Namespace = "IPA.Updating.Backup"; //@ref.Name = "";
if (@ref.Namespace == "IllusionInjector.Utilities") @ref.Namespace = "IPA.Utilities"; //@ref.Name = "";
if (@ref.Namespace == "IllusionInjector.Logging.Printers") @ref.Namespace = "IPA.Logging.Printers"; //@ref.Name = "";
if (@ref.Namespace == "IllusionInjector.Updating.ModsaberML") @ref.Namespace = "IPA.Updating.ModSaber"; //@ref.Name = "";
}
module.Write(pluginCopy);
@ -383,9 +381,10 @@ namespace IPA.Loader
foreach (string s in copiedPlugins)
{
var result = LoadPluginsFromFile(s);
_ipaPlugins.AddRange(result.Item2);
if (result == null) continue;
_ipaPlugins.AddRange(result.NonNull());
}
Logger.log.Info(exeName);
Logger.log.Info($"Running on Unity {Application.unityVersion}");
Logger.log.Info($"Game version {BeatSaber.GameVersion}");
@ -404,12 +403,12 @@ namespace IPA.Loader
Logger.log.Info("-----------------------------");
}
private static Tuple<IEnumerable<PluginInfo>, IEnumerable<Old.IPlugin>> LoadPluginsFromFile(string file)
private static IEnumerable<Old.IPlugin> LoadPluginsFromFile(string file)
{
var ipaPlugins = new List<Old.IPlugin>();
if (!File.Exists(file) || !file.EndsWith(".dll", true, null))
return new Tuple<IEnumerable<PluginInfo>, IEnumerable<Old.IPlugin>>(null, ipaPlugins);
return ipaPlugins;
T OptionalGetPlugin<T>(Type t) where T : class
{
@ -456,7 +455,7 @@ namespace IPA.Loader
Logger.loader.Error(e);
}
return new Tuple<IEnumerable<PluginInfo>, IEnumerable<Old.IPlugin>>(null, ipaPlugins);
return ipaPlugins;
}
internal static class AppInfo


+ 2
- 2
IPA.Loader/PluginInterfaces/IPA/IPlugin.cs View File

@ -4,8 +4,8 @@
namespace IPA.Old
{
/// <summary>
/// Interface for generic Illusion unity plugins. Every class that implements this will be loaded if the DLL is placed at
/// data/Managed/Plugins.
/// Interface for generic Illusion unity plugins. Every class that implements this will be loaded if the DLL is placed in
/// Plugins.
/// </summary>
[Obsolete("When building plugins for Beat Saber, use IBeatSaberPlugin")]
public interface IPlugin


+ 1
- 1
IPA.Loader/Updating/BeatMods/ApiEndpoint.cs View File

@ -10,7 +10,7 @@ using Version = SemVer.Version;
namespace IPA.Updating.BeatMods
{
#if NET4
#if BeatSaber
class ApiEndpoint
{
public const string BeatModBase = "https://beatmods.com";


+ 1
- 1
IPA.Loader/Updating/BeatMods/Updater.cs View File

@ -30,7 +30,7 @@ namespace IPA.Updating.BeatMods
internal const string SpecialDeletionsFile = "$$delete";
}
#if NET4
#if BeatSaber
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
internal partial class Updater : MonoBehaviour
{


+ 14
- 0
Net3-Proxy/CompilerServices.cs View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
public sealed class CallerMemberNameAttribute : Attribute
{
}
}

+ 1
- 0
Net3-Proxy/Net3-Proxy.csproj View File

@ -40,6 +40,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Array.cs" />
<Compile Include="CompilerServices.cs" />
<Compile Include="Directory.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="File.cs" />


Loading…
Cancel
Save