Exemplo n.º 1
0
        private void DrawExceptionSelectBox(PlottedGraph plot)
        {
            uint[]? exceptionNodes = plot.InternalProtoGraph.GetExceptionNodes();
            if (exceptionNodes is null || exceptionNodes.Length == 0)
            {
                string caption = $"No exceptions recorded in thread ID {_ActiveGraph?.TID}";
                ImGuiUtils.DrawRegionCenteredText(caption);
                return;
            }

            string[] labels = exceptionNodes.Select(x => x.ToString()).ToArray();
            if (ImGui.BeginTable("##ExceptionsTable", 2, ImGuiTableFlags.ScrollY | ImGuiTableFlags.RowBg, ImGui.GetContentRegionAvail() - new Vector2(10, _activeHighlights.SelectedExceptionNodes.Any() ? 30 : 0)))
            {
                ImGui.TableSetupColumn("Address", ImGuiTableColumnFlags.WidthFixed, 160);
                ImGui.TableSetupColumn("Module");
                ImGui.TableSetupScrollFreeze(0, 1);
                ImGui.TableHeadersRow();

                foreach (uint nodeidx in exceptionNodes)
                {
                    NodeData?n = plot.InternalProtoGraph.GetNode(nodeidx);

                    if (n is not null)
                    {
                        ImGui.TableNextRow();
                        if (ImGui.TableNextColumn())
                        {
                            if (ImGui.Selectable($"0x{n.Address:X}", _activeHighlights.SelectedExceptionNodes.Contains(nodeidx), ImGuiSelectableFlags.SpanAllColumns))
                            {
                                if (_activeHighlights.SelectedExceptionNodes.Contains(nodeidx))
                                {
                                    _activeHighlights.SelectedExceptionNodes.Remove(nodeidx);
                                    plot.RemoveHighlightedNodes(new List <uint> {
                                        nodeidx
                                    }, CONSTANTS.HighlightType.Exceptions);
                                }
                                else
                                {
                                    _activeHighlights.SelectedExceptionNodes.Add(nodeidx);
                                    plot.AddHighlightedNodes(new List <uint> {
                                        nodeidx
                                    }, CONSTANTS.HighlightType.Exceptions);
                                }
                            }
                        }
                        if (ImGui.TableNextColumn())
                        {
                            ImGui.Text(System.IO.Path.GetFileName(plot.InternalProtoGraph.ProcessData.GetModulePath(n.GlobalModuleID)));
                        }
                    }
                }
                ImGui.EndTable();
            }
        }
Exemplo n.º 2
0
        private static void DrawTraceCombo(TraceRecord trace, bool abbreviate)
        {
            var    tracelist = trace.Target.GetTracesUIList();
            string selString = (abbreviate ? "PID " : "Process ") + trace.PID;

            if (ImGui.TableNextColumn())
            {
                ImGui.AlignTextToFramePadding();
                ImGuiUtils.DrawHorizCenteredText($"{tracelist.Length}x");
                SmallWidgets.MouseoverText($"This target binary has {tracelist.Length} loaded trace{(tracelist.Length != 1 ? 's' : "")} associated with it");
            }

            if (ImGui.TableNextColumn())
            {
                ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X - 35);
                if (ImGui.BeginCombo("##ProcessTraceCombo", selString))
                {
                    foreach (var selectableTrace in tracelist)
                    {
                        bool   current = trace.PID == selectableTrace.PID && trace.randID == selectableTrace.randID;
                        string label   = "PID " + selectableTrace.PID;
                        if (current is false)
                        {
                            //label = "Parent: " + label + $" ({selectableTrace.Target.FileName})";
                            label = label + $" ({selectableTrace.Target.FileName})";
                        }
                        if (selectableTrace.GraphCount == 0)
                        {
                            label = label + "[0 graphs]";
                        }
                        if (ImGui.Selectable(label, current))
                        {
                            rgatState.SelectActiveTrace(selectableTrace);
                        }
                        if (selectableTrace.Children.Length > 0)
                        {
                            CreateTracesDropdown(selectableTrace, 1);
                        }
                    }
                    ImGui.EndCombo();
                }
                ImGui.SameLine();
                ImGui.Text($"{ImGuiController.FA_ICON_COGS}");
            }
        }
