Decompiled source of ItemOnLevel v1.0.2

ItemOnLevel.dll

Decompiled 3 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.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2.Networking;
using RoR2;
using RoR2.Networking;
using UnityEngine.Networking;

[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("ItemOnLevel")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e765efc1a45cd1b4acbe4942f017cd7b71811807")]
[assembly: AssemblyProduct("ItemOnLevel")]
[assembly: AssemblyTitle("ItemOnLevel")]
[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 ItemOnLevel
{
	[BepInPlugin("General.ItemOnLevel", "ItemOnLevel", "1.0.2")]
	public class ItemOnLevel : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_OnServerConnect <>9__10_0;

			internal void <Awake>b__10_0(orig_OnServerConnect s, NetworkManagerSystemSteam u, NetworkConnection t)
			{
				canSpawn = true;
				Log.Info("canSpawn is set to true");
			}
		}

		public const string PluginGUID = "General.ItemOnLevel";

		public const string PluginAuthor = "General";

		public const string PluginName = "ItemOnLevel";

		public const string PluginVersion = "1.0.2";

		private static Dictionary<float, string> levelToItem = new Dictionary<float, string>();

		private static bool canSpawn = false;

		public static ConfigEntry<string> LevelToItemString { get; set; }

		public void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			object obj = <>c.<>9__10_0;
			if (obj == null)
			{
				hook_OnServerConnect val = delegate
				{
					canSpawn = true;
					Log.Info("canSpawn is set to true");
				};
				<>c.<>9__10_0 = val;
				obj = (object)val;
			}
			NetworkManagerSystemSteam.OnServerConnect += (hook_OnServerConnect)obj;
			LevelToItemString = ((BaseUnityPlugin)this).Config.Bind<string>("ItemToLevel", "Dictionary", "5-Hoof,10-JumpBoost,15-Feather", "A string representing a dictionary of the level to item formatted as \"5-Feather,15-Feather\"\nHopoo Feather = Feather, Wax Quail = JumpBoost, Paul's Goat Hoof = Hoof");
			string[] array = LevelToItemString.Value.Split(',');
			string[] array2 = array;
			foreach (string text in array2)
			{
				string[] array3 = text.Split("-");
				levelToItem.Add(float.Parse(array3[0]), array3[1]);
			}
			GlobalEventManager.onCharacterLevelUp += GlobalEventManager_onCharacterLevelUp;
		}

		private void GlobalEventManager_onCharacterLevelUp(CharacterBody body)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			Log.Info($"My current level is {body.level}");
			if (body.isPlayerControlled && canSpawn && levelToItem.ContainsKey(body.level))
			{
				Log.Info("Spawning " + levelToItem[body.level]);
				body.inventory.GiveItemString(levelToItem[body.level]);
				SimpleChatMessage val = new SimpleChatMessage();
				val.baseToken = "<color=#e5eefc>{0}</color>";
				val.paramTokens = new string[1] { $"Giving {body.GetUserName()} a {levelToItem[body.level]} for reaching level {body.level}" };
				Chat.SendBroadcastChat((ChatMessageBase)(object)val);
			}
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
}