using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CWMoreSlots")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CWMoreSlots")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("77da3c93-925f-4b4c-92c1-cf367a7b760a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MoreSlotsMod;
[ContentWarningPlugin("com.reblazer.moreslots", "1.0.0", false)]
[BepInPlugin("com.reblazer.moreslots", "More Slots", "1.0.0")]
public class MoreSlotsPlugin : BaseUnityPlugin
{
public static ManualLogSource ModLogger;
private void Awake()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
ModLogger = ((BaseUnityPlugin)this).Logger;
Harmony val = new Harmony("com.reblazer.moreslots");
val.PatchAll();
ModLogger.LogInfo((object)"ReBlazeR's More Slots Mod has been loaded successfully!");
}
}
public static class Refl
{
public static void SilentWrite(object target, object value)
{
if (target == null || value == null)
{
return;
}
List<FieldInfo> declaredFields = AccessTools.GetDeclaredFields(target.GetType());
foreach (FieldInfo item in declaredFields)
{
if (item.FieldType == value.GetType())
{
item.SetValue(target, value);
break;
}
}
}
public static void ExpandVisuals(object target)
{
if (target == null)
{
return;
}
List<FieldInfo> declaredFields = AccessTools.GetDeclaredFields(target.GetType());
foreach (FieldInfo item in declaredFields)
{
if (item.FieldType == typeof(Transform[]))
{
Transform[] array = (Transform[])item.GetValue(target);
if (array != null && array.Length == 3)
{
List<Transform> list = array.ToList();
list.Add(array[0]);
list.Add(array[0]);
item.SetValue(target, list.ToArray());
}
}
}
}
}
[HarmonyPatch(typeof(Player), "Start")]
public class InitPatch
{
private static void Postfix(Player __instance)
{
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Expected O, but got Unknown
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Expected O, but got Unknown
if (__instance.IsLocal)
{
PlayerInventory val = default(PlayerInventory);
if (__instance.TryGetInventory(ref val) && val.slots.Length < 5)
{
InventorySlot[] slots = val.slots;
InventorySlot[] slots2 = (InventorySlot[])(object)new InventorySlot[5]
{
slots[0],
slots[1],
slots[2],
new InventorySlot(3, val),
new InventorySlot(4, val)
};
val.slots = slots2;
MoreSlotsPlugin.ModLogger.LogInfo((object)"Inventory memory expanded to 5 slots.");
}
Refl.ExpandVisuals(__instance);
if (__instance.data != null)
{
Refl.ExpandVisuals(__instance.data);
}
PlayerItems component = ((Component)__instance).GetComponent<PlayerItems>();
if ((Object)(object)component != (Object)null)
{
Refl.ExpandVisuals(component);
}
}
}
}
[HarmonyPatch(typeof(Player), "Update")]
public class InputPatch
{
private static void Postfix(Player __instance)
{
if (!((Object)(object)__instance != (Object)(object)Player.localPlayer) && GlobalInputHandler.CanTakeInput())
{
if (Input.GetKeyDown((KeyCode)52))
{
__instance.data.selectedItemSlot = ((__instance.data.selectedItemSlot == 3) ? (-1) : 3);
}
if (Input.GetKeyDown((KeyCode)53))
{
__instance.data.selectedItemSlot = ((__instance.data.selectedItemSlot == 4) ? (-1) : 4);
}
}
}
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
public class ForcePatch
{
private static bool Prefix(PlayerInventory __instance, ItemDescriptor item, ref bool __result, ref InventorySlot slot)
{
//IL_0015: 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_011e: Unknown result type (might be due to invalid IL or missing references)
InventorySlot val = null;
InventorySlot[] slots = __instance.slots;
foreach (InventorySlot val2 in slots)
{
if ((Object)(object)val2.ItemInSlot.item == (Object)null)
{
val = val2;
break;
}
}
if (val == null)
{
return true;
}
if (val.SlotID <= 2)
{
return true;
}
try
{
Refl.SilentWrite(val, item);
slot = val;
__result = true;
Player component = ((Component)__instance).GetComponent<Player>();
if ((Object)(object)component != (Object)null && component.data.isLocal && component.data.selectedItemSlot == val.SlotID)
{
PlayerItems component2 = ((Component)component).GetComponent<PlayerItems>();
if ((Object)(object)component2 != (Object)null)
{
MethodInfo methodInfo = AccessTools.Method(typeof(PlayerItems), "EquipItem", new Type[1] { typeof(ItemDescriptor) }, (Type[])null);
if (methodInfo != null)
{
methodInfo.Invoke(component2, new object[1] { item });
}
}
}
return false;
}
catch (Exception ex)
{
MoreSlotsPlugin.ModLogger.LogWarning((object)("Force Add Error: " + ex.Message));
return true;
}
}
}
[HarmonyPatch(typeof(PlayerInventory), "TryGetSlot")]
public class GetSlotPatch
{
private static bool Prefix(PlayerInventory __instance, int slotID, ref bool __result, ref InventorySlot slot)
{
if (slotID >= 0 && slotID < __instance.slots.Length)
{
slot = __instance.slots[slotID];
__result = true;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(HotbarUI), "Set")]
public class HotbarFix
{
private static void Prefix(HotbarUI __instance)
{
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
if (__instance.slots.Length < 5)
{
HotbarSlotUI[] slots = __instance.slots;
HotbarSlotUI val = slots[2];
Transform parent = ((Component)val).transform.parent;
GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, parent);
GameObject val3 = Object.Instantiate<GameObject>(((Component)val).gameObject, parent);
((Object)val2).name = "SlotUI_3";
((Object)val3).name = "SlotUI_4";
TryChangeTextReflected(val2, "4");
TryChangeTextReflected(val3, "5");
HotbarSlotUI component = val2.GetComponent<HotbarSlotUI>();
HotbarSlotUI component2 = val3.GetComponent<HotbarSlotUI>();
__instance.slots = (HotbarSlotUI[])(object)new HotbarSlotUI[5]
{
slots[0],
slots[1],
slots[2],
component,
component2
};
RectTransform component3 = ((Component)parent).GetComponent<RectTransform>();
if ((Object)(object)component3 != (Object)null)
{
component3.sizeDelta = new Vector2(component3.sizeDelta.x + 130f, component3.sizeDelta.y);
}
}
}
private static void TryChangeTextReflected(GameObject go, string newText)
{
Component[] componentsInChildren = go.GetComponentsInChildren<Component>();
Component[] array = componentsInChildren;
foreach (Component val in array)
{
if (!(((object)val).GetType().Name == "TextMeshProUGUI"))
{
continue;
}
PropertyInfo propertyInfo = AccessTools.Property(((object)val).GetType(), "text");
if (propertyInfo != null)
{
string text = (string)propertyInfo.GetValue(val);
if (text.Length <= 2)
{
propertyInfo.SetValue(val, newText);
}
}
}
}
}