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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("ItemEveryStage")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e0448dde05052bf7475eef9fd857fbb759f8c070")]
[assembly: AssemblyProduct("ItemEveryStage")]
[assembly: AssemblyTitle("ItemEveryStage")]
[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 ItemEveryStage
{
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("Lawlzee.ItemEveryStage", "ItemEveryStage", "1.0.1")]
public class ItemEveryStagePlugin : BaseUnityPlugin
{
private class ItemGift
{
public ItemIndex ItemIndex { get; }
public int Quantity { get; }
public ItemGift(ItemIndex itemIndex, int quantity)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
ItemIndex = itemIndex;
Quantity = quantity;
}
}
public const string PluginGUID = "Lawlzee.ItemEveryStage";
public const string PluginAuthor = "Lawlzee";
public const string PluginName = "ItemEveryStage";
public const string PluginVersion = "1.0.1";
private const string _itemsToGiveDescription = "Controls which items are given at every stage.\r\n\r\nFormat:\r\n<count>:<item>,<count>:<item>...\r\n\r\nExamples:\r\n2:hoof\r\n1:clover,3:firework\r\n\r\nAll the items are:\r\n";
private ConfigEntry<bool> _modEnabled;
private ConfigEntry<string> _itemsToGive;
private StringInputFieldOption _itemsToGiveOption;
private int _oldStageCount;
public void Awake()
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Expected O, but got Unknown
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Expected O, but got Unknown
Log.Init(((BaseUnityPlugin)this).Logger);
_modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Configuration", "Mod enabled", true, "Mod enabled");
ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_modEnabled));
_itemsToGive = ((BaseUnityPlugin)this).Config.Bind<string>("Configuration", "Items given at every stage", "1:Hoof", "Controls which items are given at every stage.\r\n\r\nFormat:\r\n<count>:<item>,<count>:<item>...\r\n\r\nExamples:\r\n2:hoof\r\n1:clover,3:firework\r\n\r\nAll the items are:\r\n");
_itemsToGiveOption = new StringInputFieldOption(_itemsToGive);
ModSettingsManager.AddOption((BaseOption)(object)_itemsToGiveOption);
Texture2D val = LoadTexture("icon.png");
ModSettingsManager.SetModIcon(Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0f, 0f)));
Run.onRunStartGlobal += Run_onRunStartGlobal;
Stage.onServerStageBegin += Stage_onServerStageBegin;
ItemCatalog.Init += new hook_Init(ItemCatalog_Init);
}
private void ItemCatalog_Init(orig_Init orig)
{
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Expected O, but got Unknown
orig.Invoke();
if (_modEnabled.Value)
{
IOrderedEnumerable<string> values = from x in ItemCatalog.itemDefs
select Language.GetString(x.nameToken) + ": '" + ((Object)x).name + "'" into x
orderby x
select x;
string text = string.Join(Environment.NewLine, values);
((BaseOption)_itemsToGiveOption).SetDescription("Controls which items are given at every stage.\r\n\r\nFormat:\r\n<count>:<item>,<count>:<item>...\r\n\r\nExamples:\r\n2:hoof\r\n1:clover,3:firework\r\n\r\nAll the items are:\r\n" + text, new BaseOptionConfig());
}
}
private Texture2D LoadTexture(string name)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
//IL_002a: Expected O, but got Unknown
Texture2D val = new Texture2D(2, 2);
ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), name)));
return val;
}
private void Run_onRunStartGlobal(Run obj)
{
if (_modEnabled.Value)
{
_oldStageCount = -1;
Log.Debug("Run_onRunStartGlobal");
}
}
private void Stage_onServerStageBegin(Stage obj)
{
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
if (!_modEnabled.Value)
{
return;
}
Log.Debug("Stage_onServerStageBegin");
int stageClearCount = Run.instance.stageClearCount;
if (_oldStageCount != stageClearCount)
{
foreach (CharacterMaster readOnlyInstances in CharacterMaster.readOnlyInstancesList)
{
if (!Object.op_Implicit((Object)(object)readOnlyInstances.playerCharacterMasterController) || !Object.op_Implicit((Object)(object)readOnlyInstances.playerCharacterMasterController.networkUser))
{
continue;
}
foreach (ItemGift itemGift in GetItemGifts())
{
readOnlyInstances.inventory.GiveItem(itemGift.ItemIndex, itemGift.Quantity);
GenericPickupController.SendPickupMessage(readOnlyInstances, PickupCatalog.FindPickupIndex(itemGift.ItemIndex));
}
}
}
_oldStageCount = stageClearCount;
}
private IEnumerable<ItemGift> GetItemGifts()
{
string[] array = _itemsToGive.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
string[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
string[] array3 = array2[i].Split(new char[1] { ':' }, StringSplitOptions.RemoveEmptyEntries);
if (array3.Length != 2)
{
continue;
}
string s = array3[0].Trim();
string item = array3[1].Trim();
if (!int.TryParse(s, out var quantityValue))
{
continue;
}
ItemDef[] itemDefs = ItemCatalog.itemDefs;
foreach (ItemDef val in itemDefs)
{
if (item.Equals(((Object)val).name, StringComparison.OrdinalIgnoreCase))
{
yield return new ItemGift(val.itemIndex, quantityValue);
}
}
}
}
}
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);
}
}
}