Apply style

This commit is contained in:
ghorsington committed 2021-04-11 14:10:00 +03:00
1 parent 5959c03522
commit c874d4f6b3
34 files changed
+160 -60

No files matched your search

+2 -2
View File
@@ -312,8 +312,8 @@ namespace BepInEx.Bootstrap
if (missingDependencies.Count != 0)
{
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())
}";
string.Join(", ", missingDependencies.Select(s => s.VersionRange == null ? s.DependencyGUID : $"{s.DependencyGUID} ({s.VersionRange})").ToArray())
}";
DependencyErrors.Add(message);
Logger.LogError(message);
@@ -8,7 +8,10 @@ namespace BepInEx.Configuration
public abstract class AcceptableValueBase
{
/// <param name="valueType">Type of values that this class can Clamp.</param>
protected AcceptableValueBase(Type valueType) => ValueType = valueType;
protected AcceptableValueBase(Type valueType)
{
ValueType = valueType;
}
/// <summary>
/// Type of the supported values.
@@ -17,11 +17,13 @@ namespace BepInEx.Configuration
ConfigDefinition definition,
T defaultValue,
ConfigDescription configDescription) : base(configFile, definition, typeof(T),
defaultValue, configDescription) =>
defaultValue, configDescription)
{
configFile.SettingChanged += (sender, args) =>
{
if (args.ChangedSetting == this) SettingChanged?.Invoke(sender, args);
};
}
/// <summary>
/// Value of this setting.
+32 -1
View File
@@ -55,7 +55,10 @@ namespace BepInEx.Configuration
{
get
{
lock (_ioLock) return Entries.Keys.ToList().AsReadOnly();
lock (_ioLock)
{
return Entries.Keys.ToList().AsReadOnly();
}
}
}
@@ -77,7 +80,9 @@ namespace BepInEx.Configuration
get
{
lock (_ioLock)
{
return Entries[key];
}
}
}
@@ -98,14 +103,18 @@ namespace BepInEx.Configuration
KeyValuePair<ConfigDefinition, ConfigEntryBase> item)
{
lock (_ioLock)
{
Entries.Add(item.Key, item.Value);
}
}
/// <inheritdoc />
public bool Contains(KeyValuePair<ConfigDefinition, ConfigEntryBase> item)
{
lock (_ioLock)
{
return ((ICollection<KeyValuePair<ConfigDefinition, ConfigEntryBase>>) Entries).Contains(item);
}
}
void ICollection<KeyValuePair<ConfigDefinition, ConfigEntryBase>>.CopyTo(
@@ -113,14 +122,18 @@ namespace BepInEx.Configuration
int arrayIndex)
{
lock (_ioLock)
{
((ICollection<KeyValuePair<ConfigDefinition, ConfigEntryBase>>) Entries).CopyTo(array, arrayIndex);
}
}
bool ICollection<KeyValuePair<ConfigDefinition, ConfigEntryBase>>.Remove(
KeyValuePair<ConfigDefinition, ConfigEntryBase> item)
{
lock (_ioLock)
{
return Entries.Remove(item.Key);
}
}
/// <inheritdoc />
@@ -129,7 +142,9 @@ namespace BepInEx.Configuration
get
{
lock (_ioLock)
{
return Entries.Count;
}
}
}
@@ -140,7 +155,9 @@ namespace BepInEx.Configuration
public bool ContainsKey(ConfigDefinition key)
{
lock (_ioLock)
{
return Entries.ContainsKey(key);
}
}
/// <inheritdoc />
@@ -151,20 +168,26 @@ namespace BepInEx.Configuration
public bool Remove(ConfigDefinition key)
{
lock (_ioLock)
{
return Entries.Remove(key);
}
}
/// <inheritdoc />
public void Clear()
{
lock (_ioLock)
{
Entries.Clear();
}
}
bool IDictionary<ConfigDefinition, ConfigEntryBase>.TryGetValue(ConfigDefinition key, out ConfigEntryBase value)
{
lock (_ioLock)
{
return Entries.TryGetValue(key, out value);
}
}
/// <inheritdoc />
@@ -173,7 +196,9 @@ namespace BepInEx.Configuration
get
{
lock (_ioLock)
{
return Entries[key];
}
}
set => throw new InvalidOperationException("Directly setting a config entry is not supported");
}
@@ -187,7 +212,9 @@ namespace BepInEx.Configuration
get
{
lock (_ioLock)
{
return Entries.Keys.ToArray();
}
}
}
@@ -200,7 +227,9 @@ namespace BepInEx.Configuration
get
{
lock (_ioLock)
{
return Entries.Values.ToArray();
}
}
}
@@ -214,7 +243,9 @@ namespace BepInEx.Configuration
public ConfigEntryBase[] GetConfigEntries()
{
lock (_ioLock)
{
return Entries.Values.ToArray();
}
}
#region Save/Load
@@ -9,7 +9,10 @@ namespace BepInEx.Configuration
public sealed class SettingChangedEventArgs : EventArgs
{
/// <inheritdoc />
public SettingChangedEventArgs(ConfigEntryBase changedSetting) => ChangedSetting = changedSetting;
public SettingChangedEventArgs(ConfigEntryBase changedSetting)
{
ChangedSetting = changedSetting;
}
/// <summary>
/// Setting that was changed
+5 -5
View File
@@ -23,14 +23,14 @@ namespace BepInEx
}
private const uint SHIFT_JIS_CP = 932;
public static bool ConsoleEnabled => EnableConsoleArgOverride ?? ConfigConsoleEnabled.Value;
public static readonly ConfigEntry<bool> ConfigConsoleEnabled = ConfigFile.CoreConfig.Bind(
"Logging.Console", "Enabled",
false,
"Enables showing a console for log output.");
public static readonly ConfigEntry<bool> ConfigPreventClose = ConfigFile.CoreConfig.Bind(
"Logging.Console", "PreventClose",
false,
@@ -69,11 +69,11 @@ namespace BepInEx
/// The stream that writes to an external console. Null if no such console exists
/// </summary>
public static TextWriter ConsoleStream => Driver?.ConsoleOut;
private static readonly bool? EnableConsoleArgOverride;
private const string ENABLE_CONSOLE_ARG = "--enable-console";
static ConsoleManager()
{
// Ensure GetCommandLineArgs failing (e.g. on unix) does not kill bepin
@@ -127,7 +127,7 @@ namespace BepInEx
Driver.CreateConsole(codepage);
// Console.SetOut(ConsoleStream);
if (ConfigPreventClose.Value)
Driver.PreventClose();
}
+1 -1
View File
@@ -10,7 +10,7 @@ namespace BepInEx
bool ConsoleActive { get; }
bool ConsoleIsExternal { get; }
void PreventClose();
void Initialize(bool alreadyActive);
@@ -15,11 +15,11 @@ namespace BepInEx.Unix
"ForceBepInExTTYDriver",
false,
"If enabled, forces to use custom BepInEx TTY driver for handling terminal output on unix.");
static LinuxConsoleDriver()
{
UseMonoTtyDriver = false;
if (ForceCustomTtyDriverConfig.Value)
return;
+4 -1
View File
@@ -67,6 +67,9 @@ namespace BepInEx.Unix
base.Dispose(disposing);
}
~UnixStream() => Dispose(false);
~UnixStream()
{
Dispose(false);
}
}
}
@@ -26,9 +26,11 @@ namespace UnityInjector.ConsoleUtil
[DllImport("kernel32.dll", SetLastError = true)]
private static extern int MultiByteToWideChar(uint codePage,
uint dwFlags,
[In] [MarshalAs(UnmanagedType.LPArray)] byte[] lpMultiByteStr,
[In] [MarshalAs(UnmanagedType.LPArray)]
byte[] lpMultiByteStr,
int cbMultiByte,
[Out] [MarshalAs(UnmanagedType.LPWStr)] char[] lpWideCharStr,
[Out] [MarshalAs(UnmanagedType.LPWStr)]
char[] lpWideCharStr,
int cchWideChar);
[DllImport("kernel32.dll")]
@@ -39,7 +41,8 @@ namespace UnityInjector.ConsoleUtil
uint dwFlags,
[In] [MarshalAs(UnmanagedType.LPWStr)] char[] lpWideCharStr,
int cchWideChar,
[Out] [MarshalAs(UnmanagedType.LPArray)] byte[] lpMultiByteStr,
[Out] [MarshalAs(UnmanagedType.LPArray)]
byte[] lpMultiByteStr,
int cbMultiByte,
IntPtr lpDefaultChar,
IntPtr lpUsedDefaultChar);
@@ -19,7 +19,10 @@ namespace UnityInjector.ConsoleUtil
{
private readonly uint _codePage;
private ConsoleEncoding(uint codePage) => _codePage = codePage;
private ConsoleEncoding(uint codePage)
{
_codePage = codePage;
}
public override int CodePage => (int) _codePage;
@@ -30,7 +30,7 @@ namespace UnityInjector.ConsoleUtil
if (!SetConsoleTitle(value)) throw new InvalidOperationException("Console title invalid");
}
}
public static void PreventClose()
{
if (!IsAttached)
@@ -129,14 +129,14 @@ namespace UnityInjector.ConsoleUtil
[DllImport("kernel32.dll", BestFitMapping = true, CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool SetConsoleTitle(string title);
[DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr hwnd, bool bRevert);
const uint SC_CLOSE = 0xF060;
const uint MF_BYCOMMAND = 0x00000000;
private const uint SC_CLOSE = 0xF060;
private const uint MF_BYCOMMAND = 0x00000000;
[DllImport("user32.dll")]
static extern bool DeleteMenu(IntPtr hMenu, uint uPosition, uint uFlags);
private static extern bool DeleteMenu(IntPtr hMenu, uint uPosition, uint uFlags);
}
}
-1
View File
@@ -1,6 +1,5 @@
using System;
using System.Runtime.InteropServices;
#if NET35
using System.Security.Permissions;
@@ -68,11 +68,8 @@ namespace BepInEx
};
ConsoleActive = true;
}
public void PreventClose()
{
ConsoleWindow.PreventClose();
}
public void PreventClose() => ConsoleWindow.PreventClose();
public void DetachConsole()
{
+12 -3
View File
@@ -122,7 +122,10 @@ namespace BepInEx
/// <param name="guid">The GUID of the referenced plugin.</param>
/// <param name="version">The version range of the referenced plugin.</param>
/// <remarks>When version is supplied the dependency is always treated as HardDependency</remarks>
public BepInDependency(string guid, string version) : this(guid) => VersionRange = Range.Parse(version);
public BepInDependency(string guid, string version) : this(guid)
{
VersionRange = Range.Parse(version);
}
/// <summary>
/// The GUID of the referenced plugin.
@@ -179,7 +182,10 @@ namespace BepInEx
/// If the other plugin exists, this plugin will not be loaded and a warning will be shown.
/// </summary>
/// <param name="IncompatibilityGUID">The GUID of the referenced plugin.</param>
public BepInIncompatibility(string IncompatibilityGUID) => this.IncompatibilityGUID = IncompatibilityGUID;
public BepInIncompatibility(string IncompatibilityGUID)
{
this.IncompatibilityGUID = IncompatibilityGUID;
}
/// <summary>
/// The GUID of the referenced plugin.
@@ -209,7 +215,10 @@ namespace BepInEx
public class BepInProcess : Attribute
{
/// <param name="ProcessName">The name of the process that this plugin will run under.</param>
public BepInProcess(string ProcessName) => this.ProcessName = ProcessName;
public BepInProcess(string ProcessName)
{
this.ProcessName = ProcessName;
}
/// <summary>
/// The name of the process that this plugin will run under.
+4 -1
View File
@@ -108,6 +108,9 @@ namespace BepInEx.Logging
catch (ObjectDisposedException) { }
}
~DiskLogListener() => Dispose();
~DiskLogListener()
{
Dispose();
}
}
}
+4 -1
View File
@@ -11,7 +11,10 @@ namespace BepInEx.Logging
/// Creates a manual log source.
/// </summary>
/// <param name="sourceName">Name of the log source.</param>
public ManualLogSource(string sourceName) => SourceName = sourceName;
public ManualLogSource(string sourceName)
{
SourceName = sourceName;
}
/// <inheritdoc />
public string SourceName { get; }
+4 -1
View File
@@ -13,7 +13,10 @@ namespace BepInEx.Logging
/// <summary>
/// Creates a new trace log source.
/// </summary>
protected TraceLogSource() => LogSource = new ManualLogSource("Trace");
protected TraceLogSource()
{
LogSource = new ManualLogSource("Trace");
}
/// <summary>
/// Whether Trace logs are currently being rerouted.
+1 -1
View File
@@ -78,7 +78,7 @@ namespace BepInEx
/// The name of the currently executing process.
/// </summary>
public static string ProcessName { get; private set; }
/// <summary>
/// List of directories from where Mono will search assemblies before assembly resolving is invoked.
/// </summary>
+5 -3
View File
@@ -22,7 +22,7 @@ namespace BepInEx
/// <see cref="System.Reflection.Emit" /> namespace.
/// </summary>
public static bool CLRSupportsDynamicAssemblies => CheckSRE();
/// <summary>
/// An encoding for UTF-8 which does not emit a byte order mark (BOM).
/// </summary>
@@ -345,7 +345,7 @@ namespace BepInEx
var newTrusted = curTrusted == null ? addTrusted : $"{curTrusted}{Path.PathSeparator}{addTrusted}";
appDomain.SetData(TRUSTED_PLATFORM_ASSEMBLIES, newTrusted);
}
/// <summary>
/// Gets unique files in all given directories. If the file with the same name exists in multiple directories,
/// only the first occurrence is returned.
@@ -353,7 +353,8 @@ namespace BepInEx
/// <param name="directories">Directories to search from.</param>
/// <param name="pattern">File pattern to search.</param>
/// <returns>Collection of all files in the directories.</returns>
public static IEnumerable<string> GetUniqueFilesInDirectories(IEnumerable<string> directories, string pattern = "*")
public static IEnumerable<string> GetUniqueFilesInDirectories(IEnumerable<string> directories,
string pattern = "*")
{
var result = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
foreach (var directory in directories)
@@ -363,6 +364,7 @@ namespace BepInEx
if (!result.ContainsKey(fileName))
result[fileName] = file;
}
return result.Values;
}
}
@@ -117,7 +117,8 @@ namespace BepInEx.IL2CPP.Hook.Allocator
public static readonly nint MAP_FAILED = -1;
static Unix() =>
static Unix()
{
typeof(Unix).ResolveDynDllImports(new Dictionary<string, List<DynDllMapping>>
{
["libc"] = new()
@@ -127,6 +128,7 @@ namespace BepInEx.IL2CPP.Hook.Allocator
"/usr/lib/libSystem.dylib" // OSX POSIX
}
});
}
#pragma warning disable 649 // Set by MonoMod
[DynDllImport("mmap")]
@@ -69,7 +69,10 @@ namespace BepInEx.IL2CPP.Hook
/// Constructs a new instance of <see cref="NativeDetour" /> method patcher.
/// </summary>
/// <param name="original"></param>
public IL2CPPDetourMethodPatcher(MethodBase original) : base(original) => Init();
public IL2CPPDetourMethodPatcher(MethodBase original) : base(original)
{
Init();
}
private void Init()
{
@@ -91,15 +94,20 @@ namespace BepInEx.IL2CPP.Hook
}
// Get the native MethodInfo struct for the target method
originalNativeMethodInfo = UnityVersionHandler.Wrap((Il2CppMethodInfo*) (IntPtr) methodField.GetValue(null));
originalNativeMethodInfo =
UnityVersionHandler.Wrap((Il2CppMethodInfo*) (IntPtr) methodField.GetValue(null));
// Create a trampoline from the original target method
var trampolinePtr =
DetourGenerator.CreateTrampolineFromFunction(originalNativeMethodInfo.MethodPointer, out _, out _);
// Create a modified native MethodInfo struct to point towards the trampoline
modifiedNativeMethodInfo = UnityVersionHandler.NewMethod(); //(Il2CppMethodInfo*) Marshal.AllocHGlobal(Marshal.SizeOf<Il2CppMethodInfo>());
Buffer.MemoryCopy(originalNativeMethodInfo.Pointer.ToPointer(), modifiedNativeMethodInfo.Pointer.ToPointer(), modifiedNativeMethodInfo.StructSize, originalNativeMethodInfo.StructSize);
modifiedNativeMethodInfo =
UnityVersionHandler
.NewMethod(); //(Il2CppMethodInfo*) Marshal.AllocHGlobal(Marshal.SizeOf<Il2CppMethodInfo>());
Buffer.MemoryCopy(originalNativeMethodInfo.Pointer.ToPointer(),
modifiedNativeMethodInfo.Pointer.ToPointer(), modifiedNativeMethodInfo.StructSize,
originalNativeMethodInfo.StructSize);
modifiedNativeMethodInfo.MethodPointer = trampolinePtr;
isValid = true;
}
@@ -6,8 +6,10 @@ namespace BepInEx.IL2CPP.Logging
{
public class IL2CPPUnityLogSource : ILogSource
{
public IL2CPPUnityLogSource() =>
public IL2CPPUnityLogSource()
{
Application.s_LogCallbackHandler = new Action<string, string, LogType>(UnityLogCallback);
}
public string SourceName { get; } = "Unity";
+1 -1
View File
@@ -72,7 +72,7 @@ namespace BepInEx.NetLauncher
Log.LogInfo($"{assemblyPatcher.PatcherPlugins.Count} patcher plugin(s) loaded");
assemblyPatcher.LoadAssemblyDirectories(new []{ Paths.GameRootPath }, new []{ "dll", "exe" });
assemblyPatcher.LoadAssemblyDirectories(new[] { Paths.GameRootPath }, new[] { "dll", "exe" });
Log.LogInfo($"{assemblyPatcher.AssembliesToPatch.Count} assemblies discovered");
+2 -1
View File
@@ -79,7 +79,8 @@ namespace BepInEx.NetLauncher
#if DEBUG
filename =
Path.Combine(Directory.GetCurrentDirectory(), Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName));
Path.Combine(Directory.GetCurrentDirectory(),
Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName));
ResolveDirectories.Add(Path.GetDirectoryName(filename));
// for debugging within VS
+4 -2
View File
@@ -24,7 +24,7 @@ namespace BepInEx.Preloader.Core
/// Full path to the game executable currently running.
/// </summary>
public static string DOORSTOP_PROCESS_PATH { get; private set; }
/// <summary>
/// Array of paths where Mono searches DLLs from before assembly resolvers are invoked.
/// </summary>
@@ -35,7 +35,9 @@ namespace BepInEx.Preloader.Core
DOORSTOP_INVOKE_DLL_PATH = Environment.GetEnvironmentVariable("DOORSTOP_INVOKE_DLL_PATH");
DOORSTOP_MANAGED_FOLDER_DIR = Environment.GetEnvironmentVariable("DOORSTOP_MANAGED_FOLDER_DIR");
DOORSTOP_PROCESS_PATH = Environment.GetEnvironmentVariable("DOORSTOP_PROCESS_PATH");
DOORSTOP_DLL_SEARCH_DIRS = Environment.GetEnvironmentVariable("DOORSTOP_DLL_SEARCH_DIRS")?.Split(Path.PathSeparator) ?? new string[0];
DOORSTOP_DLL_SEARCH_DIRS =
Environment.GetEnvironmentVariable("DOORSTOP_DLL_SEARCH_DIRS")?.Split(Path.PathSeparator) ??
new string[0];
}
}
}
@@ -214,7 +214,8 @@ namespace BepInEx.Preloader.Core
/// are skipped.
/// </summary>
/// <param name="directories">The directories to search.</param>
public void LoadAssemblyDirectories(params string[] directories) => LoadAssemblyDirectories(directories, new []{ "dll" });
public void LoadAssemblyDirectories(params string[] directories) =>
LoadAssemblyDirectories(directories, new[] { "dll" });
/// <summary>
/// Adds all assemblies in given directories to be patched and loaded by this patcher instance. Non-managed assemblies are
@@ -42,11 +42,11 @@ namespace BepInEx.Preloader.Unity
PlatformUtils.SetPlatform();
var bepinPath = Utility.ParentDirectory(Path.GetFullPath(EnvVars.DOORSTOP_INVOKE_DLL_PATH), 2);
Paths.SetExecutablePath(EnvVars.DOORSTOP_PROCESS_PATH, bepinPath,
EnvVars.DOORSTOP_MANAGED_FOLDER_DIR,
EnvVars.DOORSTOP_DLL_SEARCH_DIRS);
LoadCriticalAssemblies();
AppDomain.CurrentDomain.AssemblyResolve += LocalResolve;
// Remove temporary resolver early so it won't override local resolver
@@ -58,6 +58,7 @@ namespace BepInEx.Preloader.RuntimeFixes
var type = (TraceEventType) Enum.Parse(typeof(TraceEventType), kind);
lock (ListenersSyncRoot)
{
foreach (var obj in Listeners)
{
var traceListener = (TraceListener) obj;
@@ -65,6 +66,7 @@ namespace BepInEx.Preloader.RuntimeFixes
if (AutoFlush) traceListener.Flush();
}
}
return false;
}
+4 -1
View File
@@ -10,7 +10,10 @@ namespace BepInEx.Shared
[AttributeUsage(AttributeTargets.Assembly)]
public class BuildInfoAttribute : Attribute
{
public BuildInfoAttribute(string info) => Info = info;
public BuildInfoAttribute(string info)
{
Info = info;
}
public string Info { get; }
}
+2 -1
View File
@@ -46,7 +46,8 @@ namespace BepInEx.Unity.Bootstrap
// TODO: Figure out better version obtaining mechanism (e.g. from globalmanagers)
private static string UnityVersion
{
[MethodImpl(MethodImplOptions.NoInlining)] get => Application.unityVersion;
[MethodImpl(MethodImplOptions.NoInlining)]
get => Application.unityVersion;
}
private static void StaticStart(string gameExePath = null)
@@ -18,7 +18,8 @@ namespace BepInEx.Configuration
/// </summary>
public struct KeyboardShortcut
{
static KeyboardShortcut() =>
static KeyboardShortcut()
{
TomlTypeConverter.AddConverter(
typeof(KeyboardShortcut),
new TypeConverter
@@ -26,6 +27,7 @@ namespace BepInEx.Configuration
ConvertToString = (o, type) => ((KeyboardShortcut) o).Serialize(),
ConvertToObject = (s, type) => Deserialize(s)
});
}
/// <summary>
/// Shortcut that never triggers.
@@ -59,7 +61,10 @@ namespace BepInEx.Configuration
ArgumentException($"Can't set {nameof(mainKey)} to KeyCode.None if there are any {nameof(modifiers)}");
}
private KeyboardShortcut(KeyCode[] keys) => _allKeys = SanitizeKeys(keys);
private KeyboardShortcut(KeyCode[] keys)
{
_allKeys = SanitizeKeys(keys);
}
private static KeyCode[] SanitizeKeys(params KeyCode[] keys)
{
+4 -1
View File
@@ -15,7 +15,10 @@ namespace BepInEx.Unity.Logging
/// <summary>
/// Creates a new Unity log source.
/// </summary>
public UnityLogSource() => InternalUnityLogMessage += UnityLogMessageHandler;
public UnityLogSource()
{
InternalUnityLogMessage += UnityLogMessageHandler;
}
/// <inheritdoc />
public string SourceName { get; } = "Unity Log";
+8 -2
View File
@@ -75,7 +75,10 @@ namespace BepInEx
{
if (action == null) throw new ArgumentNullException(nameof(action));
lock (_invokeLock) _invokeList += action;
lock (_invokeLock)
{
_invokeList += action;
}
}
/// <summary>
@@ -167,7 +170,10 @@ namespace BepInEx
{
internal bool ExceptionThrown;
public InvokeResult() => AsyncWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
public InvokeResult()
{
AsyncWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
}
public bool IsCompleted { get; private set; }
public WaitHandle AsyncWaitHandle { get; }