Decompiled source of Gimme v1.0.0

plugins/Gimme/Gimme.dll

Decompiled 2 months ago
using System;
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.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using On.RoR2;
using On.RoR2.Achievements;
using RoR2;
using RoR2.Achievements;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Gimme")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Gimme")]
[assembly: AssemblyTitle("Gimme")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Gimme;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInProcess("Risk of Rain 2.exe")]
[BepInPlugin("com.nulldev.ror2.gimme", "Gimme", "1.0.0")]
public class Main : BaseUnityPlugin
{
	private const string GUID = "com.nulldev.ror2.gimme";

	private const string NAME = "Gimme";

	private const string VERSION = "1.0.0";

	internal static ManualLogSource log { get; set; }

	private void Awake()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		log = ((BaseUnityPlugin)this).Logger;
		Console.RunCmd += new hook_RunCmd(Console_RunCmd);
		BaseAchievement.Grant += new hook_Grant(AchievementBlocker);
		log.LogInfo((object)"Gimme loaded successfully.");
	}

	private static void AchievementBlocker(orig_Grant orig, BaseAchievement self)
	{
		log.LogDebug((object)("[Gimme::AchievementBlocker] Preventing the following achievement: " + (object)self));
	}

	private static void Console_RunCmd(orig_RunCmd orig, Console self, CmdSender sender, string concommandName, List<string> userArgs)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Expected O, but got Unknown
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Expected O, but got Unknown
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Expected O, but got Unknown
		//IL_0184: 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)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Expected O, but got Unknown
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Expected O, but got Unknown
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Expected O, but got Unknown
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Expected O, but got Unknown
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Expected O, but got Unknown
		if (!NetworkServer.active || (Object)(object)Run.instance == (Object)null || !concommandName.Equals("say", StringComparison.InvariantCultureIgnoreCase))
		{
			orig.Invoke(self, sender, concommandName, userArgs);
			return;
		}
		string text = userArgs.FirstOrDefault();
		if (string.IsNullOrWhiteSpace(text) || !text.StartsWith("/"))
		{
			orig.Invoke(self, sender, concommandName, userArgs);
			return;
		}
		string[] source = text.Split(' ');
		string text2 = source.FirstOrDefault().Substring(1);
		string[] array = source.Skip(1).ToArray();
		if (text2.ToUpperInvariant() == "GIMME" || text2.ToUpperInvariant() == "GI")
		{
			Chat.SendBroadcastChat((ChatMessageBase)new UserChatMessage
			{
				sender = ((Component)sender.networkUser).gameObject,
				text = text
			});
			if (array.Length < 2 || array[0] == "" || array[0].ToUpperInvariant() == "HELP")
			{
				Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
				{
					baseToken = "<color=#AAE6F0>/gi itemname playername [amount]\n/gimme itemname playername [amount]\n/gr [itemname] [amount]\n/gimmerandom [itemname] [amount]\nWill give items into playername's inventory"
				});
				return;
			}
			string text3 = Give.Give_item(sender.networkUser, array, log);
			if (text3 == null)
			{
				Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
				{
					baseToken = "<color=#ff4646>ERROR: null output</color>"
				});
			}
			else
			{
				Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
				{
					baseToken = text3
				});
			}
		}
		else if (text2.ToUpperInvariant() == "GR" || text2.ToUpperInvariant() == "GIMMERANDOM")
		{
			Chat.SendBroadcastChat((ChatMessageBase)new UserChatMessage
			{
				sender = ((Component)sender.networkUser).gameObject,
				text = text
			});
			string text4 = Give.Give_item_random(sender.networkUser, array, log);
			if (text4 == null)
			{
				Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
				{
					baseToken = "<color=#ff4646>ERROR: null output</color>"
				});
			}
			else
			{
				Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
				{
					baseToken = text4
				});
			}
		}
		else if (text2.ToUpperInvariant() == "GIMME_DUMP_ITEMS")
		{
			Give.Dump_items();
			Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
			{
				baseToken = "Gimme wrote a gimme_items.txt into your game's directory."
			});
		}
		else
		{
			orig.Invoke(self, sender, concommandName, userArgs);
		}
	}
}
internal class Give
{
	public const string green = "<color=#96EBAA>";

