Decompiled source of SnickiUpgrades v1.0.2

SnickiUpgrades.dll

Decompiled a month ago
using System;
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 System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using REPOLib.Modules;
using Unity.VisualScripting;
using UnityEngine;

[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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Snicki")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+fc440fd86bed2a16810aaec392f81e22df5ac1d1")]
[assembly: AssemblyProduct("SnickiUpgrades")]
[assembly: AssemblyTitle("SnickiUpgrades")]
[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 SnickiUpgrades
{
	[HarmonyPatch(typeof(RunManager))]
	internal class PlayerManagerScript
	{
		private static Random rng = new Random();

		private static List<Player> _players = new List<Player>();

		private static bool playerRevived = false;

		[HarmonyPatch("ChangeLevel")]
		private static void RunManagerChangeLevelPostfix()
		{
			if (!SemiFunc.IsMultiplayer() || !SemiFunc.IsNotMasterClient())
			{
				ApplyPatch();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("UpdateLevel")]
		private static void RunManagerUpdateLevelPostfix()
		{
			if (!SemiFunc.IsMasterClientOrSingleplayer())
			{
				ApplyPatch();
			}
		}

		private static void ApplyPatch()
		{
			if (SemiFunc.RunIsShop() && SemiFunc.IsMasterClientOrSingleplayer())
			{
				SnickiUpgrades.Logger.LogDebug((object)"Dies ist der Shop");
			}
			else if (SemiFunc.RunIsLevel())
			{
				SnickiUpgrades.Logger.LogDebug((object)"Dies ist ein Level");
				playerRevived = false;
				_players = PhotonNetwork.PlayerList.ToList();
			}
			else if (SemiFunc.RunIsArena())
			{
				SnickiUpgrades.Logger.LogDebug((object)"Dies ist die Arena");
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerHealth), "Death")]
		private static void PlayerDied()
		{
			SnickiUpgrades.Logger.LogDebug((object)"Player Died");
			PlayerAvatar[] source = Object.FindObjectsOfType<PlayerAvatar>();
			List<PlayerAvatar> list = new List<PlayerAvatar>();
			foreach (KeyValuePair<string, int> dic in Upgrades.GetUpgrade("Last Chance").PlayerDictionary)
			{
				if (dic.Value >= 1)
				{
					List<PlayerAvatar> list2 = source.Where((PlayerAvatar x) => x.steamID == dic.Key).ToList();
					if (list2.Count() > 0 && Object.op_Implicit((Object)(object)list2[0]))
					{
						list.Add(list2[0]);
					}
				}
			}
			if (!list.Any((PlayerAvatar x) => x.playerHealth.health > 0) && !playerRevived)
			{
				PlayerAvatar val = list[rng.Next(0, list.Count() - 1)];
				RevivePlayer(val);
				SnickiUpgrades.LastChanceUpgradeRegister.RemoveLevel(val.steamID, 1);
				playerRevived = true;
			}
		}

		private static async void RevivePlayer(PlayerAvatar player)
		{
			Component teleporter = default(Component);
			if (!((Component)player).TryGetComponent(typeof(Teleporter), ref teleporter))
			{
				teleporter = (Component)(object)((Component)player).gameObject.AddComponent<Teleporter>();
			}
			await Task.Delay(1250);
			player.playerHealth.health = player.playerHealth.maxHealth;
			player.playerHealth.InvincibleSet(1.5f);
			player.Revive(true);
			SnickiUpgrades.Logger.LogInfo((object)("Revived player named => " + player.playerName));
			await Task.Delay(100);
			if (RoundDirector.instance.allExtractionPointsCompleted)
			{
				SnickiUpgrades.Logger.LogDebug((object)"Teleporting to random Extract");
				List<GameObject> extractpoints = RoundDirector.instance.extractionPointList;
				TruckDoor truckdoor = Object.FindObjectOfType<TruckDoor>();
				if (extractpoints.Count > 1)
				{
					extractpoints.Remove(((Component)truckdoor.extractionPointNearest).gameObject);
				}
				GameObject selectedPoint = extractpoints[rng.Next(0, extractpoints.Count() - 1)];
				((Teleporter)(object)teleporter).MoveToObject(player, selectedPoint);
			}
			else
			{
				SnickiUpgrades.Logger.LogDebug((object)"Teleporting to Truck");
				((Teleporter)(object)teleporter).MoveToTruck(player);
			}
		}
	}
	[BepInPlugin("Snicki.SnickiUpgrades", "SnickiUpgrades", "1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class SnickiUpgrades : BaseUnityPlugin
	{
		public static GameObject teleporter;

		public static PlayerUpgrade LastChanceUpgradeRegister;

		internal static SnickiUpgrades Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			string text = Path.Combine(directoryName, "snickiupgrades");
			AssetBundle assetBundle = AssetBundle.LoadFromFile(text);
			InitUpgrades(assetBundle);
		}

		private static void InitUpgrades(AssetBundle assetBundle)
		{
			Logger.LogDebug((object)"Init Upgrades");
			Item val = assetBundle.LoadAsset<Item>("Item Upgrade Player Last Chance");
			val.prefab = assetBundle.LoadAsset<GameObject>("Item Upgrade Player Last Chance");
			Items.RegisterItem(val);
			LastChanceUpgradeRegister = Upgrades.RegisterUpgrade("Last Chance", val, (Action<PlayerAvatar, int>)InitLastChanceUpgrade, (Action<PlayerAvatar, int>)UseLastChanceUpgrade);
		}

		private static void InitLastChanceUpgrade(PlayerAvatar player, int level)
		{
			Logger.LogDebug((object)"Upgrade got Init");
			if (player.isLocal)
			{
			}
		}

		private static void UseLastChanceUpgrade(PlayerAvatar player, int level)
		{
			Logger.LogDebug((object)"Upgrade got Used");
			if (player.isLocal)
			{
			}
		}

		internal void Patch()
		{
			//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_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll(typeof(PlayerManagerScript));
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
	internal class Teleporter : MonoBehaviourPun
	{
		public static Teleporter Instance;

		private PhotonView photonView;

		private void Awake()
		{
			if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			Instance = this;
			photonView = ComponentHolderProtocol.AddComponent<PhotonView>((Object)(object)this);
		}

		public void MoveToTruck(PlayerAvatar player)
		{
			//IL_009a: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			SnickiUpgrades.Logger.LogDebug((object)"Mocing to Truck");
			if (SemiFunc.IsMultiplayer())
			{
				player.photonView.RPC("ForceTeleportRPC", (RpcTarget)0, new object[3]
				{
					player.photonView.ViewID,
					((Component)LevelGenerator.Instance.LevelPathTruck).transform.position,
					((Component)LevelGenerator.Instance.LevelPathTruck).transform.rotation
				});
			}
			else
			{
				ForceTeleportRPC(player.photonView.ViewID, ((Component)LevelGenerator.Instance.LevelPathTruck).transform.position, ((Component)LevelGenerator.Instance.LevelPathTruck).transform.rotation);
			}
		}

		public void MoveToObject(PlayerAvatar player, GameObject gameObject)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.IsMultiplayer())
			{
				player.photonView.RPC("ForceTeleportRPC", (RpcTarget)0, new object[3]
				{
					player.photonView.ViewID,
					gameObject.transform.position,
					gameObject.transform.rotation
				});
			}
			else
			{
				ForceTeleportRPC(player.photonView.ViewID, gameObject.transform.position, gameObject.transform.rotation);
			}
		}

		[PunRPC]
		public void ForceTeleportRPC(int photonViewId, Vector3 position, Quaternion rotation)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			ForceTeleportRPC_internal(SemiFunc.PlayerAvatarGetFromPhotonID(photonViewId), position, rotation);
		}

		private void ForceTeleportRPC_internal(PlayerAvatar player, Vector3 position, Quaternion rotation)
		{
			//IL_0007: 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)
			//IL_001c: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			((Component)player).transform.position = position;
			((Component)player).transform.rotation = rotation;
			player.clientPosition = position;
			player.clientRotation = rotation;
			player.clientPositionCurrent = position;
			player.clientRotationCurrent = rotation;
			if (player.isLocal && (Object)(object)PlayerController.instance != (Object)null)
			{
				PlayerController instance = PlayerController.instance;
				((Component)instance).transform.position = position;
				((Component)instance).transform.rotation = rotation;
				instance.rb.velocity = Vector3.zero;
				instance.rb.angularVelocity = Vector3.zero;
				instance.rb.MovePosition(position);
				instance.rb.MoveRotation(rotation);
				instance.InputDisable(0.1f);
				PlayerCollisionController collisionController = instance.CollisionController;
				if (collisionController != null)
				{
					collisionController.ResetFalling();
				}
			}
		}
	}
}