Decompiled source of Blahaj v1.1.0

plugins/4902-shark.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Blahaj.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using Steamworks;
using Steamworks.Data;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Blahaj
{
	[BepInPlugin("4902.Shark", "Shark", "1.0.0")]
	public class gura : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("4902.Shark");

		public static ManualLogSource mls;

		public static ConfigEntry<int> blue_percentage;

		public static ConfigEntry<int> pink_percentage;

		private void Awake()
		{
			blue_percentage = ((BaseUnityPlugin)this).Config.Bind<int>("", "blahaj_percent", 50, "percentage that blahaj will replace axle\ninput = percentage, 50 is 50% etc");
			pink_percentage = ((BaseUnityPlugin)this).Config.Bind<int>("", "pink_variant_percent", 10, "percentage that blahaj will be pink\ninput = percentage");
			mls = Logger.CreateLogSource("Shark");
			mls.LogInfo((object)"Blahaj is in your walls");
			harmony.PatchAll(typeof(go));
			harmony.PatchAll(typeof(pcb));
			harmony.PatchAll(typeof(hm));
		}
	}
}
namespace Blahaj.Patches
{
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class go
	{
		public static string[] item = new string[2];

		public static Mesh[] fish = (Mesh[])(object)new Mesh[2];

		public static Material[][] cats = new Material[3][];

		public static AudioClip[] take = (AudioClip[])(object)new AudioClip[2];

		public static AudioClip[] give = (AudioClip[])(object)new AudioClip[2];

		private static bool dots = false;

		[HarmonyPatch("Start")]
		private static void Postfix(GrabbableObject __instance)
		{
			//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_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			if (!(((Object)__instance.itemProperties).name == "Cog1"))
			{
				return;
			}
			if (item[0] == null)
			{
				string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "4902-shark").Replace("\\", "/");
				gura.mls.LogMessage((object)("Searching this filepath:" + text));
				AssetBundle assetBundle = AssetBundle.LoadFromFileAsync(text).assetBundle;
				item[0] = "Large axle";
				fish[0] = ((Component)__instance).GetComponent<MeshFilter>().mesh;
				cats[0] = ((Renderer)((Component)__instance).GetComponent<MeshRenderer>()).materials;
				take[0] = __instance.itemProperties.grabSFX;
				give[0] = __instance.itemProperties.dropSFX;
				item[1] = "Shark plushie";
				fish[1] = assetBundle.LoadAsset<Mesh>("blahaj.fbx");
				cats[1] = (Material[])(object)new Material[1] { assetBundle.LoadAsset<Material>("blahaj.mat") };
				cats[2] = (Material[])(object)new Material[1] { assetBundle.LoadAsset<Material>("beyoublahaj.mat") };
				take[1] = assetBundle.LoadAsset<AudioClip>("blahajgrab.mp3");
				give[1] = assetBundle.LoadAsset<AudioClip>("blahajdrop.mp3");
			}
			if (item[0] == null)
			{
				return;
			}
			Random random;
			if (GameNetworkManager.Instance.disableSteam)
			{
				random = new Random();
			}
			else
			{
				Lobby value = GameNetworkManager.Instance.currentLobby.Value;
				random = new Random((int)((SteamId.op_Implicit(((Lobby)(ref value)).Id) + ((Component)__instance).GetComponent<NetworkObject>().NetworkObjectId) % 1000000000));
			}
			Random random2 = random;
			int num = ((random2.Next(0, 100) < gura.blue_percentage.Value) ? 1 : 0);
			if (num == 1)
			{
				if (!dots)
				{
					Vector3[] vertices = fish[1].vertices;
					Vector3[] normals = fish[1].normals;
					Bounds bounds = fish[1].bounds;
					Vector3 center = ((Bounds)(ref bounds)).center;
					for (int i = 0; i < vertices.Length; i++)
					{
						ref Vector3 reference = ref vertices[i];
						reference = vertices[i] - center;
						ref Vector3 reference2 = ref vertices[i];
						reference2 = vertices[i] * 48f;
						float x = vertices[i].x;
						float z = vertices[i].z;
						float x2 = normals[i].x;
						float z2 = normals[i].z;
						vertices[i].x = z;
						vertices[i].z = 0f - x;
						normals[i].x = z2;
						normals[i].z = 0f - x2;
						ref Vector3 reference3 = ref vertices[i];
						reference3 = vertices[i] + center;
					}
					fish[1].vertices = vertices;
					fish[1].normals = normals;
					fish[1].RecalculateBounds();
					fish[1].RecalculateNormals();
					dots = true;
				}
				((Renderer)((Component)__instance).GetComponent<MeshRenderer>()).materials = ((random2.Next(0, 100) < gura.pink_percentage.Value) ? cats[2] : cats[1]);
			}
			else
			{
				((Renderer)((Component)__instance).GetComponent<MeshRenderer>()).materials = cats[0];
			}
			__instance.itemProperties.itemName = item[num];
			((Component)__instance).GetComponentInChildren<ScanNodeProperties>().headerText = item[num];
			((Component)__instance).GetComponent<MeshFilter>().mesh = fish[num];
			__instance.itemProperties.grabSFX = take[num];
			__instance.itemProperties.dropSFX = give[num];
		}

