Decompiled source of QuickRematch v3.3.0

plugins/QuickRematch/QuickRematch.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LLBML.GameEvents;
using LLBML.Players;
using LLBML.States;
using LLBML.Utils;
using LLScreen;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("43d590c0-ac18-464d-a84e-05e3090f5316")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyTitle("QuickRematch (uk.daioutzu.plugins.llb.quickrematch)")]
[assembly: AssemblyProduct("QuickRematch")]
[assembly: AssemblyVersion("3.3.0.0")]
namespace QuickRematch;

[BepInPlugin("uk.daioutzu.plugins.llb.quickrematch", "QuickRematch", "3.3.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInProcess("LLBlaze.exe")]
internal class QuickRematch : BaseUnityPlugin
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static OnLobbyReadyHandler <>9__24_0;

		internal void <Start>b__24_0(object o, LobbyReadyArgs a)
		{
			RestoreCharacter(Player.GetLocalPlayer());
			QuickReready();
		}
	}

	public const string TEXMOD_GUID = "no.mrgentle.plugins.llb.texturemod";

	public static BaseUnityPlugin texmodInstance = null;

	public static MethodInfo TM_getSkinMethod = null;

	public static MethodInfo TM_setSkinMethod = null;

	public static ConfigEntry<bool> autoRematch;

	public static ConfigEntry<bool> autoSelectCharacter;

	public static ConfigEntry<bool> autoReready;

	public static ConfigEntry<bool> reselectRandom;

	public static ConfigEntry<bool> storeCharacterOnRelaunch;

	public static ConfigEntry<int> storedCharacter;

	public static ConfigEntry<int> storedVariant;

	public static ConfigEntry<string> storedSkin;

	public static Character characterSelected = (Character)101;

	public static CharacterVariant variantSelected = (CharacterVariant)0;

	public static byte[] skinSelected = null;

	public static ManualLogSource Log { get; private set; } = null;


	public static QuickRematch Instance { get; private set; } = null;


	private void Awake()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		InitModOptions(((BaseUnityPlugin)this).Config);
		Harmony val = new Harmony("uk.daioutzu.plugins.llb.quickrematch");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Patching QuickRematch");
		val.PatchAll(typeof(QuickRematch_Patch));
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Patching CharacterRepicker");
		val.PatchAll(typeof(CharacterRepicker_Patch));
	}

	private void Start()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Expected O, but got Unknown
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Expected O, but got Unknown
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)"QuickRematch Started");
		if (storeCharacterOnRelaunch.Value)
		{
			characterSelected = (Character)storedCharacter.Value;
			variantSelected = (CharacterVariant)storedVariant.Value;
			skinSelected = Convert.FromBase64String(storedSkin.Value);
		}
		ModDependenciesUtils.RegisterToModMenu(((BaseUnityPlugin)this).Info, (List<string>)null);
		object obj = <>c.<>9__24_0;
		if (obj == null)
		{
			OnLobbyReadyHandler val = delegate
			{
				RestoreCharacter(Player.GetLocalPlayer());
				QuickReready();
			};
			<>c.<>9__24_0 = val;
			obj = (object)val;
		}
		LobbyEvents.OnLobbyReady += (OnLobbyReadyHandler)obj;
		LobbyEvents.OnUserCharacterPick += new OnUserCharacterPickHandler(OnUserCharacterPick);
		LobbyEvents.OnUserSkinClick += new OnUserSkinClickHandler(OnUserSkinClick);
		if (ModDependenciesUtils.IsModLoaded("no.mrgentle.plugins.llb.texturemod"))
		{
			PluginInfo val2 = Chainloader.PluginInfos["no.mrgentle.plugins.llb.texturemod"];
			if (val2.Metadata.Version.Major >= 2 && val2.Metadata.Version.Minor >= 3)
			{
				texmodInstance = Chainloader.PluginInfos["no.mrgentle.plugins.llb.texturemod"].Instance;
				TM_getSkinMethod = AccessTools.Method(((object)texmodInstance).GetType(), "External_GetSkinHashFromPlayer", new Type[1] { typeof(int) }, (Type[])null);
				TM_setSkinMethod = AccessTools.Method(((object)texmodInstance).GetType(), "External_AssignSkinToPlayer", new Type[2]
				{
					typeof(int),
					typeof(byte[])
				}, (Type[])null);
			}
		}
	}

	private void InitModOptions(ConfigFile config)
	{
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Expected O, but got Unknown
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Expected O, but got Unknown
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Expected O, but got Unknown
		autoRematch = config.Bind<bool>("Toggles", "autoRematch", true, (ConfigDescription)null);
		autoSelectCharacter = config.Bind<bool>("Toggles", "autoSelectCharacter", true, (ConfigDescription)null);
		autoReready = config.Bind<bool>("Toggles", "autoReready", true, (ConfigDescription)null);
		reselectRandom = config.Bind<bool>("Toggles", "reselectRandom", true, (ConfigDescription)null);
		storeCharacterOnRelaunch = config.Bind<bool>("Toggles", "storeCharacterOnRelaunch", false, (ConfigDescription)null);
		storedCharacter = config.Bind<int>("Storage", "storedCharacter", 101, new ConfigDescription("", (AcceptableValueBase)null, new object[1] { "modmenu_hidden" }));
		storedVariant = config.Bind<int>("Storage", "storedVariant", 0, new ConfigDescription("", (AcceptableValueBase)null, new object[1] { "modmenu_hidden" }));
		storedSkin = config.Bind<string>("Storage", "storedSkin", "", new ConfigDescription("", (AcceptableValueBase)null, new object[1] { "modmenu_hidden" }));
	}

	private void OnUserCharacterPick(PlayersCharacterButton pcb, OnUserCharacterPickArgs args)
	{
		((MonoBehaviour)this).StartCoroutine(SaveCharacterAndVariantLater(Player.GetLocalPlayer()));
	}

	private void OnUserSkinClick(PlayersSelection ps, OnUserSkinClickArgs args)
	{
		if (args.clickerNr == -1 || (args.clickerNr == Player.LocalPlayerNumber && args.toSkinNr == args.clickerNr))
		{
			((MonoBehaviour)this).StartCoroutine(SaveCharacterAndVariantLater(Player.GetLocalPlayer()));
		}
	}

	private IEnumerator SaveCharacterAndVariantLater(Player player)
	{
		yield return (object)new WaitForEndOfFrame();
		yield return (object)new WaitForEndOfFrame();
		yield return (object)new WaitForEndOfFrame();
		yield return (object)new WaitForEndOfFrame();
		yield return (object)new WaitForEndOfFrame();
		yield return (object)new WaitForEndOfFrame();
		StoreCharacterSelected(player);
	}

	public static void StoreCharacterSelected(Player player)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		if (player.CharacterSelectedIsRandom && reselectRandom.Value)
		{
			characterSelected = (Character)102;
			variantSelected = (CharacterVariant)0;
		}
		else
		{
			characterSelected = player.Character;
			variantSelected = player.CharacterVariant;
		}
		StoreCharacterAndVariant(characterSelected, variantSelected);
	}

	public static void StoreCharacterAndVariant(Character character, CharacterVariant variant = 0)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Expected I4, but got Unknown
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Expected I4, but got Unknown
		characterSelected = character;
		variantSelected = variant;
		if ((Object)(object)texmodInstance != (Object)null)
		{
			try
			{
				skinSelected = TM_getSkinMethod.Invoke(texmodInstance, new object[1] { Player.GetLocalPlayer().nr }) as byte[];
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Caught exception trying to get the skin of the current player: " + ex));
			}
		}
		Log.LogInfo((object)("Saving char: " + ((object)(Character)(ref characterSelected)).ToString() + " | " + ((object)(CharacterVariant)(ref variantSelected)).ToString()));
		if (storeCharacterOnRelaunch.Value)
		{
			storedCharacter.Value = (int)characterSelected;
			storedVariant.Value = (int)variantSelected;
			storedSkin.Value = Convert.ToBase64String(skinSelected ?? new byte[0]);
		}
	}

	public static void RestoreCharacter(Player player)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Invalid comparison between Unknown and I4
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected I4, but got Unknown
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Invalid comparison between Unknown and I4
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		if (!autoSelectCharacter.Value || (int)characterSelected == 101)
		{
			return;
		}
		Log.LogInfo((object)("Restoring char to " + ((object)(Character)(ref characterSelected)).ToString() + " | " + ((object)(CharacterVariant)(ref variantSelected)).ToString()));
		GameStates.DirectProcess(new Message((Msg)50, player.nr, (int)characterSelected, (object)null, -1));
		if ((int)characterSelected != 102 && (int)variantSelected != 0)
		{
			Log.LogInfo((object)"Restoring variant as well");
			player.CharacterVariant = variantSelected;
		}
		if ((Object)(object)texmodInstance != (Object)null)
		{
			byte[] array = skinSelected;
			if (array != null && array.Length != 0)
			{
				try
				{
					TM_setSkinMethod.Invoke(texmodInstance, new object[2]
					{
						Player.GetLocalPlayer().nr,
						skinSelected
					});
				}
				catch (Exception ex)
				{
					Log.LogError((object)("Caught exception trying to set the skin of the current player: " + ex));
				}
			}
		}
		GameStatesLobbyUtils.RefreshLocalPlayerState();
	}

	public static void QuickReready()
	{
		if (autoReready.Value)
		{
			Log.LogInfo((object)"Quick Readying");
			if (GameStates.IsInOnlineLobby())
			{
				GameStatesLobbyUtils.MakeSureReadyIs(true, false);
				Player.GetLocalPlayer().ready = true;
			}
			GameStatesLobbyUtils.RefreshLocalPlayerState();
		}
		else
		{
			Log.LogDebug((object)"ReReady was disabled.");
		}
	}
}
internal static class PluginInfos
{
	public const string PLUGIN_NAME = "QuickRematch";

