mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
Reformat code after last commits
This commit is contained in:
1 parent
77a12ccc06
commit
ff4e1b7c7f
49 files changed
+242
-295
No files matched your search
@@ -75,7 +75,7 @@ namespace BepInEx.Bootstrap
|
||||
static TypeLoader()
|
||||
{
|
||||
CecilResolver = new DefaultAssemblyResolver();
|
||||
ReaderParameters = new ReaderParameters {AssemblyResolver = CecilResolver};
|
||||
ReaderParameters = new ReaderParameters { AssemblyResolver = CecilResolver };
|
||||
|
||||
CecilResolver.ResolveFailure += CecilResolveOnFailure;
|
||||
}
|
||||
@@ -126,7 +126,8 @@ namespace BepInEx.Bootstrap
|
||||
public static Dictionary<string, List<T>> FindPluginTypes<T>(string directory,
|
||||
Func<TypeDefinition, string, T> typeSelector,
|
||||
Func<AssemblyDefinition, bool> assemblyFilter =
|
||||
null, string cacheName = null)
|
||||
null,
|
||||
string cacheName = null)
|
||||
where T : ICacheable, new()
|
||||
{
|
||||
var result = new Dictionary<string, List<T>>();
|
||||
@@ -220,7 +221,7 @@ namespace BepInEx.Bootstrap
|
||||
items.Add(entry);
|
||||
}
|
||||
|
||||
result[entryIdentifier] = new CachedAssembly<T> {Timestamp = entryDate, CacheItems = items};
|
||||
result[entryIdentifier] = new CachedAssembly<T> { Timestamp = entryDate, CacheItems = items };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,15 +36,10 @@ namespace BepInEx.Configuration
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool IsValid(object value)
|
||||
{
|
||||
return value is T v && AcceptableValues.Any(x => x.Equals(v));
|
||||
}
|
||||
public override bool IsValid(object value) => value is T v && AcceptableValues.Any(x => x.Equals(v));
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToDescriptionString()
|
||||
{
|
||||
return "# Acceptable values: " + string.Join(", ", AcceptableValues.Select(x => x.ToString()).ToArray());
|
||||
}
|
||||
public override string ToDescriptionString() =>
|
||||
"# Acceptable values: " + string.Join(", ", AcceptableValues.Select(x => x.ToString()).ToArray());
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace BepInEx.Configuration
|
||||
/// <inheritdoc />
|
||||
public class ConfigDefinition : IEquatable<ConfigDefinition>
|
||||
{
|
||||
private static readonly char[] _invalidConfigChars = {'=', '\n', '\t', '\\', '"', '\'', '[', ']'};
|
||||
private static readonly char[] _invalidConfigChars = { '=', '\n', '\t', '\\', '"', '\'', '[', ']' };
|
||||
|
||||
/// <summary>
|
||||
/// Create a new definition. Definitions with same section and key are equal.
|
||||
@@ -52,7 +52,7 @@ namespace BepInEx.Configuration
|
||||
{
|
||||
if (other == null) return false;
|
||||
return string.Equals(Key, other.Key)
|
||||
&& string.Equals(Section, other.Section);
|
||||
&& string.Equals(Section, other.Section);
|
||||
}
|
||||
|
||||
private static void CheckInvalidConfigChars(string val, string name)
|
||||
|
||||
@@ -13,15 +13,15 @@ namespace BepInEx.Configuration
|
||||
{
|
||||
private T _typedValue;
|
||||
|
||||
internal ConfigEntry(ConfigFile configFile, ConfigDefinition definition, T defaultValue,
|
||||
internal ConfigEntry(ConfigFile configFile,
|
||||
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.
|
||||
@@ -62,8 +62,11 @@ namespace BepInEx.Configuration
|
||||
/// <summary>
|
||||
/// Types of defaultValue and definition.AcceptableValues have to be the same as settingType.
|
||||
/// </summary>
|
||||
internal ConfigEntryBase(ConfigFile configFile, ConfigDefinition definition, Type settingType,
|
||||
object defaultValue, ConfigDescription configDescription)
|
||||
internal ConfigEntryBase(ConfigFile configFile,
|
||||
ConfigDefinition definition,
|
||||
Type settingType,
|
||||
object defaultValue,
|
||||
ConfigDescription configDescription)
|
||||
{
|
||||
ConfigFile = configFile ?? throw new ArgumentNullException(nameof(configFile));
|
||||
Definition = definition ?? throw new ArgumentNullException(nameof(definition));
|
||||
@@ -147,10 +150,7 @@ namespace BepInEx.Configuration
|
||||
/// <summary>
|
||||
/// Trigger setting changed event.
|
||||
/// </summary>
|
||||
protected void OnSettingChanged(object sender)
|
||||
{
|
||||
ConfigFile.OnSettingChanged(sender, this);
|
||||
}
|
||||
protected void OnSettingChanged(object sender) => ConfigFile.OnSettingChanged(sender, this);
|
||||
|
||||
/// <summary>
|
||||
/// Write a description of this setting using all available metadata.
|
||||
|
||||
@@ -109,7 +109,8 @@ namespace BepInEx.Configuration
|
||||
}
|
||||
|
||||
void ICollection<KeyValuePair<ConfigDefinition, ConfigEntryBase>>.CopyTo(
|
||||
KeyValuePair<ConfigDefinition, ConfigEntryBase>[] array, int arrayIndex)
|
||||
KeyValuePair<ConfigDefinition, ConfigEntryBase>[] array,
|
||||
int arrayIndex)
|
||||
{
|
||||
lock (_ioLock)
|
||||
((ICollection<KeyValuePair<ConfigDefinition, ConfigEntryBase>>) Entries).CopyTo(array, arrayIndex);
|
||||
@@ -143,10 +144,8 @@ namespace BepInEx.Configuration
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Add(ConfigDefinition key, ConfigEntryBase value)
|
||||
{
|
||||
public void Add(ConfigDefinition key, ConfigEntryBase value) =>
|
||||
throw new InvalidOperationException("Directly adding a config entry is not supported");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Remove(ConfigDefinition key)
|
||||
@@ -251,7 +250,7 @@ namespace BepInEx.Configuration
|
||||
continue;
|
||||
}
|
||||
|
||||
var split = line.Split(new[] {'='}, 2); //actual config line
|
||||
var split = line.Split(new[] { '=' }, 2); //actual config line
|
||||
if (split.Length != 2)
|
||||
continue; //empty/invalid line
|
||||
|
||||
@@ -399,7 +398,8 @@ namespace BepInEx.Configuration
|
||||
/// <param name="configDefinition">Section and Key of the setting.</param>
|
||||
/// <param name="defaultValue">Value of the setting if the setting was not created yet.</param>
|
||||
/// <param name="configDescription">Description of the setting shown to the user and other metadata.</param>
|
||||
public ConfigEntry<T> Bind<T>(ConfigDefinition configDefinition, T defaultValue,
|
||||
public ConfigEntry<T> Bind<T>(ConfigDefinition configDefinition,
|
||||
T defaultValue,
|
||||
ConfigDescription configDescription = null)
|
||||
{
|
||||
if (!TomlTypeConverter.CanConvert(typeof(T)))
|
||||
@@ -438,7 +438,9 @@ namespace BepInEx.Configuration
|
||||
/// <param name="key">Name of the setting.</param>
|
||||
/// <param name="defaultValue">Value of the setting if the setting was not created yet.</param>
|
||||
/// <param name="configDescription">Description of the setting shown to the user and other metadata.</param>
|
||||
public ConfigEntry<T> Bind<T>(string section, string key, T defaultValue,
|
||||
public ConfigEntry<T> Bind<T>(string section,
|
||||
string key,
|
||||
T defaultValue,
|
||||
ConfigDescription configDescription = null) =>
|
||||
Bind(new ConfigDefinition(section, key), defaultValue, configDescription);
|
||||
|
||||
@@ -464,7 +466,8 @@ namespace BepInEx.Configuration
|
||||
/// <param name="defaultValue">Value of the setting if the setting was not created yet.</param>
|
||||
/// <param name="configDescription">Description of the setting shown to the user and other metadata.</param>
|
||||
[Obsolete("Use Bind instead")]
|
||||
public ConfigEntry<T> AddSetting<T>(ConfigDefinition configDefinition, T defaultValue,
|
||||
public ConfigEntry<T> AddSetting<T>(ConfigDefinition configDefinition,
|
||||
T defaultValue,
|
||||
ConfigDescription configDescription = null) =>
|
||||
Bind(configDefinition, defaultValue, configDescription);
|
||||
|
||||
@@ -479,7 +482,9 @@ namespace BepInEx.Configuration
|
||||
/// <param name="defaultValue">Value of the setting if the setting was not created yet.</param>
|
||||
/// <param name="configDescription">Description of the setting shown to the user and other metadata.</param>
|
||||
[Obsolete("Use Bind instead")]
|
||||
public ConfigEntry<T> AddSetting<T>(string section, string key, T defaultValue,
|
||||
public ConfigEntry<T> AddSetting<T>(string section,
|
||||
string key,
|
||||
T defaultValue,
|
||||
ConfigDescription configDescription = null) =>
|
||||
Bind(new ConfigDefinition(section, key), defaultValue, configDescription);
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@ namespace BepInEx.Unix
|
||||
|
||||
Func<Stream, Encoding, bool, StreamWriter> GetCtor(int[] perm)
|
||||
{
|
||||
var parameters = new[] {typeof(Stream), typeof(Encoding), typeof(bool)};
|
||||
var parameters = new[] { typeof(Stream), typeof(Encoding), typeof(bool) };
|
||||
var ctor = AccessTools.Constructor(cStreamWriter, perm.Select(i => parameters[i]).ToArray());
|
||||
if (ctor != null)
|
||||
return (stream, encoding, l) =>
|
||||
{
|
||||
var vals = new object[] {stream, encoding, l};
|
||||
var vals = new object[] { stream, encoding, l };
|
||||
return (StreamWriter) ctor.Invoke(perm.Select(i => vals[i]).ToArray());
|
||||
};
|
||||
return null;
|
||||
@@ -35,8 +35,8 @@ namespace BepInEx.Unix
|
||||
|
||||
var ctorParams = new[]
|
||||
{
|
||||
new[] {0, 1, 2}, // Unity 5.x and up
|
||||
new[] {0, 1} // Unity 4.7 and older
|
||||
new[] { 0, 1, 2 }, // Unity 5.x and up
|
||||
new[] { 0, 1 } // Unity 4.7 and older
|
||||
};
|
||||
|
||||
cStreamWriterConstructor = ctorParams.Select(GetCtor).FirstOrDefault(f => f != null);
|
||||
|
||||
@@ -66,15 +66,11 @@ namespace BepInEx.Unix
|
||||
ConsoleOut = StandardOut;
|
||||
}
|
||||
|
||||
public void CreateConsole(uint codepage)
|
||||
{
|
||||
public void CreateConsole(uint codepage) =>
|
||||
Logger.LogWarning("An external console currently cannot be spawned on a Unix platform.");
|
||||
}
|
||||
|
||||
public void DetachConsole()
|
||||
{
|
||||
public void DetachConsole() =>
|
||||
throw new PlatformNotSupportedException("Cannot detach console on a Unix platform");
|
||||
}
|
||||
|
||||
public void SetConsoleColor(ConsoleColor color)
|
||||
{
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace BepInEx.Unix
|
||||
|
||||
var colorOffset =
|
||||
baseOffset
|
||||
+ intSize * (int) TermInfoNumbers.MaxColors; // Finally the offset for the max color integer
|
||||
+ intSize * (int) TermInfoNumbers.MaxColors; // Finally the offset for the max color integer
|
||||
|
||||
//int stringOffset = baseOffset + (intSize * intFieldLength);
|
||||
|
||||
@@ -168,13 +168,13 @@ namespace BepInEx.Unix
|
||||
|
||||
private static int GetInt32(byte[] buffer, int offset) =>
|
||||
buffer[offset]
|
||||
| (buffer[offset + 1] << 8)
|
||||
| (buffer[offset + 2] << 16)
|
||||
| (buffer[offset + 3] << 24);
|
||||
| (buffer[offset + 1] << 8)
|
||||
| (buffer[offset + 2] << 16)
|
||||
| (buffer[offset + 3] << 24);
|
||||
|
||||
private static short GetInt16(byte[] buffer, int offset) =>
|
||||
(short) (buffer[offset]
|
||||
| (buffer[offset + 1] << 8));
|
||||
| (buffer[offset + 1] << 8));
|
||||
|
||||
private static int GetInteger(int intSize, byte[] buffer, int offset) =>
|
||||
intSize == 2
|
||||
|
||||
@@ -31,17 +31,11 @@ namespace BepInEx.Unix
|
||||
public IntPtr FileHandle { get; }
|
||||
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
UnixStreamHelper.fflush(FileHandle);
|
||||
}
|
||||
public override void Flush() => UnixStreamHelper.fflush(FileHandle);
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) => throw new InvalidOperationException();
|
||||
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
public override void SetLength(long value) => throw new InvalidOperationException();
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
@@ -65,10 +59,7 @@ namespace BepInEx.Unix
|
||||
gcHandle.Free();
|
||||
}
|
||||
|
||||
private void ReleaseUnmanagedResources()
|
||||
{
|
||||
UnixStreamHelper.fclose(FileHandle);
|
||||
}
|
||||
private void ReleaseUnmanagedResources() => UnixStreamHelper.fclose(FileHandle);
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
@@ -76,9 +67,6 @@ namespace BepInEx.Unix
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
~UnixStream()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
~UnixStream() => Dispose(false);
|
||||
}
|
||||
}
|
||||
@@ -24,26 +24,24 @@ namespace UnityInjector.ConsoleUtil
|
||||
private static extern uint GetACP();
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern int MultiByteToWideChar(
|
||||
uint codePage,
|
||||
uint dwFlags,
|
||||
[In] [MarshalAs(UnmanagedType.LPArray)] byte[] lpMultiByteStr,
|
||||
int cbMultiByte,
|
||||
[Out] [MarshalAs(UnmanagedType.LPWStr)] char[] lpWideCharStr,
|
||||
int cchWideChar);
|
||||
private static extern int MultiByteToWideChar(uint codePage,
|
||||
uint dwFlags,
|
||||
[In] [MarshalAs(UnmanagedType.LPArray)] byte[] lpMultiByteStr,
|
||||
int cbMultiByte,
|
||||
[Out] [MarshalAs(UnmanagedType.LPWStr)] char[] lpWideCharStr,
|
||||
int cchWideChar);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
private static extern IntPtr SetConsoleOutputCP(uint codepage);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern int WideCharToMultiByte(
|
||||
uint codePage,
|
||||
uint dwFlags,
|
||||
[In] [MarshalAs(UnmanagedType.LPWStr)] char[] lpWideCharStr,
|
||||
int cchWideChar,
|
||||
[Out] [MarshalAs(UnmanagedType.LPArray)] byte[] lpMultiByteStr,
|
||||
int cbMultiByte,
|
||||
IntPtr lpDefaultChar,
|
||||
IntPtr lpUsedDefaultChar);
|
||||
private static extern int WideCharToMultiByte(uint codePage,
|
||||
uint dwFlags,
|
||||
[In] [MarshalAs(UnmanagedType.LPWStr)] char[] lpWideCharStr,
|
||||
int cchWideChar,
|
||||
[Out] [MarshalAs(UnmanagedType.LPArray)] byte[] lpMultiByteStr,
|
||||
int cbMultiByte,
|
||||
IntPtr lpDefaultChar,
|
||||
IntPtr lpUsedDefaultChar);
|
||||
}
|
||||
}
|
||||
@@ -99,14 +99,13 @@ namespace UnityInjector.ConsoleUtil
|
||||
private static extern bool CloseHandle(IntPtr handle);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
private static extern IntPtr CreateFile(
|
||||
string fileName,
|
||||
uint desiredAccess,
|
||||
int shareMode,
|
||||
IntPtr securityAttributes,
|
||||
int creationDisposition,
|
||||
int flagsAndAttributes,
|
||||
IntPtr templateFile);
|
||||
private static extern IntPtr CreateFile(string fileName,
|
||||
uint desiredAccess,
|
||||
int shareMode,
|
||||
IntPtr securityAttributes,
|
||||
int creationDisposition,
|
||||
int flagsAndAttributes,
|
||||
IntPtr templateFile);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = false)]
|
||||
private static extern bool FreeConsole();
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace BepInEx.ConsoleUtil
|
||||
if (!flag)
|
||||
return;
|
||||
var num = bufferInfo.wAttributes;
|
||||
num &= isBackground ? (short)-241 : (short)-16;
|
||||
num &= isBackground ? (short) -241 : (short) -16;
|
||||
num = (short) ((ushort) num | (ushort) color);
|
||||
SetConsoleTextAttribute(conOut, num);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace BepInEx
|
||||
// As such, we're trying to use SafeFileHandle when it's available and go back to IntPtr overload if not available
|
||||
private static readonly ConstructorInfo FileStreamCtor = new[]
|
||||
{
|
||||
AccessTools.Constructor(typeof(FileStream), new[] {typeof(SafeFileHandle), typeof(FileAccess)}),
|
||||
AccessTools.Constructor(typeof(FileStream), new[] {typeof(IntPtr), typeof(FileAccess)})
|
||||
AccessTools.Constructor(typeof(FileStream), new[] { typeof(SafeFileHandle), typeof(FileAccess) }),
|
||||
AccessTools.Constructor(typeof(FileStream), new[] { typeof(IntPtr), typeof(FileAccess) })
|
||||
}.FirstOrDefault(m => m != null);
|
||||
|
||||
public TextWriter StandardOut { get; private set; }
|
||||
@@ -85,10 +85,7 @@ namespace BepInEx
|
||||
Kon.ForegroundColor = color;
|
||||
}
|
||||
|
||||
public void SetConsoleTitle(string title)
|
||||
{
|
||||
ConsoleWindow.Title = title;
|
||||
}
|
||||
public void SetConsoleTitle(string title) => ConsoleWindow.Title = title;
|
||||
|
||||
private static FileStream OpenFileStream(IntPtr handle)
|
||||
{
|
||||
|
||||
@@ -186,15 +186,9 @@ namespace BepInEx
|
||||
/// </summary>
|
||||
public string IncompatibilityGUID { get; protected set; }
|
||||
|
||||
void ICacheable.Save(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(IncompatibilityGUID);
|
||||
}
|
||||
void ICacheable.Save(BinaryWriter bw) => bw.Write(IncompatibilityGUID);
|
||||
|
||||
void ICacheable.Load(BinaryReader br)
|
||||
{
|
||||
IncompatibilityGUID = br.ReadString();
|
||||
}
|
||||
void ICacheable.Load(BinaryReader br) => IncompatibilityGUID = br.ReadString();
|
||||
|
||||
internal static IEnumerable<BepInIncompatibility> FromCecilType(TypeDefinition td)
|
||||
{
|
||||
|
||||
@@ -25,8 +25,11 @@ namespace BepInEx.Logging
|
||||
/// when debugging crashes.
|
||||
/// </param>
|
||||
/// <param name="fileLimit">Maximum amount of concurrently opened log files. Can help with infinite game boot loops.</param>
|
||||
public DiskLogListener(string localPath, LogLevel displayedLogLevel = LogLevel.Info, bool appendLog = false,
|
||||
bool delayedFlushing = true, int fileLimit = 5)
|
||||
public DiskLogListener(string localPath,
|
||||
LogLevel displayedLogLevel = LogLevel.Info,
|
||||
bool appendLog = false,
|
||||
bool delayedFlushing = true,
|
||||
int fileLimit = 5)
|
||||
{
|
||||
DisplayedLogLevel = displayedLogLevel;
|
||||
|
||||
@@ -97,17 +100,14 @@ namespace BepInEx.Logging
|
||||
{
|
||||
FlushTimer?.Dispose();
|
||||
|
||||
try
|
||||
{
|
||||
LogWriter?.Flush();
|
||||
LogWriter?.Dispose();
|
||||
try
|
||||
{
|
||||
LogWriter?.Flush();
|
||||
LogWriter?.Dispose();
|
||||
}
|
||||
catch (ObjectDisposedException) { }
|
||||
}
|
||||
catch (ObjectDisposedException) {}
|
||||
}
|
||||
|
||||
~DiskLogListener()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
~DiskLogListener() => Dispose();
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,7 @@ namespace BepInEx.Logging
|
||||
HarmonyLogger.MessageReceived += HandleHarmonyMessage;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
HarmonyLogger.MessageReceived -= HandleHarmonyMessage;
|
||||
}
|
||||
public void Dispose() => HarmonyLogger.MessageReceived -= HandleHarmonyMessage;
|
||||
|
||||
public string SourceName { get; } = "HarmonyX";
|
||||
public event EventHandler<LogEventArgs> LogEvent;
|
||||
|
||||
@@ -81,13 +81,13 @@ namespace BepInEx.Logging
|
||||
level = GetHighestLevel(level);
|
||||
return level switch
|
||||
{
|
||||
LogLevel.Fatal => ConsoleColor.Red,
|
||||
LogLevel.Error => ConsoleColor.DarkRed,
|
||||
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
|
||||
LogLevel.Info => ConsoleColor.DarkGray,
|
||||
LogLevel.Debug => ConsoleColor.DarkGray,
|
||||
_ => ConsoleColor.Gray
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,10 +38,7 @@ namespace BepInEx.Logging
|
||||
/// </summary>
|
||||
/// <param name="level">The level of the entry.</param>
|
||||
/// <param name="data">The data of the entry.</param>
|
||||
internal static void Log(LogLevel level, object data)
|
||||
{
|
||||
InternalLogSource.Log(level, data);
|
||||
}
|
||||
internal static void Log(LogLevel level, object data) => InternalLogSource.Log(level, data);
|
||||
|
||||
internal static void LogFatal(object data) => Log(LogLevel.Fatal, data);
|
||||
internal static void LogError(object data) => Log(LogLevel.Error, data);
|
||||
|
||||
@@ -27,10 +27,7 @@ namespace BepInEx.Logging
|
||||
/// </summary>
|
||||
/// <param name="level">Log levels to attach to the message. Multiple can be used with bitwise ORing.</param>
|
||||
/// <param name="data">Data to log.</param>
|
||||
public void Log(LogLevel level, object data)
|
||||
{
|
||||
LogEvent?.Invoke(this, new LogEventArgs(data, level, this));
|
||||
}
|
||||
public void Log(LogLevel level, object data) => LogEvent?.Invoke(this, new LogEventArgs(data, level, this));
|
||||
|
||||
/// <summary>
|
||||
/// Logs a message with <see cref="LogLevel.Fatal" /> level.
|
||||
|
||||
@@ -45,36 +45,37 @@ namespace BepInEx.Logging
|
||||
/// Writes a message to the underlying <see cref="ManualLogSource" /> instance.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to write.</param>
|
||||
public override void Write(string message)
|
||||
{
|
||||
LogSource.LogInfo(message);
|
||||
}
|
||||
public override void Write(string message) => LogSource.LogInfo(message);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a message and a newline to the underlying <see cref="ManualLogSource" /> instance.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to write.</param>
|
||||
public override void WriteLine(string message)
|
||||
{
|
||||
LogSource.LogInfo(message);
|
||||
}
|
||||
public override void WriteLine(string message) => LogSource.LogInfo(message);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id,
|
||||
string format, params object[] args) =>
|
||||
public override void TraceEvent(TraceEventCache eventCache,
|
||||
string source,
|
||||
TraceEventType eventType,
|
||||
int id,
|
||||
string format,
|
||||
params object[] args) =>
|
||||
TraceEvent(eventCache, source, eventType, id, string.Format(format, args));
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id,
|
||||
public override void TraceEvent(TraceEventCache eventCache,
|
||||
string source,
|
||||
TraceEventType eventType,
|
||||
int id,
|
||||
string message)
|
||||
{
|
||||
var level = eventType switch
|
||||
{
|
||||
TraceEventType.Critical => LogLevel.Fatal,
|
||||
TraceEventType.Error => LogLevel.Error,
|
||||
TraceEventType.Warning => LogLevel.Warning,
|
||||
TraceEventType.Critical => LogLevel.Fatal,
|
||||
TraceEventType.Error => LogLevel.Error,
|
||||
TraceEventType.Warning => LogLevel.Warning,
|
||||
TraceEventType.Information => LogLevel.Info,
|
||||
_ => LogLevel.Debug
|
||||
_ => LogLevel.Debug
|
||||
};
|
||||
LogSource.Log(level, $"{message}".Trim());
|
||||
}
|
||||
|
||||
@@ -78,7 +78,8 @@ namespace BepInEx
|
||||
/// </summary>
|
||||
public static string ProcessName { get; private set; }
|
||||
|
||||
public static void SetExecutablePath(string executablePath, string bepinRootPath = null,
|
||||
public static void SetExecutablePath(string executablePath,
|
||||
string bepinRootPath = null,
|
||||
string managedPath = null)
|
||||
{
|
||||
ExecutablePath = executablePath;
|
||||
@@ -100,9 +101,7 @@ namespace BepInEx
|
||||
CachePath = Path.Combine(BepInExRootPath, "cache");
|
||||
}
|
||||
|
||||
internal static void SetPluginPath(string pluginPath)
|
||||
{
|
||||
internal static void SetPluginPath(string pluginPath) =>
|
||||
PluginPath = Utility.CombinePaths(BepInExRootPath, pluginPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-13
@@ -169,15 +169,17 @@ namespace BepInEx
|
||||
/// <param name="directory">Directory to search the assembly from.</param>
|
||||
/// <param name="assembly">The loaded assembly.</param>
|
||||
/// <returns>True, if the assembly was found and loaded. Otherwise, false.</returns>
|
||||
private static bool TryResolveDllAssembly<T>(AssemblyName assemblyName, string directory,
|
||||
Func<string, T> loader, out T assembly) where T : class
|
||||
private static bool TryResolveDllAssembly<T>(AssemblyName assemblyName,
|
||||
string directory,
|
||||
Func<string, T> loader,
|
||||
out T assembly) where T : class
|
||||
{
|
||||
assembly = null;
|
||||
|
||||
var potentialDirectories = new List<string> {directory};
|
||||
var potentialDirectories = new List<string> { directory };
|
||||
|
||||
if (!Directory.Exists(directory))
|
||||
return false;
|
||||
if (!Directory.Exists(directory))
|
||||
return false;
|
||||
|
||||
potentialDirectories.AddRange(Directory.GetDirectories(directory, "*", SearchOption.AllDirectories));
|
||||
|
||||
@@ -243,12 +245,12 @@ namespace BepInEx
|
||||
/// <param name="readerParameters">Reader parameters that contain possible custom assembly resolver.</param>
|
||||
/// <param name="assembly">The loaded assembly.</param>
|
||||
/// <returns>True, if the assembly was found and loaded. Otherwise, false.</returns>
|
||||
public static bool TryResolveDllAssembly(AssemblyName assemblyName, string directory,
|
||||
ReaderParameters readerParameters, out AssemblyDefinition assembly)
|
||||
{
|
||||
return TryResolveDllAssembly(assemblyName, directory,
|
||||
s => AssemblyDefinition.ReadAssembly(s, readerParameters), out assembly);
|
||||
}
|
||||
public static bool TryResolveDllAssembly(AssemblyName assemblyName,
|
||||
string directory,
|
||||
ReaderParameters readerParameters,
|
||||
out AssemblyDefinition assembly) =>
|
||||
TryResolveDllAssembly(assemblyName, directory,
|
||||
s => AssemblyDefinition.ReadAssembly(s, readerParameters), out assembly);
|
||||
|
||||
/// <summary>
|
||||
/// Tries to create a file with the given name
|
||||
@@ -259,8 +261,11 @@ namespace BepInEx
|
||||
/// <param name="access">File access options</param>
|
||||
/// <param name="share">File share options</param>
|
||||
/// <returns></returns>
|
||||
public static bool TryOpenFileStream(string path, FileMode mode, out FileStream fileStream,
|
||||
FileAccess access = FileAccess.ReadWrite, FileShare share = FileShare.Read)
|
||||
public static bool TryOpenFileStream(string path,
|
||||
FileMode mode,
|
||||
out FileStream fileStream,
|
||||
FileAccess access = FileAccess.ReadWrite,
|
||||
FileShare share = FileShare.Read)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -45,9 +45,9 @@ namespace BepInEx.IL2CPP
|
||||
return foundAssembly;
|
||||
|
||||
if (Utility.TryResolveDllAssembly(assemblyName, Paths.BepInExAssemblyDirectory, out foundAssembly)
|
||||
|| Utility.TryResolveDllAssembly(assemblyName, Paths.PatcherPluginPath, out foundAssembly)
|
||||
|| Utility.TryResolveDllAssembly(assemblyName, Paths.PluginPath, out foundAssembly)
|
||||
|| Utility.TryResolveDllAssembly(assemblyName, Preloader.IL2CPPUnhollowedPath, out foundAssembly))
|
||||
|| Utility.TryResolveDllAssembly(assemblyName, Paths.PatcherPluginPath, out foundAssembly)
|
||||
|| Utility.TryResolveDllAssembly(assemblyName, Paths.PluginPath, out foundAssembly)
|
||||
|| Utility.TryResolveDllAssembly(assemblyName, Preloader.IL2CPPUnhollowedPath, out foundAssembly))
|
||||
return foundAssembly;
|
||||
|
||||
return null;
|
||||
|
||||
@@ -71,8 +71,12 @@ namespace BepInEx.IL2CPP.Hook.Allocator
|
||||
public static vm_region_64Delegate vm_region_64;
|
||||
#pragma warning restore 649
|
||||
|
||||
public delegate int vm_region_64Delegate(nint target_task, ref nint address, ref nint size, int flavor,
|
||||
ref vm_region_basic_info_64 info, ref uint infoCnt,
|
||||
public delegate int vm_region_64Delegate(nint target_task,
|
||||
ref nint address,
|
||||
ref nint size,
|
||||
int flavor,
|
||||
ref vm_region_basic_info_64 info,
|
||||
ref uint infoCnt,
|
||||
ref uint object_name);
|
||||
// ReSharper restore InconsistentNaming
|
||||
}
|
||||
|
||||
@@ -111,16 +111,14 @@ namespace BepInEx.IL2CPP.Hook.Allocator
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsInRelJmpRange(nint src, nint dst) => dst - src is <= int.MaxValue and >= int.MinValue;
|
||||
|
||||
private static PageAllocator Init()
|
||||
{
|
||||
return PlatformHelper.Current switch
|
||||
private static PageAllocator Init() =>
|
||||
PlatformHelper.Current switch
|
||||
{
|
||||
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 NotSupportedException()
|
||||
var v when v.Is(Platform.Linux) => new LinuxPageAllocator(),
|
||||
var v when v.Is(Platform.MacOS) => new MacOsPageAllocator(),
|
||||
_ => throw new NotSupportedException()
|
||||
};
|
||||
}
|
||||
|
||||
private class PageChunk
|
||||
{
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace BepInEx.IL2CPP.Hook.Allocator
|
||||
{
|
||||
var (start, end) = GetFreeArea(hint);
|
||||
// Try to allocate to end (after original method) first, then try before
|
||||
var addrs = new[] {end, start};
|
||||
var addrs = new[] { end, start };
|
||||
foreach (var addr in addrs)
|
||||
{
|
||||
if (addr == 0)
|
||||
@@ -92,7 +92,11 @@ namespace BepInEx.IL2CPP.Hook.Allocator
|
||||
|
||||
private static class Unix
|
||||
{
|
||||
public delegate nint mmapDelegate(nint addr, nuint length, Protection prot, MapFlags flags, int fd,
|
||||
public delegate nint mmapDelegate(nint addr,
|
||||
nuint length,
|
||||
Protection prot,
|
||||
MapFlags flags,
|
||||
int fd,
|
||||
int offset);
|
||||
|
||||
public delegate int munmapDelegate(nint addr, nuint length);
|
||||
@@ -113,8 +117,7 @@ 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()
|
||||
@@ -124,7 +127,6 @@ namespace BepInEx.IL2CPP.Hook.Allocator
|
||||
"/usr/lib/libSystem.dylib" // OSX POSIX
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#pragma warning disable 649 // Set by MonoMod
|
||||
[DynDllImport("mmap")]
|
||||
|
||||
@@ -111,7 +111,9 @@ namespace BepInEx.IL2CPP.Hook.Allocator
|
||||
public static extern int VirtualQuery(nint lpAddress, ref MEMORY_BASIC_INFORMATION lpBuffer, int dwLength);
|
||||
|
||||
[DllImport("kernel32", SetLastError = true)]
|
||||
public static extern nint VirtualAlloc(nint lpAddress, nuint dwSize, AllocationType flAllocationType,
|
||||
public static extern nint VirtualAlloc(nint lpAddress,
|
||||
nuint dwSize,
|
||||
AllocationType flAllocationType,
|
||||
ProtectConstant flProtect);
|
||||
|
||||
[DllImport("kernel32", SetLastError = true)]
|
||||
|
||||
@@ -54,7 +54,9 @@ namespace BepInEx.IL2CPP
|
||||
/// The minimum amount of length that the detour should consume. If the generated redirect is
|
||||
/// smaller than this, the remaining space is padded with NOPs.
|
||||
/// </param>
|
||||
public static void ApplyDetour(IntPtr functionPtr, IntPtr detourPtr, Architecture architecture,
|
||||
public static void ApplyDetour(IntPtr functionPtr,
|
||||
IntPtr detourPtr,
|
||||
Architecture architecture,
|
||||
int minimumLength = 0)
|
||||
{
|
||||
var jmp = GenerateAbsoluteJump(detourPtr, functionPtr, architecture);
|
||||
@@ -66,7 +68,8 @@ namespace BepInEx.IL2CPP
|
||||
Marshal.WriteByte(functionPtr + i, 0x90);
|
||||
}
|
||||
|
||||
public static IntPtr CreateTrampolineFromFunction(IntPtr originalFuncPointer, out int trampolineLength,
|
||||
public static IntPtr CreateTrampolineFromFunction(IntPtr originalFuncPointer,
|
||||
out int trampolineLength,
|
||||
out int jmpLength)
|
||||
{
|
||||
var instructionBuffer = new byte[32];
|
||||
@@ -100,9 +103,13 @@ namespace BepInEx.IL2CPP
|
||||
/// <param name="minimumTrampolineLength">Copies at least this many bytes of assembly from <see cref="functionPtr" />.</param>
|
||||
/// <param name="trampolineLength">Returns the total length of the trampoline, in bytes.</param>
|
||||
/// <param name="jmpLength">Returns the length of the jmp at the end of the trampoline, in bytes.</param>
|
||||
public static void CreateTrampolineFromFunction(byte[] instructionBuffer, IntPtr functionPtr,
|
||||
IntPtr trampolinePtr, int minimumTrampolineLength,
|
||||
Architecture arch, out int trampolineLength, out int jmpLength)
|
||||
public static void CreateTrampolineFromFunction(byte[] instructionBuffer,
|
||||
IntPtr functionPtr,
|
||||
IntPtr trampolinePtr,
|
||||
int minimumTrampolineLength,
|
||||
Architecture arch,
|
||||
out int trampolineLength,
|
||||
out int jmpLength)
|
||||
{
|
||||
// Decode original function up until we go past the needed bytes to write the jump to patchedFunctionPtr
|
||||
|
||||
|
||||
@@ -39,10 +39,7 @@ namespace BepInEx.IL2CPP.Hook
|
||||
public bool IsValid { get; protected set; } = true;
|
||||
public bool IsApplied { get; protected set; }
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
Apply(null);
|
||||
}
|
||||
public void Apply() => Apply(null);
|
||||
|
||||
|
||||
public void Undo()
|
||||
@@ -60,10 +57,7 @@ namespace BepInEx.IL2CPP.Hook
|
||||
IsApplied = false;
|
||||
}
|
||||
|
||||
public void Free()
|
||||
{
|
||||
IsValid = false;
|
||||
}
|
||||
public void Free() => IsValid = false;
|
||||
|
||||
public MethodBase GenerateTrampoline(MethodBase signature = null)
|
||||
{
|
||||
@@ -166,7 +160,9 @@ namespace BepInEx.IL2CPP.Hook
|
||||
TrampolineJmpSize = jmpLength;
|
||||
}
|
||||
|
||||
public static FastNativeDetour CreateAndApply<T>(IntPtr from, T to, out T original,
|
||||
public static FastNativeDetour CreateAndApply<T>(IntPtr from,
|
||||
T to,
|
||||
out T original,
|
||||
CallingConvention? callingConvention = null) where T : Delegate
|
||||
{
|
||||
var toPtr = callingConvention != null
|
||||
|
||||
@@ -69,10 +69,7 @@ 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()
|
||||
{
|
||||
@@ -272,10 +269,7 @@ namespace BepInEx.IL2CPP.Hook
|
||||
return dmd;
|
||||
}
|
||||
|
||||
private static void ReportException(Exception ex)
|
||||
{
|
||||
DetourLogger.LogError(ex.ToString());
|
||||
}
|
||||
private static void ReportException(Exception ex) => DetourLogger.LogError(ex.ToString());
|
||||
|
||||
private static Type ConvertManagedTypeToIL2CPPType(Type managedType)
|
||||
{
|
||||
@@ -322,7 +316,9 @@ namespace BepInEx.IL2CPP.Hook
|
||||
.GetValue(null);
|
||||
}
|
||||
|
||||
private static void EmitConvertArgumentToManaged(ILGenerator il, int argIndex, Type managedParamType,
|
||||
private static void EmitConvertArgumentToManaged(ILGenerator il,
|
||||
int argIndex,
|
||||
Type managedParamType,
|
||||
out LocalBuilder variable)
|
||||
{
|
||||
variable = null;
|
||||
@@ -359,7 +355,7 @@ namespace BepInEx.IL2CPP.Hook
|
||||
il.Emit(OpCodes.Br_S, endLabel);
|
||||
|
||||
il.MarkLabel(notNullLabel);
|
||||
il.Emit(OpCodes.Newobj, AccessTools.DeclaredConstructor(originalType, new[] {typeof(IntPtr)}));
|
||||
il.Emit(OpCodes.Newobj, AccessTools.DeclaredConstructor(originalType, new[] { typeof(IntPtr) }));
|
||||
|
||||
il.MarkLabel(endLabel);
|
||||
}
|
||||
@@ -406,15 +402,15 @@ namespace BepInEx.IL2CPP.Hook
|
||||
TypeAttributes.SequentialLayout, typeof(System.ValueType));
|
||||
var fb = tb.DefineField("buffer", typeof(IntPtr), FieldAttributes.Public);
|
||||
fb.SetCustomAttribute(new
|
||||
CustomAttributeBuilder(AccessTools.Constructor(typeof(MarshalAsAttribute), new[] {typeof(UnmanagedType)}),
|
||||
new object[] {UnmanagedType.ByValArray},
|
||||
CustomAttributeBuilder(AccessTools.Constructor(typeof(MarshalAsAttribute), new[] { typeof(UnmanagedType) }),
|
||||
new object[] { UnmanagedType.ByValArray },
|
||||
new[]
|
||||
{
|
||||
AccessTools.Field(typeof(MarshalAsAttribute),
|
||||
nameof(MarshalAsAttribute.SizeConst)),
|
||||
AccessTools.Field(typeof(MarshalAsAttribute),
|
||||
nameof(MarshalAsAttribute.ArraySubType))
|
||||
}, new object[] {size, UnmanagedType.U1}));
|
||||
}, new object[] { size, UnmanagedType.U1 }));
|
||||
|
||||
var type = tb.CreateType();
|
||||
return FixedStructCache[size] = type;
|
||||
|
||||
@@ -17,10 +17,8 @@ namespace BepInEx.IL2CPP.Logging
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
private void IL2CPPLogCallback(string message)
|
||||
{
|
||||
private void IL2CPPLogCallback(string message) =>
|
||||
LogEvent?.Invoke(this, new LogEventArgs(message.Trim(), LogLevel.Message, this));
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate void IL2CPPLogCallbackDelegate([In] [MarshalAs(UnmanagedType.LPStr)] string message);
|
||||
|
||||
@@ -19,12 +19,12 @@ namespace BepInEx.IL2CPP.Logging
|
||||
{
|
||||
var level = type switch
|
||||
{
|
||||
LogType.Error => LogLevel.Error,
|
||||
LogType.Assert => LogLevel.Debug,
|
||||
LogType.Warning => LogLevel.Warning,
|
||||
LogType.Log => LogLevel.Message,
|
||||
LogType.Error => LogLevel.Error,
|
||||
LogType.Assert => LogLevel.Debug,
|
||||
LogType.Warning => LogLevel.Warning,
|
||||
LogType.Log => LogLevel.Message,
|
||||
LogType.Exception => LogLevel.Error,
|
||||
_ => LogLevel.Message
|
||||
_ => LogLevel.Message
|
||||
};
|
||||
LogEvent?.Invoke(this, new LogEventArgs(logLine, level, this));
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace BepInEx.IL2CPP
|
||||
}));
|
||||
CreateInstanceAndUnwrap =
|
||||
AccessTools.MethodDelegate<Func<AppDomain, string, string, object>>(AccessTools.Method(appDomain,
|
||||
nameof(CreateInstanceAndUnwrap), new[] {typeof(string), typeof(string)}));
|
||||
nameof(CreateInstanceAndUnwrap), new[] { typeof(string), typeof(string) }));
|
||||
}
|
||||
|
||||
public static Func<AppDomain, string, string, object> CreateInstanceAndUnwrap { get; }
|
||||
@@ -122,20 +122,11 @@ namespace BepInEx.IL2CPP
|
||||
[Serializable]
|
||||
private class AppDomainListener : MarshalByRefObject
|
||||
{
|
||||
public void DoPreloaderLog(object data, LogLevel level)
|
||||
{
|
||||
Preloader.Log.Log(level, data);
|
||||
}
|
||||
public void DoPreloaderLog(object data, LogLevel level) => Preloader.Log.Log(level, data);
|
||||
|
||||
public void DoDumperLog(object data, LogLevel level)
|
||||
{
|
||||
Il2cppDumperLogger.Log(level, data);
|
||||
}
|
||||
public void DoDumperLog(object data, LogLevel level) => Il2cppDumperLogger.Log(level, data);
|
||||
|
||||
public void DoUnhollowerLog(object data, LogLevel level)
|
||||
{
|
||||
Preloader.UnhollowerLog.Log(level, data);
|
||||
}
|
||||
public void DoUnhollowerLog(object data, LogLevel level) => Preloader.UnhollowerLog.Log(level, data);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace BepInEx.NetLauncher
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.LogDebug("Using entrypoint assembly from disk");
|
||||
Log.LogDebug("Using entrypoint assembly from disk");
|
||||
entrypointAssembly = Assembly.LoadFrom(executablePath);
|
||||
}
|
||||
}
|
||||
@@ -104,15 +104,15 @@ namespace BepInEx.NetLauncher
|
||||
|
||||
AssemblyFix.Execute(entrypointAssembly);
|
||||
|
||||
entrypointAssembly.EntryPoint.Invoke(null, new [] { args });
|
||||
entrypointAssembly.EntryPoint.Invoke(null, new[] { args });
|
||||
}
|
||||
|
||||
#region Config
|
||||
|
||||
private static readonly ConfigEntry<string> ConfigEntrypointExecutable = ConfigFile.CoreConfig.Bind<string>(
|
||||
"Preloader.Entrypoint", "Assembly",
|
||||
null,
|
||||
"The local filename of the .NET executable to target.");
|
||||
"Preloader.Entrypoint", "Assembly",
|
||||
null,
|
||||
"The local filename of the .NET executable to target.");
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ namespace BepInEx.NetLauncher
|
||||
return foundAssembly;
|
||||
|
||||
if (LocalUtility.TryResolveDllAssembly(assemblyName, Paths.BepInExAssemblyDirectory, out foundAssembly)
|
||||
|| LocalUtility.TryResolveDllAssembly(assemblyName, Paths.PatcherPluginPath, out foundAssembly)
|
||||
|| LocalUtility.TryResolveDllAssembly(assemblyName, Paths.PluginPath, out foundAssembly))
|
||||
|| LocalUtility.TryResolveDllAssembly(assemblyName, Paths.PatcherPluginPath, out foundAssembly)
|
||||
|| LocalUtility.TryResolveDllAssembly(assemblyName, Paths.PluginPath, out foundAssembly))
|
||||
return foundAssembly;
|
||||
|
||||
return null;
|
||||
@@ -78,7 +78,8 @@ namespace BepInEx.NetLauncher
|
||||
string filename;
|
||||
|
||||
#if DEBUG
|
||||
filename = Path.Combine(Directory.GetCurrentDirectory(), Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName));
|
||||
filename =
|
||||
Path.Combine(Directory.GetCurrentDirectory(), Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName));
|
||||
ResolveDirectories.Add(Path.GetDirectoryName(filename));
|
||||
|
||||
// for debugging within VS
|
||||
|
||||
@@ -17,8 +17,10 @@ namespace BepInEx.NetLauncher
|
||||
/// <param name="directory">Directory to search the assembly from.</param>
|
||||
/// <param name="assembly">The loaded assembly.</param>
|
||||
/// <returns>True, if the assembly was found and loaded. Otherwise, false.</returns>
|
||||
private static bool TryResolveDllAssembly<T>(AssemblyName assemblyName, string directory,
|
||||
Func<string, T> loader, out T assembly) where T : class
|
||||
private static bool TryResolveDllAssembly<T>(AssemblyName assemblyName,
|
||||
string directory,
|
||||
Func<string, T> loader,
|
||||
out T assembly) where T : class
|
||||
{
|
||||
assembly = null;
|
||||
|
||||
|
||||
@@ -175,10 +175,10 @@ namespace BepInEx.Patcher
|
||||
var voidType = unity.MainModule.ImportReference(typeof(void));
|
||||
var cctor = new MethodDefinition(".cctor",
|
||||
MethodAttributes.Static
|
||||
| MethodAttributes.Private
|
||||
| MethodAttributes.HideBySig
|
||||
| MethodAttributes.SpecialName
|
||||
| MethodAttributes.RTSpecialName,
|
||||
| MethodAttributes.Private
|
||||
| MethodAttributes.HideBySig
|
||||
| MethodAttributes.SpecialName
|
||||
| MethodAttributes.RTSpecialName,
|
||||
voidType);
|
||||
|
||||
var ilp = cctor.Body.GetILProcessor();
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace BepInEx.Preloader.Core
|
||||
patcherPlugin.Patcher = (ref AssemblyDefinition pAss) =>
|
||||
{
|
||||
//we do the array fuckery here to get the ref result out
|
||||
object[] args = {pAss};
|
||||
object[] args = { pAss };
|
||||
|
||||
patcher.Invoke(null, args);
|
||||
|
||||
@@ -214,10 +214,7 @@ namespace BepInEx.Preloader.Core
|
||||
/// are skipped.
|
||||
/// </summary>
|
||||
/// <param name="directory">The directory to search.</param>
|
||||
public void LoadAssemblyDirectory(string directory)
|
||||
{
|
||||
LoadAssemblyDirectory(directory, "dll");
|
||||
}
|
||||
public void LoadAssemblyDirectory(string directory) => LoadAssemblyDirectory(directory, "dll");
|
||||
|
||||
/// <summary>
|
||||
/// Adds all assemblies in a directory to be patched and loaded by this patcher instance. Non-managed assemblies are
|
||||
@@ -401,17 +398,13 @@ namespace BepInEx.Preloader.Core
|
||||
Assembly loadedAssembly;
|
||||
|
||||
if (ConfigLoadDumpedAssemblies.Value)
|
||||
{
|
||||
loadedAssembly = Assembly.LoadFrom(Path.Combine(DumpedAssembliesPath, filename));
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var assemblyStream = new MemoryStream())
|
||||
{
|
||||
assembly.Write(assemblyStream);
|
||||
loadedAssembly = Assembly.Load(assemblyStream.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
LoadedAssemblies.Add(filename, loadedAssembly);
|
||||
|
||||
|
||||
@@ -36,15 +36,9 @@ namespace BepInEx.Preloader.Core
|
||||
public string TypeName { get; set; } = string.Empty;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Save(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(TypeName);
|
||||
}
|
||||
public void Save(BinaryWriter bw) => bw.Write(TypeName);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Load(BinaryReader br)
|
||||
{
|
||||
TypeName = br.ReadString();
|
||||
}
|
||||
public void Load(BinaryReader br) => TypeName = br.ReadString();
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace BepInEx.Preloader.RuntimeFixes
|
||||
|
||||
public static void Apply()
|
||||
{
|
||||
loggedTextWriter = new LoggedTextWriter {Parent = Console.Out};
|
||||
loggedTextWriter = new LoggedTextWriter { Parent = Console.Out };
|
||||
Console.SetOut(loggedTextWriter);
|
||||
Harmony.CreateAndPatchAll(typeof(ConsoleSetOutFix));
|
||||
}
|
||||
|
||||
@@ -95,8 +95,8 @@ namespace BepInEx.Preloader.Unity
|
||||
return foundAssembly;
|
||||
|
||||
if (Utility.TryResolveDllAssembly(assemblyName, Paths.BepInExAssemblyDirectory, out foundAssembly)
|
||||
|| Utility.TryResolveDllAssembly(assemblyName, Paths.PatcherPluginPath, out foundAssembly)
|
||||
|| Utility.TryResolveDllAssembly(assemblyName, Paths.PluginPath, out foundAssembly))
|
||||
|| Utility.TryResolveDllAssembly(assemblyName, Paths.PatcherPluginPath, out foundAssembly)
|
||||
|| Utility.TryResolveDllAssembly(assemblyName, Paths.PluginPath, out foundAssembly))
|
||||
return foundAssembly;
|
||||
|
||||
return null;
|
||||
|
||||
@@ -38,13 +38,13 @@ namespace BepInEx.Preloader.RuntimeFixes
|
||||
harmony.Patch(AccessTools.Method("System.TermInfoReader:ReadHeader"),
|
||||
new HarmonyMethod(typeof(XTermFix), nameof(ReadHeaderPrefix)));
|
||||
|
||||
harmony.Patch(AccessTools.Method("System.TermInfoReader:Get", new[] {AccessTools.TypeByName("System.TermInfoNumbers")}),
|
||||
harmony.Patch(AccessTools.Method("System.TermInfoReader:Get", new[] { AccessTools.TypeByName("System.TermInfoNumbers") }),
|
||||
transpiler: new HarmonyMethod(typeof(XTermFix), nameof(GetTermInfoNumbersTranspiler)));
|
||||
|
||||
harmony.Patch(AccessTools.Method("System.TermInfoReader:Get", new[] {AccessTools.TypeByName("System.TermInfoStrings")}),
|
||||
harmony.Patch(AccessTools.Method("System.TermInfoReader:Get", new[] { AccessTools.TypeByName("System.TermInfoStrings") }),
|
||||
transpiler: new HarmonyMethod(typeof(XTermFix), nameof(GetTermInfoStringsTranspiler)));
|
||||
|
||||
harmony.Patch(AccessTools.Method("System.TermInfoReader:GetStringBytes", new[] {AccessTools.TypeByName("System.TermInfoStrings")}),
|
||||
harmony.Patch(AccessTools.Method("System.TermInfoReader:GetStringBytes", new[] { AccessTools.TypeByName("System.TermInfoStrings") }),
|
||||
transpiler: new HarmonyMethod(typeof(XTermFix), nameof(GetTermInfoStringsTranspiler)));
|
||||
|
||||
DetourHelper.Native = null;
|
||||
@@ -83,8 +83,11 @@ namespace BepInEx.Preloader.RuntimeFixes
|
||||
throw new Exception($"Unknown xterm header format: {magic}");
|
||||
}
|
||||
|
||||
public static bool ReadHeaderPrefix(byte[] buffer, ref int position, ref short ___boolSize,
|
||||
ref short ___numSize, ref short ___strOffsets)
|
||||
public static bool ReadHeaderPrefix(byte[] buffer,
|
||||
ref int position,
|
||||
ref short ___boolSize,
|
||||
ref short ___numSize,
|
||||
ref short ___strOffsets)
|
||||
{
|
||||
var magic = GetInt16(buffer, position);
|
||||
position += 2;
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace BepInEx.Preloader.Unity
|
||||
{
|
||||
assemblyPatcher.PatcherPlugins.Add(new PatcherPlugin
|
||||
{
|
||||
TargetDLLs = () => new[] {ConfigEntrypointAssembly.Value},
|
||||
TargetDLLs = () => new[] { ConfigEntrypointAssembly.Value },
|
||||
Patcher = PatchEntrypoint,
|
||||
TypeName = "BepInEx.Chainloader"
|
||||
});
|
||||
@@ -192,7 +192,7 @@ namespace BepInEx.Preloader.Unity
|
||||
cctor = new MethodDefinition(".cctor",
|
||||
MethodAttributes.Static | MethodAttributes.Private |
|
||||
MethodAttributes.HideBySig
|
||||
| MethodAttributes.SpecialName | MethodAttributes.RTSpecialName,
|
||||
| MethodAttributes.SpecialName | MethodAttributes.RTSpecialName,
|
||||
assembly.MainModule.ImportReference(typeof(void)));
|
||||
|
||||
entryType.Methods.Add(cctor);
|
||||
|
||||
@@ -18,8 +18,7 @@ namespace BepInEx.Configuration
|
||||
/// </summary>
|
||||
public struct KeyboardShortcut
|
||||
{
|
||||
static KeyboardShortcut()
|
||||
{
|
||||
static KeyboardShortcut() =>
|
||||
TomlTypeConverter.AddConverter(
|
||||
typeof(KeyboardShortcut),
|
||||
new TypeConverter
|
||||
@@ -27,7 +26,6 @@ namespace BepInEx.Configuration
|
||||
ConvertToString = (o, type) => ((KeyboardShortcut) o).Serialize(),
|
||||
ConvertToObject = (s, type) => Deserialize(s)
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shortcut that never triggers.
|
||||
@@ -53,7 +51,7 @@ namespace BepInEx.Configuration
|
||||
/// </summary>
|
||||
/// <param name="mainKey">Main key to press</param>
|
||||
/// <param name="modifiers">Keys that should be held down before main key is registered</param>
|
||||
public KeyboardShortcut(KeyCode mainKey, params KeyCode[] modifiers) : this(new[] {mainKey}.Concat(modifiers)
|
||||
public KeyboardShortcut(KeyCode mainKey, params KeyCode[] modifiers) : this(new[] { mainKey }.Concat(modifiers)
|
||||
.ToArray())
|
||||
{
|
||||
if (mainKey == KeyCode.None && modifiers.Any())
|
||||
@@ -66,10 +64,10 @@ namespace BepInEx.Configuration
|
||||
private static KeyCode[] SanitizeKeys(params KeyCode[] keys)
|
||||
{
|
||||
if (keys.Length == 0 || keys[0] == KeyCode.None)
|
||||
return new[] {KeyCode.None};
|
||||
return new[] { KeyCode.None };
|
||||
|
||||
return new[] {keys[0]}.Concat(keys.Skip(1).Distinct().Where(x => x != keys[0]).OrderBy(x => (int) x))
|
||||
.ToArray();
|
||||
return new[] { keys[0] }.Concat(keys.Skip(1).Distinct().Where(x => x != keys[0]).OrderBy(x => (int) x))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -90,7 +88,7 @@ namespace BepInEx.Configuration
|
||||
{
|
||||
try
|
||||
{
|
||||
var parts = str.Split(new[] {' ', '+', ',', ';', '|'}, StringSplitOptions.RemoveEmptyEntries)
|
||||
var parts = str.Split(new[] { ' ', '+', ',', ';', '|' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(x => (KeyCode) Enum.Parse(typeof(KeyCode), x)).ToArray();
|
||||
return new KeyboardShortcut(parts);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace BepInEx.Unity.Logging
|
||||
{
|
||||
try
|
||||
{
|
||||
methodInfo.Invoke(null, new object[] {""});
|
||||
methodInfo.Invoke(null, new object[] { "" });
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace BepInEx.Unity.Logging
|
||||
{
|
||||
var registerLogCallback =
|
||||
typeof(Application).GetMethod("RegisterLogCallback", BindingFlags.Public | BindingFlags.Static);
|
||||
registerLogCallback.Invoke(null, new object[] {callback});
|
||||
registerLogCallback.Invoke(null, new object[] { callback });
|
||||
//UnsubscribeAction = () => registerLogCallback.Invoke(null, new object[] { null });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,8 @@ namespace BepInEx
|
||||
public static class ThreadingExtensions
|
||||
{
|
||||
/// <inheritdoc cref="RunParallel{TIn,TOut}(IList{TIn},Func{TIn,TOut},int)" />
|
||||
public static IEnumerable<TOut> RunParallel<TIn, TOut>(this IEnumerable<TIn> data, Func<TIn, TOut> work,
|
||||
public static IEnumerable<TOut> RunParallel<TIn, TOut>(this IEnumerable<TIn> data,
|
||||
Func<TIn, TOut> work,
|
||||
int workerCount = -1)
|
||||
{
|
||||
foreach (var result in RunParallel(data.ToList(), work))
|
||||
@@ -213,7 +214,8 @@ namespace BepInEx
|
||||
/// aborted.
|
||||
/// </exception>
|
||||
/// <exception cref="ArgumentException">Need at least 1 workerCount.</exception>
|
||||
public static IEnumerable<TOut> RunParallel<TIn, TOut>(this IList<TIn> data, Func<TIn, TOut> work,
|
||||
public static IEnumerable<TOut> RunParallel<TIn, TOut>(this IList<TIn> data,
|
||||
Func<TIn, TOut> work,
|
||||
int workerCount = -1)
|
||||
{
|
||||
if (workerCount < 0)
|
||||
|
||||
@@ -21,9 +21,6 @@ namespace BepInEx.Tests
|
||||
}
|
||||
|
||||
[AssemblyCleanup]
|
||||
public static void CleanupAss()
|
||||
{
|
||||
Directory.Delete(_testPath, true);
|
||||
}
|
||||
public static void CleanupAss() => Directory.Delete(_testPath, true);
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,7 @@ namespace BepInEx.Configuration.Tests
|
||||
private static ConcurrentBag<ConfigFile> _toRemove;
|
||||
|
||||
[ClassInitialize]
|
||||
public static void Init(TestContext context)
|
||||
{
|
||||
_toRemove = new ConcurrentBag<ConfigFile>();
|
||||
}
|
||||
public static void Init(TestContext context) => _toRemove = new ConcurrentBag<ConfigFile>();
|
||||
|
||||
[ClassCleanup]
|
||||
public static void Cleanup()
|
||||
@@ -36,10 +33,7 @@ namespace BepInEx.Configuration.Tests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SaveTest()
|
||||
{
|
||||
MakeConfig().Save();
|
||||
}
|
||||
public void SaveTest() => MakeConfig().Save();
|
||||
|
||||
[TestMethod]
|
||||
public void SaveTestValueChange()
|
||||
@@ -303,7 +297,7 @@ namespace BepInEx.Configuration.Tests
|
||||
var w = c.Bind("Cat", "Key", "", new ConfigDescription("Test"));
|
||||
|
||||
var unescaped = @"D:\test\p ath";
|
||||
foreach (var testVal in new[] {unescaped, @"D:\\test\\p ath"})
|
||||
foreach (var testVal in new[] { unescaped, @"D:\\test\\p ath" })
|
||||
{
|
||||
File.WriteAllText(c.ConfigFilePath, $"[Cat]\n# Test\nKey={testVal}\n");
|
||||
c.Reload();
|
||||
|
||||
Reference in new issue
Block a user