using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using SmolMods.Core;
using TMPro;
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("smolMods.DarkMenus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e90a00273091d71235f09886429f05ccd89d5c5b")]
[assembly: AssemblyProduct("smolMods.DarkMenus")]
[assembly: AssemblyTitle("smolMods.DarkMenus")]
[assembly: AssemblyVersion("1.0.0.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 SmolMods.DarkMenus
{
internal static class FadeStripKiller
{
private sealed class Victim
{
public GameObject go;
}
private static readonly List<Victim> Killed = new List<Victim>();
private static readonly Vector3[] Corners = (Vector3[])(object)new Vector3[4];
private static float _next;
internal static void Tick(bool themeOn)
{
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Expected O, but got Unknown
if (Time.unscaledTime < _next)
{
return;
}
_next = Time.unscaledTime + 1f;
if (!themeOn)
{
Restore();
return;
}
Il2CppArrayBase<Canvas> val = Object.FindObjectsOfType<Canvas>();
if (val == null)
{
return;
}
List<Graphic> list = new List<Graphic>();
foreach (Canvas item in val)
{
try
{
if (!((Object)(object)item == (Object)null) && ((Behaviour)item).isActiveAndEnabled)
{
Il2CppArrayBase<Graphic> componentsInChildren = ((Component)item).GetComponentsInChildren<Graphic>(false);
if (componentsInChildren != null)
{
list.AddRange((IEnumerable<Graphic>)componentsInChildren);
}
}
}
catch
{
}
}
_ = list.Count;
int num = 0;
int num2 = 0;
bool flag2 = default(bool);
foreach (Graphic item2 in list)
{
try
{
if ((Object)(object)item2 == (Object)null || (Object)(object)((Il2CppObjectBase)item2).TryCast<TMP_Text>() != (Object)null || (Object)(object)((Il2CppObjectBase)item2).TryCast<Text>() != (Object)null || !ScreenRect(item2, out var w, out var h, out var yMin, out var yMax))
{
continue;
}
bool num3 = w >= (float)Screen.width * 0.4f;
if (num3)
{
num++;
}
if (!num3 || h < (float)Screen.height * 0.02f || h > (float)Screen.height * 0.35f)
{
continue;
}
bool num4 = yMin >= (float)Screen.height * 0.6f;
bool flag = yMax <= (float)Screen.height * 0.4f;
if ((!num4 && !flag) || !((Component)item2).gameObject.activeInHierarchy)
{
continue;
}
GameObject gameObject = ((Component)item2).gameObject;
Killed.Add(new Victim
{
go = gameObject
});
ManualLogSource log = ModSettingsApi.Log;
if (log != null)
{
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(35, 3, ref flag2);
if (flag2)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Dark menus: hid fade strip '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(Path(gameObject.transform));
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' w=");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(w, "F0");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" h=");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(h, "F0");
}
log.LogInfo(val2);
}
gameObject.SetActive(false);
}
catch
{
num2++;
}
}
}
private static bool ScreenRect(Graphic g, out float w, out float h, out float yMin, out float yMax)
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: 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_009f: 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_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_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_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_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
w = (h = (yMin = (yMax = 0f)));
try
{
RectTransform rectTransform = g.rectTransform;
if ((Object)(object)rectTransform == (Object)null)
{
return false;
}
Canvas canvas = g.canvas;
Camera val = null;
if ((Object)(object)canvas != (Object)null && (int)canvas.renderMode != 0)
{
val = canvas.worldCamera;
}
rectTransform.GetWorldCorners(Il2CppStructArray<Vector3>.op_Implicit(Corners));
Vector2 val2 = default(Vector2);
((Vector2)(ref val2))..ctor(float.MaxValue, float.MaxValue);
Vector2 val3 = default(Vector2);
((Vector2)(ref val3))..ctor(float.MinValue, float.MinValue);
for (int i = 0; i < 4; i++)
{
Vector2 val4 = RectTransformUtility.WorldToScreenPoint(val, Corners[i]);
val2 = Vector2.Min(val2, val4);
val3 = Vector2.Max(val3, val4);
}
w = val3.x - val2.x;
h = val3.y - val2.y;
yMin = val2.y;
yMax = val3.y;
return true;
}
catch
{
return false;
}
}
private static void Restore()
{
if (Killed.Count == 0)
{
return;
}
foreach (Victim item in Killed)
{
try
{
if ((Object)(object)item.go != (Object)null)
{
item.go.SetActive(true);
}
}
catch
{
}
}
Killed.Clear();
}
private static bool InMainMenu()
{
try
{
return (Object)(object)WorldManager.localPlayerCharacter == (Object)null;
}
catch
{
return false;
}
}
private static string CanvasMode(Graphic g)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
try
{
return ((Object)(object)g.canvas != (Object)null) ? ((object)g.canvas.renderMode/*cast due to .constrained prefix*/).ToString() : "(none)";
}
catch
{
return "(?)";
}
}
private static string Path(Transform t)
{
try
{
List<string> list = new List<string>();
int num = 0;
while ((Object)(object)t != (Object)null && num++ < 8)
{
list.Insert(0, ((Object)t).name);
t = t.parent;
}
return string.Join("/", list);
}
catch
{
return "(?)";
}
}
}
internal static class MenuTheme
{
private static readonly Color DarkPaper = new Color(0.11f, 0.11f, 0.13f);
private static readonly Color LightInk = new Color(0.93f, 0.93f, 0.9f);
private static readonly Dictionary<int, (Graphic g, Color original)> Known = new Dictionary<int, (Graphic, Color)>();
private static readonly List<Transform> Panels = new List<Transform>();
private static Transform _mainMenuPanel;
private static GameObject _backdrop;
private static GameObject _passwordBackdrop;
private static int _passwordBackdropGoId;
private static readonly Dictionary<int, bool> OwnershipSkip = new Dictionary<int, bool>();
private static int _colorRootsVersion = -1;
private const float DarkPaperAlpha = 0.31f;
private static readonly Vector3[] CornerBuffer = (Vector3[])(object)new Vector3[4];
internal static void TrackMenu(Transform menuTransform)
{
AddPanel(PanelRootOf(menuTransform));
}
private static void AddPanel(Transform panel)
{
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
if ((Object)(object)panel == (Object)null)
{
return;
}
for (int num = Panels.Count - 1; num >= 0; num--)
{
if ((Object)(object)Panels[num] == (Object)null)
{
Panels.RemoveAt(num);
}
}
foreach (Transform panel2 in Panels)
{
if ((Object)(object)panel2 == (Object)(object)panel)
{
return;
}
}
Panels.Add(panel);
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(25, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[theme] tracking panel '");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)panel).name);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
}
logger.LogInfo(val);
}
private static void TrackMainMenu()
{
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Expected O, but got Unknown
try
{
if ((Object)(object)_mainMenuPanel != (Object)null)
{
return;
}
MainMenuManager val = null;
try
{
val = MainMenuManager.instance;
}
catch
{
}
if ((Object)(object)val == (Object)null)
{
return;
}
Transform val2 = null;
try
{
if ((Object)(object)val.titleMenu != (Object)null)
{
val2 = ((Component)val.titleMenu).transform;
}
}
catch
{
}
if ((Object)(object)val2 == (Object)null)
{
try
{
if ((Object)(object)val.settingsMenu != (Object)null)
{
val2 = ((Component)val.settingsMenu).transform;
}
}
catch
{
}
}
if (!((Object)(object)val2 == (Object)null))
{
Canvas componentInParent = ((Component)val2).GetComponentInParent<Canvas>();
if (!((Object)(object)componentInParent == (Object)null))
{
AddPanel(_mainMenuPanel = (((Object)(object)componentInParent.rootCanvas != (Object)null) ? ((Component)componentInParent.rootCanvas).transform : ((Component)componentInParent).transform));
}
}
}
catch (Exception ex)
{
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(30, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[theme] TrackMainMenu failed: ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val3);
}
}
private static void EnsureBackdrop(bool enabled)
{
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Expected O, but got Unknown
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: 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)
//IL_0076: 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_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Expected O, but got Unknown
try
{
if ((Object)(object)_mainMenuPanel == (Object)null)
{
_backdrop = null;
return;
}
if (!enabled)
{
if ((Object)(object)_backdrop != (Object)null && _backdrop.activeSelf)
{
_backdrop.SetActive(false);
}
return;
}
if ((Object)(object)_backdrop == (Object)null)
{
GameObject val = new GameObject("BigDarkMenusBackdrop");
val.transform.SetParent(_mainMenuPanel, false);
RectTransform obj = val.AddComponent<RectTransform>();
obj.anchorMin = Vector2.zero;
obj.anchorMax = Vector2.one;
obj.offsetMin = Vector2.zero;
obj.offsetMax = Vector2.zero;
Image obj2 = val.AddComponent<Image>();
((Graphic)obj2).color = new Color(DarkPaper.r, DarkPaper.g, DarkPaper.b, 1f);
((Graphic)obj2).raycastTarget = false;
_backdrop = val;
Plugin.Logger.LogInfo((object)"[theme] main menu backdrop created");
}
if (_backdrop.transform.GetSiblingIndex() != 0)
{
_backdrop.transform.SetSiblingIndex(0);
}
if (!_backdrop.activeSelf)
{
_backdrop.SetActive(true);
}
}
catch (Exception ex)
{
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(25, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[theme] backdrop failed: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val2);
_backdrop = null;
}
}
private static void EnsurePasswordBackdrop(bool enabled)
{
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Expected O, but got Unknown
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: 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_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Expected O, but got Unknown
try
{
if ((Object)(object)_passwordBackdrop == (Object)null)
{
_passwordBackdropGoId = 0;
if (!enabled)
{
return;
}
MainMenuManager val = null;
try
{
val = MainMenuManager.instance;
}
catch
{
}
if ((Object)(object)val == (Object)null || (Object)(object)val.passwordMenu == (Object)null)
{
return;
}
Transform val2 = PanelRootOf(((Component)val.passwordMenu).transform);
if ((Object)(object)val2 == (Object)null)
{
return;
}
GameObject val3 = new GameObject("SmolModsPasswordBackdrop");
val3.transform.SetParent(val2, false);
RectTransform obj2 = val3.AddComponent<RectTransform>();
obj2.anchorMin = Vector2.zero;
obj2.anchorMax = Vector2.one;
obj2.offsetMin = Vector2.zero;
obj2.offsetMax = Vector2.zero;
Image obj3 = val3.AddComponent<Image>();
((Graphic)obj3).color = new Color(DarkPaper.r, DarkPaper.g, DarkPaper.b, 1f);
((Graphic)obj3).raycastTarget = false;
val3.transform.SetSiblingIndex(0);
_passwordBackdrop = val3;
_passwordBackdropGoId = ((Object)val3).GetInstanceID();
Plugin.Logger.LogInfo((object)"[theme] password prompt backdrop created");
}
if (_passwordBackdrop.activeSelf != enabled)
{
_passwordBackdrop.SetActive(enabled);
}
}
catch (Exception ex)
{
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val4 = new BepInExWarningLogInterpolatedStringHandler(34, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("[theme] password backdrop failed: ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val4);
_passwordBackdrop = null;
_passwordBackdropGoId = 0;
}
}
private static Transform PanelRootOf(Transform t)
{
if ((Object)(object)t == (Object)null)
{
return null;
}
Canvas componentInParent = ((Component)t).GetComponentInParent<Canvas>();
if ((Object)(object)componentInParent == (Object)null)
{
return t;
}
Transform val = (((Object)(object)componentInParent.rootCanvas != (Object)null) ? ((Component)componentInParent.rootCanvas).transform : ((Component)componentInParent).transform);
Transform val2 = t;
while ((Object)(object)val2.parent != (Object)null && (Object)(object)val2.parent != (Object)(object)val)
{
val2 = val2.parent;
}
return val2;
}
internal static void Apply(bool enabled, bool force = true)
{
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Expected O, but got Unknown
TrackMainMenu();
EnsureBackdrop(enabled);
EnsurePasswordBackdrop(enabled);
if (!enabled)
{
if (Known.Count > 0)
{
RestoreForgotten();
Known.Clear();
OwnershipSkip.Clear();
}
return;
}
bool flag = default(bool);
for (int num = Panels.Count - 1; num >= 0; num--)
{
Transform val = Panels[num];
if ((Object)(object)val == (Object)null)
{
Panels.RemoveAt(num);
}
else
{
try
{
if (force || ((Component)val).gameObject.activeInHierarchy)
{
ApplyToPanel(val, enabled);
}
}
catch (Exception ex)
{
ManualLogSource logger = Plugin.Logger;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(27, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[theme] panel pass failed: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val2);
}
}
}
}
internal static bool IsInTrackedPanel(Transform t)
{
if ((Object)(object)t == (Object)null)
{
return false;
}
foreach (Transform panel in Panels)
{
if (!((Object)(object)panel == (Object)null) && ((Object)(object)t == (Object)(object)panel || t.IsChildOf(panel)))
{
return true;
}
}
return false;
}
internal static void ApplyToSubtree(Transform root, bool enabled)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
if ((Object)(object)root == (Object)null)
{
return;
}
try
{
ApplyToPanel(root, enabled);
}
catch (Exception ex)
{
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(29, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[theme] subtree pass failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val);
}
}
private static void ApplyToPanel(Transform panel, bool enabled)
{
//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: 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_01fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_0225: Unknown result type (might be due to invalid IL or missing references)
//IL_0229: Unknown result type (might be due to invalid IL or missing references)
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_0219: Unknown result type (might be due to invalid IL or missing references)
//IL_022e: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: 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_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0234: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_0257: Unknown result type (might be due to invalid IL or missing references)
//IL_025c: Unknown result type (might be due to invalid IL or missing references)
//IL_024a: Unknown result type (might be due to invalid IL or missing references)
//IL_0266: Unknown result type (might be due to invalid IL or missing references)
bool flag = (Object)(object)_mainMenuPanel != (Object)null && (Object)(object)panel == (Object)(object)_mainMenuPanel;
if (_colorRootsVersion != ModSettingsApi.ColorRootsVersion)
{
_colorRootsVersion = ModSettingsApi.ColorRootsVersion;
OwnershipSkip.Clear();
}
foreach (Graphic componentsInChild in ((Component)panel).GetComponentsInChildren<Graphic>(true))
{
if ((Object)(object)componentsInChild == (Object)null)
{
continue;
}
int instanceID = ((Object)componentsInChild).GetInstanceID();
if (OwnershipSkip.TryGetValue(instanceID, out var value))
{
if (value)
{
Known.Remove(instanceID);
continue;
}
}
else
{
value = HudTintApi.IsHudOwned(componentsInChild) || ModSettingsApi.IsColorManaged(((Component)componentsInChild).transform);
OwnershipSkip[instanceID] = value;
if (value)
{
Known.Remove(instanceID);
continue;
}
}
if (Plugin.IsCursorOwned(componentsInChild))
{
continue;
}
int instanceID2 = ((Object)((Component)componentsInChild).gameObject).GetInstanceID();
if (((Object)(object)_backdrop != (Object)null && instanceID2 == ((Object)_backdrop).GetInstanceID()) || (_passwordBackdropGoId != 0 && instanceID2 == _passwordBackdropGoId))
{
continue;
}
if (flag && IsWideFadeStrip(componentsInChild))
{
if (!Known.ContainsKey(instanceID))
{
Known[instanceID] = (componentsInChild, componentsInChild.color);
}
(Graphic, Color) value2;
if (enabled)
{
if (componentsInChild.color.a > 0.001f)
{
Color color = componentsInChild.color;
componentsInChild.color = new Color(color.r, color.g, color.b, 0f);
}
}
else if (Known.TryGetValue(instanceID, out value2) && !Approximately(componentsInChild.color, value2.Item2))
{
componentsInChild.color = value2.Item2;
}
continue;
}
Color val;
bool flag2;
if (Known.TryGetValue(instanceID, out (Graphic, Color) value3))
{
val = value3.Item2;
flag2 = true;
}
else
{
val = componentsInChild.color;
if (Saturation(val) >= 0.32f || val.a < 0.05f)
{
continue;
}
if (!IsLogoLettering(componentsInChild))
{
val = RecoverOriginal(val);
}
flag2 = false;
}
Color val2 = (enabled ? Invert(val, flag, componentsInChild) : val);
if (flag2 || !Approximately(val, val2))
{
if (!flag2)
{
Known[instanceID] = (componentsInChild, val);
}
if (!Approximately(componentsInChild.color, val2))
{
componentsInChild.color = val2;
}
}
}
}
private static void RestoreForgotten()
{
//IL_0041: 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_0061: Unknown result type (might be due to invalid IL or missing references)
List<int> list = new List<int>();
foreach (KeyValuePair<int, (Graphic, Color)> item2 in Known)
{
Graphic item = item2.Value.Item1;
if ((Object)(object)item == (Object)null)
{
list.Add(item2.Key);
}
else if (!Approximately(item.color, item2.Value.Item2))
{
item.color = item2.Value.Item2;
}
}
foreach (int item3 in list)
{
Known.Remove(item3);
}
}
private static Color RecoverOriginal(Color c)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: 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_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
if (IsThemeColor(c, DarkPaper))
{
return new Color(1f, 1f, 1f, c.a);
}
if (IsThemeColor(c, LightInk))
{
return new Color(0.09f, 0.09f, 0.09f, c.a);
}
return c;
}
private static bool IsThemeColor(Color c, Color theme)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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_0032: 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)
if (Mathf.Abs(c.r - theme.r) < 0.02f && Mathf.Abs(c.g - theme.g) < 0.02f)
{
return Mathf.Abs(c.b - theme.b) < 0.02f;
}
return false;
}
private static Color Invert(Color c, bool isMainMenu, Graphic g)
{
//IL_0000: 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_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: 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_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
if (Luminance(c) > 0.5f)
{
if (isMainMenu)
{
if (!CoversMostOfScreen(g))
{
return c;
}
return new Color(DarkPaper.r, DarkPaper.g, DarkPaper.b, c.a);
}
return new Color(DarkPaper.r, DarkPaper.g, DarkPaper.b, c.a * 0.31f);
}
return new Color(LightInk.r, LightInk.g, LightInk.b, c.a);
}
private static bool IsLogoLettering(Graphic g)
{
try
{
Image val = ((Il2CppObjectBase)g).TryCast<Image>();
return (Object)(object)val != (Object)null && (Object)(object)val.sprite != (Object)null && ((Object)val.sprite).name == "BigWalkLogo";
}
catch
{
return false;
}
}
private static bool CoversMostOfScreen(Graphic g)
{
try
{
RectTransform component = ((Component)g).GetComponent<RectTransform>();
if ((Object)(object)component == (Object)null)
{
return false;
}
component.GetWorldCorners(Il2CppStructArray<Vector3>.op_Implicit(CornerBuffer));
float num = CornerBuffer[2].x - CornerBuffer[0].x;
float num2 = CornerBuffer[2].y - CornerBuffer[0].y;
return num >= (float)Screen.width * 0.6f && num2 >= (float)Screen.height * 0.6f;
}
catch
{
return false;
}
}
private static bool IsWideFadeStrip(Graphic g)
{
try
{
RectTransform component = ((Component)g).GetComponent<RectTransform>();
if ((Object)(object)component == (Object)null)
{
return false;
}
component.GetWorldCorners(Il2CppStructArray<Vector3>.op_Implicit(CornerBuffer));
float num = CornerBuffer[2].x - CornerBuffer[0].x;
float num2 = CornerBuffer[2].y - CornerBuffer[0].y;
if (num < (float)Screen.width * 0.4f || num2 < (float)Screen.height * 0.03f || num2 > (float)Screen.height * 0.35f)
{
return false;
}
bool num3 = CornerBuffer[0].y >= (float)Screen.height * 0.65f;
bool flag = CornerBuffer[2].y <= (float)Screen.height * 0.35f;
return num3 || flag;
}
catch
{
return false;
}
}
private static bool Approximately(Color a, Color b)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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_0032: 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_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
if (Mathf.Abs(a.r - b.r) < 0.004f && Mathf.Abs(a.g - b.g) < 0.004f && Mathf.Abs(a.b - b.b) < 0.004f)
{
return Mathf.Abs(a.a - b.a) < 0.004f;
}
return false;
}
internal static float Luminance(Color c)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: 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)
return 0.299f * c.r + 0.587f * c.g + 0.114f * c.b;
}
internal static float Saturation(Color c)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: 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)
float num = Mathf.Max(c.r, Mathf.Max(c.g, c.b));
float num2 = Mathf.Min(c.r, Mathf.Min(c.g, c.b));
if (!(num <= 0.0001f))
{
return (num - num2) / num;
}
return 0f;
}
}
[BepInPlugin("com.smolmods.darkmenus", "smolMods.DarkMenus", "1.0.11")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
public const string PluginGuid = "com.smolmods.darkmenus";
public const string PluginName = "smolMods.DarkMenus";
public const string PluginVersion = "1.0.11";
internal static ManualLogSource Logger;
internal static ModRowDef MenuRow;
private static readonly Dictionary<int, (Graphic g, Color c)> CursorGraphics = new Dictionary<int, (Graphic, Color)>();
private static readonly List<Shadow> CursorShadows = new List<Shadow>();
private static NmouseObject[] _nmice;
internal static bool MenusEnabled
{
get
{
if (MenuRow != null)
{
return MenuRow.Value == 1;
}
return false;
}
}
public override void Load()
{
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Expected O, but got Unknown
//IL_00cd: 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_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
//IL_0085: 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_012b: Expected O, but got Unknown
Logger = ((BasePlugin)this).Log;
MenuRow = ModSettingsApi.AddArrayRow(400, "Dark menus", "settings_mod_darkMenus", 1, new int[2] { 0, 1 }, (Func<int, string>)((int v) => (v != 1) ? "Off" : "On"), (Action<int>)delegate(int v)
{
MenuTheme.Apply(v == 1);
ModSettingsApi.RefreshRows();
}, (Func<int, Color?>)null, false, false);
bool flag = default(bool);
try
{
ClassInjector.RegisterTypeInIl2Cpp<ThemeTicker>();
GameObject val = new GameObject("SmolModsDarkMenusTicker");
Object.DontDestroyOnLoad((Object)val);
((Object)val).hideFlags = (HideFlags)61;
val.AddComponent<ThemeTicker>();
}
catch (Exception ex)
{
ManualLogSource logger = Logger;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(26, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Theme ticker unavailable: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val2);
}
Harmony val3 = new Harmony("com.smolmods.darkmenus");
val3.PatchAll(typeof(Plugin).Assembly);
int num = 0;
foreach (MethodBase patchedMethod in val3.GetPatchedMethods())
{
_ = patchedMethod;
num++;
}
ManualLogSource logger2 = Logger;
BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(27, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>("smolMods.DarkMenus");
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>("1.0.11");
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" loaded, ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(num);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" methods patched.");
}
logger2.LogInfo(val4);
}
internal static bool IsCursorOwned(Graphic g)
{
return CursorGraphics.ContainsKey(((Object)g).GetInstanceID());
}
internal static void ApplyCursor(bool enabled)
{
//IL_0269: Unknown result type (might be due to invalid IL or missing references)
//IL_0270: Expected O, but got Unknown
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
//IL_0218: Unknown result type (might be due to invalid IL or missing references)
//IL_0192: Unknown result type (might be due to invalid IL or missing references)
//IL_0226: 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_01f3: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!enabled)
{
foreach (var value in CursorGraphics.Values)
{
try
{
if ((Object)(object)value.g != (Object)null)
{
value.g.color = value.c;
}
}
catch
{
}
}
CursorGraphics.Clear();
foreach (Shadow cursorShadow in CursorShadows)
{
try
{
if ((Object)(object)cursorShadow != (Object)null)
{
((Behaviour)cursorShadow).enabled = false;
}
}
catch
{
}
}
CursorShadows.Clear();
_nmice = null;
return;
}
bool flag = _nmice == null || _nmice.Length == 0;
NmouseObject[] nmice;
if (!flag)
{
nmice = _nmice;
for (int i = 0; i < nmice.Length; i++)
{
if ((Object)(object)nmice[i] == (Object)null)
{
flag = true;
break;
}
}
}
if (flag)
{
_nmice = Il2CppArrayBase<NmouseObject>.op_Implicit(Object.FindObjectsOfType<NmouseObject>(true));
}
nmice = _nmice;
foreach (NmouseObject val in nmice)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
GameObject cursor = val.cursor;
if ((Object)(object)cursor == (Object)null)
{
continue;
}
foreach (Graphic componentsInChild in cursor.GetComponentsInChildren<Graphic>(true))
{
int instanceID = ((Object)componentsInChild).GetInstanceID();
if (!CursorGraphics.ContainsKey(instanceID))
{
CursorGraphics[instanceID] = (componentsInChild, componentsInChild.color);
Shadow val2 = ((Component)componentsInChild).gameObject.GetComponent<Shadow>();
if ((Object)(object)val2 == (Object)null)
{
val2 = ((Component)componentsInChild).gameObject.AddComponent<Shadow>();
}
val2.effectColor = new Color(0f, 0f, 0f, 0.65f);
val2.effectDistance = new Vector2(3f, -3f);
((Behaviour)val2).enabled = true;
CursorShadows.Add(val2);
}
if (componentsInChild.color != Color.white)
{
componentsInChild.color = Color.white;
}
}
}
}
catch (Exception ex)
{
ManualLogSource logger = Logger;
bool flag2 = default(bool);
BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(24, 1, ref flag2);
if (flag2)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Cursor recolour failed: ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val3);
}
}
}
public class ThemeTicker : MonoBehaviour
{
private float _next;
public ThemeTicker(IntPtr ptr)
: base(ptr)
{
}
private void Update()
{
if (Time.unscaledTime < _next)
{
return;
}
_next = Time.unscaledTime + 0.2f;
try
{
MenuTheme.Apply(Plugin.MenusEnabled, force: false);
}
catch
{
}
try
{
Plugin.ApplyCursor(Plugin.MenusEnabled);
}
catch
{
}
try
{
FadeStripKiller.Tick(Plugin.MenusEnabled);
}
catch
{
}
}
}
[HarmonyPatch]
internal static class MenuPatches
{
[HarmonyPostfix]
[HarmonyPatch(typeof(SettingsMenu), "OnEnable")]
private static void SettingsMenu_OnEnable(SettingsMenu __instance)
{
if (!__instance.isInMainMenu)
{
MenuTheme.TrackMenu(((Component)__instance).transform);
}
MenuTheme.Apply(Plugin.MenusEnabled);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(SettingsMenu), "PressCatagoryButton")]
private static void SettingsMenu_PressCatagory()
{
MenuTheme.Apply(Plugin.MenusEnabled);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(SettingsMenu), "SwapToCatagory")]
private static void SettingsMenu_SwapCatagory()
{
MenuTheme.Apply(Plugin.MenusEnabled);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(SettingsRow), "Refresh")]
private static void SettingsRow_Refresh(SettingsRow __instance)
{
if (Plugin.MenusEnabled && MenuTheme.IsInTrackedPanel(((Component)__instance).transform))
{
MenuTheme.ApplyToSubtree(((Component)__instance).transform, enabled: true);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(WorldMenuManager), "OpenMenu")]
private static void WorldMenu_OpenMenu(WorldMenuManager __instance)
{
if ((Object)(object)__instance.settingsMenu != (Object)null)
{
MenuTheme.TrackMenu(((Component)__instance.settingsMenu).transform);
}
if ((Object)(object)__instance.pauseMenuForCurrentMode != (Object)null)
{
MenuTheme.TrackMenu(((Component)__instance.pauseMenuForCurrentMode).transform);
}
MenuTheme.Apply(Plugin.MenusEnabled);
}
}
}