Decompiled source of KakaBug v1.6.0

KakaBug.dll

Decompiled 4 months ago
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 HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;

[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 = "")]
[assembly: AssemblyCompany("KakaBug")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Changes the Hoarder Bugs's chitter sound to Danikaka's woohoo! And more!")]
[assembly: AssemblyFileVersion("1.6.0.0")]
[assembly: AssemblyInformationalVersion("1.6.0")]
[assembly: AssemblyProduct("KakaBug")]
[assembly: AssemblyTitle("KakaBug")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.6.0.0")]
[module: UnverifiableCode]
namespace KakaBug;

[BepInPlugin("KakaBug", "KakaBug", "1.6.0")]
public class Plugin : BaseUnityPlugin
{
	public static AudioClip[] Audio = (AudioClip[])(object)new AudioClip[15];

	public static Sprite kakaFaceSprite1;

	public static Sprite kakaFaceSprite2;

	public static Sprite kakaFaceSprite3;

	public static Sprite kakaFaceSprite4;

	public static Sprite kakaBugFaceSprite;

	public static Sprite kakaBugFaceSprite1;

	public static Texture2D fishPosterTexture;

	public static SpriteRenderer screenSpriteRend;

	private UnityWebRequest getAudioLoader(string location, string file)
	{
		return UnityWebRequestMultimedia.GetAudioClip("File://" + location + file, (AudioType)13);
	}

	private void Awake()
	{
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Expected O, but got Unknown
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Expected O, but got Unknown
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Expected O, but got Unknown
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Expected O, but got Unknown
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Expected O, but got Unknown
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Unknown result type (might be due to invalid IL or missing references)
		//IL_029e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Expected O, but got Unknown
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02df: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0307: Expected O, but got Unknown
		//IL_032e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0335: Expected O, but got Unknown
		//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0411: Unknown result type (might be due to invalid IL or missing references)
		//IL_042b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0445: Unknown result type (might be due to invalid IL or missing references)
		//IL_045f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0479: Unknown result type (might be due to invalid IL or missing references)
		//IL_0493: Unknown result type (might be due to invalid IL or missing references)
		//IL_0354: Unknown result type (might be due to invalid IL or missing references)
		//IL_035a: Invalid comparison between Unknown and I4
		string text = ((BaseUnityPlugin)this).Info.Location.TrimEnd("KakaBug.dll".ToCharArray());
		if (Directory.Exists(Path.Combine(text, "KakaBug")))
		{
			text += "KakaBug\\";
		}
		ArrayList arrayList = new ArrayList();
		arrayList.Add(getAudioLoader(text, "woohoo.mp3"));
		arrayList.Add(getAudioLoader(text, "mlm.mp3"));
		arrayList.Add(getAudioLoader(text, "chomp.mp3"));
		arrayList.Add(getAudioLoader(text, "woof.mp3"));
		arrayList.Add(getAudioLoader(text, "chillbanko.mp3"));
		arrayList.Add(getAudioLoader(text, "binary-bars.mp3"));
		string path = text + "kakaBugFace.png";
		string path2 = text + "kakaBugFaceTalk.png";
		string path3 = text + "kakaScreenFace1.png";
		string path4 = text + "kakaScreenFace2.png";
		string path5 = text + "kakaScreenFace3.png";
		Texture2D val = new Texture2D(2, 2);
		Texture2D val2 = new Texture2D(2, 2);
		Texture2D val3 = new Texture2D(2, 2);
		Texture2D val4 = new Texture2D(2, 2);
		Texture2D val5 = new Texture2D(2, 2);
		ImageConversion.LoadImage(val, File.ReadAllBytes(path));
		ImageConversion.LoadImage(val2, File.ReadAllBytes(path2));
		ImageConversion.LoadImage(val3, File.ReadAllBytes(path3));
		ImageConversion.LoadImage(val4, File.ReadAllBytes(path4));
		ImageConversion.LoadImage(val5, File.ReadAllBytes(path5));
		kakaBugFaceSprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		kakaBugFaceSprite1 = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f));
		kakaFaceSprite1 = Sprite.Create(val3, new Rect(0f, 0f, (float)((Texture)val3).width, (float)((Texture)val3).height), new Vector2(0.5f, 0.5f));
		kakaFaceSprite2 = Sprite.Create(val4, new Rect(0f, 0f, (float)((Texture)val4).width, (float)((Texture)val4).height), new Vector2(0.5f, 0.5f));
		kakaFaceSprite3 = Sprite.Create(val5, new Rect(0f, 0f, (float)((Texture)val5).width, (float)((Texture)val5).height), new Vector2(0.5f, 0.5f));
		string path6 = text + "Disgrace.png";
		Texture2D val6 = new Texture2D(2, 2);
		ImageConversion.LoadImage(val6, File.ReadAllBytes(path6));
		kakaFaceSprite4 = Sprite.Create(val6, new Rect(0f, 0f, (float)((Texture)val6).width, (float)((Texture)val6).height), new Vector2(0.5f, 0.5f));
		string path7 = text + "sushi-party.png";
		fishPosterTexture = new Texture2D(2, 2);
		ImageConversion.LoadImage(fishPosterTexture, File.ReadAllBytes(path7));
		int num = 0;
		foreach (UnityWebRequest item in arrayList)
		{
			UnityWebRequest val7 = item;
			val7.SendWebRequest();
			while (!val7.isDone)
			{
			}
			if ((int)val7.result == 1)
			{
				Audio[num] = DownloadHandlerAudioClip.GetContent(val7);
				num++;
				continue;
			}
			((BaseUnityPlugin)this).Logger.LogError((object)$"Could not load all audio files.\tAt least 1 of {arrayList.Count} files are missing.");
			return;
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Finished getting audio!");
		new Harmony("KakaBug").PatchAll(typeof(HoarderBugPatch));
		new Harmony("KakaBug").PatchAll(typeof(CrawlerPatch));
		new Harmony("KakaBug").PatchAll(typeof(MouthDogPatch));
		new Harmony("KakaBug").PatchAll(typeof(JesterPatch));
		new Harmony("KakaBug").PatchAll(typeof(SpritePatch));
		new Harmony("KakaBug").PatchAll(typeof(ScreenPatch));
		new Harmony("KakaBug").PatchAll(typeof(FirePlayersEventPatch));
		new Harmony("KakaBug").PatchAll(typeof(VehiclePatch));
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin KakaBug is loaded!");
	}
}
[HarmonyPatch(typeof(HoarderBugAI))]
internal class HoarderBugPatch
{
	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void AudioPatch(HoarderBugAI __instance)
	{
		AudioClip[] chitterSFX = (AudioClip[])(object)new AudioClip[1] { Plugin.Audio[0] };
		__instance.chitterSFX = chitterSFX;
	}
}
[HarmonyPatch(typeof(CrawlerAI))]
internal class CrawlerPatch
{
	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void AudioPatch1(CrawlerAI __instance)
	{
		AudioClip[] longRoarSFX = (AudioClip[])(object)new AudioClip[1] { Plugin.Audio[1] };
		AudioClip bitePlayerSFX = Plugin.Audio[2];
		__instance.longRoarSFX = longRoarSFX;
		__instance.bitePlayerSFX = bitePlayerSFX;
	}
}
[HarmonyPatch(typeof(MouthDogAI))]
internal class MouthDogPatch
{
	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void AudioPatch2(MouthDogAI __instance)
	{
		__instance.breathingSFX = Plugin.Audio[3];
	}
}
[HarmonyPatch(typeof(JesterAI))]
internal class JesterPatch
{
	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void AudioPatch3(JesterAI __instance)
	{
		__instance.popGoesTheWeaselTheme = Plugin.Audio[4];
	}

	[HarmonyPatch("SetJesterInitialValues")]
	[HarmonyPostfix]
	public static void ForceTime(JesterAI __instance)
	{
		__instance.popUpTimer = 39f;
	}
}
[HarmonyPatch(typeof(HoarderBugAI))]
internal class SpritePatch
{
	private static SpriteRenderer faceSpriteRenderer;

	private static Sprite currentSprite;

	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void FaceImagePatch(HoarderBugAI __instance)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		GameObject gameObject = ((Component)((Component)__instance).gameObject.transform.Find("HoarderBugModel/AnimContainer/Armature/Abdomen/Chest/Head")).gameObject;
		GameObject val = new GameObject("face");
		faceSpriteRenderer = val.AddComponent<SpriteRenderer>();
		faceSpriteRenderer.sprite = Plugin.kakaBugFaceSprite;
		((Component)faceSpriteRenderer).transform.SetParent(gameObject.transform);
		((Component)faceSpriteRenderer).transform.SetLocalPositionAndRotation(new Vector3(-1.6f, 2.33f, 0.02f), new Quaternion(-0.356f, -0.61f, -0.356f, 0.61f));
		((Component)faceSpriteRenderer).transform.localScale = new Vector3(1.3f, 1.3f, 1.3f);
	}

	[HarmonyPatch("Update")]
	[HarmonyPrefix]
	public static void TalkingImagePatch(HoarderBugAI __instance)
	{
		Sprite val = (((EnemyAI)__instance).creatureVoice.isPlaying ? Plugin.kakaBugFaceSprite1 : Plugin.kakaBugFaceSprite);
		if ((Object)(object)val != (Object)(object)currentSprite)
		{
			currentSprite = val;
			faceSpriteRenderer.sprite = currentSprite;
		}
	}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class FirePlayersEventPatch
{
	public static bool isGameOver;

	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void SetGameOverFalse()
	{
		isGameOver = false;
	}

	[HarmonyPatch("FirePlayersAfterDeadlineClientRpc")]
	[HarmonyPostfix]
	public static void DisgracePatch(StartOfRound __instance)
	{
		isGameOver = true;
		Plugin.screenSpriteRend.sprite = Plugin.kakaFaceSprite4;
		((MonoBehaviour)__instance).StartCoroutine(resettingKakaScreen());
	}

	private static IEnumerator resettingKakaScreen()
	{
		yield return (object)new WaitForSeconds(31f);
		isGameOver = false;
	}
}
[HarmonyPatch(typeof(ManualCameraRenderer))]
internal class ScreenPatch
{
	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void FaceImagePatch(ManualCameraRenderer __instance)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)GameObject.Find("KakaScreen") == (Object)null)
		{
			GameObject val = GameObject.Find("MonitorWall");
			GameObject gameObject = ((Component)val.transform.Find("Cube")).gameObject;
			GameObject val2 = new GameObject("KakaScreen");
			Plugin.screenSpriteRend = val2.AddComponent<SpriteRenderer>();
			Plugin.screenSpriteRend.sprite = Plugin.kakaFaceSprite1;
			((Component)Plugin.screenSpriteRend).transform.SetParent(gameObject.transform);
			((Component)Plugin.screenSpriteRend).transform.localPosition = new Vector3(-0.509f, -0.485f, 0.508f);
			((Component)Plugin.screenSpriteRend).transform.localRotation = new Quaternion(0.4f, 0.4f, 0.58f, 0.58f);
			((Component)Plugin.screenSpriteRend).transform.localScale = new Vector3(0.3468f, 0.3468f, 0.3468f);
			((Component)__instance).gameObject.AddComponent<SpriteRotator>().Initialize(Plugin.screenSpriteRend, new List<Sprite>
			{
				Plugin.kakaFaceSprite1,
				Plugin.kakaFaceSprite2,
				Plugin.kakaFaceSprite3
			});
		}
	}

	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void FishPosterPatch(ManualCameraRenderer __instance)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		if ((Object)(object)GameObject.Find("FishPoster") == (Object)null)
		{
			GameObject gameObject = GameObject.Find("HangarShip/Plane.001").gameObject;
			GameObject val = new GameObject("FishPoster");
			val.transform.SetParent(gameObject.transform);
			((Renderer)gameObject.GetComponent<MeshRenderer>()).materials[1].mainTexture = (Texture)(object)Plugin.fishPosterTexture;
		}
	}
}
[HarmonyPatch(typeof(VehicleController))]
internal class VehiclePatch
{
	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void MoreRadioPatch(VehicleController __instance)
	{
		AudioClip[] radioClips = __instance.radioClips;
		AudioClip[] first = (AudioClip[])(object)new AudioClip[1] { Plugin.Audio[5] };
		__instance.radioClips = first.Concat(radioClips).ToArray();
	}
}
public class SpriteRotator : MonoBehaviour
{
	private SpriteRenderer spriteRenderer;

	private List<Sprite> sprites;

	private int currentSpriteIndex;

	private float timer;

	public void Initialize(SpriteRenderer renderer, List<Sprite> spriteList)
	{
		spriteRenderer = renderer;
		sprites = spriteList;
		currentSpriteIndex = 0;
		timer = 0f;
	}

	private void Update()
	{
		timer += Time.deltaTime;
		if (!FirePlayersEventPatch.isGameOver && timer >= 2f)
		{
			timer = 0f;
			currentSpriteIndex = (currentSpriteIndex + 1) % sprites.Count;
			spriteRenderer.sprite = sprites[currentSpriteIndex];
		}
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "KakaBug";

	public const string PLUGIN_NAME = "KakaBug";

	public const string PLUGIN_VERSION = "1.6.0";
}