-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppress harmony warnings when checking for optional methods and types
- Loading branch information
Showing
3 changed files
with
49 additions
and
8 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,13 @@ | ||
using HarmonyLib; | ||
using System; | ||
using Tobey.UnityAudio.Utilities; | ||
|
||
namespace Tobey.UnityAudio.ExtensionMethods; | ||
internal static class TraverseExtensions | ||
{ | ||
public static Traverse OptionalMethod(this Traverse traverse, string name, params object[] arguments) => | ||
TraverseHelper.SuppressHarmonyWarnings(() => traverse.Method(name, arguments)); | ||
|
||
public static Traverse OptionalMethod(this Traverse traverse, string name, Type[] paramTypes, params object[] arguments) => | ||
TraverseHelper.SuppressHarmonyWarnings(() => traverse.Method(name, paramTypes, arguments)); | ||
} |
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
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,24 @@ | ||
using HarmonyLib; | ||
using HarmonyLib.Tools; | ||
using System; | ||
|
||
namespace Tobey.UnityAudio.Utilities; | ||
internal static class TraverseHelper | ||
{ | ||
public static T SuppressHarmonyWarnings<T>(Func<T> fn) | ||
{ | ||
var initialFilter = Logger.ChannelFilter; | ||
Logger.ChannelFilter &= ~Logger.LogChannel.Warn; | ||
try | ||
{ | ||
return fn(); | ||
} | ||
finally | ||
{ | ||
Logger.ChannelFilter = initialFilter; | ||
} | ||
} | ||
|
||
public static Traverse CreateWithOptionalType(string name) => | ||
SuppressHarmonyWarnings(() => Traverse.CreateWithType(name)); | ||
} |