Decompiled source of LCSplatBombGrenadeMod v1.1.4

LCSplatBombGrenadeMod.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using HarmonyLib.Tools;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("LCSplatBombGrenadeMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Replace the model and sounds of the Stun Grenade with Splat Bombs from Splatoon!")]
[assembly: AssemblyFileVersion("1.1.4.0")]
[assembly: AssemblyInformationalVersion("1.1.4")]
[assembly: AssemblyProduct("LCSplatBombGrenadeMod")]
[assembly: AssemblyTitle("LCSplatBombGrenadeMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.4.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 LCSplatBombGrenadeMod
{
	internal class HarmonyPatches
	{
		[HarmonyPatch(typeof(StartOfRound), "Start")]
		public class NewStartOfRoundStart
		{
			[HarmonyPostfix]
			public static void Postfix(StartOfRound __instance)
			{
				if (SetStunGrenade)
				{
					return;
				}
				foreach (Item items in __instance.allItemsList.itemsList)
				{
					if (((Object)items).name == "StunGrenade")
					{
						Plugin.Logger.LogDebug((object)"Found stun grenade, setting item properties and terminal text to Splat Bomb...");
						StunGrenadeItem component = items.spawnPrefab.GetComponent<StunGrenadeItem>();
						items.itemName = "Splat Bomb";
						items.toolTips[0] = "Use Splat Bomb : [LMB]";
						((Vector3)(ref items.positionOffset)).Set(-0.2f, 0.17f, 0.03f);
						((Vector3)(ref items.rotationOffset)).Set(180f, -25f, 0f);
						items.verticalOffset = 0.03f;
						Plugin.SetIconsAndSounds(component);
						Plugin.SetSplatBombKeyword();
						SetStunGrenade = true;
						break;
					}
				}
				Plugin.PostSetExistingPrefabs();
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "Start")]
		public class NewStunGrenadeStart
		{
			[HarmonyPostfix]
			public static void Postfix(GrabbableObject __instance)
			{
				if (((Object)__instance).name == "StunGrenade(Clone)")
				{
					StunGrenadeItem component = ((Component)__instance).GetComponent<StunGrenadeItem>();
					MeshFilter component2 = ((Component)__instance).GetComponent<MeshFilter>();
					MeshFilter component3 = ((Component)((Component)__instance).transform.GetChild(0)).GetComponent<MeshFilter>();
					component3.mesh = null;
					Plugin.SetNewChildBomb(component, component2);
				}
			}
		}

		[HarmonyPatch(typeof(StunGrenadeItem), "SetControlTipForGrenade")]
		public class NewStunGrenadeSetControlTip
		{
			[HarmonyPostfix]
			public static void Postfix(StunGrenadeItem __instance)
			{
				string[] array = (__instance.pinPulled ? new string[1] { "Throw Splat Bomb : [LMB]" } : new string[1] { "Activate Splat Bomb : [LMB] " });
				if (((NetworkBehaviour)__instance).IsOwner && ((Object)((Component)__instance).gameObject).name == "StunGrenade(Clone)")
				{
					HUDManager.Instance.ChangeControlTipMultiple(array, true, ((GrabbableObject)__instance).itemProperties);
				}
			}
		}

		[HarmonyPatch(typeof(StunGrenadeItem), "ExplodeStunGrenade")]
		public class NewStunGrenadeExplode
		{
			[HarmonyPostfix]
			public static void Postfix(StunGrenadeItem __instance)
			{
				if (((Object)((Component)__instance).gameObject).name == "StunGrenade(Clone)")
				{
					((Renderer)((Component)((Component)__instance).transform.GetChild(2).GetChild(1)).GetComponent<MeshRenderer>()).material = Plugin.SplatBombEmptyMaterial;
				}
			}
		}

		public static bool SetStunGrenade;
	}
	[BepInPlugin("LCSplatBombGrenadeMod", "LCSplatBombGrenadeMod", "1.1.4")]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin instance;

		internal static ManualLogSource Logger;

		public string sAssemblyLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		public static AssetBundle SplatBombModAssets;

		public static GameObject SplatBomb;

		public static GameObject SplatBombInkSplattersGround;

		public static AudioClip SplatBombPullPinSFX;

		public static AudioClip SplatBombExplodeSFX;

		public static AudioClip SplatBombGrabSFX;

		public static AudioClip SplatBombPocketSFX;

		public static AudioClip SplatBombDropSFX;

		public static Sprite SplatBombIcon;

		public static Material SplatBombEmptyMaterial;

		private void Awake()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin LCSplatBombGrenadeMod is loaded!");
			Harmony val = new Harmony("LCSplatBombGrenadeMod");
			val.PatchAll();
			HarmonyFileLog.Enabled = false;
			SplatBombModAssets = AssetBundle.LoadFromFile(Path.Combine(sAssemblyLocation, "splatbombmodassets"));
			if ((Object)(object)SplatBombModAssets == (Object)null)
			{
				Logger.LogError((object)"Failed to load SplatBomb AssetBundle");
				return;
			}
			Logger.LogInfo((object)"Loaded SplatBomb AssetBundle");
			SplatBomb = SplatBombModAssets.LoadAsset<GameObject>("Assets/SplatBombPrefab.prefab");
			SplatBombIcon = SplatBombModAssets.LoadAsset<Sprite>("Assets/ItemIcon.png");
			SplatBombPullPinSFX = SplatBombModAssets.LoadAsset<AudioClip>("Assets/SplatSounds/SplatPullPinSFX.ogg");
			SplatBombExplodeSFX = SplatBombModAssets.LoadAsset<AudioClip>("Assets/SplatSounds/SplatExplodeSFX.ogg");
			SplatBombGrabSFX = SplatBombModAssets.LoadAsset<AudioClip>("Assets/SplatSounds/SplatGrabSFX.ogg");
			SplatBombPocketSFX = SplatBombModAssets.LoadAsset<AudioClip>("Assets/SplatSounds/SplatPocketSFX.ogg");
			SplatBombDropSFX = SplatBombModAssets.LoadAsset<AudioClip>("Assets/SplatSounds/SplatDropSFX.ogg");
			SplatBombInkSplattersGround = SplatBombModAssets.LoadAsset<GameObject>("Assets/SplatInk/GroundSplatters/SplatBombInkSplattersGround.prefab");
			SplatBombEmptyMaterial = SplatBombModAssets.LoadAsset<Material>("Assets/SplatBombAssets/EmptyMaterial.mat");
		}

		public static void SetIconsAndSounds(StunGrenadeItem __instance)
		{
			__instance.pullPinSFX = SplatBombPullPinSFX;
			__instance.explodeSFX = SplatBombExplodeSFX;
			((GrabbableObject)__instance).itemProperties.itemIcon = SplatBombIcon;
			((GrabbableObject)__instance).itemProperties.grabSFX = SplatBombGrabSFX;
			((GrabbableObject)__instance).itemProperties.pocketSFX = SplatBombPocketSFX;
			((GrabbableObject)__instance).itemProperties.dropSFX = SplatBombDropSFX;
			__instance.stunGrenadeExplosion = SplatBombInkSplattersGround;
		}

		public static void SetSplatBombKeyword()
		{
			Terminal val = Object.FindObjectOfType<Terminal>();
			TerminalKeyword val2 = null;
			bool flag = false;
			bool flag2 = false;
			TerminalKeyword[] allKeywords = val.terminalNodes.allKeywords;
			foreach (TerminalKeyword val3 in allKeywords)
			{
				if (((Object)val3).name == "StunGrenade")
				{
					val3.word = "splat";
					flag = true;
				}
				else if (((Object)val3).name == "Buy")
				{
					val2 = val3;
					flag2 = true;
				}
				if (flag && flag2)
				{
					break;
				}
			}
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			TerminalNode val4 = null;
			CompatibleNoun[] compatibleNouns = val2.compatibleNouns;
			foreach (CompatibleNoun val5 in compatibleNouns)
			{
				if (((Object)val5.noun).name == "StunGrenade")
				{
					val4 = val5.result;
					break;
				}
			}
			if (!((Object)(object)val4 == (Object)null))
			{
				val4.displayText = "You have requested to order Splat Bombs. Amount: [variableAmount].\nTotal cost of items: [totalCost].\n\nPlease CONFIRM or DENY.\n\n";
				val4.terminalOptions[0].result.displayText = "Ordered [variableAmount] Splat Bombs. Your new balance is [playerCredits].\n\nOur contractors enjoy fast, free shipping while on the job! Any purchased items will arrive hourly at your approximate location.\n\n";
			}
		}

		public static void SetNewChildBomb(StunGrenadeItem GrenadeScript, MeshFilter OriginalMesh)
		{
			Object.Instantiate<GameObject>(SplatBomb, ((Component)GrenadeScript).transform);
			OriginalMesh.mesh = ((Component)SplatBomb.transform.GetChild(0)).GetComponent<MeshFilter>().mesh;
		}

		public static void PostSetExistingPrefabs()
		{
			StunGrenadeItem[] array = Object.FindObjectsOfType<StunGrenadeItem>();
			StunGrenadeItem[] array2 = array;
			foreach (StunGrenadeItem val in array2)
			{
				if (((Object)((Component)val).gameObject).name == "StunGrenade(Clone)")
				{
					val.pullPinSFX = SplatBombPullPinSFX;
					val.explodeSFX = SplatBombExplodeSFX;
					val.stunGrenadeExplosion = SplatBombInkSplattersGround;
					if (val.hasExploded)
					{
						((Renderer)((Component)((Component)val).transform.GetChild(2).GetChild(1)).GetComponent<MeshRenderer>()).material = SplatBombEmptyMaterial;
					}
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LCSplatBombGrenadeMod";

		public const string PLUGIN_NAME = "LCSplatBombGrenadeMod";

		public const string PLUGIN_VERSION = "1.1.4";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}