Moved the IsEnabled check from computing effective file list to the hook.

This commit is contained in:
Ottermandias 2021-01-28 11:24:08 +01:00
parent 7e51e663ec
commit b987fe53cb
3 changed files with 21 additions and 22 deletions

View file

@ -108,9 +108,6 @@ namespace Penumbra.Mods
{ {
ResolvedFiles.Clear(); ResolvedFiles.Clear();
SwappedFiles.Clear(); SwappedFiles.Clear();
if (!_plugin.Configuration.IsEnabled)
return;
var registeredFiles = new Dictionary< string, string >(); var registeredFiles = new Dictionary< string, string >();

View file

@ -127,30 +127,33 @@ namespace Penumbra
if( LogAllFiles ) if( LogAllFiles )
{ {
PluginLog.Log( "[GetResourceHandler] {0}", gameFsPath ); PluginLog.Log( "[GetResourceHandler] {0}", gameFsPath );
} }
if (Plugin.Configuration.IsEnabled)
{
var replacementPath = Plugin.ModManager.ResolveSwappedOrReplacementFilePath( gameFsPath );
var replacementPath = Plugin.ModManager.ResolveSwappedOrReplacementFilePath( gameFsPath ); // path must be < 260 because statically defined array length :(
if( replacementPath == null || replacementPath.Length >= 260 )
{
return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown );
}
// path must be < 260 because statically defined array length :( var cleanPath = replacementPath.Replace( '\\', '/' );
if( replacementPath == null || replacementPath.Length >= 260 ) var path = Encoding.ASCII.GetBytes( cleanPath );
{
return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown );
}
var cleanPath = replacementPath.Replace( '\\', '/' ); var bPath = stackalloc byte[path.Length + 1];
var path = Encoding.ASCII.GetBytes( cleanPath ); Marshal.Copy( path, 0, new IntPtr( bPath ), path.Length );
pPath = ( char* )bPath;
var bPath = stackalloc byte[path.Length + 1]; Crc32.Init();
Marshal.Copy( path, 0, new IntPtr( bPath ), path.Length ); Crc32.Update( path );
pPath = ( char* )bPath; *pResourceHash = Crc32.Checksum;
Crc32.Init();
Crc32.Update( path );
*pResourceHash = Crc32.Checksum;
#if DEBUG #if DEBUG
PluginLog.Log( "[GetResourceHandler] resolved {GamePath} to {NewPath}", gameFsPath, replacementPath ); PluginLog.Log( "[GetResourceHandler] resolved {GamePath} to {NewPath}", gameFsPath, replacementPath );
#endif #endif
}
return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown ); return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown );
} }

View file

@ -63,7 +63,6 @@ namespace Penumbra.UI
if( ImGui.Checkbox( LabelEnabled, ref enabled ) ) if( ImGui.Checkbox( LabelEnabled, ref enabled ) )
{ {
_config.IsEnabled = enabled; _config.IsEnabled = enabled;
_base.ReloadMods();
_configChanged = true; _configChanged = true;
} }
} }