Decompiled source of JaydeeCube v1.0.0

com.github.zehsteam.JaydeeCube.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Unity.Netcode;
using UnityEngine;
using com.github.zehsteam.JaydeeCube.Dependencies;
using com.github.zehsteam.JaydeeCube.Enums;
using com.github.zehsteam.JaydeeCube.Helpers;
using com.github.zehsteam.JaydeeCube.MonoBehaviours;
using com.github.zehsteam.JaydeeCube.NetcodePatcher;
using com.github.zehsteam.JaydeeCube.Objects;
using com.github.zehsteam.JaydeeCube.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.zehsteam.JaydeeCube")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Adds a customizable Jaydee Cube scrap item.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e2641f8b8f396e046f7314182f3778f0f07dd8d9")]
[assembly: AssemblyProduct("JaydeeCube")]
[assembly: AssemblyTitle("com.github.zehsteam.JaydeeCube")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
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 com.github.zehsteam.JaydeeCube
{
	internal class ConfigManager
	{
		public ConfigEntry<bool> ExtendedLogging { get; private set; }

		public ItemConfigData JaydeeCube { get; private set; }

		public ConfigManager()
		{
			BindConfigs();
			ConfigHelper.ClearUnusedEntries();
		}

		private void BindConfigs()
		{
			ConfigHelper.SkipAutoGen();
			ExtendedLogging = ConfigHelper.Bind("General", "ExtendedLogging", defaultValue: false, "Enable extended logging.");
			JaydeeCube = new ItemConfigData(Content.JaydeeCube, "Jaydee Cube", 20, twoHanded: false, 6, 80, 250);
		}
	}
	internal static class Content
	{
		public static GameObject NetworkHandlerPrefab { get; private set; }

		public static Item JaydeeCube { get; private set; }

		public static void Load()
		{
			LoadAssetsFromAssetBundle();
		}

		private static void LoadAssetsFromAssetBundle()
		{
			AssetBundle val = LoadAssetBundle("jaydeecube_assets");
			if (!((Object)(object)val == (Object)null))
			{
				NetworkHandlerPrefab = LoadAssetFromAssetBundle<GameObject>("NetworkHandler", val);
				NetworkHandlerPrefab.AddComponent<PluginNetworkBehaviour>();
				JaydeeCube = LoadAssetFromAssetBundle<Item>("JaydeeCube", val);
				Plugin.Logger.LogInfo((object)"Successfully loaded assets from AssetBundle!");
			}
		}

		private static AssetBundle LoadAssetBundle(string fileName)
		{
			try
			{
				string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Info.Location);
				string text = Path.Combine(directoryName, fileName);
				return AssetBundle.LoadFromFile(text);
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Failed to load AssetBundle \"{fileName}\". {arg}");
			}
			return null;
		}

		private static T LoadAssetFromAssetBundle<T>(string name, AssetBundle assetBundle) where T : Object
		{
			if (string.IsNullOrWhiteSpace(name))
			{
				Plugin.Logger.LogError((object)("Failed to load asset of type \"" + typeof(T).Name + "\" from AssetBundle. Name is null or whitespace."));
				return default(T);
			}
			if ((Object)(object)assetBundle == (Object)null)
			{
				Plugin.Logger.LogError((object)("Failed to load asset of type \"" + typeof(T).Name + "\" with name \"" + name + "\" from AssetBundle. AssetBundle is null."));
				return default(T);
			}
			T val = assetBundle.LoadAsset<T>(name);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogError((object)("Failed to load asset of type \"" + typeof(T).Name + "\" with name \"" + name + "\" from AssetBundle. No asset found with that type and name."));
				return default(T);
			}
			return val;
		}
	}
	internal static class NetworkUtils
	{
		public static bool IsConnected
		{
			get
			{
				if ((Object)(object)NetworkManager.Singleton == (Object)null)
				{
					return false;
				}
				return NetworkManager.Singleton.IsConnectedClient;
			}
		}

		public static bool IsServer
		{
			get
			{
				if ((Object)(object)NetworkManager.Singleton == (Object)null)
				{
					return false;
				}
				return NetworkManager.Singleton.IsServer;
			}
		}

		public static bool IsHost
		{
			get
			{
				if ((Object)(object)NetworkManager.Singleton == (Object)null)
				{
					return false;
				}
				return NetworkManager.Singleton.IsHost;
			}
		}

		public static ulong GetLocalClientId()
		{
			return NetworkManager.Singleton.LocalClientId;
		}

		public static bool IsLocalClientId(ulong clientId)
		{
			return clientId == GetLocalClientId();
		}

		public static bool IsNetworkPrefab(GameObject prefab)
		{
			foreach (NetworkPrefab prefab2 in NetworkManager.Singleton.NetworkConfig.Prefabs.Prefabs)
			{
				if ((Object)(object)prefab2.Prefab == (Object)(object)prefab)
				{
					return true;
				}
			}
			return false;
		}
	}
	[BepInPlugin("com.github.zehsteam.JaydeeCube", "JaydeeCube", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class Plugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("com.github.zehsteam.JaydeeCube");

		internal static Plugin Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static ConfigManager ConfigManager { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Logger = Logger.CreateLogSource("com.github.zehsteam.JaydeeCube");
			Logger.LogInfo((object)"JaydeeCube has awoken!");
			_harmony.PatchAll(typeof(GameNetworkManagerPatch));
			_harmony.PatchAll(typeof(StartOfRoundPatch));
			Content.Load();
			ConfigManager = new ConfigManager();
			RegisterScrapItems();
			NetcodePatcherAwake();
		}

		private void NetcodePatcherAwake()
		{
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				Type[] types = executingAssembly.GetTypes();
				Type[] array = types;
				foreach (Type type in array)
				{
					MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
					MethodInfo[] array2 = methods;
					foreach (MethodInfo methodInfo in array2)
					{
						try
						{
							object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
							if (customAttributes.Length != 0)
							{
								try
								{
									methodInfo.Invoke(null, null);
								}
								catch (TargetInvocationException ex)
								{
									Logger.LogWarning((object)("Failed to invoke method " + methodInfo.Name + ": " + ex.Message));
								}
							}
						}
						catch (Exception ex2)
						{
							Logger.LogWarning((object)("Error processing method " + methodInfo.Name + " in type " + type.Name + ": " + ex2.Message));
						}
					}
				}
			}
			catch (Exception ex3)
			{
				Logger.LogError((object)("An error occurred in NetcodePatcherAwake: " + ex3.Message));
			}
		}

		private void RegisterScrapItems()
		{
			ItemHelper.RegisterScrap(ConfigManager.JaydeeCube);
		}

		public void LogInfoExtended(object data)
		{
			LogExtended((LogLevel)16, data);
		}

		public void LogWarningExtended(object data)
		{
			LogExtended((LogLevel)4, data);
		}

		public void LogExtended(LogLevel level, object data)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (ConfigManager == null || ConfigManager.ExtendedLogging == null)
			{
				Logger.Log(level, data);
			}
			else if (ConfigManager.ExtendedLogging.Value)
			{
				Logger.Log(level, data);
			}
		}
	}
	internal static class Utils
	{
		public static string GetEnumName<T>(T e) where T : Enum
		{
			return Enum.GetName(typeof(T), e) ?? string.Empty;
		}

		public static string GetPluginDirectoryPath()
		{
			return Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Info.Location);
		}

		public static string GetConfigDirectoryPath()
		{
			return Paths.ConfigPath;
		}

		public static string GetGlobalConfigDirectoryPath()
		{
			return Path.Combine(Application.persistentDataPath, "JaydeeCube");
		}

		public static ConfigFile CreateConfigFile(string directoryPath, string name = null, bool saveOnInit = false)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			BepInPlugin metadata = MetadataHelper.GetMetadata((object)Plugin.Instance);
			if (name == null)
			{
				name = metadata.GUID;
			}
			name += ".cfg";
			return new ConfigFile(Path.Combine(directoryPath, name), saveOnInit, metadata);
		}

		public static ConfigFile CreateLocalConfigFile(string name = null, bool saveOnInit = false)
		{
			if (name == null)
			{
				name = "com.github.zehsteam.JaydeeCube-" + name;
			}
			return CreateConfigFile(Paths.ConfigPath, name, saveOnInit);
		}

		public static ConfigFile CreateGlobalConfigFile(string name = null, bool saveOnInit = false)
		{
			if (name == null)
			{
				name = "global";
			}
			return CreateConfigFile(GetGlobalConfigDirectoryPath(), name, saveOnInit);
		}

		public static bool RandomPercent(float percent)
		{
			if (percent <= 0f)
			{
				return false;
			}
			if (percent >= 100f)
			{
				return true;
			}
			return Random.value * 100f <= percent;
		}

		public static int GetRandomIndexFromWeightList(List<int> weightList)
		{
			List<(int, int)> list = new List<(int, int)>();
			for (int i = 0; i < weightList.Count; i++)
			{
				int num = weightList[i];
				if (num > 0)
				{
					list.Add((i, num));
				}
			}
			int num2 = 0;
			foreach (var item4 in list)
			{
				int item = item4.Item2;
				num2 += item;
			}
			if (num2 == 0)
			{
				return -1;
			}
			int num3 = Random.Range(0, num2);
			int num4 = 0;
			foreach (var item5 in list)
			{
				int item2 = item5.Item1;
				int item3 = item5.Item2;
				num4 += item3;
				if (num3 < num4)
				{
					return item2;
				}
			}
			throw new InvalidOperationException("Weights are not properly specified.");
		}

		public static bool TryParseValue<T>(string value, out T result)
		{
			try
			{
				if (typeof(T) == typeof(int) && int.TryParse(value, out var result2))
				{
					result = (T)(object)result2;
					return true;
				}
				if (typeof(T) == typeof(float) && float.TryParse(value, out var result3))
				{
					result = (T)(object)result3;
					return true;
				}
				if (typeof(T) == typeof(double) && double.TryParse(value, out var result4))
				{
					result = (T)(object)result4;
					return true;
				}
				if (typeof(T) == typeof(bool) && bool.TryParse(value, out var result5))
				{
					result = (T)(object)result5;
					return true;
				}
				if (typeof(T) == typeof(string))
				{
					result = (T)(object)value;
					return true;
				}
			}
			catch
			{
			}
			result = default(T);
			return false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.github.zehsteam.JaydeeCube";

		public const string PLUGIN_NAME = "JaydeeCube";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace com.github.zehsteam.JaydeeCube.Patches
{
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal static class GameNetworkManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPatch()
		{
			AddNetworkPrefabs();
		}

		private static void AddNetworkPrefabs()
		{
			AddNetworkPrefab(Content.NetworkHandlerPrefab);
		}

		private static void AddNetworkPrefab(GameObject prefab)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to register network prefab. GameObject is null.");
				return;
			}
			NetworkManager.Singleton.AddNetworkPrefab(prefab);
			Plugin.Logger.LogInfo((object)("Registered \"" + ((Object)prefab).name + "\" network prefab."));
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal static class StartOfRoundPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePatch()
		{
			SpawnNetworkHandler();
		}

		private static void SpawnNetworkHandler()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkUtils.IsServer)
			{
				GameObject val = Object.Instantiate<GameObject>(Content.NetworkHandlerPrefab, Vector3.zero, Quaternion.identity);
				val.GetComponent<NetworkObject>().Spawn(false);
			}
		}

		[HarmonyPatch("OnClientConnect")]
		[HarmonyPrefix]
		private static void OnClientConnectPatch(ref ulong clientId)
		{
			if (NetworkUtils.IsServer)
			{
				SyncedConfigEntryBase.SendConfigsToClient(clientId);
			}
		}
	}
}
namespace com.github.zehsteam.JaydeeCube.Objects
{
	[Serializable]
	public class AudioClipGroup
	{
		public AudioClip AudioClip;

