Decompiled source of Morph Ball Soccer v1.0.0

MorphBall.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MorphBall")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MorphBall")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("57f833e0-fd87-40ba-a798-ac42c29f3bd7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MorphBall
{
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.Dummydude.MorphBall";

		public const string PLUGIN_NAME = "MorphBall";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	[BepInPlugin("com.Dummydude.MorphBall", "MorphBall", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("com.Dummydude.MorphBall");

		public static string mainAssetBundleName = "balls";

		public static AssetBundle MainAssetBundle = null;

		public GameObject VariaMorph;

		public GameObject LightMorph;

		public GameObject DarkMorph;

		public GameObject PowerMorph;

		public GameObject MetroidMorph;

		public GameObject GravityMorph;

		public GameObject[] morphGameObjects;

		public static Plugin Instance { get; private set; }

		public static ManualLogSource Log => ((BaseUnityPlugin)Instance).Logger;

		public void Awake()
		{
			Instance = this;
			Log.LogInfo((object)"Subscirbe to Dummydude");
			harmony.PatchAll();
			PopulateAssets();
		}

		private static string GetAssemblyName()
		{
			return Assembly.GetExecutingAssembly().GetName().Name.Replace(" ", "_");
		}

		public static void PopulateAssets()
		{
			if ((Object)(object)MainAssetBundle == (Object)null)
			{
				Console.WriteLine(GetAssemblyName() + "." + mainAssetBundleName);
				using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetAssemblyName() + "." + mainAssetBundleName);
				MainAssetBundle = AssetBundle.LoadFromStream(stream);
			}
			Instance.morphGameObjects = MainAssetBundle.LoadAllAssets<GameObject>();
			Instance.VariaMorph = MainAssetBundle.LoadAsset<GameObject>("morphball8");
			Instance.LightMorph = MainAssetBundle.LoadAsset<GameObject>("morphball3");
			Instance.DarkMorph = MainAssetBundle.LoadAsset<GameObject>("morphball4");
			Instance.PowerMorph = MainAssetBundle.LoadAsset<GameObject>("morphball5");
			Instance.MetroidMorph = MainAssetBundle.LoadAsset<GameObject>("morphball6");
			Instance.GravityMorph = MainAssetBundle.LoadAsset<GameObject>("morphball7");
		}
	}
}
namespace MorphBall.Patches
{
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class GrabbableObjectPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		internal static void ReplaceModel(GrabbableObject __instance)
		{
			((MonoBehaviour)StartOfRound.Instance).StartCoroutine(delay(__instance));
		}

		[HarmonyPatch("LoadItemSaveData")]
		[HarmonyPrefix]
		public static bool LoadSoccerBallData(GrabbableObject __instance, int saveData)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.itemProperties.itemName == "Soccer ball")
			{
				Plugin.Log.LogInfo((object)$"Got soccerball input data. the save value is {saveData}");
				__instance.useCooldown = saveData;
				GameObject val = Object.Instantiate<GameObject>(Plugin.Instance.morphGameObjects[(int)(__instance.useCooldown - 1f)], ((Component)__instance).gameObject.transform);
				val.transform.rotation = Quaternion.Euler(0f, 90f, 20f);
				val.transform.position = ((Component)__instance).transform.position;
				val.transform.localScale = new Vector3(2f, 2f, 2f);
				((Renderer)((Component)__instance).gameObject.GetComponent<MeshRenderer>()).material = null;
				((Component)__instance).gameObject.GetComponent<MeshFilter>().mesh = null;
			}
			return true;
		}

		[HarmonyPatch("GetItemDataToSave")]
		[HarmonyPrefix]
		public static bool GetSoccerBallDataToSave(GrabbableObject __instance, ref int __result)
		{
			if (__instance.itemProperties.itemName == "Soccer ball")
			{
				Plugin.Log.LogInfo((object)$"Morph Ball Variant is: {__instance.useCooldown}");
				__result = (int)__instance.useCooldown;
			}
			return false;
		}

		internal static IEnumerator delay(GrabbableObject __instance)
		{
			yield return (object)new WaitForSeconds(0.5f);
			if (__instance.itemProperties.itemName == "Soccer ball" && __instance.useCooldown == 0f)
			{
				Plugin.Log.LogWarning((object)"The save value of the Soccer Ball is 0. This either means there is a safe file issue, or the Soccer Ball just spawned.");
				__instance.useCooldown = Random.Range(1, Plugin.Instance.morphGameObjects.Length + 1);
				GameObject randomMorph = Plugin.Instance.morphGameObjects[(int)__instance.useCooldown - 1];
				GameObject morphball = Object.Instantiate<GameObject>(randomMorph, ((Component)__instance).gameObject.transform);
				morphball.transform.rotation = Quaternion.Euler(0f, 90f, 20f);
				morphball.transform.position = ((Component)__instance).transform.position;
				morphball.transform.localScale = new Vector3(2f, 2f, 2f);
				((Renderer)((Component)__instance).gameObject.GetComponent<MeshRenderer>()).material = null;
				((Component)__instance).gameObject.GetComponent<MeshFilter>().mesh = null;
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("LoadShipGrabbableItems")]
		[HarmonyPrefix]
		public static bool Method(StartOfRound __instance)
		{
			for (int i = 0; i < __instance.allItemsList.itemsList.Count; i++)
			{
				if (__instance.allItemsList.itemsList[i].itemName == "Soccer ball")
				{
					__instance.allItemsList.itemsList[i].saveItemVariable = true;
					Plugin.Log.LogInfo((object)"Successfully patched the item list.");
				}
			}
			return true;
		}
	}
}