Decompiled source of Cursed items mod v1.2.0

BepInEx/CursedItems/CursedItemsMod.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using CursedItemsMod.Patches;
using GameNetcodeStuff;
using HarmonyLib;
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("CursedItemsMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CursedItemsMod")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("98e1c83f-f402-49df-9bd7-80ff10ebdbf1")]
[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 CursedItemsMod
{
	[BepInPlugin("Aksels.CursedItemsMod", "Cursed Items", "1.2.0.0")]
	public class CusedItemBase : BaseUnityPlugin
	{
		private const string modGUID = "Aksels.CursedItemsMod";

		private const string modName = "Cursed Items";

		private const string modVersion = "1.2.0.0";

		private readonly Harmony harmony = new Harmony("Aksels.CursedItemsMod");

		private static CusedItemBase Instance;

		internal ManualLogSource mls;

		internal static List<AudioClip> SoundFX;

		internal static AssetBundle Bundle;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Aksels.CursedItemsMod");
			mls.LogInfo((object)"The test mod has awaken");
			harmony.PatchAll(typeof(CusedItemBase));
			harmony.PatchAll(typeof(PlayerControllerBPatches));
			mls = ((BaseUnityPlugin)this).Logger;
			SoundFX = new List<AudioClip>();
			string location = ((BaseUnityPlugin)Instance).Info.Location;
			location = location.TrimEnd("CursedItemsMod.dll".ToCharArray());
			Bundle = AssetBundle.LoadFromFile(location + "scoob");
			if ((Object)(object)Bundle != (Object)null)
			{
				mls.LogError((object)"Successfully loaded asset bundle");
				SoundFX = Bundle.LoadAllAssets<AudioClip>().ToList();
			}
			else
			{
				mls.LogError((object)"Failed to load asset bundle");
			}
		}
	}
}
namespace CursedItemsMod.Patches
{
	internal class PlayerControllerBPatches
	{
		private static bool actionStarted = false;

		internal ManualLogSource mls;

		private static Random _random = new Random(0);

		private static Vector3 _teleportPos;

		[HarmonyPatch(typeof(PlayerControllerB), "GrabObject")]
		[HarmonyPostfix]
		private static void playerControllerBPatches(PlayerControllerB __instance)
		{
			Stopwatch stopwatch = new Stopwatch();
			AudioSource audioSource = ((Component)__instance).gameObject.AddComponent<AudioSource>();
			Random random = new Random();
			double num = random.NextDouble();
			double num2 = 0.1;
			List<Action> list = new List<Action>
			{
				delegate
				{
					WeavyOnPickup(__instance);
				},
				delegate
				{
					MuffledOnPickup(__instance);
				},
				delegate
				{
					TeleportOnPickup(__instance);
				}
			};
			if (__instance.isGrabbingObjectAnimation && !actionStarted && num < num2)
			{
				Random random2 = new Random();
				int index = random2.Next(list.Count);
				list[index]();
			}
			async void MuffledOnPickup(PlayerControllerB instance)
			{
				if (instance.isGrabbingObjectAnimation && !actionStarted)
				{
					audioSource.PlayOneShot(CusedItemBase.SoundFX[0]);
					stopwatch.Start();
					Console.WriteLine("Muffled has started");
					actionStarted = true;
				}
				while (stopwatch.ElapsedMilliseconds < 10000 && stopwatch.ElapsedMilliseconds > 0)
				{
					Console.WriteLine("Muffled is ongoing");
					instance.voiceMuffledByEnemy = true;
					await Task.Delay(100);
				}
				if (stopwatch.ElapsedMilliseconds >= 10000)
				{
					instance.voiceMuffledByEnemy = false;
					stopwatch.Stop();
					Console.WriteLine("Stopping Muffled");
					actionStarted = false;
				}
			}
			async void TeleportOnPickup(PlayerControllerB instance)
			{
				if (instance.isGrabbingObjectAnimation && !actionStarted)
				{
					Console.WriteLine("Teleport has started");
					Type type = typeof(PlayerControllerB);
					FieldInfo teleportingField = type.GetField("teleportingThisFrame", BindingFlags.Instance | BindingFlags.NonPublic);
					if (teleportingField != null)
					{
						teleportingField.SetValue(instance, true);
					}
					else
					{
						Console.WriteLine("teleportingThisFrame field not found!");
					}
					int rand = _random.Next(0, RoundManager.Instance.insideAINodes.Length);
					_teleportPos = RoundManager.Instance.insideAINodes[rand].transform.position;
					Console.WriteLine($"Set teleport position to {_teleportPos}");
					instance.TeleportPlayer(_teleportPos, false, 0f, false, true);
					audioSource.PlayOneShot(CusedItemBase.SoundFX[0]);
					await Task.Delay(1000);
					if (actionStarted)
					{
						if (teleportingField != null)
						{
							teleportingField.SetValue(instance, false);
						}
						else
						{
							Console.WriteLine("teleportingThisFrame field not found!");
						}
						actionStarted = false;
					}
				}
			}
			async void WeavyOnPickup(PlayerControllerB instance)
			{
				if (instance.isGrabbingObjectAnimation && !actionStarted)
				{
					audioSource.PlayOneShot(CusedItemBase.SoundFX[0]);
					stopwatch.Start();
					Console.WriteLine("Big chungus has started");
					actionStarted = true;
				}
				if (actionStarted)
				{
					float originalCarryWeight = __instance.carryWeight;
					float addedWeight = 3f;
					audioSource.PlayOneShot(CusedItemBase.SoundFX[0]);
					while (stopwatch.ElapsedMilliseconds < 10000 && stopwatch.ElapsedMilliseconds > 0)
					{
						Console.WriteLine("Big chungus ongoing");
						instance.carryWeight = originalCarryWeight + addedWeight;
						await Task.Delay(100);
					}
					if (stopwatch.ElapsedMilliseconds >= 10000)
					{
						__instance.carryWeight = originalCarryWeight;
						stopwatch.Stop();
						Console.WriteLine("Stopping Big chungus");
						actionStarted = false;
					}
				}
			}
		}
	}
}