Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of BepInUtils v1.2.1
NicholaScott.BepInEx.Utils.dll
Decompiled 2 years agousing System; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("NicholaScott.BepInEx.Utils")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("NicholaScott.BepInEx.Utils")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("40BD9160-E0A3-402F-AE4F-059B39509F43")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] namespace NicholaScott.BepInEx.Utils { [BepInPlugin("NicholaScott.BepInEx.Utils", "BepInUtils", "1.2.1")] public class BepInUtils : BaseUnityPlugin { public void Awake() { ((BaseUnityPlugin)this).Logger.LogInfo((object)"System loaded."); } } } namespace NicholaScott.BepInEx.Utils.Resources { public static class Extensions { public static byte[] ReadAllBytes(this Stream inStream) { if (inStream is MemoryStream memoryStream) { return memoryStream.ToArray(); } using MemoryStream memoryStream2 = new MemoryStream(); inStream.CopyTo(memoryStream2); return memoryStream2.ToArray(); } } } namespace NicholaScott.BepInEx.Utils.Patching { [AttributeUsage(AttributeTargets.Class)] public class Production : Attribute { } public static class Extensions { public static Harmony PatchAttribute<TAttr>(this Assembly sourceAssembly, string guid, Action<object> logMethod = null) where TAttr : Attribute { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown Harmony val = new Harmony(string.Join(".", guid, typeof(TAttr).Name)); foreach (Type item in from t in sourceAssembly.GetTypes() where t.IsClass && t.GetCustomAttributes(typeof(TAttr)).Any() select t) { int num = val.GetPatchedMethods().Count(); val.PatchAll(item); int num2 = val.GetPatchedMethods().Count(); int num3 = num2 - num; logMethod?.Invoke(string.Format("[{0}] Patched class {1}, containing {2} method{3}", typeof(TAttr).Name, item.Name, num3, (num3 > 1) ? "s." : ".")); } return val; } } } namespace NicholaScott.BepInEx.Utils.Instancing { public class AutoSingleton<TPrepare> where TPrepare : Object { private static TPrepare _instance; public static TPrepare Instance { get { if (!Object.op_Implicit((Object)(object)_instance)) { _instance = Object.FindObjectOfType<TPrepare>(); } return _instance; } } } public class CachedItem<TItem> { public delegate TItem InstanceLocator(); public delegate bool ItemNotNull(TItem item); private InstanceLocator locatorMethod; private ItemNotNull notNullMethod; private bool valueAssigned = false; private TItem value; public TItem Value { get { if (valueAssigned && (notNullMethod == null || notNullMethod(value))) { return value; } value = locatorMethod(); valueAssigned = notNullMethod == null || notNullMethod(value); return value; } } public CachedItem(InstanceLocator locator, ItemNotNull notNull = null) { locatorMethod = locator; notNullMethod = notNull; } public void ClearCache() { valueAssigned = false; } public static implicit operator TItem(CachedItem<TItem> item) { return item.Value; } } public class Singleton<TPrepare> { public static TPrepare Instance; public static ManualLogSource Logger { get { object? obj = typeof(BaseUnityPlugin).GetProperty("Logger", BindingFlags.Instance | BindingFlags.NonPublic)?.GetGetMethod(nonPublic: true)?.Invoke(Instance, Array.Empty<object>()); return (ManualLogSource)((obj is ManualLogSource) ? obj : null); } } } public class Singleton<TPrepare, TConfig> : Singleton<TPrepare> { public static TConfig Configuration; } } namespace NicholaScott.BepInEx.Utils.Configuration { [AttributeUsage(AttributeTargets.Field)] public class ConfigEntryDefinition : Attribute { public string Category; public string Name; public string Description; } public static class Extensions { public static TStruct BindStruct<TStruct>(this ConfigFile config, TStruct defaults) where TStruct : struct { //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Expected O, but got Unknown //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Expected O, but got Unknown object obj = new TStruct(); FieldInfo[] fields = typeof(TStruct).GetFields(); foreach (FieldInfo fieldInfo in fields) { ConfigEntryDefinition configEntryDefinition = fieldInfo.GetCustomAttribute<ConfigEntryDefinition>() ?? new ConfigEntryDefinition(); configEntryDefinition.Category = configEntryDefinition.Category ?? "General"; configEntryDefinition.Name = configEntryDefinition.Name ?? fieldInfo.Name; configEntryDefinition.Description = configEntryDefinition.Description ?? ""; object obj2 = ((typeof(ConfigFile).GetMethods()?.Where((MethodInfo m) => m.IsGenericMethod && m.Name.Contains("Bind") && m.GetParameters()[0].ParameterType == typeof(ConfigDefinition)).First())?.MakeGenericMethod(fieldInfo.FieldType))?.Invoke(config, new object[3] { (object)new ConfigDefinition(configEntryDefinition.Category, configEntryDefinition.Name), fieldInfo.GetValue(defaults), (object)new ConfigDescription(configEntryDefinition.Description, (AcceptableValueBase)null, Array.Empty<object>()) }); object obj3 = (obj2?.GetType().GetProperty("Value"))?.GetGetMethod().Invoke(obj2, null); fieldInfo.SetValue(obj, obj3 ?? fieldInfo.GetValue(defaults)); } return (TStruct)obj; } } }