Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ui3TD authored May 14, 2023
1 parent e6ece02 commit 074b25e
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 0 deletions.
32 changes: 32 additions & 0 deletions HarmonyIntegration.csproj
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>
25 changes: 25 additions & 0 deletions HarmonyIntegration.sln
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
6 changes: 6 additions & 0 deletions NuGet.Config
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>
99 changes: 99 additions & 0 deletions Plugin.cs
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);
}
}
}
}

0 comments on commit 074b25e

Please sign in to comment.