using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using Logger;
using Microsoft.CodeAnalysis;
using MonoMod.RuntimeDetour;
using On;
using Onyx_API;
using Onyx_API.Items;
using UnityEngine;
using UnityEngine.Events;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("DebugConsole")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+4fbebb21c26a04695ff6501376e78dd6949edcaf")]
[assembly: AssemblyProduct("DebugConsole")]
[assembly: AssemblyTitle("DebugConsole")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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;
}
}
}
internal static class Commands
{
[Initializer(new Type[] { typeof(ItemCatalog) })]
private static void Init()
{
HashSet<string> hashSet = new HashSet<string>();
foreach (ItemDef allItemDef in ItemCatalog.allItemDefs)
{
hashSet.Add(allItemDef.name);
}
Console.RegisterCommand("Give_Item", GiveItem, new HashSet<string>[1] { hashSet });
Console.RegisterCommand("DebugMode", DebugMode);
}
private static void DebugMode(object[] parameters)
{
GameScript.debugMode = !GameScript.debugMode;
Log.Info("debugMode set to " + GameScript.debugMode);
}
private static void GiveItem(object[] parameters)
{
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Expected O, but got Unknown
int num = 0;
if (parameters.Length != 0)
{
if (parameters[0] is int num2)
{
num = num2;
}
if (parameters[0] is string text)
{
num = ItemCatalog.FindItemDef(text).Index;
}
ItemDef itemDef = ItemCatalog.GetItemDef(num);
int num3 = 1;
if (parameters.Length > 1)
{
if (!(parameters[1] is int num4) || 1 == 0)
{
throw new ArgumentException("ItemCount argument must be a number");
}
num3 = num4;
}
int num5 = ((itemDef.maxDurability > 0) ? itemDef.maxDurability : 0);
if (parameters.Length > 2)
{
if (!(parameters[1] is int num6) || 1 == 0)
{
throw new ArgumentException("ItemCount argument must be a number");
}
num5 = num6;
}
Singletons.GameScript.AddItem(new Item(num, num3, new int[4], (float)num5, (GameObject)null));
return;
}
throw new ArgumentException("number of Arguments for command give_item has to be at least 1");
}
}
public class Console : MonoBehaviour
{
[CompilerGenerated]
private static class <>O
{
public static Action<Action<int, int, bool>, int, int, bool> <0>__Screen_SetResolution;
public static hook_Update <1>__PlayerControllerN_Update;
public static UnityAction <2>__SetWindowSize;
}
public static float fixedAge;
private static int fontSize;
private static string inputString = "";
private static List<string> autocompleteStrings = new List<string>();
private static float backspaceTimer = 0f;
private static readonly Dictionary<string, Action<object[]>> _commands = new Dictionary<string, Action<object[]>>();
private static readonly Dictionary<string, HashSet<string>[]> _autoCompletes = new Dictionary<string, HashSet<string>[]>();
private static readonly Dictionary<string, string> _autoCompletesToUpper = new Dictionary<string, string>();
private static bool consoleOpen = false;
private static int _autocompleteIndex = 0;
private static List<KeyValuePair<LogType, string>> consoleLog = new List<KeyValuePair<LogType, string>>();
private static Texture2D inputBackground = null;
private static Texture2D autocompleteBackground = null;
private static Rect inputTextBox;
private static Rect consoleHistoryBox;
private static Rect[] autocompleteSuggestionBoxes = (Rect[])(object)new Rect[20];
private static GUIStyle inputBoxStyle;
private static GUIStyle autoCompleteBoxStyle;
[Initializer(null)]
private static void Init()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Expected O, but got Unknown
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Expected O, but got Unknown
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: 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_0164: Expected O, but got Unknown
GameObject val = Object.Instantiate<GameObject>(new GameObject("Console"));
Object.DontDestroyOnLoad((Object)(object)val);
val.AddComponent<Console>();
int num = 10;
int num2 = 10;
inputBackground = new Texture2D(num, num2);
string path = Path.Combine(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images"), "InputBackground.png");
inputBackground.LoadImage(File.ReadAllBytes(path));
((Texture)inputBackground).wrapMode = (TextureWrapMode)1;
((Texture)inputBackground).filterMode = (FilterMode)0;
int num3 = 10;
int num4 = 10;
autocompleteBackground = new Texture2D(num3, num4);
string path2 = Path.Combine(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images"), "AutocompleteBackground.png");
autocompleteBackground.LoadImage(File.ReadAllBytes(path2));
((Texture)autocompleteBackground).wrapMode = (TextureWrapMode)1;
((Texture)autocompleteBackground).filterMode = (FilterMode)0;
new Hook((MethodBase)typeof(Screen).GetMethod("SetResolution", new Type[3]
{
typeof(int),
typeof(int),
typeof(bool)
}), (Delegate)new Action<Action<int, int, bool>, int, int, bool>(Screen_SetResolution));
object obj = <>O.<1>__PlayerControllerN_Update;
if (obj == null)
{
hook_Update val2 = PlayerControllerN_Update;
<>O.<1>__PlayerControllerN_Update = val2;
obj = (object)val2;
}
PlayerControllerN.Update += (hook_Update)obj;
}
private static void PlayerControllerN_Update(orig_Update orig, PlayerControllerN self)
{
if (!consoleOpen)
{
orig.Invoke(self);
}
}
private static void Screen_SetResolution(Action<int, int, bool> orig, int width, int height, bool fullscreen)
{
//IL_0020: 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_002b: Expected O, but got Unknown
orig(width, height, fullscreen);
UnityEvent nextFixedUpdate = API_Manager.nextFixedUpdate;
object obj = <>O.<2>__SetWindowSize;
if (obj == null)
{
UnityAction val = SetWindowSize;
<>O.<2>__SetWindowSize = val;
obj = (object)val;
}
nextFixedUpdate.AddListener((UnityAction)obj);
}
private void Start()
{
SetWindowSize();
}
private static void SetWindowSize()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: 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_007b: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: 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)
//IL_00d0: Expected O, but got Unknown
//IL_00d6: Expected O, but got Unknown
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Expected O, but got Unknown
fontSize = Screen.width / 50;
inputTextBox = new Rect(0f, (float)(Screen.height - Screen.height / 25), (float)Screen.width, (float)(Screen.height / 25));
for (int i = 0; i < autocompleteSuggestionBoxes.Length; i++)
{
autocompleteSuggestionBoxes[i] = new Rect(20f, (float)(Screen.height - Screen.height / 25 - Screen.height / 25 * (i + 1)), (float)Screen.width, (float)(Screen.height / 25));
}
consoleHistoryBox = new Rect(0f, 0f, (float)Screen.width, (float)(Screen.height - Screen.height / 25));
inputBoxStyle = new GUIStyle
{
border = new RectOffset(1, 1, 1, 1)
};
inputBoxStyle.normal.background = inputBackground;
inputBoxStyle.fontSize = fontSize;
inputBoxStyle.alignment = (TextAnchor)3;
inputBoxStyle.normal.textColor = new Color(0.9f, 0.9f, 0.9f);
autoCompleteBoxStyle = new GUIStyle(inputBoxStyle);
autoCompleteBoxStyle.normal.background = autocompleteBackground;
}
private void FixedUpdate()
{
fixedAge += Time.fixedDeltaTime;
}
private void Update()
{
if (Input.GetKeyDown((KeyCode)96))
{
consoleOpen = !consoleOpen;
UpdateInputText();
}
else
{
if (!consoleOpen)
{
return;
}
bool flag = false;
string text = Regex.Replace(Input.inputString, "[^\\x20-\\x7F]", "");
if (text != string.Empty)
{
inputString += text;
flag = true;
}
if (Input.GetKeyDown((KeyCode)8) && inputString.Length > 0)
{
inputString = inputString.Remove(inputString.Length - 1);
flag = true;
}
if (Input.GetKey((KeyCode)8) && inputString.Length > 0)
{
if (backspaceTimer < 0f)
{
inputString = inputString.Remove(inputString.Length - 1);
flag = true;
backspaceTimer += 0.05f;
}
backspaceTimer -= Time.deltaTime;
}
else
{
backspaceTimer = 0.3f;
}
if (Input.GetKey((KeyCode)9) && autocompleteStrings.Count > 0)
{
inputString = autocompleteStrings[0];
}
if (Input.GetKey((KeyCode)13))
{
string[] array = inputString.Split(new char[1] { ' ' });
if (_commands.TryGetValue(array[0], out var value))
{
object[] array2 = new object[array.Length - 1];
for (int i = 0; i < array2.Length; i++)
{
array2[i] = array[i + 1];
if (int.TryParse(array[i + 1], out var result))
{
array2[i] = result;
}
}
try
{
value(array2);
}
catch (Exception data)
{
Log.Error(data);
}
}
else if (!Utility.IsNullOrWhiteSpace(array[0]))
{
inputString = "";
throw new ArgumentException(array[0] + " is not a valid command");
}
inputString = "";
flag = true;
}
if (flag)
{
UpdateInputText();
}
}
}
private void UpdateInputText()
{
string[] array = inputString.Split(new char[1] { ' ' });
autocompleteStrings = new List<string>();
if (array.Length < 1)
{
return;
}
if (array.Length == 1)
{
foreach (KeyValuePair<string, HashSet<string>[]> autoComplete in _autoCompletes)
{
if (autoComplete.Key.Contains(array[0].ToLower()))
{
autocompleteStrings.Add(_autoCompletesToUpper[autoComplete.Key]);
}
}
}
if (!_autoCompletes.TryGetValue(array[0].ToLower(), out var value) || _autoCompletes[array[0].ToLower()].Length < array.Length - 1)
{
return;
}
string text = "";
if (array.Length <= 1)
{
return;
}
for (int i = 0; i < array.Length - 1; i++)
{
text = text + array[i] + " ";
}
foreach (string item in value[array.Length - 2])
{
if (item.Contains(array[^1].ToLower()))
{
autocompleteStrings.Add(text + _autoCompletesToUpper[item]);
}
}
}
public static void RegisterCommand(string name, Action<object[]> action, HashSet<string>[] autocomplete = null)
{
if (autocomplete == null)
{
autocomplete = new HashSet<string>[0];
}
_commands.Add(name, action);
HashSet<string>[] array = new HashSet<string>[autocomplete.Length];
for (int i = 0; i < autocomplete.Length; i++)
{
array[i] = new HashSet<string>();
foreach (string item in autocomplete[i])
{
_autoCompletesToUpper.Add(item.ToLower(), item);
array[i].Add(item.ToLower());
}
}
_autoCompletes.Add(name.ToLower(), array);
_autoCompletesToUpper.Add(name.ToLower(), name);
}
private void OnGUI()
{
//IL_002e: 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_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
if (consoleOpen)
{
GUIStyle style = GUI.skin.GetStyle("label");
style.fontSize = fontSize;
GUI.Box(consoleHistoryBox, "");
if ((double)(fixedAge % 1f) < 0.5)
{
GUI.Box(inputTextBox, " > " + inputString, inputBoxStyle);
}
else
{
GUI.Box(inputTextBox, " > " + inputString + "|", inputBoxStyle);
}
for (int i = 0; i < autocompleteSuggestionBoxes.Length && i < autocompleteStrings.Count; i++)
{
GUI.Box(autocompleteSuggestionBoxes[i], " " + autocompleteStrings[i], autoCompleteBoxStyle);
}
}
}
}
namespace Logger
{
internal static class Log
{
private static ManualLogSource _logSource;
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
internal static void message(object data)
{
_logSource.LogMessage(data);
}
internal static void Debug(object data)
{
_logSource.LogDebug(data);
}
internal static void Error(object data)
{
_logSource.LogError(data);
}
internal static void Fatal(object data)
{
_logSource.LogFatal(data);
}
internal static void Info(object data)
{
StackFrame stackFrame = new StackFrame(1);
MethodBase method = stackFrame.GetMethod();
_logSource.LogInfo((object)("[" + method.Name + "]: " + data));
}
internal static void Message(object data)
{
message(data);
}
internal static void Warning(object data)
{
_logSource.LogWarning(data);
}
}
}
namespace DebugConsole
{
[BepInPlugin("com.Onyx.DebugConsole", "DebugConsole", "1.0.0")]
public class DebugConsole : BaseUnityPlugin
{
public const string PluginGUID = "com.Onyx.DebugConsole";
public const string PluginAuthor = "Onyx";
public const string PluginName = "DebugConsole";
public const string PluginVersion = "1.0.0";
public void Awake()
{
Log.Init(((BaseUnityPlugin)this).Logger);
}
}
}