	public const string PLUGIN_ID = "uk.daioutzu.plugins.llb.quickrematch";

	public const string PLUGIN_VERSION = "3.3.0";
}
public static class CharacterRepicker_Patch
{
	private static bool doRefresh;

	[HarmonyPatch(typeof(ScreenPlayersStage), "OnOpen")]
	[HarmonyPostfix]
	public static void SaveCharacter()
	{
		QuickRematch.StoreCharacterSelected(Player.GetLocalPlayer());
	}

	[HarmonyPatch(typeof(HDLIJDBFGKN), "GDHHGDONCKN")]
	[HarmonyPrefix]
	public static bool ReceivePlayerState_Prefix(JMLEHJLKPAC CNPOFPNNPAB, bool IDPADEAGKPJ)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Invalid comparison between Unknown and I4
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Invalid comparison between Unknown and I4
		if (IDPADEAGKPJ)
		{
			return true;
		}
		PlayerLobbyState val = PlayerLobbyState.op_Implicit(CNPOFPNNPAB);
		if (val.playerNr == Player.LocalPlayerNumber)
		{
			doRefresh = (int)val.character != QuickRematch.storedCharacter.Value || (int)val.variant != QuickRematch.storedVariant.Value || !val.ready;
		}
		return true;
	}

	[HarmonyPatch(typeof(HDLIJDBFGKN), "GDHHGDONCKN")]
	[HarmonyPostfix]
	public static void ReceivePlayerState_ReselectCharacter(JMLEHJLKPAC CNPOFPNNPAB, bool IDPADEAGKPJ)
	{
		if (!IDPADEAGKPJ && doRefresh)
		{
			QuickRematch.RestoreCharacter(Player.GetLocalPlayer());
			QuickRematch.QuickReready();
			doRefresh = false;
		}
	}
}
public static class QuickRematch_Patch
{
	[HarmonyPatch(typeof(PostScreen), "ShowButtonsNow")]
	[HarmonyPostfix]
	public static void RematchAfterGains(PostScreen __instance)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Expected I4, but got Unknown
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		if (QuickRematch.autoRematch.Value)
		{
			QuickRematch.Log.LogInfo((object)"Rematching");
			NIPJFJKNGHO resultButtons = __instance.resultButtons;
			switch (resultButtons - 1)
			{
			case 2:
				GameStates.Send(new Message((Msg)70, -1, 1, (object)null, -1));
				break;
			case 0:
			case 3:
				GameStates.Send((Msg)3, -1, -1);
				break;
			default:
				GameStates.Send(new Message((Msg)70, -1, 0, (object)null, -1));
				break;
			}
			QuickRematch.Log.LogInfo((object)"Rematched");
		}
	}

	[HarmonyPatch(typeof(PostScreen), "CFillXpBar")]
	[HarmonyPostfix]
	public static IEnumerator DisableXpGains(IEnumerator incoming)
	{
		QuickRematch.Log.LogInfo((object)"StoppedXpGains_PassPost");
		yield break;
	}

	[HarmonyPatch(typeof(CPNJEILDILH), "PEORFKFKGGGG")]
	[HarmonyPostfix]
	public static IEnumerator DisableCurrencyGains(IEnumerator incoming)
	{
		QuickRematch.Log.LogInfo((object)"StoppedCurrencyGains_PassPost");
		yield break;
	}
}