Decompiled source of PlayZone v1.0.4

BepInEx/plugins/PlayZone.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CullFactory;
using CullFactory.Behaviours.CullingMethods;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PlayZone.Compatibility;
using UnityEngine;
using itolib.Behaviours.Events;
using itolib.Behaviours.Props;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("LethalLevelLoader")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PlayZone")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A custom interior for Company employees to bring their families to. Created by LethalMatt and pacoito.")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+bfe6b19ef211cce78fef4babef4df27a0804c5ae")]
[assembly: AssemblyProduct("PlayZone")]
[assembly: AssemblyTitle("PlayZone")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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 PlayZone
{
	public class Config
	{
		public ConfigEntry<bool> INJECT_CUSTOM_SCRAP { get; private set; }

		public ConfigEntry<float> ELEVATOR_MUSIC_VOLUME { get; private set; }

		public ConfigEntry<float> BOWLING_MUSIC_VOLUME { get; private set; }

		public ConfigEntry<float> TRAMPOLINE_VOLUME { get; private set; }

		public ConfigEntry<float> ROTATOR_BONK_VOLUME { get; private set; }

		public ConfigEntry<bool> BOWLING_BALL_TOM_SCREAM { get; private set; }

		public ConfigEntry<bool> CULLFACTORY_BLACKLIST { get; private set; }

		public Config(ConfigFile cfg)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Expected O, but got Unknown
			cfg.SaveOnConfigSet = false;
			INJECT_CUSTOM_SCRAP = cfg.Bind<bool>("Scrap", "InjectScrap", true, "Inject custom scrap into the spawnable scrap pool of any moon PlayZone generates in. Can be disabled to let other mods handle or tweak item spawn weights.");
			ELEVATOR_MUSIC_VOLUME = cfg.Bind<float>("Audio", "ElevatorMusicVolume", 1f, new ConfigDescription("Volume level for PlayZone's elevator music.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			BOWLING_MUSIC_VOLUME = cfg.Bind<float>("Audio", "BowlingMusicVolume", 1f, new ConfigDescription("Volume level for music played at the CosmicZone.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			TRAMPOLINE_VOLUME = cfg.Bind<float>("Audio", "TrampolineVolume", 1f, new ConfigDescription("Volume level for all trampolines and bouncy surfaces.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			ROTATOR_BONK_VOLUME = cfg.Bind<float>("Audio", "RotatorBonkVolume", 1f, new ConfigDescription("Volume level for the rotator hazard's hit sound effect.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			BOWLING_BALL_TOM_SCREAM = cfg.Bind<bool>("Other", "BowlingBallTomScream", true, "Adds a 2% chance to play a Tom scream when kicking a Cosmic Bowling Ball.");
			CULLFACTORY_BLACKLIST = cfg.Bind<bool>("Compatibility", "CullFactoryBlacklist", true, "Add PlayZone to CullFactory's interior blacklist. If you'd rather have it be handled by CullFactory's settings, disable this and add 'PlayZoneDungeonFlow' to the config.");
			ClearOrphanedEntries(cfg);
			cfg.SaveOnConfigSet = true;
			cfg.Save();
		}

		private void ClearOrphanedEntries(ConfigFile config)
		{
			PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
			((Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(config))?.Clear();
		}
	}
	[BepInDependency("pacoito.itolib", "0.1.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("LethalMatt.PlayZone", "PlayZone", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "LethalMatt.PlayZone";

		public const string PLUGIN_NAME = "PlayZone";

		public const string VERSION = "1.0.3";

		internal static ManualLogSource StaticLogger { get; private set; }

		internal static Harmony Harmony { get; private set; }

		public static Config Settings { get; private set; }

		private void Awake()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			StaticLogger = ((BaseUnityPlugin)this).Logger;
			try
			{
				Settings = new Config(((BaseUnityPlugin)this).Config);
				Harmony = new Harmony("LethalMatt.PlayZone");
				if (CullFactoryCompatibility.Enabled)
				{
					Harmony.PatchAll(typeof(CullFactoryCompatibility));
				}
				StaticLogger.LogInfo((object)"PlayZone v1.0.3 loaded!");
			}
			catch (Exception arg)
			{
				StaticLogger.LogError((object)string.Format("Error while initializing '{0}': {1}", "PlayZone", arg));
			}
		}
	}
}
namespace PlayZone.Compatibility
{
	[HarmonyPatch]
	public class CullFactoryCompatibility
	{
		private static bool? _enabled;

		public static bool Enabled
		{
			get
			{
				bool valueOrDefault = _enabled.GetValueOrDefault();
				if (!_enabled.HasValue)
				{
					valueOrDefault = Chainloader.PluginInfos.ContainsKey("com.fumiko.CullFactory");
					_enabled = valueOrDefault;
				}
				return _enabled.Value;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		[HarmonyPatch(typeof(CullingMethod), "Initialize")]
		[HarmonyPrefix]
		internal static void AddToCullingBlacklist()
		{
			if (!Plugin.Settings.CULLFACTORY_BLACKLIST.Value)
			{
				return;
			}
			for (int i = 0; i < Config.InteriorsWithDisabledCulling.Length; i++)
			{
				if (string.CompareOrdinal(Config.InteriorsWithDisabledCulling[i], "PlayZoneDungeonFlow") == 0)
				{
					return;
				}
			}
			string[] array = new string[Config.InteriorsWithDisabledCulling.Length + 1];
			Config.InteriorsWithDisabledCulling.CopyTo(array, 0);
			array[^1] = "PlayZoneDungeonFlow";
			Config.InteriorsWithDisabledCulling = array;
		}
	}
}
namespace PlayZone.Behaviours
{
	public class ChangeSettings : MonoBehaviour
	{
		public ScrapInjector? scrapInjector;

		public AudioSource? elevatorSource;

		public AudioSource? discoSource;

		public AudioSource? trampolineSource;

		public AudioSource? rotatorSource;

		public WeightedEvent? bowlingBallEvent;

		public float DefaultElevatorVolume { get; private set; }

		public float DefaultDiscoVolume { get; private set; }

		public float DefaultTrampolineVolume { get; private set; }

		public float DefaultRotatorBonkVolume { get; private set; }

		public void Awake()
		{
			if ((Object)(object)scrapInjector != (Object)null)
			{
				((Behaviour)scrapInjector).enabled = Plugin.Settings.INJECT_CUSTOM_SCRAP.Value;
			}
			if ((Object)(object)elevatorSource != (Object)null)
			{
				DefaultElevatorVolume = elevatorSource.volume;
				AudioSource? obj = elevatorSource;
				obj.volume *= Plugin.Settings.ELEVATOR_MUSIC_VOLUME.Value;
				Plugin.Settings.ELEVATOR_MUSIC_VOLUME.SettingChanged += ChangeElevatorVolume;
			}
			if ((Object)(object)discoSource != (Object)null)
			{
				DefaultDiscoVolume = discoSource.volume;
				AudioSource? obj2 = discoSource;
				obj2.volume *= Plugin.Settings.BOWLING_MUSIC_VOLUME.Value;
				Plugin.Settings.BOWLING_MUSIC_VOLUME.SettingChanged += ChangeDiscoVolume;
			}
			if ((Object)(object)trampolineSource != (Object)null)
			{
				DefaultTrampolineVolume = trampolineSource.volume;
				AudioSource? obj3 = trampolineSource;
				obj3.volume *= Plugin.Settings.TRAMPOLINE_VOLUME.Value;
				Plugin.Settings.TRAMPOLINE_VOLUME.SettingChanged += ChangeTrampolineVolume;
			}
			if ((Object)(object)rotatorSource != (Object)null)
			{
				DefaultRotatorBonkVolume = rotatorSource.volume;
				AudioSource? obj4 = rotatorSource;
				obj4.volume *= Plugin.Settings.ROTATOR_BONK_VOLUME.Value;
				Plugin.Settings.ROTATOR_BONK_VOLUME.SettingChanged += ChangeRotatorBonkVolume;
			}
			if ((Object)(object)bowlingBallEvent != (Object)null && !Plugin.Settings.BOWLING_BALL_TOM_SCREAM.Value)
			{
				bowlingBallEvent.eventEntries.RemoveAt(0);
			}
		}

		public void OnDestroy()
		{
			Plugin.Settings.ELEVATOR_MUSIC_VOLUME.SettingChanged -= ChangeElevatorVolume;
			Plugin.Settings.BOWLING_MUSIC_VOLUME.SettingChanged -= ChangeDiscoVolume;
		}

		public void ChangeElevatorVolume(object sender, EventArgs args)
		{
			if ((Object)(object)elevatorSource != (Object)null)
			{
				SettingChangedEventArgs val = (SettingChangedEventArgs)(object)((args is SettingChangedEventArgs) ? args : null);
				if (val != null && val.ChangedSetting is ConfigEntry<float> val2)
				{
					elevatorSource.volume = DefaultElevatorVolume * val2.Value;
				}
			}
		}

		public void ChangeDiscoVolume(object sender, EventArgs args)
		{
			if ((Object)(object)discoSource != (Object)null)
			{
				SettingChangedEventArgs val = (SettingChangedEventArgs)(object)((args is SettingChangedEventArgs) ? args : null);
				if (val != null && val.ChangedSetting is ConfigEntry<float> val2)
				{
					discoSource.volume = DefaultDiscoVolume * val2.Value;
				}
			}
		}

		public void ChangeTrampolineVolume(object sender, EventArgs args)
		{
			if ((Object)(object)trampolineSource != (Object)null)
			{
				SettingChangedEventArgs val = (SettingChangedEventArgs)(object)((args is SettingChangedEventArgs) ? args : null);
				if (val != null && val.ChangedSetting is ConfigEntry<float> val2)
				{
					trampolineSource.volume = DefaultTrampolineVolume * val2.Value;
				}
			}
		}

		public void ChangeRotatorBonkVolume(object sender, EventArgs args)
		{
			if ((Object)(object)rotatorSource != (Object)null)
			{
				SettingChangedEventArgs val = (SettingChangedEventArgs)(object)((args is SettingChangedEventArgs) ? args : null);
				if (val != null && val.ChangedSetting is ConfigEntry<float> val2)
				{
					rotatorSource.volume = DefaultRotatorBonkVolume * val2.Value;
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}