-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net46</TargetFramework> | ||
<AssemblyName>HarmonyIntegration</AssemblyName> | ||
<Description>Integrates Harmony into Idol Manager using BepInEx</Description> | ||
<Version>1.0.0</Version> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" /> | ||
<PackageReference Include="BepInEx.Core" Version="5.*" /> | ||
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" /> | ||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net46" Version="1.0.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="UnityEngine.Modules" Version="2019.4.23" IncludeAssets="compile" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'"> | ||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="Assembly-CSharp"> | ||
<HintPath>dll\Assembly-CSharp.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.3.32929.385 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HarmonyIntegration", "HarmonyIntegration.csproj", "{1D84DDF3-1E75-4677-9C68-0F9610FEA36D}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1D84DDF3-1E75-4677-9C68-0F9610FEA36D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1D84DDF3-1E75-4677-9C68-0F9610FEA36D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1D84DDF3-1E75-4677-9C68-0F9610FEA36D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1D84DDF3-1E75-4677-9C68-0F9610FEA36D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {7EAB1F1A-A406-4069-A4D1-31FD6ECC247C} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<add key="BepInEx" value="https://nuget.bepinex.dev/v3/index.json" /> | ||
</packageSources> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using BepInEx; | ||
using BepInEx.Logging; | ||
using HarmonyLib; | ||
using System.IO; | ||
using System.Reflection; | ||
|
||
namespace HarmonyIntegration | ||
{ | ||
[BepInPlugin("com.name.HarmonyIntegration", "HarmonyIntegration", "1.0.0")] | ||
public class Plugin : BaseUnityPlugin | ||
{ | ||
private void Awake() | ||
{ | ||
Log = Logger; | ||
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!"); | ||
|
||
var harmony = new Harmony("com.name.HarmonyIntegration"); | ||
harmony.PatchAll(); | ||
} | ||
|
||
public static ManualLogSource Log; | ||
|
||
} | ||
|
||
[HarmonyPatch(typeof(Mods), "ReEnableMods")] | ||
public class Mods_ReEnableMods_P | ||
{ | ||
static void Postfix() | ||
{ | ||
Plugin.Log.LogInfo($"Postfix Injected Successfully."); | ||
foreach (Mods._mod mod in Mods._Mods) | ||
{ | ||
mod.Enabled = staticVars.Settings.IsModEnabled(mod.ModName); | ||
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)) | ||
{ | ||
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); | ||
} | ||
else | ||
{ | ||
Harmony.UnpatchID(modName); | ||
Plugin.Log.LogInfo($"Mod patch has been unloaded: " + modTitle); | ||
} | ||
} | ||
else | ||
{ | ||
Plugin.Log.LogInfo($"No patch found: " + modTitle); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
[HarmonyPatch(typeof(staticVars._settings), "SwitchModStatus")] | ||
public class StaticVars__settings_SwitchModStatus_P | ||
{ | ||
static void Postfix(string ModName) | ||
{ | ||
Plugin.Log.LogInfo($"Postfix Injected Successfully."); | ||
Plugin.Log.LogInfo($"ModName: " + ModName); | ||
Mods._mod mod = Mods.GetMod(ModName); | ||
|
||
mod.Enabled = staticVars.Settings.IsModEnabled(mod.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)) | ||
{ | ||
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); | ||
} | ||
else | ||
{ | ||
Harmony.UnpatchID(ModName); | ||
Plugin.Log.LogInfo($"Mod patch has been unloaded: " + modTitle); | ||
} | ||
} | ||
else | ||
{ | ||
Plugin.Log.LogInfo($"No patch found: " + modTitle); | ||
} | ||
} | ||
} | ||
} |