Decompiled source of BonkBadge v0.1.1

BonkBadge/BonkBadge.dll

Decompiled 3 weeks ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MoreBadges;
using UnityEngine;

[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("BonkBadge")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BonkBadge")]
[assembly: AssemblyTitle("BonkBadge")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace BonkBadgeMod
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.snosz.bonkbadge", "BonkBadge", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static class BadgeNames
		{
			public const string BonkBadge = "Badge_BonkBadgeMod_Bonk";
		}

		[HarmonyPatch(typeof(CharacterItems), "DropItemRpc")]
		public static class DropItemRpcPatch
		{
			private static bool Prefix(CharacterItems __instance, ItemInstanceData itemInstanceData)
			{
				object value = Traverse.Create((object)__instance).Field("character").GetValue();
				Character val = (Character)((value is Character) ? value : null);
				if ((Object)(object)val == (Object)null || !val.IsLocal)
				{
					return true;
				}
				if ((Object)(object)val.data.currentItem != (Object)null && val.data.currentItem.GetName() == "COCONUT")
				{
					Instance.thrownCoconutID = val.data.currentItem.itemID;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Bonkable), "Bonk")]
		public static class BonkPatch
		{
			private static void Postfix(Bonkable __instance, Collision coll)
			{
				Character componentInParent = coll.gameObject.GetComponentInParent<Character>();
				Item val = default(Item);
				if (!((Object)(object)componentInParent == (Object)null) && componentInParent.IsLocal && ((Component)__instance).gameObject.TryGetComponent<Item>(ref val) && val.itemID == Instance.thrownCoconutID)
				{
					MoreBadgesPlugin.AddProgress("Badge_BonkBadgeMod_Bonk", 1);
					Instance.thrownCoconutID = null;
				}
			}
		}

		public static Plugin Instance;

		private static Harmony _harmony;

		public ushort? thrownCoconutID;

		private AssetBundle iconBundle;

		private void Awake()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			Instance = this;
			_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.snosz.bonkbadge");
			byte[] badges = Resource1.badges;
			iconBundle = AssetBundle.LoadFromMemory(badges);
			Texture2D val = iconBundle.LoadAsset<Texture2D>("Badge_128Bonk");
			CustomBadge val2 = new CustomBadge("Badge_BonkBadgeMod_Bonk", "Bonk Badge", "Bonk yourself with a coconut.", (List<string>)null, (List<string>)null, val, 1, false, false);
			MoreBadgesPlugin.RegisterBadge(val2, "coconut");
		}
	}
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resource1
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("BonkBadgeMod.Resource1", typeof(Resource1).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] badges
		{
			get
			{
				object @object = ResourceManager.GetObject("badges", resourceCulture);
				return (byte[])@object;
			}
		}

		internal Resource1()
		{
		}
	}
}