Decompiled source of More Employees v1.0.0

MoreEmployees.dll

Decompiled 14 hours 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.0.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 = 15;

	public static int barnEmployees = 15;

	public static int dockEmployees = 15;

	public static int sweatshopEmployees = 2;

	public static int bungalowEmployees = 5;

	public static int motelEmployees = 1;

	public static int storageUnitEmployees = 5;

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

	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);
			foreach (string text in array)
			{
				if (text.StartsWith("barnEmployees="))
				{
					barnEmployees = ParseRightInt(text, barnEmployees);
				}
				else if (text.StartsWith("dockEmployees="))
				{
					dockEmployees = ParseRightInt(text, dockEmployees);
				}
				else if (text.StartsWith("sweatshopEmployees="))
				{
					sweatshopEmployees = ParseRightInt(text, sweatshopEmployees);
				}
				else if (text.StartsWith("bungalowEmployees="))
				{
					bungalowEmployees = ParseRightInt(text, bungalowEmployees);
				}
				else if (text.StartsWith("motelEmployees="))
				{
					motelEmployees = ParseRightInt(text, motelEmployees);
				}
				else if (text.StartsWith("storageUnitEmployees="))
				{
					storageUnitEmployees = ParseRightInt(text, storageUnitEmployees);
				}
				else if (text.StartsWith("manorEmployees="))
				{
					manorEmployees = ParseRightInt(text, manorEmployees);
				}
			}
			MelonLogger.Msg("MoreEmployees config loaded from " + _configPath);
		}
		catch (Exception ex)
		{
			MelonLogger.Error("MoreEmployees LoadConfig failed: " + ex.Message);
		}
	}

	private void SaveConfig()
	{
		try
		{
			string contents = "barnEmployees=" + barnEmployees + "\ndockEmployees=" + dockEmployees + "\nsweatshopEmployees=" + sweatshopEmployees + "\nbungalowEmployees=" + bungalowEmployees + "\nmotelEmployees=" + motelEmployees + "\nstorageUnitEmployees=" + storageUnitEmployees + "\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 ParseRightInt(string line, int fallback)
	{
		try
		{
			string[] array = line.Split(new char[1] { '=' }, 2);
			if (array.Length == 2)
			{
				return int.Parse(array[1]);
			}
		}
		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;
			}
		}
	}
}