Decompiled source of TetoRocket v1.0.0

plugins/TetoRocket.dll

Decompiled 6 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Fields;
using TetoPlush.Lib;
using UnityEngine;
using UnityEngine.Audio;

[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("TetoRocket")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TetoRocket")]
[assembly: AssemblyTitle("TetoRocket")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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 TetoPlush
{
	[BepInPlugin("com.plimous.tetoRocket", "Teto Plush Rocket Replacement", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class TetoMain : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "com.plimous.tetoRocket";

		public const string PLUGIN_NAME = "Teto Plush Rocket Replacement";

		public const string PLUGIN_VERSION = "1.0.0";

		private static AssetBundle? tetoassets;

		private static Harmony? harmony_inst;

		private static GameObject? teto;

		private static AudioClip? teto_audio;

		private static Texture2D? teto_image;

		public static GameObject Teto => teto;

		public static AudioClip TetoWav => teto_audio;

		public static Texture2D TetoImage => teto_image;

		private void Awake()
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			try
			{
				Stream manifestResourceStream = typeof(TetoMain).Assembly.GetManifestResourceStream("TetoRocket.Resources.teto_plush_assetbundle");
				if (manifestResourceStream != null)
				{
					tetoassets = AssetBundle.LoadFromStream(manifestResourceStream);
					teto = tetoassets.LoadAsset<GameObject>("teto_plush");
					teto_audio = tetoassets.LoadAsset<AudioClip>("teto_wav");
					if (ConfigCompat.Enabled)
					{
						teto_image = tetoassets.LoadAsset<Texture2D>("teto_image");
						ConfigCompat.PluginConfigIntializer("com.plimous.tetoRocket", "Teto Plush Rocket Replacement");
					}
					else
					{
						Debug.LogWarning((object)new string("PluginConfigurator optional dependency not found; continuing..."));
					}
					harmony_inst = new Harmony("com.plimous.tetoRocket");
					harmony_inst.PatchAll();
					return;
				}
				throw new NullReferenceException();
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)$"Exception with type {arg}");
			}
		}
	}
}
namespace TetoPlush.Patches
{
	[HarmonyPatch(typeof(Grenade))]
	internal static class TetoRocket
	{
		private static readonly AudioMixerGroup MIXER_GROUP = MonoSingleton<AudioMixerController>.Instance.allGroup;

		private static readonly float ROCKET_VECTOR_SCALE = 90f;

		private static readonly float CORE_VECTOR_SCALE = 50f;

		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void GrenadeInitializer(Grenade __instance)
		{
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			bool enemyRocketModelEnabled = ConfigCompat.EnemyRocketModelEnabled;
			bool enemyRocketSoundEnabled = ConfigCompat.EnemyRocketSoundEnabled;
			bool playerRocketSoundEnabled = ConfigCompat.PlayerRocketSoundEnabled;
			if (!__instance.enemy || enemyRocketModelEnabled)
			{
				MeshRenderer[] componentsInChildren = ((Component)__instance).gameObject.GetComponentsInChildren<MeshRenderer>();
				GameObject val = Object.Instantiate<GameObject>(TetoMain.Teto, ((Component)__instance).transform);
				MeshRenderer componentInChildren = val.GetComponentInChildren<MeshRenderer>();
				if (__instance.rocket)
				{
					val.transform.localEulerAngles = new Vector3(0f, 0f, 180f);
					Transform transform = val.transform;
					transform.localPosition += new Vector3(0f, 0f, 1f);
					val.transform.localScale = new Vector3(ROCKET_VECTOR_SCALE, ROCKET_VECTOR_SCALE, ROCKET_VECTOR_SCALE);
				}
				else
				{
					val.transform.localScale = new Vector3(CORE_VECTOR_SCALE, CORE_VECTOR_SCALE, CORE_VECTOR_SCALE);
				}
				val.gameObject.layer = 25;
				MeshRenderer[] array = componentsInChildren;
				foreach (MeshRenderer val2 in array)
				{
					((Renderer)val2).enabled = false;
				}
				((Renderer)componentInChildren).material.shader = ((Renderer)componentsInChildren[0]).material.shader;
				((Renderer)componentInChildren).receiveShadows = false;
				if ((!__instance.enemy && playerRocketSoundEnabled) || (__instance.enemy && enemyRocketSoundEnabled))
				{
					AudioSourceSetter(val);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("Explode")]
		private static void TetoAudioContinueOnExplode(Grenade __instance)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)__instance).transform.Find("teto_plush(Clone)");
			AudioSource val2 = default(AudioSource);
			if ((Object)(object)val != (Object)null && ((Component)val).gameObject.TryGetComponent<AudioSource>(ref val2))
			{
				int timeSamples = val2.timeSamples;
				if (timeSamples > 0 && val2.timeSamples < val2.clip.samples)
				{
					((Component)val2).gameObject.transform.DetachChildren();
					AudioSource val3 = Object.Instantiate<AudioSource>(val2, ((Component)val2).transform.position, ((Component)val2).transform.rotation);
					Object.Destroy((Object)(object)((Component)val3).gameObject.GetComponentInChildren<MeshRenderer>());
					Object.Destroy((Object)(object)((Component)val3).gameObject.GetComponentInChildren<MeshFilter>());
					val3.timeSamples = timeSamples;
					((Behaviour)val3).enabled = true;
					AudioSourceExtensions.Play(val3, true);
					Object.Destroy((Object)(object)((Component)val3).gameObject, 1f);
				}
			}
		}

