Decompiled source of Employees Always Work v2.0.0

Employee Always Work & Plants Always Grow v2.0.0.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using EmployeeAlwaysWork;
using HarmonyLib;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Employees;
using Il2CppScheduleOne.GameTime;
using Il2CppScheduleOne.Growing;
using MelonLoader;
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: MelonInfo(typeof(EmployeeAlwaysWorkMod), "Employee Always Work & Plants Always Grow", "2.0.0", "Leclowndu93150", null)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ClassLibrary2")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ClassLibrary2")]
[assembly: AssemblyTitle("ClassLibrary2")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace EmployeeAlwaysWork
{
	public class EmployeeAlwaysWorkMod : MelonMod
	{
		private static bool _isPatchApplied;

		private static Harmony _harmonyInstance;

		public const int WAGE_TIMER_MINUTES = 24;

		public override void OnInitializeMelon()
		{
			((MelonEventBase<LemonAction<int, string>>)(object)MelonEvents.OnSceneWasLoaded).Subscribe((LemonAction<int, string>)OnSceneLoaded, 0, false);
		}

		private void OnSceneLoaded(int buildIndex, string sceneName)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			if (sceneName == "Main" && !_isPatchApplied)
			{
				try
				{
					_harmonyInstance = new Harmony("EmployeeAlwaysWorkMod");
					_harmonyInstance.PatchAll();
					_isPatchApplied = true;
					((MelonBase)this).LoggerInstance.Msg("Employee Always Work & Plants Always Grow mod successfully initialized in scene: " + sceneName);
				}
				catch (Exception ex)
				{
					((MelonBase)this).LoggerInstance.Error("Failed to patch mod: " + ex.Message);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Employee), "CanWork")]
	public static class EmployeeCanWorkPatch
	{
		[HarmonyPrefix]
		public static bool Prefix(Employee __instance, ref bool __result)
		{
			TimeManager instance = NetworkSingleton<TimeManager>.Instance;
			if ((Object)(object)instance != (Object)null && instance.IsEndOfDay)
			{
				bool flag = (Object)(object)__instance.GetBed() != (Object)null;
				bool paidForToday = __instance.PaidForToday;
				__result = flag && paidForToday;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Employee), "UpdateBehaviour")]
	public static class EmployeeUpdateBehaviourPatch
	{
		public static Dictionary<Employee, DateTime> _lastEndOfDayCheckTime = new Dictionary<Employee, DateTime>();

		[HarmonyPrefix]
		public static bool Prefix(Employee __instance)
		{
			TimeManager instance = NetworkSingleton<TimeManager>.Instance;
			if ((Object)(object)instance != (Object)null && instance.IsEndOfDay)
			{
				if (__instance.Fired)
				{
					return true;
				}
				if (!_lastEndOfDayCheckTime.TryGetValue(__instance, out var value))
				{
					value = DateTime.Now;
					_lastEndOfDayCheckTime[__instance] = value;
				}
				if ((DateTime.Now - value).TotalMinutes >= 24.0)
				{
					_lastEndOfDayCheckTime[__instance] = DateTime.Now;
					__instance.PaidForToday = false;
				}
				bool flag = (Object)(object)__instance.GetBed() != (Object)null;
				bool paidForToday = __instance.PaidForToday;
				if (!flag)
				{
					__instance.SubmitNoWorkReason("I haven't been assigned a bed", "You can use your management clipboard to assign me a bed.", 0);
					__instance.SetIdle(true);
					return false;
				}
				if (!paidForToday)
				{
					if (!__instance.IsPayAvailable())
					{
						__instance.SubmitNoWorkReason("I haven't been paid yet", "You can place cash in my briefcase on my bed.", 0);
						__instance.SetIdle(true);
						return false;
					}
					__instance.RemoveDailyWage();
					__instance.SetIsPaid();
					__instance.SetIdle(false);
				}
				else
				{
					__instance.SetIdle(false);
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Employee), "OnDestroy")]
	public static class EmployeeOnDestroyPatch
	{
		[HarmonyPostfix]
		public static void Postfix(Employee __instance)
		{
			if (EmployeeUpdateBehaviourPatch._lastEndOfDayCheckTime.ContainsKey(__instance))
			{
				EmployeeUpdateBehaviourPatch._lastEndOfDayCheckTime.Remove(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(Plant), "MinPass")]
	public static class PlantMinPassPatch
	{
		[HarmonyPrefix]
		public static bool Prefix(Plant __instance)
		{
			if (__instance.NormalizedGrowthProgress >= 1f)
			{
				return false;
			}
			TimeManager instance = NetworkSingleton<TimeManager>.Instance;
			if ((Object)(object)instance == (Object)null || !instance.IsEndOfDay)
			{
				return true;
			}
			float num = 1f / ((float)__instance.GrowthTime * 60f);
			num *= __instance.Pot.GetAdditiveGrowthMultiplier();
			float num2 = default(float);
			num *= __instance.Pot.GetAverageLightExposure(ref num2);
			num *= __instance.Pot.GrowSpeedMultiplier;
			num *= num2;
			if (__instance.Pot.NormalizedWaterLevel <= 0f || __instance.Pot.NormalizedWaterLevel > 1f)
			{
				num *= 0f;
			}
			__instance.SetNormalizedGrowthProgress(__instance.NormalizedGrowthProgress + num);
			return false;
		}
	}
}