Decompiled source of RollerBallMine v1.0.0

RollerBallMine.dll

Decompiled 4 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using LethalLib.Extras;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using StaticNetcodeLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RollerBallMine")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("RollerBallMine")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RollerBallMine")]
[assembly: AssemblyTitle("RollerBallMine")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RollerBallMine
{
	[BepInPlugin("wexop.roller_ball_mine", "RollerBallMine", "1.0.0")]
	[BepInDependency("evaisa.lethallib", "0.15.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class RollerBallMinePlugin : BaseUnityPlugin
	{
		private const string GUID = "wexop.roller_ball_mine";

		private const string NAME = "RollerBallMine";

		private const string VERSION = "1.0.0";

		public static RollerBallMinePlugin instance;

		public ConfigEntry<int> maxSpawn;

		public ConfigEntry<int> minSpawn;

		public ConfigEntry<float> Speed;

		public ConfigEntry<float> TriggerRadius;

		public ConfigEntry<float> ExplodeTime;

		public ConfigEntry<float> ExplosionRange;

		public ConfigEntry<int> ExplosionDamage;

		public ConfigEntry<float> DetectionRange;

		private void Awake()
		{
			instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"RollerBallMine starting....");
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "rollerballmine");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			LoadConfigs();
			SpawnableMapObjectDef val2 = val.LoadAsset<SpawnableMapObjectDef>("Assets/LethalCompany/Mods/RollerBallMine/RollerBallMine.asset");
			((BaseUnityPlugin)this).Logger.LogInfo((object)(((Object)val2.spawnableMapObject.prefabToSpawn).name + " FOUND"));
			((Keyframe)(ref val2.spawnableMapObject.numberToSpawn.keys[0])).value = instance.minSpawn.Value;
			((Keyframe)(ref val2.spawnableMapObject.numberToSpawn.keys[1])).value = instance.maxSpawn.Value;
			NetworkPrefabs.RegisterNetworkPrefab(val2.spawnableMapObject.prefabToSpawn);
			Utilities.FixMixerGroups(val2.spawnableMapObject.prefabToSpawn);
			MapObjects.RegisterMapObject(val2, (LevelTypes)(-1), (Func<SelectableLevel, AnimationCurve>)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"RollerBallMine is ready!");
		}

		public static string ConditionalString(string value)
		{
			string text = value.ToLower();
			while (text.Contains(" "))
			{
				text = text.Replace(" ", "");
			}
			return text;
		}

		private void LoadConfigs()
		{
			minSpawn = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MinSpawn", 0, "Min RollerBallMine possible for one game. You need to restart the game.");
			CreateIntConfig(minSpawn);
			maxSpawn = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxSpawn", 10, "Max RollerBallMine possible for one game. You need to restart the game.");
			CreateIntConfig(maxSpawn);
			Speed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Speed", 5f, "RollerBallMine speed. You don't need to restart the game :)");
			CreateFloatConfig(Speed, 0f, 40f);
			TriggerRadius = ((BaseUnityPlugin)this).Config.Bind<float>("General", "TriggerRadius", 0.5f, "RollerBallMine distance with player to explode. You don't need to restart the game :)");
			CreateFloatConfig(TriggerRadius, 0f, 10f);
			ExplodeTime = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ExplodeTime", 3f, "RollerBallMine time to explode if it don't touch any player. You don't need to restart the game :)");
			CreateFloatConfig(ExplodeTime, 0f, 10f);
			ExplosionRange = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ExplosionRange", 5f, "RollerBallMine explosion range. You don't need to restart the game :)");
			CreateFloatConfig(ExplosionRange, 0f, 30f);
			ExplosionDamage = ((BaseUnityPlugin)this).Config.Bind<int>("General", "ExplosionDamage", 100, "RollerBallMine explosion damage to player. You don't need to restart the game :)");
			CreateIntConfig(ExplosionDamage);
			DetectionRange = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DetectionRange", 10f, "RollerBallMine player detection distance. You don't need to restart the game :)");
			CreateFloatConfig(DetectionRange);
		}

		private void CreateFloatConfig(ConfigEntry<float> configEntry, float min = 0f, float max = 100f)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			FloatSliderOptions val = new FloatSliderOptions();
			((BaseRangeOptions<float>)val).Min = min;
			((BaseRangeOptions<float>)val).Max = max;
			((BaseOptions)val).RequiresRestart = false;
			FloatSliderConfigItem val2 = new FloatSliderConfigItem(configEntry, val);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2);
		}

		private void CreateIntConfig(ConfigEntry<int> configEntry, int min = 0, int max = 100)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			IntSliderOptions val = new IntSliderOptions();
			((BaseRangeOptions<int>)val).Min = min;
			((BaseRangeOptions<int>)val).Max = max;
			((BaseOptions)val).RequiresRestart = false;
			IntSliderConfigItem val2 = new IntSliderConfigItem(configEntry, val);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2);
		}

		private void CreateStringConfig(ConfigEntry<string> configEntry, bool requireRestart = false)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			TextInputFieldConfigItem val = new TextInputFieldConfigItem(configEntry, new TextInputFieldOptions
			{
				RequiresRestart = requireRestart
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val);
		}

		private void CreateBoolConfig(ConfigEntry<bool> configEntry, bool requireRestart = false)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			BoolCheckBoxConfigItem val = new BoolCheckBoxConfigItem(configEntry, new BoolCheckBoxOptions
			{
				RequiresRestart = requireRestart
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "RollerBallMine";

		public const string PLUGIN_NAME = "RollerBallMine";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace RollerBallMine.Utils
{
	public class RegisterUtil
	{
		public static void RegisterEnemyWithConfig(string configMoonRarity, EnemyType enemy, TerminalNode terminalNode, TerminalKeyword terminalKeyword, float powerLevel, int spawnCount)
		{
			enemy.MaxCount = spawnCount;
			enemy.PowerLevel = powerLevel;
			var (dictionary, dictionary2) = ConfigParsing(configMoonRarity);
			Enemies.RegisterEnemy(enemy, dictionary, dictionary2, terminalNode, terminalKeyword);
		}

		public static void RegisterScrapWithConfig(string configMoonRarity, Item scrap)
		{
			var (dictionary, dictionary2) = ConfigParsing(configMoonRarity);
			Items.RegisterScrap(scrap, dictionary, dictionary2);
		}

		public static void RegisterShopItemWithConfig(bool enabledScrap, Item item, TerminalNode terminalNode, int itemCost, string configMoonRarity)
		{
			Items.RegisterShopItem(item, (TerminalNode)null, (TerminalNode)null, terminalNode, itemCost);
			if (enabledScrap)
			{
				RegisterScrapWithConfig(configMoonRarity, item);
			}
		}

		public static (Dictionary<LevelTypes, int> spawnRateByLevelType, Dictionary<string, int> spawnRateByCustomLevelType) ConfigParsing(string configMoonRarity)
		{
			//IL_0099: 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)
			Dictionary<LevelTypes, int> dictionary = new Dictionary<LevelTypes, int>();
			Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
			foreach (string item in from s in configMoonRarity.Split(',')
				select s.Trim())
			{
				string[] array = item.Split(':');
				if (array.Length != 2)
				{
					continue;
				}
				string text = array[0];
				if (!int.TryParse(array[1], out var result))
				{
					continue;
				}
				if (Enum.TryParse<LevelTypes>(text, ignoreCase: true, out LevelTypes result2))
				{
					dictionary[result2] = result;
					continue;
				}
				string value = text + "Level";
				if (Enum.TryParse<LevelTypes>(value, ignoreCase: true, out result2))
				{
					dictionary[result2] = result;
				}
				else
				{
					dictionary2[text] = result;
				}
			}
			return (dictionary, dictionary2);
		}
	}
}
namespace RollerBallMine.Scripts
{
	[StaticNetcode]
	public class NetworkRollerBallMine
	{
		[ClientRpc]
		public static void DetectPlayerClientRpc(ulong networkId, Vector3 position)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			List<RollerBallMine> list = Object.FindObjectsByType<RollerBallMine>((FindObjectsSortMode)0).ToList();
			RollerBallMine rollerBallMine = list.Find((RollerBallMine e) => ((NetworkBehaviour)e).NetworkObjectId == networkId);
			if ((Object)(object)rollerBallMine == (Object)null)
			{
				Debug.LogError((object)$"ROLLER BALL NOT FOUND {networkId}");
			}
			else
			{
				rollerBallMine.DetectPlayer(position);
			}
		}

		[ClientRpc]
		public static void ExplodeClientRpc(ulong networkId)
		{
			List<RollerBallMine> list = Object.FindObjectsByType<RollerBallMine>((FindObjectsSortMode)0).ToList();
			RollerBallMine rollerBallMine = list.Find((RollerBallMine e) => ((NetworkBehaviour)e).NetworkObjectId == networkId);
			if ((Object)(object)rollerBallMine == (Object)null)
			{
				Debug.LogError((object)$"ROLLER BALL NOT FOUND {networkId}");
			}
			else
			{
				rollerBallMine.Explode();
			}
		}

		[ClientRpc]
		public static void SetValueClientRpc(ulong networkId, int value)
		{
			List<RollerBallMine> list = Object.FindObjectsByType<RollerBallMine>((FindObjectsSortMode)0).ToList();
			RollerBallMine rollerBallMine = list.Find((RollerBallMine e) => ((NetworkBehaviour)e).NetworkObjectId == networkId);
			if ((Object)(object)rollerBallMine == (Object)null)
			{
				Debug.LogError((object)$"ROLLER BALL NOT FOUND {networkId}");
			}
			else
			{
				rollerBallMine.SetValue(value);
			}
		}
	}
	public class RollerBallMine : NetworkBehaviour, IHittable
	{
		private static readonly int Run = Animator.StringToHash("run");

		private static readonly int Open = Animator.StringToHash("open");

		public GameObject model;

		public Animator modelAnimator;

		public Animator spikeAnimator;

		public NavMeshAgent navMeshAgent;

		public AudioSource sfxAudioSource;

		public AudioSource runAudioSource;

		public AudioClip explodeClip;

		public AudioClip activateClip;

		public AudioClip runClip;

		public ParticleSystem explosion;

		public float speed = 5f;

		private float explosionRange = 5f;

		private int explosionDamage = 100;

		private float detectionRange = 10f;

		private bool detected;

		private bool hasExploded;

		private float explodeTime = 3f;

		private float detectPlayerRadius = 0.5f;

		public void SetValue(int value)
		{
			ScanNodeProperties componentInChildren = ((Component)this).GetComponentInChildren<ScanNodeProperties>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.subText = $"Value: {value}";
			}
		}

		private void Start()
		{
			explodeTime = RollerBallMinePlugin.instance.ExplodeTime.Value;
			detectPlayerRadius = RollerBallMinePlugin.instance.TriggerRadius.Value;
			detectionRange = RollerBallMinePlugin.instance.DetectionRange.Value;
			explosionDamage = RollerBallMinePlugin.instance.ExplosionDamage.Value;
			speed = RollerBallMinePlugin.instance.Speed.Value;
			explosionRange = RollerBallMinePlugin.instance.ExplosionRange.Value;
			if (((NetworkBehaviour)this).IsServer)
			{
				NetworkRollerBallMine.SetValueClientRpc(((NetworkBehaviour)this).NetworkBehaviourId, Random.Range(40, 70));
			}
			((Behaviour)navMeshAgent).enabled = true;
		}

		private void Update()
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			if (hasExploded)
			{
				return;
			}
			if (detected)
			{
				explodeTime -= Time.deltaTime;
				if (explodeTime <= 0f && ((NetworkBehaviour)this).IsServer)
				{
					NetworkRollerBallMine.ExplodeClientRpc(((NetworkBehaviour)this).NetworkObjectId);
				}
				navMeshAgent.Move(((Component)this).transform.forward * speed * Time.deltaTime);
				StartOfRound.Instance.allPlayerScripts.ToList().ForEach(delegate(PlayerControllerB player)
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_0012: Unknown result type (might be due to invalid IL or missing references)
					if (Vector3.Distance(((Component)this).transform.position, ((Component)player).transform.position) <= detectPlayerRadius && ((NetworkBehaviour)this).IsServer)
					{
						NetworkRollerBallMine.ExplodeClientRpc(((NetworkBehaviour)this).NetworkObjectId);
					}
				});
				return;
			}
			StartOfRound.Instance.allPlayerScripts.ToList().ForEach(delegate(PlayerControllerB player)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: 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)
				//IL_008f: Unknown result type (might be due to invalid IL or missing references)
				if (Vector3.Distance(((Component)this).transform.position, ((Component)player).transform.position) <= detectionRange && Vector3.Distance(new Vector3(0f, ((Component)this).transform.position.y, 0f), new Vector3(0f, ((Component)player).transform.position.y, 0f)) <= 2f && ((NetworkBehaviour)this).IsServer)
				{
					NetworkRollerBallMine.DetectPlayerClientRpc(((NetworkBehaviour)this).NetworkObjectId, ((Component)player).transform.position);
				}
			});
		}

		public void DetectPlayer(Vector3 pos)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			detected = true;
			((Component)this).transform.LookAt(pos);
			((Component)this).transform.eulerAngles = new Vector3(0f, ((Component)this).transform.eulerAngles.y, 0f);
			modelAnimator.SetBool(Run, true);
			spikeAnimator.SetBool(Open, true);
			sfxAudioSource.PlayOneShot(activateClip);
		}

		public void Explode()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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)
			if (hasExploded)
			{
				return;
			}
			hasExploded = true;
			explosion.Play();
			sfxAudioSource.PlayOneShot(explodeClip);
			if (Vector3.Distance(((Component)GameNetworkManager.Instance.localPlayerController).transform.position, ((Component)this).transform.position) <= explosionRange)
			{
				GameNetworkManager.Instance.localPlayerController.DamagePlayer(explosionDamage, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
			}
			List<EnemyAI> list = Object.FindObjectsOfType<EnemyAI>().ToList();
			list.ForEach(delegate(EnemyAI enemy)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				if (Vector3.Distance(((Component)enemy).transform.position, ((Component)this).transform.position) <= explosionRange)
				{
					enemy.HitEnemy(5, (PlayerControllerB)null, false, -1);
				}
			});
			List<Landmine> list2 = Object.FindObjectsOfType<Landmine>().ToList();
			list2.ForEach(delegate(Landmine mine)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				if (!mine.hasExploded && Vector3.Distance(((Component)mine).transform.position, ((Component)this).transform.position) <= explosionRange && ((NetworkBehaviour)this).IsServer)
				{
					mine.ExplodeMineServerRpc();
				}
			});
			((MonoBehaviour)this).StartCoroutine(DestroyObject());
		}

		public IEnumerator DestroyObject()
		{
			model.SetActive(false);
			yield return (object)new WaitForSeconds(1f);
			if (((NetworkBehaviour)this).IsServer)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		public bool Hit(int force, Vector3 hitDirection, PlayerControllerB playerWhoHit = null, bool playHitSFX = false, int hitID = -1)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				NetworkRollerBallMine.ExplodeClientRpc(((NetworkBehaviour)this).NetworkObjectId);
			}
			return true;
		}

		private void OnTriggerEnter(Collider other)
		{
			if ((((Component)other).CompareTag("Player") || ((Component)other).CompareTag("Enemy")) && ((NetworkBehaviour)this).IsServer)
			{
				NetworkRollerBallMine.ExplodeClientRpc(((NetworkBehaviour)this).NetworkObjectId);
			}
		}
	}
}