Decompiled source of TerrasRebalance v1.2.0

TerrasRebalance.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TerrasRebalance.Patches;
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("TerrasRebalance")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Personally tuned tweaks and rebalances for Lethal Company")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+1832cbf93bf761d51c1e43aa3a5665280be73191")]
[assembly: AssemblyProduct("TerrasRebalance")]
[assembly: AssemblyTitle("TerrasRebalance")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TerrasRebalance
{
	internal class TerrasRebalanceConfig
	{
		internal static ConfigEntry<bool> changeShovelWeight;

		internal static ConfigEntry<bool> changeStopSignWeight;

		internal static ConfigEntry<bool> changeJetpackPrice;

		internal static ConfigEntry<bool> changeButlerHealth;

		internal static ConfigEntry<bool> changeBeeBehavior;

		internal static ConfigEntry<bool> changeNutcrackerBehavior;

		internal static ConfigEntry<bool> changeMouthDogHealth;

		internal static ConfigEntry<bool> changeJesterTimer;

		internal static ConfigEntry<bool> changeStormyTimers;

		internal static void Bind(ConfigFile config)
		{
			changeShovelWeight = config.Bind<bool>("Items", "8 lb Shovel", true, "Shovels are 8 lbs.\n\nDisable this if you're using other mods to change the weight of Shovels.");
			changeStopSignWeight = config.Bind<bool>("Items", "21 lb Stop Sign", true, "Stop Signs are 21 lbs.\n\nDisable this if you're using other mods to change the weight of Stop Signs.");
			changeJetpackPrice = config.Bind<bool>("Items", "$700 Jetpack", true, "Jetpacks are $700.\n\nDisable this if you're using other mods to change the price of Jetpacks.");
			changeButlerHealth = config.Bind<bool>("Entites", "4 HP Butlers", true, "Butlers have 4 HP on multiplayer. (It is still 2 in singleplayer)\n\nDisable this if you're using other mods that change the behavior of Butlers.");
			changeBeeBehavior = config.Bind<bool>("Entites", "Rebalanced Bees", true, "Mask Hornets and Circuit Bees cannot open doors, but Mask Hornets travel at their multiplayer speed in singleplayer.\n\nDisable this if you're using other mods that change the behavior of bees.");
			changeNutcrackerBehavior = config.Bind<bool>("Entites", "Gradually Faster Nutcracker", true, "Nutcrackers at 2-3 HP will shoot slightly faster. (1.3s for the first shot, 1s for the second shot)\n\nDisable this if you're using other mods that change the behavior of Nutcrackers.");
			changeMouthDogHealth = config.Bind<bool>("Entites", "10 HP Eyeless Dogs", true, "Eyeless Dogs have 10 HP instead of 12.\n\nDisable this if you're using other mods that change the behavior of Eyeless Dogs.");
			changeJesterTimer = config.Bind<bool>("Entites", "Old Jester Timer", true, "Jesters will wait 25-42 seconds to begin cranking.\n\nDisable this if you're using other mods that change the timer of Jesters.");
			changeStormyTimers = config.Bind<bool>("Weather", "Rebalanced Stormy", true, "Increase the maximum duration between lightning strikes slightly (by 25%) and doubles the minimum duration for held items being struck.\n\nDisable this if you're using other mods that change the behavior of Stormy Weather.");
		}
	}
	[BepInPlugin("TerrasRebalance", "TerrasRebalance", "1.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("TerrasRebalance");

		public static Plugin Instance;

		private void Awake()
		{
			if (Instance == null)
			{
				Instance = this;
			}
			TerrasRebalanceConfig.Bind(((BaseUnityPlugin)this).Config);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin TerrasRebalance is loaded!");
			if (TerrasRebalanceConfig.changeBeeBehavior.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Applying Bees Patch");
				harmony.PatchAll(typeof(CircuitBeesPatch));
				harmony.PatchAll(typeof(ButlerBeesPatch));
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Bees Patched");
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Skipping Bees Patch");
			}
			if (TerrasRebalanceConfig.changeButlerHealth.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Applying Butler Patch");
				harmony.PatchAll(typeof(ButlerPatch));
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Butler Patched");
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Skipping Butler Patch");
			}
			if (TerrasRebalanceConfig.changeJesterTimer.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Applying Jester Patch");
				harmony.PatchAll(typeof(JesterPatch));
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Jester Patched");
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Skipping Jester Patch");
			}
			if (TerrasRebalanceConfig.changeMouthDogHealth.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Applying Mouth Dog Patch");
				harmony.PatchAll(typeof(MouthDogPatch));
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Mouth Dog Patched");
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Skipping Mouth Dog Patch");
			}
			if (TerrasRebalanceConfig.changeNutcrackerBehavior.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Applying Nutcracker Patch");
				harmony.PatchAll(typeof(NutcrackerPatch));
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Nutcracker Patched");
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Skipping Nutcracker Patch");
			}
			if (TerrasRebalanceConfig.changeShovelWeight.Value || TerrasRebalanceConfig.changeStopSignWeight.Value || TerrasRebalanceConfig.changeJetpackPrice.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Applying Items Patch");
				harmony.PatchAll(typeof(ItemPatch));
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Items Patched");
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Skipping Items Patch");
			}
			if (TerrasRebalanceConfig.changeStormyTimers.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Applying Stormy Patch");
				harmony.PatchAll(typeof(StormyPatch));
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Stormy Patched");
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Skipping Stormy Patch");
			}
		}

		public static void Log(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)msg);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "TerrasRebalance";

		public const string PLUGIN_NAME = "TerrasRebalance";

		public const string PLUGIN_VERSION = "1.2.0";
	}
}
namespace TerrasRebalance.Patches
{
	[HarmonyPatch(typeof(RedLocustBees))]
	public class CircuitBeesPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Postfix(RedLocustBees __instance)
		{
			((EnemyAI)__instance).openDoorSpeedMultiplier = 0f;
		}
	}
	[HarmonyPatch(typeof(ButlerBeesEnemyAI))]
	public class ButlerBeesPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Postfix(ButlerBeesEnemyAI __instance)
		{
			((EnemyAI)__instance).openDoorSpeedMultiplier = 0f;
		}

		[HarmonyPatch("DoAIInterval")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> SpeedPatch(IEnumerable<CodeInstruction> instructions)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count - 1; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 4.25f)
				{
					list[i] = new CodeInstruction(OpCodes.Ldc_R4, (object)5.4f);
					break;
				}
			}
			return list;
		}
	}
	[HarmonyPatch(typeof(ButlerEnemyAI))]
	public class ButlerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void ChangeButlerHealth(ref ButlerEnemyAI __instance)
		{
			if (StartOfRound.Instance.connectedPlayersAmount > 0)
			{
				((EnemyAI)__instance).enemyHP = 4;
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class ItemPatch
	{
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		[HarmonyPostfix]
		private static void ChangeItemData()
		{
			foreach (Item items in StartOfRound.Instance.allItemsList.itemsList)
			{
				switch (((Object)items).name)
				{
				case "Shovel":
					if (TerrasRebalanceConfig.changeShovelWeight.Value)
					{
						items.weight = 1.08f;
					}
					break;
				case "StopSign":
					if (TerrasRebalanceConfig.changeStopSignWeight.Value)
					{
						items.weight = 1.2f;
					}
					break;
				case "Jetpack":
					if (TerrasRebalanceConfig.changeJetpackPrice.Value)
					{
						items.creditsWorth = 700;
					}
					break;
				}
			}
		}
	}
	[HarmonyPatch(typeof(JesterAI))]
	public class JesterPatch
	{
		[HarmonyPatch(typeof(JesterAI), "SetJesterInitialValues")]
		[HarmonyPostfix]
		private static void ChangeJesterTimer(ref JesterAI __instance)
		{
			__instance.beginCrankingTimer = Random.Range(25f, 42f);
		}
	}
	[HarmonyPatch(typeof(MouthDogAI))]
	public class MouthDogPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void ChangeDogHealth(ref MouthDogAI __instance)
		{
			((EnemyAI)__instance).enemyHP = 10;
		}
	}
	[HarmonyPatch(typeof(NutcrackerEnemyAI))]
	public class NutcrackerPatch
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> AimGunPatch(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Expected O, but got Unknown
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			bool flag = false;
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count - 1; i++)
			{
				if (list[i + 1].opcode == OpCodes.Ldc_R4 && (float)list[i + 1].operand == 1.3f && !flag)
				{
					list.Insert(i + 1, new CodeInstruction(OpCodes.Ldloc_1, (object)null));
					list.Insert(i + 2, new CodeInstruction(OpCodes.Ldloc_1, (object)null));
					list.Insert(i + 4, new CodeInstruction(OpCodes.Ldc_R4, (object)1f));
					list.Insert(i + 5, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(NutcrackerPatch), "ChangeAimTime", (Type[])null, (Type[])null)));
					flag = true;
				}
				if (list[i + 1].opcode == OpCodes.Ldc_R4 && (float)list[i + 1].operand == 1.75f)
				{
					list.Insert(i + 1, new CodeInstruction(OpCodes.Ldloc_1, (object)null));
					list.Insert(i + 2, new CodeInstruction(OpCodes.Ldloc_1, (object)null));
					list.Insert(i + 4, new CodeInstruction(OpCodes.Ldc_R4, (object)1.3f));
					list.Insert(i + 5, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(NutcrackerPatch), "ChangeAimTime", (Type[])null, (Type[])null)));
					break;
				}
			}
			return list;
		}

		public float ChangeAimTime(NutcrackerEnemyAI ai, float aimTime, float changeTime)
		{
			if (((EnemyAI)ai).enemyHP > 3)
			{
				return aimTime;
			}
			return changeTime;
		}
	}
	[HarmonyPatch(typeof(StormyWeather))]
	public class StormyPatch
	{
		[HarmonyPatch(typeof(StormyWeather), "Update")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> UpdatePatch(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Expected O, but got Unknown
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count - 1; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 1f && list[i + 1].opcode == OpCodes.Ldc_R4 && (float)list[i + 1].operand == 28f)
				{
					list[i + 1] = new CodeInstruction(OpCodes.Ldc_R4, (object)35f);
					list[i + 4] = new CodeInstruction(OpCodes.Ldc_R4, (object)25f);
				}
				if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 4f && list[i + 1].opcode == OpCodes.Ldc_R4 && (float)list[i + 1].operand == 20f)
				{
					list[i] = new CodeInstruction(OpCodes.Ldc_R4, (object)8f);
					list[i + 1] = new CodeInstruction(OpCodes.Ldc_R4, (object)25f);
					break;
				}
			}
			return list;
		}
	}
}