using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HG;
using HG.Reflection;
using Microsoft.CodeAnalysis;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ExamplePlugin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ExamplePlugin")]
[assembly: AssemblyTitle("ExamplePlugin")]
[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 ExamplePlugin
{
internal static class CommandRegistration
{
internal static void RegisterAllConCommandsFromThisAssembly(Action<string> logInfo, Action<string> logWarn, Action<Exception> logErr)
{
try
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
List<MethodInfo> list = typeof(Console).GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Where(delegate(MethodInfo m)
{
ParameterInfo[] parameters = m.GetParameters();
if (parameters.Length != 1)
{
return false;
}
if (parameters[0].ParameterType != typeof(Assembly))
{
return false;
}
string text = m.Name.ToLowerInvariant();
return text.Contains("register") && (text.Contains("command") || text.Contains("concommand"));
}).ToList();
if (list.Count == 0)
{
logWarn("No Console method found that accepts (Assembly) for registering commands.");
return;
}
MethodInfo methodInfo = list.OrderByDescending((MethodInfo m) => m.IsStatic).First();
logInfo($"Found Console registration method: {methodInfo.DeclaringType.FullName}.{methodInfo.Name} (static={methodInfo.IsStatic})");
if (methodInfo.IsStatic)
{
methodInfo.Invoke(null, new object[1] { executingAssembly });
}
else
{
if ((Object)(object)Console.instance == (Object)null)
{
logWarn("Console.instance is null; cannot call instance registration method yet.");
return;
}
methodInfo.Invoke(Console.instance, new object[1] { executingAssembly });
}
logInfo("ConCommands registration invoked for this assembly.");
}
catch (Exception obj)
{
logErr(obj);
}
}
}
public static class Commands
{
[ConCommand(/*Could not decode attribute arguments.*/)]
public static void FindItem(ConCommandArgs args)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: 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_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: 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)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
if (!EnsureHost(args))
{
return;
}
if (args.userArgs == null || args.userArgs.Count < 1)
{
((ConCommandArgs)(ref args)).Log("Usage: find_item <text>");
return;
}
string text = string.Join(" ", args.userArgs).ToLowerInvariant();
int num = 0;
Enumerator<ItemDef> enumerator = ItemCatalog.allItemDefs.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
ItemDef current = enumerator.Current;
string text2 = (((Object)current).name ?? "").ToLowerInvariant();
string text3 = GetDisplayName(current).ToLowerInvariant();
if (text2.Contains(text) || text3.Contains(text))
{
((ConCommandArgs)(ref args)).Log("- " + ((Object)current).name + " | \"" + GetDisplayName(current) + "\"");
num++;
if (num >= 25)
{
break;
}
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
if (num == 0)
{
((ConCommandArgs)(ref args)).Log("No items matched '" + text + "'.");
}
}
[ConCommand(/*Could not decode attribute arguments.*/)]
public static void GiveItem(ConCommandArgs args)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
if (!EnsureHost(args))
{
return;
}
List<string> userArgs = args.userArgs;
if (userArgs == null || userArgs.Count < 2)
{
((ConCommandArgs)(ref args)).Log("Usage: give_item <count> <item...> [@all]");
return;
}
if (!int.TryParse(userArgs[0], out var result) || result == 0)
{
((ConCommandArgs)(ref args)).Log("Count must be a non-zero integer.");
((ConCommandArgs)(ref args)).Log("Usage: give_item <count> <item...> [@all]");
return;
}
List<string> list = userArgs.Skip(1).ToList();
bool flag = false;
for (int num = list.Count - 1; num >= 0; num--)
{
if (IsAllFlag(list[num]))
{
flag = true;
list.RemoveAt(num);
}
}
if (list.Count == 0)
{
((ConCommandArgs)(ref args)).Log("You must specify an item name.");
((ConCommandArgs)(ref args)).Log("Usage: give_item <count> <item...> [@all]");
return;
}
string text = string.Join(" ", list).Trim();
ItemDef val = ResolveItem(text);
if ((Object)(object)val == (Object)null)
{
((ConCommandArgs)(ref args)).Log("Item '" + text + "' not found. Try: find_item " + text);
return;
}
if (flag)
{
int num2 = 0;
foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
{
object obj;
if (instance == null)
{
obj = null;
}
else
{
CharacterMaster master = instance.master;
obj = ((master != null) ? master.inventory : null);
}
Inventory val2 = (Inventory)obj;
if (!((Object)(object)val2 == (Object)null))
{
val2.GiveItem(val.itemIndex, result);
num2++;
}
}
((ConCommandArgs)(ref args)).Log($"Gave {result}x \"{GetDisplayName(val)}\" to {num2} player(s).");
return;
}
object obj2 = ((ConCommandArgs)(ref args)).senderMaster;
if (obj2 == null)
{
PlayerCharacterMasterController? obj3 = PlayerCharacterMasterController.instances.FirstOrDefault();
obj2 = ((obj3 != null) ? obj3.master : null);
}
if (obj2 != null)
{
Inventory inventory = ((CharacterMaster)obj2).inventory;
if (inventory != null)
{
inventory.GiveItem(val.itemIndex, result);
}
}
((ConCommandArgs)(ref args)).Log($"Gave {result}x \"{GetDisplayName(val)}\".");
static bool IsAllFlag(string s)
{
if (!string.Equals(s, "@all", StringComparison.OrdinalIgnoreCase) && !string.Equals(s, "all", StringComparison.OrdinalIgnoreCase))
{
return string.Equals(s, "/all", StringComparison.OrdinalIgnoreCase);
}
return true;
}
}
private static bool EnsureHost(ConCommandArgs args)
{
if (!NetworkServer.active)
{
((ConCommandArgs)(ref args)).Log("Host only command.");
return false;
}
return true;
}
private static string GetDisplayName(ItemDef def)
{
if (!string.IsNullOrEmpty(def.nameToken))
{
return Language.GetString(def.nameToken);
}
return ((Object)def).name ?? "(unknown)";
}
private static ItemDef ResolveItem(string input)
{
//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_0023: 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_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
input = (input ?? "").Trim();
if (input.Length == 0)
{
return null;
}
Enumerator<ItemDef> enumerator = ItemCatalog.allItemDefs.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
ItemDef current = enumerator.Current;
if (string.Equals(((Object)current).name, input, StringComparison.OrdinalIgnoreCase))
{
return current;
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
string value = input.ToLowerInvariant();
enumerator = ItemCatalog.allItemDefs.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
ItemDef current2 = enumerator.Current;
string text = (((Object)current2).name ?? "").ToLowerInvariant();
string text2 = GetDisplayName(current2).ToLowerInvariant();
if (text.Contains(value) || text2.Contains(value))
{
return current2;
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
return null;
}
}
[BepInPlugin("BradenB.ItemSpawnCommands", "ItemSpawnCommands", "1.0.0")]
public class ExamplePlugin : BaseUnityPlugin
{
public const string PluginAuthor = "BradenB";
public const string PluginName = "ItemSpawnCommands";
public const string PluginVersion = "1.0.0";
public const string PluginGUID = "BradenB.ItemSpawnCommands";
private void Awake()
{
Log.Init(((BaseUnityPlugin)this).Logger);
((BaseUnityPlugin)this).Logger.LogInfo((object)"ExamplePlugin loaded");
}
}
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);
}
}
}