Decompiled source of ConfigTeams v1.1.0

ConfigTeams.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MoreTeam")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoreTeam")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b17f6498-5cc1-49e0-b2f9-def5ffdd0a6f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MoreTeams;

[BepInPlugin("com.OctoLab.MoreTeams", "Config Teams", "1.1.0")]
public class MoreTeams : BaseUnityPlugin
{
	[HarmonyPatch(typeof(GameSessionHandler), "SpawnPlayers")]
	public static class SpawnPlayers_Patch
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_I4_4 && list[i + 1].opcode == OpCodes.Newarr && list[i + 1].operand is Type type && type == typeof(int))
				{
					list[i].opcode = OpCodes.Ldsfld;
					list[i].operand = AccessTools.Field(typeof(MoreTeams), "TeamsNumber");
					break;
				}
			}
			return list;
		}
	}

	public static ManualLogSource Log;

	public bool Loaded;

	public static ConfigEntry<string> ColorsNameConfig;

	public static ConfigEntry<bool> ReplaceTeams;

	public static string[] ColorsNames = new string[0];

	public static string[][] Colours = new string[0][];

	public static int TeamsNumber = 4;

	private void Awake()
	{
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		Log.LogInfo((object)"More Teams start loading");
		ReplaceTeams = ((BaseUnityPlugin)this).Config.Bind<bool>("Colors", "ReplaceTeams", false, "Replace original teams if true, only add new if false");
		ColorsNameConfig = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "Colors", "yellow|grayscale", "Colors that become new teams");
		LoadColorsFromConfig();
		Harmony val = new Harmony("com.OctoLab.MoreTeams");
		val.PatchAll();
		Loaded = false;
		if (ReplaceTeams.Value && ColorsNames.Length <= 4)
		{
			CharacterSelectHandler_online.clientSideMods_you_can_increment_this_to_enable_matchmaking_for_your_mods__please_dont_use_it_to_cheat_thats_really_cringe_especially_if_its_desyncing_others___you_didnt_even_win_on_your_opponents_screen___I_cannot_imagine_a_sadder_existence++;
			Log.LogInfo((object)"enjoy multiplayer :)");
		}
	}

	private void Update()
	{
		if (!Loaded)
		{
			AddExtraTeamColors();
		}
	}

	public static Color HexToColor(string hex)
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		hex = hex.TrimStart(new char[1] { '#' });
		return new Color((float)int.Parse(hex.Substring(0, 2), NumberStyles.HexNumber) / 255f, (float)int.Parse(hex.Substring(2, 2), NumberStyles.HexNumber) / 255f, (float)int.Parse(hex.Substring(4, 2), NumberStyles.HexNumber) / 255f);
	}

	private void LoadColorsFromConfig()
	{
		ColorsNames = ColorsNameConfig.Value.Split(new char[1] { '|' });
		Colours = new string[ColorsNames.Length][];
		for (int i = 0; i < ColorsNames.Length; i++)
		{
			ConfigEntry<string> val = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", ColorsNames[i], "ffd500|d38800|fffb00", "Standart color - yellow");
			Colours[i] = val.Value.Split(new char[1] { '|' });
			Log.LogInfo((object)("Loaded Colors from " + ColorsNames[i]));
		}
	}

	private void AddExtraTeamColors()
	{
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		TeamColors val = Resources.FindObjectsOfTypeAll<TeamColors>().FirstOrDefault();
		if ((Object)(object)val == (Object)null)
		{
			Log.LogError((object)"Error on adding teams :(");
			return;
		}
		bool value = ReplaceTeams.Value;
		TeamColor[] teamColors = val.teamColors;
		int num = teamColors.Length;
		if (value)
		{
			num = 0;
		}
		int num2 = num + Colours.Length;
		if (value && num2 < teamColors.Length)
		{
			num2 = teamColors.Length;
		}
		TeamColor[] array = (TeamColor[])(object)new TeamColor[num2];
		Array.Copy(teamColors, array, teamColors.Length);
		for (int i = num; i < Colours.Length + num; i++)
		{
			string[] array2 = Colours[i - num];
			array[i] = new TeamColor
			{
				team = i,
				fill = HexToColor(array2[0]),
				border = HexToColor(array2[1]),
				saturated = HexToColor(array2[2])
			};
			Log.LogInfo((object)("Added " + ColorsNames[i - num] + " team"));
		}
		val.teamColors = array;
		TeamsNumber = num2;
		Loaded = true;
		if (value)
		{
			if (Colours.Length <= 4)
			{
				Log.LogInfo((object)$"Replaced {Colours.Length} teams");
				return;
			}
			Log.LogInfo((object)"Replaced all teams");
			Log.LogInfo((object)$"Added {Colours.Length - 4} more teams");
		}
		else
		{
			Log.LogInfo((object)$"Added {Colours.Length} more teams");
		}
	}
}