Decompiled source of RiskHunters v1.0.0

Pocket.RiskHunters.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;

[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("Pocket.RiskHunters")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RiskHunters")]
[assembly: AssemblyTitle("Pocket.RiskHunters")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 RiskHunters
{
	[BepInPlugin("Pocket.RiskHunters", "RiskHunters", "1.0.0")]
	public class RiskHunters : BaseUnityPlugin
	{
		private enum PlayerType
		{
			Hunter,
			Hunted,
			Debug
		}

		private static Random random = new Random();

		private static PlayerCharacterMasterController? target;

		private static float maxGain = 500f;

		private static float startTimer;

		private static int index = 0;

		private static string[] scenes = new string[15]
		{
			"RoR2/Base/blackbeach/blackbeach.asset", "RoR2/Base/blackbeach2/blackbeach2.asset", "RoR2/Base/dampcavesimple/dampcavesimple.asset", "RoR2/Base/foggyswamp/foggyswamp.asset", "RoR2/Base/frozenwall/frozenwall.asset", "RoR2/Base/golemplains/golemplains.asset", "RoR2/Base/golemplains2/golemplains2.asset", "RoR2/Base/goolake/goolake.asset", "RoR2/Base/rootjungle/rootjungle.asset", "RoR2/Base/shipgraveyard/shipgraveyard.asset",
			"RoR2/Base/skymeadow/skymeadow.asset", "RoR2/Base/wispgraveyard/wispgraveyard.asset", "RoR2/DLC1/ancientloft/ancientloft.asset", "RoR2/DLC1/snowyforest/snowyforest.asset", "RoR2/DLC1/sulfurpools/sulfurpools.asset"
		};

		public static RiskHunters Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			AddHooks();
			Logger.LogInfo((object)"Pocket.RiskHunters v1.0.0 has loaded!");
		}

		private static void AddHooks()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			Run.Start += new hook_Start(Run_Start);
			SceneDirector.PopulateScene += new hook_PopulateScene(SceneDirector_PopulateScene);
		}

		private static void Run_Start(orig_Start orig, Run self)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			if (((NetworkBehaviour)Run.instance).isServer)
			{
				Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
				{
					baseToken = "<color=#bb0011>[RH] RISK HUNTERS GO!"
				});
				random = new Random((int)Run.instance.seed);
				orig.Invoke(self);
			}
		}

		private static void SceneDirector_PopulateScene(orig_PopulateScene orig, SceneDirector self)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_004d: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)self.teleporterInstance) && Object.op_Implicit((Object)(object)self.teleporterSpawnCard))
			{
				self.teleporterInstance = DirectorCore.instance.TrySpawnObject(new DirectorSpawnRequest(self.teleporterSpawnCard, new DirectorPlacementRule
				{
					placementMode = (PlacementMode)4
				}, new Xoroshiro128Plus(Run.instance.seed)));
				Run.instance.OnServerTeleporterPlaced(self, self.teleporterInstance);
			}
		}

		public void FixedUpdate()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name == "lobby")
			{
				return;
			}
			activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name == "intro")
			{
				return;
			}
			activeScene = SceneManager.GetActiveScene();
			if (!(((Scene)(ref activeScene)).name == "splash"))
			{
				if (Input.GetKeyDown((KeyCode)48))
				{
					SetAllPlayersTeams();
				}
				if (Input.GetKeyDown((KeyCode)57))
				{
					AdvanceScene();
				}
				CheckTargetPlayerStatus();
				EraseMonsters();
			}
		}

		private static void CheckTargetPlayerStatus()
		{
			if (!((Object)(object)target == (Object)null) && PlayerCharacterMasterController.instances.Count > 1)
			{
				HealthComponent healthComponent = target.master.GetBody().healthComponent;
				if (!healthComponent.alive)
				{
					AddScores();
					AdvanceScene();
				}
			}
		}

		private static void AddScores()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			if (((NetworkBehaviour)Run.instance).isServer)
			{
				float num = Run.instance.time - startTimer;
				SimpleChatMessage val = new SimpleChatMessage();
				string[] obj = new string[5] { "<color=#bb0011>[RH] ", null, null, null, null };
				PlayerCharacterMasterController? obj2 = target;
				obj[1] = ((obj2 != null) ? obj2.GetDisplayName() : null);
				obj[2] = " gains ";
				obj[3] = Mathf.Min(num, maxGain).ToString();
				obj[4] = " points!";
				val.baseToken = string.Concat(obj);
				Chat.SendBroadcastChat((ChatMessageBase)(object)val);
			}
		}

		private static void CancelEnemySpawnSystem()
		{
			if (Object.FindObjectsOfType<DirectorCore>().Length != 0)
			{
				DirectorCore[] array = Object.FindObjectsOfType<DirectorCore>();
				foreach (DirectorCore val in array)
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
		}

		private static void EraseMonsters()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			List<HealthComponent> list = new List<HealthComponent>();
			CharacterBody[] array = Object.FindObjectsOfType<CharacterBody>();
			foreach (CharacterBody val in array)
			{
				if ((Object)(object)val.master != (Object)null && (int)val.master.teamIndex == 2)
				{
					list.Add(val.healthComponent);
				}
			}
			for (int j = 0; j < list.Count; j++)
			{
				if ((Object)(object)list[j] != (Object)null)
				{
					list[j].Suicide((GameObject)null, (GameObject)null, (DamageType)0);
				}
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void SetAllPlayersTeams(ConCommandArgs args)
		{
			SetAllPlayersTeams();
		}

		private static void SetAllPlayersTeams()
		{
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Expected O, but got Unknown
			startTimer = Run.instance.time;
			EraseMonsters();
			int count = PlayerCharacterMasterController.instances.Count;
			int num = random.Next(0, count);
			if (count > 1)
			{
				int num2 = 0;
				foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
				{
					if (num2++ == num)
					{
						instance.master.teamIndex = (TeamIndex)0;
						target = instance;
						OutfitPlayer(instance, PlayerType.Hunted);
					}
					else
					{
						instance.master.teamIndex = (TeamIndex)1;
						OutfitPlayer(instance, PlayerType.Hunter);
					}
				}
			}
			else
			{
				foreach (PlayerCharacterMasterController instance2 in PlayerCharacterMasterController.instances)
				{
					instance2.master.teamIndex = (TeamIndex)0;
					target = instance2;
					OutfitPlayer(instance2, PlayerType.Debug);
				}
			}
			if ((Object)(object)target != (Object)null)
			{
				Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
				{
					baseToken = "<color=#bb0011>[RH] Hunt " + target.GetDisplayName() + "!"
				});
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void RedItem(ConCommandArgs args)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
				{
					baseToken = "<color=#bb0011>[RH] Giving item index " + index
				});
				GiveItem(instance, Run.instance.availableTier3DropList[index++], 1);
			}
		}

		private static void OutfitPlayer(PlayerCharacterMasterController playerCharacterMasterController, PlayerType playerType)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			ClearItems(playerCharacterMasterController);
			switch (playerType)
			{
			case PlayerType.Hunter:
				GiveItem(playerCharacterMasterController, Run.instance.availableTier1DropList[14], 20);
				GiveItem(playerCharacterMasterController, Run.instance.availableTier3DropList[10], 1);
				break;
			case PlayerType.Hunted:
				GiveItem(playerCharacterMasterController, Run.instance.availableTier1DropList[3], 999);
				break;
			case PlayerType.Debug:
				GiveItem(playerCharacterMasterController, Run.instance.availableTier1DropList[14], 20);
				GiveItem(playerCharacterMasterController, Run.instance.availableTier3DropList[10], 1);
				break;
			}
		}

		private static void ClearItems(PlayerCharacterMasterController playerCharacterMasterController)
		{
			//IL_001b: 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)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			CharacterMaster master = playerCharacterMasterController.master;
			List<ItemIndex> itemAcquisitionOrder = master.inventory.itemAcquisitionOrder;
			for (int i = 0; i < itemAcquisitionOrder.Count; i++)
			{
				ItemIndex val = itemAcquisitionOrder[0];
				master.inventory.RemoveItem(val, Mathf.Min(master.inventory.GetItemCount(val), int.MaxValue));
			}
		}

		private static void GiveItem(PlayerCharacterMasterController playerCharacterMasterController, PickupIndex pickupIndex, int count)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			CharacterMaster master = playerCharacterMasterController.master;
			master.inventory.GiveItem(PickupCatalog.GetPickupDef(pickupIndex).itemIndex, count);
		}

		private static SceneDef SetSceneDef()
		{
			//IL_0018: 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)
			return Addressables.LoadAssetAsync<SceneDef>((object)scenes[random.Next(0, scenes.Length)]).WaitForCompletion();
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void AdvanceScene(ConCommandArgs args)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			if ((Object)(object)target != (Object)null)
			{
				float num = Run.instance.time - startTimer;
				SimpleChatMessage val = new SimpleChatMessage();
				val.baseToken = "<color=#bb0011>[RH] " + target.GetDisplayName() + " gains " + Mathf.Min(num, maxGain) + " points!";
				Chat.SendBroadcastChat((ChatMessageBase)(object)val);
			}
			AdvanceScene();
		}

		private static void AdvanceScene()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			SceneDef val = SetSceneDef();
			Debug.Log((object)val.baseSceneName);
			SceneExitController val2 = Object.FindObjectOfType<SceneExitController>();
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = new SceneExitController();
			}
			val2.useRunNextStageScene = false;
			val2.destinationScene = val;
			val2.SetState((ExitState)2);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Pocket.RiskHunters";

		public const string PLUGIN_NAME = "RiskHunters";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}