Decompiled source of JunkAndItemAutoDestroy v1.4.1

BepInEx/plugins/JunkAndItemAutoDestroy.dll

Decompiled 2 weeks ago
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 HarmonyLib;
using Unity.Netcode;
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("ExpiredItemAutoDestroy")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ExpiredItemAutoDestroy")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c9935df2-9ad7-48f5-82ae-3a2b1132c2c6")]
[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")]
[BepInPlugin("com.lan.JunkAndItemAutoDestroy", "自动回收垃圾和过期商品", "1.4.0")]
public class TimelineChangedPatch : BaseUnityPlugin
{
	private static int expiredItemCount;

	private static int expiredJunkCount;

	private static int expiredItemMoney;

	private static int expiredJunkMoney;

	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Harmony val = new Harmony("com.lan.JunkAndItemAutoDestroy");
		val.PatchAll(typeof(TimelineChangedPatch));
		Debug.LogWarning((object)"过期物品和垃圾自动回收 --作者:她说缝上都不给我");
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(GameManager))]
	[HarmonyPatch("OnTimelineChanged")]
	public static void Postfix(GameManager __instance, float current)
	{
		if (((NetworkBehaviour)__instance).IsServer && IsApproximately6AM(current))
		{
			ProcessExpiredItems(__instance);
			__instance.IncrementCoinsServer(expiredItemMoney, (TransactionType)6, $"成功回收了(Successfully recycled){expiredItemCount}个过期物品,获得(expired items and earned){expiredItemMoney}C");
			GameManager.Instance.ShowNotificationClientRpc($"<color=yellow>成功回收了(Successfully recycled)</color> {expiredItemCount} <color=yellow>过期物品,获得(expired items and earned)</color>{expiredItemMoney}C", true, 15f, true);
			__instance.IncrementCoinsServer(expiredJunkMoney, (TransactionType)6, $"成功回收了(Successfully recycled){expiredJunkCount}个垃圾,获得(junk and earned){expiredJunkMoney}C");
			GameManager.Instance.ShowNotificationClientRpc($"<color=yellow>成功回收了(Successfully recycled)</color> {expiredJunkCount} <color=yellow>个垃圾,获得(junk and earned)</color>{expiredJunkMoney}C", true, 15f, true);
			expiredItemCount = 0;
			expiredJunkCount = 0;
			expiredItemMoney = 0;
			expiredJunkMoney = 0;
		}
	}

	private static bool IsApproximately6AM(float time)
	{
		return time >= 6.03f && time < 6.05f;
	}

	private static void ProcessExpiredItems(GameManager gameManager)
	{
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		List<Item> list = Object.FindObjectsOfType<Item>().ToList();
		for (int i = 0; i < list.Count; i++)
		{
			if (((NetworkBehaviour)list[i]).NetworkObject.IsSpawned && list[i].IsExpired())
			{
				ProcessSingleItem(list[i], gameManager);
			}
			else if (((NetworkBehaviour)list[i]).NetworkObject.IsSpawned && (Object)(object)list[i].itemSO != (Object)null && list[i].itemSO.itemName.Equals("junk"))
			{
				ProcessSingleItem(list[i], gameManager);
			}
			else if (((NetworkBehaviour)list[i]).NetworkObject.IsSpawned && !list[i].onStand.Value && list[i].amount.Value == 0)
			{
				ProcessSingleItem(list[i], gameManager);
			}
		}
		List<ItemSO> list2 = Resources.FindObjectsOfTypeAll<ItemSO>().ToList();
		Dictionary<long, ItemSO> dictionary = new Dictionary<long, ItemSO>();
		foreach (ItemSO item in list2)
		{
			if (item.itemName.Equals("junk"))
			{
				dictionary.Add(item.id, item);
			}
		}
		PlayerInventory component = ((Component)NetworkManager.Singleton.LocalClient.PlayerObject).GetComponent<PlayerInventory>();
		for (int j = 0; j < component.slots.Count; j++)
		{
			if (dictionary.ContainsKey(component.slots[j].itemId))
			{
				ItemSO val = dictionary[component.slots[j].itemId];
				float num = Convert.ToSingle(component.slots[j].amount);
				int num2 = Mathf.FloorToInt((float)val.basePrice * 0.5f * num);
				expiredJunkCount += val.amount;
				expiredJunkMoney += num2;
				component.slots[j] = new InventorySlot
				{
					itemId = -1L,
					amount = -1,
					cost = -1,
					dayCounter = -1
				};
			}
		}
	}

	private static void ProcessSingleItem(Item item, GameManager gameManager)
	{
		float num = Convert.ToSingle(item.amount.Value);
		int num2 = Mathf.FloorToInt((float)item.itemSO.basePrice * 0.5f * num);
		if (item.itemSO.amount >= 1 && item.onStand.Value)
		{
			item.amount.Value = 0;
			item.dayCounter.Value = 1;
			item.SaveItem();
			expiredItemCount += item.itemSO.amount;
			expiredItemMoney += num2;
		}
		else if ((item.itemSO.amount >= 1 || item.itemSO.amount == 0) && !item.onStand.Value)
		{
			num2 += 20;
			((NetworkBehaviour)item).NetworkObject.Despawn(true);
			expiredJunkCount += item.itemSO.amount;
			expiredJunkMoney += num2;
		}
		else if (item.itemSO.itemName.Equals("junk"))
		{
			((NetworkBehaviour)item).NetworkObject.Despawn(true);
			expiredJunkCount += item.itemSO.amount;
			expiredJunkMoney += num2;
		}
	}
}

JunkAndItemAutoDestroy.dll