		public AudioClip AudioClipFar;

		public float Length => AudioClip.length;

		public AudioClipGroup(AudioClip audioClip, AudioClip audioClipFar)
		{
			AudioClip = audioClip;
			AudioClipFar = audioClipFar;
		}
	}
	[Serializable]
	public class AudioClipGroupWithWeight : AudioClipGroup
	{
		[Range(0f, 100f)]
		public int Weight = 10;

		public AudioClipGroupWithWeight(AudioClip audioClip, AudioClip audioClipFar, int weight = 10)
			: base(audioClip, audioClipFar)
		{
			Weight = weight;
		}
	}
	[Serializable]
	public class AudioClipGroupWithData<T> : AudioClipGroup
	{
		public T Data;

		public AudioClipGroupWithData(AudioClip audioClip, AudioClip audioClipFar, T data)
			: base(audioClip, audioClipFar)
		{
			Data = data;
		}
	}
	[Serializable]
	public class AudioSourceGroup
	{
		public AudioSource AudioSource;

		public AudioSource AudioSourceFar;

		public bool IsPlaying => AudioSource.isPlaying;

		public float Volume
		{
			get
			{
				return AudioSource.volume;
			}
			set
			{
				AudioSource.volume = value;
				AudioSourceFar.volume = value;
			}
		}

