Decompiled source of ReplaceBoltWithMaxwell v1.0.0

LC_Maxwell.dll

Decompiled 6 months ago
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.Logging;
using HarmonyLib;
using LC_Maxwell.Patches;
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("LC_Maxwell")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LC_Maxwell")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("95bd5934-fecf-4a5f-808b-c6fe55364f45")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LC_Maxwell
{
	[BepInPlugin("Mellowdy.MaxwellReplacer", "MaxwellReplacer", "1.0.0")]
	public class MaxwellReplacerMod : BaseUnityPlugin
	{
		private const string modGUID = "Mellowdy.MaxwellReplacer";

		private const string modName = "MaxwellReplacer";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Mellowdy.MaxwellReplacer");

		public static ManualLogSource mls;

		private static MaxwellReplacerMod instance;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			mls = Logger.CreateLogSource("Mellowdy.MaxwellReplacer");
			mls.LogInfo((object)"Maxwell is in your walls");
			harmony.PatchAll(typeof(MaxwellReplacerMod));
			harmony.PatchAll(typeof(ItemReplacerPatch));
		}
	}
}
namespace LC_Maxwell.Patches
{
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class ItemReplacerPatch
	{
		private static string itemName = "Maxwell";

		private static string assetName = "maxwell.max";

		private static Mesh customMesh = null;

		private static Material dingus;

		private static Material whiskers;

		private static float maxwellSize = 6f;

		private static string[] affectedObjects = new string[2] { "largebolt", "bigbolt" };

		private static AudioClip pickUp;

		private static string pickUpAudioName = "CatPickup.wav";

		private static AudioClip drop;

		private static string dropAudioName = "CatDrop.wav";

		private static Vector3 resting = new Vector3(-90f, 0f, 0f);

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void ReplaceModel(ref Item ___itemProperties, ref MeshRenderer ___mainObjectRenderer)
		{
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)customMesh == (Object)null)
				{
					string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
					string text = Path.Combine(directoryName, assetName).Replace("\\", "/");
					MaxwellReplacerMod.mls.LogMessage((object)("Searching this filepath:" + text));
					AssetBundleCreateRequest val = AssetBundle.LoadFromFileAsync(text);
					AssetBundle assetBundle = val.assetBundle;
					customMesh = assetBundle.LoadAsset<Mesh>("dingus.mesh");
					dingus = assetBundle.LoadAsset<Material>("dingus.mat");
					whiskers = assetBundle.LoadAsset<Material>("whiskers.mat");
					pickUp = assetBundle.LoadAsset<AudioClip>(pickUpAudioName);
					drop = assetBundle.LoadAsset<AudioClip>(dropAudioName);
				}
			}
			catch
			{
				MaxwellReplacerMod.mls.LogError((object)"Assets did not load");
			}
			if (affectedObjects.Contains(((Object)___itemProperties).name.ToLower()))
			{
				MeshFilter component = ((Component)___mainObjectRenderer).GetComponent<MeshFilter>();
				component.mesh = Object.Instantiate<Mesh>(customMesh);
				Mesh mesh = component.mesh;
				Vector3[] vertices = mesh.vertices;
				Bounds bounds = mesh.bounds;
				Vector3 center = ((Bounds)(ref bounds)).center;
				for (int i = 0; i < vertices.Length; i++)
				{
					vertices[i] = center + (vertices[i] - center) * maxwellSize;
				}
				mesh.vertices = vertices;
				mesh.RecalculateBounds();
				((Renderer)___mainObjectRenderer).materials = (Material[])(object)new Material[2] { dingus, whiskers };
				___itemProperties.restingRotation = resting;
				___itemProperties.grabSFX = pickUp;
				___itemProperties.dropSFX = drop;
				___itemProperties.spawnPrefab.GetComponent<MeshFilter>().mesh = mesh;
				((Component)___mainObjectRenderer).GetComponentInChildren<ScanNodeProperties>().headerText = itemName;
				___itemProperties.itemName = itemName;
				___itemProperties.restingRotation = resting;
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void Upright(ref Item ___itemProperties, ref MeshRenderer ___mainObjectRenderer)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (affectedObjects.Contains(((Object)___itemProperties).name.ToLower()))
				{
					Quaternion rotation = ((Component)___mainObjectRenderer).transform.rotation;
					((Component)___mainObjectRenderer).transform.rotation = Quaternion.Euler(-90f * Mathf.Sign(((Component)___mainObjectRenderer).transform.lossyScale.x), Time.time * 90f, 0f);
				}
			}
			catch
			{
				MaxwellReplacerMod.mls.LogMessage((object)(((Object)___itemProperties).name.ToLower() + " failed to update rotation"));
			}
		}
	}
}