Decompiled source of candlemod v1.0.0

AbandonedCompanyAssets.dll

Decompiled 2 years 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 AbandonedCompanyAssets.Behaviours;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("AbandonedCompanyAssets")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Find abandoned company assets.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AbandonedCompanyAssets")]
[assembly: AssemblyTitle("AbandonedCompanyAssets")]
[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 AbandonedCompanyAssets
{
	public static class Configs
	{
		public static bool spawnEquipmentInFacility = true;

		public static int maxEquipmentSpawns = 8;

		public static int minEquipmentSpawns = 2;
	}
	public static class assetCall
	{
		private static string assetFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "abandonedcompanypropertyitems");

		public static AssetBundle bundle = AssetBundle.LoadFromFile(assetFile);
	}
	[BepInPlugin("AbandonedCompanyAssets", "AbandonedCompanyAssets", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private enum spawnRate
		{
			Legendary = 5,
			Epic = 10,
			Rare = 20,
			Uncommon = 30,
			Common = 40,
			Extremely_Common = 50,
			Too_Common = 75,
			Cheating = 1000
		}

		internal static ManualLogSource ACALog;

		public static Item candle = assetCall.bundle.LoadAsset<Item>("Assets/candleItem.asset");

		private readonly Harmony harmony = new Harmony("AbandonedCompanyAssets");

		public static Plugin instance;

		public void Awake()
		{
			instance = this;
			ACALog = ((BaseUnityPlugin)this).Logger;
			createItemLight createItemLight = candle.spawnPrefab.AddComponent<createItemLight>();
			candle.spawnPrefab.AddComponent<flickeringLight>();
			((GrabbableObject)createItemLight).grabbable = true;
			((GrabbableObject)createItemLight).grabbableToEnemies = true;
			((GrabbableObject)createItemLight).useCooldown = 0.8f;
			((GrabbableObject)createItemLight).itemProperties = candle;
			NetworkPrefabs.RegisterNetworkPrefab(candle.spawnPrefab);
			Utilities.FixMixerGroups(candle.spawnPrefab);
			Items.RegisterScrap(candle, 20, (LevelTypes)(-1));
			candle.toolTips = new string[1] { "Use item : [LMB]" };
			createItemLight.minFail = 2;
			createItemLight.maxFail = 5;
			TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>();
			val.clearPreviousText = true;
			val.displayText = "The Candle. A cheap but extremely unreliable method of lighting your way. The Company is not responsible for any fires.\n\n";
			Items.RegisterShopItem(candle, (TerminalNode)null, (TerminalNode)null, val, 7);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin AbandonedCompanyAssets is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "AbandonedCompanyAssets";

		public const string PLUGIN_NAME = "AbandonedCompanyAssets";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace AbandonedCompanyAssets.Behaviours
{
	internal class createItemLight : GrabbableObject
	{
		private ParticleSystem particles;

		private Light lighting;

		private AudioSource audioSource;

		private PlayerControllerB player;

		public AudioClip flame = assetCall.bundle.LoadAsset<AudioClip>("Assets/Ripped Assets/AudioClip/CandleFlame.ogg");

		public AudioClip lightFlame = assetCall.bundle.LoadAsset<AudioClip>("Assets/Ripped Assets/AudioClip/LightCandle.ogg");

		public AudioClip blowFlame = assetCall.bundle.LoadAsset<AudioClip>("Assets/Ripped Assets/AudioClip/LightCandleBlow.ogg");

		public PlayerControllerB currentPlayer;

		private int failNumber = Random.Range(minFail, maxFail);

		public int failCount;

		public int totalFailCount;

		public static int minFail;

		public static int maxFail;

		public bool currentlyLit;

		public static int candleAmount;

		private bool deadCandle;

		private Queue<float> smoothQueue;

		private float lastSum = 1f;

		public void Reset()
		{
			smoothQueue.Clear();
			lastSum = 0f;
		}

		public override void Start()
		{
			((GrabbableObject)this).Start();
			candleAmount++;
			failNumber = Random.Range(minFail, maxFail);
			particles = ((Component)this).GetComponentInChildren<ParticleSystem>();
			lighting = ((Component)this).GetComponentInChildren<Light>();
			audioSource = ((Component)this).GetComponentInChildren<AudioSource>();
			if (!currentlyLit)
			{
				lightCandle(grabbing: false, freshCandle: true);
				candleStart(startCandle: false);
			}
			else
			{
				lightCandle(grabbing: false, freshCandle: true);
				candleStart(startCandle: true);
			}
			if ((Object)(object)particles == (Object)null)
			{
				Plugin.ACALog.LogDebug((object)"WHERE THE FUCK ARE MY PARTICLES");
			}
			if ((Object)(object)lighting == (Object)null)
			{
				Plugin.ACALog.LogDebug((object)"WHERE THE FUCK ARE MY PARTICLES");
			}
		}

		public override void EquipItem()
		{
			((GrabbableObject)this).EquipItem();
		}

		public override void GrabItem()
		{
			((GrabbableObject)this).GrabItem();
		}

		public override void DiscardItem()
		{
			((GrabbableObject)this).DiscardItem();
			if (currentlyLit)
			{
				particles.Play();
				candleStart(startCandle: true);
			}
			else
			{
				particles.Stop();
				particles.Clear();
				candleStart(startCandle: false);
			}
		}

		public override void PocketItem()
		{
			((GrabbableObject)this).PocketItem();
			particles.Stop();
			particles.Clear();
			((Behaviour)lighting).enabled = false;
			candleStart(startCandle: false);
			if (currentlyLit)
			{
				audioSource.pitch = Random.Range(0.9f, 1.1f);
				audioSource.PlayOneShot(blowFlame);
				currentlyLit = false;
			}
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			Plugin.ACALog.LogDebug((object)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
			if (currentlyLit)
			{
				lightCandle(grabbing: false, freshCandle: false);
			}
			else
			{
				lightCandle(grabbing: false, freshCandle: false);
			}
		}

		private void candleStart(bool startCandle)
		{
			if (startCandle)
			{
				audioSource.clip = flame;
				audioSource.pitch = Random.Range(0.9f, 1.1f);
				audioSource.loop = true;
				audioSource.Play();
			}
			else
			{
				audioSource.Stop();
			}
		}

		public void lightCandle(bool grabbing, bool freshCandle)
		{
			currentPlayer = GameNetworkManager.Instance.localPlayerController;
			int num = (int)currentPlayer.insanityLevel / 2;
			int num2 = Random.Range(1, 100);
			int num3 = Random.Range(1, 115 - num);
			if (currentPlayer.insanityLevel >= 15f && (double)(float)num2 >= (double)(float)num3 * 3.5 && !grabbing && !currentlyLit && failCount < 2 && totalFailCount < failNumber && !freshCandle)
			{
				failCount++;
				totalFailCount++;
				particles.Stop();
				particles.Clear();
				currentlyLit = false;
				((Behaviour)lighting).enabled = false;
				candleStart(startCandle: false);
				audioSource.pitch = Random.Range(0.4f, 0.6f);
				audioSource.PlayOneShot(blowFlame);
			}
			else if (!currentlyLit && totalFailCount < failNumber && !freshCandle)
			{
				particles.Play();
				((Behaviour)lighting).enabled = true;
				candleStart(startCandle: true);
				audioSource.pitch = Random.Range(0.9f, 1.1f);
				audioSource.PlayOneShot(lightFlame);
				currentlyLit = true;
				failCount = 0;
			}
			else if (totalFailCount < failNumber)
			{
				particles.Stop();
				((Behaviour)lighting).enabled = false;
				candleStart(startCandle: false);
				audioSource.pitch = Random.Range(0.9f, 1.1f);
				audioSource.PlayOneShot(blowFlame);
				currentlyLit = false;
			}
			else
			{
				particles.Stop();
				((Behaviour)lighting).enabled = false;
				candleStart(startCandle: false);
				deadCandle = true;
			}
		}
	}
	internal class flickeringLight : MonoBehaviour
	{
		private Light lightSource;

		public static float minIntensity = 100f;

		public static float maxIntensity = 200f;

		public static int smoothing = 35;

		private Queue<float> smoothQueue;

		private float lastSum = 1f;

		public void Reset()
		{
			smoothQueue.Clear();
			lastSum = 0f;
		}

		public void Start()
		{
			smoothQueue = new Queue<float>(smoothing);
			if ((Object)(object)lightSource == (Object)null)
			{
				lightSource = ((Component)this).GetComponentInChildren<Light>();
			}
		}

		public void Update()
		{
			if (!((Object)(object)lightSource == (Object)null))
			{
				while (smoothQueue.Count >= smoothing)
				{
					lastSum -= smoothQueue.Dequeue();
				}
				float num = Random.Range(minIntensity, maxIntensity);
				smoothQueue.Enqueue(num);
				lastSum += num;
				lightSource.intensity = lastSum / (float)smoothQueue.Count;
			}
		}
	}
	internal class saving : StartOfRound
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}