		public float Pitch
		{
			get
			{
				return AudioSource.pitch;
			}
			set
			{
				AudioSource.pitch = value;
				AudioSourceFar.pitch = value;
			}
		}

		public AudioSourceGroup(AudioSource audioSource, AudioSource audioSourceFar)
		{
			AudioSource = audioSource;
			AudioSourceFar = audioSourceFar;
		}

		public void Play()
		{
			AudioSource.Play();
			AudioSourceFar.Play();
		}

		public float PlayOneShot(AudioClipGroup audioClipGroup, float volumeScale = 1f)
		{
			if (audioClipGroup == null)
			{
				return 0f;
			}
			float result = 0f;
			if ((Object)(object)audioClipGroup.AudioClip != (Object)null)
			{
				result = audioClipGroup.AudioClip.length;
				AudioSource.PlayOneShot(audioClipGroup.AudioClip, volumeScale);
			}
			if ((Object)(object)audioClipGroup.AudioClipFar != (Object)null)
			{
				AudioSourceFar.PlayOneShot(audioClipGroup.AudioClipFar, volumeScale);
			}
			return result;
		}

		public void Pause()
		{
			AudioSource.Pause();
			AudioSourceFar.Pause();
		}

		public void Stop()
		{
			AudioSource.Stop();
			AudioSourceFar.Stop();
		}
	}
	public class ItemConfigData
	{
		public static List<ItemConfigData> Instances { get; private set; } = new List<ItemConfigData>();


		public ConfigEntry<int> SpawnWeight { get; private set; }

		public SyncedConfigEntry<bool> TwoHanded { get; private set; }

		public SyncedConfigEntry<int> CarryWeight { get; private set; }

		public ConfigEntry<int> MinValue { get; private set; }

		public ConfigEntry<int> MaxValue { get; private set; }

		public Item Item { get; private set; }

		public ItemConfigData(Item item, string section, int rarity, bool twoHanded, int carryWeight, int minValue, int maxValue)
		{
			Instances.Add(this);
			Item = item;
			Bind(section, rarity, twoHanded, carryWeight, minValue, maxValue);
		}

		private void Bind(string section, int rarity, bool twoHanded, int carryWeight, int minValue, int maxValue)
		{
			if (!((Object)(object)Item == (Object)null))
			{
				SpawnWeight = ConfigHelper.Bind(section, "SpawnWeight", rarity, Item.itemName + " spawn chance weight.");
				TwoHanded = ConfigHelper.BindSynced(section, "TwoHanded", twoHanded, "If enabled, " + Item.itemName + " will be two-handed.");
				CarryWeight = ConfigHelper.BindSynced(section, "CarryWeight", carryWeight, Item.itemName + " carry weight in pounds.");
				MinValue = ConfigHelper.Bind(section, "MinValue", minValue, Item.itemName + " min scrap value.");
				MaxValue = ConfigHelper.Bind(section, "MaxValue", maxValue, Item.itemName + " max scrap value.");
				SpawnWeight.SettingChanged += delegate
				{
					SpawnWeight_SettingsChanged();
				};
				TwoHanded.SettingChanged += delegate
				{
					Properties_SettingsChanged();
				};
				CarryWeight.SettingChanged += delegate
				{
					Properties_SettingsChanged();
				};
				MinValue.SettingChanged += delegate
				{
					Properties_SettingsChanged();
				};
				MaxValue.SettingChanged += delegate
				{
					Properties_SettingsChanged();
				};
			}
		}

		private void SpawnWeight_SettingsChanged()
		{
			ItemHelper.UpdateScrapRarity(this);
		}

		private void Properties_SettingsChanged()
		{
			ItemHelper.UpdateItemProperties(this);
		}
	}
	internal class JsonSave
	{
		private JObject _data;

		public string DirectoryPath { get; private set; }

		public string FileName { get; private set; }

		public string FilePath => Path.Combine(DirectoryPath, FileName);

		public JsonSave(string directoryPath, string fileName)
		{
			DirectoryPath = directoryPath;
			FileName = fileName;
			_data = ReadFile();
		}

		public bool KeyExists(string key)
		{
			if (_data == null)
			{
				Plugin.Logger.LogError((object)"KeyExists: Data is null. Ensure the save file is properly loaded.");
				return false;
			}
			return _data.ContainsKey(key);
		}

		public T LoadValue<T>(string key, T defaultValue = default(T))
		{
			if (TryLoadValue<T>(key, out var value))
			{
				return value;
			}
			return defaultValue;
		}

		public bool TryLoadValue<T>(string key, out T value)
		{
			//IL_0064: Expected O, but got Unknown
			value = default(T);
			if (_data == null)
			{
				Plugin.Logger.LogError((object)("LoadValue: Data is null. Returning default value for key: " + key + "."));
				return false;
			}
			JToken val = default(JToken);
			if (_data.TryGetValue(key, ref val))
			{
				try
				{
					value = val.ToObject<T>();
					return true;
				}
				catch (JsonException val2)
				{
					JsonException val3 = val2;
					Plugin.Logger.LogError((object)("LoadValue: JSON Conversion Error for key: " + key + ". " + ((Exception)(object)val3).Message));
				}
				catch (ArgumentNullException ex)
				{
					Plugin.Logger.LogError((object)("LoadValue: Argument Null Error for key: " + key + ". " + ex.Message));
				}
				catch (Exception ex2)
				{
					Plugin.Logger.LogError((object)("LoadValue: Unexpected Error for key: " + key + ". " + ex2.Message));
				}
				return false;
			}
			Plugin.Instance.LogWarningExtended("LoadValue: Key '" + key + "' does not exist. Returning default value.");
			return false;
		}

		public bool SaveValue<T>(string key, T value)
		{
			if (_data == null)
			{
				Plugin.Logger.LogError((object)("SaveValue: Data is null. Cannot save key: " + key + "."));
				return false;
			}
			try
			{
				JToken val = JToken.FromObject((object)value);
				if (_data.ContainsKey(key))
				{
					_data[key] = val;
				}
				else
				{
					_data.Add(key, val);
				}
				return WriteFile(_data);
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError((object)("SaveValue: Error saving key: " + key + ". " + ex.Message));
				return false;
			}
		}

