Decompiled source of NoTimeOff v0.1.0

NoTimeOff.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NoTimeOff;
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 planetName = "";

		public static void SetPreviousPlanet()
		{
			planetName = StartOfRound.Instance.currentLevel.PlanetName;
			Logger.Info("Planet Name set to: " + planetName);
		}

		[HarmonyPrefix]
		[HarmonyPriority(700)]
		[HarmonyPatch(typeof(StartOfRound), "ShipLeave")]
		public static void ShipLeave()
		{
			SelectableLevel currentLevel = StartOfRound.Instance.currentLevel;
			SetPreviousPlanet();
		}

		[HarmonyPostfix]
		[HarmonyPriority(700)]
		[HarmonyPatch(typeof(StartOfRound), "ShipHasLeft")]
		public static void ShipHasLeft()
		{
			Logger.Info("Current Planet : " + StartOfRound.Instance.currentLevel.PlanetName);
			if (NetworkManager.Singleton.IsHost)
			{
				Logger.Info("Server Detected");
				Net.Instance.TimeOffServerRpc();
			}
		}
	}
	[BepInPlugin("NoTimeOff", "NoTimeOff", "1.0.0")]
	internal class Plugin : BaseUnityPlugin
	{
		public static GameObject netObject;

		internal static Plugin Instance { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger.SetLogger(((BaseUnityPlugin)this).Logger);
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Patch();
			Logger.Info("NoTimeOff v1.0.0 has loaded!");
			NetcodePatcherAwake();
		}

		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("NoTimeOff");
			}
			Logger.Debug("Patching...");
			Harmony.PatchAll();
			Logger.Debug("Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.Debug("Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.Debug("Finished unpatching!");
		}

		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
{
	public static class Logger
	{
		private static ManualLogSource? log;

		public static void SetLogger(ManualLogSource logSource)
		{
			log = logSource;
		}

		private static void Log(LogLevel level, object? content)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource? obj = log;
			if (obj != null)
			{
				obj.Log(level, content ?? "null");
			}
		}

		public static void Trace(object? content)
		{
			Log((LogLevel)8, content);
		}

		public static void Debug(object? content)
		{
			Log((LogLevel)32, content);
		}

		public static void Info(object? content)
		{
			Log((LogLevel)16, content);
		}

		public static void Warn(object? content)
		{
			Log((LogLevel)4, content);
		}

		public static void Error(object? content)
		{
			Log((LogLevel)2, content);
		}
	}
	[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();
		}

		[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();
				}
			}
		}

		[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);
			}
		}

		[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)
			{
				return;
			}
			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;
				if (PatchCompanyMoon.planetName == "71 Gordion")
				{
					TimeOfDay instance = TimeOfDay.Instance;
					instance.timeUntilDeadline -= TimeOfDay.Instance.totalTime;
					TimeOfDay.Instance.UpdateProfitQuotaCurrentTime();
					int num = (int)(TimeOfDay.Instance.timeUntilDeadline / TimeOfDay.Instance.totalTime);
					HUDManager.Instance.DisplayDaysLeft(num);
					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 NoTimeOffAssets
{
	[HarmonyPatch]
	public class Assets
	{
		internal static AssetBundle bundle;

		public static bool ReadSettingEarly(string filePath, string settingName)
		{
			try
			{
				if (!File.Exists(filePath))
				{
					return false;
				}
				string input = File.ReadAllText(filePath);
				string pattern = Regex.Escape(settingName) + "\\s*=\\s*(true|false)";
				Match match = Regex.Match(input, pattern, RegexOptions.IgnoreCase);
				if (match.Success)
				{
					string value = match.Groups[1].Value;
					return bool.Parse(value);
				}
				return false;
			}
			catch (Exception)
			{
				return false;
			}
		}

		internal static void Load()
		{
			bundle = LoadAssetBundleFile("bundle");
		}

		private static AssetBundle LoadAssetBundleFile(string fileName)
		{
			try
			{
				string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Info.Location);
				string text = Path.Combine(directoryName, fileName);
				return AssetBundle.LoadFromFile(text);
			}
			catch (Exception arg)
			{
				Logger.Warn($"Failed to load AssetBundle \"{fileName}\". {arg}");
			}
			return null;
		}

		internal static AssetBundle LoadAssetBundle(string fileName)
		{
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				using Stream stream = executingAssembly.GetManifestResourceStream(fileName);
				return AssetBundle.LoadFromStream(stream);
			}
			catch (Exception ex)
			{
				Logger.Error("An error occurred while loading the asset bundle: " + ex.Message);
			}
			return null;
		}

		private static void RegisterNetworkPrefabs(params GameObject[] objects)
		{
			foreach (GameObject val in objects)
			{
				NetworkManager.Singleton.AddNetworkPrefab(val);
			}
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace NoTimeOff.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}