Decompiled source of AutoCompanyBuilding v1.2.1

AutoCompanyBuilding.dll

Decompiled 5 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using AutoCompanyBuilding.Patches;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("AutoCompanyBuilding")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoCompanyBuilding")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5bc747e-4294-4a2d-9cbf-71992f97b9de")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AutoCompanyBuilding
{
	[BepInPlugin("La_Chips.AutoCompanyBuilding", "Auto Company Building", "1.2.1.0")]
	public class AutoCompanyBuildingBase : BaseUnityPlugin
	{
		private const string PLUGIN_GUID = "La_Chips.AutoCompanyBuilding";

		private const string PLUGIN_NAME = "Auto Company Building";

		private const string PLUGIN_VERSION = "1.2.1.0";

		private readonly Harmony harmony = new Harmony("La_Chips.AutoCompanyBuilding");

		private static AutoCompanyBuildingBase Instance;

		public static ManualLogSource logSource;

		public static int groupCredits;

		public static bool hasRerouted;

		private void Awake()
		{
			logSource = Logger.CreateLogSource("La_Chips.AutoCompanyBuilding");
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
				logSource.LogInfo((object)"Creating static instance");
			}
			logSource.LogInfo((object)"Plugin La_Chips.AutoCompanyBuilding is loaded!");
			harmony.PatchAll(typeof(AutoCompanyBuildingBase));
			harmony.PatchAll(typeof(TerminalPatch));
			harmony.PatchAll(typeof(StartOfRoundPatch));
		}
	}
}
namespace AutoCompanyBuilding.Patches
{
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		private static GameNetworkManager ___gameNetworkManager = GameNetworkManager.Instance;

		[HarmonyPatch("EndOfGame")]
		[HarmonyPostfix]
		private static void ResetHasRerouted()
		{
			if (___gameNetworkManager.isHostingGame)
			{
				AutoCompanyBuildingBase.hasRerouted = false;
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void AutoShipToCompanyBuilding(StartOfRound __instance)
		{
			if (___gameNetworkManager.isHostingGame)
			{
				if (__instance.currentLevelID == 3)
				{
					AutoCompanyBuildingBase.hasRerouted = true;
				}
				else if (__instance.CanChangeLevels() && TimeOfDay.Instance.daysUntilDeadline == 0 && !AutoCompanyBuildingBase.hasRerouted && TimeOfDay.Instance.quotaFulfilled < TimeOfDay.Instance.profitQuota)
				{
					__instance.ChangeLevelServerRpc(3, AutoCompanyBuildingBase.groupCredits);
					__instance.ChangeLevel(3);
					AutoCompanyBuildingBase.hasRerouted = true;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void gatherGroupCreditsValue(ref int ___groupCredits)
		{
			AutoCompanyBuildingBase.groupCredits = ___groupCredits;
		}
	}
}