Exemplo n.º 3
0
        protected override void DrawWindowContent()
        {
            // left
            {
                Vector2 childSize = ImGui.GetContentRegionAvail();
                childSize.X *= 0.2f;
                ImGui.BeginChild("##left", childSize);
                {
                    ImGuiUtils.BeginGroupFrame();

                    if (ImGui.Button("Load"))
                    {
                        ImGuiStyleConfig.Load(new IniConfig("style"));
                    }

                    ImGuiUtils.SmartSeparator();

                    if (ImGui.Button("Save"))
                    {
                        ImGuiStyleConfig.Save(new IniConfig("style"));
                    }

                    ImGuiUtils.EndGroupFrame();
                }
                ImGui.EndChild();
            }

            ImGui.SameLine();

            // right
            {
                Vector2 childSize = ImGui.GetContentRegionAvail();
                ImGui.BeginChild("##right", childSize);
                {
                    ImGui.ShowStyleEditor();

                    ImGui.EndChild();
                }
                ImGui.EndChild();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Draw a trace selector
        /// </summary>
        /// <param name="trace">Parent trace</param>
        /// <param name="abbreviate">Make the label a bit shorter to fit in the preview pane width</param>
        /// <returns>Selected graph or null</returns>
        public static PlottedGraph?Draw(TraceRecord?trace, bool abbreviate = false)
        {
            if (trace is null)
            {
                if (ImGui.BeginChild(ImGui.GetID("TraceSelect"), new Vector2(ImGui.GetContentRegionAvail().X - 4, ImGui.GetContentRegionAvail().Y)))
                {
                    ImGuiUtils.DrawRegionCenteredText($"No selected trace");
                    ImGui.EndChild();
                }
                return(null);
            }

            PlottedGraph?selectedGraph = null;

            if (ImGui.BeginChild(ImGui.GetID("TraceSelect"), new Vector2(ImGui.GetContentRegionAvail().X - 4, 52)))
            {
                ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, new Vector2(1, 1));
                if (ImGui.BeginTable("#TraceSelectorTable", 2))
                {
                    ImGui.TableSetupColumn("#IconsTraceSel", ImGuiTableColumnFlags.WidthFixed, 35);
                    ImGui.TableNextRow();
                    DrawTraceCombo(trace, abbreviate);

                    ImGui.TableNextRow();
                    DrawThreadSelectorCombo(trace, out selectedGraph, abbreviate);
                    ImGui.EndTable();
                }
                ImGui.PopStyleVar();
                ImGui.EndChild();
            }

            if (selectedGraph is not null)
            {
                rgatState.SetActiveGraph(selectedGraph);
            }
            return(selectedGraph);
        }
Exemplo n.º 5
0
        private static void DrawThreadSelectorCombo(TraceRecord?trace, out PlottedGraph?selectedGraph, bool abbreviate)
        {
            selectedGraph = null;
            ProtoGraph?graph = rgatState.ActiveGraph?.InternalProtoGraph;

            if (trace is not null && graph is not null)
            {
                string selString = $"{(abbreviate ? "TID" : "Thread")} {graph.ThreadID}: {graph.FirstInstrumentedModuleName}";
                if (graph.NodeCount == 0)
                {
                    selString += " [Uninstrumented]";
                }
                List <PlottedGraph> graphs = trace.GetPlottedGraphs();
                if (ImGui.TableNextColumn())
                {
                    ImGui.AlignTextToFramePadding();
                    ImGuiUtils.DrawHorizCenteredText($"{graphs.Count}x");
                    SmallWidgets.MouseoverText($"This trace has {graphs.Count} thread{(graphs.Count != 1 ? 's' : "")}");
                }

                if (ImGui.TableNextColumn())
                {
                    ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X - 35);
                    if (ImGui.BeginCombo("##SelectorThreadCombo", selString))
                    {
                        foreach (PlottedGraph selectablegraph in graphs)
                        {
                            string caption   = $"{selectablegraph.TID}: {selectablegraph.InternalProtoGraph.FirstInstrumentedModuleName}";
                            int    nodeCount = selectablegraph.GraphNodeCount();
                            if (nodeCount == 0)
                            {
                                ImGui.PushStyleColor(ImGuiCol.Text, Themes.GetThemeColourUINT(Themes.eThemeColour.Dull1));
                                caption += " [Uninstrumented]";
                            }
                            else
                            {
                                ImGui.PushStyleColor(ImGuiCol.Text, Themes.GetThemeColourUINT(Themes.eThemeColour.WindowText));
                                caption += $" [{nodeCount} nodes]";
                            }

                            if (ImGui.Selectable(caption, graph.ThreadID == selectablegraph.TID) && nodeCount > 0)
                            {
                                selectedGraph = selectablegraph;
                            }
                            if (ImGui.IsItemHovered())
                            {
                                ImGui.BeginTooltip();
                                ImGui.Text($"Thread Start: 0x{selectablegraph.InternalProtoGraph.StartAddress:X} [{selectablegraph.InternalProtoGraph.StartModuleName}]");
                                if (selectablegraph.InternalProtoGraph.NodeList.Count > 0)
                                {
                                    NodeData?n = selectablegraph.InternalProtoGraph.GetNode(0);
                                    if (n is not null)
                                    {
                                        string insBase = System.IO.Path.GetFileName(graph.ProcessData.GetModulePath(n.GlobalModuleID));
                                        ImGui.Text($"First Instrumented: 0x{n.Address:X} [{insBase}]");
                                    }
                                }
                                ImGui.EndTooltip();
                            }
                            ImGui.PopStyleColor();
                        }
                        ImGui.EndCombo();
                    }
                    ImGui.SameLine();
                    ImGui.Text($"{ImGuiController.FA_ICON_COG}");
                }
            }
        }
