Decompiled source of ElGrinchosAndFriends v1.0.4

plugins/El Grinchos and Friends/El Grinchos and Friends.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
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 Damagescript;
using El Grinchos and Friends.NetcodePatcher;
using ElGrinchosAndFriends.Configuration;
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: AssemblyCompany("El Grinchos and Friends")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4+4f4c394ee103fc03394c4fe85ea5778e299d27f7")]
[assembly: AssemblyProduct("ElGrinchosAndFriends")]
[assembly: AssemblyTitle("El Grinchos and Friends")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 ExampleEnemy
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "El Grinchos and Friends";

		public const string PLUGIN_NAME = "ElGrinchosAndFriends";

		public const string PLUGIN_VERSION = "1.0.4";
	}
}
namespace ElGrinchosAndFriends
{
	[BepInPlugin("Kyriso.ElGrinchosAndFriends", "ElGrinchosAndFriends", "1.0.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static AssetBundle? ModAssets;

		internal static PluginConfig BoundConfig { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			BoundConfig = new PluginConfig(((BaseUnityPlugin)this).Config);
			Logger.LogInfo((object)"\r\n                                                                                                    \r\n                                                                                                    \r\n                                              ========                                              \r\n                                            ===     ===                                             \r\n                                            ======    ==                                            \r\n                                                       ==                                           \r\n                                                       ===                                          \r\n                                                         =                                          \r\n                                                         =                                          \r\n                                       #+    ========== ==                                          \r\n                                       =%%* ==============                                          \r\n                                         -#@+=========#@%#                                          \r\n                                       --==========*@@+===                                          \r\n                                    **----===============                                           \r\n                                   -------===========----%-                                         \r\n                                   -------===========-------                                        \r\n                                    -----=============-----                                         \r\n                                     -===================                                           \r\n                             ===========================                                            \r\n                            =======+%@%#%%##%##%@*====-----                                         \r\n                            ====+@%==============+@*===========                                     \r\n                            ===*@=================+%@#+========-                                    \r\n                            ==#@@@@%@@@%#######%@@@@@@@%=======-                                    \r\n                             ==============================--==                                     \r\n                               =============================                                        \r\n                                      ================                                              \r\n                                       =========                                                    \r\n                                       =========                                                    \r\n               =====-                 -=========                                                    \r\n               ===-===                ===========-                                                  \r\n               ====-====             ===============-                                               \r\n               ==-===-==             ================-                                              \r\n                ========-           ===================================--                           \r\n                 ===========--      ========================================                        \r\n                   ====-====================-.==========               ==-===                       \r\n                      -=======================-:-=======                  ===-                      \r\n                                    ======================                 =--=                     \r\n                                    =====================                          \r\n\r\n___________.__      ________      .__              .__                  \r\n\\_   _____/|  |    /  _____/______|__| ____   ____ |  |__   ____  ______\r\n |    __)_ |  |   /   \\  __\\_  __ \\  |/    \\_/ ___\\|  |  \\ /  _ \\/  ___/\r\n |        \\|  |__ \\    \\_\\  \\  | \\/  |   |  \\  \\___|   Y  (  <_> )___ \\ \r\n/_______  /|____/  \\______  /__|  |__|___|  /\\___  >___|  /\\____/____  >\r\n        \\/                \\/              \\/     \\/     \\/           \\/                  \r\n                                                                                            \r\n");
			string path = "modassets";
			ModAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), path));
			if ((Object)(object)ModAssets == (Object)null)
			{
				Logger.LogError((object)"Failed to load custom assets.");
				return;
			}
			Item val = ModAssets.LoadAsset<Item>("ElGrinchosItem");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError((object)"Failed to load ElGrinchosItem item from AssetBundle.");
				return;
			}
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			int value = BoundConfig.SpawnWeightElGrinchos.Value;
			Items.RegisterScrap(val, value, (LevelTypes)(-1));
			Logger.LogInfo((object)"ElGrinchos is in the game !");
			Item val2 = ModAssets.LoadAsset<Item>("ElGoldchosItem");
			if ((Object)(object)val2 == (Object)null)
			{
				Logger.LogError((object)"Failed to load ElGoldchosItem item from AssetBundle.");
				return;
			}
			NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
			int value2 = BoundConfig.SpawnWeightELGoldchos.Value;
			Items.RegisterScrap(val2, value2, (LevelTypes)(-1));
			Item newvalue = ModAssets.LoadAsset<Item>("ElCowboyItem");
			Item val3 = ModAssets.LoadAsset<Item>("GagouarItem");
			if ((Object)(object)val3 == (Object)null)
			{
				Logger.LogError((object)"Failed to load Gagouar item from AssetBundle.");
				return;
			}
			DamagePlayerItem damagePlayerItem = val3.spawnPrefab.GetComponent<DamagePlayerItem>();
			if ((Object)(object)damagePlayerItem == (Object)null)
			{
				damagePlayerItem = val3.spawnPrefab.AddComponent<DamagePlayerItem>();
			}
			((GrabbableObject)damagePlayerItem).itemProperties = val3;
			((GrabbableObject)damagePlayerItem).grabbable = true;
			((GrabbableObject)damagePlayerItem).grabbableToEnemies = true;
			damagePlayerItem.newvalue = newvalue;
			damagePlayerItem.prefab = val3.spawnPrefab;
			DamagePlayerItem damagePlayerItem2 = damagePlayerItem;
			Transform obj = damagePlayerItem.prefab.transform.Find("El_Grinchos");
			damagePlayerItem2.grinchosObject = ((obj != null) ? ((Component)obj).gameObject : null);
			NetworkPrefabs.RegisterNetworkPrefab(val3.spawnPrefab);
			int value3 = BoundConfig.SpawnWeightGagouar.Value;
			Items.RegisterScrap(val3, value3, (LevelTypes)(-1));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Kyriso.ElGrinchosAndFriends";

		public const string PLUGIN_NAME = "ElGrinchosAndFriends";

		public const string PLUGIN_VERSION = "1.0.4";
	}
}
namespace ElGrinchosAndFriends.Configuration
{
	public class PluginConfig
	{
		public ConfigEntry<int> SpawnWeightElGrinchos;

