public static bool LoadModule(string module) { #if CPP #if ML var path = $@"MelonLoader\Managed\{module}.dll"; #else var path = $@"BepInEx\unhollowed\{module}.dll"; #endif if (!File.Exists(path)) { return(false); } try { Assembly.Load(File.ReadAllBytes(path)); return(true); } catch (Exception e) { ExplorerCore.Log(e.GetType() + ", " + e.Message); } #endif return(false); }
public override void UpdateValue() { base.UpdateValue(); if (Value == null) { return; } try { var enabledNames = Value.ToString().Split(',').Select(it => it.Trim()); m_enabledFlags = new bool[EnumNames.Length]; for (int i = 0; i < EnumNames.Length; i++) { m_enabledFlags[i] = enabledNames.Contains(EnumNames[i]); } } catch (Exception e) { ExplorerCore.Log(e.ToString()); } }
private void DrawTextureControls() { GUIHelper.BeginHorizontal(); GUILayout.Label("Save folder:", new GUILayoutOption[] { GUILayout.Width(80f) }); saveFolder = GUIHelper.TextField(saveFolder, new GUILayoutOption[0]); GUIHelper.Space(10f); GUILayout.EndHorizontal(); if (GUILayout.Button("Save to PNG", new GUILayoutOption[] { GUILayout.Width(100f) })) { var name = RemoveInvalidFilenameChars(currentTex.name ?? ""); if (string.IsNullOrEmpty(name)) { if (OwnerCacheObject is CacheMember cacheMember) { name = cacheMember.MemInfo.Name; } else { name = "UNTITLED"; } } Texture2DHelpers.SaveTextureAsPNG(currentTex, saveFolder, name, false); ExplorerCore.Log($@"Saved to {saveFolder}\{name}.png!"); } }
public void ResetConsole(bool log = true) { if (Evaluator != null) { Evaluator.Dispose(); } m_evalLogBuilder = new StringBuilder(); Evaluator = new ScriptEvaluator(new StringWriter(m_evalLogBuilder)) { InteractiveBaseClass = typeof(ScriptInteraction) }; UsingDirectives = new List <string>(); foreach (string use in DefaultUsing) { AddUsing(use); } if (log) { ExplorerCore.Log($"C# Console reset. Using directives:\r\n{Evaluator.GetUsing()}"); } }
public static void Help() { ExplorerCore.Log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); ExplorerCore.Log(" C# Console Help "); ExplorerCore.Log(""); ExplorerCore.Log("The following helper methods are available:"); ExplorerCore.Log(""); ExplorerCore.Log("void Log(object message)"); ExplorerCore.Log(" prints a message to the console window and debug log"); ExplorerCore.Log(" usage: Log(\"hello world\");"); ExplorerCore.Log(""); ExplorerCore.Log("object CurrentTarget()"); ExplorerCore.Log(" returns the target object of the current tab (in tab view mode only)"); ExplorerCore.Log(" usage: var target = CurrentTarget();"); ExplorerCore.Log(""); ExplorerCore.Log("object[] AllTargets()"); ExplorerCore.Log(" returns an object[] array containing all currently inspected objects"); ExplorerCore.Log(" usage: var targets = AllTargets();"); ExplorerCore.Log(""); ExplorerCore.Log("void Inspect(object obj)"); ExplorerCore.Log(" inspects the provided object in a new window."); ExplorerCore.Log(" usage: Inspect(Camera.main);"); ExplorerCore.Log(""); ExplorerCore.Log("void Inspect(Type type)"); ExplorerCore.Log(" attempts to inspect the provided type with static-only reflection."); ExplorerCore.Log(" usage: Inspect(typeof(Camera));"); }
public void SetValue(object instance, string input, int fieldIndex) { var field = Fields[fieldIndex]; object val; if (field.FieldType == typeof(string)) { val = input; } else { if (!ParseUtility.TryParse(input, field.FieldType, out val, out Exception ex)) { ExplorerCore.LogWarning("Unable to parse input!"); if (ex != null) { ExplorerCore.Log(ex.ReflectionExToString()); } return; } } field.SetValue(instance, val); }
public static Texture2D ForceReadTexture(Texture2D tex) { try { FilterMode origFilter = tex.filterMode; tex.filterMode = FilterMode.Point; var rt = RenderTexture.GetTemporary(tex.width, tex.height, 0, RenderTextureFormat.ARGB32); rt.filterMode = FilterMode.Point; RenderTexture.active = rt; #if MONO Graphics.Blit(tex, rt); #else var iCall = ICallHelper.GetICall <d_Blit2>("UnityEngine.Graphics::Blit2"); iCall.Invoke(tex.Pointer, rt.Pointer); #endif var _newTex = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, false); _newTex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0); _newTex.Apply(false, false); RenderTexture.active = null; tex.filterMode = origFilter; return(_newTex); } catch (Exception e) { ExplorerCore.Log("Exception on ForceReadTexture: " + e.ToString()); return(default);
internal void GetNames() { var type = Value?.GetType() ?? FallbackType; if (m_lastEnumType == type) { return; } m_lastEnumType = type; if (m_subContentConstructed) { DestroySubContent(); } if (!s_enumNamesCache.ContainsKey(type)) { // using GetValues not GetNames, to catch instances of weird enums (eg CameraClearFlags) var values = Enum.GetValues(type); var list = new List <KeyValuePair <int, string> >(); var set = new HashSet <string>(); foreach (var value in values) { var name = value.ToString(); if (set.Contains(name)) { continue; } set.Add(name); var backingType = Enum.GetUnderlyingType(type); int intValue; try { // this approach is necessary, a simple '(int)value' is not sufficient. var unbox = Convert.ChangeType(value, backingType); intValue = (int)Convert.ChangeType(unbox, typeof(int)); } catch (Exception ex) { ExplorerCore.LogWarning("[InteractiveEnum] Could not Unbox underlying type " + backingType.Name + " from " + type.FullName); ExplorerCore.Log(ex.ToString()); continue; } list.Add(new KeyValuePair <int, string>(intValue, name)); } s_enumNamesCache.Add(type, list.ToArray()); } m_values = s_enumNamesCache[type]; }
public static void UpdateInstances() { if (!Instances.Any()) { return; } try { for (int i = Instances.Count - 1; i >= 0; i--) { var instance = Instances[i]; if (instance == null || !instance.UIRoot) { Instances.RemoveAt(i); continue; } if (instance.Enabled) { instance.Update(); } } } catch (Exception ex) { ExplorerCore.Log(ex); } }
private static void LoadBundle() { var bundlePath = ExplorerCore.EXPLORER_FOLDER + @"\explorerui.bundle"; if (File.Exists(bundlePath)) { var bundle = AssetBundle.LoadFromFile(bundlePath); BackupShader = bundle.LoadAsset <Shader>("DefaultUI"); // Fix for games which don't ship with 'UI/Default' shader. if (Graphic.defaultGraphicMaterial.shader?.name != "UI/Default") { ExplorerCore.Log("This game does not ship with the 'UI/Default' shader, using manual Default Shader..."); Graphic.defaultGraphicMaterial.shader = BackupShader; } ResizeCursor = bundle.LoadAsset <Sprite>("cursor"); ConsoleFont = bundle.LoadAsset <Font>("CONSOLA"); ExplorerCore.Log("Loaded UI bundle"); } else { ExplorerCore.LogWarning("Could not find the ExplorerUI Bundle! It should exist at '" + bundlePath + "'"); return; } }
public static Texture2D ForceReadTexture(Texture2D tex) { try { FilterMode origFilter = tex.filterMode; tex.filterMode = FilterMode.Point; var rt = RenderTexture.GetTemporary(tex.width, tex.height, 0, RenderTextureFormat.ARGB32); rt.filterMode = FilterMode.Point; RenderTexture.active = rt; Instance.Blit(tex, rt); var _newTex = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, false); _newTex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0); _newTex.Apply(false, false); RenderTexture.active = null; tex.filterMode = origFilter; return(_newTex); } catch (Exception e) { ExplorerCore.Log("Exception on ForceReadTexture: " + e.ToString()); return(default);
public static void ResetConsole(bool logSuccess = true) { if (SRENotSupported) { return; } if (Evaluator != null) { Evaluator.Dispose(); } evaluatorOutput = new StringBuilder(); Evaluator = new ScriptEvaluator(new StringWriter(evaluatorOutput)) { InteractiveBaseClass = typeof(ScriptInteraction) }; usingDirectives = new HashSet <string>(); foreach (var use in DefaultUsing) { AddUsing(use); } if (logSuccess) { ExplorerCore.Log($"C# Console reset. Using directives:\r\n{Evaluator.GetUsing()}"); } }
// --------- GUI Draw Function --------- // public override void DrawWindow() { try { DrawHeaderArea(); GUIHelper.BeginVertical(GUIContent.none, GUI.skin.box, null); DrawPageButtons(); if (!m_searching) { DrawGameObjectList(); } else { DrawSearchResultsList(); } GUILayout.EndVertical(); } catch (Exception e) { if (!e.Message.Contains("in a group with only")) { ExplorerCore.Log(e.ToString()); } } }
private IEnumerable <Transform> GetRootObjectsManual_Impl() { try { var array = Resources.FindObjectsOfTypeAll(ReflectionHelpers.TransformType); var list = new List <Transform>(); foreach (var obj in array) { #if CPP var transform = obj.TryCast <Transform>(); #else var transform = obj as Transform; #endif if (transform.parent == null && transform.gameObject.scene.name == m_currentScene) { list.Add(transform); } } return(list); } catch (Exception e) { ExplorerCore.Log("Exception getting root scene objects (manual): " + e.GetType() + ", " + e.Message + "\r\n" + e.StackTrace); return(new Transform[0]); } }
internal static void OnSetParentClicked() { var go = GameObjectInspector.ActiveInstance.TargetGO; if (!go) { return; } var input = s_setParentInput.text; if (string.IsNullOrEmpty(input)) { go.transform.parent = null; } else { if (GameObject.Find(input) is GameObject newParent) { go.transform.parent = newParent.transform; } else { ExplorerCore.Log($"Could not find any GameObject from name or path '{input}'! Note: The target must be enabled."); } } }
public override void Update() { try { if (Target == null) { ExplorerCore.Log("Target is null!"); DestroyWindow(); return; } if (!TargetGO && !GetObjectAsGameObject()) { ExplorerCore.Log("Target was destroyed!"); DestroyWindow(); return; } if (m_freeze) { if (m_localContext) { TargetGO.transform.localPosition = m_frozenPosition; TargetGO.transform.localRotation = m_frozenRotation; } else { TargetGO.transform.position = m_frozenPosition; TargetGO.transform.rotation = m_frozenRotation; } TargetGO.transform.localScale = m_frozenScale; } // update child objects var childList = new List <Transform>(); for (int i = 0; i < TargetGO.transform.childCount; i++) { childList.Add(TargetGO.transform.GetChild(i)); } childList.Sort((a, b) => b.childCount.CompareTo(a.childCount)); m_children = childList.ToArray(); ChildPages.ItemCount = m_children.Length; // update components #if CPP var compList = new Il2CppSystem.Collections.Generic.List <Component>(); TargetGO.GetComponentsInternal(ReflectionHelpers.ComponentType, true, false, true, false, compList); m_components = compList.ToArray(); #else m_components = TargetGO.GetComponents <Component>(); #endif CompPages.ItemCount = m_components.Length; } catch (Exception e) { DestroyOnException(e); } }
public object[] ParseArguments() { if (m_arguments.Length < 1) { return(new object[0]); } var parsedArgs = new List <object>(); for (int i = 0; i < m_arguments.Length; i++) { var input = m_argumentInput[i]; var type = m_arguments[i].ParameterType; if (type.IsByRef) { type = type.GetElementType(); } if (!string.IsNullOrEmpty(input)) { if (type == typeof(string)) { parsedArgs.Add(input); continue; } else { try { var arg = type.GetMethod("Parse", new Type[] { typeof(string) }) .Invoke(null, new object[] { input }); parsedArgs.Add(arg); continue; } catch { ExplorerCore.Log($"Could not parse input '{input}' for argument #{i} '{m_arguments[i].Name}' ({type.FullName})"); } } } // No input, see if there is a default value. if (m_arguments[i].IsOptional) { parsedArgs.Add(m_arguments[i].DefaultValue); continue; } // Try add a null arg I guess parsedArgs.Add(null); } return(parsedArgs.ToArray()); }
public override void Init() { ExplorerCore.Log("Initializing Legacy Input support..."); _mousePositionProp = TInput.GetProperty("mousePosition"); _getKeyMethod = TInput.GetMethod("GetKey", new Type[] { typeof(KeyCode) }); _getKeyDownMethod = TInput.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) }); _getMouseButtonMethod = TInput.GetMethod("GetMouseButton", new Type[] { typeof(int) }); _getMouseButtonDownMethod = TInput.GetMethod("GetMouseButtonDown", new Type[] { typeof(int) }); }
public static object CurrentTarget() { if (!WindowManager.TabView) { ExplorerCore.Log("CurrentTarget() is only a valid method when in Tab View mode!"); return(null); } return(WindowManager.Windows.ElementAt(TabViewWindow.Instance.TargetTabID).Target); }
public static void Init() { InitEventSystemPropertyHandlers(); // Make sure console is supported on this platform try { ResetConsole(false); // ensure the compiler is supported (if this fails then SRE is probably stubbed) Evaluator.Compile("0 == 0"); } catch (Exception ex) { DisableConsole(ex); return; } // Setup console Lexer = new LexerBuilder(); Completer = new CSAutoCompleter(); SetupHelpInteraction(); Panel.OnInputChanged += OnInputChanged; Panel.InputScroller.OnScroll += OnInputScrolled; Panel.OnCompileClicked += Evaluate; Panel.OnResetClicked += ResetConsole; Panel.OnHelpDropdownChanged += HelpSelected; Panel.OnAutoIndentToggled += OnToggleAutoIndent; Panel.OnCtrlRToggled += OnToggleCtrlRShortcut; Panel.OnSuggestionsToggled += OnToggleSuggestions; Panel.OnPanelResized += OnInputScrolled; // Run startup script try { if (!Directory.Exists(ScriptsFolder)) { Directory.CreateDirectory(ScriptsFolder); } var startupPath = Path.Combine(ScriptsFolder, "startup.cs"); if (File.Exists(startupPath)) { ExplorerCore.Log($"Executing startup script from '{startupPath}'..."); var text = File.ReadAllText(startupPath); Input.Text = text; Evaluate(); } } catch (Exception ex) { ExplorerCore.LogWarning($"Exception executing startup script: {ex}"); } }
public static void SetCurrentPage(int index) { if (index < 0 || Pages.Count <= index) { ExplorerCore.Log("cannot set page " + index); return; } m_currentPage = index; GUIHelper.BringWindowToFront(MainWindowID); GUI.FocusWindow(MainWindowID); }
private void DestroyOnException(Exception e) { if (pendingDestroy) { return; } ExplorerCore.Log($"Exception drawing GameObject Window: {e.GetType()}, {e.Message}"); pendingDestroy = true; DestroyWindow(); }
public override void SetConfigValue <T>(ConfigElement <T> element, T value) { if (Config.TryGetEntry(CTG_NAME, element.Name, out ConfigEntry <T> configEntry)) { configEntry.Value = value; } else { ExplorerCore.Log("Could not get config entry '" + element.Name + "'"); } }
public override void SetupEvents() { try { Application.add_logMessageReceived(new Action <string, string, LogType>(Application_logMessageReceived)); } catch (Exception ex) { ExplorerCore.LogWarning("Exception setting up Unity log listener, make sure Unity libraries have been unstripped!"); ExplorerCore.Log(ex); } }
internal static void Init() { try { ExplorerCore.Harmony.PatchAll(typeof(UnityCrashPrevention)); ExplorerCore.Log("Initialized UnityCrashPrevention."); } catch //(Exception ex) { //ExplorerCore.Log($"Exception setting up Canvas crash prevention patch: {ex}"); } }
public static void GetAutocompletes(string input) { try { // Credit ManylMarco CSharpConsole.AutoCompletes.Clear(); string[] completions = CSharpConsole.Instance.Evaluator.GetCompletions(input, out string prefix); if (completions != null) { if (prefix == null) { prefix = input; } CSharpConsole.AutoCompletes.AddRange(completions .Where(x => !string.IsNullOrEmpty(x)) .Select(x => new Suggestion(x, prefix, Suggestion.Contexts.Other)) ); } string trimmed = input.Trim(); if (trimmed.StartsWith("using")) { trimmed = trimmed.Remove(0, 5).Trim(); } IEnumerable <Suggestion> namespaces = Suggestion.Namespaces .Where(x => x.StartsWith(trimmed) && x.Length > trimmed.Length) .Select(x => new Suggestion( x.Substring(trimmed.Length), x.Substring(0, trimmed.Length), Suggestion.Contexts.Namespace)); CSharpConsole.AutoCompletes.AddRange(namespaces); IEnumerable <Suggestion> keywords = Suggestion.Keywords .Where(x => x.StartsWith(trimmed) && x.Length > trimmed.Length) .Select(x => new Suggestion( x.Substring(trimmed.Length), x.Substring(0, trimmed.Length), Suggestion.Contexts.Keyword)); CSharpConsole.AutoCompletes.AddRange(keywords); } catch (Exception ex) { ExplorerCore.Log("Autocomplete error:\r\n" + ex.ToString()); ClearAutocompletes(); } }
private void SetValueFromBinaryInput() { try { var method = typeof(Convert).GetMethod($"To{ValueType.Name}", new Type[] { typeof(string), typeof(int) }); Value = method.Invoke(null, new object[] { m_binaryInput, 2 }); OwnerCacheObject.SetValue(); RefreshToString(); } catch (Exception e) { ExplorerCore.Log("Exception setting value: " + e.GetType() + ", " + e.Message); } }
public void RefreshUI(InputField[] inputs, object instance) { try { for (int i = 0; i < m_fields.Length; i++) { var field = m_fields[i]; float val = (float)field.GetValue(instance); inputs[i].text = val.ToString(); } } catch (Exception ex) { ExplorerCore.Log(ex); } }
private static MethodInfo GetEncodeToPNGMethod() { if (ReflectionUtility.GetTypeByName("UnityEngine.ImageConversion") is Type imageConversion) { return(m_encodeToPNGMethod = imageConversion.GetMethod("EncodeToPNG", ReflectionUtility.AllFlags)); } var method = typeof(Texture2D).GetMethod("EncodeToPNG", ReflectionUtility.AllFlags); if (method != null) { return(m_encodeToPNGMethod = method); } ExplorerCore.Log("ERROR: Cannot get any EncodeToPNG method!"); return(null); }
public override void SetColorBlock(Selectable selectable, ColorBlock _colorBlock) { try { selectable = selectable.TryCast <Selectable>(); ReflectionUtility.GetPropertyInfo(typeof(Selectable), "m_Colors") .SetValue(selectable, _colorBlock, null); ReflectionUtility.GetMethodInfo(typeof(Selectable), "OnSetProperty") .Invoke(selectable, ArgumentUtility.EmptyArgs); } catch (Exception ex) { ExplorerCore.Log(ex); } }