Decompiled source of Vanoce se blizi v1.0.0

LethalPowerOfChrist.dll

Decompiled 3 days 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.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LCSoundTool;
using Unity.Netcode;
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_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		if (textures != null)
		{
			if (!((NetworkBehaviour)player).IsClient)
			{
				Plugin.Logger.LogInfo((object)"Other client, skipping hud flash");
				return;
			}
			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)audioSource == (Object)null)
		{
			audioSource = GetOrAddAudioSource();
			Plugin.Logger.LogInfo((object)"Audio Source Set");
		}
		if ((Object)(object)player == (Object)null)
		{
			player = GameNetworkManager.Instance.localPlayerController;
			Plugin.Logger.LogInfo((object)"Player set");
		}
		if (!isFlashing)
		{
			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);
		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 <= 20 && player.health > 0 && !player.isPlayerDead)
		{
			audioSource.PlayOneShot(Plugin.dangerSound);
			Flash();
			((MonoBehaviour)this).Invoke("RepeatFlash", 5f);
			isFlashing = true;
		}
		else
		{
			isFlashing = false;
		}
	}

	private AudioSource GetOrAddAudioSource()
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Expected O, but got Unknown
		Transform val = ((Component)GameNetworkManager.Instance.localPlayerController).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.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")]
	[HarmonyPrefix]
	internal static void PlayerControllerB_Awake_Prefix(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)
	{
		if ((Object)(object)__instance == (Object)(object)GameNetworkManager.Instance.localPlayerController)
		{
			Plugin.hudFlasher.BeginFlash();
		}
	}

	[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))
	{
		Plugin.hudFlasher.StopFlash();
	}

	[HarmonyPatch(typeof(StartOfRound), "ReviveDeadPlayers")]
	[HarmonyPostfix]
	internal static void PlayerControllerB_KillPlayer_Postfix()
	{
		Plugin.hudFlasher.StopFlash();
	}

	private static GameObject GetOrAddHUDObject()
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		GameObject val = GameObject.Find("Canvas");
		GameObject 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"));
		}
		else
		{
			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;
	}
}
[BepInPlugin("LemoCoffee.LethalCompany.PowerOfChrist", "Power Of Christ", "0.0.2")]
[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 = "0.0.2";

	internal static AudioClip dangerSound;

	internal static AudioSource audioSource;

	internal static HudFlasher hudFlasher;

	internal static Texture2D[] hudImages;

	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;
		HarmonyInstance.PatchAll(ExecutingAssembly);
		dangerSound = SoundTool.GetAudioClip("LemoCoffee-PowerOfChrist", "sound.wav");
		Logger.LogInfo((object)"Power of Christ is compelling with V0.0.2");
	}
}