Decompiled source of BoplGuns v1.0.0

Plugins/BoplGuns.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
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(".NETFramework,Version=v4.6", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("BoplGuns")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BoplGuns")]
[assembly: AssemblyTitle("BoplGuns")]
[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 BoplGuns
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BoplGuns";

		public const string PLUGIN_NAME = "BoplGuns";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace MyFirstBoplPlugin
{
	[BepInPlugin("com.Shad0wDev.BoplGuns", "BoplGuns", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public class ProjectileScript : MonoBehaviour
		{
			private float speed = 100f;

			private void Start()
			{
				Object.Destroy((Object)(object)((Component)this).gameObject, 2f);
			}

			public void Initialize(Vector3 direction, float rotationAdjustment)
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: 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_0013: 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_0019: 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_002c: Unknown result type (might be due to invalid IL or missing references)
				Quaternion val = Quaternion.Euler(0f, 0f, rotationAdjustment);
				Vector3 val2 = val * direction;
				((Component)this).GetComponent<Rigidbody2D>().velocity = Vector2.op_Implicit(val2 * speed);
			}
		}

		public class Guns
		{
			public string Name;

			public string ImagePath;

			public string BulletPath;

			public string FireSoundURL;

			public float BulletSize;

			public Key EquipKey;

			public bool Spread;

			public float RotateFix;

			public float BulletRotateFix;
		}

		private bool loadedGuns = false;

		private GameObject gunHolder;

		private AudioSource fireSound;

		private Guns Ak47;

		private Guns Shotgun;

		private string EquippedGunString = "None";

		private Guns RealEquippedGun;

		private Texture2D currentBullet;

		private List<Guns> GunList = new List<Guns>();

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin com.Shad0wDev.BopGuns is loaded!");
		}

		private void Start()
		{
			ReadGuns();
		}

		private void ReadGuns()
		{
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			string text = Path.Combine(directoryName, "Guns");
			if (!Directory.Exists(text))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Guns directory not found: " + text));
				return;
			}
			Debug.Log((object)("Guns directory found: " + text));
			string[] files = Directory.GetFiles(text, "*.BoplGun");
			if (files.Length == 0)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("No .BoplGun files found in directory: " + text));
				return;
			}
			string[] array = files;
			foreach (string text2 in array)
			{
				try
				{
					string text3 = File.ReadAllText(text2);
					Guns guns = ParseGun(text3);
					Debug.Log((object)("Parsed gun from file " + text2 + ": " + text3));
					if (guns != null)
					{
						GunList.Add(guns);
					}
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("Error reading gun file " + text2 + ": " + ex.Message));
				}
			}
		}

		private Guns ParseGun(string gunData)
		{
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			Guns guns = new Guns();
			string[] array = gunData.Split(new char[1] { ';' });
			string[] array2 = array;
			foreach (string text in array2)
			{
				string[] array3 = text.Split(new char[1] { '=' });
				if (array3.Length == 2)
				{
					string text2 = array3[0].Trim();
					string text3 = array3[1].Trim();
					switch (text2)
					{
					case "Name":
						guns.Name = text3;
						break;
					case "ImagePath":
						guns.ImagePath = text3;
						break;
					case "BulletPath":
						guns.BulletPath = text3;
						break;
					case "BulletSize":
						guns.BulletSize = float.Parse(text3);
						break;
					case "Spread":
						guns.Spread = bool.Parse(text3);
						break;
					case "RotateFix":
						guns.RotateFix = float.Parse(text3);
						break;
					case "BulletRotateFix":
						guns.BulletRotateFix = float.Parse(text3);
						break;
					case "EquipKey":
						guns.EquipKey = (Key)Enum.Parse(typeof(Key), text3);
						break;
					}
				}
			}
			return guns;
		}

		private void Update()
		{
			//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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			string name = ((Scene)(ref activeScene)).name;
			if (name.Contains("Level"))
			{
				foreach (Guns gun in GunList)
				{
					if (!((ButtonControl)Keyboard.current[gun.EquipKey]).wasPressedThisFrame)
					{
						continue;
					}
					if (RealEquippedGun != null)
					{
						if (RealEquippedGun.EquipKey == gun.EquipKey)
						{
							Object.Destroy((Object)(object)GameObject.Find("PlayerList/Player(Clone)/GunSprite"));
							RealEquippedGun = null;
							loadedGuns = false;
						}
						else
						{
							EquipGun(gun);
						}
					}
					else
					{
						EquipGun(gun);
					}
				}
			}
			if (loadedGuns)
			{
				RotateGunTowardsMouse();
				if (Mouse.current.leftButton.wasPressedThisFrame)
				{
					ShootProjectile();
				}
			}
		}

		private void CreateGun(Texture2D gunTexture)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("PlayerList/Player(Clone)");
			gunHolder = new GameObject("GunSprite");
			gunHolder.transform.parent = val.transform;
			gunHolder.transform.position = val.transform.position;
			SpriteRenderer val2 = gunHolder.AddComponent<SpriteRenderer>();
			val2.sprite = Sprite.Create(gunTexture, new Rect(0f, 0f, (float)((Texture)gunTexture).width, (float)((Texture)gunTexture).height), new Vector2(0.5f, 0.5f));
		}

		private Texture2D LoadTexture(string path)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			byte[] array = File.ReadAllBytes(path);
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, array);
			return val;
		}

		private void EquipGun(Guns GunToLoad)
		{
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			string path = Path.Combine(directoryName, GunToLoad.ImagePath + ".png");
			string path2 = Path.Combine(directoryName, GunToLoad.BulletPath + ".png");
			Texture2D gunTexture = LoadTexture(path);
			Texture2D val = LoadTexture(path2);
			Object.Destroy((Object)(object)GameObject.Find("PlayerList/Player(Clone)/GunSprite"));
			CreateGun(gunTexture);
			currentBullet = val;
			RealEquippedGun = GunToLoad;
			EquippedGunString = GunToLoad.Name;
			if (!string.IsNullOrEmpty(GunToLoad.FireSoundURL))
			{
			}
			loadedGuns = true;
		}

		private void RotateGunTowardsMouse()
		{
			//IL_001f: 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_0030: 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)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)gunHolder != (Object)null)
			{
				Vector2 val = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue();
				Vector3 val2 = Camera.main.ScreenToWorldPoint(Vector2.op_Implicit(val));
				val2.z = 0f;
				Vector3 position = gunHolder.transform.position;
				Vector3 val3 = val2 - position;
				float num = Mathf.Atan2(val3.y, val3.x) * 57.29578f;
				gunHolder.transform.rotation = Quaternion.Euler(0f, 0f, num - RealEquippedGun.RotateFix);
			}
		}

		private void ShootProjectile()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Projectile");
			val.transform.position = gunHolder.transform.position;
			val.transform.rotation = gunHolder.transform.rotation;
			SpriteRenderer val2 = val.AddComponent<SpriteRenderer>();
			val2.sprite = Sprite.Create(currentBullet, new Rect(0f, 0f, (float)((Texture)currentBullet).width, (float)((Texture)currentBullet).height), new Vector2(0.5f, 0.5f));
			val.transform.localScale = new Vector3(RealEquippedGun.BulletSize, RealEquippedGun.BulletSize, 1f);
			float bulletRotateFix = RealEquippedGun.BulletRotateFix;
			Rigidbody2D val3 = val.AddComponent<Rigidbody2D>();
			if (RealEquippedGun.Spread)
			{
				GameObject val4 = val;
				GameObject val5 = Object.Instantiate<GameObject>(val);
				GameObject val6 = Object.Instantiate<GameObject>(val);
				Vector2 val7 = Vector2.op_Implicit(-gunHolder.transform.right * 100f);
				val7 = Vector2.op_Implicit(Quaternion.Euler(0f, 0f, bulletRotateFix) * Vector2.op_Implicit(val7));
				Vector3 val8 = gunHolder.transform.right + gunHolder.transform.up;
				Vector2 val9 = Vector2.op_Implicit(-((Vector3)(ref val8)).normalized * 100f);
				val9 = Vector2.op_Implicit(Quaternion.Euler(0f, 0f, bulletRotateFix) * Vector2.op_Implicit(val9));
				val8 = gunHolder.transform.right - gunHolder.transform.up;
				Vector2 val10 = Vector2.op_Implicit(-((Vector3)(ref val8)).normalized * 100f);
				val10 = Vector2.op_Implicit(Quaternion.Euler(0f, 0f, bulletRotateFix) * Vector2.op_Implicit(val10));
				val4.GetComponent<Rigidbody2D>().velocity = val7;
				val5.GetComponent<Rigidbody2D>().velocity = val9;
				val6.GetComponent<Rigidbody2D>().velocity = val10;
				Object.Destroy((Object)(object)val4, 10f);
				Object.Destroy((Object)(object)val5, 10f);
				Object.Destroy((Object)(object)val6, 10f);
			}
			else
			{
				GameObject val11 = val;
				val11.AddComponent<CircleCollider2D>();
				((Collider2D)val11.GetComponent<CircleCollider2D>()).isTrigger = true;
				Vector2 val12 = Vector2.op_Implicit(-gunHolder.transform.right * 100f);
				val12 = Vector2.op_Implicit(Quaternion.Euler(0f, 0f, bulletRotateFix) * Vector2.op_Implicit(val12));
				val3.velocity = val12;
				Object.Destroy((Object)(object)val11, 10f);
			}
		}
	}
}