mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Move hook to MaterialResourceHandle.Load (inlining my beloathed)
This commit is contained in:
parent
1b5553284c
commit
700fef4f04
7 changed files with 18 additions and 17 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit 8ee82929fa6c725b8f556904ba022fb418991b5c
|
||||
Subproject commit ac9d9c78ae0025489b80ce2e798cdaacb0b43947
|
||||
|
|
@ -6,11 +6,11 @@ namespace Penumbra.Communication;
|
|||
/// <item>Parameter is the material resource handle for which the shader package has been loaded. </item>
|
||||
/// <item>Parameter is the associated game object. </item>
|
||||
/// </list> </summary>
|
||||
public sealed class MtrlShpkLoaded() : EventWrapper<nint, nint, MtrlShpkLoaded.Priority>(nameof(MtrlShpkLoaded))
|
||||
public sealed class MtrlLoaded() : EventWrapper<nint, nint, MtrlLoaded.Priority>(nameof(MtrlLoaded))
|
||||
{
|
||||
public enum Priority
|
||||
{
|
||||
/// <seealso cref="Penumbra.Interop.Hooks.PostProcessing.ShaderReplacementFixer.OnMtrlShpkLoaded"/>
|
||||
/// <seealso cref="Penumbra.Interop.Hooks.PostProcessing.ShaderReplacementFixer.OnMtrlLoaded"/>
|
||||
ShaderReplacementFixer = 0,
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ public class CommunicatorService : IDisposable, IService
|
|||
/// <inheritdoc cref="Communication.CreatedCharacterBase"/>
|
||||
public readonly CreatedCharacterBase CreatedCharacterBase = new();
|
||||
|
||||
/// <inheritdoc cref="Communication.MtrlShpkLoaded"/>
|
||||
public readonly MtrlShpkLoaded MtrlShpkLoaded = new();
|
||||
/// <inheritdoc cref="Communication.MtrlLoaded"/>
|
||||
public readonly MtrlLoaded MtrlLoaded = new();
|
||||
|
||||
/// <inheritdoc cref="Communication.ModDataChanged"/>
|
||||
public readonly ModDataChanged ModDataChanged = new();
|
||||
|
|
@ -87,7 +87,7 @@ public class CommunicatorService : IDisposable, IService
|
|||
TemporaryGlobalModChange.Dispose();
|
||||
CreatingCharacterBase.Dispose();
|
||||
CreatedCharacterBase.Dispose();
|
||||
MtrlShpkLoaded.Dispose();
|
||||
MtrlLoaded.Dispose();
|
||||
ModDataChanged.Dispose();
|
||||
ModOptionChanged.Dispose();
|
||||
ModDiscoveryStarted.Dispose();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue