Decompiled source of BerryHarvestTweaks v1.0.4

BepInEx/plugins/BerryHarvestTweaks/BerryHarvestTweaks.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("BerryHarvestTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4")]
[assembly: AssemblyProduct("BerryHarvestTweaks")]
[assembly: AssemblyTitle("BerryHarvestTweaks")]
[assembly: AssemblyVersion("1.0.4.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 BerryHarvestTweaks
{
	[BepInPlugin("com.chatgpt.berryharvesttweaks", "BerryHarvestTweaks", "1.0.3")]
	public sealed class BerryHarvestTweaksPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.chatgpt.berryharvesttweaks";

		public const string PluginName = "BerryHarvestTweaks";

		public const string PluginVersion = "1.0.3";

		private Harmony _harmony;

		internal static void LogFallback(Pickable pickable)
		{
			if ((Object)(object)pickable != (Object)null)
			{
				pickable.m_amount = Random.Range(2, 8);
			}
		}

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_harmony = new Harmony("com.chatgpt.berryharvesttweaks");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"BerryHarvestTweaks 1.0.3 loaded.");
		}

		private void OnDestroy()
		{
			if (_harmony != null)
			{
				_harmony.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(Pickable), "RPC_Pick")]
	internal static class PickableRpcPickPatch
	{
		private sealed class SavedValues
		{
			internal GameObject ItemPrefab;

			internal int Amount;

			internal bool DontScale;

			internal bool Changed;
		}

		private static void Prefix(Pickable __instance, out SavedValues __state)
		{
			__state = new SavedValues();
			if ((Object)(object)__instance == (Object)null || (Object)(object)((Component)__instance).gameObject == (Object)null)
			{
				return;
			}
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid() || !component.IsOwner())
			{
				return;
			}
			string text = ((Object)((Component)__instance).gameObject).name;
			if (text.EndsWith("(Clone)", StringComparison.Ordinal))
			{
				text = text.Substring(0, text.Length - "(Clone)".Length).Trim();
			}
			if (text != "RaspberryBush" && text != "BlueberryBush")
			{
				return;
			}
			__state.ItemPrefab = __instance.m_itemPrefab;
			__state.Amount = __instance.m_amount;
			__state.DontScale = __instance.m_dontScale;
			__state.Changed = true;
			if (Random.value < 0.1f)
			{
				GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab("Pukeberries") : null);
				if ((Object)(object)val != (Object)null)
				{
					__instance.m_itemPrefab = val;
					__instance.m_amount = Random.Range(2, 8);
				}
				else
				{
					BerryHarvestTweaksPlugin.LogFallback(__instance);
				}
			}
			else
			{
				__instance.m_amount = Random.Range(2, 8);
			}
			__instance.m_dontScale = true;
		}

		private static void Postfix(Pickable __instance, SavedValues __state)
		{
			if (__state != null && __state.Changed && !((Object)(object)__instance == (Object)null))
			{
				__instance.m_itemPrefab = __state.ItemPrefab;
				__instance.m_amount = __state.Amount;
				__instance.m_dontScale = __state.DontScale;
			}
		}
	}
}