Exemplo n.º 6
0
        private void DrawComponents(Entity context)
        {
            // TODO: fix
            bool entityEnabled = context.Enabled;

            if (ImGui.Checkbox("Enabled", ref entityEnabled))
            {
                context.Enabled = entityEnabled;
            }

            var components = context.Components;

            for (int compi = 0; compi < components.Count; compi++)
            {
                Component component = components[compi];

                Type componentType = component.GetType();

                bool stay = true;

                ImGui.PushID(componentType.Name + compi);

                bool valcol = !component.Valid;
                if (valcol)
                {
                    ImGui.PushStyleColor(ImGuiCol.Header, new Vector4(0.412f, 0.118f, 0.118f, 1.0f));
                    ImGui.PushStyleColor(ImGuiCol.HeaderHovered, new Vector4(0.729f, 0.208f, 0.208f, 1.0f));
                }

                // item shifting drop
                unsafe
                {
                    // smoll fix
                    bool resetTarget = false;
                    if (targetedComponent == component)
                    {
                        ImGui.Button("##target", new Vector2(ImGui.GetColumnWidth(), 2.5f));
                        if (ImGui.IsItemHovered())
                        {
                            resetTarget = true;
                        }
                    }

                    if (ImGui.BeginDragDropTarget())
                    {
                        var payload = ImGui.AcceptDragDropPayload("_COMPONENT");
                        if (payload.NativePtr != null && selectedDragNDropComponent != null)
                        {
                            int tci = Context.ActiveEntity.GetComponentIndex(targetedComponent);
                            if (tci > Context.ActiveEntity.GetComponentIndex(selectedDragNDropComponent))
                            {
                                tci--;
                            }
                            Context.ActiveEntity.ShiftComponent(selectedDragNDropComponent, tci);

                            selectedDragNDropComponent = null;
                            targetedComponent          = null;
                        }
                        ImGui.EndDragDropTarget();
                    }

                    if (resetTarget)
                    {
                        targetedComponent = null;
                    }
                }

                bool collapsingHeader = ImGui.CollapsingHeader(componentType.Name, ref stay);

                // item shifting drag
                {
                    if (ImGui.BeginDragDropSource())
                    {
                        ImGui.Text("Component: " + componentType.Name);
                        selectedDragNDropComponent = component;
                        ImGui.SetDragDropPayload("_COMPONENT", IntPtr.Zero, 0);
                        ImGui.EndDragDropSource();
                    }

                    if (ImGui.BeginDragDropTarget())
                    {
                        targetedComponent = component;
                        ImGui.EndDragDropTarget();
                    }
                }

                // contex menu
                {
                    if (ImGui.BeginPopupContextItem())
                    {
                        if (ImGui.MenuItem("Move Up"))
                        {
                            context.ShiftComponent(component, Math.Max(0, compi - 1));
                        }
                        if (ImGui.MenuItem("Move Down"))
                        {
                            context.ShiftComponent(component, Math.Min(components.Count - 1, compi + 1));
                        }
                        ImGui.Separator();
                        if (ImGui.MenuItem("Remove"))
                        {
                            Context.ActiveEntity.RemoveComponent(component);
                        }

                        ImGui.EndPopup();
                    }
                }

                var   style = ImGui.GetStyle();
                float collapsingHeaderButtonOffset = ((ImGui.GetTextLineHeight() + style.FramePadding.Y * 2) + 1);
                ImGui.SameLine(ImGui.GetContentRegionAvail().X - (collapsingHeaderButtonOffset * 1 + style.FramePadding.X + style.FramePadding.Y));
                bool enabled = component.Enabled;
                if (ImGui.Checkbox("##enabled", ref enabled))
                {
                    component.Enabled = enabled;
                }
                ImGui.SameLine(ImGui.GetContentRegionAvail().X - (collapsingHeaderButtonOffset * 2 + style.FramePadding.X + style.FramePadding.Y));
                if (ImGui.ArrowButton("up", ImGuiDir.Up))
                {
                    context.ShiftComponent(component, Math.Max(0, compi - 1));
                }
                ImGui.SameLine(ImGui.GetContentRegionAvail().X - (collapsingHeaderButtonOffset * 3 + style.FramePadding.X + style.FramePadding.Y));
                if (ImGui.ArrowButton("down", ImGuiDir.Down))
                {
                    context.ShiftComponent(component, Math.Min(components.Count - 1, compi + 1));
                }


                if (collapsingHeader)
                {
                    ImGuiUtils.BeginGroupFrame();

                    MemberInfo[] membs = componentType.GetMembers();

                    for (int mi = 0; mi < membs.Length; mi++)
                    {
                        var mem = membs[mi];
                        if (mem.MemberType == MemberTypes.Field || mem.MemberType == MemberTypes.Property)
                        {
                            PropertyDrawer.DrawEditorValue(mem, component);
                        }
                    }

                    //ImGui.Separator();

                    ImGuiUtils.EndGroupFrame();
                }

                if (valcol)
                {
                    ImGui.PopStyleColor(2);
                }

                ImGui.PopID();

                if (!stay)
                {
                    Context.ActiveEntity.RemoveComponent(component);
                }
            }
        }
