mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +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 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
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.
|
/// 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()
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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");
|
||||||
|
|
|
||||||
|
|
@ -95,25 +95,21 @@ internal static class ServiceManager
|
||||||
|
|
||||||
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<T>.Provide(service);
|
||||||
|
LoadedServices.Add(typeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
Service<DalamudStartInfo>.Provide(startInfo);
|
ProvideService(dalamud);
|
||||||
LoadedServices.Add(typeof(DalamudStartInfo));
|
ProvideService(startInfo);
|
||||||
|
ProvideService(fs);
|
||||||
Service<ReliableFileStorage>.Provide(fs);
|
ProvideService(configuration);
|
||||||
LoadedServices.Add(typeof(ReliableFileStorage));
|
ProvideService(new ServiceContainer());
|
||||||
|
ProvideService(
|
||||||
Service<DalamudConfiguration>.Provide(configuration);
|
|
||||||
LoadedServices.Add(typeof(DalamudConfiguration));
|
|
||||||
|
|
||||||
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(
|
||||||
|
|
|
||||||
|
|
@ -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");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue