Decompiled source of JumpingBirds v1.0.0

JumpingBirds.dll

Decompiled 3 days ago
using System;
using System.Collections;
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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("JumpingBirds")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("JumpingBirds")]
[assembly: AssemblyTitle("JumpingBirds")]
[assembly: AssemblyVersion("1.0.0.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 JumpingBirds
{
	[BepInPlugin("com.celunar.JumpingBirds", "JumpingBirds", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static Plugin Instance;

		private void Awake()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"================================");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"JumpingBirds 1.0.0 loaded!");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Chicken ID: 114");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"================================");
			new Harmony("com.celunar.JumpingBirds").PatchAll();
		}

		internal static void SpawnChicken(Character character)
		{
			if ((Object)(object)character == (Object)null)
			{
				return;
			}
			try
			{
				Type type = FindType("ItemDatabase");
				Type type2 = FindType("GameUtils");
				if (type == null)
				{
					((BaseUnityPlugin)Instance).Logger.LogError((object)"ItemDatabase type not found!");
					return;
				}
				if (type2 == null)
				{
					((BaseUnityPlugin)Instance).Logger.LogError((object)"GameUtils type not found!");
					return;
				}
				object obj = FindObjectOfType(type);
				if (obj == null)
				{
					((BaseUnityPlugin)Instance).Logger.LogError((object)"ItemDatabase instance not found!");
					return;
				}
				object member = GetMember(obj, "itemLookup");
				if (member == null)
				{
					((BaseUnityPlugin)Instance).Logger.LogError((object)"itemLookup not found!");
					return;
				}
				Item val = FindItemById(member, 114);
				if ((Object)(object)val == (Object)null)
				{
					((BaseUnityPlugin)Instance).Logger.LogError((object)"ITEM 114 NOT FOUND!");
					return;
				}
				((BaseUnityPlugin)Instance).Logger.LogInfo((object)("ITEM 114 = " + ((Object)val).name));
				MethodInfo methodInfo = null;
				MethodInfo[] methods = type2.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo2 in methods)
				{
					if (!(methodInfo2.Name != "InstantiateAndGrab"))
					{
						ParameterInfo[] parameters = methodInfo2.GetParameters();
						if (parameters.Length == 3)
						{
							methodInfo = methodInfo2;
							break;
						}
					}
				}
				if (methodInfo == null)
				{
					((BaseUnityPlugin)Instance).Logger.LogError((object)"InstantiateAndGrab not found!");
					return;
				}
				object obj2 = null;
				if (!methodInfo.IsStatic)
				{
					obj2 = FindObjectOfType(type2);
					if (obj2 == null)
					{
						((BaseUnityPlugin)Instance).Logger.LogError((object)"GameUtils instance not found!");
						return;
					}
				}
				object[] parameters2 = new object[3] { val, character, 1 };
				methodInfo.Invoke(obj2, parameters2);
				((BaseUnityPlugin)Instance).Logger.LogInfo((object)"Chicken 114 spawned!");
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)Instance).Logger.LogError((object)"SPAWN ERROR:");
				((BaseUnityPlugin)Instance).Logger.LogError((object)ex.ToString());
			}
		}

		private static Type FindType(string name)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				Type type = assembly.GetType(name);
				if (type != null)
				{
					return type;
				}
				try
				{
					Type[] types = assembly.GetTypes();
					foreach (Type type2 in types)
					{
						if (type2.Name == name)
						{
							return type2;
						}
					}
				}
				catch
				{
				}
			}
			return null;
		}

		private static object FindObjectOfType(Type type)
		{
			Object[] array = Resources.FindObjectsOfTypeAll(type);
			if (array != null && array.Length != 0)
			{
				return array[0];
			}
			return null;
		}

		private static object GetMember(object obj, string name)
		{
			Type type = obj.GetType();
			FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				return field.GetValue(obj);
			}
			PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null)
			{
				return property.GetValue(obj);
			}
			return null;
		}

		private static Item FindItemById(object lookup, ushort wantedId)
		{
			if (!(lookup is IEnumerable enumerable))
			{
				return null;
			}
			foreach (object item in enumerable)
			{
				if (item == null)
				{
					continue;
				}
				Type type = item.GetType();
				PropertyInfo property = type.GetProperty("Key");
				PropertyInfo property2 = type.GetProperty("Value");
				if (property == null || property2 == null)
				{
					continue;
				}
				object value = property.GetValue(item);
				if (value != null)
				{
					ushort num;
					try
					{
						num = Convert.ToUInt16(value);
					}
					catch
					{
						continue;
					}
					if (num == wantedId)
					{
						object? value2 = property2.GetValue(item);
						return (Item)((value2 is Item) ? value2 : null);
					}
				}
			}
			return null;
		}
	}
	[HarmonyPatch(typeof(Character), "OnStartJump")]
	public static class Character_OnStartJump_Patch
	{
		[HarmonyPostfix]
		private static void Postfix(Character __instance)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				Plugin.SpawnChicken(__instance);
			}
		}
	}
}