using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Cinemachine;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using OnTogetherMods.Shared;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Experimental.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PhotoMode")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.1.0")]
[assembly: AssemblyInformationalVersion("0.4.1+622bd7ccbb267719684ff770ce18e1834dc51b45")]
[assembly: AssemblyProduct("PhotoMode")]
[assembly: AssemblyTitle("PhotoMode")]
[assembly: AssemblyVersion("0.4.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 OnTogetherMods.Shared
{
internal static class PanelStack
{
private const string TableKey = "OnTogetherMods.PanelStack.Panels";
private const string HiddenKey = "OnTogetherMods.PanelStack.Hidden";
private const string IconBarKey = "OnTogetherMods.IconBar.Rect";
private const float Margin = 20f;
private const float FromRight = 0.15f;
private const float Gap = 10f;
private const int WorldScene = 2;
public const int PhotoModeOrder = 0;
public const int EmoteSyncOrder = 10;
public const int TeleportSpotsOrder = 20;
public const int SongPlayerOrder = 30;
public const int TraceOverlayOrder = 40;
public const int NameDesignerOrder = 50;
public const string CanvasPrefix = "OnTogetherMods ";
private static int _deskFrame = -1;
private static bool _desk;
public static float Width => (float)Screen.width * 1080f / (float)Screen.height;
public static bool Hidden
{
get
{
if (!(AppDomain.CurrentDomain.GetData("OnTogetherMods.PanelStack.Hidden") is int num) || Time.frameCount > num)
{
return InDeskMode;
}
return true;
}
}
public static bool InDeskMode
{
get
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Invalid comparison between Unknown and I4
int frameCount = Time.frameCount;
if (_deskFrame != frameCount)
{
_deskFrame = frameCount;
_desk = false;
Scene activeScene = SceneManager.GetActiveScene();
if (((Scene)(ref activeScene)).buildIndex == 2)
{
OverlayManager i = MonoSingleton<OverlayManager>.I;
_desk = (Object)(object)i != (Object)null && (int)i.ResolutionMode == 3;
}
}
return _desk;
}
}
public static bool IsModCanvas(Canvas canvas)
{
Canvas val = canvas;
Transform parent = ((Component)canvas).transform.parent;
while ((Object)(object)parent != (Object)null)
{
Canvas component = ((Component)parent).GetComponent<Canvas>();
val = (((Object)(object)component != (Object)null) ? component : val);
parent = parent.parent;
}
return ((Object)((Component)val).gameObject).name.StartsWith("OnTogetherMods ", StringComparison.Ordinal);
}
public static void HideForCapture()
{
AppDomain.CurrentDomain.SetData("OnTogetherMods.PanelStack.Hidden", Time.frameCount + 1);
}
public static Rect Place(string id, int order, Vector2 size)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
Hashtable hashtable = Panels();
int frameCount = Time.frameCount;
hashtable[id] = new double[3] { order, size.y, frameCount };
float width = Width;
float num = Mathf.Max(20f, width * 0.85f - size.x);
float num2 = Bottom(num + size.x, frameCount) - size.y;
foreach (DictionaryEntry item in hashtable)
{
string text = (string)item.Key;
double[] array = (double[])item.Value;
bool flag = (double)frameCount - array[2] <= 2.0;
bool flag2 = array[0] < (double)order || (array[0] == (double)order && string.CompareOrdinal(text, id) < 0);
if (text != id && flag && flag2)
{
num2 -= (float)array[1] + 10f;
}
}
return new Rect(num, num2, size.x, size.y);
}
private static float Bottom(float windowRight, int frame)
{
float num = 1060f;
if (AppDomain.CurrentDomain.GetData("OnTogetherMods.IconBar.Rect") is double[] array && (double)frame - array[4] <= 2.0)
{
float num2 = 1080f / (float)Screen.height;
if (array[0] * (double)num2 < (double)(windowRight + 10f))
{
num = Mathf.Min(num, (float)array[1] * num2 - 10f);
}
}
return num;
}
public static Matrix4x4 Begin(out float width)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
float num = (float)Screen.height / 1080f;
Matrix4x4 matrix = GUI.matrix;
GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f));
width = (float)Screen.width / num;
return matrix;
}
public static void End(Matrix4x4 previous)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
GUI.matrix = previous;
}
public static GUIStyle MakeStyle(TextAnchor alignment)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: 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_001e: 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_002c: 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_003f: Expected O, but got Unknown
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
GUIStyle val = new GUIStyle(GUI.skin.box)
{
alignment = alignment,
fontSize = 15,
richText = true,
wordWrap = false,
padding = new RectOffset(12, 12, 10, 10)
};
val.normal.textColor = Color.white;
return val;
}
private static Hashtable Panels()
{
Hashtable hashtable = AppDomain.CurrentDomain.GetData("OnTogetherMods.PanelStack.Panels") as Hashtable;
if (hashtable == null)
{
hashtable = new Hashtable();
AppDomain.CurrentDomain.SetData("OnTogetherMods.PanelStack.Panels", hashtable);
}
return hashtable;
}
}
internal static class IconBar
{
public enum State
{
Plain,
Open,
On,
Off
}
public enum Click
{
None,
Left,
Right
}
private struct Metrics
{
public float Unit;
public int Art;
public int Button;
public int Gap;
public int Margin;
}
private static class Patches
{
private static Action<InputManager, bool> _setMouse0Down;
private static Action<InputManager, bool> _setMouse1;
private static Action<InputManager, bool> _setMouse1Up;
private static FieldRef<QuadPainterGPU, Vector2> _previousUV;
private static bool _leftOnBar;
private static bool _rightOnBar;
public static void Apply(Harmony harmony)
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Expected O, but got Unknown
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Expected O, but got Unknown
_setMouse0Down = Setter("IsMouseButton0Down");
_setMouse1 = Setter("IsMouseButton1");
_setMouse1Up = Setter("IsMouseButton1Up");
harmony.Patch((MethodBase)AccessTools.Method(typeof(InputManager), "Update", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Patches), "InputPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
_previousUV = AccessTools.FieldRefAccess<QuadPainterGPU, Vector2>("previousUV");
harmony.Patch((MethodBase)AccessTools.Method(typeof(QuadPainterGPU), "Update", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Patches), "PaintPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
private static void InputPostfix(InputManager __instance)
{
bool mouseOver = MouseOver;
if (Input.GetMouseButtonDown(0))
{
_leftOnBar = mouseOver;
}
if (Input.GetMouseButtonDown(1))
{
_rightOnBar = mouseOver;
}
if (mouseOver)
{
_setMouse0Down(__instance, arg2: false);
}
if (_rightOnBar)
{
_setMouse1(__instance, arg2: false);
_setMouse1Up(__instance, arg2: false);
}
if (!Input.GetMouseButton(0))
{
_leftOnBar = false;
}
if (!Input.GetMouseButton(1))
{
_rightOnBar = false;
}
}
private static bool PaintPrefix(QuadPainterGPU __instance)
{
if (__instance.IsActive && (_leftOnBar || MouseOver))
{
_previousUV.Invoke(__instance).x = -1f;
return false;
}
return true;
}
private static Action<InputManager, bool> Setter(string property)
{
return (Action<InputManager, bool>)Delegate.CreateDelegate(typeof(Action<InputManager, bool>), AccessTools.PropertySetter(typeof(InputManager), property));
}
}
public const int PhotoModeOrder = 0;
public const int EmoteSyncOrder = 10;
public const int TeleportSpotsOrder = 20;
public const int NameDesignerOrder = 30;
public const int DeskSnapOrder = 40;
public const int FocusAnywhereOrder = 50;
public const int SongPlayerOrder = 60;
public const int TraceOverlayOrder = 70;
public const int ChatRangeOrder = 80;
private const string RectKey = "OnTogetherMods.IconBar.Rect";
private const string TableKey = "OnTogetherMods.IconBar.Icons";
private const string PatchedKey = "OnTogetherMods.IconBar.Patched";
private const string BlockerKey = "OnTogetherMods.IconBar.Blocker";
private const string BlockerFrameKey = "OnTogetherMods.IconBar.BlockerFrame";
private const string HiddenKey = "OnTogetherMods.IconBar.HiddenUntil";
private const int WorldScene = 2;
private const int TooltipDepth = -100;
private static readonly Dictionary<char, Color32> Palette = new Dictionary<char, Color32>
{
{
'K',
new Color32((byte)42, (byte)36, (byte)51, byte.MaxValue)
},
{
'W',
new Color32((byte)247, (byte)243, (byte)234, byte.MaxValue)
},
{
'G',
new Color32((byte)201, (byte)198, (byte)207, byte.MaxValue)
},
{
'g',
new Color32((byte)143, (byte)138, (byte)153, byte.MaxValue)
},
{
'D',
new Color32((byte)87, (byte)82, (byte)95, byte.MaxValue)
},
{
'B',
new Color32((byte)168, (byte)107, (byte)60, byte.MaxValue)
},
{
'b',
new Color32((byte)217, (byte)160, (byte)102, byte.MaxValue)
},
{
'd',
new Color32((byte)110, (byte)67, (byte)37, byte.MaxValue)
},
{
'R',
new Color32((byte)224, (byte)90, (byte)90, byte.MaxValue)
},
{
'r',
new Color32((byte)168, (byte)58, (byte)70, byte.MaxValue)
},
{
'p',
new Color32((byte)246, (byte)165, (byte)165, byte.MaxValue)
},
{
'Y',
new Color32((byte)245, (byte)208, (byte)97, byte.MaxValue)
},
{
'y',
new Color32((byte)201, (byte)150, (byte)50, byte.MaxValue)
},
{
'O',
new Color32((byte)232, (byte)146, (byte)74, byte.MaxValue)
},
{
'L',
new Color32((byte)159, (byte)214, (byte)245, byte.MaxValue)
},
{
'U',
new Color32((byte)74, (byte)143, (byte)217, byte.MaxValue)
},
{
'u',
new Color32((byte)47, (byte)90, (byte)158, byte.MaxValue)
},
{
'N',
new Color32((byte)116, (byte)192, (byte)105, byte.MaxValue)
},
{
'n',
new Color32((byte)63, (byte)138, (byte)74, byte.MaxValue)
},
{
'P',
new Color32((byte)246, (byte)207, (byte)174, byte.MaxValue)
},
{
'V',
new Color32((byte)154, (byte)114, (byte)214, byte.MaxValue)
},
{
'v',
new Color32((byte)105, (byte)72, (byte)160, byte.MaxValue)
},
{
'S',
new Color32((byte)233, (byte)139, (byte)181, byte.MaxValue)
},
{
'H',
new Color32((byte)60, (byte)48, (byte)56, byte.MaxValue)
}
};
private static readonly Color32 ButtonFill = new Color32((byte)28, (byte)26, (byte)34, (byte)200);
private static readonly Color32 ButtonEdge = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)30);
private static readonly Color32 HoverFill = new Color32((byte)48, (byte)45, (byte)58, (byte)225);
private static readonly Color32 HoverEdge = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)80);
private static readonly Color32 OpenFill = new Color32((byte)70, (byte)64, (byte)88, (byte)235);
private static readonly Color32 OpenEdge = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)150);
private static readonly Color32 DotFill = new Color32((byte)140, (byte)220, (byte)120, byte.MaxValue);
private static readonly Color32 DotEdge = new Color32((byte)20, (byte)40, (byte)20, byte.MaxValue);
private static readonly Dictionary<string[], Texture2D[]> Icons = new Dictionary<string[], Texture2D[]>();
private static Texture2D _buttonTexture;
private static Texture2D _hoverTexture;
private static Texture2D _openTexture;
private static Texture2D _dotTexture;
private static GUIStyle _buttonStyle;
private static GUIStyle _tipStyle;
private static int _builtFor;
private static int _cachedFrame = -1;
private static bool _inWorld;
private static bool _visible;
private static int _pressedButton;
private static bool RowHidden
{
get
{
if (AppDomain.CurrentDomain.GetData("OnTogetherMods.IconBar.HiddenUntil") is int num)
{
return Time.frameCount <= num;
}
return false;
}
}
public static bool MouseOver
{
get
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: 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: Unknown result type (might be due to invalid IL or missing references)
if (!(AppDomain.CurrentDomain.GetData("OnTogetherMods.IconBar.Rect") is double[] array) || array[5] < 0.5 || (double)Time.frameCount - array[4] > 2.0)
{
return false;
}
Vector3 mousePosition = Input.mousePosition;
Rect val = default(Rect);
((Rect)(ref val))..ctor((float)array[0], (float)array[1], (float)array[2], (float)array[3]);
return ((Rect)(ref val)).Contains(new Vector2(mousePosition.x, (float)Screen.height - mousePosition.y));
}
}
public static Click Draw(string id, int order, string[] pixels, State state, string name, KeyCode key, string hint = null)
{
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: 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_0049: 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_0029: Unknown result type (might be due to invalid IL or missing references)
//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_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
int controlID = GUIUtility.GetControlID((FocusType)2);
Event current = Event.current;
Refresh();
if (!_inWorld)
{
Hide(controlID, current);
UpdateBlocker(shown: false, default(Rect));
return Click.None;
}
Rect bar;
Metrics m;
Rect icon = Place(id, order, out bar, out m);
Share(bar);
UpdateBlocker(_visible, bar);
if (!_visible)
{
Hide(controlID, current);
return Click.None;
}
Matrix4x4 matrix = GUI.matrix;
GUI.matrix = Matrix4x4.identity;
try
{
return Handle(controlID, current, icon, m, pixels, state, name, key, hint);
}
finally
{
GUI.matrix = matrix;
}
}
public static void HideRow()
{
AppDomain.CurrentDomain.SetData("OnTogetherMods.IconBar.HiddenUntil", Time.frameCount + 1);
}
public static string KeyText(KeyCode key)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
if ((int)key != 0)
{
return $" ({key})";
}
return "";
}
private static Click Handle(int control, Event e, Rect icon, Metrics m, string[] pixels, State state, string name, KeyCode key, string hint)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: 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_002c: Expected I4, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
bool flag = ((Rect)(ref icon)).Contains(e.mousePosition);
EventType typeForControl = e.GetTypeForControl(control);
switch ((int)typeForControl)
{
default:
{
if ((int)typeForControl != 7)
{
break;
}
BuildStyles(m);
bool flag2 = GUIUtility.hotControl == control;
_buttonStyle.normal.background = ((state == State.Open || (flag2 && flag)) ? _openTexture : (flag ? _hoverTexture : _buttonTexture));
_buttonStyle.Draw(icon, false, false, false, false);
Texture2D[] array = IconTextures(pixels);
GUI.DrawTexture(new Rect(((Rect)(ref icon)).x + (((Rect)(ref icon)).width - (float)m.Art) / 2f, ((Rect)(ref icon)).y + (((Rect)(ref icon)).height - (float)m.Art) / 2f, (float)m.Art, (float)m.Art), (Texture)(object)((state == State.Off) ? array[1] : array[0]));
if (state == State.On)
{
float num = Mathf.Max(1, Mathf.RoundToInt(2f * m.Unit));
float num2 = ((Texture)_dotTexture).width;
GUI.DrawTexture(new Rect(((Rect)(ref icon)).xMax - num - num2, ((Rect)(ref icon)).yMax - num - num2, num2, num2), (Texture)(object)_dotTexture);
}
int num3;
if (flag)
{
num3 = ((GUIUtility.hotControl == 0 || flag2) ? 1 : 0);
if (num3 != 0)
{
DrawTooltip(icon, m, Tooltip(state, name, key, hint));
}
}
else
{
num3 = 0;
}
GUI.depth = ((num3 != 0) ? (-100) : 0);
break;
}
case 0:
if (flag && (e.button == 0 || e.button == 1))
{
GUIUtility.hotControl = control;
_pressedButton = e.button;
e.Use();
}
break;
case 3:
if (GUIUtility.hotControl == control)
{
e.Use();
}
break;
case 1:
if (GUIUtility.hotControl != control)
{
break;
}
GUIUtility.hotControl = 0;
e.Use();
if (flag && e.button == _pressedButton)
{
if (e.button != 0)
{
return Click.Right;
}
return Click.Left;
}
break;
case 2:
break;
}
return Click.None;
}
private static string Tooltip(State state, string name, KeyCode key, string hint)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
string text = name + KeyText(key);
switch (state)
{
case State.On:
text += ": on";
break;
case State.Off:
text += ": off";
break;
}
if (hint == null)
{
return text;
}
return text + "\n" + hint;
}
private static void DrawTooltip(Rect icon, Metrics m, string text)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: 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_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
GUIContent val = new GUIContent(text);
Vector2 val2 = _tipStyle.CalcSize(val);
float num = Mathf.Clamp(((Rect)(ref icon)).center.x - val2.x / 2f, (float)m.Margin, Mathf.Max((float)m.Margin, (float)(Screen.width - m.Margin) - val2.x));
float num2 = ((Rect)(ref icon)).y - (float)m.Gap - val2.y;
_tipStyle.Draw(new Rect(Mathf.Round(num), Mathf.Round(num2), val2.x, val2.y), val, false, false, false, false);
}
private static void Hide(int control, Event e)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Invalid comparison between Unknown and I4
if (GUIUtility.hotControl == control)
{
GUIUtility.hotControl = 0;
}
if ((int)e.type == 7)
{
GUI.depth = 0;
}
}
private static Metrics Measure()
{
float num = (float)Screen.height / 1080f;
int num2 = Mathf.Max(1, Mathf.RoundToInt(2f * num));
int num3 = Mathf.Max(2, Mathf.RoundToInt(4f * num));
return new Metrics
{
Unit = num,
Art = 16 * num2,
Button = 16 * num2 + 2 * num3,
Gap = Mathf.Max(2, Mathf.RoundToInt(6f * num)),
Margin = Mathf.RoundToInt(20f * num)
};
}
private static Rect Place(string id, int order, out Rect bar, out Metrics m)
{
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
Hashtable hashtable = Table();
int frameCount = Time.frameCount;
if (hashtable[id] is double[] array)
{
array[0] = order;
array[1] = frameCount;
}
else
{
hashtable[id] = new double[2] { order, frameCount };
}
int num = 0;
int num2 = 0;
foreach (DictionaryEntry item in hashtable)
{
string text = (string)item.Key;
double[] array2 = (double[])item.Value;
if (!((double)frameCount - array2[1] > 2.0))
{
num2++;
if (text != id && (array2[0] < (double)order || (array2[0] == (double)order && string.CompareOrdinal(text, id) < 0)))
{
num++;
}
}
}
m = Measure();
int num3 = num2 * m.Button + (num2 - 1) * m.Gap;
int num4 = Screen.width - m.Margin - num3;
int num5 = Screen.height - m.Margin - m.Button;
bar = new Rect((float)num4, (float)num5, (float)num3, (float)m.Button);
return new Rect((float)(num4 + num * (m.Button + m.Gap)), (float)num5, (float)m.Button, (float)m.Button);
}
private static void Share(Rect bar)
{
AppDomain currentDomain = AppDomain.CurrentDomain;
int frameCount = Time.frameCount;
if (!(currentDomain.GetData("OnTogetherMods.IconBar.Rect") is double[] array) || (int)array[4] != frameCount || !(array[2] >= (double)((Rect)(ref bar)).width))
{
currentDomain.SetData("OnTogetherMods.IconBar.Rect", new double[6]
{
((Rect)(ref bar)).x,
((Rect)(ref bar)).y,
((Rect)(ref bar)).width,
((Rect)(ref bar)).height,
frameCount,
_visible ? 1 : 0
});
}
}
private static Hashtable Table()
{
Hashtable hashtable = AppDomain.CurrentDomain.GetData("OnTogetherMods.IconBar.Icons") as Hashtable;
if (hashtable == null)
{
hashtable = new Hashtable();
AppDomain.CurrentDomain.SetData("OnTogetherMods.IconBar.Icons", hashtable);
}
return hashtable;
}
private static void Refresh()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: 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)
//IL_0063: Invalid comparison between Unknown and I4
int frameCount = Time.frameCount;
if (_cachedFrame != frameCount)
{
_cachedFrame = frameCount;
Scene activeScene = SceneManager.GetActiveScene();
_inWorld = ((Scene)(ref activeScene)).buildIndex == 2;
_visible = false;
if (_inWorld && !PanelStack.Hidden && !RowHidden)
{
TaskManager i = MonoSingleton<TaskManager>.I;
_visible = (Object)(object)i != (Object)null && ((int)i.LockState == 0 || (int)i.LockState == 5);
}
}
}
private static void UpdateBlocker(bool shown, Rect bar)
{
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Expected O, but got Unknown
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
AppDomain currentDomain = AppDomain.CurrentDomain;
int frameCount = Time.frameCount;
if (currentDomain.GetData("OnTogetherMods.IconBar.BlockerFrame") is int num && num == frameCount)
{
return;
}
currentDomain.SetData("OnTogetherMods.IconBar.BlockerFrame", frameCount);
object? data = currentDomain.GetData("OnTogetherMods.IconBar.Blocker");
GameObject val = (GameObject)((data is GameObject) ? data : null);
if ((Object)(object)val == (Object)null)
{
if (!shown)
{
return;
}
val = CreateBlocker();
currentDomain.SetData("OnTogetherMods.IconBar.Blocker", val);
}
if (shown)
{
RectTransform val2 = (RectTransform)val.transform.GetChild(0);
Vector2 val3 = default(Vector2);
((Vector2)(ref val3))..ctor(((Rect)(ref bar)).x, (float)Screen.height - ((Rect)(ref bar)).yMax);
if (val2.anchoredPosition != val3)
{
val2.anchoredPosition = val3;
}
if (val2.sizeDelta != ((Rect)(ref bar)).size)
{
val2.sizeDelta = ((Rect)(ref bar)).size;
}
}
if (val.activeSelf != shown)
{
val.SetActive(shown);
}
}
private static GameObject CreateBlocker()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("OnTogetherMods IconBar ClickBlocker");
Object.DontDestroyOnLoad((Object)(object)val);
Canvas obj = val.AddComponent<Canvas>();
obj.renderMode = (RenderMode)0;
obj.sortingOrder = 32767;
val.AddComponent<GraphicRaycaster>();
GameObject val2 = new GameObject("Area", new Type[3]
{
typeof(RectTransform),
typeof(CanvasRenderer),
typeof(Image)
});
val2.transform.SetParent(val.transform, false);
((Graphic)val2.GetComponent<Image>()).color = Color.clear;
RectTransform val3 = (RectTransform)val2.transform;
val3.anchorMin = Vector2.zero;
val3.anchorMax = Vector2.zero;
val3.pivot = Vector2.zero;
val.SetActive(false);
return val;
}
public static void Patch()
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
AppDomain currentDomain = AppDomain.CurrentDomain;
if (currentDomain.GetData("OnTogetherMods.IconBar.Patched") != null)
{
return;
}
currentDomain.SetData("OnTogetherMods.IconBar.Patched", true);
try
{
Patches.Apply(new Harmony("nelphei.ontogether.iconbar"));
}
catch (Exception arg)
{
Debug.LogError((object)$"[OnTogetherMods] Icon bar patches failed, so clicks on it may reach the game: {arg}");
}
}
private static Texture2D[] IconTextures(string[] pixels)
{
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
if (Icons.TryGetValue(pixels, out var value) && (Object)(object)value[0] != (Object)null && (Object)(object)value[1] != (Object)null)
{
return value;
}
Color32[] array = (Color32[])(object)new Color32[256];
Color32[] array2 = (Color32[])(object)new Color32[256];
for (int i = 0; i < 16; i++)
{
string text = ((i < pixels.Length) ? pixels[i] : "");
for (int j = 0; j < 16; j++)
{
char key = ((j < text.Length) ? text[j] : '.');
Color32 value2;
Color32 val = (Color32)(Palette.TryGetValue(key, out value2) ? value2 : new Color32((byte)0, (byte)0, (byte)0, (byte)0));
int num = (15 - i) * 16 + j;
array[num] = val;
byte b = (byte)Mathf.RoundToInt(0.3f * (float)(int)val.r + 0.59f * (float)(int)val.g + 0.11f * (float)(int)val.b);
array2[num] = new Color32(b, b, b, (byte)((float)(int)val.a * 0.45f));
}
}
value = (Texture2D[])(object)new Texture2D[2]
{
NewTexture(16, 16, array, (FilterMode)0),
NewTexture(16, 16, array2, (FilterMode)0)
};
Icons[pixels] = value;
return value;
}
private static void BuildStyles(Metrics m)
{
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Expected O, but got Unknown
//IL_0105: Expected O, but got Unknown
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Expected O, but got Unknown
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Expected O, but got Unknown
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: 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_019f: Expected O, but got Unknown
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
if (_builtFor != Screen.height || _buttonStyle == null || !((Object)(object)_buttonTexture != (Object)null) || !((Object)(object)_dotTexture != (Object)null))
{
_builtFor = Screen.height;
int num = Mathf.Max(2, Mathf.RoundToInt(6f * m.Unit));
Destroy(_buttonTexture);
Destroy(_hoverTexture);
Destroy(_openTexture);
Destroy(_dotTexture);
_buttonTexture = RoundedBox(num, ButtonFill, ButtonEdge);
_hoverTexture = RoundedBox(num, HoverFill, HoverEdge);
_openTexture = RoundedBox(num, OpenFill, OpenEdge);
int num2 = Mathf.Max(2, Mathf.RoundToInt(3f * m.Unit));
_dotTexture = RoundedBox(num2, DotFill, DotEdge, 2 * num2);
int num3 = num + 1;
_buttonStyle = new GUIStyle
{
border = new RectOffset(num3, num3, num3, num3)
};
_tipStyle = new GUIStyle
{
border = new RectOffset(num3, num3, num3, num3),
padding = new RectOffset(Mathf.RoundToInt(10f * m.Unit), Mathf.RoundToInt(10f * m.Unit), Mathf.RoundToInt(6f * m.Unit), Mathf.RoundToInt(6f * m.Unit)),
fontSize = Mathf.Max(8, Mathf.RoundToInt(15f * m.Unit)),
alignment = (TextAnchor)3,
wordWrap = false,
richText = false
};
_tipStyle.normal.background = _hoverTexture;
_tipStyle.normal.textColor = Color.white;
}
}
private static Texture2D RoundedBox(int radius, Color32 fill, Color32 edge, int size = 0)
{
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: 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)
if (size <= 0)
{
size = 2 * radius + 4;
}
Color32[] array = (Color32[])(object)new Color32[size * size];
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
float num = (float)j + 0.5f;
float num2 = (float)i + 0.5f;
float num3 = Mathf.Max(Mathf.Max((float)radius - num, num - (float)(size - radius)), 0f);
float num4 = Mathf.Max(Mathf.Max((float)radius - num2, num2 - (float)(size - radius)), 0f);
float num5 = Mathf.Sqrt(num3 * num3 + num4 * num4) - (float)radius;
float num6 = Mathf.Clamp01(0.5f - num5);
Color val = Color.Lerp(Color32.op_Implicit(fill), Color32.op_Implicit(edge), Mathf.Clamp01(num5 + 1.5f));
val.a *= num6;
array[i * size + j] = Color32.op_Implicit(val);
}
}
return NewTexture(size, size, array, (FilterMode)1);
}
private static Texture2D NewTexture(int width, int height, Color32[] pixels, FilterMode filter)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
Texture2D val = new Texture2D(width, height, (TextureFormat)4, false)
{
filterMode = filter,
wrapMode = (TextureWrapMode)1,
hideFlags = (HideFlags)61
};
val.SetPixels32(pixels);
val.Apply(false, true);
return val;
}
private static void Destroy(Texture2D texture)
{
if ((Object)(object)texture != (Object)null)
{
Object.Destroy((Object)(object)texture);
}
}
}
}
namespace PhotoMode
{
internal static class Icon
{
public static readonly string[] Pixels = new string[16]
{
"................", "................", ".....KKKKKK.....", "....KDDDDDDK....", ".KKKKKKKKKKKKKK.", "KGGGGKKKKKGGGGGK", "KGGGKLLLLLKGRRGK", "KGGKLWWLLLLKGGGK", "KDDKLWLLLLLKDDDK", "KDDKLLLLLLLKDDDK",
"KDDKLLLLLLUKDDDK", "KGGGKLLLUUKGGGGK", "KGGGGKKKKKGGGGGK", ".KKKKKKKKKKKKKK.", "................", "................"
};
}
[HarmonyPatch(typeof(TaskManager), "IsCancelInputs")]
internal static class CancelInputsPatch
{
private static void Postfix(ref bool __result)
{
if (PhotoModeController.IsActive)
{
__result = true;
}
}
}
[HarmonyPatch(typeof(InputManager), "Update")]
internal static class EnterKeyPatch
{
private static readonly Action<InputManager, bool> SetEnterKeyDown = Setter("EnterKeyDown");
private static readonly Action<InputManager, bool> SetEnterKeyUp = Setter("EnterKeyUp");
private static void Postfix(InputManager __instance)
{
if (PhotoModeController.IsActive && !PhotoModeController.ChatShown)
{
SetEnterKeyDown(__instance, arg2: false);
SetEnterKeyUp(__instance, arg2: false);
}
}
private static Action<InputManager, bool> Setter(string property)
{
return (Action<InputManager, bool>)Delegate.CreateDelegate(typeof(Action<InputManager, bool>), AccessTools.PropertySetter(typeof(InputManager), property));
}
}
[HarmonyPatch(typeof(PlayerMovementController), "SetScreenCameraRotation")]
internal static class PlayerCameraPatch
{
private static bool Prefix()
{
return !PhotoModeController.IsActive;
}
}
internal sealed class PhotoModeController : MonoBehaviour
{
private const float RefreshInterval = 0.5f;
private const float ZoomStepDegrees = 3f;
private const float MinFov = 10f;
private const float MaxFov = 100f;
private readonly UiHider _ui = new UiHider();
private Camera _camera;
private CinemachineBrain _brain;
private bool _brainWasEnabled;
private Transform _player;
private Vector3 _startPosition;
private Quaternion _startRotation;
private float _startFov;
private float _yaw;
private float _pitch;
private TMP_InputField _chatField;
private bool _typingLastFrame;
private bool _restoreSelectAll;
private bool _looking;
private bool _iconClicked;
private bool _capturing;
private bool _exitRequested;
private bool _showHelp;
private float _refreshTimer;
private string _toastText;
private float _toastUntil;
private volatile string _saveResult;
private string _lastPhotoStamp;
private int _photoStampCount;
private GUIStyle _panelStyle;
internal static bool IsActive { get; private set; }
internal static bool ChatShown { get; private set; }
private static Settings S => Plugin.Settings;
private void Update()
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
string saveResult = _saveResult;
if (saveResult != null)
{
_saveResult = null;
Toast(saveResult);
}
bool iconClicked = _iconClicked;
_iconClicked = false;
if (!IsActive)
{
if (Input.GetKeyDown(S.ToggleKey.Value) || iconClicked)
{
TryEnter();
}
return;
}
if ((Object)(object)_camera == (Object)null)
{
Exit();
return;
}
_refreshTimer -= Time.unscaledDeltaTime;
if (_refreshTimer <= 0f)
{
_refreshTimer = 0.5f;
_ui.Refresh();
}
if (IsTyping() || _typingLastFrame)
{
if (Input.GetKeyDown((KeyCode)27))
{
StopTyping();
}
return;
}
if (Input.GetKeyDown(S.ToggleKey.Value) || Input.GetKeyDown((KeyCode)27))
{
_exitRequested = true;
return;
}
if (Input.GetKeyDown(S.ResetKey.Value))
{
_camera.fieldOfView = _startFov;
SetCamera(_startPosition, _startRotation);
}
if (Input.GetKeyDown(S.NameTagsKey.Value))
{
_ui.SetNameTagsHidden(!_ui.NameTagsHidden);
Toast(_ui.NameTagsHidden ? "Name tags hidden" : "Name tags shown");
}
if (Input.GetKeyDown(S.ChatKey.Value))
{
SetChatShown(!_ui.ChatShown, quiet: false);
}
if (Input.GetKeyDown(S.HelpKey.Value))
{
_showHelp = !_showHelp;
}
if (Input.GetKeyDown(S.CaptureKey.Value) && !_capturing)
{
((MonoBehaviour)this).StartCoroutine(Capture());
}
}
private void LateUpdate()
{
if (!IsActive)
{
return;
}
if (_exitRequested || (Object)(object)_camera == (Object)null)
{
Exit();
return;
}
IconBar.HideRow();
ClickToType();
bool flag = (_typingLastFrame = IsTyping());
float unscaledDeltaTime = Time.unscaledDeltaTime;
UpdateLook();
if (!flag)
{
UpdateMove(unscaledDeltaTime);
}
UpdateZoom();
}
private bool IsTyping()
{
if ((Object)(object)_chatField == (Object)null)
{
return false;
}
if (_chatField.isFocused)
{
return true;
}
EventSystem current = EventSystem.current;
if ((Object)(object)current != (Object)null)
{
return (Object)(object)current.currentSelectedGameObject == (Object)(object)((Component)_chatField).gameObject;
}
return false;
}
private void StopTyping()
{
EventSystem current = EventSystem.current;
if ((Object)(object)current != (Object)null && (Object)(object)_chatField != (Object)null && (Object)(object)current.currentSelectedGameObject == (Object)(object)((Component)_chatField).gameObject)
{
current.SetSelectedGameObject((GameObject)null);
}
TaskManager i = MonoSingleton<TaskManager>.I;
if ((Object)(object)i != (Object)null && i.IsWriting)
{
i.OnWritingDeactive();
}
}
private void ClickToType()
{
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Expected O, but got Unknown
if (_restoreSelectAll && ((Object)(object)_chatField == (Object)null || _chatField.isFocused || !IsTyping()))
{
if ((Object)(object)_chatField != (Object)null)
{
_chatField.onFocusSelectAll = true;
}
_restoreSelectAll = false;
}
if (!_ui.ChatShown || (Object)(object)_chatField == (Object)null || !Input.GetMouseButtonDown(0) || !((Component)_chatField).gameObject.activeInHierarchy || _chatField.isFocused)
{
return;
}
Canvas componentInParent = ((Component)_chatField).GetComponentInParent<Canvas>();
Canvas val = (((Object)(object)componentInParent != (Object)null) ? componentInParent.rootCanvas : null);
Camera val2 = (((Object)(object)val == (Object)null || (int)val.renderMode == 0) ? null : val.worldCamera);
if (RectTransformUtility.RectangleContainsScreenPoint((RectTransform)((Component)_chatField).transform, Vector2.op_Implicit(Input.mousePosition), val2))
{
if (_typingLastFrame && _chatField.onFocusSelectAll)
{
_chatField.onFocusSelectAll = false;
_restoreSelectAll = true;
}
((Selectable)_chatField).Select();
}
}
private void OnDestroy()
{
if (IsActive)
{
Exit();
}
}
private void TryEnter()
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: 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_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
TextChannelManager i = NetworkSingleton<TextChannelManager>.I;
if ((Object)(object)i == (Object)null || (Object)(object)i.MainPlayer == (Object)null || (Object)(object)MonoSingleton<MainSceneManager>.I == (Object)null)
{
return;
}
TaskManager i2 = MonoSingleton<TaskManager>.I;
if ((Object)(object)i2 != (Object)null && i2.IsWriting)
{
return;
}
OverlayManager i3 = MonoSingleton<OverlayManager>.I;
if ((Object)(object)i3 != (Object)null && (int)i3.ResolutionMode != 0)
{
Toast("Photo mode only works in the normal window mode.");
return;
}
SwanManager i4 = NetworkSingleton<SwanManager>.I;
if ((Object)(object)i4 != (Object)null && i4.IsPlayerOnSwan())
{
Toast("Photo mode isn't available on the swan.");
return;
}
SettingsController i5 = MonoSingleton<SettingsController>.I;
if ((Object)(object)i5 != (Object)null && (Object)(object)i5.GetCanvas != (Object)null && ((Behaviour)i5.GetCanvas).enabled)
{
Toast("Close the settings menu first.");
return;
}
Camera main = Camera.main;
if ((Object)(object)main == (Object)null)
{
Plugin.Log.LogWarning((object)"No main camera found, so photo mode can't start.");
return;
}
_camera = main;
_player = i.MainPlayer;
UIManager i6 = MonoSingleton<UIManager>.I;
_chatField = (((Object)(object)i6 != (Object)null) ? i6.MessageInputField : null);
_typingLastFrame = false;
_brain = ((Component)main).GetComponent<CinemachineBrain>();
_brainWasEnabled = (Object)(object)_brain != (Object)null && ((Behaviour)_brain).enabled;
if ((Object)(object)_brain != (Object)null)
{
((Behaviour)_brain).enabled = false;
}
else
{
Plugin.Log.LogWarning((object)"Main camera has no CinemachineBrain. The game may fight the free camera.");
}
_startPosition = ((Component)main).transform.position;
_startRotation = ((Component)main).transform.rotation;
_startFov = main.fieldOfView;
SetCamera(_startPosition, _startRotation);
_showHelp = S.ShowHelp.Value;
_exitRequested = false;
_refreshTimer = 0.5f;
IsActive = true;
_ui.Hide(S.HideNameTags.Value);
if (S.ShowChat.Value)
{
SetChatShown(shown: true, quiet: true);
}
Plugin.Log.LogInfo((object)"Photo mode on.");
}
private void SetChatShown(bool shown, bool quiet)
{
UIManager i = MonoSingleton<UIManager>.I;
if (shown && (Object)(object)i != (Object)null && i.IsMessagePanelHidden)
{
if (!quiet)
{
Toast("Chat is minimised. Open it in the game first, then start photo mode.");
}
return;
}
if (!shown && IsTyping())
{
StopTyping();
}
if (!_ui.SetChatShown(shown))
{
Toast("Couldn't find the chat box. See the BepInEx log.");
return;
}
ChatShown = _ui.ChatShown;
if (!quiet)
{
Toast(shown ? "Chat shown" : "Chat hidden");
}
}
private void Exit()
{
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
IsActive = false;
ChatShown = false;
_exitRequested = false;
_ui.RestoreAll();
if (_restoreSelectAll && (Object)(object)_chatField != (Object)null)
{
_chatField.onFocusSelectAll = true;
}
_restoreSelectAll = false;
_typingLastFrame = false;
_chatField = null;
if ((Object)(object)_camera != (Object)null)
{
((Component)_camera).transform.SetPositionAndRotation(_startPosition, _startRotation);
_camera.fieldOfView = _startFov;
}
if ((Object)(object)_brain != (Object)null)
{
((Behaviour)_brain).enabled = _brainWasEnabled;
}
StopLooking();
_camera = null;
_brain = null;
_player = null;
Plugin.Log.LogInfo((object)"Photo mode off.");
}
private void UpdateLook()
{
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
bool mouseButton = Input.GetMouseButton(1);
if (mouseButton && !_looking)
{
_looking = true;
Cursor.lockState = (CursorLockMode)1;
Cursor.visible = false;
}
else if (!mouseButton && _looking)
{
StopLooking();
}
if (_looking)
{
float num = S.LookSensitivity.Value * (_camera.fieldOfView / 60f);
_yaw += Input.GetAxisRaw("Mouse X") * num;
_pitch -= Input.GetAxisRaw("Mouse Y") * num;
_pitch = Mathf.Clamp(_pitch, -89f, 89f);
}
((Component)_camera).transform.rotation = Quaternion.Euler(_pitch, _yaw, 0f);
}
private void StopLooking()
{
_looking = false;
Cursor.lockState = (CursorLockMode)0;
Cursor.visible = true;
}
private void UpdateMove(float dt)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: 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_0163: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: 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_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: 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_01cf: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
Vector3 zero = Vector3.zero;
if (Input.GetKey((KeyCode)119))
{
zero.z += 1f;
}
if (Input.GetKey((KeyCode)115))
{
zero.z -= 1f;
}
if (Input.GetKey((KeyCode)100))
{
zero.x += 1f;
}
if (Input.GetKey((KeyCode)97))
{
zero.x -= 1f;
}
if (Input.GetKey((KeyCode)101))
{
zero.y += 1f;
}
if (Input.GetKey((KeyCode)113))
{
zero.y -= 1f;
}
if (zero == Vector3.zero)
{
return;
}
float num = S.MoveSpeed.Value;
if (Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303))
{
num *= S.FastMultiplier.Value;
}
if (Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305))
{
num *= S.SlowMultiplier.Value;
}
Transform transform = ((Component)_camera).transform;
Vector3 val = transform.forward * zero.z + transform.right * zero.x + Vector3.up * zero.y;
Vector3 val2 = transform.position + Vector3.ClampMagnitude(val, 1f) * num * dt;
float value = S.MaxDistance.Value;
if (value > 0f && (Object)(object)_player != (Object)null)
{
Vector3 val3 = val2 - _player.position;
if (((Vector3)(ref val3)).magnitude > value)
{
val2 = _player.position + ((Vector3)(ref val3)).normalized * value;
}
}
transform.position = val2;
}
private void UpdateZoom()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
float y = Input.mouseScrollDelta.y;
if (Mathf.Abs(y) > 0.01f && !_camera.orthographic)
{
_camera.fieldOfView = Mathf.Clamp(_camera.fieldOfView - y * 3f, 10f, 100f);
}
}
private void SetCamera(Vector3 position, Quaternion rotation)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: 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)
((Component)_camera).transform.SetPositionAndRotation(position, rotation);
Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles;
_yaw = eulerAngles.y;
_pitch = Mathf.Clamp((eulerAngles.x > 180f) ? (eulerAngles.x - 360f) : eulerAngles.x, -89f, 89f);
}
private IEnumerator Capture()
{
_capturing = true;
PanelStack.HideForCapture();
_ui.Refresh();
yield return (object)new WaitForEndOfFrame();
Texture2D val = null;
try
{
val = ScreenCapture.CaptureScreenshotAsTexture(Mathf.Clamp(S.ResolutionMultiplier.Value, 1, 4));
int width = ((Texture)val).width;
int height = ((Texture)val).height;
Color32[] pixels = val.GetPixels32();
string path = NextPhotoPath();
Task.Run(delegate
{
SavePhoto(path, pixels, width, height);
});
PlayShutter();
}
catch (Exception arg)
{
Plugin.Log.LogError((object)$"Couldn't take a photo: {arg}");
Toast("Couldn't take the photo. See the BepInEx log.");
}
finally
{
if ((Object)(object)val != (Object)null)
{
Object.Destroy((Object)(object)val);
}
_capturing = false;
}
}
private void SavePhoto(string path, Color32[] pixels, int width, int height)
{
try
{
byte[] array = new byte[pixels.Length * 3];
int num = 0;
int num2 = 0;
while (num < pixels.Length)
{
array[num2] = pixels[num].r;
array[num2 + 1] = pixels[num].g;
array[num2 + 2] = pixels[num].b;
num++;
num2 += 3;
}
byte[] bytes = ImageConversion.EncodeArrayToPNG((Array)array, (GraphicsFormat)3, (uint)width, (uint)height, 0u);
File.WriteAllBytes(path, bytes);
Plugin.Log.LogInfo((object)$"Saved {width}x{height} photo to {path}");
_saveResult = "Saved " + Path.GetFileName(path);
}
catch (Exception arg)
{
Plugin.Log.LogError((object)$"Couldn't save photo to {path}: {arg}");
_saveResult = "Couldn't save the photo. See the BepInEx log.";
}
}
private string NextPhotoPath()
{
string text = PhotoFolder();
Directory.CreateDirectory(text);
string text2 = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
_photoStampCount = ((!(text2 == _lastPhotoStamp)) ? 1 : (_photoStampCount + 1));
_lastPhotoStamp = text2;
string text4;
while (true)
{
string text3 = ((_photoStampCount > 1) ? $"_{_photoStampCount}" : "");
text4 = Path.Combine(text, "OnTogether_" + text2 + text3 + ".png");
if (!File.Exists(text4))
{
break;
}
_photoStampCount++;
}
return text4;
}
private static string PhotoFolder()
{
string text = S.SaveFolder.Value?.Trim();
if (!string.IsNullOrEmpty(text))
{
return Environment.ExpandEnvironmentVariables(text);
}
string text2 = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
if (string.IsNullOrEmpty(text2))
{
text2 = Application.persistentDataPath;
}
return Path.Combine(text2, "On-Together");
}
private static void PlayShutter()
{
if (S.ShutterSound.Value)
{
SFXManager i = MonoSingleton<SFXManager>.I;
if ((Object)(object)i != (Object)null)
{
i.PlayUIClick();
}
}
}
private void Toast(string text)
{
_toastText = text;
_toastUntil = Time.unscaledTime + 3f;
}
private void OnGUI()
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Expected O, but got Unknown
//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: 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_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Expected O, but got Unknown
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
if (S.ShowIcon.Value && IconBar.Draw("PhotoMode", 0, Icon.Pixels, IconBar.State.Plain, "Photo Mode", S.ToggleKey.Value) == IconBar.Click.Left)
{
_iconClicked = true;
}
if (_capturing || PanelStack.Hidden)
{
return;
}
bool flag = IsActive && _showHelp;
bool flag2 = _toastText != null && Time.unscaledTime < _toastUntil;
if (flag || flag2)
{
if (_panelStyle == null)
{
_panelStyle = PanelStack.MakeStyle((TextAnchor)0);
}
float width;
Matrix4x4 previous = PanelStack.Begin(out width);
if (flag)
{
string text = "<b>PHOTO MODE</b>\nHold right mouse: look WASD: move Q / E: down / up\nShift: faster Ctrl: slower Scroll: zoom\n" + $"{S.CaptureKey.Value}: take photo {S.NameTagsKey.Value}: name tags " + $"{S.ChatKey.Value}: chat {S.ResetKey.Value}: reset camera\n" + (_ui.ChatShown ? "Enter or click the chat box: type Esc: stop typing\n" : "") + $"{S.HelpKey.Value}: hide this panel {S.ToggleKey.Value} or Esc: exit";
Vector2 size = _panelStyle.CalcSize(new GUIContent(text));
GUI.Box(PanelStack.Place("PhotoMode", 0, size), text, _panelStyle);
}
if (flag2)
{
Vector2 val = _panelStyle.CalcSize(new GUIContent(_toastText));
GUI.Box(new Rect((width - val.x) / 2f, 40f, val.x, val.y), _toastText, _panelStyle);
}
PanelStack.End(previous);
}
}
}
[BepInPlugin("nelphei.ontogether.photomode", "Photo Mode", "0.4.1")]
public class Plugin : BaseUnityPlugin
{
public const string PluginGuid = "nelphei.ontogether.photomode";
public const string PluginName = "Photo Mode";
public const string PluginVersion = "0.4.1";
internal static ManualLogSource Log;
internal static Settings Settings;
private GameObject _host;
private void Awake()
{
//IL_0020: 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_003f: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
Settings = new Settings(((BaseUnityPlugin)this).Config);
new Harmony("nelphei.ontogether.photomode").PatchAll();
IconBar.Patch();
_host = new GameObject("PhotoMode");
((Object)_host).hideFlags = (HideFlags)61;
Object.DontDestroyOnLoad((Object)(object)_host);
_host.AddComponent<PhotoModeController>();
Log.LogInfo((object)string.Format("{0} {1} loaded. Press {2} in a lobby to start.", "Photo Mode", "0.4.1", Settings.ToggleKey.Value));
}
private void OnDestroy()
{
if ((Object)(object)_host != (Object)null)
{
Object.Destroy((Object)(object)_host);
}
}
}
internal sealed class Settings
{
public readonly ConfigEntry<KeyCode> ToggleKey;
public readonly ConfigEntry<KeyCode> CaptureKey;
public readonly ConfigEntry<KeyCode> NameTagsKey;
public readonly ConfigEntry<KeyCode> ChatKey;
public readonly ConfigEntry<KeyCode> ResetKey;
public readonly ConfigEntry<KeyCode> HelpKey;
public readonly ConfigEntry<float> MoveSpeed;
public readonly ConfigEntry<float> FastMultiplier;
public readonly ConfigEntry<float> SlowMultiplier;
public readonly ConfigEntry<float> LookSensitivity;
public readonly ConfigEntry<float> MaxDistance;
public readonly ConfigEntry<bool> HideNameTags;
public readonly ConfigEntry<bool> ShowChat;
public readonly ConfigEntry<bool> ShowHelp;
public readonly ConfigEntry<bool> ShutterSound;
public readonly ConfigEntry<int> ResolutionMultiplier;
public readonly ConfigEntry<string> SaveFolder;
public readonly ConfigEntry<bool> ShowIcon;
public Settings(ConfigFile config)
{
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Expected O, but got Unknown
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Expected O, but got Unknown
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Expected O, but got Unknown
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Expected O, but got Unknown
//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Expected O, but got Unknown
//IL_0265: Unknown result type (might be due to invalid IL or missing references)
//IL_026f: Expected O, but got Unknown
ToggleKey = config.Bind<KeyCode>("Keys", "ToggleKey", (KeyCode)290, "Turns photo mode on and off. Escape also turns it off.");
CaptureKey = config.Bind<KeyCode>("Keys", "CaptureKey", (KeyCode)112, "Takes a photo. Only works while photo mode is on.");
NameTagsKey = config.Bind<KeyCode>("Keys", "NameTagsKey", (KeyCode)104, "Shows or hides name tags and chat bubbles while photo mode is on.");
ChatKey = config.Bind<KeyCode>("Keys", "ChatKey", (KeyCode)116, "Shows or hides the chat box while photo mode is on. While it's showing, press Enter or click the chat box to type, and Esc to stop typing. Photo mode keys pause while you type.");
ResetKey = config.Bind<KeyCode>("Keys", "ResetKey", (KeyCode)114, "Moves the camera back to where photo mode started.");
HelpKey = config.Bind<KeyCode>("Keys", "HelpKey", (KeyCode)282, "Shows or hides the controls panel while photo mode is on.");
MoveSpeed = config.Bind<float>("Camera", "MoveSpeed", 3f, new ConfigDescription("Camera speed in metres per second. For comparison, players walk at 4.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 50f), Array.Empty<object>()));
FastMultiplier = config.Bind<float>("Camera", "FastMultiplier", 3f, new ConfigDescription("Speed multiplier while holding Shift.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 20f), Array.Empty<object>()));
SlowMultiplier = config.Bind<float>("Camera", "SlowMultiplier", 0.25f, new ConfigDescription("Speed multiplier while holding Ctrl.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 1f), Array.Empty<object>()));
LookSensitivity = config.Bind<float>("Camera", "LookSensitivity", 2f, new ConfigDescription("How fast the camera turns when you hold the right mouse button.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 20f), Array.Empty<object>()));
MaxDistance = config.Bind<float>("Camera", "MaxDistance", 30f, new ConfigDescription("How far the camera can fly from your character, in metres. 0 means no limit.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>()));
HideNameTags = config.Bind<bool>("Photos", "HideNameTagsByDefault", true, "Hide name tags and chat bubbles when photo mode starts. Toggle with NameTagsKey.");
ShowChat = config.Bind<bool>("Photos", "ShowChatByDefault", false, "Keep the chat box visible when photo mode starts. Toggle with ChatKey. When shown, it appears in photos too.");
ShowHelp = config.Bind<bool>("Photos", "ShowHelpByDefault", true, "Show the controls panel when photo mode starts. It is never included in photos.");
ShutterSound = config.Bind<bool>("Photos", "ShutterSound", true, "Play a click when a photo is saved. Only you hear it.");
ResolutionMultiplier = config.Bind<int>("Photos", "ResolutionMultiplier", 1, new ConfigDescription("Saves photos at this multiple of your screen resolution. 2 on a 1080p screen gives 4K photos.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 4), Array.Empty<object>()));
SaveFolder = config.Bind<string>("Photos", "SaveFolder", "", "Folder for photos. Leave empty to use Pictures\\On-Together.");
ShowIcon = config.Bind<bool>("Display", "ShowIcon", true, "Show a camera icon in the row of mod icons at the bottom-right. Clicking it does what ToggleKey does, and right-clicking it while photo mode is on does what HelpKey does. It's never in photos.");
}
}
internal sealed class UiHider
{
private static readonly FieldRef<TextBubbleController, Canvas> BubbleCanvas = AccessTools.FieldRefAccess<TextBubbleController, Canvas>("_textBubbleCanvas");
private static readonly string[] ChatFields = new string[8] { "_messagePanelParent", "_messagePanel", "_messagePanelTransform", "_messageInputField", "_globalPanel", "_localPanel", "_globalMessagePanel", "_localMessagePanel" };
private readonly List<Canvas> _hiddenScreenCanvases = new List<Canvas>();
private readonly List<Canvas> _hiddenBubbleCanvases = new List<Canvas>();
private readonly List<Canvas> _chatCanvases = new List<Canvas>();
private readonly List<Canvas> _blockers = new List<Canvas>();
private readonly List<GraphicRaycaster> _disabledRaycasters = new List<GraphicRaycaster>();
private readonly List<Transform> _chatRoots = new List<Transform>();
private readonly HashSet<Transform> _chatPath = new HashSet<Transform>();
public bool NameTagsHidden { get; private set; }
public bool ChatShown { get; private set; }
public void Hide(bool hideNameTags)
{
NameTagsHidden = hideNameTags;
Refresh();
}
public void Refresh()
{
HideScreenCanvases();
if (NameTagsHidden)
{
HideBubbleCanvases();
}
if (ChatShown)
{
HideAllButChat();
}
}
public void SetNameTagsHidden(bool hidden)
{
NameTagsHidden = hidden;
if (hidden)
{
HideBubbleCanvases();
}
else
{
Restore(_hiddenBubbleCanvases);
}
}
public bool SetChatShown(bool shown)
{
if (shown == ChatShown)
{
return true;
}
if (shown)
{
if (!FindChat())
{
return false;
}
ChatShown = true;
for (int num = _hiddenScreenCanvases.Count - 1; num >= 0; num--)
{
Canvas val = _hiddenScreenCanvases[num];
if ((Object)(object)val != (Object)null && IsChat(((Component)val).transform))
{
((Behaviour)val).enabled = true;
_chatCanvases.Add(val);
_hiddenScreenCanvases.RemoveAt(num);
DisableRaycaster(val);
}
}
HideAllButChat();
}
else
{
ChatShown = false;
StopShowingChat();
foreach (Canvas chatCanvase in _chatCanvases)
{
if ((Object)(object)chatCanvase != (Object)null && ((Behaviour)chatCanvase).enabled)
{
((Behaviour)chatCanvase).enabled = false;
_hiddenScreenCanvases.Add(chatCanvase);
}
}
_chatCanvases.Clear();
HideScreenCanvases();
}
return true;
}
public void RestoreAll()
{
ChatShown = false;
StopShowingChat();
_chatCanvases.Clear();
Restore(_hiddenScreenCanvases);
Restore(_hiddenBubbleCanvases);
}
private void HideScreenCanvases()
{
Canvas[] array = Object.FindObjectsByType<Canvas>((FindObjectsInactive)1, (FindObjectsSortMode)0);
foreach (Canvas val in array)
{
if (((Behaviour)val).enabled && !IsInWorld(val) && !PanelStack.IsModCanvas(val) && (!ChatShown || !IsChat(((Component)val).transform)))
{
((Behaviour)val).enabled = false;
_hiddenScreenCanvases.Add(val);
}
}
}
private void HideBubbleCanvases()
{
TextBubbleController[] array = Object.FindObjectsByType<TextBubbleController>((FindObjectsInactive)1, (FindObjectsSortMode)0);
foreach (TextBubbleController val in array)
{
Canvas val2 = BubbleCanvas.Invoke(val);
if (!((Object)(object)val2 == (Object)null) && ((Behaviour)val2).enabled)
{
((Behaviour)val2).enabled = false;
_hiddenBubbleCanvases.Add(val2);
}
}
}
private bool FindChat()
{
_chatRoots.Clear();
_chatPath.Clear();
UIManager i = MonoSingleton<UIManager>.I;
if ((Object)(object)i == (Object)null)
{
return false;
}
string[] chatFields = ChatFields;
foreach (string text in chatFields)
{
Transform val = AsTransform(AccessTools.Field(typeof(UIManager), text)?.GetValue(i));
if ((Object)(object)val == (Object)null)
{
Plugin.Log.LogWarning((object)("Couldn't find UIManager." + text + ". The game may have changed its chat box."));
continue;
}
_chatRoots.Add(val);
Transform val2 = val;
while ((Object)(object)val2 != (Object)null)
{
_chatPath.Add(val2);
val2 = val2.parent;
}
}
return _chatRoots.Count > 0;
}
private void HideAllButChat()
{
foreach (Transform chatRoot in _chatRoots)
{
Canvas val = (((Object)(object)chatRoot != (Object)null) ? OutermostCanvas(chatRoot) : null);
if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).transform == (Object)(object)chatRoot)
{
continue;
}
Transform transform = ((Component)val).transform;
Transform parent = chatRoot.parent;
while ((Object)(object)parent != (Object)null)
{
if (!IsInsideChat(parent))
{
HideNonChatChildren(parent);
}
if ((Object)(object)parent == (Object)(object)transform)
{
break;
}
parent = parent.parent;
}
}
}
private void HideNonChatChildren(Transform node)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Expected O, but got Unknown
foreach (Transform item in node)
{
Transform val = item;
if (!_chatPath.Contains(val) && val is RectTransform && !((Object)(object)((Component)val).GetComponent<Canvas>() != (Object)null))
{
Canvas val2 = ((Component)val).gameObject.AddComponent<Canvas>();
if ((Object)(object)val2 != (Object)null)
{
((Behaviour)val2).enabled = false;
_blockers.Add(val2);
}
}
}
}
private void DisableRaycaster(Canvas canvas)
{
GraphicRaycaster component = ((Component)canvas).GetComponent<GraphicRaycaster>();
if ((Object)(object)component != (Object)null && ((Behaviour)component).enabled)
{
((Behaviour)component).enabled = false;
_disabledRaycasters.Add(component);
}
}
private void StopShowingChat()
{
foreach (Canvas blocker in _blockers)
{
if ((Object)(object)blocker != (Object)null)
{
Object.Destroy((Object)(object)blocker);
}
}
_blockers.Clear();
foreach (GraphicRaycaster disabledRaycaster in _disabledRaycasters)
{
if ((Object)(object)disabledRaycaster != (Object)null)
{
((Behaviour)disabledRaycaster).enabled = true;
}
}
_disabledRaycasters.Clear();
_chatRoots.Clear();
_chatPath.Clear();
}
private bool IsChat(Transform t)
{
if (!_chatPath.Contains(t))
{
return IsInsideChat(t);
}
return true;
}
private bool IsInsideChat(Transform t)
{
foreach (Transform chatRoot in _chatRoots)
{
if ((Object)(object)chatRoot != (Object)null && t.IsChildOf(chatRoot))
{
return true;
}
}
return false;
}
private static Transform AsTransform(object value)
{
GameObject val = (GameObject)((value is GameObject) ? value : null);
if (val != null && (Object)(object)val != (Object)null)
{
return val.transform;
}
Component val2 = (Component)((value is Component) ? value : null);
if (val2 != null && (Object)(object)val2 != (Object)null)
{
return val2.transform;
}
return null;
}
private static void Restore(List<Canvas> canvases)
{
foreach (Canvas canvase in canvases)
{
if ((Object)(object)canvase != (Object)null)
{
((Behaviour)canvase).enabled = true;
}
}
canvases.Clear();
}
private static bool IsInWorld(Canvas canvas)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Invalid comparison between Unknown and I4
Canvas val = OutermostCanvas(((Component)canvas).transform);
if ((Object)(object)val != (Object)null)
{
return (int)val.renderMode == 2;
}
return false;
}
private static Canvas OutermostCanvas(Transform t)
{
Canvas[] componentsInParent = ((Component)t).GetComponentsInParent<Canvas>(true);
if (componentsInParent.Length == 0)
{
return null;
}
return componentsInParent[^1];
}
}
}