Decompiled source of DragoAshlands v1.7.0

plugins/kg_bin.dll

Decompiled 6 months ago
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("kg_bin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("kg_bin")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("317450EF-AEB9-4488-9E0C-D29C6A5E8CFD")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace kg_bin;

[BepInPlugin("kg_bin", "kg_bin", "1.0.0")]
public class kg_bin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(AudioMan), "Awake")]
	private static class AudioMan_Awake_Patch
	{
		private static void Postfix(AudioMan __instance)
		{
			Explosion.GetComponentInChildren<AudioSource>().outputAudioMixerGroup = __instance.m_masterMixer.outputAudioMixerGroup;
		}
	}

	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	private static class ZNetScene_Awake_Patch
	{
		private static void Postfix(ZNetScene __instance)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			__instance.m_prefabs.Add(Bin);
			__instance.m_namedPrefabs.Add(StringExtensionMethods.GetStableHashCode(((Object)Bin).name), Bin);
			PieceTable buildPieces = __instance.GetPrefab("Hammer").GetComponent<ItemDrop>().m_itemData.m_shared.m_buildPieces;
			Bin.GetComponent<Piece>().m_resources = (Requirement[])(object)new Requirement[2]
			{
				new Requirement
				{
					m_resItem = __instance.GetPrefab("Stone").GetComponent<ItemDrop>(),
					m_amount = 10,
					m_recover = true
				},
				new Requirement
				{
					m_resItem = __instance.GetPrefab("SurtlingCore").GetComponent<ItemDrop>(),
					m_amount = 2,
					m_recover = true
				}
			};
			if (!buildPieces.m_pieces.Contains(Bin))
			{
				buildPieces.m_pieces.Add(Bin);
			}
		}
	}

	public class BinComponent : MonoBehaviour
	{
		private ZNetView _znv;

		private void Awake()
		{
			_znv = ((Component)this).GetComponentInParent<ZNetView>();
		}

		private void OnTriggerEnter(Collider other)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if (_znv.IsValid())
			{
				ItemDrop val = (Object.op_Implicit((Object)(object)((Component)other).GetComponentInParent<ItemDrop>()) ? ((Component)other).GetComponentInParent<ItemDrop>() : ((Component)other).GetComponent<ItemDrop>());
				if (Object.op_Implicit((Object)(object)val) && val.m_nview.IsValid() && val.m_nview.IsOwner())
				{
					ZNetScene.instance.Destroy(((Component)val).gameObject);
					Object.Instantiate<GameObject>(Explosion, ((Component)val).transform.position, Quaternion.identity);
				}
			}
		}
	}

	private const string GUID = "kg_bin";

	private const string PluginName = "kg_bin";

	private const string PluginVersion = "1.0.0";

	private static AssetBundle asset;

	private static GameObject Bin;

	private static GameObject Explosion;

	private void Awake()
	{
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		asset = GetAssetBundle("binremover");
		Bin = asset.LoadAsset<GameObject>("ItemBinPlatformMod");
		Bin.GetComponent<Piece>().m_name = "Magic Bin";
		Bin.GetComponent<Piece>().m_description = "A magical bin that destroys all items thrown in it";
		Explosion = asset.LoadAsset<GameObject>("Explosion_Small");
		((Component)Bin.transform.Find("sphere")).gameObject.AddComponent<BinComponent>();
		new Harmony("kg_bin").PatchAll();
	}

	private static AssetBundle GetAssetBundle(string filename)
	{
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		string name = executingAssembly.GetManifestResourceNames().Single((string str) => str.EndsWith(filename));
		using Stream stream = executingAssembly.GetManifestResourceStream(name);
		return AssetBundle.LoadFromStream(stream);
	}
}