Skip to content

Commit

Permalink
Modernized modloader, make it actually replace patched assemblies
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmuscaria committed Feb 8, 2024
1 parent b398807 commit e5f7c07
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 32 deletions.
12 changes: 0 additions & 12 deletions modloader/Doorstop/Doorstop.cs

This file was deleted.

15 changes: 0 additions & 15 deletions modloader/Doorstop/Doorstop.csproj

This file was deleted.

Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions modloader/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>
48 changes: 48 additions & 0 deletions modloader/Plugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Mono.Cecil;

namespace modloader
{
public static class Patcher
{
public static IEnumerable<string> TargetDLLs => GetDLLs();

public static IEnumerable<string> GetDLLs()
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Path.Combine(Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path)), "replace");

if (Directory.Exists(path))
{
foreach (string assembly in Directory.GetFiles(path, "*.dll", SearchOption.TopDirectoryOnly))
{
Console.WriteLine("Found Assembly replacement at " + assembly);
string fileName = Path.GetFileName(assembly);
yield return fileName;
}
}
}

// Patches the assemblies
public static void Patch(ref AssemblyDefinition assembly)
{
Console.WriteLine("Replacing " + assembly.FullName);

string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Path.Combine(Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path)), "replace");
if (Directory.Exists(path))
{
assembly = AssemblyDefinition.ReadAssembly(Path.Combine(path, assembly.Name.Name + ".dll"));
}
else
{
Console.WriteLine("Replacment path is gone??? No game Assembles will be patched!");
}
}
}
}
22 changes: 22 additions & 0 deletions modloader/modloader.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<AssemblyName>modloader</AssemblyName>
<Description>My first plugin</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="UnityEngine.Modules" Version="5.3.4" IncludeAssets="compile" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>
</Project>
19 changes: 14 additions & 5 deletions modloader/modloader.sln
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Doorstop", "Doorstop\Doorstop.csproj", "{ED48B984-7FF8-4BED-9C31-9110F3FB3A4B}"
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "modloader", "modloader.csproj", "{E4FAB302-FC55-4F05-81DE-B43652B4AA13}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ED48B984-7FF8-4BED-9C31-9110F3FB3A4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED48B984-7FF8-4BED-9C31-9110F3FB3A4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED48B984-7FF8-4BED-9C31-9110F3FB3A4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED48B984-7FF8-4BED-9C31-9110F3FB3A4B}.Release|Any CPU.Build.0 = Release|Any CPU
{E4FAB302-FC55-4F05-81DE-B43652B4AA13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4FAB302-FC55-4F05-81DE-B43652B4AA13}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4FAB302-FC55-4F05-81DE-B43652B4AA13}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4FAB302-FC55-4F05-81DE-B43652B4AA13}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1F587C02-7DCD-4A3A-8F81-A54ABCCB9808}
EndGlobalSection
EndGlobal

0 comments on commit e5f7c07

Please sign in to comment.