Decompiled source of BrackenSaucisse v2.0.0

Roucas76.BrackenSaucisse.dll

Decompiled 3 days 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CSync.Extensions;
using CSync.Lib;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Roucas76.BrackenSaucisse")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+93c808757960a6b69ef8730188a215a97622a9e1")]
[assembly: AssemblyProduct("BrackenSaucisse")]
[assembly: AssemblyTitle("Roucas76.BrackenSaucisse")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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 BrackenSaucisse
{
	public class BrackenSaucisseConfig : SyncedConfig2<BrackenSaucisseConfig>
	{
		[SyncedEntryField]
		public readonly SyncedEntry<double> SausageChances;

		public BrackenSaucisseConfig(ConfigFile cfg)
			: base("Roucas76.BrackenSaucisse")
		{
			SausageChances = SyncedBindingExtensions.BindSyncedEntry<double>(cfg, "BrackenSaucisse", "SausageChances", 12.5, "Chances to trigger the Saucissade.");
			ConfigManager.Register<BrackenSaucisseConfig>((SyncedConfig2<BrackenSaucisseConfig>)(object)this);
		}
	}
	[BepInPlugin("Roucas76.BrackenSaucisse", "BrackenSaucisse", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency("com.sigurd.csync", "5.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static BrackenSaucisseConfig Config;

		public static Plugin Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Config = new BrackenSaucisseConfig(((BaseUnityPlugin)this).Config);
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			Logger.LogInfo((object)"Roucas76.BrackenSaucisse v1.0.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("Roucas76.BrackenSaucisse");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Roucas76.BrackenSaucisse";

		public const string PLUGIN_NAME = "BrackenSaucisse";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace BrackenSaucisse.Patches
{
	[HarmonyPatch(typeof(EnemyAI))]
	public class BrackenEverywherePatch
	{
		[HarmonyPatch(typeof(EnemyAI), "PlayerIsTargetable")]
		[HarmonyPostfix]
		private static void TargetAnything(EnemyAI __instance, ref bool __result)
		{
			if ((Object)(object)__instance == (Object)(object)GiftBoxItemPatch.Bracken)
			{
				__result = true;
			}
		}
	}
	[HarmonyPatch(typeof(GiftBoxItem))]
	public class GiftBoxItemPatch
	{
		public static PlayerControllerB? Player;

		private static GiftBoxItem? Instance;

		public static FlowermanAI? Bracken;

		[HarmonyPatch(typeof(GiftBoxItem), "ItemActivate")]
		[HarmonyPrefix]
		private static void DoActivate(GiftBoxItem __instance)
		{
			Instance = __instance;
			Player = GameNetworkManager.Instance.localPlayerController;
			float num = Random.value * 100f;
			Plugin.Logger.LogInfo((object)$"ROLL Sausage : {num}");
			if ((double)num <= Plugin.Config.SausageChances.Value)
			{
				ForceGlizzy();
				GetBracken();
			}
		}

		private static void ForceGlizzy()
		{
			Item val = StartOfRound.Instance.allItemsList.itemsList.Find((Item x) => x.itemName.Equals("Glizzy"));
			Instance.objectInPresentItem = val;
			Instance.objectInPresent = val.spawnPrefab;
			Random random = new Random((int)((GrabbableObject)Instance).targetFloorPosition.x + (int)((GrabbableObject)Instance).targetFloorPosition.y);
			Instance.objectInPresentValue = (int)((float)random.Next(val.minValue + 25, val.maxValue + 35) * RoundManager.Instance.scrapValueMultiplier);
		}

		private static void GetBracken()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_006c: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			EnemyAI val = ((IEnumerable<EnemyAI>)RoundManager.Instance.SpawnedEnemies).FirstOrDefault((Func<EnemyAI, bool>)((EnemyAI x) => (Object)(object)((Component)x).GetComponent<FlowermanAI>() != (Object)null));
			NetworkObject value;
			if ((Object)(object)val != (Object)null)
			{
				value = ((NetworkBehaviour)val).NetworkObject;
			}
			else
			{
				Vector3 val2 = -((Component)Player).transform.forward;
				Vector3 val3 = ((Component)Player).transform.position + val2 * 0.1f;
				List<SpawnableEnemyWithRarity> list = new List<SpawnableEnemyWithRarity>();
				list.AddRange(RoundManager.Instance.currentLevel.Enemies);
				list.AddRange(RoundManager.Instance.currentLevel.OutsideEnemies);
				list.AddRange(RoundManager.Instance.currentLevel.DaytimeEnemies);
				SpawnableEnemyWithRarity val4 = list.Find((SpawnableEnemyWithRarity x) => x.enemyType.enemyName.Equals("Flowerman"));
				NetworkObjectReference val5 = RoundManager.Instance.SpawnEnemyGameObject(val3, 0f, -1, val4.enemyType);
				NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(((NetworkObjectReference)(ref val5)).NetworkObjectId, out value);
			}
			if ((Object)(object)value != (Object)null)
			{
				Bracken = ((Component)value).GetComponent<FlowermanAI>();
				((EnemyAI)Bracken).SetEnemyOutside(true);
				((EnemyAI)Bracken).SetMovingTowardsTargetPlayer(Player);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	public class SausagePatch
	{
		private static PlayerControllerB Player;

		[HarmonyPatch(typeof(PlayerControllerB), "Awake")]
		[HarmonyPostfix]
		private static void Awake(PlayerControllerB __instance)
		{
			Player = __instance;
		}

		[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
		[HarmonyPrefix]
		private static void PostFix(PlayerControllerB __instance, ref bool spawnBody)
		{
			if (!((Object)(object)__instance != (Object)(object)GiftBoxItemPatch.Player))
			{
				spawnBody = false;
				GiftBoxItemPatch.Player = null;
			}
		}
	}
}