Exemplo n.º 7
0
        protected override void DrawWindowContent()
        {
            if (_viewportPanel == null || !_viewportPanel.IsOpen())
            {
                return;
            }

            if (ready = (Context.ActiveEntity != null && Context.ActiveEntity.HasComponentOfType <TransformComponent>()))
            {
                if (_viewportPanel.CurrentCamera != null)
                {
                    cameraView       = _viewportPanel.CurrentCamera.ViewMatrix;
                    cameraProjection = _viewportPanel.CurrentCamera.ProjectionMatrix;

                    var tc = Context.ActiveEntity.GetComponent <TransformComponent>();
                    transformMat = tc.WorldTransformMatrix;

                    ImGui.Text("Operation");
                    {
                        //if (ImGui.IsKeyDown('G') && io.KeyShift)
                        //    currentGizmoOperation = OPERATION.TRANSLATE;
                        //if (ImGui.IsKeyPressed('R') && io.KeyShift)
                        //    currentGizmoOperation = OPERATION.ROTATE;
                        //if (ImGui.IsKeyPressed('S') && io.KeyShift)
                        //    currentGizmoOperation = OPERATION.SCALE;
                        //if (ImGui.IsItemHovered())
                        //{
                        //    ImGui.BeginTooltip();
                        //    ImGui.TextUnformatted("shortcut");
                        //    ImGui.EndTooltip();
                        //}

                        ImGuiUtils.BeginGroupFrame();
                        if (ImGui.RadioButton("Translate", currentGizmoOperation == OPERATION.TRANSLATE))
                        {
                            currentGizmoOperation = OPERATION.TRANSLATE;
                        }
                        if (ImGui.RadioButton("Rotate", currentGizmoOperation == OPERATION.ROTATE))
                        {
                            currentGizmoOperation = OPERATION.ROTATE;
                        }
                        if (ImGui.RadioButton("Scale", currentGizmoOperation == OPERATION.SCALE))
                        {
                            currentGizmoOperation = OPERATION.SCALE;
                        }
                        ImGuiUtils.EndGroupFrame();
                    }

                    //ImGui.Separator();
                    //
                    //ImGui.Text("Item transform");
                    //{
                    //    Vector3 translation = new Vector3();
                    //    Vector3 rotation = new Vector3();
                    //    Vector3 scale = new Vector3();
                    //
                    //    bool d = false;
                    //
                    //    ImGuizmo.DecomposeMatrixToComponents(ref transformMat.M11, ref translation.X, ref rotation.X, ref scale.X);
                    //    d |= ImGui.DragFloat3("Translation", ref translation);
                    //    d |= ImGui.DragFloat3("Rotation", ref rotation);
                    //    d |= ImGui.DragFloat3("Scale", ref scale);
                    //
                    //    if (d)
                    //    {
                    //        ImGuizmo.RecomposeMatrixFromComponents(ref translation.X, ref rotation.X, ref scale.X, ref transformMat.M11);
                    //        EditorLayer.Instance.SelectedEntity.GetComponent<TransformComponent>().SetTransformUseEuler(transformMat);
                    //    }
                    //}

                    ImGui.Text("Mode");
                    {
                        if (currentGizmoOperation != OPERATION.SCALE)
                        {
                            ImGuiUtils.BeginGroupFrame();
                            if (ImGui.RadioButton("Local", currentGizmoMode == MODE.LOCAL))
                            {
                                currentGizmoMode = MODE.LOCAL;
                            }
                            ImGui.SameLine();
                            if (ImGui.RadioButton("World", currentGizmoMode == MODE.WORLD))
                            {
                                currentGizmoMode = MODE.WORLD;
                            }
                            ImGuiUtils.EndGroupFrame();
                        }
                    }

                    // drawing of the gizmo is when the viewport draws
                }
            }
        }