Decompiled source of NoTimeOff v0.2.1

NoTimeOff.dll

Decompiled a month ago
using System;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using NoTimeOff.Helpers;
using NoTimeOff.NetcodePatcher;
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("NoTimeOff")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+7b084e364273dc0bdf28484053968c3e5a7d41e9")]
[assembly: AssemblyProduct("NoTimeOff")]
[assembly: AssemblyTitle("NoTimeOff")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
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 NoTimeOff
{
	[HarmonyPatch]
	internal class PatchCompanyMoon
	{
		public static string[] planetList;

		public static string prevLevel;

		public static bool hasDeductedDay = false;

		public static string ConfiguredMaps = NoTimeOffBase.config_PlanetName.Value;

		public static bool ConfigLogging = NoTimeOffBase.config_Logging.Value;

		[HarmonyPrefix]
		[HarmonyPriority(700)]
		[HarmonyPatch(typeof(StartOfRound), "ShipLeave")]
		public static void ShipLeave()
		{
			prevLevel = StartOfRound.Instance.currentLevel.PlanetName.ToString();
			hasDeductedDay = false;
		}

		[HarmonyPrefix]
		[HarmonyPriority(700)]
		[HarmonyPatch(typeof(StartOfRound), "Start")]
		public static void InitStart(StartOfRound __instance)
		{
			SelectableLevel[] levels = StartOfRound.Instance.levels;
			foreach (SelectableLevel val in levels)
			{
				if (ConfigLogging)
				{
					NoTimeOffBase.Instance.mls.LogDebug((object)("All Map Names: " + val.PlanetName));
				}
			}
			planetList = ConfiguredMaps.ToLower().Split(',');
		}

		[HarmonyPostfix]
		[HarmonyPriority(700)]
		[HarmonyPatch(typeof(StartOfRound), "SetShipReadyToLand")]
		public static void ShipReadyToLand()
		{
			if (!NetworkManager.Singleton.IsServer)
			{
				return;
			}
			if (ConfigLogging)
			{
				NoTimeOffBase.Instance.mls.LogInfo((object)$"Days until deadline: {TimeOfDay.Instance.daysUntilDeadline}");
			}
			if (!((Object)(object)StartOfRound.Instance == (Object)null) && !((Object)(object)TimeOfDay.Instance == (Object)null) && !((float)TimeOfDay.Instance.daysUntilDeadline <= 0f) && planetList != null && prevLevel != null && planetList.Contains(prevLevel.ToLower()) && !hasDeductedDay && (Object)(object)Net.Instance != (Object)null)
			{
				if (ConfigLogging)
				{
					NoTimeOffBase.Instance.mls.LogInfo((object)("Deducting day for map: " + prevLevel));
				}
				Net.Instance.TimeOffServerRpc();
				if (ConfigLogging)
				{
					NoTimeOffBase.Instance.mls.LogInfo((object)$"Day deducted. Days until deadline: {TimeOfDay.Instance.daysUntilDeadline}");
				}
				hasDeductedDay = true;
				prevLevel = "";
			}
		}
	}
	[BepInPlugin("SoftDiamond.NoTimeOff", "NoTimeOff", "1.0.0")]
	public class NoTimeOffBase : BaseUnityPlugin
	{
		public ManualLogSource mls;

		private const string GUID = "SoftDiamond.NoTimeOff";

		private const string NAME = "NoTimeOff";

		private const string VERSION = "1.0.0";

		private readonly Harmony harmony = new Harmony("SoftDiamond.NoTimeOff");

		public static ConfigEntry<string> config_PlanetName;

		public static ConfigEntry<bool> config_Logging;

		internal static NoTimeOffBase Instance { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("SoftDiamond.NoTimeOff");
			ConfigSetup();
			harmony.PatchAll();
			mls.LogInfo((object)"NoTimeOff has initialized!");
			NetcodePatcherAwake();
		}

		private void ConfigSetup()
		{
			config_PlanetName = ((BaseUnityPlugin)this).Config.Bind<string>("Affected Map Name(s)", "Names", "71 Gordion", "What planets/moons should be forced? Uses SelectableLevel.PlanetName variable.");
			config_Logging = ((BaseUnityPlugin)this).Config.Bind<bool>("Logging", "Enable Debug Logging", true, "Enable or disable debug logging for NoTimeOff.");
		}

		private void NetcodePatcherAwake()
		{
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				Type[] types = executingAssembly.GetTypes();
				Type[] array = types;
				foreach (Type type in array)
				{
					MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
					MethodInfo[] array2 = methods;
					foreach (MethodInfo methodInfo in array2)
					{
						try
						{
							object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
							if (customAttributes.Length != 0)
							{
								try
								{
									methodInfo.Invoke(null, null);
								}
								catch (TargetInvocationException ex)
								{
									((BaseUnityPlugin)this).Logger.LogWarning((object)("Failed to invoke method " + methodInfo.Name + ": " + ex.Message));
								}
							}
						}
						catch (Exception ex2)
						{
							((BaseUnityPlugin)this).Logger.LogWarning((object)("Error processing method " + methodInfo.Name + " in type " + type.Name + ": " + ex2.Message));
						}
					}
				}
			}
			catch (Exception ex3)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("An error occurred in NetcodePatcherAwake: " + ex3.Message));
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "NoTimeOff";

		public const string PLUGIN_NAME = "NoTimeOff";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace NoTimeOff.Helpers
{
	[HarmonyPatch]
	internal class Net : NetworkBehaviour
	{
		public static Net Instance;

		private static GameObject netObject;

		public void Awake()
		{
			Instance = this;
		}

		public void Update()
		{
		}

		public override void OnNetworkSpawn()
		{
			Instance = this;
			((NetworkBehaviour)this).OnNetworkSpawn();
		}

		public override void OnNetworkDespawn()
		{
			((NetworkBehaviour)this).OnNetworkDespawn();
		}

		[HarmonyPostfix]
		[HarmonyPriority(700)]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		private static void InitalizeServerObject()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			if (!((Object)(object)netObject != (Object)null))
			{
				netObject = new GameObject("NetObject");
				Object.DontDestroyOnLoad((Object)(object)netObject);
				netObject.AddComponent<Net>();
				netObject.AddComponent<NetworkObject>();
				NetworkManager.Singleton.AddNetworkPrefab(netObject);
			}
		}

		[HarmonyPrefix]
		[HarmonyPriority(700)]
		[HarmonyPatch(typeof(Terminal), "Start")]
		private static void SpawnServerObject()
		{
			if (Object.FindObjectOfType<NetworkManager>().IsServer)
			{
				GameObject val = Object.Instantiate<GameObject>(netObject);
				val.GetComponent<NetworkObject>().Spawn(false);
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void TimeOffServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1229807651u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1229807651u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					TimeOffClientRpc();
				}
			}
		}

		[ClientRpc]
		public void TimeOffClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2721403131u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2721403131u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					TimeOfDay instance = TimeOfDay.Instance;
					instance.timeUntilDeadline -= TimeOfDay.Instance.totalTime;
					TimeOfDay.Instance.UpdateProfitQuotaCurrentTime();
					int daysUntilDeadline = TimeOfDay.Instance.daysUntilDeadline;
					HUDManager.Instance.DisplayDaysLeft(daysUntilDeadline);
					TimeOfDay.Instance.OnDayChanged();
				}
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(1229807651u, new RpcReceiveHandler(__rpc_handler_1229807651), "TimeOffServerRpc");
			((NetworkBehaviour)this).__registerRpc(2721403131u, new RpcReceiveHandler(__rpc_handler_2721403131), "TimeOffClientRpc");
			((NetworkBehaviour)this).__initializeRpcs();
		}

		private static void __rpc_handler_1229807651(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((Net)(object)target).TimeOffServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2721403131(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((Net)(object)target).TimeOffClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "Net";
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace NoTimeOff.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}