Decompiled source of FasterDealers v2.0.0

FasterDealers.dll

Decompiled a week ago
using System;
using System.Collections;
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 System.Threading;
using FasterDealers;
using FasterDealers.Integrations;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using S1API.Entities;
using S1API.Entities.NPCs.Docks;
using S1API.Entities.NPCs.Downtown;
using S1API.Entities.NPCs.Northtown;
using S1API.Entities.NPCs.Suburbia;
using S1API.Entities.NPCs.Uptown;
using S1API.Entities.NPCs.Westville;
using S1API.Logging;
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(Core), "FasterDealers", "2.0.0", "Riccaforte", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonAuthorColor(1, 68, 2, 152)]
[assembly: MelonColor(1, 0, 223, 255)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FasterDealers")]
[assembly: AssemblyConfiguration("CrossCompat")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1a0aa9e5928180b357a93d73b12843a191563f76")]
[assembly: AssemblyProduct("FasterDealers")]
[assembly: AssemblyTitle("FasterDealers")]
[assembly: NeutralResourcesLanguage("en-US")]
[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.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;
		}
	}
	[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 FasterDealers
{
	public class Core : MelonMod
	{
		[CompilerGenerated]
		private sealed class <SetAllDealerSpeeds>d__15 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Core <>4__this;

			private object <>s__1;

			private bool <>s__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <SetAllDealerSpeeds>d__15(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>s__1 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00da: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e4: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>4__this._completedDealers = 0;
					MelonCoroutines.Start(<>4__this.WaitAndSetDealerSpeed<BenjiColeman>(speedMultiplier.Value));
					MelonCoroutines.Start(<>4__this.WaitAndSetDealerSpeed<MollyPresley>(speedMultiplier.Value));
					MelonCoroutines.Start(<>4__this.WaitAndSetDealerSpeed<BradCrosby>(speedMultiplier.Value));
					MelonCoroutines.Start(<>4__this.WaitAndSetDealerSpeed<JaneLucero>(speedMultiplier.Value));
					MelonCoroutines.Start(<>4__this.WaitAndSetDealerSpeed<WeiLong>(speedMultiplier.Value));
					MelonCoroutines.Start(<>4__this.WaitAndSetDealerSpeed<LeoRivers>(speedMultiplier.Value));
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (<>4__this._completedDealers < 6)
				{
					<>2__current = (object)new WaitForSeconds(0.5f);
					<>1__state = 1;
					return true;
				}
				<>4__this._logger.Msg($"Speed multiplier of {speedMultiplier.Value} set for all dealer NPCs!");
				<>s__1 = <>4__this._lock;
				<>s__2 = false;
				try
				{
					Monitor.Enter(<>s__1, ref <>s__2);
					<>4__this._speedsBeingSet = false;
					<>4__this._waitingDealers.Clear();
				}
				finally
				{
					if (<>s__2)
					{
						Monitor.Exit(<>s__1);
					}
				}
				<>s__1 = null;
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <WaitAndSetDealerSpeed>d__16<T> : IEnumerator<object>, IEnumerator, IDisposable where T : NPC
		{
			private int <>1__state;

			private object <>2__current;

			public float speed;

			public Core <>4__this;

			private string <dealerName>5__1;

			private NPC <dealer>5__2;

			private bool <loggedWaiting>5__3;

			private object <>s__4;

			private bool <>s__5;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <WaitAndSetDealerSpeed>d__16(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<dealerName>5__1 = null;
				<dealer>5__2 = null;
				<>s__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_010c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<dealerName>5__1 = typeof(T).Name;
					<dealer>5__2 = null;
					<loggedWaiting>5__3 = false;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				while (<dealer>5__2 == null)
				{
					<dealer>5__2 = NPC.Get<T>();
					if (<dealer>5__2 != null)
					{
						continue;
					}
					<>s__4 = <>4__this._lock;
					<>s__5 = false;
					try
					{
						Monitor.Enter(<>s__4, ref <>s__5);
						if (!<loggedWaiting>5__3 && <>4__this._waitingDealers.Add(<dealerName>5__1))
						{
							<>4__this._logger.Msg("Waiting for " + <dealerName>5__1 + " instance to be created...");
							<loggedWaiting>5__3 = true;
						}
					}
					finally
					{
						if (<>s__5)
						{
							Monitor.Exit(<>s__4);
						}
					}
					<>s__4 = null;
					<>2__current = (object)new WaitForSeconds(0.5f);
					<>1__state = 1;
					return true;
				}
				<dealer>5__2.Movement.SpeedMultiplier = speed;
				<>4__this._logger.Msg($"Set speed multiplier to {speed} for {<dealerName>5__1}");
				<>4__this._completedDealers++;
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static MelonPreferences_Category fasterDealersCategory;

		private static MelonPreferences_Entry<bool> modEnabled;

		private static MelonPreferences_Entry<float> speedMultiplier;

		private Log _logger = new Log("FasterDealers");

		private bool _speedsBeingSet = false;

		private int _completedDealers = 0;

		private const int TOTAL_DEALERS = 6;

		private readonly object _lock = new object();

		private HashSet<string> _waitingDealers = new HashSet<string>();

		public static Core? Instance { get; private set; }

		public override void OnInitializeMelon()
		{
			Instance = this;
			HarmonyPatches.SetModInstance(this);
			LoadConfig();
			_logger.Msg("Mod initialized and config loaded. Waiting for Main scene to load.");
		}

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			((MelonMod)this).OnSceneWasInitialized(buildIndex, sceneName);
			if (!modEnabled.Value || sceneName != "Main")
			{
				return;
			}
			lock (_lock)
			{
				if (_speedsBeingSet)
				{
					_logger.Msg("Dealer speed setting already in progress, skipping...");
					return;
				}
				_speedsBeingSet = true;
				_waitingDealers.Clear();
			}
			MelonCoroutines.Start(SetAllDealerSpeeds());
		}

		[IteratorStateMachine(typeof(<SetAllDealerSpeeds>d__15))]
		private IEnumerator SetAllDealerSpeeds()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <SetAllDealerSpeeds>d__15(0)
			{
				<>4__this = this
			};
		}

		[IteratorStateMachine(typeof(<WaitAndSetDealerSpeed>d__16<>))]
		private IEnumerator WaitAndSetDealerSpeed<T>(float speed) where T : NPC
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitAndSetDealerSpeed>d__16<T>(0)
			{
				<>4__this = this,
				speed = speed
			};
		}

		private void LoadConfig()
		{
			fasterDealersCategory = MelonPreferences.CreateCategory("FasterDealers");
			modEnabled = fasterDealersCategory.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			speedMultiplier = fasterDealersCategory.CreateEntry<float>("SpeedMultiplier", 3f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		}
	}
}
namespace FasterDealers.Utils
{
	public static class Constants
	{
		public static class Defaults
		{
			public const bool BOOLEAN_DEFAULT = false;
		}

		public static class Constraints
		{
			public const float MIN_CONSTRAINT = 0f;

			public const float MAX_CONSTRAINT = 100f;
		}

		public static class Game
		{
			public const string GAME_STUDIO = "TVGS";

			public const string GAME_NAME = "Schedule I";
		}

		public const string MOD_NAME = "FasterDealers";

		public const string MOD_VERSION = "2.0.0";

		public const string MOD_AUTHOR = "Riccaforte";

		public const string MOD_DESCRIPTION = "A simple mod to make all drug dealer NPCs faster! Speed multiplier can be configured to your desired speed.";

		public const string PREFERENCES_CATEGORY = "FasterDealers";
	}
}
namespace FasterDealers.Integrations
{
	[HarmonyPatch]
	public static class HarmonyPatches
	{
		private static Core? _modInstance;

		public static void SetModInstance(Core modInstance)
		{
			_modInstance = modInstance;
		}
	}
}