Decompiled source of HumanizedShopPatched v1.0.1

plugins/HumanizedShop/HumanizedShop.dll

Decompiled 2 hours ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HumanizedShop")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+d5d0a010668996d23822bd3994164dd916f75e12")]
[assembly: AssemblyProduct("HumanizedShop")]
[assembly: AssemblyTitle("HumanizedShop")]
[assembly: AssemblyVersion("1.0.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HumanizedShop
{
	[BepInPlugin("upgame.REPO.HumanizedShop", "Humanized Shop", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGUID = "upgame.REPO.HumanizedShop";

		public const string PluginName = "Humanized Shop";

		public const string PluginVersion = "1.0.1";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> FreeEnable;

		internal static ConfigEntry<int> Probability;

		internal static float Rebate;

		private void Awake()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			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)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			Harmony val = new Harmony("upgame.REPO.HumanizedShop");
			val.PatchAll(typeof(ShopInitializePatch));
			val.PatchAll(typeof(GetValuePatch));
			Log.LogInfo((object)"Humanized Shop 1.0.1 loaded.");
		}
	}
	[HarmonyPatch]
	internal static class ShopInitializePatch
	{
		private static MethodBase TargetMethod()
		{
			return (from m in AccessTools.GetDeclaredMethods(typeof(ShopManager))
				where m.Name == "ShopInitialize"
				orderby m.GetParameters().Length descending
				select m).First();
		}

		private static void Prefix()
		{
			if (SemiFunc.IsMasterClientOrSingleplayer() && SemiFunc.RunIsShop())
			{
				Plugin.Rebate = CalculateDiscount();
				Plugin.Log.LogInfo((object)$"Shop discount this visit: {Plugin.Rebate * 100f:0}% off");
			}
		}

		private static float CalculateDiscount()
		{
			float value = Random.value;
			if (value < 0.03f)
			{
				return 0.9f - Random.value * 0.1f;
			}
			if (value < 0.1f)
			{
				return 0.8f - Random.value * 0.1f;
			}
			if (value < 0.25f)
			{
				return 0.7f - Random.value * 0.1f;
			}
			if (value < 0.55f)
			{
				return 0.6f - Random.value * 0.4f;
			}
			return 0.2f - Random.value * 0.2f;
		}
	}
	[HarmonyPatch(typeof(ItemAttributes), "GetValue")]
	internal static class GetValuePatch
	{
		private static void Postfix(ref int ___value, PhotonView ___photonView)
		{
			if (SemiFunc.IsMasterClientOrSingleplayer() && SemiFunc.RunIsShop())
			{
				int value = Plugin.Probability.Value;
				if (Plugin.FreeEnable.Value && value > 0 && Random.Range(0, 101) <= value)
				{
					___value = 0;
				}
				else
				{
					___value = (int)Mathf.Max(1f, (float)___value * (1f - Plugin.Rebate));
				}
				if (GameManager.Multiplayer() && (Object)(object)___photonView != (Object)null && ___photonView.ViewID != 0)
				{
					___photonView.RPC("GetValueRPC", (RpcTarget)1, new object[1] { ___value });
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "HumanizedShop";

		public const string PLUGIN_NAME = "HumanizedShop";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}