Decompiled 2 weeks ago
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.Configuration;
using HarmonyLib;
using Unity.Netcode;
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("ExpiredItemAutoDestroy")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ExpiredItemAutoDestroy")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c9935df2-9ad7-48f5-82ae-3a2b1132c2c6")]
[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")]
[HarmonyPatch(typeof(GameManager))]
[HarmonyPatch("OnTimelineChanged")]
public static class TimelineChangedPatch
{
	[HarmonyPostfix]
	public static void Postfix(GameManager __instance, float current)
	{
		if (NetworkManager.Singleton.IsServer && IsApproximately6AM(current))
		{
			ProcessExpiredItems(__instance);
		}
	}

	private static bool IsApproximately6AM(float time)
	{
		return time >= 6f && time < ExpirationPatcher.stopRecycleTime.Value;
	}

	private static void ProcessExpiredItems(GameManager gameManager)
	{
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		List<Item> list = Object.FindObjectsOfType<Item>().ToList();
		for (int i = 0; i < list.Count; i++)
		{
			if (list[i].amount.Value > 0)
			{
				if (ExpirationPatcher.isAutoRecycleExpiredItem.Value && ((NetworkBehaviour)list[i]).NetworkObject.IsSpawned && list[i].IsExpired())
				{
					ProcessSingleItem(list[i], gameManager);
				}
				else if (ExpirationPatcher.isAutoRecycleJunk.Value && ((NetworkBehaviour)list[i]).NetworkObject.IsSpawned && (Object)(object)list[i].itemSO != (Object)null && list[i].itemSO.itemName.Equals("junk"))
				{
					ProcessSingleItem(list[i], gameManager);
				}
			}
		}
		if (!ExpirationPatcher.isAutoRecycleJunk.Value)
		{
			return;
		}
		List<ItemSO> list2 = Resources.FindObjectsOfTypeAll<ItemSO>().ToList();
		Dictionary<long, ItemSO> dictionary = new Dictionary<long, ItemSO>();
		foreach (ItemSO item in list2)
		{
			if (item.itemName.Equals("junk"))
			{
				dictionary.Add(item.id, item);
			}
		}
		PlayerInventory component = ((Component)NetworkManager.Singleton.LocalClient.PlayerObject).GetComponent<PlayerInventory>();
		for (int j = 0; j < component.slots.Count; j++)
		{
			if (dictionary.ContainsKey(component.slots[j].itemId))
			{
				ItemSO val = dictionary[component.slots[j].itemId];
				float num = Convert.ToSingle(component.slots[j].amount);
				int num2 = Mathf.FloorToInt((float)val.basePrice * 0.5f * num);
				gameManager.IncrementCoinsServer(num2, (TransactionType)6, val.itemName);
				component.slots[j] = new InventorySlot
				{
					itemId = -1L,
					amount = -1,
					cost = -1,
					dayCounter = -1
				};
			}
		}
	}

	private static void ProcessSingleItem(Item item, GameManager gameManager)
	{
		float num = Convert.ToSingle(item.amount.Value);
		int num2 = Mathf.FloorToInt((float)item.itemSO.basePrice * 0.5f * num);
		if (item.itemSO.amount > 1 && item.onStand.Value)
		{
			gameManager.IncrementCoinsServer(num2, (TransactionType)6, item.itemSO.itemName);
			item.amount.Value = 0;
			item.dayCounter.Value = 1;
			item.SaveItem();
		}
		else if (item.itemSO.amount > 1 && !item.onStand.Value)
		{
			num2 += 20;
			gameManager.IncrementCoinsServer(num2, (TransactionType)6, item.itemSO.itemName);
			((NetworkBehaviour)item).NetworkObject.Despawn(true);
		}
	}
}
[BepInPlugin("com.lan.JunkAndItemAutoDestroy", "自动回收垃圾和过期商品", "1.2.0")]
public class ExpirationPatcher : BaseUnityPlugin
{
	public static ConfigEntry<bool> isAutoRecycleExpiredItem;

	public static ConfigEntry<bool> isAutoRecycleJunk;

	public static ConfigEntry<float> stopRecycleTime;

	private void Awake()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Expected O, but got Unknown
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Expected O, but got Unknown
		ConfigDescription val = new ConfigDescription("是否开启自动回收过期商品 -- Whether to enable automatic recycling of expired items", (AcceptableValueBase)(object)new AcceptableValueList<bool>(new bool[2] { true, false }), Array.Empty<object>());
		isAutoRecycleExpiredItem = ((BaseUnityPlugin)this).Config.Bind<bool>("回收设置 -- Recycle Settings", "是否自动回收过期商品 -- isAutoRecycleExpiredItem", true, val);
		ConfigDescription val2 = new ConfigDescription("是否开启自动回收垃圾 -- Whether to enable automatic recycling of junk items", (AcceptableValueBase)(object)new AcceptableValueList<bool>(new bool[2] { true, false }), Array.Empty<object>());
		isAutoRecycleJunk = ((BaseUnityPlugin)this).Config.Bind<bool>("回收设置 -- Recycle Settings", "是否自动回收垃圾 -- isAutoRecycleJunk", true, val2);
		ConfigDescription val3 = new ConfigDescription("停止回收时间(小时),尽量不要动 -- Stop recycling time (hours),try not to modify as much as possible", (AcceptableValueBase)(object)new AcceptableValueRange<float>(6f, 7f), Array.Empty<object>());
		stopRecycleTime = ((BaseUnityPlugin)this).Config.Bind<float>("回收设置 -- Recycle Settings", "stopRecycleTime", 6.03f, val3);
		Harmony val4 = new Harmony("com.lan.JunkAndItemAutoDestroy");
		val4.PatchAll();
		Debug.LogWarning((object)"过期物品和垃圾自动回收 --作者:她说缝上都不给我");
	}
}