	public const string player = "<color=#AAE6F0>";

	public const string error = "<color=#FF8282>";

	public const string bold = "<color=#ff4646>";

	private static readonly Dictionary<ItemDef, int> RESTRICTED_ITEMS;

	static Give()
	{
		RESTRICTED_ITEMS = new Dictionary<ItemDef, int>();
		RESTRICTED_ITEMS.Add(Items.LunarDagger, 64);
		RESTRICTED_ITEMS.Add(Items.RandomEquipmentTrigger, 128);
		RESTRICTED_ITEMS.Add(Items.AttackSpeedAndMoveSpeed, 100);
		RESTRICTED_ITEMS.Add(Items.SprintBonus, 100);
		RESTRICTED_ITEMS.Add(Items.Hoof, 100);
		RESTRICTED_ITEMS.Add(Items.JumpBoost, 10);
		RESTRICTED_ITEMS.Add(Items.FallBoots, 10);
		RESTRICTED_ITEMS.Add(Items.AutoCastEquipment, 32);
		RESTRICTED_ITEMS.Add(Items.HalfAttackSpeedHalfCooldowns, 8);
		RESTRICTED_ITEMS.Add(Items.Talisman, 69);
		RESTRICTED_ITEMS.Add(Items.HalfSpeedDoubleHealth, 16);
	}

