Decompiled source of ApparatusRetrieval v1.0.2

kamppix.ApparatusRetrieval.dll

Decompiled 2 months 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.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
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("kamppix.ApparatusRetrieval")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+cf5c745dc4b6f85cb490156dce4f4038eadf8f21")]
[assembly: AssemblyProduct("ApparatusRetrieval")]
[assembly: AssemblyTitle("kamppix.ApparatusRetrieval")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 ApparatusRetrieval
{
	[BepInPlugin("kamppix.ApparatusRetrieval", "ApparatusRetrieval", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		internal static Dictionary<int, float> MapSizes = new Dictionary<int, float>();

		internal static int[] SkippedMoons = new int[2] { 8, 11 };

		internal static Dictionary<string, ConfigEntry<float>> FloatConfig = new Dictionary<string, ConfigEntry<float>>();

		internal static Dictionary<string, ConfigEntry<bool>> BoolConfig = new Dictionary<string, ConfigEntry<bool>>();

		public static Plugin Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			AddConfig();
			Logger.LogInfo((object)"kamppix.ApparatusRetrieval v1.0.2 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("kamppix.ApparatusRetrieval");
			}
			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!");
		}

		private void AddConfig()
		{
			FloatConfig.Add("MapSizeMultiplier", ((BaseUnityPlugin)this).Config.Bind<float>("Difficulty", "MapSizeMultiplier", 1f, "Size multiplier for map generation. Minimum value: 1"));
			FloatConfig.Add("DaySpeedMultiplier", ((BaseUnityPlugin)this).Config.Bind<float>("Difficulty", "DaySpeedMultiplier", 1f, "Speed multiplier for daytime progression."));
			BoolConfig.Add("InstantWipe", ((BaseUnityPlugin)this).Config.Bind<bool>("Difficulty", "InstantWipe", false, "Every employee dies when one of you does."));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "kamppix.ApparatusRetrieval";

		public const string PLUGIN_NAME = "ApparatusRetrieval";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}
namespace ApparatusRetrieval.Patches
{
	[HarmonyPatch(typeof(RedLocustBees), "Start")]
	public class BeesStartPatch
	{
		private static void Postfix(RedLocustBees __instance)
		{
			__instance.hive.SetScrapValue(0);
		}
	}
	[HarmonyPatch(typeof(RoundManager), "GenerateNewLevelClientRpc")]
	public class GenerateLevelPatch
	{
		private static void Prefix(RoundManager __instance, ref int levelID)
		{
			if (Plugin.MapSizes.Count == 0)
			{
				SelectableLevel[] levels = StartOfRound.Instance.levels;
				foreach (SelectableLevel val in levels)
				{
					Plugin.MapSizes.Add(val.levelID, val.factorySizeMultiplier);
				}
			}
			SelectableLevel currentLevel = __instance.currentLevel;
			currentLevel.dungeonFlowTypes = StartOfRound.Instance.levels[0].dungeonFlowTypes;
			currentLevel.dungeonFlowTypes[0].rarity = 1;
			currentLevel.dungeonFlowTypes[1].rarity = 0;
			currentLevel.dungeonFlowTypes[2].rarity = 0;
			currentLevel.factorySizeMultiplier = Plugin.MapSizes[levelID] * Plugin.FloatConfig["MapSizeMultiplier"].Value;
			currentLevel.DaySpeedMultiplier = Plugin.FloatConfig["DaySpeedMultiplier"].Value;
			foreach (SpawnableEnemyWithRarity enemy in currentLevel.Enemies)
			{
				enemy.enemyType.PowerLevel = 0f;
			}
			foreach (SpawnableEnemyWithRarity outsideEnemy in currentLevel.OutsideEnemies)
			{
				outsideEnemy.enemyType.PowerLevel = 0f;
			}
		}
	}
	[HarmonyPatch(typeof(Terminal), "Start")]
	public class ItemPricePatch
	{
		private static void Postfix(Terminal __instance)
		{
			Item[] buyableItemsList = __instance.buyableItemsList;
			foreach (Item val in buyableItemsList)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.creditsWorth = 0;
				}
			}
			BuyableVehicle[] buyableVehicles = __instance.buyableVehicles;
			foreach (BuyableVehicle val2 in buyableVehicles)
			{
				if (val2 != null)
				{
					val2.creditsWorth = 0;
				}
			}
			foreach (TerminalNode item in __instance.ShipDecorSelection)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.itemCost = 0;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Terminal), "SetItemSales")]
	public class ItemSalePatch
	{
		private static bool Prefix(Terminal __instance)
		{
			if (__instance.itemSalesPercentages == null || __instance.itemSalesPercentages.Length == 0)
			{
				__instance.InitializeItemSalesPercentages();
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(JesterAI), "Update")]
	public class JesterSpeedPatch
	{
		private static void Postfix(JesterAI __instance)
		{
			if (((EnemyAI)__instance).currentBehaviourStateIndex == 2 && !__instance.inKillAnimation && !(((EnemyAI)__instance).stunNormalizedTimer > 0f))
			{
				((EnemyAI)__instance).agent.speed = Mathf.Min(((EnemyAI)__instance).agent.speed, 3f);
			}
		}
	}
	[HarmonyPatch(typeof(StartMatchLever), "BeginHoldingInteractOnLever")]
	public class LeverPullPatch
	{
		private static bool Prefix()
		{
			return false;
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "SetTimeAndPlanetToSavedSettings")]
	public class LoadSavePatch
	{
		private static void Prefix(StartOfRound __instance)
		{
			TimeOfDay.Instance.quotaVariables.startingQuota = 1;
			TimeOfDay.Instance.quotaVariables.deadlineDaysAmount = __instance.levels.Length - Plugin.SkippedMoons.Length - 1;
			TimeOfDay.Instance.quotaVariables.startingCredits = 0;
			int num = 0;
			int[] skippedMoons = Plugin.SkippedMoons;
			foreach (int num2 in skippedMoons)
			{
				if (num == num2)
				{
					num++;
				}
			}
			__instance.defaultPlanet = num;
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "PassTimeToNextDay")]
	public class PassTimePatch
	{
		private static bool Prefix(StartOfRound __instance)
		{
			if (__instance.isChallengeFile)
			{
				TimeOfDay.Instance.globalTime = 100f;
				__instance.SetMapScreenInfoToCurrentLevel();
				return false;
			}
			if (__instance.scrapCollectedLastRound == 0)
			{
				bool flag = false;
				if (TimeOfDay.Instance.timeUntilDeadline >= 0f)
				{
					TimeOfDay.Instance.timeUntilDeadline = TimeOfDay.Instance.timeUntilDeadline - TimeOfDay.Instance.timeUntilDeadline % TimeOfDay.Instance.totalTime + TimeOfDay.Instance.totalTime;
				}
				else
				{
					TimeOfDay.Instance.timeUntilDeadline = 0f;
				}
			}
			if (TimeOfDay.Instance.timeUntilDeadline >= 0f)
			{
				TimeOfDay.Instance.timeUntilDeadline = TimeOfDay.Instance.timeUntilDeadline - TimeOfDay.Instance.timeUntilDeadline % TimeOfDay.Instance.totalTime + 1f;
			}
			TimeOfDay.Instance.OnDayChanged();
			TimeOfDay.Instance.globalTime = 100f;
			TimeOfDay.Instance.UpdateProfitQuotaCurrentTime();
			if (__instance.currentLevel.planetHasTime)
			{
				HUDManager.Instance.DisplayDaysLeft((int)Mathf.Floor(TimeOfDay.Instance.timeUntilDeadline / TimeOfDay.Instance.totalTime));
			}
			__instance.SetMapScreenInfoToCurrentLevel();
			if (TimeOfDay.Instance.timeUntilDeadline > 0f && TimeOfDay.Instance.daysUntilDeadline <= 0 && TimeOfDay.Instance.timesFulfilledQuota <= 0)
			{
				((MonoBehaviour)__instance).StartCoroutine(__instance.playDaysLeftAlertSFXDelayed());
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "KillPlayerClientRpc")]
	public class PlayerDeathPatch
	{
		private static void Postfix(PlayerControllerB __instance)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.BoolConfig["InstantWipe"].Value && __instance.isPlayerDead)
			{
				PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
				if (!localPlayerController.isPlayerDead)
				{
					localPlayerController.KillPlayer(Vector3.zero, true, (CauseOfDeath)0, 1, default(Vector3));
				}
			}
		}
	}
	[HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")]
	public class PurchasePatch
	{
		private static void Postfix(TerminalNode __result)
		{
			if (__result.buyVehicleIndex != -1 || __result.shipUnlockableID != -1)
			{
				__result.itemCost = 0;
			}
			else if (__result.buyRerouteToMoon != -1)
			{
				__result.itemCost = 1;
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
	public class ScrapDespawnPatch
	{
		private static void Prefix()
		{
			bool flag = true;
			StartOfRound.Instance.allPlayersDead = false;
		}
	}
	[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
	public class ScrapSpawnPatch
	{
		private static bool Prefix()
		{
			return false;
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "AllPlayersHaveRevivedClientRpc")]
	public class ShipRoutePatch
	{
		private static void Postfix(StartOfRound __instance)
		{
			int num = __instance.levels.Length - Plugin.SkippedMoons.Length;
			int num2 = num - TimeOfDay.Instance.daysUntilDeadline - 1;
			int[] skippedMoons = Plugin.SkippedMoons;
			foreach (int num3 in skippedMoons)
			{
				if (num2 >= num3)
				{
					num2++;
				}
			}
			if (num2 == 3)
			{
				num2 = 8;
			}
			if (__instance.currentLevelID != num2 && num2 != -1)
			{
				__instance.ChangeLevelServerRpc(num2, 0);
				__instance.AutoSaveShipData();
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "LoadUnlockables")]
	public class UnlockableLoadPatch
	{
		private static void Postfix(StartOfRound __instance)
		{
			for (int i = 0; i < __instance.unlockablesList.unlockables.Count; i++)
			{
				if (__instance.unlockablesList.unlockables[i].unlockableType == 0)
				{
					__instance.UnlockShipObject(i);
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "ResetShipFurniture")]
	public class UnlockableResetPatch
	{
		private static void Postfix(StartOfRound __instance)
		{
			for (int i = 0; i < __instance.unlockablesList.unlockables.Count; i++)
			{
				if (__instance.unlockablesList.unlockables[i].unlockableType == 0)
				{
					__instance.UnlockShipObject(i);
				}
			}
		}
	}
}
namespace QuotaScalingMoons.Patches
{
	[HarmonyPatch(typeof(LungProp), "DisconnectFromMachinery")]
	public class ApparatusPullPatch
	{
		private static void Prefix(LungProp __instance)
		{
			((GrabbableObject)__instance).SetScrapValue(1);
		}
	}
}