ReShade related fixes (#1963)

* Handle ReShadeAddonInterface ctor exceptions

* Lower ReShadeApiVersion to 1

* fixes
This commit is contained in:
srkizer 2024-07-24 04:01:41 +09:00 committed by GitHub
parent ec269f483e
commit 1380a55935
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,7 +15,7 @@ namespace Dalamud.Interface.Internal.ReShadeHandling;
/// <summary>ReShade interface.</summary> /// <summary>ReShade interface.</summary>
internal sealed unsafe partial class ReShadeAddonInterface : IDisposable internal sealed unsafe partial class ReShadeAddonInterface : IDisposable
{ {
private const int ReShadeApiVersion = 12; private const int ReShadeApiVersion = 1;
private readonly HMODULE hDalamudModule; private readonly HMODULE hDalamudModule;
@ -25,6 +25,8 @@ internal sealed unsafe partial class ReShadeAddonInterface : IDisposable
private readonly DelegateStorage<ReShadeInitSwapChain> initSwapChainDelegate; private readonly DelegateStorage<ReShadeInitSwapChain> initSwapChainDelegate;
private readonly DelegateStorage<ReShadeDestroySwapChain> destroySwapChainDelegate; private readonly DelegateStorage<ReShadeDestroySwapChain> destroySwapChainDelegate;
private bool requiresFinalize;
private ReShadeAddonInterface() private ReShadeAddonInterface()
{ {
this.hDalamudModule = (HMODULE)Marshal.GetHINSTANCE(typeof(ReShadeAddonInterface).Assembly.ManifestModule); this.hDalamudModule = (HMODULE)Marshal.GetHINSTANCE(typeof(ReShadeAddonInterface).Assembly.ManifestModule);
@ -40,16 +42,37 @@ internal sealed unsafe partial class ReShadeAddonInterface : IDisposable
0, 0,
this.GetModuleHandleExWDetour); this.GetModuleHandleExWDetour);
this.addonModuleResolverHook.Enable(); try
Exports.ReShadeRegisterEvent( {
AddonEvent.ReShadeOverlay, this.addonModuleResolverHook.Enable();
this.reShadeOverlayDelegate = new((ref ApiObject rt) => this.ReShadeOverlay?.Invoke(ref rt))); Exports.ReShadeRegisterEvent(
Exports.ReShadeRegisterEvent( AddonEvent.ReShadeOverlay,
AddonEvent.InitSwapChain, this.reShadeOverlayDelegate = new((ref ApiObject rt) => this.ReShadeOverlay?.Invoke(ref rt)));
this.initSwapChainDelegate = new((ref ApiObject rt) => this.InitSwapChain?.Invoke(ref rt))); Exports.ReShadeRegisterEvent(
Exports.ReShadeRegisterEvent( AddonEvent.InitSwapChain,
AddonEvent.DestroySwapChain, this.initSwapChainDelegate = new((ref ApiObject rt) => this.InitSwapChain?.Invoke(ref rt)));
this.destroySwapChainDelegate = new((ref ApiObject rt) => this.DestroySwapChain?.Invoke(ref rt))); Exports.ReShadeRegisterEvent(
AddonEvent.DestroySwapChain,
this.destroySwapChainDelegate = new((ref ApiObject rt) => this.DestroySwapChain?.Invoke(ref rt)));
}
catch (Exception e1)
{
Exports.ReShadeUnregisterAddon(this.hDalamudModule);
try
{
this.addonModuleResolverHook.Disable();
this.addonModuleResolverHook.Dispose();
}
catch (Exception e2)
{
throw new AggregateException(e1, e2);
}
throw;
}
this.requiresFinalize = true;
} }
/// <summary>Finalizes an instance of the <see cref="ReShadeAddonInterface"/> class.</summary> /// <summary>Finalizes an instance of the <see cref="ReShadeAddonInterface"/> class.</summary>
@ -104,9 +127,10 @@ internal sealed unsafe partial class ReShadeAddonInterface : IDisposable
private void ReleaseUnmanagedResources() private void ReleaseUnmanagedResources()
{ {
Exports.ReShadeUnregisterEvent(AddonEvent.InitSwapChain, this.initSwapChainDelegate); if (!this.requiresFinalize)
Exports.ReShadeUnregisterEvent(AddonEvent.DestroySwapChain, this.destroySwapChainDelegate); return;
Exports.ReShadeUnregisterEvent(AddonEvent.ReShadeOverlay, this.reShadeOverlayDelegate); this.requiresFinalize = false;
// This will also unregister addon event registrations.
Exports.ReShadeUnregisterAddon(this.hDalamudModule); Exports.ReShadeUnregisterAddon(this.hDalamudModule);
this.addonModuleResolverHook.Disable(); this.addonModuleResolverHook.Disable();
this.addonModuleResolverHook.Dispose(); this.addonModuleResolverHook.Dispose();