Decompiled source of More Employees v1.1.0

MoreEmployees.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppScheduleOne.Employees;
using Il2CppScheduleOne.Property;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(MoreEmployeesMod), "MoreEmployees", "1.1.0", "HontoRon", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MoreEmployees")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MoreEmployees")]
[assembly: AssemblyTitle("MoreEmployees")]
[assembly: AssemblyVersion("1.0.0.0")]
[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;
		}
	}
}
public class MoreEmployeesMod : MelonMod
{
	public static int manorEmployees = 12;

	public static int barnEmployees = 10;

	public static int dockEmployees = 10;

	public static int sweatshopEmployees = 1;

	public static int bungalowEmployees = 5;

	public static int motelEmployees = 0;

	public static int storageUnitEmployees = 3;

	private static string _configPath = Path.Combine(MelonEnvironment.UserDataDirectory, "MoreEmployees.cfg");

	public override void OnInitializeMelon()
	{
		LoadConfig();
		((MelonBase)this).HarmonyInstance.PatchAll();
		MelonLogger.Msg("MoreEmployees loaded.");
	}

	private void LoadConfig()
	{
		try
		{
			if (!File.Exists(_configPath))
			{
				SaveConfig();
				return;
			}
			string[] array = File.ReadAllLines(_configPath);
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (string.IsNullOrEmpty(text) || text.StartsWith("#") || text.StartsWith(";") || (text.StartsWith("[") && text.EndsWith("]")))
				{
					continue;
				}
				int num = text.IndexOf('=');
				if (num > 0)
				{
					string text2 = text.Substring(0, num).Trim().ToLowerInvariant();
					string text3 = text.Substring(num + 1).Trim();
					int num2 = text3.IndexOf('#');
					if (num2 >= 0)
					{
						text3 = text3.Substring(0, num2).Trim();
					}
					int num3 = text3.IndexOf(';');
					if (num3 >= 0)
					{
						text3 = text3.Substring(0, num3).Trim();
					}
					if (text3.Length >= 2 && text3.StartsWith("\"") && text3.EndsWith("\""))
					{
						text3 = text3.Substring(1, text3.Length - 2).Trim();
					}
					switch (text2)
					{
					case "barnemployees":
						barnEmployees = ParseInt(text3, barnEmployees);
						break;
					case "dockemployees":
						dockEmployees = ParseInt(text3, dockEmployees);
						break;
					case "sweatshopemployees":
						sweatshopEmployees = ParseInt(text3, sweatshopEmployees);
						break;
					case "bungalowemployees":
						bungalowEmployees = ParseInt(text3, bungalowEmployees);
						break;
					case "motelemployees":
						motelEmployees = ParseInt(text3, motelEmployees);
						break;
					case "storageunitemployees":
						storageUnitEmployees = ParseInt(text3, storageUnitEmployees);
						break;
					case "manoremployees":
						manorEmployees = ParseInt(text3, manorEmployees);
						break;
					}
				}
			}
			MelonLogger.Msg($"Limits: Barn={barnEmployees}, Dock={dockEmployees}, Sweatshop={sweatshopEmployees}, Bungalow={bungalowEmployees}, Motel={motelEmployees}, StorageUnit={storageUnitEmployees}, Manor={manorEmployees}");
			MelonLogger.Msg("MoreEmployees config loaded from " + _configPath);
		}
		catch (Exception ex)
		{
			MelonLogger.Error("MoreEmployees LoadConfig failed: " + ex.Message);
		}
	}

	private void SaveConfig()
	{
		try
		{
			string contents = "[More Employees]\n# Default = 10\nbarnEmployees = " + barnEmployees + "\n# Default = 10\ndockEmployees = " + dockEmployees + "\n# Default = 1\nsweatshopEmployees = " + sweatshopEmployees + "\n# Default = 5\nbungalowEmployees = " + bungalowEmployees + "\n# Default = 0\nmotelEmployees = " + motelEmployees + "\n# Default = 3\nstorageUnitEmployees = " + storageUnitEmployees + "\n# Default = 12\nmanorEmployees = " + manorEmployees + "\n";
			File.WriteAllText(_configPath, contents);
			MelonLogger.Msg("MoreEmployees config created at " + _configPath);
		}
		catch (Exception ex)
		{
			MelonLogger.Error("MoreEmployees SaveConfig failed: " + ex.Message);
		}
	}

	private int ParseInt(string s, int fallback)
	{
		try
		{
			if (int.TryParse(s, out var result))
			{
				return result;
			}
		}
		catch
		{
		}
		return fallback;
	}
}
[HarmonyPatch(typeof(Employee))]
public class MoreEmployeesPatch
{
	private static bool applied;

	[HarmonyPrefix]
	[HarmonyPatch("AssignProperty")]
	private static void Prefix(Employee __instance, Property __0)
	{
		if (applied)
		{
			return;
		}
		applied = true;
		try
		{
			ApplyCapacities();
		}
		catch (Exception ex)
		{
			MelonLogger.Error("MoreEmployees ApplyCapacities failed: " + ex.Message);
		}
	}

	private static void ApplyCapacities()
	{
		SetCapacityByGameObjectName("Barn", MoreEmployeesMod.barnEmployees);
		SetCapacityByGameObjectName("DocksWarehouse", MoreEmployeesMod.dockEmployees);
		GameObject val = GameObject.Find("@Properties");
		if ((Object)(object)val == (Object)null)
		{
			MelonLogger.Error("MoreEmployees: @Properties not found.");
			return;
		}
		SetCapacityByChildName(val.transform, "Sweatshop", MoreEmployeesMod.sweatshopEmployees);
		SetCapacityByChildName(val.transform, "Bungalow", MoreEmployeesMod.bungalowEmployees);
		SetCapacityByChildName(val.transform, "MotelRoom", MoreEmployeesMod.motelEmployees);
		SetCapacityByChildName(val.transform, "StorageUnit", MoreEmployeesMod.storageUnitEmployees);
		SetCapacityByChildName(val.transform, "Manor", MoreEmployeesMod.manorEmployees);
		MelonLogger.Msg("MoreEmployees: employee capacities applied.");
	}

	private static void SetCapacityByGameObjectName(string goName, int cap)
	{
		GameObject val = GameObject.Find(goName);
		if (!((Object)(object)val == (Object)null))
		{
			Property component = val.GetComponent<Property>();
			if (!((Object)(object)component == (Object)null) && component.EmployeeCapacity != cap)
			{
				component.EmployeeCapacity = cap;
			}
		}
	}

	private static void SetCapacityByChildName(Transform parent, string childName, int cap)
	{
		Transform val = parent.Find(childName);
		if (!((Object)(object)val == (Object)null))
		{
			Property component = ((Component)val).GetComponent<Property>();
			if ((Object)(object)component != (Object)null && component.EmployeeCapacity != cap)
			{
				component.EmployeeCapacity = cap;
			}
		}
	}
}