using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using FishNet;
using FishNet.Object;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.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;
}
}
}
namespace moreStrafts.UISpawnAddon
{
[BepInPlugin("com.morestrafts.uispawn.addon", "MoreStrafts UI and Spawn Fixes Addon", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class UISpawnAddonPlugin : BaseUnityPlugin
{
private void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
Harmony val = new Harmony("com.morestrafts.uispawn.addon");
val.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"MoreStrafts UI and Spawn Fixes Addon v1.0.0 loaded!");
}
}
[HarmonyPatch(typeof(LobbyController), "RemoveExtraPlayerItem")]
public static class RemoveExtraPlayerItemPatch
{
private static bool Prefix(LobbyController __instance)
{
List<PlayerListItem> value = Traverse.Create((object)__instance).Field("PlayerListItems").GetValue<List<PlayerListItem>>();
List<PlayerListItem> value2 = Traverse.Create((object)__instance).Field("PlayerListItemsTab").GetValue<List<PlayerListItem>>();
int maxPlayers = SteamLobby.Instance.maxPlayers;
List<PlayerListItem> list = new List<PlayerListItem>();
for (int i = 0; i < value.Count; i++)
{
if (i >= maxPlayers)
{
list.Add(value[i]);
}
}
foreach (PlayerListItem item in list)
{
Object.Destroy((Object)(object)((Component)item).gameObject);
value.Remove(item);
}
List<PlayerListItem> list2 = new List<PlayerListItem>();
for (int j = 0; j < value2.Count; j++)
{
if (j >= maxPlayers)
{
list2.Add(value2[j]);
}
}
foreach (PlayerListItem item2 in list2)
{
Object.Destroy((Object)(object)((Component)item2).gameObject);
value2.Remove(item2);
}
return false;
}
}
[HarmonyPatch(typeof(LobbyController), "CreateClientPlayerItem")]
public static class CreateClientPlayerItemPatch
{
private static bool Prefix(LobbyController __instance)
{
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0283: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0305: Unknown result type (might be due to invalid IL or missing references)
//IL_030a: Unknown result type (might be due to invalid IL or missing references)
//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
List<PlayerListItem> value = Traverse.Create((object)__instance).Field("PlayerListItems").GetValue<List<PlayerListItem>>();
List<PlayerListItem> value2 = Traverse.Create((object)__instance).Field("PlayerListItemsTab").GetValue<List<PlayerListItem>>();
SteamLobby value3 = Traverse.Create((object)__instance).Field("manager").GetValue<SteamLobby>();
Transform value4 = Traverse.Create((object)__instance).Field("tabScreen").GetValue<Transform>();
foreach (NetworkObject player in value3.players)
{
if (!value.Any((PlayerListItem b) => b.ConnectionID == player.Owner.ClientId))
{
GameObject val = Object.Instantiate<GameObject>(__instance.PlayerListItemPrefab);
PlayerListItem component = val.GetComponent<PlayerListItem>();
ClientInstance component2 = ((Component)player).GetComponent<ClientInstance>();
component.PlayerName = component2.PlayerName;
component.ConnectionID = component2.ConnectionID;
component.PlayerIdNumber = component2.PlayerId;
component.PlayerSteamID = component2.PlayerSteamID;
component.Ready = component2.Ready;
component.SetPlayerValues();
val.transform.SetParent(__instance.PlayerListViewContent.transform);
val.transform.localScale = Vector3.one;
int num = component2.PlayerId - 1;
if (num >= 0 && num < __instance.clientPosition.Length)
{
val.transform.position = __instance.clientPosition[num].position;
}
else
{
Vector3 position = __instance.clientPosition[__instance.clientPosition.Length - 1].position;
val.transform.position = position + Vector3.down * 60f * (float)(num - __instance.clientPosition.Length + 1);
}
value.Add(component);
}
if (!value2.Any((PlayerListItem b) => b.ConnectionID == player.Owner.ClientId))
{
GameObject val2 = Object.Instantiate<GameObject>(__instance.PlayerListItemPrefab);
PlayerListItem component3 = val2.GetComponent<PlayerListItem>();
ClientInstance component4 = ((Component)player).GetComponent<ClientInstance>();
component3.PlayerName = component4.PlayerName;
component3.ConnectionID = component4.ConnectionID;
component3.PlayerIdNumber = component4.PlayerId;
component3.PlayerSteamID = component4.PlayerSteamID;
component3.Ready = component4.Ready;
component3.SetPlayerValues();
val2.transform.SetParent(value4);
val2.transform.localScale = Vector3.one;
Transform[] tabclientPosition = __instance.tabclientPosition;
int num2 = component4.PlayerId - 1;
if (num2 >= 0 && num2 < tabclientPosition.Length)
{
val2.transform.position = tabclientPosition[num2].position;
}
else
{
Vector3 position2 = tabclientPosition[^1].position;
val2.transform.position = position2 + Vector3.down * 60f * (float)(num2 - tabclientPosition.Length + 1);
}
value2.Add(component3);
}
}
return false;
}
}
[HarmonyPatch(typeof(PlayerListItem), "Update")]
public static class PlayerListItemUpdatePatch
{
private static bool Prefix(PlayerListItem __instance)
{
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Unknown result type (might be due to invalid IL or missing references)
//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
GameObject value = Traverse.Create((object)__instance).Field("cosmeticbutton").GetValue<GameObject>();
PauseManager value2 = Traverse.Create((object)__instance).Field("pauseManager").GetValue<PauseManager>();
LobbyController value3 = Traverse.Create((object)__instance).Field("lobbyController").GetValue<LobbyController>();
GameManager value4 = Traverse.Create((object)__instance).Field("gameManager").GetValue<GameManager>();
TMP_Dropdown value5 = Traverse.Create((object)__instance).Field("teamIdDropdown").GetValue<TMP_Dropdown>();
ulong value6 = Traverse.Create((object)__instance).Field("localSteamId").GetValue<ulong>();
if ((Object)(object)value != (Object)null && (Object)(object)value2 != (Object)null)
{
value.transform.localScale = (value2.inMainMenu ? Vector3.one : Vector3.zero);
}
bool flag = ((Object)((Component)((Component)__instance).transform.parent).gameObject).name == "-- TAB SCREEN --";
if (__instance.PlayerIdNumber > 0 && (Object)(object)value3 != (Object)null)
{
int num = __instance.PlayerIdNumber - 1;
if (flag)
{
if (num < value3.tabclientPosition.Length)
{
((Component)__instance).transform.position = value3.tabclientPosition[num].position;
}
else
{
Vector3 position = value3.tabclientPosition[value3.tabclientPosition.Length - 1].position;
int num2 = num - (value3.tabclientPosition.Length - 1);
((Component)__instance).transform.position = new Vector3(position.x, position.y - (float)num2 * 0.5f, position.z);
}
}
else if (num < value3.clientPosition.Length)
{
((Component)__instance).transform.position = value3.clientPosition[num].position;
}
else
{
Vector3 position2 = value3.clientPosition[value3.clientPosition.Length - 1].position;
int num3 = num - (value3.clientPosition.Length - 1);
((Component)__instance).transform.position = new Vector3(position2.x, position2.y - (float)num3 * 0.5f, position2.z);
}
}
if ((Object)(object)value4 != (Object)null && (Object)(object)value5 != (Object)null)
{
bool value7 = Traverse.Create((object)value4).Field("playingTeams").GetValue<bool>();
((Component)value5).gameObject.SetActive(value7);
if (InstanceFinder.NetworkManager.IsServer)
{
((Selectable)value5).interactable = !flag;
}
else if (value6 == __instance.PlayerSteamID)
{
((Selectable)value5).interactable = !flag;
}
}
return false;
}
}
[HarmonyPatch(typeof(ClientInstance), "RpcLogic___RunIntoLobby_3316948804")]
public static class RunIntoLobbyPatch
{
private static bool Prefix(ClientInstance __instance, int id)
{
AboubiPreviewLobby[] previews = LobbyController.Instance.previews;
if (id >= 0 && id < previews.Length && (Object)(object)previews[id] != (Object)null)
{
return true;
}
return false;
}
}
[HarmonyPatch(typeof(PlayerManager), "SpawnPlayer", new Type[]
{
typeof(int),
typeof(int),
typeof(Vector3),
typeof(Quaternion)
})]
public static class SpawnPlayerOffsetPatch
{
private static void Prefix(PlayerManager __instance, ref Vector3 position)
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: 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_005d: Unknown result type (might be due to invalid IL or missing references)
ClientInstance component = ((Component)__instance).GetComponent<ClientInstance>();
if (!((Object)(object)component == (Object)null))
{
int playerId = component.PlayerId;
float num = (float)playerId * 36f * ((float)Math.PI / 180f);
float num2 = 0.5f;
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(Mathf.Cos(num) * num2, 0f, Mathf.Sin(num) * num2);
position += val;
}
}
}
[HarmonyPatch(typeof(PlayerListItem), "Start")]
public static class ExpandTeamDropdownPatch
{
private static void Postfix(PlayerListItem __instance)
{
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0206: Unknown result type (might be due to invalid IL or missing references)
//IL_0291: Unknown result type (might be due to invalid IL or missing references)
//IL_0296: Unknown result type (might be due to invalid IL or missing references)
//IL_0298: Unknown result type (might be due to invalid IL or missing references)
//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
//IL_033e: Unknown result type (might be due to invalid IL or missing references)
//IL_0355: Unknown result type (might be due to invalid IL or missing references)
TMP_Dropdown value = Traverse.Create((object)__instance).Field("teamIdDropdown").GetValue<TMP_Dropdown>();
if ((Object)(object)value == (Object)null)
{
return;
}
int maxPlayers = SteamLobby.Instance.maxPlayers;
if (maxPlayers <= 4)
{
return;
}
value.ClearOptions();
List<string> list = new List<string>();
for (int i = 1; i <= maxPlayers; i++)
{
list.Add($"{i}");
}
value.AddOptions(list);
value.RefreshShownValue();
int teamId = ScoreManager.Instance.GetTeamId(__instance.PlayerIdNumber);
value.value = teamId;
value.RefreshShownValue();
RectTransform component = ((Component)value).GetComponent<RectTransform>();
if ((Object)(object)component != (Object)null)
{
Transform val = ((Component)value).transform.Find("SettingName");
if ((Object)(object)val != (Object)null)
{
TextMeshProUGUI component2 = ((Component)val).GetComponent<TextMeshProUGUI>();
if ((Object)(object)component2 != (Object)null)
{
string text = "Player";
if (ClientInstance.playerInstances.TryGetValue(__instance.PlayerIdNumber, out var value2))
{
text = value2.PlayerName;
}
((TMP_Text)component2).text = text;
((TMP_Text)component2).overflowMode = (TextOverflowModes)1;
((Component)val).gameObject.SetActive(true);
((Behaviour)component2).enabled = true;
((Graphic)component2).color = new Color(1f, 1f, 1f, 1f);
((TMP_Text)component2).fontSize = 14f;
}
}
}
int playerIdNumber = __instance.PlayerIdNumber;
if (!((Object)(object)component != (Object)null) || maxPlayers <= 4)
{
return;
}
Vector2 anchoredPosition = component.anchoredPosition;
if (playerIdNumber >= 4)
{
int num = playerIdNumber - 4;
float num2 = 135f;
float num3 = 70f;
float num4 = -650f;
float num5 = num4 + (float)num * num2;
float num6 = anchoredPosition.y + num3;
component.anchoredPosition = new Vector2(num5, num6);
if ((Object)(object)((Transform)component).parent != (Object)null)
{
Transform val2 = ((Transform)component).parent.Find("playername");
float num7 = 0f;
if ((Object)(object)val2 != (Object)null)
{
RectTransform component3 = ((Component)val2).GetComponent<RectTransform>();
TextMeshProUGUI component4 = ((Component)val2).GetComponent<TextMeshProUGUI>();
if ((Object)(object)component3 != (Object)null)
{
if ((Object)(object)component4 != (Object)null)
{
((TMP_Text)component4).alignment = (TextAlignmentOptions)513;
}
Vector2 anchoredPosition2 = component3.anchoredPosition;
num7 = anchoredPosition2.y - num3;
component3.anchoredPosition = new Vector2(num5, num7);
component3.pivot = new Vector2(0f, 0.5f);
}
}
Transform val3 = ((Transform)component).parent.Find("readytext");
if ((Object)(object)val3 != (Object)null)
{
RectTransform component5 = ((Component)val3).GetComponent<RectTransform>();
TextMeshProUGUI component6 = ((Component)val3).GetComponent<TextMeshProUGUI>();
if ((Object)(object)component5 != (Object)null)
{
if ((Object)(object)component6 != (Object)null)
{
((TMP_Text)component6).alignment = (TextAlignmentOptions)513;
}
float num8 = num7 - 20f;
component5.anchoredPosition = new Vector2(num5, num8);
component5.pivot = new Vector2(0f, 0.5f);
}
}
}
}
if ((Object)(object)((Transform)component).parent != (Object)null)
{
Transform val4 = ((Transform)component).parent.Find("icon");
if ((Object)(object)val4 != (Object)null)
{
((Component)val4).gameObject.SetActive(false);
}
}
}
}
}