Decompiled source of Russian Roulette v1.0.1

plugins/RussianRoulette.dll

Decompiled 3 weeks ago
using System;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PEAKLib.Core;
using PEAKLib.Items.UnityEditor;
using Peak.Afflictions;
using Photon.Pun;
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(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("RussianRoulette2")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("RussianRoulette2")]
[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 RussianRoulette2
{
	public class Action_RotateGun : ItemActionBase
	{
		public bool rotated = false;

		public bool GetRotated()
		{
			return rotated;
		}

		protected override void Subscribe()
		{
			Item item = base.item;
			item.OnSecondaryFinishedCast = (Action)Delegate.Combine(item.OnSecondaryFinishedCast, new Action(Rotate));
		}

		protected override void Unsubscribe()
		{
			Item item = base.item;
			item.OnSecondaryFinishedCast = (Action)Delegate.Remove(item.OnSecondaryFinishedCast, new Action(Rotate));
		}

		private void Rotate()
		{
			rotated = !rotated;
			Plugin.Log.LogInfo((object)("Rotated gun:" + rotated));
			((MonoBehaviourPun)this).photonView.RPC("RPC_OrientGun", (RpcTarget)0, new object[2]
			{
				((MonoBehaviourPun)base.item).photonView.ViewID,
				rotated
			});
		}

		[PunRPC]
		private void RPC_OrientGun(int itemPhotonID, bool rotated)
		{
			PhotonView val = PhotonView.Find(itemPhotonID);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"Could not find gun by photon id.");
				return;
			}
			Plugin.Log.LogInfo((object)"Gun rotated for everybody.");
			Item val2 = ((val != null) ? ((Component)val).GetComponent<Item>() : null);
			((Renderer)((Component)((Component)val2).transform.GetChild(1)).GetComponent<MeshRenderer>()).enabled = !rotated;
			((Renderer)((Component)((Component)val2).transform.GetChild(2)).GetComponent<MeshRenderer>()).enabled = rotated;
		}
	}
	public class Action_ShootGun : ItemAction
	{
		public float maxDistance;

		public float dartCollisionSize;

		public int shootChance;

		public Action_RotateGun rotateAction;

		public float bonusStamina;

		public float damage;

		public Transform spawnTransform;

		public GameObject dartVFX;

		private LayerType layerMaskType;

		private RaycastHit lineHit;

		private RaycastHit[] sphereHits;

		public SFX_Instance shotSFX;

		public SFX_Instance emptySFX;

		public override void RunAction()
		{
			FireDart();
		}

		private void OnDrawGizmosSelected()
		{
			//IL_0013: 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)
			if (!((Object)(object)spawnTransform == (Object)null))
			{
				Gizmos.color = Color.red;
				Gizmos.DrawWireSphere(spawnTransform.position, dartCollisionSize);
			}
		}

		private void FireDart()
		{
			//IL_003f: 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_005f: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			if (rotateAction.GetRotated())
			{
				DartImpact(((ItemActionBase)this).character, spawnTransform.position, spawnTransform.position);
				return;
			}
			Physics.Raycast(spawnTransform.position, ((Component)MainCamera.instance).transform.forward, ref lineHit, maxDistance, LayerMask.op_Implicit(HelperFunctions.terrainMapMask), (QueryTriggerInteraction)1);
			if (!Object.op_Implicit((Object)(object)((RaycastHit)(ref lineHit)).collider))
			{
				((RaycastHit)(ref lineHit)).distance = maxDistance;
				((RaycastHit)(ref lineHit)).point = spawnTransform.position + ((Component)MainCamera.instance).transform.forward * maxDistance;
			}
			sphereHits = Physics.SphereCastAll(spawnTransform.position, dartCollisionSize, ((Component)MainCamera.instance).transform.forward, ((RaycastHit)(ref lineHit)).distance, LayerMask.GetMask(new string[1] { "Character" }), (QueryTriggerInteraction)1);
			RaycastHit[] array = sphereHits;
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val = array[i];
				if (!Object.op_Implicit((Object)(object)((RaycastHit)(ref val)).collider))
				{
					continue;
				}
				Character componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Character>();
				if (Object.op_Implicit((Object)(object)componentInParent))
				{
					Debug.Log((object)"HIT");
					if ((Object)(object)componentInParent != (Object)(object)((ItemActionBase)this).character)
					{
						DartImpact(componentInParent, spawnTransform.position, ((RaycastHit)(ref val)).point);
						return;
					}
				}
			}
			DartImpact(null, spawnTransform.position, ((RaycastHit)(ref lineHit)).point);
		}

		[PunRPC]
		private void RPC_GunSound(Vector3 origin)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			AudioSource.PlayClipAtPoint(shotSFX.GetClip(), origin);
			GamefeelHandler.instance.AddPerlinShakeProximity(origin, 5f, 0.2f, 15f, 10f);
		}

		private void DartImpact(Character hitCharacter, Vector3 origin, Vector3 endpoint)
		{
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			bool flag = Random.Range(0, 100) < shootChance;
			if (flag && !rotateAction.GetRotated())
			{
				((MonoBehaviourPun)this).photonView.RPC("RPC_StartSmoke", (RpcTarget)0, new object[1] { ((MonoBehaviourPun)((ItemActionBase)this).item).photonView.ViewID });
			}
			if (Object.op_Implicit((Object)(object)hitCharacter))
			{
				((MonoBehaviourPun)this).photonView.RPC("RPC_GunImpact", (RpcTarget)0, new object[4]
				{
					((MonoBehaviourPun)hitCharacter).photonView.ViewID,
					origin,
					endpoint,
					flag
				});
			}
			else
			{
				((MonoBehaviourPun)this).photonView.RPC("RPC_GunImpact", (RpcTarget)0, new object[4] { -1, origin, endpoint, flag });
			}
		}

		[PunRPC]
		private void RPC_StartSmoke(int itemPhotonID)
		{
			PhotonView val = PhotonView.Find(itemPhotonID);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"Could not find gun by photon id.");
				return;
			}
			ItemParticles val2 = ((val != null) ? ((Component)val).GetComponent<ItemParticles>() : null);
			val2.EnableSmoke(true);
		}

		[PunRPC]
		private void RPC_GunImpact(int characterID, Vector3 origin, Vector3 endpoint, bool isRealBullet)
		{
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			if (characterID != -1)
			{
				Character component = ((Component)PhotonNetwork.GetPhotonView(characterID)).gameObject.GetComponent<Character>();
				if ((Object)(object)component != (Object)null && ((MonoBehaviourPun)component).photonView.IsMine)
				{
					Debug.Log((object)"I'M HIT");
					if (isRealBullet)
					{
						component.refs.afflictions.AddStatus((STATUSTYPE)0, damage, false, true);
					}
					else
					{
						component.refs.afflictions.AddAffliction((Affliction)new Affliction_AddBonusStamina(bonusStamina, 1f), false);
					}
				}
			}
			if (isRealBullet)
			{
				AudioSource.PlayClipAtPoint(shotSFX.GetClip(), origin);
				GamefeelHandler.instance.AddPerlinShakeProximity(origin, 10f, 0.2f, 15f, 10f);
				if (!rotateAction.GetRotated())
				{
					Object.Instantiate<GameObject>(dartVFX, endpoint, Quaternion.identity);
				}
				GamefeelHandler.instance.AddPerlinShakeProximity(endpoint, 5f, 0.2f, 15f, 10f);
			}
			else
			{
				AudioSource.PlayClipAtPoint(emptySFX.GetClip(), origin);
			}
		}
	}
	[BepInPlugin("RussianRoulette", "Russian roulette", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static GameObject gunPrefab;

		internal static bool spawnGun;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			ConfigEntry<int> shotChancePercentage = ((BaseUnityPlugin)this).Config.Bind<int>("Revolver Settings", "shotChancePercentage", 20, "The chance of the shot being a real one, on 20 roughly 1 in 5 shots are real");
			ConfigEntry<int> numberOfShots = ((BaseUnityPlugin)this).Config.Bind<int>("Revolver Settings", "numberOfShots", -1, "How many bullets the revolver has. -1 is infinite.");
			ConfigEntry<double> damage = ((BaseUnityPlugin)this).Config.Bind<double>("Revolver Settings", "damage", 0.5, "How much damage a hit player should receive. By default, half their health.");
			ConfigEntry<double> bonusStamina = ((BaseUnityPlugin)this).Config.Bind<double>("Revolver Settings", "bonusStamina", 0.2, "How much bonus stamina a non-hit player should receive. By default, 20% of the bonus stamina bar.");
			ConfigEntry<bool> val = ((BaseUnityPlugin)this).Config.Bind<bool>("Revolver Settings", "spawnNextToBingBong", true, "Whether the revolver should spawn on the beach next to Bing Bong.");
			spawnGun = val.Value;
			BundleLoader.LoadBundleWithName((BaseUnityPlugin)(object)this, "revolver.peakbundle", (Action<PeakBundle>)delegate(PeakBundle peakBundle)
			{
				UnityItemContent val2 = peakBundle.LoadAsset<UnityItemContent>("ItemContent");
				GameObject itemPrefab = val2.ItemPrefab;
				Action_ShootGun action_ShootGun = itemPrefab.AddComponent<Action_ShootGun>();
				Action_RotateGun rotateAction = itemPrefab.AddComponent<Action_RotateGun>();
				((ItemAction)action_ShootGun).OnCastFinished = true;
				action_ShootGun.spawnTransform = itemPrefab.transform.GetChild(0);
				action_ShootGun.maxDistance = 500f;
				action_ShootGun.dartCollisionSize = 0.1f;
				action_ShootGun.dartVFX = peakBundle.LoadAsset<GameObject>("VFX_Gunshot");
				action_ShootGun.shotSFX = peakBundle.LoadAsset<SFX_Instance>("SFXI Gunshot");
				action_ShootGun.emptySFX = peakBundle.LoadAsset<SFX_Instance>("SFXI Empty Revolver");
				action_ShootGun.rotateAction = rotateAction;
				action_ShootGun.shootChance = shotChancePercentage.Value;
				action_ShootGun.damage = (float)damage.Value;
				action_ShootGun.bonusStamina = (float)bonusStamina.Value;
				itemPrefab.GetComponent<Item>().totalUses = numberOfShots.Value;
				gunPrefab = itemPrefab;
				peakBundle.Mod.RegisterContent();
			});
			Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin com.mironinja4.plugins.russianroulette is loaded!");
		}

		[HarmonyPatch(typeof(LocalizedText))]
		[HarmonyPatch("GetText", new Type[]
		{
			typeof(string),
			typeof(bool)
		})]
		[HarmonyPrefix]
		private static bool patchItemName(ref string __result, string id, bool printDebug)
		{
			if (id.ToUpper() == "FLIP")
			{
				__result = "flip";
				return false;
			}
			if (id.ToUpper() == "NAME_REVOLVER")
			{
				__result = "REVOLVER";
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(SingleItemSpawner))]
		[HarmonyPatch("TrySpawnItems")]
		[HarmonyPostfix]
		private static void patchSpawnGun(SingleItemSpawner __instance)
		{
			//IL_004a: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance.prefab == (Object)null))
			{
				GameObject prefab = __instance.prefab;
				if (spawnGun && ((Object)prefab).name == "BingBong")
				{
					PhotonView component = PhotonNetwork.InstantiateItemRoom(((Object)gunPrefab).name, ((Component)__instance).transform.position + Vector3.up * 0.3f, ((Component)__instance).transform.rotation).GetComponent<PhotonView>();
				}
			}
		}
	}
}