plugins\Bell.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BellNS;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("JotunnModExample")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JotunnModExample")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
public class Bell : MonoBehaviour, Hoverable, Interactable
{
	private ZNetView m_nview;

	private float lastrung;

	[SerializeField]
	private float m_animation_speed = 1f;

	[SerializeField]
	private float m_audio_pitch = 1f;

	[SerializeField]
	private bool m_is_church_bell;

	private void Awake()
	{
		m_nview = ((Component)this).GetComponent<ZNetView>();
		if (!((Object)(object)m_nview == (Object)null) && m_nview.GetZDO() != null)
		{
			m_nview.Register("RingBell", (Action<long>)delegate
			{
				RingBell();
			});
		}
	}

	public void RingBell()
	{
		if (m_nview.IsValid())
		{
			Animator component = ((Component)this).GetComponent<Animator>();
			component.SetTrigger("ring");
			component.speed = m_animation_speed;
			AudioSource componentInChildren = ((Component)this).GetComponentInChildren<AudioSource>();
			componentInChildren.pitch = m_audio_pitch;
			componentInChildren.minDistance = BellMain.BellMinRadiusConfig.Value;
			componentInChildren.maxDistance = BellMain.BellMaxRadiusConfig.Value;
			componentInChildren.Play();
		}
	}

	public string GetHoverName()
	{
		return "$piece_bell";
	}

	public string GetHoverText()
	{
		return Localization.instance.Localize("$piece_bell\n[<color=yellow><b>$KEY_Use</b></color>] $bell_ring");
	}

	public bool Interact(Humanoid user, bool hold, bool alt)
	{
		Interact();
		return true;
	}

	public bool Interact()
	{
		if (!m_nview.IsValid())
		{
			return false;
		}
		if (Time.realtimeSinceStartup - lastrung > 6f)
		{
			lastrung = Time.realtimeSinceStartup;
			m_nview.InvokeRPC(ZNetView.Everybody, "RingBell", Array.Empty<object>());
			if (m_is_church_bell && BellMain.StopGroundShakingConfig.Value)
			{
				StopEvent();
			}
			return true;
		}
		return false;
	}

	private void StopEvent()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent();
		if (activeEvent != null && RandEventSystem.instance.IsInsideRandomEventArea(activeEvent, ((Component)this).transform.position) && activeEvent.m_name == "foresttrolls")
		{
			RandEventSystem.instance.ResetRandomEvent();
		}
	}

	public bool UseItem(Humanoid user, ItemData item)
	{
		return true;
	}
}
namespace BellNS;

[BepInPlugin("org.bepinex.plugins.bid.bell", "Bell", "0.6.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class BellMain : BaseUnityPlugin
{
	public const string PluginGUID = "org.bepinex.plugins.bid.bell";

	public const string PluginName = "Bell";

	public const string PluginVersion = "0.6.2";

	public static ConfigEntry<int> BellMinRadiusConfig;

	public static ConfigEntry<int> BellMaxRadiusConfig;

	public static ConfigEntry<bool> StopGroundShakingConfig;

	private readonly Harmony harmony = new Harmony("org.bepinex.plugins.bid.bell");

	private void Awake()
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		AssetBundle val = AssetUtils.LoadAssetBundleFromResources("bell");
		if ((Object)(object)val == (Object)null)
		{
			MonoBehaviour.print((object)"Error loading assetbundle bell");
			return;
		}
		CreateConfigValues();
		try
		{
			AddPieces(val);
		}
		catch (Exception arg)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)$"Exception caught while adding custom creatures: {arg}");
		}
		finally
		{
			val.Unload(false);
		}
		new Harmony("org.bepinex.plugins.bid.bell").PatchAll();
	}

	private void OnDestroy()
	{
		harmony.UnpatchSelf();
	}

	private void CreateConfigValues()
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected O, but got Unknown
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Expected O, but got Unknown
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Expected O, but got Unknown
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Expected O, but got Unknown
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
		BellMinRadiusConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Client config", "BellSoundMinRadius", 20, new ConfigDescription("Radius the bell sound is heard at max level", (AcceptableValueBase)null, Array.Empty<object>()));
		BellMaxRadiusConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Client config", "BellSoundMaxRadius", 100, new ConfigDescription("Radius the bell sound flattens out to 0", (AcceptableValueBase)null, Array.Empty<object>()));
		StopGroundShakingConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Server config", "ChurchBellStopForestTrolls", false, new ConfigDescription("shall ringing the chruch bell stop the ground from shaking? (event forest trolls)", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		SynchronizationManager.OnConfigurationSynchronized += delegate(object obj, ConfigurationSynchronizationEventArgs attr)
		{
			if (attr.InitialSynchronization)
			{
				Logger.LogMessage((object)"Initial Config sync event received");
			}
			else
			{
				Logger.LogMessage((object)"Config sync event received");
			}
		};
	}

	private void AddPieces(AssetBundle bellAssetBundle)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Expected O, but got Unknown
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Expected O, but got Unknown
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Expected O, but got Unknown
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Expected O, but got Unknown
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: 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)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Expected O, but got Unknown
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Expected O, but got Unknown
		GameObject val = bellAssetBundle.LoadAsset<GameObject>("bell");
		PieceManager instance = PieceManager.Instance;
		PieceConfig val2 = new PieceConfig();
		val2.PieceTable = "Hammer";
		val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
		{
			new RequirementConfig
			{
				Item = "Wood",
				Recover = true,
				Amount = 2
			},
			new RequirementConfig
			{
				Item = "Bronze",
				Recover = true,
				Amount = 5
			}
		};
		val2.CraftingStation = "forge";
		instance.AddPiece(new CustomPiece(val, true, val2));
		GameObject val3 = bellAssetBundle.LoadAsset<GameObject>("bell_church");
		if (!StopGroundShakingConfig.Value)
		{
			val3.GetComponent<Piece>().m_description = val.GetComponent<Piece>().m_description;
		}
		PieceManager instance2 = PieceManager.Instance;
		val2 = new PieceConfig();
		val2.PieceTable = "Hammer";
		val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
		{
			new RequirementConfig
			{
				Item = "Wood",
				Recover = true,
				Amount = 4
			},
			new RequirementConfig
			{
				Item = "Bronze",
				Recover = true,
				Amount = 10
			}
		};
		val2.CraftingStation = "forge";
		instance2.AddPiece(new CustomPiece(val3, true, val2));
	}
}