		private JObject ReadFile()
		{
			//IL_0080: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			try
			{
				if (!File.Exists(FilePath))
				{
					Plugin.Logger.LogWarning((object)("ReadFile: Save file does not exist at \"" + FilePath + "\". Initializing with an empty file."));
					return new JObject();
				}
				using FileStream stream = new FileStream(FilePath, FileMode.Open, FileAccess.Read);
				using StreamReader streamReader = new StreamReader(stream, Encoding.UTF8);
				return JObject.Parse(streamReader.ReadToEnd());
			}
			catch (JsonException val)
			{
				JsonException val2 = val;
				Plugin.Logger.LogError((object)("ReadFile: JSON Parsing Error for file: \"" + FilePath + "\". " + ((Exception)(object)val2).Message));
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError((object)("ReadFile: Unexpected Error for file: \"" + FilePath + "\". " + ex.Message));
			}
			return new JObject();
		}

		private bool WriteFile(JObject data)
		{
			try
			{
				if (!Directory.Exists(DirectoryPath))
				{
					Directory.CreateDirectory(DirectoryPath);
				}
				File.WriteAllText(FilePath, ((object)data).ToString(), Encoding.UTF8);
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError((object)("WriteFile: Unexpected Error for file: \"" + FilePath + "\". " + ex.Message));
			}
			return false;
		}
	}
	public class SyncedConfigEntry<T> : SyncedConfigEntryBase
	{
		private ConfigEntry<T> _configEntry;

		private T _serverValue;

		public T Value
		{
			get
			{
				return GetValue();
			}
			set
			{
				SetValue(value);
			}
		}

		public T DefaultValue => (T)((ConfigEntryBase)_configEntry).DefaultValue;

		public override string Section => ((ConfigEntryBase)_configEntry).Definition.Section;

		public override string Key => ((ConfigEntryBase)_configEntry).Definition.Key;

		public event Action<T> SettingChanged;

		public SyncedConfigEntry(string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues = null, ConfigFile configFile = null)
		{
			SyncedConfigEntryBase.AddInstance(this);
			_configEntry = ConfigHelper.Bind(section, key, defaultValue, description, requiresRestart: false, acceptableValues, null, configFile);
			_configEntry.SettingChanged += SettingChangedInternal;
			Application.quitting += delegate
			{
				_configEntry.SettingChanged -= SettingChangedInternal;
			};
		}

		public T GetValue()
		{
			if (NetworkUtils.IsConnected && !NetworkUtils.IsServer)
			{
				return _serverValue;
			}
			return _configEntry.Value;
		}

		public void SetValue(T value)
		{
			if (!NetworkUtils.IsConnected || NetworkUtils.IsServer)
			{
				_configEntry.Value = value;
			}
		}

		public void ResetToDefault()
		{
			if (!NetworkUtils.IsConnected || NetworkUtils.IsServer)
			{
				_configEntry.Value = DefaultValue;
			}
		}

		private void SettingChangedInternal(object sender, EventArgs e)
		{
			if (NetworkUtils.IsConnected && NetworkUtils.IsServer)
			{
				this.SettingChanged?.Invoke(Value);
				SendConfigToClients();
			}
		}

		private void SendConfigToClients()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkUtils.IsConnected && NetworkUtils.IsServer)
			{
				PluginNetworkBehaviour.Instance?.SetSyncedConfigValueClientRpc(Section, Key, Value.ToString());
			}
		}

		public override void SendConfigToClient(ulong clientId)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkUtils.IsConnected && NetworkUtils.IsServer)
			{
				ClientRpcParams val = default(ClientRpcParams);
				val.Send = new ClientRpcSendParams
				{
					TargetClientIds = new <>z__ReadOnlySingleElementList<ulong>(clientId)
				};
				ClientRpcParams clientRpcParams = val;
				PluginNetworkBehaviour.Instance?.SetSyncedConfigValueClientRpc(Section, Key, Value.ToString(), clientRpcParams);
			}
		}

		public override void SetValueFromServer(string value)
		{
			if (NetworkUtils.IsConnected && !NetworkUtils.IsServer)
			{
				if (!Utils.TryParseValue<T>(value, out var result))
				{
					throw new InvalidOperationException($"Failed to parse value: \"{value}\" for type {typeof(T)}");
				}
				_serverValue = result;
				Plugin.Instance.LogInfoExtended("Set synced config entry value from server. (Section: \"" + Section + "\", Key: \"" + Key + "\", Value: \"" + value + "\")");
				this.SettingChanged?.Invoke(result);
			}
		}
	}
	public abstract class SyncedConfigEntryBase
	{
		private static readonly object _instancesLock = new object();

		public static List<SyncedConfigEntryBase> Instances { get; private set; } = new List<SyncedConfigEntryBase>();


		public abstract string Section { get; }

		public abstract string Key { get; }

		public static void AddInstance(SyncedConfigEntryBase instance)
		{
			lock (_instancesLock)
			{
				Instances.Add(instance);
			}
		}

		public static void RemoveInstance(SyncedConfigEntryBase instance)
		{
			lock (_instancesLock)
			{
				Instances.Remove(instance);
			}
		}

		public abstract void SendConfigToClient(ulong clientId);

		public abstract void SetValueFromServer(string value);

		public static void SendConfigsToClient(ulong clientId)
		{
			if (!NetworkUtils.IsConnected || !NetworkUtils.IsServer || NetworkUtils.IsLocalClientId(clientId))
			{
				return;
			}
			foreach (SyncedConfigEntryBase instance in Instances)
			{
				instance.SendConfigToClient(clientId);
			}
		}

		public static void SetValueFromServer(string section, string key, string value)
		{
			if (NetworkUtils.IsConnected && !NetworkUtils.IsServer)
			{
				SyncedConfigEntryBase syncedConfigEntryBase = Instances.Find((SyncedConfigEntryBase x) => x.Section == section && x.Key == key);
				if (syncedConfigEntryBase == null)
				{
					Plugin.Logger.LogWarning((object)("No matching synced config entry found for section: \"" + section + "\", key: \"" + key + "\""));
				}
				else
				{
					syncedConfigEntryBase.SetValueFromServer(value);
				}
			}
		}
	}
}
namespace com.github.zehsteam.JaydeeCube.MonoBehaviours
{
	public abstract class AdvancedGrabbableObject : GrabbableObject
	{
		public int UniqueId { get; private set; }

		public string SaveKey => string.Format("{0}_{1}", "AdvancedGrabbableObject", UniqueId);

		public virtual void Awake()
		{
			if (NetworkUtils.IsServer)
			{
				UniqueId = Random.Range(0, 1000000);
			}
		}

		public override void OnNetworkSpawn()
		{
			((NetworkBehaviour)this).OnNetworkSpawn();
			if (NetworkUtils.IsServer)
			{
				NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnected;
			}
		}

		public override void OnNetworkDespawn()
		{
			((NetworkBehaviour)this).OnNetworkDespawn();
			if (NetworkUtils.IsServer)
			{
				NetworkManager.Singleton.OnClientConnectedCallback -= OnClientConnected;
			}
		}

