Decompiled source of AddBerry v1.0.2

plugins/AddBerryPlugin/AddBerryPlugin.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("AddBerryPlugin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AddBerryPlugin")]
[assembly: AssemblyTitle("AddBerryPlugin")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AddBerryPlugin;

[BepInPlugin("com.addberry.plugin", "AddBerry", "1.0.2")]
[BepInProcess("valheim.exe")]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "com.addberry.plugin";

	public const string NAME = "AddBerry";

	public const string VERSION = "1.0.2";

	private readonly Harmony _harmony = new Harmony("com.addberry.plugin");

	internal static Dictionary<string, (ConfigEntry<int> Min, ConfigEntry<int> Max)> ItemConfig;

	internal static Dictionary<string, string> DisplayNames;

	internal static ManualLogSource Log;

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		ItemConfig = new Dictionary<string, (ConfigEntry<int>, ConfigEntry<int>)>();
		DisplayNames = new Dictionary<string, string>();
		Register("RaspberryBush", "Raspberry");
		Register("BlueberryBush", "Blueberry");
		Register("CloudberryBush", "Cloudberry");
		Register("Pickable_Mushroom", "Mushroom");
		Register("Pickable_Mushroom_yellow", "Yellow Mushroom");
		Register("Pickable_Dandelion", "Dandelion");
		Register("Pickable_Thistle", "Thistle");
		Register("LingonberryBush", "Lingonberry");
		Register("Pickable_Mushroom_blue", "Blue Mushroom");
		Register("Pickable_Fiddlehead", "Fiddlehead");
		Register("Pickable_SmokePuff", "Smoke Puff");
		_harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"AddBerry 1.0.2 loaded");
		void Register(string prefabName, string displayName)
		{
			ItemConfig[prefabName] = Bind(displayName);
			DisplayNames[prefabName] = displayName;
		}
	}

	private (ConfigEntry<int>, ConfigEntry<int>) Bind(string section)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Expected O, but got Unknown
		ConfigEntry<int> item = ((BaseUnityPlugin)this).Config.Bind<int>(section, "Min Drop Amount", 1, new ConfigDescription("Minimum number of items dropped when picked.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
		ConfigEntry<int> item2 = ((BaseUnityPlugin)this).Config.Bind<int>(section, "Max Drop Amount", 10, new ConfigDescription("Maximum number of items dropped when picked.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
		return (item, item2);
	}

	private void OnDestroy()
	{
		_harmony.UnpatchSelf();
	}
}
[HarmonyPatch(typeof(Pickable), "Interact")]
public static class Patch_PickableAmount
{
	public static void Prefix(Pickable __instance)
	{
		string key = ((Object)((Component)__instance).gameObject).name.Replace("(Clone)", "").Trim();
		if (Plugin.ItemConfig.TryGetValue(key, out (ConfigEntry<int>, ConfigEntry<int>) value))
		{
			__instance.m_amount = Random.Range(value.Item1.Value, value.Item2.Value + 1);
		}
	}
}
[HarmonyPatch(typeof(ZNetScene), "Awake")]
public static class Patch_ZNetScenePrefabCheck
{
	private static bool _logged;

	public static void Postfix(ZNetScene __instance)
	{
		if (_logged)
		{
			return;
		}
		_logged = true;
		foreach (string key in Plugin.ItemConfig.Keys)
		{
			string text = Plugin.DisplayNames[key];
			bool flag = (Object)(object)__instance.GetPrefab(key) != (Object)null;
			Plugin.Log.LogInfo((object)("[AddBerry] " + text + ": " + key + " " + (flag ? "OK" : "MISSING")));
		}
	}
}