-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added BepInEx.SuppressGetTypesErrorsPatcher
- Loading branch information
1 parent
3a08eab
commit 7967ac7
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
BepInEx.SuppressGetTypesErrors/BepInEx.SuppressGetTypesErrorsPatcher.csproj
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,63 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{F2A30C40-4073-45AC-8325-E255BD2B011D}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>BepInEx</RootNamespace> | ||
<AssemblyName>BepInEx.SuppressGetTypesErrorsPatcher</AssemblyName> | ||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>true</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>embedded</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>..\bin\BepInEx\patchers\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>embedded</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>..\bin\BepInEx\patchers\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<DebugSymbols>true</DebugSymbols> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="0Harmony"> | ||
<HintPath>..\lib\0Harmony.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="BepInEx"> | ||
<HintPath>..\lib\BepInEx.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="Mono.Cecil"> | ||
<HintPath>..\lib\Mono.Cecil.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="UnityEngine"> | ||
<HintPath>..\lib\UnityEngine.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="SuppressGetTypesErrorsPatcher.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</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,15 @@ | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
using static BepInEx.SuppressGetTypesErrorsPatcher; | ||
|
||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("https://github.com/BepInEx/BepInEx.Utility")] | ||
[assembly: AssemblyCopyright("Copyright 2021")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
[assembly: ComVisible(false)] | ||
[assembly: AssemblyTitle(GUID)] | ||
[assembly: AssemblyProduct(GUID)] | ||
[assembly: AssemblyDescription(PluginName)] | ||
[assembly: AssemblyVersion(Version)] | ||
[assembly: AssemblyFileVersion(Version)] |
43 changes: 43 additions & 0 deletions
43
BepInEx.SuppressGetTypesErrors/SuppressGetTypesErrorsPatcher.cs
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,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using BepInEx.Bootstrap; | ||
using HarmonyLib; | ||
using Mono.Cecil; | ||
|
||
namespace BepInEx | ||
{ | ||
public static class SuppressGetTypesErrorsPatcher | ||
{ | ||
public const string GUID = "BepInEx.SuppressGetTypesErrorsPatcher"; | ||
public const string PluginName = "Suppress Type.GetTypes Errors"; | ||
public const string Version = "1.0"; | ||
|
||
// Needed to be a valid patcher | ||
public static IEnumerable<string> TargetDLLs { get; } = Enumerable.Empty<string>(); | ||
|
||
// Needed to be a valid patcher | ||
public static void Patch(AssemblyDefinition assembly) { } | ||
|
||
public static void Finish() | ||
{ | ||
// Need to run this in finalizer after all assemblies are patched or we might patch an assembly that gets replaced later | ||
Harmony.CreateAndPatchAll(typeof(SuppressGetTypesErrorsPatcher), GUID); | ||
} | ||
|
||
[HarmonyPatch(typeof(Assembly), nameof(Assembly.GetTypes), new Type[0])] | ||
[HarmonyFinalizer] | ||
public static void HandleReflectionTypeLoad(ref Exception __exception, ref Type[] __result) | ||
{ | ||
if (__exception == null) | ||
return; | ||
if (__exception is ReflectionTypeLoadException re) | ||
{ | ||
__exception = null; | ||
__result = re.Types.Where(t => t != null).ToArray(); | ||
UnityEngine.Debug.Log($"Encountered ReflectionTypeLoadException which was suppressed. Full error: \n${TypeLoader.TypeLoadExceptionToString(re)}"); | ||
} | ||
} | ||
} | ||
} |
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