diff --git a/BepInEx.Core/Bootstrap/BaseChainloader.cs b/BepInEx.Core/Bootstrap/BaseChainloader.cs
index 1156817..3873100 100644
--- a/BepInEx.Core/Bootstrap/BaseChainloader.cs
+++ b/BepInEx.Core/Bootstrap/BaseChainloader.cs
@@ -23,13 +23,13 @@ namespace BepInEx.Bootstrap
///
/// List of all instances loaded via the chainloader.
///
- public Dictionary Plugins { get; } = new Dictionary();
+ public Dictionary Plugins { get; } = new();
///
/// Collection of error chainloader messages that occured during plugin loading.
/// Contains information about what certain plugins were not loaded.
///
- public List DependencyErrors { get; } = new List();
+ public List DependencyErrors { get; } = new();
public virtual void Initialize(string gameExePath = null)
{
@@ -128,13 +128,13 @@ namespace BepInEx.Bootstrap
dependencyDict.Remove(pluginInfo.Metadata.GUID);
var incompatiblePlugins = pluginInfo.Incompatibilities.Select(x => x.IncompatibilityGUID).Where(x => pluginsByGuid.ContainsKey(x)).ToArray();
- string message = $@"Could not load [{pluginInfo}] because it is incompatible with: {string.Join(", ", incompatiblePlugins)}";
+ var message = $@"Could not load [{pluginInfo}] because it is incompatible with: {string.Join(", ", incompatiblePlugins)}";
DependencyErrors.Add(message);
Logger.LogError(message);
}
else if (PluginTargetsWrongBepin(pluginInfo))
{
- string message = $@"Plugin [{pluginInfo}] targets a wrong version of BepInEx ({pluginInfo.TargettedBepInExVersion}) and might not work until you update";
+ var message = $@"Plugin [{pluginInfo}] targets a wrong version of BepInEx ({pluginInfo.TargettedBepInExVersion}) and might not work until you update";
DependencyErrors.Add(message);
Logger.LogWarning(message);
}
@@ -169,7 +169,7 @@ namespace BepInEx.Bootstrap
var missingDependencies = new List();
foreach (var dependency in plugin.Dependencies)
{
- bool IsHardDependency(BepInDependency dep)
+ static bool IsHardDependency(BepInDependency dep)
=> (dep.Flags & BepInDependency.DependencyFlags.HardDependency) != 0;
// If the dependency wasn't already processed, it's missing altogether
@@ -202,7 +202,7 @@ namespace BepInEx.Bootstrap
if (missingDependencies.Count != 0)
{
- string message = $@"Could not load [{plugin}] because it has missing dependencies: {
+ var message = $@"Could not load [{plugin}] because it has missing dependencies: {
string.Join(", ", missingDependencies.Select(s => s.VersionRange == null ? s.DependencyGUID : $"{s.DependencyGUID} ({s.VersionRange})").ToArray())
}";
DependencyErrors.Add(message);
@@ -256,7 +256,7 @@ namespace BepInEx.Bootstrap
#endregion
- private static Regex allowedGuidRegex { get; } = new Regex(@"^[a-zA-Z0-9\._\-]+$");
+ private static Regex allowedGuidRegex { get; } = new(@"^[a-zA-Z0-9\._\-]+$");
///
/// Analyzes the given type definition and attempts to convert it to a valid
diff --git a/BepInEx.Core/Bootstrap/TypeLoader.cs b/BepInEx.Core/Bootstrap/TypeLoader.cs
index 07a8baa..0803e9f 100644
--- a/BepInEx.Core/Bootstrap/TypeLoader.cs
+++ b/BepInEx.Core/Bootstrap/TypeLoader.cs
@@ -39,7 +39,6 @@ namespace BepInEx.Bootstrap
///
public List CacheItems { get; set; }
-
///
/// Timestamp of the assembly. Used to check the age of the cache.
///
@@ -61,7 +60,7 @@ namespace BepInEx.Bootstrap
///
public static readonly ReaderParameters ReaderParameters;
- public static HashSet SearchDirectories = new HashSet();
+ public static HashSet SearchDirectories = new();
static TypeLoader()
{
@@ -81,13 +80,7 @@ namespace BepInEx.Bootstrap
Utility.TryResolveDllAssembly(name, Paths.ManagedPath, ReaderParameters, out assembly))
return assembly;
- foreach (var dir in SearchDirectories)
- {
- if (Utility.TryResolveDllAssembly(name, dir, ReaderParameters, out assembly))
- return assembly;
- }
-
- return AssemblyResolve?.Invoke(sender, reference);
+ return SearchDirectories.Any(dir => Utility.TryResolveDllAssembly(name, dir, ReaderParameters, out assembly)) ? assembly : AssemblyResolve?.Invoke(sender, reference);
}
///
diff --git a/BepInEx.Core/Configuration/ConfigDescription.cs b/BepInEx.Core/Configuration/ConfigDescription.cs
index 2ed734e..5ca1ae4 100644
--- a/BepInEx.Core/Configuration/ConfigDescription.cs
+++ b/BepInEx.Core/Configuration/ConfigDescription.cs
@@ -38,6 +38,6 @@ namespace BepInEx.Configuration
///
/// An empty description.
///
- public static ConfigDescription Empty { get; } = new ConfigDescription("");
+ public static ConfigDescription Empty { get; } = new("");
}
}
diff --git a/BepInEx.Core/Configuration/ConfigFile.cs b/BepInEx.Core/Configuration/ConfigFile.cs
index df5e3f9..857313b 100644
--- a/BepInEx.Core/Configuration/ConfigFile.cs
+++ b/BepInEx.Core/Configuration/ConfigFile.cs
@@ -21,9 +21,9 @@ namespace BepInEx.Configuration
///
/// All config entries inside
///
- protected Dictionary Entries { get; } = new Dictionary();
+ protected Dictionary Entries { get; } = new();
- private Dictionary OrphanedEntries { get; } = new Dictionary();
+ private Dictionary OrphanedEntries { get; } = new();
///
/// Create a list with all config entries inside of this config file.
@@ -92,7 +92,7 @@ namespace BepInEx.Configuration
#region Save/Load
- private readonly object _ioLock = new object();
+ private readonly object _ioLock = new();
///
/// Reloads the config from disk. Unsaved changes are lost.
diff --git a/BepInEx.Core/Configuration/TomlTypeConverter.cs b/BepInEx.Core/Configuration/TomlTypeConverter.cs
index c2a990f..b4616ce 100644
--- a/BepInEx.Core/Configuration/TomlTypeConverter.cs
+++ b/BepInEx.Core/Configuration/TomlTypeConverter.cs
@@ -16,7 +16,7 @@ namespace BepInEx.Configuration
// Don't put anything from UnityEngine here or it will break preloader, use LazyTomlConverterLoader instead
private static Dictionary TypeConverters { get; } = new Dictionary
{
- [typeof(string)] = new TypeConverter
+ [typeof(string)] = new()
{
ConvertToString = (obj, type) => Escape((string)obj),
ConvertToObject = (str, type) =>
@@ -27,12 +27,12 @@ namespace BepInEx.Configuration
return Unescape(str);
},
},
- [typeof(bool)] = new TypeConverter
+ [typeof(bool)] = new()
{
ConvertToString = (obj, type) => obj.ToString().ToLowerInvariant(),
ConvertToObject = (str, type) => bool.Parse(str),
},
- [typeof(byte)] = new TypeConverter
+ [typeof(byte)] = new()
{
ConvertToString = (obj, type) => obj.ToString(),
ConvertToObject = (str, type) => byte.Parse(str),
@@ -40,42 +40,42 @@ namespace BepInEx.Configuration
//integral types
- [typeof(sbyte)] = new TypeConverter
+ [typeof(sbyte)] = new()
{
ConvertToString = (obj, type) => obj.ToString(),
ConvertToObject = (str, type) => sbyte.Parse(str),
},
- [typeof(byte)] = new TypeConverter
+ [typeof(byte)] = new()
{
ConvertToString = (obj, type) => obj.ToString(),
ConvertToObject = (str, type) => byte.Parse(str),
},
- [typeof(short)] = new TypeConverter
+ [typeof(short)] = new()
{
ConvertToString = (obj, type) => obj.ToString(),
ConvertToObject = (str, type) => short.Parse(str),
},
- [typeof(ushort)] = new TypeConverter
+ [typeof(ushort)] = new()
{
ConvertToString = (obj, type) => obj.ToString(),
ConvertToObject = (str, type) => ushort.Parse(str),
},
- [typeof(int)] = new TypeConverter
+ [typeof(int)] = new()
{
ConvertToString = (obj, type) => obj.ToString(),
ConvertToObject = (str, type) => int.Parse(str),
},
- [typeof(uint)] = new TypeConverter
+ [typeof(uint)] = new()
{
ConvertToString = (obj, type) => obj.ToString(),
ConvertToObject = (str, type) => uint.Parse(str),
},
- [typeof(long)] = new TypeConverter
+ [typeof(long)] = new()
{
ConvertToString = (obj, type) => obj.ToString(),
ConvertToObject = (str, type) => long.Parse(str),
},
- [typeof(ulong)] = new TypeConverter
+ [typeof(ulong)] = new()
{
ConvertToString = (obj, type) => obj.ToString(),
ConvertToObject = (str, type) => ulong.Parse(str),
@@ -83,17 +83,17 @@ namespace BepInEx.Configuration
//floating point types
- [typeof(float)] = new TypeConverter
+ [typeof(float)] = new()
{
ConvertToString = (obj, type) => ((float)obj).ToString(NumberFormatInfo.InvariantInfo),
ConvertToObject = (str, type) => float.Parse(str, NumberFormatInfo.InvariantInfo),
},
- [typeof(double)] = new TypeConverter
+ [typeof(double)] = new()
{
ConvertToString = (obj, type) => ((double)obj).ToString(NumberFormatInfo.InvariantInfo),
ConvertToObject = (str, type) => double.Parse(str, NumberFormatInfo.InvariantInfo),
},
- [typeof(decimal)] = new TypeConverter
+ [typeof(decimal)] = new()
{
ConvertToString = (obj, type) => ((decimal)obj).ToString(NumberFormatInfo.InvariantInfo),
ConvertToObject = (str, type) => decimal.Parse(str, NumberFormatInfo.InvariantInfo),
@@ -101,7 +101,7 @@ namespace BepInEx.Configuration
//enums are special
- [typeof(Enum)] = new TypeConverter
+ [typeof(Enum)] = new()
{
ConvertToString = (obj, type) => obj.ToString(),
ConvertToObject = (str, type) => Enum.Parse(type, str, true),
diff --git a/BepInEx.Core/Console/Unix/TtyHandler.cs b/BepInEx.Core/Console/Unix/TtyHandler.cs
index 55908b5..885d226 100644
--- a/BepInEx.Core/Console/Unix/TtyHandler.cs
+++ b/BepInEx.Core/Console/Unix/TtyHandler.cs
@@ -32,8 +32,7 @@ namespace BepInEx.Unix
internal static class TtyHandler
{
- private static readonly string[] ncursesLocations = new[]
- {
+ private static readonly string[] ncursesLocations = {
"/usr/share/terminfo",
"/etc/terminfo",
"/usr/lib/terminfo",
diff --git a/BepInEx.Core/Logging/DiskLogListener.cs b/BepInEx.Core/Logging/DiskLogListener.cs
index 2e33ae4..acf1fe5 100644
--- a/BepInEx.Core/Logging/DiskLogListener.cs
+++ b/BepInEx.Core/Logging/DiskLogListener.cs
@@ -67,7 +67,7 @@ namespace BepInEx.Logging
InstantFlushing = !delayedFlushing;
}
- public static HashSet BlacklistedSources = new HashSet();
+ public static HashSet BlacklistedSources = new();
///
public void LogEvent(object sender, LogEventArgs eventArgs)
diff --git a/BepInEx.Core/Logging/LogEventArgs.cs b/BepInEx.Core/Logging/LogEventArgs.cs
index c644e1c..d9ba684 100644
--- a/BepInEx.Core/Logging/LogEventArgs.cs
+++ b/BepInEx.Core/Logging/LogEventArgs.cs
@@ -10,17 +10,17 @@ namespace BepInEx.Logging
///
/// Logged data.
///
- public object Data { get; protected set; }
+ public object Data { get; }
///
/// Log levels for the data.
///
- public LogLevel Level { get; protected set; }
+ public LogLevel Level { get; }
///
/// Log source that emitted the log event.
///
- public ILogSource Source { get; protected set; }
+ public ILogSource Source { get; }
///
/// Creates the log event args-
diff --git a/BepInEx.Core/Logging/LogLevel.cs b/BepInEx.Core/Logging/LogLevel.cs
index 15cbf59..abc2471 100644
--- a/BepInEx.Core/Logging/LogLevel.cs
+++ b/BepInEx.Core/Logging/LogLevel.cs
@@ -81,23 +81,16 @@ namespace BepInEx.Logging
public static ConsoleColor GetConsoleColor(this LogLevel level)
{
level = GetHighestLevel(level);
-
- switch (level)
+ return level switch
{
- case LogLevel.Fatal:
- return ConsoleColor.Red;
- case LogLevel.Error:
- return ConsoleColor.DarkRed;
- case LogLevel.Warning:
- return ConsoleColor.Yellow;
- case LogLevel.Message:
- return ConsoleColor.White;
- case LogLevel.Info:
- default:
- return ConsoleColor.Gray;
- case LogLevel.Debug:
- return ConsoleColor.DarkGray;
- }
+ LogLevel.Fatal => ConsoleColor.Red,
+ LogLevel.Error => ConsoleColor.DarkRed,
+ LogLevel.Warning => ConsoleColor.Yellow,
+ LogLevel.Message => ConsoleColor.White,
+ LogLevel.Info => ConsoleColor.DarkGray,
+ LogLevel.Debug => ConsoleColor.DarkGray,
+ _ => ConsoleColor.Gray
+ };
}
}
}
\ No newline at end of file
diff --git a/BepInEx.Core/Logging/Logger.cs b/BepInEx.Core/Logging/Logger.cs
index 46abb04..8a62560 100644
--- a/BepInEx.Core/Logging/Logger.cs
+++ b/BepInEx.Core/Logging/Logger.cs
@@ -74,7 +74,7 @@ namespace BepInEx.Logging
void ICollection.Clear()
{
- foreach (var item in base.ToArray())
+ foreach (var item in ToArray())
{
((ICollection)this).Remove(item);
}
@@ -85,7 +85,7 @@ namespace BepInEx.Logging
if (item == null)
return false;
- if (!base.Contains(item))
+ if (!Contains(item))
return false;
item.LogEvent -= InternalLogEvent;
diff --git a/BepInEx.Core/Logging/StdOutLogListener.cs b/BepInEx.Core/Logging/StdOutLogListener.cs
index 09c6547..678425c 100644
--- a/BepInEx.Core/Logging/StdOutLogListener.cs
+++ b/BepInEx.Core/Logging/StdOutLogListener.cs
@@ -10,8 +10,7 @@ namespace BepInEx.Core.Logging
{
public void LogEvent(object sender, LogEventArgs eventArgs)
{
- string log = $"[{eventArgs.Level,-7}:{((ILogSource)sender).SourceName,10}] {eventArgs.Data}\r\n";
-
+ var log = $"[{eventArgs.Level,-7}:{((ILogSource)sender).SourceName,10}] {eventArgs.Data}\r\n";
ConsoleManager.StandardOutStream?.Write(log);
}
diff --git a/BepInEx.Core/Logging/TraceLogSource.cs b/BepInEx.Core/Logging/TraceLogSource.cs
index 086e289..86f97a8 100644
--- a/BepInEx.Core/Logging/TraceLogSource.cs
+++ b/BepInEx.Core/Logging/TraceLogSource.cs
@@ -11,7 +11,7 @@ namespace BepInEx.Logging
///
/// Whether Trace logs are currently being rerouted.
///
- public static bool IsListening { get; protected set; } = false;
+ public static bool IsListening { get; private set; }
private static TraceLogSource traceListener;
@@ -69,28 +69,14 @@ namespace BepInEx.Logging
///
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
{
- LogLevel level;
-
- switch (eventType)
+ var level = eventType switch
{
- case TraceEventType.Critical:
- level = LogLevel.Fatal;
- break;
- case TraceEventType.Error:
- level = LogLevel.Error;
- break;
- case TraceEventType.Warning:
- level = LogLevel.Warning;
- break;
- case TraceEventType.Information:
- level = LogLevel.Info;
- break;
- case TraceEventType.Verbose:
- default:
- level = LogLevel.Debug;
- break;
- }
-
+ TraceEventType.Critical => LogLevel.Fatal,
+ TraceEventType.Error => LogLevel.Error,
+ TraceEventType.Warning => LogLevel.Warning,
+ TraceEventType.Information => LogLevel.Info,
+ _ => LogLevel.Debug
+ };
LogSource.Log(level, $"{message}".Trim());
}
}
diff --git a/BepInEx.Core/Utility.cs b/BepInEx.Core/Utility.cs
index e8384ec..f4c85ba 100644
--- a/BepInEx.Core/Utility.cs
+++ b/BepInEx.Core/Utility.cs
@@ -129,14 +129,14 @@ namespace BepInEx
/// Thrown when a cyclic dependency occurs.
public static IEnumerable TopologicalSort(IEnumerable nodes, Func> dependencySelector)
{
- List sorted_list = new List();
+ var sorted_list = new List();
- HashSet visited = new HashSet();
- HashSet sorted = new HashSet();
+ var visited = new HashSet();
+ var sorted = new HashSet();
foreach (TNode input in nodes)
{
- Stack currentStack = new Stack();
+ var currentStack = new Stack();
if (!Visit(input, currentStack))
{
throw new Exception("Cyclic Dependency:\r\n" + currentStack.Select(x => $" - {x}") //append dashes
@@ -159,13 +159,9 @@ namespace BepInEx
else
{
visited.Add(node);
-
stack.Push(node);
-
- foreach (var dep in dependencySelector(node))
- if (!Visit(dep, stack))
- return false;
-
+ if (dependencySelector(node).Any(dep => !Visit(dep, stack)))
+ return false;
sorted.Add(node);
sorted_list.Add(node);
@@ -194,7 +190,7 @@ namespace BepInEx
foreach (string subDirectory in potentialDirectories)
{
- string[] potentialPaths = new[]
+ var potentialPaths = new[]
{
$"{assemblyName.Name}.dll",
$"{assemblyName.Name}.exe"
diff --git a/BepInEx.IL2CPP/Hook/Allocator/LinuxPageAllocator.cs b/BepInEx.IL2CPP/Hook/Allocator/LinuxPageAllocator.cs
index 86ca040..5e1ba1d 100644
--- a/BepInEx.IL2CPP/Hook/Allocator/LinuxPageAllocator.cs
+++ b/BepInEx.IL2CPP/Hook/Allocator/LinuxPageAllocator.cs
@@ -19,8 +19,8 @@ namespace BepInEx.IL2CPP.Allocator
{
int startIndex = line.IndexOf('-');
int endIndex = line.IndexOf(' ');
- long startAddr = long.Parse(line.Substring(0, startIndex), NumberStyles.HexNumber);
- long endAddr = long.Parse(line.Substring(startIndex + 1, endIndex - startIndex - 1), NumberStyles.HexNumber);
+ long startAddr = long.Parse(line[..startIndex], NumberStyles.HexNumber);
+ long endAddr = long.Parse(line[(startIndex+1)..endIndex], NumberStyles.HexNumber);
yield return (new IntPtr(startAddr), new IntPtr(endAddr));
}
}
diff --git a/BepInEx.IL2CPP/Hook/Allocator/PageAllocator.cs b/BepInEx.IL2CPP/Hook/Allocator/PageAllocator.cs
index 3cb30eb..0a8254e 100644
--- a/BepInEx.IL2CPP/Hook/Allocator/PageAllocator.cs
+++ b/BepInEx.IL2CPP/Hook/Allocator/PageAllocator.cs
@@ -32,7 +32,7 @@ namespace BepInEx.IL2CPP.Allocator
private static PageAllocator instance;
- private readonly List allocatedChunks = new List();
+ private readonly List allocatedChunks = new();
///
/// Platform-specific instance of page allocator.
@@ -125,7 +125,7 @@ namespace BepInEx.IL2CPP.Allocator
var v when v.Is(Platform.Windows) => new WindowsPageAllocator(),
var v when v.Is(Platform.Linux) => new LinuxPageAllocator(),
var v when v.Is(Platform.MacOS) => new MacOsPageAllocator(),
- _ => throw new NotImplementedException()
+ _ => throw new NotImplementedException()
};
}
diff --git a/BepInEx.IL2CPP/Hook/Allocator/UnixPageAllocator.cs b/BepInEx.IL2CPP/Hook/Allocator/UnixPageAllocator.cs
index ebfa29f..9a5e5c0 100644
--- a/BepInEx.IL2CPP/Hook/Allocator/UnixPageAllocator.cs
+++ b/BepInEx.IL2CPP/Hook/Allocator/UnixPageAllocator.cs
@@ -90,7 +90,7 @@ namespace BepInEx.IL2CPP.Allocator
private static class Unix
{
- public static readonly IntPtr MAP_FAILED = new IntPtr(-1);
+ public static readonly IntPtr MAP_FAILED = new(-1);
[DynDllImport("mmap")]
public static mmapDelegate mmap;
diff --git a/BepInEx.IL2CPP/Hook/Allocator/WindowsPageAllocator.cs b/BepInEx.IL2CPP/Hook/Allocator/WindowsPageAllocator.cs
index 18abb1d..7ea4994 100644
--- a/BepInEx.IL2CPP/Hook/Allocator/WindowsPageAllocator.cs
+++ b/BepInEx.IL2CPP/Hook/Allocator/WindowsPageAllocator.cs
@@ -102,7 +102,7 @@ namespace BepInEx.IL2CPP.Allocator
[StructLayout(LayoutKind.Sequential)]
// ReSharper disable once InconsistentNaming
- public struct MEMORY_BASIC_INFORMATION
+ public readonly struct MEMORY_BASIC_INFORMATION
{
public readonly IntPtr BaseAddress;
public readonly IntPtr AllocationBase;
diff --git a/BepInEx.IL2CPP/Hook/DetourGenerator.cs b/BepInEx.IL2CPP/Hook/DetourGenerator.cs
index eed0a9c..4eb2bd6 100644
--- a/BepInEx.IL2CPP/Hook/DetourGenerator.cs
+++ b/BepInEx.IL2CPP/Hook/DetourGenerator.cs
@@ -229,7 +229,7 @@ namespace BepInEx.IL2CPP
private sealed class CodeWriterImpl : CodeWriter
{
- readonly List allBytes = new List();
+ readonly List allBytes = new();
public override void WriteByte(byte value) => allBytes.Add(value);
public byte[] ToArray() => allBytes.ToArray();
}
diff --git a/BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs b/BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs
index 46ecab0..e7d17ce 100644
--- a/BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs
+++ b/BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs
@@ -185,7 +185,7 @@ namespace BepInEx.IL2CPP.Hook
if (!Original.IsStatic)
unmanagedParams[0] = typeof(IntPtr);
- unmanagedParams[unmanagedParams.Length - 1] = typeof(Il2CppMethodInfo*);
+ unmanagedParams[^1] = typeof(Il2CppMethodInfo*);
Array.Copy(managedParams.Select(ConvertManagedTypeToIL2CPPType).ToArray(), 0,
unmanagedParams, paramStartIndex, managedParams.Length);
diff --git a/BepInEx.IL2CPP/Logging/IL2CPPUnityLogSource.cs b/BepInEx.IL2CPP/Logging/IL2CPPUnityLogSource.cs
index 55b4ccd..ef5029e 100644
--- a/BepInEx.IL2CPP/Logging/IL2CPPUnityLogSource.cs
+++ b/BepInEx.IL2CPP/Logging/IL2CPPUnityLogSource.cs
@@ -13,27 +13,15 @@ namespace BepInEx.IL2CPP.Logging
public void UnityLogCallback(string logLine, string exception, LogType type)
{
- LogLevel level = LogLevel.Message;
-
- switch (type)
+ var level = type switch
{
- case LogType.Error:
- level = LogLevel.Error;
- break;
- case LogType.Assert:
- level = LogLevel.Debug;
- break;
- case LogType.Warning:
- level = LogLevel.Warning;
- break;
- case LogType.Log:
- level = LogLevel.Message;
- break;
- case LogType.Exception:
- level = LogLevel.Error;
- break;
- }
-
+ LogType.Error => LogLevel.Error,
+ LogType.Assert => LogLevel.Debug,
+ LogType.Warning => LogLevel.Warning,
+ LogType.Log => LogLevel.Message,
+ LogType.Exception => LogLevel.Error,
+ _ => LogLevel.Message
+ };
LogEvent?.Invoke(this, new LogEventArgs(logLine, level, this));
}
diff --git a/BepInEx.IL2CPP/MonoExtensions.cs b/BepInEx.IL2CPP/MonoExtensions.cs
index d068e6f..02cd219 100644
--- a/BepInEx.IL2CPP/MonoExtensions.cs
+++ b/BepInEx.IL2CPP/MonoExtensions.cs
@@ -16,7 +16,7 @@ namespace BepInEx
{
if (d == null)
{
- throw new ArgumentNullException("d");
+ throw new ArgumentNullException(nameof(d));
}
return GetFunctionPointerForDelegateInternal2(d, conv);
diff --git a/BepInEx.Preloader.Core/Logging/PreloaderConsoleListener.cs b/BepInEx.Preloader.Core/Logging/PreloaderConsoleListener.cs
index 576e245..b49cd15 100644
--- a/BepInEx.Preloader.Core/Logging/PreloaderConsoleListener.cs
+++ b/BepInEx.Preloader.Core/Logging/PreloaderConsoleListener.cs
@@ -12,7 +12,7 @@ namespace BepInEx.Preloader.Core.Logging
///
/// A list of all objects that this listener has received.
///
- public static List LogEvents { get; } = new List();
+ public static List LogEvents { get; } = new();
///
public void LogEvent(object sender, LogEventArgs eventArgs)
diff --git a/BepInEx.Preloader.Core/Patching/AssemblyPatcher.cs b/BepInEx.Preloader.Core/Patching/AssemblyPatcher.cs
index 0cca81e..892072f 100644
--- a/BepInEx.Preloader.Core/Patching/AssemblyPatcher.cs
+++ b/BepInEx.Preloader.Core/Patching/AssemblyPatcher.cs
@@ -29,7 +29,7 @@ namespace BepInEx.Preloader.Core
///
/// A list of plugins that will be initialized and executed, in the order of the list.
///
- public List PatcherPlugins { get; } = new List();
+ public List PatcherPlugins { get; } = new();
///
@@ -42,13 +42,13 @@ namespace BepInEx.Preloader.Core
/// The dictionary has the name of the file, without any directories. These are used by the dumping functionality, and as such, these are also required to be unique. They do not have to be exactly the same as the real filename, however they have to be mapped deterministically.
/// Order is not respected, as it will be sorted by dependencies.
///
- public Dictionary AssembliesToPatch { get; } = new Dictionary();
+ public Dictionary AssembliesToPatch { get; } = new();
///
/// Contains a dictionary of assemblies that have been loaded as part of executing this assembly patcher..
/// The key is the same key as used in , while the value is the actual assembly itself.
///
- public Dictionary LoadedAssemblies { get; } = new Dictionary();
+ public Dictionary LoadedAssemblies { get; } = new();
///
/// The directory location as to where patched assemblies will be saved to and loaded from disk, for debugging purposes. Defaults to BepInEx/DumpedAssemblies
@@ -366,11 +366,9 @@ namespace BepInEx.Preloader.Core
loadedAssembly = Assembly.LoadFile(Path.Combine(DumpedAssembliesPath, filename));
else
{
- using (var assemblyStream = new MemoryStream())
- {
- assembly.Write(assemblyStream);
- loadedAssembly =Assembly.Load(assemblyStream.ToArray());
- }
+ using var assemblyStream = new MemoryStream();
+ assembly.Write(assemblyStream);
+ loadedAssembly =Assembly.Load(assemblyStream.ToArray());
}
LoadedAssemblies.Add(filename, loadedAssembly);
diff --git a/BepInEx.Preloader.Core/RuntimeFixes/ConsoleSetOutFix.cs b/BepInEx.Preloader.Core/RuntimeFixes/ConsoleSetOutFix.cs
index 54db78b..74f9ead 100644
--- a/BepInEx.Preloader.Core/RuntimeFixes/ConsoleSetOutFix.cs
+++ b/BepInEx.Preloader.Core/RuntimeFixes/ConsoleSetOutFix.cs
@@ -15,7 +15,7 @@ namespace BepInEx.Preloader.RuntimeFixes
{
loggedTextWriter = new LoggedTextWriter { Parent = Console.Out };
Console.SetOut(loggedTextWriter);
- HarmonyLib.Harmony.CreateAndPatchAll(typeof(ConsoleSetOutFix));
+ Harmony.CreateAndPatchAll(typeof(ConsoleSetOutFix));
}
[HarmonyPatch(typeof(Console), nameof(Console.SetOut))]
diff --git a/BepInEx.Preloader.Unity/RuntimeFixes/TraceFix.cs b/BepInEx.Preloader.Unity/RuntimeFixes/TraceFix.cs
index 593c113..b3b12a5 100644
--- a/BepInEx.Preloader.Unity/RuntimeFixes/TraceFix.cs
+++ b/BepInEx.Preloader.Unity/RuntimeFixes/TraceFix.cs
@@ -40,7 +40,7 @@ namespace BepInEx.Preloader.RuntimeFixes
instance.Patch(
typeof(Trace).GetMethod("DoTrace", BindingFlags.Static | BindingFlags.NonPublic),
- prefix: new HarmonyMethod(typeof(TraceFix).GetMethod(nameof(DoTraceReplacement), BindingFlags.Static | BindingFlags.NonPublic)));
+ new HarmonyMethod(typeof(TraceFix).GetMethod(nameof(DoTraceReplacement), BindingFlags.Static | BindingFlags.NonPublic)));
}
diff --git a/BepInEx.Preloader.Unity/RuntimeFixes/UnityPatches.cs b/BepInEx.Preloader.Unity/RuntimeFixes/UnityPatches.cs
index f34289b..cf41479 100644
--- a/BepInEx.Preloader.Unity/RuntimeFixes/UnityPatches.cs
+++ b/BepInEx.Preloader.Unity/RuntimeFixes/UnityPatches.cs
@@ -7,9 +7,9 @@ namespace BepInEx.Preloader.RuntimeFixes
{
internal static class UnityPatches
{
- private static HarmonyLib.Harmony HarmonyInstance { get; set; }
+ private static Harmony HarmonyInstance { get; set; }
- public static Dictionary AssemblyLocations { get; } = new Dictionary(StringComparer.InvariantCultureIgnoreCase);
+ public static Dictionary AssemblyLocations { get; } = new(StringComparer.InvariantCultureIgnoreCase);
public static void Apply()
{