Decompiled source of EmeraudeBucheron v1.0.0

plugins/EmeraudeBucheron.dll

Decompiled 44 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Utils;
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("EmeraudeBucheron")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EmeraudeBucheron")]
[assembly: AssemblyTitle("EmeraudeBucheron")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 EmeraudeBucheron
{
	[BepInPlugin("emeraude.bucheron", "Emeraude Bucheron", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "emeraude.bucheron";

		public const string Name = "Emeraude Bucheron";

		public const string Version = "1.0.0";

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			new Harmony("emeraude.bucheron").PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Emeraude Bucheron 1.0.0 loaded");
		}
	}
	internal static class TreeDrops
	{
		private const string ResinPrefab = "Resin";

		private const int ResinMin = 1;

		private const int ResinMax = 3;

		private static readonly HashSet<string> SeedPrefabs = new HashSet<string> { "BeechSeeds", "BirchSeeds", "Acorn", "FirCone", "PineCone" };

		internal static TreeBase Felling;

		internal static void Complete(DropTable table, List<GameObject> drops)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			DropData val = ((IEnumerable<DropData>)table.m_drops).FirstOrDefault((Func<DropData, bool>)((DropData d) => IsResin(d.m_item)));
			if (Object.op_Implicit((Object)(object)val.m_item))
			{
				int num = Random.Range(1, 4) - drops.Count(IsResin);
				for (int num2 = 0; num2 < num; num2++)
				{
					drops.Add(val.m_item);
				}
			}
			foreach (DropData seed in table.m_drops.Where((DropData d) => IsSeed(d.m_item)))
			{
				if (!drops.Any((GameObject d) => ((Object)d).name == ((Object)seed.m_item).name))
				{
					int num3 = Random.Range(Mathf.Max(1, seed.m_stackMin), Mathf.Max(1, seed.m_stackMax) + 1);
					for (int num4 = 0; num4 < num3; num4++)
					{
						drops.Add(seed.m_item);
					}
				}
			}
		}

		internal static bool IsResin(GameObject item)
		{
			if (Object.op_Implicit((Object)(object)item))
			{
				return ((Object)item).name == "Resin";
			}
			return false;
		}

		internal static bool IsSeed(GameObject item)
		{
			if (Object.op_Implicit((Object)(object)item))
			{
				return SeedPrefabs.Contains(((Object)item).name);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(TreeBase), "RPC_Damage")]
	internal static class TreeBaseDamagePatch
	{
		private static void Prefix(TreeBase __instance)
		{
			TreeDrops.Felling = __instance;
		}

		private static Exception Finalizer(Exception __exception)
		{
			TreeDrops.Felling = null;
			return __exception;
		}
	}
	[HarmonyPatch(typeof(DropTable), "GetDropList", new Type[] { })]
	internal static class DropListPatch
	{
		private static void Postfix(DropTable __instance, List<GameObject> __result)
		{
			TreeBase felling = TreeDrops.Felling;
			if (Object.op_Implicit((Object)(object)felling) && __instance == felling.m_dropWhenDestroyed)
			{
				TreeDrops.Complete(__instance, __result);
			}
		}
	}
	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	internal static class TreeListPatch
	{
		private static void Postfix(ZNetScene __instance)
		{
			IEnumerable<string> values = from p in __instance.m_prefabs
				select (!Object.op_Implicit((Object)(object)p)) ? null : p.GetComponent<TreeBase>() into t
				where Object.op_Implicit((Object)(object)t)
				select ((Object)t).name + " [" + string.Join(", ", t.m_dropWhenDestroyed.m_drops.Select((DropData d) => (!Object.op_Implicit((Object)(object)d.m_item)) ? "?" : ((Object)d.m_item).name)) + "]" + (t.m_dropWhenDestroyed.m_drops.Any((DropData d) => TreeDrops.IsResin(d.m_item)) ? " résine" : "") + (t.m_dropWhenDestroyed.m_drops.Any((DropData d) => TreeDrops.IsSeed(d.m_item)) ? " graines" : "");
			Plugin.Log.LogInfo((object)("Arbres : " + string.Join(" ; ", values)));
		}
	}
}