From 12baa5135f2fe3ea437caa734a060947e413cf8f Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Mon, 10 Sep 2018 21:06:05 -0500 Subject: [PATCH] Added support for native libraries --- IPA.Injector/Injector.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/IPA.Injector/Injector.cs b/IPA.Injector/Injector.cs index 3df55ab2..2cd57b08 100644 --- a/IPA.Injector/Injector.cs +++ b/IPA.Injector/Injector.cs @@ -3,9 +3,9 @@ using IPA.Logging; using System; using System.IO; using System.Reflection; +using System.Runtime.InteropServices; using UnityEngine; using static IPA.Logging.Logger; -using Logger = IPA.Logging.Logger; namespace IPA.Injector { @@ -17,12 +17,29 @@ namespace IPA.Injector if (!injected) { injected = true; + + #region Add Library load locations AppDomain.CurrentDomain.AssemblyResolve += AssemblyLibLoader; + try + { + if (!SetDllDirectory(Path.Combine(Environment.CurrentDirectory, "Libs", "Native"))) + { + libLoader.Warn("Unable to add native library path to load path"); + } + } + catch (Exception) { } + #endregion + var bootstrapper = new GameObject("Bootstrapper").AddComponent(); bootstrapper.Destroyed += Bootstrapper_Destroyed; } } + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool SetDllDirectory(string lpPathName); + + #region Managed library loader private static string libsDir; private static Assembly AssemblyLibLoader(object source, ResolveEventArgs e) { @@ -54,6 +71,7 @@ namespace IPA.Injector { libLoader.Log(lvl, message); } + #endregion private static void Bootstrapper_Destroyed() {