mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-16 05:34:25 +01:00
43 lines
1.6 KiB
C#
43 lines
1.6 KiB
C#
using System.Collections.Frozen;
|
|
using OtterGui.Services;
|
|
using Penumbra.Api.Enums;
|
|
using Penumbra.Interop.Hooks.ResourceLoading;
|
|
using Penumbra.Interop.Structs;
|
|
using Penumbra.String;
|
|
using Penumbra.String.Classes;
|
|
|
|
namespace Penumbra.Interop.Processing;
|
|
|
|
public interface IFilePostProcessor : IService
|
|
{
|
|
public ResourceType Type { get; }
|
|
public unsafe void PostProcess(ResourceHandle* resource, CiByteString originalGamePath, ReadOnlySpan<byte> additionalData);
|
|
}
|
|
|
|
public unsafe class FilePostProcessService : IRequiredService, IDisposable
|
|
{
|
|
private readonly ResourceLoader _resourceLoader;
|
|
private readonly FrozenDictionary<ResourceType, IFilePostProcessor> _processors;
|
|
|
|
public FilePostProcessService(ResourceLoader resourceLoader, ServiceManager services)
|
|
{
|
|
_resourceLoader = resourceLoader;
|
|
_processors = services.GetServicesImplementing<IFilePostProcessor>().ToFrozenDictionary(s => s.Type, s => s);
|
|
_resourceLoader.BeforeResourceComplete += OnResourceComplete;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_resourceLoader.BeforeResourceComplete -= OnResourceComplete;
|
|
}
|
|
|
|
private void OnResourceComplete(ResourceHandle* resource, CiByteString path, Utf8GamePath original,
|
|
ReadOnlySpan<byte> additionalData, bool isAsync)
|
|
{
|
|
if (resource->LoadState != LoadState.Success)
|
|
return;
|
|
|
|
if (_processors.TryGetValue(resource->FileType, out var processor))
|
|
processor.PostProcess(resource, original.Path, additionalData);
|
|
}
|
|
}
|