Decompiled source of HakitaSupremacy v1.1.1

HakitaSupremacy.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Configgy;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("HakitaSupremacy")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HakitaSupremacy")]
[assembly: AssemblyTitle("HakitaSupremacy")]
[assembly: AssemblyVersion("1.0.0.0")]
[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;
		}
	}
}
[BepInPlugin("HakitaSupremacy.adry.ultrakill", "Hakita Supremacy", "2.9.4")]
public class HakitaSupremacy : BaseUnityPlugin
{
	private Dictionary<string, GameObject> loadedPlushies = new Dictionary<string, GameObject>();

	private List<GameObject> activePlushies = new List<GameObject>();

	private bool isPlushiesLoaded;

	private bool playerDead;

	private bool waitingForRespawn;

	[Configgable("Settings", "Enable Mod", 0, null)]
	private static ConfigToggle modEnabled = new ConfigToggle(true);

	[Configgable("Settings", "Select Plushie", 0, null)]
	private static ConfigDropdown<string> selectedPlushie = new ConfigDropdown<string>(new string[8] { "DevPlushie (Hakita)", "DevPlushie (Jacob)", "DevPlushie (Mako)", "DevPlushie (Dalia)", "DevPlushie (BigRock)", "DevPlushie (Heckteck)", "DevPlushie (Francis)", "DevPlushie (Meganeko)" }, "DevPlushie (Hakita)", (string[])null);

	[Configgable("Settings", "Spawn All Plushies", 0, null)]
	private static ConfigToggle spawnAllPlushies = new ConfigToggle(false);

	private ConfigBuilder config;