		protected virtual void OnClientConnected(ulong clientId)
		{
		}

		public override int GetItemDataToSave()
		{
			return UniqueId;
		}

		public override void LoadItemSaveData(int saveData)
		{
			((GrabbableObject)this).LoadItemSaveData(saveData);
			UniqueId = saveData;
		}

		protected override void __initializeVariables()
		{
			((GrabbableObject)this).__initializeVariables();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "AdvancedGrabbableObject";
		}
	}
	public class AdvancedNoisemakerProp : AdvancedGrabbableObject
	{
		[Space(20f)]
		[Header("Advanced Noisemaker Prop")]
		[Space(5f)]
		public AudioSourceGroup NoiseAudio;

		public AudioClipGroupWithWeight[] NoiseSFX = Array.Empty<AudioClipGroupWithWeight>();

		[Space(10f)]
		public float NoiseRange = 65f;

		public float MaxLoudness = 1f;

		public float MinLoudness = 0.95f;

		public float MinPitch = 1f;

		public float MaxPitch = 1f;

		[Space(10f)]
		public bool UseDynamicCooldown;

		public bool CancelActiveSFXOnItemActivate;

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			if (NoiseSFX.Length != 0)
			{
				int randomIndexFromWeightList = Utils.GetRandomIndexFromWeightList(NoiseSFX.Select((AudioClipGroupWithWeight x) => x.Weight).ToList());
				PlaySound(randomIndexFromWeightList);
			}
		}

		public void PlaySound(int index)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (NoiseSFX.Length != 0)
			{
				PlaySoundServerRpc(index);
				PlaySoundOnLocalClient(index);
			}
		}

		[ServerRpc(RequireOwnership = false)]
		protected void PlaySoundServerRpc(int index, ServerRpcParams serverRpcParams = default(ServerRpcParams))
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(2648581654u, serverRpcParams, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val, index);
				((NetworkBehaviour)this).__endSendServerRpc(ref val, 2648581654u, serverRpcParams, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ulong senderClientId = serverRpcParams.Receive.SenderClientId;
				if (((NetworkBehaviour)this).NetworkManager.ConnectedClients.ContainsKey(senderClientId))
				{
					PlaySoundClientRpc(index, senderClientId);
				}
			}
		}

		[ClientRpc]
		protected void PlaySoundClientRpc(int index, ulong senderClientId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(321270847u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, index);
					BytePacker.WriteValueBitPacked(val2, senderClientId);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 321270847u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !NetworkUtils.IsLocalClientId(senderClientId))
				{
					PlaySoundOnLocalClient(index);
				}
			}
		}

		public void PlaySoundOnLocalClient(int index)
		{
			AudioClipGroup audioClipGroup = ((index >= 0 && index < NoiseSFX.Length) ? NoiseSFX[index] : null);
			PlaySoundOnLocalClient(audioClipGroup);
			OnPlaySoundFromIndex(index);
		}

		protected virtual void OnPlaySoundFromIndex(int index)
		{
		}

		public float PlaySoundOnLocalClient(AudioClip audioClip, AudioClip audioClipFar, bool stopPreviousSFX = false)
		{
			return PlaySoundOnLocalClient(new AudioClipGroup(audioClip, audioClipFar), stopPreviousSFX);
		}

		public float PlaySoundOnLocalClient(AudioClipGroup audioClipGroup, bool stopPreviousSFX = false)
		{
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			if (audioClipGroup == null || (Object)(object)audioClipGroup.AudioClip == (Object)null)
			{
				return 0f;
			}
			float num = (float)Random.Range((int)(MinLoudness * 100f), (int)(MaxLoudness * 100f)) / 100f;
			float pitch = (float)Random.Range((int)(MinPitch * 100f), (int)(MaxPitch * 100f)) / 100f;
			if (CancelActiveSFXOnItemActivate || stopPreviousSFX)
			{
				NoiseAudio.Stop();
			}
			if (UseDynamicCooldown && !CancelActiveSFXOnItemActivate)
			{
				((GrabbableObject)this).currentUseCooldown = audioClipGroup.Length;
			}
			NoiseAudio.Pitch = pitch;
			NoiseAudio.PlayOneShot(audioClipGroup, num);
			WalkieTalkie.TransmitOneShotAudio(NoiseAudio.AudioSource, audioClipGroup.AudioClip, num);
			RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, NoiseRange, num, 0, ((GrabbableObject)this).isInElevator && StartOfRound.Instance.hangarDoorsClosed, 0);
			if (MinLoudness >= 0.6f && (Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null)
			{
				((GrabbableObject)this).playerHeldBy.timeSinceMakingLoudNoise = 0f;
			}
			return audioClipGroup.Length;
		}

		protected override void __initializeVariables()
		{
			base.__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_AdvancedNoisemakerProp()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(2648581654u, new RpcReceiveHandler(__rpc_handler_2648581654));
			NetworkManager.__rpc_func_table.Add(321270847u, new RpcReceiveHandler(__rpc_handler_321270847));
		}

		private static void __rpc_handler_2648581654(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int index = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref index);
				ServerRpcParams server = rpcParams.Server;
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((AdvancedNoisemakerProp)(object)target).PlaySoundServerRpc(index, server);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_321270847(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int index = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref index);
				ulong senderClientId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref senderClientId);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((AdvancedNoisemakerProp)(object)target).PlaySoundClientRpc(index, senderClientId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "AdvancedNoisemakerProp";
		}
	}
	public class JaydeeCube : AdvancedNoisemakerProp
	{
		protected override void __initializeVariables()
		{
			base.__initializeVariables();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "JaydeeCube";
		}
	}
	internal class PluginNetworkBehaviour : NetworkBehaviour
	{
		public static PluginNetworkBehaviour Instance { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			else
			{
				Instance = this;
			}
		}

		public override void OnNetworkSpawn()
		{
			((NetworkBehaviour)this).OnNetworkSpawn();
			if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this)
			{
				if (((NetworkBehaviour)this).IsServer)
				{
					((NetworkBehaviour)this).NetworkObject.Despawn(true);
				}
			}
			else
			{
				Instance = this;
			}
		}

		[ClientRpc]
		public void SetSyncedConfigValueClientRpc(string section, string key, string value, ClientRpcParams clientRpcParams = default(ClientRpcParams))
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(3557915812u, clientRpcParams, (RpcDelivery)0);
				bool flag = section != null;
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val)).WriteValueSafe(section, false);
				}
				bool flag2 = key != null;
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag2, default(ForPrimitives));
				if (flag2)
				{
					((FastBufferWriter)(ref val)).WriteValueSafe(key, false);
				}
				bool flag3 = value != null;
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag3, default(ForPrimitives));
				if (flag3)
				{
					((FastBufferWriter)(ref val)).WriteValueSafe(value, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 3557915812u, clientRpcParams, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !NetworkUtils.IsServer)
			{
				SyncedConfigEntryBase.SetValueFromServer(section, key, value);
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_PluginNetworkBehaviour()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(3557915812u, new RpcReceiveHandler(__rpc_handler_3557915812));
		}

		private static void __rpc_handler_3557915812(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string section = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref section, false);
				}
				bool flag2 = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag2, default(ForPrimitives));
				string key = null;
				if (flag2)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref key, false);
				}
				bool flag3 = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag3, default(ForPrimitives));
				string value = null;
				if (flag3)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref value, false);
				}
				ClientRpcParams client = rpcParams.Client;
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((PluginNetworkBehaviour)(object)target).SetSyncedConfigValueClientRpc(section, key, value, client);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "PluginNetworkBehaviour";
		}
	}
}
namespace com.github.zehsteam.JaydeeCube.Helpers
{
	internal static class ConfigHelper
	{
		public static void SkipAutoGen()
		{
			if (LethalConfigProxy.Enabled)
			{
				LethalConfigProxy.SkipAutoGen();
			}
		}

