From 055399a7e7acfeed5f5d3b1ea32144733ec85619 Mon Sep 17 00:00:00 2001 From: Adam <893184+NotAdam@users.noreply.github.com> Date: Sat, 26 Dec 2020 13:59:21 +1100 Subject: [PATCH] fix utf16 paths (se why???) and probably make ttmp importing more better --- Penumbra/ResourceLoader.cs | 20 ++++++++++---------- Penumbra/UI/SettingsInterface.cs | 17 ++++++++++------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Penumbra/ResourceLoader.cs b/Penumbra/ResourceLoader.cs index ee4ccdb5..efa18869 100644 --- a/Penumbra/ResourceLoader.cs +++ b/Penumbra/ResourceLoader.cs @@ -162,27 +162,27 @@ namespace Penumbra var candidate = Plugin.ModManager.GetCandidateForGameFile( gameFsPath ); var swappedFilePath = Plugin.ModManager.GetSwappedFilePath( gameFsPath ); - var path = candidate?.FullName ?? swappedFilePath; + var fsPath = candidate?.FullName ?? swappedFilePath; // path must be < 260 because statically defined array length :( - if( path == null || path.Length >= 260 ) + if( fsPath == null || fsPath.Length >= 260 ) { return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown ); } - var cleanPath = path.Replace( '\\', '/' ); - var utfPath = Encoding.UTF8.GetBytes( cleanPath ); + var cleanPath = fsPath.Replace( '\\', '/' ); + var path = Encoding.ASCII.GetBytes( cleanPath ); - var bPath = stackalloc byte[utfPath.Length + 1]; - Marshal.Copy( utfPath, 0, new IntPtr( bPath ), utfPath.Length ); + var bPath = stackalloc byte[path.Length + 1]; + Marshal.Copy( path, 0, new IntPtr( bPath ), path.Length ); pPath = ( char* )bPath; Crc32.Init(); - Crc32.Update( utfPath ); + Crc32.Update( path ); *pResourceHash = Crc32.Checksum; #if DEBUG - PluginLog.Log( "[GetResourceHandler] resolved {GamePath} to {NewPath}", gameFsPath, path ); + PluginLog.Log( "[GetResourceHandler] resolved {GamePath} to {NewPath}", gameFsPath, fsPath ); #endif return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown ); @@ -206,7 +206,8 @@ namespace Penumbra pFileDesc->FileMode = FileMode.LoadUnpackedResource; - var utfPath = Encoding.UTF8.GetBytes( gameFsPath ); + // note: must be utf16 + var utfPath = Encoding.Unicode.GetBytes( gameFsPath ); Marshal.Copy( utfPath, 0, new IntPtr( &pFileDesc->UtfFileName ), utfPath.Length ); @@ -215,7 +216,6 @@ namespace Penumbra pFileDesc->FileDescriptor = fd; - return ReadFile( pFileHandler, pFileDesc, priority, isSync ); } diff --git a/Penumbra/UI/SettingsInterface.cs b/Penumbra/UI/SettingsInterface.cs index 1231ee19..a89add44 100644 --- a/Penumbra/UI/SettingsInterface.cs +++ b/Penumbra/UI/SettingsInterface.cs @@ -1,6 +1,5 @@ using System; using System.Diagnostics; -using System.Drawing; using System.IO; using System.Linq; using System.Numerics; @@ -18,7 +17,7 @@ namespace Penumbra.UI { private readonly Plugin _plugin; - public bool Visible { get; set; } = true; + public bool Visible = false; private static readonly Vector2 AutoFillSize = new Vector2( -1, -1 ); private static readonly Vector2 ModListSize = new Vector2( 200, -1 ); @@ -43,9 +42,9 @@ namespace Penumbra.UI { ImGui.SetNextWindowSizeConstraints( MinSettingsSize, MaxSettingsSize ); #if DEBUG - var ret = ImGui.Begin( _plugin.PluginDebugTitleStr ); + var ret = ImGui.Begin( _plugin.PluginDebugTitleStr, ref Visible ); #else - var ret = ImGui.Begin( _plugin.Name ); + var ret = ImGui.Begin( _plugin.Name, ref Visible ); #endif if( !ret ) { @@ -55,10 +54,14 @@ namespace Penumbra.UI ImGui.BeginTabBar( "PenumbraSettings" ); DrawSettingsTab(); - DrawResourceMods(); - DrawEffectiveFileList(); - DrawDeleteModal(); + if( !_isImportRunning ) + { + DrawResourceMods(); + DrawEffectiveFileList(); + + DrawDeleteModal(); + } ImGui.EndTabBar();