using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CartDuplicator.Patches;
using HarmonyLib;
using Photon.Pun;
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("CartDuplicator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CartDuplicator")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c3dd3bd7-b7d1-4490-ad3d-0422f13bcbfd")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CartDuplicator
{
[BepInPlugin("Bocon.CartDuplicator", "Cart Duplicator", "1.4.0")]
public class CartDuplicator : BaseUnityPlugin
{
private const string modGUID = "Bocon.CartDuplicator";
private const string modeName = "Cart Duplicator";
private const string modVersion = "1.4.0";
private readonly Harmony harmony = new Harmony("Bocon.CartDuplicator");
private static CartDuplicator Instance;
internal ManualLogSource mls;
private ConfigEntry<Vector3> duplicationOffset;
private ConfigEntry<int> duplicationAmount;
private ConfigEntry<bool> smallCartReplacement;
private ConfigEntry<bool> dynamicSpawning;
private void Awake()
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Expected O, but got Unknown
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("Bocon.CartDuplicator");
duplicationOffset = ((BaseUnityPlugin)this).Config.Bind<Vector3>("General", "DuplicationOffset", new Vector3(2f, 0f, 0f), "Offset for the duplicated cart position");
duplicationAmount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "DuplicationAmount", 1, new ConfigDescription("Number of additional carts to duplicate", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
smallCartReplacement = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "SmallCartReplacement", false, "Replace the duplicated carts with the pocket C.A.R.T.");
dynamicSpawning = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DynamicSpawning", false, "Enable dynamic spawning based on player count");
mls.LogInfo((object)"Cart Duplicator Mod Loaded");
harmony.PatchAll(typeof(CartDuplicator));
harmony.PatchAll(typeof(DuplicateCartPatch));
}
public static Vector3 GetDuplicationOffset()
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
return Instance.duplicationOffset.Value;
}
public static int GetDuplicationAmount()
{
return Instance.duplicationAmount.Value;
}
public static bool GetSmallCartReplacement()
{
return Instance.smallCartReplacement.Value;
}
public static bool GetDynamicSpawning()
{
return Instance.dynamicSpawning.Value;
}
}
}
namespace CartDuplicator.Patches
{
[HarmonyPatch(typeof(PunManager))]
[HarmonyPatch("SpawnItem")]
public class DuplicateCartPatch : MonoBehaviourPunCallbacks
{
[HarmonyPostfix]
public static void After_SpawnItem(Item item, ItemVolume volume)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)item == (Object)null || (Object)(object)volume == (Object)null || item.itemAssetName != "Item Cart Medium")
{
return;
}
int num = CartDuplicator.GetDuplicationAmount();
Vector3 duplicationOffset = CartDuplicator.GetDuplicationOffset();
string text = (CartDuplicator.GetSmallCartReplacement() ? "Item Cart Small" : ((Object)item.prefab).name);
int playerCount = GetPlayerCount();
if (CartDuplicator.GetDynamicSpawning())
{
if (playerCount >= 10)
{
num += 2;
}
else if (playerCount >= 5)
{
num++;
}
}
if (PhotonNetwork.IsConnected && PhotonNetwork.IsMasterClient)
{
for (int i = 0; i < num; i++)
{
PhotonNetwork.InstantiateRoomObject("Items/" + text, ((Component)volume).transform.position + duplicationOffset * (float)(i + 1), item.spawnRotationOffset, (byte)0, (object[])null);
}
}
else if (!PhotonNetwork.IsConnected)
{
GameObject val = (CartDuplicator.GetSmallCartReplacement() ? Resources.Load<GameObject>("Items/Item Cart Small") : item.prefab);
for (int j = 0; j < num; j++)
{
Object.Instantiate<GameObject>(val, ((Component)volume).transform.position + duplicationOffset * (float)(j + 1), item.spawnRotationOffset);
}
}
}
public static List<PlayerAvatar> PlayerGetAll()
{
return GameDirector.instance.PlayerList;
}
public static int GetPlayerCount()
{
return PlayerGetAll().Count;
}
}
}