Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions RuntimeUnityEditor.Bepin5/LogViewer/LogViewerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ string GetTrimmedTypeName(ILogSource obj)
/// <inheritdoc />
protected override void DrawContents()
{
GUILayout.BeginHorizontal();
GUILayout.BeginHorizontal(IMGUIUtils.EmptyLayoutOptions);
{
GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthTrue);
{
Expand All @@ -141,11 +141,11 @@ protected override void DrawContents()
GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthFalse);
{
if (!Capture) GUI.color = Color.red;
Capture = GUILayout.Toggle(Capture, new GUIContent("Enable log capture", "Note: This can hurt performance, especially if there is log spam."));
Capture = GUILayout.Toggle(Capture, new GUIContent("Enable log capture", "Note: This can hurt performance, especially if there is log spam."), IMGUIUtils.EmptyLayoutOptions);
GUI.color = Color.white;
CaptureOnStartup = GUILayout.Toggle(CaptureOnStartup, new GUIContent("Enable on game startup", "Warning: This can hurt performance, especially after running for a while!"));
CaptureOnStartup = GUILayout.Toggle(CaptureOnStartup, new GUIContent("Enable on game startup", "Warning: This can hurt performance, especially after running for a while!"), IMGUIUtils.EmptyLayoutOptions);

if (GUILayout.Button("Clear the list"))
if (GUILayout.Button("Clear the list", IMGUIUtils.EmptyLayoutOptions))
{
_logEntries.Clear();
_filteredLogEntries.Clear();
Expand All @@ -155,16 +155,16 @@ protected override void DrawContents()
}
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.BeginHorizontal(IMGUIUtils.EmptyLayoutOptions);
{
GUILayout.BeginHorizontal(GUI.skin.box);
GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.EmptyLayoutOptions);
{
GUILayout.Label(new GUIContent("Captured log levels:", "Only new log messages with these levels will be captured, therefore enabling levels will not show past log messages!"));
GUILayout.Label(new GUIContent("Captured log levels:", "Only new log messages with these levels will be captured, therefore enabling levels will not show past log messages!"), IMGUIUtils.EmptyLayoutOptions);
var filter = LogLevelFilter;
foreach (var logLevel in new[] { LogLevel.Debug, LogLevel.Info, LogLevel.Message, LogLevel.Warning, LogLevel.Error, LogLevel.Fatal, LogLevel.All })
{
GUI.changed = false;
var result = GUILayout.Toggle((filter & logLevel) != 0, logLevel.ToString());
var result = GUILayout.Toggle((filter & logLevel) != 0, logLevel.ToString(), IMGUIUtils.EmptyLayoutOptions);
if (GUI.changed)
LogLevelFilter = result ? filter | logLevel : filter & ~logLevel;
}
Expand All @@ -173,18 +173,18 @@ protected override void DrawContents()

GUILayout.FlexibleSpace();

GUILayout.BeginHorizontal(GUI.skin.box);
GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.EmptyLayoutOptions);
{
if (GUILayout.Button("Sources")) Inspector.Instance.Push(new InstanceStackEntry(BepInEx.Logging.Logger.Sources, "Log Sources"), true);
if (GUILayout.Button("Listeners")) Inspector.Instance.Push(new InstanceStackEntry(BepInEx.Logging.Logger.Listeners, "Log Listeners"), true);
if (GUILayout.Button("Sources", IMGUIUtils.EmptyLayoutOptions)) Inspector.Instance.Push(new InstanceStackEntry(BepInEx.Logging.Logger.Sources, "Log Sources"), true);
if (GUILayout.Button("Listeners", IMGUIUtils.EmptyLayoutOptions)) Inspector.Instance.Push(new InstanceStackEntry(BepInEx.Logging.Logger.Listeners, "Log Listeners"), true);
}
GUILayout.EndHorizontal();
}
GUILayout.EndHorizontal();

var heightMeasured = _itemHeight != 0;

_scrollPosition = GUILayout.BeginScrollView(_scrollPosition, false, true);
_scrollPosition = GUILayout.BeginScrollView(_scrollPosition, false, true, IMGUIUtils.EmptyLayoutOptions);
{
var logEntries = _filteredLogEntries;

Expand All @@ -197,7 +197,7 @@ protected override void DrawContents()
for (var i = skipped; i < skipped + visible; i++)
{
var entry = logEntries[logEntries.Count - 1 - i];
GUILayout.BeginHorizontal(GUI.skin.box);
GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.EmptyLayoutOptions);
{
if (entry.DrawEntry())
{
Expand Down
24 changes: 12 additions & 12 deletions RuntimeUnityEditor.Bepin5/PatchInspector/ILViewerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ public ILViewerWindow(int windowId, MethodBase method, string originalIL, List<P

protected override void DrawContents()
{
if (GUILayout.Button(_headingGc, IMGUIUtils.UpperCenterLabelStyle))
if (GUILayout.Button(_headingGc, IMGUIUtils.UpperCenterLabelStyle, IMGUIUtils.EmptyLayoutOptions))
{
//if (IMGUIUtils.IsMouseRightClick())
ContextMenu.Instance.Show(_method);
}

GUILayout.BeginHorizontal();
GUILayout.BeginHorizontal(IMGUIUtils.EmptyLayoutOptions);
{
_patchesScrollPosition = GUILayout.BeginScrollView(_patchesScrollPosition, GUI.skin.box, GUILayoutShim.ExpandHeight(true), GUILayout.Width(400));
{
GUILayout.BeginVertical(GUI.skin.box);
GUILayout.BeginVertical(GUI.skin.box, IMGUIUtils.EmptyLayoutOptions);
{
var isSelected = _selectedPatchIndex == -1;
if (isSelected) GUI.color = Color.cyan;
Expand All @@ -80,7 +80,7 @@ protected override void DrawContents()
}
GUILayout.EndVertical();

GUILayout.BeginHorizontal();
GUILayout.BeginHorizontal(IMGUIUtils.EmptyLayoutOptions);
{
GUILayout.Label("Patches:", IMGUIUtils.LayoutOptionsExpandWidthTrue);

Expand All @@ -91,15 +91,15 @@ protected override void DrawContents()

if (_patchMethods.Count == 0)
{
GUILayout.Label("No patches found for this method.", IMGUIUtils.UpperCenterLabelStyle);
GUILayout.Label("No patches found for this method.", IMGUIUtils.UpperCenterLabelStyle, IMGUIUtils.EmptyLayoutOptions);
}
else
{
for (var i = 0; i < _patchMethods.Count; i++)
{
var patch = _patchMethods[i];

GUILayout.BeginHorizontal(GUI.skin.box);
GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.EmptyLayoutOptions);
{
var newEnabled = GUILayout.Toggle(patch.IsEnabled, "", GUILayout.Width(20));
if (newEnabled != patch.IsEnabled)
Expand Down Expand Up @@ -132,19 +132,19 @@ protected override void DrawContents()

GUILayout.Space(5);

GUILayout.BeginVertical(GUI.skin.box, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true));
GUILayout.BeginVertical(GUI.skin.box, GUILayoutShim.ExpandHeight(true), GUILayoutShim.ExpandWidth(true));
if (_selectedPatchIndex == -1)
{
GUILayout.Label("IL Code for the Original Method (target being patched)");
GUILayout.Label("IL Code for the Original Method (target being patched)", IMGUIUtils.EmptyLayoutOptions);
_ilScrollPosition = GUILayout.BeginScrollView(_ilScrollPosition, GUILayoutShim.ExpandHeight(true));
GUILayout.TextArea(_originalIL);
GUILayout.TextArea(_originalIL, IMGUIUtils.EmptyLayoutOptions);
GUILayout.EndScrollView();
}
else if (_selectedPatchIndex >= 0 && _selectedPatchIndex < _patchMethods.Count)
{
var selectedPatch = _patchMethods[_selectedPatchIndex];

GUILayout.BeginHorizontal();
GUILayout.BeginHorizontal(IMGUIUtils.EmptyLayoutOptions);
{
GUILayout.Space(3);

Expand All @@ -160,13 +160,13 @@ protected override void DrawContents()

_ilScrollPosition = GUILayout.BeginScrollView(_ilScrollPosition, GUILayoutShim.ExpandHeight(true));

GUILayout.TextArea(selectedPatch.ILCode);
GUILayout.TextArea(selectedPatch.ILCode, IMGUIUtils.EmptyLayoutOptions);

GUILayout.EndScrollView();
}
else
{
GUILayout.Label("Select a method from the list on the left to view its IL code.", IMGUIUtils.MiddleCenterLabelStyle);
GUILayout.Label("Select a method from the list on the left to view its IL code.", IMGUIUtils.MiddleCenterLabelStyle, IMGUIUtils.EmptyLayoutOptions);
}
GUILayout.EndVertical();
}
Expand Down
18 changes: 9 additions & 9 deletions RuntimeUnityEditor.Bepin5/PatchInspector/PatchInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override void OnGUI()
/// <inheritdoc />
protected override void DrawContents()
{
GUILayout.BeginHorizontal(GUI.skin.box);
GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.EmptyLayoutOptions);
{
GUILayout.Label("Search: ", IMGUIUtils.LayoutOptionsExpandWidthFalse);

Expand All @@ -109,7 +109,7 @@ protected override void DrawContents()
if (_foundPatches.Count > 0)
{
_scrollPos = GUILayout.BeginScrollView(_scrollPos, GUI.skin.box);
GUILayout.Label($"Found {_foundPatches.Count} patches", IMGUIUtils.UpperCenterLabelStyle);
GUILayout.Label($"Found {_foundPatches.Count} patches", IMGUIUtils.UpperCenterLabelStyle, IMGUIUtils.EmptyLayoutOptions);

for (var i = 0; i < _foundPatches.Count; i++)
{
Expand All @@ -118,9 +118,9 @@ protected override void DrawContents()
Color prevColor = GUI.color;
GUI.color = patch.IsEnabled ? Color.white : new Color(0.8f, 0.8f, 0.8f, 1f);

GUILayout.BeginVertical(GUI.skin.box);
GUILayout.BeginVertical(GUI.skin.box, IMGUIUtils.EmptyLayoutOptions);
{
GUILayout.BeginHorizontal();
GUILayout.BeginHorizontal(IMGUIUtils.EmptyLayoutOptions);
{
bool newEnabled = GUILayout.Toggle(patch.IsEnabled, "", IMGUIUtils.LayoutOptionsExpandWidthFalse);
if (newEnabled != patch.IsEnabled)
Expand All @@ -141,7 +141,7 @@ protected override void DrawContents()
var patchName = $"Patch: [{patch.PatchType}] {patch.Patch?.PatchMethod?.Name ?? "Not applied"}";

if (patch.Patch == null) GUI.enabled = false;
if (GUILayout.Button(new GUIContent(patchName, null, "Click to see more information about the patch method. Right click for more options."), GUI.skin.label))
if (GUILayout.Button(new GUIContent(patchName, null, "Click to see more information about the patch method. Right click for more options."), GUI.skin.label, IMGUIUtils.EmptyLayoutOptions))
{
if (IMGUIUtils.IsMouseRightClick())
ContextMenu.Instance.Show(patch.Patch.PatchMethod, null, $"MethodInfo: {patch.Patch.PatchMethod?.DeclaringType?.Name}.{patch.Patch.PatchMethod?.Name}", null, null);
Expand All @@ -151,12 +151,12 @@ protected override void DrawContents()

GUI.enabled = true;

if (GUILayout.Button(new GUIContent($"Patcher: {patch.PatcherNamespace}", null, "Click to search for types in this namespace."), GUI.skin.label))
if (GUILayout.Button(new GUIContent($"Patcher: {patch.PatcherNamespace}", null, "Click to search for types in this namespace."), GUI.skin.label, IMGUIUtils.EmptyLayoutOptions))
Inspector.Instance.Push(new InstanceStackEntry(AccessTools.AllTypes().Where(x => x.Namespace == patch.PatcherNamespace).ToArray(), "Types in " + patch.PatcherNamespace), true);

if (GUILayout.Button(
new GUIContent($"Assembly: {patch.PatcherAssembly}", null,
$"File: {patch.FilePath}\n\nClick to open explorer focused on this file. Right click for to inspect the Assembly instance."), GUI.skin.label))
$"File: {patch.FilePath}\n\nClick to open explorer focused on this file. Right click for to inspect the Assembly instance."), GUI.skin.label, IMGUIUtils.EmptyLayoutOptions))
{
if (IMGUIUtils.IsMouseRightClick())
ContextMenu.Instance.Show(AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.GetName().Name == patch.PatcherAssembly), null, "Assembly: " + patch.PatcherAssembly,
Expand Down Expand Up @@ -188,13 +188,13 @@ protected override void DrawContents()
else if (!string.IsNullOrEmpty(SearchInput))
{
GUILayout.Space(10);
GUILayout.Label("No patches found.", IMGUIUtils.UpperCenterLabelStyle);
GUILayout.Label("No patches found.", IMGUIUtils.UpperCenterLabelStyle, IMGUIUtils.EmptyLayoutOptions);
GUILayout.FlexibleSpace();
}
else
{
GUILayout.Space(10);
GUILayout.Label("Use the search box to search for currently applied Harmony patches by method, class, or namespace.\n\nExamples: 'OnClick', 'method:OnClick class:AddButtonCtrl', 'namespace:SimpleGame'", IMGUIUtils.UpperCenterLabelStyle);
GUILayout.Label("Use the search box to search for currently applied Harmony patches by method, class, or namespace.\n\nExamples: 'OnClick', 'method:OnClick class:AddButtonCtrl', 'namespace:SimpleGame'", IMGUIUtils.UpperCenterLabelStyle, IMGUIUtils.EmptyLayoutOptions);
GUILayout.FlexibleSpace();
}
}
Expand Down
7 changes: 7 additions & 0 deletions RuntimeUnityEditor.Core/Utils/Abstractions/GUILayoutShim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

namespace RuntimeUnityEditor.Core
{
/// <summary>
/// Provides a shim for GUILayout methods that are often missing in IL2CPP.
/// </summary>
public static class GUILayoutShim
{
/// <inheritdoc cref="GUILayout.MaxWidth"/>
public static GUILayoutOption MaxWidth(float width)
{
#if IL2CPP
Expand All @@ -14,6 +18,7 @@ public static GUILayoutOption MaxWidth(float width)
#endif
}

/// <inheritdoc cref="GUILayout.ExpandWidth"/>
public static GUILayoutOption ExpandWidth(bool expand)
{
#if IL2CPP
Expand All @@ -24,6 +29,7 @@ public static GUILayoutOption ExpandWidth(bool expand)
#endif
}

/// <inheritdoc cref="GUILayout.ExpandHeight"/>
public static GUILayoutOption ExpandHeight(bool expand)
{
#if IL2CPP
Expand All @@ -35,6 +41,7 @@ public static GUILayoutOption ExpandHeight(bool expand)
}


/// <inheritdoc cref="GUILayout.MinWidth"/>
public static GUILayoutOption MinWidth(float width)
{
#if IL2CPP
Expand Down
13 changes: 6 additions & 7 deletions RuntimeUnityEditor.Core/Utils/IMGUIUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ namespace RuntimeUnityEditor.Core.Utils
/// </summary>
public static class IMGUIUtils
{
/// <summary>
/// Options with GUILayout.ExpandWidth(true). Useful for avoiding allocations.
/// </summary>
/// <summary> Options with GUILayout.ExpandWidth(true). Useful for avoiding allocations. </summary>
public static readonly GUILayoutOption[] LayoutOptionsExpandWidthTrue = { GUILayoutShim.ExpandWidth(true) };

/// <summary>
/// Options with GUILayout.ExpandWidth(false). Useful for avoiding allocations.
/// </summary>
/// <summary> Options with GUILayout.ExpandWidth(false). Useful for avoiding allocations. </summary>
public static readonly GUILayoutOption[] LayoutOptionsExpandWidthFalse = { GUILayoutShim.ExpandWidth(false) };
/// <summary> Options with GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false). Useful for avoiding allocations. </summary>
public static readonly GUILayoutOption[] LayoutOptionsNoExpansion = { GUILayoutShim.ExpandWidth(false), GUILayoutShim.ExpandHeight(false) };
/// <summary> Empty layout options array. Useful for avoiding allocations. </summary>
public static readonly GUILayoutOption[] EmptyLayoutOptions = new GUILayoutOption[0];

private static Texture2D SolidBoxTex { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using HarmonyLib;
using RuntimeUnityEditor.Core.Inspector.Entries;
using RuntimeUnityEditor.Core.ObjectTree;
using RuntimeUnityEditor.Core.Utils;
using RuntimeUnityEditor.Core.Utils.Abstractions;
using RuntimeUnityEditor.Core.Utils.ObjectDumper;
using UnityEngine;
using Component = UnityEngine.Component;

namespace RuntimeUnityEditor.Core.Inspector
{
Expand Down
Loading