mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
Explicitly use the monomod assembly name
Not needed, but helps differentiate between a Reloaded hook a little. Also: utilize Dispose.
This commit is contained in:
parent
448ef94a0b
commit
1bc167f133
2 changed files with 20 additions and 15 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
@ -24,7 +23,6 @@ using Dalamud.Logging.Internal;
|
||||||
using Dalamud.Plugin.Internal;
|
using Dalamud.Plugin.Internal;
|
||||||
using Dalamud.Plugin.Ipc.Internal;
|
using Dalamud.Plugin.Ipc.Internal;
|
||||||
using Dalamud.Support;
|
using Dalamud.Support;
|
||||||
using MonoMod.RuntimeDetour;
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using Serilog.Core;
|
using Serilog.Core;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
|
|
@ -46,6 +44,7 @@ namespace Dalamud
|
||||||
|
|
||||||
private readonly ManualResetEvent unloadSignal;
|
private readonly ManualResetEvent unloadSignal;
|
||||||
private readonly ManualResetEvent finishUnloadSignal;
|
private readonly ManualResetEvent finishUnloadSignal;
|
||||||
|
private MonoMod.RuntimeDetour.Hook processMonoHook;
|
||||||
private bool hasDisposedPlugins = false;
|
private bool hasDisposedPlugins = false;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -358,6 +357,8 @@ namespace Dalamud
|
||||||
|
|
||||||
SerilogEventSink.Instance.LogLine -= SerilogOnLogLine;
|
SerilogEventSink.Instance.LogLine -= SerilogOnLogLine;
|
||||||
|
|
||||||
|
this.processMonoHook?.Dispose();
|
||||||
|
|
||||||
Log.Debug("Dalamud::Dispose() OK!");
|
Log.Debug("Dalamud::Dispose() OK!");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -379,6 +380,14 @@ namespace Dalamud
|
||||||
Log.Debug("Reset ExceptionFilter, old: {0}", oldFilter);
|
Log.Debug("Reset ExceptionFilter, old: {0}", oldFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void SerilogOnLogLine(object? sender, (string Line, LogEventLevel Level, DateTimeOffset TimeStamp, Exception? Exception) e)
|
||||||
|
{
|
||||||
|
if (e.Exception == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Troubleshooting.LogException(e.Exception, e.Line);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Patch method for the class Process.Handle. This patch facilitates fixing Reloaded so that it
|
/// Patch method for the class Process.Handle. This patch facilitates fixing Reloaded so that it
|
||||||
/// uses pseudo-handles to access memory, to prevent permission errors.
|
/// uses pseudo-handles to access memory, to prevent permission errors.
|
||||||
|
|
@ -400,21 +409,13 @@ namespace Dalamud
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SerilogOnLogLine(object? sender, (string Line, LogEventLevel Level, DateTimeOffset TimeStamp, Exception? Exception) e)
|
|
||||||
{
|
|
||||||
if (e.Exception == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Troubleshooting.LogException(e.Exception, e.Line);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ApplyProcessPatch()
|
private void ApplyProcessPatch()
|
||||||
{
|
{
|
||||||
var targetType = typeof(Process);
|
var targetType = typeof(Process);
|
||||||
|
|
||||||
var handleTarget = targetType.GetProperty(nameof(Process.Handle)).GetGetMethod();
|
var handleTarget = targetType.GetProperty(nameof(Process.Handle)).GetGetMethod();
|
||||||
var handlePatch = typeof(Dalamud).GetMethod(nameof(Dalamud.ProcessHandlePatch), BindingFlags.NonPublic | BindingFlags.Static);
|
var handlePatch = typeof(Dalamud).GetMethod(nameof(Dalamud.ProcessHandlePatch), BindingFlags.NonPublic | BindingFlags.Static);
|
||||||
_ = new Hook(handleTarget, handlePatch);
|
this.processMonoHook = new MonoMod.RuntimeDetour.Hook(handleTarget, handlePatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -20,7 +19,6 @@ using Dalamud.Logging.Internal;
|
||||||
using Dalamud.Plugin.Internal.Exceptions;
|
using Dalamud.Plugin.Internal.Exceptions;
|
||||||
using Dalamud.Plugin.Internal.Types;
|
using Dalamud.Plugin.Internal.Types;
|
||||||
using Dalamud.Utility;
|
using Dalamud.Utility;
|
||||||
using MonoMod.RuntimeDetour;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Dalamud.Plugin.Internal
|
namespace Dalamud.Plugin.Internal
|
||||||
|
|
@ -137,6 +135,9 @@ namespace Dalamud.Plugin.Internal
|
||||||
Log.Error(ex, $"Error disposing {plugin.Name}");
|
Log.Error(ex, $"Error disposing {plugin.Name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.assemblyLocationMonoHook?.Dispose();
|
||||||
|
this.assemblyCodeBaseMonoHook?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1063,6 +1064,9 @@ namespace Dalamud.Plugin.Internal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal partial class PluginManager
|
internal partial class PluginManager
|
||||||
{
|
{
|
||||||
|
private MonoMod.RuntimeDetour.Hook assemblyLocationMonoHook;
|
||||||
|
private MonoMod.RuntimeDetour.Hook assemblyCodeBaseMonoHook;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A mapping of plugin assembly name to patch data. Used to fill in missing data due to loading
|
/// A mapping of plugin assembly name to patch data. Used to fill in missing data due to loading
|
||||||
/// plugins via byte[].
|
/// plugins via byte[].
|
||||||
|
|
@ -1150,12 +1154,12 @@ namespace Dalamud.Plugin.Internal
|
||||||
|
|
||||||
var locationTarget = targetType.GetProperty(nameof(Assembly.Location)).GetGetMethod();
|
var locationTarget = targetType.GetProperty(nameof(Assembly.Location)).GetGetMethod();
|
||||||
var locationPatch = typeof(PluginManager).GetMethod(nameof(PluginManager.AssemblyLocationPatch), BindingFlags.NonPublic | BindingFlags.Static);
|
var locationPatch = typeof(PluginManager).GetMethod(nameof(PluginManager.AssemblyLocationPatch), BindingFlags.NonPublic | BindingFlags.Static);
|
||||||
_ = new Hook(locationTarget, locationPatch);
|
this.assemblyLocationMonoHook = new MonoMod.RuntimeDetour.Hook(locationTarget, locationPatch);
|
||||||
|
|
||||||
#pragma warning disable SYSLIB0012 // Type or member is obsolete
|
#pragma warning disable SYSLIB0012 // Type or member is obsolete
|
||||||
var codebaseTarget = targetType.GetProperty(nameof(Assembly.CodeBase)).GetGetMethod();
|
var codebaseTarget = targetType.GetProperty(nameof(Assembly.CodeBase)).GetGetMethod();
|
||||||
var codebasePatch = typeof(PluginManager).GetMethod(nameof(PluginManager.AssemblyCodeBasePatch), BindingFlags.NonPublic | BindingFlags.Static);
|
var codebasePatch = typeof(PluginManager).GetMethod(nameof(PluginManager.AssemblyCodeBasePatch), BindingFlags.NonPublic | BindingFlags.Static);
|
||||||
_ = new Hook(codebaseTarget, codebasePatch);
|
this.assemblyCodeBaseMonoHook = new MonoMod.RuntimeDetour.Hook(codebaseTarget, codebasePatch);
|
||||||
#pragma warning restore SYSLIB0012 // Type or member is obsolete
|
#pragma warning restore SYSLIB0012 // Type or member is obsolete
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue