Decompiled source of HumanizedShop v1.0.0

HumanizedShop.dll

Decompiled a day ago
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 System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using HumanizedShop.Patches;
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("HumanizedShop")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HumanizedShop")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e1d8b55e-8c1f-4c9f-840d-868f1e17ee38")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
public static class Utils
{
	public static string List2Str(List<Item> items)
	{
		StringBuilder stringBuilder = new StringBuilder();
		foreach (Item item in items)
		{
			stringBuilder.Append(((Object)item).name + "、");
		}
		return stringBuilder.ToString();
	}

	public static string Dict2Str(Dictionary<itemSecretShopType, List<Item>> dicts)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		StringBuilder stringBuilder = new StringBuilder();
		foreach (KeyValuePair<itemSecretShopType, List<Item>> dict in dicts)
		{
			itemSecretShopType key = dict.Key;
			stringBuilder.Append(((object)(itemSecretShopType)(ref key)).ToString() + ": ");
			foreach (Item item in dict.Value)
			{
				stringBuilder.Append(((Object)item).name + "、");
			}
			stringBuilder.Append("\n");
		}
		return stringBuilder.ToString();
	}
}
public static class Log
{
	public static ManualLogSource _logSource;

	static Log()
	{
		_logSource = Logger.CreateLogSource("Humanized Shop");
	}

	public static void LogInfo(object data)
	{
		_logSource.LogInfo(data);
	}

	public static void LogWarning(object data)
	{
		_logSource.LogWarning(data);
	}

	public static void LogError(object data)
	{
		_logSource.LogError(data);
	}

	public static void LogDebug(object data)
	{
		_logSource.LogDebug(data);
	}

	public static void LogFatal(object data)
	{
		_logSource.LogFatal(data);
	}

	public static void LogMessage(object data)
	{
		_logSource.LogMessage(data);
	}
}
namespace HumanizedShop
{
	[BepInPlugin("upgame.REPO.HumanizedShop", "Humanized Shop", "1.0.0")]
	public class PluginBase : BaseUnityPlugin
	{
		public const string PluginGUID = "upgame.REPO.HumanizedShop";

		public const string PluginName = "Humanized Shop";

		public const string PluginVersion = "1.0.0";

		private readonly Harmony _harmony = new Harmony("upgame.REPO.HumanizedShop");

		private static PluginBase Instance;

		private ConfigEntry<bool> _freeEnable;

		private ConfigEntry<int> _probability;

		public static float _rebate = 0f;

		private static AcceptableValueRange<int> acceptableRange = new AcceptableValueRange<int>(0, 100);

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			if ((Object)Instance == (Object)null)
			{
				Instance = this;
			}
			Log.LogInfo("<更好的商店系统>加载成功! Successfully loaded plugin: upgame.REPO.HumanizedShop!");
			_freeEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable", true, "True is set items can be randomly given for free.");
			_probability = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Probability", 5, new ConfigDescription("The probability of free item.", (AcceptableValueBase)(object)acceptableRange, Array.Empty<object>()));
			_probability.Value = Mathf.Clamp(_probability.Value, 0, 100);
			_harmony.PatchAll(typeof(PluginBase));
			_harmony.PatchAll(typeof(ShopManager_ShopInitialize_PosPatch));
			_harmony.PatchAll(typeof(ItemAttributes_GetValuee_Patch));
			Log.LogInfo((_freeEnable.Value ? "已启用商店上架免费商品" : "已禁用商店上架免费商品") ?? "");
		}

		public static bool GetEnable()
		{
			return Instance._freeEnable.Value;
		}

		public static int GetProbability()
		{
			return Instance._probability.Value;
		}
	}
}
namespace HumanizedShop.Patches
{
	[HarmonyPatch(typeof(ShopManager), "ShopInitialize")]
	public class ShopManager_ShopInitialize_PosPatch
	{
		private static Random random = new Random();

		public static void Prefix(ShopManager __instance)
		{
			if (SemiFunc.IsMasterClientOrSingleplayer() && SemiFunc.RunIsShop())
			{
				PluginBase._rebate = CalculateDiscount();
				Log.LogInfo($"ShopRebate: 生成商店折扣......{PluginBase._rebate * 100f}%");
			}
		}

		public static float CalculateDiscount()
		{
			float num = (float)random.NextDouble();
			if (num < 0.3f)
			{
				return 0.9f - (float)random.NextDouble() * 0.1f;
			}
			if (num < 0.1f)
			{
				return 0.8f - (float)random.NextDouble() * 0.1f;
			}
			if (num < 0.25f)
			{
				return 0.7f - (float)random.NextDouble() * 0.1f;
			}
			if (num < 0.55f)
			{
				return 0.6f - (float)random.NextDouble() * 0.4f;
			}
			return 0.2f - (float)random.NextDouble() * 0.2f;
		}
	}
	[HarmonyPatch(typeof(ItemAttributes), "GetValue")]
	public class ItemAttributes_GetValuee_Patch
	{
		private static Random random;

		private static readonly FieldRef<ShopManager, float> _getItemValueMultiplier;

		private static readonly FieldRef<ShopManager, float> _getUpgradeValueIncrease;

		private static readonly FieldRef<ShopManager, float> _getHealthPackValueIncrease;

		private static readonly FieldRef<ShopManager, float> _getCrystalValueIncrease;

		static ItemAttributes_GetValuee_Patch()
		{
			random = new Random();
			FieldInfo field = typeof(ShopManager).GetField("itemValueMultiplier", BindingFlags.Instance | BindingFlags.NonPublic);
			_getItemValueMultiplier = AccessTools.FieldRefAccess<ShopManager, float>(field);
			FieldInfo field2 = typeof(ShopManager).GetField("upgradeValueIncrease", BindingFlags.Instance | BindingFlags.NonPublic);
			_getUpgradeValueIncrease = AccessTools.FieldRefAccess<ShopManager, float>(field2);
			FieldInfo field3 = typeof(ShopManager).GetField("healthPackValueIncrease", BindingFlags.Instance | BindingFlags.NonPublic);
			_getHealthPackValueIncrease = AccessTools.FieldRefAccess<ShopManager, float>(field3);
			FieldInfo field4 = typeof(ShopManager).GetField("crystalValueIncrease", BindingFlags.Instance | BindingFlags.NonPublic);
			_getCrystalValueIncrease = AccessTools.FieldRefAccess<ShopManager, float>(field4);
		}

		public static bool Prefix(ref int ___value, float ___itemValueMin, float ___itemValueMax, itemType ___itemType, string ___itemAssetName, PhotonView ___photonView, string ___itemName)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Invalid comparison between Unknown and I4
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Invalid comparison between Unknown and I4
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Invalid comparison between Unknown and I4
			if (GameManager.Multiplayer() && !PhotonNetwork.IsMasterClient)
			{
				return true;
			}
			if (!SemiFunc.RunIsShop())
			{
				return true;
			}
			float num = Random.Range(___itemValueMin, ___itemValueMax) * _getItemValueMultiplier.Invoke(ShopManager.instance);
			if (num < 1000f)
			{
				num = 1000f;
			}
			if (num >= 1000f)
			{
				num = Mathf.Ceil(num / 1000f);
			}
			if ((int)___itemType == 3)
			{
				num += num * _getUpgradeValueIncrease.Invoke(ShopManager.instance) * (float)StatsManager.instance.GetItemsUpgradesPurchased(___itemAssetName);
			}
			else if ((int)___itemType == 8)
			{
				num += num * _getHealthPackValueIncrease.Invoke(ShopManager.instance) * (float)RunManager.instance.levelsCompleted;
			}
			else if ((int)___itemType == 5)
			{
				num += num * _getCrystalValueIncrease.Invoke(ShopManager.instance) * (float)RunManager.instance.levelsCompleted;
			}
			if (PluginBase.GetEnable() && PluginBase.GetProbability() > 0 && random.Next(0, 101) <= PluginBase.GetProbability())
			{
				___value = 0;
			}
			else
			{
				float num2 = Mathf.Clamp(num * (1f - PluginBase._rebate), 1f, num * (1f - PluginBase._rebate));
				___value = (int)num2;
			}
			if (GameManager.Multiplayer())
			{
				___photonView.RPC("GetValueRPC", (RpcTarget)1, new object[1] { ___value });
			}
			return false;
		}

		public static void Postfix()
		{
		}
	}
}