Move hook to MaterialResourceHandle.Load (inlining my beloathed)

This commit is contained in:
Exter-N 2024-08-05 03:41:35 +02:00
parent 1b5553284c
commit 700fef4f04
7 changed files with 18 additions and 17 deletions

View file

@ -99,7 +99,7 @@ public class HookOverrides
public struct ResourceHooks
{
public bool ApricotResourceLoad;
public bool LoadMtrlShpk;
public bool LoadMtrl;
public bool LoadMtrlTex;
public bool ResolvePathHooks;
public bool ResourceHandleDestructor;

View file

@ -110,7 +110,7 @@ public sealed unsafe class ShaderReplacementFixer : IDisposable, IRequiredServic
_modelRendererOnRenderMaterialHook = hooks.CreateHook<ModelRendererOnRenderMaterialDelegate>("ModelRenderer.OnRenderMaterial",
Sigs.ModelRendererOnRenderMaterial, ModelRendererOnRenderMaterialDetour,
!HookOverrides.Instance.PostProcessing.ModelRendererOnRenderMaterial).Result;
_communicator.MtrlShpkLoaded.Subscribe(OnMtrlShpkLoaded, MtrlShpkLoaded.Priority.ShaderReplacementFixer);
_communicator.MtrlLoaded.Subscribe(OnMtrlLoaded, MtrlLoaded.Priority.ShaderReplacementFixer);
_resourceHandleDestructor.Subscribe(OnResourceHandleDestructor, ResourceHandleDestructor.Priority.ShaderReplacementFixer);
}
@ -118,7 +118,7 @@ public sealed unsafe class ShaderReplacementFixer : IDisposable, IRequiredServic
{
_modelRendererOnRenderMaterialHook.Dispose();
_humanOnRenderMaterialHook.Dispose();
_communicator.MtrlShpkLoaded.Unsubscribe(OnMtrlShpkLoaded);
_communicator.MtrlLoaded.Unsubscribe(OnMtrlLoaded);
_resourceHandleDestructor.Unsubscribe(OnResourceHandleDestructor);
_hairMaskState.ClearMaterials();
_characterOcclusionState.ClearMaterials();
@ -147,7 +147,7 @@ public sealed unsafe class ShaderReplacementFixer : IDisposable, IRequiredServic
return shpkName.SequenceEqual(mtrlResource->ShpkNameSpan);
}
private void OnMtrlShpkLoaded(nint mtrlResourceHandle, nint gameObject)
private void OnMtrlLoaded(nint mtrlResourceHandle, nint gameObject)
{
var mtrl = (MaterialResourceHandle*)mtrlResourceHandle;
var shpk = mtrl->ShaderPackageResourceHandle;

View file

@ -5,28 +5,28 @@ using Penumbra.Services;
namespace Penumbra.Interop.Hooks.Resources;
public sealed unsafe class LoadMtrlShpk : FastHook<LoadMtrlShpk.Delegate>
public sealed unsafe class LoadMtrl : FastHook<LoadMtrl.Delegate>
{
private readonly GameState _gameState;
private readonly CommunicatorService _communicator;
public LoadMtrlShpk(HookManager hooks, GameState gameState, CommunicatorService communicator)
public LoadMtrl(HookManager hooks, GameState gameState, CommunicatorService communicator)
{
_gameState = gameState;
_communicator = communicator;
Task = hooks.CreateHook<Delegate>("Load Material Shaders", Sigs.LoadMtrlShpk, Detour, !HookOverrides.Instance.Resources.LoadMtrlShpk);
Task = hooks.CreateHook<Delegate>("Load Material", Sigs.LoadMtrl, Detour, !HookOverrides.Instance.Resources.LoadMtrl);
}
public delegate byte Delegate(MaterialResourceHandle* mtrlResourceHandle);
public delegate byte Delegate(MaterialResourceHandle* mtrlResourceHandle, void* unk1, byte unk2);
private byte Detour(MaterialResourceHandle* handle)
private byte Detour(MaterialResourceHandle* handle, void* unk1, byte unk2)
{
var last = _gameState.MtrlData.Value;
var mtrlData = _gameState.LoadSubFileHelper((nint)handle);
_gameState.MtrlData.Value = mtrlData;
var ret = Task.Result.Original(handle);
var ret = Task.Result.Original(handle, unk1, unk2);
_gameState.MtrlData.Value = last;
_communicator.MtrlShpkLoaded.Invoke((nint)handle, mtrlData.AssociatedGameObject);
_communicator.MtrlLoaded.Invoke((nint)handle, mtrlData.AssociatedGameObject);
return ret;
}
}

View file

@ -4,6 +4,7 @@ using Penumbra.GameData;
namespace Penumbra.Interop.Hooks.Resources;
// TODO check if this is still needed, as our hooked function is called by LoadMtrl's hooked function
public sealed unsafe class LoadMtrlTex : FastHook<LoadMtrlTex.Delegate>
{
private readonly GameState _gameState;