	public static string Give_item_random(NetworkUser sender, string[] args, ManualLogSource log)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		_ = sender.id;
		Inventory val = (((Object)(object)sender != (Object)null) ? sender.master.inventory : null);
		NetworkUser randomUser = StringParsers.GetRandomUser();
		Inventory val2 = (((Object)(object)randomUser != (Object)null) ? randomUser.master.inventory : null);
		if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2))
		{
			return "<color=#ff4646>ERROR: null inventory</color>";
		}
		int result = 1;
		if (args.Length == 2 && !int.TryParse(args[1], out result))
		{
			return "<color=#FF8282>Invalid quantity argument!</color>";
		}
		return _provide_item(sender, val, val2, randomUser, result, args, log);
	}

	private static string last(string[] arr)
	{
		return arr[^1];
	}

	public static string Give_item(NetworkUser sender, string[] args, ManualLogSource log)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		_ = sender.id;
		Inventory val = (((Object)(object)sender != (Object)null) ? sender.master.inventory : null);
		NetworkUser netUserFromString = StringParsers.GetNetUserFromString(args[1]);
		if ((Object)(object)netUserFromString == (Object)null)
		{
			return "<color=#FF8282>Could not find specified </color>player<color=#FF8282> '<color=#ff4646>" + args[1] + "</color>'</color>";
		}
		Inventory val2 = (((Object)(object)netUserFromString != (Object)null) ? netUserFromString.master.inventory : null);
		if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2))
		{
			return "<color=#ff4646>ERROR: null inventory</color>";
		}
		int result = 1;
		if (args.Length == 3 && !int.TryParse(args[2], out result))
		{
			return "<color=#FF8282>Invalid quantity argument!</color>";
		}
		return _provide_item(sender, val, val2, netUserFromString, result, args, log);
	}

	public static string _provide_item(NetworkUser sender, Inventory inventory1, Inventory inventory2, NetworkUser netUserFromString, int num, string[] args, ManualLogSource log)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Invalid comparison between Unknown and I4
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Invalid comparison between Unknown and I4
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Invalid comparison between Unknown and I4
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Invalid comparison between Unknown and I4
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		string text = "<color=#AAE6F0>" + netUserFromString.masterController.GetDisplayName() + "</color>";
		string text2 = "<color=#AAE6F0>" + sender.masterController.GetDisplayName() + "</color>";
		ItemIndex val = (ItemIndex)(-1);
		if (args.Length == 0)
		{
			val = StringParsers.RandomItem();
		}
		else
		{
			if ((args[0].ToLower() == "e" || args[0].ToLower() == "equip" || args[0].ToLower() == "equipment") && (int)inventory1.GetEquipmentIndex() == -1)
			{
				return "<color=#FF8282>Sender does not have an </color><color=#ff7d00>equipment</color>";
			}
			if ((int)val == -1)
			{
				val = StringParsers.FindItem(args[0], log);
			}
		}
		if ((int)val == -1)
		{
			return "<color=#FF8282>Could not find specified </color>item<color=#FF8282> '<color=#ff4646>" + args[0] + "</color>'</color>";
		}
		ItemDef itemDef = ItemCatalog.GetItemDef(val);
		PickupIndex val2 = PickupCatalog.FindPickupIndex(val);
		string text3 = Util.GenerateColoredString(Language.GetString(itemDef.nameToken), Color32.op_Implicit(PickupCatalog.GetPickupDef(val2).baseColor));
		if ((Object)(object)itemDef == (Object)(object)Items.CaptainDefenseMatrix || ((int)itemDef.tier == 5 && (Object)(object)itemDef != (Object)(object)Items.ExtraLifeConsumed && (Object)(object)itemDef != (Object)(object)Items.ExtraLifeVoidConsumed && (Object)(object)itemDef != (Object)(object)Items.FragileDamageBonusConsumed && (Object)(object)itemDef != (Object)(object)Items.HealingPotionConsumed && (Object)(object)itemDef != (Object)(object)Items.RegeneratingScrapConsumed))
		{
			return text3 + "<color=#FF8282> is not dropable</color>";
		}
		if (RESTRICTED_ITEMS.ContainsKey(itemDef))
		{
			int itemCount = inventory2.GetItemCount(itemDef);
			int num2 = RESTRICTED_ITEMS[itemDef];
			if (num >= num2)
			{
				return "<color=#FF8282>Too much of item requested, the limit is '" + (num2 - 1) + "'.</color>";
			}
			if (itemCount + num >= num2)
			{
				return "<color=#FF8282>Player already has too much of item.</color>";
			}
		}
		if (num > 1)
		{
			text3 += Util.GenerateColoredString("s", Color32.op_Implicit(PickupCatalog.GetPickupDef(val2).baseColor));
		}
		if (num > 1024)
		{
			num = 1024;
		}
		inventory2.GiveItem(val, num);
		if ((Object)(object)inventory1 != (Object)(object)inventory2)
		{
			inventory1.RemoveItem(val, num);
		}
		if (text.Equals(text2))
		{
			return string.Format("{0}{1} gave themselves {2} {3}</color>", "<color=#96EBAA>", text2, num, text3);
		}
		return string.Format("{0}{1} gave {2} {3} to </color>{4}", "<color=#96EBAA>", text2, num, text3, text);
	}

	internal static void Dump_items()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Expected I4, but got Unknown
		using StreamWriter streamWriter = new StreamWriter("gimme_items.txt");
		streamWriter.WriteLine("// Gimme FORMAT_ONE");
		AllItemsEnumerator enumerator = ItemCatalog.allItems.GetEnumerator();
		try
		{
			while (((AllItemsEnumerator)(ref enumerator)).MoveNext())
			{
				ItemIndex current = ((AllItemsEnumerator)(ref enumerator)).Current;
				ItemDef itemDef = ItemCatalog.GetItemDef(current);
				string @string = Language.GetString(itemDef.nameToken);
				string text = "";
				text += "{index:";
				text += ((object)(ItemIndex)(ref current)).ToString();
				text += ",tier:";
				text += (int)itemDef.tier;
				text += ",nameToken:\"";
				text += ((Object)itemDef).name;
				text += "\",localizedName:\"";
				text += @string;
				text += "\"}";
				streamWriter.WriteLine(text);
			}
		}
		finally
		{
			((IDisposable)(AllItemsEnumerator)(ref enumerator)).Dispose();
		}
	}
}
internal sealed class StringParsers
{
	private static readonly Random rng = new Random();

