// Do this in a separate method to not trigger cctor prematurely private static void InitializeAssemblyResolvers() { // Need to initialize interop first because it installs its own special assembly resolver HarmonyInterop.Initialize(); AppDomain.CurrentDomain.AssemblyResolve += LocalResolve; // Remove temporary resolver early so it won't override local resolver AppDomain.CurrentDomain.AssemblyResolve -= Entrypoint.ResolveCurrentDirectory; }
public static void PreloaderPreMain() { string bepinPath = Utility.ParentDirectory(Path.GetFullPath(EnvVars.DOORSTOP_INVOKE_DLL_PATH), 2); Paths.SetExecutablePath(EnvVars.DOORSTOP_PROCESS_PATH, bepinPath, EnvVars.DOORSTOP_MANAGED_FOLDER_DIR); HarmonyInterop.Initialize(); AppDomain.CurrentDomain.AssemblyResolve += LocalResolve; // Remove temporary resolver early so it won't override local resolver AppDomain.CurrentDomain.AssemblyResolve -= Entrypoint.ResolveCurrentDirectory; PreloaderMain(); }
public void Apply() { PatchMethod[] ToPatchMethod(Patch[] patches) { return(patches.Select(p => new PatchMethod { after = p.after, before = p.before, method = p.patch, priority = p.priority, owner = p.owner, }).ToArray()); } var info = HarmonySharedState.GetPatchInfo(mb); var state = new PatchInfoWrapper { prefixes = ToPatchMethod(info.prefixes), postfixes = ToPatchMethod(info.postfixes), transpilers = ToPatchMethod(info.transpilers), finalizers = new PatchMethod[0] }; var add = new PatchInfoWrapper { finalizers = new PatchMethod[0] }; var remove = new PatchInfoWrapper { finalizers = new PatchMethod[0] }; Diff(previousState.prefixes, state.prefixes, out add.prefixes, out remove.prefixes); Diff(previousState.postfixes, state.postfixes, out add.postfixes, out remove.postfixes); Diff(previousState.transpilers, state.transpilers, out add.transpilers, out remove.transpilers); previousState = state; HarmonyInterop.ApplyPatch(mb, add, remove); }