Decompiled source of NukeLib v0.1.0

plugins\NukeLib.dll

Decompiled 11 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NukeLib")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a30d010809fa1d64df5fa93472aa8d71fcc6bd7d")]
[assembly: AssemblyProduct("NukeLib")]
[assembly: AssemblyTitle("NukeLib")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace NukeLib
{
	[BepInPlugin("com.github.end-4.nukeLib", "NukeLib", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource? Log;

		public static string workingPath = Assembly.GetExecutingAssembly().Location;

		public static string workingDir = Path.GetDirectoryName(workingPath);

		public const string PluginGUID = "com.github.end-4.nukeLib";

		public const string PluginName = "NukeLib";

		public const string PluginVersion = "0.1.0";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
		}
	}
}
namespace NukeLib.Reflection
{
	public static class ReflectionUtils
	{
		public static T GetPrivate<T>(this object obj, string fieldName)
		{
			Type type = obj.GetType();
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
			FieldInfo? field = type.GetField(fieldName, bindingAttr);
			if (field == null)
			{
				throw new ArgumentException("Field '" + fieldName + "' doesn't exist in class " + type.Name);
			}
			return (T)field.GetValue(obj);
		}

		public static void SetPrivate<T>(this object obj, string fieldName, T value)
		{
			Type type = obj.GetType();
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
			FieldInfo? field = type.GetField(fieldName, bindingAttr);
			if (field == null)
			{
				throw new ArgumentException("Field '" + fieldName + "' doesn't exist in class " + type.Name);
			}
			field.SetValue(obj, value);
		}
	}
}
namespace NukeLib.Assets
{
	public static class FileAssetHelper
	{
		public static Sprite LoadNewSprite(string filePath, float pixelsPerUnit = 100f, SpriteMeshType spriteType = (SpriteMeshType)1)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = LoadTexture(filePath);
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0f, 0f), pixelsPerUnit, 0u, spriteType);
		}

		public static Sprite ConvertTextureToSprite(Texture2D texture, float pixelsPerUnit = 100f, SpriteMeshType spriteType = (SpriteMeshType)1)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			return Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), new Vector2(0f, 0f), pixelsPerUnit, 0u, spriteType);
		}

		public static Texture2D LoadTexture(string FilePath)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (File.Exists(FilePath))
			{
				byte[] array = File.ReadAllBytes(FilePath);
				Texture2D val = new Texture2D(2, 2);
				if (ImageConversion.LoadImage(val, array))
				{
					return val;
				}
			}
			return null;
		}

		public static async Task<Texture2D> LoadTextureAsync(string filePath)
		{
			if (!File.Exists(filePath))
			{
				return null;
			}
			string text = "file://" + filePath;
			UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(text);
			try
			{
				UnityWebRequestAsyncOperation operation = uwr.SendWebRequest();
				while (!((AsyncOperation)operation).isDone)
				{
					await Task.Yield();
				}
				if ((int)uwr.result != 1)
				{
					return null;
				}
				return DownloadHandlerTexture.GetContent(uwr);
			}
			finally
			{
				((IDisposable)uwr)?.Dispose();
			}
		}
	}
}