mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-01-02 13:53:42 +01:00
Maybe improve IMC handling.
This commit is contained in:
parent
23a08f30c4
commit
e261b4c0c5
4 changed files with 21 additions and 132 deletions
|
|
@ -128,7 +128,6 @@ public unsafe class ImcFile : MetaBaseFile
|
|||
var newLength = ( ( ( ActualLength - 1 ) >> 7 ) + 1 ) << 7;
|
||||
PluginLog.Verbose( "Resized IMC {Path} from {Length} to {NewLength}.", Path, Length, newLength );
|
||||
ResizeResources( newLength );
|
||||
ChangesSinceLoad = true;
|
||||
}
|
||||
|
||||
var defaultPtr = ( ImcEntry* )( Data + PreambleSize );
|
||||
|
|
@ -218,18 +217,18 @@ public unsafe class ImcFile : MetaBaseFile
|
|||
}
|
||||
}
|
||||
|
||||
public void Replace( ResourceHandle* resource, bool firstTime )
|
||||
public void Replace( ResourceHandle* resource )
|
||||
{
|
||||
var (data, length) = resource->GetData();
|
||||
if( data == IntPtr.Zero )
|
||||
var newData = Penumbra.MetaFileManager.AllocateDefaultMemory( Length, 8 );
|
||||
if( newData == null )
|
||||
{
|
||||
PluginLog.Error("Could not replace loaded IMC data at 0x{Data:X}, allocation failed." );
|
||||
return;
|
||||
}
|
||||
Functions.MemCpyUnchecked( newData, Data, Length );
|
||||
|
||||
resource->SetData( ( IntPtr )Data, Length );
|
||||
if( firstTime )
|
||||
{
|
||||
Penumbra.MetaFileManager.AddImcFile( resource, this, data, length );
|
||||
}
|
||||
Penumbra.MetaFileManager.Free( data, length );
|
||||
resource->SetData( ( IntPtr )newData, Length );
|
||||
}
|
||||
}
|
||||
|
|
@ -119,9 +119,9 @@ public partial class MetaManager
|
|||
{
|
||||
foreach( var file in _imcFiles.Values )
|
||||
{
|
||||
Penumbra.MetaFileManager.ResetByFile( file );
|
||||
file.Dispose();
|
||||
}
|
||||
|
||||
_imcFiles.Clear();
|
||||
_imcManipulations.Clear();
|
||||
RestoreImcDelegate();
|
||||
|
|
@ -132,7 +132,6 @@ public partial class MetaManager
|
|||
if( _imcManagerCount++ == 0 )
|
||||
{
|
||||
Penumbra.ResourceLoader.ResourceLoadCustomization += ImcLoadHandler;
|
||||
Penumbra.ResourceLoader.ResourceLoaded += ImcResourceHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +140,6 @@ public partial class MetaManager
|
|||
if( --_imcManagerCount == 0 )
|
||||
{
|
||||
Penumbra.ResourceLoader.ResourceLoadCustomization -= ImcLoadHandler;
|
||||
Penumbra.ResourceLoader.ResourceLoaded -= ImcResourceHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -163,33 +161,16 @@ public partial class MetaManager
|
|||
|
||||
var lastUnderscore = split.LastIndexOf( ( byte )'_' );
|
||||
var name = lastUnderscore == -1 ? split.ToString() : split.Substring( 0, lastUnderscore ).ToString();
|
||||
if( Penumbra.CollectionManager.ByName( name, out var collection )
|
||||
if( ( Penumbra.TempMods.Collections.TryGetValue( name, out var collection )
|
||||
|| Penumbra.CollectionManager.ByName( name, out collection ) )
|
||||
&& collection.HasCache
|
||||
&& collection.MetaCache!._imcFiles.TryGetValue( Utf8GamePath.FromSpan( path.Span, out var p ) ? p : Utf8GamePath.Empty, out var file ) )
|
||||
{
|
||||
PluginLog.Debug( "Loaded {GamePath:l} from file and replaced with IMC from collection {Collection:l}.", path,
|
||||
collection.Name );
|
||||
file.Replace( fileDescriptor->ResourceHandle, true );
|
||||
file.ChangesSinceLoad = false;
|
||||
collection.AnonymizedName );
|
||||
file.Replace( fileDescriptor->ResourceHandle );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static unsafe void ImcResourceHandler( ResourceHandle* resource, Utf8GamePath gamePath, FullPath? _2, object? resolveData )
|
||||
{
|
||||
// Only check imcs.
|
||||
if( resource->FileType != ResourceType.Imc
|
||||
|| resolveData is not ModCollection { HasCache: true } collection
|
||||
|| !collection.MetaCache!._imcFiles.TryGetValue( gamePath, out var file )
|
||||
|| !file.ChangesSinceLoad )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PluginLog.Debug( "File {GamePath:l} was already loaded but IMC in collection {Collection:l} was changed, so reloaded.", gamePath,
|
||||
collection.Name );
|
||||
file.Replace( resource, false );
|
||||
file.ChangesSinceLoad = false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue