Decompiled source of Librarby v0.1.1

Librarby.dll

Decompiled 23 minutes ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("UKMod template")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UKMod template")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3d018c2f-f5bc-47be-a844-3e9888579d1f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Librarby;

public static class LibrarbyAPI
{
	private static readonly ManualLogSource Log = Logger.CreateLogSource("Librarby");

	public static AudioClip DeflateClip { get; internal set; }

	public static bool Deflate(GameObject target)
	{
		if ((Object)(object)target == (Object)null)
		{
			return false;
		}
		if ((Object)(object)target.GetComponent<Deflater>() != (Object)null)
		{
			return false;
		}
		target.AddComponent<Deflater>();
		Log.LogInfo((object)(((Object)target).name + " deflated!"));
		return true;
	}
}
public class Deflater : MonoBehaviour
{
	private const float Duration = 7f;

	private const float MinYScale = 0.001f;

	private const float XZStretch = 1.5f;

	private const float Thrust = 150f;

	private const float FlightDrag = 1f;

	private const float AngularDrag = 0.05f;

	private const float WobbleInterval = 0.125f;

	private const float WobbleStart = 0.1f;

	private const float WobbleMax = 1f;

	private Rigidbody rb;

	private Vector3 startScale;

	private Vector3 endScale;

	private float elapsed;

	private float wobbleTimer;

	private bool finished;

	private void Awake()
	{
		//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		Behaviour[] components = ((Component)this).GetComponents<Behaviour>();
		foreach (Behaviour val in components)
		{
			if ((Object)(object)val != (Object)(object)this)
			{
				val.enabled = false;
			}
		}
		Animator[] componentsInChildren = ((Component)this).GetComponentsInChildren<Animator>();
		foreach (Animator val2 in componentsInChildren)
		{
			((Behaviour)val2).enabled = false;
		}
		AudioClip deflateClip = LibrarbyAPI.DeflateClip;
		if ((Object)(object)deflateClip != (Object)null)
		{
			AudioSource val3 = ((Component)this).gameObject.AddComponent<AudioSource>();
			val3.clip = deflateClip;
			val3.loop = false;
			val3.playOnAwake = false;
			val3.spatialBlend = 1f;
			val3.minDistance = 5f;
			val3.maxDistance = 100f;
			val3.volume = 1f;
			val3.Play();
		}
		int num = LayerMask.NameToLayer("Limb");
		if (num < 0)
		{
			num = LayerMask.NameToLayer("limb");
		}
		if (num >= 0)
		{
			Transform[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<Transform>(true);
			foreach (Transform val4 in componentsInChildren2)
			{
				((Component)val4).gameObject.layer = num;
			}
		}
		Collider[] componentsInChildren3 = ((Component)this).GetComponentsInChildren<Collider>();
		if (componentsInChildren3.Length == 0)
		{
			if ((Object)(object)((Component)this).GetComponent<MeshFilter>() != (Object)null)
			{
				((Component)this).gameObject.AddComponent<MeshCollider>().convex = true;
			}
			else
			{
				((Component)this).gameObject.AddComponent<BoxCollider>();
			}
		}
		else
		{
			Collider[] array = componentsInChildren3;
			foreach (Collider val5 in array)
			{
				val5.enabled = true;
				val5.isTrigger = false;
				MeshCollider val6 = (MeshCollider)(object)((val5 is MeshCollider) ? val5 : null);
				if (val6 != null && !val6.convex)
				{
					val6.convex = true;
				}
			}
		}
		Joint[] components2 = ((Component)this).GetComponents<Joint>();
		foreach (Joint val7 in components2)
		{
			Object.Destroy((Object)(object)val7);
		}
		rb = ((Component)this).GetComponent<Rigidbody>();
		if ((Object)(object)rb == (Object)null)
		{
			rb = ((Component)this).gameObject.AddComponent<Rigidbody>();
		}
		rb.isKinematic = false;
		rb.constraints = (RigidbodyConstraints)0;
		rb.freezeRotation = false;
		rb.mass = 1f;
		rb.drag = 1f;
		rb.angularDrag = 0.05f;
		rb.useGravity = false;
		rb.collisionDetectionMode = (CollisionDetectionMode)1;
		startScale = ((Component)this).transform.localScale;
		endScale = new Vector3(startScale.x * 1.5f, 0.001f, startScale.z * 1.5f);
	}

	private void Update()
	{
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		if (!finished)
		{
			elapsed += Time.deltaTime;
			float num = Mathf.Clamp01(elapsed / 7f);
			float num2 = Mathf.SmoothStep(0f, 1f, num);
			((Component)this).transform.localScale = new Vector3(Mathf.Lerp(startScale.x, endScale.x, num2), Mathf.Lerp(startScale.y, endScale.y, num2), Mathf.Lerp(startScale.z, endScale.z, num2));
			if (num >= 1f)
			{
				Finish();
			}
		}
	}

	private void FixedUpdate()
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		if (!finished)
		{
			rb.AddForce(((Component)this).transform.forward * 150f, (ForceMode)0);
			wobbleTimer += Time.fixedDeltaTime;
			while (wobbleTimer >= 0.125f)
			{
				wobbleTimer -= 0.125f;
				float num = Mathf.Clamp01(elapsed / 7f);
				float num2 = Mathf.Lerp(0.1f, 1f, num);
				rb.AddTorque(Random.onUnitSphere * num2, (ForceMode)2);
			}
		}
	}

	private void Finish()
	{
		finished = true;
		rb.useGravity = true;
	}
}
[BepInPlugin("com.nico.librarby", "Librarby", "0.1.0")]
public class LibrarbyPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "com.nico.librarby";

	public const string PluginName = "Librarby";

	public const string PluginVersion = "0.1.0";

	private const string DeflateDebugSection = "Debug.Deflate";

	private ConfigEntry<bool> testKeybindEnabled;

	private ConfigEntry<KeyCode> testKey;

	private void Awake()
	{
		((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
		testKeybindEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug.Deflate", "EnableTestKeybind", false, "If true, pressing the test key deflates whatever you're aiming at.");
		testKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Debug.Deflate", "TestKey", (KeyCode)287, "Key that triggers the deflate test.");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Librarby 0.1.0 loaded");
		((MonoBehaviour)this).StartCoroutine(LoadDeflateClip());
	}

	private IEnumerator LoadDeflateClip()
	{
		string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "deflate.mp3");
		if (!File.Exists(path))
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("deflate.mp3 not found at " + path));
			yield break;
		}
		string url = new Uri(path).AbsoluteUri;
		UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(url, (AudioType)13);
		try
		{
			yield return req.SendWebRequest();
			if (req.isNetworkError || req.isHttpError)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Failed to load deflate.mp3: " + req.error));
				yield break;
			}
			AudioClip clip = DownloadHandlerAudioClip.GetContent(req);
			((Object)clip).name = "deflate";
			LibrarbyAPI.DeflateClip = clip;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded deflate.mp3");
		}
		finally
		{
			((IDisposable)req)?.Dispose();
		}
	}

	private void Update()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		if (!testKeybindEnabled.Value || !Input.GetKeyDown(testKey.Value))
		{
			return;
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Test key pressed");
		Camera val = Camera.main;
		if ((Object)(object)val == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"Camera.main is null, falling back to first enabled camera");
			Camera[] allCameras = Camera.allCameras;
			foreach (Camera val2 in allCameras)
			{
				if (((Behaviour)val2).enabled)
				{
					val = val2;
					break;
				}
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"No camera found");
			return;
		}
		Ray val3 = val.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
		RaycastHit val4 = default(RaycastHit);
		if (Physics.Raycast(val3, ref val4, 200f, -1, (QueryTriggerInteraction)1))
		{
			LibrarbyAPI.Deflate(((Component)((RaycastHit)(ref val4)).collider).gameObject);
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Nothing under the crosshair");
		}
	}
}