using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using InnerNet;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("LobbyMapChanger")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Change Among Us Maps from the Lobby")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LobbyMapChanger")]
[assembly: AssemblyTitle("LobbyMapChanger")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace MoreSettings;
[BepInPlugin("com.yourname.moresettings", "More Settings", "1.0.0")]
public class Plugin : BasePlugin
{
public static int ActivePhysicalMapId = -1;
public static GameObject SpawnedMapObject = null;
public static List<GameObject> CachedLobbyClutter = new List<GameObject>();
public static bool HasShownHostTip = false;
public override void Load()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
new Harmony("com.yourname.moresettings").PatchAll();
((BasePlugin)this).Log.LogInfo((object)"More Settings mod loaded successfully!");
}
}
[HarmonyPatch(typeof(LobbyBehaviour), "Update")]
public static class LobbyUpdatePatch
{
private static Dictionary<Transform, Vector3> originalPositions = new Dictionary<Transform, Vector3>();
[HarmonyPostfix]
public static void Postfix(LobbyBehaviour __instance)
{
//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
//IL_02e1: Expected O, but got Unknown
//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
//IL_02d2: Expected O, but got Unknown
if ((Object)(object)__instance == (Object)null)
{
return;
}
bool flag = (Object)(object)Plugin.SpawnedMapObject != (Object)null;
if (!flag && (Object)(object)AmongUsClient.Instance != (Object)null && ((InnerNetClient)AmongUsClient.Instance).AmHost)
{
if (!Plugin.HasShownHostTip && (Object)(object)DestroyableSingleton<HudManager>.Instance != (Object)null && (Object)(object)DestroyableSingleton<HudManager>.Instance.Chat != (Object)null && (Object)(object)PlayerControl.LocalPlayer != (Object)null)
{
DestroyableSingleton<HudManager>.Instance.Chat.AddChat(PlayerControl.LocalPlayer, "<color=#00FF00>HOST TIP:</color> Type <color=#FFFF00>/map skeld</color>, <color=#FFFF00>reversed</color> (or <color=#FFFF00>dleks</color>), <color=#FFFF00>mira</color>, <color=#FFFF00>polus</color>, <color=#FFFF00>airship</color>, <color=#FFFF00>fungle</color>, or <color=#FFFF00>lobby</color> in chat to change the map background!", true);
Plugin.HasShownHostTip = true;
}
}
else if (!flag)
{
Plugin.HasShownHostTip = false;
}
if (flag && Plugin.CachedLobbyClutter.Count > 0)
{
foreach (GameObject item in Plugin.CachedLobbyClutter)
{
if ((Object)(object)item != (Object)null && item.activeSelf && !IsProtectedHierarchy(item.transform))
{
item.SetActive(false);
}
}
foreach (PlayerControl item2 in Object.FindObjectsOfType<PlayerControl>())
{
if ((Object)(object)item2 != (Object)null && (Object)(object)item2 != (Object)(object)PlayerControl.LocalPlayer)
{
Object.Destroy((Object)(object)((Component)item2).gameObject);
}
}
}
if ((Object)(object)DestroyableSingleton<HudManager>.Instance != (Object)null)
{
if ((Object)(object)DestroyableSingleton<HudManager>.Instance.TaskPanel != (Object)null)
{
((Component)DestroyableSingleton<HudManager>.Instance.TaskPanel).gameObject.SetActive(flag);
}
if ((Object)(object)DestroyableSingleton<HudManager>.Instance.ReportButton != (Object)null)
{
((Component)DestroyableSingleton<HudManager>.Instance.ReportButton).gameObject.SetActive(!flag);
}
if ((Object)(object)DestroyableSingleton<HudManager>.Instance.Chat != (Object)null && (Object)(object)((Component)DestroyableSingleton<HudManager>.Instance.Chat).gameObject != (Object)null)
{
((Component)DestroyableSingleton<HudManager>.Instance.Chat).gameObject.SetActive(true);
}
if ((Object)(object)DestroyableSingleton<HudManager>.Instance.MapButton != (Object)null)
{
((Component)DestroyableSingleton<HudManager>.Instance.MapButton).gameObject.SetActive(flag);
((Behaviour)DestroyableSingleton<HudManager>.Instance.MapButton).enabled = flag;
foreach (SpriteRenderer componentsInChild in ((Component)DestroyableSingleton<HudManager>.Instance.MapButton).GetComponentsInChildren<SpriteRenderer>(true))
{
if ((Object)(object)componentsInChild != (Object)null)
{
((Renderer)componentsInChild).enabled = flag;
}
}
}
UpdateMapButtonLayout(((Component)DestroyableSingleton<HudManager>.Instance).transform, flag);
}
if (!Input.GetKeyDown((KeyCode)9) || !((Object)(object)Plugin.SpawnedMapObject != (Object)null))
{
return;
}
foreach (MapBehaviour item3 in Object.FindObjectsOfType<MapBehaviour>(true))
{
if (!((Object)(object)item3 != (Object)null))
{
continue;
}
try
{
if (((Component)item3).gameObject.activeSelf)
{
item3.Close();
}
else
{
item3.Show(new MapOptions());
}
}
catch
{
try
{
item3.Show(new MapOptions());
}
catch
{
}
}
}
}
private static void UpdateMapButtonLayout(Transform parent, bool active)
{
if ((Object)(object)parent == (Object)null)
{
return;
}
for (int i = 0; i < parent.childCount; i++)
{
Transform child = parent.GetChild(i);
if ((Object)(object)child == (Object)null)
{
continue;
}
string text = ((Object)child).name.ToLower();
if (text.Contains("mapbutton") || text == "map" || text.Contains("map_button"))
{
((Component)child).gameObject.SetActive(active);
Button component = ((Component)child).GetComponent<Button>();
if ((Object)(object)component != (Object)null)
{
((Selectable)component).interactable = active;
}
foreach (Image componentsInChild in ((Component)child).GetComponentsInChildren<Image>(true))
{
if ((Object)(object)componentsInChild != (Object)null)
{
((Behaviour)componentsInChild).enabled = active;
}
}
foreach (SpriteRenderer componentsInChild2 in ((Component)child).GetComponentsInChildren<SpriteRenderer>(true))
{
if ((Object)(object)componentsInChild2 != (Object)null)
{
((Renderer)componentsInChild2).enabled = active;
}
}
}
if (child.childCount > 0)
{
UpdateMapButtonLayout(child, active);
}
}
}
private static bool IsProtectedHierarchy(Transform t)
{
if ((Object)(object)t == (Object)null)
{
return false;
}
string text = ((Object)t).name.ToLower();
if (text.Contains("wardrobe") || text.Contains("laptop") || text.Contains("computer") || text.Contains("setting") || text.Contains("customization") || text.Contains("cosmetic") || text.Contains("stand") || text.Contains("button") || text.Contains("ui") || text.Contains("chat") || text.Contains("canvas") || text.Contains("hud") || text.Contains("menu") || text.Contains("hat") || text.Contains("skin") || text.Contains("pet") || text.Contains("map"))
{
return true;
}
return IsProtectedHierarchy(t.parent);
}
private static bool ContainsProtectedChild(Transform t)
{
if ((Object)(object)t == (Object)null)
{
return false;
}
string text = ((Object)t).name.ToLower();
if (text.Contains("wardrobe") || text.Contains("laptop") || text.Contains("computer") || text.Contains("setting") || text.Contains("customization") || text.Contains("cosmetic") || text.Contains("stand") || text.Contains("button") || text.Contains("ui") || text.Contains("chat") || text.Contains("canvas") || text.Contains("hud") || text.Contains("menu") || text.Contains("hat") || text.Contains("skin") || text.Contains("pet") || text.Contains("map"))
{
return true;
}
for (int i = 0; i < t.childCount; i++)
{
if (ContainsProtectedChild(t.GetChild(i)))
{
return true;
}
}
return false;
}
public static void SwitchMapScenery(LobbyBehaviour lobby, int targetPrefabIndex)
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_044a: Unknown result type (might be due to invalid IL or missing references)
//IL_044f: Unknown result type (might be due to invalid IL or missing references)
//IL_047d: Unknown result type (might be due to invalid IL or missing references)
//IL_0482: Unknown result type (might be due to invalid IL or missing references)
//IL_0495: Unknown result type (might be due to invalid IL or missing references)
//IL_049a: Unknown result type (might be due to invalid IL or missing references)
//IL_0465: Unknown result type (might be due to invalid IL or missing references)
//IL_046a: Unknown result type (might be due to invalid IL or missing references)
//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
//IL_028b: Unknown result type (might be due to invalid IL or missing references)
//IL_024b: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
//IL_04e2: Unknown result type (might be due to invalid IL or missing references)
//IL_0995: Unknown result type (might be due to invalid IL or missing references)
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_07ff: Unknown result type (might be due to invalid IL or missing references)
//IL_080f: Unknown result type (might be due to invalid IL or missing references)
//IL_0814: Unknown result type (might be due to invalid IL or missing references)
Plugin.ActivePhysicalMapId = targetPrefabIndex;
UpdateMapOverlays(targetPrefabIndex);
if (originalPositions.Count == 0 && (Object)(object)lobby != (Object)null)
{
for (int i = 0; i < ((Component)lobby).transform.childCount; i++)
{
Transform child = ((Component)lobby).transform.GetChild(i);
if ((Object)(object)child != (Object)null)
{
originalPositions[child] = child.position;
}
}
}
if ((Object)(object)Plugin.SpawnedMapObject != (Object)null)
{
Object.Destroy((Object)(object)Plugin.SpawnedMapObject);
Plugin.SpawnedMapObject = null;
}
int num;
switch (targetPrefabIndex)
{
case -1:
{
foreach (GameObject item in Plugin.CachedLobbyClutter)
{
if ((Object)(object)item != (Object)null)
{
item.SetActive(true);
}
}
Plugin.CachedLobbyClutter.Clear();
if ((Object)(object)lobby != (Object)null)
{
foreach (Renderer componentsInChild in ((Component)lobby).GetComponentsInChildren<Renderer>(true))
{
if ((Object)(object)componentsInChild != (Object)null)
{
componentsInChild.enabled = true;
}
}
foreach (Collider2D componentsInChild2 in ((Component)lobby).GetComponentsInChildren<Collider2D>(true))
{
if ((Object)(object)componentsInChild2 != (Object)null)
{
((Behaviour)componentsInChild2).enabled = true;
}
}
}
for (int j = 0; j < ((Component)lobby).transform.childCount; j++)
{
Transform child2 = ((Component)lobby).transform.GetChild(j);
if ((Object)(object)child2 != (Object)null && (Object)(object)((Component)child2).gameObject != (Object)null)
{
((Component)child2).gameObject.SetActive(true);
if (originalPositions.ContainsKey(child2))
{
child2.position = originalPositions[child2];
}
}
}
if ((Object)(object)PlayerControl.LocalPlayer != (Object)null)
{
((Component)PlayerControl.LocalPlayer).transform.position = new Vector3(0f, 0f, -1f);
}
return;
}
default:
num = targetPrefabIndex;
break;
case 3:
num = 0;
break;
}
int num2 = num;
bool flag = targetPrefabIndex == 3;
GameObject val = null;
if ((Object)(object)AmongUsClient.Instance != (Object)null && num2 >= 0 && num2 < AmongUsClient.Instance.ShipPrefabs.Count)
{
val = AmongUsClient.Instance.ShipPrefabs[num2].InstantiateAsync(Vector3.zero, Quaternion.identity, (Transform)null).WaitForCompletion();
}
if ((Object)(object)val != (Object)null)
{
Plugin.SpawnedMapObject = val;
if (flag)
{
val.transform.localScale = new Vector3(-1f, 1f, 1f);
}
foreach (ShipStatus componentsInChild3 in val.GetComponentsInChildren<ShipStatus>(true))
{
if ((Object)(object)componentsInChild3 != (Object)null)
{
Object.Destroy((Object)(object)componentsInChild3);
}
}
foreach (Component componentsInChild4 in val.GetComponentsInChildren<Component>(true))
{
if (!((Object)(object)componentsInChild4 != (Object)null))
{
continue;
}
string name = ((object)componentsInChild4).GetType().Name;
if (name.Contains("AudioSource") || name.Contains("Vision") || name.Contains("Fog"))
{
PropertyInfo property = ((object)componentsInChild4).GetType().GetProperty("enabled");
if (property != null)
{
property.SetValue(componentsInChild4, false);
}
}
}
foreach (Transform componentsInChild5 in val.GetComponentsInChildren<Transform>(true))
{
if (!((Object)(object)componentsInChild5 == (Object)null) && !((Object)(object)((Component)componentsInChild5).gameObject == (Object)null))
{
string text = ((Object)((Component)componentsInChild5).gameObject).name.ToLower();
if (text.Contains("emergency") || text.Contains("meeting") || text.Contains("button"))
{
Object.Destroy((Object)(object)((Component)componentsInChild5).gameObject);
}
else
{
((Component)componentsInChild5).gameObject.SetActive(true);
}
}
}
}
Vector3 val2 = (Vector3)(targetPrefabIndex switch
{
0 => new Vector3(0f, 0.2f, -1f),
3 => new Vector3(0f, 0.2f, -1f),
1 => new Vector3(-4.4f, 2.2f, -1f),
2 => new Vector3(16.6f, -2f, -1f),
4 => new Vector3(0f, 0f, -1f),
5 => new Vector3(-9.5f, 0.5f, -1f),
_ => new Vector3(0f, 0f, -1f),
});
Plugin.CachedLobbyClutter.Clear();
HideLobbyClutterRecursive(((Component)lobby).transform);
if ((Object)(object)lobby != (Object)null)
{
foreach (Renderer componentsInChild6 in ((Component)lobby).GetComponentsInChildren<Renderer>(true))
{
if (!((Object)(object)componentsInChild6 != (Object)null))
{
continue;
}
if (IsProtectedHierarchy(((Component)componentsInChild6).transform))
{
componentsInChild6.enabled = true;
continue;
}
string text2 = ((Object)((Component)componentsInChild6).gameObject).name.ToLower();
if (!text2.Contains("setting") && !text2.Contains("menu") && !text2.Contains("ui") && !text2.Contains("chat") && !text2.Contains("wardrobe") && !text2.Contains("laptop") && !text2.Contains("computer") && !text2.Contains("customization") && !text2.Contains("canvas") && !text2.Contains("cosmetic") && !text2.Contains("stand") && !text2.Contains("button") && !text2.Contains("map"))
{
componentsInChild6.enabled = false;
}
}
foreach (Collider2D componentsInChild7 in ((Component)lobby).GetComponentsInChildren<Collider2D>(true))
{
if ((Object)(object)componentsInChild7 == (Object)null || (Object)(object)((Component)componentsInChild7).gameObject == (Object)null)
{
continue;
}
if (IsProtectedHierarchy(((Component)componentsInChild7).transform))
{
((Behaviour)componentsInChild7).enabled = true;
continue;
}
string text3 = ((Object)((Component)componentsInChild7).gameObject).name.ToLower();
if (text3.Contains("wardrobe") || text3.Contains("customization") || text3.Contains("laptop") || text3.Contains("computer") || text3.Contains("setting") || text3.Contains("button") || text3.Contains("stand") || text3.Contains("ui") || text3.Contains("chat") || text3.Contains("map"))
{
((Behaviour)componentsInChild7).enabled = true;
}
else
{
((Behaviour)componentsInChild7).enabled = false;
}
}
for (int k = 0; k < ((Component)lobby).transform.childCount; k++)
{
Transform child3 = ((Component)lobby).transform.GetChild(k);
if (!((Object)(object)child3 == (Object)null))
{
string text4 = ((Object)child3).name.ToLower();
if (text4.Contains("wardrobe") || text4.Contains("cosmetic") || text4.Contains("stand") || text4.Contains("laptop") || text4.Contains("computer") || text4.Contains("setting"))
{
((Component)child3).gameObject.SetActive(true);
child3.position = val2 + new Vector3(1.2f, 0f, 0f);
}
}
}
foreach (Transform componentsInChild8 in ((Component)lobby).GetComponentsInChildren<Transform>(true))
{
if ((Object)(object)componentsInChild8 == (Object)null)
{
continue;
}
string text5 = ((Object)componentsInChild8).name.ToLower();
if (!text5.Contains("wardrobe") && !text5.Contains("cosmetic") && !text5.Contains("stand") && !text5.Contains("laptop") && !text5.Contains("computer") && !text5.Contains("setting") && !text5.Contains("chat") && !text5.Contains("ui") && !text5.Contains("menu") && !text5.Contains("map"))
{
continue;
}
((Component)componentsInChild8).gameObject.SetActive(true);
foreach (Renderer componentsInChild9 in ((Component)componentsInChild8).GetComponentsInChildren<Renderer>(true))
{
if ((Object)(object)componentsInChild9 != (Object)null)
{
componentsInChild9.enabled = true;
componentsInChild9.sortingLayerName = "Players";
componentsInChild9.sortingOrder = 2000;
}
}
}
}
if (!((Object)(object)PlayerControl.LocalPlayer != (Object)null))
{
return;
}
((Component)PlayerControl.LocalPlayer).transform.position = val2;
foreach (PlayerControl item2 in Object.FindObjectsOfType<PlayerControl>())
{
if ((Object)(object)item2 != (Object)null && (Object)(object)item2 != (Object)(object)PlayerControl.LocalPlayer)
{
Object.Destroy((Object)(object)((Component)item2).gameObject);
}
}
foreach (SpriteRenderer componentsInChild10 in ((Component)PlayerControl.LocalPlayer).GetComponentsInChildren<SpriteRenderer>(true))
{
if ((Object)(object)componentsInChild10 != (Object)null)
{
((Renderer)componentsInChild10).sortingLayerName = "Players";
((Renderer)componentsInChild10).sortingOrder = 2500;
}
}
}
private static void HideLobbyClutterRecursive(Transform parent)
{
if ((Object)(object)parent == (Object)null)
{
return;
}
if (ContainsProtectedChild(parent))
{
((Component)parent).gameObject.SetActive(true);
for (int i = 0; i < parent.childCount; i++)
{
HideLobbyClutterRecursive(parent.GetChild(i));
}
return;
}
for (int j = 0; j < parent.childCount; j++)
{
Transform child = parent.GetChild(j);
if ((Object)(object)child == (Object)null || (Object)(object)((Component)child).gameObject == (Object)null)
{
continue;
}
if (ContainsProtectedChild(child))
{
((Component)child).gameObject.SetActive(true);
HideLobbyClutterRecursive(child);
continue;
}
string text = ((Object)((Component)child).gameObject).name.ToLower();
if (text.Contains("table") || text.Contains("pizza") || text.Contains("balloon") || text.Contains("chair") || text.Contains("dropship") || text.Contains("shuttle") || text.Contains("dropshipanim") || text.Contains("sidebar") || text.Contains("border") || text.Contains("background") || text.Contains("dark") || text.Contains("mask") || text.Contains("shadow") || text.Contains("lighting") || text.Contains("occlusion"))
{
((Component)child).gameObject.SetActive(false);
Plugin.CachedLobbyClutter.Add(((Component)child).gameObject);
}
else
{
HideLobbyClutterRecursive(child);
}
}
}
private static void UpdateMapOverlays(int mapId)
{
foreach (MapBehaviour item in Object.FindObjectsOfType<MapBehaviour>(true))
{
if ((Object)(object)item == (Object)null)
{
continue;
}
foreach (Transform componentsInChild in ((Component)item).GetComponentsInChildren<Transform>(true))
{
if (!((Object)(object)componentsInChild == (Object)null) && !((Object)(object)componentsInChild.parent != (Object)(object)((Component)item).transform))
{
string text = ((Object)componentsInChild).name.ToLower();
bool active = mapId switch
{
0 => text.Contains("skeld") || text.Contains("ship") || text.Contains("normal"),
3 => text.Contains("skeld") || text.Contains("ship") || text.Contains("normal"),
1 => text.Contains("mira") || text.Contains("hq"),
2 => text.Contains("polus") || text.Contains("outpost"),
4 => text.Contains("airship"),
5 => text.Contains("fungle"),
_ => true,
};
if (text.Contains("skeld") || text.Contains("mira") || text.Contains("polus") || text.Contains("airship") || text.Contains("fungle"))
{
((Component)componentsInChild).gameObject.SetActive(active);
}
}
}
}
}
}
[HarmonyPatch(typeof(ChatController), "AddChat")]
public static class ChatControllerAddChatPatch
{
public static bool Prefix(PlayerControl sourcePlayer, string chatText)
{
if ((Object)(object)sourcePlayer == (Object)(object)PlayerControl.LocalPlayer && !string.IsNullOrEmpty(chatText) && chatText.StartsWith("/map", StringComparison.OrdinalIgnoreCase))
{
string text = ((chatText.Length > 4) ? chatText.Substring(4).Trim().ToLower() : "");
int num = -1;
switch (text)
{
case "skeld":
case "0":
case "normal":
num = 0;
break;
case "reversed":
case "revskeld":
case "3":
case "rev":
case "dleks":
num = 3;
break;
case "mira":
case "mirahq":
case "1":
num = 1;
break;
case "polus":
case "2":
num = 2;
break;
case "airship":
case "4":
num = 4;
break;
case "fungle":
case "5":
num = 5;
break;
case "lobby":
case "none":
case "off":
num = -1;
break;
default:
return false;
}
LobbyBehaviour val = Object.FindObjectOfType<LobbyBehaviour>();
if ((Object)(object)val != (Object)null)
{
LobbyUpdatePatch.SwitchMapScenery(val, num);
}
return false;
}
return true;
}
}