		[HarmonyPatch("PlayDropSFX")]
		private static void Prefix(ref GrabbableObject __instance)
		{
			if (item[0] != null && (Object)(object)__instance != (Object)null && ((Object)__instance.itemProperties).name == "Cog1" && (Object)(object)((Component)__instance).GetComponentInChildren<ScanNodeProperties>() != (Object)null)
			{
				__instance.itemProperties.dropSFX = ((((Component)__instance).GetComponentInChildren<ScanNodeProperties>().headerText == item[1]) ? give[1] : give[0]);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class pcb
	{
		[HarmonyPatch("BeginGrabObject")]
		private static void Postfix(ref GrabbableObject ___currentlyGrabbingObject)
		{
			if (go.item[0] != null && (Object)(object)___currentlyGrabbingObject != (Object)null && ((Object)___currentlyGrabbingObject.itemProperties).name == "Cog1" && (Object)(object)((Component)___currentlyGrabbingObject).GetComponentInChildren<ScanNodeProperties>() != (Object)null)
			{
				___currentlyGrabbingObject.itemProperties.grabSFX = ((((Component)___currentlyGrabbingObject).GetComponentInChildren<ScanNodeProperties>().headerText == go.item[1]) ? go.take[1] : go.take[0]);
				___currentlyGrabbingObject.itemProperties.itemName = ((Component)___currentlyGrabbingObject).GetComponentInChildren<ScanNodeProperties>().headerText;
			}
		}

		[HarmonyPatch("ScrollMouse_performed")]
		private static void Prefix(ref CallbackContext context, ref int ___currentItemSlot, ref GrabbableObject[] ___ItemSlots)
		{
			if (go.item[0] != null)
			{
				bool flag = false;
				if (((CallbackContext)(ref context)).ReadValue<float>() > 0f)
				{
					flag = true;
				}
				int num = ___currentItemSlot - 1;
				if (flag)
				{
					num = (___currentItemSlot + 1) % ___ItemSlots.Length;
				}
				else if (___currentItemSlot == 0)
				{
					num = ___ItemSlots.Length - 1;
				}
				if (num >= 0 && num < ___ItemSlots.Length && (Object)(object)___ItemSlots[num] != (Object)null && ((Object)___ItemSlots[num].itemProperties).name == "Cog1" && (Object)(object)((Component)___ItemSlots[num]).GetComponentInChildren<ScanNodeProperties>() != (Object)null)
				{
					___ItemSlots[num].itemProperties.grabSFX = ((((Component)___ItemSlots[num]).GetComponentInChildren<ScanNodeProperties>().headerText == go.item[1]) ? go.take[1] : go.take[0]);
					___ItemSlots[num].itemProperties.itemName = ((Component)___ItemSlots[num]).GetComponentInChildren<ScanNodeProperties>().headerText;
				}
			}
		}
	}
	[HarmonyPatch(typeof(HUDManager))]
	internal class hm
	{
		[HarmonyPrefix]
		[HarmonyPatch("DisplayNewScrapFound")]
		private static void Prefix1(ref List<GrabbableObject> ___itemsToBeDisplayed)
		{
			if (go.item[0] != null && (Object)(object)___itemsToBeDisplayed[0] != (Object)null && ((Object)___itemsToBeDisplayed[0].itemProperties).name == "Cog1" && (Object)(object)((Component)___itemsToBeDisplayed[0]).GetComponentInChildren<ScanNodeProperties>() != (Object)null)
			{
				___itemsToBeDisplayed[0].itemProperties.itemName = (___itemsToBeDisplayed[0].itemProperties.spawnPrefab.GetComponentInChildren<ScanNodeProperties>().headerText = ((Component)___itemsToBeDisplayed[0]).GetComponentInChildren<ScanNodeProperties>().headerText);
			}
		}

		[HarmonyPatch("displayScrapTimer")]
		[HarmonyPrefix]
		private static void Prefix2(ref GameObject displayingObject)
		{
			if (go.item[0] != null && ((Object)displayingObject).name == "Cog(Clone)" && (Object)(object)displayingObject.GetComponentInChildren<ScanNodeProperties>() != (Object)null)
			{
				displayingObject.GetComponent<MeshFilter>().mesh = ((displayingObject.GetComponentInChildren<ScanNodeProperties>().headerText == go.item[1]) ? go.fish[1] : go.fish[0]);
			}
		}
	}
}