	private void Awake()
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[HakitaSupremacy] Mod initialized.");
		config = new ConfigBuilder("HakitaSupremacy.adry.ultrakill", "Hakita Supremacy");
		config.BuildAll();
		Object.DontDestroyOnLoad((Object)(object)this);
		SceneManager.sceneLoaded += OnSceneLoaded;
		((MonoBehaviour)this).StartCoroutine(LoadAllPlushies());
	}

	private void Update()
	{
		if (!((ConfigValueElement<bool>)(object)modEnabled).Value || !IsGameplayScene())
		{
			return;
		}
		NewMovement instance = MonoSingleton<NewMovement>.Instance;
		if ((Object)(object)instance == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"[HakitaSupremacy] Player instance not found.");
			return;
		}
		if (waitingForRespawn && (Object)(object)instance != (Object)null && !instance.dead)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[HakitaSupremacy] Player respawn detected. Respawning plushies...");
			waitingForRespawn = false;
			RespawnPlushies();
		}
		if ((Object)(object)instance != (Object)null && instance.dead && !playerDead)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[HakitaSupremacy] Player died. Waiting for respawn...");
			playerDead = true;
			waitingForRespawn = true;
		}
		if ((Object)(object)instance != (Object)null && !instance.dead && playerDead)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[HakitaSupremacy] Player revived.");
			playerDead = false;
		}
		VerifyPlushies();
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)("[HakitaSupremacy] Scene loaded: " + ((Scene)(ref scene)).name));
		if (isPlushiesLoaded && ((ConfigValueElement<bool>)(object)modEnabled).Value && IsGameplayScene())
		{
			playerDead = false;
			waitingForRespawn = false;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[HakitaSupremacy] Spawning plushies for the new scene...");
			SpawnPlushies();
		}
	}

	private IEnumerator LoadAllPlushies()
	{
		string[] plushieKeys = new string[8] { "DevPlushie (Hakita)", "DevPlushie (Jacob)", "DevPlushie (Mako)", "DevPlushie (Dalia)", "DevPlushie (BigRock)", "DevPlushie (Heckteck)", "DevPlushie (Francis)", "DevPlushie (Meganeko)" };
		string[] array = plushieKeys;
		foreach (string plushieKey in array)
		{
			string assetPath = "Assets/Prefabs/Items/DevPlushies/" + plushieKey + ".prefab";
			AsyncOperationHandle<GameObject> handle = Addressables.LoadAssetAsync<GameObject>((object)assetPath);
			yield return handle;
			if ((int)handle.Status == 1)
			{
				loadedPlushies[plushieKey] = handle.Result;
				((BaseUnityPlugin)this).Logger.LogInfo((object)("[HakitaSupremacy] Plushie " + plushieKey + " loaded successfully."));
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("[HakitaSupremacy] Failed to load plushie: " + plushieKey));
			}
		}
		isPlushiesLoaded = true;
	}

	private void SpawnPlushies()
	{
		if (!((ConfigValueElement<bool>)(object)modEnabled).Value || !isPlushiesLoaded)
		{
			return;
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[HakitaSupremacy] Spawning plushies...");
		ClearActivePlushies();
		if (((ConfigValueElement<bool>)(object)spawnAllPlushies).Value)
		{
			foreach (GameObject value3 in loadedPlushies.Values)
			{
				SpawnPlushie(value3);
			}
			return;
		}
		string value = ((ConfigValueElement<string>)(object)selectedPlushie).Value;
		if (loadedPlushies.TryGetValue(value, out var value2))
		{
			SpawnPlushie(value2);
		}
	}

	private void SpawnPlushie(GameObject plushiePrefab)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		NewMovement instance = MonoSingleton<NewMovement>.Instance;
		if ((Object)(object)instance == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"[HakitaSupremacy] Player not found to spawn the plushie.");
			return;
		}
		Vector3 val = ((Component)instance).transform.position + Vector3.up * (2f + (float)activePlushies.Count * 0.5f);
		GameObject item = Object.Instantiate<GameObject>(plushiePrefab, val, Quaternion.identity);
		activePlushies.Add(item);
		((BaseUnityPlugin)this).Logger.LogInfo((object)("[HakitaSupremacy] Plushie " + ((Object)plushiePrefab).name + " spawned above the player."));
	}

	private void RespawnPlushies()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[HakitaSupremacy] Respawning plushies...");
		ClearActivePlushies();
		SpawnPlushies();
	}

	private void ClearActivePlushies()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[HakitaSupremacy] Removing active plushies.");
		foreach (GameObject activePlushy in activePlushies)
		{
			if ((Object)(object)activePlushy != (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("[HakitaSupremacy] Plushie " + ((Object)activePlushy).name + " removed successfully."));
				Object.Destroy((Object)(object)activePlushy);
			}
		}
		activePlushies.Clear();
	}

	private void VerifyPlushies()
	{
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		NewMovement instance = MonoSingleton<NewMovement>.Instance;
		if ((Object)(object)instance == (Object)null)
		{
			return;
		}
		List<GameObject> list = new List<GameObject>();
		Dictionary<GameObject, string> dictionary = new Dictionary<GameObject, string>();
		foreach (KeyValuePair<string, GameObject> loadedPlushy in loadedPlushies)
		{
			foreach (GameObject activePlushy in activePlushies)
			{
				if ((Object)(object)activePlushy != (Object)null && ((Object)activePlushy).name.Contains(loadedPlushy.Key))
				{
					dictionary[activePlushy] = loadedPlushy.Key;
				}
			}
		}
		foreach (GameObject activePlushy2 in activePlushies)
		{
			if ((Object)(object)activePlushy2 == (Object)null || activePlushy2.transform.position.y < ((Component)instance).transform.position.y - 50f)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("[HakitaSupremacy] Plushie " + (((activePlushy2 != null) ? ((Object)activePlushy2).name : null) ?? "unknown") + " is out of bounds and needs to be respawned."));
				list.Add(activePlushy2);
			}
		}
		foreach (GameObject item in list)
		{
			if ((Object)(object)item != (Object)null && dictionary.TryGetValue(item, out var value))
			{
				activePlushies.Remove(item);
				Object.Destroy((Object)(object)item);
				if (loadedPlushies.TryGetValue(value, out var value2))
				{
					SpawnPlushie(value2);
				}
			}
		}
		if (list.Count > 0)
		{
			MonoSingleton<HudMessageReceiver>.Instance.SendHudMessage($"{list.Count} plushie(s) respawned to your position.", "", "", 0, false);
		}
	}

	private bool IsGameplayScene()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		Scene activeScene = SceneManager.GetActiveScene();
		string sceneName = ((Scene)(ref activeScene)).name;
		string[] array = new string[3] { "Main Menu", "Bootstrap", "Intro" };
		if (Array.Exists(array, (string s) => s.Equals(sceneName)))
		{
			return false;
		}
		if ((Object)(object)Object.FindObjectOfType<MainMenuPit>() != (Object)null || (Object)(object)Object.FindObjectOfType<TitleScreen>() != (Object)null)
		{
			return false;
		}
		return true;
	}
}