		private static void AudioSourceSetter(GameObject obj)
		{
			AudioSource val = obj.gameObject.AddComponent<AudioSource>();
			val.clip = Object.Instantiate<AudioClip>(TetoMain.TetoWav);
			((Component)val).transform.SetParent(obj.transform);
			val.outputAudioMixerGroup = MIXER_GROUP;
			val.volume = 1f;
			val.minDistance = 20f;
			val.maxDistance = 80f;
			val.rolloffMode = (AudioRolloffMode)1;
			val.dopplerLevel = 0.075f;
			val.spatialBlend = 1f;
			AudioSourceExtensions.Play(val, true);
		}
	}
}
namespace TetoPlush.Lib
{
	public static class ConfigCompat
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static BoolValueChangeEventDelegate <>9__12_1;

			public static BoolValueChangeEventDelegate <>9__12_2;

			internal void <PluginConfigIntializer>b__12_1(BoolValueChangeEvent e)
			{
				enemyRocketSound = e.value;
			}

			internal void <PluginConfigIntializer>b__12_2(BoolValueChangeEvent e)
			{
				playerRocketSound = e.value;
			}
		}

		private static bool enemyRocket;

		private static bool enemyRocketSound;

		private static bool playerRocketSound;

		private static bool? enabledValue;

		public static bool Enabled
		{
			get
			{
				if (!enabledValue.HasValue)
				{
					enabledValue = Chainloader.PluginInfos.ContainsKey("com.eternalUnion.pluginConfigurator");
				}
				return enabledValue.Value;
			}
		}

		public static bool EnemyRocketModelEnabled => !Enabled || enemyRocket;

		public static bool EnemyRocketSoundEnabled => !Enabled || enemyRocketSound;

		public static bool PlayerRocketSoundEnabled => !Enabled || playerRocketSound;

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void PluginConfigIntializer(string modGUID, string modName)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			PluginConfigurator val = PluginConfigurator.Create(modName, modGUID);
			val.presetButtonHidden = true;
			val.presetButtonInteractable = false;
			Texture2D tetoImage = TetoMain.TetoImage;
			Sprite image = Sprite.Create(tetoImage, new Rect(0f, 0f, (float)((Texture)tetoImage).width, (float)((Texture)tetoImage).height), new Vector2(0f, 0f));
			val.image = image;
			BoolField val2 = new BoolField(val.rootPanel, "Enemy Rockets Are Plush", "does_enemy_rocket", true);
			ConfigDivision div = new ConfigDivision(val.rootPanel, "enemy_division")
			{
				interactable = val2.value
			};
			BoolField val3 = new BoolField((ConfigPanel)(object)div, "Enemy Rocket Teto Noise", "does_enemy_rocket_sound", true);
			BoolField val4 = new BoolField(val.rootPanel, "Player Rocket Teto Noise", "does_player_rocket_sound", true);
			enemyRocket = val2.value;
			enemyRocketSound = val3.value;
			playerRocketSound = val4.value;
			val2.onValueChange += (BoolValueChangeEventDelegate)delegate(BoolValueChangeEvent e)
			{
				((ConfigField)div).interactable = e.value;
				enemyRocket = e.value;
			};
			object obj = <>c.<>9__12_1;
			if (obj == null)
			{
				BoolValueChangeEventDelegate val5 = delegate(BoolValueChangeEvent e)
				{
					enemyRocketSound = e.value;
				};
				<>c.<>9__12_1 = val5;
				obj = (object)val5;
			}
			val3.onValueChange += (BoolValueChangeEventDelegate)obj;
			object obj2 = <>c.<>9__12_2;
			if (obj2 == null)
			{
				BoolValueChangeEventDelegate val6 = delegate(BoolValueChangeEvent e)
				{
					playerRocketSound = e.value;
				};
				<>c.<>9__12_2 = val6;
				obj2 = (object)val6;
			}
			val4.onValueChange += (BoolValueChangeEventDelegate)obj2;
		}
	}
}