From bd97fcc195fac94ffd4cd8aba4989baf5c139ca8 Mon Sep 17 00:00:00 2001 From: DeathWeasel1337 <37981563+DeathWeasel1337@users.noreply.github.com> Date: Sat, 10 Aug 2019 20:11:47 -0500 Subject: [PATCH] Add project files --- BepInEx.DeveloperConsole.sln | 25 +++++ .../BepInEx.DeveloperConsole.csproj | 56 +++++++++++ .../DeveloperConsole.LogListener.cs | 17 ++++ .../DeveloperConsole.SceneDumper.cs | 68 +++++++++++++ BepInEx.DeveloperConsole/DeveloperConsole.cs | 97 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 35 +++++++ 6 files changed, 298 insertions(+) create mode 100644 BepInEx.DeveloperConsole.sln create mode 100644 BepInEx.DeveloperConsole/BepInEx.DeveloperConsole.csproj create mode 100644 BepInEx.DeveloperConsole/DeveloperConsole.LogListener.cs create mode 100644 BepInEx.DeveloperConsole/DeveloperConsole.SceneDumper.cs create mode 100644 BepInEx.DeveloperConsole/DeveloperConsole.cs create mode 100644 BepInEx.DeveloperConsole/Properties/AssemblyInfo.cs diff --git a/BepInEx.DeveloperConsole.sln b/BepInEx.DeveloperConsole.sln new file mode 100644 index 0000000..3a93ebd --- /dev/null +++ b/BepInEx.DeveloperConsole.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29020.237 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInEx.DeveloperConsole", "BepInEx.DeveloperConsole\BepInEx.DeveloperConsole.csproj", "{3C7BB8A4-13FD-4F27-BF26-BF908E06D628}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3C7BB8A4-13FD-4F27-BF26-BF908E06D628}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3C7BB8A4-13FD-4F27-BF26-BF908E06D628}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3C7BB8A4-13FD-4F27-BF26-BF908E06D628}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3C7BB8A4-13FD-4F27-BF26-BF908E06D628}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {521B1E47-9429-4670-8741-51CD93A77909} + EndGlobalSection +EndGlobal diff --git a/BepInEx.DeveloperConsole/BepInEx.DeveloperConsole.csproj b/BepInEx.DeveloperConsole/BepInEx.DeveloperConsole.csproj new file mode 100644 index 0000000..ea3f83f --- /dev/null +++ b/BepInEx.DeveloperConsole/BepInEx.DeveloperConsole.csproj @@ -0,0 +1,56 @@ + + + + + Debug + AnyCPU + {3C7BB8A4-13FD-4F27-BF26-BF908E06D628} + Library + Properties + BepInEx.DeveloperConsole + BepInEx.DeveloperConsole + v3.5 + 512 + true + + + false + none + false + ..\bin\BepInEx\plugins\ + DEBUG;TRACE + prompt + 4 + + + none + true + ..\bin\BepInEx\plugins\ + TRACE + prompt + 4 + + + + ..\lib\BepInEx.dll + False + + + + + + + + + ..\lib\UnityEngine.dll + False + + + + + + + + + + \ No newline at end of file diff --git a/BepInEx.DeveloperConsole/DeveloperConsole.LogListener.cs b/BepInEx.DeveloperConsole/DeveloperConsole.LogListener.cs new file mode 100644 index 0000000..d17005e --- /dev/null +++ b/BepInEx.DeveloperConsole/DeveloperConsole.LogListener.cs @@ -0,0 +1,17 @@ +using BepInEx.Logging; + +namespace BepInEx +{ + public partial class DeveloperConsole + { + private sealed class LogListener : ILogListener + { + public void Dispose() { } + + public void LogEvent(object sender, LogEventArgs eventArgs) + { + OnEntryLogged(eventArgs); + } + } + } +} diff --git a/BepInEx.DeveloperConsole/DeveloperConsole.SceneDumper.cs b/BepInEx.DeveloperConsole/DeveloperConsole.SceneDumper.cs new file mode 100644 index 0000000..747ff04 --- /dev/null +++ b/BepInEx.DeveloperConsole/DeveloperConsole.SceneDumper.cs @@ -0,0 +1,68 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Text; +using BepInEx.Logging; +using UnityEngine; +using UnityEngine.SceneManagement; + +namespace BepInEx +{ + static class SceneDumper + { + public static void DumpScene() + { + var objects = SceneManager.GetActiveScene().GetRootGameObjects(); + + var fname = Path.GetTempFileName(); + using (var f = File.OpenWrite(fname)) + using (var sw = new StreamWriter(f, Encoding.UTF8)) + { + foreach (var obj in objects) + { + PrintRecursive(sw, obj); + } + } + Process.Start("notepad.exe", fname); + } + + private static void PrintRecursive(StreamWriter sw, GameObject obj) + { + PrintRecursive(sw, obj, 0); + } + + private static void PrintRecursive(StreamWriter sw, GameObject obj, int d) + { + //Console.WriteLine(obj.name); + var pad1 = new string(' ', 3 * d); + var pad2 = new string(' ', 3 * (d + 1)); + var pad3 = new string(' ', 3 * (d + 2)); + sw.WriteLine(pad1 + obj.name + "--" + obj.GetType().FullName); + + foreach (Component c in obj.GetComponents()) + { + sw.WriteLine(pad2 + "::" + c.GetType().Name); + + var ct = c.GetType(); + var props = ct.GetProperties(System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); + foreach (var p in props) + { + try + { + var v = p.GetValue(c, null); + sw.WriteLine(pad3 + "@" + p.Name + "<" + p.PropertyType.Name + "> = " + v); + } + catch (Exception e) + { + DeveloperConsole.Logger.Log(LogLevel.Debug, e); + } + } + + } + foreach (Transform t in obj.transform) + { + PrintRecursive(sw, t.gameObject, d + 1); + } + } + } +} diff --git a/BepInEx.DeveloperConsole/DeveloperConsole.cs b/BepInEx.DeveloperConsole/DeveloperConsole.cs new file mode 100644 index 0000000..88c03a8 --- /dev/null +++ b/BepInEx.DeveloperConsole/DeveloperConsole.cs @@ -0,0 +1,97 @@ +using BepInEx; +using BepInEx.Configuration; +using BepInEx.Logging; +using System.Linq; +using UnityEngine; + +namespace BepInEx +{ + [BepInPlugin(GUID, PluginName, Version)] + public partial class DeveloperConsole : BaseUnityPlugin + { + public const string GUID = "com.bepis.bepinex.developerconsole"; + public const string PluginName = "Developer Console"; + public const string Version = "1.0"; + internal static new ManualLogSource Logger; + + private bool showingUI = false; + private static string TotalLog = ""; + private Rect UI = new Rect(20, 20, 400, 400); + private static Vector2 scrollPosition = Vector2.zero; + + public static ConfigFile BepinexConfig { get; } = new ConfigFile(Utility.CombinePaths(Paths.ConfigPath, "BepInEx.cfg"), false); + + public static ConfigWrapper LogDepth { get; private set; } + public static ConfigWrapper LogUnity { get; private set; } + + public DeveloperConsole() + { + LogDepth = Config.Wrap("Config", "Log buffer size", "Size of the log buffer in characters", 16300); + LogUnity = BepinexConfig.Wrap("Logging", "UnityLogListening", "Enables showing unity log messages in the BepInEx logging system.", true); + + Logging.Logger.Listeners.Add(new LogListener()); + Logger = base.Logger; + } + + private static void OnEntryLogged(LogEventArgs logEventArgs) + { + string current = $"{TotalLog}\r\n{logEventArgs.Data?.ToString()}"; + if (current.Length > LogDepth.Value) + { + var trimmed = current.Remove(0, 1000); + + // Trim until the first newline to avoid partial line + var newlineHit = false; + trimmed = new string(trimmed.SkipWhile(x => !newlineHit && !(newlineHit = (x == '\n'))).ToArray()); + + current = "--LOG TRIMMED--\n" + trimmed; + } + TotalLog = current; + + scrollPosition = new Vector2(0, float.MaxValue); + } + + protected void OnGUI() + { + if (showingUI) + UI = GUILayout.Window(589, UI, WindowFunction, "Developer Console"); + } + + protected void Update() + { + if (Input.GetKeyDown(KeyCode.Pause)) + showingUI = !showingUI; + } + + private void WindowFunction(int windowID) + { + GUILayout.BeginHorizontal(); + { + if (GUILayout.Button("Clear console")) + TotalLog = "Log cleared"; + if (GUILayout.Button("Dump scene")) + SceneDumper.DumpScene(); + + LogUnity.Value = GUILayout.Toggle(LogUnity.Value, "Unity"); + } + GUILayout.EndHorizontal(); + + GUILayout.BeginVertical(GUI.skin.box); + { + scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true); + { + GUILayout.BeginVertical(); + { + GUILayout.FlexibleSpace(); + GUILayout.TextArea(TotalLog, GUI.skin.label); + } + GUILayout.EndVertical(); + } + GUILayout.EndScrollView(); + } + GUILayout.EndVertical(); + + GUI.DragWindow(); + } + } +} \ No newline at end of file diff --git a/BepInEx.DeveloperConsole/Properties/AssemblyInfo.cs b/BepInEx.DeveloperConsole/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..934b97c --- /dev/null +++ b/BepInEx.DeveloperConsole/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("BepInEx.DeveloperConsole")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("BepInEx.DeveloperConsole")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("3c7bb8a4-13fd-4f27-bf26-bf908e06d628")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion(BepInEx.DeveloperConsole.Version)]