mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Temporary fix for E4S crashes.
This commit is contained in:
parent
0823423eda
commit
59fa4c4fe4
2 changed files with 343 additions and 298 deletions
|
|
@ -5,6 +5,7 @@ using System.Text;
|
|||
using System.Text.RegularExpressions;
|
||||
using Dalamud.Hooking;
|
||||
using Dalamud.Logging;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
using Penumbra.GameData.Util;
|
||||
using Penumbra.Mods;
|
||||
using Penumbra.Structs;
|
||||
|
|
@ -18,6 +19,7 @@ public class ResourceLoader : IDisposable
|
|||
public Penumbra Penumbra { get; set; }
|
||||
|
||||
public bool IsEnabled { get; set; }
|
||||
public bool HacksEnabled { get; set; }
|
||||
|
||||
public Crc32 Crc32 { get; }
|
||||
|
||||
|
|
@ -126,6 +128,29 @@ public class ResourceLoader : IDisposable
|
|||
LoadMdlFileExternHook = new Hook< LoadMdlFileExternPrototype >( loadMdlFileExternAddress, LoadMdlFileExternDetour );
|
||||
}
|
||||
|
||||
private bool CheckForTerritory()
|
||||
{
|
||||
var territory = Dalamud.GameData.GetExcelSheet< TerritoryType >()?.GetRow( Dalamud.ClientState.TerritoryType );
|
||||
var bad = territory?.Unknown40 ?? false;
|
||||
switch( bad )
|
||||
{
|
||||
case true when HacksEnabled:
|
||||
CheckFileStateHook?.Disable();
|
||||
LoadTexFileExternHook?.Disable();
|
||||
LoadMdlFileExternHook?.Disable();
|
||||
HacksEnabled = false;
|
||||
return bad;
|
||||
case false when Penumbra.Config.IsEnabled && !HacksEnabled:
|
||||
CheckFileStateHook?.Enable();
|
||||
LoadTexFileExternHook?.Enable();
|
||||
LoadMdlFileExternHook?.Enable();
|
||||
HacksEnabled = true;
|
||||
break;
|
||||
}
|
||||
|
||||
return bad;
|
||||
}
|
||||
|
||||
private static bool CheckFileStateDetour( IntPtr _, ulong _2 )
|
||||
=> true;
|
||||
|
||||
|
|
@ -198,6 +223,11 @@ public class ResourceLoader : IDisposable
|
|||
bool isUnknown
|
||||
)
|
||||
{
|
||||
if( CheckForTerritory() )
|
||||
{
|
||||
return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown );
|
||||
}
|
||||
|
||||
string file;
|
||||
var modManager = Service< ModManager >.Get();
|
||||
|
||||
|
|
@ -247,6 +277,11 @@ public class ResourceLoader : IDisposable
|
|||
|
||||
private unsafe byte ReadSqpackHandler( IntPtr pFileHandler, SeFileDescriptor* pFileDesc, int priority, bool isSync )
|
||||
{
|
||||
if( CheckForTerritory() )
|
||||
{
|
||||
return ReadSqpackHook?.Original( pFileHandler, pFileDesc, priority, isSync ) ?? 0;
|
||||
}
|
||||
|
||||
if( ReadFile == null || pFileDesc == null || pFileDesc->ResourceHandle == null )
|
||||
{
|
||||
PluginLog.Error( "THIS SHOULD NOT HAPPEN" );
|
||||
|
|
@ -286,7 +321,12 @@ public class ResourceLoader : IDisposable
|
|||
return;
|
||||
}
|
||||
|
||||
if( ReadSqpackHook == null || GetResourceSyncHook == null || GetResourceAsyncHook == null || CheckFileStateHook == null || LoadTexFileExternHook == null || LoadMdlFileExternHook == null)
|
||||
if( ReadSqpackHook == null
|
||||
|| GetResourceSyncHook == null
|
||||
|| GetResourceAsyncHook == null
|
||||
|| CheckFileStateHook == null
|
||||
|| LoadTexFileExternHook == null
|
||||
|| LoadMdlFileExternHook == null )
|
||||
{
|
||||
PluginLog.Error( "[GetResourceHandler] Could not activate hooks because at least one was not set." );
|
||||
return;
|
||||
|
|
@ -300,6 +340,7 @@ public class ResourceLoader : IDisposable
|
|||
LoadMdlFileExternHook.Enable();
|
||||
|
||||
IsEnabled = true;
|
||||
HacksEnabled = true;
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
|
|
@ -316,6 +357,7 @@ public class ResourceLoader : IDisposable
|
|||
LoadTexFileExternHook?.Disable();
|
||||
LoadMdlFileExternHook?.Disable();
|
||||
IsEnabled = false;
|
||||
HacksEnabled = false;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ using Penumbra.Mods;
|
|||
using Penumbra.UI.Custom;
|
||||
using Penumbra.Util;
|
||||
|
||||
namespace Penumbra.UI
|
||||
{
|
||||
namespace Penumbra.UI;
|
||||
|
||||
public partial class SettingsInterface
|
||||
{
|
||||
private static void DrawDebugTabPlayers()
|
||||
|
|
@ -128,7 +128,7 @@ namespace Penumbra.UI
|
|||
ImGui.Text( value );
|
||||
}
|
||||
|
||||
private static void DrawDebugTabGeneral()
|
||||
private void DrawDebugTabGeneral()
|
||||
{
|
||||
if( !ImGui.CollapsingHeader( "General##Debug" ) )
|
||||
{
|
||||
|
|
@ -155,13 +155,17 @@ namespace Penumbra.UI
|
|||
PrintValue( "Mod Manager BasePath", manager.BasePath?.Name ?? "NULL" );
|
||||
PrintValue( "Mod Manager BasePath-Full", manager.BasePath?.FullName ?? "NULL" );
|
||||
PrintValue( "Mod Manager BasePath IsRooted", Path.IsPathRooted( Penumbra.Config.ModDirectory ).ToString() );
|
||||
PrintValue( "Mod Manager BasePath Exists", manager.BasePath != null ? Directory.Exists( manager.BasePath.FullName ).ToString() : false.ToString() );
|
||||
PrintValue( "Mod Manager BasePath Exists",
|
||||
manager.BasePath != null ? Directory.Exists( manager.BasePath.FullName ).ToString() : false.ToString() );
|
||||
PrintValue( "Mod Manager Valid", manager.Valid.ToString() );
|
||||
PrintValue( "Mod Manager Temp Path", manager.TempPath?.FullName ?? "NULL" );
|
||||
PrintValue( "Mod Manager Temp Path IsRooted",
|
||||
( !Penumbra.Config.TempDirectory.Any() || Path.IsPathRooted( Penumbra.Config.TempDirectory ) ).ToString() );
|
||||
PrintValue( "Mod Manager Temp Path Exists", manager.TempPath != null ? Directory.Exists( manager.TempPath.FullName ).ToString() : false.ToString() );
|
||||
PrintValue( "Mod Manager Temp Path Exists",
|
||||
manager.TempPath != null ? Directory.Exists( manager.TempPath.FullName ).ToString() : false.ToString() );
|
||||
PrintValue( "Mod Manager Temp Path IsWritable", manager.TempWritable.ToString() );
|
||||
PrintValue( "Resource Loader Enabled", _penumbra.ResourceLoader.IsEnabled.ToString() );
|
||||
PrintValue( "Resource Loader Hacks Enabled", _penumbra.ResourceLoader.HacksEnabled.ToString() );
|
||||
}
|
||||
|
||||
private void DrawDebugTabRedraw()
|
||||
|
|
@ -406,4 +410,3 @@ namespace Penumbra.UI
|
|||
ImGui.NewLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue