using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using SSSGame;
using SandSailorStudio.Inventory;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("blacks7ar")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("KarviExpandedStorage")]
[assembly: AssemblyTitle("KarviExpandedStorage")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.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;
}
}
[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 KarviExpandedStorage
{
[BepInPlugin("blacks7ar.KarviExpandedStorage", "KarviExpandedStorage", "1.0.0")]
public class Plugin : BasePlugin
{
[HarmonyPatch]
private static class Patches
{
private static readonly Dictionary<IntPtr, int> _OriginalValue = new Dictionary<IntPtr, int>();
private static readonly Dictionary<IntPtr, int> LastAppliedCount = new Dictionary<IntPtr, int>();
private static readonly Dictionary<IntPtr, int> OriginalQuantity = new Dictionary<IntPtr, int>();
[HarmonyPostfix]
[HarmonyPatch(typeof(ItemContainerComponent), "Initialize")]
private static void Initialize_Postfix(ItemContainerComponent __instance)
{
object obj;
if (__instance == null)
{
obj = null;
}
else
{
ItemContainer container = __instance.container;
obj = ((container != null) ? container.containerType : null);
}
if ((Object)obj == (Object)null || (Object)(object)__instance.inventoryComponent == (Object)null)
{
return;
}
ItemContainerType containerType = __instance.container.containerType;
string name = ((Object)containerType).name;
Il2CppReferenceArray<StorageClassData> storageClasses = containerType.storageClasses;
if (storageClasses == null)
{
return;
}
IntPtr pointer = ((Il2CppObjectBase)containerType).Pointer;
switch (name)
{
case "Storage_SmallItems_Karvi":
{
int value = _smallMultiplier.Value;
{
foreach (StorageClassData item in (Il2CppArrayBase<StorageClassData>)(object)storageClasses)
{
if (!_OriginalValue.TryGetValue(pointer, out var value2))
{
value2 = item.stackSize;
_OriginalValue[pointer] = value2;
}
int stackSize = value2 * value;
item.stackSize = stackSize;
}
break;
}
}
case "Storage_MediumItems_Karvi":
{
int value = _mediumMultiplier.Value;
{
foreach (StorageClassData item2 in (Il2CppArrayBase<StorageClassData>)(object)storageClasses)
{
if (!_OriginalValue.TryGetValue(pointer, out var value4))
{
value4 = item2.stackSize;
_OriginalValue[pointer] = value4;
}
int stackSize3 = value4 * value;
item2.stackSize = stackSize3;
}
break;
}
}
case "Storage_LargeItems_Karvi":
{
int value = _largeMultiplier.Value;
{
foreach (StorageClassData item3 in (Il2CppArrayBase<StorageClassData>)(object)storageClasses)
{
if (!_OriginalValue.TryGetValue(pointer, out var value3))
{
value3 = item3.stackSize;
_OriginalValue[pointer] = value3;
}
int stackSize2 = value3 * value;
item3.stackSize = stackSize2;
}
break;
}
}
case "Storage_Water":
if ((Object)(object)__instance.inventoryComponent != (Object)null)
{
__instance.container.capacity = _waterVolume.Value;
}
break;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(LootSpawner), "SpawnLootStack")]
private static void SpawnLootStack_Postfix(LootSpawner __instance, LootData loot, int stackIndex)
{
if (_IsExpandedBuildingModInstalled || _IsStackSizeModInstalled || loot == null)
{
return;
}
loot.spawnChance = 1f;
HarvestInteraction harvestInteraction = __instance.harvestInteraction;
if ((Object)(object)harvestInteraction == (Object)null || (Object)(object)harvestInteraction._itemComponent == (Object)null || harvestInteraction._itemComponent.ItemInstance == null)
{
return;
}
int count = harvestInteraction._itemComponent.ItemInstance.count;
IntPtr pointer = ((Il2CppObjectBase)loot).Pointer;
Il2CppStructArray<int> stacks = loot.stacks;
if (stacks == null || ((Il2CppArrayBase<int>)(object)stacks).Count == 0)
{
return;
}
Il2CppStructArray<int> val = new Il2CppStructArray<int>((long)((Il2CppArrayBase<int>)(object)stacks).Length);
for (int i = 0; i < ((Il2CppArrayBase<int>)(object)stacks).Length; i++)
{
if (!OriginalQuantity.TryGetValue(pointer, out var value))
{
value = ((Il2CppArrayBase<int>)(object)stacks)[i];
OriginalQuantity[pointer] = value;
}
if (LastAppliedCount.TryGetValue(pointer, out var value2) && value2 == count)
{
return;
}
int num = ((count != 1) ? (value * count) : value);
((Il2CppArrayBase<int>)(object)val)[i] = num;
}
LastAppliedCount[pointer] = count;
loot.stacks = val;
}
}
private static class Helper
{
public static bool CheckExpandedBuildingStorage()
{
if (!((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("blacks7ar.ExpandedBuildingStorage"))
{
return false;
}
KLogger.LogInfo((object)"ExpandedBuildingStorage mod detected, skipping spawn loot patch..");
return true;
}
public static bool CheckStackSizeMod()
{
if (!((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("blacks7ar.StackSizeMultiplier"))
{
return false;
}
KLogger.LogInfo((object)"ExpandedBuildingStorage mod detected, skipping spawn loot patch..");
return true;
}
}
private const string modGUID = "blacks7ar.KarviExpandedStorage";
public const string modName = "KarviExpandedStorage";
public const string modAuthor = "blacks7ar";
public const string modVersion = "1.0.0";
private static ManualLogSource KLogger;
private static ConfigEntry<int> _smallMultiplier;
private static ConfigEntry<int> _mediumMultiplier;
private static ConfigEntry<int> _largeMultiplier;
private static ConfigEntry<int> _waterVolume;
private static bool _IsExpandedBuildingModInstalled;
private static bool _IsStackSizeModInstalled;
public override void Load()
{
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
KLogger = ((BasePlugin)this).Log;
KLogger.LogInfo((object)"Mod loaded!");
_smallMultiplier = ((BasePlugin)this).Config.Bind<int>("General", "Small Items", 10, "Stack multiplier for small items.");
_mediumMultiplier = ((BasePlugin)this).Config.Bind<int>("General", "Medium Items", 10, "Stack multiplier for Medium items.");
_largeMultiplier = ((BasePlugin)this).Config.Bind<int>("General", "Large Items", 5, "Stack multiplier for large items.");
_waterVolume = ((BasePlugin)this).Config.Bind<int>("General", "Water Capacity", 200, "Water capacity.");
_IsExpandedBuildingModInstalled = Helper.CheckExpandedBuildingStorage();
_IsStackSizeModInstalled = Helper.CheckStackSizeMod();
new Harmony("blacks7ar.KarviExpandedStorage").PatchAll();
}
}
}