		public static void AddButton(string section, string name, string description, string buttonText, Action callback)
		{
			if (LethalConfigProxy.Enabled)
			{
				LethalConfigProxy.AddButton(section, name, description, buttonText, callback);
			}
		}

		public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, string description, bool requiresRestart = false, AcceptableValueBase acceptableValues = null, Action<T> settingChanged = null, ConfigFile configFile = null)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			if (configFile == null)
			{
				configFile = ((BaseUnityPlugin)Plugin.Instance).Config;
			}
			ConfigEntry<T> configEntry = ((acceptableValues == null) ? configFile.Bind<T>(section, key, defaultValue, description) : configFile.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, Array.Empty<object>())));
			if (settingChanged != null)
			{
				configEntry.SettingChanged += delegate
				{
					settingChanged?.Invoke(configEntry.Value);
				};
			}
			if (LethalConfigProxy.Enabled)
			{
				LethalConfigProxy.AddConfig<T>(configEntry, requiresRestart);
			}
			return configEntry;
		}

		public static SyncedConfigEntry<T> BindSynced<T>(string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues = null, Action<T> settingChanged = null, ConfigFile configFile = null)
		{
			SyncedConfigEntry<T> syncedConfigEntry = new SyncedConfigEntry<T>(section, key, defaultValue, description, acceptableValues, configFile);
			if (settingChanged != null)
			{
				syncedConfigEntry.SettingChanged += settingChanged;
			}
			return syncedConfigEntry;
		}

		public static Dictionary<ConfigDefinition, string> GetOrphanedConfigEntries(ConfigFile configFile = null)
		{
			if (configFile == null)
			{
				configFile = ((BaseUnityPlugin)Plugin.Instance).Config;
			}
			PropertyInfo property = ((object)configFile).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
			return (Dictionary<ConfigDefinition, string>)property.GetValue(configFile, null);
		}

		public static void SetConfigEntryValue<T>(ConfigEntry<T> configEntry, string value)
		{
			if (typeof(T) == typeof(int) && int.TryParse(value, out var result))
			{
				configEntry.Value = (T)(object)result;
				return;
			}
			if (typeof(T) == typeof(float) && float.TryParse(value, out var result2))
			{
				configEntry.Value = (T)(object)result2;
				return;
			}
			if (typeof(T) == typeof(double) && double.TryParse(value, out var result3))
			{
				configEntry.Value = (T)(object)result3;
				return;
			}
			if (typeof(T) == typeof(bool) && bool.TryParse(value, out var result4))
			{
				configEntry.Value = (T)(object)result4;
				return;
			}
			if (typeof(T) == typeof(string))
			{
				configEntry.Value = (T)(object)value;
				return;
			}
			throw new InvalidOperationException($"Unsupported type: {typeof(T)}");
		}

		public static void SetConfigEntryValue<T>(SyncedConfigEntry<T> syncedConfigEntry, string value)
		{
			if (typeof(T) == typeof(int) && int.TryParse(value, out var result))
			{
				syncedConfigEntry.Value = (T)(object)result;
				return;
			}
			if (typeof(T) == typeof(float) && float.TryParse(value, out var result2))
			{
				syncedConfigEntry.Value = (T)(object)result2;
				return;
			}
			if (typeof(T) == typeof(double) && double.TryParse(value, out var result3))
			{
				syncedConfigEntry.Value = (T)(object)result3;
				return;
			}
			if (typeof(T) == typeof(bool) && bool.TryParse(value, out var result4))
			{
				syncedConfigEntry.Value = (T)(object)result4;
				return;
			}
			if (typeof(T) == typeof(string))
			{
				syncedConfigEntry.Value = (T)(object)value;
				return;
			}
			throw new InvalidOperationException($"Unsupported type: {typeof(T)}");
		}

		public static void ClearUnusedEntries(ConfigFile configFile = null)
		{
			if (configFile == null)
			{
				configFile = ((BaseUnityPlugin)Plugin.Instance).Config;
			}
			Dictionary<ConfigDefinition, string> orphanedConfigEntries = GetOrphanedConfigEntries(configFile);
			if (orphanedConfigEntries != null)
			{
				orphanedConfigEntries.Clear();
				configFile.Save();
			}
		}
	}
	internal static class ItemHelper
	{
		public static void RegisterScrap(Item item, int rarity, bool twoHanded, int carryWeight, int minValue, int maxValue)
		{
			if ((Object)(object)item == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to register scrap item. Item is null.");
				return;
			}
			item.twoHanded = twoHanded;
			item.weight = (float)carryWeight / 105f + 1f;
			item.minValue = minValue;
			item.maxValue = maxValue;
			Utilities.FixMixerGroups(item.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(item.spawnPrefab);
			Items.RegisterScrap(item, rarity, (LevelTypes)(-1));
			Plugin.Logger.LogInfo((object)$"Registered \"{item.itemName}\" scrap item. (Rarity: {rarity}, TwoHanded: {twoHanded}, CarryWeight: {carryWeight}, MinValue: {minValue}, MaxValue: {maxValue})");
		}

		public static void RegisterScrap(ItemConfigData itemConfigData)
		{
			RegisterScrap(itemConfigData.Item, itemConfigData.SpawnWeight.Value, itemConfigData.TwoHanded.Value, itemConfigData.CarryWeight.Value, itemConfigData.MinValue.Value, itemConfigData.MaxValue.Value);
		}

		public static void UpdateScrapRarity(Item item, int rarity)
		{
			if ((Object)(object)item == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to update scrap item rarity. Item is null.");
				return;
			}
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to update scrap item rarity. StartOfRound instance is null.");
				return;
			}
			SelectableLevel[] levels = StartOfRound.Instance.levels;
			foreach (SelectableLevel val in levels)
			{
				foreach (SpawnableItemWithRarity item2 in val.spawnableScrap)
				{
					if (!((Object)(object)item2.spawnableItem != (Object)(object)item))
					{
						item2.rarity = rarity;
						Plugin.Logger.LogInfo((object)$"Updated \"{item.itemName}\" scrap item rarity to {rarity} on \"{val.PlanetName}\".");
					}
				}
			}
		}

		public static void UpdateScrapRarity(ItemConfigData itemConfigData)
		{
			UpdateScrapRarity(itemConfigData.Item, itemConfigData.SpawnWeight.Value);
		}

		public static void UpdateItemProperties(Item item, bool twoHanded, int carryWeight, int minValue, int maxValue)
		{
			if ((Object)(object)item == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to update item properties. Item is null.");
				return;
			}
			item.twoHanded = twoHanded;
			item.weight = (float)carryWeight / 105f + 1f;
			item.minValue = minValue;
			item.maxValue = maxValue;
			Plugin.Logger.LogInfo((object)$"Updated \"{item.itemName}\" item properties. (TwoHanded: {twoHanded}, CarryWeight: {carryWeight}, MinValue: {minValue}, MaxValue: {maxValue})");
		}

		public static void UpdateItemProperties(string itemName, bool twoHanded, int carryWeight, int minValue, int maxValue)
		{
			if (!TryGetItem(itemName, out var item, matchCase: false))
			{
				Plugin.Logger.LogError((object)("Failed to update item properties. Item is null. (ItemName: " + itemName + ")"));
			}
			else
			{
				UpdateItemProperties(item, twoHanded, carryWeight, minValue, maxValue);
			}
		}

		public static void UpdateItemProperties(ItemConfigData itemConfigData)
		{
			UpdateItemProperties(itemConfigData.Item, itemConfigData.TwoHanded.Value, itemConfigData.CarryWeight.Value, itemConfigData.MinValue.Value, itemConfigData.MaxValue.Value);
		}

		public static Item GetItem(string itemName, bool matchCase = true)
		{
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to get item by name. StartOfRound instance is null.");
				return null;
			}
			StringComparison comparisonType = ((!matchCase) ? StringComparison.OrdinalIgnoreCase : StringComparison.CurrentCulture);
			foreach (Item items in StartOfRound.Instance.allItemsList.itemsList)
			{
				if (items.itemName.Equals(itemName, comparisonType))
				{
					return items;
				}
			}
			return null;
		}

		public static bool TryGetItem(string itemName, out Item item, bool matchCase = true)
		{
			item = GetItem(itemName, matchCase);
			return (Object)(object)item != (Object)null;
		}

		public static List<Item> GetItems(string[] itemNames, bool matchCase = true)
		{
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to get items by names. StartOfRound instance is null.");
				return new List<Item>();
			}
			List<Item> list = new List<Item>();
			foreach (string itemName in itemNames)
			{
				if (TryGetItem(itemName, out var item, matchCase))
				{
					list.Add(item);
				}
			}
			return list;
		}
	}
	internal static class SaveHelper
	{
		private static JsonSave _modpackSave;

		private static JsonSave _globalSave;

		static SaveHelper()
		{
			_modpackSave = new JsonSave(Utils.GetConfigDirectoryPath(), "JaydeeCube_Save");
			_globalSave = new JsonSave(Utils.GetGlobalConfigDirectoryPath(), "GlobalSave");
		}

		public static bool KeyExists(string key, SaveLocation saveLocation)
		{
			try
			{
				string key2 = GetKey(key, saveLocation);
				switch (saveLocation)
				{
				case SaveLocation.CurrentSave:
					return ES3.KeyExists(key2, GetCurrentSaveFilePath());
				case SaveLocation.GeneralSave:
					return ES3.KeyExists(key2, GetGeneralSaveFilePath());
				case SaveLocation.Modpack:
					return _modpackSave.KeyExists(key2);
				case SaveLocation.Global:
					return _globalSave.KeyExists(key2);
				default:
					Plugin.Logger.LogWarning((object)$"KeyExists: Unknown SaveLocation: {saveLocation}");
					return false;
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError((object)$"KeyExists Error: Key: \"{key}\", SaveLocation: {saveLocation}. Exception: {ex.Message}");
				return false;
			}
		}

		public static T LoadValue<T>(string key, SaveLocation saveLocation, T defaultValue = default(T))
		{
			try
			{
				string key2 = GetKey(key, saveLocation);
				switch (saveLocation)
				{
				case SaveLocation.CurrentSave:
					return ES3.Load<T>(key2, GetCurrentSaveFilePath(), defaultValue);
				case SaveLocation.GeneralSave:
					return ES3.Load<T>(key2, GetGeneralSaveFilePath(), defaultValue);
				case SaveLocation.Modpack:
					return _modpackSave.LoadValue(key2, defaultValue);
				case SaveLocation.Global:
					return _globalSave.LoadValue(key2, defaultValue);
				default:
					Plugin.Logger.LogWarning((object)$"LoadValue: Unknown SaveLocation: {saveLocation}");
					return defaultValue;
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError((object)$"LoadValue Error: Key: \"{key}\", SaveLocation: {saveLocation}. Exception: {ex.Message}");
				return defaultValue;
			}
		}

		public static bool SaveValue<T>(string key, T value, SaveLocation saveLocation)
		{
			if (string.IsNullOrWhiteSpace(key) || value == null)
			{
				Plugin.Logger.LogError((object)"SaveValue: Invalid key or value.");
				return false;
			}
			try
			{
				string key2 = GetKey(key, saveLocation);
				switch (saveLocation)
				{
				case SaveLocation.CurrentSave:
					ES3.Save<T>(key2, value, GetCurrentSaveFilePath());
					return true;
				case SaveLocation.GeneralSave:
					ES3.Save<T>(key2, value, GetGeneralSaveFilePath());
					return true;
				case SaveLocation.Modpack:
					return _modpackSave.SaveValue(key2, value);
				case SaveLocation.Global:
					return _globalSave.SaveValue(key2, value);
				default:
					Plugin.Logger.LogWarning((object)$"SaveValue: Unknown SaveLocation: {saveLocation}");
					return false;
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError((object)$"SaveValue Error: Key: \"{key}\", SaveLocation: {saveLocation}. Exception: {ex.Message}");
				return false;
			}
		}

		private static string GetKey(string key, SaveLocation saveLocation)
		{
			if (1 == 0)
			{
			}
			string result = (((uint)saveLocation > 1u) ? key : ("com.github.zehsteam.JaydeeCube." + key));
			if (1 == 0)
			{
			}
			return result;
		}

		private static string GetCurrentSaveFilePath()
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)null)
			{
				Plugin.Logger.LogWarning((object)"GetCurrentSaveFilePath: GameNetworkManager instance is null. Returning an empty string.");
				return string.Empty;
			}
			return GameNetworkManager.Instance.currentSaveFileName ?? string.Empty;
		}

		private static string GetGeneralSaveFilePath()
		{
			return "LCGeneralSaveData";
		}
	}
}
namespace com.github.zehsteam.JaydeeCube.Enums
{
	internal enum SaveLocation
	{
		CurrentSave,
		GeneralSave,
		Modpack,
		Global
	}
}
namespace com.github.zehsteam.JaydeeCube.Dependencies
{
	internal static class LethalConfigProxy
	{
		public const string PLUGIN_GUID = "ainavt.lc.lethalconfig";

