diff --git a/Dalamud.Injector/DalamudLauncher.cs b/Dalamud.Injector/DalamudLauncher.cs
index d7e43ac4d..7acd25bba 100644
--- a/Dalamud.Injector/DalamudLauncher.cs
+++ b/Dalamud.Injector/DalamudLauncher.cs
@@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.IO.Pipes;
-using System.Text;
-using CoreHook.BinaryInjection;
using CoreHook.BinaryInjection.RemoteInjection;
using CoreHook.BinaryInjection.RemoteInjection.Configuration;
using CoreHook.IPC.Platform;
@@ -25,24 +24,55 @@ namespace Dalamud.Injector
public void Relaunch(uint pid)
{
+ // TODO
+ // 1. Open process `pid` with handle
+ // 2. Read command arguments (requires reading PEB)
+ // 3. Construct new arguments
+ // 3.1 Decrypt arguments acquired from step.2 (possible key space is very small so it's feasible to do this)
+ // 3.2 Manipulate arguments as needed
+ // 3.3 Re-encrypt arguments with new timestamp
+ // 4 Launch a new process with new argument which was computed from step.3
+ // 5 Attempt to inject into that process.
+ // 6. If all succeeded, terminate the old process.
//
+ // delegate Step 3 to 5 to Launch() maybe?
}
+ ///
+ /// Injects Dalamud into the process. See remarks for process state prerequisites.
+ ///
+ ///
+ /// TODO: CREATE_SUSPENDED -> entrypoint explainations
+ ///
+ /// A process id to inject Dalamud into.
public void Inject(uint pid)
{
-
+ // Please keep in mind that this config values (especially ClrRootPath) assumes that
+ // Dalamud is compiled as self-contained to avoid requiring people to pre-install specific .NET Core version.
+ // https://docs.microsoft.com/en-us/dotnet/core/deploying/
var corehookConfig = new RemoteInjectorConfiguration
{
- ClrBootstrapLibrary = "",
- ClrRootPath = "",
- DetourLibrary = "",
- HostLibrary = "",
- InjectionPipeName = "",
- PayloadLibrary = "",
+ InjectionPipeName = $"Dalamud-{pid}-CoreHook",
+ ClrRootPath = m_options.BinaryDirectory, // `dotnet.runtimeconfig.json` is not needed for self-contained app.
+ ClrBootstrapLibrary = Path.Combine(m_options.BinaryDirectory, "CoreHook.CoreLoad.dll"),
+ DetourLibrary = Path.Combine(m_options.BinaryDirectory, "corehook64.dll"),
+ HostLibrary = Path.Combine(m_options.BinaryDirectory, "coreload64.dll"),
+ PayloadLibrary = Path.Combine(m_options.BinaryDirectory, "Dalamud.dll"),
VerboseLog = false,
};
- RemoteInjector.Inject((int)pid, corehookConfig, new PipePlatform(), m_options.RootDirectory);
+ try
+ {
+ RemoteInjector.Inject((int)pid, corehookConfig, new PipePlatform(), m_options.RootDirectory);
+ }
+ catch (Exception ex)
+ {
+ const string message = "Failed to inject Dalamud library into the process.";
+
+ // Could not inject Dalamud for whatever reason; it could be process is not actually running, insufficient os privilege, or whatever the thing SE put in their game;
+ // Therefore there's not much we can do on this side; You have to trobleshoot by yourself somehow.
+ throw new DalamudLauncherException(pid, message, ex);
+ }
}
}
diff --git a/Dalamud.Injector/DalamudLauncherOptions.cs b/Dalamud.Injector/DalamudLauncherOptions.cs
index e8b0b26a5..27e39363a 100644
--- a/Dalamud.Injector/DalamudLauncherOptions.cs
+++ b/Dalamud.Injector/DalamudLauncherOptions.cs
@@ -12,13 +12,16 @@ namespace Dalamud.Injector
};
///
- ///
+ /// A directory to where Dalamud data is located.
///
public string RootDirectory { get; set; } = "";
///
- ///
+ /// A directory to where `Dalamud.dll` and its dependencies are located.
///
+ ///
+ /// This path doesn't need to be the same directory as where the launcher is located.
+ ///
public string BinaryDirectory { get; set; } = "";
}
}
diff --git a/Dalamud.Injector/Exceptions.cs b/Dalamud.Injector/Exceptions.cs
index 23e8dc356..5778f655d 100644
--- a/Dalamud.Injector/Exceptions.cs
+++ b/Dalamud.Injector/Exceptions.cs
@@ -1,26 +1,27 @@
using System;
-using System.Collections.Generic;
-using System.Text;
namespace Dalamud.Injector
{
- public class DalamudException : Exception
- {
- public DalamudException() : base() { }
-
- public DalamudException(string message) : base(message) { }
-
- public DalamudException(string message, Exception inner) : base(message, inner) { }
- }
-
- public partial class DalamudProcessException : DalamudException
+ ///
+ /// An error that is thrown when injecting Dalamud into the process failed.
+ ///
+ public partial class DalamudLauncherException : Exception
{
+ ///
+ /// A target process id that was attempted to.
+ ///
public uint ProcessId { get; }
}
- public partial class DalamudProcessException
+ public partial class DalamudLauncherException
{
- public DalamudProcessException(uint pid, string message) : base(message)
+ public DalamudLauncherException() : base() { }
+
+ public DalamudLauncherException(string message) : base(message) { }
+
+ public DalamudLauncherException(string message, Exception inner) : base(message, inner) { }
+
+ public DalamudLauncherException(uint pid, string message, Exception inner) : base(message, inner)
{
ProcessId = pid;
}
diff --git a/Dalamud/Dalamud.csproj b/Dalamud/Dalamud.csproj
index 9ead7d04f..a5d982e6e 100644
--- a/Dalamud/Dalamud.csproj
+++ b/Dalamud/Dalamud.csproj
@@ -1,7 +1,7 @@
Library
- net472
+ netcoreapp3.1
preview
true
enable
@@ -14,20 +14,15 @@
-
-
-
-
-
-
+
diff --git a/Dalamud/FodyWeavers.xml b/Dalamud/FodyWeavers.xml
deleted file mode 100644
index 4e68ed1a8..000000000
--- a/Dalamud/FodyWeavers.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/Dalamud/FodyWeavers.xsd b/Dalamud/FodyWeavers.xsd
deleted file mode 100644
index 2f1b8aae7..000000000
--- a/Dalamud/FodyWeavers.xsd
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
-
-
-
-
-
-
-
-
- Used to control if the On_PropertyName_Changed feature is enabled.
-
-
-
-
- Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.
-
-
-
-
- Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.
-
-
-
-
- Used to control if equality checks should use the Equals method resolved from the base class.
-
-
-
-
- Used to control if equality checks should use the static Equals method resolved from the base class.
-
-
-
-
-
-
-
- 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.
-
-
-
-
- A comma-separated list of error codes that can be safely ignored in assembly verification.
-
-
-
-
- 'false' to turn off automatic generation of the XML Schema file.
-
-
-
-
-
\ No newline at end of file