Decompiled source of RepoDiscountMod v1.0.9

RepoDiscountMod.dll

Decompiled 2 weeks ago
using System.Collections;
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.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("RepoDiscountMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RepoDiscountMod")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7b758bb3-c2ff-4a84-a4f6-a1ac9b36d757")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RepoDiscountMod;

[BepInPlugin("com.maze.repodiscountmod", "Repo Discount Mod", "1.1.0")]
public class RepoDiscountMod : BaseUnityPlugin
{
	public static ManualLogSource LogSource;

	public const float DiscountFactor = 0.3f;

	private void Awake()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		LogSource = ((BaseUnityPlugin)this).Logger;
		Harmony val = new Harmony("com.maze.repodiscountmod");
		val.PatchAll();
		LogSource.LogInfo((object)"[RepoDiscountMod] Mod chargé avec la remise visible et active !");
	}
}
internal static class ShopManagerExtensions
{
	private static readonly FieldInfo ShoppingListField = AccessTools.Field(typeof(ShopManager), "shoppingList");

	public static IList GetShoppingList(this ShopManager shop)
	{
		return (IList)ShoppingListField.GetValue(shop);
	}
}
[HarmonyPatch(typeof(SemiFunc), "ShopGetTotalCost")]
internal class Patch_ShopGetTotalCost
{
	private static readonly FieldInfo ValueField = AccessTools.Field(typeof(ItemAttributes), "value");

	private static readonly FieldInfo InExtractionField = AccessTools.Field(typeof(RoomVolumeCheck), "inExtractionPoint");

	private static void Postfix(ref int __result)
	{
		int num = 0;
		int num2 = 0;
		IList shoppingList = ShopManager.instance.GetShoppingList();
		if (shoppingList == null)
		{
			return;
		}
		foreach (object item in shoppingList)
		{
			ItemAttributes val = (ItemAttributes)((item is ItemAttributes) ? item : null);
			if (!((Object)(object)val == (Object)null))
			{
				int num3 = (int)ValueField.GetValue(val);
				num += num3;
				RoomVolumeCheck component = ((Component)val).GetComponent<RoomVolumeCheck>();
				num2 = ((!((Object)(object)component != (Object)null) || !(bool)InExtractionField.GetValue(component)) ? (num2 + num3) : (num2 + Mathf.CeilToInt((float)num3 * 0.3f)));
			}
		}
		__result = num2;
	}
}
[HarmonyPatch(typeof(ExtractionPoint), "DestroyTheFirstPhysObjectsInShopList")]
internal static class Patch_DestroyFirstShopItem
{
	private static readonly FieldInfo ValueField = AccessTools.Field(typeof(ItemAttributes), "value");

	private static readonly FieldInfo InExtractionField = AccessTools.Field(typeof(RoomVolumeCheck), "inExtractionPoint");

	private static bool Prefix()
	{
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Invalid comparison between Unknown and I4
		if (!SemiFunc.IsMasterClientOrSingleplayer())
		{
			return false;
		}
		ShopManager instance = ShopManager.instance;
		IList shoppingList = instance.GetShoppingList();
		if (shoppingList == null || shoppingList.Count == 0)
		{
			return false;
		}
		object? obj = shoppingList[0];
		ItemAttributes val = (ItemAttributes)((obj is ItemAttributes) ? obj : null);
		if ((Object)(object)val == (Object)null)
		{
			return false;
		}
		int num = (int)ValueField.GetValue(val);
		RoomVolumeCheck component = ((Component)val).GetComponent<RoomVolumeCheck>();
		int num2 = ((component != null && (bool)InExtractionField.GetValue(component)) ? Mathf.CeilToInt((float)num * 0.3f) : num);
		if (SemiFunc.StatGetRunCurrency() >= num2)
		{
			SemiFunc.StatSetRunCurrency(SemiFunc.StatGetRunCurrency() - num2);
			StatsManager.instance.ItemPurchase(val.item.itemAssetName);
			if ((int)val.item.itemType == 3)
			{
				StatsManager.instance.AddItemsUpgradesPurchased(val.item.itemAssetName);
			}
			((Component)val).GetComponent<PhysGrabObject>().DestroyPhysGrabObject();
			shoppingList.RemoveAt(0);
		}
		SemiFunc.ShopUpdateCost();
		return false;
	}
}
[HarmonyPatch(typeof(ExtractionPoint), "DestroyAllPhysObjectsInShoppingList")]
internal static class Patch_DestroyAllShopItems
{
	private static readonly FieldInfo ValueField = AccessTools.Field(typeof(ItemAttributes), "value");

	private static readonly FieldInfo InExtractionField = AccessTools.Field(typeof(RoomVolumeCheck), "inExtractionPoint");

	private static bool Prefix()
	{
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Invalid comparison between Unknown and I4
		if (!SemiFunc.IsMasterClientOrSingleplayer())
		{
			return false;
		}
		ShopManager instance = ShopManager.instance;
		IList shoppingList = instance.GetShoppingList();
		if (shoppingList == null || shoppingList.Count == 0)
		{
			return false;
		}
		List<ItemAttributes> list = new List<ItemAttributes>();
		foreach (object item in shoppingList)
		{
			ItemAttributes val = (ItemAttributes)((item is ItemAttributes) ? item : null);
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			int num = (int)ValueField.GetValue(val);
			RoomVolumeCheck component = ((Component)val).GetComponent<RoomVolumeCheck>();
			int num2 = ((component != null && (bool)InExtractionField.GetValue(component)) ? Mathf.CeilToInt((float)num * 0.3f) : num);
			if (SemiFunc.StatGetRunCurrency() >= num2)
			{
				SemiFunc.StatSetRunCurrency(SemiFunc.StatGetRunCurrency() - num2);
				StatsManager.instance.ItemPurchase(val.item.itemAssetName);
				if ((int)val.item.itemType == 3)
				{
					StatsManager.instance.AddItemsUpgradesPurchased(val.item.itemAssetName);
				}
				((Component)val).GetComponent<PhysGrabObject>().DestroyPhysGrabObject();
				list.Add(val);
			}
		}
		foreach (ItemAttributes item2 in list)
		{
			shoppingList.Remove(item2);
		}
		SemiFunc.ShopUpdateCost();
		return false;
	}
}