Decompiled source of LCBlackhand v0.1.1

BepInEx/plugins/LCBlackhand.dll

Decompiled a year ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
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 Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LCBlackhand")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Blackhand for Lethal Company")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1")]
[assembly: AssemblyProduct("LCBlackhand")]
[assembly: AssemblyTitle("LCBlackhand")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.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 LethalCompanyBlackhand
{
	[BepInPlugin("LCBlackhand.72BABE48-2C08-4594-8E75-54B90CCB1CFD", "LC Blackhand Mod", "0.1.0")]
	public class BlackHandPlugin : BaseUnityPlugin
	{
		private const string PLUGIN_GUID = "LCBlackhand.72BABE48-2C08-4594-8E75-54B90CCB1CFD";

		private const string PLUGIN_NAME = "LC Blackhand Mod";

		private const string PLUGIN_VERSION = "0.1.0";

		private readonly Harmony harmony = new Harmony("LCBlackhand.72BABE48-2C08-4594-8E75-54B90CCB1CFD");

		public static BlackHandPlugin Instance { get; private set; }

		public static string PluginPath { get; private set; }

		public static AssetBundle AssetBundle { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			PluginPath = ((BaseUnityPlugin)this).Info.Location;
			LogInfo("Loading blackhand...");
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(PluginPath), "blackhandassetbundle"));
			if ((Object)(object)val == (Object)null)
			{
				LogError("Failed to load blackhand assets!");
				return;
			}
			AssetBundle = val;
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin LCBlackhand.72BABE48-2C08-4594-8E75-54B90CCB1CFD is loaded! CNMD");
		}

		public static void LogInfo(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)16, (object)message);
		}

		public static void LogWarning(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)4, (object)message);
		}

		public static void LogError(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)2, (object)message);
		}

		public static void LogError(Exception ex)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)2, (object)ex);
		}

		public static void LogDebug(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)32, (object)message);
		}
	}
	internal class SharedCoroutineStarter : MonoBehaviour
	{
		private static SharedCoroutineStarter _instance;

		public static Coroutine StartCoroutine(IEnumerator routine)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_instance == (Object)null)
			{
				_instance = new GameObject("Shared Coroutine Starter").AddComponent<SharedCoroutineStarter>();
				Object.DontDestroyOnLoad((Object)(object)_instance);
			}
			return ((MonoBehaviour)_instance).StartCoroutine(routine);
		}
	}
	public class LoadFromFileExample : MonoBehaviour
	{
		private void Start()
		{
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "myassetBundle"));
			if ((Object)(object)val == (Object)null)
			{
				Debug.Log((object)"Failed to load AssetBundle!");
			}
			else
			{
				val.LoadAsset<GameObject>("MyObject");
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LCBlackhand";

		public const string PLUGIN_NAME = "LCBlackhand";

		public const string PLUGIN_VERSION = "0.0.1";
	}
}
namespace LethalCompanyBlackhand.Patches
{
	internal static class AudioLoad
	{
		private static bool FirstRun = true;

		public static List<AudioClip> ShovelAC = new List<AudioClip>();

		public static bool FinishedLoading = false;

		public static void Load()
		{
			if (FirstRun)
			{
				FirstRun = false;
				if ((Object)(object)BlackHandPlugin.AssetBundle == (Object)null)
				{
					BlackHandPlugin.LogError("Assetbundle is null");
				}
				else
				{
					SharedCoroutineStarter.StartCoroutine(LoadBlackhandFromBundle(BlackHandPlugin.AssetBundle));
				}
			}
		}

		private static IEnumerator LoadBlackhandFromBundle(AssetBundle assetBundle)
		{
			try
			{
				ShovelAC = (from ac in assetBundle.LoadAllAssets<AudioClip>()
					where AudioMap.Shovel.Contains(((Object)ac).name)
					select ac).ToList();
			}
			catch
			{
			}
			yield break;
		}