		public ConfigEntry<int> SpawnWeightELGoldchos;

		public ConfigEntry<int> SpawnWeightGagouar;

		public PluginConfig(ConfigFile cfg)
		{
			SpawnWeightElGrinchos = cfg.Bind<int>("General", "Spawn weight ElGrinchos", 18, "The spawn chance weight for ElGrinchos, relative to other existing items.\nGoes up from 0, lower is more rare, 100 and up is very common.");
			SpawnWeightELGoldchos = cfg.Bind<int>("General", "Spawn weight ELGoldchos", 5, "The spawn chance weight for ELGoldchos, relative to other existing items.\nGoes up from 0, lower is more rare, 100 and up is very common.");
			SpawnWeightGagouar = cfg.Bind<int>("General", "Spawn weight Gagouar", 15, "The spawn chance weight for Gagouar, relative to other existing items.\nGoes up from 0, lower is more rare, 100 and up is very common.");
			ClearUnusedEntries(cfg);
		}

		private void ClearUnusedEntries(ConfigFile cfg)
		{
			PropertyInfo property = ((object)cfg).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(cfg, null);
			dictionary.Clear();
			cfg.Save();
		}
	}
}
namespace Damagescript
{
	internal class DamagePlayerItem : PhysicsProp
	{
		public GameObject? prefab;

		public GameObject? grinchosObject;

		public Item? newvalue;

		public float detectionRange = 0.5f;

		public float gagouarMinDistance = 2f;

		private bool hasTransformed;

		private AudioSource? audioSource;

