Decompiled source of ViniModTrolling v1.2.1

ViniMod.dll

Decompiled 6 months 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using ViniMod.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ViniMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ViniMod")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("40cae2cb-bb3e-49f1-b936-e751b774f718")]
[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 ViniMod
{
	public class ConfigSettings
	{
		public List<ulong> SteamIdsList = new List<ulong>();

		public List<ulong> CoilHeadTargetsList = new List<ulong>();

		public List<ulong> YippeBoomTargetsList = new List<ulong>();

		public ConfigEntry<string> SteamIds { get; set; }

		public ConfigEntry<string> CoilHeadTargets { get; set; }

		public ConfigEntry<string> YippeBoomTargets { get; set; }

		public ConfigEntry<string> YippeDanceTargets { get; set; }

		public ConfigEntry<bool> ApplyToAll { get; set; }

		public void LoadConfigs()
		{
			SteamIds = ((BaseUnityPlugin)ViniModBase.Instance).Config.Bind<string>("SteamIds", "SteamIdsList", "0", "Add steamID64 (Dec) in the following format: 124551,12414124,5125251");
			CoilHeadTargets = ((BaseUnityPlugin)ViniModBase.Instance).Config.Bind<string>("CoilHeadTargets", "CoilHeadTargetsList", "0", "Add steamID64 (Dec) in the following format: 124551,12414124,5125251");
			YippeBoomTargets = ((BaseUnityPlugin)ViniModBase.Instance).Config.Bind<string>("YippeBoomTargets", "YippeBoomTargetsList", "0", "Add steamID64 (Dec) in the following format: 124551,12414124,5125251");
			ApplyToAll = ((BaseUnityPlugin)ViniModBase.Instance).Config.Bind<bool>("ApplyToAll", "ApplyToAll", true, "Apply trolling to all players in game, This will ignore the steamIDS");
			try
			{
				SteamIdsList = SteamIds.Value.Split(new char[1] { ',' }).Select(ulong.Parse).ToList();
				CoilHeadTargetsList = CoilHeadTargets.Value.Split(new char[1] { ',' }).Select(ulong.Parse).ToList();
				YippeBoomTargetsList = YippeBoomTargets.Value.Split(new char[1] { ',' }).Select(ulong.Parse).ToList();
			}
			catch (Exception ex)
			{
				ViniModBase.mls.LogError((object)("Invalid format for steamIds!" + ex.Message));
			}
		}
	}
	[BepInPlugin("ViniMod", "Vini MOD", "1.1.0")]
	public class ViniModBase : BaseUnityPlugin
	{
		private const string modGUID = "ViniMod";

		private const string modName = "Vini MOD";

		private const string modVersion = "1.1.0";

		public static ConfigSettings configSettings = new ConfigSettings();

		private readonly Harmony harmony = new Harmony("ViniMod");

		public static ViniModBase Instance;

		public static ManualLogSource mls;

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_Landmine()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("ViniMod-ClientExplodeRpc", new HandleNamedMessageDelegate(HoardingBugPatch.ExplodeYipeeClientRpc));
			NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("ViniMod-ServerExplodeRpc", new HandleNamedMessageDelegate(HoardingBugPatch.ExplodeYipeeServerRpc));
		}

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("ViniMod");
			mls.LogDebug((object)"ViniMod has awoken!");
			configSettings.LoadConfigs();
			mls.LogDebug((object)"Config has awoken!");
			mls = ((BaseUnityPlugin)this).Logger;
			harmony.PatchAll(typeof(ViniModBase));
			harmony.PatchAll(typeof(RoundManagerPatch));
			harmony.PatchAll(typeof(HoardingBugPatch));
			harmony.PatchAll(typeof(CoilHeadPatch));
		}
	}
}
namespace ViniMod.Patches
{
	internal class CoilHeadPatch
	{
		[HarmonyPatch(typeof(SpringManAI), "Update")]
		[HarmonyPostfix]
		public static void Prefix(SpringManAI __instance, ref float ___currentAnimSpeed)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			List<PlayerControllerB> list = StartOfRound.Instance.allPlayerScripts.Where((PlayerControllerB item) => ViniModBase.configSettings.CoilHeadTargetsList.Contains(item.playerSteamId)).ToList();
			if (ViniModBase.configSettings.ApplyToAll.Value)
			{
				list = StartOfRound.Instance.allPlayerScripts.ToList();
			}
			foreach (PlayerControllerB item in list)
			{
				if (item.HasLineOfSightToPosition(((Component)__instance).transform.position + Vector3.up * 1.6f, 68f, 60, -1f) && Vector3.Distance(((Component)item.gameplayCamera).transform.position, ((EnemyAI)__instance).eye.position) > 0.3f)
				{
					if (!((NetworkBehaviour)__instance).IsServer)
					{
						((EnemyAI)__instance).ChangeOwnershipOfEnemy(StartOfRound.Instance.allPlayerScripts[0].actualClientId);
					}
					__instance.SetAnimationGoServerRpc();
					___currentAnimSpeed = 0.01f;
					((EnemyAI)__instance).creatureAnimator.SetFloat("walkSpeed", 0.01f);
					((EnemyAI)__instance).agent.speed = 0.01f;
				}
			}
		}
	}
	internal class FlowerManPatch
	{
		[HarmonyPatch(typeof(FlowermanAI), "DoAIInterval")]
		[HarmonyPrefix]
		public static void Prefix(HoarderBugAI __instance, ref PlayerControllerB ___targetPlayer)
		{
			if (!___targetPlayer.isPlayerDead)
			{
				PlayerControllerB val = StartOfRound.Instance.allPlayerScripts.Where((PlayerControllerB item) => ViniModBase.configSettings.SteamIdsList.Contains(item.playerSteamId)).First();
				ViniModBase.mls.LogDebug((object)((Object)val).name);
				if ((Object)(object)val != (Object)null)
				{
					((EnemyAI)__instance).targetPlayer = val;
				}
			}
		}
	}
	[HarmonyPatch(typeof(HoarderBugAI))]
	internal class HoardingBugPatch : NetworkBehaviour
	{
		public static HoardingBugPatch hoardingBugPatchInst;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void startPatch()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("ViniMod-ClientExplodeRpc", new HandleNamedMessageDelegate(ExplodeYipeeClientRpc));
			NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("ViniMod-ServerExplodeRpc", new HandleNamedMessageDelegate(ExplodeYipeeServerRpc));
		}

		[HarmonyPatch(typeof(HoarderBugAI), "DetectAndLookAtPlayers")]
		[HarmonyPostfix]
		public static void Postfix(HoarderBugAI __instance, ref bool ___isEnemyDead, ref float ___annoyanceMeter, ref Vector3 ___serverPosition)
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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)
			PlayerControllerB val;
			try
			{
				val = ((EnemyAI)__instance).GetClosestPlayer(true, true, true);
			}
			catch
			{
				val = null;
			}
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			if ((Object)(object)hoardingBugPatchInst == (Object)null)
			{
				hoardingBugPatchInst = new HoardingBugPatch();
			}
			if ((ViniModBase.configSettings.YippeBoomTargetsList.Contains(val.playerSteamId) || ViniModBase.configSettings.ApplyToAll.Value) && !___isEnemyDead && ((Object)(object)__instance?.angryAtPlayer != (Object)null || ___annoyanceMeter > 1.5f || Vector3.Distance(((Component)val).transform.position, ___serverPosition) < 5f))
			{
				ViniModBase.mls.LogDebug((object)("Yipeee BOOM!" + ((Object)((Component)val).transform).name + "  " + val.playerUsername + "\n"));
				RoundManager.PlayRandomClip(((EnemyAI)__instance).creatureSFX, __instance.chitterSFX, true, 1f, 0);
				if ((Object)(object)val != (Object)null && !val.isPlayerDead && !((Object)(object)val != (Object)(object)GameNetworkManager.Instance.localPlayerController))
				{
					hoardingBugPatchInst.TriggerMineOnLocalClientByExiting(___serverPosition);
				}
			}
		}

		private void TriggerMineOnLocalClientByExiting(Vector3 location)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			Landmine.SpawnExplosion(location, true, 5f, 5f);
			ManualLogSource mls = ViniModBase.mls;
			Vector3 val = location;
			mls.LogDebug((object)("Boom at " + ((object)(Vector3)(ref val)).ToString()));
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				ViniModBase.mls.LogDebug((object)"Server is dead?");
				return;
			}
			ViniModBase.mls.LogInfo((object)base.__rpc_exec_stage);
			if (networkManager.IsServer || networkManager.IsHost)
			{
				ViniModBase.mls.LogDebug((object)"Ís server, sending to clients...");
				FastBufferWriter val2 = default(FastBufferWriter);
				((FastBufferWriter)(ref val2))..ctor(12, (Allocator)2, -1);
				((FastBufferWriter)(ref val2)).WriteValueSafe(ref location);
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("ViniMod-ClientExplodeRpc", val2, (NetworkDelivery)3);
			}
			else
			{
				ViniModBase.mls.LogDebug((object)"is client, sending to Server...");
				FastBufferWriter val3 = default(FastBufferWriter);
				((FastBufferWriter)(ref val3))..ctor(12, (Allocator)2, -1);
				((FastBufferWriter)(ref val3)).WriteValueSafe(ref location);
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("ViniMod-ServerExplodeRpc", 0uL, val3, (NetworkDelivery)3);
			}
		}

		public static void ExplodeYipeeClientRpc(ulong clientId, FastBufferReader reader)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = default(Vector3);
			((FastBufferReader)(ref reader)).ReadValue(ref val);
			Landmine.SpawnExplosion(val, true, 5f, 5f);
			ViniModBase.mls.LogDebug((object)"ExplodeClientRPC");
		}

		public static void ExplodeYipeeServerRpc(ulong clientId, FastBufferReader reader)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = default(Vector3);
			((FastBufferReader)(ref reader)).ReadValue(ref val);
			Landmine.SpawnExplosion(val, true, 5f, 5f);
			ViniModBase.mls.LogDebug((object)"Explode Server RPC");
			FastBufferWriter val2 = default(FastBufferWriter);
			((FastBufferWriter)(ref val2))..ctor(12, (Allocator)2, -1);
			((FastBufferWriter)(ref val2)).WriteValueSafe(ref val);
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("ViniMod-ClientExplodeRpc", val2, (NetworkDelivery)3);
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		[HarmonyPatch(typeof(RoundManager), "LoadNewLevel")]
		[HarmonyPrefix]
		public static void spawnYippees(ref SelectableLevel newLevel)
		{
			//IL_0180: 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_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: 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_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			ViniModBase.mls.LogDebug((object)newLevel.PlanetName);
			if (!(newLevel.PlanetName == "71 Gordion"))
			{
				return;
			}
			bool flag = false;
			bool flag2 = false;
			foreach (SpawnableEnemyWithRarity outsideEnemy in newLevel.OutsideEnemies)
			{
				if ((Object)(object)outsideEnemy.enemyType.enemyPrefab.GetComponent<NutcrackerEnemyAI>() != (Object)null)
				{
					flag = true;
				}
			}
			if (!flag)
			{
				SelectableLevel[] levels = StartOfRound.Instance.levels;
				foreach (SelectableLevel val in levels)
				{
					foreach (SpawnableEnemyWithRarity enemy in val.Enemies)
					{
						if ((Object)(object)enemy.enemyType.enemyPrefab.GetComponent<NutcrackerEnemyAI>() != (Object)null && !flag2)
						{
							flag2 = true;
							newLevel.OutsideEnemies.Add(enemy);
						}
					}
				}
			}
			for (int j = 0; j < newLevel.OutsideEnemies.Count; j++)
			{
				if ((Object)(object)newLevel.OutsideEnemies[j].enemyType.enemyPrefab.GetComponent<NutcrackerEnemyAI>() != (Object)null)
				{
					Vector3 navMeshPosition = RoundManager.Instance.GetNavMeshPosition(new Vector3(10f, -2.67f, 10f), default(NavMeshHit), 5f, -1);
					GameObject val2 = Object.Instantiate<GameObject>(newLevel.OutsideEnemies[j].enemyType.enemyPrefab, navMeshPosition, Quaternion.Euler(Vector3.zero));
					val2.gameObject.GetComponentInChildren<NetworkObject>().Spawn(true);
					RoundManager.Instance.SpawnedEnemies.Add(val2.GetComponent<EnemyAI>());
					EnemyType enemyType = val2.GetComponent<EnemyAI>().enemyType;
					enemyType.numberSpawned++;
					((Behaviour)val2.GetComponent<NavMeshAgent>()).enabled = true;
				}
				else
				{
					ViniModBase.mls.LogDebug((object)("Found a " + ((Object)newLevel.OutsideEnemies[j].enemyType).name + ":("));
				}
			}
		}
	}
}