Decompiled source of SpewMe v1.0.0

plugins/SpewMe.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
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: AssemblyCompany("SpewMe")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+183253291689616afb0dcf9389ea20483bd38701")]
[assembly: AssemblyProduct("SpewMe")]
[assembly: AssemblyTitle("SpewMe")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace SpewMe;

internal static class MyPluginInfo
{
	internal const string PLUGIN_GUID = "com.yourname.spewme";

	internal const string PLUGIN_NAME = "SpewMe";

	internal const string PLUGIN_VERSION = "1.0.0";
}
[BepInPlugin("com.yourname.spewme", "SpewMe", "1.0.0")]
public class SpewMePlugin : BaseUnityPlugin
{
	internal static ManualLogSource Logger;

	private readonly Harmony harmony = new Harmony("com.yourname.spewme");

	private void Awake()
	{
		Logger = ((BaseUnityPlugin)this).Logger;
		harmony.PatchAll();
		Logger.LogInfo((object)"SpewMe загружен! Нажми J чтобы прицепить блюню на лицо.");
	}

	private void Update()
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		if (!Input.GetKeyDown((KeyCode)106))
		{
			return;
		}
		PlayerAvatar localPlayer = GetLocalPlayer();
		if ((Object)(object)localPlayer == (Object)null)
		{
			Logger.LogWarning((object)"Локальный игрок не найден.");
			return;
		}
		EnemySlowMouth val = FindNearestSpewer(((Component)localPlayer).transform.position);
		if ((Object)(object)val != (Object)null)
		{
			ForceAttachSpewer(val, localPlayer);
			Logger.LogInfo((object)"Spewer прицеплен принудительно!");
		}
		else
		{
			Logger.LogInfo((object)"Spewer не найден в сцене, спавним нового...");
			((MonoBehaviour)this).StartCoroutine(SpawnAndAttachSpewer(localPlayer));
		}
	}

	private PlayerAvatar GetLocalPlayer()
	{
		if ((Object)(object)PlayerAvatar.instance != (Object)null)
		{
			return PlayerAvatar.instance;
		}
		PlayerAvatar[] array = Object.FindObjectsOfType<PlayerAvatar>();
		int num = 0;
		if (num < array.Length)
		{
			PlayerAvatar val = array[num];
			try
			{
				FieldInfo field = typeof(PlayerAvatar).GetField("isLocal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null && (bool)field.GetValue(val))
				{
					return val;
				}
			}
			catch
			{
			}
			return val;
		}
		return null;
	}

	private EnemySlowMouth FindNearestSpewer(Vector3 origin)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		EnemySlowMouth[] array = Object.FindObjectsOfType<EnemySlowMouth>();
		EnemySlowMouth result = null;
		float num = float.MaxValue;
		EnemySlowMouth[] array2 = array;
		foreach (EnemySlowMouth val in array2)
		{
			float num2 = Vector3.Distance(origin, ((Component)val).transform.position);
			if (num2 < num)
			{
				num = num2;
				result = val;
			}
		}
		return result;
	}

	private void ForceAttachSpewer(EnemySlowMouth spewer, PlayerAvatar player)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: 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_0026: 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_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		((Component)spewer).transform.position = ((Component)player).transform.position + ((Component)player).transform.forward * 0.5f + Vector3.up * 1.5f;
		try
		{
			MethodInfo methodInfo = typeof(EnemySlowMouth).GetMethod("AttachToPlayer", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? typeof(EnemySlowMouth).GetMethod("Attach", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? typeof(EnemySlowMouth).GetMethod("LatchOntoPlayer", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? typeof(EnemySlowMouth).GetMethod("OnAttach", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (methodInfo != null)
			{
				methodInfo.Invoke(spewer, new object[1] { player });
				Logger.LogInfo((object)("Вызван метод: " + methodInfo.Name));
			}
			else
			{
				SetSpewTarget(spewer, player);
			}
		}
		catch (Exception ex)
		{
			Logger.LogError((object)("Ошибка при прикреплении: " + ex.Message));
			SetSpewTarget(spewer, player);
		}
	}

	private void SetSpewTarget(EnemySlowMouth spewer, PlayerAvatar player)
	{
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: 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_0176: 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_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		FieldInfo[] fields = typeof(EnemySlowMouth).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		foreach (FieldInfo fieldInfo in fields)
		{
			Logger.LogDebug((object)("  Field: " + fieldInfo.Name + " (" + fieldInfo.FieldType.Name + ")"));
			if (fieldInfo.FieldType == typeof(PlayerAvatar) && (fieldInfo.Name.ToLower().Contains("target") || fieldInfo.Name.ToLower().Contains("player") || fieldInfo.Name.ToLower().Contains("attach")))
			{
				fieldInfo.SetValue(spewer, player);
				Logger.LogInfo((object)("Установлено поле цели: " + fieldInfo.Name));
			}
		}
		FieldInfo fieldInfo2 = typeof(EnemySlowMouth).GetField("currentState", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? typeof(EnemySlowMouth).GetField("state", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (fieldInfo2 != null)
		{
			Logger.LogInfo((object)("State field: " + fieldInfo2.Name + ", type: " + fieldInfo2.FieldType.Name));
		}
		((Component)spewer).transform.position = ((Component)player).transform.position + ((Component)player).transform.forward * 0.3f + Vector3.up * 1.6f;
		Logger.LogInfo((object)"Spewer телепортирован к лицу игрока. Он сам должен прикрепиться.");
	}

	private IEnumerator SpawnAndAttachSpewer(PlayerAvatar player)
	{
		GameObject val = FindSpewPrefab();
		if ((Object)(object)val == (Object)null)
		{
			Logger.LogWarning((object)"Префаб Spewer не найден. Попробуй сначала войти в уровень где есть Spewer.");
			yield break;
		}
		Vector3 val2 = ((Component)player).transform.position + ((Component)player).transform.forward * 1f + Vector3.up * 1.5f;
		GameObject obj = Object.Instantiate<GameObject>(val, val2, Quaternion.identity);
		yield return (object)new WaitForSeconds(0.1f);
		EnemySlowMouth component = obj.GetComponent<EnemySlowMouth>();
		if ((Object)(object)component != (Object)null)
		{
			ForceAttachSpewer(component, player);
		}
		else
		{
			Logger.LogWarning((object)"Спавн прошёл, но EnemySlowMouth компонент не найден.");
		}
	}

	private GameObject FindSpewPrefab()
	{
		EnemyDirector val = Object.FindObjectOfType<EnemyDirector>();
		GameObject[] array2;
		if ((Object)(object)val != (Object)null)
		{
			FieldInfo field = typeof(EnemyDirector).GetField("enemyList", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				object value = field.GetValue(val);
				if (value is List<GameObject> list)
				{
					foreach (GameObject item in list)
					{
						if ((Object)(object)item != (Object)null && ((Object)item).name.ToLower().Contains("slowmouth"))
						{
							return item;
						}
					}
				}
				else if (value is GameObject[] array)
				{
					array2 = array;
					foreach (GameObject val2 in array2)
					{
						if ((Object)(object)val2 != (Object)null && ((Object)val2).name.ToLower().Contains("slowmouth"))
						{
							return val2;
						}
					}
				}
			}
		}
		GameObject val3 = Resources.Load<GameObject>("EnemySlowMouth");
		if ((Object)(object)val3 != (Object)null)
		{
			return val3;
		}
		array2 = Resources.FindObjectsOfTypeAll<GameObject>();
		foreach (GameObject val4 in array2)
		{
			if (((Object)val4).name.ToLower().Contains("slowmouth") || ((Object)val4).name.ToLower().Contains("spewer"))
			{
				return val4;
			}
		}
		return null;
	}
}