Decompiled source of poop v1.0.999

LethalPowerOfChrist.dll

Decompiled 4 hours ago
using System;
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 BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LCSoundTool;
using UnityEngine;
using UnityEngine.UI;

[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("LethalPowerOfChrist")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A holy addition for true believers in the Lethal Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LethalPowerOfChrist")]
[assembly: AssemblyTitle("LethalPowerOfChrist")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace PowerOfChrist;

internal class HudFlasher : MonoBehaviour
{
	public RawImage image;

	public Texture2D[] textures;

	public bool isFlashing = false;

	public float flashTime = 2f;

	public PlayerControllerB player;

	public AudioSource audioSource;

	private void Start()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: 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_0061: 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)
		image = ((Component)this).gameObject.GetComponent<RawImage>();
		((Graphic)image).color = new Color(1f, 1f, 1f, 0f);
		RectTransform component = ((Component)this).gameObject.GetComponent<RectTransform>();
		component.anchoredPosition = Vector2.op_Implicit(Vector3.zero);
		((Transform)component).localPosition = Vector3.zero;
		((Transform)component).localRotation = Quaternion.identity;
		((Transform)component).localScale = Vector3.one;
	}

	private void Update()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		if (((Graphic)image).color.a > 0f)
		{
			((Graphic)image).color = new Color(1f, 1f, 1f, Mathf.MoveTowards(((Graphic)image).color.a, 0f, 1f / flashTime * Time.deltaTime));
			if (((Graphic)image).color.a == 0f)
			{
				((Component)image).GetComponent<RectTransform>().sizeDelta = new Vector2(1f, 1f);
			}
		}
	}

	public void Flash()
	{
		//IL_003b: 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_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		if (textures != null)
		{
			SetImageToRandTexture(ref image, textures);
			((Component)image).GetComponent<RectTransform>().sizeDelta = new Vector2((float)Screen.width, (float)Screen.height);
			RectTransform component = ((Component)this).gameObject.GetComponent<RectTransform>();
			component.anchoredPosition = Vector2.op_Implicit(Vector3.zero);
			((Graphic)image).color = new Color(1f, 1f, 1f, 1f);
		}
	}

	private void SetImageToRandTexture(ref RawImage image, Texture2D[] textures)
	{
		image.texture = (Texture)(object)textures[Random.Range(0, textures.Length)];
	}

	public bool BeginFlash()
	{
		if ((Object)(object)player == (Object)null)
		{
			player = GameNetworkManager.Instance.localPlayerController;
			Plugin.Logger.LogInfo((object)"Player set");
		}
		if ((Object)(object)audioSource == (Object)null)
		{
			audioSource = GetOrAddAudioSource();
			Plugin.Logger.LogInfo((object)"Audio Source Set");
		}
		if (!isFlashing || Plugin.allowOverlap)
		{
			RepeatFlash();
			return true;
		}
		return false;
	}

	public void StopFlash()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		isFlashing = false;
		((Graphic)image).color = new Color(1f, 1f, 1f, 0f);
		((Component)image).GetComponent<RectTransform>().sizeDelta = new Vector2(1f, 1f);
		if ((Object)(object)audioSource != (Object)null)
		{
			audioSource.Stop();
		}
	}

	private void RepeatFlash()
	{
		if ((Object)(object)player == (Object)null)
		{
			Plugin.Logger.LogWarning((object)"Player object is null, stopping");
			isFlashing = false;
		}
		else if (player.health <= Plugin.triggerValue && player.health > 0 && !player.isPlayerDead)
		{
			audioSource.PlayOneShot(Plugin.dangerSound);
			Flash();
			if (!Plugin.flashOnce)
			{
				((MonoBehaviour)this).Invoke("RepeatFlash", Plugin.flashDelay);
				isFlashing = true;
			}
		}
		else
		{
			isFlashing = false;
		}
	}

	private AudioSource GetOrAddAudioSource()
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		Transform val = ((Component)player).transform.Find("Audios");
		Transform val2 = val.Find("PowerOfChristAudio");
		if ((Object)(object)val2 == (Object)null)
		{
			GameObject val3 = new GameObject("PowerOfChristAudio", new Type[1] { typeof(AudioSource) });
			AudioSource component = val3.GetComponent<AudioSource>();
			component.clip = Plugin.dangerSound;
			component.loop = false;
			component.playOnAwake = false;
			component.spatialize = false;
			component.Stop();
			val3.transform.SetParent(val);
			Plugin.audioSource = component;
			return component;
		}
		Plugin.Logger.LogInfo((object)"Audio source already exists");
		return ((Component)val2).GetComponent<AudioSource>();
	}
}
[HarmonyPatch]
internal class Patches
{
	[HarmonyPatch(typeof(PlayerControllerB), "Awake")]
	[HarmonyPostfix]
	internal static void PlayerControllerB_Awake_Postfix(ref PlayerControllerB __instance)
	{
		try
		{
			if ((Object)(object)Plugin.hudFlasher == (Object)null)
			{
				Plugin.hudFlasher = GetOrAddHUDObject().GetComponent<HudFlasher>();
				Plugin.hudFlasher.textures = CreateTexturesFromFolder(Path.Combine(Path.GetDirectoryName(Plugin.ExecutingAssembly.Location), "images"));
				Plugin.Logger.LogInfo((object)("Created flasher with " + Plugin.hudFlasher.textures.Length + " textures"));
			}
		}
		catch (Exception ex)
		{
			Plugin.Logger.LogError((object)ex);
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")]
	[HarmonyPostfix]
	internal static void PlayerControllerB_DamagePlayer_Postfix(ref PlayerControllerB __instance, int damageNumber, bool hasDamageSFX, bool callRPC, CauseOfDeath causeOfDeath, int deathAnimation, bool fallDamage, Vector3 force)
	{
		BeginFlasher();
	}

	[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
	[HarmonyPostfix]
	internal static void PlayerControllerB_KillPlayer_Postfix(ref PlayerControllerB __instance, Vector3 bodyVelocity, bool spawnBody = true, CauseOfDeath causeOfDeath = 0, int deathAnimation = 0, Vector3 positionOffset = default(Vector3))
	{
		StopFlasher();
	}

	[HarmonyPatch(typeof(StartOfRound), "ReviveDeadPlayers")]
	[HarmonyPostfix]
	internal static void StartOfRound_ReviveDeadPlayers_Postfix()
	{
		StopFlasher();
	}

	private static GameObject GetOrAddHUDObject()
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		GameObject val = GameObject.Find("Canvas");
		GameObject val2 = null;
		if ((Object)(object)val2 == (Object)null)
		{
			val2 = new GameObject("ImageFlasher", new Type[2]
			{
				typeof(RawImage),
				typeof(HudFlasher)
			});
			val2.transform.SetParent(val.transform);
		}
		return val2;
	}

	private static Texture2D LoadImageInFolder(string path)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Expected O, but got Unknown
		Texture2D val = new Texture2D(2, 2);
		byte[] array = File.ReadAllBytes(path);
		if (!ImageConversion.LoadImage(val, array))
		{
			Plugin.Logger.LogWarning((object)(path + " failed to be loaded"));
			return null;
		}
		Plugin.Logger.LogInfo((object)(path + " successfully loaded"));
		return val;
	}

	private static Texture2D[] CreateTexturesFromFolder(string path)
	{
		string[] files = Directory.GetFiles(path, "*.png");
		Texture2D[] array = (Texture2D[])(object)new Texture2D[files.Length];
		for (int i = 0; i < files.Length; i++)
		{
			array[i] = LoadImageInFolder(files[i]);
		}
		return array;
	}

	private static bool StopFlasher()
	{
		if ((Object)(object)Plugin.hudFlasher != (Object)null)
		{
			Plugin.hudFlasher.StopFlash();
			return true;
		}
		return false;
	}

	private static void BeginFlasher()
	{
		Plugin.hudFlasher.BeginFlash();
	}
}
[BepInPlugin("LemoCoffee.LethalCompany.PowerOfChrist", "Power Of Christ", "1.0.4")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class Plugin : BaseUnityPlugin
{
	public const string pluginGuid = "LemoCoffee.LethalCompany.PowerOfChrist";

	public const string pluginName = "Power Of Christ";

	public const string pluginVersion = "1.0.4";

	internal static AudioClip dangerSound;

	internal static AudioSource audioSource;

	internal static float volume;

	internal static HudFlasher hudFlasher;

	internal static Texture2D[] hudImages;

	internal static bool flashOnce;

	internal static bool allowOverlap;

	internal static int triggerValue;

	internal static float flashDelay;

	internal static ManualLogSource Logger { get; private set; }

	internal static Harmony HarmonyInstance { get; } = new Harmony("LemoCoffee.LethalCompany.PowerOfChrist");


	internal static Assembly ExecutingAssembly { get; } = Assembly.GetExecutingAssembly();


	public void Awake()
	{
		Logger = ((BaseUnityPlugin)this).Logger;
		string soundName = "";
		Configure(ref soundName);
		HarmonyInstance.PatchAll(ExecutingAssembly);
		dangerSound = SoundTool.GetAudioClip("LemoCoffee-PowerOfChrist", soundName);
		Logger.LogInfo((object)"Power of Christ is compelling with V1.0.4");
	}

	private void Configure(ref string soundName)
	{
		volume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "Volume", 1f, (ConfigDescription)null).Value;
		soundName = ((BaseUnityPlugin)this).Config.Bind<string>("Audio", "File Name", "sound.wav", (ConfigDescription)null).Value;
		flashOnce = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Flash Once", false, (ConfigDescription)null).Value;
		allowOverlap = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Allow Overlap", false, (ConfigDescription)null).Value;
		triggerValue = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Trigger Point", 20, (ConfigDescription)null).Value;
		flashDelay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Flash Delay", 5f, (ConfigDescription)null).Value;
	}
}