fix: register interfaces for provided services

This commit is contained in:
goat 2023-09-30 01:09:25 +02:00
parent 4b9de31240
commit 4a1b220d4a
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
9 changed files with 46 additions and 20 deletions

View file

@ -2,6 +2,7 @@ using System;
using System.IO; using System.IO;
using Dalamud.Configuration.Internal; using Dalamud.Configuration.Internal;
using Dalamud.Game;
using Dalamud.Game.Command; using Dalamud.Game.Command;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Plugin; using Dalamud.Plugin;
@ -55,7 +56,7 @@ namespace Dalamud.CorePlugin
/// </summary> /// </summary>
/// <param name="pluginInterface">Dalamud plugin interface.</param> /// <param name="pluginInterface">Dalamud plugin interface.</param>
/// <param name="log">Logging service.</param> /// <param name="log">Logging service.</param>
public PluginImpl(DalamudPluginInterface pluginInterface, IPluginLog log) public PluginImpl(DalamudPluginInterface pluginInterface, IPluginLog log, ISigScanner scanner)
{ {
try try
{ {
@ -65,6 +66,8 @@ namespace Dalamud.CorePlugin
this.windowSystem.AddWindow(new PluginWindow()); this.windowSystem.AddWindow(new PluginWindow());
this.pluginLog.Information(scanner.ToString());
this.Interface.UiBuilder.Draw += this.OnDraw; this.Interface.UiBuilder.Draw += this.OnDraw;
this.Interface.UiBuilder.OpenConfigUi += this.OnOpenConfigUi; this.Interface.UiBuilder.OpenConfigUi += this.OnOpenConfigUi;
this.Interface.UiBuilder.OpenMainUi += this.OnOpenMainUi; this.Interface.UiBuilder.OpenMainUi += this.OnOpenMainUi;

20
Dalamud.Injector/Hacks.cs Normal file
View file

@ -0,0 +1,20 @@
using System;
// ReSharper disable once CheckNamespace
namespace Dalamud;
// TODO: Get rid of this! Move StartInfo to another assembly, make this good
/// <summary>
/// Class to initialize Service&lt;T&gt;s.
/// </summary>
internal static class ServiceManager
{
/// <summary>
/// Indicates that the class is a service.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class Service : Attribute
{
}
}

View file

@ -19,6 +19,7 @@ namespace Dalamud.Configuration.Internal;
/// Class containing Dalamud settings. /// Class containing Dalamud settings.
/// </summary> /// </summary>
[Serializable] [Serializable]
[ServiceManager.Service]
internal sealed class DalamudConfiguration : IServiceType, IDisposable internal sealed class DalamudConfiguration : IServiceType, IDisposable
{ {
private static readonly JsonSerializerSettings SerializerSettings = new() private static readonly JsonSerializerSettings SerializerSettings = new()

View file

@ -29,6 +29,7 @@ namespace Dalamud;
/// <summary> /// <summary>
/// The main Dalamud class containing all subsystems. /// The main Dalamud class containing all subsystems.
/// </summary> /// </summary>
[ServiceManager.Service]
internal sealed class Dalamud : IServiceType internal sealed class Dalamud : IServiceType
{ {
#region Internals #region Internals

View file

@ -10,6 +10,7 @@ namespace Dalamud;
/// Struct containing information needed to initialize Dalamud. /// Struct containing information needed to initialize Dalamud.
/// </summary> /// </summary>
[Serializable] [Serializable]
[ServiceManager.Service]
public record DalamudStartInfo : IServiceType public record DalamudStartInfo : IServiceType
{ {
/// <summary> /// <summary>

View file

@ -11,6 +11,7 @@ namespace Dalamud.Game;
/// </summary> /// </summary>
[PluginInterface] [PluginInterface]
[InterfaceVersion("1.0")] [InterfaceVersion("1.0")]
[ServiceManager.Service]
#pragma warning disable SA1015 #pragma warning disable SA1015
[ResolveVia<ISigScanner>] [ResolveVia<ISigScanner>]
#pragma warning restore SA1015 #pragma warning restore SA1015

View file

@ -16,6 +16,7 @@ namespace Dalamud.IoC.Internal;
/// This is only used to resolve dependencies for plugins. /// This is only used to resolve dependencies for plugins.
/// Dalamud services are constructed via Service{T}.ConstructObject at the moment. /// Dalamud services are constructed via Service{T}.ConstructObject at the moment.
/// </summary> /// </summary>
[ServiceManager.Service]
internal class ServiceContainer : IServiceProvider, IServiceType internal class ServiceContainer : IServiceProvider, IServiceType
{ {
private static readonly ModuleLog Log = new("SERVICECONTAINER"); private static readonly ModuleLog Log = new("SERVICECONTAINER");

View file

@ -92,28 +92,24 @@ internal static class ServiceManager
var cacheDir = new DirectoryInfo(Path.Combine(startInfo.WorkingDirectory!, "cachedSigs")); var cacheDir = new DirectoryInfo(Path.Combine(startInfo.WorkingDirectory!, "cachedSigs"));
if (!cacheDir.Exists) if (!cacheDir.Exists)
cacheDir.Create(); cacheDir.Create();
lock (LoadedServices) lock (LoadedServices)
{ {
Service<Dalamud>.Provide(dalamud); void ProvideService<T>(T service) where T : IServiceType
LoadedServices.Add(typeof(Dalamud)); {
Debug.Assert(typeof(T).GetServiceKind().HasFlag(ServiceKind.ManualService), "Provided service must have Service attribute");
Service<DalamudStartInfo>.Provide(startInfo); Service<T>.Provide(service);
LoadedServices.Add(typeof(DalamudStartInfo)); LoadedServices.Add(typeof(T));
}
Service<ReliableFileStorage>.Provide(fs); ProvideService(dalamud);
LoadedServices.Add(typeof(ReliableFileStorage)); ProvideService(startInfo);
ProvideService(fs);
Service<DalamudConfiguration>.Provide(configuration); ProvideService(configuration);
LoadedServices.Add(typeof(DalamudConfiguration)); ProvideService(new ServiceContainer());
ProvideService(
Service<ServiceContainer>.Provide(new ServiceContainer());
LoadedServices.Add(typeof(ServiceContainer));
Service<TargetSigScanner>.Provide(
new TargetSigScanner( new TargetSigScanner(
true, new FileInfo(Path.Combine(cacheDir.FullName, $"{startInfo.GameVersion}.json")))); true, new FileInfo(Path.Combine(cacheDir.FullName, $"{startInfo.GameVersion}.json"))));
LoadedServices.Add(typeof(TargetSigScanner));
} }
using (Timings.Start("CS Resolver Init")) using (Timings.Start("CS Resolver Init"))
@ -149,7 +145,8 @@ internal static class ServiceManager
serviceContainer.RegisterInterfaces(serviceType); serviceContainer.RegisterInterfaces(serviceType);
// Scoped service do not go through Service<T> and are never early loaded // Scoped service do not go through Service<T> and are never early loaded
if (serviceKind.HasFlag(ServiceKind.ScopedService)) // Manual services are provided
if (serviceKind.HasFlag(ServiceKind.ScopedService) || serviceKind.HasFlag(ServiceKind.ManualService))
continue; continue;
Debug.Assert( Debug.Assert(

View file

@ -23,6 +23,7 @@ namespace Dalamud.Storage;
/// <remarks> /// <remarks>
/// This is not an early-loaded service, as it is needed before they are initialized. /// This is not an early-loaded service, as it is needed before they are initialized.
/// </remarks> /// </remarks>
[ServiceManager.Service]
public class ReliableFileStorage : IServiceType, IDisposable public class ReliableFileStorage : IServiceType, IDisposable
{ {
private static readonly ModuleLog Log = new("VFS"); private static readonly ModuleLog Log = new("VFS");