		private static IEnumerator LoadAudioClip(string directory)
		{
			BlackHandPlugin.LogInfo("Loading " + directory);
			string[] files = Directory.GetFiles(directory, "*.mp3");
			string[] array = files;
			foreach (string file in array)
			{
				UnityWebRequest loader = UnityWebRequestMultimedia.GetAudioClip(file, (AudioType)13);
				loader.SendWebRequest();
				while (!loader.isDone)
				{
					yield return null;
				}
				if (loader.error != null)
				{
					BlackHandPlugin.LogError("Error loading " + file + "\n" + loader.error);
					yield return null;
				}
				AudioClip content = DownloadHandlerAudioClip.GetContent(loader);
				if (Object.op_Implicit((Object)(object)content) && (int)content.loadState == 2)
				{
					((Object)content).name = Path.GetFileName(file);
					ShovelAC.Add(content);
				}
			}
			BlackHandPlugin.LogInfo("Done loading blackhand");
			FinishedLoading = true;
		}
	}
	internal class AudioMap
	{
		public static IEnumerable<string> Shovel { get; private set; } = new HashSet<string>
		{
			"cnm1", "cnm2", "cnm3", "cnm4", "cao", "wocao", "bzb", "cnmgl", "nsgd", "cnmdngg",
			"nzmggyy"
		};

	}
	[HarmonyPatch(typeof(ItemDropship))]
	internal class ItemDropshipPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void patch(ItemDropship __instance)
		{
			AudioClip clip = BlackHandPlugin.AssetBundle.LoadAsset<AudioClip>("蓝精灵");
			AudioSource component = ((Component)((Component)__instance).transform.Find("Music")).gameObject.GetComponent<AudioSource>();
			AudioSource component2 = ((Component)((Component)((Component)__instance).transform.Find("Music")).transform.Find("Music (1)")).gameObject.GetComponent<AudioSource>();
			component.clip = clip;
			component2.clip = clip;
		}
	}
	[HarmonyPatch(typeof(ShipAlarmCord))]
	internal class ShipAlarmCordPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Postfix(ShipAlarmCord __instance)
		{
			__instance.hornFar.clip = BlackHandPlugin.AssetBundle.LoadAsset<AudioClip>("百家争鸣");
			__instance.hornClose.clip = BlackHandPlugin.AssetBundle.LoadAsset<AudioClip>("百家争鸣");
			__instance.cordPullSFX = BlackHandPlugin.AssetBundle.LoadAsset<AudioClip>("我操");
		}
	}
	[HarmonyPatch(typeof(ShipTeleporter))]
	internal class ShipTeleporterPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void Postfix(ShipTeleporter __instance)
		{
			__instance.teleporterSpinSFX = BlackHandPlugin.AssetBundle.LoadAsset<AudioClip>("3600度旋转");
			__instance.teleporterBeamUpSFX = BlackHandPlugin.AssetBundle.LoadAsset<AudioClip>("揭谛揭谛");
		}
	}
	[HarmonyPatch(typeof(Shovel))]
	internal class ShovelPatch
	{
		private static int lastcnm = -1;

		[HarmonyPatch("SwingShovel")]
		[HarmonyPrefix]
		private static void PrefixSwing(Shovel __instance, bool cancel = false)
		{
			if (AudioLoad.ShovelAC.Count != 0)
			{
				int index = new Random().Next(0, AudioLoad.ShovelAC.Count - 1);
				AudioClip val = AudioLoad.ShovelAC[index];
				if (!(((Object)__instance.swing).name == ((Object)val).name))
				{
					__instance.swing = val;
					BlackHandPlugin.LogDebug("黑手!");
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		private static void Prefix()
		{
			AudioLoad.Load();
		}
	}
	[HarmonyPatch(typeof(Turret))]
	internal class TurrentPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Postfix(Turret __instance)
		{
			__instance.detectPlayerSFX = BlackHandPlugin.AssetBundle.LoadAsset<AudioClip>("听懂了吗");
			__instance.firingSFX = BlackHandPlugin.AssetBundle.LoadAsset<AudioClip>("滚你妈逼老骚逼");
		}
	}
	[HarmonyPatch(typeof(WalkieTalkie))]
	internal class WalkieTalkiePatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Postfix(WalkieTalkie __instance)
		{
			__instance.switchWalkieTalkiePowerOn = BlackHandPlugin.AssetBundle.LoadAsset<AudioClip>("我操");
			__instance.switchWalkieTalkiePowerOff = BlackHandPlugin.AssetBundle.LoadAsset<AudioClip>("你怎么这么自私");
		}
	}
}