	internal static ItemIndex FindItemInInventory(string input, Inventory inventory)
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: 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)
		List<ItemIndex> itemAcquisitionOrder = inventory.itemAcquisitionOrder;
		if (!itemAcquisitionOrder.Any())
		{
			return (ItemIndex)(-1);
		}
		input = ReformatString(input);
		if (int.TryParse(input, out var result))
		{
			if (result > itemAcquisitionOrder.Count || result < 0)
			{
				return (ItemIndex)(-1);
			}
			if (result == 0)
			{
				return itemAcquisitionOrder[itemAcquisitionOrder.Count - 1];
			}
			return itemAcquisitionOrder[itemAcquisitionOrder.Count - result];
		}
		for (int num = itemAcquisitionOrder.Count - 1; num >= 0; num--)
		{
			ItemDef itemDef = ItemCatalog.GetItemDef(itemAcquisitionOrder[num]);
			if (ReformatString(Language.GetString(itemDef.nameToken)).Contains(input))
			{
				return itemDef.itemIndex;
			}
		}
		return (ItemIndex)(-1);
	}

	public static EquipmentIndex GetEquipFromPartial(string name)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		name = ReformatString(name);
		EquipmentDef[] equipmentDefs = EquipmentCatalog.equipmentDefs;
		foreach (EquipmentDef val in equipmentDefs)
		{
			if (ReformatString(Language.GetString(val.nameToken)).Contains(name))
			{
				return val.equipmentIndex;
			}
		}
		return (EquipmentIndex)(-1);
	}

	internal static NetworkUser GetRandomUser()
	{
		return NetworkUser.readOnlyInstancesList[rng.Next(NetworkUser.readOnlyInstancesList.Count)];
	}

	internal static NetworkUser GetNetUserFromString(string name)
	{
		if (int.TryParse(name, out var result))
		{
			if (result < NetworkUser.readOnlyInstancesList.Count && result >= 0)
			{
				return NetworkUser.readOnlyInstancesList[result];
			}
			return null;
		}
		name = ReformatString(name);
		foreach (NetworkUser readOnlyInstances in NetworkUser.readOnlyInstancesList)
		{
			if (ReformatString(readOnlyInstances.userName).StartsWith(name))
			{
				return readOnlyInstances;
			}
		}
		foreach (NetworkUser readOnlyInstances2 in NetworkUser.readOnlyInstancesList)
		{
			if (ReformatString(readOnlyInstances2.userName).Contains(name))
			{
				return readOnlyInstances2;
			}
		}
		return null;
	}

	internal static string ReformatString(string input)
	{
		return Regex.Replace(input, "[ '_.,-]", string.Empty).ToLower();
	}

	internal static ItemIndex RandomItem()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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)
		int index = rng.Next(((IEnumerable<ItemIndex>)(object)ItemCatalog.allItems).Count());
		return ((IEnumerable<ItemIndex>)(object)ItemCatalog.allItems).AsParallel().DefaultIfEmpty((ItemIndex)(-1)).ElementAtOrDefault(index);
	}

	internal static ItemIndex FindItem(string item, ManualLogSource log)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		return (from candidate in ((IEnumerable<ItemIndex>)(object)ItemCatalog.allItems).AsParallel()
			where Language.GetString(ItemCatalog.GetItemDef(candidate).nameToken).IndexOf(item, StringComparison.OrdinalIgnoreCase) >= 0
			select candidate).DefaultIfEmpty((ItemIndex)(-1)).First();
	}
}
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);
	}
}