mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
fix: register interfaces for provided services
This commit is contained in:
parent
4b9de31240
commit
4a1b220d4a
9 changed files with 46 additions and 20 deletions
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.IO;
|
||||
|
||||
using Dalamud.Configuration.Internal;
|
||||
using Dalamud.Game;
|
||||
using Dalamud.Game.Command;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Plugin;
|
||||
|
|
@ -55,7 +56,7 @@ namespace Dalamud.CorePlugin
|
|||
/// </summary>
|
||||
/// <param name="pluginInterface">Dalamud plugin interface.</param>
|
||||
/// <param name="log">Logging service.</param>
|
||||
public PluginImpl(DalamudPluginInterface pluginInterface, IPluginLog log)
|
||||
public PluginImpl(DalamudPluginInterface pluginInterface, IPluginLog log, ISigScanner scanner)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -65,6 +66,8 @@ namespace Dalamud.CorePlugin
|
|||
|
||||
this.windowSystem.AddWindow(new PluginWindow());
|
||||
|
||||
this.pluginLog.Information(scanner.ToString());
|
||||
|
||||
this.Interface.UiBuilder.Draw += this.OnDraw;
|
||||
this.Interface.UiBuilder.OpenConfigUi += this.OnOpenConfigUi;
|
||||
this.Interface.UiBuilder.OpenMainUi += this.OnOpenMainUi;
|
||||
|
|
|
|||
20
Dalamud.Injector/Hacks.cs
Normal file
20
Dalamud.Injector/Hacks.cs
Normal 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<T>s.
|
||||
/// </summary>
|
||||
internal static class ServiceManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates that the class is a service.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class Service : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ namespace Dalamud.Configuration.Internal;
|
|||
/// Class containing Dalamud settings.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[ServiceManager.Service]
|
||||
internal sealed class DalamudConfiguration : IServiceType, IDisposable
|
||||
{
|
||||
private static readonly JsonSerializerSettings SerializerSettings = new()
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ namespace Dalamud;
|
|||
/// <summary>
|
||||
/// The main Dalamud class containing all subsystems.
|
||||
/// </summary>
|
||||
[ServiceManager.Service]
|
||||
internal sealed class Dalamud : IServiceType
|
||||
{
|
||||
#region Internals
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ namespace Dalamud;
|
|||
/// Struct containing information needed to initialize Dalamud.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[ServiceManager.Service]
|
||||
public record DalamudStartInfo : IServiceType
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ namespace Dalamud.Game;
|
|||
/// </summary>
|
||||
[PluginInterface]
|
||||
[InterfaceVersion("1.0")]
|
||||
[ServiceManager.Service]
|
||||
#pragma warning disable SA1015
|
||||
[ResolveVia<ISigScanner>]
|
||||
#pragma warning restore SA1015
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ namespace Dalamud.IoC.Internal;
|
|||
/// This is only used to resolve dependencies for plugins.
|
||||
/// Dalamud services are constructed via Service{T}.ConstructObject at the moment.
|
||||
/// </summary>
|
||||
[ServiceManager.Service]
|
||||
internal class ServiceContainer : IServiceProvider, IServiceType
|
||||
{
|
||||
private static readonly ModuleLog Log = new("SERVICECONTAINER");
|
||||
|
|
|
|||
|
|
@ -95,25 +95,21 @@ internal static class ServiceManager
|
|||
|
||||
lock (LoadedServices)
|
||||
{
|
||||
Service<Dalamud>.Provide(dalamud);
|
||||
LoadedServices.Add(typeof(Dalamud));
|
||||
void ProvideService<T>(T service) where T : IServiceType
|
||||
{
|
||||
Debug.Assert(typeof(T).GetServiceKind().HasFlag(ServiceKind.ManualService), "Provided service must have Service attribute");
|
||||
Service<T>.Provide(service);
|
||||
LoadedServices.Add(typeof(T));
|
||||
}
|
||||
|
||||
Service<DalamudStartInfo>.Provide(startInfo);
|
||||
LoadedServices.Add(typeof(DalamudStartInfo));
|
||||
|
||||
Service<ReliableFileStorage>.Provide(fs);
|
||||
LoadedServices.Add(typeof(ReliableFileStorage));
|
||||
|
||||
Service<DalamudConfiguration>.Provide(configuration);
|
||||
LoadedServices.Add(typeof(DalamudConfiguration));
|
||||
|
||||
Service<ServiceContainer>.Provide(new ServiceContainer());
|
||||
LoadedServices.Add(typeof(ServiceContainer));
|
||||
|
||||
Service<TargetSigScanner>.Provide(
|
||||
ProvideService(dalamud);
|
||||
ProvideService(startInfo);
|
||||
ProvideService(fs);
|
||||
ProvideService(configuration);
|
||||
ProvideService(new ServiceContainer());
|
||||
ProvideService(
|
||||
new TargetSigScanner(
|
||||
true, new FileInfo(Path.Combine(cacheDir.FullName, $"{startInfo.GameVersion}.json"))));
|
||||
LoadedServices.Add(typeof(TargetSigScanner));
|
||||
}
|
||||
|
||||
using (Timings.Start("CS Resolver Init"))
|
||||
|
|
@ -149,7 +145,8 @@ internal static class ServiceManager
|
|||
serviceContainer.RegisterInterfaces(serviceType);
|
||||
|
||||
// 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;
|
||||
|
||||
Debug.Assert(
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ namespace Dalamud.Storage;
|
|||
/// <remarks>
|
||||
/// This is not an early-loaded service, as it is needed before they are initialized.
|
||||
/// </remarks>
|
||||
[ServiceManager.Service]
|
||||
public class ReliableFileStorage : IServiceType, IDisposable
|
||||
{
|
||||
private static readonly ModuleLog Log = new("VFS");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue