static void InitEventSystemPropertyHandlers() { try { foreach (var member in typeof(EventSystem).GetMembers(AccessTools.all)) { if (member.Name == "m_CurrentSelected") { Type backingType; if (member.MemberType == MemberTypes.Property) { backingType = (member as PropertyInfo).PropertyType; } else { backingType = (member as FieldInfo).FieldType; } usingEventSystemDictionaryMembers = ReflectionUtility.IsDictionary(backingType); break; } } } catch (Exception ex) { ExplorerCore.LogWarning($"Exception checking EventSystem property backing type: {ex}"); } }
public override void UpdateMouseInspect(Vector2 mousePos) { if (!MainCamera) { MainCamera = Camera.main; } if (!MainCamera) { ExplorerCore.LogWarning("No Main Camera was found, unable to inspect world!"); MouseInspector.Instance.StopInspect(); return; } var ray = MainCamera.ScreenPointToRay(mousePos); Physics.Raycast(ray, out RaycastHit hit, 1000f); if (hit.transform) { OnHitGameObject(hit.transform.gameObject); } else if (lastHitObject) { MouseInspector.Instance.ClearHitData(); } }
public void OnSaveClipClicked() { if (!RefAudioClip) { ExplorerCore.LogWarning("AudioClip is null, maybe it was destroyed?"); return; } if (string.IsNullOrEmpty(savePathInput.Text)) { ExplorerCore.LogWarning("Save path cannot be empty!"); return; } string path = savePathInput.Text; if (!path.EndsWith(".wav", StringComparison.InvariantCultureIgnoreCase)) { path += ".wav"; } path = IOUtility.EnsureValidFilePath(path); if (File.Exists(path)) { File.Delete(path); } SavWav.Save(RefAudioClip, path); }
public override bool Init() { Instance = this; try { InitConsole(); AutoCompleter.Init(); ResetConsole(false); // Make sure compiler is supported on this platform Evaluator.Compile("new object();"); return(true); } catch (Exception e) { string info = "The C# Console has been disabled because"; if (e is NotSupportedException && e.TargetSite?.Name == "DefineDynamicAssembly") { info += " Reflection.Emit is not supported."; } else { info += $" of an unknown error.\r\n({e.ReflectionExToString()})"; } ExplorerCore.LogWarning(info); this.RefNavbarButton.GetComponentInChildren <Text>().text += " (disabled)"; return(false); } }
public void Evaluate(string code, bool suppressWarning = false) { m_evaluator.Compile(code, out Mono.CSharp.CompiledMethod compiled); if (compiled == null) { if (!suppressWarning) { ExplorerCore.LogWarning("Unable to compile the code!"); } } else { try { object ret = VoidType.Value; compiled.Invoke(ref ret); } catch (Exception e) { if (!suppressWarning) { ExplorerCore.LogWarning($"Exception executing code: {e.GetType()}, {e.Message}\r\n{e.StackTrace}"); } } } }
// Setting the value of an index to the list public void TrySetValueToIndex(object value, int index) { try { if (!IsWritableGenericIList) { RefIList[index] = value; } else { genericIndexer.SetValue(CurrentOwner.Value, value, new object[] { index }); } var entry = cachedEntries[index]; entry.SetValueFromSource(value); if (entry.CellView != null) { entry.SetDataToCell(entry.CellView); } } catch (Exception ex) { ExplorerCore.LogWarning($"Exception setting IList value: {ex}"); } }
public override void Init() { Instance = this; try { m_codeEditor = new CodeEditor(); AutoCompleter.Init(); ResetConsole(); // Make sure compiler is supported on this platform m_evaluator.Compile(""); foreach (string use in DefaultUsing) { AddUsing(use); } } catch (Exception e) { // TODO remove page button from menu? ExplorerCore.LogWarning($"Error setting up console!\r\nMessage: {e.Message}"); } }
/// <summary> /// Check if an object is null, and if it's a UnityEngine.Object then also check if it was destroyed. /// </summary> public static bool IsNullOrDestroyed(this object obj, bool suppressWarning = true) { var unityObj = obj as Object; if (obj == null) { if (!suppressWarning) { ExplorerCore.LogWarning("The target instance is null!"); } return(true); } else if (obj is Object) { if (!unityObj) { if (!suppressWarning) { ExplorerCore.LogWarning("The target UnityEngine.Object was destroyed!"); } return(true); } } return(false); }
public void Unpatch() { try { if (prefix != null) { patchProcessor.Unpatch(prefix); } if (postfix != null) { patchProcessor.Unpatch(postfix); } if (finalizer != null) { patchProcessor.Unpatch(finalizer); } if (transpiler != null) { patchProcessor.Unpatch(transpiler); } Enabled = false; } catch (Exception ex) { ExplorerCore.LogWarning($"Exception unpatching method: {ex}"); } }
public void AddUIInputModule() { if (TInputSystemUIInputModule == null) { ExplorerCore.LogWarning("Unable to find UI Input Module Type, Input will not work!"); return; } var assetType = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputActionAsset"); m_newInputModule = RuntimeProvider.Instance.AddComponent <BaseInputModule>(UIManager.CanvasRoot, TInputSystemUIInputModule); var asset = RuntimeProvider.Instance.CreateScriptable(assetType); inputExtensions = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputActionSetupExtensions"); var addMap = inputExtensions.GetMethod("AddActionMap", new Type[] { assetType, typeof(string) }); var map = addMap.Invoke(null, new object[] { asset, "UI" }); CreateAction(map, "point", new[] { "<Mouse>/position" }, "point"); CreateAction(map, "click", new[] { "<Mouse>/leftButton" }, "leftClick"); CreateAction(map, "rightClick", new[] { "<Mouse>/rightButton" }, "rightClick"); CreateAction(map, "scrollWheel", new[] { "<Mouse>/scroll" }, "scrollWheel"); UI_Enable = map.GetType().GetMethod("Enable"); UI_Enable.Invoke(map, new object[0]); UI_ActionMap = map; }
private void GetSuggestions(string value) { suggestions.Clear(); suggestedNames.Clear(); if (BaseType == null) { ExplorerCore.LogWarning("Autocompleter Base type is null!"); return; } // Check for exact match first if (ReflectionUtility.AllTypes.TryGetValue(value, out Type t) && allowedTypes.Contains(t)) { AddSuggestion(t); } foreach (var entry in allowedTypes) { if (entry.FullName.ContainsIgnoreCase(value)) { AddSuggestion(entry); } } }
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); }
// ~~~~~~~~~~~ Add Hooks window ~~~~~~~~~~~ public void OnClassSelectedForHooks(string typeFullName) { var type = ReflectionUtility.GetTypeByName(typeFullName); if (type == null) { ExplorerCore.LogWarning($"Could not find any type by name {typeFullName}!"); return; } Panel.SetAddHooksLabelType(SignatureHighlighter.Parse(type, true)); Panel.ResetMethodFilter(); filteredEligableMethods.Clear(); currentAddEligableMethods.Clear(); foreach (var method in type.GetMethods(ReflectionUtility.FLAGS)) { if (method.IsGenericMethod || UERuntimeHelper.IsBlacklisted(method)) { continue; } currentAddEligableMethods.Add(method); filteredEligableMethods.Add(method); } isAddingMethods = true; Panel.SetPage(HookManagerPanel.Pages.ClassMethodSelector); Panel.AddHooksScrollPool.Refresh(true, true); }
public object Evaluate(string str, bool suppressWarning = false) { object ret = VoidType.Value; m_evaluator.Compile(str, out var compiled); try { if (compiled == null) { throw new Exception("Mono.Csharp Service was unable to compile the code provided."); } compiled.Invoke(ref ret); } catch (Exception e) { if (!suppressWarning) { ExplorerCore.LogWarning(e.GetType() + ", " + e.Message); } } return(ret); }
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]; }
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; } }
private void OnInputChanged(string val, int fieldIndex) { try { float f; if (IsValueColor32) { byte value = byte.Parse(val); sliders[fieldIndex].value = value; f = (float)((decimal)value / 255); } else { f = float.Parse(val); sliders[fieldIndex].value = f; } SetColorField(f, fieldIndex); } catch (ArgumentException) { } // ignore bad user input catch (FormatException) { } catch (OverflowException) { } catch (Exception ex) { ExplorerCore.LogWarning("InteractiveColor OnInput: " + ex.ToString()); } }
protected override void TrySetValue(object value) { if (!CanWrite) { return; } try { bool _static = PropertyInfo.GetAccessors(true)[0].IsStatic; if (HasArguments) { PropertyInfo.SetValue(DeclaringInstance, value, Evaluator.TryParseArguments()); } else { PropertyInfo.SetValue(DeclaringInstance, value, null); } } catch (Exception ex) { ExplorerCore.LogWarning(ex); } }
public override void ConstructSubcontent() { base.ConstructSubcontent(); if (StructInfo == null) { ExplorerCore.LogWarning("Setting up subcontent but structinfo is null"); return; } var editorContainer = UIFactory.CreateVerticalGroup(m_subContentParent, "EditorContent", false, true, true, true, 2, new Vector4(4, 4, 4, 4), new Color(0.08f, 0.08f, 0.08f)); m_inputs = new InputField[StructInfo.FieldNames.Length]; for (int i = 0; i < StructInfo.FieldNames.Length; i++) { AddEditorRow(i, editorContainer); } if (Owner.CanWrite) { var applyBtn = UIFactory.CreateButton(editorContainer, "ApplyButton", "Apply", OnSetValue, new Color(0.2f, 0.2f, 0.2f)); UIFactory.SetLayoutElement(applyBtn.gameObject, minWidth: 175, minHeight: 25, flexibleWidth: 0); void OnSetValue() { Owner.SetValue(); RefreshUIForValue(); } } }
public bool TryLoadConfig() { try { if (!File.Exists(INI_PATH)) { return(false); } string ini = File.ReadAllText(INI_PATH); var data = _parser.Parse(ini); foreach (var config in data.Sections["Config"]) { if (ConfigManager.InternalConfigs.TryGetValue(config.KeyName, out IConfigElement configElement)) { configElement.BoxedValue = StringToConfigValue(config.Value, configElement.ElementType); } } return(true); } catch (Exception ex) { ExplorerCore.LogWarning("Error loading internal data: " + ex.ToString()); return(false); } }
private void InvokeOnValueChanged(string value) { if (value.Length == UIManager.MAX_INPUTFIELD_CHARS) { ExplorerCore.LogWarning($"Reached maximum InputField character length! ({UIManager.MAX_INPUTFIELD_CHARS})"); } OnInputChanged?.Invoke(value); }
private void OnGameObjectButtonClicked() { if (!ComponentRef) { ExplorerCore.LogWarning("Component reference is null or destroyed!"); return; } InspectorManager.Inspect(ComponentRef.gameObject); }
public override void OnBeginMouseInspect() { MainCamera = Camera.main; if (!MainCamera) { ExplorerCore.LogWarning("No MainCamera found! Cannot inspect world!"); return; } }
public virtual void OnBorrowed(CacheObjectBase owner) { if (this.m_owner != null) { ExplorerCore.LogWarning("Setting an IValue's owner but there is already one set. Maybe it wasn't cleaned up?"); ReleaseFromOwner(); } this.m_owner = owner; }
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}"); } }
protected override void TrySetValue(object value) { try { FieldInfo.SetValue(DeclaringInstance, value); } catch (Exception ex) { ExplorerCore.LogWarning(ex); } }
public static void Create() { if (Instance != null) { ExplorerCore.LogWarning("An instance of MainMenu already exists, cannot create another!"); return; } Instance = new MainMenu(); Instance.Init(); }
private void SetValueFromDropdown() { try { CurrentOwner.SetUserValue(ValueAtIdx(enumDropdown.value).ActualValue); } catch (Exception ex) { ExplorerCore.LogWarning("Exception setting from dropdown: " + ex); } }
public void OnMainButtonClicked() { if (cachedTransform.Value) { OnGameObjectClicked?.Invoke(cachedTransform.Value.gameObject); } else { ExplorerCore.LogWarning("The object was destroyed!"); } }
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); } }