using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer;
using UnityExplorer.CSConsole;
using UnityExplorer.CacheObject;
using UnityExplorer.CacheObject.Views;
using UnityExplorer.UI;
using UnityExplorer.UI.Widgets;
using UnityExplorerAddons.API;
using UnityExplorerAddons.Modules;
using UniverseLib;
using UniverseLib.UI;
using UniverseLib.UI.Models;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("UnityExplorerAddons")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0")]
[assembly: AssemblyInformationalVersion("0.1.0+git068d82f-dirty-main.068d82fc47b73ca1bf48100cb8c2a211b364f620")]
[assembly: AssemblyProduct("UnityExplorerAddons")]
[assembly: AssemblyTitle("UnityExplorerAddons")]
[assembly: TargetPlatform("Windows7.0")]
[assembly: SupportedOSPlatform("Windows7.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace UnityExplorerAddons
{
public class CSConsoleExtension : ScriptInteraction
{
public static void Watch(StaticExpressionDelegate del)
{
WatchAPI.Watch(del);
}
public static void Watch<T>(T instance, ExpressionWatcherDelegate<T> del)
{
WatchAPI.Watch(instance, del);
}
public static void Watch<T>(object instance, ExpressionWatcherDelegate<T> del)
{
WatchAPI.Watch(instance, del);
}
}
[BepInPlugin("JarheadHME.UnityExplorerAddons", "UnityExplorerAddons", "0.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class EntryPoint : BasePlugin
{
private Harmony _Harmony = null;
public override void Load()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Expected O, but got Unknown
_Harmony = new Harmony("UnityExplorerAddons.Harmony");
_Harmony.PatchAll();
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(32, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin has loaded with ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_Harmony.GetPatchedMethods().Count());
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" patches!");
}
Logger.Info(val);
ClassInjector.RegisterTypeInIl2Cpp<ValueWatcher>();
GameObject val2 = new GameObject("ValueWatcher");
Object.DontDestroyOnLoad((Object)(object)val2);
((Object)val2).hideFlags = (HideFlags)61;
val2.AddComponent<ValueWatcher>();
}
public override bool Unload()
{
_Harmony.UnpatchSelf();
return ((BasePlugin)this).Unload();
}
}
internal static class Logger
{
private static readonly ManualLogSource _Logger;
static Logger()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
_Logger = new ManualLogSource("UnityExplorerAddons");
Logger.Sources.Add((ILogSource)(object)_Logger);
}
private static string Format(object msg)
{
return msg.ToString();
}
public static void Info(BepInExInfoLogInterpolatedStringHandler handler)
{
_Logger.LogInfo(handler);
}
public static void Info(string str)
{
_Logger.LogMessage((object)str);
}
public static void Info(object data)
{
_Logger.LogMessage((object)Format(data));
}
public static void Debug(BepInExDebugLogInterpolatedStringHandler handler)
{
_Logger.LogDebug(handler);
}
public static void Debug(string str)
{
_Logger.LogDebug((object)str);
}
public static void Debug(object data)
{
_Logger.LogDebug((object)Format(data));
}
public static void Error(BepInExErrorLogInterpolatedStringHandler handler)
{
_Logger.LogError(handler);
}
public static void Error(string str)
{
_Logger.LogError((object)str);
}
public static void Error(object data)
{
_Logger.LogError((object)Format(data));
}
public static void Fatal(BepInExFatalLogInterpolatedStringHandler handler)
{
_Logger.LogFatal(handler);
}
public static void Fatal(string str)
{
_Logger.LogFatal((object)str);
}
public static void Fatal(object data)
{
_Logger.LogFatal((object)Format(data));
}
public static void Warn(BepInExWarningLogInterpolatedStringHandler handler)
{
_Logger.LogWarning(handler);
}
public static void Warn(string str)
{
_Logger.LogWarning((object)str);
}
public static void Warn(object data)
{
_Logger.LogWarning((object)Format(data));
}
[Conditional("DEBUG")]
public static void DebugOnly(object data)
{
_Logger.LogDebug((object)Format(data));
}
}
[GeneratedCode("VersionInfoGenerator", "2.1.3+git35c0c2a-master")]
[CompilerGenerated]
internal static class VersionInfo
{
public const string RootNamespace = "UnityExplorerAddons";
public const string Version = "0.1.0";
public const string VersionPrerelease = null;
public const string VersionMetadata = "git068d82f-dirty-main";
public const string SemVer = "0.1.0+git068d82f-dirty-main";
public const string GitRevShort = "068d82f-dirty";
public const string GitRevLong = "068d82fc47b73ca1bf48100cb8c2a211b364f620-dirty";
public const string GitBranch = "main";
public const string GitTag = null;
public const int GitCommitsSinceTag = 0;
public const bool GitIsDirty = true;
}
}
namespace UnityExplorerAddons.Patches
{
[HarmonyPatch]
internal class AddNavBarButtonPatch
{
private static ButtonRef WatchNavButton;
[HarmonyTargetMethod]
public static MethodBase GetTarget()
{
return AccessTools.Method(typeof(UIManager), "InitUI", (Type[])null, (Type[])null);
}
[HarmonyPostfix]
public static void AddWatchButton()
{
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
WatchNavButton = UIFactory.CreateButton(UIManager.NavbarTabButtonHolder, "WatchButton", "Watch", (Color?)null);
GameObject gameObject = ((Component)WatchNavButton.Component).gameObject;
gameObject.AddComponent<ContentSizeFitter>().horizontalFit = (FitMode)2;
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(gameObject, (bool?)false, (bool?)true, (bool?)true, (bool?)true, (int?)0, (int?)0, (int?)0, (int?)5, (int?)5, (TextAnchor?)(TextAnchor)4);
UIFactory.SetLayoutElement(gameObject, (int?)60, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (bool?)null);
RuntimeHelper.SetColorBlock((Selectable)(object)WatchNavButton.Component, (Color?)UniversalUI.DisabledButtonColor, (Color?)(UniversalUI.DisabledButtonColor * 1.2f), (Color?)null, (Color?)null);
ButtonRef watchNavButton = WatchNavButton;
watchNavButton.OnClick = (Action)Delegate.Combine(watchNavButton.OnClick, new Action(ToggleWatchWindow));
GameObject gameObject2 = ((Component)gameObject.transform.Find("Text")).gameObject;
gameObject2.AddComponent<ContentSizeFitter>().horizontalFit = (FitMode)2;
UIFactory.SetLayoutElement(((Component)UIManager.GetPanel((Panels)4).NavButton.Component).gameObject, (int?)40, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (bool?)null);
UIFactory.SetLayoutElement(((Component)UIManager.GetPanel((Panels)3).NavButton.Component).gameObject, (int?)70, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (bool?)null);
UIFactory.SetLayoutElement(((Component)UIManager.GetPanel((Panels)7).NavButton.Component).gameObject, (int?)60, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (bool?)null);
}
public static void ToggleWatchWindow()
{
//IL_001c: 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_0021: 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_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)
ValueWatcher.IsVisible = !ValueWatcher.IsVisible;
Color val = (ValueWatcher.IsVisible ? UniversalUI.EnabledButtonColor : UniversalUI.DisabledButtonColor);
RuntimeHelper.SetColorBlock((Selectable)(object)WatchNavButton.Component, (Color?)val, (Color?)(val * 1.2f), (Color?)null, (Color?)null);
}
}
[HarmonyPatch]
internal class AddToCSConsolePatch
{
[HarmonyPatch(typeof(ConsoleController), "ResetConsole", new Type[] { typeof(bool) })]
[HarmonyPostfix]
public static void ChangeConsoleBaseClass()
{
ScriptEvaluator evaluator = ConsoleController.Evaluator;
AccessTools.PropertySetter(typeof(ScriptEvaluator), "InteractiveBaseClass").Invoke(evaluator, new object[1] { typeof(CSConsoleExtension) });
}
}
[HarmonyPatch]
internal class WatchButtonSetupPatch
{
[HarmonyPatch(typeof(CacheObjectCell), "CreateContent")]
[HarmonyPostfix]
public static void AddWatchButton(CacheObjectCell __instance)
{
//IL_00a3: 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)
ButtonRef copyButton = __instance.CopyButton;
GameObject gameObject = ((Component)((Transform)copyButton.Transform).parent).gameObject;
UIFactory.SetLayoutElement(gameObject, (int?)30, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (bool?)null);
ButtonRef val = UIFactory.CreateButton(((Component)((Transform)copyButton.Transform).parent).gameObject, "WatchButton", "Watch", (Color?)new Color(0.13f, 0.13f, 0.13f, 1f));
GameObject gameObject2 = ((Component)val.Component).gameObject;
int? num = 25;
UIFactory.SetLayoutElement(gameObject2, (int?)33, num, (int?)0, (int?)null, (int?)null, (int?)null, (bool?)null);
((Graphic)val.ButtonText).color = Color.cyan;
val.ButtonText.fontSize = 10;
val.OnClick = (Action)Delegate.Combine(val.OnClick, (Action)delegate
{
CacheObjectCell obj = __instance;
if (!(((obj != null) ? obj.Occupant : null) is CacheMember))
{
ExplorerCore.LogWarning((object)"Cell that wanted to be watched doesn't have a Member to watch???");
}
else
{
object[] array = null;
if (__instance.Occupant is CacheMethod)
{
CacheObjectBase occupant = __instance.Occupant;
CacheMethod val2 = (CacheMethod)(object)((occupant is CacheMethod) ? occupant : null);
EvaluateWidget evaluator = ((CacheMember)val2).Evaluator;
array = ((evaluator != null) ? evaluator.TryParseArguments() : null);
if (((CacheObjectBase)val2).HasArguments && (array == null || array.Length == 0))
{
ExplorerCore.LogWarning((object)("Method " + ((CacheMember)val2).NameForFiltering + " requires arguments, and none have been placed."));
return;
}
}
List<(CacheMember, object[])> simpleWatches = ValueWatcher.SimpleWatches;
CacheObjectBase occupant2 = __instance.Occupant;
simpleWatches.Add(((CacheMember)(object)((occupant2 is CacheMember) ? occupant2 : null), array));
}
});
}
}
}
namespace UnityExplorerAddons.Modules
{
internal class ExpressionHolder<T> : IExpressionHolder
{
internal readonly T obj;
internal readonly ExpressionWatcherDelegate<T> func;
internal ExpressionHolder(ExpressionWatcherDelegate<T> func, T obj = default(T))
{
this.obj = obj;
this.func = func;
}
public object GetObject()
{
return obj;
}
public string Invoke()
{
return func(obj);
}
}
internal interface IExpressionHolder
{
object GetObject();
string Invoke();
}
internal class StaticExpressionHolder : IExpressionHolder
{
internal StaticExpressionDelegate func;
public StaticExpressionHolder(StaticExpressionDelegate func)
{
this.func = func;
}
public object GetObject()
{
return null;
}
public string Invoke()
{
return func();
}
}
internal class ValueWatcher : MonoBehaviour
{
public static readonly List<(CacheMember, object[])> SimpleWatches = new List<(CacheMember, object[])>();
public static readonly List<IExpressionHolder> ExpressionWatches = new List<IExpressionHolder>();
private static readonly List<int> m_simpleToRemove = new List<int>();
private static readonly List<int> m_expToRemove = new List<int>();
public int ScreenWidth = 1920;
public int ScreenHeight = 1080;
public int Width = 400;
public int Height = 720;
public static int LineDifference = 22;
public static bool IsVisible = false;
public static bool IsUniExpUIActive => UIManager.ShowMenu;
public void Awake()
{
ScreenWidth = Screen.width;
ScreenHeight = Screen.height;
Width = ScreenWidth / 4;
Height = (int)((double)ScreenHeight / 2.5);
}
public void OnGUI()
{
//IL_003d: 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_03b0: Unknown result type (might be due to invalid IL or missing references)
if (!IsVisible)
{
return;
}
int num = ScreenWidth - Width;
int num2 = ScreenHeight / 3;
GUI.Box(new Rect((float)num, (float)num2, (float)Width, (float)Height), "Watch List");
RemoveQueuedRemovals();
int num3 = 0;
int num4 = num2 + LineDifference + 10;
if (SimpleWatches.Count > 0)
{
GUI.Label(new Rect((float)(num + 5), (float)num4, (float)(Width - 10), (float)LineDifference), "Simple Watches");
num4 += LineDifference;
for (int i = 0; i < SimpleWatches.Count; i++)
{
(CacheMember, object[]) tuple = SimpleWatches[i];
CacheMember item = tuple.Item1;
Object val = null;
if (!item.IsStatic && item.DeclaringInstance.GetType().IsSubclassOf(typeof(Object)))
{
val = ReflectionExtensions.TryCast<Object>(item.DeclaringInstance);
if (val == (Object)null)
{
ExplorerCore.LogWarning((object)$"Object for Watch index {i} ({item.NameForFiltering}) destroyed");
m_simpleToRemove.Add(i);
continue;
}
}
string value;
if (item is CacheMethod)
{
CacheMethod val2 = (CacheMethod)(object)((item is CacheMethod) ? item : null);
try
{
value = val2.MethodInfo.Invoke(((CacheMember)val2).DeclaringInstance, tuple.Item2)?.ToString();
}
catch (Exception value2)
{
ExplorerCore.LogWarning((object)$"Simple watch (method) index {i} ({item.NameForFiltering}) errored, removing.\n{value2}");
m_simpleToRemove.Add(i);
continue;
}
}
else
{
item.Evaluate();
object value3 = ((CacheObjectBase)item).Value;
Object val3 = ((value3 != null) ? ReflectionExtensions.TryCast<Object>(value3) : null);
value = ((!(val3 != (Object)null)) ? ((CacheObjectBase)item).Value?.ToString() : (val3.name + " (" + ((CacheObjectBase)item).Value.ToString() + ")"));
}
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder2 = stringBuilder;
StringBuilder stringBuilder3 = stringBuilder2;
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(2, 2, stringBuilder2);
handler.AppendFormatted(item.NameForFiltering);
handler.AppendLiteral(": ");
handler.AppendFormatted(value);
stringBuilder3.Append(ref handler);
if (val != (Object)null)
{
stringBuilder2 = stringBuilder;
StringBuilder stringBuilder4 = stringBuilder2;
handler = new StringBuilder.AppendInterpolatedStringHandler(3, 1, stringBuilder2);
handler.AppendLiteral(" - ");
handler.AppendFormatted(val.name);
stringBuilder4.Append(ref handler);
}
CreateWatchEntry(num4, LineDifference, stringBuilder.ToString(), num3++, exp: false);
num4 += LineDifference;
}
num4 += LineDifference;
}
num3 = 0;
if (ExpressionWatches.Count <= 0)
{
return;
}
GUI.Label(new Rect((float)(num + 5), (float)num4, (float)(Width - 10), (float)LineDifference), "Expression Watches");
num4 += LineDifference;
for (int j = 0; j < ExpressionWatches.Count; j++)
{
IExpressionHolder expressionHolder = ExpressionWatches[j];
object @object = expressionHolder.GetObject();
if (@object != null && @object.GetType().IsSubclassOf(typeof(Object)) && ReflectionExtensions.TryCast<Object>(@object) == (Object)null)
{
ExplorerCore.LogWarning((object)$"Expression Watch index {j} instance is null");
m_expToRemove.Add(j);
continue;
}
try
{
string text = expressionHolder.Invoke();
int num5 = LineDifference * text.Split('\n').Length;
CreateWatchEntry(num4, num5, text, num3++, exp: true);
num4 += num5;
}
catch (Exception value4)
{
ExplorerCore.LogWarning((object)$"Exception occurred while evaluating Expression Watch index {j}, removing.\n{value4}");
m_expToRemove.Add(j);
}
}
}
private void RemoveQueuedRemovals()
{
for (int num = m_simpleToRemove.Count - 1; num >= 0; num--)
{
SimpleWatches.RemoveAt(m_simpleToRemove[num]);
}
m_simpleToRemove.Clear();
for (int num2 = m_expToRemove.Count - 1; num2 >= 0; num2--)
{
ExpressionWatches.RemoveAt(m_expToRemove[num2]);
}
m_expToRemove.Clear();
}
internal void CreateWatchEntry(int ypos, int height, string info, int index, bool exp)
{
//IL_001c: 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)
int num = ScreenWidth - Width;
GUI.Label(new Rect((float)(num + 5), (float)ypos, 2.1474836E+09f, (float)height), $"[{index}] {info}");
if (IsUniExpUIActive && GUI.Button(new Rect((float)(num - 25), (float)(ypos - 2), 22f, 22f), " X"))
{
if (exp)
{
m_expToRemove.Add(index);
}
else
{
m_simpleToRemove.Add(index);
}
}
}
}
}
namespace UnityExplorerAddons.API
{
public delegate string StaticExpressionDelegate();
public delegate string ExpressionWatcherDelegate<T>(T instance);
public static class WatchAPI
{
public static void Watch(StaticExpressionDelegate del)
{
StaticExpressionHolder item = new StaticExpressionHolder(del);
ValueWatcher.ExpressionWatches.Add(item);
}
public static void Watch<T>(T instance, ExpressionWatcherDelegate<T> del)
{
ExpressionHolder<T> item = new ExpressionHolder<T>(del, instance);
ValueWatcher.ExpressionWatches.Add(item);
}
public static void Watch<T>(object instance, ExpressionWatcherDelegate<T> del)
{
ExpressionHolder<T> item = new ExpressionHolder<T>(del, (T)instance);
ValueWatcher.ExpressionWatches.Add(item);
}
}
}