Maybe fix face decals not correctly reloading in character collections.

This commit is contained in:
Ottermandias 2022-05-11 20:55:26 +02:00
parent fc1255661c
commit d2f84aa976
4 changed files with 24 additions and 7 deletions

View file

@ -24,15 +24,16 @@ public unsafe partial class PathResolver
[Signature( "E8 ?? ?? ?? ?? 48 85 C0 74 21 C7 40" )]
public Hook< CharacterBaseCreateDelegate >? CharacterBaseCreateHook;
private ModCollection? _lastCreatedCollection;
private IntPtr CharacterBaseCreateDetour( uint a, IntPtr b, IntPtr c, byte d )
{
using var cmp = MetaChanger.ChangeCmp( this, out var collection );
using var cmp = MetaChanger.ChangeCmp( this, out _lastCreatedCollection );
var ret = CharacterBaseCreateHook!.Original( a, b, c, d );
if( LastGameObject != null )
{
DrawObjectToObject[ ret ] = ( collection!, LastGameObject->ObjectIndex );
DrawObjectToObject[ ret ] = (_lastCreatedCollection!, LastGameObject->ObjectIndex );
}
return ret;
}

View file

@ -12,7 +12,6 @@ public unsafe partial class PathResolver
// Humans
private IntPtr ResolveDecalDetour( IntPtr drawObject, IntPtr path, IntPtr unk3, uint unk4 )
=> ResolvePathDetour( drawObject, ResolveDecalPathHook!.Original( drawObject, path, unk3, unk4 ) );
private IntPtr ResolveEidDetour( IntPtr drawObject, IntPtr path, IntPtr unk3 )
=> ResolvePathDetour( drawObject, ResolveEidPathHook!.Original( drawObject, path, unk3 ) );

View file

@ -32,11 +32,14 @@ public partial class PathResolver : IDisposable
private bool CharacterResolver( Utf8GamePath gamePath, ResourceCategory _1, ResourceType type, int _2, out (FullPath?, object?) data )
{
// Check if the path was marked for a specific collection,
// or if it is a file loaded by a material, and if we are currently in a material load.
// or if it is a file loaded by a material, and if we are currently in a material load,
// or if it is a face decal path and the current mod collection is set.
// If not use the default collection.
// We can remove paths after they have actually been loaded.
// A potential next request will add the path anew.
var nonDefault = HandleMaterialSubFiles( type, out var collection ) || PathCollections.TryRemove( gamePath.Path, out collection );
var nonDefault = HandleMaterialSubFiles( type, out var collection )
|| PathCollections.TryRemove( gamePath.Path, out collection )
|| HandleDecalFile( type, gamePath, out collection );
if( !nonDefault )
{
collection = Penumbra.CollectionManager.Default;
@ -53,6 +56,20 @@ public partial class PathResolver : IDisposable
return true;
}
private bool HandleDecalFile( ResourceType type, Utf8GamePath gamePath, out ModCollection? collection )
{
if( type == ResourceType.Tex
&& _lastCreatedCollection != null
&& gamePath.Path.Substring( "chara/common/texture/".Length ).StartsWith( 'd', 'e', 'c', 'a', 'l', '_', 'f', 'a', 'c', 'e' ) )
{
collection = _lastCreatedCollection;
return true;
}
collection = null;
return false;
}
public void Enable()
{
if( Enabled )