		public override void Update()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).Update();
			if (hasTransformed)
			{
				return;
			}
			GameObject val = GameObject.Find("El_Grinchos");
			if ((Object)(object)val == (Object)null || (Object)(object)prefab == (Object)null)
			{
				return;
			}
			Transform parent = val.transform.parent;
			GameObject val2 = ((parent != null) ? ((Component)parent).gameObject : null) ?? val;
			float num = Vector3.Distance(val.transform.position, prefab.transform.position);
			PhysicsProp component = val2.GetComponent<PhysicsProp>();
			PhysicsProp component2 = prefab.GetComponent<PhysicsProp>();
			if (!((Object)(object)component != (Object)null) || !((Object)(object)component2 != (Object)null) || !(num <= detectionRange) || ((GrabbableObject)component).heldByPlayerOnServer || ((GrabbableObject)component2).isHeld)
			{
				return;
			}
			if (CheckDistanceToOtherGagouars(prefab))
			{
				Debug.Log((object)"Gagouar trop proche d'un autre. Transformation annulée.");
				return;
			}
			if ((Object)(object)newvalue == (Object)null)
			{
				Debug.LogError((object)"newvalue est nul.");
				return;
			}
			if ((Object)(object)grinchosObject == (Object)null)
			{
				Transform obj = prefab.transform.Find("El_GrinchosModel");
				grinchosObject = ((obj != null) ? ((Component)obj).gameObject : null);
				if ((Object)(object)grinchosObject == (Object)null)
				{
					Debug.LogError((object)"El_Grinchos non trouvé dans le préfab.");
					return;
				}
				grinchosObject.SetActive(false);
			}
			grinchosObject.SetActive(true);
			Debug.Log((object)"El_GrinchosModel activé.");
			Object.Destroy((Object)(object)val2);
			Debug.Log((object)"Le préfab contenant El_Grinchos a été détruit.");
			Transform val3 = prefab.transform.Find("ScanNode");
			if ((Object)(object)val3 != (Object)null)
			{
				ScanNodeProperties component3 = ((Component)val3).GetComponent<ScanNodeProperties>();
				if ((Object)(object)component3 != (Object)null)
				{
					component3.scrapValue = 150;
					component3.subText = "value: $150";
					component3.headerText = "El Cowboy";
				}
			}
			PhysicsProp component4 = ((Component)this).gameObject.GetComponent<PhysicsProp>();
			if ((Object)(object)component4 != (Object)null)
			{
				((GrabbableObject)component4).itemProperties = newvalue;
				((GrabbableObject)this).scrapValue = 150;
				if ((Object)(object)newvalue?.dropSFX != (Object)null)
				{
					PlaySound(newvalue.dropSFX);
				}
			}
			hasTransformed = true;
		}

		private bool CheckDistanceToOtherGagouars(GameObject gagouarPrefab)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			GameObject gagouarPrefab2 = gagouarPrefab;
			IEnumerable<PhysicsProp> enumerable = from prop in Object.FindObjectsOfType<PhysicsProp>()
				where (Object)(object)((Component)prop).gameObject != (Object)(object)gagouarPrefab2
				where ((Object)((Component)prop).gameObject).name.Contains("Gagouar")
				where !((Component)prop).gameObject.GetComponent<DamagePlayerItem>().hasTransformed
				select prop;
			foreach (PhysicsProp item in enumerable)
			{
				float num = Vector3.Distance(((Component)item).transform.position, gagouarPrefab2.transform.position);
				if (num <= gagouarMinDistance)
				{
					return true;
				}
			}
			return false;
		}

		private void PlaySound(AudioClip clip)
		{
			if ((Object)(object)audioSource == (Object)null)
			{
				audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
			}
			if (!audioSource.isPlaying)
			{
				audioSource.PlayOneShot(clip);
			}
			else
			{
				Debug.Log((object)"Le son est déjà en train de jouer, il ne sera pas joué à nouveau.");
			}
		}

		protected override void __initializeVariables()
		{
			((PhysicsProp)this).__initializeVariables();
		}

		protected internal override string? __getTypeName()
		{
			return "DamagePlayerItem";
		}
	}
}
namespace El Grinchos and Friends.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}