Decompiled source of BozorosTweaks v1.0.1

BozorosTweaks.dll

Decompiled 4 hours ago
using System;
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 BozorosTweaks.Patches;
using BozorosTweaks.Util;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("BozorosTweaks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Fixes, tweaks, and small additions for LethalMatt's Bozoros!")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BozorosTweaks")]
[assembly: AssemblyTitle("BozorosTweaks")]
[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 BozorosTweaks
{
	[BepInPlugin("pacoito.BozorosTweaks", "BozorosTweaks", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal const string GUID = "pacoito.BozorosTweaks";

		internal const string PLUGIN_NAME = "BozorosTweaks";

		internal const string VERSION = "1.0.0";

		internal static ManualLogSource? StaticLogger { get; private set; }

		internal static Harmony? Harmony { get; private set; }

		private void Awake()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			StaticLogger = ((BaseUnityPlugin)this).Logger;
			try
			{
				Harmony = new Harmony("pacoito.BozorosTweaks");
				Harmony.PatchAll(typeof(LoadPatches));
				Harmony.PatchAll(typeof(ClownGiantPatch));
				StaticLogger.LogInfo((object)"'BozorosTweaks' loaded!");
			}
			catch (Exception arg)
			{
				StaticLogger.LogError((object)string.Format("Error while initializing '{0}': {1}", "BozorosTweaks", arg));
			}
		}
	}
}
namespace BozorosTweaks.Util
{
	internal class VanillaPrefabUtils
	{
		internal static bool GetInsideEnemyPrefab(string enemyName, out GameObject? enemyPrefab)
		{
			string enemyName2 = enemyName;
			enemyPrefab = null;
			for (int i = 0; i < StartOfRound.Instance.levels.Length; i++)
			{
				EnemyType val = StartOfRound.Instance.levels[i]?.Enemies?.Find((SpawnableEnemyWithRarity enemy) => string.CompareOrdinal(enemy.enemyType.enemyName, enemyName2) == 0)?.enemyType;
				if ((Object)(object)val != (Object)null)
				{
					enemyPrefab = val.enemyPrefab;
					return true;
				}
			}
			ManualLogSource? staticLogger = Plugin.StaticLogger;
			if (staticLogger != null)
			{
				staticLogger.LogWarning((object)("Could not find enemy '" + enemyName2 + "' in any moon's list of spawns."));
			}
			return false;
		}

		internal static bool GetOutsideEnemyPrefab(string enemyName, out GameObject? enemyPrefab)
		{
			string enemyName2 = enemyName;
			enemyPrefab = null;
			for (int i = 0; i < StartOfRound.Instance.levels.Length; i++)
			{
				EnemyType val = StartOfRound.Instance.levels[i]?.OutsideEnemies?.Find((SpawnableEnemyWithRarity enemy) => string.CompareOrdinal(enemy.enemyType.enemyName, enemyName2) == 0)?.enemyType;
				if ((Object)(object)val != (Object)null)
				{
					enemyPrefab = val.enemyPrefab;
					return true;
				}
			}
			ManualLogSource? staticLogger = Plugin.StaticLogger;
			if (staticLogger != null)
			{
				staticLogger.LogWarning((object)("Could not find enemy '" + enemyName2 + "' in any moon's list of spawns."));
			}
			return false;
		}
	}
}
namespace BozorosTweaks.Patches
{
	[HarmonyPatch(typeof(ForestGiantAI), "Start")]
	internal class ClownGiantPatch
	{
		public static GameObject? ForestGiantPrefab { get; internal set; }

		private static void Postfix(ForestGiantAI __instance)
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			if (((Object)((Component)__instance).gameObject).name.StartsWith("ClownGiant"))
			{
				GameObject? forestGiantPrefab = ForestGiantPrefab;
				ForestGiantAI val = default(ForestGiantAI);
				if (forestGiantPrefab != null && forestGiantPrefab.TryGetComponent<ForestGiantAI>(ref val))
				{
					((EnemyAI)__instance).enemyHP = ((EnemyAI)val).enemyHP;
					((EnemyAI)__instance).enemyType = ((EnemyAI)val).enemyType;
					((EnemyAI)__instance).enemyBehaviourStates = ((EnemyAI)val).enemyBehaviourStates;
					__instance.giantFall = val.giantFall;
					__instance.giantCry = val.giantCry;
					GameObject gameObject = ((Component)((Component)__instance).transform.Find("FGiantModelContainer/AnimContainer")).gameObject;
					gameObject.GetComponent<Animator>().runtimeAnimatorController = (RuntimeAnimatorController)new AnimatorOverrideController(((Component)ForestGiantPrefab.transform.Find("FGiantModelContainer/AnimContainer")).GetComponent<Animator>().runtimeAnimatorController);
					gameObject.AddComponent<EnemyAnimationEvent>().mainScript = (EnemyAI)(object)__instance;
					__instance.giantBurningAudio = ((Component)Object.Instantiate<Transform>(ForestGiantPrefab.transform.Find("FGiantModelContainer/BurningSFX"), gameObject.transform.GetParent(), false)).GetComponent<AudioSource>();
					((Object)__instance.giantBurningAudio).name = "BurningSFX";
					__instance.burningParticlesContainer = ((Component)Object.Instantiate<Transform>(ForestGiantPrefab.transform.Find("FireParticlesContainer"), ((Component)__instance).transform, false)).gameObject;
					((Object)__instance.burningParticlesContainer).name = "FireParticlesContainer";
					__instance.deathFallPosition = Object.Instantiate<Transform>(ForestGiantPrefab.transform.Find("FallPosition"), ((Component)__instance).transform, false);
					((Object)__instance.deathFallPosition).name = "FallPosition";
				}
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager), "LoadNewLevel")]
	internal class EnemiesPatch
	{
		public static EnemyType? BarberType { get; internal set; }

		public static bool EnemiesAdded { get; private set; }

		[HarmonyPostfix]
		private static void LoadNewLevelPost(SelectableLevel newLevel)
		{
			if (!EnemiesAdded && !((Object)(object)BarberType == (Object)null) && string.CompareOrdinal(newLevel.PlanetName, "Bozoros") == 0)
			{
				AddEnemy(newLevel, Object.Instantiate<EnemyType>(BarberType), 85, 2);
				AddEnemy(newLevel, Object.Instantiate<EnemyType>(BarberType), 45, 2, isOutside: true);
				EnemiesAdded = true;
			}
		}

		private static void AddEnemy(SelectableLevel level, EnemyType spawnEnemyType, int spawnRarity, int maxCount, bool isOutside = false, bool isDaytime = false)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			spawnEnemyType.MaxCount = maxCount;
			spawnEnemyType.isOutsideEnemy = isOutside;
			spawnEnemyType.isDaytimeEnemy = isDaytime;
			List<SpawnableEnemyWithRarity> list;
			if (!isOutside && !isDaytime)
			{
				list = level.Enemies;
			}
			else if (isOutside)
			{
				list = level.OutsideEnemies;
			}
			else
			{
				if (!(isOutside && isDaytime))
				{
					return;
				}
				list = level.DaytimeEnemies;
			}
			SpawnableEnemyWithRarity item = new SpawnableEnemyWithRarity
			{
				enemyType = spawnEnemyType,
				rarity = spawnRarity
			};
			list.Add(item);
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "Start")]
	internal class LoadPatches
	{
		[HarmonyPostfix]
		private static void OnStartPost()
		{
			if (VanillaPrefabUtils.GetOutsideEnemyPrefab("ForestGiant", out GameObject enemyPrefab))
			{
				ClownGiantPatch.ForestGiantPrefab = enemyPrefab;
			}
		}
	}
}