Decompiled source of WarehousePlus v1.0.1

Mods/WarehousePlus.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Doors;
using Il2CppScheduleOne.Levelling;
using Il2CppScheduleOne.Map;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using WarehousePlus;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(WarehousePlusMod), "WarehousePlus", "1.0.1", "Blazinggggg", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("WarehousePlus")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WarehousePlus")]
[assembly: AssemblyTitle("WarehousePlus")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 WarehousePlus
{
	public static class Config
	{
		private static MelonPreferences_Category _cat;

		private static MelonPreferences_Entry<bool> _alwaysOpen;

		private static MelonPreferences_Entry<int> _openTime;

		private static MelonPreferences_Entry<int> _closeTime;

		private static MelonPreferences_Entry<string> _requiredRank;

		private static MelonPreferences_Entry<int> _requiredTier;

		public static bool AlwaysOpen => _alwaysOpen.Value;

		public static int OpenTime => _openTime.Value;

		public static int CloseTime => _closeTime.Value;

		public static string RequiredRank => _requiredRank.Value;

		public static int RequiredTier => _requiredTier.Value;

		public static void Init()
		{
			_cat = MelonPreferences.CreateCategory("WarehousePlus", "Warehouse Plus");
			_alwaysOpen = _cat.CreateEntry<bool>("AlwaysOpen", false, "Always Open", "When true the warehouse stays open 24/7, ignoring open/close times.", false, false, (ValueValidator)null, (string)null);
			_openTime = _cat.CreateEntry<int>("OpenTime", 1800, "Open Time (24h)", "Opening time in 24h format. 1800 = 6:00 PM, 1200 = 12:00 PM, 0 = 12:00 AM.", false, false, (ValueValidator)null, (string)null);
			_closeTime = _cat.CreateEntry<int>("CloseTime", 600, "Close Time (24h)", "Closing time in 24h format. 600 = 6:00 AM, 1200 = 12:00 PM, 2300 = 11:00 PM.", false, false, (ValueValidator)null, (string)null);
			_requiredRank = _cat.CreateEntry<string>("RequiredRank", "Hoodlum", "Required Rank", "Street Rat, Hoodlum, Peddler, Hustler, Bagman, Enforcer, Shot Caller, Block Boss, Underlord, Baron, Kingpin", false, false, (ValueValidator)null, (string)null);
			_requiredTier = _cat.CreateEntry<int>("RequiredTier", 5, "Required Tier (1-5)", "Tier within the rank. 1 = I, 2 = II, 3 = III, 4 = IV, 5 = V.", false, false, (ValueValidator)null, (string)null);
			((MelonEventBase<LemonAction<bool, bool>>)(object)_alwaysOpen.OnEntryValueChanged).Subscribe((LemonAction<bool, bool>)delegate
			{
				OnAnySettingChanged("AlwaysOpen");
			}, 0, false);
			((MelonEventBase<LemonAction<int, int>>)(object)_openTime.OnEntryValueChanged).Subscribe((LemonAction<int, int>)delegate
			{
				OnAnySettingChanged("OpenTime");
			}, 0, false);
			((MelonEventBase<LemonAction<int, int>>)(object)_closeTime.OnEntryValueChanged).Subscribe((LemonAction<int, int>)delegate
			{
				OnAnySettingChanged("CloseTime");
			}, 0, false);
			((MelonEventBase<LemonAction<string, string>>)(object)_requiredRank.OnEntryValueChanged).Subscribe((LemonAction<string, string>)delegate
			{
				OnAnySettingChanged("RequiredRank");
			}, 0, false);
			((MelonEventBase<LemonAction<int, int>>)(object)_requiredTier.OnEntryValueChanged).Subscribe((LemonAction<int, int>)delegate
			{
				OnAnySettingChanged("RequiredTier");
			}, 0, false);
			MelonLogger.Msg($"[Config] Loaded — AlwaysOpen={AlwaysOpen}  Open={OpenTime}  Close={CloseTime}  Rank={RequiredRank} {RequiredTier}");
		}

		public static ERank ParseRank(string input)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrWhiteSpace(input))
			{
				return (ERank)1;
			}
			switch (input.Trim().ToLowerInvariant().Replace(" ", "")
				.Replace("_", ""))
			{
			case "streetrat":
				return (ERank)0;
			case "hoodlum":
				return (ERank)1;
			case "peddler":
				return (ERank)2;
			case "hustler":
				return (ERank)3;
			case "bagman":
				return (ERank)4;
			case "enforcer":
				return (ERank)5;
			case "shotcaller":
				return (ERank)6;
			case "blockboss":
				return (ERank)7;
			case "underlord":
				return (ERank)8;
			case "baron":
				return (ERank)9;
			case "kingpin":
				return (ERank)10;
			default:
				MelonLogger.Warning("[WarehousePlus] Unknown rank \"" + input + "\", defaulting to Hoodlum. Valid: Street Rat, Hoodlum, Peddler, Hustler, Bagman, Enforcer, Shot Caller, Block Boss, Underlord, Baron, Kingpin");
				return (ERank)1;
			}
		}

		private static void OnAnySettingChanged(string entryName)
		{
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (_openTime.Value < 0 || _openTime.Value > 2359)
				{
					_openTime.Value = Clamp(_openTime.Value, 0, 2359);
				}
				if (_closeTime.Value < 0 || _closeTime.Value > 2359)
				{
					_closeTime.Value = Clamp(_closeTime.Value, 0, 2359);
				}
				if (_requiredTier.Value < 1 || _requiredTier.Value > 5)
				{
					_requiredTier.Value = Clamp(_requiredTier.Value, 1, 5);
				}
				ApplyRankLive();
				ERank value = ParseRank(RequiredRank);
				MelonLogger.Msg($"[WarehousePlus] {entryName} changed → AlwaysOpen={AlwaysOpen}  Open={OpenTime}  Close={CloseTime}  Rank={value} {RequiredTier}");
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[WarehousePlus] OnAnySettingChanged: " + ex.Message);
			}
		}

		public static void ApplyRankLive()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				DarkMarket instance = NetworkSingleton<DarkMarket>.Instance;
				if (!((Object)(object)instance == (Object)null))
				{
					ERank val = ParseRank(RequiredRank);
					int num = Clamp(RequiredTier, 1, 5);
					instance.UnlockRank = new FullRank(val, num);
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[WarehousePlus] ApplyRankLive: " + ex.Message);
			}
		}

		public static void Save()
		{
			MelonPreferences.Save();
		}

		private static int Clamp(int v, int min, int max)
		{
			return (v < min) ? min : ((v > max) ? max : v);
		}
	}
	[HarmonyPatch(typeof(DarkMarketRollerDoors), "CanOpen")]
	public static class Patch_RollerDoors_CanOpen
	{
		public static bool Prefix(ref bool __result)
		{
			try
			{
				if (Config.AlwaysOpen)
				{
					__result = true;
					return false;
				}
				DarkMarket instance = NetworkSingleton<DarkMarket>.Instance;
				if ((Object)(object)instance != (Object)null && (Object)(object)instance.AccessZone != (Object)null)
				{
					__result = instance.IsOpen;
					return false;
				}
			}
			catch (Exception value)
			{
				MelonLogger.Error($"[WarehousePlus] RollerDoors CanOpen patch error: {value}");
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(DarkMarketAccessZone), "GetIsOpen")]
	public static class Patch_AccessZone_GetIsOpen
	{
		public static bool Prefix(DarkMarketAccessZone __instance, ref bool __result)
		{
			try
			{
				if (Config.AlwaysOpen)
				{
					__result = true;
					return false;
				}
				if (((TimedAccessZone)__instance).OpenTime != Config.OpenTime || ((TimedAccessZone)__instance).CloseTime != Config.CloseTime)
				{
					((TimedAccessZone)__instance).OpenTime = Config.OpenTime;
					((TimedAccessZone)__instance).CloseTime = Config.CloseTime;
				}
				return true;
			}
			catch (Exception value)
			{
				MelonLogger.Error($"[WarehousePlus] GetIsOpen patch error: {value}");
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(DarkMarket), "ShouldBeOpen")]
	public static class Patch_DarkMarket_ShouldBeOpen
	{
		public static bool Prefix(ref bool __result)
		{
			try
			{
				if (Config.AlwaysOpen)
				{
					__result = true;
					return false;
				}
			}
			catch (Exception value)
			{
				MelonLogger.Error($"[WarehousePlus] ShouldBeOpen patch error: {value}");
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(DarkMarket), "Start")]
	public static class Patch_DarkMarket_Start
	{
		public static void Postfix(DarkMarket __instance)
		{
			try
			{
				Config.ApplyRankLive();
				MelonLogger.Msg("[WarehousePlus] DarkMarket rank override applied.");
			}
			catch (Exception value)
			{
				MelonLogger.Error($"[WarehousePlus] DarkMarket.Start patch error: {value}");
			}
		}
	}
	public class WarehousePlusMod : MelonMod
	{
		public override void OnInitializeMelon()
		{
			Config.Init();
			((MelonBase)this).LoggerInstance.Msg("WarehousePlus v1.0.0 loaded.");
			((MelonBase)this).LoggerInstance.Msg("Configure via the Mod Manager Phone App or UserData/MelonPreferences.cfg");
		}
	}
}