Skip to content

Commit

Permalink
Update Plugin.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
ui3TD authored May 15, 2023
1 parent a53fcf9 commit 39b8556
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions source/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using BepInEx;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using System.IO;
using System.Reflection;
using SimpleJSON;

namespace HarmonyIntegration
{
Expand Down Expand Up @@ -34,21 +35,26 @@ static void Postfix()
string modDir = mod.Path;
string modName = mod.ModName;
string modTitle = mod.Title;
var patchFile = Path.Combine(modDir.TrimEnd(new char[] { Path.DirectorySeparatorChar }), "patch.dll");

if (File.Exists(patchFile))
string modInfoFile = Path.Combine(modDir.TrimEnd(new char[] { Path.DirectorySeparatorChar }), "info.json");
JSONNode modInfo = mainScript.ProcessInboundData(File.ReadAllText(modInfoFile));
string modHarmonyID = modInfo["HarmonyID"];

var patchFile = Path.Combine(modDir.TrimEnd(new char[] { Path.DirectorySeparatorChar }), modHarmonyID + ".dll");

if (modHarmonyID != null && File.Exists(patchFile))
{
if (mod.Enabled)
{
var patchDll = Assembly.LoadFrom(patchFile);
var harmony = new Harmony(modName);
harmony.PatchAll(patchDll);
Plugin.Log.LogInfo($"Mod patch has been loaded: " + modTitle);
Assembly patchDll = Assembly.LoadFrom(patchFile);

Harmony.CreateAndPatchAll(patchDll, modHarmonyID);

Plugin.Log.LogInfo($"Mod patch loaded: " + patchDll.FullName);
}
else
{
Harmony.UnpatchID(modName);
Plugin.Log.LogInfo($"Mod patch has been unloaded: " + modTitle);
Plugin.Log.LogInfo($"Mod patch not enabled: " + modTitle);
}
}
else
Expand All @@ -73,21 +79,26 @@ static void Postfix(string ModName)
string modDir = mod.Path;
string modTitle = mod.Title;
Plugin.Log.LogInfo($"modDir: " + modDir);
var patchFile = Path.Combine(modDir.TrimEnd(new char[] { Path.DirectorySeparatorChar }), "patch.dll");

if (File.Exists(patchFile))
string modInfoFile = Path.Combine(modDir.TrimEnd(new char[] { Path.DirectorySeparatorChar }), "info.json");
JSONNode modInfo = mainScript.ProcessInboundData(File.ReadAllText(modInfoFile));
string modHarmonyID = modInfo["HarmonyID"];

var patchFile = Path.Combine(modDir.TrimEnd(new char[] { Path.DirectorySeparatorChar }), modHarmonyID + ".dll");

if (modHarmonyID != null && File.Exists(patchFile))
{
if (mod.Enabled)
{
var patchDll = Assembly.LoadFrom(patchFile);
var harmony = new Harmony(ModName);
harmony.PatchAll(patchDll);
Plugin.Log.LogInfo($"Mod patch has been loaded: " + modTitle);
Harmony.CreateAndPatchAll(patchDll, modHarmonyID);

Plugin.Log.LogInfo($"Mod patch loaded: " + patchDll.FullName);
}
else
{
Harmony.UnpatchID(ModName);
Plugin.Log.LogInfo($"Mod patch has been unloaded: " + modTitle);
Harmony.UnpatchID(modHarmonyID);
Plugin.Log.LogInfo($"Mod patch unloaded: " + modHarmonyID);
}
}
else
Expand Down

0 comments on commit 39b8556

Please sign in to comment.