mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
fix: network sig, some installer bugs
This commit is contained in:
parent
558aa6ec16
commit
15d340d0ed
5 changed files with 105 additions and 28 deletions
39
Dalamud/Game/Internal/AntiDebug.cs
Normal file
39
Dalamud/Game/Internal/AntiDebug.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Dalamud.Hooking;
|
||||||
|
using EasyHook;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
|
namespace Dalamud.Game.Internal
|
||||||
|
{
|
||||||
|
class AntiDebug : IDisposable
|
||||||
|
{
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||||
|
private delegate bool IsDebuggerPresentDelegate();
|
||||||
|
|
||||||
|
private Hook<IsDebuggerPresentDelegate> debuggerPresentHook;
|
||||||
|
|
||||||
|
public AntiDebug() {
|
||||||
|
this.debuggerPresentHook = new Hook<IsDebuggerPresentDelegate>(LocalHook.GetProcAddress("Kernel32", "IsDebuggerPresent"),
|
||||||
|
new IsDebuggerPresentDelegate(IsDebuggerPresentDetour));
|
||||||
|
|
||||||
|
Log.Verbose("IsDebuggerPresent address {IsDebuggerPresent}", this.debuggerPresentHook.Address);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Enable() {
|
||||||
|
this.debuggerPresentHook.Enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
this.debuggerPresentHook.Disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsDebuggerPresentDetour() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -43,6 +43,8 @@ namespace Dalamud.Game.Internal {
|
||||||
|
|
||||||
public LibcFunction Libc { get; private set; }
|
public LibcFunction Libc { get; private set; }
|
||||||
|
|
||||||
|
private AntiDebug antiDebug;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public Framework(SigScanner scanner, Dalamud dalamud) {
|
public Framework(SigScanner scanner, Dalamud dalamud) {
|
||||||
|
|
@ -65,6 +67,8 @@ namespace Dalamud.Game.Internal {
|
||||||
Network = new GameNetwork(dalamud, scanner);
|
Network = new GameNetwork(dalamud, scanner);
|
||||||
|
|
||||||
//Resource = new ResourceManager(dalamud, scanner);
|
//Resource = new ResourceManager(dalamud, scanner);
|
||||||
|
|
||||||
|
this.antiDebug = new AntiDebug();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HookVTable() {
|
private void HookVTable() {
|
||||||
|
|
@ -81,6 +85,7 @@ namespace Dalamud.Game.Internal {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Enable() {
|
public void Enable() {
|
||||||
|
this.antiDebug.Enable();
|
||||||
Gui.Enable();
|
Gui.Enable();
|
||||||
Network.Enable();
|
Network.Enable();
|
||||||
//Resource.Enable();
|
//Resource.Enable();
|
||||||
|
|
@ -89,6 +94,7 @@ namespace Dalamud.Game.Internal {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
|
this.antiDebug.Dispose();
|
||||||
Gui.Dispose();
|
Gui.Dispose();
|
||||||
Network.Dispose();
|
Network.Dispose();
|
||||||
//Resource.Dispose();
|
//Resource.Dispose();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ namespace Dalamud.Game.Internal.Network {
|
||||||
|
|
||||||
protected override void Setup64Bit(SigScanner sig) {
|
protected override void Setup64Bit(SigScanner sig) {
|
||||||
//ProcessZonePacket = sig.ScanText("48 89 74 24 18 57 48 83 EC 50 8B F2 49 8B F8 41 0F B7 50 02 8B CE E8 ?? ?? 7A FF 0F B7 57 02 8D 42 89 3D 5F 02 00 00 0F 87 60 01 00 00 4C 8D 05");
|
//ProcessZonePacket = sig.ScanText("48 89 74 24 18 57 48 83 EC 50 8B F2 49 8B F8 41 0F B7 50 02 8B CE E8 ?? ?? 7A FF 0F B7 57 02 8D 42 89 3D 5F 02 00 00 0F 87 60 01 00 00 4C 8D 05");
|
||||||
ProcessZonePacket = sig.ScanText("48 89 74 24 18 57 48 83 EC 50 8B F2 49 8B F8 41 0F B7 50 02 8B CE E8 ?? ?? 73 FF 0F B7 57 02 8D 42 ?? 3D ?? ?? 00 00 0F 87 60 01 00 00 4C 8D 05");
|
//ProcessZonePacket = sig.ScanText("48 89 74 24 18 57 48 83 EC 50 8B F2 49 8B F8 41 0F B7 50 02 8B CE E8 ?? ?? 73 FF 0F B7 57 02 8D 42 ?? 3D ?? ?? 00 00 0F 87 60 01 00 00 4C 8D 05");
|
||||||
|
ProcessZonePacket = sig.ScanText("48 89 74 24 ?? 57 48 83 EC 50 8B FA 49 8B F0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ namespace Dalamud.Plugin
|
||||||
private string pluginDirectory;
|
private string pluginDirectory;
|
||||||
private ReadOnlyCollection<PluginDefinition> pluginMaster;
|
private ReadOnlyCollection<PluginDefinition> pluginMaster;
|
||||||
private bool errorModalDrawing = true;
|
private bool errorModalDrawing = true;
|
||||||
|
private bool errorModalOnNextFrame = false;
|
||||||
|
|
||||||
private enum PluginInstallStatus {
|
private enum PluginInstallStatus {
|
||||||
None,
|
None,
|
||||||
|
|
@ -38,7 +39,11 @@ namespace Dalamud.Plugin
|
||||||
public PluginInstallerWindow(PluginManager manager, string pluginDirectory) {
|
public PluginInstallerWindow(PluginManager manager, string pluginDirectory) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.pluginDirectory = pluginDirectory;
|
this.pluginDirectory = pluginDirectory;
|
||||||
Task.Run(CachePluginMaster).ContinueWith(t => { this.masterDownloadFailed = t.IsFaulted; });
|
Task.Run(CachePluginMaster).ContinueWith(t => {
|
||||||
|
this.masterDownloadFailed = this.masterDownloadFailed || t.IsFaulted;
|
||||||
|
this.errorModalDrawing = this.masterDownloadFailed;
|
||||||
|
this.errorModalOnNextFrame = this.masterDownloadFailed;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CachePluginMaster() {
|
private void CachePluginMaster() {
|
||||||
|
|
@ -55,28 +60,34 @@ namespace Dalamud.Plugin
|
||||||
|
|
||||||
private void InstallPlugin(PluginDefinition definition) {
|
private void InstallPlugin(PluginDefinition definition) {
|
||||||
try {
|
try {
|
||||||
var path = Path.GetTempFileName();
|
var outputDir = new DirectoryInfo(Path.Combine(this.pluginDirectory, definition.InternalName, definition.AssemblyVersion));
|
||||||
|
var dllFile = new FileInfo(Path.Combine(outputDir.FullName, $"{definition.InternalName}.dll"));
|
||||||
|
var disabledFile = new FileInfo(Path.Combine(outputDir.FullName, ".disabled"));
|
||||||
|
|
||||||
Log.Information("Downloading plugin to {0}", path);
|
if (dllFile.Exists) {
|
||||||
|
if (disabledFile.Exists)
|
||||||
|
disabledFile.Delete();
|
||||||
|
|
||||||
using var client = new WebClient();
|
this.manager.LoadPluginFromAssembly(dllFile);
|
||||||
|
this.installStatus = PluginInstallStatus.Success;
|
||||||
client.DownloadFile(PluginRepoBaseUrl + $"/plugins/{definition.InternalName}/latest.zip", path);
|
return;
|
||||||
var outputDir = Path.Combine(this.pluginDirectory, definition.InternalName);
|
|
||||||
|
|
||||||
if (File.Exists(Path.Combine(outputDir, ".disabled"))) {
|
|
||||||
Log.Information("Plugin was disabled, re-enabling.");
|
|
||||||
File.Delete(Path.Combine(outputDir, ".disabled"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (outputDir.Exists)
|
||||||
|
outputDir.Delete(true);
|
||||||
|
outputDir.Create();
|
||||||
|
|
||||||
|
var path = Path.GetTempFileName();
|
||||||
|
Log.Information("Downloading plugin to {0}", path);
|
||||||
|
using var client = new WebClient();
|
||||||
|
client.DownloadFile(PluginRepoBaseUrl + $"/plugins/{definition.InternalName}/latest.zip", path);
|
||||||
|
|
||||||
Log.Information("Extracting to {0}", outputDir);
|
Log.Information("Extracting to {0}", outputDir);
|
||||||
|
|
||||||
Directory.CreateDirectory(outputDir);
|
ZipFile.ExtractToDirectory(path, outputDir.FullName);
|
||||||
|
|
||||||
ZipFile.ExtractToDirectory(path, outputDir);
|
|
||||||
|
|
||||||
this.installStatus = PluginInstallStatus.Success;
|
this.installStatus = PluginInstallStatus.Success;
|
||||||
this.manager.LoadPluginFromAssembly(new FileInfo(Path.Combine(outputDir, $"{definition.InternalName}.dll")));
|
this.manager.LoadPluginFromAssembly(dllFile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.Error(e, "Plugin download failed hard.");
|
Log.Error(e, "Plugin download failed hard.");
|
||||||
this.installStatus = PluginInstallStatus.Fail;
|
this.installStatus = PluginInstallStatus.Fail;
|
||||||
|
|
@ -129,7 +140,11 @@ namespace Dalamud.Plugin
|
||||||
{
|
{
|
||||||
this.installStatus = PluginInstallStatus.InProgress;
|
this.installStatus = PluginInstallStatus.InProgress;
|
||||||
|
|
||||||
Task.Run(() => InstallPlugin(pluginDefinition)).ContinueWith(t => { this.installStatus = t.IsFaulted ? PluginInstallStatus.Fail : this.installStatus; });
|
Task.Run(() => InstallPlugin(pluginDefinition)).ContinueWith(t => {
|
||||||
|
this.installStatus = t.IsFaulted ? PluginInstallStatus.Fail : this.installStatus;
|
||||||
|
this.errorModalDrawing = this.installStatus == PluginInstallStatus.Fail;
|
||||||
|
this.errorModalOnNextFrame = this.installStatus == PluginInstallStatus.Fail;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,21 +199,30 @@ namespace Dalamud.Plugin
|
||||||
|
|
||||||
if (ImGui.Button("test modal")) {
|
if (ImGui.Button("test modal")) {
|
||||||
this.installStatus = PluginInstallStatus.Fail;
|
this.installStatus = PluginInstallStatus.Fail;
|
||||||
|
this.errorModalDrawing = true;
|
||||||
|
this.errorModalOnNextFrame = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.Spacing();
|
ImGui.Spacing();
|
||||||
|
|
||||||
if (this.installStatus == PluginInstallStatus.Fail || this.masterDownloadFailed) {
|
|
||||||
if (ImGui.BeginPopupModal("Installer failed", ref this.errorModalDrawing, ImGuiWindowFlags.AlwaysAutoResize))
|
if (ImGui.BeginPopupModal("Installer failed", ref this.errorModalDrawing, ImGuiWindowFlags.AlwaysAutoResize))
|
||||||
{
|
{
|
||||||
ImGui.TextWrapped("The installer ran into an issue. Please restart the game and report this error on our discord.");
|
ImGui.Text("The plugin installer ran into an issue.");
|
||||||
|
ImGui.Text("Please restart the game and report this error on our discord.");
|
||||||
|
|
||||||
|
ImGui.Spacing();
|
||||||
|
|
||||||
if (ImGui.Button("OK", new Vector2(120, 40))) { ImGui.CloseCurrentPopup(); }
|
if (ImGui.Button("OK", new Vector2(120, 40))) { ImGui.CloseCurrentPopup(); }
|
||||||
|
|
||||||
ImGui.EndPopup();
|
ImGui.EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.errorModalOnNextFrame) {
|
||||||
|
ImGui.OpenPopup("Installer failed");
|
||||||
|
this.errorModalOnNextFrame = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ImGui.End();
|
ImGui.End();
|
||||||
|
|
||||||
return windowOpen;
|
return windowOpen;
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,8 @@ namespace Dalamud.Plugin
|
||||||
var thisPlugin = this.Plugins.Where(x => x.Definition != null)
|
var thisPlugin = this.Plugins.Where(x => x.Definition != null)
|
||||||
.First(x => x.Definition.InternalName == definition.InternalName);
|
.First(x => x.Definition.InternalName == definition.InternalName);
|
||||||
|
|
||||||
var outputDir = Path.Combine(this.pluginDirectory, definition.InternalName);
|
var outputDir = new DirectoryInfo(Path.Combine(this.pluginDirectory, definition.InternalName, definition.AssemblyVersion));
|
||||||
File.Create(Path.Combine(outputDir, ".disabled"));
|
File.Create(Path.Combine(outputDir.FullName, ".disabled"));
|
||||||
|
|
||||||
thisPlugin.Plugin.Dispose();
|
thisPlugin.Plugin.Dispose();
|
||||||
|
|
||||||
|
|
@ -68,9 +68,12 @@ namespace Dalamud.Plugin
|
||||||
|
|
||||||
if (type.GetInterface(interfaceType.FullName) != null)
|
if (type.GetInterface(interfaceType.FullName) != null)
|
||||||
{
|
{
|
||||||
var plugin = (IDalamudPlugin)Activator.CreateInstance(type);
|
var disabledFile = new FileInfo(Path.Combine(dllFile.Directory.FullName, ".disabled"));
|
||||||
|
|
||||||
var dalamudInterface = new DalamudPluginInterface(this.dalamud, type.Assembly.GetName().Name);
|
if (disabledFile.Exists) {
|
||||||
|
Log.Information("Plugin {0} is disabled.", dllFile.FullName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var defJsonFile = new FileInfo(Path.Combine(dllFile.Directory.FullName, $"{Path.GetFileNameWithoutExtension(dllFile.Name)}.json"));
|
var defJsonFile = new FileInfo(Path.Combine(dllFile.Directory.FullName, $"{Path.GetFileNameWithoutExtension(dllFile.Name)}.json"));
|
||||||
|
|
||||||
|
|
@ -86,8 +89,12 @@ namespace Dalamud.Plugin
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log.Information("Plugin DLL {0} has no definition.", dllFile.FullName);
|
Log.Information("Plugin DLL {0} has no definition.", dllFile.FullName);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var plugin = (IDalamudPlugin)Activator.CreateInstance(type);
|
||||||
|
|
||||||
|
var dalamudInterface = new DalamudPluginInterface(this.dalamud, type.Assembly.GetName().Name);
|
||||||
plugin.Initialize(dalamudInterface);
|
plugin.Initialize(dalamudInterface);
|
||||||
Log.Information("Loaded plugin: {0}", plugin.Name);
|
Log.Information("Loaded plugin: {0}", plugin.Name);
|
||||||
this.Plugins.Add((plugin, pluginDef));
|
this.Plugins.Add((plugin, pluginDef));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue