using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using Assets.Scripts.Inventory__Items__Pickups.Items;
using Assets.Scripts.Saves___Serialization.Progression.Achievements;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ChestLootOverride")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ae4eb2bca00af8a1c4407a3dade780d904d89265")]
[assembly: AssemblyProduct("ChestLootOverride")]
[assembly: AssemblyTitle("ChestLootOverride")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 ChestLootOverride
{
[BepInPlugin("com.Rofliex.ChestLootOverride", "ChestLootOverride", "2.0.0")]
public class ChestLootOverride : BasePlugin
{
[HarmonyPatch(typeof(ItemInventory), "AddItem", new Type[] { typeof(EItem) })]
public static class ItemInventoryAddItem1Patch
{
[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
public static void AddItem1Original(ItemInventory __instance, EItem eItem)
{
throw new NotImplementedException();
}
[HarmonyPrefix]
public static bool Prefix(ItemInventory __instance, ref EItem eItem)
{
Patc(ref eItem);
_itemToReplace = null;
return true;
}
}
[HarmonyPatch(typeof(ItemInventory), "AddItem", new Type[]
{
typeof(EItem),
typeof(int)
})]
public static class ItemInventoryAddItem2Patch
{
[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
public static void AddItem2Original(ItemInventory __instance, EItem eItem, int count)
{
throw new NotImplementedException();
}
[HarmonyPrefix]
public static bool Prefix(ItemInventory __instance, ref EItem eItem, ref int count)
{
Patc(ref eItem);
return true;
}
}
[HarmonyPatch(typeof(ChestOpening), "OpenChest")]
public static class ChestLootPatch
{
[HarmonyPrefix]
public static bool Prefix(ChestOpening __instance, ref ItemData itemData)
{
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Expected O, but got Unknown
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
//IL_006a: 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)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: 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)
//IL_007e: Expected O, but got Unknown
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: 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_008f: 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_00c9: Expected O, but got Unknown
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
if (!Instance._enableMod.Value)
{
return true;
}
bool flag = default(bool);
try
{
ManualLogSource log = ((BasePlugin)Instance).Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(14, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Opened chest #");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_chestOpenCount);
}
log.LogInfo(val);
if (_chestLootOverrides.TryGetValue(_chestOpenCount, out var value))
{
ManualLogSource log2 = ((BasePlugin)Instance).Log;
LogLevel val2 = (LogLevel)16;
LogLevel val3 = val2;
BepInExLogInterpolatedStringHandler val4 = new BepInExLogInterpolatedStringHandler(23, 1, val2, ref flag);
if (flag)
{
val4.AppendLiteral("Current override item: ");
val4.AppendFormatted<EItem>(value);
}
log2.Log(val3, val4);
ItemData item = DataManager.Instance.GetItem(value);
if (itemData.eItem != value)
{
ManualLogSource log3 = ((BasePlugin)Instance).Log;
val = new BepInExInfoLogInterpolatedStringHandler(34, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[OpenChest] Swapping Visuals: ");
BepInExInfoLogInterpolatedStringHandler obj = val;
ItemData obj2 = itemData;
((BepInExLogInterpolatedStringHandler)obj).AppendFormatted<string>(((obj2 != null) ? ((UnlockableBase)obj2).GetName() : null) ?? "NULL");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((UnlockableBase)item).GetName());
}
log3.LogInfo(val);
itemData = item;
__instance.itemData = item;
_itemToReplace = item.eItem;
}
}
}
catch (Exception ex)
{
ManualLogSource log4 = ((BasePlugin)Instance).Log;
BepInExErrorLogInterpolatedStringHandler val5 = new BepInExErrorLogInterpolatedStringHandler(24, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Error processing chest: ");
((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<Exception>(ex);
}
log4.LogError(val5);
}
return true;
}
}
public const string PluginGuid = "com.Rofliex.ChestLootOverride";
public const string PluginName = "ChestLootOverride";
public const string PluginVersion = "2.0.0";
public static ChestLootOverride Instance;
private static int _chestOpenCount;
private static Dictionary<int, EItem> _chestLootOverrides;
private Harmony _harmony;
private ConfigEntry<bool> _enableMod;
private static EItem? _itemToReplace;
public override void Load()
{
//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0206: Expected O, but got Unknown
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_0222: Expected O, but got Unknown
//IL_0262: Unknown result type (might be due to invalid IL or missing references)
//IL_0268: Expected O, but got Unknown
Instance = this;
_enableMod = ((BasePlugin)this).Config.Bind<bool>("General", "EnableMod", true, "Enable/disable the mod");
((BasePlugin)this).Config.Bind<string>("ChestOverrides", "Chest1Item", "CreditCardGreen", (ConfigDescription)null);
((BasePlugin)this).Config.Bind<string>("ChestOverrides", "Chest2Item", "SoulHarvester", (ConfigDescription)null);
((BasePlugin)this).Config.Bind<string>("ChestOverrides", "Chest3Item", "Anvil", (ConfigDescription)null);
((BasePlugin)this).Config.Bind<string>("ChestOverrides", "Chest4Item", "HolyBook", (ConfigDescription)null);
((BasePlugin)this).Config.Bind<string>("ChestOverrides", "Chest6Item", "Key", (ConfigDescription)null);
((BasePlugin)this).Config.Bind<string>("ChestOverrides", "Chest7Item", "CreditCardGreen", (ConfigDescription)null);
((BasePlugin)this).Config.Bind<string>("ChestOverrides", "Chest9Item", "SuckyMagnet", (ConfigDescription)null);
((BasePlugin)this).Config.Bind<string>("ChestOverrides", "Chest10Item", "Bonker", (ConfigDescription)null);
((BasePlugin)this).Config.Bind<string>("ChestOverrides", "Chest12Item", "Anvil", (ConfigDescription)null);
((BasePlugin)this).Config.Bind<string>("ChestOverrides", "Chest15Item", "LightningOrb", (ConfigDescription)null);
((BasePlugin)this).Config.Bind<string>("ChestOverrides", "Chest16Item", "Kevin", (ConfigDescription)null);
((BasePlugin)this).Config.Bind<string>("ChestOverrides", "Chest18Item", "GoldenShield", (ConfigDescription)null);
((BasePlugin)this).Config.Bind<string>("ChestOverrides", "Chest19Item", "OverpoweredLamp", (ConfigDescription)null);
_chestLootOverrides = new Dictionary<int, EItem>();
LoadChestOverridesFromConfig();
ChestOpening.A_ChestFinished += Action<ItemData>.op_Implicit((Action<ItemData>)OnChestFinished);
GameManager.A_RunStarted += Action.op_Implicit((Action)delegate
{
_chestOpenCount = 1;
_itemToReplace = null;
ChestLootOverride instance = Instance;
if (instance != null)
{
((BasePlugin)instance).Log.LogInfo((object)"Chest counter reset");
}
});
_harmony = new Harmony("com.Rofliex.ChestLootOverride");
_harmony.PatchAll();
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(15, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("ChestLootOverride");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("2.0.0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" initialized!");
}
log.LogInfo(val);
ManualLogSource log2 = ((BasePlugin)this).Log;
val = new BepInExInfoLogInterpolatedStringHandler(24, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Chest overrides loaded: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_chestLootOverrides.Count);
}
log2.LogInfo(val);
static void OnChestFinished(ItemData itemData)
{
_chestOpenCount++;
}
}
private void LoadChestOverridesFromConfig()
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Expected O, but got Unknown
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Expected O, but got Unknown
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
Regex regex = new Regex("^Chest(\\d+)Item$", RegexOptions.IgnoreCase);
List<ConfigDefinition> list = ((BasePlugin)this).Config.Keys.Where((ConfigDefinition key) => key.Section == "ChestOverrides").ToList();
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(22, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Found config entries: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(list.Count);
}
log.LogInfo(val);
foreach (ConfigDefinition item in list)
{
Match match = regex.Match(item.Key);
if (!match.Success || !int.TryParse(match.Groups[1].Value, out var result))
{
continue;
}
ConfigEntry<string> val2 = ((BasePlugin)this).Config.Bind<string>("ChestOverrides", item.Key, "None", $"Item for chest #{result}");
if (!(val2.Value != "None") || string.IsNullOrWhiteSpace(val2.Value))
{
continue;
}
if (Enum.TryParse<EItem>(val2.Value, ignoreCase: true, out EItem result2))
{
_chestLootOverrides[result] = result2;
ManualLogSource log2 = ((BasePlugin)this).Log;
val = new BepInExInfoLogInterpolatedStringHandler(10, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Chest #");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(result);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" → ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<EItem>(result2);
}
log2.LogInfo(val);
}
else
{
ManualLogSource log3 = ((BasePlugin)this).Log;
BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(33, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Invalid item name for chest #");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(result);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(": '");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(val2.Value);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("'");
}
log3.LogWarning(val3);
}
}
}
private static void Patc(ref EItem eItem)
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Expected O, but got Unknown
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Expected I4, but got Unknown
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
if (Instance._enableMod.Value && _itemToReplace.HasValue && _chestLootOverrides.TryGetValue(_chestOpenCount - 1, out var value))
{
ManualLogSource log = ((BasePlugin)Instance).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(33, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Replacing item in inventory: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<EItem?>(_itemToReplace);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<EItem>(value);
}
log.LogInfo(val);
eItem = (EItem)(int)value;
}
}
}
}