Decompiled source of HeyItsCalebTTV v1.0.0

BenInEx/plugins/HeyitscalebTTV.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using Photon.Pun;
using Photon.Realtime;
using Steamworks;
using Steamworks.Data;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[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("HeyitscalebTTV")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HeyitscalebTTV")]
[assembly: AssemblyTitle("HeyitscalebTTV")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CustomREPOmod;

[BepInPlugin("Nuke.HeyitscalebTTV", "HeyitscalebTTV", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(NetworkConnect), "TryJoiningRoom")]
	private class TryJoiningRoomPatch
	{
		private static bool Prefix(ref string ___RoomName)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			if (string.IsNullOrEmpty(___RoomName))
			{
				return true;
			}
			if (ConfigMaxPlayers.Value <= 0)
			{
				return true;
			}
			RoomOptions val = new RoomOptions
			{
				MaxPlayers = ConfigMaxPlayers.Value
			};
			PhotonNetwork.JoinOrCreateRoom(___RoomName, val, TypedLobby.Default, (string[])null);
			return false;
		}
	}

	[HarmonyPatch(typeof(SteamManager), "HostLobby")]
	private class HostLobbyPatch
	{
		private static readonly ManualLogSource MyLogger = Logger.CreateLogSource("HeyitscalebTTV");

		private static bool Prefix()
		{
			HostLobbyAsync();
			return false;
		}

		private static async void HostLobbyAsync()
		{
			MyLogger.LogInfo((object)"Hosting Steam lobby...");
			Lobby? lobby = await SteamMatchmaking.CreateLobbyAsync(ConfigMaxPlayers.Value);
			if (lobby.HasValue)
			{
				Lobby value = lobby.Value;
				((Lobby)(ref value)).SetPublic();
				value = lobby.Value;
				((Lobby)(ref value)).SetJoinable(false);
			}
			else
			{
				MyLogger.LogError((object)"Failed to create Steam lobby!");
			}
		}
	}

	[HarmonyPatch(typeof(PlayerHealth))]
	internal class PlayerHealthPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Hurt")]
		public static bool HurtPrefix()
		{
			return (Object)(object)RunManager.instance.levelCurrent != (Object)(object)RunManager.instance.levelShop;
		}
	}

	[HarmonyPatch(typeof(ChatManager))]
	internal class ChatManagerPatch
	{
		[HarmonyPatch("StateActive")]
		[HarmonyILManipulator]
		private static void ILManipulateStateActive(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ILCursor val = new ILCursor(il);
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 50)
			});
			val.Index -= 3;
			val.RemoveRange(29);
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)"ChatManager.StateActive patched to remove character limit!");
		}

		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void AwakePostfix(ChatManager __instance)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			TMP_Text chatText = (TMP_Text)(object)__instance.chatText;
			chatText.enableWordWrapping = true;
			Vector2 sizeDelta = chatText.rectTransform.sizeDelta;
			sizeDelta.x = ConfigChatboxWidth.Value;
			chatText.rectTransform.sizeDelta = sizeDelta;
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)("Chatbox modified: word wrapping enabled, width set to " + ConfigChatboxWidth.Value + "!"));
		}
	}

	[HarmonyPatch(typeof(PlayerController))]
	internal class PlayerControllerPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Update")]
		private static void StamRegenPatch(ref float ___sprintRechargeAmount)
		{
			___sprintRechargeAmount = ConfigStaminaRecharge.Value;
			((BaseUnityPlugin)Instance).Logger.LogDebug((object)("Stamina recharge set to " + ConfigStaminaRecharge.Value + "!"));
		}
	}

	internal sealed class PlayerCountBehavior : MonoBehaviour
	{
		internal TextMeshProUGUI tmp;

		private void Update()
		{
			if (!((Object)(object)tmp == (Object)null))
			{
				Room currentRoom = PhotonNetwork.CurrentRoom;
				((TMP_Text)tmp).text = $"Players: {((currentRoom != null) ? currentRoom.PlayerCount : 0)}/{((currentRoom != null) ? currentRoom.MaxPlayers : 6)}";
			}
		}
	}

	[HarmonyPatch(typeof(ItemUpgradePlayerHealth), "Upgrade")]
	internal class ItemUpgradePlayerHealthPatch
	{
		private static bool Prefix(ItemUpgradePlayerHealth __instance)
		{
			foreach (PlayerAvatar item in SemiFunc.PlayerGetAll())
			{
				PunManager.instance.UpgradePlayerHealth(SemiFunc.PlayerGetSteamID(item));
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(ItemUpgradePlayerEnergy), "Upgrade")]
	internal class ItemUpgradePlayerEnergyPatch
	{
		private static bool Prefix(ItemUpgradePlayerEnergy __instance)
		{
			foreach (PlayerAvatar item in SemiFunc.PlayerGetAll())
			{
				PunManager.instance.UpgradePlayerEnergy(SemiFunc.PlayerGetSteamID(item));
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(ItemUpgradeMapPlayerCount), "Upgrade")]
	internal class ItemUpgradeMapPlayerCountPatch
	{
		private static bool Prefix(ItemUpgradeMapPlayerCount __instance)
		{
			foreach (PlayerAvatar item in SemiFunc.PlayerGetAll())
			{
				PunManager.instance.UpgradeMapPlayerCount(SemiFunc.PlayerGetSteamID(item));
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(ItemUpgradePlayerSprintSpeed), "Upgrade")]
	internal class ItemUpgradePlayerSprintSpeedPatch
	{
		private static bool Prefix(ItemUpgradePlayerSprintSpeed __instance)
		{
			foreach (PlayerAvatar item in SemiFunc.PlayerGetAll())
			{
				PunManager.instance.UpgradePlayerSprintSpeed(SemiFunc.PlayerGetSteamID(item));
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(ItemUpgradePlayerExtraJump), "Upgrade")]
	internal class ItemUpgradePlayerExtraJumpPatch
	{
		private static bool Prefix(ItemUpgradePlayerExtraJump __instance)
		{
			foreach (PlayerAvatar item in SemiFunc.PlayerGetAll())
			{
				PunManager.instance.UpgradePlayerExtraJump(SemiFunc.PlayerGetSteamID(item));
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(ItemUpgradePlayerGrabRange), "Upgrade")]
	internal class ItemUpgradePlayerGrabRangePatch
	{
		private static bool Prefix(ItemUpgradePlayerGrabRange __instance)
		{
			foreach (PlayerAvatar item in SemiFunc.PlayerGetAll())
			{
				PunManager.instance.UpgradePlayerGrabRange(SemiFunc.PlayerGetSteamID(item));
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(ItemUpgradePlayerGrabStrength), "Upgrade")]
	internal class ItemUpgradePlayerGrabStrengthPatch
	{
		private static bool Prefix(ItemUpgradePlayerGrabStrength __instance)
		{
			foreach (PlayerAvatar item in SemiFunc.PlayerGetAll())
			{
				PunManager.instance.UpgradePlayerGrabStrength(SemiFunc.PlayerGetSteamID(item));
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(ItemUpgradePlayerGrabThrow), "Upgrade")]
	internal class ItemUpgradePlayerGrabThrowPatch
	{
		private static bool Prefix(ItemUpgradePlayerGrabThrow __instance)
		{
			foreach (PlayerAvatar item in SemiFunc.PlayerGetAll())
			{
				PunManager.instance.UpgradePlayerThrowStrength(SemiFunc.PlayerGetSteamID(item));
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(ItemUpgradePlayerTumbleLaunch), "Upgrade")]
	internal class ItemUpgradePlayerTumbleLaunchPatch
	{
		private static bool Prefix(ItemUpgradePlayerTumbleLaunch __instance)
		{
			foreach (PlayerAvatar item in SemiFunc.PlayerGetAll())
			{
				PunManager.instance.UpgradePlayerTumbleLaunch(SemiFunc.PlayerGetSteamID(item));
			}
			return false;
		}
	}

	private readonly Harmony harmony = new Harmony("Nuke.HeyitscalebTTV");

	public static ConfigEntry<int> ConfigMaxPlayers;

	public static ConfigEntry<float> ConfigStaminaRecharge;

	public static ConfigEntry<float> ConfigChatboxWidth;

	public static ConfigEntry<float> ConfigPlayerCountX;

	public static ConfigEntry<float> ConfigPlayerCountY;

	public static ConfigEntry<bool> ConfigEnableHealthUpgrade;

	public static ConfigEntry<bool> ConfigEnableEnergyUpgrade;

	public static ConfigEntry<bool> ConfigEnableMapPlayerCountUpgrade;

	public static ConfigEntry<bool> ConfigEnableSprintSpeedUpgrade;

	public static ConfigEntry<bool> ConfigEnableExtraJumpUpgrade;

	public static ConfigEntry<bool> ConfigEnableGrabRangeUpgrade;

	public static ConfigEntry<bool> ConfigEnableGrabStrengthUpgrade;

	public static ConfigEntry<bool> ConfigEnableGrabThrowUpgrade;

	public static ConfigEntry<bool> ConfigEnableTumbleLaunchUpgrade;

	private bool uiPatched = false;

	public static Plugin Instance;

	private void Awake()
	{
		Instance = this;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"CustomREPOmod loaded!");
		ConfigMaxPlayers = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxPlayers", 10, "Maximum players in the lobby (1-255).");
		ConfigStaminaRecharge = ((BaseUnityPlugin)this).Config.Bind<float>("Gameplay", "StaminaRecharge", 8f, "Stamina recharge rate per frame (default: 8).");
		ConfigChatboxWidth = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "ChatboxWidth", 534f, "Width of the chatbox in pixels (default: 534).");
		ConfigPlayerCountX = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "PlayerCountX", 0f, "X position of the player count display (default: 0).");
		ConfigPlayerCountY = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "PlayerCountY", 210f, "Y position of the player count display (default: 210).");
		ConfigEnableHealthUpgrade = ((BaseUnityPlugin)this).Config.Bind<bool>("TeamBoosters", "EnableHealthUpgrade", true, "Apply health upgrades to all players.");
		ConfigEnableEnergyUpgrade = ((BaseUnityPlugin)this).Config.Bind<bool>("TeamBoosters", "EnableEnergyUpgrade", true, "Apply energy upgrades to all players.");
		ConfigEnableMapPlayerCountUpgrade = ((BaseUnityPlugin)this).Config.Bind<bool>("TeamBoosters", "EnableMapPlayerCountUpgrade", true, "Apply map player count upgrades to all players.");
		ConfigEnableSprintSpeedUpgrade = ((BaseUnityPlugin)this).Config.Bind<bool>("TeamBoosters", "EnableSprintSpeedUpgrade", true, "Apply sprint speed upgrades to all players.");
		ConfigEnableExtraJumpUpgrade = ((BaseUnityPlugin)this).Config.Bind<bool>("TeamBoosters", "EnableExtraJumpUpgrade", true, "Apply extra jump upgrades to all players.");
		ConfigEnableGrabRangeUpgrade = ((BaseUnityPlugin)this).Config.Bind<bool>("TeamBoosters", "EnableGrabRangeUpgrade", true, "Apply grab range upgrades to all players.");
		ConfigEnableGrabStrengthUpgrade = ((BaseUnityPlugin)this).Config.Bind<bool>("TeamBoosters", "EnableGrabStrengthUpgrade", true, "Apply grab strength upgrades to all players.");
		ConfigEnableGrabThrowUpgrade = ((BaseUnityPlugin)this).Config.Bind<bool>("TeamBoosters", "EnableGrabThrowUpgrade", true, "Apply grab throw upgrades to all players.");
		ConfigEnableTumbleLaunchUpgrade = ((BaseUnityPlugin)this).Config.Bind<bool>("TeamBoosters", "EnableTumbleLaunchUpgrade", true, "Apply tumble launch upgrades to all players.");
		if (!SteamClient.IsValid)
		{
			SteamClient.Init(3241660u, true);
			if (!SteamClient.IsValid)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to initialize Steamworks!");
				return;
			}
		}
		harmony.PatchAll();
		if (ConfigEnableHealthUpgrade.Value)
		{
			harmony.PatchAll(typeof(ItemUpgradePlayerHealthPatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Player Health Upgrade patch applied for team boosting.");
		}
		if (ConfigEnableEnergyUpgrade.Value)
		{
			harmony.PatchAll(typeof(ItemUpgradePlayerEnergyPatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Player Energy Upgrade patch applied for team boosting.");
		}
		if (ConfigEnableMapPlayerCountUpgrade.Value)
		{
			harmony.PatchAll(typeof(ItemUpgradeMapPlayerCountPatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Map Player Count Upgrade patch applied for team boosting.");
		}
		if (ConfigEnableSprintSpeedUpgrade.Value)
		{
			harmony.PatchAll(typeof(ItemUpgradePlayerSprintSpeedPatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Player Sprint Speed Upgrade patch applied for team boosting.");
		}
		if (ConfigEnableExtraJumpUpgrade.Value)
		{
			harmony.PatchAll(typeof(ItemUpgradePlayerExtraJumpPatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Player Extra Jump Upgrade patch applied for team boosting.");
		}
		if (ConfigEnableGrabRangeUpgrade.Value)
		{
			harmony.PatchAll(typeof(ItemUpgradePlayerGrabRangePatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Player Grab Range Upgrade patch applied for team boosting.");
		}
		if (ConfigEnableGrabStrengthUpgrade.Value)
		{
			harmony.PatchAll(typeof(ItemUpgradePlayerGrabStrengthPatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Player Grab Strength Upgrade patch applied for team boosting.");
		}
		if (ConfigEnableGrabThrowUpgrade.Value)
		{
			harmony.PatchAll(typeof(ItemUpgradePlayerGrabThrowPatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Player Grab Throw Upgrade patch applied for team boosting.");
		}
		if (ConfigEnableTumbleLaunchUpgrade.Value)
		{
			harmony.PatchAll(typeof(ItemUpgradePlayerTumbleLaunchPatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Player Tumble Launch Upgrade patch applied for team boosting.");
		}
	}

	private void OnDestroy()
	{
		SteamClient.Shutdown();
	}

	private void Update()
	{
		if (!uiPatched && PhotonNetwork.InRoom)
		{
			PatchPlayerListUI();
			uiPatched = true;
		}
	}

	private void PatchPlayerListUI()
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Expected O, but got Unknown
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Expected O, but got Unknown
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Expected O, but got Unknown
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_027e: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.Find("UI/HUD/HUD Canvas/HUD/Menu Holder/Menu Page Lobby(clone)/Player List");
		if ((Object)(object)val == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Player List not found!");
			return;
		}
		RectTransform component = val.GetComponent<RectTransform>();
		if ((Object)(object)component == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"No RectTransform on Player List!");
			return;
		}
		GameObject val2 = new GameObject("ScrollView", new Type[1] { typeof(RectTransform) });
		val2.transform.SetParent(val.transform.parent, false);
		ScrollRect val3 = val2.AddComponent<ScrollRect>();
		val3.content = component;
		val3.horizontal = false;
		val3.vertical = true;
		val3.scrollSensitivity = 10f;
		GameObject val4 = new GameObject("Viewport", new Type[2]
		{
			typeof(RectTransform),
			typeof(Mask)
		});
		val4.transform.SetParent(val2.transform, false);
		((Graphic)val4.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0f);
		val3.viewport = val4.GetComponent<RectTransform>();
		((Transform)component).SetParent(val4.transform, false);
		GameObject val5 = new GameObject("Scrollbar", new Type[1] { typeof(RectTransform) });
		val5.transform.SetParent(val2.transform, false);
		Scrollbar val6 = val5.AddComponent<Scrollbar>();
		val6.direction = (Direction)2;
		val3.verticalScrollbar = val6;
		((Component)val3).GetComponent<RectTransform>().sizeDelta = new Vector2(250f, 400f);
		((Component)val6).GetComponent<RectTransform>().sizeDelta = new Vector2(20f, 400f);
		((Component)val6).GetComponent<RectTransform>().anchoredPosition = new Vector2(135f, 0f);
		GameObject val7 = new GameObject("PlayerCount", new Type[1] { typeof(RectTransform) });
		val7.transform.SetParent(val2.transform.parent, false);
		TextMeshProUGUI val8 = val7.AddComponent<TextMeshProUGUI>();
		((TMP_Text)val8).fontSize = 20f;
		((TMP_Text)val8).alignment = (TextAlignmentOptions)514;
		((Graphic)val8).color = Color.white;
		RectTransform component2 = val7.GetComponent<RectTransform>();
		component2.sizeDelta = new Vector2(200f, 30f);
		component2.anchoredPosition = new Vector2(ConfigPlayerCountX.Value, ConfigPlayerCountY.Value);
		PlayerCountBehavior playerCountBehavior = val7.AddComponent<PlayerCountBehavior>();
		playerCountBehavior.tmp = val8;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Player List scrolling and player count UI enabled!");
	}
}