diff --git a/Penumbra/Mods/ModManager.cs b/Penumbra/Mods/ModManager.cs index 55e14e42..a3280d8d 100644 --- a/Penumbra/Mods/ModManager.cs +++ b/Penumbra/Mods/ModManager.cs @@ -111,9 +111,9 @@ namespace Penumbra.Mods } - public FileInfo GetCandidateForGameFile( string resourcePath ) + public FileInfo GetCandidateForGameFile( string gameResourcePath ) { - var val = ResolvedFiles.TryGetValue( resourcePath.ToLowerInvariant(), out var candidate ); + var val = ResolvedFiles.TryGetValue( gameResourcePath, out var candidate ); if( !val ) { return null; @@ -127,9 +127,16 @@ namespace Penumbra.Mods return candidate; } - public string GetSwappedFilePath( string originalPath ) + public string GetSwappedFilePath( string gameResourcePath ) { - return SwappedFiles.TryGetValue( originalPath, out var swappedPath ) ? swappedPath : null; + return SwappedFiles.TryGetValue( gameResourcePath, out var swappedPath ) ? swappedPath : null; + } + + public string ResolveSwappedOrReplacementFilePath( string gameResourcePath ) + { + gameResourcePath = gameResourcePath.ToLowerInvariant(); + + return GetCandidateForGameFile( gameResourcePath )?.FullName ?? GetSwappedFilePath( gameResourcePath ); } } } \ No newline at end of file diff --git a/Penumbra/ResourceLoader.cs b/Penumbra/ResourceLoader.cs index efa18869..31ed1f2c 100644 --- a/Penumbra/ResourceLoader.cs +++ b/Penumbra/ResourceLoader.cs @@ -158,19 +158,15 @@ namespace Penumbra PluginLog.Log( "[GetResourceHandler] {0}", gameFsPath ); } - - var candidate = Plugin.ModManager.GetCandidateForGameFile( gameFsPath ); - var swappedFilePath = Plugin.ModManager.GetSwappedFilePath( gameFsPath ); - - var fsPath = candidate?.FullName ?? swappedFilePath; + var replacementPath = Plugin.ModManager.ResolveSwappedOrReplacementFilePath( gameFsPath ); // path must be < 260 because statically defined array length :( - if( fsPath == null || fsPath.Length >= 260 ) + if( replacementPath == null || replacementPath.Length >= 260 ) { return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown ); } - var cleanPath = fsPath.Replace( '\\', '/' ); + var cleanPath = replacementPath.Replace( '\\', '/' ); var path = Encoding.ASCII.GetBytes( cleanPath ); var bPath = stackalloc byte[path.Length + 1]; @@ -182,7 +178,7 @@ namespace Penumbra *pResourceHash = Crc32.Checksum; #if DEBUG - PluginLog.Log( "[GetResourceHandler] resolved {GamePath} to {NewPath}", gameFsPath, fsPath ); + PluginLog.Log( "[GetResourceHandler] resolved {GamePath} to {NewPath}", gameFsPath, replacementPath ); #endif return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown );