Decompiled source of Shotgun v1.0.0

Gun.dll

Decompiled 6 months ago
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using LC_API.ServerAPI;
using LethalLib.Modules;
using Unity.Netcode;
using UnityEngine;
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 = "")]
[assembly: AssemblyCompany("Gun")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Gun")]
[assembly: AssemblyTitle("Gun")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Gun;

[BepInPlugin("Gun", "Gun", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public static ManualLogSource logger;

	public void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Gun is loaded!");
		AssetBundle val = AssetBundle.LoadFromMemory(Resource1.shotgun);
		string[] allAssetNames = val.GetAllAssetNames();
		foreach (string text in allAssetNames)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)text);
		}
		Item val2 = val.LoadAsset<Item>("shotgun");
		Shotgun shotgun = val2.spawnPrefab.AddComponent<Shotgun>();
		((GrabbableObject)shotgun).itemProperties = val2;
		shotgun.shootSound = val.LoadAsset<AudioClip>("fire");
		shotgun.noammoSound = val.LoadAsset<AudioClip>("noammo");
		shotgun.BulletTrail = val.LoadAsset<GameObject>("hot trail");
		Items.RegisterShopItem(val2, 0);
		NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		if (Utils.Main.IsIngame())
		{
			ModdedServer.SetServerModdedOnly();
		}
	}
}
public class Shotgun : GrabbableObject
{
	private ParticleSystem particleSystem;

	private AudioSource audioSource;

	public AudioClip shootSound;

	public AudioClip noammoSound;

	public GameObject BulletTrail;

	private Transform BulletSpawnPoint;

	public float spread = 7f;

	public float range = 35f;

	private RoundManager roundManager;

	public void Awake()
	{
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		particleSystem = ((Component)this).GetComponentInChildren<ParticleSystem>();
		audioSource = ((Component)this).GetComponent<AudioSource>();
		roundManager = Object.FindObjectOfType<RoundManager>();
		BulletSpawnPoint = ((Component)this).transform.GetChild(0);
		base.grabbable = true;
		base.grabbableToEnemies = true;
		base.mainObjectRenderer = ((Component)this).GetComponent<MeshRenderer>();
		base.useCooldown = 2f;
		base.insertedBattery = new Battery(false, 1f);
	}

	public override void ItemActivate(bool used, bool buttonDown = true)
	{
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: 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_0449: Unknown result type (might be due to invalid IL or missing references)
		//IL_044e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0455: Unknown result type (might be due to invalid IL or missing references)
		//IL_045a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_033a: Unknown result type (might be due to invalid IL or missing references)
		//IL_036a: Unknown result type (might be due to invalid IL or missing references)
		//IL_039a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_042a: Unknown result type (might be due to invalid IL or missing references)
		((GrabbableObject)this).ItemActivate(used, buttonDown);
		if (base.insertedBattery.charge >= 0.16f)
		{
			Battery insertedBattery = base.insertedBattery;
			insertedBattery.charge -= 0.16f;
			if (base.insertedBattery.charge < 0.16f)
			{
				base.insertedBattery.charge = 0f;
			}
			audioSource.PlayOneShot(shootSound);
			particleSystem.Play();
			RaycastHit val3 = default(RaycastHit);
			IHittable val4 = default(IHittable);
			EnemyAI val5 = default(EnemyAI);
			for (int i = 0; i < 5; i++)
			{
				float num = Random.Range(0f - spread - 3f, spread + 3f);
				float num2 = Random.Range(0f - spread, spread);
				Vector3 val = ((Component)this).transform.position + ((Component)this).transform.forward * range;
				((Vector3)(ref val))..ctor(val.x + num, val.y + num2, val.z + num);
				Vector3 val2 = val - ((Component)this).transform.position;
				LineRenderer component = Object.Instantiate<GameObject>(BulletTrail, BulletSpawnPoint).GetComponent<LineRenderer>();
				if (Physics.Raycast(((Component)this).transform.position, ((Vector3)(ref val2)).normalized, ref val3, range))
				{
					SpawnTrail(component, ((RaycastHit)(ref val3)).point);
					if (((Component)((RaycastHit)(ref val3)).collider).TryGetComponent<IHittable>(ref val4))
					{
						if (val4 == null)
						{
							return;
						}
						val4.Hit(1, ((Component)base.playerHeldBy.gameplayCamera).transform.forward, base.playerHeldBy, false);
					}
					else
					{
						if (!((Component)((RaycastHit)(ref val3)).collider).TryGetComponent<EnemyAI>(ref val5))
						{
							continue;
						}
						if ((Object)(object)val5 == (Object)null || ((Object)val5).name.ToLower().Contains("ghost") || ((Object)val5).name.ToLower().Contains("spring") || !val5.enemyType.canDie)
						{
							return;
						}
						if (val5.enemyHP <= 0)
						{
							continue;
						}
						EnemyAI obj = val5;
						obj.enemyHP--;
						if (val5.enemyHP == 0)
						{
							switch (val5.enemyType.enemyName)
							{
							case "HoarderBug":
								SpawnScrap(roundManager.currentLevel.spawnableScrap[2], ((Component)val5).transform.position, 50);
								break;
							case "Centipede":
								SpawnScrap(roundManager.currentLevel.spawnableScrap[2], ((Component)val5).transform.position, 50);
								break;
							case "SandSpider":
								SpawnScrap(roundManager.currentLevel.spawnableScrap[2], ((Component)val5).transform.position, 100);
								break;
							case "MouthDog":
								SpawnScrap(roundManager.currentLevel.spawnableScrap[2], ((Component)val5).transform.position, 100);
								break;
							case "Flowerman":
								SpawnScrap(roundManager.currentLevel.spawnableScrap[2], ((Component)val5).transform.position, 200);
								break;
							case "Jester":
								SpawnScrap(roundManager.currentLevel.spawnableScrap[2], ((Component)val5).transform.position, 500);
								break;
							default:
								SpawnScrap(roundManager.currentLevel.spawnableScrap[2], ((Component)val5).transform.position, 100);
								break;
							}
						}
					}
				}
				else
				{
					SpawnTrail(component, ((Component)this).transform.position + val2 * 100f);
				}
			}
			((MonoBehaviour)this).StartCoroutine(ShakeCamera());
		}
		else
		{
			audioSource.PlayOneShot(noammoSound);
		}
	}

	private void SpawnTrail(LineRenderer Trail, Vector3 HitPoint)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: 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)
		Trail.SetPositions((Vector3[])(object)new Vector3[2] { BulletSpawnPoint.position, HitPoint });
		((Component)Trail).gameObject.AddComponent<LineRendererFadeOut>();
	}

	public void SpawnScrap(SpawnableItemWithRarity scrapItem, Vector3 enemyPos, int customWorth = 0)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: 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_0050: 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_00df: Unknown result type (might be due to invalid IL or missing references)
		List<int> list = new List<int>();
		List<NetworkObjectReference> list2 = new List<NetworkObjectReference>();
		List<Item> list3 = new List<Item>();
		GameObject val = Object.Instantiate<GameObject>(scrapItem.spawnableItem.spawnPrefab, enemyPos, default(Quaternion), roundManager.spawnedScrapContainer);
		GrabbableObject component = val.GetComponent<GrabbableObject>();
		((Component)component).transform.rotation = Quaternion.Euler(component.itemProperties.restingRotation);
		component.fallTime = 0f;
		list3.Add(scrapItem.spawnableItem);
		list.Add((int)((float)roundManager.AnomalyRandom.Next(list3[0].minValue, list3[0].maxValue) * roundManager.scrapValueMultiplier));
		component.scrapValue = list[list.Count - 1];
		NetworkObject component2 = val.GetComponent<NetworkObject>();
		component2.Spawn(false);
		list2.Add(NetworkObjectReference.op_Implicit(component2));
		if (customWorth != 0)
		{
			component.SetScrapValue(customWorth);
		}
		((MonoBehaviour)this).StartCoroutine(roundManager.waitForScrapToSpawnToSync(list2.ToArray(), list.ToArray()));
	}

	private IEnumerator ShakeCamera()
	{
		Vector3 originalPosition = ((Component)base.playerHeldBy.gameplayCamera).transform.localPosition;
		float elapsed = 0f;
		while (elapsed < 0.4f)
		{
			float x = Random.Range(-1f, 1f) * 0.3f;
			float y = Random.Range(-1f, 1f) * 0.3f;
			((Component)base.playerHeldBy.gameplayCamera).transform.localPosition = new Vector3(x, y, originalPosition.z);
			elapsed += Time.deltaTime;
			yield return null;
		}
		((Component)base.playerHeldBy.gameplayCamera).transform.localPosition = originalPosition;
	}
}
public class LineRendererFadeOut : MonoBehaviour
{
	public LineRenderer lineRenderer;

	public float fadeDuration = 1f;

	public float destroyDelay = 0.5f;

	private float elapsed = 0f;

	private bool isFading = true;

	private void Start()
	{
		lineRenderer = ((Component)this).GetComponent<LineRenderer>();
	}

	private void Update()
	{
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: 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)
		if (isFading)
		{
			if (elapsed < fadeDuration)
			{
				float num = Mathf.Lerp(1f, 0f, elapsed / fadeDuration);
				((Renderer)lineRenderer).material.color = new Color(((Renderer)lineRenderer).material.color.r, ((Renderer)lineRenderer).material.color.g, ((Renderer)lineRenderer).material.color.b, num);
				elapsed += Time.deltaTime;
			}
			else
			{
				((Renderer)lineRenderer).material.color = new Color(((Renderer)lineRenderer).material.color.r, ((Renderer)lineRenderer).material.color.g, ((Renderer)lineRenderer).material.color.b, 0f);
				isFading = false;
				Object.Destroy((Object)(object)((Component)this).gameObject, destroyDelay);
			}
		}
	}
}
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resource1
{
	private static ResourceManager resourceMan;

	private static CultureInfo resourceCulture;

	[EditorBrowsable(EditorBrowsableState.Advanced)]
	internal static ResourceManager ResourceManager
	{
		get
		{
			if (resourceMan == null)
			{
				ResourceManager resourceManager = new ResourceManager("Gun.Resource1", typeof(Resource1).Assembly);
				resourceMan = resourceManager;
			}
			return resourceMan;
		}
	}

	[EditorBrowsable(EditorBrowsableState.Advanced)]
	internal static CultureInfo Culture
	{
		get
		{
			return resourceCulture;
		}
		set
		{
			resourceCulture = value;
		}
	}

	internal static byte[] shotgun
	{
		get
		{
			object @object = ResourceManager.GetObject("shotgun", resourceCulture);
			return (byte[])@object;
		}
	}

	internal Resource1()
	{
	}
}
internal class Utils
{
	public class Main
	{
		public static bool IsIngame()
		{
			GameObject val = GameObject.Find("Environment");
			if ((Object)(object)val != (Object)null)
			{
				return true;
			}
			return false;
		}
	}
}
public static class MyPluginInfo
{
	public const string PLUGIN_GUID = "Gun";

	public const string PLUGIN_NAME = "Gun";

	public const string PLUGIN_VERSION = "1.0.0";
}