using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Assets.Scripts.Actors.Player;
using Assets.Scripts.Inventory__Items__Pickups;
using Assets.Scripts.Inventory__Items__Pickups.Weapons;
using Assets.Scripts.Saves___Serialization.Progression.Achievements;
using Assets.Scripts.Saves___Serialization.SaveFiles;
using Assets.Scripts.UI;
using Assets.Scripts._Data.ShopItems;
using Assets.Scripts._Data.Tomes;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("TomeAndWeaponSlotExpansion")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("TomeAndWeaponSlotExpansion")]
[assembly: AssemblyTitle("TomeAndWeaponSlotExpansion")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte flag)
{
NullableFlags = new byte[1] { flag };
}
public NullableAttribute(byte[] flags)
{
NullableFlags = flags;
}
}
}
namespace TomeAndWeaponSlotExpansion
{
[HarmonyPatch(typeof(InventoryUtility), "GetNumAvailableWeaponSlots")]
internal static class WeaponCapacityPatch
{
private static void Postfix(ref int __result)
{
__result = SlotRules.Capacity(__result, ExtraShop.Level((EShopItem)7462301));
}
}
[HarmonyPatch(typeof(InventoryUtility), "GetNumAvailableTomeSlots")]
internal static class TomeCapacityPatch
{
private static void Postfix(ref int __result)
{
__result = SlotRules.Capacity(__result, ExtraShop.Level((EShopItem)7462302));
}
}
internal static class ExtraShop
{
internal const EShopItem Weapons = (EShopItem)7462301;
internal const EShopItem Tomes = (EShopItem)7462302;
internal static bool IsExtra(ShopItemData? data)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Expected I4, but got Unknown
if ((Object)(object)data != (Object)null)
{
return SlotRules.IsExtra((int)data.eShopItem);
}
return false;
}
internal static int Level(EShopItem id)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
SaveManager instance = SaveManager.Instance;
ProgressionSaveFile val = ((instance != null) ? instance.progression : null);
if (((val != null) ? val.shopItems : null) == null || !val.shopItems.ContainsKey(id))
{
return 0;
}
return SlotRules.ClampLevel(val.shopItems[id]);
}
internal static void EnsureSaveEntries(ProgressionSaveFile? save)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: 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)
//IL_0058: 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)
if (((save != null) ? save.shopItems : null) == null)
{
return;
}
EShopItem[] array = (EShopItem[])(object)new EShopItem[2]
{
(EShopItem)7462301,
(EShopItem)7462302
};
foreach (EShopItem val in array)
{
if (!save.shopItems.ContainsKey(val))
{
save.shopItems.Add(val, 0);
}
else
{
save.shopItems[val] = SlotRules.ClampLevel(save.shopItems[val]);
}
}
}
internal static void Register(DataManager manager)
{
if (manager.shopItems != null)
{
Add(manager, (EShopItem)3, (EShopItem)7462301, "Extra Weapon Slots", 10000);
Add(manager, (EShopItem)4, (EShopItem)7462302, "Extra Tome Slots", 10001);
SaveManager instance = SaveManager.Instance;
EnsureSaveEntries((instance != null) ? instance.progression : null);
}
}
private static void Add(DataManager manager, EShopItem templateId, EShopItem id, string name, int order)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Expected O, but got Unknown
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Expected I4, but got Unknown
if (manager.shopItems.ContainsKey(id))
{
if (((Object)manager.shopItems[id]).name != name)
{
throw new InvalidOperationException($"Another shop item is using reserved ID {(int)id}.");
}
return;
}
ShopItemData val = Object.Instantiate<ShopItemData>(manager.GetShopItemData(templateId));
((Object)val).name = name;
val.eShopItem = id;
((UnlockableBase)val).price = 125;
val.linearIncrease = 0;
val.exponentialMultiplier = 1f;
val.maxLevel = 2;
val.value = 1f;
val.canRefund = true;
((UnlockableBase)val).isEnabled = true;
((UnlockableBase)val).showInUnlocks = false;
val.unlockRequirement = null;
val.sortingOrder = order;
manager.shopItems.Add(id, val);
ManualLogSource log = ((BasePlugin)Plugin.Instance).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(43, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Registered ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(name);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": two purchases at ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(125);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" silver each.");
}
log.LogInfo(val2);
}
}
[HarmonyPatch(typeof(DataManager), "Load")]
internal static class RegisterShopPatch
{
private static void Postfix(DataManager __instance)
{
ExtraShop.Register(__instance);
}
}
[HarmonyPatch(typeof(ShopWindow), "Start")]
internal static class ShopStartPatch
{
private static void Prefix()
{
ExtraShop.Register(DataManager.Instance);
}
}
[HarmonyPatch(typeof(ProgressionSaveFile), "Init")]
internal static class SaveInitPatch
{
private static void Postfix(ProgressionSaveFile __instance)
{
ExtraShop.EnsureSaveEntries(__instance);
}
}
[HarmonyPatch(typeof(UnlockableBase), "GetName")]
internal static class ShopNamePatch
{
private static bool Prefix(UnlockableBase __instance, ref string __result)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Invalid comparison between Unknown and I4
ShopItemData val = ((Il2CppObjectBase)__instance).TryCast<ShopItemData>();
if (!ExtraShop.IsExtra(val))
{
return true;
}
__result = (((int)val.eShopItem == 7462301) ? "Extra Weapon Slots" : "Extra Tome Slots");
return false;
}
}
[HarmonyPatch(typeof(UnlockableBase), "GetDescription")]
internal static class ShopDescriptionPatch
{
private static bool Prefix(UnlockableBase __instance, ref string __result)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Invalid comparison between Unknown and I4
ShopItemData val = ((Il2CppObjectBase)__instance).TryCast<ShopItemData>();
if (!ExtraShop.IsExtra(val))
{
return true;
}
string text = (((int)val.eShopItem == 7462301) ? "weapon" : "tome");
__result = "Carry one additional " + text + " per purchase. Two extra slots available, 125 silver each.\nMochiFlow Mod";
return false;
}
}
[HarmonyPatch(typeof(ProgressionSaveFile), "PurchaseShopItem")]
internal static class PurchaseSavePatch
{
private static void Prefix(ProgressionSaveFile __instance, ShopItemData shopItemData)
{
if (ExtraShop.IsExtra(shopItemData))
{
ExtraShop.EnsureSaveEntries(__instance);
}
}
private static void Postfix(ShopItemData shopItemData, bool __result)
{
if (__result && ExtraShop.IsExtra(shopItemData))
{
SaveManager.Instance.SaveProgression();
}
}
}
[HarmonyPatch(typeof(ProgressionSaveFile), "RefundShopItem")]
internal static class RefundSavePatch
{
private static void Postfix(ShopItemData shopItemData, bool __result)
{
if (__result && ExtraShop.IsExtra(shopItemData))
{
SaveManager.Instance.SaveProgression();
}
}
}
internal static class InventoryDisplay
{
internal static void Refresh(GameObject prefab, Transform weaponParent, Transform tomeParent, List<InventoryItemPrefabUI> weapons, List<InventoryItemPrefabUI> tomes, Transform root)
{
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
MyPlayer instance = MyPlayer.Instance;
PlayerInventory val = ((instance != null) ? instance.inventory : null);
if (val != null && val.weaponInventory != null && val.tomeInventory != null)
{
List<UnlockableBase> list = new List<UnlockableBase>();
Enumerator<EWeapon, WeaponBase> enumerator = val.weaponInventory.weapons.GetEnumerator();
while (enumerator.MoveNext())
{
KeyValuePair<EWeapon, WeaponBase> current = enumerator.Current;
list.Add((UnlockableBase)(object)current.Value.weaponData);
}
List<UnlockableBase> list2 = new List<UnlockableBase>();
Enumerator<ETome, int> enumerator2 = val.tomeInventory.tomeLevels.GetEnumerator();
while (enumerator2.MoveNext())
{
KeyValuePair<ETome, int> current2 = enumerator2.Current;
list2.Add((UnlockableBase)(object)DataManager.Instance.GetTome(current2.Key));
}
Extend(prefab, weaponParent, weapons, list, InventoryUtility.GetNumAvailableWeaponSlots());
Extend(prefab, tomeParent, tomes, list2, InventoryUtility.GetNumAvailableTomeSlots());
UiUtility.RebuildUi(root);
}
}
private static void Extend(GameObject prefab, Transform parent, List<InventoryItemPrefabUI> slots, List<UnlockableBase> items, int capacity)
{
if ((Object)(object)prefab == (Object)null || (Object)(object)parent == (Object)null || slots == null)
{
return;
}
int num = Math.Max(capacity, items.Count);
while (slots.Count < num)
{
slots.Add(Object.Instantiate<GameObject>(prefab, parent).GetComponent<InventoryItemPrefabUI>());
}
for (int i = 4; i < slots.Count; i++)
{
InventoryItemPrefabUI val = slots[i];
((Component)val).gameObject.SetActive(i < num);
if (i < num)
{
val.SetItem((i < items.Count) ? items[i] : null);
}
}
}
}
[HarmonyPatch(typeof(InventoryHud), "Refresh")]
internal static class HudSlotsPatch
{
private static void Postfix(InventoryHud __instance)
{
InventoryDisplay.Refresh(__instance.itemContainerPrefab, __instance.weaponParent, __instance.tomeParent, __instance.weaponContainers, __instance.tomeContainers, ((Component)__instance).transform);
}
}
[HarmonyPatch(typeof(UpgradeInventoryUI), "Refresh")]
internal static class UpgradeSlotsPatch
{
private static void Postfix(UpgradeInventoryUI __instance)
{
InventoryDisplay.Refresh(__instance.itemContainerPrefab, __instance.weaponParent, __instance.tomeParent, __instance.weaponContainers, __instance.tomeContainers, ((Component)__instance).transform);
}
}
[BepInPlugin("mochiflow.tomeandweaponslotexpansion", "Tome and Weapon Slot Expansion", "1.0.1")]
public sealed class Plugin : BasePlugin
{
public const string Id = "mochiflow.tomeandweaponslotexpansion";
public const string Version = "1.0.1";
private Harmony? harmony;
internal static Plugin Instance { get; private set; }
public override void Load()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Expected O, but got Unknown
Instance = this;
harmony = new Harmony("mochiflow.tomeandweaponslotexpansion");
harmony.PatchAll(typeof(Plugin).Assembly);
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(93, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Slot Expansion ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.1");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded. Two extra weapon slots and two extra tome slots; 125 silver per slot.");
}
log.LogInfo(val);
}
}
internal static class ShopCardStyle
{
private static readonly Color Gold = new Color(1f, 0.78f, 0.2f, 1f);
private static readonly Dictionary<int, Color> OriginalColors = new Dictionary<int, Color>();
internal static void Apply(ShopContainer container)
{
bool extra = ExtraShop.IsExtra(container.data);
Tint(((Component)container).GetComponent<Image>(), extra);
Transform obj = ((Component)container).transform.Find("Border");
Tint((obj != null) ? ((Component)obj).GetComponent<Image>() : null, extra);
Transform levelsParent = container.levelsParent;
Tint((levelsParent != null) ? ((Component)levelsParent).GetComponent<Image>() : null, extra);
}
private static void Tint(Image? image, bool extra)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: 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)
if (!((Object)(object)image == (Object)null))
{
int instanceID = ((Object)image).GetInstanceID();
Color value;
if (extra)
{
OriginalColors.TryAdd(instanceID, ((Graphic)image).color);
((Graphic)image).color = Gold;
}
else if (OriginalColors.Remove(instanceID, out value))
{
((Graphic)image).color = value;
}
}
}
}
[HarmonyPatch(typeof(ShopContainer), "Set")]
internal static class ShopCardStylePatch
{
private static void Postfix(ShopContainer __instance)
{
ShopCardStyle.Apply(__instance);
}
}
internal static class SlotRules
{
internal const int Price = 125;
internal const int PurchaseLimit = 2;
internal const int WeaponId = 7462301;
internal const int TomeId = 7462302;
internal static bool IsExtra(int id)
{
if (id != 7462301)
{
return id == 7462302;
}
return true;
}
internal static int ClampLevel(int level)
{
return Math.Clamp(level, 0, 2);
}
internal static int Capacity(int original, int purchased)
{
if (original > 1)
{
return original + ClampLevel(purchased);
}
return original;
}
}
}