Decompiled source of BuyMore v1.0.0

BepInEx/plugins/FateArth/FateArth.BuyMorePlugin.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AzureSky;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using UnityEngine.Localization.Tables;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FateArth.BuyMorePlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("解锁订货上限")]
[assembly: AssemblyTitle("FateArth.BuyMorePlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 BuyMorePlugin
{
	[HarmonyPatch]
	public class BuyMorePatch : NetworkBehaviour
	{
		[HarmonyPatch(typeof(GameManager), "AddDockOrderServerRpc")]
		[HarmonyPrefix]
		private static bool Prefix1(GameManager __instance, long itemId)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Invalid comparison between Unknown and I4
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Invalid comparison between Unknown and I4
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
			if ((Object)(object)networkManager == (Object)null || !networkManager.IsListening)
			{
				return false;
			}
			FieldInfo field = typeof(NetworkBehaviour).GetField("__rpc_exec_stage", BindingFlags.Instance | BindingFlags.NonPublic);
			__RpcExecStage val = (__RpcExecStage)field.GetValue(__instance);
			if ((int)val != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				MethodInfo method = typeof(NetworkBehaviour).GetMethod("__beginSendServerRpc", BindingFlags.Instance | BindingFlags.NonPublic);
				MethodInfo method2 = typeof(NetworkBehaviour).GetMethod("__endSendServerRpc", BindingFlags.Instance | BindingFlags.NonPublic);
				ServerRpcParams val2 = default(ServerRpcParams);
				FastBufferWriter val3 = (FastBufferWriter)method.Invoke(__instance, new object[3]
				{
					2820931299u,
					val2,
					(object)(RpcDelivery)0
				});
				BytePacker.WriteValueBitPacked(val3, itemId);
				method2.Invoke(__instance, new object[4]
				{
					val3,
					2820931299u,
					val2,
					(object)(RpcDelivery)0
				});
			}
			if ((int)val != 1 || (!networkManager.IsServer && !networkManager.IsHost))
			{
				return false;
			}
			field.SetValue(__instance, (object)(__RpcExecStage)0);
			FieldInfo field2 = typeof(GameManager).GetField("activeDockOrders", BindingFlags.Instance | BindingFlags.NonPublic);
			NetworkList<long> val4 = (NetworkList<long>)field2.GetValue(__instance);
			FieldInfo field3 = typeof(GameManager).GetField("coins", BindingFlags.Instance | BindingFlags.NonPublic);
			NetworkVariable<int> val5 = (NetworkVariable<int>)field3.GetValue(__instance);
			ItemSO itemById = __instance.GetItemById(itemId);
			ProductSO val6 = (ProductSO)(object)((itemById is ProductSO) ? itemById : null);
			int num = __instance.GetWholesalePrice(val6) * ((ItemSO)val6).amount;
			if (val5.Value < num)
			{
				return false;
			}
			__instance.IncrementCoinsServer(-num, (TransactionType)1, ((ItemSO)val6).itemName);
			val4.Add(((ItemSO)val6).id);
			__instance.FinishTutorialServerRpc(__instance.tutorialOrder.id);
			return false;
		}

		[HarmonyPatch(typeof(GameManager), "CheckDay")]
		[HarmonyPrefix]
		private static bool Prefix2(GameManager __instance)
		{
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0610: Unknown result type (might be due to invalid IL or missing references)
			//IL_061a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			EventSO currentEvent = __instance.GetCurrentEvent();
			SeasonSO currentSeason = __instance.GetCurrentSeason();
			UIManager.Instance.SetDateText(__instance.GetCurrentDay(), currentSeason.title);
			UIManager.Instance.SetEventText(currentEvent);
			UIManager.Instance.SetEventTooltip("");
			int index = Random.Range(0, currentSeason.weatherProfiles.Count);
			AzureWeatherProfile val = currentSeason.weatherProfiles[index];
			AudioClip val2 = null;
			for (int num = __instance.eventProps.transform.childCount - 1; num >= 0; num--)
			{
				Object.Destroy((Object)(object)((Component)__instance.eventProps.transform.GetChild(num)).gameObject);
			}
			for (int num2 = __instance.seasonProps.transform.childCount - 1; num2 >= 0; num2--)
			{
				Object.Destroy((Object)(object)((Component)__instance.seasonProps.transform.GetChild(num2)).gameObject);
			}
			if ((Object)(object)currentSeason.props != (Object)null)
			{
				Object.Instantiate<GameObject>(currentSeason.props, __instance.seasonProps.transform);
			}
			if ((Object)(object)currentEvent != (Object)null)
			{
				if ((Object)(object)currentEvent.weatherProfile != (Object)null)
				{
					val = currentEvent.weatherProfile;
				}
				if ((Object)(object)currentEvent.audioClip != (Object)null)
				{
					val2 = currentEvent.audioClip;
				}
				if ((Object)(object)currentEvent.props != (Object)null)
				{
					Object.Instantiate<GameObject>(currentEvent.props, __instance.eventProps.transform);
				}
				string text = "";
				if (currentEvent.products.Count > 0)
				{
					string text2 = string.Join(",", currentEvent.products.Select((ProductSO m) => ((ItemSO)m).GetLocalizedName()).ToArray());
					string localizedString = LocalizationSettings.StringDatabase.GetLocalizedString(TableReference.op_Implicit("Translations"), TableEntryReference.op_Implicit("price_increase"), (Locale)null, (FallbackBehavior)0, Array.Empty<object>());
					UIManager.Instance.ShowLocalNotification("<color=yellow>" + currentEvent.GetLocalizedName() + "</color> " + localizedString + ": <color=yellow>" + text2 + "</color>", false, 15f, false);
					text = text + "<color=#8A5125>" + localizedString + "</color>\n" + text2 + "\n";
				}
				if (currentEvent.forbiddenProducts.Count > 0)
				{
					string text3 = string.Join(",", currentEvent.forbiddenProducts.Select((ProductSO m) => ((ItemSO)m).GetLocalizedName()).ToArray());
					string localizedString2 = LocalizationSettings.StringDatabase.GetLocalizedString(TableReference.op_Implicit("Translations"), TableEntryReference.op_Implicit("banned_items"), (Locale)null, (FallbackBehavior)0, Array.Empty<object>());
					UIManager.Instance.ShowLocalNotification("<color=yellow>" + currentEvent.GetLocalizedName() + "</color> " + localizedString2 + ": <color=red>" + text3 + "</color>", false, 15f, false);
					text = text + "<color=#8A5125>" + localizedString2 + "</color>\n" + text3 + "\n";
				}
				string localizedString3 = LocalizationSettings.StringDatabase.GetLocalizedString(TableReference.op_Implicit("Translations"), TableEntryReference.op_Implicit("tax_rate"), (Locale)null, (FallbackBehavior)0, Array.Empty<object>());
				int num3 = Mathf.RoundToInt((float)__instance.initialTaxPercentage * currentEvent.taxMultiplier);
				UIManager.Instance.ShowLocalNotification($"{localizedString3}: <color=yellow>{num3}%</color>", false, 15f, false);
				UIManager.Instance.SetEventTooltip(text + $"<color=#8A5125>{localizedString3}</color>\n{num3}%");
			}
			if ((Object)(object)val2 != (Object)null)
			{
				AudioManager.Instance.SwapTrack(val2);
			}
			else
			{
				AudioManager.Instance.SwapToDefaultBg();
			}
			if (((NetworkBehaviour)__instance).IsServer)
			{
				WeatherManager.Instance.ChangeWeatherProfileServer(val, 1f);
				if (WeatherManager.Instance.CanWaterDirt(val))
				{
					foreach (BlockDirt item in from x in Object.FindObjectsOfType<BlockDirt>()
						where !x.greenhouse
						select x)
					{
						item.WaterServerRpc(((Component)item).transform.position, false);
					}
					BlockTree[] array = Object.FindObjectsOfType<BlockTree>();
					foreach (BlockTree val3 in array)
					{
						val3.WaterServerRpc(((Component)val3).transform.position, false);
					}
				}
				FieldInfo field = typeof(GameManager).GetField("activeDockOrders", BindingFlags.Instance | BindingFlags.NonPublic);
				NetworkList<long> val4 = (NetworkList<long>)field.GetValue(__instance);
				FieldInfo field2 = typeof(GameManager).GetField("day", BindingFlags.Instance | BindingFlags.NonPublic);
				NetworkVariable<int> val5 = (NetworkVariable<int>)field2.GetValue(__instance);
				for (int j = 0; j < val4.Count; j++)
				{
					long num4 = val4[j];
					ItemSO itemById = __instance.GetItemById(num4);
					ProductSO val6 = (ProductSO)(object)((itemById is ProductSO) ? itemById : null);
					Transform child = __instance.dockOrderSpawnPositions.GetChild(j % __instance.dockOrderSpawnPositions.childCount);
					int wholesalePrice = __instance.GetWholesalePrice(val6, val5.Value - 1);
					__instance.SpawnItemAtPositionServerRpc(num4, child.position, child.rotation, false, Vector3.zero, ((ItemSO)val6).amount, wholesalePrice, 0);
				}
				if (val4.Count > 0)
				{
					UIManager.Instance.ShowNotificationClientRpc(LocalizationSettings.StringDatabase.GetLocalizedString(TableReference.op_Implicit("Translations"), TableEntryReference.op_Implicit("order_arrived"), (Locale)null, (FallbackBehavior)0, Array.Empty<object>()), false, 5f, false);
				}
				val4.Clear();
			}
			__instance.CalculateCapacity();
			UIManager.Instance.CloseEndOfDayPanel();
			return false;
		}

		[HarmonyPatch(typeof(UIManager), "UpdateDockOrdersPanel")]
		[HarmonyPostfix]
		private static void Postfix(UIManager __instance)
		{
			((TMP_Text)__instance.textDockOrderSize).text = GameManager.Instance.GetActiveDockOrders().Count + "/∞";
		}
	}
	[BepInPlugin("FateArth.BuyMorePlugin", "解锁订货上限", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		internal static Harmony harmony;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			harmony = new Harmony("FateArth.BuyMorePlugin");
			harmony.PatchAll();
			Logger.LogInfo((object)"Plugin FateArth.BuyMorePlugin is loaded!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "FateArth.BuyMorePlugin";

		public const string PLUGIN_NAME = "解锁订货上限";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}