77using  FFXIVClientStructs . FFXIV . Client . Graphics . Render ; 
88using  OtterGui . Services ; 
99using  Penumbra . GameData ; 
10+ using  Penumbra . Interop . Hooks . ResourceLoading ; 
1011using  Penumbra . Services ; 
1112
1213namespace  Penumbra . Interop . Hooks . PostProcessing ; 
@@ -31,19 +32,23 @@ private static readonly IComparer<ForcedTextureConfig> ForcedTextureConfigCompar
3132
3233    public  TextureReportRecord [ ] ?  TextureReport  {  get ;  private  set ;  } 
3334
34-     [ Signature ( Sigs . RenderTargetManagerInitialize ,  DetourName  =  nameof ( RenderTargetManagerInitializeDetour ) ) ] 
35-     private  readonly  Hook < RenderTargetManagerInitializeFunc >  _renderTargetManagerInitialize  =  null ! ; 
36- 
37-     [ Signature ( Sigs . DeviceCreateTexture2D ,  DetourName  =  nameof ( CreateTexture2DDetour ) ) ] 
38-     private  readonly  Hook < CreateTexture2DFunc >  _createTexture2D  =  null ! ; 
35+     private  readonly  Hook < RenderTargetManagerInitializeFunc > ?  _renderTargetManagerInitialize ; 
36+     private  readonly  Hook < CreateTexture2DFunc > ?                _createTexture2D ; 
3937
4038    public  RenderTargetHdrEnabler ( IGameInteropProvider  interop ,  Configuration  config ,  IDalamudPluginInterface  pi , 
41-         DalamudConfigService  dalamudConfig ) 
39+         DalamudConfigService  dalamudConfig ,   PeSigScanner   peScanner ) 
4240    { 
4341        _config  =  config ; 
44-         interop . InitializeFromAttributes ( this ) ; 
45-         if  ( config . HdrRenderTargets  &&  ! HookOverrides . Instance . PostProcessing . RenderTargetManagerInitialize ) 
46-             _renderTargetManagerInitialize . Enable ( ) ; 
42+         if  ( peScanner . TryScanText ( Sigs . RenderTargetManagerInitialize ,  out  var  initializeAddress ) 
43+          &&  peScanner . TryScanText ( Sigs . DeviceCreateTexture2D ,          out  var  createAddress ) ) 
44+         { 
45+             _renderTargetManagerInitialize  = 
46+                 interop . HookFromAddress < RenderTargetManagerInitializeFunc > ( initializeAddress ,  RenderTargetManagerInitializeDetour ) ; 
47+             _createTexture2D  =  interop . HookFromAddress < CreateTexture2DFunc > ( createAddress ,  CreateTexture2DDetour ) ; 
48+ 
49+             if  ( config . HdrRenderTargets  &&  ! HookOverrides . Instance . PostProcessing . RenderTargetManagerInitialize ) 
50+                 _renderTargetManagerInitialize . Enable ( ) ; 
51+         } 
4752
4853        _share  =  pi . GetOrCreateData ( "Penumbra.RenderTargetHDR.V1" ,  ( )  => 
4954        { 
@@ -87,19 +92,19 @@ public void Dispose()
8792
8893    private  void  Dispose ( bool  _ ) 
8994    { 
90-         _createTexture2D . Dispose ( ) ; 
91-         _renderTargetManagerInitialize . Dispose ( ) ; 
95+         _createTexture2D ? . Dispose ( ) ; 
96+         _renderTargetManagerInitialize ? . Dispose ( ) ; 
9297    } 
9398
9499    private  nint  RenderTargetManagerInitializeDetour ( RenderTargetManager *  @this ) 
95100    { 
96-         _createTexture2D . Enable ( ) ; 
101+         _createTexture2D ! . Enable ( ) ; 
97102        _share . Item5 [ 0 ]        =  true ; 
98103        _textureIndices . Value  =  new  TextureIndices ( 0 ,  0 ) ; 
99104        _textures . Value        =  _config . DebugMode  ?  [ ]  :  null ; 
100105        try 
101106        { 
102-             return  _renderTargetManagerInitialize . Original ( @this ) ; 
107+             return  _renderTargetManagerInitialize ! . Original ( @this ) ; 
103108        } 
104109        finally 
105110        { 
@@ -133,7 +138,7 @@ private nint RenderTargetManagerInitializeDetour(RenderTargetManager* @this)
133138            _textureIndices . Value  =  indices ; 
134139        } 
135140
136-         var  texture  =  _createTexture2D . Original ( @this ,  size ,  mipLevel ,  textureFormat ,  flags ,  unk ) ; 
141+         var  texture  =  _createTexture2D ! . Original ( @this ,  size ,  mipLevel ,  textureFormat ,  flags ,  unk ) ; 
137142        if  ( _textures . IsValueCreated ) 
138143            _textures . Value ? . Add ( ( nint ) texture ,  ( indices . CreationOrder  -  1 ,  originalTextureFormat ) ) ; 
139144        return  texture ; 
0 commit comments