		private static bool? _enabled;

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

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void SkipAutoGen()
		{
			LethalConfigManager.SkipAutoGen();
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddConfig<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			AcceptableValueBase acceptableValues = ((ConfigEntryBase)configEntry).Description.AcceptableValues;
			if (acceptableValues != null)
			{
				if (acceptableValues is AcceptableValueRange<float> || acceptableValues is AcceptableValueRange<int>)
				{
					AddConfigSlider<T>(configEntry, requiresRestart);
					return;
				}
				if (acceptableValues is AcceptableValueList<string>)
				{
					AddConfigDropdown<T>(configEntry, requiresRestart);
					return;
				}
			}
			if (!(configEntry is ConfigEntry<string> val))
			{
				if (!(configEntry is ConfigEntry<bool> val2))
				{
					if (!(configEntry is ConfigEntry<float> val3))
					{
						if (!(configEntry is ConfigEntry<int> val4))
						{
							throw new NotSupportedException($"Unsupported type: {typeof(T)}");
						}
						LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(val4, requiresRestart));
					}
					else
					{
						LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(val3, requiresRestart));
					}
				}
				else
				{
					LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(val2, requiresRestart));
				}
			}
			else
			{
				LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(val, requiresRestart));
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddConfigSlider<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			if (!(configEntry is ConfigEntry<float> val))
			{
				if (!(configEntry is ConfigEntry<int> val2))
				{
					throw new NotSupportedException($"Slider not supported for type: {typeof(T)}");
				}
				LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(val2, requiresRestart));
			}
			else
			{
				LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(val, requiresRestart));
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddConfigDropdown<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			if (configEntry is ConfigEntry<string> val)
			{
				LethalConfigManager.AddConfigItem((BaseConfigItem)new TextDropDownConfigItem(val, requiresRestart));
				return;
			}
			throw new NotSupportedException($"Dropdown not supported for type: {typeof(T)}");
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddButton(string section, string name, string description, string buttonText, Action callback)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			LethalConfigManager.AddConfigItem((BaseConfigItem)new GenericButtonConfigItem(section, name, description, buttonText, (GenericButtonHandler)delegate
			{
				callback?.Invoke();
			}));
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
[CompilerGenerated]
internal sealed class <>z__ReadOnlySingleElementList<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
	private sealed class Enumerator : IDisposable, IEnumerator, IEnumerator<T>
	{
		object IEnumerator.Current => _item;

		T IEnumerator<T>.Current => _item;

		public Enumerator(T item)
		{
			_item = item;
		}

		bool IEnumerator.MoveNext()
		{
			return !_moveNextCalled && (_moveNextCalled = true);
		}

		void IEnumerator.Reset()
		{
			_moveNextCalled = false;
		}

		void IDisposable.Dispose()
		{
		}
	}

	int ICollection.Count => 1;

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => this;

	object IList.this[int index]
	{
		get
		{
			if (index != 0)
			{
				throw new IndexOutOfRangeException();
			}
			return _item;
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	bool IList.IsFixedSize => true;

	bool IList.IsReadOnly => true;

	int IReadOnlyCollection<T>.Count => 1;

	T IReadOnlyList<T>.this[int index]
	{
		get
		{
			if (index != 0)
			{
				throw new IndexOutOfRangeException();
			}
			return _item;
		}
	}

	int ICollection<T>.Count => 1;

	bool ICollection<T>.IsReadOnly => true;

	T IList<T>.this[int index]
	{
		get
		{
			if (index != 0)
			{
				throw new IndexOutOfRangeException();
			}
			return _item;
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	public <>z__ReadOnlySingleElementList(T item)
	{
		_item = item;
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		return new Enumerator(_item);
	}

	void ICollection.CopyTo(Array array, int index)
	{
		array.SetValue(_item, index);
	}

	int IList.Add(object value)
	{
		throw new NotSupportedException();
	}

	void IList.Clear()
	{
		throw new NotSupportedException();
	}

	bool IList.Contains(object value)
	{
		return EqualityComparer<T>.Default.Equals(_item, (T)value);
	}

	int IList.IndexOf(object value)
	{
		return (!EqualityComparer<T>.Default.Equals(_item, (T)value)) ? (-1) : 0;
	}

	void IList.Insert(int index, object value)
	{
		throw new NotSupportedException();
	}

	void IList.Remove(object value)
	{
		throw new NotSupportedException();
	}

	void IList.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}

	IEnumerator<T> IEnumerable<T>.GetEnumerator()
	{
		return new Enumerator(_item);
	}

	void ICollection<T>.Add(T item)
	{
		throw new NotSupportedException();
	}

	void ICollection<T>.Clear()
	{
		throw new NotSupportedException();
	}

	bool ICollection<T>.Contains(T item)
	{
		return EqualityComparer<T>.Default.Equals(_item, item);
	}

	void ICollection<T>.CopyTo(T[] array, int arrayIndex)
	{
		array[arrayIndex] = _item;
	}

	bool ICollection<T>.Remove(T item)
	{
		throw new NotSupportedException();
	}

	int IList<T>.IndexOf(T item)
	{
		return (!EqualityComparer<T>.Default.Equals(_item, item)) ? (-1) : 0;
	}

	void IList<T>.Insert(int index, T item)
	{
		throw new NotSupportedException();
	}

	void IList<T>.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}
}
namespace com.github.zehsteam.JaydeeCube.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}