Decompiled source of Blahaj v1.0.6

LC_Blahaj.dll

Decompiled 4 months ago
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.Logging;
using HarmonyLib;
using LC_Blåhaj.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_Blåhaj")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LC_Blåhaj")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("349b55f3-8fa2-413e-b05f-317be6634fce")]
[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_Blåhaj
{
	[BepInPlugin("Mellowdy.BlahajReplacer", "BlahajReplacer", "1.0.0")]
	public class BlåhajReplacerMod : BaseUnityPlugin
	{
		private const string modGUID = "Mellowdy.BlahajReplacer";

		private const string modName = "BlahajReplacer";

		private const string modVersion = "1.0.0";

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

		public static ManualLogSource mls;

		private static BlåhajReplacerMod instance;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			mls = Logger.CreateLogSource("Mellowdy.BlahajReplacer");
			mls.LogInfo((object)"Blåhaj is soothing your soul");
			harmony.PatchAll(typeof(BlåhajReplacerMod));
			harmony.PatchAll(typeof(ItemReplacerPatch));
		}
	}
}
namespace LC_Blåhaj.Patches
{
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class ItemReplacerPatch
	{
		private static string itemName = "Blåhaj";

		private static string assetName = "blahaj.haj";

		private static Mesh customMesh = null;

		private static string meshName = "blåhaj.mesh";

		private static Material blåhajMat;

		private static string materialName = "defaultMat.mat";

		private static AudioClip pickUp;

		private static string pickUpAudioName = "BlåhajPickup.wav";

		private static AudioClip drop;

		private static string dropAudioName = "BlåhajPickup.mp3";

		private static float blåhajSize = 5f;

		private static string affectedObject = "fishtestprop";

		private static Vector3 rotation = new Vector3(0f, 0f, 0f);

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void ReplaceModel(ref Item ___itemProperties, ref MeshRenderer ___mainObjectRenderer, ref int ___floorYRot)
		{
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)customMesh == (Object)null)
			{
				string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				string text = Path.Combine(directoryName, assetName).Replace("\\", "/");
				BlåhajReplacerMod.mls.LogMessage((object)("Searching this filepath:" + text));
				AssetBundleCreateRequest val = AssetBundle.LoadFromFileAsync(text);
				AssetBundle assetBundle = val.assetBundle;
				customMesh = assetBundle.LoadAsset<Mesh>(meshName);
				blåhajMat = assetBundle.LoadAsset<Material>(materialName);
				pickUp = assetBundle.LoadAsset<AudioClip>(pickUpAudioName);
				drop = assetBundle.LoadAsset<AudioClip>(dropAudioName);
				ScanNodeProperties[] array = Object.FindObjectsOfType<ScanNodeProperties>();
				foreach (ScanNodeProperties val2 in array)
				{
					BlåhajReplacerMod.mls.LogMessage((object)(((Object)val2).name + " " + val2.headerText + " " + val2.subText));
				}
			}
			if (affectedObject == ((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 j = 0; j < vertices.Length; j++)
				{
					vertices[j] = center + (vertices[j] - center) * blåhajSize;
				}
				mesh.vertices = vertices;
				mesh.RecalculateBounds();
				((Renderer)___mainObjectRenderer).materials = (Material[])(object)new Material[1] { blåhajMat };
				((Component)___mainObjectRenderer).transform.localScale = new Vector3(0.08f, 0.08f, 0.08f);
				___itemProperties.grabSFX = pickUp;
				___itemProperties.dropSFX = drop;
				___itemProperties.spawnPrefab.GetComponent<MeshFilter>().mesh = mesh;
				___itemProperties.spawnPrefab.transform.localScale = new Vector3(0.08f, 0.08f, 0.08f);
				___itemProperties.itemName = itemName;
				((Component)___mainObjectRenderer).GetComponentInChildren<ScanNodeProperties>().headerText = itemName;
				___floorYRot = -1;
				___itemProperties.restingRotation = rotation;
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void Upright(ref Item ___itemProperties, ref MeshRenderer ___mainObjectRenderer)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (affectedObject == ((Object)___itemProperties).name.ToLower())
				{
					((Component)___mainObjectRenderer).transform.localScale = new Vector3(0.08f, 0.08f, 0.08f);
				}
			}
			catch
			{
				BlåhajReplacerMod.mls.LogMessage((object)(((Object)___itemProperties).name.ToLower() + " failed to update rotation"));
			}
		}

		private static void Print(string s)
		{
			BlåhajReplacerMod.mls.LogMessage((object)s);
		}
	}
}