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 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("UpgradeDivider")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UpgradeDivider")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("182a7d4f-9336-4f29-b91f-73d4bb0940ef")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.yourname.repo.coopdiscount", "Co-op Discount Mod", "1.0.0")]
public class CoopDiscountMod : BaseUnityPlugin
{
[HarmonyPatch]
public static class ShopManagerPatch
{
[HarmonyTargetMethod]
public static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(ShopManager), "GetAllItemsFromStatsManager", (Type[])null, (Type[])null);
}
[HarmonyPrefix]
public static bool Prefix(ShopManager __instance)
{
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Invalid comparison between Unknown and I4
//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Invalid comparison between Unknown and I4
//IL_0223: Unknown result type (might be due to invalid IL or missing references)
//IL_0229: Invalid comparison between Unknown and I4
//IL_0262: Unknown result type (might be due to invalid IL or missing references)
//IL_0268: Invalid comparison between Unknown and I4
//IL_026d: Unknown result type (might be due to invalid IL or missing references)
//IL_0273: Invalid comparison between Unknown and I4
//IL_0278: Unknown result type (might be due to invalid IL or missing references)
//IL_027e: Invalid comparison between Unknown and I4
//IL_032c: Unknown result type (might be due to invalid IL or missing references)
//IL_0332: Invalid comparison between Unknown and I4
//IL_0351: Unknown result type (might be due to invalid IL or missing references)
//IL_0382: Unknown result type (might be due to invalid IL or missing references)
//IL_036b: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)"✅ [Co-op Discount Mod] Patched GetAllItemsFromStatsManager");
if (SemiFunc.IsNotMasterClient())
{
return false;
}
__instance.potentialItems.Clear();
__instance.potentialItemConsumables.Clear();
__instance.potentialItemUpgrades.Clear();
__instance.potentialItemHealthPacks.Clear();
__instance.potentialSecretItems.Clear();
foreach (Item value in StatsManager.instance.itemDictionary.Values)
{
int num = SemiFunc.StatGetItemsPurchased(value.itemAssetName);
float num2 = 0f;
if ((int)value.itemType == 3)
{
float num3 = value.value.valueMax / 1000f * itemValueMultiplierRef.Invoke(__instance);
int itemsUpgradesPurchased = StatsManager.instance.GetItemsUpgradesPurchased(value.itemAssetName);
num3 += num3 * upgradeValueIncreaseRef.Invoke(__instance) * (float)itemsUpgradesPurchased;
num3 = Mathf.Ceil(num3);
int num4 = Mathf.Max(1, (GameDirector.instance?.PlayerList?.Count).GetValueOrDefault(1));
if (num4 > 1)
{
float num5 = 1f / (float)Mathf.Clamp(num4, 1, 4);
float num6 = Mathf.Ceil(num3 * num5);
Debug.Log((object)$"[Mod] {num4} players – discount → '{value.itemAssetName}' = {num6}");
num2 = num6;
value.value.valueMax = num6;
}
else
{
Debug.Log((object)$"[Mod] SOLO – full price → '{value.itemAssetName}' = {num3}");
num2 = num3;
}
}
else
{
num2 = value.value.valueMax / 1000f * itemValueMultiplierRef.Invoke(__instance);
if ((int)value.itemType == 8)
{
num2 += num2 * healthPackValueIncreaseRef.Invoke(__instance) * (float)RunManager.instance.levelsCompleted;
num2 = Mathf.Ceil(num2);
}
if ((int)value.itemType == 5)
{
num2 += num2 * crystalValueIncreaseRef.Invoke(__instance) * (float)RunManager.instance.levelsCompleted;
num2 = Mathf.Ceil(num2);
}
}
float num7 = num2;
bool flag = (int)value.itemType == 3;
bool flag2 = (int)value.itemType == 8;
bool flag3 = (int)value.itemType == 5;
int maxAmountInShop = value.maxAmountInShop;
if (num >= maxAmountInShop || (value.maxPurchase && StatsManager.instance.GetItemsUpgradesPurchasedTotal(value.itemAssetName) >= value.maxPurchaseAmount) || (!(num7 <= (float)__instance.totalCurrency) && Random.Range(0, 100) >= 25))
{
continue;
}
for (int i = 0; i < maxAmountInShop - num; i++)
{
if (flag)
{
__instance.potentialItemUpgrades.Add(value);
continue;
}
if (flag2)
{
__instance.potentialItemHealthPacks.Add(value);
continue;
}
if (flag3)
{
__instance.potentialItemConsumables.Add(value);
continue;
}
if ((int)value.itemSecretShopType == 0)
{
__instance.potentialItems.Add(value);
continue;
}
if (!__instance.potentialSecretItems.ContainsKey(value.itemSecretShopType))
{
__instance.potentialSecretItems[value.itemSecretShopType] = new List<Item>();
}
__instance.potentialSecretItems[value.itemSecretShopType].Add(value);
}
}
ListExtension.Shuffle<Item>((IList<Item>)__instance.potentialItems);
ListExtension.Shuffle<Item>((IList<Item>)__instance.potentialItemConsumables);
ListExtension.Shuffle<Item>((IList<Item>)__instance.potentialItemUpgrades);
ListExtension.Shuffle<Item>((IList<Item>)__instance.potentialItemHealthPacks);
foreach (List<Item> value2 in __instance.potentialSecretItems.Values)
{
ListExtension.Shuffle<Item>((IList<Item>)value2);
}
return false;
}
}
private static FieldRef<ShopManager, float> itemValueMultiplierRef;
private static FieldRef<ShopManager, float> upgradeValueIncreaseRef;
private static FieldRef<ShopManager, float> healthPackValueIncreaseRef;
private static FieldRef<ShopManager, float> crystalValueIncreaseRef;
private void Awake()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ Co-op Discount Mod initializing...");
Harmony val = new Harmony("com.yourname.repo.coopdiscount");
itemValueMultiplierRef = AccessTools.FieldRefAccess<ShopManager, float>("itemValueMultiplier");
upgradeValueIncreaseRef = AccessTools.FieldRefAccess<ShopManager, float>("upgradeValueIncrease");
healthPackValueIncreaseRef = AccessTools.FieldRefAccess<ShopManager, float>("healthPackValueIncrease");
crystalValueIncreaseRef = AccessTools.FieldRefAccess<ShopManager, float>("crystalValueIncrease");
val.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ Co-op Discount Mod loaded.");
}
}