Decompiled source of LateShiftIL2CPP v1.0.6

Mods\LateShiftIL2CPP.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using Il2CppFishNet;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Dialogue;
using Il2CppScheduleOne.Employees;
using Il2CppScheduleOne.GameTime;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Management;
using Il2CppScheduleOne.Money;
using Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.NPCs.Behaviour;
using Il2CppScheduleOne.ObjectScripts;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using LateShift;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(LateShiftMod), "LateShift", "1.0.6", "lasersquid", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("LateShiftIL2CPP")]
[assembly: AssemblyConfiguration("IL2CPP")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyInformationalVersion("1.0.6+edef2efacb56f1825679d1012dc1c7edc7ecfd7d")]
[assembly: AssemblyProduct("LateShiftIL2CPP")]
[assembly: AssemblyTitle("LateShiftIL2CPP")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.6.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LateShift
{
	public class LateShiftMod : MelonMod
	{
		public MelonPreferences_Category melonPrefs;

		public Harmony harmony = new Harmony("com.lasersquid.lateshift");

		public override void OnInitializeMelon()
		{
			CreateMelonPreferences();
			Utils.SetMod(this);
			((MelonBase)this).LoggerInstance.Msg("Initialized.");
		}

		private void CreateMelonPreferences()
		{
			melonPrefs = MelonPreferences.CreateCategory("LateShift");
			melonPrefs.SetFilePath("UserData/LateShift.cfg", true, false);
			melonPrefs.CreateEntry<bool>("employeesAlwaysWork", true, "Employees always work", "Employees keep working at 4am", false, false, (ValueValidator)null, (string)null);
			melonPrefs.CreateEntry<bool>("workWithoutBeds", true, "Employees work without beds", "Employees work without beds or lockers", false, false, (ValueValidator)null, (string)null);
			melonPrefs.CreateEntry<bool>("payEmployeesFromBank", false, "Autopay employees from bank account", "Autopay employees from bank account if true; otherwise pay with cash", false, false, (ValueValidator)null, (string)null);
			melonPrefs.SaveToFile(false);
		}
	}
	public static class Utils
	{
		public class UnityObjectComparer : IEqualityComparer<Object>
		{
			public bool Equals(Object a, Object b)
			{
				return a.GetInstanceID() == b.GetInstanceID();
			}

			public int GetHashCode(Object item)
			{
				return item.GetInstanceID();
			}
		}

		private static LateShiftMod Mod;

		public static void PrintException(Exception e)
		{
			Warn("Exception: " + e.GetType().Name + " - " + e.Message);
			Warn("Source: " + e.Source);
			Warn(e.StackTrace ?? "");
			if (e.InnerException != null)
			{
				Warn("Inner exception: " + e.InnerException.GetType().Name + " - " + e.InnerException.Message);
				Warn("Source: " + e.InnerException.Source);
				Warn(e.InnerException.StackTrace ?? "");
				if (e.InnerException.InnerException != null)
				{
					Warn("Inner inner exception: " + e.InnerException.InnerException.GetType().Name + " - " + e.InnerException.InnerException.Message);
					Warn("Source: " + e.InnerException.InnerException.Source);
					Warn(e.InnerException.InnerException.StackTrace ?? "");
				}
			}
		}

		public static Treturn GetField<Ttarget, Treturn>(string fieldName, object target) where Treturn : class
		{
			return CastTo<Treturn>(GetField<Ttarget>(fieldName, target));
		}

		public static object GetField<Ttarget>(string fieldName, object target)
		{
			return AccessTools.Property(typeof(Ttarget), fieldName).GetValue(target);
		}

		public static void SetField<Ttarget>(string fieldName, object target, object value)
		{
			AccessTools.Property(typeof(Ttarget), fieldName).SetValue(target, value);
		}

		public static Treturn GetProperty<Ttarget, Treturn>(string fieldName, object target) where Treturn : class
		{
			return CastTo<Treturn>(GetProperty<Ttarget>(fieldName, target));
		}

		public static object GetProperty<Ttarget>(string fieldName, object target)
		{
			return AccessTools.Property(typeof(Ttarget), fieldName).GetValue(target);
		}

		public static void SetProperty<Ttarget>(string fieldName, object target, object value)
		{
			AccessTools.Property(typeof(Ttarget), fieldName).SetValue(target, value);
		}

		public static Treturn CallMethod<Ttarget, Treturn>(string methodName, object target) where Treturn : class
		{
			return CastTo<Treturn>(CallMethod<Ttarget>(methodName, target, Array.Empty<object>()));
		}

		public static Treturn CallMethod<Ttarget, Treturn>(string methodName, object target, object[] args) where Treturn : class
		{
			return CastTo<Treturn>(CallMethod<Ttarget>(methodName, target, args));
		}

		public static Treturn CallMethod<Ttarget, Treturn>(string methodName, Type[] argTypes, object target, object[] args) where Treturn : class
		{
			return CastTo<Treturn>(CallMethod<Ttarget>(methodName, argTypes, target, args));
		}

		public static object CallMethod<Ttarget>(string methodName, object target)
		{
			return AccessTools.Method(typeof(Ttarget), methodName, (Type[])null, (Type[])null).Invoke(target, Array.Empty<object>());
		}

		public static object CallMethod<Ttarget>(string methodName, object target, object[] args)
		{
			return AccessTools.Method(typeof(Ttarget), methodName, (Type[])null, (Type[])null).Invoke(target, args);
		}

		public static object CallMethod<Ttarget>(string methodName, Type[] argTypes, object target, object[] args)
		{
			return AccessTools.Method(typeof(Ttarget), methodName, argTypes, (Type[])null).Invoke(target, args);
		}

		public static void SetMod(LateShiftMod mod)
		{
			Mod = mod;
		}

		public static T CastTo<T>(object o) where T : class
		{
			if (!(o is T result))
			{
				return null;
			}
			return result;
		}

		public static bool Is<T>(object o)
		{
			return o is T;
		}

		public static T CastTo<T>(Il2CppObjectBase o) where T : Il2CppObjectBase
		{
			return o.TryCast<T>();
		}

		public static bool Is<T>(Il2CppObjectBase o) where T : Il2CppObjectBase
		{
			return o.TryCast<T>() != null;
		}

		public static UnityAction ToUnityAction(Action action)
		{
			return DelegateSupport.ConvertDelegate<UnityAction>((Delegate)action);
		}

		public static UnityAction<T> ToUnityAction<T>(Action<T> action)
		{
			return DelegateSupport.ConvertDelegate<UnityAction<T>>((Delegate)action);
		}

		public static T ToInterface<T>(Object o) where T : Il2CppObjectBase
		{
			return Utils.CastTo<T>(Activator.CreateInstance(typeof(T), ((Il2CppObjectBase)o).Pointer));
		}

		public static void Log(string message)
		{
			((MelonBase)Mod).LoggerInstance.Msg(message);
		}

		public static void Warn(string message)
		{
			((MelonBase)Mod).LoggerInstance.Warning(message);
		}

		public static MelonPreferences_Category GetMelonPrefs()
		{
			return Mod.melonPrefs;
		}

		public static T GetMelonPrefEntry<T>(string entryName)
		{
			return GetMelonPrefs().GetEntry<T>(entryName).Value;
		}

		public static void Debug(string message)
		{
			if (GetMelonPrefEntry<bool>("debugLogs"))
			{
				((MelonBase)Mod).LoggerInstance.Msg("DEBUG: " + message);
			}
		}

		public static void VerboseLog(string message)
		{
			if (GetMelonPrefEntry<bool>("verboseLogs"))
			{
				((MelonBase)Mod).LoggerInstance.Msg(message);
			}
		}
	}
	[HarmonyPatch]
	public class NoBedsPatches
	{
		[HarmonyPatch(typeof(Employee), "IsPayAvailable")]
		[HarmonyPrefix]
		public static bool IsPayAvailablePrefix(Employee __instance, ref bool __result)
		{
			MoneyManager instance = NetworkSingleton<MoneyManager>.Instance;
			EmployeeHome home = __instance.GetHome();
			if (Utils.GetMelonPrefEntry<bool>("payEmployeesFromBank"))
			{
				__result = instance.onlineBalance >= __instance.DailyWage;
				return false;
			}
			if (Utils.GetMelonPrefEntry<bool>("workWithoutBeds"))
			{
				if ((Object)(object)home == (Object)null)
				{
					__result = instance.cashBalance >= __instance.DailyWage;
				}
				else
				{
					__result = home.GetCashSum() >= __instance.DailyWage;
				}
			}
			else if ((Object)(object)home == (Object)null)
			{
				__result = false;
			}
			else
			{
				__result = home.GetCashSum() >= __instance.DailyWage;
			}
			return false;
		}

		[HarmonyPatch(typeof(Employee), "RemoveDailyWage")]
		[HarmonyPrefix]
		public static bool RemoveDailyWagePrefix(Employee __instance)
		{
			if (!InstanceFinder.IsServer)
			{
				return false;
			}
			MoneyManager instance = NetworkSingleton<MoneyManager>.Instance;
			EmployeeHome home = __instance.GetHome();
			if (Utils.GetMelonPrefEntry<bool>("payEmployeesFromBank"))
			{
				if (instance.onlineBalance >= __instance.DailyWage)
				{
					instance.CreateOnlineTransaction("Employee Pay", 0f - __instance.DailyWage, 1f, ((NPC)__instance).fullName + ", employeetype, location");
				}
			}
			else if (Utils.GetMelonPrefEntry<bool>("workWithoutBeds"))
			{
				if ((Object)(object)home == (Object)null)
				{
					if (instance.cashBalance >= __instance.DailyWage)
					{
						instance.ChangeCashBalance(0f - __instance.DailyWage, true, false);
					}
				}
				else if (home.GetCashSum() >= __instance.DailyWage)
				{
					instance.ChangeCashBalance(0f - __instance.DailyWage, true, false);
					home.RemoveCash(__instance.DailyWage);
				}
			}
			else
			{
				if ((Object)(object)home == (Object)null)
				{
					return false;
				}
				if (home.GetCashSum() >= __instance.DailyWage)
				{
					instance.ChangeCashBalance(0f - __instance.DailyWage, true, false);
					home.RemoveCash(__instance.DailyWage);
				}
			}
			return false;
		}

		[HarmonyPatch(typeof(Employee), "GetWorkIssue")]
		[HarmonyPrefix]
		public static bool GetWorkIssuePrefix(Employee __instance, ref bool __result, ref DialogueContainer notWorkingReason)
		{
			if ((Object)(object)__instance.GetHome() == (Object)null && !Utils.GetMelonPrefEntry<bool>("workWithoutBeds"))
			{
				notWorkingReason = __instance.BedNotAssignedDialogue;
				__result = true;
				return false;
			}
			if (!__instance.PaidForToday)
			{
				notWorkingReason = __instance.NotPaidDialogue;
				__result = true;
				return false;
			}
			List<NoWorkReason> field = Utils.GetField<Employee, List<NoWorkReason>>("WorkIssues", __instance);
			if (__instance.TimeSinceLastWorked >= 5 && field.Count > 0)
			{
				notWorkingReason = Object.Instantiate<DialogueContainer>(__instance.WorkIssueDialogueTemplate);
				notWorkingReason.GetDialogueNodeByLabel("ENTRY").DialogueText = field[0].Reason;
				if (!string.IsNullOrEmpty(field[0].Fix))
				{
					notWorkingReason.GetDialogueNodeByLabel("FIX").DialogueText = field[0].Fix;
				}
				else
				{
					notWorkingReason.GetDialogueNodeByLabel("ENTRY").choices = Il2CppReferenceArray<DialogueChoiceData>.op_Implicit((DialogueChoiceData[])(object)new DialogueChoiceData[0]);
				}
				__result = true;
				return false;
			}
			notWorkingReason = null;
			__result = false;
			return false;
		}

		[HarmonyPatch(typeof(Employee), "CanWork")]
		[HarmonyPostfix]
		public static void CanWorkPostfix(Employee __instance, ref bool __result)
		{
			bool flag = (Object)(object)__instance.GetHome() != (Object)null;
			bool melonPrefEntry = Utils.GetMelonPrefEntry<bool>("workWithoutBeds");
			bool melonPrefEntry2 = Utils.GetMelonPrefEntry<bool>("employeesAlwaysWork");
			bool isEndOfDay = NetworkSingleton<TimeManager>.Instance.IsEndOfDay;
			bool paidForToday = __instance.PaidForToday;
			if (!__result && !flag && paidForToday && !isEndOfDay && melonPrefEntry)
			{
				__result = true;
			}
			if (!__result && flag && paidForToday && isEndOfDay && melonPrefEntry2)
			{
				__result = true;
			}
			if (!__result && !flag && paidForToday && isEndOfDay && melonPrefEntry && melonPrefEntry2)
			{
				__result = true;
			}
		}

		[HarmonyPatch(typeof(Employee), "UpdateBehaviour")]
		[HarmonyPrefix]
		public static bool UpdateBehaviourPrefix(Employee __instance)
		{
			bool melonPrefEntry = Utils.GetMelonPrefEntry<bool>("workWithoutBeds");
			bool melonPrefEntry2 = Utils.GetMelonPrefEntry<bool>("employeesAlwaysWork");
			if (__instance.Fired)
			{
				return false;
			}
			if ((Object)(object)((NPC)__instance).Behaviour.activeBehaviour == (Object)null || (Object)(object)((NPC)__instance).Behaviour.activeBehaviour == (Object)(object)__instance.WaitOutside)
			{
				bool flag = false;
				bool flag2 = false;
				if ((Object)(object)__instance.GetHome() == (Object)null && !melonPrefEntry)
				{
					flag = true;
					__instance.SubmitNoWorkReason("I haven't been assigned a locker", "You can use your management clipboard to assign me a locker.", 0);
				}
				else if (NetworkSingleton<TimeManager>.Instance.IsEndOfDay && !melonPrefEntry2)
				{
					flag = true;
					__instance.SubmitNoWorkReason("Sorry boss, my shift ends at 4AM.", string.Empty, 0);
				}
				else if (!__instance.PaidForToday)
				{
					if (__instance.IsPayAvailable())
					{
						flag2 = true;
					}
					else
					{
						flag = true;
						__instance.SubmitNoWorkReason("I haven't been paid yet", "You can place cash in my locker.", 0);
					}
				}
				if (flag)
				{
					Utils.CallMethod<Employee>("SetWaitOutside", __instance, new object[1] { true });
					return false;
				}
				if (InstanceFinder.IsServer && flag2 && __instance.IsPayAvailable())
				{
					__instance.RemoveDailyWage();
					__instance.SetIsPaid();
				}
			}
			return false;
		}

		[HarmonyPatch(typeof(Packager), "UpdateBehaviour")]
		[HarmonyPrefix]
		public static bool PackagerUpdateBehaviourPrefix(Packager __instance)
		{
			UpdateBehaviourPrefix((Employee)(object)__instance);
			if (((Behaviour)__instance.PackagingBehaviour).Active)
			{
				Utils.CallMethod<Packager>("MarkIsWorking", __instance);
				return false;
			}
			if (((Behaviour)((Employee)__instance).MoveItemBehaviour).Active)
			{
				Utils.CallMethod<Packager>("MarkIsWorking", __instance);
				return false;
			}
			if (((Employee)__instance).Fired)
			{
				Utils.CallMethod<Packager>("LeavePropertyAndDespawn", __instance);
				return false;
			}
			if (!(bool)Utils.CallMethod<Packager>("CanWork", __instance))
			{
				return false;
			}
			PackagerConfiguration property = Utils.GetProperty<Packager, PackagerConfiguration>("configuration", __instance);
			if (property.AssignedStationCount + property.Routes.Routes.Count == 0)
			{
				((Employee)__instance).SubmitNoWorkReason("I haven't been assigned to any stations or routes.", "You can use your management clipboards to assign stations or routes to me.", 0);
				((Employee)__instance).SetIdle(true);
				return false;
			}
			if (!InstanceFinder.IsServer)
			{
				return false;
			}
			PackagingStation val = Utils.CallMethod<Packager, PackagingStation>("GetStationToAttend", __instance);
			if ((Object)(object)val != (Object)null)
			{
				Utils.CallMethod<Packager>("StartPackaging", __instance, new object[1] { val });
				return false;
			}
			BrickPress val2 = Utils.CallMethod<Packager, BrickPress>("GetBrickPress", __instance);
			if ((Object)(object)val2 != (Object)null)
			{
				Utils.CallMethod<Packager>("StartPress", __instance, new object[1] { val2 });
				return false;
			}
			PackagingStation val3 = Utils.CallMethod<Packager, PackagingStation>("GetStationMoveItems", __instance);
			if ((Object)(object)val3 != (Object)null)
			{
				Utils.CallMethod<Packager>("StartMoveItem", new Type[1] { typeof(PackagingStation) }, __instance, new object[1] { val3 });
				return false;
			}
			BrickPress val4 = Utils.CallMethod<Packager, BrickPress>("GetBrickPressMoveItems", __instance);
			if ((Object)(object)val4 != (Object)null)
			{
				Utils.CallMethod<Packager>("StartMoveItem", new Type[1] { typeof(BrickPress) }, __instance, new object[1] { val4 });
				return false;
			}
			object[] array = new object[1];
			AdvancedTransitRoute val5 = Utils.CallMethod<Packager, AdvancedTransitRoute>("GetTransitRouteReady", __instance, array);
			ItemInstance val6 = Utils.CastTo<ItemInstance>(array[0]);
			if (val5 != null)
			{
				((Employee)__instance).MoveItemBehaviour.Initialize((TransitRoute)(object)val5, val6, val6.Quantity, false);
				((Behaviour)((Employee)__instance).MoveItemBehaviour).Enable_Networked();
				return false;
			}
			((Employee)__instance).SubmitNoWorkReason("There's nothing for me to do right now.", "I need one of my assigned stations to have enough product and packaging to get to work.", 0);
			((Employee)__instance).SetIdle(true);
			return false;
		}
	}
}